#include <chrono>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>

static int SLEEP_TIME = 50000;
static int GENERATION_STEP = 1;

__global__ void singleBlockLifeKernel(uint32_t *cols, int numGenerations) {
  __shared__ uint8_t grid[1024]; // TODO Should this be uint32_t?

  int colIdx = threadIdx.x;

  // Copy data from global memory to shared memory
  uint32_t colData = cols[colIdx];

  // Split the data out into an easy to handle array
  for (int i = 0; i < 32; ++i) {
    grid[i * 32 + colIdx] = ((colData & 1 << i)) >> i;
  }

  // The bit mask is a quick and dirty way of computing the positive bounded %32
  uint8_t leftIdx = ((colIdx - 1) & 0x1f);
  uint8_t rightIdx = ((colIdx + 1) & 0x1f);

  for (int g = 0; g < numGenerations; ++g) {
    uint8_t lastSides = 0, lastMiddle = 0, thisSides = 0, thisMiddle = 0,
            nextSides = 0, nextMiddle = 0;

    // Get the nieghbors from the row below
    lastSides = grid[31 * 32 + leftIdx] & 1;
    lastSides += grid[31 * 32 + rightIdx] & 1;
    lastMiddle = grid[31 * 32 + colIdx];

    // Get the neighbors in this row and the cell itself
    thisSides = grid[leftIdx] & 1;
    thisSides += grid[rightIdx] & 1;
    thisMiddle = grid[colIdx];

    // Perform cellular automata
    for (int i = 0; i < 31; ++i) {

      // Get the neighbors in the next row
      nextSides = grid[(i + 1) * 32 + leftIdx] & 1;
      nextSides += grid[(i + 1) * 32 + rightIdx] & 1;
      nextMiddle = grid[(i + 1) * 32 + colIdx];

      // Calculate the numbers of neighbors still alive
      uint8_t neighbors =
          lastSides + lastMiddle + thisSides + nextSides + nextMiddle;

      // Write the next state directly to the memory location already allocated
      // for this square, just in a differnt bit
      // TODO Maybe just make this a macro?
      grid[i * 32 + colIdx] |=
          (~neighbors >> 1 & neighbors & (thisMiddle | neighbors) << 1) & 2;

      // The current row becomes the last row, mutatis mutandis for the next row
      lastSides = thisSides;
      lastMiddle = thisMiddle;
      thisSides = nextSides;
      thisMiddle = nextMiddle;
    }

    // The next row for the last row in the cell will be the dame as the first
    // row
    nextSides = grid[leftIdx] & 1;
    nextSides += grid[rightIdx] & 1;
    nextMiddle = grid[colIdx] & 1;

    // Compute the number of neighbors for this row
    uint8_t neighbors =
        lastSides + lastMiddle + thisSides + nextSides + nextMiddle;

    // Write the next state directly to the memory location already allocated
    // for this square, just in a differnt bit
    grid[31 * 32 + colIdx] |=
        (~neighbors >> 1 & neighbors & (thisMiddle | neighbors) << 1) & 2;

    // Make sure all threads have finished the current generation before starting the next generation
    __syncthreads();

    // Shift the next state of the cell into the current state of the cell
    for (int i = 0; i < 32; ++i) {
      grid[i * 32 + colIdx] >>= 1;
    }
  }

  // Clear the register to store compacted data
  colData = 0;

  // Cram the data back into a single value
  for (int i = 0; i < 32; ++i) {
    colData |= ((grid[i * 32 + colIdx]) & 1) << i;
  }

  // Copy the data back into global memory
  cols[colIdx] = colData;
}

void generateGrid(uint32_t *&cols) {

  uint32_t seed = std::chrono::duration_cast<std::chrono::milliseconds>(
                      std::chrono::system_clock::now().time_since_epoch())
                      .count();
  srand(seed);

  for (int i = 0; i < 32; ++i) {
    cols[i] = rand() & rand() & 0xFFFFFFFF;
  }
}

void drawGrid(uint32_t *col, int generation) {
  printf("\033[H");
  for (int y = 0; y < 32; ++y) {
    // printf("\n\033[1;%dH", y+1);
    for (int x = 0; x < 32; ++x)
      printf((col[x] & (1l << y)) ? "██" : "  ");
    printf("\n");
  }
  printf("%d    ", generation);
  usleep(SLEEP_TIME);
}

int main(int argc, char **argv) {

  if (argc > 1)
    GENERATION_STEP = std::stoi(argv[1]);

  if (argc > 2)
    SLEEP_TIME = std::stoi(argv[2]);

  uint32_t *cols;
  uint32_t generation = 0;

  cudaMallocManaged(&cols, sizeof(uint32_t) * 32);

  generateGrid(cols);
  drawGrid(cols, generation);

  while (true) {
    singleBlockLifeKernel<<<1, 32>>>(cols, GENERATION_STEP);
    generation += GENERATION_STEP;
    cudaDeviceSynchronize();
    drawGrid(cols, generation);
  }
  cudaFree(cols);
  return 0;
}
	.file	"tmpxft_0022f6c7_00000000-6_life32x32.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3752:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3752:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12generateGridRPj
	.type	_Z12generateGridRPj, @function
_Z12generateGridRPj:
.LFB3747:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	movq	%rdi, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	$1000000, %ecx
	cqto
	idivq	%rcx
	movl	%eax, %edi
	call	srand@PLT
.L3:
	call	rand@PLT
	movl	%eax, %ebx
	call	rand@PLT
	movq	(%r12), %rdx
	andl	%eax, %ebx
	movl	%ebx, (%rdx,%rbp)
	addq	$4, %rbp
	cmpq	$128, %rbp
	jne	.L3
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3747:
	.size	_Z12generateGridRPj, .-_Z12generateGridRPj
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"\342\226\210\342\226\210"
.LC1:
	.string	"  "
.LC2:
	.string	"\033[H"
.LC3:
	.string	"\n"
.LC4:
	.string	"%d    "
	.text
	.globl	_Z8drawGridPji
	.type	_Z8drawGridPji, @function
_Z8drawGridPji:
.LFB3748:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	xorl	%eax, %eax
	leaq	.LC1(%rip), %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rdi, %r14
	movl	$2, %edi
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movl	%esi, %r12d
	leaq	.LC2(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	xorl	%ebp, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	pushq	%rdx
	.cfi_def_cfa_offset 64
	call	__printf_chk@PLT
.L8:
	movl	$1, %r13d
	movl	%ebp, %ecx
	xorl	%ebx, %ebx
	salq	%cl, %r13
.L10:
	testl	%r13d, (%r14,%rbx,4)
	leaq	.LC0(%rip), %rsi
	movl	$2, %edi
	cmove	%r15, %rsi
	xorl	%eax, %eax
	incq	%rbx
	call	__printf_chk@PLT
	cmpq	$32, %rbx
	jne	.L10
	leaq	.LC3(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	incl	%ebp
	call	__printf_chk@PLT
	cmpl	$32, %ebp
	jne	.L8
	movl	%r12d, %edx
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	movl	_ZL10SLEEP_TIME(%rip), %edi
	popq	%rax
	.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
	jmp	usleep@PLT
	.cfi_endproc
.LFE3748:
	.size	_Z8drawGridPji, .-_Z8drawGridPji
	.globl	_Z42__device_stub__Z21singleBlockLifeKernelPjiPji
	.type	_Z42__device_stub__Z21singleBlockLifeKernelPjiPji, @function
_Z42__device_stub__Z21singleBlockLifeKernelPjiPji:
.LFB3774:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movl	%esi, 4(%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L15
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z21singleBlockLifeKernelPji(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L15:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L17
	call	__stack_chk_fail@PLT
.L17:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3774:
	.size	_Z42__device_stub__Z21singleBlockLifeKernelPjiPji, .-_Z42__device_stub__Z21singleBlockLifeKernelPjiPji
	.globl	_Z21singleBlockLifeKernelPji
	.type	_Z21singleBlockLifeKernelPji, @function
_Z21singleBlockLifeKernelPji:
.LFB3775:
	.cfi_startproc
	endbr64
	jmp	_Z42__device_stub__Z21singleBlockLifeKernelPjiPji
	.cfi_endproc
.LFE3775:
	.size	_Z21singleBlockLifeKernelPji, .-_Z21singleBlockLifeKernelPji
	.section	.rodata.str1.1
.LC5:
	.string	"_Z21singleBlockLifeKernelPji"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3777:
	.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	.LC5(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z21singleBlockLifeKernelPji(%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
.LFE3777:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev,"axG",@progbits,_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD5Ev,comdat
	.align 2
	.weak	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.type	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev, @function
_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev:
.LFB3884:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	__errno_location@PLT
	cmpl	$0, (%rax)
	jne	.L22
	movl	(%rbx), %edx
	movl	%edx, (%rax)
.L22:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3884:
	.size	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev, .-_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.weak	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	.set	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev,_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev
	.section	.text._ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_,"axG",@progbits,_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_,comdat
	.weak	_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_
	.type	_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_, @function
_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_:
.LFB3879:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3879
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movq	%rdi, %r15
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rcx, %r12
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rdx, %rbx
	subq	$56, %rsp
	.cfi_def_cfa_offset 112
	movl	%r8d, 12(%rsp)
	leaq	28(%rsp), %r13
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	__errno_location@PLT
	movl	12(%rsp), %edx
	leaq	32(%rsp), %rsi
	movq	%rbx, %rdi
	movq	%rax, %rbp
	movl	(%rax), %eax
	movl	%eax, 28(%rsp)
	xorl	%eax, %eax
	movl	%eax, 0(%rbp)
.LEHB0:
	call	*%r15
	movq	32(%rsp), %rdx
	cmpq	%rbx, %rdx
	jne	.L26
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L39
	movq	%r14, %rdi
	call	_ZSt24__throw_invalid_argumentPKc@PLT
.L26:
	cmpl	$34, 0(%rbp)
	je	.L28
	movl	$2147483648, %ecx
	movl	$4294967295, %esi
	addq	%rax, %rcx
	cmpq	%rcx, %rsi
	jnb	.L29
.L28:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L39
	movq	%r14, %rdi
	call	_ZSt20__throw_out_of_rangePKc@PLT
.LEHE0:
.L29:
	testq	%r12, %r12
	je	.L31
	subq	%rbx, %rdx
	movq	%rdx, (%r12)
.L31:
	movq	%r13, %rdi
	movl	%eax, 12(%rsp)
	call	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	movl	12(%rsp), %eax
	movq	40(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L34
	jmp	.L39
.L35:
	endbr64
	movq	%rax, %rbx
.L32:
	movq	%r13, %rdi
	call	_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD1Ev
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L39
	movq	%rbx, %rdi
.LEHB1:
	call	_Unwind_Resume@PLT
.LEHE1:
.L39:
	call	__stack_chk_fail@PLT
.L34:
	addq	$56, %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
.LFE3879:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table._ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_,"aG",@progbits,_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_,comdat
.LLSDA3879:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3879-.LLSDACSB3879
.LLSDACSB3879:
	.uleb128 .LEHB0-.LFB3879
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L35-.LFB3879
	.uleb128 0
	.uleb128 .LEHB1-.LFB3879
	.uleb128 .LEHE1-.LEHB1
	.uleb128 0
	.uleb128 0
.LLSDACSE3879:
	.section	.text._ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_,"axG",@progbits,_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_,comdat
	.size	_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_, .-_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_
	.section	.rodata._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_.str1.1,"aMS",@progbits,1
.LC6:
	.string	"basic_string: construction from null is not valid"
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC5IS3_EEPKcRKS3_,comdat
	.align 2
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, @function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_:
.LFB4109:
	.cfi_startproc
	endbr64
	pushq	%r12
	.cfi_def_cfa_offset 16
	.cfi_offset 12, -16
	pushq	%rbp
	.cfi_def_cfa_offset 24
	.cfi_offset 6, -24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset 3, -32
	subq	$16, %rsp
	.cfi_def_cfa_offset 48
	movq	%fs:40, %rax
	movq	%rax, 8(%rsp)
	xorl	%eax, %eax
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	jne	.L43
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L48
	leaq	.LC6(%rip), %rdi
	call	_ZSt19__throw_logic_errorPKc@PLT
.L43:
	movq	%rdi, %rbx
	movq	%rsi, %rdi
	movq	%rsi, %rbp
	call	strlen@PLT
	movq	%rax, (%rsp)
	leaq	0(%rbp,%rax), %r12
	cmpq	$15, %rax
	jbe	.L45
	movq	%rsp, %rsi
	xorl	%edx, %edx
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm@PLT
	movq	%rax, (%rbx)
	movq	(%rsp), %rax
	movq	%rax, 16(%rbx)
.L45:
	movq	(%rbx), %rdi
	movq	%r12, %rdx
	movq	%rbp, %rsi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE13_S_copy_charsEPcPKcS7_@PLT
	movq	(%rsp), %rax
	movq	(%rbx), %rdx
	movq	%rax, 8(%rbx)
	movb	$0, (%rdx,%rax)
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	je	.L46
.L48:
	call	__stack_chk_fail@PLT
.L46:
	addq	$16, %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
.LFE4109:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
	.set	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.section	.rodata.str1.1
.LC7:
	.string	"stoi"
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB3749:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA3749
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	movq	%fs:40, %rax
	movq	%rax, 72(%rsp)
	xorl	%eax, %eax
	cmpl	$1, %edi
	jle	.L51
	movq	%rsi, %rbp
	leaq	28(%rsp), %r14
	movq	8(%rsi), %rsi
	movl	%edi, %r12d
	leaq	40(%rsp), %rbx
	movq	%r14, %rdx
	leaq	.LC7(%rip), %r13
	movq	%rbx, %rdi
.LEHB2:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE2:
	movq	40(%rsp), %rdx
	xorl	%ecx, %ecx
	movq	%r13, %rsi
	movq	__isoc23_strtol@GOTPCREL(%rip), %rdi
	movl	$10, %r8d
.LEHB3:
	call	_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_
.LEHE3:
	movq	%rbx, %rdi
	movl	%eax, _ZL15GENERATION_STEP(%rip)
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	cmpl	$2, %r12d
	je	.L51
	movq	16(%rbp), %rsi
	movq	%r14, %rdx
	movq	%rbx, %rdi
.LEHB4:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE4:
	movq	40(%rsp), %rdx
	xorl	%ecx, %ecx
	movq	%r13, %rsi
	movq	__isoc23_strtol@GOTPCREL(%rip), %rdi
	movl	$10, %r8d
.LEHB5:
	call	_ZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_
.LEHE5:
	movq	%rbx, %rdi
	movl	%eax, _ZL10SLEEP_TIME(%rip)
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
.L51:
	leaq	8(%rsp), %rbx
	movl	$1, %edx
	movl	$128, %esi
	movl	$134217729, %ebp
	movq	%rbx, %rdi
	salq	$5, %rbp
.LEHB6:
	call	cudaMallocManaged@PLT
	movq	%rbx, %rdi
	xorl	%ebx, %ebx
	call	_Z12generateGridRPj
	movq	8(%rsp), %rdi
	xorl	%esi, %esi
	call	_Z8drawGridPji
.L54:
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%rbp, %rdx
	movl	$1, %ecx
	movabsq	$4294967297, %rdi
	movl	$1, %esi
	movq	%rbp, 28(%rsp)
	movl	$1, 36(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L53
	movl	_ZL15GENERATION_STEP(%rip), %esi
	movq	8(%rsp), %rdi
	call	_Z42__device_stub__Z21singleBlockLifeKernelPjiPji
.L53:
	addl	_ZL15GENERATION_STEP(%rip), %ebx
	call	cudaDeviceSynchronize@PLT
	movq	8(%rsp), %rdi
	movl	%ebx, %esi
	call	_Z8drawGridPji
	jmp	.L54
.L60:
	endbr64
	jmp	.L68
.L61:
	endbr64
.L68:
	movq	%rax, %rbp
.L57:
	movq	%rbx, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	72(%rsp), %rax
	subq	%fs:40, %rax
	je	.L58
	call	__stack_chk_fail@PLT
.L58:
	movq	%rbp, %rdi
	call	_Unwind_Resume@PLT
.LEHE6:
	.cfi_endproc
.LFE3749:
	.section	.gcc_except_table,"a",@progbits
.LLSDA3749:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE3749-.LLSDACSB3749
.LLSDACSB3749:
	.uleb128 .LEHB2-.LFB3749
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB3-.LFB3749
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L60-.LFB3749
	.uleb128 0
	.uleb128 .LEHB4-.LFB3749
	.uleb128 .LEHE4-.LEHB4
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB5-.LFB3749
	.uleb128 .LEHE5-.LEHB5
	.uleb128 .L61-.LFB3749
	.uleb128 0
	.uleb128 .LEHB6-.LFB3749
	.uleb128 .LEHE6-.LEHB6
	.uleb128 0
	.uleb128 0
.LLSDACSE3749:
	.section	.text.startup
	.size	main, .-main
	.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
	.data
	.align 4
	.type	_ZL15GENERATION_STEP, @object
	.size	_ZL15GENERATION_STEP, 4
_ZL15GENERATION_STEP:
	.long	1
	.align 4
	.type	_ZL10SLEEP_TIME, @object
	.size	_ZL10SLEEP_TIME, 4
_ZL10SLEEP_TIME:
	.long	50000
	.hidden	DW.ref.__gxx_personality_v0
	.weak	DW.ref.__gxx_personality_v0
	.section	.data.rel.local.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat
	.align 8
	.type	DW.ref.__gxx_personality_v0, @object
	.size	DW.ref.__gxx_personality_v0, 8
DW.ref.__gxx_personality_v0:
	.quad	__gxx_personality_v0
	.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 <chrono>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>

static int SLEEP_TIME = 50000;
static int GENERATION_STEP = 1;

__global__ void singleBlockLifeKernel(uint32_t *cols, int numGenerations) {
  __shared__ uint8_t grid[1024]; // TODO Should this be uint32_t?

  int colIdx = threadIdx.x;

  // Copy data from global memory to shared memory
  uint32_t colData = cols[colIdx];

  // Split the data out into an easy to handle array
  for (int i = 0; i < 32; ++i) {
    grid[i * 32 + colIdx] = ((colData & 1 << i)) >> i;
  }

  // The bit mask is a quick and dirty way of computing the positive bounded %32
  uint8_t leftIdx = ((colIdx - 1) & 0x1f);
  uint8_t rightIdx = ((colIdx + 1) & 0x1f);

  for (int g = 0; g < numGenerations; ++g) {
    uint8_t lastSides = 0, lastMiddle = 0, thisSides = 0, thisMiddle = 0,
            nextSides = 0, nextMiddle = 0;

    // Get the nieghbors from the row below
    lastSides = grid[31 * 32 + leftIdx] & 1;
    lastSides += grid[31 * 32 + rightIdx] & 1;
    lastMiddle = grid[31 * 32 + colIdx];

    // Get the neighbors in this row and the cell itself
    thisSides = grid[leftIdx] & 1;
    thisSides += grid[rightIdx] & 1;
    thisMiddle = grid[colIdx];

    // Perform cellular automata
    for (int i = 0; i < 31; ++i) {

      // Get the neighbors in the next row
      nextSides = grid[(i + 1) * 32 + leftIdx] & 1;
      nextSides += grid[(i + 1) * 32 + rightIdx] & 1;
      nextMiddle = grid[(i + 1) * 32 + colIdx];

      // Calculate the numbers of neighbors still alive
      uint8_t neighbors =
          lastSides + lastMiddle + thisSides + nextSides + nextMiddle;

      // Write the next state directly to the memory location already allocated
      // for this square, just in a differnt bit
      // TODO Maybe just make this a macro?
      grid[i * 32 + colIdx] |=
          (~neighbors >> 1 & neighbors & (thisMiddle | neighbors) << 1) & 2;

      // The current row becomes the last row, mutatis mutandis for the next row
      lastSides = thisSides;
      lastMiddle = thisMiddle;
      thisSides = nextSides;
      thisMiddle = nextMiddle;
    }

    // The next row for the last row in the cell will be the dame as the first
    // row
    nextSides = grid[leftIdx] & 1;
    nextSides += grid[rightIdx] & 1;
    nextMiddle = grid[colIdx] & 1;

    // Compute the number of neighbors for this row
    uint8_t neighbors =
        lastSides + lastMiddle + thisSides + nextSides + nextMiddle;

    // Write the next state directly to the memory location already allocated
    // for this square, just in a differnt bit
    grid[31 * 32 + colIdx] |=
        (~neighbors >> 1 & neighbors & (thisMiddle | neighbors) << 1) & 2;

    // Make sure all threads have finished the current generation before starting the next generation
    __syncthreads();

    // Shift the next state of the cell into the current state of the cell
    for (int i = 0; i < 32; ++i) {
      grid[i * 32 + colIdx] >>= 1;
    }
  }

  // Clear the register to store compacted data
  colData = 0;

  // Cram the data back into a single value
  for (int i = 0; i < 32; ++i) {
    colData |= ((grid[i * 32 + colIdx]) & 1) << i;
  }

  // Copy the data back into global memory
  cols[colIdx] = colData;
}

void generateGrid(uint32_t *&cols) {

  uint32_t seed = std::chrono::duration_cast<std::chrono::milliseconds>(
                      std::chrono::system_clock::now().time_since_epoch())
                      .count();
  srand(seed);

  for (int i = 0; i < 32; ++i) {
    cols[i] = rand() & rand() & 0xFFFFFFFF;
  }
}

void drawGrid(uint32_t *col, int generation) {
  printf("\033[H");
  for (int y = 0; y < 32; ++y) {
    // printf("\n\033[1;%dH", y+1);
    for (int x = 0; x < 32; ++x)
      printf((col[x] & (1l << y)) ? "██" : "  ");
    printf("\n");
  }
  printf("%d    ", generation);
  usleep(SLEEP_TIME);
}

int main(int argc, char **argv) {

  if (argc > 1)
    GENERATION_STEP = std::stoi(argv[1]);

  if (argc > 2)
    SLEEP_TIME = std::stoi(argv[2]);

  uint32_t *cols;
  uint32_t generation = 0;

  hipMallocManaged(&cols, sizeof(uint32_t) * 32);

  generateGrid(cols);
  drawGrid(cols, generation);

  while (true) {
    singleBlockLifeKernel<<<1, 32>>>(cols, GENERATION_STEP);
    generation += GENERATION_STEP;
    hipDeviceSynchronize();
    drawGrid(cols, generation);
  }
  hipFree(cols);
  return 0;
}
	.text
	.file	"life32x32.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.globl	_Z36__device_stub__singleBlockLifeKernelPji # -- Begin function _Z36__device_stub__singleBlockLifeKernelPji
	.type	_Z36__device_stub__singleBlockLifeKernelPji,@function
_Z36__device_stub__singleBlockLifeKernelPji: # @_Z36__device_stub__singleBlockLifeKernelPji
	.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	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	4(%rsp), %rcx
	movl	%esi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%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	$_Z21singleBlockLifeKernelPji, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	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	_Z36__device_stub__singleBlockLifeKernelPji, .Lfunc_end0-_Z36__device_stub__singleBlockLifeKernelPji
	.cfi_endproc
                                        # -- End function
	.globl	_Z12generateGridRPj             # -- Begin function _Z12generateGridRPj
	.type	_Z12generateGridRPj,@function
_Z12generateGridRPj:                    # @_Z12generateGridRPj
	.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	%rdi, %rbx
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movabsq	$4835703278458516699, %rcx      # imm = 0x431BDE82D7B634DB
	imulq	%rcx
	movq	%rdx, %rdi
	shrq	$63, %rdi
	shrq	$18, %rdx
	addl	%edx, %edi
                                        # kill: def $edi killed $edi killed $rdi
	callq	srand
	xorl	%r14d, %r14d
.LBB1_1:                                # =>This Inner Loop Header: Depth=1
	callq	rand
	movl	%eax, %ebp
	callq	rand
	andl	%ebp, %eax
	movq	(%rbx), %rcx
	movl	%eax, (%rcx,%r14,4)
	incq	%r14
	cmpq	$32, %r14
	jne	.LBB1_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_end1:
	.size	_Z12generateGridRPj, .Lfunc_end1-_Z12generateGridRPj
	.cfi_endproc
                                        # -- End function
	.globl	_Z8drawGridPji                  # -- Begin function _Z8drawGridPji
	.type	_Z8drawGridPji,@function
_Z8drawGridPji:                         # @_Z8drawGridPji
	.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	$.L.str, %edi
	xorl	%eax, %eax
	callq	printf
	xorl	%r15d, %r15d
.LBB2_1:                                # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_2 Depth 2
	movl	$1, %r12d
	movl	%r15d, %ecx
	shlq	%cl, %r12
	xorl	%r13d, %r13d
.LBB2_2:                                #   Parent Loop BB2_1 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	$.L.str.2, %edi
	testl	%r12d, (%r14,%r13,4)
	je	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_2 Depth=2
	movl	$.L.str.1, %edi
.LBB2_4:                                #   in Loop: Header=BB2_2 Depth=2
	xorl	%eax, %eax
	callq	printf
	incq	%r13
	cmpq	$32, %r13
	jne	.LBB2_2
# %bb.5:                                #   in Loop: Header=BB2_1 Depth=1
	movl	$10, %edi
	callq	putchar@PLT
	incq	%r15
	cmpq	$32, %r15
	jne	.LBB2_1
# %bb.6:
	movl	$.L.str.4, %edi
	movl	%ebx, %esi
	xorl	%eax, %eax
	callq	printf
	movl	_ZL10SLEEP_TIME(%rip), %edi
	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
	jmp	usleep                          # TAILCALL
.Lfunc_end2:
	.size	_Z8drawGridPji, .Lfunc_end2-_Z8drawGridPji
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %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
	cmpl	$2, %edi
	jl	.LBB3_33
# %bb.1:
	movq	%rsi, %r14
	movl	%edi, %ebp
	movq	8(%rsi), %rsi
.Ltmp0:
	leaq	16(%rsp), %rdi
	leaq	15(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp1:
# %bb.2:
	movq	16(%rsp), %r15
	callq	__errno_location
	movq	%rax, %rbx
	movl	(%rax), %r13d
	movl	$0, (%rax)
	leaq	48(%rsp), %r12
	movq	%r15, %rdi
	movq	%r12, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	%r15, (%r12)
	je	.LBB3_3
# %bb.9:
	movslq	%eax, %rcx
	cmpq	%rax, %rcx
	jne	.LBB3_11
# %bb.10:
	movl	(%rbx), %ecx
	cmpl	$34, %ecx
	je	.LBB3_11
# %bb.13:
	testl	%ecx, %ecx
	jne	.LBB3_15
# %bb.14:
	movl	%r13d, (%rbx)
.LBB3_15:
	movl	%eax, _ZL15GENERATION_STEP(%rip)
	leaq	32(%rsp), %r12
	movq	-16(%r12), %rdi
	cmpq	%r12, %rdi
	je	.LBB3_17
# %bb.16:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB3_17:
	cmpl	$2, %ebp
	je	.LBB3_33
# %bb.18:
	movq	16(%r14), %rsi
.Ltmp3:
	leaq	16(%rsp), %rdi
	leaq	15(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp4:
# %bb.19:
	movq	16(%rsp), %r14
	movl	(%rbx), %ebp
	movl	$0, (%rbx)
	leaq	48(%rsp), %r15
	movq	%r14, %rdi
	movq	%r15, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	%r14, (%r15)
	je	.LBB3_20
# %bb.25:
	movabsq	$-4294967296, %rcx              # imm = 0xFFFFFFFF00000000
	leaq	-2147483648(%rax), %rdx
	cmpq	%rcx, %rdx
	jb	.LBB3_27
# %bb.26:
	movl	(%rbx), %ecx
	cmpl	$34, %ecx
	je	.LBB3_27
# %bb.29:
	testl	%ecx, %ecx
	jne	.LBB3_31
# %bb.30:
	movl	%ebp, (%rbx)
.LBB3_31:
	movl	%eax, _ZL10SLEEP_TIME(%rip)
	movq	16(%rsp), %rdi
	cmpq	%r12, %rdi
	je	.LBB3_33
# %bb.32:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i27
	callq	_ZdlPv
.LBB3_33:                               # %.thread
	movabsq	$4294967297, %rbx               # imm = 0x100000001
	leaq	16(%rsp), %r14
	movl	$128, %esi
	movq	%r14, %rdi
	movl	$1, %edx
	callq	hipMallocManaged
	movq	%r14, %rdi
	callq	_Z12generateGridRPj
	movq	(%r14), %rdi
	xorl	%r14d, %r14d
	xorl	%esi, %esi
	callq	_Z8drawGridPji
	leaq	31(%rbx), %r15
.LBB3_34:                               # =>This Inner Loop Header: Depth=1
	movq	%rbx, %rdi
	movl	$1, %esi
	movq	%r15, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_36
# %bb.35:                               #   in Loop: Header=BB3_34 Depth=1
	movq	16(%rsp), %rdi
	movl	_ZL15GENERATION_STEP(%rip), %esi
	callq	_Z36__device_stub__singleBlockLifeKernelPji
.LBB3_36:                               #   in Loop: Header=BB3_34 Depth=1
	addl	_ZL15GENERATION_STEP(%rip), %r14d
	callq	hipDeviceSynchronize
	movq	16(%rsp), %rdi
	movl	%r14d, %esi
	callq	_Z8drawGridPji
	jmp	.LBB3_34
.LBB3_3:
.Ltmp13:
	movl	$.L.str.5, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp14:
# %bb.4:
.LBB3_11:                               # %.critedge.i.i
.Ltmp11:
	movl	$.L.str.5, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp12:
# %bb.12:
.LBB3_20:
.Ltmp8:
	movl	$.L.str.5, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp9:
# %bb.21:
.LBB3_27:                               # %.critedge.i.i22
.Ltmp6:
	movl	$.L.str.5, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp7:
# %bb.28:
.LBB3_37:
.Ltmp5:
	jmp	.LBB3_38
.LBB3_22:
.Ltmp10:
	movq	%rax, %r14
	cmpl	$0, (%rbx)
	jne	.LBB3_24
# %bb.23:
	movl	%ebp, (%rbx)
.LBB3_24:                               # %_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i23
	movq	16(%rsp), %rdi
	cmpq	%r12, %rdi
	jne	.LBB3_8
	jmp	.LBB3_39
.LBB3_40:
.Ltmp2:
.LBB3_38:
	movq	%rax, %r14
	jmp	.LBB3_39
.LBB3_5:
.Ltmp15:
	movq	%rax, %r14
	cmpl	$0, (%rbx)
	jne	.LBB3_7
# %bb.6:
	movl	%r13d, (%rbx)
.LBB3_7:                                # %_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i
	leaq	32(%rsp), %rax
	movq	-16(%rax), %rdi
	cmpq	%rax, %rdi
	je	.LBB3_39
.LBB3_8:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i18
	callq	_ZdlPv
.LBB3_39:
	movq	%r14, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table3:
.Lexception0:
	.byte	255                             # @LPStart Encoding = omit
	.byte	255                             # @TType Encoding = omit
	.byte	1                               # Call site Encoding = uleb128
	.uleb128 .Lcst_end0-.Lcst_begin0
.Lcst_begin0:
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 1 <<
	.uleb128 .Ltmp1-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp1
	.uleb128 .Ltmp2-.Lfunc_begin0           #     jumps to .Ltmp2
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp3-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp4-.Ltmp3                  #   Call between .Ltmp3 and .Ltmp4
	.uleb128 .Ltmp5-.Lfunc_begin0           #     jumps to .Ltmp5
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp4-.Lfunc_begin0           # >> Call Site 3 <<
	.uleb128 .Ltmp13-.Ltmp4                 #   Call between .Ltmp4 and .Ltmp13
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp13-.Lfunc_begin0          # >> Call Site 4 <<
	.uleb128 .Ltmp12-.Ltmp13                #   Call between .Ltmp13 and .Ltmp12
	.uleb128 .Ltmp15-.Lfunc_begin0          #     jumps to .Ltmp15
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp8-.Lfunc_begin0           # >> Call Site 5 <<
	.uleb128 .Ltmp7-.Ltmp8                  #   Call between .Ltmp8 and .Ltmp7
	.uleb128 .Ltmp10-.Lfunc_begin0          #     jumps to .Ltmp10
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp7-.Lfunc_begin0           # >> Call Site 6 <<
	.uleb128 .Lfunc_end3-.Ltmp7             #   Call between .Ltmp7 and .Lfunc_end3
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
.Lcst_end0:
	.p2align	2, 0x0
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_ # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_startproc
# %bb.0:
	pushq	%r14
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	pushq	%rax
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -24
	.cfi_offset %r14, -16
	leaq	16(%rdi), %rax
	movq	%rax, (%rdi)
	testq	%rsi, %rsi
	je	.LBB4_1
# %bb.2:
	movq	%rsi, %rbx
	movq	%rdi, %r14
	movq	%rsi, %rdi
	callq	strlen
	leaq	(%rax,%rbx), %rdx
	movq	%r14, %rdi
	movq	%rbx, %rsi
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	jmp	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # TAILCALL
.LBB4_1:
	.cfi_def_cfa_offset 32
	movl	$.L.str.6, %edi
	callq	_ZSt19__throw_logic_errorPKc
.Lfunc_end4:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .Lfunc_end4-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_endproc
                                        # -- End function
	.section	.text._ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,"axG",@progbits,_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,comdat
	.weak	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag # -- Begin function _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.p2align	1, 0x90
	.type	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag,@function
_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag: # @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.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	%rdx, %r14
	movq	%rsi, %r15
	movq	%rdi, %rbx
	subq	%rsi, %r14
	movq	%r14, (%rsp)
	cmpq	$15, %r14
	jbe	.LBB5_1
# %bb.2:
	movq	%rsp, %r12
	movq	%rbx, %rdi
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_createERmm
	movq	%rax, (%rbx)
	movq	(%r12), %rcx
	movq	%rcx, 16(%rbx)
	jmp	.LBB5_3
.LBB5_1:                                # %._crit_edge
	movq	(%rbx), %rax
.LBB5_3:
	testq	%r14, %r14
	je	.LBB5_7
# %bb.4:
	cmpq	$1, %r14
	jne	.LBB5_6
# %bb.5:
	movb	(%r15), %cl
	movb	%cl, (%rax)
	jmp	.LBB5_7
.LBB5_6:
	movq	%rax, %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
.LBB5_7:                                # %_ZZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tagEN6_GuardD2Ev.exit
	movq	(%rsp), %rax
	movq	%rax, 8(%rbx)
	movq	(%rbx), %rcx
	movb	$0, (%rcx,%rax)
	addq	$8, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag, .Lfunc_end5-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_endproc
                                        # -- End function
	.text
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB6_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB6_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z21singleBlockLifeKernelPji, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$40, %rsp
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end6:
	.size	__hip_module_ctor, .Lfunc_end6-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB7_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB7_2:
	retq
.Lfunc_end7:
	.size	__hip_module_dtor, .Lfunc_end7-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z21singleBlockLifeKernelPji,@object # @_Z21singleBlockLifeKernelPji
	.section	.rodata,"a",@progbits
	.globl	_Z21singleBlockLifeKernelPji
	.p2align	3, 0x0
_Z21singleBlockLifeKernelPji:
	.quad	_Z36__device_stub__singleBlockLifeKernelPji
	.size	_Z21singleBlockLifeKernelPji, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"\033[H"
	.size	.L.str, 4

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"\342\226\210\342\226\210"
	.size	.L.str.1, 7

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"%d    "
	.size	.L.str.4, 7

	.type	_ZL10SLEEP_TIME,@object         # @_ZL10SLEEP_TIME
	.data
	.p2align	2, 0x0
_ZL10SLEEP_TIME:
	.long	50000                           # 0xc350
	.size	_ZL10SLEEP_TIME, 4

	.type	_ZL15GENERATION_STEP,@object    # @_ZL15GENERATION_STEP
	.p2align	2, 0x0
_ZL15GENERATION_STEP:
	.long	1                               # 0x1
	.size	_ZL15GENERATION_STEP, 4

	.type	.L.str.5,@object                # @.str.5
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.5:
	.asciz	"stoi"
	.size	.L.str.5, 5

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"basic_string: construction from null is not valid"
	.size	.L.str.6, 50

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z21singleBlockLifeKernelPji"
	.size	.L__unnamed_1, 29

	.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 _Z36__device_stub__singleBlockLifeKernelPji
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _Z21singleBlockLifeKernelPji
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z21singleBlockLifeKernelPji ; -- Begin function _Z21singleBlockLifeKernelPji
	.globl	_Z21singleBlockLifeKernelPji
	.p2align	8
	.type	_Z21singleBlockLifeKernelPji,@function
_Z21singleBlockLifeKernelPji:           ; @_Z21singleBlockLifeKernelPji
; %bb.0:
	s_load_b64 s[2:3], s[0:1], 0x0
	v_dual_mov_b32 v4, v0 :: v_dual_lshlrev_b32 v1, 2, v0
	s_waitcnt lgkmcnt(0)
	global_load_b32 v3, v1, s[2:3]
	v_add_co_u32 v1, s2, s2, v1
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v2, null, s3, 0, s2
	s_mov_b32 s2, 0
.LBB0_1:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_2) | instid1(VALU_DEP_1)
	s_lshl_b32 s3, 1, s2
	s_waitcnt vmcnt(0)
	v_and_b32_e32 v5, s3, v3
	v_lshrrev_b32_e32 v5, s2, v5
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s2, 32
	ds_store_b8 v4, v5
	v_add_nc_u32_e32 v4, 32, v4
	s_cbranch_scc0 .LBB0_1
; %bb.2:
	s_load_b32 s1, s[0:1], 0x8
	s_mov_b32 s0, 0
	s_waitcnt lgkmcnt(0)
	s_cmp_gt_i32 s1, 0
	s_cbranch_scc0 .LBB0_9
; %bb.3:                                ; %.lr.ph
	v_add_nc_u32_e32 v3, 1, v0
	v_add_nc_u32_e32 v4, -1, v0
	s_mov_b32 s2, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_and_b32_e32 v3, 31, v3
	v_and_b32_e32 v4, 31, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_or_b32_e32 v5, 32, v3
	v_or_b32_e32 v6, 32, v4
.LBB0_4:                                ; =>This Loop Header: Depth=1
                                        ;     Child Loop BB0_5 Depth 2
                                        ;     Child Loop BB0_7 Depth 2
	ds_load_u8 v9, v4 offset:992
	ds_load_u8 v10, v3 offset:992
	ds_load_u8 v7, v0
	ds_load_u8 v11, v4
	ds_load_u8 v12, v3
	ds_load_u8 v8, v0 offset:992
	s_mov_b32 s3, 0
	s_waitcnt lgkmcnt(5)
	v_and_b32_e32 v9, 1, v9
	s_waitcnt lgkmcnt(4)
	v_and_b32_e32 v10, 1, v10
	s_waitcnt lgkmcnt(2)
	v_and_b32_e32 v13, 1, v11
	s_waitcnt lgkmcnt(1)
	v_and_b32_e32 v12, 1, v12
	v_add_nc_u16 v11, v10, v9
	s_delay_alu instid0(VALU_DEP_2)
	v_add_nc_u16 v9, v12, v13
.LBB0_5:                                ;   Parent Loop BB0_4 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	s_waitcnt lgkmcnt(0)
	v_dual_mov_b32 v15, v8 :: v_dual_add_nc_u32 v10, s3, v6
	v_add_nc_u32_e32 v12, s3, v5
	v_dual_mov_b32 v8, v7 :: v_dual_add_nc_u32 v13, s3, v0
	ds_load_u8 v14, v10
	ds_load_u8 v12, v12
	ds_load_u8 v7, v13 offset:32
	ds_load_u8 v16, v13
	v_mov_b32_e32 v10, v9
	v_add_nc_u16 v9, v15, v11
	s_add_i32 s3, s3, 32
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_eq_i32 s3, 0x3e0
	s_waitcnt lgkmcnt(3)
	v_and_b32_e32 v11, 1, v14
	v_add_nc_u16 v9, v9, v10
	s_waitcnt lgkmcnt(2)
	v_and_b32_e32 v12, 1, v12
	s_waitcnt lgkmcnt(1)
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_nc_u16 v14, v9, v7
	v_add_nc_u16 v9, v12, v11
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u16 v11, v14, v9
	v_xor_b32_e32 v12, -1, v11
	v_or_b32_e32 v14, v11, v8
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshrrev_b16 v12, 1, v12
	v_lshlrev_b16 v14, 1, v14
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v11, v11, v12
	v_and_b32_e32 v11, v11, v14
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_and_b32_e32 v11, 2, v11
	s_waitcnt lgkmcnt(0)
	v_or_b32_e32 v12, v11, v16
	v_mov_b32_e32 v11, v10
	ds_store_b8 v13, v12
	s_cbranch_scc0 .LBB0_5
; %bb.6:                                ;   in Loop: Header=BB0_4 Depth=1
	ds_load_u8 v11, v4
	ds_load_u8 v12, v0
	ds_load_u8 v13, v0 offset:992
	ds_load_u8 v14, v3
	v_add_nc_u16 v8, v8, v10
	s_mov_b32 s3, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_2)
	v_add_nc_u16 v8, v8, v9
	s_waitcnt lgkmcnt(3)
	v_and_b32_e32 v9, 1, v11
	s_waitcnt lgkmcnt(0)
	v_and_b32_e32 v10, 1, v14
	v_add_nc_u16 v8, v8, v9
	v_and_b32_e32 v9, 1, v12
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u16 v8, v8, v10
	v_add_nc_u16 v8, v8, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_xor_b32_e32 v9, -1, v8
	v_or_b32_e32 v7, v8, v7
	v_lshrrev_b16 v9, 1, v9
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b16 v7, 1, v7
	v_and_b32_e32 v8, v8, v9
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_and_b32_e32 v7, v8, v7
	v_and_b32_e32 v7, 2, v7
	s_delay_alu instid0(VALU_DEP_1)
	v_or_b32_e32 v7, v7, v13
	ds_store_b8 v0, v7 offset:992
	s_waitcnt lgkmcnt(0)
	s_barrier
	buffer_gl0_inv
.LBB0_7:                                ;   Parent Loop BB0_4 Depth=1
                                        ; =>  This Inner Loop Header: Depth=2
	v_add_nc_u32_e32 v7, s3, v0
	s_add_i32 s3, s3, 32
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmpk_eq_i32 s3, 0x400
	ds_load_u8 v8, v7
	s_waitcnt lgkmcnt(0)
	v_lshrrev_b16 v8, 1, v8
	ds_store_b8 v7, v8
	s_cbranch_scc0 .LBB0_7
; %bb.8:                                ;   in Loop: Header=BB0_4 Depth=1
	s_add_i32 s2, s2, 1
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_eq_u32 s2, s1
	s_cbranch_scc0 .LBB0_4
.LBB0_9:                                ; %.preheader.preheader
	v_mov_b32_e32 v3, 0
.LBB0_10:                               ; %.preheader
                                        ; =>This Inner Loop Header: Depth=1
	ds_load_u8 v4, v0
	v_add_nc_u32_e32 v0, 32, v0
	s_waitcnt lgkmcnt(0)
	v_and_b32_e32 v4, 1, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(SALU_CYCLE_1)
	v_lshl_or_b32 v3, v4, s0, v3
	s_add_i32 s0, s0, 1
	s_cmp_eq_u32 s0, 32
	s_cbranch_scc0 .LBB0_10
; %bb.11:
	global_store_b32 v[1:2], v3, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z21singleBlockLifeKernelPji
		.amdhsa_group_segment_fixed_size 1024
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 12
		.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 17
		.amdhsa_next_free_sgpr 4
		.amdhsa_reserve_vcc 0
		.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	_Z21singleBlockLifeKernelPji, .Lfunc_end0-_Z21singleBlockLifeKernelPji
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 792
; NumSgprs: 4
; NumVgprs: 17
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 1024 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 4
; NumVGPRsForWavesPerEU: 17
; 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
      - .offset:         8
        .size:           4
        .value_kind:     by_value
    .group_segment_fixed_size: 1024
    .kernarg_segment_align: 8
    .kernarg_segment_size: 12
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z21singleBlockLifeKernelPji
    .private_segment_fixed_size: 0
    .sgpr_count:     4
    .sgpr_spill_count: 0
    .symbol:         _Z21singleBlockLifeKernelPji.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     17
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
