/* A program to solve the hotplate problem  using GPU

  Author: Bukola Grace Omotoso
  MNumber: M01424979
  ID: bgo2e
  Last Modified: 11/27/2018
  
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include<cuda_runtime.h>
#include<device_launch_parameters.h>
#include<cuda.h>



#define CHECK(call) \
{ \
 const cudaError_t error = call; \
 if (error != cudaSuccess) \
 { \
 printf("Error: %s:%d, ", __FILE__, __LINE__); \
 printf("code:%d, reason: %s\n", error, cudaGetErrorString(error)); \
 exit(1); \
 } \
}


float** buildHotplate(int rows, int columns) {
float** hotplate;
hotplate = (float**) malloc(rows*sizeof(float*));
for (int i = 0; i < rows; i++)
   hotplate[i] = (float*) malloc(columns*sizeof(float));
   return hotplate;
}

float* flattenArray(float** arrayToFlatten, int num_rows, int num_cols){
	float* flattenedArray = (float*) malloc(num_rows*num_cols*sizeof(float));
	int counter = 0;
	
	for (int row = 0; row < num_rows; row++){
		
	{
		for(int col = 0; col < num_cols; col++){
			flattenedArray[counter] = arrayToFlatten[row][col];
			counter++;
		}
	}
	
}
		return flattenedArray;
}

 void initializeHotPlate(int num_rows, int num_cols, float** hotplate, float** hotplateClone, int top_temp, int left_temp, int right_temp, int bottom_temp)	{
 	int num_outer_grid = (2 * num_rows) + (2 * (num_cols - 2));
	float outer_grid_sum = (top_temp * (num_cols - 2)) + (left_temp * (num_rows - 1)) + (bottom_temp * num_cols) + (right_temp * (num_rows - 1));
    float initial_inner_val = outer_grid_sum / num_outer_grid;

    for (int row = 0; row < num_rows; row++) {
            for (int column = 0; column < num_cols; column++) {

                //top values override the top row except the edges
                 if ((row == 0) & (column != 0 & column != num_cols - 1)) {
                	hotplate[row][column] = top_temp;
                    hotplateClone[row][column] = top_temp;
                } 
                else if (column == 0 && (row != (num_rows-1))) {
                    hotplate[row][column] = left_temp;
                    hotplateClone[row][column] = left_temp;
                }
                else if (column == (num_cols - 1) && (row != (num_rows-1))) {
                    hotplate[row][column] = right_temp;
                    hotplateClone[row][column] = right_temp;
                }
                else if(row == (num_rows -1 )){
                    hotplate[row][column] = bottom_temp;
                    hotplateClone[row][column] = bottom_temp;
                }
                if ((row != 0) && (row != num_rows - 1) && (column != 0) && (column != num_cols - 1))
                    hotplate[row][column] = initial_inner_val;
            }
        }

 }

 void swapHotplate(float *a, float *b) {

    float *tmp = a;
    a = b;
    b = tmp;
}


__global__ 
void generateHeat(int num_rows, int num_cols, float* hotplate, float* hotplateClone, float* d_maximums, float epsilon) {
        float max_difference = 0;
        float previous_val;
        float current_val;
        float diff;
        
         int row = blockIdx.x * blockDim.x + threadIdx.x;
         
            if (row > 0 && row < (num_rows-1)){
                for (int col = 1; col < (num_cols - 1); col++) {
					
				int idx = (row * num_cols) + col;
				float top = hotplate[idx - num_cols];				
				float bottom = hotplate[idx + num_cols];
				float left =  hotplate[idx - 1];
				float right =  hotplate[idx + 1];

                    previous_val = hotplate[idx];
                    current_val = (top + bottom + left + right) / 4.0;
                    diff = fabsf(previous_val - current_val);
                    if (diff > max_difference){
                        max_difference = diff;
                    }
                    hotplateClone[idx] = current_val;
                }
                
                d_maximums[row] = max_difference;
			}
}


/*Get the maximum values from all threads*/
float max_max_diff(float arr[], int n)
{
    int i;
        float max = arr[0];
    for (i = 1; i < n; i++)
        if (arr[i] > max)
            max = arr[i];
    return max;
}



int main(int argc, char const *argv[])
{		int num_rows = atoi(argv[1]);
		int num_cols = atoi(argv[2]);
		int top_temp = atoi(argv[3]);
		int left_temp = atoi(argv[4]);
		int right_temp = atoi(argv[5]);
		int bottom_temp = atoi(argv[6]);
		float epsilon = atof(argv[7]);
		
		float* flattenedhotplate;
		float* flattenedhotplateClone;
		float* maximums;

		
		int gridsize = 8;
		int block = 0;
		int block1 = (num_rows/gridsize);
		if (gridsize > num_rows)
			block = 1;
		else if ((block1 * gridsize) < num_rows){
			block = block1 + 1;
		}else{
			block = block1;
		}
		size_t nBytes = num_rows*num_cols * sizeof(float);
		double max_difference = epsilon + 1;
		int counter = 0;

        float** hotplate =  buildHotplate(num_rows, num_cols);
        float** hotplateClone = buildHotplate(num_rows, num_cols);
        
        
         
        initializeHotPlate(num_rows, num_cols, hotplate, hotplateClone, top_temp, left_temp, right_temp, bottom_temp);    
         
         flattenedhotplate = (float*) malloc(num_cols*num_rows*sizeof(float));
         flattenedhotplateClone = (float*) malloc(num_cols*num_rows*sizeof(float));
         maximums = (float*)malloc(num_rows*sizeof(float));
         
     
         flattenedhotplate = flattenArray(hotplate, num_rows, num_cols);
         flattenedhotplateClone = flattenArray(hotplateClone, num_rows, num_cols);

         
         float *d_hotplate; 
         float *d_hotplateClone;
         float *d_maximums;
	

		CHECK(cudaMalloc((float**)&d_hotplate, nBytes));
		CHECK(cudaMalloc((float**)&d_hotplateClone, nBytes));
		CHECK(cudaMalloc((float**)&d_maximums, num_rows*sizeof(float)));
		
		
		CHECK(cudaMemcpy( d_hotplate, flattenedhotplate, nBytes, cudaMemcpyHostToDevice));
		CHECK(cudaMemcpy(d_hotplateClone, flattenedhotplateClone, nBytes, cudaMemcpyHostToDevice));
		
		printf("%10s%10s\n", "Iteration", "Epsilon");

		 while(max_difference > epsilon){
        
		generateHeat<<<block,gridsize>>>(num_rows, num_cols, d_hotplate, d_hotplateClone, d_maximums, epsilon);
	
		cudaDeviceSynchronize();
		CHECK(cudaMemcpy(maximums, d_maximums, num_rows*sizeof(float), cudaMemcpyDeviceToHost));
		max_difference = max_max_diff(maximums, num_rows-1);
        
            float *T = d_hotplate;
            d_hotplate = d_hotplateClone;
            d_hotplateClone  =  T;
            
            if (counter > 0 && (counter & (counter - 1)) == 0)
                printf("%6d%15.6f\n", counter, max_difference);
            if (max_difference < epsilon) {
                printf("%6d%15.6f\n", counter, max_difference);
                break;
            }
            counter++;
	}
	
	cudaFree(d_hotplate);
	cudaFree(d_hotplateClone);
	cudaFree(d_maximums);
	
		return 0;

}


	.file	"tmpxft_002c5eb4_00000000-6_hotplate.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2048:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2048:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z13buildHotplateii
	.type	_Z13buildHotplateii, @function
_Z13buildHotplateii:
.LFB2040:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movslq	%edi, %rdi
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	salq	$3, %rdi
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movslq	%esi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
	salq	$2, %rbx
	call	malloc@PLT
	movq	%rax, %rbp
.L3:
	cmpl	%r13d, %r12d
	jle	.L7
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rax, 0(%rbp,%r13,8)
	incq	%r13
	jmp	.L3
.L7:
	popq	%rdx
	.cfi_def_cfa_offset 40
	movq	%rbp, %rax
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2040:
	.size	_Z13buildHotplateii, .-_Z13buildHotplateii
	.globl	_Z12flattenArrayPPfii
	.type	_Z12flattenArrayPPfii, @function
_Z12flattenArrayPPfii:
.LFB2041:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	movl	%esi, %edi
	imull	%edx, %edi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	%esi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%edx, %ebx
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	xorl	%edi, %edi
	xorl	%ecx, %ecx
	xorl	%esi, %esi
	testl	%ebx, %ebx
	cmovns	%ebx, %edi
.L9:
	cmpl	%ecx, %ebp
	jle	.L8
	movslq	%esi, %rdx
	leaq	(%rax,%rdx,4), %r8
	xorl	%edx, %edx
.L12:
	cmpl	%edx, %ebx
	jle	.L14
	movq	(%r12,%rcx,8), %r9
	movss	(%r9,%rdx,4), %xmm0
	movss	%xmm0, (%r8,%rdx,4)
	incq	%rdx
	jmp	.L12
.L14:
	addl	%edi, %esi
	incq	%rcx
	jmp	.L9
.L8:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2041:
	.size	_Z12flattenArrayPPfii, .-_Z12flattenArrayPPfii
	.globl	_Z18initializeHotPlateiiPPfS0_iiii
	.type	_Z18initializeHotPlateiiPPfS0_iiii, @function
_Z18initializeHotPlateiiPPfS0_iiii:
.LFB2042:
	.cfi_startproc
	endbr64
	movl	%edi, %r11d
	movl	%esi, %edi
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdx, %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leal	-2(%rdi), %edx
	movq	%rcx, %r10
	leal	-1(%rdi), %r15d
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%edx, %eax
	addl	%r11d, %edx
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	imull	%r8d, %eax
	addl	%edx, %edx
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	cvtsi2ssl	%edx, %xmm0
	leal	-1(%r11), %ebp
	movl	%ebp, %ecx
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	imull	%r9d, %ecx
	addl	%ecx, %eax
	movl	64(%rsp), %ecx
	imull	%edi, %ecx
	addl	%ecx, %eax
	movl	56(%rsp), %ecx
	imull	%ebp, %ecx
	addl	%ecx, %eax
	cvtsi2ssl	%eax, %xmm1
	xorl	%eax, %eax
	divss	%xmm0, %xmm1
.L16:
	movl	%eax, %ebx
	cmpl	%r11d, %eax
	jge	.L46
	xorl	%edx, %edx
	xorl	%ecx, %ecx
.L25:
	cmpl	%edi, %ecx
	jge	.L47
	testl	%ecx, %ecx
	setne	-9(%rsp)
	cmpl	%ecx, %r15d
	setne	%r12b
	testl	%ebx, %ebx
	jne	.L17
	testb	%r12b, -9(%rsp)
	je	.L17
	cvtsi2ssl	%r8d, %xmm0
	movq	(%rsi), %r12
	movss	%xmm0, (%r12,%rdx)
	movq	(%r10), %r12
	movss	%xmm0, (%r12,%rdx)
	jmp	.L18
.L17:
	cmpl	%ebx, %ebp
	setne	%r13b
	testl	%ecx, %ecx
	jne	.L19
	testb	%r13b, %r13b
	je	.L19
	cvtsi2ssl	%r9d, %xmm0
	movq	(%rsi,%rax,8), %r12
	movss	%xmm0, (%r12)
	movq	(%r10,%rax,8), %r12
	movss	%xmm0, (%r12)
	jmp	.L18
.L19:
	cmpl	%ecx, %r15d
	jne	.L21
	movq	(%rsi,%rax,8), %r14
	addq	%rdx, %r14
	movq	%r14, -8(%rsp)
	movq	(%r10,%rax,8), %r14
	addq	%rdx, %r14
	cmpl	%ebx, %ebp
	je	.L22
	cvtsi2ssl	56(%rsp), %xmm0
	movq	-8(%rsp), %r13
	movss	%xmm0, 0(%r13)
	movss	%xmm0, (%r14)
	jmp	.L18
.L21:
	cmpl	%ebx, %ebp
	jne	.L23
.L22:
	cvtsi2ssl	64(%rsp), %xmm0
	movq	(%rsi,%rax,8), %r14
	movss	%xmm0, (%r14,%rdx)
	movq	(%r10,%rax,8), %r14
	movss	%xmm0, (%r14,%rdx)
.L23:
	testl	%ebx, %ebx
	setne	%r14b
	andl	%r13d, %r14d
	testb	%r14b, -9(%rsp)
	je	.L18
	testb	%r12b, %r12b
	je	.L18
	movq	(%rsi,%rax,8), %r12
	movss	%xmm1, (%r12,%rdx)
.L18:
	incl	%ecx
	addq	$4, %rdx
	jmp	.L25
.L47:
	incq	%rax
	jmp	.L16
.L46:
	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
.LFE2042:
	.size	_Z18initializeHotPlateiiPPfS0_iiii, .-_Z18initializeHotPlateiiPPfS0_iiii
	.globl	_Z12swapHotplatePfS_
	.type	_Z12swapHotplatePfS_, @function
_Z12swapHotplatePfS_:
.LFB2043:
	.cfi_startproc
	endbr64
	ret
	.cfi_endproc
.LFE2043:
	.size	_Z12swapHotplatePfS_, .-_Z12swapHotplatePfS_
	.globl	_Z12max_max_diffPfi
	.type	_Z12max_max_diffPfi, @function
_Z12max_max_diffPfi:
.LFB2044:
	.cfi_startproc
	endbr64
	movss	(%rdi), %xmm0
	movl	$1, %eax
.L50:
	cmpl	%eax, %esi
	jle	.L53
	movss	(%rdi,%rax,4), %xmm1
	incq	%rax
	maxss	%xmm0, %xmm1
	movaps	%xmm1, %xmm0
	jmp	.L50
.L53:
	ret
	.cfi_endproc
.LFE2044:
	.size	_Z12max_max_diffPfi, .-_Z12max_max_diffPfi
	.globl	_Z39__device_stub__Z12generateHeatiiPfS_S_fiiPfS_S_f
	.type	_Z39__device_stub__Z12generateHeatiiPfS_S_fiiPfS_S_f, @function
_Z39__device_stub__Z12generateHeatiiPfS_S_fiiPfS_S_f:
.LFB2070:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movl	%edi, 44(%rsp)
	leaq	72(%rsp), %rdi
	movl	%esi, 40(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rdx, 32(%rsp)
	leaq	56(%rsp), %rdx
	movq	%rcx, 24(%rsp)
	leaq	64(%rsp), %rcx
	movq	%r8, 16(%rsp)
	movss	%xmm0, 12(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L54
	pushq	64(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z12generateHeatiiPfS_S_f(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 208
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L54:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2070:
	.size	_Z39__device_stub__Z12generateHeatiiPfS_S_fiiPfS_S_f, .-_Z39__device_stub__Z12generateHeatiiPfS_S_fiiPfS_S_f
	.globl	_Z12generateHeatiiPfS_S_f
	.type	_Z12generateHeatiiPfS_S_f, @function
_Z12generateHeatiiPfS_S_f:
.LFB2071:
	.cfi_startproc
	endbr64
	jmp	_Z39__device_stub__Z12generateHeatiiPfS_S_fiiPfS_S_f
	.cfi_endproc
.LFE2071:
	.size	_Z12generateHeatiiPfS_S_f, .-_Z12generateHeatiiPfS_S_f
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/grace-omotoso/CUDA_Hotplate/master/hotplate.cu"
.LC2:
	.string	"Error: %s:%d, "
.LC3:
	.string	"code:%d, reason: %s\n"
.LC4:
	.string	"Epsilon"
.LC5:
	.string	"Iteration"
.LC6:
	.string	"%10s%10s\n"
.LC7:
	.string	"%6d%15.6f\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2045:
	.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
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movq	16(%r12), %rdi
	movl	%eax, %ebx
	call	atoi@PLT
	movq	24(%r12), %rdi
	movl	%eax, %ebp
	call	atoi@PLT
	movq	32(%r12), %rdi
	movl	%eax, 32(%rsp)
	call	atoi@PLT
	movq	40(%r12), %rdi
	movl	%eax, %r15d
	call	atoi@PLT
	movq	48(%r12), %rdi
	movl	%eax, %r13d
	call	atoi@PLT
	movq	56(%r12), %rdi
	movl	$1, %r12d
	movl	%eax, %r14d
	call	atof@PLT
	cvtsd2ss	%xmm0, %xmm2
	movss	%xmm2, 20(%rsp)
	cmpl	$7, %ebx
	jle	.L60
	movl	%ebx, %eax
	movl	%ebx, %r12d
	andl	$-8, %eax
	sarl	$3, %r12d
	cmpl	%ebx, %eax
	jge	.L60
	incl	%r12d
.L60:
	movl	%ebx, %eax
	movss	20(%rsp), %xmm0
	movl	%ebp, %esi
	movl	%ebx, %edi
	imull	%ebp, %eax
	addss	.LC0(%rip), %xmm0
	cltq
	cvtss2sd	%xmm0, %xmm3
	movsd	%xmm3, 8(%rsp)
	salq	$2, %rax
	movq	%rax, 24(%rsp)
	call	_Z13buildHotplateii
	movl	%ebp, %esi
	movl	%ebx, %edi
	movq	%rax, 40(%rsp)
	call	_Z13buildHotplateii
	movl	%r15d, %r9d
	movl	%ebp, %esi
	movl	%ebx, %edi
	movq	%rax, 48(%rsp)
	pushq	%r14
	.cfi_def_cfa_offset 200
	pushq	%r13
	.cfi_def_cfa_offset 208
	movq	64(%rsp), %rcx
	movl	48(%rsp), %r8d
	movq	56(%rsp), %rdx
	call	_Z18initializeHotPlateiiPPfS0_iiii
	movslq	%ebx, %rax
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 48(%rsp)
	call	malloc@PLT
	movq	56(%rsp), %rdi
	movl	%ebp, %edx
	movl	%ebx, %esi
	movq	%rax, 72(%rsp)
	call	_Z12flattenArrayPPfii
	movq	64(%rsp), %rdi
	movl	%ebp, %edx
	movl	%ebx, %esi
	movq	%rax, %r13
	call	_Z12flattenArrayPPfii
	movq	%rax, %r15
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
	movq	24(%rsp), %rsi
	leaq	72(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	$194, %ecx
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L82
	movq	24(%rsp), %rsi
	leaq	80(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L62
	movl	$195, %ecx
.L82:
	leaq	.LC1(%rip), %rdx
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%r14d, %edi
	call	cudaGetErrorString@PLT
	movl	%r14d, %edx
	movq	%rax, %rcx
.L83:
	movl	$2, %edi
	leaq	.LC3(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L62:
	movq	32(%rsp), %rsi
	leaq	88(%rsp), %rdi
	call	cudaMalloc@PLT
	movl	$196, %ecx
	movl	%eax, %r14d
	testl	%eax, %eax
	jne	.L82
	movq	24(%rsp), %rdx
	movq	72(%rsp), %rdi
	movl	$1, %ecx
	movq	%r13, %rsi
	call	cudaMemcpy@PLT
	movl	$199, %ecx
	movl	%eax, %r13d
	testl	%eax, %eax
	jne	.L84
	movq	24(%rsp), %rdx
	movq	80(%rsp), %rdi
	movl	$1, %ecx
	movq	%r15, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %r13d
	testl	%eax, %eax
	je	.L65
	movl	$200, %ecx
.L84:
	leaq	.LC1(%rip), %rdx
	leaq	.LC2(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	%r13d, %edi
	call	cudaGetErrorString@PLT
	movl	%r13d, %edx
	movq	%rax, %rcx
	jmp	.L83
.L65:
	leaq	.LC4(%rip), %rcx
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%r13d, %r13d
	leaq	.LC5(%rip), %rdx
	leaq	.LC6(%rip), %rsi
	movabsq	$4294967304, %r14
	call	__printf_chk@PLT
.L66:
	movsd	8(%rsp), %xmm6
	cvtss2sd	20(%rsp), %xmm0
	comisd	%xmm0, %xmm6
	jbe	.L72
	movl	%r12d, 96(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r14, %rdx
	movabsq	$4294967297, %rax
	movl	$1, %ecx
	movq	%rax, 100(%rsp)
	movq	96(%rsp), %rdi
	movl	104(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L67
	movss	20(%rsp), %xmm0
	movq	88(%rsp), %r8
	movl	%ebp, %esi
	movl	%ebx, %edi
	movq	80(%rsp), %rcx
	movq	72(%rsp), %rdx
	call	_Z39__device_stub__Z12generateHeatiiPfS_S_fiiPfS_S_f
.L67:
	call	cudaDeviceSynchronize@PLT
	movq	32(%rsp), %rdx
	movq	88(%rsp), %rsi
	movl	$2, %ecx
	movq	56(%rsp), %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %r15d
	testl	%eax, %eax
	je	.L68
	movl	$209, %ecx
	leaq	.LC1(%rip), %rdx
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	movl	%r15d, %edi
	call	cudaGetErrorString@PLT
	movl	%r15d, %edx
	movq	%rax, %rcx
	jmp	.L83
.L68:
	movq	56(%rsp), %rdi
	leal	-1(%rbx), %esi
	call	_Z12max_max_diffPfi
	movq	72(%rsp), %rax
	movq	80(%rsp), %rdx
	cvtss2sd	%xmm0, %xmm4
	movaps	%xmm0, %xmm1
	movsd	%xmm4, 8(%rsp)
	movq	%rdx, 72(%rsp)
	movq	%rax, 80(%rsp)
	testl	%r13d, %r13d
	je	.L69
	leal	-1(%r13), %eax
	testl	%r13d, %eax
	jne	.L69
	movss	%xmm0, 24(%rsp)
	movl	%r13d, %edx
	movaps	%xmm4, %xmm0
	movb	$1, %al
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	call	__printf_chk@PLT
	movss	24(%rsp), %xmm1
.L69:
	movss	20(%rsp), %xmm5
	comiss	%xmm1, %xmm5
	jbe	.L80
	movsd	8(%rsp), %xmm0
	movl	%r13d, %edx
	movl	$2, %edi
	movb	$1, %al
	leaq	.LC7(%rip), %rsi
	call	__printf_chk@PLT
	jmp	.L72
.L80:
	incl	%r13d
	jmp	.L66
.L72:
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	movq	80(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rdi
	call	cudaFree@PLT
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L74
	call	__stack_chk_fail@PLT
.L74:
	addq	$136, %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
.LFE2045:
	.size	main, .-main
	.section	.rodata.str1.1
.LC8:
	.string	"_Z12generateHeatiiPfS_S_f"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2073:
	.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	.LC8(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z12generateHeatiiPfS_S_f(%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
.LFE2073:
	.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
.LC0:
	.long	1065353216
	.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:

/* A program to solve the hotplate problem  using GPU

  Author: Bukola Grace Omotoso
  MNumber: M01424979
  ID: bgo2e
  Last Modified: 11/27/2018
  
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include<hip/hip_runtime.h>





#define CHECK(call) \
{ \
 const hipError_t error = call; \
 if (error != hipSuccess) \
 { \
 printf("Error: %s:%d, ", __FILE__, __LINE__); \
 printf("code:%d, reason: %s\n", error, hipGetErrorString(error)); \
 exit(1); \
 } \
}


float** buildHotplate(int rows, int columns) {
float** hotplate;
hotplate = (float**) malloc(rows*sizeof(float*));
for (int i = 0; i < rows; i++)
   hotplate[i] = (float*) malloc(columns*sizeof(float));
   return hotplate;
}

float* flattenArray(float** arrayToFlatten, int num_rows, int num_cols){
	float* flattenedArray = (float*) malloc(num_rows*num_cols*sizeof(float));
	int counter = 0;
	
	for (int row = 0; row < num_rows; row++){
		
	{
		for(int col = 0; col < num_cols; col++){
			flattenedArray[counter] = arrayToFlatten[row][col];
			counter++;
		}
	}
	
}
		return flattenedArray;
}

 void initializeHotPlate(int num_rows, int num_cols, float** hotplate, float** hotplateClone, int top_temp, int left_temp, int right_temp, int bottom_temp)	{
 	int num_outer_grid = (2 * num_rows) + (2 * (num_cols - 2));
	float outer_grid_sum = (top_temp * (num_cols - 2)) + (left_temp * (num_rows - 1)) + (bottom_temp * num_cols) + (right_temp * (num_rows - 1));
    float initial_inner_val = outer_grid_sum / num_outer_grid;

    for (int row = 0; row < num_rows; row++) {
            for (int column = 0; column < num_cols; column++) {

                //top values override the top row except the edges
                 if ((row == 0) & (column != 0 & column != num_cols - 1)) {
                	hotplate[row][column] = top_temp;
                    hotplateClone[row][column] = top_temp;
                } 
                else if (column == 0 && (row != (num_rows-1))) {
                    hotplate[row][column] = left_temp;
                    hotplateClone[row][column] = left_temp;
                }
                else if (column == (num_cols - 1) && (row != (num_rows-1))) {
                    hotplate[row][column] = right_temp;
                    hotplateClone[row][column] = right_temp;
                }
                else if(row == (num_rows -1 )){
                    hotplate[row][column] = bottom_temp;
                    hotplateClone[row][column] = bottom_temp;
                }
                if ((row != 0) && (row != num_rows - 1) && (column != 0) && (column != num_cols - 1))
                    hotplate[row][column] = initial_inner_val;
            }
        }

 }

 void swapHotplate(float *a, float *b) {

    float *tmp = a;
    a = b;
    b = tmp;
}


__global__ 
void generateHeat(int num_rows, int num_cols, float* hotplate, float* hotplateClone, float* d_maximums, float epsilon) {
        float max_difference = 0;
        float previous_val;
        float current_val;
        float diff;
        
         int row = blockIdx.x * blockDim.x + threadIdx.x;
         
            if (row > 0 && row < (num_rows-1)){
                for (int col = 1; col < (num_cols - 1); col++) {
					
				int idx = (row * num_cols) + col;
				float top = hotplate[idx - num_cols];				
				float bottom = hotplate[idx + num_cols];
				float left =  hotplate[idx - 1];
				float right =  hotplate[idx + 1];

                    previous_val = hotplate[idx];
                    current_val = (top + bottom + left + right) / 4.0;
                    diff = fabsf(previous_val - current_val);
                    if (diff > max_difference){
                        max_difference = diff;
                    }
                    hotplateClone[idx] = current_val;
                }
                
                d_maximums[row] = max_difference;
			}
}


/*Get the maximum values from all threads*/
float max_max_diff(float arr[], int n)
{
    int i;
        float max = arr[0];
    for (i = 1; i < n; i++)
        if (arr[i] > max)
            max = arr[i];
    return max;
}



int main(int argc, char const *argv[])
{		int num_rows = atoi(argv[1]);
		int num_cols = atoi(argv[2]);
		int top_temp = atoi(argv[3]);
		int left_temp = atoi(argv[4]);
		int right_temp = atoi(argv[5]);
		int bottom_temp = atoi(argv[6]);
		float epsilon = atof(argv[7]);
		
		float* flattenedhotplate;
		float* flattenedhotplateClone;
		float* maximums;

		
		int gridsize = 8;
		int block = 0;
		int block1 = (num_rows/gridsize);
		if (gridsize > num_rows)
			block = 1;
		else if ((block1 * gridsize) < num_rows){
			block = block1 + 1;
		}else{
			block = block1;
		}
		size_t nBytes = num_rows*num_cols * sizeof(float);
		double max_difference = epsilon + 1;
		int counter = 0;

        float** hotplate =  buildHotplate(num_rows, num_cols);
        float** hotplateClone = buildHotplate(num_rows, num_cols);
        
        
         
        initializeHotPlate(num_rows, num_cols, hotplate, hotplateClone, top_temp, left_temp, right_temp, bottom_temp);    
         
         flattenedhotplate = (float*) malloc(num_cols*num_rows*sizeof(float));
         flattenedhotplateClone = (float*) malloc(num_cols*num_rows*sizeof(float));
         maximums = (float*)malloc(num_rows*sizeof(float));
         
     
         flattenedhotplate = flattenArray(hotplate, num_rows, num_cols);
         flattenedhotplateClone = flattenArray(hotplateClone, num_rows, num_cols);

         
         float *d_hotplate; 
         float *d_hotplateClone;
         float *d_maximums;
	

		CHECK(hipMalloc((float**)&d_hotplate, nBytes));
		CHECK(hipMalloc((float**)&d_hotplateClone, nBytes));
		CHECK(hipMalloc((float**)&d_maximums, num_rows*sizeof(float)));
		
		
		CHECK(hipMemcpy( d_hotplate, flattenedhotplate, nBytes, hipMemcpyHostToDevice));
		CHECK(hipMemcpy(d_hotplateClone, flattenedhotplateClone, nBytes, hipMemcpyHostToDevice));
		
		printf("%10s%10s\n", "Iteration", "Epsilon");

		 while(max_difference > epsilon){
        
		generateHeat<<<block,gridsize>>>(num_rows, num_cols, d_hotplate, d_hotplateClone, d_maximums, epsilon);
	
		hipDeviceSynchronize();
		CHECK(hipMemcpy(maximums, d_maximums, num_rows*sizeof(float), hipMemcpyDeviceToHost));
		max_difference = max_max_diff(maximums, num_rows-1);
        
            float *T = d_hotplate;
            d_hotplate = d_hotplateClone;
            d_hotplateClone  =  T;
            
            if (counter > 0 && (counter & (counter - 1)) == 0)
                printf("%6d%15.6f\n", counter, max_difference);
            if (max_difference < epsilon) {
                printf("%6d%15.6f\n", counter, max_difference);
                break;
            }
            counter++;
	}
	
	hipFree(d_hotplate);
	hipFree(d_hotplateClone);
	hipFree(d_maximums);
	
		return 0;

}


	.text
	.file	"hotplate.hip"
	.globl	_Z13buildHotplateii             # -- Begin function _Z13buildHotplateii
	.type	_Z13buildHotplateii,@function
_Z13buildHotplateii:                    # @_Z13buildHotplateii
	.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	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %r14d
	movl	%edi, %ebp
	movslq	%edi, %r15
	leaq	(,%r15,8), %rdi
	callq	malloc
	movq	%rax, %rbx
	testl	%r15d, %r15d
	jle	.LBB0_3
# %bb.1:                                # %.lr.ph
	movslq	%r14d, %r14
	shlq	$2, %r14
	movl	%ebp, %r15d
	xorl	%r12d, %r12d
.LBB0_2:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, (%rbx,%r12,8)
	incq	%r12
	cmpq	%r12, %r15
	jne	.LBB0_2
.LBB0_3:                                # %._crit_edge
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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	_Z13buildHotplateii, .Lfunc_end0-_Z13buildHotplateii
	.cfi_endproc
                                        # -- End function
	.globl	_Z12flattenArrayPPfii           # -- Begin function _Z12flattenArrayPPfii
	.type	_Z12flattenArrayPPfii,@function
_Z12flattenArrayPPfii:                  # @_Z12flattenArrayPPfii
	.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
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, 16(%rsp)                  # 8-byte Spill
	movl	%edx, %eax
	imull	%esi, %eax
	movslq	%eax, %rdi
	shlq	$2, %rdi
	callq	malloc
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	testl	%ebp, %ebp
	jle	.LBB1_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebx, %r12d
	shlq	$2, %r12
	movl	%ebp, %r13d
	xorl	%ebp, %ebp
	testl	%ebx, %ebx
	movl	$0, %r14d
	cmovgl	%ebx, %r14d
	xorl	%r15d, %r15d
.LBB1_2:                                # %.preheader
                                        # =>This Inner Loop Header: Depth=1
	testl	%ebx, %ebx
	jle	.LBB1_4
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB1_2 Depth=1
	movq	16(%rsp), %rax                  # 8-byte Reload
	movq	(%rax,%r15,8), %rsi
	movslq	%ebp, %rax
	movq	8(%rsp), %rcx                   # 8-byte Reload
	leaq	(%rcx,%rax,4), %rdi
	movq	%r12, %rdx
	callq	memcpy@PLT
.LBB1_4:                                # %._crit_edge
                                        #   in Loop: Header=BB1_2 Depth=1
	incq	%r15
	addl	%r14d, %ebp
	cmpq	%r15, %r13
	jne	.LBB1_2
.LBB1_5:                                # %._crit_edge20
	movq	8(%rsp), %rax                   # 8-byte Reload
	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	_Z12flattenArrayPPfii, .Lfunc_end1-_Z12flattenArrayPPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z18initializeHotPlateiiPPfS0_iiii # -- Begin function _Z18initializeHotPlateiiPPfS0_iiii
	.type	_Z18initializeHotPlateiiPPfS0_iiii,@function
_Z18initializeHotPlateiiPPfS0_iiii:     # @_Z18initializeHotPlateiiPPfS0_iiii
	.cfi_startproc
# %bb.0:
                                        # kill: def $r9d killed $r9d def $r9
                                        # kill: def $esi killed $esi def $rsi
                                        # kill: def $edi killed $edi def $rdi
	testl	%edi, %edi
	jle	.LBB2_22
# %bb.1:                                # %.preheader.lr.ph
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	56(%rsp), %eax
	movl	48(%rsp), %r10d
	leal	-2(%rsi), %r11d
	leal	(%rsi,%rdi), %ebx
	addl	$-2, %ebx
	imull	%r8d, %r11d
	leal	-1(%rdi), %ebp
	movl	%eax, %r14d
	imull	%esi, %r14d
	addl	%r11d, %r14d
	leal	(%r10,%r9), %r11d
	imull	%ebp, %r11d
	addl	%r14d, %r11d
	cvtsi2ss	%r11d, %xmm0
	addl	%ebx, %ebx
	cvtsi2ss	%ebx, %xmm1
	divss	%xmm1, %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2ss	%r9d, %xmm1
	leal	-1(%rsi), %r9d
	cvtsi2ss	%r8d, %xmm2
	movl	%ebp, %r8d
	movl	%edi, %edi
	movl	%esi, %r11d
	xorl	%ebx, %ebx
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_4 Depth 2
	testl	%esi, %esi
	jle	.LBB2_20
# %bb.3:                                # %.lr.ph
                                        #   in Loop: Header=BB2_2 Depth=1
	xorl	%r14d, %r14d
.LBB2_4:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	testq	%r14, %r14
	je	.LBB2_8
# %bb.5:                                #   in Loop: Header=BB2_4 Depth=2
	testq	%rbx, %rbx
	jne	.LBB2_8
# %bb.6:                                #   in Loop: Header=BB2_4 Depth=2
	cmpq	%r14, %r9
	je	.LBB2_8
# %bb.7:                                #   in Loop: Header=BB2_4 Depth=2
	movq	(%rdx,%rbx,8), %r15
	movss	%xmm2, (%r15,%r14,4)
	movq	(%rcx,%rbx,8), %r15
	movss	%xmm2, (%r15,%r14,4)
	jmp	.LBB2_19
.LBB2_8:                                #   in Loop: Header=BB2_4 Depth=2
	testq	%r14, %r14
	jne	.LBB2_11
# %bb.9:                                #   in Loop: Header=BB2_4 Depth=2
	cmpq	%r8, %rbx
	je	.LBB2_11
# %bb.10:                               #   in Loop: Header=BB2_4 Depth=2
	movq	(%rdx,%rbx,8), %r15
	movss	%xmm1, (%r15)
	movq	(%rcx,%rbx,8), %r15
	movss	%xmm1, (%r15)
	jmp	.LBB2_19
.LBB2_11:                               #   in Loop: Header=BB2_4 Depth=2
	cmpq	%r14, %r9
	setne	%r15b
	cmpq	%r8, %rbx
	sete	%bpl
	orb	%r15b, %bpl
	cmpb	$1, %bpl
	jne	.LBB2_13
# %bb.12:                               #   in Loop: Header=BB2_4 Depth=2
	cmpq	%r8, %rbx
	jne	.LBB2_14
.LBB2_13:                               # %.sink.split
                                        #   in Loop: Header=BB2_4 Depth=2
	testb	%bpl, %bpl
	movl	%r10d, %ebp
	cmovnel	%eax, %ebp
	xorps	%xmm3, %xmm3
	cvtsi2ss	%ebp, %xmm3
	movq	%r9, %r15
	cmovneq	%r14, %r15
	movq	(%rdx,%rbx,8), %r12
	movss	%xmm3, (%r12,%r15,4)
	movq	(%rcx,%rbx,8), %r12
	movss	%xmm3, (%r12,%r15,4)
.LBB2_14:                               #   in Loop: Header=BB2_4 Depth=2
	cmpq	%r14, %r9
	je	.LBB2_19
# %bb.15:                               #   in Loop: Header=BB2_4 Depth=2
	testq	%rbx, %rbx
	je	.LBB2_19
# %bb.16:                               #   in Loop: Header=BB2_4 Depth=2
	cmpq	%r8, %rbx
	je	.LBB2_19
# %bb.17:                               #   in Loop: Header=BB2_4 Depth=2
	testq	%r14, %r14
	je	.LBB2_19
# %bb.18:                               #   in Loop: Header=BB2_4 Depth=2
	movq	(%rdx,%rbx,8), %r15
	movss	%xmm0, (%r15,%r14,4)
.LBB2_19:                               # %.thread
                                        #   in Loop: Header=BB2_4 Depth=2
	incq	%r14
	cmpq	%r14, %r11
	jne	.LBB2_4
.LBB2_20:                               # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	incq	%rbx
	cmpq	%rdi, %rbx
	jne	.LBB2_2
# %bb.21:
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.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
	.cfi_restore %rbx
	.cfi_restore %r12
	.cfi_restore %r14
	.cfi_restore %r15
	.cfi_restore %rbp
.LBB2_22:                               # %._crit_edge83
	retq
.Lfunc_end2:
	.size	_Z18initializeHotPlateiiPPfS0_iiii, .Lfunc_end2-_Z18initializeHotPlateiiPPfS0_iiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z12swapHotplatePfS_            # -- Begin function _Z12swapHotplatePfS_
	.type	_Z12swapHotplatePfS_,@function
_Z12swapHotplatePfS_:                   # @_Z12swapHotplatePfS_
	.cfi_startproc
# %bb.0:
	retq
.Lfunc_end3:
	.size	_Z12swapHotplatePfS_, .Lfunc_end3-_Z12swapHotplatePfS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z27__device_stub__generateHeatiiPfS_S_f # -- Begin function _Z27__device_stub__generateHeatiiPfS_S_f
	.type	_Z27__device_stub__generateHeatiiPfS_S_f,@function
_Z27__device_stub__generateHeatiiPfS_S_f: # @_Z27__device_stub__generateHeatiiPfS_S_f
	.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	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	20(%rsp), %rax
	movl	%edi, (%rax)
	leaq	16(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	56(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	48(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	40(%rsp), %rcx
	movq	%r8, (%rcx)
	leaq	12(%rsp), %r8
	movss	%xmm0, (%r8)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z12generateHeatiiPfS_S_f, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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_end4:
	.size	_Z27__device_stub__generateHeatiiPfS_S_f, .Lfunc_end4-_Z27__device_stub__generateHeatiiPfS_S_f
	.cfi_endproc
                                        # -- End function
	.globl	_Z12max_max_diffPfi             # -- Begin function _Z12max_max_diffPfi
	.type	_Z12max_max_diffPfi,@function
_Z12max_max_diffPfi:                    # @_Z12max_max_diffPfi
	.cfi_startproc
# %bb.0:
	movss	(%rdi), %xmm1                   # xmm1 = mem[0],zero,zero,zero
	cmpl	$2, %esi
	jl	.LBB5_1
# %bb.2:                                # %.lr.ph.preheader
	movl	%esi, %eax
	movl	$1, %ecx
.LBB5_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movss	(%rdi,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	maxss	%xmm1, %xmm0
	incq	%rcx
	movaps	%xmm0, %xmm1
	cmpq	%rcx, %rax
	jne	.LBB5_3
# %bb.4:                                # %._crit_edge
	retq
.LBB5_1:
	movaps	%xmm1, %xmm0
	retq
.Lfunc_end5:
	.size	_Z12max_max_diffPfi, .Lfunc_end5-_Z12max_max_diffPfi
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI6_0:
	.long	0x3f800000                      # float 1
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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, %r12
	movq	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %ebx
	movq	16(%r12), %rdi
	callq	atoi
	movl	%eax, %r14d
	movq	24(%r12), %rdi
	callq	atoi
	movl	%eax, 4(%rsp)                   # 4-byte Spill
	movq	32(%r12), %rdi
	callq	atoi
	movl	%eax, 32(%rsp)                  # 4-byte Spill
	movq	40(%r12), %rdi
	callq	atoi
                                        # kill: def $eax killed $eax def $rax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movq	48(%r12), %rdi
	callq	atoi
	movl	%eax, %r15d
	movq	56(%r12), %rdi
	callq	atof
	leal	7(%rbx), %eax
	testl	%ebx, %ebx
	cmovnsl	%ebx, %eax
	movsd	%xmm0, 48(%rsp)                 # 8-byte Spill
	movl	%eax, %ecx
	sarl	$3, %ecx
	andl	$-8, %eax
	xorl	%edx, %edx
	cmpl	%ebx, %eax
	setl	%dl
	addl	%ecx, %edx
	cmpl	$8, %ebx
	movl	$1, %eax
	cmovgel	%edx, %eax
	movl	%eax, 40(%rsp)                  # 4-byte Spill
	movl	%r14d, %eax
	imull	%ebx, %eax
	movslq	%eax, %r12
	shlq	$2, %r12
	movl	%ebx, %edi
	movl	%r14d, %esi
	callq	_Z13buildHotplateii
	movq	%rax, %rbp
	movl	%ebx, %edi
	movl	%r14d, %esi
	callq	_Z13buildHotplateii
	movq	%rax, %r13
	movl	%ebx, %edi
	movl	%r14d, %esi
	movq	%rbp, %rdx
	movq	%rax, %rcx
	movl	4(%rsp), %r8d                   # 4-byte Reload
	movl	32(%rsp), %r9d                  # 4-byte Reload
	pushq	%r15
	.cfi_adjust_cfa_offset 8
	pushq	16(%rsp)                        # 8-byte Folded Reload
	.cfi_adjust_cfa_offset 8
	callq	_Z18initializeHotPlateiiPPfS0_iiii
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
	movslq	%ebx, %rdi
	shlq	$2, %rdi
	movq	%rdi, 32(%rsp)                  # 8-byte Spill
	callq	malloc
	movq	%rax, %r15
	movq	%rbp, %rdi
	movl	%ebx, %esi
	movl	%r14d, %edx
	callq	_Z12flattenArrayPPfii
	movq	%rax, %rbp
	movq	%r13, %rdi
	movl	%ebx, %esi
	movl	%r14d, 68(%rsp)                 # 4-byte Spill
	movl	%r14d, %edx
	callq	_Z12flattenArrayPPfii
	movq	%rax, %r14
	leaq	24(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_1
# %bb.4:
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_5
# %bb.6:
	leaq	56(%rsp), %rdi
	movq	32(%rsp), %rsi                  # 8-byte Reload
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB6_7
# %bb.8:
	movq	24(%rsp), %rdi
	movq	%rbp, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_9
# %bb.11:
	movq	16(%rsp), %rdi
	movq	%r14, %rsi
	movq	%r12, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_12
# %bb.13:
	cvtsd2ss	48(%rsp), %xmm1                 # 8-byte Folded Reload
	movss	%xmm1, 4(%rsp)                  # 4-byte Spill
	movss	.LCPI6_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	addss	%xmm1, %xmm0
	movss	%xmm0, 8(%rsp)                  # 4-byte Spill
	xorl	%r12d, %r12d
	movl	$.L.str.3, %edi
	movl	$.L.str.4, %esi
	movl	$.L.str.5, %edx
	xorl	%eax, %eax
	callq	printf
	movss	4(%rsp), %xmm2                  # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	movss	8(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	ucomiss	%xmm2, %xmm0
	jbe	.LBB6_28
# %bb.14:                               # %.lr.ph
	movabsq	$4294967296, %rax               # imm = 0x100000000
	movl	40(%rsp), %ebp                  # 4-byte Reload
	btsq	$32, %rbp
	leal	-1(%rbx), %r13d
	addq	$8, %rax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
.LBB6_15:                               # =>This Loop Header: Depth=1
                                        #     Child Loop BB6_22 Depth 2
	movq	%rbp, %rdi
	movl	$1, %esi
	movq	8(%rsp), %rdx                   # 8-byte Reload
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_17
# %bb.16:                               #   in Loop: Header=BB6_15 Depth=1
	movq	24(%rsp), %rdx
	movq	16(%rsp), %rcx
	movq	56(%rsp), %r8
	movl	%ebx, %edi
	movl	68(%rsp), %esi                  # 4-byte Reload
	movss	4(%rsp), %xmm0                  # 4-byte Reload
                                        # xmm0 = mem[0],zero,zero,zero
	callq	_Z27__device_stub__generateHeatiiPfS_S_f
.LBB6_17:                               #   in Loop: Header=BB6_15 Depth=1
	callq	hipDeviceSynchronize
	movq	56(%rsp), %rsi
	movq	%r15, %rdi
	movq	32(%rsp), %rdx                  # 8-byte Reload
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB6_18
# %bb.19:                               #   in Loop: Header=BB6_15 Depth=1
	movss	(%r15), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	cmpl	$3, %ebx
	jl	.LBB6_20
# %bb.21:                               # %.lr.ph.i.preheader
                                        #   in Loop: Header=BB6_15 Depth=1
	movl	$1, %eax
.LBB6_22:                               # %.lr.ph.i
                                        #   Parent Loop BB6_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%r15,%rax,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	maxss	%xmm0, %xmm1
	incq	%rax
	movaps	%xmm1, %xmm0
	cmpq	%rax, %r13
	jne	.LBB6_22
	jmp	.LBB6_23
.LBB6_20:                               #   in Loop: Header=BB6_15 Depth=1
	movaps	%xmm0, %xmm1
.LBB6_23:                               # %_Z12max_max_diffPfi.exit
                                        #   in Loop: Header=BB6_15 Depth=1
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm0
	movq	24(%rsp), %rax
	movq	16(%rsp), %rcx
	movq	%rcx, 24(%rsp)
	movq	%rax, 16(%rsp)
	leal	-1(%r12), %eax
	movl	%r12d, %ecx
	xorl	%eax, %ecx
	cmpl	%eax, %ecx
	jbe	.LBB6_25
# %bb.24:                               #   in Loop: Header=BB6_15 Depth=1
	movl	$.L.str.6, %edi
	movl	%r12d, %esi
	movb	$1, %al
	movss	%xmm1, 48(%rsp)                 # 4-byte Spill
	movsd	%xmm0, 40(%rsp)                 # 8-byte Spill
	callq	printf
	movsd	40(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movss	48(%rsp), %xmm1                 # 4-byte Reload
                                        # xmm1 = mem[0],zero,zero,zero
.LBB6_25:                               #   in Loop: Header=BB6_15 Depth=1
	movss	4(%rsp), %xmm2                  # 4-byte Reload
                                        # xmm2 = mem[0],zero,zero,zero
	ucomiss	%xmm1, %xmm2
	ja	.LBB6_26
# %bb.27:                               #   in Loop: Header=BB6_15 Depth=1
	incl	%r12d
	ucomiss	%xmm2, %xmm1
	ja	.LBB6_15
	jmp	.LBB6_28
.LBB6_26:                               # %.thread
	movl	$.L.str.6, %edi
	movl	%r12d, %esi
	movb	$1, %al
	callq	printf
.LBB6_28:                               # %.loopexit
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movq	56(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$72, %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
.LBB6_18:
	.cfi_def_cfa_offset 128
	movl	%eax, %r14d
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	movl	$209, %edx
	xorl	%eax, %eax
	callq	printf
	movl	%r14d, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %edi
	movl	%r14d, %esi
	jmp	.LBB6_3
.LBB6_1:
	movl	%eax, %r13d
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	movl	$194, %edx
	jmp	.LBB6_2
.LBB6_5:
	movl	%eax, %r13d
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	movl	$195, %edx
	jmp	.LBB6_2
.LBB6_7:
	movl	%eax, %r13d
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	movl	$196, %edx
.LBB6_2:
	xorl	%eax, %eax
	callq	printf
	movl	%r13d, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %edi
	movl	%r13d, %esi
	jmp	.LBB6_3
.LBB6_9:
	movl	%eax, %ebp
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	movl	$199, %edx
	jmp	.LBB6_10
.LBB6_12:
	movl	%eax, %ebp
	movl	$.L.str, %edi
	movl	$.L.str.1, %esi
	movl	$200, %edx
.LBB6_10:
	xorl	%eax, %eax
	callq	printf
	movl	%ebp, %edi
	callq	hipGetErrorString
	movl	$.L.str.2, %edi
	movl	%ebp, %esi
.LBB6_3:
	movq	%rax, %rdx
	xorl	%eax, %eax
	callq	printf
	movl	$1, %edi
	callq	exit
.Lfunc_end6:
	.size	main, .Lfunc_end6-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	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z12generateHeatiiPfS_S_f, %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_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__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	.LBB8_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
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z12generateHeatiiPfS_S_f,@object # @_Z12generateHeatiiPfS_S_f
	.section	.rodata,"a",@progbits
	.globl	_Z12generateHeatiiPfS_S_f
	.p2align	3, 0x0
_Z12generateHeatiiPfS_S_f:
	.quad	_Z27__device_stub__generateHeatiiPfS_S_f
	.size	_Z12generateHeatiiPfS_S_f, 8

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

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/grace-omotoso/CUDA_Hotplate/master/hotplate.hip"
	.size	.L.str.1, 110

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"code:%d, reason: %s\n"
	.size	.L.str.2, 21

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Iteration"
	.size	.L.str.4, 10

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Epsilon"
	.size	.L.str.5, 8

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

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z12generateHeatiiPfS_S_f"
	.size	.L__unnamed_1, 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 _Z27__device_stub__generateHeatiiPfS_S_f
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z12generateHeatiiPfS_S_f
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z12generateHeatiiPfS_S_f ; -- Begin function _Z12generateHeatiiPfS_S_f
	.globl	_Z12generateHeatiiPfS_S_f
	.p2align	8
	.type	_Z12generateHeatiiPfS_S_f,@function
_Z12generateHeatiiPfS_S_f:              ; @_Z12generateHeatiiPfS_S_f
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x34
	s_load_b64 s[2:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_add_i32 s2, s2, -1
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_lt_i32_e32 vcc_lo, 0, v1
	v_cmp_gt_i32_e64 s2, s2, v1
	s_and_b32 s2, vcc_lo, s2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s4, s2
	s_cbranch_execz .LBB0_5
; %bb.1:                                ; %.preheader
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x8
	s_load_b64 s[0:1], s[0:1], 0x18
	v_mov_b32_e32 v0, 0
	s_cmp_lt_i32 s3, 3
	s_cbranch_scc1 .LBB0_4
; %bb.2:                                ; %.lr.ph
	v_mad_u64_u32 v[2:3], null, v1, s3, 1
	s_ashr_i32 s9, s3, 31
	s_mov_b32 s8, s3
	v_mov_b32_e32 v0, 0
	s_lshl_b64 s[8:9], s[8:9], 2
	s_add_i32 s2, s3, -2
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v3, 31, v2
	v_add_nc_u32_e32 v4, s3, v2
	s_sub_u32 s3, 0, s8
	v_lshlrev_b64 v[6:7], 2, v[2:3]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[8:9], 2, v[4:5]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v2, vcc_lo, s6, v6
	v_add_co_ci_u32_e32 v3, vcc_lo, s7, v7, vcc_lo
	v_add_co_u32 v4, vcc_lo, s4, v6
	v_add_co_ci_u32_e32 v5, vcc_lo, s5, v7, vcc_lo
	v_add_co_u32 v6, vcc_lo, s4, v8
	v_add_co_ci_u32_e32 v7, vcc_lo, s5, v9, vcc_lo
	s_subb_u32 s4, 0, s9
.LBB0_3:                                ; =>This Inner Loop Header: Depth=1
	v_add_co_u32 v8, vcc_lo, v4, s3
	v_add_co_ci_u32_e32 v9, vcc_lo, s4, v5, vcc_lo
	s_add_i32 s2, s2, -1
	global_load_b32 v11, v[6:7], off
	s_clause 0x1
	global_load_b32 v12, v[8:9], off
	global_load_b96 v[8:10], v[4:5], off offset:-4
	v_add_co_u32 v6, vcc_lo, v6, 4
	v_add_co_ci_u32_e32 v7, vcc_lo, 0, v7, vcc_lo
	v_add_co_u32 v4, vcc_lo, v4, 4
	v_add_co_ci_u32_e32 v5, vcc_lo, 0, v5, vcc_lo
	s_cmp_eq_u32 s2, 0
	s_waitcnt vmcnt(1)
	v_add_f32_e32 v11, v12, v11
	s_waitcnt vmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f32_e32 v8, v11, v8
	v_add_f32_e32 v8, v8, v10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_fmac_f32_e32 v9, 0xbe800000, v8
	v_mul_f32_e32 v8, 0x3e800000, v8
	v_cmp_gt_f32_e64 s5, |v9|, v0
	global_store_b32 v[2:3], v8, off
	v_add_co_u32 v2, vcc_lo, v2, 4
	v_add_co_ci_u32_e32 v3, vcc_lo, 0, v3, vcc_lo
	v_cndmask_b32_e64 v0, v0, |v9|, s5
	s_cbranch_scc0 .LBB0_3
.LBB0_4:                                ; %Flow69
	v_mov_b32_e32 v2, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v1, vcc_lo, s0, v1
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_store_b32 v[1:2], v0, off
.LBB0_5:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z12generateHeatiiPfS_S_f
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.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 13
		.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	_Z12generateHeatiiPfS_S_f, .Lfunc_end0-_Z12generateHeatiiPfS_S_f
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 436
; NumSgprs: 18
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 13
; 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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z12generateHeatiiPfS_S_f
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z12generateHeatiiPfS_S_f.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
