#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <sys/time.h>

#define TICKS 10
#define HEIGHT 512
#define WIDTH HEIGHT
#define NUM_GENERATORS 512
#define SOFTENING 10
#define NUM_THREADS 128

typedef struct {
	float* seed;
	float* fitness;
} GenData;

GenData* alloc_gen_data() {
	GenData* gen_data = (GenData*)malloc(sizeof(GenData));	
	gen_data->seed = (float*)malloc(sizeof(float) * HEIGHT * WIDTH * NUM_GENERATORS);
	gen_data->fitness = (float*)malloc(sizeof(float) * NUM_GENERATORS);
	return gen_data;
}

__device__ void fitness(float* fitness_arr, float* seed, int* gen_compare_dev, int idx) {
	fitness_arr[idx] = 0.0;
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			if(gen_compare_dev[i * WIDTH + j] == 1) {
				fitness_arr[idx] -= 1.0 - seed[(idx * HEIGHT * WIDTH) + (i * WIDTH) + j];
			//	if(idx == 0)
				//	printf("F");
			} else {
				fitness_arr[idx] -= seed[(idx * HEIGHT * WIDTH) + (i * WIDTH) + j] - 1.0;
			//	if(idx == 0)
				//	printf("B");
			}
		}
	}
}

__global__ void kernel(float* fitness_arr, float* seed, int* gen_compare){
	int idx = ((blockIdx.x * NUM_THREADS) + threadIdx.x);
	if(idx >= 0 && idx < NUM_GENERATORS)
		fitness(fitness_arr, seed, gen_compare, idx); 
}

unsigned long utime(void) 
{
	struct timeval tv;
	unsigned long result = 0;
	
	gettimeofday(&tv, NULL);
	result += (tv.tv_sec * 1000000);
	result += tv.tv_usec;
	
	return result;
}

float randPercent() {
	return ((rand() % 1000)/(1000.0));
}

void init_generator(GenData* gen_data, int idx) {
	// printf("I AM IN THE FUNCTION\n");
	// printf("CC%p\n", gen_data);
	// printf("CC%p\n", gen_data->fitness);
	// printf("CC%p\n", gen_data->seed);
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			// printf("%i, %i, %i = %i\n", i, j, idx, (idx * HEIGHT * WIDTH) + (i * WIDTH) + j);
			
			// printf("%f\n", *gen_data->seed); // this should (not) fail
			gen_data->seed[(idx * HEIGHT * WIDTH) + (i * WIDTH) + j] = randPercent();
			// gen_data->image[(idx * HEIGHT * WIDTH) + (i * WIDTH) + j] = false;
		}
	}
	// printf("I AM OUT OF THE FORLOOP\n");
	gen_data->fitness[idx] = 0;
	// printf("FASDF\n");
}
/*
bool* init_letter() {
	bool* gen_compare = (bool*)malloc(sizeof(bool) * WIDTH*HEIGHT);	
	char* hold = (char*)malloc(sizeof(char) * WIDTH*HEIGHT);
	sscanf("0000000000011000001001000100001001111110010000100010010000011000", "%s", hold);
	for(int i = 0; i < WIDTH*HEIGHT; i++) {
		gen_compare[i] = hold[i] == '1';
	}
	return gen_compare;
}
*/

void exchange_float(float* arr, int a, int b) {
	float temp = arr[a];
	arr[a] = arr[b];
	arr[b] = temp;
}

void exchange_bool(bool* arr, int a, int b) {
	bool temp = arr[a];
	arr[a] = arr[b];
	arr[b] = temp;
}

void exchange_generators(GenData* gen_data, int a, int b) {
	exchange_float(gen_data->fitness, a, b);
	int aPrime = a * HEIGHT * WIDTH;
	int bPrime = b * HEIGHT * WIDTH;
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			int ij = i * WIDTH  + j;
			exchange_float(gen_data->seed, aPrime+ij, bPrime+ij);
			// exchange_bool(gen_data->image, aPrime+ij, bPrime+ij);
		}
	}
}

int partition(GenData* gen_data, int p, int r) 
{
	int pivot = gen_data->fitness[r];
	int i = p - 1;
	for(int j = p; j < r - 1; j++) {
		if(gen_data->fitness[j] < pivot) {
			i++;
			exchange_generators(gen_data, i, j);
		}
	}
	exchange_generators(gen_data, i + 1, r);
	return i + 1;
}

void sort(GenData* gen_data, int p, int r) {
	if(p < r) {
		int q = partition(gen_data, p, r);
		sort(gen_data, p, q-1);
		sort(gen_data, q+1, r);
	}
}

void mutate(GenData* gen_data, GenData* new_gen_data, int idx) {
	int l = (idx*2 + 0)*HEIGHT*WIDTH;
	int r = (idx*2 + 1)*HEIGHT*WIDTH;
	int o = idx*HEIGHT*WIDTH;
	//printf("pre mutate seed: %f\n", new_gen_data->seed[r]);
	
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			int ij = i * WIDTH  + j;
		
			/*
			// image
			new_gen_data->image[l + ij] = gen_data->image[o + ij];
			new_gen_data->image[r + ij] = gen_data->image[o + ij];
			*/
			
			// seed
			float randAmount = (0.5 - randPercent())/SOFTENING;
			new_gen_data->seed[l + ij] = (gen_data->seed[o + ij] + randAmount);
			if(new_gen_data->seed[l + ij] < 0) {
				new_gen_data->seed[l + ij] = 0.0;
			} else if (new_gen_data->seed[l + ij] > 1) {
				new_gen_data->seed[l + ij] = 1.0;
			}
			new_gen_data->seed[r + ij] = (gen_data->seed[o + ij] - randAmount);
			if(new_gen_data->seed[r + ij] < 0) {
				new_gen_data->seed[r + ij] = 0.0;
			} else if (new_gen_data->seed[r + ij] > 1) {
				new_gen_data->seed[r + ij] = 1.0;
			}
			
			/*
			if(gen_compare[ij]) {
				new_gen_data->seed[l + ij] = gen_data->seed[o + ij] + .1;
				new_gen_data->seed[r + ij] = gen_data->seed[o + ij] + .1;
			} else {
				new_gen_data->seed[l + ij] = gen_data->seed[o + ij] - .1;
				new_gen_data->seed[r + ij] = gen_data->seed[o + ij] - .1;
			}
			*/
			
			/*
			new_gen_data->seed[l + ij] = gen_data->seed[o + ij] + (0.5 - randPercent()) / 50;
			new_gen_data->seed[r + ij] = gen_data->seed[o + ij] + (0.5 - randPercent()) / 50;
			*/
		}
	}
	
		//printf("post mutate seed: %f\n", new_gen_data->seed[r]);
		
}

void next_gen(GenData* gen_data, GenData* new_gen_data) {
	sort(gen_data, 0, NUM_GENERATORS-1);
	/*
	for(int i = 0; i < NUM_GENERATORS; i++) {
		printf("postsort: %i, %f\n", i, gen_data->fitness[i]);
	}
	*/
	// printf("best fitness of this tick is: %f\n", gen_data->fitness[0]);
	for(int i = 0; i < NUM_GENERATORS/2; i++) {
		mutate(gen_data, new_gen_data, i);
	}
}

void tick(GenData* gen_data, GenData* new_gen_data, int* gen_compare_dev, GenData* gen_data_dev) {

	// COPY IT IN
	// cudaMemcpy( gen_data_dev->fitness, gen_data->fitness, sizeof(float ) * NUM_GENERATORS, cudaMemcpyHostToDevice );
	cudaMemcpy( gen_data_dev->seed, gen_data->seed, sizeof(float) * NUM_GENERATORS * HEIGHT * WIDTH, cudaMemcpyHostToDevice) ; 
	
	// CALL IT
	dim3 grid((NUM_GENERATORS + NUM_THREADS - 1) / NUM_THREADS);
	kernel<<<grid, NUM_THREADS>>>(gen_data_dev->fitness, gen_data_dev->seed, gen_compare_dev);
	
	// YES
	cudaMemcpy( gen_data->fitness, gen_data_dev->fitness, sizeof(float) * NUM_GENERATORS, cudaMemcpyDeviceToHost );
	// cudaMemcpy( gen_data->seed, gen_data_dev->seed, sizeof(float) * NUM_GENERATORS * HEIGHT * WIDTH, cudaMemcpyDeviceToHost ); 
	
	next_gen(gen_data, new_gen_data);
}

int main(int arc, char **argv) {
	// allocate
	
	// printf("START \n");
	
	GenData* gen_data = alloc_gen_data();	
	
	// init
	srand(time(NULL));	
	GenData* gen_data_dev = (GenData*) malloc (sizeof(GenData));
	cudaMalloc(&gen_data_dev->fitness, sizeof(float) * NUM_GENERATORS);
	cudaMalloc(&gen_data_dev->seed, sizeof(float) * HEIGHT * WIDTH * NUM_GENERATORS);
	
	// printf("CUDAMALLOC \n");
	
	for(int i = 0; i < NUM_GENERATORS; i++) {
		init_generator(gen_data, i);
	}
	// printf("STETSET\n");
	// bool* gen_compare = init_letter();
	int* gen_compare_int = (int*)malloc(sizeof(int) * HEIGHT * WIDTH);
	
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
		/*
			if(gen_compare[i * WIDTH + j]) {
				gen_compare_int[i * WIDTH + j] = 1;
			} else {
				gen_compare_int[i * WIDTH + j] = 0;
			}
		*/
			if(randPercent() < .5) {
				gen_compare_int[i * WIDTH + j] = 1;
			} else {
				gen_compare_int[i * WIDTH + j] = 0;
			}
			
		}
	}
	
	int* gen_compare_dev;
	cudaMalloc(&gen_compare_dev, sizeof(int) * HEIGHT * WIDTH);
	cudaMemcpy(gen_compare_dev, gen_compare_int, sizeof(int) * HEIGHT * WIDTH, cudaMemcpyHostToDevice);
	
	// ticks
	GenData* new_gen_data = alloc_gen_data();
	// printf("gen_data: %p, new_gen_data: %p\n", gen_data, new_gen_data);
	
	for(int i = 0; i < TICKS; i++) {
		// printf("Tick! %i \n", i); 
		unsigned long start = utime();
		tick(gen_data, new_gen_data, gen_compare_dev, gen_data_dev);
		unsigned long end = utime();
		unsigned long elapsed = end - start;
		printf("for tick %i the time is %lu\n", i, elapsed);
		GenData* temp = gen_data;
		gen_data = new_gen_data;
		new_gen_data = temp;
	}
	
	
	// print
	/*
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			if(gen_data->seed[i * WIDTH  + j] > .5) {
				printf("0.");
			} else {
				printf("1.");
			}
		}
		printf("\n");
	}
	*/
	
	// printf("That gen_par run had %i generators running for %i ticks and took %lu seconds!\n", NUM_GENERATORS, TICKS, elapsed/1000);
	
	// destroy
	free(gen_data);
}

	.file	"tmpxft_003b6743_00000000-6_gen_par.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2043:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2043:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z14alloc_gen_datav
	.type	_Z14alloc_gen_datav, @function
_Z14alloc_gen_datav:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movl	$16, %edi
	call	malloc@PLT
	movl	$536870912, %edi
	movq	%rax, %rbx
	call	malloc@PLT
	movl	$2048, %edi
	movq	%rax, (%rbx)
	call	malloc@PLT
	movq	%rax, 8(%rbx)
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z14alloc_gen_datav, .-_Z14alloc_gen_datav
	.globl	_Z7fitnessPfS_Pii
	.type	_Z7fitnessPfS_Pii, @function
_Z7fitnessPfS_Pii:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movl	$1, 12(%rsp)
	movl	12(%rsp), %edi
	call	exit@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z7fitnessPfS_Pii, .-_Z7fitnessPfS_Pii
	.globl	_Z5utimev
	.type	_Z5utimev, @function
_Z5utimev:
.LFB2029:
	.cfi_startproc
	endbr64
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	xorl	%esi, %esi
	movq	%fs:40, %rax
	movq	%rax, 24(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	imulq	$1000000, 8(%rsp), %rax
	addq	16(%rsp), %rax
	movq	24(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L7
	call	__stack_chk_fail@PLT
.L7:
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2029:
	.size	_Z5utimev, .-_Z5utimev
	.globl	_Z11randPercentv
	.type	_Z11randPercentv, @function
_Z11randPercentv:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	call	rand@PLT
	movl	$1000, %ecx
	cltd
	idivl	%ecx
	cvtsi2sdl	%edx, %xmm0
	divsd	.LC0(%rip), %xmm0
	popq	%rdx
	.cfi_def_cfa_offset 8
	cvtsd2ss	%xmm0, %xmm0
	ret
	.cfi_endproc
.LFE2030:
	.size	_Z11randPercentv, .-_Z11randPercentv
	.globl	_Z14init_generatorP7GenDatai
	.type	_Z14init_generatorP7GenDatai, @function
_Z14init_generatorP7GenDatai:
.LFB2031:
	.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
	xorl	%r13d, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%esi, %rbx
	movq	%rbx, %r15
	salq	$20, %r15
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L13:
	movq	%r13, %r14
	xorl	%r12d, %r12d
	salq	$11, %r14
	addq	%r15, %r14
.L14:
	leaq	(%r14,%r12,4), %rax
	addq	0(%rbp), %rax
	incq	%r12
	movq	%rax, 8(%rsp)
	call	_Z11randPercentv
	movq	8(%rsp), %rax
	movss	%xmm0, (%rax)
	cmpq	$512, %r12
	jne	.L14
	incq	%r13
	cmpq	$512, %r13
	jne	.L13
	movq	8(%rbp), %rax
	movl	$0x00000000, (%rax,%rbx,4)
	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
.LFE2031:
	.size	_Z14init_generatorP7GenDatai, .-_Z14init_generatorP7GenDatai
	.globl	_Z14exchange_floatPfii
	.type	_Z14exchange_floatPfii, @function
_Z14exchange_floatPfii:
.LFB2032:
	.cfi_startproc
	endbr64
	movslq	%esi, %rsi
	movslq	%edx, %rdx
	leaq	(%rdi,%rsi,4), %rcx
	leaq	(%rdi,%rdx,4), %rax
	movss	(%rcx), %xmm0
	movss	(%rax), %xmm1
	movss	%xmm1, (%rcx)
	movss	%xmm0, (%rax)
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z14exchange_floatPfii, .-_Z14exchange_floatPfii
	.globl	_Z13exchange_boolPbii
	.type	_Z13exchange_boolPbii, @function
_Z13exchange_boolPbii:
.LFB2033:
	.cfi_startproc
	endbr64
	movslq	%edx, %rdx
	movslq	%esi, %rsi
	addq	%rdi, %rsi
	addq	%rdx, %rdi
	movb	(%rsi), %al
	movb	(%rdi), %dl
	movb	%dl, (%rsi)
	movb	%al, (%rdi)
	ret
	.cfi_endproc
.LFE2033:
	.size	_Z13exchange_boolPbii, .-_Z13exchange_boolPbii
	.globl	_Z19exchange_generatorsP7GenDataii
	.type	_Z19exchange_generatorsP7GenDataii, @function
_Z19exchange_generatorsP7GenDataii:
.LFB2034:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	%esi, %r9d
	movl	%edx, %r8d
	movq	%rdi, %r11
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	movq	8(%rdi), %rdi
	movl	%r9d, %ebp
	subl	%r9d, %r8d
	sall	$18, %ebp
	sall	$18, %r8d
	xorl	%r10d, %r10d
	call	_Z14exchange_floatPfii
.L21:
	leal	(%r10,%rbp), %r9d
	xorl	%ebx, %ebx
.L22:
	movq	(%r11), %rdi
	leal	(%r9,%r8), %edx
	movl	%r9d, %esi
	incl	%ebx
	incl	%r9d
	call	_Z14exchange_floatPfii
	cmpl	$512, %ebx
	jne	.L22
	addl	$512, %r10d
	cmpl	$262144, %r10d
	jne	.L21
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2034:
	.size	_Z19exchange_generatorsP7GenDataii, .-_Z19exchange_generatorsP7GenDataii
	.globl	_Z9partitionP7GenDataii
	.type	_Z9partitionP7GenDataii, @function
_Z9partitionP7GenDataii:
.LFB2035:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movslq	%edx, %rax
	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	%rax, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leal	-1(%r12), %r14d
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%esi, %rbx
	pushq	%rcx
	.cfi_def_cfa_offset 64
	movq	8(%rdi), %r15
	cvttss2sil	(%r15,%rax,4), %ebp
	leal	-1(%rsi), %eax
.L27:
	leal	1(%rax), %r13d
	cmpl	%ebx, %r14d
	jle	.L33
	cvtsi2ssl	%ebp, %xmm0
	comiss	(%r15,%rbx,4), %xmm0
	jbe	.L28
	movl	%ebx, %edx
	movl	%r13d, %esi
	movq	%rdi, (%rsp)
	call	_Z19exchange_generatorsP7GenDataii
	movq	(%rsp), %rdi
	movl	%r13d, %eax
.L28:
	incq	%rbx
	jmp	.L27
.L33:
	movl	%r12d, %edx
	movl	%r13d, %esi
	call	_Z19exchange_generatorsP7GenDataii
	popq	%rdx
	.cfi_def_cfa_offset 56
	movl	%r13d, %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
.LFE2035:
	.size	_Z9partitionP7GenDataii, .-_Z9partitionP7GenDataii
	.globl	_Z4sortP7GenDataii
	.type	_Z4sortP7GenDataii, @function
_Z4sortP7GenDataii:
.LFB2036:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	%edx, %r13d
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
.L36:
	cmpl	%r13d, %esi
	jge	.L34
	movl	%r13d, %edx
	movq	%r12, %rdi
	movl	%esi, 12(%rsp)
	call	_Z9partitionP7GenDataii
	movl	12(%rsp), %esi
	movq	%r12, %rdi
	movl	%eax, %ebp
	leal	-1(%rax), %edx
	call	_Z4sortP7GenDataii
	leal	1(%rbp), %esi
	jmp	.L36
.L34:
	addq	$16, %rsp
	.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
.LFE2036:
	.size	_Z4sortP7GenDataii, .-_Z4sortP7GenDataii
	.globl	_Z6mutateP7GenDataS0_i
	.type	_Z6mutateP7GenDataS0_i, @function
_Z6mutateP7GenDataS0_i:
.LFB2037:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rsi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	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
	movl	%edx, %ebp
	movslq	%edx, %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	sall	$19, %ebp
	imulq	$-1048576, %rdx, %rbx
	xorl	%edx, %edx
	movslq	%ebp, %rbp
	salq	$2, %rbp
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
.L39:
	movq	%rbp, %r12
	xorl	%r13d, %r13d
.L42:
	movl	%edx, 12(%rsp)
	call	_Z11randPercentv
	leaq	(%rbx,%r12), %rax
	addq	(%r14), %rax
	xorps	%xmm2, %xmm2
	movsd	.LC3(%rip), %xmm1
	cvtss2sd	%xmm0, %xmm0
	movq	(%r15), %rcx
	movl	12(%rsp), %edx
	subsd	%xmm0, %xmm1
	movss	(%rax), %xmm0
	divsd	.LC4(%rip), %xmm1
	cvtsd2ss	%xmm1, %xmm1
	leaq	(%rcx,%r12), %rsi
	addss	%xmm1, %xmm0
	comiss	%xmm0, %xmm2
	ja	.L44
	movss	.LC2(%rip), %xmm3
	minss	%xmm0, %xmm3
	movaps	%xmm3, %xmm0
	jmp	.L40
.L44:
	xorps	%xmm0, %xmm0
.L40:
	movss	%xmm0, (%rsi)
	movss	(%rax), %xmm0
	leaq	1048576(%rcx,%r12), %rcx
	subss	%xmm1, %xmm0
	comiss	%xmm0, %xmm2
	ja	.L46
	movss	.LC2(%rip), %xmm1
	minss	%xmm0, %xmm1
	movaps	%xmm1, %xmm0
	jmp	.L41
.L46:
	xorps	%xmm0, %xmm0
.L41:
	incl	%r13d
	movss	%xmm0, (%rcx)
	addq	$4, %r12
	cmpl	$512, %r13d
	jne	.L42
	addl	$512, %edx
	addq	$2048, %rbp
	cmpl	$262144, %edx
	jne	.L39
	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
.LFE2037:
	.size	_Z6mutateP7GenDataS0_i, .-_Z6mutateP7GenDataS0_i
	.globl	_Z8next_genP7GenDataS0_
	.type	_Z8next_genP7GenDataS0_, @function
_Z8next_genP7GenDataS0_:
.LFB2038:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	$511, %edx
	movq	%rsi, %r12
	xorl	%esi, %esi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	xorl	%ebx, %ebx
	call	_Z4sortP7GenDataii
.L51:
	movl	%ebx, %edx
	movq	%r12, %rsi
	movq	%rbp, %rdi
	incl	%ebx
	call	_Z6mutateP7GenDataS0_i
	cmpl	$256, %ebx
	jne	.L51
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2038:
	.size	_Z8next_genP7GenDataS0_, .-_Z8next_genP7GenDataS0_
	.globl	_Z29__device_stub__Z6kernelPfS_PiPfS_Pi
	.type	_Z29__device_stub__Z6kernelPfS_PiPfS_Pi, @function
_Z29__device_stub__Z6kernelPfS_PiPfS_Pi:
.LFB2065:
	.cfi_startproc
	endbr64
	subq	$136, %rsp
	.cfi_def_cfa_offset 144
	movq	%rdi, 24(%rsp)
	leaq	40(%rsp), %rcx
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movq	%rdx, 8(%rsp)
	leaq	32(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 112(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L54
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z6kernelPfS_Pi(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 160
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 152
	popq	%rdx
	.cfi_def_cfa_offset 144
.L54:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L56
	call	__stack_chk_fail@PLT
.L56:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2065:
	.size	_Z29__device_stub__Z6kernelPfS_PiPfS_Pi, .-_Z29__device_stub__Z6kernelPfS_PiPfS_Pi
	.globl	_Z6kernelPfS_Pi
	.type	_Z6kernelPfS_Pi, @function
_Z6kernelPfS_Pi:
.LFB2066:
	.cfi_startproc
	endbr64
	jmp	_Z29__device_stub__Z6kernelPfS_PiPfS_Pi
	.cfi_endproc
.LFE2066:
	.size	_Z6kernelPfS_Pi, .-_Z6kernelPfS_Pi
	.globl	_Z4tickP7GenDataS0_PiS0_
	.type	_Z4tickP7GenDataS0_PiS0_, @function
_Z4tickP7GenDataS0_PiS0_:
.LFB2039:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movq	%rdx, %r13
	movl	$536870912, %edx
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	movq	%rsi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	movq	%rdi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	movq	%rcx, %rbx
	movl	$1, %ecx
	subq	$40, %rsp
	.cfi_def_cfa_offset 80
	movq	(%rdi), %rsi
	movq	(%rbx), %rdi
	call	cudaMemcpy@PLT
	movl	$33554433, %edx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1073741825, %edi
	salq	$7, %rdx
	movl	$1, %ecx
	movl	$1, %esi
	salq	$2, %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L60
	movq	8(%rbx), %rdi
	movq	(%rbx), %rsi
	movq	%r13, %rdx
	call	_Z29__device_stub__Z6kernelPfS_PiPfS_Pi
.L60:
	movq	8(%rbx), %rsi
	movq	8(%rbp), %rdi
	movl	$2, %ecx
	movl	$2048, %edx
	call	cudaMemcpy@PLT
	addq	$40, %rsp
	.cfi_def_cfa_offset 40
	movq	%r12, %rsi
	movq	%rbp, %rdi
	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
	jmp	_Z8next_genP7GenDataS0_
	.cfi_endproc
.LFE2039:
	.size	_Z4tickP7GenDataS0_PiS0_, .-_Z4tickP7GenDataS0_PiS0_
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC6:
	.string	"for tick %i the time is %lu\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2040:
	.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
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	call	_Z14alloc_gen_datav
	xorl	%edi, %edi
	movq	%rax, %rbp
	call	time@PLT
	movl	%eax, %edi
	call	srand@PLT
	movl	$16, %edi
	call	malloc@PLT
	movl	$2048, %esi
	movq	%rax, %r12
	leaq	8(%rax), %rdi
	call	cudaMalloc@PLT
	movl	$536870912, %esi
	movq	%r12, %rdi
	call	cudaMalloc@PLT
.L63:
	movl	%ebx, %esi
	movq	%rbp, %rdi
	incl	%ebx
	call	_Z14init_generatorP7GenDatai
	cmpl	$512, %ebx
	jne	.L63
	movl	$1048576, %edi
	xorl	%r14d, %r14d
	call	malloc@PLT
	movq	%rax, %rbx
.L64:
	movq	%r14, %r15
	xorl	%r13d, %r13d
	salq	$11, %r15
	addq	%rbx, %r15
.L65:
	call	_Z11randPercentv
	movss	.LC5(%rip), %xmm1
	xorl	%eax, %eax
	comiss	%xmm0, %xmm1
	seta	%al
	movl	%eax, (%r15,%r13,4)
	incq	%r13
	cmpq	$512, %r13
	jne	.L65
	incq	%r14
	cmpq	$512, %r14
	jne	.L64
	movq	%rsp, %rdi
	movl	$1048576, %esi
	xorl	%r13d, %r13d
	call	cudaMalloc@PLT
	movq	(%rsp), %rdi
	movq	%rbx, %rsi
	movl	$1, %ecx
	movl	$1048576, %edx
	leaq	.LC6(%rip), %r14
	call	cudaMemcpy@PLT
	call	_Z14alloc_gen_datav
	movq	%rax, %rbx
.L67:
	call	_Z5utimev
	movq	(%rsp), %rdx
	movq	%r12, %rcx
	movq	%rbx, %rsi
	movq	%rbp, %rdi
	movq	%rax, %r15
	call	_Z4tickP7GenDataS0_PiS0_
	call	_Z5utimev
	movl	%r13d, %edx
	movq	%r14, %rsi
	movl	$2, %edi
	subq	%r15, %rax
	incl	%r13d
	movq	%rax, %rcx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	cmpl	$10, %r13d
	je	.L73
	xchgq	%rbx, %rbp
	jmp	.L67
.L73:
	movq	%rbx, %rdi
	call	free@PLT
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L68
	call	__stack_chk_fail@PLT
.L68:
	addq	$24, %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
.LFE2040:
	.size	main, .-main
	.section	.rodata.str1.1
.LC7:
	.string	"_Z6kernelPfS_Pi"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2068:
	.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	.LC7(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z6kernelPfS_Pi(%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
.LFE2068:
	.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
.LC0:
	.long	0
	.long	1083129856
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC2:
	.long	1065353216
	.section	.rodata.cst8
	.align 8
.LC3:
	.long	0
	.long	1071644672
	.align 8
.LC4:
	.long	0
	.long	1076101120
	.section	.rodata.cst4
	.align 4
.LC5:
	.long	1056964608
	.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 <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#include <sys/time.h>

#define TICKS 10
#define HEIGHT 512
#define WIDTH HEIGHT
#define NUM_GENERATORS 512
#define SOFTENING 10
#define NUM_THREADS 128

typedef struct {
	float* seed;
	float* fitness;
} GenData;

GenData* alloc_gen_data() {
	GenData* gen_data = (GenData*)malloc(sizeof(GenData));	
	gen_data->seed = (float*)malloc(sizeof(float) * HEIGHT * WIDTH * NUM_GENERATORS);
	gen_data->fitness = (float*)malloc(sizeof(float) * NUM_GENERATORS);
	return gen_data;
}

__device__ void fitness(float* fitness_arr, float* seed, int* gen_compare_dev, int idx) {
	fitness_arr[idx] = 0.0;
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			if(gen_compare_dev[i * WIDTH + j] == 1) {
				fitness_arr[idx] -= 1.0 - seed[(idx * HEIGHT * WIDTH) + (i * WIDTH) + j];
			//	if(idx == 0)
				//	printf("F");
			} else {
				fitness_arr[idx] -= seed[(idx * HEIGHT * WIDTH) + (i * WIDTH) + j] - 1.0;
			//	if(idx == 0)
				//	printf("B");
			}
		}
	}
}

__global__ void kernel(float* fitness_arr, float* seed, int* gen_compare){
	int idx = ((blockIdx.x * NUM_THREADS) + threadIdx.x);
	if(idx >= 0 && idx < NUM_GENERATORS)
		fitness(fitness_arr, seed, gen_compare, idx); 
}

unsigned long utime(void) 
{
	struct timeval tv;
	unsigned long result = 0;
	
	gettimeofday(&tv, NULL);
	result += (tv.tv_sec * 1000000);
	result += tv.tv_usec;
	
	return result;
}

float randPercent() {
	return ((rand() % 1000)/(1000.0));
}

void init_generator(GenData* gen_data, int idx) {
	// printf("I AM IN THE FUNCTION\n");
	// printf("CC%p\n", gen_data);
	// printf("CC%p\n", gen_data->fitness);
	// printf("CC%p\n", gen_data->seed);
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			// printf("%i, %i, %i = %i\n", i, j, idx, (idx * HEIGHT * WIDTH) + (i * WIDTH) + j);
			
			// printf("%f\n", *gen_data->seed); // this should (not) fail
			gen_data->seed[(idx * HEIGHT * WIDTH) + (i * WIDTH) + j] = randPercent();
			// gen_data->image[(idx * HEIGHT * WIDTH) + (i * WIDTH) + j] = false;
		}
	}
	// printf("I AM OUT OF THE FORLOOP\n");
	gen_data->fitness[idx] = 0;
	// printf("FASDF\n");
}
/*
bool* init_letter() {
	bool* gen_compare = (bool*)malloc(sizeof(bool) * WIDTH*HEIGHT);	
	char* hold = (char*)malloc(sizeof(char) * WIDTH*HEIGHT);
	sscanf("0000000000011000001001000100001001111110010000100010010000011000", "%s", hold);
	for(int i = 0; i < WIDTH*HEIGHT; i++) {
		gen_compare[i] = hold[i] == '1';
	}
	return gen_compare;
}
*/

void exchange_float(float* arr, int a, int b) {
	float temp = arr[a];
	arr[a] = arr[b];
	arr[b] = temp;
}

void exchange_bool(bool* arr, int a, int b) {
	bool temp = arr[a];
	arr[a] = arr[b];
	arr[b] = temp;
}

void exchange_generators(GenData* gen_data, int a, int b) {
	exchange_float(gen_data->fitness, a, b);
	int aPrime = a * HEIGHT * WIDTH;
	int bPrime = b * HEIGHT * WIDTH;
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			int ij = i * WIDTH  + j;
			exchange_float(gen_data->seed, aPrime+ij, bPrime+ij);
			// exchange_bool(gen_data->image, aPrime+ij, bPrime+ij);
		}
	}
}

int partition(GenData* gen_data, int p, int r) 
{
	int pivot = gen_data->fitness[r];
	int i = p - 1;
	for(int j = p; j < r - 1; j++) {
		if(gen_data->fitness[j] < pivot) {
			i++;
			exchange_generators(gen_data, i, j);
		}
	}
	exchange_generators(gen_data, i + 1, r);
	return i + 1;
}

void sort(GenData* gen_data, int p, int r) {
	if(p < r) {
		int q = partition(gen_data, p, r);
		sort(gen_data, p, q-1);
		sort(gen_data, q+1, r);
	}
}

void mutate(GenData* gen_data, GenData* new_gen_data, int idx) {
	int l = (idx*2 + 0)*HEIGHT*WIDTH;
	int r = (idx*2 + 1)*HEIGHT*WIDTH;
	int o = idx*HEIGHT*WIDTH;
	//printf("pre mutate seed: %f\n", new_gen_data->seed[r]);
	
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			int ij = i * WIDTH  + j;
		
			/*
			// image
			new_gen_data->image[l + ij] = gen_data->image[o + ij];
			new_gen_data->image[r + ij] = gen_data->image[o + ij];
			*/
			
			// seed
			float randAmount = (0.5 - randPercent())/SOFTENING;
			new_gen_data->seed[l + ij] = (gen_data->seed[o + ij] + randAmount);
			if(new_gen_data->seed[l + ij] < 0) {
				new_gen_data->seed[l + ij] = 0.0;
			} else if (new_gen_data->seed[l + ij] > 1) {
				new_gen_data->seed[l + ij] = 1.0;
			}
			new_gen_data->seed[r + ij] = (gen_data->seed[o + ij] - randAmount);
			if(new_gen_data->seed[r + ij] < 0) {
				new_gen_data->seed[r + ij] = 0.0;
			} else if (new_gen_data->seed[r + ij] > 1) {
				new_gen_data->seed[r + ij] = 1.0;
			}
			
			/*
			if(gen_compare[ij]) {
				new_gen_data->seed[l + ij] = gen_data->seed[o + ij] + .1;
				new_gen_data->seed[r + ij] = gen_data->seed[o + ij] + .1;
			} else {
				new_gen_data->seed[l + ij] = gen_data->seed[o + ij] - .1;
				new_gen_data->seed[r + ij] = gen_data->seed[o + ij] - .1;
			}
			*/
			
			/*
			new_gen_data->seed[l + ij] = gen_data->seed[o + ij] + (0.5 - randPercent()) / 50;
			new_gen_data->seed[r + ij] = gen_data->seed[o + ij] + (0.5 - randPercent()) / 50;
			*/
		}
	}
	
		//printf("post mutate seed: %f\n", new_gen_data->seed[r]);
		
}

void next_gen(GenData* gen_data, GenData* new_gen_data) {
	sort(gen_data, 0, NUM_GENERATORS-1);
	/*
	for(int i = 0; i < NUM_GENERATORS; i++) {
		printf("postsort: %i, %f\n", i, gen_data->fitness[i]);
	}
	*/
	// printf("best fitness of this tick is: %f\n", gen_data->fitness[0]);
	for(int i = 0; i < NUM_GENERATORS/2; i++) {
		mutate(gen_data, new_gen_data, i);
	}
}

void tick(GenData* gen_data, GenData* new_gen_data, int* gen_compare_dev, GenData* gen_data_dev) {

	// COPY IT IN
	// cudaMemcpy( gen_data_dev->fitness, gen_data->fitness, sizeof(float ) * NUM_GENERATORS, cudaMemcpyHostToDevice );
	hipMemcpy( gen_data_dev->seed, gen_data->seed, sizeof(float) * NUM_GENERATORS * HEIGHT * WIDTH, hipMemcpyHostToDevice) ; 
	
	// CALL IT
	dim3 grid((NUM_GENERATORS + NUM_THREADS - 1) / NUM_THREADS);
	kernel<<<grid, NUM_THREADS>>>(gen_data_dev->fitness, gen_data_dev->seed, gen_compare_dev);
	
	// YES
	hipMemcpy( gen_data->fitness, gen_data_dev->fitness, sizeof(float) * NUM_GENERATORS, hipMemcpyDeviceToHost );
	// cudaMemcpy( gen_data->seed, gen_data_dev->seed, sizeof(float) * NUM_GENERATORS * HEIGHT * WIDTH, cudaMemcpyDeviceToHost ); 
	
	next_gen(gen_data, new_gen_data);
}

int main(int arc, char **argv) {
	// allocate
	
	// printf("START \n");
	
	GenData* gen_data = alloc_gen_data();	
	
	// init
	srand(time(NULL));	
	GenData* gen_data_dev = (GenData*) malloc (sizeof(GenData));
	hipMalloc(&gen_data_dev->fitness, sizeof(float) * NUM_GENERATORS);
	hipMalloc(&gen_data_dev->seed, sizeof(float) * HEIGHT * WIDTH * NUM_GENERATORS);
	
	// printf("CUDAMALLOC \n");
	
	for(int i = 0; i < NUM_GENERATORS; i++) {
		init_generator(gen_data, i);
	}
	// printf("STETSET\n");
	// bool* gen_compare = init_letter();
	int* gen_compare_int = (int*)malloc(sizeof(int) * HEIGHT * WIDTH);
	
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
		/*
			if(gen_compare[i * WIDTH + j]) {
				gen_compare_int[i * WIDTH + j] = 1;
			} else {
				gen_compare_int[i * WIDTH + j] = 0;
			}
		*/
			if(randPercent() < .5) {
				gen_compare_int[i * WIDTH + j] = 1;
			} else {
				gen_compare_int[i * WIDTH + j] = 0;
			}
			
		}
	}
	
	int* gen_compare_dev;
	hipMalloc(&gen_compare_dev, sizeof(int) * HEIGHT * WIDTH);
	hipMemcpy(gen_compare_dev, gen_compare_int, sizeof(int) * HEIGHT * WIDTH, hipMemcpyHostToDevice);
	
	// ticks
	GenData* new_gen_data = alloc_gen_data();
	// printf("gen_data: %p, new_gen_data: %p\n", gen_data, new_gen_data);
	
	for(int i = 0; i < TICKS; i++) {
		// printf("Tick! %i \n", i); 
		unsigned long start = utime();
		tick(gen_data, new_gen_data, gen_compare_dev, gen_data_dev);
		unsigned long end = utime();
		unsigned long elapsed = end - start;
		printf("for tick %i the time is %lu\n", i, elapsed);
		GenData* temp = gen_data;
		gen_data = new_gen_data;
		new_gen_data = temp;
	}
	
	
	// print
	/*
	for(int i = 0; i < HEIGHT; i++) {
		for(int j = 0; j < WIDTH; j++) {
			if(gen_data->seed[i * WIDTH  + j] > .5) {
				printf("0.");
			} else {
				printf("1.");
			}
		}
		printf("\n");
	}
	*/
	
	// printf("That gen_par run had %i generators running for %i ticks and took %lu seconds!\n", NUM_GENERATORS, TICKS, elapsed/1000);
	
	// destroy
	free(gen_data);
}

	.text
	.file	"gen_par.hip"
	.globl	_Z14alloc_gen_datav             # -- Begin function _Z14alloc_gen_datav
	.type	_Z14alloc_gen_datav,@function
_Z14alloc_gen_datav:                    # @_Z14alloc_gen_datav
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movl	$16, %edi
	callq	malloc
	movq	%rax, %rbx
	movl	$536870912, %edi                # imm = 0x20000000
	callq	malloc
	movq	%rax, (%rbx)
	movl	$2048, %edi                     # imm = 0x800
	callq	malloc
	movq	%rax, 8(%rbx)
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z14alloc_gen_datav, .Lfunc_end0-_Z14alloc_gen_datav
	.cfi_endproc
                                        # -- End function
	.globl	_Z21__device_stub__kernelPfS_Pi # -- Begin function _Z21__device_stub__kernelPfS_Pi
	.type	_Z21__device_stub__kernelPfS_Pi,@function
_Z21__device_stub__kernelPfS_Pi:        # @_Z21__device_stub__kernelPfS_Pi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z6kernelPfS_Pi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z21__device_stub__kernelPfS_Pi, .Lfunc_end1-_Z21__device_stub__kernelPfS_Pi
	.cfi_endproc
                                        # -- End function
	.globl	_Z5utimev                       # -- Begin function _Z5utimev
	.type	_Z5utimev,@function
_Z5utimev:                              # @_Z5utimev
	.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
	xorl	%esi, %esi
	callq	gettimeofday
	imulq	$1000000, (%rbx), %rax          # imm = 0xF4240
	addq	8(%rbx), %rax
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z5utimev, .Lfunc_end2-_Z5utimev
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z11randPercentv
.LCPI3_0:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	_Z11randPercentv
	.type	_Z11randPercentv,@function
_Z11randPercentv:                       # @_Z11randPercentv
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	rand
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$38, %rcx
	addl	%edx, %ecx
	imull	$1000, %ecx, %ecx               # imm = 0x3E8
	subl	%ecx, %eax
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI3_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	popq	%rax
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end3:
	.size	_Z11randPercentv, .Lfunc_end3-_Z11randPercentv
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z14init_generatorP7GenDatai
.LCPI4_0:
	.quad	0x408f400000000000              # double 1000
	.text
	.globl	_Z14init_generatorP7GenDatai
	.type	_Z14init_generatorP7GenDatai,@function
_Z14init_generatorP7GenDatai:           # @_Z14init_generatorP7GenDatai
	.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
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%esi, %ebx
	movq	%rdi, %r14
	movl	%esi, %eax
	shll	$18, %eax
	movslq	%eax, %r15
	shlq	$2, %r15
	xorl	%r12d, %r12d
.LBB4_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB4_2 Depth 2
	xorl	%r13d, %r13d
.LBB4_2:                                #   Parent Loop BB4_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movsd	.LCPI4_0(%rip), %xmm1           # xmm1 = mem[0],zero
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$38, %rcx
	addl	%edx, %ecx
	imull	$1000, %ecx, %ecx               # imm = 0x3E8
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm1, %xmm0
	movq	(%r14), %rax
	cvtsd2ss	%xmm0, %xmm0
	addq	%r15, %rax
	movss	%xmm0, (%rax,%r13,4)
	incq	%r13
	cmpq	$512, %r13                      # imm = 0x200
	jne	.LBB4_2
# %bb.3:                                #   in Loop: Header=BB4_1 Depth=1
	incq	%r12
	addq	$2048, %r15                     # imm = 0x800
	cmpq	$512, %r12                      # imm = 0x200
	jne	.LBB4_1
# %bb.4:
	movq	8(%r14), %rax
	movslq	%ebx, %rcx
	movl	$0, (%rax,%rcx,4)
	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	_Z14init_generatorP7GenDatai, .Lfunc_end4-_Z14init_generatorP7GenDatai
	.cfi_endproc
                                        # -- End function
	.globl	_Z14exchange_floatPfii          # -- Begin function _Z14exchange_floatPfii
	.type	_Z14exchange_floatPfii,@function
_Z14exchange_floatPfii:                 # @_Z14exchange_floatPfii
	.cfi_startproc
# %bb.0:
	movslq	%esi, %rax
	movss	(%rdi,%rax,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movslq	%edx, %rcx
	movss	(%rdi,%rcx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movss	%xmm1, (%rdi,%rax,4)
	movss	%xmm0, (%rdi,%rcx,4)
	retq
.Lfunc_end5:
	.size	_Z14exchange_floatPfii, .Lfunc_end5-_Z14exchange_floatPfii
	.cfi_endproc
                                        # -- End function
	.globl	_Z13exchange_boolPbii           # -- Begin function _Z13exchange_boolPbii
	.type	_Z13exchange_boolPbii,@function
_Z13exchange_boolPbii:                  # @_Z13exchange_boolPbii
	.cfi_startproc
# %bb.0:
	movslq	%esi, %rax
	movb	(%rdi,%rax), %cl
	movslq	%edx, %rdx
	movb	(%rdi,%rdx), %sil
	movb	%sil, (%rdi,%rax)
	movb	%cl, (%rdi,%rdx)
	retq
.Lfunc_end6:
	.size	_Z13exchange_boolPbii, .Lfunc_end6-_Z13exchange_boolPbii
	.cfi_endproc
                                        # -- End function
	.globl	_Z19exchange_generatorsP7GenDataii # -- Begin function _Z19exchange_generatorsP7GenDataii
	.type	_Z19exchange_generatorsP7GenDataii,@function
_Z19exchange_generatorsP7GenDataii:     # @_Z19exchange_generatorsP7GenDataii
	.cfi_startproc
# %bb.0:
	movq	8(%rdi), %rax
	movslq	%esi, %rcx
	movss	(%rax,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movslq	%edx, %rdx
	movss	(%rax,%rdx,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movss	%xmm1, (%rax,%rcx,4)
	movss	%xmm0, (%rax,%rdx,4)
	shll	$18, %ecx
	shll	$18, %edx
	movq	(%rdi), %rsi
	movslq	%ecx, %rax
	movslq	%edx, %rcx
	leaq	(%rsi,%rax,4), %rax
	leaq	(%rsi,%rcx,4), %rcx
	xorl	%edx, %edx
	movl	$2048, %esi                     # imm = 0x800
.LBB7_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB7_2 Depth 2
	xorl	%edi, %edi
.LBB7_2:                                #   Parent Loop BB7_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movss	(%rax,%rdi,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	movss	(%rcx,%rdi,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	movss	%xmm1, (%rax,%rdi,4)
	movss	%xmm0, (%rcx,%rdi,4)
	incq	%rdi
	cmpq	$512, %rdi                      # imm = 0x200
	jne	.LBB7_2
# %bb.3:                                #   in Loop: Header=BB7_1 Depth=1
	incq	%rdx
	addq	%rsi, %rcx
	addq	%rsi, %rax
	cmpq	$512, %rdx                      # imm = 0x200
	jne	.LBB7_1
# %bb.4:
	retq
.Lfunc_end7:
	.size	_Z19exchange_generatorsP7GenDataii, .Lfunc_end7-_Z19exchange_generatorsP7GenDataii
	.cfi_endproc
                                        # -- End function
	.globl	_Z9partitionP7GenDataii         # -- Begin function _Z9partitionP7GenDataii
	.type	_Z9partitionP7GenDataii,@function
_Z9partitionP7GenDataii:                # @_Z9partitionP7GenDataii
	.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
	subq	$16, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %r14d
	movl	%esi, %ebx
	movq	%rdi, %r15
	leal	-1(%r14), %ebp
	cmpl	%esi, %ebp
	jle	.LBB8_6
# %bb.1:                                # %.lr.ph
	movq	8(%r15), %rax
	movslq	%r14d, %rcx
	movss	(%rax,%rcx,4), %xmm0            # xmm0 = mem[0],zero,zero,zero
	cvttps2dq	%xmm0, %xmm0
	cvtdq2ps	%xmm0, %xmm0
	movslq	%ebx, %r12
	decl	%ebx
	movaps	%xmm0, (%rsp)                   # 16-byte Spill
.LBB8_2:                                # =>This Inner Loop Header: Depth=1
	movq	8(%r15), %rax
	ucomiss	(%rax,%r12,4), %xmm0
	jbe	.LBB8_4
# %bb.3:                                #   in Loop: Header=BB8_2 Depth=1
	incl	%ebx
	movq	%r15, %rdi
	movl	%ebx, %esi
	movl	%r12d, %edx
	callq	_Z19exchange_generatorsP7GenDataii
	movaps	(%rsp), %xmm0                   # 16-byte Reload
.LBB8_4:                                #   in Loop: Header=BB8_2 Depth=1
	incq	%r12
	cmpl	%r12d, %ebp
	jne	.LBB8_2
# %bb.5:                                # %._crit_edge.loopexit
	incl	%ebx
.LBB8_6:                                # %._crit_edge
	movq	%r15, %rdi
	movl	%ebx, %esi
	movl	%r14d, %edx
	callq	_Z19exchange_generatorsP7GenDataii
	movl	%ebx, %eax
	addq	$16, %rsp
	.cfi_def_cfa_offset 48
	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_end8:
	.size	_Z9partitionP7GenDataii, .Lfunc_end8-_Z9partitionP7GenDataii
	.cfi_endproc
                                        # -- End function
	.globl	_Z4sortP7GenDataii              # -- Begin function _Z4sortP7GenDataii
	.type	_Z4sortP7GenDataii,@function
_Z4sortP7GenDataii:                     # @_Z4sortP7GenDataii
	.cfi_startproc
# %bb.0:
	cmpl	%edx, %esi
	jge	.LBB9_4
# %bb.1:                                # %tailrecurse.preheader
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.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 %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebx
	movl	%esi, %ebp
	movq	%rdi, %r14
.LBB9_2:                                # %tailrecurse
                                        # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movl	%ebp, %esi
	movl	%ebx, %edx
	callq	_Z9partitionP7GenDataii
	movl	%eax, %r15d
	leal	-1(%r15), %edx
	movq	%r14, %rdi
	movl	%ebp, %esi
	callq	_Z4sortP7GenDataii
	incl	%r15d
	movl	%r15d, %ebp
	cmpl	%ebx, %r15d
	jl	.LBB9_2
# %bb.3:
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.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 %r14
	.cfi_restore %r15
	.cfi_restore %rbp
.LBB9_4:                                # %tailrecurse._crit_edge
	retq
.Lfunc_end9:
	.size	_Z4sortP7GenDataii, .Lfunc_end9-_Z4sortP7GenDataii
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function _Z6mutateP7GenDataS0_i
.LCPI10_0:
	.quad	0xc08f400000000000              # double -1000
.LCPI10_1:
	.quad	0x3fe0000000000000              # double 0.5
.LCPI10_2:
	.quad	0x4024000000000000              # double 10
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI10_3:
	.long	0x3f800000                      # float 1
	.text
	.globl	_Z6mutateP7GenDataS0_i
	.type	_Z6mutateP7GenDataS0_i,@function
_Z6mutateP7GenDataS0_i:                 # @_Z6mutateP7GenDataS0_i
	.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
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movl	%edx, %eax
	shll	$19, %eax
	shll	$18, %edx
	movslq	%edx, %r15
	cltq
	shlq	$2, %r15
	leaq	1048576(,%rax,4), %r12
	xorl	%r13d, %r13d
.LBB10_1:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB10_2 Depth 2
	xorl	%ebp, %ebp
.LBB10_2:                               #   Parent Loop BB10_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$38, %rcx
	addl	%edx, %ecx
	imull	$1000, %ecx, %ecx               # imm = 0x3E8
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	.LCPI10_0(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	cvtss2sd	%xmm0, %xmm0
	addsd	.LCPI10_1(%rip), %xmm0
	divsd	.LCPI10_2(%rip), %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movq	(%r14), %rcx
	addq	%r15, %rcx
	movss	(%rcx,%rbp,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	addss	%xmm0, %xmm1
	movq	(%rbx), %rax
	addq	%r12, %rax
	movss	%xmm1, -1048576(%rax,%rbp,4)
	xorps	%xmm2, %xmm2
	ucomiss	%xmm1, %xmm2
	ja	.LBB10_4
# %bb.3:                                #   in Loop: Header=BB10_2 Depth=2
	movss	.LCPI10_3(%rip), %xmm2          # xmm2 = mem[0],zero,zero,zero
	ucomiss	%xmm2, %xmm1
	jbe	.LBB10_5
.LBB10_4:                               # %.sink.split
                                        #   in Loop: Header=BB10_2 Depth=2
	movss	%xmm2, -1048576(%rax,%rbp,4)
.LBB10_5:                               #   in Loop: Header=BB10_2 Depth=2
	movss	(%rcx,%rbp,4), %xmm1            # xmm1 = mem[0],zero,zero,zero
	subss	%xmm0, %xmm1
	movss	%xmm1, (%rax,%rbp,4)
	xorps	%xmm0, %xmm0
	ucomiss	%xmm1, %xmm0
	ja	.LBB10_7
# %bb.6:                                #   in Loop: Header=BB10_2 Depth=2
	movss	.LCPI10_3(%rip), %xmm0          # xmm0 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	jbe	.LBB10_8
.LBB10_7:                               # %.sink.split56
                                        #   in Loop: Header=BB10_2 Depth=2
	movss	%xmm0, (%rax,%rbp,4)
.LBB10_8:                               #   in Loop: Header=BB10_2 Depth=2
	incq	%rbp
	cmpq	$512, %rbp                      # imm = 0x200
	jne	.LBB10_2
# %bb.9:                                #   in Loop: Header=BB10_1 Depth=1
	incq	%r13
	movl	$2048, %eax                     # imm = 0x800
	addq	%rax, %r15
	addq	%rax, %r12
	cmpq	$512, %r13                      # imm = 0x200
	jne	.LBB10_1
# %bb.10:
	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_end10:
	.size	_Z6mutateP7GenDataS0_i, .Lfunc_end10-_Z6mutateP7GenDataS0_i
	.cfi_endproc
                                        # -- End function
	.globl	_Z8next_genP7GenDataS0_         # -- Begin function _Z8next_genP7GenDataS0_
	.type	_Z8next_genP7GenDataS0_,@function
_Z8next_genP7GenDataS0_:                # @_Z8next_genP7GenDataS0_
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movq	%rdi, %r14
	xorl	%ebp, %ebp
	xorl	%esi, %esi
	movl	$511, %edx                      # imm = 0x1FF
	callq	_Z4sortP7GenDataii
.LBB11_1:                               # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movq	%rbx, %rsi
	movl	%ebp, %edx
	callq	_Z6mutateP7GenDataS0_i
	incl	%ebp
	cmpl	$256, %ebp                      # imm = 0x100
	jne	.LBB11_1
# %bb.2:
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end11:
	.size	_Z8next_genP7GenDataS0_, .Lfunc_end11-_Z8next_genP7GenDataS0_
	.cfi_endproc
                                        # -- End function
	.globl	_Z4tickP7GenDataS0_PiS0_        # -- Begin function _Z4tickP7GenDataS0_PiS0_
	.type	_Z4tickP7GenDataS0_PiS0_,@function
_Z4tickP7GenDataS0_PiS0_:               # @_Z4tickP7GenDataS0_PiS0_
	.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	%rcx, %r15
	movq	%rdx, %r12
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	(%rcx), %rdi
	movq	(%r14), %rsi
	movl	$536870912, %edx                # imm = 0x20000000
	movl	$1, %ecx
	callq	hipMemcpy
	movabsq	$4294967300, %rdi               # imm = 0x100000004
	leaq	124(%rdi), %rdx
	movl	$1, %esi
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB12_2
# %bb.1:
	movq	(%r15), %rsi
	movq	8(%r15), %rdi
	movq	%r12, %rdx
	callq	_Z21__device_stub__kernelPfS_Pi
.LBB12_2:
	movq	8(%r14), %rdi
	movq	8(%r15), %rsi
	movl	$2048, %edx                     # imm = 0x800
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r14, %rdi
	movq	%rbx, %rsi
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	_Z8next_genP7GenDataS0_         # TAILCALL
.Lfunc_end12:
	.size	_Z4tickP7GenDataS0_PiS0_, .Lfunc_end12-_Z4tickP7GenDataS0_PiS0_
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI13_0:
	.quad	0x408f400000000000              # double 1000
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI13_1:
	.long	0x3f000000                      # float 0.5
	.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
	callq	_Z14alloc_gen_datav
	movq	%rax, %r14
	xorl	%r15d, %r15d
	xorl	%edi, %edi
	callq	time
	movl	%eax, %edi
	callq	srand
	movl	$16, %edi
	callq	malloc
	movq	%rax, %rbx
	leaq	8(%rax), %rdi
	movl	$2048, %esi                     # imm = 0x800
	callq	hipMalloc
	movl	$536870912, %esi                # imm = 0x20000000
	movq	%rbx, %rdi
	callq	hipMalloc
.LBB13_1:                               # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movl	%r15d, %esi
	callq	_Z14init_generatorP7GenDatai
	incl	%r15d
	cmpl	$512, %r15d                     # imm = 0x200
	jne	.LBB13_1
# %bb.2:
	movl	$1048576, %edi                  # imm = 0x100000
	callq	malloc
	movq	%rax, %r15
	xorl	%r12d, %r12d
	movq	%rax, %r13
.LBB13_3:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB13_4 Depth 2
	xorl	%ebp, %ebp
.LBB13_4:                               #   Parent Loop BB13_3 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	callq	rand
	movsd	.LCPI13_0(%rip), %xmm1          # xmm1 = mem[0],zero
	cltq
	imulq	$274877907, %rax, %rcx          # imm = 0x10624DD3
	movq	%rcx, %rdx
	shrq	$63, %rdx
	sarq	$38, %rcx
	addl	%edx, %ecx
	imull	$1000, %ecx, %ecx               # imm = 0x3E8
	subl	%ecx, %eax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%eax, %xmm0
	divsd	%xmm1, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	xorl	%eax, %eax
	movss	.LCPI13_1(%rip), %xmm1          # xmm1 = mem[0],zero,zero,zero
	ucomiss	%xmm0, %xmm1
	seta	%al
	movl	%eax, (%r13,%rbp,4)
	incq	%rbp
	cmpq	$512, %rbp                      # imm = 0x200
	jne	.LBB13_4
# %bb.5:                                #   in Loop: Header=BB13_3 Depth=1
	incq	%r12
	addq	$2048, %r13                     # imm = 0x800
	cmpq	$512, %r12                      # imm = 0x200
	jne	.LBB13_3
# %bb.6:
	leaq	32(%rsp), %r12
	movl	$1048576, %esi                  # imm = 0x100000
	movq	%r12, %rdi
	callq	hipMalloc
	movq	(%r12), %rdi
	movl	$1048576, %edx                  # imm = 0x100000
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	callq	_Z14alloc_gen_datav
	movq	%rax, %r12
	xorl	%ebp, %ebp
	movq	%rbx, 24(%rsp)                  # 8-byte Spill
.LBB13_7:                               # =>This Inner Loop Header: Depth=1
	movq	%r12, %r13
	movq	%r14, %r12
	leaq	8(%rsp), %r15
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	8(%rsp), %r14
	movq	16(%rsp), %rbx
	movq	32(%rsp), %rdx
	movq	%r12, %rdi
	movq	%r13, %rsi
	movq	24(%rsp), %rcx                  # 8-byte Reload
	callq	_Z4tickP7GenDataS0_PiS0_
	movq	%r15, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	8(%rsp), %rax
	subq	%r14, %rax
	movq	16(%rsp), %rcx
	subq	%rbx, %rcx
	imulq	$1000000, %rax, %rdx            # imm = 0xF4240
	addq	%rcx, %rdx
	movl	$.L.str, %edi
	movl	%ebp, %esi
	xorl	%eax, %eax
	callq	printf
	incl	%ebp
	movq	%r13, %r14
	cmpl	$10, %ebp
	jne	.LBB13_7
# %bb.8:
	movq	%r13, %rdi
	callq	free
	xorl	%eax, %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_end13:
	.size	main, .Lfunc_end13-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	.LBB14_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB14_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z6kernelPfS_Pi, %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_end14:
	.size	__hip_module_ctor, .Lfunc_end14-__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	.LBB15_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
.LBB15_2:
	retq
.Lfunc_end15:
	.size	__hip_module_dtor, .Lfunc_end15-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z6kernelPfS_Pi,@object         # @_Z6kernelPfS_Pi
	.section	.rodata,"a",@progbits
	.globl	_Z6kernelPfS_Pi
	.p2align	3, 0x0
_Z6kernelPfS_Pi:
	.quad	_Z21__device_stub__kernelPfS_Pi
	.size	_Z6kernelPfS_Pi, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"for tick %i the time is %lu\n"
	.size	.L.str, 29

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z6kernelPfS_Pi"
	.size	.L__unnamed_1, 16

	.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__kernelPfS_Pi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z6kernelPfS_Pi
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z6kernelPfS_Pi         ; -- Begin function _Z6kernelPfS_Pi
	.globl	_Z6kernelPfS_Pi
	.p2align	8
	.type	_Z6kernelPfS_Pi,@function
_Z6kernelPfS_Pi:                        ; @_Z6kernelPfS_Pi
; %bb.0:
	v_lshl_add_u32 v0, s15, 7, v0
	s_mov_b32 s2, exec_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_cmpx_gt_u32_e32 0x200, v0
	s_cbranch_execz .LBB0_10
; %bb.1:
	s_load_b128 s[4:7], s[0:1], 0x0
	v_mov_b32_e32 v1, 0
	s_load_b64 s[0:1], s[0:1], 0x10
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[2:3], 2, v[0:1]
	v_lshlrev_b32_e32 v0, 18, v0
	v_lshlrev_b64 v[4:5], 2, v[0:1]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v2, vcc_lo, s4, v2
	v_add_co_ci_u32_e32 v3, vcc_lo, s5, v3, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v0, vcc_lo, s6, v4
	v_add_co_ci_u32_e32 v8, vcc_lo, s7, v5, vcc_lo
	s_mov_b32 s4, 0
	global_store_b32 v[2:3], v1, off
.LBB0_2:                                ; %.preheader.i
                                        ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_3 Depth 2
	s_mov_b64 s[2:3], 0
.LBB0_3:                                ;   Parent Loop BB0_2 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_delay_alu instid0(SALU_CYCLE_1)
	v_add_co_u32 v4, vcc_lo, v0, s2
	v_add_co_ci_u32_e32 v5, vcc_lo, s3, v8, vcc_lo
	s_add_u32 s6, s0, s2
	s_addc_u32 s7, s1, s3
	s_load_b32 s5, s[6:7], 0x0
	global_load_b32 v4, v[4:5], off
	s_waitcnt lgkmcnt(0)
	s_cmp_lg_u32 s5, 1
	s_waitcnt vmcnt(0)
	v_cvt_f64_f32_e32 v[4:5], v4
	s_cbranch_scc0 .LBB0_5
; %bb.4:                                ;   in Loop: Header=BB0_3 Depth=2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[6:7], v[4:5], -1.0
	s_mov_b32 s5, 0
	s_branch .LBB0_6
.LBB0_5:                                ;   in Loop: Header=BB0_3 Depth=2
	s_mov_b32 s5, -1
                                        ; implicit-def: $vgpr6_vgpr7
.LBB0_6:                                ; %Flow
                                        ;   in Loop: Header=BB0_3 Depth=2
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_not1_b32 vcc_lo, exec_lo, s5
	s_cbranch_vccnz .LBB0_8
; %bb.7:                                ;   in Loop: Header=BB0_3 Depth=2
	s_delay_alu instid0(VALU_DEP_1)
	v_add_f64 v[6:7], -v[4:5], 1.0
.LBB0_8:                                ;   in Loop: Header=BB0_3 Depth=2
	v_cvt_f64_f32_e32 v[4:5], v1
	s_add_u32 s2, s2, 4
	s_addc_u32 s3, s3, 0
	s_cmpk_eq_i32 s2, 0x800
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_f64 v[4:5], v[4:5], -v[6:7]
	v_cvt_f32_f64_e32 v1, v[4:5]
	global_store_b32 v[2:3], v1, off
	s_cbranch_scc0 .LBB0_3
; %bb.9:                                ;   in Loop: Header=BB0_2 Depth=1
	v_add_co_u32 v0, vcc_lo, 0x800, v0
	s_add_i32 s4, s4, 1
	v_add_co_ci_u32_e32 v8, vcc_lo, 0, v8, vcc_lo
	s_add_u32 s0, s0, 0x800
	s_addc_u32 s1, s1, 0
	s_cmpk_eq_i32 s4, 0x200
	s_cbranch_scc0 .LBB0_2
.LBB0_10:                               ; %_Z7fitnessPfS_Pii.exit
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z6kernelPfS_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 24
		.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 9
		.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	_Z6kernelPfS_Pi, .Lfunc_end0-_Z6kernelPfS_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 328
; NumSgprs: 18
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 24
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z6kernelPfS_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z6kernelPfS_Pi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
