#include <stdlib.h>
#include <stdio.h>
#include <cuda_runtime.h>
#include <time.h>

//#define __DEBUG

#define element_addr(a, m, n, d) (a + ((m) * (d) + n))
#define element(a, m, n, d) (((m >= 0)&&(m < d)&&(n >= 0)&&(n < d))? (a[(m) * (d) + n]) : 0) 

#define CUDA_CALL(cmd) do { \
	if((err = cmd) != cudaSuccess) { \
		printf("(%d) Cuda Error: %s\n", __LINE__, cudaGetErrorString(err) ); \
	} \
} while(0)

int calculateGPU(const int *living, float *honey[2], int d, int n, float rbee, float rflow);
int calculateCPU(const int *living, float *honey[2], int d, int n, float rbee, float rflow);

int main(int argc, char **argv)
{
	FILE *fp;
	int d, n;
	float rbee, rflow;
	int *living;
	float *honey[2], *honeyr;
	int i, j;
	int resin;

	if (argc != 2) {
		printf("sampl0 <input_file>\n");
		return 1;
	}
	
	fp = fopen(argv[1], "r");
	if(fp == NULL) {
		printf("fopen %s error\n", argv[1]);
		return 1;
	}

	fscanf(fp, "%d %d", &d, &n);
	fscanf(fp, "%f %f", &rbee, &rflow);
#ifdef __DEBUG
	printf("D=%d N=%d\n", d, n);
	printf("R(bee)=%f R(flow)=%f\n", rbee, rflow);
#endif

	living = (int *) malloc( d * d * sizeof(int) );
	if(living == NULL) {
		printf("malloc living[] error\n");
		return 1;
	}
	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			fscanf(fp, "%d", element_addr(living, i, j, d));
		}
	}
#ifdef __DEBUG
	printf("livingmap = \n");
	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			printf("%d ", element(living, i, j, d));
		}
		printf("\n");
	}
#endif

	honey[0] = (float *)malloc( d * d * sizeof(float) );
	honey[1] = (float *)malloc( d * d * sizeof(float) );
	honeyr   = (float *)malloc( d * d * sizeof(float) );
	if(honey[0] == NULL || honey[1] == NULL || honeyr == NULL ) {
		printf("malloc honey[] error\n");
		return 1;
	}

	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			fscanf(fp, "%f", element_addr(honey[0], i, j, d));
		}
	}
#ifdef __DEBUG
	printf("honey = \n");
	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			printf("%f ", element(honey[0], i, j, d));
		}
		printf("\n");
	}
#endif
	fclose(fp);

	calculateGPU(living, honey, d, n, rbee, rflow); //always return in honey[1]

	memcpy(honeyr, honey[1], d * d * sizeof(float) );

	resin = calculateCPU(living, honey, d, n, rbee, rflow);
#ifdef __DEBUG
	printf("result is in honey[%d] \n",resin);
#endif

	fp = fopen("beehive_res.txt", "w");
	n = 0;
	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			fprintf(fp, "%f ", element(honeyr, i, j, d));
			if( fabs( (element(honey[resin], i, j, d) - element(honeyr, i, j, d)) / element(honey[resin], i, j, d) ) > 0.0001) {
			//if(element(honey[resin], i, j, d) != element(honeyr, i, j, d) ) {
				printf("<%d, %d>:%f %f\n", i, j, element(honey[resin], i, j, d), element(honeyr, i, j, d));
				n++;
			}
		}
		fprintf(fp, "\n");
	}
	printf("error: %d\n", n);

	fclose (fp);

	free(honey[0]);
	free(honey[1]);
	free(honeyr);
	free(living);

	return 0;
}

int calculateCPU(const int *living, float *honey[2], int d, int n, float rbee, float rflow)
{
	int ite;
	int src, resin = 0;
	int i, j;
	clock_t start, end;
	double time;

	start = clock();
	for(ite = 0; ite < n; ite++ ) {
		src = resin;
		resin = 1 - resin;

		for(i = 0; i < d; i++ ) {
			for(j = 0; j < d; j++ ) {
				*(element_addr(honey[resin], i, j, d)) = rflow * (
						element(honey[src], i-1, j-1, d) + element(honey[src], i-1, j, d) + element(honey[src], i-1, j+1, d) 
					  +	element(honey[src], i, j-1, d)   + element(honey[src], i, j+1, d)
					  +	element(honey[src], i+1, j-1, d) + element(honey[src], i+1, j, d) + element(honey[src], i+1, j+1, d) 
					) + (1.0 - 8.0 * rflow) * element(honey[src], i, j, d)
					+ rbee * element(living, i, j, d);
			}
		}
	}
	end = clock();
	time = ((double)(end-start))/CLOCKS_PER_SEC;
	printf("CPU computation: %lf sec\n", time);

	return resin;
}

	.file	"tmpxft_00391127_00000000-6_framework.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
.LC4:
	.string	"CPU computation: %lf sec\n"
	.text
	.globl	_Z12calculateCPUPKiPPfiiff
	.type	_Z12calculateCPUPKiPPfiiff, @function
_Z12calculateCPUPKiPPfiiff:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	xorl	%r12d, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movl	%edx, %ebx
	subq	$88, %rsp
	.cfi_def_cfa_offset 144
	movss	%xmm1, 12(%rsp)
	movq	%rdi, 56(%rsp)
	movl	%ecx, 68(%rsp)
	movss	%xmm0, 72(%rsp)
	call	clock@PLT
	movsd	.LC1(%rip), %xmm2
	movsd	.LC2(%rip), %xmm3
	xorl	%r10d, %r10d
	movq	%rax, 48(%rsp)
	movslq	%ebx, %rax
	movss	12(%rsp), %xmm1
	salq	$2, %rax
	movq	%rax, 24(%rsp)
	leal	(%rbx,%rbx), %eax
	movl	%eax, 76(%rsp)
.L3:
	movl	68(%rsp), %eax
	cmpl	%eax, %r10d
	jge	.L35
	movl	%r12d, %eax
	xorl	%r11d, %r11d
	xorl	%r8d, %r8d
	xorl	%ecx, %ecx
	xorl	$1, %eax
	movl	%eax, 12(%rsp)
	leaq	0(%rbp,%r12,8), %rax
	movq	%rax, 16(%rsp)
	movslq	12(%rsp), %rax
	leaq	0(%rbp,%rax,8), %rax
	movq	%rax, 32(%rsp)
.L4:
	cmpl	%ebx, %ecx
	jge	.L36
	movl	76(%rsp), %eax
	movl	%r8d, %r12d
	cvtss2sd	%xmm1, %xmm0
	movaps	%xmm3, %xmm4
	mulsd	%xmm2, %xmm0
	subl	%ebx, %r12d
	leal	1(%rcx), %r9d
	movq	%r11, %rsi
	addl	%r12d, %eax
	movl	%eax, 64(%rsp)
	movq	16(%rsp), %rax
	movl	64(%rsp), %edi
	movq	(%rax), %rdx
	movq	32(%rsp), %rax
	subsd	%xmm0, %xmm4
	movq	(%rax), %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
.L13:
	testl	%ecx, %ecx
	je	.L16
	leal	(%r12,%rax), %r13d
	xorps	%xmm0, %xmm0
	movslq	%r13d, %r13
	leaq	0(,%r13,4), %r14
	testq	%rax, %rax
	je	.L6
	movss	-4(%rdx,%r14), %xmm0
.L6:
	movss	(%rdx,%r13,4), %xmm5
	jmp	.L5
.L16:
	xorps	%xmm0, %xmm0
	movaps	%xmm0, %xmm5
.L5:
	addss	%xmm5, %xmm0
	xorps	%xmm5, %xmm5
	testl	%ecx, %ecx
	je	.L7
	leal	1(%rax), %r13d
	cmpl	%r13d, %ebx
	jle	.L7
	leal	(%r12,%rax), %r13d
	movslq	%r13d, %r13
	movss	4(%rdx,%r13,4), %xmm5
.L7:
	addss	%xmm5, %xmm0
	movl	%eax, %r15d
	xorps	%xmm5, %xmm5
	testq	%rax, %rax
	je	.L8
	leal	(%r8,%rax), %r13d
	movslq	%r13d, %r13
	movss	-4(%rdx,%r13,4), %xmm5
.L8:
	leal	1(%rax), %r14d
	addss	%xmm5, %xmm0
	xorps	%xmm5, %xmm5
	cmpl	%r14d, %ebx
	jle	.L9
	leal	(%r8,%rax), %r13d
	movslq	%r13d, %r13
	movss	4(%rdx,%r13,4), %xmm5
.L9:
	addss	%xmm5, %xmm0
	testl	%r15d, %r15d
	je	.L22
	cmpl	%ebx, %r9d
	jge	.L22
	movslq	%edi, %r13
	movss	-4(%rdx,%r13,4), %xmm5
	jmp	.L10
.L22:
	xorps	%xmm5, %xmm5
.L10:
	addss	%xmm5, %xmm0
	xorps	%xmm5, %xmm5
	cmpl	%ebx, %r9d
	jge	.L11
	movslq	%edi, %r13
	movss	(%rdx,%r13,4), %xmm5
.L11:
	addss	%xmm5, %xmm0
	xorps	%xmm5, %xmm5
	cmpl	%ebx, %r9d
	jge	.L12
	cmpl	%r14d, %ebx
	jle	.L12
	movslq	%edi, %r13
	movss	4(%rdx,%r13,4), %xmm5
.L12:
	addss	%xmm5, %xmm0
	cvtss2sd	(%rdx,%rsi), %xmm5
	mulsd	%xmm4, %xmm5
	incq	%rax
	movq	56(%rsp), %r15
	incl	%edi
	mulss	%xmm1, %xmm0
	cvtss2sd	%xmm0, %xmm0
	addsd	%xmm5, %xmm0
	cvtsi2ssl	(%r15,%rsi), %xmm5
	mulss	72(%rsp), %xmm5
	movq	40(%rsp), %r15
	cvtss2sd	%xmm5, %xmm5
	addsd	%xmm5, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r15,%rsi)
	addq	$4, %rsi
	cmpl	%eax, %ebx
	jg	.L13
	movq	24(%rsp), %rax
	movl	64(%rsp), %r8d
	movl	%r9d, %ecx
	addq	%rax, %r11
	jmp	.L4
.L36:
	movslq	12(%rsp), %r12
	incl	%r10d
	jmp	.L3
.L35:
	call	clock@PLT
	movq	48(%rsp), %rcx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	subq	%rcx, %rax
	cvtsi2sdq	%rax, %xmm0
	movb	$1, %al
	divsd	.LC3(%rip), %xmm0
	call	__printf_chk@PLT
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	movl	%r12d, %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
.LFE2028:
	.size	_Z12calculateCPUPKiPPfiiff, .-_Z12calculateCPUPKiPPfiiff
	.section	.rodata.str1.1
.LC6:
	.string	"sampl0 <input_file>\n"
.LC7:
	.string	"r"
.LC8:
	.string	"fopen %s error\n"
.LC9:
	.string	"%d %d"
.LC10:
	.string	"%f %f"
.LC11:
	.string	"malloc living[] error\n"
.LC12:
	.string	"%d"
.LC13:
	.string	"malloc honey[] error\n"
.LC14:
	.string	"%f"
.LC15:
	.string	"w"
.LC16:
	.string	"beehive_res.txt"
.LC17:
	.string	"%f "
.LC20:
	.string	"<%d, %d>:%f %f\n"
.LC21:
	.string	"\n"
.LC22:
	.string	"error: %d\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.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
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$72, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	cmpl	$2, %edi
	je	.L38
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	jmp	.L81
.L38:
	movq	8(%rsi), %rdi
	movq	%rsi, %rbx
	leaq	.LC7(%rip), %rsi
	call	fopen@PLT
	movq	%rax, %r13
	testq	%rax, %rax
	jne	.L40
	movq	8(%rbx), %rdx
	leaq	.LC8(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L39:
	movl	$1, %eax
	jmp	.L37
.L40:
	movq	%rax, %rdi
	leaq	28(%rsp), %rcx
	leaq	24(%rsp), %rdx
	xorl	%eax, %eax
	leaq	.LC9(%rip), %rsi
	xorl	%r14d, %r14d
	leaq	.LC12(%rip), %rbx
	call	__isoc23_fscanf@PLT
	leaq	36(%rsp), %rcx
	movq	%r13, %rdi
	xorl	%eax, %eax
	leaq	32(%rsp), %rdx
	leaq	.LC10(%rip), %rsi
	call	__isoc23_fscanf@PLT
	movl	24(%rsp), %edi
	imull	%edi, %edi
	movslq	%edi, %rdi
	salq	$2, %rdi
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L42
	leaq	.LC11(%rip), %rsi
.L82:
	movl	$2, %edi
	xorl	%eax, %eax
.L81:
	call	__printf_chk@PLT
	jmp	.L39
.L84:
	incl	%r14d
.L42:
	movl	24(%rsp), %r12d
	cmpl	%r14d, %r12d
	jle	.L83
	xorl	%r12d, %r12d
.L44:
	movl	24(%rsp), %eax
	cmpl	%r12d, %eax
	jle	.L84
	imull	%r14d, %eax
	movq	%rbx, %rsi
	movq	%r13, %rdi
	addl	%r12d, %eax
	incl	%r12d
	cltq
	leaq	0(%rbp,%rax,4), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	jmp	.L44
.L83:
	imull	%r12d, %r12d
	movslq	%r12d, %r12
	leaq	0(,%r12,4), %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, %r15
	movq	%rax, 40(%rsp)
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movq	%rax, %r14
	movq	%rax, 48(%rsp)
	call	malloc@PLT
	testq	%r15, %r15
	movq	%rax, %rbx
	sete	%al
	testq	%r14, %r14
	sete	%dl
	orb	%dl, %al
	jne	.L70
	xorl	%r15d, %r15d
	leaq	.LC14(%rip), %r14
	testq	%rbx, %rbx
	jne	.L45
.L70:
	leaq	.LC13(%rip), %rsi
	jmp	.L82
.L86:
	incl	%r15d
.L45:
	cmpl	%r15d, 24(%rsp)
	jle	.L85
	xorl	%r12d, %r12d
.L48:
	movl	24(%rsp), %eax
	cmpl	%r12d, %eax
	jle	.L86
	imull	%r15d, %eax
	movq	40(%rsp), %rdx
	movq	%r14, %rsi
	movq	%r13, %rdi
	addl	%r12d, %eax
	incl	%r12d
	cltq
	leaq	(%rdx,%rax,4), %rdx
	xorl	%eax, %eax
	call	__isoc23_fscanf@PLT
	jmp	.L48
.L85:
	movq	%r13, %rdi
	leaq	40(%rsp), %r13
	call	fclose@PLT
	movl	28(%rsp), %ecx
	movl	24(%rsp), %edx
	movq	%r13, %rsi
	movss	36(%rsp), %xmm1
	movss	32(%rsp), %xmm0
	movq	%rbp, %rdi
	call	_Z12calculateGPUPKiPPfiiff@PLT
	movl	24(%rsp), %r14d
	movq	8(%rsp), %rcx
	movq	%rbx, %rdi
	movq	48(%rsp), %rsi
	movl	%r14d, %edx
	imull	%r14d, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	__memcpy_chk@PLT
	movl	28(%rsp), %ecx
	movl	%r14d, %edx
	movq	%r13, %rsi
	movss	36(%rsp), %xmm1
	movss	32(%rsp), %xmm0
	movq	%rbp, %rdi
	xorl	%r14d, %r14d
	call	_Z12calculateCPUPKiPPfiiff
	leaq	.LC15(%rip), %rsi
	leaq	.LC16(%rip), %rdi
	movl	%eax, %r13d
	call	fopen@PLT
	movq	%rax, %r12
	xorl	%eax, %eax
	movl	%eax, 28(%rsp)
.L49:
	cmpl	%r14d, 24(%rsp)
	jle	.L87
	xorl	%r15d, %r15d
.L57:
	movl	24(%rsp), %eax
	cmpl	%r15d, %eax
	jle	.L88
	xorps	%xmm0, %xmm0
	cmpl	%r14d, %eax
	jle	.L50
	imull	%r14d, %eax
	addl	%r15d, %eax
	cltq
	cvtss2sd	(%rbx,%rax,4), %xmm0
.L50:
	leaq	.LC17(%rip), %rdx
	movl	$2, %esi
	movq	%r12, %rdi
	movb	$1, %al
	call	__fprintf_chk@PLT
	movl	24(%rsp), %eax
	cmpl	%r14d, %eax
	jle	.L65
	cmpl	%r15d, %eax
	jle	.L65
	movl	%eax, %edx
	movslq	%r13d, %rcx
	imull	%r14d, %edx
	movq	40(%rsp,%rcx,8), %rcx
	addl	%r15d, %edx
	movslq	%edx, %rdx
	movss	(%rcx,%rdx,4), %xmm0
	movss	(%rbx,%rdx,4), %xmm1
	jmp	.L51
.L65:
	xorps	%xmm0, %xmm0
	movaps	%xmm0, %xmm1
.L51:
	subss	%xmm1, %xmm0
	cmpl	%r15d, %eax
	jle	.L66
	cmpl	%r14d, %eax
	jle	.L66
	movl	%eax, %edx
	movslq	%r13d, %rcx
	imull	%r14d, %edx
	movq	40(%rsp,%rcx,8), %rcx
	addl	%r15d, %edx
	movslq	%edx, %rdx
	movss	(%rcx,%rdx,4), %xmm1
	jmp	.L52
.L66:
	xorps	%xmm1, %xmm1
.L52:
	divss	%xmm1, %xmm0
	andps	.LC18(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	comisd	.LC19(%rip), %xmm0
	jbe	.L53
	cmpl	%r14d, %eax
	jle	.L68
	cmpl	%r15d, %eax
	jle	.L68
	imull	%r14d, %eax
	movslq	%r13d, %rdx
	movq	40(%rsp,%rdx,8), %rdx
	addl	%r15d, %eax
	cltq
	cvtss2sd	(%rbx,%rax,4), %xmm1
	cvtss2sd	(%rdx,%rax,4), %xmm0
	jmp	.L55
.L68:
	xorps	%xmm1, %xmm1
	movaps	%xmm1, %xmm0
.L55:
	movl	%r15d, %ecx
	movl	%r14d, %edx
	leaq	.LC20(%rip), %rsi
	movb	$2, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	incl	28(%rsp)
.L53:
	incl	%r15d
	jmp	.L57
.L88:
	leaq	.LC21(%rip), %rdx
	movq	%r12, %rdi
	xorl	%eax, %eax
	incl	%r14d
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L49
.L87:
	movl	28(%rsp), %edx
	leaq	.LC22(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movq	%r12, %rdi
	call	fclose@PLT
	movq	40(%rsp), %rdi
	call	free@PLT
	movq	48(%rsp), %rdi
	call	free@PLT
	movq	%rbx, %rdi
	call	free@PLT
	movq	%rbp, %rdi
	call	free@PLT
	xorl	%eax, %eax
.L37:
	movq	56(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L58
	call	__stack_chk_fail@PLT
.L58:
	addq	$72, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2054:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2054:
	.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
.LC1:
	.long	0
	.long	1075838976
	.align 8
.LC2:
	.long	0
	.long	1072693248
	.align 8
.LC3:
	.long	0
	.long	1093567616
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC18:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst8
	.align 8
.LC19:
	.long	-350469331
	.long	1058682594
	.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 <stdlib.h>
#include <stdio.h>
#include <hip/hip_runtime.h>
#include <time.h>

//#define __DEBUG

#define element_addr(a, m, n, d) (a + ((m) * (d) + n))
#define element(a, m, n, d) (((m >= 0)&&(m < d)&&(n >= 0)&&(n < d))? (a[(m) * (d) + n]) : 0) 

#define CUDA_CALL(cmd) do { \
	if((err = cmd) != hipSuccess) { \
		printf("(%d) Cuda Error: %s\n", __LINE__, hipGetErrorString(err) ); \
	} \
} while(0)

int calculateGPU(const int *living, float *honey[2], int d, int n, float rbee, float rflow);
int calculateCPU(const int *living, float *honey[2], int d, int n, float rbee, float rflow);

int main(int argc, char **argv)
{
	FILE *fp;
	int d, n;
	float rbee, rflow;
	int *living;
	float *honey[2], *honeyr;
	int i, j;
	int resin;

	if (argc != 2) {
		printf("sampl0 <input_file>\n");
		return 1;
	}
	
	fp = fopen(argv[1], "r");
	if(fp == NULL) {
		printf("fopen %s error\n", argv[1]);
		return 1;
	}

	fscanf(fp, "%d %d", &d, &n);
	fscanf(fp, "%f %f", &rbee, &rflow);
#ifdef __DEBUG
	printf("D=%d N=%d\n", d, n);
	printf("R(bee)=%f R(flow)=%f\n", rbee, rflow);
#endif

	living = (int *) malloc( d * d * sizeof(int) );
	if(living == NULL) {
		printf("malloc living[] error\n");
		return 1;
	}
	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			fscanf(fp, "%d", element_addr(living, i, j, d));
		}
	}
#ifdef __DEBUG
	printf("livingmap = \n");
	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			printf("%d ", element(living, i, j, d));
		}
		printf("\n");
	}
#endif

	honey[0] = (float *)malloc( d * d * sizeof(float) );
	honey[1] = (float *)malloc( d * d * sizeof(float) );
	honeyr   = (float *)malloc( d * d * sizeof(float) );
	if(honey[0] == NULL || honey[1] == NULL || honeyr == NULL ) {
		printf("malloc honey[] error\n");
		return 1;
	}

	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			fscanf(fp, "%f", element_addr(honey[0], i, j, d));
		}
	}
#ifdef __DEBUG
	printf("honey = \n");
	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			printf("%f ", element(honey[0], i, j, d));
		}
		printf("\n");
	}
#endif
	fclose(fp);

	calculateGPU(living, honey, d, n, rbee, rflow); //always return in honey[1]

	memcpy(honeyr, honey[1], d * d * sizeof(float) );

	resin = calculateCPU(living, honey, d, n, rbee, rflow);
#ifdef __DEBUG
	printf("result is in honey[%d] \n",resin);
#endif

	fp = fopen("beehive_res.txt", "w");
	n = 0;
	for( i = 0; i < d; i++ ) {
		for( j = 0; j < d; j++ ) {
			fprintf(fp, "%f ", element(honeyr, i, j, d));
			if( fabs( (element(honey[resin], i, j, d) - element(honeyr, i, j, d)) / element(honey[resin], i, j, d) ) > 0.0001) {
			//if(element(honey[resin], i, j, d) != element(honeyr, i, j, d) ) {
				printf("<%d, %d>:%f %f\n", i, j, element(honey[resin], i, j, d), element(honeyr, i, j, d));
				n++;
			}
		}
		fprintf(fp, "\n");
	}
	printf("error: %d\n", n);

	fclose (fp);

	free(honey[0]);
	free(honey[1]);
	free(honeyr);
	free(living);

	return 0;
}

int calculateCPU(const int *living, float *honey[2], int d, int n, float rbee, float rflow)
{
	int ite;
	int src, resin = 0;
	int i, j;
	clock_t start, end;
	double time;

	start = clock();
	for(ite = 0; ite < n; ite++ ) {
		src = resin;
		resin = 1 - resin;

		for(i = 0; i < d; i++ ) {
			for(j = 0; j < d; j++ ) {
				*(element_addr(honey[resin], i, j, d)) = rflow * (
						element(honey[src], i-1, j-1, d) + element(honey[src], i-1, j, d) + element(honey[src], i-1, j+1, d) 
					  +	element(honey[src], i, j-1, d)   + element(honey[src], i, j+1, d)
					  +	element(honey[src], i+1, j-1, d) + element(honey[src], i+1, j, d) + element(honey[src], i+1, j+1, d) 
					) + (1.0 - 8.0 * rflow) * element(honey[src], i, j, d)
					+ rbee * element(living, i, j, d);
			}
		}
	}
	end = clock();
	time = ((double)(end-start))/CLOCKS_PER_SEC;
	printf("CPU computation: %lf sec\n", time);

	return resin;
}

	.text
	.file	"framework.hip"
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function main
.LCPI0_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI0_1:
	.quad	0x3f1a36e2eb1c432d              # double 1.0E-4
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	cmpl	$2, %edi
	jne	.LBB0_33
# %bb.1:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	movl	$.L.str.1, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB0_35
# %bb.2:
	movq	%rax, %r15
	movq	%rsp, %rbx
	leaq	4(%rsp), %rcx
	movl	$.L.str.3, %esi
	movq	%rax, %rdi
	movq	%rbx, %rdx
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	leaq	12(%rsp), %rdx
	leaq	8(%rsp), %rcx
	movl	$.L.str.4, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%rbx), %ebp
	movl	%ebp, %r14d
	imull	%r14d, %r14d
	shlq	$2, %r14
	movq	%r14, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB0_38
# %bb.3:                                # %.preheader126
	movq	%rax, %rbx
	testl	%ebp, %ebp
	jle	.LBB0_10
# %bb.4:                                # %.preheader125.preheader
	xorl	%r14d, %r14d
.LBB0_5:                                # %.preheader125
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_7 Depth 2
	testl	%ebp, %ebp
	jle	.LBB0_8
# %bb.6:                                # %.lr.ph.preheader
                                        #   in Loop: Header=BB0_5 Depth=1
	xorl	%r12d, %r12d
.LBB0_7:                                # %.lr.ph
                                        #   Parent Loop BB0_5 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	imull	%r14d, %ebp
	movslq	%ebp, %rax
	addq	%r12, %rax
	leaq	(%rbx,%rax,4), %rdx
	movl	$.L.str.6, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%rsp), %ebp
	incq	%r12
	cmpl	%ebp, %r12d
	jl	.LBB0_7
.LBB0_8:                                # %._crit_edge
                                        #   in Loop: Header=BB0_5 Depth=1
	incl	%r14d
	cmpl	%ebp, %r14d
	jl	.LBB0_5
# %bb.9:                                # %._crit_edge129.loopexit
	movl	%ebp, %r14d
	imull	%r14d, %r14d
	shlq	$2, %r14
.LBB0_10:                               # %._crit_edge129
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r12
	movq	%rax, 16(%rsp)
	movq	%r14, %rdi
	callq	malloc
	movq	%rax, %r13
	movq	%rax, 24(%rsp)
	movq	%r14, %rdi
	callq	malloc
	testq	%r12, %r12
	je	.LBB0_39
# %bb.11:                               # %._crit_edge129
	testq	%r13, %r13
	je	.LBB0_39
# %bb.12:                               # %._crit_edge129
	testq	%rax, %rax
	je	.LBB0_39
# %bb.13:                               # %.preheader124
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	testl	%ebp, %ebp
	jle	.LBB0_19
# %bb.14:                               # %.preheader123.preheader
	xorl	%r13d, %r13d
.LBB0_15:                               # %.preheader123
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_17 Depth 2
	testl	%ebp, %ebp
	jle	.LBB0_18
# %bb.16:                               # %.lr.ph131.preheader
                                        #   in Loop: Header=BB0_15 Depth=1
	xorl	%r14d, %r14d
.LBB0_17:                               # %.lr.ph131
                                        #   Parent Loop BB0_15 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	imull	%r13d, %ebp
	movslq	%ebp, %rax
	addq	%r14, %rax
	leaq	(%r12,%rax,4), %rdx
	movl	$.L.str.8, %esi
	movq	%r15, %rdi
	xorl	%eax, %eax
	callq	__isoc23_fscanf
	movl	(%rsp), %ebp
	incq	%r14
	cmpl	%ebp, %r14d
	jl	.LBB0_17
.LBB0_18:                               # %._crit_edge132
                                        #   in Loop: Header=BB0_15 Depth=1
	incl	%r13d
	cmpl	%ebp, %r13d
	jl	.LBB0_15
.LBB0_19:                               # %._crit_edge134
	movq	%r15, %rdi
	callq	fclose
	movl	(%rsp), %edx
	movl	4(%rsp), %ecx
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	8(%rsp), %xmm1                  # xmm1 = mem[0],zero,zero,zero
	leaq	16(%rsp), %r15
	movq	%rbx, %rdi
	movq	%r15, %rsi
	callq	_Z12calculateGPUPKiPPfiiff
	movq	8(%r15), %rsi
	movl	(%rsp), %ebp
	movl	%ebp, %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movq	32(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rdi
	callq	memcpy@PLT
	movl	4(%rsp), %ecx
	movss	12(%rsp), %xmm0                 # xmm0 = mem[0],zero,zero,zero
	movss	8(%rsp), %xmm1                  # xmm1 = mem[0],zero,zero,zero
	movq	%rbx, %rdi
	movq	%r15, %rsi
	movl	%ebp, %edx
	callq	_Z12calculateCPUPKiPPfiiff
	movl	%eax, %r12d
	movl	$.L.str.9, %edi
	movl	$.L.str.10, %esi
	callq	fopen
	movq	%rax, %r15
	movl	$0, 4(%rsp)
	movl	(%rsp), %eax
	xorl	%ebp, %ebp
	movl	$0, %esi
	testl	%eax, %eax
	jle	.LBB0_32
# %bb.20:                               # %.preheader.lr.ph
	movl	%r12d, %ebp
	xorl	%r12d, %r12d
.LBB0_21:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_23 Depth 2
	testl	%eax, %eax
	jle	.LBB0_30
# %bb.22:                               # %.lr.ph136.preheader
                                        #   in Loop: Header=BB0_21 Depth=1
	xorl	%r13d, %r13d
.LBB0_23:                               # %.lr.ph136
                                        #   Parent Loop BB0_21 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	xorps	%xmm0, %xmm0
	cmpl	%eax, %r12d
	jge	.LBB0_25
# %bb.24:                               #   in Loop: Header=BB0_23 Depth=2
	imull	%r12d, %eax
	addl	%r13d, %eax
	cltq
	movss	(%r14,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
.LBB0_25:                               #   in Loop: Header=BB0_23 Depth=2
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.11, %esi
	movq	%r15, %rdi
	movb	$1, %al
	callq	fprintf
	movl	(%rsp), %eax
	cmpl	%eax, %r12d
	jge	.LBB0_29
# %bb.26:                               #   in Loop: Header=BB0_23 Depth=2
	cmpl	%eax, %r13d
	jge	.LBB0_29
# %bb.27:                               #   in Loop: Header=BB0_23 Depth=2
	movq	16(%rsp,%rbp,8), %rcx
	movl	%r12d, %edx
	imull	%eax, %edx
	addl	%r13d, %edx
	movslq	%edx, %rdx
	movss	(%rcx,%rdx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	(%r14,%rdx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movaps	%xmm0, %xmm2
	subss	%xmm1, %xmm2
	divss	%xmm0, %xmm2
	andps	.LCPI0_0(%rip), %xmm2
	cvtss2sd	%xmm2, %xmm2
	ucomisd	.LCPI0_1(%rip), %xmm2
	jbe	.LBB0_29
# %bb.28:                               # %.thread122
                                        #   in Loop: Header=BB0_23 Depth=2
	cvtss2sd	%xmm0, %xmm0
	cvtss2sd	%xmm1, %xmm1
	movl	$.L.str.12, %edi
	movl	%r12d, %esi
	movl	%r13d, %edx
	movb	$2, %al
	callq	printf
	incl	4(%rsp)
	movl	(%rsp), %eax
.LBB0_29:                               # %.thread120
                                        #   in Loop: Header=BB0_23 Depth=2
	incl	%r13d
	cmpl	%eax, %r13d
	jl	.LBB0_23
.LBB0_30:                               # %._crit_edge137
                                        #   in Loop: Header=BB0_21 Depth=1
	movl	$10, %edi
	movq	%r15, %rsi
	callq	fputc@PLT
	incl	%r12d
	movl	(%rsp), %eax
	cmpl	%eax, %r12d
	jl	.LBB0_21
# %bb.31:                               # %._crit_edge139.loopexit
	movl	4(%rsp), %esi
	xorl	%ebp, %ebp
.LBB0_32:                               # %._crit_edge139
	movl	$.L.str.14, %edi
	xorl	%eax, %eax
	callq	printf
	movq	%r15, %rdi
	callq	fclose
	movq	16(%rsp), %rdi
	callq	free
	movq	24(%rsp), %rdi
	callq	free
	movq	%r14, %rdi
	callq	free
	movq	%rbx, %rdi
	callq	free
	jmp	.LBB0_37
.LBB0_33:
	movl	$.Lstr.2, %edi
.LBB0_34:
	callq	puts@PLT
	jmp	.LBB0_36
.LBB0_35:
	movq	8(%rbx), %rsi
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
.LBB0_36:
	movl	$1, %ebp
.LBB0_37:
	movl	%ebp, %eax
	addq	$40, %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
.LBB0_38:
	.cfi_def_cfa_offset 96
	movl	$.Lstr.1, %edi
	jmp	.LBB0_34
.LBB0_39:
	movl	$.Lstr, %edi
	jmp	.LBB0_34
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z12calculateCPUPKiPPfiiff
.LCPI1_0:
	.quad	0xc020000000000000              # double -8
.LCPI1_1:
	.quad	0x3ff0000000000000              # double 1
.LCPI1_2:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	_Z12calculateCPUPKiPPfiiff
	.type	_Z12calculateCPUPKiPPfiiff,@function
_Z12calculateCPUPKiPPfiiff:             # @_Z12calculateCPUPKiPPfiiff
	.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	$40, %rsp
	.cfi_def_cfa_offset 96
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movss	%xmm1, 12(%rsp)                 # 4-byte Spill
	movss	%xmm0, 16(%rsp)                 # 4-byte Spill
	movl	%ecx, %ebx
	movl	%edx, %r14d
	movq	%rsi, 32(%rsp)                  # 8-byte Spill
	movq	%rdi, %r13
	callq	clock
	movl	%ebx, 20(%rsp)                  # 4-byte Spill
	testl	%ebx, %ebx
	movq	%rax, 24(%rsp)                  # 8-byte Spill
	jle	.LBB1_1
# %bb.2:                                # %.lr.ph179
	movss	12(%rsp), %xmm9                 # 4-byte Reload
                                        # xmm9 = mem[0],zero,zero,zero
	xorps	%xmm0, %xmm0
	cvtss2sd	%xmm9, %xmm0
	mulsd	.LCPI1_0(%rip), %xmm0
	addsd	.LCPI1_1(%rip), %xmm0
	xorl	%eax, %eax
	xorl	%ecx, %ecx
	movss	16(%rsp), %xmm10                # 4-byte Reload
                                        # xmm10 = mem[0],zero,zero,zero
.LBB1_3:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_5 Depth 2
                                        #       Child Loop BB1_6 Depth 3
	movl	$1, %r12d
	subl	%ecx, %r12d
	testl	%r14d, %r14d
	jle	.LBB1_27
# %bb.4:                                # %.preheader.lr.ph
                                        #   in Loop: Header=BB1_3 Depth=1
	movl	%ecx, %ecx
	movl	%r12d, %edx
	movq	32(%rsp), %rsi                  # 8-byte Reload
	movq	(%rsi,%rcx,8), %rcx
	movq	(%rsi,%rdx,8), %rdx
	xorl	%esi, %esi
.LBB1_5:                                # %.preheader
                                        #   Parent Loop BB1_3 Depth=1
                                        # =>  This Loop Header: Depth=2
                                        #       Child Loop BB1_6 Depth 3
	leal	-1(%rsi), %edi
	imull	%r14d, %edi
	movl	%esi, %r9d
	imull	%r14d, %r9d
	leal	1(%rsi), %r8d
	movl	%r8d, %r10d
	imull	%r14d, %r10d
	xorl	%ebx, %ebx
.LBB1_6:                                #   Parent Loop BB1_3 Depth=1
                                        #     Parent Loop BB1_5 Depth=2
                                        # =>    This Inner Loop Header: Depth=3
	movl	%ebx, %r11d
	testl	%esi, %esi
	je	.LBB1_11
# %bb.7:                                #   in Loop: Header=BB1_6 Depth=3
	testl	%r11d, %r11d
	je	.LBB1_11
# %bb.8:                                # %.thread183
                                        #   in Loop: Header=BB1_6 Depth=3
	leal	(%r11,%rdi), %ebx
	movslq	%ebx, %rbx
	movss	-4(%rcx,%rbx,4), %xmm1          # xmm1 = mem[0],zero,zero,zero
	jmp	.LBB1_9
.LBB1_11:                               #   in Loop: Header=BB1_6 Depth=3
	xorps	%xmm1, %xmm1
	testl	%esi, %esi
	je	.LBB1_12
.LBB1_9:                                #   in Loop: Header=BB1_6 Depth=3
	leal	(%r11,%rdi), %ebx
	movslq	%ebx, %rbp
	movss	(%rcx,%rbp,4), %xmm2            # xmm2 = mem[0],zero,zero,zero
	leal	1(%r11), %ebx
	cmpl	%r14d, %ebx
	jge	.LBB1_10
# %bb.13:                               #   in Loop: Header=BB1_6 Depth=3
	movss	4(%rcx,%rbp,4), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movb	$1, %bpl
	jmp	.LBB1_14
.LBB1_10:                               #   in Loop: Header=BB1_6 Depth=3
	xorps	%xmm3, %xmm3
	xorl	%ebp, %ebp
	jmp	.LBB1_14
.LBB1_12:                               # %.thread
                                        #   in Loop: Header=BB1_6 Depth=3
	leal	1(%r11), %ebx
	cmpl	%r14d, %ebx
	setl	%bpl
	xorps	%xmm2, %xmm2
	xorps	%xmm3, %xmm3
.LBB1_14:                               #   in Loop: Header=BB1_6 Depth=3
	xorps	%xmm4, %xmm4
	xorps	%xmm5, %xmm5
	testl	%r11d, %r11d
	je	.LBB1_16
# %bb.15:                               #   in Loop: Header=BB1_6 Depth=3
	leal	(%r11,%r9), %r15d
	movslq	%r15d, %r15
	movss	-4(%rcx,%r15,4), %xmm5          # xmm5 = mem[0],zero,zero,zero
.LBB1_16:                               #   in Loop: Header=BB1_6 Depth=3
	testb	%bpl, %bpl
	je	.LBB1_18
# %bb.17:                               #   in Loop: Header=BB1_6 Depth=3
	leal	(%r11,%r9), %r15d
	movslq	%r15d, %r15
	movss	4(%rcx,%r15,4), %xmm4           # xmm4 = mem[0],zero,zero,zero
.LBB1_18:                               #   in Loop: Header=BB1_6 Depth=3
	xorps	%xmm6, %xmm6
	xorps	%xmm7, %xmm7
	cmpl	%r14d, %r8d
	jge	.LBB1_21
# %bb.19:                               #   in Loop: Header=BB1_6 Depth=3
	testl	%r11d, %r11d
	je	.LBB1_21
# %bb.20:                               #   in Loop: Header=BB1_6 Depth=3
	leal	(%r11,%r10), %r15d
	movslq	%r15d, %r15
	movss	-4(%rcx,%r15,4), %xmm7          # xmm7 = mem[0],zero,zero,zero
.LBB1_21:                               #   in Loop: Header=BB1_6 Depth=3
	cmpl	%r14d, %r8d
	jge	.LBB1_22
# %bb.23:                               #   in Loop: Header=BB1_6 Depth=3
	leal	(%r11,%r10), %r15d
	movslq	%r15d, %r15
	movss	(%rcx,%r15,4), %xmm8            # xmm8 = mem[0],zero,zero,zero
	testb	%bpl, %bpl
	je	.LBB1_25
# %bb.24:                               #   in Loop: Header=BB1_6 Depth=3
	movss	4(%rcx,%r15,4), %xmm6           # xmm6 = mem[0],zero,zero,zero
	jmp	.LBB1_25
.LBB1_22:                               #   in Loop: Header=BB1_6 Depth=3
	xorps	%xmm8, %xmm8
.LBB1_25:                               # %.thread170
                                        #   in Loop: Header=BB1_6 Depth=3
	addss	%xmm2, %xmm1
	addss	%xmm3, %xmm1
	addss	%xmm5, %xmm1
	addss	%xmm4, %xmm1
	addss	%xmm7, %xmm1
	addss	%xmm8, %xmm1
	addss	%xmm6, %xmm1
	mulss	%xmm9, %xmm1
	cvtss2sd	%xmm1, %xmm1
	addl	%r9d, %r11d
	movslq	%r11d, %r11
	xorps	%xmm2, %xmm2
	cvtss2sd	(%rcx,%r11,4), %xmm2
	mulsd	%xmm0, %xmm2
	xorps	%xmm3, %xmm3
	cvtsi2ssl	(%r13,%r11,4), %xmm3
	addsd	%xmm1, %xmm2
	mulss	%xmm10, %xmm3
	xorps	%xmm1, %xmm1
	cvtss2sd	%xmm3, %xmm1
	addsd	%xmm2, %xmm1
	cvtsd2ss	%xmm1, %xmm1
	movss	%xmm1, (%rdx,%r11,4)
	cmpl	%r14d, %ebx
	jl	.LBB1_6
# %bb.26:                               # %._crit_edge
                                        #   in Loop: Header=BB1_5 Depth=2
	movl	%r8d, %esi
	cmpl	%r14d, %r8d
	jne	.LBB1_5
.LBB1_27:                               # %._crit_edge175
                                        #   in Loop: Header=BB1_3 Depth=1
	incl	%eax
	movl	%r12d, %ecx
	cmpl	20(%rsp), %eax                  # 4-byte Folded Reload
	jne	.LBB1_3
	jmp	.LBB1_28
.LBB1_1:
	xorl	%r12d, %r12d
.LBB1_28:                               # %._crit_edge180
	callq	clock
	subq	24(%rsp), %rax                  # 8-byte Folded Reload
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI1_2(%rip), %xmm0
	movl	$.L.str.15, %edi
	movb	$1, %al
	callq	printf
	movl	%r12d, %eax
	addq	$40, %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	_Z12calculateCPUPKiPPfiiff, .Lfunc_end1-_Z12calculateCPUPKiPPfiiff
	.cfi_endproc
                                        # -- End function
	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"r"
	.size	.L.str.1, 2

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"fopen %s error\n"
	.size	.L.str.2, 16

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%f %f"
	.size	.L.str.4, 6

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

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

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"beehive_res.txt"
	.size	.L.str.9, 16

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

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"%f "
	.size	.L.str.11, 4

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

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"error: %d\n"
	.size	.L.str.14, 11

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"CPU computation: %lf sec\n"
	.size	.L.str.15, 26

	.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	"malloc honey[] error"
	.size	.Lstr, 21

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"malloc living[] error"
	.size	.Lstr.1, 22

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"sampl0 <input_file>"
	.size	.Lstr.2, 20

	.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_

	.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_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
