/** \file
*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <stdint.h>

#define BLOCKLEN 512

int nextPower(int);
void die(const char *);
void warn(const char *);
void read_from_file(int *, char *, int);
void write_to_file(int *, char *, int);

/**
 * play - Plays the game for one step.
 * First, counts the neighbors, taking into account boundary conditions
 * Then, acts on the rules.
 * Updates need to happen all together, so a temporary new array is allocated
 */
__global__ void play(int *X, int *d_new, int N){
    //a block of threads works on a row
    int glob_i = blockIdx.x; //which row
    int temp_i = glob_i;

    //shared memory size = 3 lines * N cells each
    extern __shared__ int localArray[];

    //read row above (i-1) and write to localArray[0][j]
    if (glob_i == 0){
        temp_i = N - 1; //cyclic boundary condition
    }else{
        temp_i = glob_i - 1; //simple case
    }
    for(int j = threadIdx.x; j < N; j+=blockDim.x){
        if(j<N){
            localArray[0*N + j] = X[(temp_i)*N + j];
        }
    }

    //read own row (i) and write to localArray[1][j]
    for(int j = threadIdx.x; j < N; j+=blockDim.x){
        if(j<N){
            localArray[1*N + j] = X[(glob_i)*N + j];
        }
    }

    //read from row below (i+1) and write to localArray[2][j]
    if(glob_i == N-1){
        temp_i = 0; //cyclic boundary condition
    }else{
        temp_i = glob_i + 1; //simple case
    }
    for(int j = threadIdx.x; j < N; j+=blockDim.x){
        if(j<N){
            localArray[2*N + j] = X[(temp_i)*N + j];
        }
    }
    //wait for shared memory to be "full"
    __syncthreads();

    //shared memory is now complete, we're ready to operate on it
    int up, down, left, right;
    for(int j = threadIdx.x; j < N; j+=blockDim.x){
        if (j < N){
            int idx = N*glob_i + j;

            up = 0;
            down = 2;
            //cyclic boundary conditions
            left =  j == 0 ? N - 1 : j - 1;
            right = j == N-1 ? 0 : j + 1; 

            int sum = 
                localArray[N*up+left]+       //i-1, j-1
                localArray[N*up+j]+          //i-1, j
                localArray[N*up+right]+      //i-1, j+1

                localArray[N*1+left]+        //i, j-1
                localArray[N*1+right]+       //i, j+1

                localArray[N*down+left]+     //i+1, j-1
                localArray[N*down+j]+        //i+1, j
                localArray[N*down+right];    //i+1, j+1

            
            //act based on rules - write to global array
            if(localArray[1*N + j] == 0  && sum == 3 ){
                d_new[idx]=1; //born
            }else if ( localArray[1*N + j] == 1  && (sum < 2 || sum>3 ) ){
                d_new[idx]=0; //dies - loneliness or overpopulation
            }else{
                d_new[idx] = localArray[1*N + j]; //nothing changes
            }
        }
    }
    return;
}

/**
 * main - plays the game of life for t steps according to the rules:
 * - A dead(0) cell with exactly 3 living neighbors becomes alive (birth)
 * - A dead(0) cell with any other number of neighbors stays dead (barren)
 * - A live(1) cell with 0 or 1 living neighbors dies (loneliness)
 * - A live(1) cell with 4 or more living neighbors dies (overpopulation)
 * - A live(1) cell with 2 or 3 living neighbors stays alive (survival)
 */
int main(int argc, char **argv){

    //sanity check for input
    if(argc !=4){
        printf("Usage: %s filename size t, where:\n", argv[0]);
        printf("\tfilename is the input file \n");
        printf("\tsize is the grid side and \n");
        printf("\tt generations to play\n");
        die("Wrong arguments");
    }

    //declarations
    char *filename = argv[1];
    int N = atoi(argv[2]);
    int t = atoi(argv[3]);
    int gen = 0;
    int *table = (int *)malloc(N*N*sizeof(int));
    if (!table)
        die("Couldn't allocate memory to table");

    //CUDA - divide the table in N blocks of 1 line, 512 threads per block
    dim3 threadsPerBlock(BLOCKLEN, 1); //max threads/block
    dim3 numBlocks(N, 1); //split board into blocks

    //CUDA - timing
    float gputime;
    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);

    //read input
    read_from_file(table, filename, N);

    //CUDA - copy to device
    int *d_table;
    cudaMalloc(&d_table, N*N*sizeof(int));
    int *d_new;
    cudaMalloc(&d_new, N*N*sizeof(int));
    cudaEventRecord(start, 0);
    cudaMemcpy(d_table, table, N*N*sizeof(int), cudaMemcpyHostToDevice);

    //play game for t generations
    for(gen=0; gen<t; gen++){

        //alternate between using d_table and d_new as temp
        if(gen%2==0){
            //3*N*sizeof(int): size for shared memory
            play<<<numBlocks, threadsPerBlock, 3*N*sizeof(int)>>>(d_table /*data*/, d_new /*temp*/, N);
        }else{
            play<<<numBlocks, threadsPerBlock, 3*N*sizeof(int)>>>(d_new /*data*/, d_table /*temp*/, N);
        }
        cudaDeviceSynchronize(); //don't continue if kernel not done

    }
    cudaEventRecord(stop, 0);

    cudaEventSynchronize(stop);
    cudaEventElapsedTime(&gputime, start, stop);
    printf("[%d]\t %g \n",gen, gputime/1000.0f);

    //copy back from device
    if(t%2==1){
        cudaMemcpy(table, d_new, N*N*sizeof(int), cudaMemcpyDeviceToHost);
    }else{
        cudaMemcpy(table, d_table, N*N*sizeof(int), cudaMemcpyDeviceToHost);
    }
    //save output for later
    write_to_file(table, filename, N);

    free(table);
    cudaFree(d_new);
    cudaFree(d_table);
    return 0;
}

/**
 * die - display an error and terminate.
 * Used when some fatal error happens
 * and continuing would mess things up.
 */
void die(const char *message){
    if(errno){
        perror(message);
    }else{
        printf("Error: %s\n", message);
    }
    exit(1);
}

/**
 * warn - display a warning and continue
 * used when something didn't go as expected
 */
void warn(const char *message){
    if(errno){
        perror(message);
    }else{
        printf("Warning: %s\n", message);
    }
    return;
}

/**
 * read_from_file - read N*N integer values from an appropriate file.
 * Saves the game's board into array X for use by other functions
 * Warns or kills the program if something goes wrong
 */
void read_from_file(int *X, char *filename, int N){

    FILE *fp = fopen(filename, "r+");
    int size = fread(X, sizeof(int), N*N, fp);
    if(!fp)
        die("Couldn't open file to read");
    if(!size)
        die("Couldn't read from file");
    if(N*N != size)
        warn("Expected to read different number of elements");

    printf("elements read: %d\n", size);

    fclose(fp);
    return;
}

/**
 * write_to_file - write N*N integer values to a binary file.
 * Saves game's board from array X to the file
 * Names the file tableNxN_new.bin, so the input file is not overwritten
 */
void write_to_file(int *X, char *filename, int N){

    //save as tableNxN_new.bin
    char newfilename[100];
    sprintf(newfilename, "cuda_table%dx%d.bin", N, N);
    printf("writing to: %s\n", newfilename);

    FILE *fp;
    int size;
    if( ! ( fp = fopen(newfilename, "w+") ) )
        die("Couldn't open file to write");
    if( ! (size = fwrite(X, sizeof(int), N*N, fp)) )
        die("Couldn't write to file");
    if (size != N*N)
        warn("Expected to write different number of elements");

    fclose(fp);
    return;
}

int nextPower(int N){
    int n=0;
    while(1){
        if(1<<n < N){
            n++;
        }else{
            return 1<<n;
        }
    }
}

	.file	"tmpxft_002ea8ad_00000000-6_golcuda.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2035:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2035:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Error: %s\n"
	.text
	.globl	_Z3diePKc
	.type	_Z3diePKc, @function
_Z3diePKc:
.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
	movq	%rdi, 8(%rsp)
	call	__errno_location@PLT
	movq	8(%rsp), %rdi
	cmpl	$0, (%rax)
	je	.L3
	call	perror@PLT
	jmp	.L4
.L3:
	movq	%rdi, %rdx
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L4:
	movl	$1, %edi
	call	exit@PLT
	.cfi_endproc
.LFE2028:
	.size	_Z3diePKc, .-_Z3diePKc
	.section	.rodata.str1.1
.LC1:
	.string	"Warning: %s\n"
	.text
	.globl	_Z4warnPKc
	.type	_Z4warnPKc, @function
_Z4warnPKc:
.LFB2029:
	.cfi_startproc
	endbr64
	subq	$24, %rsp
	.cfi_def_cfa_offset 32
	movq	%rdi, 8(%rsp)
	call	__errno_location@PLT
	movq	8(%rsp), %rdi
	cmpl	$0, (%rax)
	je	.L8
	addq	$24, %rsp
	.cfi_remember_state
	.cfi_def_cfa_offset 8
	jmp	perror@PLT
.L8:
	.cfi_restore_state
	movq	%rdi, %rdx
	leaq	.LC1(%rip), %rsi
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 8
	movl	$2, %edi
	jmp	__printf_chk@PLT
	.cfi_endproc
.LFE2029:
	.size	_Z4warnPKc, .-_Z4warnPKc
	.section	.rodata.str1.1
.LC2:
	.string	"r+"
.LC3:
	.string	"Couldn't read from file"
.LC4:
	.string	"Expected to read different number of elements"
.LC5:
	.string	"elements read: %d\n"
	.text
	.globl	_Z14read_from_filePiPci
	.type	_Z14read_from_filePiPci, @function
_Z14read_from_filePiPci:
.LFB2030:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	movq	%rsi, %rdi
	leaq	.LC2(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%edx, %ebx
	imull	%ebx, %ebx
	call	fopen@PLT
	orq	$-1, %rsi
	movl	$4, %edx
	movq	%r12, %rdi
	movslq	%ebx, %rcx
	movq	%rax, %r8
	movq	%rax, %rbp
	call	__fread_chk@PLT
	testl	%eax, %eax
	jne	.L11
	leaq	.LC3(%rip), %rdi
	call	_Z3diePKc
.L11:
	movl	%eax, %r12d
	cmpl	%eax, %ebx
	je	.L12
	leaq	.LC4(%rip), %rdi
	call	_Z4warnPKc
.L12:
	movl	%r12d, %edx
	movl	$2, %edi
	leaq	.LC5(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	popq	%rbx
	.cfi_def_cfa_offset 24
	movq	%rbp, %rdi
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE2030:
	.size	_Z14read_from_filePiPci, .-_Z14read_from_filePiPci
	.section	.rodata.str1.1
.LC6:
	.string	"cuda_table%dx%d.bin"
.LC7:
	.string	"writing to: %s\n"
.LC8:
	.string	"w+"
.LC9:
	.string	"Couldn't open file to write"
.LC10:
	.string	"Couldn't write to file"
.LC11:
	.string	"Expected to write different number of elements"
	.text
	.globl	_Z13write_to_filePiPci
	.type	_Z13write_to_filePiPci, @function
_Z13write_to_filePiPci:
.LFB2031:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movl	%edx, %r9d
	movl	%edx, %r8d
	leaq	.LC6(%rip), %rcx
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	movl	$2, %esi
	movq	%rdi, %r12
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	movl	%edx, %ebx
	movl	$100, %edx
	subq	$112, %rsp
	.cfi_def_cfa_offset 144
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	4(%rsp), %rbp
	movq	%rbp, %rdi
	call	__sprintf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	movq	%rbp, %rdx
	leaq	.LC7(%rip), %rsi
	call	__printf_chk@PLT
	leaq	.LC8(%rip), %rsi
	movq	%rbp, %rdi
	call	fopen@PLT
	testq	%rax, %rax
	jne	.L15
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC9(%rip), %rdi
	je	.L23
	jmp	.L24
.L15:
	imull	%ebx, %ebx
	movq	%rax, %rcx
	movl	$4, %esi
	movq	%r12, %rdi
	movq	%rax, %rbp
	movslq	%ebx, %rdx
	call	fwrite@PLT
	testl	%eax, %eax
	jne	.L17
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC10(%rip), %rdi
	jne	.L24
.L23:
	call	_Z3diePKc
.L17:
	cmpl	%eax, %ebx
	je	.L19
	leaq	.LC11(%rip), %rdi
	call	_Z4warnPKc
.L19:
	movq	%rbp, %rdi
	call	fclose@PLT
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L20
.L24:
	call	__stack_chk_fail@PLT
.L20:
	addq	$112, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2031:
	.size	_Z13write_to_filePiPci, .-_Z13write_to_filePiPci
	.globl	_Z9nextPoweri
	.type	_Z9nextPoweri, @function
_Z9nextPoweri:
.LFB2032:
	.cfi_startproc
	endbr64
	xorl	%ecx, %ecx
	movl	$1, %edx
.L27:
	movl	%edx, %eax
	sall	%cl, %eax
	cmpl	%edi, %eax
	jge	.L25
	incl	%ecx
	jmp	.L27
.L25:
	ret
	.cfi_endproc
.LFE2032:
	.size	_Z9nextPoweri, .-_Z9nextPoweri
	.globl	_Z26__device_stub__Z4playPiS_iPiS_i
	.type	_Z26__device_stub__Z4playPiS_iPiS_i, @function
_Z26__device_stub__Z4playPiS_iPiS_i:
.LFB2057:
	.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
	movl	%edx, 12(%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	12(%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	.L28
	pushq	40(%rsp)
	.cfi_def_cfa_offset 152
	leaq	_Z4playPiS_i(%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
.L28:
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	je	.L30
	call	__stack_chk_fail@PLT
.L30:
	addq	$136, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2057:
	.size	_Z26__device_stub__Z4playPiS_iPiS_i, .-_Z26__device_stub__Z4playPiS_iPiS_i
	.globl	_Z4playPiS_i
	.type	_Z4playPiS_i, @function
_Z4playPiS_i:
.LFB2058:
	.cfi_startproc
	endbr64
	jmp	_Z26__device_stub__Z4playPiS_iPiS_i
	.cfi_endproc
.LFE2058:
	.size	_Z4playPiS_i, .-_Z4playPiS_i
	.section	.rodata.str1.1
.LC12:
	.string	"Usage: %s filename size t, where:\n"
.LC13:
	.string	"\tfilename is the input file \n"
.LC14:
	.string	"\tsize is the grid side and \n"
.LC15:
	.string	"\tt generations to play\n"
.LC16:
	.string	"Wrong arguments"
.LC17:
	.string	"Couldn't allocate memory to table"
.LC19:
	.string	"[%d]\t %g \n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movq	%rsi, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	subq	$104, %rsp
	.cfi_def_cfa_offset 160
	movq	%fs:40, %rax
	movq	%rax, 88(%rsp)
	xorl	%eax, %eax
	cmpl	$4, %edi
	je	.L34
	movq	(%rsi), %rdx
	movl	$2, %edi
	leaq	.LC12(%rip), %rsi
	call	__printf_chk@PLT
	leaq	.LC13(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	leaq	.LC14(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	$2, %edi
	xorl	%eax, %eax
	leaq	.LC15(%rip), %rsi
	call	__printf_chk@PLT
	leaq	.LC16(%rip), %rdi
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L51
	jmp	.L52
.L34:
	movq	16(%rsi), %rdi
	movq	8(%rsi), %r15
	call	atoi@PLT
	movq	24(%rbp), %rdi
	movl	%eax, %ebx
	call	atoi@PLT
	movl	%eax, %r12d
	movl	%ebx, %eax
	imull	%ebx, %eax
	cltq
	salq	$2, %rax
	movq	%rax, %rdi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movq	%rax, %rbp
	testq	%rax, %rax
	jne	.L36
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	leaq	.LC17(%rip), %rdi
	jne	.L52
.L51:
	call	_Z3diePKc
.L36:
	movl	$8388609, %eax
	movl	%ebx, 76(%rsp)
	leal	(%rbx,%rbx,2), %r13d
	xorl	%r14d, %r14d
	salq	$9, %rax
	leaq	32(%rsp), %rdi
	movl	$1, 72(%rsp)
	movslq	%r13d, %r13
	movq	%rax, 64(%rsp)
	subq	$511, %rax
	salq	$2, %r13
	movq	%rax, 80(%rsp)
	call	cudaEventCreate@PLT
	leaq	40(%rsp), %rdi
	call	cudaEventCreate@PLT
	movl	%ebx, %edx
	movq	%r15, %rsi
	movq	%rbp, %rdi
	call	_Z14read_from_filePiPci
	movq	8(%rsp), %rsi
	leaq	48(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rsi
	leaq	56(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	8(%rsp), %rdx
	movq	48(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
.L38:
	cmpl	%r12d, %r14d
	jge	.L53
	xorl	%r9d, %r9d
	movq	64(%rsp), %rdx
	movl	72(%rsp), %ecx
	movq	%r13, %r8
	testl	$1, %r14d
	movq	76(%rsp), %rdi
	movl	84(%rsp), %esi
	jne	.L39
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L41
	movq	56(%rsp), %rsi
	movq	48(%rsp), %rdi
	movl	%ebx, %edx
	jmp	.L48
.L39:
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L41
	movq	48(%rsp), %rsi
	movq	56(%rsp), %rdi
	movl	%ebx, %edx
.L48:
	call	_Z26__device_stub__Z4playPiS_iPiS_i
.L41:
	call	cudaDeviceSynchronize@PLT
	incl	%r14d
	jmp	.L38
.L53:
	movq	40(%rsp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	40(%rsp), %rdi
	call	cudaEventSynchronize@PLT
	movq	40(%rsp), %rdx
	movq	32(%rsp), %rsi
	leaq	28(%rsp), %rdi
	call	cudaEventElapsedTime@PLT
	xorl	%edx, %edx
	testl	%r12d, %r12d
	movl	$2, %edi
	cmovns	%r12d, %edx
	leaq	.LC19(%rip), %rsi
	movb	$1, %al
	movss	28(%rsp), %xmm0
	divss	.LC18(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	call	__printf_chk@PLT
	movl	%r12d, %eax
	movl	$2, %ecx
	cltd
	idivl	%ecx
	decl	%edx
	jne	.L44
	movq	8(%rsp), %rdx
	movq	56(%rsp), %rsi
	jmp	.L49
.L44:
	movq	8(%rsp), %rdx
	movq	48(%rsp), %rsi
	movl	$2, %ecx
.L49:
	movq	%rbp, %rdi
	call	cudaMemcpy@PLT
	movl	%ebx, %edx
	movq	%r15, %rsi
	movq	%rbp, %rdi
	call	_Z13write_to_filePiPci
	movq	%rbp, %rdi
	call	free@PLT
	movq	56(%rsp), %rdi
	call	cudaFree@PLT
	movq	48(%rsp), %rdi
	call	cudaFree@PLT
	movq	88(%rsp), %rax
	subq	%fs:40, %rax
	je	.L46
.L52:
	call	__stack_chk_fail@PLT
.L46:
	addq	$104, %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
.LFE2027:
	.size	main, .-main
	.section	.rodata.str1.1
.LC20:
	.string	"_Z4playPiS_i"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2060:
	.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	.LC20(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z4playPiS_i(%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
.LFE2060:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC18:
	.long	1148846080
	.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:

/** \file
*/

#include <hip/hip_runtime.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#include <stdint.h>

#define BLOCKLEN 512

int nextPower(int);
void die(const char *);
void warn(const char *);
void read_from_file(int *, char *, int);
void write_to_file(int *, char *, int);

/**
 * play - Plays the game for one step.
 * First, counts the neighbors, taking into account boundary conditions
 * Then, acts on the rules.
 * Updates need to happen all together, so a temporary new array is allocated
 */
__global__ void play(int *X, int *d_new, int N){
    //a block of threads works on a row
    int glob_i = blockIdx.x; //which row
    int temp_i = glob_i;

    //shared memory size = 3 lines * N cells each
    extern __shared__ int localArray[];

    //read row above (i-1) and write to localArray[0][j]
    if (glob_i == 0){
        temp_i = N - 1; //cyclic boundary condition
    }else{
        temp_i = glob_i - 1; //simple case
    }
    for(int j = threadIdx.x; j < N; j+=blockDim.x){
        if(j<N){
            localArray[0*N + j] = X[(temp_i)*N + j];
        }
    }

    //read own row (i) and write to localArray[1][j]
    for(int j = threadIdx.x; j < N; j+=blockDim.x){
        if(j<N){
            localArray[1*N + j] = X[(glob_i)*N + j];
        }
    }

    //read from row below (i+1) and write to localArray[2][j]
    if(glob_i == N-1){
        temp_i = 0; //cyclic boundary condition
    }else{
        temp_i = glob_i + 1; //simple case
    }
    for(int j = threadIdx.x; j < N; j+=blockDim.x){
        if(j<N){
            localArray[2*N + j] = X[(temp_i)*N + j];
        }
    }
    //wait for shared memory to be "full"
    __syncthreads();

    //shared memory is now complete, we're ready to operate on it
    int up, down, left, right;
    for(int j = threadIdx.x; j < N; j+=blockDim.x){
        if (j < N){
            int idx = N*glob_i + j;

            up = 0;
            down = 2;
            //cyclic boundary conditions
            left =  j == 0 ? N - 1 : j - 1;
            right = j == N-1 ? 0 : j + 1; 

            int sum = 
                localArray[N*up+left]+       //i-1, j-1
                localArray[N*up+j]+          //i-1, j
                localArray[N*up+right]+      //i-1, j+1

                localArray[N*1+left]+        //i, j-1
                localArray[N*1+right]+       //i, j+1

                localArray[N*down+left]+     //i+1, j-1
                localArray[N*down+j]+        //i+1, j
                localArray[N*down+right];    //i+1, j+1

            
            //act based on rules - write to global array
            if(localArray[1*N + j] == 0  && sum == 3 ){
                d_new[idx]=1; //born
            }else if ( localArray[1*N + j] == 1  && (sum < 2 || sum>3 ) ){
                d_new[idx]=0; //dies - loneliness or overpopulation
            }else{
                d_new[idx] = localArray[1*N + j]; //nothing changes
            }
        }
    }
    return;
}

/**
 * main - plays the game of life for t steps according to the rules:
 * - A dead(0) cell with exactly 3 living neighbors becomes alive (birth)
 * - A dead(0) cell with any other number of neighbors stays dead (barren)
 * - A live(1) cell with 0 or 1 living neighbors dies (loneliness)
 * - A live(1) cell with 4 or more living neighbors dies (overpopulation)
 * - A live(1) cell with 2 or 3 living neighbors stays alive (survival)
 */
int main(int argc, char **argv){

    //sanity check for input
    if(argc !=4){
        printf("Usage: %s filename size t, where:\n", argv[0]);
        printf("\tfilename is the input file \n");
        printf("\tsize is the grid side and \n");
        printf("\tt generations to play\n");
        die("Wrong arguments");
    }

    //declarations
    char *filename = argv[1];
    int N = atoi(argv[2]);
    int t = atoi(argv[3]);
    int gen = 0;
    int *table = (int *)malloc(N*N*sizeof(int));
    if (!table)
        die("Couldn't allocate memory to table");

    //CUDA - divide the table in N blocks of 1 line, 512 threads per block
    dim3 threadsPerBlock(BLOCKLEN, 1); //max threads/block
    dim3 numBlocks(N, 1); //split board into blocks

    //CUDA - timing
    float gputime;
    hipEvent_t start, stop;
    hipEventCreate(&start);
    hipEventCreate(&stop);

    //read input
    read_from_file(table, filename, N);

    //CUDA - copy to device
    int *d_table;
    hipMalloc(&d_table, N*N*sizeof(int));
    int *d_new;
    hipMalloc(&d_new, N*N*sizeof(int));
    hipEventRecord(start, 0);
    hipMemcpy(d_table, table, N*N*sizeof(int), hipMemcpyHostToDevice);

    //play game for t generations
    for(gen=0; gen<t; gen++){

        //alternate between using d_table and d_new as temp
        if(gen%2==0){
            //3*N*sizeof(int): size for shared memory
            play<<<numBlocks, threadsPerBlock, 3*N*sizeof(int)>>>(d_table /*data*/, d_new /*temp*/, N);
        }else{
            play<<<numBlocks, threadsPerBlock, 3*N*sizeof(int)>>>(d_new /*data*/, d_table /*temp*/, N);
        }
        hipDeviceSynchronize(); //don't continue if kernel not done

    }
    hipEventRecord(stop, 0);

    hipEventSynchronize(stop);
    hipEventElapsedTime(&gputime, start, stop);
    printf("[%d]\t %g \n",gen, gputime/1000.0f);

    //copy back from device
    if(t%2==1){
        hipMemcpy(table, d_new, N*N*sizeof(int), hipMemcpyDeviceToHost);
    }else{
        hipMemcpy(table, d_table, N*N*sizeof(int), hipMemcpyDeviceToHost);
    }
    //save output for later
    write_to_file(table, filename, N);

    free(table);
    hipFree(d_new);
    hipFree(d_table);
    return 0;
}

/**
 * die - display an error and terminate.
 * Used when some fatal error happens
 * and continuing would mess things up.
 */
void die(const char *message){
    if(errno){
        perror(message);
    }else{
        printf("Error: %s\n", message);
    }
    exit(1);
}

/**
 * warn - display a warning and continue
 * used when something didn't go as expected
 */
void warn(const char *message){
    if(errno){
        perror(message);
    }else{
        printf("Warning: %s\n", message);
    }
    return;
}

/**
 * read_from_file - read N*N integer values from an appropriate file.
 * Saves the game's board into array X for use by other functions
 * Warns or kills the program if something goes wrong
 */
void read_from_file(int *X, char *filename, int N){

    FILE *fp = fopen(filename, "r+");
    int size = fread(X, sizeof(int), N*N, fp);
    if(!fp)
        die("Couldn't open file to read");
    if(!size)
        die("Couldn't read from file");
    if(N*N != size)
        warn("Expected to read different number of elements");

    printf("elements read: %d\n", size);

    fclose(fp);
    return;
}

/**
 * write_to_file - write N*N integer values to a binary file.
 * Saves game's board from array X to the file
 * Names the file tableNxN_new.bin, so the input file is not overwritten
 */
void write_to_file(int *X, char *filename, int N){

    //save as tableNxN_new.bin
    char newfilename[100];
    sprintf(newfilename, "cuda_table%dx%d.bin", N, N);
    printf("writing to: %s\n", newfilename);

    FILE *fp;
    int size;
    if( ! ( fp = fopen(newfilename, "w+") ) )
        die("Couldn't open file to write");
    if( ! (size = fwrite(X, sizeof(int), N*N, fp)) )
        die("Couldn't write to file");
    if (size != N*N)
        warn("Expected to write different number of elements");

    fclose(fp);
    return;
}

int nextPower(int N){
    int n=0;
    while(1){
        if(1<<n < N){
            n++;
        }else{
            return 1<<n;
        }
    }
}

	.text
	.file	"golcuda.hip"
	.globl	_Z19__device_stub__playPiS_i    # -- Begin function _Z19__device_stub__playPiS_i
	.type	_Z19__device_stub__playPiS_i,@function
_Z19__device_stub__playPiS_i:           # @_Z19__device_stub__playPiS_i
	.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	12(%rsp), %rsi
	movl	%edx, (%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	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	$_Z4playPiS_i, %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_end0:
	.size	_Z19__device_stub__playPiS_i, .Lfunc_end0-_Z19__device_stub__playPiS_i
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI1_0:
	.long	0x447a0000                      # float 1000
	.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	%rsi, %r15
	cmpl	$4, %edi
	jne	.LBB1_13
# %bb.1:
	movq	8(%r15), %r14
	movq	16(%r15), %rdi
	callq	atoi
	movl	%eax, %ebx
	movq	24(%r15), %rdi
	callq	atoi
	movl	%eax, %ebp
	movl	%ebx, %r13d
	imull	%r13d, %r13d
	shlq	$2, %r13
	movq	%r13, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB1_14
# %bb.2:
	movq	%rax, %r15
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
	leaq	16(%rsp), %rdi
	callq	hipEventCreate
	movq	%r15, %rdi
	movq	%r14, %rsi
	movl	%ebx, %edx
	callq	_Z14read_from_filePiPci
	leaq	8(%rsp), %r12
	movq	%r12, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	%rsp, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	leaq	24(%rsp), %rax
	movq	(%rax), %rdi
	xorl	%r14d, %r14d
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%r12), %rdi
	movq	%r15, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%ebp, %ebp
	jle	.LBB1_12
# %bb.3:                                # %.lr.ph
	movq	%r13, 32(%rsp)                  # 8-byte Spill
	movq	%r15, 40(%rsp)                  # 8-byte Spill
	movabsq	$4294967296, %r13               # imm = 0x100000000
	movl	%ebx, %r14d
	btsq	$32, %r14
	leal	(%rbx,%rbx,2), %eax
	movslq	%eax, %r12
	shlq	$2, %r12
	xorl	%r15d, %r15d
	addq	$512, %r13                      # imm = 0x200
.LBB1_4:                                # =>This Inner Loop Header: Depth=1
	movq	%r14, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	movq	%r12, %r8
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testb	$1, %r15b
	jne	.LBB1_7
# %bb.5:                                #   in Loop: Header=BB1_4 Depth=1
	testl	%eax, %eax
	jne	.LBB1_10
# %bb.6:                                #   in Loop: Header=BB1_4 Depth=1
	movq	8(%rsp), %rdi
	movq	(%rsp), %rsi
	jmp	.LBB1_9
.LBB1_7:                                #   in Loop: Header=BB1_4 Depth=1
	testl	%eax, %eax
	jne	.LBB1_10
# %bb.8:                                #   in Loop: Header=BB1_4 Depth=1
	movq	(%rsp), %rdi
	movq	8(%rsp), %rsi
.LBB1_9:                                #   in Loop: Header=BB1_4 Depth=1
	movl	%ebx, %edx
	callq	_Z19__device_stub__playPiS_i
.LBB1_10:                               #   in Loop: Header=BB1_4 Depth=1
	callq	hipDeviceSynchronize
	incl	%r15d
	cmpl	%r15d, %ebp
	jne	.LBB1_4
# %bb.11:
	movl	%ebp, %r14d
	movq	40(%rsp), %r15                  # 8-byte Reload
	movq	32(%rsp), %r13                  # 8-byte Reload
.LBB1_12:                               # %._crit_edge
	movq	16(%rsp), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	16(%rsp), %rdi
	callq	hipEventSynchronize
	movq	24(%rsp), %rsi
	movq	16(%rsp), %rdx
	leaq	52(%rsp), %r12
	movq	%r12, %rdi
	callq	hipEventElapsedTime
	movss	(%r12), %xmm0                   # xmm0 = mem[0],zero,zero,zero
	divss	.LCPI1_0(%rip), %xmm0
	cvtss2sd	%xmm0, %xmm0
	movl	$.L.str.6, %edi
	movl	%r14d, %esi
	movb	$1, %al
	callq	printf
	andl	$-2147483647, %ebp              # imm = 0x80000001
	cmpl	$1, %ebp
	leaq	8(%rsp), %rax
	movq	%rsp, %rcx
	cmoveq	%rcx, %rax
	movq	(%rax), %rsi
	movq	%r15, %rdi
	movq	%r13, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%r15, %rdi
	movl	%ebx, %edx
	callq	_Z13write_to_filePiPci
	movq	%r15, %rdi
	callq	free
	movq	(%rsp), %rdi
	callq	hipFree
	movq	8(%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
.LBB1_13:
	.cfi_def_cfa_offset 112
	movq	(%r15), %rsi
	movl	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$.Lstr.1, %edi
	callq	puts@PLT
	movl	$.Lstr.2, %edi
	callq	puts@PLT
	movl	$.L.str.4, %edi
	callq	_Z3diePKc
.LBB1_14:
	movl	$.L.str.5, %edi
	callq	_Z3diePKc
.Lfunc_end1:
	.size	main, .Lfunc_end1-main
	.cfi_endproc
                                        # -- End function
	.globl	_Z3diePKc                       # -- Begin function _Z3diePKc
	.type	_Z3diePKc,@function
_Z3diePKc:                              # @_Z3diePKc
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	callq	__errno_location
	cmpl	$0, (%rax)
	je	.LBB2_2
# %bb.1:
	movq	%rbx, %rdi
	callq	perror
.LBB2_3:
	movl	$1, %edi
	callq	exit
.LBB2_2:
	movl	$.L.str.7, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB2_3
.Lfunc_end2:
	.size	_Z3diePKc, .Lfunc_end2-_Z3diePKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z14read_from_filePiPci         # -- Begin function _Z14read_from_filePiPci
	.type	_Z14read_from_filePiPci,@function
_Z14read_from_filePiPci:                # @_Z14read_from_filePiPci
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.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 %r15, -16
	movl	%edx, %r14d
	movq	%rsi, %rax
	movq	%rdi, %r15
	movl	$.L.str.9, %esi
	movq	%rax, %rdi
	callq	fopen
	movq	%rax, %rbx
	imull	%r14d, %r14d
	movl	$4, %esi
	movq	%r15, %rdi
	movq	%r14, %rdx
	movq	%rax, %rcx
	callq	fread
	testq	%rbx, %rbx
	je	.LBB3_5
# %bb.1:
	movq	%rax, %r15
	testl	%r15d, %r15d
	je	.LBB3_6
# %bb.2:
	cmpl	%r15d, %r14d
	je	.LBB3_4
# %bb.3:
	movl	$.L.str.12, %edi
	callq	_Z4warnPKc
.LBB3_4:
	movl	$.L.str.13, %edi
	movl	%r15d, %esi
	xorl	%eax, %eax
	callq	printf
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.LBB3_5:
	.cfi_def_cfa_offset 32
	movl	$.L.str.10, %edi
	callq	_Z3diePKc
.LBB3_6:
	movl	$.L.str.11, %edi
	callq	_Z3diePKc
.Lfunc_end3:
	.size	_Z14read_from_filePiPci, .Lfunc_end3-_Z14read_from_filePiPci
	.cfi_endproc
                                        # -- End function
	.globl	_Z13write_to_filePiPci          # -- Begin function _Z13write_to_filePiPci
	.type	_Z13write_to_filePiPci,@function
_Z13write_to_filePiPci:                 # @_Z13write_to_filePiPci
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	subq	$112, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	%edx, %ebx
	movq	%rdi, %r14
	movq	%rsp, %r15
	movl	$.L.str.14, %esi
	movq	%r15, %rdi
	movl	%edx, %ecx
	xorl	%eax, %eax
	callq	sprintf
	movl	$.L.str.15, %edi
	movq	%r15, %rsi
	xorl	%eax, %eax
	callq	printf
	movl	$.L.str.16, %esi
	movq	%r15, %rdi
	callq	fopen
	testq	%rax, %rax
	je	.LBB4_5
# %bb.1:
	movq	%rax, %r15
	imull	%ebx, %ebx
	movl	$4, %esi
	movq	%r14, %rdi
	movq	%rbx, %rdx
	movq	%rax, %rcx
	callq	fwrite
	testl	%eax, %eax
	je	.LBB4_6
# %bb.2:
	cmpl	%eax, %ebx
	je	.LBB4_4
# %bb.3:
	movl	$.L.str.19, %edi
	callq	_Z4warnPKc
.LBB4_4:
	movq	%r15, %rdi
	callq	fclose
	addq	$112, %rsp
	.cfi_def_cfa_offset 32
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB4_5:
	.cfi_def_cfa_offset 144
	movl	$.L.str.17, %edi
	callq	_Z3diePKc
.LBB4_6:
	movl	$.L.str.18, %edi
	callq	_Z3diePKc
.Lfunc_end4:
	.size	_Z13write_to_filePiPci, .Lfunc_end4-_Z13write_to_filePiPci
	.cfi_endproc
                                        # -- End function
	.globl	_Z4warnPKc                      # -- Begin function _Z4warnPKc
	.type	_Z4warnPKc,@function
_Z4warnPKc:                             # @_Z4warnPKc
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	movq	%rdi, %rbx
	callq	__errno_location
	cmpl	$0, (%rax)
	jne	.LBB5_1
# %bb.2:
	movl	$.L.str.8, %edi
	movq	%rbx, %rsi
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	printf                          # TAILCALL
.LBB5_1:
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	perror                          # TAILCALL
.Lfunc_end5:
	.size	_Z4warnPKc, .Lfunc_end5-_Z4warnPKc
	.cfi_endproc
                                        # -- End function
	.globl	_Z9nextPoweri                   # -- Begin function _Z9nextPoweri
	.type	_Z9nextPoweri,@function
_Z9nextPoweri:                          # @_Z9nextPoweri
	.cfi_startproc
# %bb.0:
	xorl	%ecx, %ecx
.LBB6_1:                                # =>This Inner Loop Header: Depth=1
	movl	$1, %eax
	shll	%cl, %eax
	incl	%ecx
	cmpl	%edi, %eax
	jl	.LBB6_1
# %bb.2:
	retq
.Lfunc_end6:
	.size	_Z9nextPoweri, .Lfunc_end6-_Z9nextPoweri
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB7_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB7_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z4playPiS_i, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end7:
	.size	__hip_module_ctor, .Lfunc_end7-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB8_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB8_2:
	retq
.Lfunc_end8:
	.size	__hip_module_dtor, .Lfunc_end8-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z4playPiS_i,@object            # @_Z4playPiS_i
	.section	.rodata,"a",@progbits
	.globl	_Z4playPiS_i
	.p2align	3, 0x0
_Z4playPiS_i:
	.quad	_Z19__device_stub__playPiS_i
	.size	_Z4playPiS_i, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Usage: %s filename size t, where:\n"
	.size	.L.str, 35

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Wrong arguments"
	.size	.L.str.4, 16

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Couldn't allocate memory to table"
	.size	.L.str.5, 34

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"[%d]\t %g \n"
	.size	.L.str.6, 11

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Error: %s\n"
	.size	.L.str.7, 11

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Warning: %s\n"
	.size	.L.str.8, 13

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"r+"
	.size	.L.str.9, 3

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	"Couldn't open file to read"
	.size	.L.str.10, 27

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	"Couldn't read from file"
	.size	.L.str.11, 24

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Expected to read different number of elements"
	.size	.L.str.12, 46

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"elements read: %d\n"
	.size	.L.str.13, 19

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	"cuda_table%dx%d.bin"
	.size	.L.str.14, 20

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"writing to: %s\n"
	.size	.L.str.15, 16

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"w+"
	.size	.L.str.16, 3

	.type	.L.str.17,@object               # @.str.17
.L.str.17:
	.asciz	"Couldn't open file to write"
	.size	.L.str.17, 28

	.type	.L.str.18,@object               # @.str.18
.L.str.18:
	.asciz	"Couldn't write to file"
	.size	.L.str.18, 23

	.type	.L.str.19,@object               # @.str.19
.L.str.19:
	.asciz	"Expected to write different number of elements"
	.size	.L.str.19, 47

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z4playPiS_i"
	.size	.L__unnamed_1, 13

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"\tfilename is the input file "
	.size	.Lstr, 29

	.type	.Lstr.1,@object                 # @str.1
.Lstr.1:
	.asciz	"\tsize is the grid side and "
	.size	.Lstr.1, 28

	.type	.Lstr.2,@object                 # @str.2
.Lstr.2:
	.asciz	"\tt generations to play"
	.size	.Lstr.2, 23

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z19__device_stub__playPiS_i
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z4playPiS_i
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z4playPiS_i            ; -- Begin function _Z4playPiS_i
	.globl	_Z4playPiS_i
	.p2align	8
	.type	_Z4playPiS_i,@function
_Z4playPiS_i:                           ; @_Z4playPiS_i
; %bb.0:
	s_clause 0x1
	s_load_b32 s3, s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	v_lshl_add_u32 v3, v0, 2, 0
	s_waitcnt lgkmcnt(0)
	v_cmp_gt_i32_e32 vcc_lo, s3, v0
	s_mul_i32 s10, s15, s3
	s_and_saveexec_b32 s11, vcc_lo
	s_cbranch_execz .LBB0_5
; %bb.1:                                ; %.lr.ph
	s_load_b32 s2, s[0:1], 0x24
	s_cmp_eq_u32 s15, 0
	v_lshl_add_u32 v1, v0, 2, 0
	s_cselect_b32 s8, s3, s15
	v_mov_b32_e32 v2, v0
	s_add_i32 s14, s8, -1
	s_add_u32 s8, s0, 24
	s_addc_u32 s9, s1, 0
	s_mov_b32 s12, 0
	s_mul_i32 s14, s14, s3
	s_waitcnt lgkmcnt(0)
	s_and_b32 s13, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b32 s16, s13, 2
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v4, s14, v2
	v_add_nc_u32_e32 v2, s13, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v4, s2, s4, v4
	v_add_co_ci_u32_e64 v5, s2, s5, v5, s2
	v_cmp_le_i32_e64 s2, s3, v2
	global_load_b32 v4, v[4:5], off
	s_or_b32 s12, s2, s12
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v4
	v_add_nc_u32_e32 v1, s16, v1
	s_and_not1_b32 exec_lo, exec_lo, s12
	s_cbranch_execnz .LBB0_2
; %bb.3:                                ; %.preheader
	s_or_b32 exec_lo, exec_lo, s12
	s_load_b32 s2, s[8:9], 0xc
	v_dual_mov_b32 v2, v0 :: v_dual_add_nc_u32 v1, s3, v0
	s_mov_b32 s9, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(SALU_CYCLE_1)
	v_lshl_add_u32 v1, v1, 2, 0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s8, s2, 0xffff
	s_lshl_b32 s12, s8, 2
.LBB0_4:                                ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v4, s10, v2
	v_add_nc_u32_e32 v2, s8, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v4, s2, s4, v4
	v_add_co_ci_u32_e64 v5, s2, s5, v5, s2
	v_cmp_le_i32_e64 s2, s3, v2
	global_load_b32 v4, v[4:5], off
	s_or_b32 s9, s2, s9
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v4
	v_add_nc_u32_e32 v1, s12, v1
	s_and_not1_b32 exec_lo, exec_lo, s9
	s_cbranch_execnz .LBB0_4
.LBB0_5:                                ; %Flow141
	s_or_b32 exec_lo, exec_lo, s11
	s_add_i32 s8, s3, -1
	s_and_saveexec_b32 s9, vcc_lo
	s_cbranch_execz .LBB0_8
; %bb.6:                                ; %.lr.ph109
	s_load_b32 s2, s[0:1], 0x24
	s_add_i32 s11, s15, 1
	v_dual_mov_b32 v2, v0 :: v_dual_lshlrev_b32 v1, 2, v0
	s_cmp_lg_u32 s15, s8
	s_cselect_b32 s13, s11, 0
	s_lshl_b32 s12, s3, 3
	s_mov_b32 s11, 0
	v_add3_u32 v1, 0, s12, v1
	s_mul_i32 s13, s13, s3
	s_waitcnt lgkmcnt(0)
	s_and_b32 s12, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b32 s14, s12, 2
.LBB0_7:                                ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v4, s13, v2
	v_add_nc_u32_e32 v2, s12, v2
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ashrrev_i32_e32 v5, 31, v4
	v_lshlrev_b64 v[4:5], 2, v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_co_u32 v4, s2, s4, v4
	v_add_co_ci_u32_e64 v5, s2, s5, v5, s2
	v_cmp_le_i32_e64 s2, s3, v2
	global_load_b32 v4, v[4:5], off
	s_or_b32 s11, s2, s11
	s_waitcnt vmcnt(0)
	ds_store_b32 v1, v4
	v_add_nc_u32_e32 v1, s14, v1
	s_and_not1_b32 exec_lo, exec_lo, s11
	s_cbranch_execnz .LBB0_7
.LBB0_8:                                ; %Flow139
	s_or_b32 exec_lo, exec_lo, s9
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_19
; %bb.9:                                ; %.lr.ph113
	s_load_b32 s0, s[0:1], 0x24
	v_dual_mov_b32 v4, 0 :: v_dual_mov_b32 v5, 1
	s_lshl_b32 s2, s3, 2
	s_mov_b32 s5, 0
	s_lshl_b32 s11, s3, 3
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s0, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	s_lshl_b32 s9, s4, 2
.LBB0_10:                               ; =>This Inner Loop Header: Depth=1
	v_add_nc_u32_e32 v2, 1, v0
	v_add_nc_u32_e32 v1, -1, v0
	v_cmp_eq_u32_e32 vcc_lo, 0, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cndmask_b32_e64 v1, v1, s8, vcc_lo
	v_cmp_ne_u32_e32 vcc_lo, s8, v0
	v_lshl_add_u32 v1, v1, 2, 0
	v_cndmask_b32_e32 v2, 0, v2, vcc_lo
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v6, s2, v1
	v_lshl_add_u32 v2, v2, 2, 0
	ds_load_b32 v7, v3
	ds_load_b32 v1, v1
	v_add_nc_u32_e32 v9, s2, v6
	v_add_nc_u32_e32 v8, s2, v2
	ds_load_b32 v2, v2
	ds_load_b32 v10, v6
	v_add_nc_u32_e32 v6, s11, v3
	ds_load_b32 v11, v8
	ds_load_b32 v9, v9
	v_add_nc_u32_e32 v8, s2, v8
	ds_load_b32 v12, v6
	v_add_nc_u32_e32 v6, s2, v3
	ds_load_b32 v8, v8
	ds_load_b32 v6, v6
	s_waitcnt lgkmcnt(7)
	v_add_nc_u32_e32 v1, v7, v1
	s_waitcnt lgkmcnt(5)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_add3_u32 v1, v1, v2, v10
	s_waitcnt lgkmcnt(3)
	v_add3_u32 v1, v1, v11, v9
	s_waitcnt lgkmcnt(1)
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_3) | instid1(VALU_DEP_3)
	v_add3_u32 v7, v1, v12, v8
	v_add_nc_u32_e32 v1, s10, v0
	s_waitcnt lgkmcnt(0)
	v_cmp_ne_u32_e32 vcc_lo, 0, v6
	v_cmp_ne_u32_e64 s0, 3, v7
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v2, 31, v1
	s_or_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s1, s0
	s_xor_b32 s12, exec_lo, s1
	s_cbranch_execz .LBB0_16
; %bb.11:                               ;   in Loop: Header=BB0_10 Depth=1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	v_add_nc_u32_e32 v7, -4, v7
	v_cmp_ne_u32_e32 vcc_lo, 1, v6
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_cmp_lt_u32_e64 s0, -3, v7
	v_add_co_u32 v1, s1, s6, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_ci_u32_e64 v2, s1, s7, v2, s1
	s_or_b32 s0, vcc_lo, s0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s1, s0
	s_xor_b32 s0, exec_lo, s1
	s_cbranch_execz .LBB0_13
; %bb.12:                               ;   in Loop: Header=BB0_10 Depth=1
	global_store_b32 v[1:2], v6, off
                                        ; implicit-def: $vgpr1_vgpr2
.LBB0_13:                               ; %Flow
                                        ;   in Loop: Header=BB0_10 Depth=1
	s_and_not1_saveexec_b32 s0, s0
	s_cbranch_execz .LBB0_15
; %bb.14:                               ;   in Loop: Header=BB0_10 Depth=1
	global_store_b32 v[1:2], v4, off
.LBB0_15:                               ; %Flow134
                                        ;   in Loop: Header=BB0_10 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
                                        ; implicit-def: $vgpr1
.LBB0_16:                               ; %Flow135
                                        ;   in Loop: Header=BB0_10 Depth=1
	s_and_not1_saveexec_b32 s0, s12
	s_cbranch_execz .LBB0_18
; %bb.17:                               ;   in Loop: Header=BB0_10 Depth=1
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v1, vcc_lo, s6, v1
	v_add_co_ci_u32_e32 v2, vcc_lo, s7, v2, vcc_lo
	global_store_b32 v[1:2], v5, off
.LBB0_18:                               ;   in Loop: Header=BB0_10 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	v_add_nc_u32_e32 v0, s4, v0
	v_add_nc_u32_e32 v3, s9, v3
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_cmp_le_i32_e32 vcc_lo, s3, v0
	s_or_b32 s5, vcc_lo, s5
	s_and_not1_b32 exec_lo, exec_lo, s5
	s_cbranch_execnz .LBB0_10
.LBB0_19:                               ; %Flow137
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z4playPiS_i
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 13
		.amdhsa_next_free_sgpr 17
		.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	_Z4playPiS_i, .Lfunc_end0-_Z4playPiS_i
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 1020
; NumSgprs: 19
; NumVgprs: 13
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 19
; NumVGPRsForWavesPerEU: 13
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
      - .offset:         144
        .size:           4
        .value_kind:     hidden_dynamic_lds_size
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z4playPiS_i
    .private_segment_fixed_size: 0
    .sgpr_count:     19
    .sgpr_spill_count: 0
    .symbol:         _Z4playPiS_i.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     13
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
