#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <random>

#include <sys/timeb.h>

#define BLOCK_SIZE 16

__global__ void Evolve(bool* field, float* scores, double b, int size, bool* next_field) 
{
	int row = blockIdx.y * blockDim.y + threadIdx.y;
	int col = blockIdx.x * blockDim.x + threadIdx.x;
	int memberIndex;

	// Score
	if (col >= size || row >= size)
		return;
	
	//printf("(%i, %i)\n", col, row);

	float score = 0;

	for (int i = -1; i <= 1; i++) //Row
	{
		for (int j = -1; j <= 1; j++) //Col
		{
			memberIndex = (col + i + size) % size + size * ((row + j + size) % size);

			if (field[memberIndex] == true)
				score++;
		}
	}

	if (!field[row*size + col])
		scores[row*size + col] = score * b;
	else
		scores[row*size + col] = score;
	
	
	__syncthreads();


	// Strategy
	int bestStrategyIndex = row*size + col;

	for (int i = -1; i <= 1; i++) //Row
	{
		for (int j = -1; j <= 1; j++) //Col
		{				
			memberIndex = (col + i + size) % size + size * ((row + j + size) % size);

			if (scores[bestStrategyIndex] < scores[memberIndex]) 
			{
				bestStrategyIndex = memberIndex;
			}
		}
	}

	next_field[row*size + col] = field[bestStrategyIndex];

	__syncthreads();
}



void InitField(bool* field, size_t size, int persentage) 
{
	for (size_t i = 0; i < size*size; i++) {
		field[i] = rand() % 100 > persentage;
	}
}

void PrintField(bool* field, int size) 
{
	printf("\n");
	for (int i = -1; i < size; i++) {
		for (size_t j = 0; j < size; j++)
		{
			if (i == -1) 
				printf("_");
			else
				printf("%s", field[i*size + j]? " " : "#");
		}
		printf("\n");
	}
}

int GetMilliCount() {
	timeb tb;
	ftime(&tb);
	int nCount = tb.millitm + (tb.time & 0xfffff) * 1000;
	return nCount;
}

int GetMilliSpan(int nTimeStart) {
	int nSpan = GetMilliCount() - nTimeStart;
	if (nSpan < 0)
		nSpan += 0x100000 * 1000;
	return nSpan;
}

int main(int argc, char * argv[])
{
	int start;

	// Main program

	bool* field;
	unsigned int size = atoi(argv[1]);
	double b = 1.81;

	unsigned int steps = 0;

	bool *d_field, *d_next_field;
	float *d_scores;

	field = (bool*)malloc(sizeof(bool)*size*size);

	// GPU Memory
	cudaMalloc((void**)&d_field, sizeof(bool)*size*size);
	cudaMalloc((void**)&d_scores, sizeof(float)*size*size);
	cudaMalloc((void**)&d_next_field, sizeof(bool)*size*size);

	InitField(field, size, 21);

	unsigned int grid_rows = (size + BLOCK_SIZE - 1) / BLOCK_SIZE;
	unsigned int grid_cols = (size + BLOCK_SIZE - 1) / BLOCK_SIZE;

	dim3 blockSize;
	dim3 gridSize;

	blockSize = dim3(BLOCK_SIZE, BLOCK_SIZE, 1);
	gridSize = dim3(grid_rows, grid_cols, 1);
	
	start = GetMilliCount();

	for (size_t i = 0; i < 1000 && GetMilliSpan(start) < 1000; i++)
	{
		steps++;
		// Init scores with zeros in GPU Memory		
		cudaMemcpy(d_field, field, size * size, cudaMemcpyKind::cudaMemcpyHostToDevice);

		cudaMemset(d_scores, 0, size * size);

		Evolve<<<gridSize, blockSize>>>(d_field, d_scores, b, size, d_next_field);

		//printf("%s\n", cudaGetErrorString(cudaGetLastError()));

		cudaMemcpy(field, d_next_field, size*size, cudaMemcpyKind::cudaMemcpyDeviceToHost);

	}

	printf("[%i, %f, %i]\n", size, GetMilliSpan(start) * 0.001 / steps, steps);

	cudaFree(d_field);
	cudaFree(d_next_field);
	cudaFree(d_scores);

    return 0;
}

	.file	"tmpxft_00220abf_00000000-6_kernel.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4115:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4115:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z9InitFieldPbmi
	.type	_Z9InitFieldPbmi, @function
_Z9InitFieldPbmi:
.LFB4108:
	.cfi_startproc
	endbr64
	imulq	%rsi, %rsi
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$100, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	leaq	(%rdi,%rsi), %rbp
	movq	%rdi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 48
.L3:
	cmpq	%rbp, %rbx
	je	.L7
	call	rand@PLT
	cltd
	idivl	%r13d
	cmpl	%r12d, %edx
	setg	(%rbx)
	incq	%rbx
	jmp	.L3
.L7:
	popq	%rax
	.cfi_def_cfa_offset 40
	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
.LFE4108:
	.size	_Z9InitFieldPbmi, .-_Z9InitFieldPbmi
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	" "
.LC1:
	.string	"#"
.LC2:
	.string	"\n"
.LC3:
	.string	"_"
.LC4:
	.string	"%s"
	.text
	.globl	_Z10PrintFieldPbi
	.type	_Z10PrintFieldPbi, @function
_Z10PrintFieldPbi:
.LFB4109:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movslq	%esi, %r15
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rsi
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	movl	$2, %edi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	movl	%r15d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	negl	%r13d
	orl	$-1, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%r15, %rbx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	__printf_chk@PLT
.L9:
	cmpl	%ebx, %r12d
	jge	.L8
	movslq	%r13d, %rax
	xorl	%ebp, %ebp
	movq	%rax, 8(%rsp)
.L15:
	cmpq	%r15, %rbp
	jnb	.L18
	cmpl	$-1, %r12d
	jne	.L10
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L11
.L10:
	movq	8(%rsp), %rax
	leaq	.LC1(%rip), %rdx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	addq	%r14, %rax
	cmpb	$0, (%rax,%rbp)
	leaq	.LC0(%rip), %rax
	cmovne	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L11:
	incq	%rbp
	jmp	.L15
.L18:
	leaq	.LC2(%rip), %rsi
	xorl	%eax, %eax
	incl	%r12d
	addl	%ebx, %r13d
	movl	$2, %edi
	call	__printf_chk@PLT
	jmp	.L9
.L8:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4109:
	.size	_Z10PrintFieldPbi, .-_Z10PrintFieldPbi
	.globl	_Z13GetMilliCountv
	.type	_Z13GetMilliCountv, @function
_Z13GetMilliCountv:
.LFB4110:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	ftime@PLT
	movl	8(%rsp), %eax
	movzwl	16(%rsp), %edx
	andl	$1048575, %eax
	imull	$1000, %eax, %eax
	addl	%edx, %eax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L20
	call	__stack_chk_fail@PLT
.L20:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4110:
	.size	_Z13GetMilliCountv, .-_Z13GetMilliCountv
	.globl	_Z12GetMilliSpani
	.type	_Z12GetMilliSpani, @function
_Z12GetMilliSpani:
.LFB4111:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	%edi, %ebx
	call	_Z13GetMilliCountv
	subl	%ebx, %eax
	jns	.L22
	addl	$1048576000, %eax
.L22:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4111:
	.size	_Z12GetMilliSpani, .-_Z12GetMilliSpani
	.globl	_Z31__device_stub__Z6EvolvePbPfdiS_PbPfdiS_
	.type	_Z31__device_stub__Z6EvolvePbPfdiS_PbPfdiS_, @function
_Z31__device_stub__Z6EvolvePbPfdiS_PbPfdiS_:
.LFB4137:
	.cfi_startproc
	endbr64
	subq	$168, %rsp
	.cfi_def_cfa_offset 176
	movq	%rdi, 40(%rsp)
	leaq	64(%rsp), %rdi
	movq	%rsi, 32(%rsp)
	leaq	76(%rsp), %rsi
	movl	%edx, 20(%rsp)
	leaq	48(%rsp), %rdx
	movq	%rcx, 8(%rsp)
	leaq	56(%rsp), %rcx
	movsd	%xmm0, 24(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 152(%rsp)
	xorl	%eax, %eax
	leaq	40(%rsp), %rax
	movl	$1, 72(%rsp)
	movq	%rax, 112(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	24(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 144(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 64(%rsp)
	movq	%rax, 76(%rsp)
	movl	$1, 84(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L25
	pushq	56(%rsp)
	.cfi_def_cfa_offset 184
	leaq	_Z6EvolvePbPfdiS_(%rip), %rdi
	pushq	56(%rsp)
	.cfi_def_cfa_offset 192
	movq	92(%rsp), %rcx
	movl	100(%rsp), %r8d
	movq	80(%rsp), %rsi
	movl	88(%rsp), %edx
	leaq	128(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 184
	popq	%rdx
	.cfi_def_cfa_offset 176
.L25:
	movq	152(%rsp), %rax
	subq	%fs:40, %rax
	je	.L27
	call	__stack_chk_fail@PLT
.L27:
	addq	$168, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4137:
	.size	_Z31__device_stub__Z6EvolvePbPfdiS_PbPfdiS_, .-_Z31__device_stub__Z6EvolvePbPfdiS_PbPfdiS_
	.globl	_Z6EvolvePbPfdiS_
	.type	_Z6EvolvePbPfdiS_, @function
_Z6EvolvePbPfdiS_:
.LFB4138:
	.cfi_startproc
	endbr64
	jmp	_Z31__device_stub__Z6EvolvePbPfdiS_PbPfdiS_
	.cfi_endproc
.LFE4138:
	.size	_Z6EvolvePbPfdiS_, .-_Z6EvolvePbPfdiS_
	.section	.rodata.str1.1
.LC7:
	.string	"[%i, %f, %i]\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB4112:
	.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	8(%rsi), %rdi
	movq	%fs:40, %rax
	movq	%rax, 56(%rsp)
	xorl	%eax, %eax
	call	atoi@PLT
	movl	%eax, %ebp
	movq	%rbp, %r12
	movq	%rbp, %rbx
	imulq	%rbp, %r12
	movq	%r12, %rdi
	call	malloc@PLT
	leaq	8(%rsp), %rdi
	movq	%r12, %rsi
	movq	%rax, %r13
	call	cudaMalloc@PLT
	leaq	0(,%r12,4), %rsi
	leaq	24(%rsp), %rdi
	call	cudaMalloc@PLT
	leaq	16(%rsp), %rdi
	movq	%r12, %rsi
	call	cudaMalloc@PLT
	movq	%rbp, %rsi
	movl	$21, %edx
	movq	%r13, %rdi
	call	_Z9InitFieldPbmi
	leal	15(%rbp), %eax
	xorl	%ebp, %ebp
	movabsq	$68719476752, %rdx
	shrl	$4, %eax
	movl	$1, 52(%rsp)
	movq	%rdx, 32(%rsp)
	movl	$1, 40(%rsp)
	movl	%eax, 44(%rsp)
	movl	%eax, 48(%rsp)
	call	_Z13GetMilliCountv
	movl	%eax, %r14d
.L31:
	movl	%r14d, %edi
	call	_Z12GetMilliSpani
	cmpl	$999, %eax
	jg	.L32
	movq	8(%rsp), %rdi
	movl	%r12d, %r15d
	movl	$1, %ecx
	movq	%r13, %rsi
	movq	%r15, %rdx
	incl	%ebp
	call	cudaMemcpy@PLT
	movq	24(%rsp), %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	call	cudaMemset@PLT
	movl	40(%rsp), %ecx
	movl	52(%rsp), %esi
	xorl	%r9d, %r9d
	movq	32(%rsp), %rdx
	movq	44(%rsp), %rdi
	xorl	%r8d, %r8d
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L33
	movq	16(%rsp), %rcx
	movsd	.LC5(%rip), %xmm0
	movl	%ebx, %edx
	movq	24(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	_Z31__device_stub__Z6EvolvePbPfdiS_PbPfdiS_
.L33:
	movq	16(%rsp), %rsi
	movl	$2, %ecx
	movq	%r15, %rdx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	cmpl	$1000, %ebp
	jne	.L31
.L32:
	movl	%r14d, %edi
	call	_Z12GetMilliSpani
	cvtsi2sdl	%ebp, %xmm1
	movl	%ebp, %ecx
	movl	%ebx, %edx
	cvtsi2sdl	%eax, %xmm0
	mulsd	.LC6(%rip), %xmm0
	leaq	.LC7(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	divsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	16(%rsp), %rdi
	call	cudaFree@PLT
	movq	24(%rsp), %rdi
	call	cudaFree@PLT
	movq	56(%rsp), %rax
	subq	%fs:40, %rax
	je	.L35
	call	__stack_chk_fail@PLT
.L35:
	addq	$72, %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
.LFE4112:
	.size	main, .-main
	.section	.rodata.str1.1
.LC8:
	.string	"_Z6EvolvePbPfdiS_"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4140:
	.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	_Z6EvolvePbPfdiS_(%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
.LFE4140:
	.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
.LC5:
	.long	-1889785610
	.long	1073542594
	.align 8
.LC6:
	.long	-755914244
	.long	1062232653
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:

#include "hip/hip_runtime.h"


#include <stdio.h>
#include <random>

#include <sys/timeb.h>

#define BLOCK_SIZE 16

__global__ void Evolve(bool* field, float* scores, double b, int size, bool* next_field) 
{
	int row = blockIdx.y * blockDim.y + threadIdx.y;
	int col = blockIdx.x * blockDim.x + threadIdx.x;
	int memberIndex;

	// Score
	if (col >= size || row >= size)
		return;
	
	//printf("(%i, %i)\n", col, row);

	float score = 0;

	for (int i = -1; i <= 1; i++) //Row
	{
		for (int j = -1; j <= 1; j++) //Col
		{
			memberIndex = (col + i + size) % size + size * ((row + j + size) % size);

			if (field[memberIndex] == true)
				score++;
		}
	}

	if (!field[row*size + col])
		scores[row*size + col] = score * b;
	else
		scores[row*size + col] = score;
	
	
	__syncthreads();


	// Strategy
	int bestStrategyIndex = row*size + col;

	for (int i = -1; i <= 1; i++) //Row
	{
		for (int j = -1; j <= 1; j++) //Col
		{				
			memberIndex = (col + i + size) % size + size * ((row + j + size) % size);

			if (scores[bestStrategyIndex] < scores[memberIndex]) 
			{
				bestStrategyIndex = memberIndex;
			}
		}
	}

	next_field[row*size + col] = field[bestStrategyIndex];

	__syncthreads();
}



void InitField(bool* field, size_t size, int persentage) 
{
	for (size_t i = 0; i < size*size; i++) {
		field[i] = rand() % 100 > persentage;
	}
}

void PrintField(bool* field, int size) 
{
	printf("\n");
	for (int i = -1; i < size; i++) {
		for (size_t j = 0; j < size; j++)
		{
			if (i == -1) 
				printf("_");
			else
				printf("%s", field[i*size + j]? " " : "#");
		}
		printf("\n");
	}
}

int GetMilliCount() {
	timeb tb;
	ftime(&tb);
	int nCount = tb.millitm + (tb.time & 0xfffff) * 1000;
	return nCount;
}

int GetMilliSpan(int nTimeStart) {
	int nSpan = GetMilliCount() - nTimeStart;
	if (nSpan < 0)
		nSpan += 0x100000 * 1000;
	return nSpan;
}

int main(int argc, char * argv[])
{
	int start;

	// Main program

	bool* field;
	unsigned int size = atoi(argv[1]);
	double b = 1.81;

	unsigned int steps = 0;

	bool *d_field, *d_next_field;
	float *d_scores;

	field = (bool*)malloc(sizeof(bool)*size*size);

	// GPU Memory
	hipMalloc((void**)&d_field, sizeof(bool)*size*size);
	hipMalloc((void**)&d_scores, sizeof(float)*size*size);
	hipMalloc((void**)&d_next_field, sizeof(bool)*size*size);

	InitField(field, size, 21);

	unsigned int grid_rows = (size + BLOCK_SIZE - 1) / BLOCK_SIZE;
	unsigned int grid_cols = (size + BLOCK_SIZE - 1) / BLOCK_SIZE;

	dim3 blockSize;
	dim3 gridSize;

	blockSize = dim3(BLOCK_SIZE, BLOCK_SIZE, 1);
	gridSize = dim3(grid_rows, grid_cols, 1);
	
	start = GetMilliCount();

	for (size_t i = 0; i < 1000 && GetMilliSpan(start) < 1000; i++)
	{
		steps++;
		// Init scores with zeros in GPU Memory		
		hipMemcpy(d_field, field, size * size, hipMemcpyKind::hipMemcpyHostToDevice);

		hipMemset(d_scores, 0, size * size);

		Evolve<<<gridSize, blockSize>>>(d_field, d_scores, b, size, d_next_field);

		//printf("%s\n", cudaGetErrorString(cudaGetLastError()));

		hipMemcpy(field, d_next_field, size*size, hipMemcpyKind::hipMemcpyDeviceToHost);

	}

	printf("[%i, %f, %i]\n", size, GetMilliSpan(start) * 0.001 / steps, steps);

	hipFree(d_field);
	hipFree(d_next_field);
	hipFree(d_scores);

    return 0;
}

	.text
	.file	"kernel.hip"
	.globl	_Z21__device_stub__EvolvePbPfdiS_ # -- Begin function _Z21__device_stub__EvolvePbPfdiS_
	.type	_Z21__device_stub__EvolvePbPfdiS_,@function
_Z21__device_stub__EvolvePbPfdiS_:      # @_Z21__device_stub__EvolvePbPfdiS_
	.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	56(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	48(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	40(%rsp), %rsi
	movsd	%xmm0, (%rsi)
	leaq	12(%rsp), %r8
	movl	%edx, (%r8)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	96(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%r8, 24(%rbx)
	movq	%rdx, 32(%rbx)
	leaq	80(%rsp), %r14
	leaq	64(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z6EvolvePbPfdiS_, %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_end0:
	.size	_Z21__device_stub__EvolvePbPfdiS_, .Lfunc_end0-_Z21__device_stub__EvolvePbPfdiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9InitFieldPbmi                # -- Begin function _Z9InitFieldPbmi
	.type	_Z9InitFieldPbmi,@function
_Z9InitFieldPbmi:                       # @_Z9InitFieldPbmi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r12
	.cfi_def_cfa_offset 32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	pushq	%rax
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movq	%rsi, %r14
	imulq	%rsi, %r14
	testq	%r14, %r14
	je	.LBB1_3
# %bb.1:                                # %.lr.ph.preheader
	movl	%edx, %ebx
	movq	%rdi, %r15
	xorl	%r12d, %r12d
.LBB1_2:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	cmpl	%ebx, %eax
	setg	(%r15,%r12)
	incq	%r12
	cmpq	%r12, %r14
	jne	.LBB1_2
.LBB1_3:                                # %._crit_edge
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z9InitFieldPbmi, .Lfunc_end1-_Z9InitFieldPbmi
	.cfi_endproc
                                        # -- End function
	.globl	_Z10PrintFieldPbi               # -- Begin function _Z10PrintFieldPbi
	.type	_Z10PrintFieldPbi,@function
_Z10PrintFieldPbi:                      # @_Z10PrintFieldPbi
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%esi, %ebx
	movq	%rdi, %r14
	movl	$10, %edi
	callq	putchar@PLT
	testl	%ebx, %ebx
	js	.LBB2_4
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebx, %r15d
	movq	%r15, %r12
	negq	%r12
	movq	$-1, %r13
.LBB2_2:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_5 Depth 2
	movq	%r12, %rbp
	testl	%ebx, %ebx
	je	.LBB2_3
.LBB2_5:                                #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cmpq	$-1, %r13
	je	.LBB2_6
# %bb.7:                                #   in Loop: Header=BB2_5 Depth=2
	cmpb	$0, (%r14,%rbp)
	movl	$.L.str.4, %esi
	je	.LBB2_9
# %bb.8:                                #   in Loop: Header=BB2_5 Depth=2
	movl	$.L.str.3, %esi
.LBB2_9:                                #   in Loop: Header=BB2_5 Depth=2
	movl	$.L.str.2, %edi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB2_10
.LBB2_6:                                #   in Loop: Header=BB2_5 Depth=2
	movl	$95, %edi
	callq	putchar@PLT
.LBB2_10:                               #   in Loop: Header=BB2_5 Depth=2
	incq	%rbp
	jne	.LBB2_5
.LBB2_3:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r13
	addq	%r15, %r14
	cmpq	%r15, %r13
	jne	.LBB2_2
.LBB2_4:                                # %._crit_edge16
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z10PrintFieldPbi, .Lfunc_end2-_Z10PrintFieldPbi
	.cfi_endproc
                                        # -- End function
	.globl	_Z13GetMilliCountv              # -- Begin function _Z13GetMilliCountv
	.type	_Z13GetMilliCountv,@function
_Z13GetMilliCountv:                     # @_Z13GetMilliCountv
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -16
	movq	%rsp, %rbx
	movq	%rbx, %rdi
	callq	ftime
	movl	$1048575, %eax                  # imm = 0xFFFFF
	andl	(%rbx), %eax
	movzwl	8(%rbx), %ecx
	imull	$1000, %eax, %eax               # imm = 0x3E8
	addl	%ecx, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z13GetMilliCountv, .Lfunc_end3-_Z13GetMilliCountv
	.cfi_endproc
                                        # -- End function
	.globl	_Z12GetMilliSpani               # -- Begin function _Z12GetMilliSpani
	.type	_Z12GetMilliSpani,@function
_Z12GetMilliSpani:                      # @_Z12GetMilliSpani
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	movl	%edi, %ebx
	leaq	8(%rsp), %r14
	movq	%r14, %rdi
	callq	ftime
	movzwl	8(%r14), %eax
	movl	$1048575, %ecx                  # imm = 0xFFFFF
	andl	(%r14), %ecx
	imull	$1000, %ecx, %ecx               # imm = 0x3E8
	addl	%eax, %ecx
	subl	%ebx, %ecx
	leal	1048576000(%rcx), %eax
	testl	%ecx, %ecx
	cmovnsl	%ecx, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end4:
	.size	_Z12GetMilliSpani, .Lfunc_end4-_Z12GetMilliSpani
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI5_0:
	.quad	0x3ffcf5c28f5c28f6              # double 1.8100000000000001
.LCPI5_1:
	.quad	0x3f50624dd2f1a9fc              # double 0.001
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	.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	8(%rsi), %rdi
	callq	atoi
	movl	%eax, %r15d
	movl	%eax, %ebx
	imulq	%rbx, %rbx
	movq	%rbx, %rdi
	callq	malloc
	movq	%rax, %r14
	leaq	32(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	leaq	(,%rbx,4), %rsi
	leaq	16(%rsp), %rdi
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movq	%rbx, %rsi
	callq	hipMalloc
	movq	%r15, 8(%rsp)                   # 8-byte Spill
	testl	%r15d, %r15d
	je	.LBB5_3
# %bb.1:                                # %.lr.ph.i.preheader
	xorl	%r15d, %r15d
.LBB5_2:                                # %.lr.ph.i
                                        # =>This Inner Loop Header: Depth=1
	callq	rand
	cltq
	imulq	$1374389535, %rax, %rcx         # imm = 0x51EB851F
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$37, %rcx
	addl	%edx, %ecx
	imull	$100, %ecx, %ecx
	subl	%ecx, %eax
	cmpl	$22, %eax
	setge	(%r14,%r15)
	incq	%r15
	cmpq	%r15, %rbx
	jne	.LBB5_2
.LBB5_3:                                # %_Z9InitFieldPbmi.exit
	movq	8(%rsp), %rbp                   # 8-byte Reload
	leal	15(%rbp), %eax
	shrl	$4, %eax
	movq	%rax, %r12
	shlq	$32, %r12
	orq	%rax, %r12
	leaq	40(%rsp), %r13
	movq	%r13, %rdi
	callq	ftime
	movzwl	8(%r13), %eax
	movl	$1048575, %edx                  # imm = 0xFFFFF
	movl	(%r13), %ecx
	andl	%edx, %ecx
	imull	$1000, %ecx, %ebx               # imm = 0x3E8
	addl	%eax, %ebx
                                        # kill: def $ebp killed $ebp killed $rbp def $rbp
	imull	%ebp, %ebp
	xorl	%r15d, %r15d
.LBB5_4:                                # =>This Inner Loop Header: Depth=1
	movq	%r13, %rdi
	callq	ftime
	movzwl	48(%rsp), %eax
	movl	40(%rsp), %ecx
	movl	$1048575, %edx                  # imm = 0xFFFFF
	andl	%edx, %ecx
	imull	$1000, %ecx, %ecx               # imm = 0x3E8
	addl	%eax, %ecx
	subl	%ebx, %ecx
	leal	1048576000(%rcx), %eax
	testl	%ecx, %ecx
	cmovnsl	%ecx, %eax
	movl	$1000, %ecx                     # imm = 0x3E8
	cmpl	%ecx, %eax
	jge	.LBB5_9
# %bb.5:                                #   in Loop: Header=BB5_4 Depth=1
	movq	32(%rsp), %rdi
	movq	%r14, %rsi
	movq	%rbp, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	movq	%rbp, %rdx
	callq	hipMemset
	movq	%r12, %rdi
	movl	$1, %esi
	movabsq	$68719476752, %rdx              # imm = 0x1000000010
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB5_7
# %bb.6:                                #   in Loop: Header=BB5_4 Depth=1
	movq	32(%rsp), %rdi
	movq	16(%rsp), %rsi
	movq	24(%rsp), %rcx
	movsd	.LCPI5_0(%rip), %xmm0           # xmm0 = mem[0],zero
	movq	8(%rsp), %rdx                   # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	callq	_Z21__device_stub__EvolvePbPfdiS_
.LBB5_7:                                #   in Loop: Header=BB5_4 Depth=1
	incq	%r15
	movq	24(%rsp), %rsi
	movq	%r14, %rdi
	movq	%rbp, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	cmpq	$1000, %r15                     # imm = 0x3E8
	jne	.LBB5_4
# %bb.8:
	movl	$1000, %r15d                    # imm = 0x3E8
.LBB5_9:                                # %.critedge
	leaq	40(%rsp), %r14
	movq	%r14, %rdi
	callq	ftime
	movl	$1048575, %eax                  # imm = 0xFFFFF
	andl	(%r14), %eax
	movzwl	8(%r14), %ecx
	imull	$1000, %eax, %eax               # imm = 0x3E8
	addl	%ecx, %eax
	subl	%ebx, %eax
	leal	1048576000(%rax), %ecx
	testl	%eax, %eax
	cmovnsl	%eax, %ecx
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ecx, %xmm0
	mulsd	.LCPI5_1(%rip), %xmm0
	movl	%r15d, %eax
	cvtsi2sd	%rax, %xmm1
	divsd	%xmm1, %xmm0
	movl	$.L.str.5, %edi
	movq	8(%rsp), %rsi                   # 8-byte Reload
                                        # kill: def $esi killed $esi killed $rsi
	movl	%r15d, %edx
	movb	$1, %al
	callq	printf
	movq	32(%rsp), %rdi
	callq	hipFree
	movq	24(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	xorl	%eax, %eax
	addq	$56, %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_end5:
	.size	main, .Lfunc_end5-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	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6EvolvePbPfdiS_, %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_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__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	.LBB7_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
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z6EvolvePbPfdiS_,@object       # @_Z6EvolvePbPfdiS_
	.section	.rodata,"a",@progbits
	.globl	_Z6EvolvePbPfdiS_
	.p2align	3, 0x0
_Z6EvolvePbPfdiS_:
	.quad	_Z21__device_stub__EvolvePbPfdiS_
	.size	_Z6EvolvePbPfdiS_, 8

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

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"[%i, %f, %i]\n"
	.size	.L.str.5, 14

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6EvolvePbPfdiS_"
	.size	.L__unnamed_1, 18

	.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 _Z21__device_stub__EvolvePbPfdiS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6EvolvePbPfdiS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6EvolvePbPfdiS_       ; -- Begin function _Z6EvolvePbPfdiS_
	.globl	_Z6EvolvePbPfdiS_
	.p2align	8
	.type	_Z6EvolvePbPfdiS_,@function
_Z6EvolvePbPfdiS_:                      ; @_Z6EvolvePbPfdiS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x34
	s_load_b32 s8, s[0:1], 0x18
	v_and_b32_e32 v3, 0x3ff, v0
	v_bfe_u32 v2, v0, 10, 10
	s_waitcnt lgkmcnt(0)
	s_lshr_b32 s3, s2, 16
	s_and_b32 s2, s2, 0xffff
	s_mul_i32 s15, s15, s3
	v_mad_u64_u32 v[0:1], null, s14, s2, v[3:4]
	v_add_nc_u32_e32 v8, s15, v2
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_max_i32_e32 v1, v8, v0
	v_cmpx_gt_i32_e64 s8, v1
	s_cbranch_execz .LBB0_12
; %bb.1:                                ; %.preheader79
	s_ashr_i32 s2, s8, 31
	v_add_nc_u32_e32 v5, s8, v0
	s_add_i32 s3, s8, s2
	v_add3_u32 v7, s15, s8, v2
	s_xor_b32 s9, s3, s2
	s_mov_b32 s10, -1
	v_cvt_f32_u32_e32 v1, s9
	s_sub_i32 s2, 0, s9
	v_mov_b32_e32 v4, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v1, v1
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v1, 0x4f7ffffe, v1
	v_cvt_u32_f32_e32 v1, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, s2, v1
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b64 s[2:3], s[0:1], 0x10
	v_mul_hi_u32 v3, v1, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_add_nc_u32_e32 v6, v1, v3
.LBB0_2:                                ; %.preheader78
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	v_add_nc_u32_e32 v1, s10, v5
	s_mov_b32 s11, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v2, 31, v1
	v_add_nc_u32_e32 v1, v1, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v1, v1, v2
	v_mul_hi_u32 v3, v1, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, v3, s9
	v_sub_nc_u32_e32 v1, v1, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v3, s9, v1
	v_cmp_le_u32_e32 vcc_lo, s9, v1
	v_cndmask_b32_e32 v1, v1, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v3, s9, v1
	v_cmp_le_u32_e32 vcc_lo, s9, v1
	v_cndmask_b32_e32 v1, v1, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v1, v1, v2
	v_sub_nc_u32_e32 v1, v1, v2
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v2, s11, v7
	s_add_i32 s11, s11, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s11, 2
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v2, v2, v3
	v_xor_b32_e32 v2, v2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v9, v2, v6
	v_mul_lo_u32 v9, v9, s9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v2, v2, v9
	v_subrev_nc_u32_e32 v9, s9, v2
	v_cmp_le_u32_e32 vcc_lo, s9, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v2, v2, v9, vcc_lo
	v_subrev_nc_u32_e32 v9, s9, v2
	v_cmp_le_u32_e32 vcc_lo, s9, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v2, v2, v9, vcc_lo
	v_xor_b32_e32 v2, v2, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v9, v2, v3
	v_mad_u64_u32 v[2:3], null, v9, s8, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v3, 31, v2
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_u8 v2, v[2:3], off
	v_add_f32_e32 v3, 1.0, v4
	s_waitcnt vmcnt(0)
	v_cmp_eq_u16_e32 vcc_lo, 0, v2
	s_delay_alu instid0(VALU_DEP_2)
	v_cndmask_b32_e32 v4, v3, v4, vcc_lo
	s_cbranch_scc0 .LBB0_3
; %bb.4:                                ;   in Loop: Header=BB0_2 Depth=1
	s_add_i32 s10, s10, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s10, 2
	s_cbranch_scc0 .LBB0_2
; %bb.5:
	v_mad_u64_u32 v[2:3], null, v8, s8, v[0:1]
	s_mov_b32 s10, exec_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_mov_b32_e32 v0, v2
	v_ashrrev_i32_e32 v1, 31, v2
	v_add_co_u32 v8, vcc_lo, s4, v0
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v9, vcc_lo, s5, v1, vcc_lo
	global_load_u8 v3, v[8:9], off
	s_waitcnt vmcnt(0)
	v_cmpx_eq_u16_e32 0, v3
; %bb.6:
	v_cvt_f64_f32_e32 v[3:4], v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f64 v[3:4], v[3:4], s[2:3]
	v_cvt_f32_f64_e32 v4, v[3:4]
; %bb.7:
	s_or_b32 exec_lo, exec_lo, s10
	v_lshlrev_b64 v[8:9], 2, v[0:1]
	s_mov_b32 s2, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v8, vcc_lo, s6, v8
	v_add_co_ci_u32_e32 v9, vcc_lo, s7, v9, vcc_lo
	global_store_b32 v[8:9], v4, off
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
.LBB0_8:                                ; %.preheader
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_9 Depth 2
	v_add_nc_u32_e32 v3, s2, v5
	s_mov_b32 s3, -1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v4, 31, v3
	v_add_nc_u32_e32 v3, v3, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v3, v3, v4
	v_mul_hi_u32 v8, v3, v6
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v8, v8, s9
	v_sub_nc_u32_e32 v3, v3, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v8, s9, v3
	v_cmp_le_u32_e32 vcc_lo, s9, v3
	v_cndmask_b32_e32 v3, v3, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_subrev_nc_u32_e32 v8, s9, v3
	v_cmp_le_u32_e32 vcc_lo, s9, v3
	v_cndmask_b32_e32 v3, v3, v8, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_xor_b32_e32 v3, v3, v4
	v_sub_nc_u32_e32 v4, v3, v4
.LBB0_9:                                ;   Parent Loop BB0_8 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v3, s3, v7
	s_add_i32 s3, s3, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	s_cmp_eq_u32 s3, 2
	v_ashrrev_i32_e32 v8, 31, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v3, v3, v8
	v_xor_b32_e32 v3, v3, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v9, v3, v6
	v_mul_lo_u32 v9, v9, s9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v3, v3, v9
	v_subrev_nc_u32_e32 v9, s9, v3
	v_cmp_le_u32_e32 vcc_lo, s9, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v3, v3, v9, vcc_lo
	v_subrev_nc_u32_e32 v9, s9, v3
	v_cmp_le_u32_e32 vcc_lo, s9, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v3, v3, v9, vcc_lo
	v_xor_b32_e32 v3, v3, v8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v3, v3, v8
	v_mad_u64_u32 v[8:9], null, v3, s8, v[4:5]
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_lshlrev_b64 v[10:11], 2, v[2:3]
	v_ashrrev_i32_e32 v9, 31, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v10, vcc_lo, s6, v10
	v_lshlrev_b64 v[12:13], 2, v[8:9]
	s_delay_alu instid0(VALU_DEP_4) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_ci_u32_e32 v11, vcc_lo, s7, v11, vcc_lo
	v_add_co_u32 v12, vcc_lo, s6, v12
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v13, vcc_lo, s7, v13, vcc_lo
	s_clause 0x1
	global_load_b32 v3, v[10:11], off
	global_load_b32 v9, v[12:13], off
	s_waitcnt vmcnt(0)
	v_cmp_lt_f32_e32 vcc_lo, v3, v9
	v_cndmask_b32_e32 v2, v2, v8, vcc_lo
	s_cbranch_scc0 .LBB0_9
; %bb.10:                               ;   in Loop: Header=BB0_8 Depth=1
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s2, 2
	s_cbranch_scc0 .LBB0_8
; %bb.11:
	v_ashrrev_i32_e32 v3, 31, v2
	v_add_co_u32 v2, vcc_lo, s4, v2
	s_load_b64 s[0:1], s[0:1], 0x20
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	global_load_u8 v2, v[2:3], off
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	s_waitcnt vmcnt(0)
	global_store_b8 v[0:1], v2, off
	s_waitcnt_vscnt null, 0x0
	s_barrier
	buffer_gl0_inv
.LBB0_12:
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6EvolvePbPfdiS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 14
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 1
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 1
		.amdhsa_next_free_vgpr 14
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z6EvolvePbPfdiS_, .Lfunc_end0-_Z6EvolvePbPfdiS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1024
; NumSgprs: 18
; NumVgprs: 14
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 14
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 14
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 1
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           8
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .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:           _Z6EvolvePbPfdiS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6EvolvePbPfdiS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     14
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
