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

#define  N           4
#define  NUM_BLOCKS  N * N / NUM_THREADS
#define  NUM_THREADS 4
#define  THRESHOLD   0.001
void printMatrix(char *id, double matrix[N * N]) {
    char *s = (char *) malloc(10000 * sizeof(char));
    sprintf(s, "%s\n", id);
    for (int row = 0; row < N; row++) {
        sprintf(s, "%s\t\t\t\t\t", s);
        for (int columns = 0; columns < N; columns++) {
            sprintf(s, "%s%.2f ", s, matrix[row * N + columns]);
        }
        sprintf(s, "%s\n", s);
    }
    printf("%s", s);
    free(s);
}

__global__ void calc(double *a, double *b){
    // printf("Grid Dimension: %d,%d,%d Block Dimension: %d,%d,%d\n", gridDim.x, gridDim.y, gridDim.z, blockDim.x, blockDim.y, blockDim.z);
    int i = blockIdx.x * blockDim.x + blockIdx.y * blockDim.y + threadIdx.x + threadIdx.y;
    // printf("I'm Block:%d,%d,%d Thread:%d,%d,%d I'll operated on %d\n", blockIdx.x, blockIdx.y, blockIdx.z, threadIdx.x, threadIdx.y, threadIdx.z, i);

    if (i % N == 0) {
        b[i] = a[i];
    } else if (i / N == 0 && i % N == N - 1) {
        b[i] = (a[i] + a[i - 1] + a[i + N]) / 3;
    } else if (i / N == 0) {
        b[i] = (a[i] + a[i + 1] + a[i - 1] + a[i + N]) / 4;
    } else if (i / N == N - 1 && i % N == N - 1) {
        b[i] = (a[i] + a[i - 1] + a[i - N]) / 3;
    } else if (i % N == N - 1) {
        b[i] = (a[i] + a[i - 1] + a[i + N] + a[i - N]) / 4;
    } else if (i / N == N - 1) {
        b[i] = (a[i] + a[i + 1] + a[i - 1] + a[i - N]) / 4;
    } else {
        b[i] = (a[i] + a[i + 1] + a[i - 1] + a[i + N] + a[i - N]) / 5;
    }

    __syncthreads();
}

int main() {
    // CUDA configs
    // We will have Grid Dimension: 4,1,1 Block Dimension: 4,1,1
    dim3 dimGrid(NUM_BLOCKS, 1, 1);
    dim3 dimBlock(NUM_THREADS, 1, 1);
    int size = N * N * sizeof(double);
    double *a, *b;

    char *log = (char *) malloc(200 * sizeof(char));
    int temperature;
    printf("Please enter the heat temperature:\n");
    scanf("%d", &temperature);
    printf("Temperature: %d\n", temperature);
    if (temperature < 0 || temperature > 9) {
        printf("Heat temperature should be between 0 and 9.\n");
        exit(-1);
    }

    double A[N * N], B[N * N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            A[i * N + j] = 0;
        }
    }
    printMatrix("Initial Matrix", A);

    for (int i = 0; i < N; i++) {
        A[i * N] = temperature;
    }
    printMatrix("Heat Matrix", A);

    int iteration_count = 0;
    while (iteration_count >= 0) { 
        // Ready for CUDA
	cudaMalloc(&a, size);
        cudaMalloc(&b, size);

	cudaMemcpy(a, A, size, cudaMemcpyHostToDevice);
        calc <<<dimGrid, dimBlock>>> (a, b);
        cudaMemcpy(B, b, size, cudaMemcpyDeviceToHost);

        iteration_count++;

        log = (char *) malloc(200 * sizeof(char));
        sprintf(log, "Iteration: %d\nMatrix", iteration_count);
        printMatrix(log, B);

        double diff_sum = 0;
        int diff_present = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                int idx = i * N + j;
                if (j != 0 && B[idx] > 0 && A[idx] > 0) {
                    diff_sum += (B[idx] - A[idx]);
                    diff_present++;
                }

               A[idx] = B[idx];
            }
        }

        double threshold = ((double) diff_sum / diff_present);
        printf("Total changes in the iteration: %f, Threshold: %f, Changed item count: %d\n", diff_sum, threshold, diff_present);
        if (diff_present > 0 && threshold < THRESHOLD) {
            printf("No change. Enough iterations: %d\n", iteration_count);
            exit(0);
        }
    }

    cudaFree(a);
    cudaFree(b);
    free(log);
    return 0;
}

	.file	"tmpxft_002b2730_00000000-6_small_main.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s\n"
.LC1:
	.string	"%s\t\t\t\t\t"
.LC2:
	.string	"%s%.2f "
.LC3:
	.string	"%s"
	.text
	.globl	_Z11printMatrixPcPd
	.type	_Z11printMatrixPcPd, @function
_Z11printMatrixPcPd:
.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
	leaq	.LC1(%rip), %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	leaq	.LC0(%rip), %r13
	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
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%rdi, 8(%rsp)
	movl	$10000, %edi
	call	malloc@PLT
	movq	8(%rsp), %r8
	movq	%r13, %rcx
	movl	$10000, %edx
	movq	%rax, (%rsp)
	movq	%rax, %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
.L4:
	movq	(%rsp), %r8
	movq	%r14, %rcx
	movl	$10000, %edx
	xorl	%eax, %eax
	movl	$2, %esi
	xorl	%ebx, %ebx
	leaq	.LC2(%rip), %r15
	movq	%r8, %rdi
	call	__sprintf_chk@PLT
.L3:
	movq	(%rsp), %r8
	movsd	0(%rbp,%rbx,8), %xmm0
	movq	%r15, %rcx
	movb	$1, %al
	movl	$10000, %edx
	movl	$2, %esi
	incq	%rbx
	movq	%r8, %rdi
	call	__sprintf_chk@PLT
	cmpq	$4, %rbx
	jne	.L3
	movq	(%rsp), %r8
	movq	%r13, %rcx
	movl	$10000, %edx
	xorl	%eax, %eax
	movl	$2, %esi
	addl	$4, %r12d
	addq	$32, %rbp
	movq	%r8, %rdi
	call	__sprintf_chk@PLT
	cmpl	$16, %r12d
	jne	.L4
	movq	(%rsp), %rdx
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	(%rsp), %rdi
	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
	jmp	free@PLT
	.cfi_endproc
.LFE2027:
	.size	_Z11printMatrixPcPd, .-_Z11printMatrixPcPd
	.globl	_Z25__device_stub__Z4calcPdS_PdS_
	.type	_Z25__device_stub__Z4calcPdS_PdS_, @function
_Z25__device_stub__Z4calcPdS_PdS_:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L9
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z4calcPdS_(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L9:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L11
	call	__stack_chk_fail@PLT
.L11:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z25__device_stub__Z4calcPdS_PdS_, .-_Z25__device_stub__Z4calcPdS_PdS_
	.globl	_Z4calcPdS_
	.type	_Z4calcPdS_, @function
_Z4calcPdS_:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z25__device_stub__Z4calcPdS_PdS_
	.cfi_endproc
.LFE2054:
	.size	_Z4calcPdS_, .-_Z4calcPdS_
	.section	.rodata.str1.1
.LC5:
	.string	"Please enter the heat temperature:\n"
.LC6:
	.string	"%d"
.LC7:
	.string	"Temperature: %d\n"
.LC8:
	.string	"Initial Matrix"
.LC9:
	.string	"Heat Matrix"
.LC10:
	.string	"Heat temperature should be between 0 and 9.\n"
.LC11:
	.string	"Iteration: %d\nMatrix"
.LC12:
	.string	"Total changes in the iteration: %f, Threshold: %f, Changed item count: %d\n"
.LC14:
	.string	"No change. Enough iterations: %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$336, %rsp
	.cfi_def_cfa_offset 384
	movq	%fs:40, %rax
	movq	%rax, 328(%rsp)
	movabsq	$4294967300, %rax
	movl	$1, 56(%rsp)
	movl	$1, 68(%rsp)
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	28(%rsp), %rsi
	leaq	.LC6(%rip), %rdi
	xorl	%eax, %eax
	call	__isoc23_scanf@PLT
	movl	28(%rsp), %edx
	xorl	%eax, %eax
	movl	$2, %edi
	leaq	.LC7(%rip), %rsi
	call	__printf_chk@PLT
	cmpl	$9, 28(%rsp)
	ja	.L15
	leaq	72(%rsp), %rbx
	xorl	%eax, %eax
	movl	$32, %ecx
	xorl	%r12d, %r12d
	movq	%rbx, %rdi
	movq	%rbx, %rsi
	leaq	.LC11(%rip), %r14
	rep stosl
	leaq	.LC8(%rip), %rdi
	call	_Z11printMatrixPcPd
	cvtsi2sdl	28(%rsp), %xmm0
	movq	%rbx, %rsi
	leaq	.LC9(%rip), %rdi
	movsd	%xmm0, 72(%rsp)
	movsd	%xmm0, 104(%rsp)
	movsd	%xmm0, 136(%rsp)
	movsd	%xmm0, 168(%rsp)
	call	_Z11printMatrixPcPd
	jmp	.L16
.L15:
	movl	$2, %edi
	leaq	.LC10(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %edi
	jmp	.L37
.L16:
	leaq	32(%rsp), %rdi
	movl	$128, %esi
	call	cudaMalloc@PLT
	leaq	40(%rsp), %rdi
	movl	$128, %esi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$128, %edx
	call	cudaMemcpy@PLT
	movl	68(%rsp), %ecx
	movl	56(%rsp), %esi
	xorl	%r9d, %r9d
	movq	60(%rsp), %rdx
	movq	48(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	movq	40(%rsp), %rsi
	movq	32(%rsp), %rdi
	call	_Z25__device_stub__Z4calcPdS_PdS_
.L25:
	movq	40(%rsp), %rsi
	leaq	200(%rsp), %r13
	movl	$2, %ecx
	incl	%r12d
	movl	$128, %edx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	movl	$200, %edi
	call	malloc@PLT
	movq	%r14, %rcx
	movl	%r12d, %r8d
	movl	$200, %edx
	movq	%rax, %rbp
	movq	%rax, %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	call	__sprintf_chk@PLT
	movq	%rbp, %rdi
	movq	%r13, %rsi
	xorl	%ebp, %ebp
	call	_Z11printMatrixPcPd
	xorps	%xmm0, %xmm0
	xorl	%ecx, %ecx
	movaps	%xmm0, %xmm2
.L17:
	movq	%rcx, %rax
	xorl	%edx, %edx
.L21:
	movsd	0(%r13,%rax), %xmm1
	testl	%edx, %edx
	jne	.L38
.L18:
	incl	%edx
	movsd	%xmm1, (%rbx,%rax)
	addq	$8, %rax
	cmpl	$4, %edx
	jne	.L21
	addq	$32, %rcx
	cmpq	$128, %rcx
	jne	.L17
	cvtsi2sdl	%ebp, %xmm2
	movaps	%xmm0, %xmm1
	movl	%ebp, %edx
	movl	$2, %edi
	leaq	.LC12(%rip), %rsi
	movb	$2, %al
	divsd	%xmm2, %xmm1
	movsd	%xmm1, 8(%rsp)
	call	__printf_chk@PLT
	testl	%ebp, %ebp
	jle	.L16
	movsd	.LC13(%rip), %xmm0
	movsd	8(%rsp), %xmm1
	comisd	%xmm1, %xmm0
	jbe	.L16
	movl	$2, %edi
	movl	%r12d, %edx
	leaq	.LC14(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	xorl	%edi, %edi
.L37:
	call	exit@PLT
.L38:
	comisd	%xmm2, %xmm1
	jbe	.L18
	movsd	(%rbx,%rax), %xmm3
	comisd	%xmm2, %xmm3
	jbe	.L18
	movaps	%xmm1, %xmm4
	incl	%ebp
	subsd	%xmm3, %xmm4
	addsd	%xmm4, %xmm0
	jmp	.L18
	.cfi_endproc
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC15:
	.string	"_Z4calcPdS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 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	.LC15(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z4calcPdS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	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	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2056:
	.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.cst8,"aM",@progbits,8
	.align 8
.LC13:
	.long	-755914244
	.long	1062232653
	.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 <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define  N           4
#define  NUM_BLOCKS  N * N / NUM_THREADS
#define  NUM_THREADS 4
#define  THRESHOLD   0.001
void printMatrix(char *id, double matrix[N * N]) {
    char *s = (char *) malloc(10000 * sizeof(char));
    sprintf(s, "%s\n", id);
    for (int row = 0; row < N; row++) {
        sprintf(s, "%s\t\t\t\t\t", s);
        for (int columns = 0; columns < N; columns++) {
            sprintf(s, "%s%.2f ", s, matrix[row * N + columns]);
        }
        sprintf(s, "%s\n", s);
    }
    printf("%s", s);
    free(s);
}

__global__ void calc(double *a, double *b){
    // printf("Grid Dimension: %d,%d,%d Block Dimension: %d,%d,%d\n", gridDim.x, gridDim.y, gridDim.z, blockDim.x, blockDim.y, blockDim.z);
    int i = blockIdx.x * blockDim.x + blockIdx.y * blockDim.y + threadIdx.x + threadIdx.y;
    // printf("I'm Block:%d,%d,%d Thread:%d,%d,%d I'll operated on %d\n", blockIdx.x, blockIdx.y, blockIdx.z, threadIdx.x, threadIdx.y, threadIdx.z, i);

    if (i % N == 0) {
        b[i] = a[i];
    } else if (i / N == 0 && i % N == N - 1) {
        b[i] = (a[i] + a[i - 1] + a[i + N]) / 3;
    } else if (i / N == 0) {
        b[i] = (a[i] + a[i + 1] + a[i - 1] + a[i + N]) / 4;
    } else if (i / N == N - 1 && i % N == N - 1) {
        b[i] = (a[i] + a[i - 1] + a[i - N]) / 3;
    } else if (i % N == N - 1) {
        b[i] = (a[i] + a[i - 1] + a[i + N] + a[i - N]) / 4;
    } else if (i / N == N - 1) {
        b[i] = (a[i] + a[i + 1] + a[i - 1] + a[i - N]) / 4;
    } else {
        b[i] = (a[i] + a[i + 1] + a[i - 1] + a[i + N] + a[i - N]) / 5;
    }

    __syncthreads();
}

int main() {
    // CUDA configs
    // We will have Grid Dimension: 4,1,1 Block Dimension: 4,1,1
    dim3 dimGrid(NUM_BLOCKS, 1, 1);
    dim3 dimBlock(NUM_THREADS, 1, 1);
    int size = N * N * sizeof(double);
    double *a, *b;

    char *log = (char *) malloc(200 * sizeof(char));
    int temperature;
    printf("Please enter the heat temperature:\n");
    scanf("%d", &temperature);
    printf("Temperature: %d\n", temperature);
    if (temperature < 0 || temperature > 9) {
        printf("Heat temperature should be between 0 and 9.\n");
        exit(-1);
    }

    double A[N * N], B[N * N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            A[i * N + j] = 0;
        }
    }
    printMatrix("Initial Matrix", A);

    for (int i = 0; i < N; i++) {
        A[i * N] = temperature;
    }
    printMatrix("Heat Matrix", A);

    int iteration_count = 0;
    while (iteration_count >= 0) { 
        // Ready for CUDA
	hipMalloc(&a, size);
        hipMalloc(&b, size);

	hipMemcpy(a, A, size, hipMemcpyHostToDevice);
        calc <<<dimGrid, dimBlock>>> (a, b);
        hipMemcpy(B, b, size, hipMemcpyDeviceToHost);

        iteration_count++;

        log = (char *) malloc(200 * sizeof(char));
        sprintf(log, "Iteration: %d\nMatrix", iteration_count);
        printMatrix(log, B);

        double diff_sum = 0;
        int diff_present = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                int idx = i * N + j;
                if (j != 0 && B[idx] > 0 && A[idx] > 0) {
                    diff_sum += (B[idx] - A[idx]);
                    diff_present++;
                }

               A[idx] = B[idx];
            }
        }

        double threshold = ((double) diff_sum / diff_present);
        printf("Total changes in the iteration: %f, Threshold: %f, Changed item count: %d\n", diff_sum, threshold, diff_present);
        if (diff_present > 0 && threshold < THRESHOLD) {
            printf("No change. Enough iterations: %d\n", iteration_count);
            exit(0);
        }
    }

    hipFree(a);
    hipFree(b);
    free(log);
    return 0;
}

	.text
	.file	"small_main.hip"
	.globl	_Z11printMatrixPcPd             # -- Begin function _Z11printMatrixPcPd
	.type	_Z11printMatrixPcPd,@function
_Z11printMatrixPcPd:                    # @_Z11printMatrixPcPd
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %r14
	movq	%rdi, %r15
	movl	$10000, %edi                    # imm = 0x2710
	callq	malloc
	movq	%rax, %rbx
	movl	$.L.str, %esi
	movq	%rax, %rdi
	movq	%r15, %rdx
	xorl	%eax, %eax
	callq	sprintf
	xorl	%r15d, %r15d
.LBB0_1:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_2 Depth 2
	movl	$.L.str.1, %esi
	movq	%rbx, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	sprintf
	xorl	%r12d, %r12d
.LBB0_2:                                #   Parent Loop BB0_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movsd	(%r14,%r12,8), %xmm0            # xmm0 = mem[0],zero
	movl	$.L.str.2, %esi
	movq	%rbx, %rdi
	movq	%rbx, %rdx
	movb	$1, %al
	callq	sprintf
	incq	%r12
	cmpq	$4, %r12
	jne	.LBB0_2
# %bb.3:                                #   in Loop: Header=BB0_1 Depth=1
	movl	$.L.str, %esi
	movq	%rbx, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	sprintf
	incq	%r15
	addq	$32, %r14
	cmpq	$4, %r15
	jne	.LBB0_1
# %bb.4:
	movl	$.L.str.3, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.Lfunc_end0:
	.size	_Z11printMatrixPcPd, .Lfunc_end0-_Z11printMatrixPcPd
	.cfi_endproc
                                        # -- End function
	.globl	_Z19__device_stub__calcPdS_     # -- Begin function _Z19__device_stub__calcPdS_
	.type	_Z19__device_stub__calcPdS_,@function
_Z19__device_stub__calcPdS_:            # @_Z19__device_stub__calcPdS_
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z4calcPdS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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_end1:
	.size	_Z19__device_stub__calcPdS_, .Lfunc_end1-_Z19__device_stub__calcPdS_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI2_0:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
	.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	$296, %rsp                      # imm = 0x128
	.cfi_def_cfa_offset 352
	.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	$.Lstr, %edi
	callq	puts@PLT
	leaq	4(%rsp), %rbx
	movl	$.L.str.5, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	__isoc23_scanf
	movl	(%rbx), %esi
	movl	$.L.str.6, %edi
	xorl	%eax, %eax
	callq	printf
	cmpl	$10, (%rbx)
	jb	.LBB2_1
# %bb.17:
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$-1, %edi
	callq	exit
.LBB2_1:
	xorps	%xmm0, %xmm0
	leaq	32(%rsp), %rbx
	movaps	%xmm0, (%rbx)
	movaps	%xmm0, 16(%rbx)
	movaps	%xmm0, 32(%rbx)
	movaps	%xmm0, 48(%rbx)
	movaps	%xmm0, 64(%rbx)
	movaps	%xmm0, 80(%rbx)
	movaps	%xmm0, 96(%rbx)
	movaps	%xmm0, 112(%rbx)
	movl	$.L.str.8, %edi
	movq	%rbx, %rsi
	callq	_Z11printMatrixPcPd
	xorl	%eax, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sdl	4(%rsp), %xmm0
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movsd	%xmm0, 32(%rsp,%rax)
	addq	$32, %rax
	cmpq	$128, %rax
	jne	.LBB2_2
# %bb.3:
	movabsq	$4294967300, %r14               # imm = 0x100000004
	movl	$.L.str.9, %edi
	movq	%rbx, %rsi
	callq	_Z11printMatrixPcPd
	xorl	%r15d, %r15d
	leaq	160(%rsp), %rbp
.LBB2_4:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_7 Depth 2
                                        #       Child Loop BB2_8 Depth 3
	movl	$128, %esi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	movl	$128, %esi
	leaq	8(%rsp), %rdi
	callq	hipMalloc
	movq	16(%rsp), %rdi
	movl	$128, %edx
	movq	%rbx, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB2_6
# %bb.5:                                #   in Loop: Header=BB2_4 Depth=1
	movq	16(%rsp), %rdi
	movq	8(%rsp), %rsi
	callq	_Z19__device_stub__calcPdS_
.LBB2_6:                                #   in Loop: Header=BB2_4 Depth=1
	movq	8(%rsp), %rsi
	movl	$128, %edx
	movq	%rbp, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	incl	%r15d
	movl	$200, %edi
	callq	malloc
	movq	%rax, %r12
	xorl	%r13d, %r13d
	movl	$.L.str.10, %esi
	movq	%rax, %rdi
	movl	%r15d, %edx
	xorl	%eax, %eax
	callq	sprintf
	movq	%r12, %rdi
	movq	%rbp, %rsi
	callq	_Z11printMatrixPcPd
	xorpd	%xmm0, %xmm0
	movq	%rbx, %rax
	movq	%rbp, %rcx
	xorl	%r12d, %r12d
	xorpd	%xmm4, %xmm4
.LBB2_7:                                # %.preheader
                                        #   Parent Loop BB2_4 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB2_8 Depth 3
	xorl	%edx, %edx
.LBB2_8:                                #   Parent Loop BB2_4 Depth=1
                                        #     Parent Loop BB2_7 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movsd	(%rcx,%rdx,8), %xmm1            # xmm1 = mem[0],zero
	testq	%rdx, %rdx
	je	.LBB2_12
# %bb.9:                                #   in Loop: Header=BB2_8 Depth=3
	ucomisd	%xmm4, %xmm1
	jbe	.LBB2_12
# %bb.10:                               #   in Loop: Header=BB2_8 Depth=3
	movsd	(%rax,%rdx,8), %xmm2            # xmm2 = mem[0],zero
	ucomisd	%xmm4, %xmm2
	jbe	.LBB2_12
# %bb.11:                               #   in Loop: Header=BB2_8 Depth=3
	movapd	%xmm1, %xmm3
	subsd	%xmm2, %xmm3
	addsd	%xmm3, %xmm0
	incl	%r12d
.LBB2_12:                               # %._crit_edge
                                        #   in Loop: Header=BB2_8 Depth=3
	movsd	%xmm1, (%rax,%rdx,8)
	incq	%rdx
	cmpq	$4, %rdx
	jne	.LBB2_8
# %bb.13:                               #   in Loop: Header=BB2_7 Depth=2
	incq	%r13
	addq	$32, %rcx
	addq	$32, %rax
	cmpq	$4, %r13
	jne	.LBB2_7
# %bb.14:                               #   in Loop: Header=BB2_4 Depth=1
	xorps	%xmm2, %xmm2
	cvtsi2sd	%r12d, %xmm2
	movapd	%xmm0, %xmm1
	divsd	%xmm2, %xmm1
	movl	$.L.str.11, %edi
	movsd	%xmm1, 24(%rsp)                 # 8-byte Spill
	movl	%r12d, %esi
	movb	$2, %al
	callq	printf
	testl	%r12d, %r12d
	jle	.LBB2_4
# %bb.15:                               #   in Loop: Header=BB2_4 Depth=1
	movsd	.LCPI2_0(%rip), %xmm0           # xmm0 = mem[0],zero
	ucomisd	24(%rsp), %xmm0                 # 8-byte Folded Reload
	jbe	.LBB2_4
# %bb.16:
	movl	$.L.str.12, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	xorl	%edi, %edi
	callq	exit
.Lfunc_end2:
	.size	main, .Lfunc_end2-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:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4calcPdS_, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%s\n"
	.size	.L.str, 4

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"%s\t\t\t\t\t"
	.size	.L.str.1, 8

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"%s%.2f "
	.size	.L.str.2, 8

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

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

	.type	.L.str.5,@object                # @.str.5
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.5:
	.asciz	"%d"
	.size	.L.str.5, 3

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

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Initial Matrix"
	.size	.L.str.8, 15

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"Heat Matrix"
	.size	.L.str.9, 12

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Iteration: %d\nMatrix"
	.size	.L.str.10, 21

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Total changes in the iteration: %f, Threshold: %f, Changed item count: %d\n"
	.size	.L.str.11, 75

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"No change. Enough iterations: %d\n"
	.size	.L.str.12, 34

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4calcPdS_"
	.size	.L__unnamed_1, 12

	.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	"Please enter the heat temperature:"
	.size	.Lstr, 35

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"Heat temperature should be between 0 and 9."
	.size	.Lstr.1, 44

	.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 _Z19__device_stub__calcPdS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z4calcPdS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4calcPdS_             ; -- Begin function _Z4calcPdS_
	.globl	_Z4calcPdS_
	.p2align	8
	.type	_Z4calcPdS_,@function
_Z4calcPdS_:                            ; @_Z4calcPdS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x1c
	s_load_b128 s[4:7], s[0:1], 0x0
	v_and_b32_e32 v1, 0x3ff, v0
	v_bfe_u32 v0, v0, 10, 10
	s_mov_b32 s0, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v0, v0, v1
	s_waitcnt lgkmcnt(0)
	s_and_b32 s3, s2, 0xffff
	s_lshr_b32 s2, s2, 16
	s_mul_i32 s14, s14, s3
	s_mul_i32 s15, s15, s2
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add3_u32 v0, s15, s14, v0
	v_ashrrev_i32_e32 v1, 31, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshrrev_b32_e32 v2, 30, v1
	v_add_nc_u32_e32 v2, v0, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v2, -4, v2
	v_sub_nc_u32_e32 v4, v0, v2
                                        ; implicit-def: $vgpr2_vgpr3
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_ne_u32_e32 0, v4
	s_xor_b32 s2, exec_lo, s0
	s_cbranch_execz .LBB0_22
; %bb.1:
	v_add_nc_u32_e32 v2, 3, v0
	v_cmp_ne_u32_e32 vcc_lo, 3, v4
	v_cmp_eq_u32_e64 s1, 3, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_lt_u32_e64 s0, 6, v2
                                        ; implicit-def: $vgpr2_vgpr3
	s_or_b32 s3, s0, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s8, s3
	s_xor_b32 s3, exec_lo, s8
	s_cbranch_execz .LBB0_19
; %bb.2:
                                        ; implicit-def: $vgpr2_vgpr3
	s_and_saveexec_b32 s8, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s8, exec_lo, s8
	s_cbranch_execz .LBB0_16
; %bb.3:
	v_and_b32_e32 v2, -4, v0
	s_xor_b32 s1, s1, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cmp_ne_u32_e64 s0, 12, v2
                                        ; implicit-def: $vgpr2_vgpr3
	s_or_b32 s1, s0, s1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s9, s1
	s_xor_b32 s1, exec_lo, s9
	s_cbranch_execz .LBB0_13
; %bb.4:
                                        ; implicit-def: $vgpr2_vgpr3
	s_and_saveexec_b32 s9, vcc_lo
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s9, exec_lo, s9
	s_cbranch_execz .LBB0_10
; %bb.5:
                                        ; implicit-def: $vgpr2_vgpr3
	s_and_saveexec_b32 s10, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s0, exec_lo, s10
	s_cbranch_execz .LBB0_7
; %bb.6:
	v_lshlrev_b64 v[2:3], 3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v3, vcc_lo
	s_clause 0x3
	global_load_b128 v[2:5], v[6:7], off offset:-8
	global_load_b64 v[8:9], v[6:7], off offset:8
	global_load_b64 v[10:11], v[6:7], off offset:32
	global_load_b64 v[6:7], v[6:7], off offset:-32
	s_waitcnt vmcnt(2)
	v_add_f64 v[4:5], v[4:5], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f64 v[2:3], v[4:5], v[2:3]
	s_waitcnt vmcnt(1)
	v_add_f64 v[2:3], v[2:3], v[10:11]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[2:3], v[2:3], v[6:7]
	v_div_scale_f64 v[4:5], null, 0x40140000, 0x40140000, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[6:7], v[4:5]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	v_div_scale_f64 v[8:9], vcc_lo, v[2:3], 0x40140000, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[8:9], v[6:7]
	v_fma_f64 v[4:5], -v[4:5], v[10:11], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[4:5], v[4:5], v[6:7], v[10:11]
	v_div_fixup_f64 v[2:3], v[4:5], 0x40140000, v[2:3]
.LBB0_7:                                ; %Flow
	s_and_not1_saveexec_b32 s0, s0
	s_cbranch_execz .LBB0_9
; %bb.8:
	v_mov_b32_e32 v1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[0:1]
	v_add_co_u32 v6, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v3, vcc_lo
	s_clause 0x2
	global_load_b64 v[8:9], v[6:7], off offset:8
	global_load_b128 v[2:5], v[6:7], off offset:-8
	global_load_b64 v[6:7], v[6:7], off offset:-32
	s_waitcnt vmcnt(1)
	v_add_f64 v[4:5], v[4:5], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f64 v[2:3], v[4:5], v[2:3]
	s_waitcnt vmcnt(0)
	v_add_f64 v[2:3], v[2:3], v[6:7]
	s_delay_alu instid0(VALU_DEP_1)
	v_ldexp_f64 v[2:3], v[2:3], -2
.LBB0_9:                                ; %Flow84
	s_or_b32 exec_lo, exec_lo, s0
.LBB0_10:                               ; %Flow86
	s_and_not1_saveexec_b32 s0, s9
	s_cbranch_execz .LBB0_12
; %bb.11:
	v_lshlrev_b64 v[2:3], 3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v3, vcc_lo
	s_clause 0x2
	global_load_b128 v[2:5], v[6:7], off offset:-8
	global_load_b64 v[8:9], v[6:7], off offset:32
	global_load_b64 v[6:7], v[6:7], off offset:-32
	s_waitcnt vmcnt(2)
	v_add_f64 v[2:3], v[4:5], v[2:3]
	s_waitcnt vmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f64 v[2:3], v[2:3], v[8:9]
	s_waitcnt vmcnt(0)
	v_add_f64 v[2:3], v[2:3], v[6:7]
	s_delay_alu instid0(VALU_DEP_1)
	v_ldexp_f64 v[2:3], v[2:3], -2
.LBB0_12:                               ; %Flow87
	s_or_b32 exec_lo, exec_lo, s0
.LBB0_13:                               ; %Flow88
	s_and_not1_saveexec_b32 s0, s1
	s_cbranch_execz .LBB0_15
; %bb.14:
	v_mov_b32_e32 v1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 3, v[0:1]
	v_add_co_u32 v6, vcc_lo, s4, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v3, vcc_lo
	s_clause 0x1
	global_load_b128 v[2:5], v[6:7], off offset:-8
	global_load_b64 v[6:7], v[6:7], off offset:-32
	s_waitcnt vmcnt(1)
	v_add_f64 v[2:3], v[4:5], v[2:3]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[2:3], v[2:3], v[6:7]
	v_div_scale_f64 v[4:5], null, 0x40080000, 0x40080000, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[6:7], v[4:5]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	v_div_scale_f64 v[8:9], vcc_lo, v[2:3], 0x40080000, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[8:9], v[6:7]
	v_fma_f64 v[4:5], -v[4:5], v[10:11], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[4:5], v[4:5], v[6:7], v[10:11]
	v_div_fixup_f64 v[2:3], v[4:5], 0x40080000, v[2:3]
.LBB0_15:                               ; %Flow89
	s_or_b32 exec_lo, exec_lo, s0
.LBB0_16:                               ; %Flow91
	s_and_not1_saveexec_b32 s0, s8
	s_cbranch_execz .LBB0_18
; %bb.17:
	v_lshlrev_b64 v[2:3], 3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v3, vcc_lo
	s_clause 0x2
	global_load_b64 v[8:9], v[6:7], off offset:8
	global_load_b128 v[2:5], v[6:7], off offset:-8
	global_load_b64 v[6:7], v[6:7], off offset:32
	s_waitcnt vmcnt(1)
	v_add_f64 v[4:5], v[4:5], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add_f64 v[2:3], v[4:5], v[2:3]
	s_waitcnt vmcnt(0)
	v_add_f64 v[2:3], v[2:3], v[6:7]
	s_delay_alu instid0(VALU_DEP_1)
	v_ldexp_f64 v[2:3], v[2:3], -2
.LBB0_18:                               ; %Flow92
	s_or_b32 exec_lo, exec_lo, s0
.LBB0_19:                               ; %Flow93
	s_and_not1_saveexec_b32 s0, s3
	s_cbranch_execz .LBB0_21
; %bb.20:
	v_lshlrev_b64 v[2:3], 3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v6, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v3, vcc_lo
	s_clause 0x1
	global_load_b128 v[2:5], v[6:7], off offset:-8
	global_load_b64 v[6:7], v[6:7], off offset:32
	s_waitcnt vmcnt(1)
	v_add_f64 v[2:3], v[4:5], v[2:3]
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[2:3], v[2:3], v[6:7]
	v_div_scale_f64 v[4:5], null, 0x40080000, 0x40080000, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_f64_e32 v[6:7], v[4:5]
	s_waitcnt_depctr 0xfff
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[8:9], -v[4:5], v[6:7], 1.0
	v_fma_f64 v[6:7], v[6:7], v[8:9], v[6:7]
	v_div_scale_f64 v[8:9], vcc_lo, v[2:3], 0x40080000, v[2:3]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[10:11], v[8:9], v[6:7]
	v_fma_f64 v[4:5], -v[4:5], v[10:11], v[8:9]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_fmas_f64 v[4:5], v[4:5], v[6:7], v[10:11]
	v_div_fixup_f64 v[2:3], v[4:5], 0x40080000, v[2:3]
.LBB0_21:                               ; %Flow94
	s_or_b32 exec_lo, exec_lo, s0
.LBB0_22:                               ; %Flow96
	s_and_not1_saveexec_b32 s0, s2
	s_cbranch_execz .LBB0_24
; %bb.23:
	v_lshlrev_b64 v[2:3], 3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_b64 v[2:3], v[2:3], off
.LBB0_24:
	s_or_b32 exec_lo, exec_lo, s0
	v_lshlrev_b64 v[0:1], 3, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s6, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b64 v[0:1], v[2:3], off
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4calcPdS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 14
		.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 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 12
		.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	_Z4calcPdS_, .Lfunc_end0-_Z4calcPdS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1348
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 1
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.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
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4calcPdS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z4calcPdS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
