#include<stdio.h>
#include<cuda.h>
#include<string.h>
#include<stdlib.h>

void print_matrix(int* mat, int rows, int cols) {
    for(int i=0; i<rows; i++) {
        for(int j=0; j<cols; j++) {
            printf("%d ", mat[i*cols + j]);
        }
        printf("\n");
    }
}

void print_matrix_file(FILE* f, int* mat, int rows, int cols) {
    for(int i=0; i<rows; i++) {
        for(int j=0; j<cols; j++) {
            fprintf(f, "%d ", mat[i*cols + j]);
        }
        fprintf(f, "\n");
    }
}


// Run query on the specified row
__device__ void runQuery(int *data, int n, int *query, int row) {
    int n_queries = query[2];
    int len = n_queries*3 + 3;

    for(int i=3; i<len; i+=3) {
        int op = query[i+2];

        if (op == -1)
            atomicSub(&data[row*n+query[i]-1], query[i+1]);
        else
            atomicAdd(&data[row*n+query[i]-1], query[i+1]);
    }
}

__global__ void searchQuery(int* data, int n, int m, int* query, int col, int x) {
    int tid = blockIdx.x*blockDim.x + threadIdx.x;

    if (tid < m) {
        if(data[tid*n + col-1] == x)
            runQuery(data, n, query, tid);
    }
}

__global__ void runQueries(int* data, int m, int n, int** queries, int q) {
    int tid = blockIdx.x*blockDim.x + threadIdx.x;

    if (tid < q) {
        int *query = queries[tid];

        int col = query[0];
        int x = query[1];

        // Search in database
        for(int row=0; row<m; row++) {
            if(data[row*n + col-1] == x)
                runQuery(data, n, query, row);
        }

        // Try kernel in kernel
        // int n_blocks = ceil((float)m / 1024);
        // searchQuery<<<n_blocks, 1024>>>(data, n, m, query, col, x);
    }
}


int main(int argc, char *argv[]) {
    if (argc < 3) {
        printf("Usage: ./a.out <input-file-name> <output-file-name>\n");
        return 0;
    }

    FILE *in = fopen(argv[1], "r");
    if (in == NULL) {
        printf("Error opening input file!\n");
        return -1;
    }

    int m,n;
    fscanf(in, "%d %d", &m, &n);

    int *data, *ddata;
    data = (int*)malloc(m*n*sizeof(int));
    cudaMalloc(&ddata, m*n*sizeof(int));

    for(int i=0; i<m; i++) {
        for(int j=0; j<n; j++) {
            fscanf(in, "%d", &data[i*n+j]);
        }
    }

    // print_matrix(data, m, n);

    int q;
    char s[10];                     // Assuming every number is less than 1000000000

    fscanf(in, "%d", &q);

    int* queries[q];                // Storage on CPU

    int* dqueries[q];               // Storage on GPU

    for(int i=0; i<q; i++) {
        fscanf(in, "%s", s);
        if (strcmp(s, "U")!=0) {
            // First char is not "U", some problem
            printf("Incorrect input, first character in query must be U, exiting!\n");
            return -1;
        }

        fscanf(in, "%s", s);
        int col = atoi(&s[1]);      // Skip first char C

        fscanf(in, "%s", s);
        int x = atoi(s);            // Value to be matched against column

        fscanf(in, "%s", s);
        int p = atoi(s);            // No of update ops

        int len = p*3 + 3;          // +1 for column, +1 for key, +1 for no. of updates

        queries[i] = (int*)malloc(len*sizeof(int));

        // For copying query to GPU
        int *dquery;
        cudaMalloc(&dquery, len*sizeof(int));

        queries[i][0] = col;
        queries[i][1] = x;
        queries[i][2] = p;

        for(int j=3; j<len; j+=3) {
            fscanf(in, "%s", s);
            queries[i][j] = atoi(&s[1]);

            fscanf(in, "%s", s);
            queries[i][j+1] = atoi(s);

            fscanf(in, "%s", s);
            queries[i][j+2] = (strcmp(s,"+") ? -1 : 1);     // -1 if -, 1 for +

            // printf("%d %d %d\n", queries[i][j], queries[i][j+1], queries[i][j+2]);
        }

        cudaMemcpy(dquery, queries[i], len*sizeof(int), cudaMemcpyHostToDevice);
        dqueries[i] = dquery;
    }

    // for(int i=0; i<q; i++) {
    //     int len = queries[i][2]*3 + 3;
    //     // printf("%d\n", len);
    //     for(int j=0; j<len; j++) {
    //         printf("%d ", queries[i][j]);
    //     }
    //     printf("\n");
    // }

    // Copy Database to GPU
    cudaMemcpy(ddata, data, m*n*sizeof(int), cudaMemcpyHostToDevice);

    // Copy array of pointers(pointing to queries) to GPU
    int** dquerieslist;
    cudaMalloc(&dquerieslist, q*sizeof(int*));

    cudaMemcpy(dquerieslist, dqueries, q*sizeof(int*), cudaMemcpyHostToDevice);

    // One query per thread
    int n_blocks = ceil((float)q / 1024);
    runQueries<<<n_blocks, 1024>>>(ddata, m, n, dquerieslist, q);

    cudaMemcpy(data, ddata, m*n*sizeof(int), cudaMemcpyDeviceToHost);

    // print_matrix(data, m, n);

    // Output to file
    FILE *out = fopen(argv[2], "w");
    if (out == NULL) {
        printf("Error opening output file!");
        return -1;
    }
    print_matrix_file(out, data, m, n);

    fclose(in);
    fclose(out);

    // Free allocated memory
    free(data);
    cudaFree(ddata);

    for(int i=0; i<q; i++) {
        free(queries[i]);
        cudaFree(dqueries[i]);
    }

    return 0;
}

	.file	"tmpxft_0025db30_00000000-6_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2033:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2033:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%d "
.LC1:
	.string	"\n"
	.text
	.globl	_Z12print_matrixPiii
	.type	_Z12print_matrixPiii, @function
_Z12print_matrixPiii:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%esi, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L3:
	cmpl	%r14d, %r13d
	jge	.L2
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %r8
.L6:
	cmpl	%r15d, %ebx
	jle	.L9
	movl	(%r8,%r15,4), %edx
	leaq	.LC0(%rip), %rsi
	xorl	%eax, %eax
	incq	%r15
	movl	$2, %edi
	movq	%r8, 8(%rsp)
	call	__printf_chk@PLT
	movq	8(%rsp), %r8
	jmp	.L6
.L9:
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	incl	%r13d
	addl	%ebx, %r12d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L3
.L2:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z12print_matrixPiii, .-_Z12print_matrixPiii
	.globl	_Z17print_matrix_fileP8_IO_FILEPiii
	.type	_Z17print_matrix_fileP8_IO_FILEPiii, @function
_Z17print_matrix_fileP8_IO_FILEPiii:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movl	%edx, %r14d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%ecx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%rdi, (%rsp)
.L11:
	cmpl	%r14d, %r13d
	jge	.L10
	movslq	%r12d, %rax
	xorl	%r15d, %r15d
	leaq	0(%rbp,%rax,4), %r9
.L14:
	cmpl	%r15d, %ebx
	jle	.L16
	movl	(%r9,%r15,4), %ecx
	movq	(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC0(%rip), %rdx
	movq	%r9, 8(%rsp)
	incq	%r15
	call	__fprintf_chk@PLT
	movq	8(%rsp), %r9
	jmp	.L14
.L16:
	movq	(%rsp), %rdi
	leaq	.LC1(%rip), %rdx
	xorl	%eax, %eax
	incl	%r13d
	movl	$2, %esi
	addl	%ebx, %r12d
	call	__fprintf_chk@PLT
	jmp	.L11
.L10:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2028:
	.size	_Z17print_matrix_fileP8_IO_FILEPiii, .-_Z17print_matrix_fileP8_IO_FILEPiii
	.globl	_Z8runQueryPiiS_i
	.type	_Z8runQueryPiiS_i, @function
_Z8runQueryPiiS_i:
.LFB2029:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z8runQueryPiiS_i, .-_Z8runQueryPiiS_i
	.globl	_Z37__device_stub__Z11searchQueryPiiiS_iiPiiiS_ii
	.type	_Z37__device_stub__Z11searchQueryPiiiS_iiPiiiS_ii, @function
_Z37__device_stub__Z11searchQueryPiiiS_iiPiiiS_ii:
.LFB2055:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 16(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movl	%r9d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 136(%rsp)
	movq	%rsp, %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L19
	pushq	48(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z11searchQueryPiiiS_ii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 192
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L19:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L21
	call	__stack_chk_fail@PLT
.L21:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2055:
	.size	_Z37__device_stub__Z11searchQueryPiiiS_iiPiiiS_ii, .-_Z37__device_stub__Z11searchQueryPiiiS_iiPiiiS_ii
	.globl	_Z11searchQueryPiiiS_ii
	.type	_Z11searchQueryPiiiS_ii, @function
_Z11searchQueryPiiiS_ii:
.LFB2056:
	.cfi_startproc
	endbr64
	jmp	_Z37__device_stub__Z11searchQueryPiiiS_iiPiiiS_ii
	.cfi_endproc
.LFE2056:
	.size	_Z11searchQueryPiiiS_ii, .-_Z11searchQueryPiiiS_ii
	.globl	_Z36__device_stub__Z10runQueriesPiiiPS_iPiiiPS_i
	.type	_Z36__device_stub__Z10runQueriesPiiiPS_iPiiiPS_i, @function
_Z36__device_stub__Z10runQueriesPiiiPS_iPiiiPS_i:
.LFB2057:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 16(%rsp)
	leaq	32(%rsp), %rdx
	movq	%rcx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z10runQueriesPiiiPS_i(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L24:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L26
	call	__stack_chk_fail@PLT
.L26:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z36__device_stub__Z10runQueriesPiiiPS_iPiiiPS_i, .-_Z36__device_stub__Z10runQueriesPiiiPS_iPiiiPS_i
	.globl	_Z10runQueriesPiiiPS_i
	.type	_Z10runQueriesPiiiPS_i, @function
_Z10runQueriesPiiiPS_i:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z10runQueriesPiiiPS_iPiiiPS_i
	.cfi_endproc
.LFE2058:
	.size	_Z10runQueriesPiiiPS_i, .-_Z10runQueriesPiiiPS_i
	.section	.rodata.str1.1
.LC2:
	.string	"Usage: ./a.out <input-file-name> <output-file-name>\n"
.LC3:
	.string	"r"
.LC4:
	.string	"Error opening input file!\n"
.LC5:
	.string	"%d %d"
.LC6:
	.string	"%d"
.LC7:
	.string	"%s"
.LC8:
	.string	"U"
.LC9:
	.string	"Incorrect input, first character in query must be U, exiting!\n"
.LC10:
	.string	"+"
.LC12:
	.string	"w"
.LC13:
	.string	"Error opening output file!"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$136, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	jg	.L30
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L31
.L30:
	movq	8(%rsi), %rdi
	movq	%rsi, %r13
	leaq	.LC3(%rip), %rsi
	call	fopen@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movq	%rax, -136(%rbp)
	testq	%rax, %rax
	je	.L64
	movq	-136(%rbp), %rdi
	leaq	-120(%rbp), %rcx
	xorl	%eax, %eax
	xorl	%r12d, %r12d
	leaq	-124(%rbp), %rdx
	leaq	.LC5(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movl	-124(%rbp), %ebx
	imull	-120(%rbp), %ebx
	movslq	%ebx, %rbx
	salq	$2, %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rsi
	leaq	-112(%rbp), %rdi
	leaq	.LC6(%rip), %rbx
	movq	%rax, -144(%rbp)
	call	cudaMalloc@PLT
.L34:
	cmpl	%r12d, -124(%rbp)
	jle	.L66
	xorl	%r14d, %r14d
.L36:
	movl	-120(%rbp), %eax
	cmpl	%r14d, %eax
	jle	.L67
	imull	%r12d, %eax
	movq	-144(%rbp), %rcx
	movq	-136(%rbp), %rdi
	movq	%rbx, %rsi
	addl	%r14d, %eax
	incl	%r14d
	cltq
	leaq	(%rcx,%rax,4), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	jmp	.L36
.L67:
	incl	%r12d
	jmp	.L34
.L66:
	movq	-136(%rbp), %rdi
	leaq	-116(%rbp), %rdx
	leaq	.LC6(%rip), %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movslq	-116(%rbp), %rax
	movq	%rsp, %rcx
	leaq	15(,%rax,8), %rax
	movq	%rax, %rsi
	movq	%rax, %rdx
	andq	$-4096, %rsi
	andq	$-16, %rdx
	subq	%rsi, %rcx
.L37:
	cmpq	%rcx, %rsp
	je	.L38
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L37
.L38:
	andl	$4095, %edx
	subq	%rdx, %rsp
	testq	%rdx, %rdx
	je	.L39
	orq	$0, -8(%rsp,%rdx)
.L39:
	movq	%rax, %rdx
	movq	%rsp, %rcx
	andq	$-4096, %rax
	movq	%rsp, %r15
	andq	$-16, %rdx
	subq	%rax, %rcx
.L40:
	cmpq	%rcx, %rsp
	je	.L41
	subq	$4096, %rsp
	orq	$0, 4088(%rsp)
	jmp	.L40
.L41:
	movq	%rdx, %rax
	andl	$4095, %eax
	subq	%rax, %rsp
	testq	%rax, %rax
	je	.L42
	orq	$0, -8(%rsp,%rax)
.L42:
	movq	%rsp, -168(%rbp)
	xorl	%r12d, %r12d
	jmp	.L43
.L69:
	movq	-160(%rbp), %rdx
	movq	-80(%rbp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	call	cudaMemcpy@PLT
	movq	-80(%rbp), %rax
	movq	-168(%rbp), %rcx
	movq	%rax, (%rcx,%r12,8)
	incq	%r12
.L43:
	cmpl	%r12d, -116(%rbp)
	jle	.L68
	movq	-136(%rbp), %rdi
	leaq	-66(%rbp), %rbx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	movq	%rbx, %rdx
	call	__isoc23_fscanf@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rbx, %rdi
	call	strcmp@PLT
	testl	%eax, %eax
	je	.L44
	leaq	.LC9(%rip), %rsi
.L65:
	movl	$2, %edi
	xorl	%eax, %eax
.L64:
	call	__printf_chk@PLT
	orl	$-1, %eax
	jmp	.L29
.L44:
	movq	-136(%rbp), %rdi
	movq	%rbx, %rdx
	leaq	.LC7(%rip), %rsi
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	leaq	-65(%rbp), %rdi
	call	atoi@PLT
	movq	-136(%rbp), %rdi
	movq	%rbx, %rdx
	leaq	.LC7(%rip), %rsi
	movl	%eax, -176(%rbp)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	%rbx, %rdi
	call	atoi@PLT
	movq	-136(%rbp), %rdi
	movq	%rbx, %rdx
	leaq	.LC7(%rip), %rsi
	movl	%eax, -152(%rbp)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	%rbx, %rdi
	call	atoi@PLT
	leal	1(%rax), %ebx
	movl	%eax, %r14d
	leal	(%rbx,%rbx,2), %eax
	movl	%eax, -172(%rbp)
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, -160(%rbp)
	call	malloc@PLT
	movq	-160(%rbp), %rsi
	leaq	-80(%rbp), %rdi
	movq	%rax, (%r15,%r12,8)
	movq	%rax, %rbx
	call	cudaMalloc@PLT
	movl	-176(%rbp), %r9d
	movl	-152(%rbp), %ecx
	movl	%r14d, 8(%rbx)
	movl	$3, %r14d
	movl	%r9d, (%rbx)
	movl	%ecx, 4(%rbx)
.L46:
	cmpl	%r14d, -172(%rbp)
	jle	.L69
	leaq	-66(%rbp), %rax
	movq	-136(%rbp), %rdi
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdx
	movq	%rax, -152(%rbp)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	leaq	-65(%rbp), %rdi
	call	atoi@PLT
	movq	-152(%rbp), %rdx
	movq	-136(%rbp), %rdi
	leaq	.LC7(%rip), %rsi
	movl	%eax, (%rbx,%r14,4)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	-152(%rbp), %rdi
	call	atoi@PLT
	movq	-152(%rbp), %rdx
	movq	-136(%rbp), %rdi
	leaq	.LC7(%rip), %rsi
	movl	%eax, 4(%rbx,%r14,4)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movq	-152(%rbp), %rdi
	leaq	.LC10(%rip), %rsi
	call	strcmp@PLT
	negl	%eax
	sbbl	%eax, %eax
	orl	$1, %eax
	movl	%eax, 8(%rbx,%r14,4)
	addq	$3, %r14
	jmp	.L46
.L68:
	movl	-124(%rbp), %edx
	imull	-120(%rbp), %edx
	movl	$1, %ecx
	movq	-144(%rbp), %rsi
	movq	-112(%rbp), %rdi
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movslq	-116(%rbp), %rsi
	leaq	-104(%rbp), %rdi
	salq	$3, %rsi
	call	cudaMalloc@PLT
	movslq	-116(%rbp), %rdx
	movq	-104(%rbp), %rdi
	movl	$1, %ecx
	movq	-168(%rbp), %rsi
	salq	$3, %rdx
	call	cudaMemcpy@PLT
	cvtsi2ssl	-116(%rbp), %xmm0
	mulss	.LC11(%rip), %xmm0
	call	ceilf@PLT
	movl	$4194305, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	cvttss2sil	%xmm0, %eax
	salq	$10, %rdx
	movl	$1, %ecx
	movl	$1, -72(%rbp)
	movq	%rdx, -80(%rbp)
	movl	%eax, -92(%rbp)
	movabsq	$4294967297, %rax
	movq	%rax, -88(%rbp)
	movq	-92(%rbp), %rdi
	movl	-84(%rbp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L50
	movl	-116(%rbp), %r8d
	movq	-104(%rbp), %rcx
	movl	-120(%rbp), %edx
	movl	-124(%rbp), %esi
	movq	-112(%rbp), %rdi
	call	_Z36__device_stub__Z10runQueriesPiiiPS_iPiiiPS_i
.L50:
	movl	-124(%rbp), %edx
	imull	-120(%rbp), %edx
	movl	$2, %ecx
	movq	-112(%rbp), %rsi
	movq	-144(%rbp), %rdi
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	16(%r13), %rdi
	leaq	.LC12(%rip), %rsi
	call	fopen@PLT
	leaq	.LC13(%rip), %rsi
	movq	%rax, %rbx
	testq	%rax, %rax
	je	.L65
	movl	-120(%rbp), %ecx
	movl	-124(%rbp), %edx
	movq	%rax, %rdi
	movq	-144(%rbp), %rsi
	call	_Z17print_matrix_fileP8_IO_FILEPiii
	movq	-136(%rbp), %rdi
	call	fclose@PLT
	movq	%rbx, %rdi
	xorl	%ebx, %ebx
	call	fclose@PLT
	movq	-144(%rbp), %rdi
	call	free@PLT
	movq	-112(%rbp), %rdi
	call	cudaFree@PLT
.L52:
	cmpl	%ebx, -116(%rbp)
	jle	.L31
	movq	(%r15,%rbx,8), %rdi
	call	free@PLT
	movq	-168(%rbp), %rax
	movq	(%rax,%rbx,8), %rdi
	incq	%rbx
	call	cudaFree@PLT
	jmp	.L52
.L31:
	xorl	%eax, %eax
.L29:
	movq	-56(%rbp), %rdx
	subq	%fs:40, %rdx
	je	.L54
	call	__stack_chk_fail@PLT
.L54:
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE2030:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z10runQueriesPiiiPS_i"
.LC15:
	.string	"_Z11searchQueryPiiiS_ii"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z10runQueriesPiiiPS_i(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC15(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z11searchQueryPiiiS_ii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC11:
	.long	981467136
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include<stdio.h>
#include<hip/hip_runtime.h>
#include<string.h>
#include<stdlib.h>

void print_matrix(int* mat, int rows, int cols) {
    for(int i=0; i<rows; i++) {
        for(int j=0; j<cols; j++) {
            printf("%d ", mat[i*cols + j]);
        }
        printf("\n");
    }
}

void print_matrix_file(FILE* f, int* mat, int rows, int cols) {
    for(int i=0; i<rows; i++) {
        for(int j=0; j<cols; j++) {
            fprintf(f, "%d ", mat[i*cols + j]);
        }
        fprintf(f, "\n");
    }
}


// Run query on the specified row
__device__ void runQuery(int *data, int n, int *query, int row) {
    int n_queries = query[2];
    int len = n_queries*3 + 3;

    for(int i=3; i<len; i+=3) {
        int op = query[i+2];

        if (op == -1)
            atomicSub(&data[row*n+query[i]-1], query[i+1]);
        else
            atomicAdd(&data[row*n+query[i]-1], query[i+1]);
    }
}

__global__ void searchQuery(int* data, int n, int m, int* query, int col, int x) {
    int tid = blockIdx.x*blockDim.x + threadIdx.x;

    if (tid < m) {
        if(data[tid*n + col-1] == x)
            runQuery(data, n, query, tid);
    }
}

__global__ void runQueries(int* data, int m, int n, int** queries, int q) {
    int tid = blockIdx.x*blockDim.x + threadIdx.x;

    if (tid < q) {
        int *query = queries[tid];

        int col = query[0];
        int x = query[1];

        // Search in database
        for(int row=0; row<m; row++) {
            if(data[row*n + col-1] == x)
                runQuery(data, n, query, row);
        }

        // Try kernel in kernel
        // int n_blocks = ceil((float)m / 1024);
        // searchQuery<<<n_blocks, 1024>>>(data, n, m, query, col, x);
    }
}


int main(int argc, char *argv[]) {
    if (argc < 3) {
        printf("Usage: ./a.out <input-file-name> <output-file-name>\n");
        return 0;
    }

    FILE *in = fopen(argv[1], "r");
    if (in == NULL) {
        printf("Error opening input file!\n");
        return -1;
    }

    int m,n;
    fscanf(in, "%d %d", &m, &n);

    int *data, *ddata;
    data = (int*)malloc(m*n*sizeof(int));
    hipMalloc(&ddata, m*n*sizeof(int));

    for(int i=0; i<m; i++) {
        for(int j=0; j<n; j++) {
            fscanf(in, "%d", &data[i*n+j]);
        }
    }

    // print_matrix(data, m, n);

    int q;
    char s[10];                     // Assuming every number is less than 1000000000

    fscanf(in, "%d", &q);

    int* queries[q];                // Storage on CPU

    int* dqueries[q];               // Storage on GPU

    for(int i=0; i<q; i++) {
        fscanf(in, "%s", s);
        if (strcmp(s, "U")!=0) {
            // First char is not "U", some problem
            printf("Incorrect input, first character in query must be U, exiting!\n");
            return -1;
        }

        fscanf(in, "%s", s);
        int col = atoi(&s[1]);      // Skip first char C

        fscanf(in, "%s", s);
        int x = atoi(s);            // Value to be matched against column

        fscanf(in, "%s", s);
        int p = atoi(s);            // No of update ops

        int len = p*3 + 3;          // +1 for column, +1 for key, +1 for no. of updates

        queries[i] = (int*)malloc(len*sizeof(int));

        // For copying query to GPU
        int *dquery;
        hipMalloc(&dquery, len*sizeof(int));

        queries[i][0] = col;
        queries[i][1] = x;
        queries[i][2] = p;

        for(int j=3; j<len; j+=3) {
            fscanf(in, "%s", s);
            queries[i][j] = atoi(&s[1]);

            fscanf(in, "%s", s);
            queries[i][j+1] = atoi(s);

            fscanf(in, "%s", s);
            queries[i][j+2] = (strcmp(s,"+") ? -1 : 1);     // -1 if -, 1 for +

            // printf("%d %d %d\n", queries[i][j], queries[i][j+1], queries[i][j+2]);
        }

        hipMemcpy(dquery, queries[i], len*sizeof(int), hipMemcpyHostToDevice);
        dqueries[i] = dquery;
    }

    // for(int i=0; i<q; i++) {
    //     int len = queries[i][2]*3 + 3;
    //     // printf("%d\n", len);
    //     for(int j=0; j<len; j++) {
    //         printf("%d ", queries[i][j]);
    //     }
    //     printf("\n");
    // }

    // Copy Database to GPU
    hipMemcpy(ddata, data, m*n*sizeof(int), hipMemcpyHostToDevice);

    // Copy array of pointers(pointing to queries) to GPU
    int** dquerieslist;
    hipMalloc(&dquerieslist, q*sizeof(int*));

    hipMemcpy(dquerieslist, dqueries, q*sizeof(int*), hipMemcpyHostToDevice);

    // One query per thread
    int n_blocks = ceil((float)q / 1024);
    runQueries<<<n_blocks, 1024>>>(ddata, m, n, dquerieslist, q);

    hipMemcpy(data, ddata, m*n*sizeof(int), hipMemcpyDeviceToHost);

    // print_matrix(data, m, n);

    // Output to file
    FILE *out = fopen(argv[2], "w");
    if (out == NULL) {
        printf("Error opening output file!");
        return -1;
    }
    print_matrix_file(out, data, m, n);

    fclose(in);
    fclose(out);

    // Free allocated memory
    free(data);
    hipFree(ddata);

    for(int i=0; i<q; i++) {
        free(queries[i]);
        hipFree(dqueries[i]);
    }

    return 0;
}

	.text
	.file	"main.hip"
	.globl	_Z12print_matrixPiii            # -- Begin function _Z12print_matrixPiii
	.type	_Z12print_matrixPiii,@function
_Z12print_matrixPiii:                   # @_Z12print_matrixPiii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rdi, 8(%rsp)                   # 8-byte Spill
	testl	%esi, %esi
	jle	.LBB0_6
# %bb.1:                                # %.preheader.lr.ph
	movl	%edx, %ebx
	movl	%esi, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %r12d
	xorl	%ebp, %ebp
	xorl	%r13d, %r13d
.LBB0_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_4 Depth 2
	testl	%ebx, %ebx
	jle	.LBB0_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	%ebp, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%r15d, %r15d
.LBB0_4:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r14,%r15,4), %esi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	incq	%r15
	cmpq	%r15, %r12
	jne	.LBB0_4
.LBB0_5:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r13
	addl	%ebx, %ebp
	cmpq	16(%rsp), %r13                  # 8-byte Folded Reload
	jne	.LBB0_2
.LBB0_6:                                # %._crit_edge13
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z12print_matrixPiii, .Lfunc_end0-_Z12print_matrixPiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z17print_matrix_fileP8_IO_FILEPiii # -- Begin function _Z17print_matrix_fileP8_IO_FILEPiii
	.type	_Z17print_matrix_fileP8_IO_FILEPiii,@function
_Z17print_matrix_fileP8_IO_FILEPiii:    # @_Z17print_matrix_fileP8_IO_FILEPiii
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, 8(%rsp)                   # 8-byte Spill
	testl	%edx, %edx
	jle	.LBB1_6
# %bb.1:                                # %.preheader.lr.ph
	movq	%rdi, %r15
	movl	%edx, %eax
	movq	%rax, 16(%rsp)                  # 8-byte Spill
	movl	%ecx, %r13d
	xorl	%ebp, %ebp
	xorl	%r14d, %r14d
	movl	%ecx, 4(%rsp)                   # 4-byte Spill
.LBB1_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_4 Depth 2
	testl	%ecx, %ecx
	jle	.LBB1_5
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	%ebp, %eax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %r12
	xorl	%ebx, %ebx
.LBB1_4:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r12,%rbx,4), %edx
	movl	$.L.str, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	fprintf
	incq	%rbx
	cmpq	%rbx, %r13
	jne	.LBB1_4
.LBB1_5:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	$10, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	incq	%r14
	movl	4(%rsp), %ecx                   # 4-byte Reload
	addl	%ecx, %ebp
	cmpq	16(%rsp), %r14                  # 8-byte Folded Reload
	jne	.LBB1_2
.LBB1_6:                                # %._crit_edge15
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z17print_matrix_fileP8_IO_FILEPiii, .Lfunc_end1-_Z17print_matrix_fileP8_IO_FILEPiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z26__device_stub__searchQueryPiiiS_ii # -- Begin function _Z26__device_stub__searchQueryPiiiS_ii
	.type	_Z26__device_stub__searchQueryPiiiS_ii,@function
_Z26__device_stub__searchQueryPiiiS_ii: # @_Z26__device_stub__searchQueryPiiiS_ii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	12(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	8(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	movq	%rsp, %r8
	movl	%r9d, (%r8)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z11searchQueryPiiiS_ii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z26__device_stub__searchQueryPiiiS_ii, .Lfunc_end2-_Z26__device_stub__searchQueryPiiiS_ii
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__runQueriesPiiiPS_i # -- Begin function _Z25__device_stub__runQueriesPiiiPS_i
	.type	_Z25__device_stub__runQueriesPiiiPS_i,@function
_Z25__device_stub__runQueriesPiiiPS_i:  # @_Z25__device_stub__runQueriesPiiiPS_i
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	12(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	8(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z10runQueriesPiiiPS_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z25__device_stub__runQueriesPiiiPS_i, .Lfunc_end3-_Z25__device_stub__runQueriesPiiiPS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x3a800000                      # float 9.765625E-4
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$120, %rsp
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	cmpl	$2, %edi
	jg	.LBB4_2
# %bb.1:
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	xorl	%ebx, %ebx
	jmp	.LBB4_29
.LBB4_2:
	movq	%rsi, %r14
	movq	8(%rsi), %rdi
	movl	$.L.str.3, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB4_23
# %bb.3:
	movq	%rax, %rbx
	movq	%r14, -128(%rbp)                # 8-byte Spill
	leaq	-52(%rbp), %r14
	leaq	-48(%rbp), %r15
	movl	$.L.str.5, %esi
	movq	%rax, %rdi
	movq	%r14, %rdx
	movq	%r15, %rcx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movslq	(%r14), %rax
	movslq	(%r15), %r12
	imulq	%rax, %r12
	shlq	$2, %r12
	movq	%r12, %rdi
	callq	malloc
	leaq	-72(%rbp), %rdi
	movq	%r12, %rsi
	movq	%rax, %r12
	callq	hipMalloc
	movl	(%r14), %ecx
	testl	%ecx, %ecx
	jle	.LBB4_10
# %bb.4:                                # %.preheader.preheader
	movl	-48(%rbp), %eax
	xorl	%r14d, %r14d
.LBB4_5:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_7 Depth 2
	testl	%eax, %eax
	jle	.LBB4_9
# %bb.6:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB4_5 Depth=1
	xorl	%r15d, %r15d
.LBB4_7:                                # %.lr.ph
                                        #   Parent Loop BB4_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	imull	%r14d, %eax
	cltq
	addq	%r15, %rax
	leaq	(%r12,%rax,4), %rdx
	movl	$.L.str.6, %esi
	movq	%rbx, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	-48(%rbp), %eax
	incq	%r15
	cmpl	%eax, %r15d
	jl	.LBB4_7
# %bb.8:                                # %._crit_edge.loopexit
                                        #   in Loop: Header=BB4_5 Depth=1
	movl	-52(%rbp), %ecx
.LBB4_9:                                # %._crit_edge
                                        #   in Loop: Header=BB4_5 Depth=1
	incl	%r14d
	cmpl	%ecx, %r14d
	jl	.LBB4_5
.LBB4_10:                               # %._crit_edge83
	movq	%r12, -120(%rbp)                # 8-byte Spill
	leaq	-44(%rbp), %r14
	movl	$.L.str.6, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	%rsp, -136(%rbp)                # 8-byte Spill
	movl	(%r14), %eax
	movq	%rsp, %r12
	leaq	15(,%rax,8), %rax
	andq	$-16, %rax
	subq	%rax, %r12
	movq	%r12, %rsp
	movl	(%r14), %eax
	movq	%rsp, %r13
	leaq	15(,%rax,8), %rcx
	andq	$-16, %rcx
	subq	%rcx, %r13
	movq	%r13, %rsp
	testl	%eax, %eax
	jle	.LBB4_17
# %bb.11:                               # %.lr.ph91
	leaq	-81(%rbp), %r15
	leaq	-82(%rbp), %r14
	xorl	%eax, %eax
	movq	%rax, -96(%rbp)                 # 8-byte Spill
	movq	%r12, -152(%rbp)                # 8-byte Spill
	movq	%r13, -144(%rbp)                # 8-byte Spill
.LBB4_12:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_15 Depth 2
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpw	$85, -82(%rbp)
	jne	.LBB4_24
# %bb.13:                               #   in Loop: Header=BB4_12 Depth=1
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	%r15, %rdi
	callq	atoi
	movl	%eax, -108(%rbp)                # 4-byte Spill
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	%r14, %rdi
	callq	atoi
	movl	%eax, -104(%rbp)                # 4-byte Spill
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	%r14, %rdi
	callq	atoi
	movl	%eax, %r13d
	leal	(%r13,%r13,2), %eax
	movl	%eax, -100(%rbp)                # 4-byte Spill
	cltq
	leaq	12(,%rax,4), %r15
	movq	%r15, %rdi
	callq	malloc
	movq	%r12, %rcx
	movq	%rax, %r12
	movq	-96(%rbp), %rax                 # 8-byte Reload
	movq	%r12, (%rcx,%rax,8)
	leaq	-64(%rbp), %rdi
	movq	%r15, -160(%rbp)                # 8-byte Spill
	movq	%r15, %rsi
	callq	hipMalloc
	movl	-108(%rbp), %eax                # 4-byte Reload
	movl	%eax, (%r12)
	movl	-104(%rbp), %eax                # 4-byte Reload
	movl	%eax, 4(%r12)
	movl	%r13d, 8(%r12)
	testl	%r13d, %r13d
	jle	.LBB4_16
# %bb.14:                               # %.lr.ph86.preheader
                                        #   in Loop: Header=BB4_12 Depth=1
	movl	-100(%rbp), %r13d               # 4-byte Reload
	xorl	%r15d, %r15d
.LBB4_15:                               # %.lr.ph86
                                        #   Parent Loop BB4_12 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	leaq	-81(%rbp), %rdi
	callq	atoi
	movl	%eax, 12(%r12,%r15,4)
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movq	%r14, %rdi
	callq	atoi
	movl	%eax, 16(%r12,%r15,4)
	movl	$.L.str.7, %esi
	movq	%rbx, %rdi
	movq	%r14, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	xorl	%eax, %eax
	cmpw	$43, -82(%rbp)
	sete	%al
	leal	-1(,%rax,2), %eax
	movl	%eax, 20(%r12,%r15,4)
	addq	$3, %r15
	cmpq	%r13, %r15
	jb	.LBB4_15
.LBB4_16:                               # %._crit_edge87
                                        #   in Loop: Header=BB4_12 Depth=1
	movq	-64(%rbp), %rdi
	movq	%r12, %rsi
	movq	-160(%rbp), %rdx                # 8-byte Reload
	movl	$1, %ecx
	callq	hipMemcpy
	movq	-64(%rbp), %rax
	movq	-144(%rbp), %r13                # 8-byte Reload
	movq	-96(%rbp), %rcx                 # 8-byte Reload
	movq	%rax, (%r13,%rcx,8)
	incq	%rcx
	movslq	-44(%rbp), %rax
	movq	%rcx, -96(%rbp)                 # 8-byte Spill
	cmpq	%rax, %rcx
	movq	-152(%rbp), %r12                # 8-byte Reload
	leaq	-81(%rbp), %r15
	jl	.LBB4_12
.LBB4_17:                               # %._crit_edge92
	movq	-72(%rbp), %rdi
	movslq	-52(%rbp), %rax
	movslq	-48(%rbp), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	-120(%rbp), %r15                # 8-byte Reload
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movslq	-44(%rbp), %rsi
	shlq	$3, %rsi
	leaq	-64(%rbp), %r14
	movq	%r14, %rdi
	callq	hipMalloc
	movq	(%r14), %rdi
	movslq	-44(%rbp), %rdx
	shlq	$3, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	cvtsi2ssl	-44(%rbp), %xmm0
	mulss	.LCPI4_0(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %edi
	btsq	$32, %rdi
	movabsq	$4294967296, %rdx               # imm = 0x100000000
	orq	$1024, %rdx                     # imm = 0x400
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_19
# %bb.18:
	movq	-72(%rbp), %rdi
	movl	-52(%rbp), %esi
	movl	-48(%rbp), %edx
	movq	-64(%rbp), %rcx
	movl	-44(%rbp), %r8d
	callq	_Z25__device_stub__runQueriesPiiiPS_i
.LBB4_19:
	movq	-72(%rbp), %rsi
	movslq	-52(%rbp), %rax
	movslq	-48(%rbp), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	-128(%rbp), %rax                # 8-byte Reload
	movq	16(%rax), %rdi
	movl	$.L.str.11, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB4_26
# %bb.20:
	movq	%rax, %r14
	movl	-52(%rbp), %edx
	movl	-48(%rbp), %ecx
	movq	%rax, %rdi
	movq	%r15, %rsi
	callq	_Z17print_matrix_fileP8_IO_FILEPiii
	movq	%rbx, %rdi
	callq	fclose
	movq	%r14, %rdi
	callq	fclose
	movq	%r15, %rdi
	callq	free
	movq	-72(%rbp), %rdi
	callq	hipFree
	cmpl	$0, -44(%rbp)
	jle	.LBB4_27
# %bb.21:                               # %.lr.ph95.preheader
	xorl	%ebx, %ebx
	xorl	%r14d, %r14d
.LBB4_22:                               # %.lr.ph95
                                        # =>This Inner Loop Header: Depth=1
	movq	(%r12,%r14,8), %rdi
	callq	free
	movq	(%r13,%r14,8), %rdi
	callq	hipFree
	incq	%r14
	movslq	-44(%rbp), %rax
	cmpq	%rax, %r14
	jl	.LBB4_22
	jmp	.LBB4_28
.LBB4_23:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$-1, %ebx
	jmp	.LBB4_29
.LBB4_24:                               # %.thread
	movl	$.Lstr, %edi
	callq	puts@PLT
	jmp	.LBB4_25
.LBB4_26:
	movl	$.L.str.12, %edi
	xorl	%eax, %eax
	callq	printf
.LBB4_25:
	movl	$-1, %ebx
	jmp	.LBB4_28
.LBB4_27:
	xorl	%ebx, %ebx
.LBB4_28:
	movq	-136(%rbp), %rsp                # 8-byte Reload
.LBB4_29:
	movl	%ebx, %eax
	leaq	-40(%rbp), %rsp
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa %rsp, 8
	retq
.Lfunc_end4:
	.size	main, .Lfunc_end4-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB5_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB5_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z11searchQueryPiiiS_ii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10runQueriesPiiiPS_i, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end5:
	.size	__hip_module_ctor, .Lfunc_end5-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB6_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB6_2:
	retq
.Lfunc_end6:
	.size	__hip_module_dtor, .Lfunc_end6-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%d "
	.size	.L.str, 4

	.type	_Z11searchQueryPiiiS_ii,@object # @_Z11searchQueryPiiiS_ii
	.section	.rodata,"a",@progbits
	.globl	_Z11searchQueryPiiiS_ii
	.p2align	3, 0x0
_Z11searchQueryPiiiS_ii:
	.quad	_Z26__device_stub__searchQueryPiiiS_ii
	.size	_Z11searchQueryPiiiS_ii, 8

	.type	_Z10runQueriesPiiiPS_i,@object  # @_Z10runQueriesPiiiPS_i
	.globl	_Z10runQueriesPiiiPS_i
	.p2align	3, 0x0
_Z10runQueriesPiiiPS_i:
	.quad	_Z25__device_stub__runQueriesPiiiPS_i
	.size	_Z10runQueriesPiiiPS_i, 8

	.type	.L.str.3,@object                # @.str.3
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.3:
	.asciz	"r"
	.size	.L.str.3, 2

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"%d %d"
	.size	.L.str.5, 6

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%d"
	.size	.L.str.6, 3

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"%s"
	.size	.L.str.7, 3

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"U"
	.size	.L.str.8, 2

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"+"
	.size	.L.str.10, 2

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"w"
	.size	.L.str.11, 2

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Error opening output file!"
	.size	.L.str.12, 27

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11searchQueryPiiiS_ii"
	.size	.L__unnamed_1, 24

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z10runQueriesPiiiPS_i"
	.size	.L__unnamed_2, 23

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Incorrect input, first character in query must be U, exiting!"
	.size	.Lstr, 62

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Error opening input file!"
	.size	.Lstr.1, 26

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"Usage: ./a.out <input-file-name> <output-file-name>"
	.size	.Lstr.2, 52

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z26__device_stub__searchQueryPiiiS_ii
	.addrsig_sym _Z25__device_stub__runQueriesPiiiPS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z11searchQueryPiiiS_ii
	.addrsig_sym _Z10runQueriesPiiiPS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11searchQueryPiiiS_ii ; -- Begin function _Z11searchQueryPiiiS_ii
	.globl	_Z11searchQueryPiiiS_ii
	.p2align	8
	.type	_Z11searchQueryPiiiS_ii,@function
_Z11searchQueryPiiiS_ii:                ; @_Z11searchQueryPiiiS_ii
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x2c
	s_load_b64 s[2:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_cmp_gt_i32_e32 vcc_lo, s3, v1
	s_and_saveexec_b32 s3, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.1:
	s_load_b64 s[4:5], s[0:1], 0x18
	v_mul_lo_u32 v0, v1, s2
	s_load_b64 s[2:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v1, s4, v0
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_co_u32 v1, vcc_lo, s2, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s3, v2, vcc_lo
	global_load_b32 v1, v[1:2], off offset:-4
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, s5, v1
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.2:
	s_load_b64 s[0:1], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_load_b32 s4, s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s4, 1
	s_cbranch_scc1 .LBB0_5
; %bb.3:                                ; %.lr.ph.i.preheader
	s_add_u32 s2, s2, -4
	v_mov_b32_e32 v1, 0
	s_addc_u32 s3, s3, -1
	s_add_u32 s0, s0, 12
	s_mul_i32 s4, s4, 3
	s_addc_u32 s1, s1, 0
	s_mov_b32 s5, 0
.LBB0_4:                                ; %.lr.ph.i
                                        ; =>This Inner Loop Header: Depth=1
	global_load_b96 v[2:4], v1, s[0:1]
	s_add_i32 s5, s5, 3
	s_add_u32 s0, s0, 12
	s_addc_u32 s1, s1, 0
	s_cmp_lt_i32 s5, s4
	s_waitcnt vmcnt(0)
	v_cmp_eq_u32_e32 vcc_lo, -1, v4
	v_add_nc_u32_e32 v5, v2, v0
	v_sub_nc_u32_e32 v2, 0, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e32 v4, v3, v2, vcc_lo
	v_ashrrev_i32_e32 v6, 31, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	v_add_co_u32 v2, vcc_lo, s2, v5
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s3, v6, vcc_lo
	global_atomic_add_u32 v[2:3], v4, off
	s_cbranch_scc1 .LBB0_4
.LBB0_5:                                ; %_Z8runQueryPiiS_i.exit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11searchQueryPiiiS_ii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 7
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z11searchQueryPiiiS_ii, .Lfunc_end0-_Z11searchQueryPiiiS_ii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 312
; NumSgprs: 18
; NumVgprs: 7
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 7
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z10runQueriesPiiiPS_i  ; -- Begin function _Z10runQueriesPiiiPS_i
	.globl	_Z10runQueriesPiiiPS_i
	.p2align	8
	.type	_Z10runQueriesPiiiPS_i,@function
_Z10runQueriesPiiiPS_i:                 ; @_Z10runQueriesPiiiPS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x2c
	s_load_b32 s3, s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mov_b32 s2, exec_lo
	v_cmpx_gt_i32_e64 s3, v1
	s_cbranch_execz .LBB1_8
; %bb.1:
	s_load_b64 s[2:3], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_cmp_lt_i32 s2, 1
	s_cbranch_scc1 .LBB1_8
; %bb.2:                                ; %.lr.ph
	s_load_b64 s[4:5], s[0:1], 0x10
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 3, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v1, vcc_lo, s5, v1, vcc_lo
	s_load_b64 s[4:5], s[0:1], 0x0
	global_load_b64 v[0:1], v[0:1], off
	s_waitcnt lgkmcnt(0)
	s_add_u32 s1, s4, -4
	s_addc_u32 s4, s5, -1
	s_mov_b32 s5, 0
	s_waitcnt vmcnt(0)
	global_load_b64 v[2:3], v[0:1], off
	v_add_co_u32 v4, vcc_lo, v0, 12
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v1, vcc_lo
.LBB1_3:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB1_6 Depth 2
	s_mul_i32 s6, s5, s3
	s_mov_b32 s7, exec_lo
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v6, s6, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v7, 31, v6
	v_lshlrev_b64 v[6:7], 2, v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s1, v6
	v_add_co_ci_u32_e32 v7, vcc_lo, s4, v7, vcc_lo
	global_load_b32 v6, v[6:7], off
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u32_e64 v6, v3
	s_cbranch_execz .LBB1_7
; %bb.4:                                ;   in Loop: Header=BB1_3 Depth=1
	global_load_b32 v6, v[0:1], off offset:8
	s_waitcnt vmcnt(0)
	v_cmp_lt_i32_e32 vcc_lo, 0, v6
	s_and_b32 exec_lo, exec_lo, vcc_lo
	s_cbranch_execz .LBB1_7
; %bb.5:                                ; %.lr.ph.i.preheader
                                        ;   in Loop: Header=BB1_3 Depth=1
	v_lshl_add_u32 v8, v6, 1, v6
	v_dual_mov_b32 v7, v5 :: v_dual_mov_b32 v6, v4
	s_mov_b32 s8, 0
	s_mov_b32 s9, 0
.LBB1_6:                                ; %.lr.ph.i
                                        ;   Parent Loop BB1_3 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	global_load_b96 v[9:11], v[6:7], off
	s_add_i32 s9, s9, 3
	v_add_co_u32 v6, s0, v6, 12
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v7, s0, 0, v7, s0
	s_waitcnt vmcnt(0)
	v_add_nc_u32_e32 v12, s6, v9
	v_sub_nc_u32_e32 v9, 0, v10
	v_cmp_eq_u32_e32 vcc_lo, -1, v11
	v_ashrrev_i32_e32 v13, 31, v12
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_cndmask_b32_e32 v11, v10, v9, vcc_lo
	v_lshlrev_b64 v[12:13], 2, v[12:13]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v9, vcc_lo, s1, v12
	v_add_co_ci_u32_e32 v10, vcc_lo, s4, v13, vcc_lo
	v_cmp_ge_i32_e32 vcc_lo, s9, v8
	global_atomic_add_u32 v[9:10], v11, off
	s_or_b32 s8, vcc_lo, s8
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 exec_lo, exec_lo, s8
	s_cbranch_execnz .LBB1_6
.LBB1_7:                                ; %_Z8runQueryPiiS_i.exit
                                        ;   in Loop: Header=BB1_3 Depth=1
	s_or_b32 exec_lo, exec_lo, s7
	s_add_i32 s5, s5, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lg_u32 s5, s2
	s_cbranch_scc1 .LBB1_3
.LBB1_8:                                ; %.loopexit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10runQueriesPiiiPS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 14
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z10runQueriesPiiiPS_i, .Lfunc_end1-_Z10runQueriesPiiiPS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 444
; NumSgprs: 18
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 14
; Occupancy: 16
; WaveLimiterHint : 1
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11searchQueryPiiiS_ii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11searchQueryPiiiS_ii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     7
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10runQueriesPiiiPS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10runQueriesPiiiPS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
