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

void printmatrix(float * mat, int n){
    int i, j;
    printf("\n");
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            printf("%f ", mat[i*n + j]);
        }
        printf("\n");
    }
}

void writematrix(FILE *outfile, float * mat, int n){
    int i, j;
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            fprintf(outfile, "%f ", mat[i*n + j]);
        }
        fprintf(outfile, "\n");
    }
}

__global__ void jacobi_iter(float *dmatrix, float *dmatrix2, float *fix_points, int n){
    int x = blockIdx.x;
    int y = threadIdx.x;
    if (fix_points[x*n + y] != 1.0){
        dmatrix2[x*n + y] = dmatrix[x*n + 1 + y]*0.25;
        dmatrix2[x*n + y] += dmatrix[x*n - 1 + y]*0.25;
        dmatrix2[x*n + y] += dmatrix[(x-1)*n + y]*0.25;
        dmatrix2[x*n + y] += dmatrix[(x+1)*n + y]*0.25;
    }
}

__global__ void max_diff_reduce(float *mat1, float *mat2, float *reduced_mat) {
    extern __shared__ float sdata[];

    // each thread loads one element from global to shared mem
    unsigned int tid = threadIdx.x;
    unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
    sdata[tid] = mat1[i] - mat2[i];
	__syncthreads();
	// do reduction in shared mem
	for (unsigned int s=blockDim.x/2; s>0; s>>=1) {
		if (tid < s) {
			sdata[tid] = fmax((float)sdata[tid], (float)sdata[tid + s]);
		}
		__syncthreads();
	}
	// write result for this block to global mem
	if (tid == 0) {
		reduced_mat[blockIdx.x] = sdata[0];
	}
}



int main(int argc, char **argv){

    char * filename;
    filename =  argv[1];
    FILE *spec = fopen(filename, "r");
    FILE *outfile = fopen(argv[2], "w");
    int n, i, j, iter; //size of square matrix
    float delta; //for ending iterations
    int check;
    check = fscanf(spec, "%d %f\n", &n, &delta);
    int msize = n*n*sizeof(float);


    float *matrix = (float *)malloc(msize); //host matrix
    float *matrix2 = (float *)malloc(msize); //host matrix
    float *fix_points = (float *)malloc(msize); //host matrix
    for (i = 0; i < n*n; i++){
         fix_points[i] = 0.0;
    }
	float *reduced_mat = (float *)malloc(n*sizeof(float));
    float *dmatrix; // kernel matrix for alternating
    cudaMalloc((void**) &dmatrix, msize);
    float *dmatrix2; // kernel matrix for alternating
    cudaMalloc((void**) &dmatrix2, msize);
    float *dfix_points; // kernel matrix fixed points
    cudaMalloc((void**) &dfix_points, msize);
	float *dreduced_mat;
	cudaMalloc((void**) &dreduced_mat, n*sizeof(float));

	int urow, ucol, drow, dcol;
    float val;

    while (fscanf(spec, "\n%f %d %d %d %d\n", &val, &urow, &ucol, &drow, &dcol) == 5){
        printf("%f %d %d %d %d\n", val, urow, ucol, drow, dcol);
        for (i=urow; i<=drow; i++){
            for(j=ucol; j<=dcol; j++){
                matrix[i*n + j] = val;
                fix_points[i*n + j] = 1.0;
            }
        }
    }
    //printmatrix(matrix, n);
    fclose(spec);
    //printf("msize: %d delta %f\n", n*n, delta);
    cudaMemcpy(dmatrix, matrix, msize, cudaMemcpyHostToDevice);
    cudaMemcpy(dmatrix2, matrix, msize, cudaMemcpyHostToDevice);
    cudaMemcpy(dfix_points, fix_points, msize, cudaMemcpyHostToDevice);
    float maxdiff = 2.0*delta;
    dim3 dimGrid(n,1);
    dim3 dimBlock(n,1,1);
    iter = 0;
    maxdiff = 3;
    while(maxdiff > delta){

        iter += 1;
        jacobi_iter<<<dimGrid, dimBlock>>>(dmatrix, dmatrix2, dfix_points, n);
        cudaThreadSynchronize();
        cudaMemcpy(matrix, dmatrix2, msize, cudaMemcpyDeviceToHost);
        jacobi_iter<<<dimGrid, dimBlock>>>(dmatrix2, dmatrix, dfix_points, n);
        cudaThreadSynchronize();
        cudaMemcpy(matrix2, dmatrix, msize, cudaMemcpyDeviceToHost);
        //max_diff_reduce<<<dimGrid, dimBlock>>>(dmatrix2, dmatrix, dreduced_mat);
		// cudaMemcpy(reduced_mat, dreduced_mat, n*sizeof(float), cudaMemcpyDeviceToHost);
        maxdiff = fabs(matrix[0] - matrix2[0]);
        //maxdiff = reduced_mat[0];
		for(i=1; i<n*n; i++){
		 	maxdiff = fmax((float) maxdiff, (float) fabs((matrix[i]-matrix2[i])));
		}
        printf("\niter: %d maxdiff: %f delta: %f\n", iter, maxdiff, delta);
	}
    cudaMemcpy(matrix, dmatrix2, msize, cudaMemcpyDeviceToHost);
    //printmatrix(matrix, n);
    cudaMemcpy(matrix, dmatrix, msize, cudaMemcpyDeviceToHost);
    //printmatrix(matrix, n);
    writematrix(outfile, matrix2, n);
    fclose(outfile);
}

	.file	"tmpxft_002ddc7c_00000000-6_jacobi.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2032:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2032:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\n"
.LC1:
	.string	"%f "
	.text
	.globl	_Z11printmatrixPfi
	.type	_Z11printmatrixPfi, @function
_Z11printmatrixPfi:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	leaq	.LC1(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%esi, %r13
	leaq	.LC0(%rip), %rsi
	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	%r13, %rbp
	salq	$2, %r13
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdi, %rbx
	movl	$2, %edi
	pushq	%rdx
	.cfi_def_cfa_offset 64
	call	__printf_chk@PLT
.L3:
	cmpl	%ebp, %r12d
	jge	.L9
	leaq	(%rbx,%r13), %r14
.L4:
	cvtss2sd	(%rbx), %xmm0
	movq	%r15, %rsi
	movl	$2, %edi
	movb	$1, %al
	call	__printf_chk@PLT
	addq	$4, %rbx
	cmpq	%r14, %rbx
	jne	.L4
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%r12d
	call	__printf_chk@PLT
	jmp	.L3
.L9:
	popq	%rax
	.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	_Z11printmatrixPfi, .-_Z11printmatrixPfi
	.globl	_Z11writematrixP8_IO_FILEPfi
	.type	_Z11writematrixP8_IO_FILEPfi, @function
_Z11writematrixP8_IO_FILEPfi:
.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movslq	%edx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	leaq	0(,%r13,4), %r14
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%r13, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%rdi, 8(%rsp)
.L11:
	cmpl	%ebp, %r12d
	jge	.L16
	xorl	%r15d, %r15d
.L12:
	movq	8(%rsp), %rdi
	cvtss2sd	(%rbx,%r15,4), %xmm0
	leaq	.LC1(%rip), %rdx
	movb	$1, %al
	movl	$2, %esi
	incq	%r15
	call	__fprintf_chk@PLT
	cmpq	%r13, %r15
	jne	.L12
	movq	8(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	incl	%r12d
	leaq	.LC0(%rip), %rdx
	addq	%r14, %rbx
	call	__fprintf_chk@PLT
	jmp	.L11
.L16:
	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	_Z11writematrixP8_IO_FILEPfi, .-_Z11writematrixP8_IO_FILEPfi
	.globl	_Z36__device_stub__Z11jacobi_iterPfS_S_iPfS_S_i
	.type	_Z36__device_stub__Z11jacobi_iterPfS_S_iPfS_S_i, @function
_Z36__device_stub__Z11jacobi_iterPfS_S_iPfS_S_i:
.LFB2054:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 4(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	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, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L17
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z11jacobi_iterPfS_S_i(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	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 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L17:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2054:
	.size	_Z36__device_stub__Z11jacobi_iterPfS_S_iPfS_S_i, .-_Z36__device_stub__Z11jacobi_iterPfS_S_iPfS_S_i
	.globl	_Z11jacobi_iterPfS_S_i
	.type	_Z11jacobi_iterPfS_S_i, @function
_Z11jacobi_iterPfS_S_i:
.LFB2055:
	.cfi_startproc
	endbr64
	jmp	_Z36__device_stub__Z11jacobi_iterPfS_S_iPfS_S_i
	.cfi_endproc
.LFE2055:
	.size	_Z11jacobi_iterPfS_S_i, .-_Z11jacobi_iterPfS_S_i
	.section	.rodata.str1.1
.LC3:
	.string	"r"
.LC4:
	.string	"w"
.LC5:
	.string	"%d %f\n"
.LC7:
	.string	"%f %d %d %d %d\n"
.LC9:
	.string	"\n%f %d %d %d %d\n"
.LC11:
	.string	"\niter: %d maxdiff: %f delta: %f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2029:
	.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$120, %rsp
	.cfi_def_cfa_offset 176
	movq	8(%rsi), %rdi
	leaq	.LC3(%rip), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	16(%rbx), %rdi
	leaq	.LC4(%rip), %rsi
	movq	%rax, %r14
	call	fopen@PLT
	leaq	24(%rsp), %rcx
	leaq	20(%rsp), %rdx
	movq	%r14, %rdi
	leaq	.LC5(%rip), %rsi
	movq	%rax, (%rsp)
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	movl	20(%rsp), %r15d
	imull	%r15d, %r15d
	leal	0(,%r15,4), %ebx
	movslq	%ebx, %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, %rbp
	call	malloc@PLT
	movq	%rbx, %rdi
	movq	%rax, %r12
	call	malloc@PLT
	movq	%rax, %r13
	xorl	%eax, %eax
.L23:
	cmpl	%eax, %r15d
	jle	.L39
	movl	$0x00000000, 0(%r13,%rax,4)
	incq	%rax
	jmp	.L23
.L39:
	leaq	48(%rsp), %rdi
	movq	%rbx, %rsi
	leaq	.LC9(%rip), %r15
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	leaq	64(%rsp), %rdi
	movq	%rbx, %rsi
	call	cudaMalloc@PLT
	movslq	20(%rsp), %rsi
	leaq	72(%rsp), %rdi
	salq	$2, %rsi
	call	cudaMalloc@PLT
.L25:
	leaq	28(%rsp), %rcx
	leaq	44(%rsp), %rdx
	pushq	%rax
	.cfi_def_cfa_offset 184
	movq	%r15, %rsi
	movq	%r14, %rdi
	leaq	48(%rsp), %rax
	pushq	%rax
	.cfi_def_cfa_offset 192
	xorl	%eax, %eax
	leaq	52(%rsp), %r9
	leaq	48(%rsp), %r8
	call	__isoc23_fscanf@PLT
	popq	%rdx
	.cfi_def_cfa_offset 184
	popq	%rcx
	.cfi_def_cfa_offset 176
	cmpl	$5, %eax
	jne	.L40
	movl	40(%rsp), %r9d
	movl	32(%rsp), %ecx
	movl	$2, %edi
	movb	$1, %al
	movl	36(%rsp), %r8d
	movl	28(%rsp), %edx
	leaq	.LC7(%rip), %rsi
	cvtss2sd	44(%rsp), %xmm0
	call	__printf_chk@PLT
	movl	28(%rsp), %ecx
	movl	20(%rsp), %edi
	movl	36(%rsp), %r8d
	movl	32(%rsp), %r10d
	movl	%ecx, %esi
	movl	40(%rsp), %r9d
	movss	44(%rsp), %xmm0
	imull	%edi, %esi
	movss	.LC8(%rip), %xmm1
.L26:
	cmpl	%ecx, %r8d
	jl	.L25
	movslq	%esi, %rax
	movslq	%r10d, %rdx
	salq	$2, %rax
	leaq	0(%rbp,%rax), %r11
	addq	%r13, %rax
.L27:
	cmpl	%edx, %r9d
	jl	.L41
	movss	%xmm0, (%r11,%rdx,4)
	movss	%xmm1, (%rax,%rdx,4)
	incq	%rdx
	jmp	.L27
.L41:
	incl	%ecx
	addl	%edi, %esi
	jmp	.L26
.L40:
	movq	%r14, %rdi
	xorl	%r14d, %r14d
	call	fclose@PLT
	movq	48(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	56(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	64(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r13, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movl	20(%rsp), %edx
	movabsq	$4294967297, %rax
	movss	.LC2(%rip), %xmm2
	movq	%rax, 84(%rsp)
	movl	%edx, 80(%rsp)
	movl	%edx, 92(%rsp)
	movq	%rax, 96(%rsp)
.L31:
	comiss	24(%rsp), %xmm2
	jbe	.L42
	movl	100(%rsp), %ecx
	movq	92(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	80(%rsp), %rdi
	movl	88(%rsp), %esi
	incl	%r14d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L32
	movl	20(%rsp), %ecx
	movq	64(%rsp), %rdx
	movq	56(%rsp), %rsi
	movq	48(%rsp), %rdi
	call	_Z36__device_stub__Z11jacobi_iterPfS_S_iPfS_S_i
.L32:
	call	cudaThreadSynchronize@PLT
	movq	56(%rsp), %rsi
	movq	%rbx, %rdx
	movq	%rbp, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movl	100(%rsp), %ecx
	movl	88(%rsp), %esi
	xorl	%r9d, %r9d
	movq	92(%rsp), %rdx
	movq	80(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	movl	20(%rsp), %ecx
	movq	64(%rsp), %rdx
	movq	48(%rsp), %rsi
	movq	56(%rsp), %rdi
	call	_Z36__device_stub__Z11jacobi_iterPfS_S_iPfS_S_i
.L33:
	call	cudaThreadSynchronize@PLT
	movq	48(%rsp), %rsi
	movq	%rbx, %rdx
	movq	%r12, %rdi
	movl	$2, %ecx
	xorl	%r15d, %r15d
	call	cudaMemcpy@PLT
	movl	20(%rsp), %r13d
	movss	0(%rbp), %xmm2
	subss	(%r12), %xmm2
	andps	.LC10(%rip), %xmm2
	imull	%r13d, %r13d
.L34:
	incq	%r15
	cmpl	%r15d, %r13d
	jle	.L43
	movss	0(%rbp,%r15,4), %xmm1
	subss	(%r12,%r15,4), %xmm1
	movaps	%xmm2, %xmm0
	andps	.LC10(%rip), %xmm1
	call	fmaxf@PLT
	movaps	%xmm0, %xmm2
	jmp	.L34
.L43:
	movl	%r14d, %edx
	leaq	.LC11(%rip), %rsi
	movl	$2, %edi
	movb	$2, %al
	movss	%xmm2, 12(%rsp)
	cvtss2sd	%xmm2, %xmm0
	cvtss2sd	24(%rsp), %xmm1
	call	__printf_chk@PLT
	movss	12(%rsp), %xmm2
	jmp	.L31
.L42:
	movq	56(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbx, %rdx
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	movq	48(%rsp), %rsi
	movq	%rbx, %rdx
	movq	%rbp, %rdi
	movl	$2, %ecx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rdi
	movl	20(%rsp), %edx
	movq	%r12, %rsi
	call	_Z11writematrixP8_IO_FILEPfi
	movq	(%rsp), %rdi
	call	fclose@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L37
	call	__stack_chk_fail@PLT
.L37:
	addq	$120, %rsp
	.cfi_def_cfa_offset 56
	xorl	%eax, %eax
	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
.LFE2029:
	.size	main, .-main
	.text
	.globl	_Z39__device_stub__Z15max_diff_reducePfS_S_PfS_S_
	.type	_Z39__device_stub__Z15max_diff_reducePfS_S_PfS_S_, @function
_Z39__device_stub__Z15max_diff_reducePfS_S_PfS_S_:
.LFB2056:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L44
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z15max_diff_reducePfS_S_(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	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 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L44:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L46
	call	__stack_chk_fail@PLT
.L46:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2056:
	.size	_Z39__device_stub__Z15max_diff_reducePfS_S_PfS_S_, .-_Z39__device_stub__Z15max_diff_reducePfS_S_PfS_S_
	.globl	_Z15max_diff_reducePfS_S_
	.type	_Z15max_diff_reducePfS_S_, @function
_Z15max_diff_reducePfS_S_:
.LFB2057:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z15max_diff_reducePfS_S_PfS_S_
	.cfi_endproc
.LFE2057:
	.size	_Z15max_diff_reducePfS_S_, .-_Z15max_diff_reducePfS_S_
	.section	.rodata.str1.1
.LC12:
	.string	"_Z15max_diff_reducePfS_S_"
.LC13:
	.string	"_Z11jacobi_iterPfS_S_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2059:
	.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	.LC12(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z15max_diff_reducePfS_S_(%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	.LC13(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z11jacobi_iterPfS_S_i(%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
.LFE2059:
	.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
.LC2:
	.long	1077936128
	.align 4
.LC8:
	.long	1065353216
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC10:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.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 <stdlib.h>
#include <hip/hip_runtime.h>

void printmatrix(float * mat, int n){
    int i, j;
    printf("\n");
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            printf("%f ", mat[i*n + j]);
        }
        printf("\n");
    }
}

void writematrix(FILE *outfile, float * mat, int n){
    int i, j;
    for (i = 0; i < n; i++){
        for (j = 0; j < n; j++){
            fprintf(outfile, "%f ", mat[i*n + j]);
        }
        fprintf(outfile, "\n");
    }
}

__global__ void jacobi_iter(float *dmatrix, float *dmatrix2, float *fix_points, int n){
    int x = blockIdx.x;
    int y = threadIdx.x;
    if (fix_points[x*n + y] != 1.0){
        dmatrix2[x*n + y] = dmatrix[x*n + 1 + y]*0.25;
        dmatrix2[x*n + y] += dmatrix[x*n - 1 + y]*0.25;
        dmatrix2[x*n + y] += dmatrix[(x-1)*n + y]*0.25;
        dmatrix2[x*n + y] += dmatrix[(x+1)*n + y]*0.25;
    }
}

__global__ void max_diff_reduce(float *mat1, float *mat2, float *reduced_mat) {
    extern __shared__ float sdata[];

    // each thread loads one element from global to shared mem
    unsigned int tid = threadIdx.x;
    unsigned int i = blockIdx.x*blockDim.x + threadIdx.x;
    sdata[tid] = mat1[i] - mat2[i];
	__syncthreads();
	// do reduction in shared mem
	for (unsigned int s=blockDim.x/2; s>0; s>>=1) {
		if (tid < s) {
			sdata[tid] = fmax((float)sdata[tid], (float)sdata[tid + s]);
		}
		__syncthreads();
	}
	// write result for this block to global mem
	if (tid == 0) {
		reduced_mat[blockIdx.x] = sdata[0];
	}
}



int main(int argc, char **argv){

    char * filename;
    filename =  argv[1];
    FILE *spec = fopen(filename, "r");
    FILE *outfile = fopen(argv[2], "w");
    int n, i, j, iter; //size of square matrix
    float delta; //for ending iterations
    int check;
    check = fscanf(spec, "%d %f\n", &n, &delta);
    int msize = n*n*sizeof(float);


    float *matrix = (float *)malloc(msize); //host matrix
    float *matrix2 = (float *)malloc(msize); //host matrix
    float *fix_points = (float *)malloc(msize); //host matrix
    for (i = 0; i < n*n; i++){
         fix_points[i] = 0.0;
    }
	float *reduced_mat = (float *)malloc(n*sizeof(float));
    float *dmatrix; // kernel matrix for alternating
    hipMalloc((void**) &dmatrix, msize);
    float *dmatrix2; // kernel matrix for alternating
    hipMalloc((void**) &dmatrix2, msize);
    float *dfix_points; // kernel matrix fixed points
    hipMalloc((void**) &dfix_points, msize);
	float *dreduced_mat;
	hipMalloc((void**) &dreduced_mat, n*sizeof(float));

	int urow, ucol, drow, dcol;
    float val;

    while (fscanf(spec, "\n%f %d %d %d %d\n", &val, &urow, &ucol, &drow, &dcol) == 5){
        printf("%f %d %d %d %d\n", val, urow, ucol, drow, dcol);
        for (i=urow; i<=drow; i++){
            for(j=ucol; j<=dcol; j++){
                matrix[i*n + j] = val;
                fix_points[i*n + j] = 1.0;
            }
        }
    }
    //printmatrix(matrix, n);
    fclose(spec);
    //printf("msize: %d delta %f\n", n*n, delta);
    hipMemcpy(dmatrix, matrix, msize, hipMemcpyHostToDevice);
    hipMemcpy(dmatrix2, matrix, msize, hipMemcpyHostToDevice);
    hipMemcpy(dfix_points, fix_points, msize, hipMemcpyHostToDevice);
    float maxdiff = 2.0*delta;
    dim3 dimGrid(n,1);
    dim3 dimBlock(n,1,1);
    iter = 0;
    maxdiff = 3;
    while(maxdiff > delta){

        iter += 1;
        jacobi_iter<<<dimGrid, dimBlock>>>(dmatrix, dmatrix2, dfix_points, n);
        hipDeviceSynchronize();
        hipMemcpy(matrix, dmatrix2, msize, hipMemcpyDeviceToHost);
        jacobi_iter<<<dimGrid, dimBlock>>>(dmatrix2, dmatrix, dfix_points, n);
        hipDeviceSynchronize();
        hipMemcpy(matrix2, dmatrix, msize, hipMemcpyDeviceToHost);
        //max_diff_reduce<<<dimGrid, dimBlock>>>(dmatrix2, dmatrix, dreduced_mat);
		// cudaMemcpy(reduced_mat, dreduced_mat, n*sizeof(float), cudaMemcpyDeviceToHost);
        maxdiff = fabs(matrix[0] - matrix2[0]);
        //maxdiff = reduced_mat[0];
		for(i=1; i<n*n; i++){
		 	maxdiff = fmax((float) maxdiff, (float) fabs((matrix[i]-matrix2[i])));
		}
        printf("\niter: %d maxdiff: %f delta: %f\n", iter, maxdiff, delta);
	}
    hipMemcpy(matrix, dmatrix2, msize, hipMemcpyDeviceToHost);
    //printmatrix(matrix, n);
    hipMemcpy(matrix, dmatrix, msize, hipMemcpyDeviceToHost);
    //printmatrix(matrix, n);
    writematrix(outfile, matrix2, n);
    fclose(outfile);
}

	.text
	.file	"jacobi.hip"
	.globl	_Z11printmatrixPfi              # -- Begin function _Z11printmatrixPfi
	.type	_Z11printmatrixPfi,@function
_Z11printmatrixPfi:                     # @_Z11printmatrixPfi
	.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
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movq	%rdi, (%rsp)                    # 8-byte Spill
	movl	$10, %edi
	callq	putchar@PLT
	testl	%ebx, %ebx
	jle	.LBB0_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebx, %r15d
	xorl	%r12d, %r12d
	xorl	%r13d, %r13d
.LBB0_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_3 Depth 2
	movl	%r12d, %eax
	movq	(%rsp), %rcx                    # 8-byte Reload
	leaq	(%rcx,%rax,4), %rbp
	xorl	%r14d, %r14d
.LBB0_3:                                #   Parent Loop BB0_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%rbp,%r14,4), %xmm0
	movl	$.L.str.1, %edi
	movb	$1, %al
	callq	printf
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB0_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB0_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r13
	addl	%ebx, %r12d
	cmpq	%r15, %r13
	jne	.LBB0_2
.LBB0_5:                                # %._crit_edge14
	addq	$8, %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	_Z11printmatrixPfi, .Lfunc_end0-_Z11printmatrixPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z11writematrixP8_IO_FILEPfi    # -- Begin function _Z11writematrixP8_IO_FILEPfi
	.type	_Z11writematrixP8_IO_FILEPfi,@function
_Z11writematrixP8_IO_FILEPfi:           # @_Z11writematrixP8_IO_FILEPfi
	.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, 16(%rsp)                  # 8-byte Spill
	movl	%edx, 12(%rsp)                  # 4-byte Spill
	testl	%edx, %edx
	jle	.LBB1_5
# %bb.1:                                # %.preheader.lr.ph
	movq	%rdi, %r15
	movl	12(%rsp), %r12d                 # 4-byte Reload
	xorl	%r13d, %r13d
	xorl	%ebp, %ebp
.LBB1_2:                                # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_3 Depth 2
	movl	%r13d, %eax
	movq	16(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rcx,%rax,4), %r14
	xorl	%ebx, %ebx
.LBB1_3:                                #   Parent Loop BB1_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cvtss2sd	(%r14,%rbx,4), %xmm0
	movl	$.L.str.1, %esi
	movq	%r15, %rdi
	movb	$1, %al
	callq	fprintf
	incq	%rbx
	cmpq	%rbx, %r12
	jne	.LBB1_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	movl	$10, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	incq	%rbp
	addl	12(%rsp), %r13d                 # 4-byte Folded Reload
	cmpq	%r12, %rbp
	jne	.LBB1_2
.LBB1_5:                                # %._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	_Z11writematrixP8_IO_FILEPfi, .Lfunc_end1-_Z11writematrixP8_IO_FILEPfi
	.cfi_endproc
                                        # -- End function
	.globl	_Z26__device_stub__jacobi_iterPfS_S_i # -- Begin function _Z26__device_stub__jacobi_iterPfS_S_i
	.type	_Z26__device_stub__jacobi_iterPfS_S_i,@function
_Z26__device_stub__jacobi_iterPfS_S_i:  # @_Z26__device_stub__jacobi_iterPfS_S_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	$112, %rsp
	.cfi_def_cfa_offset 160
	.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	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	4(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z11jacobi_iterPfS_S_i, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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__jacobi_iterPfS_S_i, .Lfunc_end2-_Z26__device_stub__jacobi_iterPfS_S_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z30__device_stub__max_diff_reducePfS_S_ # -- Begin function _Z30__device_stub__max_diff_reducePfS_S_
	.type	_Z30__device_stub__max_diff_reducePfS_S_,@function
_Z30__device_stub__max_diff_reducePfS_S_: # @_Z30__device_stub__max_diff_reducePfS_S_
	.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	$112, %rsp
	.cfi_def_cfa_offset 160
	.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	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%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	$_Z15max_diff_reducePfS_S_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	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	_Z30__device_stub__max_diff_reducePfS_S_, .Lfunc_end3-_Z30__device_stub__max_diff_reducePfS_S_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI4_0:
	.long	0x40400000                      # float 3
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0
.LCPI4_1:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.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	$104, %rsp
	.cfi_def_cfa_offset 160
	.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, %rbx
	movq	8(%rsi), %rdi
	movl	$.L.str.2, %esi
	callq	fopen
	movq	%rax, %r13
	movq	16(%rbx), %rdi
	movl	$.L.str.3, %esi
	callq	fopen
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	leaq	12(%rsp), %rbx
	leaq	36(%rsp), %rcx
	movl	$.L.str.4, %esi
	movq	%r13, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%rbx), %ebp
	movl	%ebp, %ebx
	imull	%ebx, %ebx
	leal	(,%rbx,4), %eax
	movslq	%eax, %r14
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r15
	movq	%r14, %rdi
	callq	malloc
	testl	%ebp, %ebp
	je	.LBB4_2
# %bb.1:                                # %.lr.ph.preheader
	cmpl	$1, %ebx
	adcl	$0, %ebx
	shlq	$2, %rbx
	movq	%rax, %rdi
	xorl	%esi, %esi
	movq	%rbx, %rdx
	movq	%rax, %rbx
	callq	memset@PLT
	movq	%rbx, %rax
.LBB4_2:                                # %._crit_edge
	movq	%rax, 64(%rsp)                  # 8-byte Spill
	leaq	48(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	40(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	leaq	56(%rsp), %rdi
	movq	%r14, %rsi
	callq	hipMalloc
	movslq	12(%rsp), %rsi
	shlq	$2, %rsi
	leaq	96(%rsp), %rdi
	callq	hipMalloc
	leaq	20(%rsp), %rax
	movq	%rax, (%rsp)
	leaq	16(%rsp), %rdx
	leaq	32(%rsp), %rcx
	leaq	28(%rsp), %r8
	leaq	24(%rsp), %r9
	movl	$.L.str.5, %esi
	movq	%r13, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$5, %eax
	jne	.LBB4_11
# %bb.3:
	leaq	28(%rsp), %rbx
	leaq	24(%rsp), %rbp
.LBB4_5:                                # %.lr.ph94
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_7 Depth 2
                                        #       Child Loop BB4_9 Depth 3
	xorps	%xmm0, %xmm0
	cvtss2sd	16(%rsp), %xmm0
	movl	32(%rsp), %esi
	movl	28(%rsp), %edx
	movl	24(%rsp), %ecx
	movl	20(%rsp), %r8d
	movl	$.L.str.6, %edi
	movb	$1, %al
	callq	printf
	movslq	32(%rsp), %rax
	movl	24(%rsp), %ecx
	cmpl	%ecx, %eax
	jg	.LBB4_4
# %bb.6:                                # %.lr.ph92
                                        #   in Loop: Header=BB4_5 Depth=1
	movslq	28(%rsp), %rdx
	movl	20(%rsp), %esi
	movss	16(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movslq	12(%rsp), %rdi
	incl	%ecx
	movq	%rax, %r9
	imulq	%rdi, %r9
	addq	%rdx, %r9
	leaq	(%r12,%r9,4), %r8
	shlq	$2, %rdi
	movq	64(%rsp), %r10                  # 8-byte Reload
	leaq	(%r10,%r9,4), %r9
	movl	%esi, %r10d
	subl	%edx, %r10d
	incl	%r10d
.LBB4_7:                                #   Parent Loop BB4_5 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB4_9 Depth 3
	cmpl	%esi, %edx
	jg	.LBB4_10
# %bb.8:                                # %.lr.ph87
                                        #   in Loop: Header=BB4_7 Depth=2
	xorl	%r11d, %r11d
.LBB4_9:                                #   Parent Loop BB4_5 Depth=1
                                        #     Parent Loop BB4_7 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movss	%xmm0, (%r8,%r11,4)
	movl	$1065353216, (%r9,%r11,4)       # imm = 0x3F800000
	incq	%r11
	cmpl	%r11d, %r10d
	jne	.LBB4_9
.LBB4_10:                               # %._crit_edge88
                                        #   in Loop: Header=BB4_7 Depth=2
	incq	%rax
	addq	%rdi, %r8
	addq	%rdi, %r9
	cmpl	%eax, %ecx
	jne	.LBB4_7
.LBB4_4:                                # %.loopexit
                                        #   in Loop: Header=BB4_5 Depth=1
	leaq	20(%rsp), %rax
	movq	%rax, (%rsp)
	movl	$.L.str.5, %esi
	movq	%r13, %rdi
	leaq	16(%rsp), %rdx
	leaq	32(%rsp), %rcx
	movq	%rbx, %r8
	movq	%rbp, %r9
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	cmpl	$5, %eax
	je	.LBB4_5
.LBB4_11:                               # %._crit_edge95
	movq	%r13, %rdi
	callq	fclose
	movq	48(%rsp), %rdi
	movq	%r12, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	40(%rsp), %rdi
	movq	%r12, %rsi
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	56(%rsp), %rdi
	movq	64(%rsp), %rsi                  # 8-byte Reload
	movq	%r14, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movss	.LCPI4_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	ucomiss	36(%rsp), %xmm0
	jbe	.LBB4_22
# %bb.12:                               # %.lr.ph103.preheader
	movl	12(%rsp), %r13d
	btsq	$32, %r13
	xorl	%ebp, %ebp
.LBB4_13:                               # %.lr.ph103
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_20 Depth 2
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_15
# %bb.14:                               #   in Loop: Header=BB4_13 Depth=1
	movq	48(%rsp), %rdi
	movq	40(%rsp), %rsi
	movq	56(%rsp), %rdx
	movl	12(%rsp), %ecx
	callq	_Z26__device_stub__jacobi_iterPfS_S_i
.LBB4_15:                               #   in Loop: Header=BB4_13 Depth=1
	callq	hipDeviceSynchronize
	movq	40(%rsp), %rsi
	movq	%r12, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB4_17
# %bb.16:                               #   in Loop: Header=BB4_13 Depth=1
	movq	40(%rsp), %rdi
	movq	48(%rsp), %rsi
	movq	56(%rsp), %rdx
	movl	12(%rsp), %ecx
	callq	_Z26__device_stub__jacobi_iterPfS_S_i
.LBB4_17:                               #   in Loop: Header=BB4_13 Depth=1
	callq	hipDeviceSynchronize
	movq	48(%rsp), %rsi
	movq	%r15, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movss	(%r12), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	subss	(%r15), %xmm0
	movaps	.LCPI4_1(%rip), %xmm3           # xmm3 = [NaN,NaN,NaN,NaN]
	andps	%xmm3, %xmm0
	movl	12(%rsp), %eax
	imull	%eax, %eax
	cmpl	$2, %eax
	jb	.LBB4_18
# %bb.19:                               # %.lr.ph99.preheader
                                        #   in Loop: Header=BB4_13 Depth=1
	movl	%eax, %eax
	movl	$1, %ecx
	movaps	%xmm0, %xmm4
.LBB4_20:                               # %.lr.ph99
                                        #   Parent Loop BB4_13 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r12,%rcx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	subss	(%r15,%rcx,4), %xmm1
	andps	%xmm3, %xmm1
	cmpunordss	%xmm4, %xmm4
	movaps	%xmm4, %xmm2
	andps	%xmm1, %xmm2
	maxss	%xmm0, %xmm1
	andnps	%xmm1, %xmm4
	orps	%xmm2, %xmm4
	incq	%rcx
	movaps	%xmm4, %xmm0
	cmpq	%rcx, %rax
	jne	.LBB4_20
	jmp	.LBB4_21
.LBB4_18:                               #   in Loop: Header=BB4_13 Depth=1
	movaps	%xmm0, %xmm4
.LBB4_21:                               # %._crit_edge100
                                        #   in Loop: Header=BB4_13 Depth=1
	movaps	%xmm4, 64(%rsp)                 # 16-byte Spill
	incl	%ebp
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm4, %xmm0
	xorps	%xmm1, %xmm1
	cvtss2sd	36(%rsp), %xmm1
	movl	$.L.str.7, %edi
	movl	%ebp, %esi
	movb	$2, %al
	callq	printf
	movaps	64(%rsp), %xmm0                 # 16-byte Reload
	ucomiss	36(%rsp), %xmm0
	ja	.LBB4_13
.LBB4_22:                               # %._crit_edge104
	movq	40(%rsp), %rsi
	movq	%r12, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	48(%rsp), %rsi
	movq	%r12, %rdi
	movq	%r14, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movl	12(%rsp), %edx
	movq	88(%rsp), %rbx                  # 8-byte Reload
	movq	%rbx, %rdi
	movq	%r15, %rsi
	callq	_Z11writematrixP8_IO_FILEPfi
	movq	%rbx, %rdi
	callq	fclose
	xorl	%eax, %eax
	addq	$104, %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_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	$_Z11jacobi_iterPfS_S_i, %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	$_Z15max_diff_reducePfS_S_, %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.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"%f "
	.size	.L.str.1, 4

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

	.type	_Z15max_diff_reducePfS_S_,@object # @_Z15max_diff_reducePfS_S_
	.globl	_Z15max_diff_reducePfS_S_
	.p2align	3, 0x0
_Z15max_diff_reducePfS_S_:
	.quad	_Z30__device_stub__max_diff_reducePfS_S_
	.size	_Z15max_diff_reducePfS_S_, 8

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

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%d %f\n"
	.size	.L.str.4, 7

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"\n%f %d %d %d %d\n"
	.size	.L.str.5, 17

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"%f %d %d %d %d\n"
	.size	.L.str.6, 16

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\niter: %d maxdiff: %f delta: %f\n"
	.size	.L.str.7, 33

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z11jacobi_iterPfS_S_i"
	.size	.L__unnamed_1, 23

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z15max_diff_reducePfS_S_"
	.size	.L__unnamed_2, 26

	.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

	.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__jacobi_iterPfS_S_i
	.addrsig_sym _Z30__device_stub__max_diff_reducePfS_S_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z11jacobi_iterPfS_S_i
	.addrsig_sym _Z15max_diff_reducePfS_S_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z11jacobi_iterPfS_S_i  ; -- Begin function _Z11jacobi_iterPfS_S_i
	.globl	_Z11jacobi_iterPfS_S_i
	.p2align	8
	.type	_Z11jacobi_iterPfS_S_i,@function
_Z11jacobi_iterPfS_S_i:                 ; @_Z11jacobi_iterPfS_S_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x18
	s_load_b64 s[2:3], s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_mul_i32 s15, s15, s4
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v3, s15, v0
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[3:4]
	v_add_co_u32 v4, vcc_lo, s2, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v2, vcc_lo
	s_mov_b32 s2, exec_lo
	global_load_b32 v4, v[4:5], off
	s_waitcnt vmcnt(0)
	v_cmpx_neq_f32_e32 1.0, v4
	s_cbranch_execz .LBB0_2
; %bb.1:
	s_load_b128 s[0:3], s[0:1], 0x0
	v_add_nc_u32_e32 v3, -1, v3
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v4, vcc_lo, s0, v1
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v2, vcc_lo
	v_add_co_u32 v1, vcc_lo, s2, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s3, v2, vcc_lo
	global_load_b32 v5, v[4:5], off offset:4
	v_ashrrev_i32_e32 v4, 31, v3
	s_sub_i32 s2, s15, s4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	v_add_co_u32 v3, vcc_lo, s0, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v5, 0x3e800000, v5
	global_store_b32 v[1:2], v5, off
	global_load_b32 v6, v[3:4], off
	v_cvt_f64_f32_e32 v[3:4], v5
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[5:6], v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[3:4], 0x3fd00000, v[5:6], v[3:4]
	v_cvt_f32_f64_e32 v6, v[3:4]
	v_add_nc_u32_e32 v3, s2, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_lshlrev_b64 v[4:5], 2, v[3:4]
	v_lshl_add_u32 v3, s4, 1, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v4, vcc_lo, s0, v4
	v_add_co_ci_u32_e32 v5, vcc_lo, s1, v5, vcc_lo
	global_store_b32 v[1:2], v6, off
	global_load_b32 v0, v[4:5], off
	v_cvt_f64_f32_e32 v[4:5], v6
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[6:7], v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[4:5], 0x3fd00000, v[6:7], v[4:5]
	v_cvt_f32_f64_e32 v0, v[4:5]
	v_ashrrev_i32_e32 v4, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[3:4]
	v_add_co_u32 v3, vcc_lo, s0, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	global_store_b32 v[1:2], v0, off
	global_load_b32 v3, v[3:4], off
	v_cvt_f64_f32_e32 v[5:6], v0
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[3:4], v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[3:4], 0x3fd00000, v[3:4], v[5:6]
	v_cvt_f32_f64_e32 v0, v[3:4]
	global_store_b32 v[1:2], v0, off
.LBB0_2:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z11jacobi_iterPfS_S_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 28
		.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 8
		.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	_Z11jacobi_iterPfS_S_i, .Lfunc_end0-_Z11jacobi_iterPfS_S_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 428
; NumSgprs: 18
; NumVgprs: 8
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 8
; Occupancy: 16
; WaveLimiterHint : 0
; 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	_Z15max_diff_reducePfS_S_ ; -- Begin function _Z15max_diff_reducePfS_S_
	.globl	_Z15max_diff_reducePfS_S_
	.p2align	8
	.type	_Z15max_diff_reducePfS_S_,@function
_Z15max_diff_reducePfS_S_:              ; @_Z15max_diff_reducePfS_S_
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x24
	s_load_b128 s[4:7], s[0:1], 0x0
	s_mov_b32 s2, s15
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s3, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s2, s3, v[0:1]
	v_mov_b32_e32 v2, 0
	s_cmp_lt_u32 s3, 2
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v3, vcc_lo, s4, v1
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v2, vcc_lo
	v_add_co_u32 v1, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	global_load_b32 v3, v[3:4], off
	global_load_b32 v2, v[1:2], off
	v_lshl_add_u32 v1, v0, 2, 0
	s_waitcnt vmcnt(0)
	v_sub_f32_e32 v2, v3, v2
	ds_store_b32 v1, v2
	s_waitcnt lgkmcnt(0)
	s_barrier
.LBB1_1:                                ; =>This Inner Loop Header: Depth=1
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_5
; %bb.2:                                ; %.lr.ph
                                        ;   in Loop: Header=BB1_1 Depth=1
	s_lshr_b32 s4, s3, 1
	s_mov_b32 s5, exec_lo
	v_cmpx_gt_u32_e64 s4, v0
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_1 Depth=1
	v_lshl_add_u32 v2, s4, 2, v1
	ds_load_b32 v2, v2
	ds_load_b32 v3, v1
	s_waitcnt lgkmcnt(0)
	v_dual_max_f32 v2, v2, v2 :: v_dual_max_f32 v3, v3, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_max_f32_e32 v2, v3, v2
	ds_store_b32 v1, v2
.LBB1_4:                                ;   in Loop: Header=BB1_1 Depth=1
	s_or_b32 exec_lo, exec_lo, s5
	s_waitcnt lgkmcnt(0)
	s_barrier
	s_cmp_lt_u32 s3, 4
	s_mov_b32 s3, s4
	s_branch .LBB1_1
.LBB1_5:                                ; %._crit_edge
	s_mov_b32 s3, exec_lo
	v_cmpx_eq_u32_e32 0, v0
	s_cbranch_execz .LBB1_7
; %bb.6:
	v_mov_b32_e32 v0, 0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_mov_b32 s3, 0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b64 s[2:3], s[2:3], 2
	ds_load_b32 v1, v0
	s_waitcnt lgkmcnt(0)
	s_add_u32 s0, s0, s2
	s_addc_u32 s1, s1, s3
	global_store_b32 v0, v1, s[0:1]
.LBB1_7:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15max_diff_reducePfS_S_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.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 5
		.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	_Z15max_diff_reducePfS_S_, .Lfunc_end1-_Z15max_diff_reducePfS_S_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 324
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; 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
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 28
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z11jacobi_iterPfS_S_i
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z11jacobi_iterPfS_S_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     8
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z15max_diff_reducePfS_S_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z15max_diff_reducePfS_S_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
