#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cuda_runtime.h>
#include <iomanip>
#include <iostream>

// helper for time measurement
typedef std::chrono::duration<double, std::milli> d_ms;
const auto &now = std::chrono::high_resolution_clock::now;

// Define Error Checking Macro
#define CU_CHK(ERRORCODE)                                                      \
  {                                                                            \
    cudaError_t error = ERRORCODE;                                             \
    if (error != 0) {                                                          \
      std::cerr << cudaGetErrorName(error) << ": "                             \
                << cudaGetErrorString(error) << " at " << __FILE__ << ":"      \
                << __LINE__ << "\n";                                           \
    }                                                                          \
  }

// Constants
const static int DEFAULT_NUM_ELEMENTS = 1024;
const static int DEFAULT_NUM_ITERATIONS = 5;
const static int DEFAULT_BLOCK_DIM = 128;

// Structures
struct StencilArray_t {
  float *array;
  float *tmp_array;
  int size; // size == width == height
};

// Function Prototypes
void writeToFile(float *matrix, const char *name, int size);

// Stencil Code Kernel for the speed calculation
extern void simpleStencil_Kernel_Wrapper(int gridSize, int blockSize, int size,
                                         float *grid_old, float *grid_new);
extern void optStencil_Kernel_Wrapper(int gridSize, int blockSize, int shm_size,
                                      int size, float *grid_old,
                                      float *grid_new);
// Main
int main(int argc, char *argv[]) {
  // Process Arguments
  if (argc < 2 or std::string(argv[1]) == "-h") {
    std::cout << "Usage:\n\t" << argv[0] << " <problemsize> [iterations] [result.pgm]\n";
    return 1;
  }

  int numElements = 0;
  numElements = std::stoi(argv[1]);
  numElements = numElements > 0 ? numElements : DEFAULT_NUM_ELEMENTS;

  int numIterations = 0;
  if (argc > 2)
    numIterations = std::stoi(argv[2]);
  numIterations = numIterations != 0 ? numIterations : DEFAULT_NUM_ITERATIONS;

  // Allocate Memory

  // Host Memory
  StencilArray_t h_array;
  h_array.size = numElements;
  // Pinned Memory
  CU_CHK(cudaMallocHost(
      &(h_array.array),
      static_cast<size_t>(h_array.size * h_array.size * sizeof(float))));
  CU_CHK(cudaMallocHost(
      &(h_array.tmp_array),
      static_cast<size_t>(h_array.size * h_array.size * sizeof(float))));

  // Init Particles
  //  srand(static_cast<unsigned>(time(0)));
  srand(0); // Always the same random numbers
  for (int i = 0; i < h_array.size; i++) {
    for (int j = 0; j < h_array.size; j++) {
      if (i == 0)
        h_array.array[i + h_array.size * j] = 127;
      else if (i > h_array.size / 4 && i < h_array.size * 3 / 4 &&
               j > h_array.size / 4 && j < h_array.size * 3 / 4)
        h_array.array[i + h_array.size * j] = 100;
      else
        h_array.array[i + h_array.size * j] = 0;
    }
  }

  // Device Memory
  StencilArray_t d_array;
  d_array.size = h_array.size;
  CU_CHK(cudaMalloc(
      &(d_array.array),
      static_cast<size_t>(d_array.size * d_array.size * sizeof(float))));
  CU_CHK(cudaMalloc(
      &(d_array.tmp_array),
      static_cast<size_t>(d_array.size * d_array.size * sizeof(float))));

  // Copy Data to the Device
  auto t1 = now();
  CU_CHK(cudaMemcpy(
      d_array.array, h_array.array,
      static_cast<size_t>(d_array.size * d_array.size * sizeof(float)),
      cudaMemcpyHostToDevice));
  CU_CHK(cudaMemcpy(
      d_array.tmp_array, h_array.array,
      static_cast<size_t>(d_array.size * d_array.size * sizeof(float)),
      cudaMemcpyHostToDevice));
  auto t2 = now();

  // Block Dimension / Threads per Block
  int block_dim = DEFAULT_BLOCK_DIM;

#ifdef OPT_KERNEL
  std::cout << "Using optimized Kernel\n";
#endif
  int grid_dim = ceil(static_cast<float>(d_array.size) /
                      static_cast<float>(block_dim - 2));

  std::cout << "Computing grid with " << d_array.size << "x" << d_array.size
            << " elements and " << numIterations << " iterations\n";
  std::cout << "Launch kernel with " << grid_dim << " blocks and " << block_dim
            << " threads per block\n";

  auto t3 = now();
  for (int i = 0; i < numIterations; i++) {
#ifdef OPT_KERNEL
    optStencil_Kernel_Wrapper(grid_dim, block_dim,
                              block_dim * 4 * sizeof(float), d_array.size,
                              d_array.array, d_array.tmp_array);
#else
    simpleStencil_Kernel_Wrapper(grid_dim, block_dim, d_array.size,
                                 d_array.array, d_array.tmp_array);
#endif

    float *tmp = d_array.array;
    d_array.array = d_array.tmp_array;
    d_array.tmp_array = tmp;
  }

  // Synchronize
  cudaDeviceSynchronize();
  auto t4 = now();

  // Copy Back Data
  auto t5 = now();
  cudaMemcpy(h_array.array, d_array.array,
             static_cast<size_t>(h_array.size * h_array.size * sizeof(float)),
             cudaMemcpyDeviceToHost);
  auto t6 = now();

  if(argc > 3)
  writeToFile(h_array.array, argv[3], h_array.size);

  // Compute time for copies and kernel
  d_ms time_copyH2D = t2 - t1;
  d_ms time_kernel = t4 - t3;
  d_ms time_copyD2H = t6 - t5;

  // Free Memory
  cudaFreeHost(h_array.array);
  cudaFreeHost(h_array.tmp_array);

  cudaFree(d_array.array);
  cudaFree(d_array.tmp_array);

  // Print Meassurement Results
  std::cout << "Results:\n"
            << "H2D \[s], kernel [s], D2H [s]\n"
            << time_copyH2D.count() << ", " << time_kernel.count() << ", "
            << time_copyD2H.count() << "\n";
  return 0;
}

void writeToFile(float *grid, const char *name, int size) {
  FILE *pFile;

  pFile = fopen(name, "w");
  int i, j;

  fprintf(pFile, "P2 %d %d %d\n", size, size, 127);

  for (i = 0; i < size; i++) {
    for (j = 0; j < size; j++) {
      fprintf(pFile, "%d ", (int)grid[j * size + i]);
    }
    fprintf(pFile, "\n");
  }

  fclose(pFile);

  return;
}

	.file	"tmpxft_002e1638_00000000-6_main.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4022:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4022:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"w"
.LC1:
	.string	"P2 %d %d %d\n"
.LC2:
	.string	"%d "
.LC3:
	.string	"\n"
	.text
	.globl	_Z11writeToFilePfPKci
	.type	_Z11writeToFilePfPKci, @function
_Z11writeToFilePfPKci:
.LFB4019:
	.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
	movslq	%edx, %r13
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	movq	%rdi, %r12
	movq	%rsi, %rdi
	leaq	.LC0(%rip), %rsi
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	leaq	0(,%r13,4), %r14
	movq	%r13, %rbp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	xorl	%ebx, %ebx
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	call	fopen@PLT
	movl	%r13d, %r8d
	movl	%r13d, %ecx
	movl	$2, %esi
	movq	%rax, (%rsp)
	movq	%rax, %rdi
	xorl	%eax, %eax
	movl	$127, %r9d
	leaq	.LC1(%rip), %rdx
	call	__fprintf_chk@PLT
.L3:
	cmpl	%ebx, %ebp
	jle	.L9
	leaq	(%r12,%rbx,4), %r10
	xorl	%r15d, %r15d
.L4:
	cvttss2sil	(%r10), %ecx
	movq	(%rsp), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
	leaq	.LC2(%rip), %rdx
	movq	%r10, 8(%rsp)
	incq	%r15
	call	__fprintf_chk@PLT
	movq	8(%rsp), %r10
	addq	%r14, %r10
	cmpq	%r15, %r13
	jne	.L4
	movq	(%rsp), %rdi
	leaq	.LC3(%rip), %rdx
	xorl	%eax, %eax
	incq	%rbx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L3
.L9:
	movq	(%rsp), %rdi
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	jmp	fclose@PLT
	.cfi_endproc
.LFE4019:
	.size	_Z11writeToFilePfPKci, .-_Z11writeToFilePfPKci
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4045:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4045:
	.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:
.LFB4151:
	.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	.L12
	movl	(%rbx), %edx
	movl	%edx, (%rax)
.L12:
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4151:
	.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_:
.LFB4146:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4146
	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	.L16
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	movq	%r14, %rdi
	call	_ZSt24__throw_invalid_argumentPKc@PLT
.L16:
	cmpl	$34, 0(%rbp)
	je	.L18
	movl	$2147483648, %ecx
	movl	$4294967295, %esi
	addq	%rax, %rcx
	cmpq	%rcx, %rsi
	jnb	.L19
.L18:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L29
	movq	%r14, %rdi
	call	_ZSt20__throw_out_of_rangePKc@PLT
.LEHE0:
.L19:
	testq	%r12, %r12
	je	.L21
	subq	%rbx, %rdx
	movq	%rdx, (%r12)
.L21:
	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	.L24
	jmp	.L29
.L25:
	endbr64
	movq	%rax, %rbx
.L22:
	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	.L29
	movq	%rbx, %rdi
.LEHB1:
	call	_Unwind_Resume@PLT
.LEHE1:
.L29:
	call	__stack_chk_fail@PLT
.L24:
	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
.LFE4146:
	.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
.LLSDA4146:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4146-.LLSDACSB4146
.LLSDACSB4146:
	.uleb128 .LEHB0-.LFB4146
	.uleb128 .LEHE0-.LEHB0
	.uleb128 .L25-.LFB4146
	.uleb128 0
	.uleb128 .LEHB1-.LFB4146
	.uleb128 .LEHE1-.LEHB1
	.uleb128 0
	.uleb128 0
.LLSDACSE4146:
	.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
.LC4:
	.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_:
.LFB4387:
	.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	.L33
	movq	8(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L38
	leaq	.LC4(%rip), %rdi
	call	_ZSt19__throw_logic_errorPKc@PLT
.L33:
	movq	%rdi, %rbx
	movq	%rsi, %rdi
	movq	%rsi, %rbp
	call	strlen@PLT
	movq	%rax, (%rsp)
	leaq	0(%rbp,%rax), %r12
	cmpq	$15, %rax
	jbe	.L35
	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)
.L35:
	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	.L36
.L38:
	call	__stack_chk_fail@PLT
.L36:
	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
.LFE4387:
	.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
.LC5:
	.string	"-h"
.LC6:
	.string	"Usage:\n\t"
.LC7:
	.string	" <problemsize> [iterations] [result.pgm]\n"
.LC8:
	.string	"stoi"
.LC9:
	.string	": "
.LC10:
	.string	" at "
.LC11:
	.string	"/home/ubuntu/Datasets/stackv2/train-structured/YannickEmonds/gpu-mangrove_exercises/main/benchmarks/time_instrumentation/5p-stencil/main.cu"
.LC12:
	.string	":"
.LC17:
	.string	"Computing grid with "
.LC18:
	.string	"x"
.LC19:
	.string	" elements and "
.LC20:
	.string	" iterations\n"
.LC21:
	.string	"Launch kernel with "
.LC22:
	.string	" blocks and "
.LC23:
	.string	" threads per block\n"
.LC25:
	.string	"Results:\n"
.LC26:
	.string	"H2D [s], kernel [s], D2H [s]\n"
.LC27:
	.string	", "
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4014:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4014
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	subq	$136, %rsp
	.cfi_def_cfa_offset 192
	movq	%fs:40, %rax
	movq	%rax, 120(%rsp)
	xorl	%eax, %eax
	cmpl	$1, %edi
	jle	.L41
	movq	8(%rsi), %rsi
	leaq	64(%rsp), %rbp
	movl	%edi, %r12d
	xorl	%r13d, %r13d
	leaq	88(%rsp), %r15
	movq	%rbp, %rdx
	movq	%r15, %rdi
.LEHB2:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
	cmpq	$2, 96(%rsp)
	jne	.L42
	movq	88(%rsp), %rdi
	movl	$2, %edx
	leaq	.LC5(%rip), %rsi
	call	memcmp@PLT
	testl	%eax, %eax
	sete	%r13b
.L42:
	movq	%r15, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	testb	%r13b, %r13b
	je	.L43
.L41:
	leaq	.LC6(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	(%rbx), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC7(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$1, %eax
	jmp	.L39
.L43:
	movq	8(%rbx), %rsi
	movq	%rbp, %rdx
	movq	%r15, %rdi
	leaq	.LC8(%rip), %r13
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE2:
	movq	88(%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:
	movl	%eax, %r14d
	movq	%r15, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	testl	%r14d, %r14d
	jg	.L45
	movl	$1024, %r14d
.L45:
	cmpl	$2, %r12d
	jne	.L46
.L48:
	movl	$5, %r13d
	jmp	.L47
.L46:
	movq	16(%rbx), %rsi
	movq	%rbp, %rdx
	movq	%r15, %rdi
.LEHB4:
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC1IS3_EEPKcRKS3_
.LEHE4:
	movq	88(%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:
	movl	%eax, %r13d
	movq	%r15, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	testl	%r13d, %r13d
	je	.L48
.L47:
	movl	%r14d, 56(%rsp)
	imull	%r14d, %r14d
	leaq	40(%rsp), %rdi
	xorl	%edx, %edx
	movslq	%r14d, %rsi
	salq	$2, %rsi
.LEHB6:
	call	cudaHostAlloc@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L49
	movl	%eax, %edi
	call	cudaGetErrorName@PLT
	leaq	_ZSt4cerr(%rip), %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r14d, %edi
	movq	%rax, %r15
	call	cudaGetErrorString@PLT
	movq	%r15, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$68, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L49:
	movl	56(%rsp), %esi
	leaq	48(%rsp), %rdi
	xorl	%edx, %edx
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaHostAlloc@PLT
	movl	%eax, %r14d
	testl	%eax, %eax
	je	.L50
	movl	%eax, %edi
	call	cudaGetErrorName@PLT
	leaq	_ZSt4cerr(%rip), %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r14d, %edi
	movq	%rax, %r15
	call	cudaGetErrorString@PLT
	movq	%r15, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$71, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L50:
	xorl	%edi, %edi
	call	srand@PLT
	movl	56(%rsp), %esi
	movq	40(%rsp), %r10
	xorl	%eax, %eax
	movss	.LC13(%rip), %xmm0
	movss	.LC14(%rip), %xmm1
	movl	%esi, %r9d
	leal	(%rsi,%rsi,2), %ecx
	sarl	$2, %r9d
	sarl	$2, %ecx
.L51:
	cmpl	%eax, %esi
	jle	.L104
	cmpl	%eax, %ecx
	setg	%r11b
	xorl	%edi, %edi
	xorl	%edx, %edx
.L55:
	testl	%eax, %eax
	jne	.L52
	movslq	%edi, %r8
	movss	%xmm0, (%r10,%r8,4)
	jmp	.L53
.L52:
	leal	(%rax,%rdi), %r8d
	movslq	%r8d, %r8
	leaq	(%r10,%r8,4), %r8
	cmpl	%eax, %r9d
	jge	.L54
	cmpl	%edx, %r9d
	setl	%r14b
	testb	%r11b, %r14b
	je	.L54
	cmpl	%edx, %ecx
	jle	.L54
	movss	%xmm1, (%r8)
	jmp	.L53
.L54:
	movl	$0x00000000, (%r8)
.L53:
	incl	%edx
	addl	%esi, %edi
	cmpl	%edx, %esi
	jne	.L55
	incl	%eax
	jmp	.L51
.L104:
	movl	%esi, 80(%rsp)
	imull	%esi, %esi
	movq	%rbp, %rdi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L57
	movl	%eax, %edi
	call	cudaGetErrorName@PLT
	leaq	_ZSt4cerr(%rip), %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %edi
	movq	%rax, %r14
	call	cudaGetErrorString@PLT
	movq	%r14, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$93, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L57:
	movl	80(%rsp), %esi
	leaq	72(%rsp), %rdi
	imull	%esi, %esi
	movslq	%esi, %rsi
	salq	$2, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L58
	movl	%eax, %edi
	call	cudaGetErrorName@PLT
	leaq	_ZSt4cerr(%rip), %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %edi
	movq	%rax, %r14
	call	cudaGetErrorString@PLT
	movq	%r14, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$96, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L58:
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	80(%rsp), %edx
	movq	40(%rsp), %rsi
	movl	$1, %ecx
	movq	64(%rsp), %rdi
	movq	%rax, %r15
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L59
	movl	%eax, %edi
	call	cudaGetErrorName@PLT
	leaq	_ZSt4cerr(%rip), %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %edi
	movq	%rax, %r14
	call	cudaGetErrorString@PLT
	movq	%r14, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$102, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L59:
	movl	80(%rsp), %edx
	movq	40(%rsp), %rsi
	movl	$1, %ecx
	movq	72(%rsp), %rdi
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L60
	movl	%eax, %edi
	call	cudaGetErrorName@PLT
	leaq	_ZSt4cerr(%rip), %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC9(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%ebp, %edi
	movq	%rax, %r14
	call	cudaGetErrorString@PLT
	movq	%r14, %rdi
	movq	%rax, %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC10(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC11(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC12(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$106, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
.L60:
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	cvtsi2ssl	80(%rsp), %xmm0
	divss	.LC16(%rip), %xmm0
	movq	%rax, %rbp
	call	ceilf@PLT
	leaq	.LC17(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	cvttss2sil	%xmm0, %eax
	movl	%eax, 8(%rsp)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	80(%rsp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC18(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	80(%rsp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC19(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	%r13d, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC20(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC21(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	8(%rsp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC22(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	$128, %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	leaq	.LC23(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	%rax, %r14
	xorl	%eax, %eax
.L61:
	cmpl	%r13d, %eax
	jge	.L105
	movq	64(%rsp), %rcx
	movl	80(%rsp), %edx
	movl	$128, %esi
	movl	%eax, 16(%rsp)
	movq	72(%rsp), %r8
	movl	8(%rsp), %edi
	call	_Z28simpleStencil_Kernel_WrapperiiiPfS_@PLT
	movq	64(%rsp), %rdx
	movq	72(%rsp), %rcx
	movl	16(%rsp), %eax
	movq	%rcx, 64(%rsp)
	movq	%rdx, 72(%rsp)
	incl	%eax
	jmp	.L61
.L105:
	call	cudaDeviceSynchronize@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	%rax, 8(%rsp)
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movl	56(%rsp), %edx
	movq	64(%rsp), %rsi
	movl	$2, %ecx
	movq	40(%rsp), %rdi
	movq	%rax, %r13
	imull	%edx, %edx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movq	%rax, 16(%rsp)
	cmpl	$3, %r12d
	jle	.L63
	movq	24(%rbx), %rsi
	movl	56(%rsp), %edx
	movq	40(%rsp), %rdi
	call	_Z11writeToFilePfPKci
.L63:
	movq	8(%rsp), %rax
	movsd	.LC24(%rip), %xmm1
	subq	%r15, %rbp
	leaq	.LC27(%rip), %r12
	cvtsi2sdq	%rbp, %xmm0
	movq	40(%rsp), %rdi
	subq	%r14, %rax
	cvtsi2sdq	%rax, %xmm2
	movq	16(%rsp), %rax
	divsd	%xmm1, %xmm0
	subq	%r13, %rax
	divsd	%xmm1, %xmm2
	movsd	%xmm0, 24(%rsp)
	movq	%xmm2, %rbp
	cvtsi2sdq	%rax, %xmm2
	divsd	%xmm1, %xmm2
	movq	%xmm2, %rbx
	call	cudaFreeHost@PLT
	movq	48(%rsp), %rdi
	call	cudaFreeHost@PLT
	movq	64(%rsp), %rdi
	call	cudaFree@PLT
	movq	72(%rsp), %rdi
	call	cudaFree@PLT
	leaq	.LC25(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	leaq	.LC26(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movsd	24(%rsp), %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbp, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%r12, %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rbx, %xmm0
	movq	%rax, %rdi
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	leaq	.LC3(%rip), %rsi
	movq	%rax, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	xorl	%eax, %eax
	jmp	.L39
.L70:
	endbr64
	jmp	.L103
.L71:
	endbr64
.L103:
	movq	%rax, %rbx
.L66:
	movq	%r15, %rdi
	call	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE10_M_disposeEv@PLT
	movq	120(%rsp), %rax
	subq	%fs:40, %rax
	jne	.L102
	movq	%rbx, %rdi
	call	_Unwind_Resume@PLT
.LEHE6:
.L39:
	movq	120(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L68
.L102:
	call	__stack_chk_fail@PLT
.L68:
	addq	$136, %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
.LFE4014:
	.section	.gcc_except_table,"a",@progbits
.LLSDA4014:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4014-.LLSDACSB4014
.LLSDACSB4014:
	.uleb128 .LEHB2-.LFB4014
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB3-.LFB4014
	.uleb128 .LEHE3-.LEHB3
	.uleb128 .L70-.LFB4014
	.uleb128 0
	.uleb128 .LEHB4-.LFB4014
	.uleb128 .LEHE4-.LEHB4
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB5-.LFB4014
	.uleb128 .LEHE5-.LEHB5
	.uleb128 .L71-.LFB4014
	.uleb128 0
	.uleb128 .LEHB6-.LFB4014
	.uleb128 .LEHE6-.LEHB6
	.uleb128 0
	.uleb128 0
.LLSDACSE4014:
	.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
	.globl	now
	.section	.data.rel.ro,"aw"
	.align 8
	.type	now, @object
	.size	now, 8
now:
	.quad	_ZNSt6chrono3_V212system_clock3nowEv
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC13:
	.long	1123942400
	.align 4
.LC14:
	.long	1120403456
	.align 4
.LC16:
	.long	1123811328
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC24:
	.long	0
	.long	1093567616
	.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 <chrono>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <hip/hip_runtime.h>
#include <iomanip>
#include <iostream>

// helper for time measurement
typedef std::chrono::duration<double, std::milli> d_ms;
const auto &now = std::chrono::high_resolution_clock::now;

// Define Error Checking Macro
#define CU_CHK(ERRORCODE)                                                      \
  {                                                                            \
    hipError_t error = ERRORCODE;                                             \
    if (error != 0) {                                                          \
      std::cerr << hipGetErrorName(error) << ": "                             \
                << hipGetErrorString(error) << " at " << __FILE__ << ":"      \
                << __LINE__ << "\n";                                           \
    }                                                                          \
  }

// Constants
const static int DEFAULT_NUM_ELEMENTS = 1024;
const static int DEFAULT_NUM_ITERATIONS = 5;
const static int DEFAULT_BLOCK_DIM = 128;

// Structures
struct StencilArray_t {
  float *array;
  float *tmp_array;
  int size; // size == width == height
};

// Function Prototypes
void writeToFile(float *matrix, const char *name, int size);

// Stencil Code Kernel for the speed calculation
extern void simpleStencil_Kernel_Wrapper(int gridSize, int blockSize, int size,
                                         float *grid_old, float *grid_new);
extern void optStencil_Kernel_Wrapper(int gridSize, int blockSize, int shm_size,
                                      int size, float *grid_old,
                                      float *grid_new);
// Main
int main(int argc, char *argv[]) {
  // Process Arguments
  if (argc < 2 or std::string(argv[1]) == "-h") {
    std::cout << "Usage:\n\t" << argv[0] << " <problemsize> [iterations] [result.pgm]\n";
    return 1;
  }

  int numElements = 0;
  numElements = std::stoi(argv[1]);
  numElements = numElements > 0 ? numElements : DEFAULT_NUM_ELEMENTS;

  int numIterations = 0;
  if (argc > 2)
    numIterations = std::stoi(argv[2]);
  numIterations = numIterations != 0 ? numIterations : DEFAULT_NUM_ITERATIONS;

  // Allocate Memory

  // Host Memory
  StencilArray_t h_array;
  h_array.size = numElements;
  // Pinned Memory
  CU_CHK(hipHostMalloc(
      &(h_array.array),
      static_cast<size_t>(h_array.size * h_array.size * sizeof(float)), hipHostMallocDefault));
  CU_CHK(hipHostMalloc(
      &(h_array.tmp_array),
      static_cast<size_t>(h_array.size * h_array.size * sizeof(float)), hipHostMallocDefault));

  // Init Particles
  //  srand(static_cast<unsigned>(time(0)));
  srand(0); // Always the same random numbers
  for (int i = 0; i < h_array.size; i++) {
    for (int j = 0; j < h_array.size; j++) {
      if (i == 0)
        h_array.array[i + h_array.size * j] = 127;
      else if (i > h_array.size / 4 && i < h_array.size * 3 / 4 &&
               j > h_array.size / 4 && j < h_array.size * 3 / 4)
        h_array.array[i + h_array.size * j] = 100;
      else
        h_array.array[i + h_array.size * j] = 0;
    }
  }

  // Device Memory
  StencilArray_t d_array;
  d_array.size = h_array.size;
  CU_CHK(hipMalloc(
      &(d_array.array),
      static_cast<size_t>(d_array.size * d_array.size * sizeof(float))));
  CU_CHK(hipMalloc(
      &(d_array.tmp_array),
      static_cast<size_t>(d_array.size * d_array.size * sizeof(float))));

  // Copy Data to the Device
  auto t1 = now();
  CU_CHK(hipMemcpy(
      d_array.array, h_array.array,
      static_cast<size_t>(d_array.size * d_array.size * sizeof(float)),
      hipMemcpyHostToDevice));
  CU_CHK(hipMemcpy(
      d_array.tmp_array, h_array.array,
      static_cast<size_t>(d_array.size * d_array.size * sizeof(float)),
      hipMemcpyHostToDevice));
  auto t2 = now();

  // Block Dimension / Threads per Block
  int block_dim = DEFAULT_BLOCK_DIM;

#ifdef OPT_KERNEL
  std::cout << "Using optimized Kernel\n";
#endif
  int grid_dim = ceil(static_cast<float>(d_array.size) /
                      static_cast<float>(block_dim - 2));

  std::cout << "Computing grid with " << d_array.size << "x" << d_array.size
            << " elements and " << numIterations << " iterations\n";
  std::cout << "Launch kernel with " << grid_dim << " blocks and " << block_dim
            << " threads per block\n";

  auto t3 = now();
  for (int i = 0; i < numIterations; i++) {
#ifdef OPT_KERNEL
    optStencil_Kernel_Wrapper(grid_dim, block_dim,
                              block_dim * 4 * sizeof(float), d_array.size,
                              d_array.array, d_array.tmp_array);
#else
    simpleStencil_Kernel_Wrapper(grid_dim, block_dim, d_array.size,
                                 d_array.array, d_array.tmp_array);
#endif

    float *tmp = d_array.array;
    d_array.array = d_array.tmp_array;
    d_array.tmp_array = tmp;
  }

  // Synchronize
  hipDeviceSynchronize();
  auto t4 = now();

  // Copy Back Data
  auto t5 = now();
  hipMemcpy(h_array.array, d_array.array,
             static_cast<size_t>(h_array.size * h_array.size * sizeof(float)),
             hipMemcpyDeviceToHost);
  auto t6 = now();

  if(argc > 3)
  writeToFile(h_array.array, argv[3], h_array.size);

  // Compute time for copies and kernel
  d_ms time_copyH2D = t2 - t1;
  d_ms time_kernel = t4 - t3;
  d_ms time_copyD2H = t6 - t5;

  // Free Memory
  hipHostFree(h_array.array);
  hipHostFree(h_array.tmp_array);

  hipFree(d_array.array);
  hipFree(d_array.tmp_array);

  // Print Meassurement Results
  std::cout << "Results:\n"
            << "H2D \[s], kernel [s], D2H [s]\n"
            << time_copyH2D.count() << ", " << time_kernel.count() << ", "
            << time_copyD2H.count() << "\n";
  return 0;
}

void writeToFile(float *grid, const char *name, int size) {
  FILE *pFile;

  pFile = fopen(name, "w");
  int i, j;

  fprintf(pFile, "P2 %d %d %d\n", size, size, 127);

  for (i = 0; i < size; i++) {
    for (j = 0; j < size; j++) {
      fprintf(pFile, "%d ", (int)grid[j * size + i]);
    }
    fprintf(pFile, "\n");
  }

  fclose(pFile);

  return;
}

	.text
	.file	"main.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0                          # -- Begin function main
.LCPI0_0:
	.long	0x42fe0000                      # float 127
.LCPI0_1:
	.long	0x42c80000                      # float 100
.LCPI0_2:
	.long	0x42fc0000                      # float 126
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0
.LCPI0_3:
	.quad	0x412e848000000000              # double 1.0E+6
	.text
	.globl	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	$88, %rsp
	.cfi_def_cfa_offset 144
	.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	$2, %edi
	jl	.LBB0_7
# %bb.1:
	movl	%edi, %r12d
	movq	8(%r15), %rsi
	leaq	32(%rsp), %r14
	leaq	8(%rsp), %rdx
	movq	%r14, %rdi
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	movq	(%r14), %rdi
	cmpq	$2, 8(%r14)
	jne	.LBB0_2
# %bb.3:
	movzwl	(%rdi), %eax
	cmpl	$26669, %eax                    # imm = 0x682D
	sete	%bpl
	jmp	.LBB0_4
.LBB0_2:
	xorl	%ebp, %ebp
.LBB0_4:                                # %.critedge
	leaq	48(%rsp), %rbx
	cmpq	%rbx, %rdi
	je	.LBB0_6
# %bb.5:                                # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i
	callq	_ZdlPv
.LBB0_6:                                # %.critedge103
	testb	%bpl, %bpl
	je	.LBB0_11
.LBB0_7:                                # %.critedge103.thread
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$8, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	(%r15), %rbx
	testq	%rbx, %rbx
	je	.LBB0_8
# %bb.9:
	movq	%rbx, %rdi
	callq	strlen
	movl	$_ZSt4cout, %edi
	movq	%rbx, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_10
.LBB0_8:
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cout(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_10:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
	movl	$_ZSt4cout, %edi
	movl	$.L.str.2, %esi
	movl	$41, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$1, %eax
	jmp	.LBB0_113
.LBB0_11:
	movl	%r12d, 80(%rsp)                 # 4-byte Spill
	movq	%r15, 72(%rsp)                  # 8-byte Spill
	movq	8(%r15), %rsi
.Ltmp0:
	leaq	32(%rsp), %rdi
	leaq	7(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp1:
# %bb.12:
	movq	32(%rsp), %r12
	callq	__errno_location
	movq	%rax, %r15
	movl	(%rax), %ebp
	movl	$0, (%rax)
	leaq	8(%rsp), %r13
	movq	%r12, %rdi
	movq	%r13, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	%r12, (%r13)
	je	.LBB0_13
# %bb.19:
	movq	%rax, %r14
	movslq	%r14d, %rax
	cmpq	%r14, %rax
	jne	.LBB0_21
# %bb.20:
	movl	(%r15), %eax
	cmpl	$34, %eax
	je	.LBB0_21
# %bb.23:
	testl	%eax, %eax
	jne	.LBB0_25
# %bb.24:
	movl	%ebp, (%r15)
.LBB0_25:
	movq	32(%rsp), %rdi
	cmpq	%rbx, %rdi
	je	.LBB0_27
# %bb.26:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i108
	callq	_ZdlPv
.LBB0_27:                               # %_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED2Ev.exit110
	testl	%r14d, %r14d
	movl	$1024, %r12d                    # imm = 0x400
	cmovgl	%r14d, %r12d
	cmpl	$2, 80(%rsp)                    # 4-byte Folded Reload
	je	.LBB0_43
# %bb.28:
	movq	72(%rsp), %rax                  # 8-byte Reload
	movq	16(%rax), %rsi
.Ltmp3:
	leaq	32(%rsp), %rdi
	leaq	7(%rsp), %rdx
	callq	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
.Ltmp4:
# %bb.29:
	movq	32(%rsp), %r13
	movl	(%r15), %eax
	movl	%eax, 64(%rsp)                  # 4-byte Spill
	movl	$0, (%r15)
	leaq	8(%rsp), %rbp
	movq	%r13, %rdi
	movq	%rbp, %rsi
	movl	$10, %edx
	callq	__isoc23_strtol
	cmpq	%r13, (%rbp)
	je	.LBB0_30
# %bb.34:
	movq	%rax, %r14
	movabsq	$-4294967296, %rax              # imm = 0xFFFFFFFF00000000
	leaq	-2147483648(%r14), %rcx
	cmpq	%rax, %rcx
	jb	.LBB0_36
# %bb.35:
	movl	(%r15), %eax
	cmpl	$34, %eax
	je	.LBB0_36
# %bb.38:
	testl	%eax, %eax
	jne	.LBB0_40
# %bb.39:
	movl	64(%rsp), %eax                  # 4-byte Reload
	movl	%eax, (%r15)
.LBB0_40:
	movq	32(%rsp), %rdi
	cmpq	%rbx, %rdi
	je	.LBB0_42
# %bb.41:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i117
	callq	_ZdlPv
.LBB0_42:
	testl	%r14d, %r14d
	jne	.LBB0_44
.LBB0_43:                               # %.thread
	movl	$5, %r14d
.LBB0_44:
	leaq	32(%rsp), %rdi
	movl	%r12d, 16(%rdi)
	imull	%r12d, %r12d
	shlq	$2, %r12
	movq	%r12, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	testl	%eax, %eax
	je	.LBB0_56
# %bb.45:
	movl	%eax, %r15d
	movl	%eax, %edi
	callq	hipGetErrorName
	testq	%rax, %rax
	je	.LBB0_46
# %bb.51:
	movq	%rax, %r12
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r12, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_52
.LBB0_46:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_52:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit127
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.3, %esi
	movl	$2, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%r15d, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB0_53
# %bb.54:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_55
.LBB0_53:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_55:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit129
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	movl	$4, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.5, %esi
	movl	$155, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.6, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$70, %esi
	callq	_ZNSolsEi
	movl	$.L.str.7, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB0_56:
	leaq	40(%rsp), %rdi
	movl	8(%rdi), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	xorl	%edx, %edx
	callq	hipHostMalloc
	testl	%eax, %eax
	je	.LBB0_64
# %bb.57:
	movl	%eax, %r15d
	movl	%eax, %edi
	callq	hipGetErrorName
	testq	%rax, %rax
	je	.LBB0_58
# %bb.59:
	movq	%rax, %r12
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r12, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_60
.LBB0_58:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_60:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit131
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.3, %esi
	movl	$2, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%r15d, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB0_61
# %bb.62:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_63
.LBB0_61:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_63:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit133
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	movl	$4, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.5, %esi
	movl	$155, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.6, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$73, %esi
	callq	_ZNSolsEi
	movl	$.L.str.7, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB0_64:
	xorl	%edi, %edi
	callq	srand
	movl	48(%rsp), %esi
	testl	%esi, %esi
	jle	.LBB0_75
# %bb.65:                               # %.preheader.lr.ph
	movl	%esi, %eax
	shrl	$2, %eax
	leal	(%rsi,%rsi,2), %ecx
	shrl	$2, %ecx
	leaq	(,%rsi,4), %rdx
	xorl	%edi, %edi
	movss	.LCPI0_0(%rip), %xmm0           # xmm0 = mem[0],zero,zero,zero
	movss	.LCPI0_1(%rip), %xmm1           # xmm1 = mem[0],zero,zero,zero
.LBB0_66:                               # %.lr.ph
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_67 Depth 2
	movq	32(%rsp), %r8
	leaq	(%r8,%rdi,4), %r9
	xorl	%r10d, %r10d
	xorl	%r11d, %r11d
.LBB0_67:                               #   Parent Loop BB0_66 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	%r8, %rbx
	movaps	%xmm0, %xmm2
	testq	%rdi, %rdi
	je	.LBB0_73
# %bb.68:                               #   in Loop: Header=BB0_67 Depth=2
	cmpq	%rax, %rdi
	jbe	.LBB0_72
# %bb.69:                               #   in Loop: Header=BB0_67 Depth=2
	cmpq	%rcx, %r11
	jae	.LBB0_72
# %bb.70:                               #   in Loop: Header=BB0_67 Depth=2
	cmpq	%rcx, %rdi
	jae	.LBB0_72
# %bb.71:                               #   in Loop: Header=BB0_67 Depth=2
	movq	%r9, %rbx
	movaps	%xmm1, %xmm2
	cmpq	%rax, %r11
	ja	.LBB0_73
.LBB0_72:                               #   in Loop: Header=BB0_67 Depth=2
	xorps	%xmm2, %xmm2
	movq	%r9, %rbx
.LBB0_73:                               #   in Loop: Header=BB0_67 Depth=2
	movss	%xmm2, (%rbx,%r10)
	incq	%r11
	addq	%rdx, %r10
	cmpq	%r11, %rsi
	jne	.LBB0_67
# %bb.74:                               # %._crit_edge
                                        #   in Loop: Header=BB0_66 Depth=1
	incq	%rdi
	cmpq	%rsi, %rdi
	jne	.LBB0_66
.LBB0_75:                               # %._crit_edge171
	leaq	8(%rsp), %rdi
	movl	%esi, 16(%rdi)
	imull	%esi, %esi
	shlq	$2, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB0_83
# %bb.76:
	movl	%eax, %r15d
	movl	%eax, %edi
	callq	hipGetErrorName
	testq	%rax, %rax
	je	.LBB0_77
# %bb.78:
	movq	%rax, %r12
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r12, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_79
.LBB0_77:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_79:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit135
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.3, %esi
	movl	$2, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%r15d, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB0_80
# %bb.81:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_82
.LBB0_80:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_82:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit137
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	movl	$4, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.5, %esi
	movl	$155, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.6, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$95, %esi
	callq	_ZNSolsEi
	movl	$.L.str.7, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB0_83:
	leaq	16(%rsp), %rdi
	movl	8(%rdi), %esi
	imull	%esi, %esi
	shlq	$2, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB0_91
# %bb.84:
	movl	%eax, %r15d
	movl	%eax, %edi
	callq	hipGetErrorName
	testq	%rax, %rax
	je	.LBB0_85
# %bb.86:
	movq	%rax, %r12
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r12, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_87
.LBB0_85:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_87:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit139
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.3, %esi
	movl	$2, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%r15d, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB0_88
# %bb.89:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_90
.LBB0_88:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_90:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit141
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	movl	$4, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.5, %esi
	movl	$155, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.6, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$98, %esi
	callq	_ZNSolsEi
	movl	$.L.str.7, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB0_91:
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %rbx
	movq	8(%rsp), %rdi
	movq	32(%rsp), %rsi
	movl	24(%rsp), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB0_99
# %bb.92:
	movl	%eax, %r15d
	movl	%eax, %edi
	callq	hipGetErrorName
	testq	%rax, %rax
	je	.LBB0_93
# %bb.94:
	movq	%rax, %r12
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r12, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_95
.LBB0_93:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_95:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit143
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.3, %esi
	movl	$2, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%r15d, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB0_96
# %bb.97:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_98
.LBB0_96:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_98:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit145
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	movl	$4, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.5, %esi
	movl	$155, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.6, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$105, %esi
	callq	_ZNSolsEi
	movl	$.L.str.7, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB0_99:
	movq	16(%rsp), %rdi
	movq	32(%rsp), %rsi
	movl	24(%rsp), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB0_107
# %bb.100:
	movl	%eax, %r15d
	movl	%eax, %edi
	callq	hipGetErrorName
	testq	%rax, %rax
	je	.LBB0_101
# %bb.102:
	movq	%rax, %r12
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r12, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_103
.LBB0_101:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_103:                              # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit147
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.3, %esi
	movl	$2, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	%r15d, %edi
	callq	hipGetErrorString
	testq	%rax, %rax
	je	.LBB0_104
# %bb.105:
	movq	%rax, %r15
	movq	%rax, %rdi
	callq	strlen
	movl	$_ZSt4cerr, %edi
	movq	%r15, %rsi
	movq	%rax, %rdx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	jmp	.LBB0_106
.LBB0_104:
	movq	_ZSt4cerr(%rip), %rax
	movq	-24(%rax), %rax
	leaq	_ZSt4cerr(%rax), %rdi
	movl	32(%rdi), %esi
	orl	$1, %esi
	callq	_ZNSt9basic_iosIcSt11char_traitsIcEE5clearESt12_Ios_Iostate
.LBB0_106:                              # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit149
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.4, %esi
	movl	$4, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.5, %esi
	movl	$155, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$.L.str.6, %esi
	movl	$1, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cerr, %edi
	movl	$109, %esi
	callq	_ZNSolsEi
	movl	$.L.str.7, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.LBB0_107:
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	xorps	%xmm0, %xmm0
	cvtsi2ssl	24(%rsp), %xmm0
	movq	%rax, %r12
	divss	.LCPI0_2(%rip), %xmm0
	callq	ceilf@PLT
	cvttss2si	%xmm0, %r13d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.8, %esi
	movl	$20, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	24(%rsp), %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movl	$.L.str.9, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	24(%rsp), %esi
	movq	%r15, %rdi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movl	$.L.str.10, %esi
	movl	$14, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r15, %rdi
	movl	%r14d, %esi
	callq	_ZNSolsEi
	movl	$.L.str.11, %esi
	movl	$12, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.12, %esi
	movl	$19, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	%r13d, %esi
	callq	_ZNSolsEi
	movq	%rax, %r15
	movl	$.L.str.13, %esi
	movl	$12, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%r15, %rdi
	movl	$128, %esi
	callq	_ZNSolsEi
	movl	$.L.str.14, %esi
	movl	$19, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r15
	testl	%r14d, %r14d
	jle	.LBB0_110
# %bb.108:                              # %.lr.ph174.preheader
	movq	8(%rsp), %rcx
	movq	16(%rsp), %r8
.LBB0_109:                              # %.lr.ph174
                                        # =>This Inner Loop Header: Depth=1
	movl	24(%rsp), %edx
	movl	%r13d, %edi
	movl	$128, %esi
	callq	_Z28simpleStencil_Kernel_WrapperiiiPfS_
	movq	8(%rsp), %r8
	movq	16(%rsp), %rcx
	movq	%rcx, 8(%rsp)
	movq	%r8, 16(%rsp)
	decl	%r14d
	jne	.LBB0_109
.LBB0_110:                              # %._crit_edge175
	callq	hipDeviceSynchronize
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r13
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %r14
	movq	32(%rsp), %rdi
	movq	8(%rsp), %rsi
	movl	48(%rsp), %edx
	imull	%edx, %edx
	shlq	$2, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movq	%rax, %rbp
	cmpl	$3, 80(%rsp)                    # 4-byte Folded Reload
	jle	.LBB0_112
# %bb.111:
	movq	32(%rsp), %rdi
	movq	72(%rsp), %rax                  # 8-byte Reload
	movq	24(%rax), %rsi
	movl	48(%rsp), %edx
	callq	_Z11writeToFilePfPKci
.LBB0_112:
	subq	%rbx, %r12
	cvtsi2sd	%r12, %xmm1
	movsd	.LCPI0_3(%rip), %xmm0           # xmm0 = mem[0],zero
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 64(%rsp)                 # 8-byte Spill
	subq	%r15, %r13
	xorps	%xmm1, %xmm1
	cvtsi2sd	%r13, %xmm1
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 72(%rsp)                 # 8-byte Spill
	subq	%r14, %rbp
	xorps	%xmm1, %xmm1
	cvtsi2sd	%rbp, %xmm1
	divsd	%xmm0, %xmm1
	movsd	%xmm1, 80(%rsp)                 # 8-byte Spill
	movq	32(%rsp), %rdi
	callq	hipHostFree
	movq	40(%rsp), %rdi
	callq	hipHostFree
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	$_ZSt4cout, %edi
	movl	$.L.str.15, %esi
	movl	$9, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movl	$.L.str.16, %esi
	movl	$29, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movl	$_ZSt4cout, %edi
	movsd	64(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.17, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%rbx, %rdi
	movsd	72(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movq	%rax, %rbx
	movl	$.L.str.17, %esi
	movl	$2, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	%rbx, %rdi
	movsd	80(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	callq	_ZNSo9_M_insertIdEERSoT_
	movl	$.L.str.7, %esi
	movl	$1, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	xorl	%eax, %eax
.LBB0_113:
	addq	$88, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB0_13:
	.cfi_def_cfa_offset 144
.Ltmp13:
	movl	$.L.str.21, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp14:
# %bb.14:
.LBB0_21:                               # %.critedge.i.i
.Ltmp11:
	movl	$.L.str.21, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp12:
# %bb.22:
.LBB0_30:
.Ltmp8:
	movl	$.L.str.21, %edi
	callq	_ZSt24__throw_invalid_argumentPKc
.Ltmp9:
# %bb.31:
.LBB0_36:                               # %.critedge.i.i112
.Ltmp6:
	movl	$.L.str.21, %edi
	callq	_ZSt20__throw_out_of_rangePKc
.Ltmp7:
# %bb.37:
.LBB0_50:
.Ltmp5:
	jmp	.LBB0_48
.LBB0_32:
.Ltmp10:
	movq	%rax, %r14
	cmpl	$0, (%r15)
	jne	.LBB0_17
# %bb.33:
	movl	64(%rsp), %eax                  # 4-byte Reload
	movl	%eax, (%r15)
	jmp	.LBB0_17
.LBB0_47:
.Ltmp2:
.LBB0_48:
	movq	%rax, %r14
	jmp	.LBB0_49
.LBB0_15:
.Ltmp15:
	movq	%rax, %r14
	cmpl	$0, (%r15)
	jne	.LBB0_17
# %bb.16:
	movl	%ebp, (%r15)
.LBB0_17:                               # %_ZZN9__gnu_cxx6__stoaIlicJiEEET0_PFT_PKT1_PPS3_DpT2_EPKcS5_PmS9_EN11_Save_errnoD2Ev.exit.i.i
	movq	32(%rsp), %rdi
	cmpq	%rbx, %rdi
	je	.LBB0_49
# %bb.18:                               # %_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE11_M_is_localEv.exit.i.i120
	callq	_ZdlPv
.LBB0_49:
	movq	%r14, %rdi
	callq	_Unwind_Resume@PLT
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
	.section	.gcc_except_table,"a",@progbits
	.p2align	2, 0x0
GCC_except_table0:
.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 .Lfunc_begin0-.Lfunc_begin0    # >> Call Site 1 <<
	.uleb128 .Ltmp0-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp0
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 2 <<
	.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 3 <<
	.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 4 <<
	.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 5 <<
	.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 6 <<
	.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 7 <<
	.uleb128 .Lfunc_end0-.Ltmp7             #   Call between .Ltmp7 and .Lfunc_end0
	.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	.LBB1_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
.LBB1_1:
	.cfi_def_cfa_offset 32
	movl	$.L.str.22, %edi
	callq	_ZSt19__throw_logic_errorPKc
.Lfunc_end1:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_, .Lfunc_end1-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEC2IS3_EEPKcRKS3_
	.cfi_endproc
                                        # -- End function
	.text
	.globl	_Z11writeToFilePfPKci           # -- Begin function _Z11writeToFilePfPKci
	.type	_Z11writeToFilePfPKci,@function
_Z11writeToFilePfPKci:                  # @_Z11writeToFilePfPKci
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	pushq	%rax
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movl	%edx, %ebp
	movq	%rsi, %rax
	movq	%rdi, %r15
	movl	$.L.str.18, %esi
	movq	%rax, %rdi
	callq	fopen
	movq	%rax, %r14
	movl	$.L.str.19, %esi
	movq	%rax, %rdi
	movl	%ebp, %edx
	movl	%ebp, %ecx
	movl	$127, %r8d
	xorl	%eax, %eax
	callq	fprintf
	testl	%ebp, %ebp
	jle	.LBB2_5
# %bb.1:                                # %.preheader.lr.ph
	movl	%ebp, %ebp
	leaq	(,%rbp,4), %r12
	xorl	%r13d, %r13d
	movq	%rbp, (%rsp)                    # 8-byte Spill
.LBB2_2:                                # %.lr.ph.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB2_3 Depth 2
	movq	%r15, %rbx
.LBB2_3:                                # %.lr.ph
                                        #   Parent Loop BB2_2 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cvttss2si	(%rbx), %edx
	movl	$.L.str.20, %esi
	movq	%r14, %rdi
	xorl	%eax, %eax
	callq	fprintf
	addq	%r12, %rbx
	decq	%rbp
	jne	.LBB2_3
# %bb.4:                                # %._crit_edge
                                        #   in Loop: Header=BB2_2 Depth=1
	movl	$10, %edi
	movq	%r14, %rsi
	callq	fputc@PLT
	incq	%r13
	addq	$4, %r15
	movq	(%rsp), %rbp                    # 8-byte Reload
	cmpq	%rbp, %r13
	jne	.LBB2_2
.LBB2_5:                                # %._crit_edge20
	movq	%r14, %rdi
	addq	$8, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	jmp	fclose                          # TAILCALL
.Lfunc_end2:
	.size	_Z11writeToFilePfPKci, .Lfunc_end2-_Z11writeToFilePfPKci
	.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	.LBB3_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	.LBB3_3
.LBB3_1:                                # %._crit_edge
	movq	(%rbx), %rax
.LBB3_3:
	testq	%r14, %r14
	je	.LBB3_7
# %bb.4:
	cmpq	$1, %r14
	jne	.LBB3_6
# %bb.5:
	movb	(%r15), %cl
	movb	%cl, (%rax)
	jmp	.LBB3_7
.LBB3_6:
	movq	%rax, %rdi
	movq	%r15, %rsi
	movq	%r14, %rdx
	callq	memcpy@PLT
.LBB3_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_end3:
	.size	_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag, .Lfunc_end3-_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag
	.cfi_endproc
                                        # -- End function
	.type	now,@object                     # @now
	.section	.rodata,"a",@progbits
	.globl	now
	.p2align	3, 0x0
now:
	.quad	_ZNSt6chrono3_V212system_clock3nowEv
	.size	now, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"-h"
	.size	.L.str, 3

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Usage:\n\t"
	.size	.L.str.1, 9

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	" <problemsize> [iterations] [result.pgm]\n"
	.size	.L.str.2, 42

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

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

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"/home/ubuntu/Datasets/stackv2/train-structured-repos-hip-sm89/YannickEmonds/gpu-mangrove_exercises/main/benchmarks/time_instrumentation/5p-stencil/main.hip"
	.size	.L.str.5, 156

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

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"\n"
	.size	.L.str.7, 2

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Computing grid with "
	.size	.L.str.8, 21

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

	.type	.L.str.10,@object               # @.str.10
.L.str.10:
	.asciz	" elements and "
	.size	.L.str.10, 15

	.type	.L.str.11,@object               # @.str.11
.L.str.11:
	.asciz	" iterations\n"
	.size	.L.str.11, 13

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Launch kernel with "
	.size	.L.str.12, 20

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	" blocks and "
	.size	.L.str.13, 13

	.type	.L.str.14,@object               # @.str.14
.L.str.14:
	.asciz	" threads per block\n"
	.size	.L.str.14, 20

	.type	.L.str.15,@object               # @.str.15
.L.str.15:
	.asciz	"Results:\n"
	.size	.L.str.15, 10

	.type	.L.str.16,@object               # @.str.16
.L.str.16:
	.asciz	"H2D [s], kernel [s], D2H [s]\n"
	.size	.L.str.16, 30

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

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

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

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

	.type	.L.str.21,@object               # @.str.21
.L.str.21:
	.asciz	"stoi"
	.size	.L.str.21, 5

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

	.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 _ZNSt6chrono3_V212system_clock3nowEv
	.addrsig_sym __gxx_personality_v0
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _ZSt4cout
	.addrsig_sym _ZSt4cerr
	.addrsig_sym __hip_cuid_

	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.amdgpu_metadata
---
amdhsa.kernels:  []
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
