#include <thrust/complex.h>
#include <stdio.h> 
#include <stdlib.h>
#include <png.h>
#include <sys/time.h>

#define M 200

#define DIE(...) { \
  fprintf(stderr, __VA_ARGS__); \
  exit(EXIT_FAILURE); \
}

float points[4];  // c0_real, c0_image, c1_real, c1_image
int w, h;
char cpu_gpu[5];  // do the calculations in cpu or gpu  
int num_threads_arg;
char saida[256];

void application_error(char message[256]) {
  printf ("%s\n", message);
  exit(0);
}

void write_png_file(float *buffer) {
  int i, j;
  png_bytep row = NULL;
  png_structp png_ptr;
  png_infop info_ptr;

  /* Open file for writing (binary mode) */
  FILE *fp = fopen(saida, "wb");
  if (!fp) {
    DIE("write_png_file(): Could not open file ... ");
  }

  /* Initialize write structure */
  png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  if (!png_ptr) {
    DIE("write_png_file(): png_ptr is NULL ... ");
  }
  
  /* Initialize info structure */
  info_ptr = png_create_info_struct(png_ptr);
  if (!info_ptr) {
    if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    DIE("write_png_file(): info_ptr is NULL ... ");
  }

  /* Exception handling */
  if (setjmp(png_jmpbuf(png_ptr))) {
    if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
    if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    if (fp != NULL) fclose(fp);
    if (row != NULL) free(row);
    DIE("write_png_file(): libpng error ... ");
  }

  png_init_io(png_ptr, fp);

  png_set_IHDR(png_ptr, info_ptr, w, h,
			8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
			PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

  png_write_info(png_ptr, info_ptr);

  row = (png_bytep) malloc(3 * w * sizeof(png_byte));

  /* write image data */
  for (i = 0; i < h; ++i) {
    for (j = 0; j < w; ++j) {
      row[3 * j] = buffer[i * w + j];
      row[3 * j + 1] = 0;
      row[3 * j + 2] =  0;
    }
    png_write_row(png_ptr, row);
  }

  /* End write */
  png_write_end(png_ptr, NULL);

  if (fp != NULL) fclose(fp);
	if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
	if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
	if (row != NULL) free(row); 
}

float test_complex_number(int k) {
  int j = k / w;
  int i = k % w;

  float dx = (points[2] - points[0]) / w ;
  float dy = (points[3] - points[1]) / h;
  float image = points[1] + dy * i;
  float real = points[0] + dx * j;

  thrust::complex<float> c = thrust::complex<float>(real, image);
  thrust::complex<float> z = thrust::complex<float>(0, 0);
  int it = 0;

  while (it < M && norm(z) < 2.0) {
    z = z * z + c;
    ++it;
  }

  if (it < M) {
    return (255 * it) / M;
  } 
  
  return 0;
}

float *cpu_create_image() {
  float *buffer = (float *) malloc(sizeof(float) * w * h);
  int k;

  if (buffer == NULL) {
    DIE("createImage(): could create buffer ... ");
  }

  #pragma omp parallel for num_threads(num_threads_arg) 
  for (k = 0; k < w * h; ++k)
    buffer[k] = test_complex_number(k);
 
  return buffer;
}

void cpu_solve() {
  float *buffer;
  buffer = cpu_create_image();
  write_png_file(buffer);
  free(buffer);
}

__global__
void gpu_create_image(float *buffer, int w, int h, float *points) {
  const int globalIndex = blockDim.x*blockIdx.x + threadIdx.x;
  
  if (globalIndex < w * h) {
    int j = globalIndex / w;
    int i = globalIndex % w;

    float dx = (points[2] - points[0]) / w ;
    float dy = (points[3] - points[1]) / h;
    float image = points[1] + dy * i;
    float real = points[0] + dx * j;

    thrust::complex<float> c = thrust::complex<float>(real, image);
    thrust::complex<float> z = thrust::complex<float>(0, 0);

    int it = 0;

    while (it < M && norm(z) < 2.0) {
      z = z * z + c;
      ++it;
    }

    if (it < M) buffer[globalIndex] = (255 * it) / M;
    else buffer[globalIndex] = 0;
  } 
}


void gpu_solve() {
  const int THREADS_PER_BLOCK = num_threads_arg;
  const int NUM_BLOCKS = (w * h + THREADS_PER_BLOCK - 1) / THREADS_PER_BLOCK;
  float *buffer_cpu;
  float *buffer_gpu, *points_gpu;
 
  buffer_cpu = (float *) malloc(sizeof(float) * w * h);

  if (buffer_cpu == NULL) {
    DIE("gpu_solve(): buffer_cpu is NULL ...");
  }

  cudaMalloc(&buffer_gpu, w * h * sizeof(float));
  cudaMalloc(&points_gpu, 4 * sizeof(float));

  cudaMemcpy(points_gpu, points, 4 * sizeof(float), cudaMemcpyHostToDevice);

  gpu_create_image<<<NUM_BLOCKS, THREADS_PER_BLOCK>>>(buffer_gpu, w, h, points_gpu);
  cudaDeviceSynchronize();

  cudaMemcpy(buffer_cpu, buffer_gpu, w * h * sizeof(float), cudaMemcpyDeviceToHost);

  write_png_file(buffer_cpu);

  cudaFree(buffer_gpu);
  cudaFree(points);
}

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

  struct timeval start, end;

  // Read Arguments
  if (argc < 9 
  || sscanf(argv[1], "%f", &points[0])        != 1 
  || sscanf(argv[2], "%f", &points[1])        != 1
  || sscanf(argv[3], "%f", &points[2])        != 1 
  || sscanf(argv[4], "%f", &points[3])        != 1 
  || sscanf(argv[5], "%d", &w)                != 1 
  || sscanf(argv[6], "%d", &h)                != 1
  || sscanf(argv[7], "%s", cpu_gpu)           != 1 
  || sscanf(argv[8], "%d", &num_threads_arg)  != 1
  || sscanf(argv[9], "%s", saida)             != 1) {
    DIE("Invalid Arguments ...\n");
  }

  gettimeofday(&start, NULL);
  if (cpu_gpu[0] == 'c') cpu_solve();
  else gpu_solve();
  gettimeofday(&end, NULL);

  double elapsed_time = (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 10000000.0;
  printf("%.4lf\n", elapsed_time);

  return 0;
}
	.file	"tmpxft_0027a147_00000000-6_mbrot.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB5949:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE5949:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%s\n"
	.text
	.globl	_Z17application_errorPc
	.type	_Z17application_errorPc, @function
_Z17application_errorPc:
.LFB5940:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	popq	%rax
	.cfi_def_cfa_offset 8
	leaq	.LC0(%rip), %rsi
	pushq	%rax
	.cfi_def_cfa_offset 16
	movq	%rdi, %rdx
	xorl	%eax, %eax
	movl	$2, %edi
	call	__printf_chk@PLT
	xorl	%edi, %edi
	call	exit@PLT
	.cfi_endproc
.LFE5940:
	.size	_Z17application_errorPc, .-_Z17application_errorPc
	.section	.rodata.str1.1
.LC1:
	.string	"wb"
.LC2:
	.string	"write_png_file(): Could not open file ... "
.LC3:
	.string	"1.6.43"
.LC4:
	.string	"write_png_file(): png_ptr is NULL ... "
.LC5:
	.string	"write_png_file(): info_ptr is NULL ... "
.LC6:
	.string	"write_png_file(): libpng error ... "
	.text
	.globl	_Z14write_png_filePf
	.type	_Z14write_png_filePf, @function
_Z14write_png_filePf:
.LFB5941:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	leaq	.LC1(%rip), %rsi
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$56, %rsp
	.cfi_def_cfa_offset 80
	movq	%rdi, 24(%rsp)
	leaq	saida(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	fopen@PLT
	movq	%rax, 16(%rsp)
	testq	%rax, %rax
	jne	.L5
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	movl	$2, %esi
	jmp	.L35
.L5:
	leaq	.LC3(%rip), %rdi
	xorl	%ecx, %ecx
	xorl	%edx, %edx
	xorl	%esi, %esi
	call	png_create_write_struct@PLT
	movq	%rax, 32(%rsp)
	movq	%rax, %rdi
	testq	%rax, %rax
	jne	.L6
	leaq	.LC4(%rip), %rdx
.L36:
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	xorl	%eax, %eax
.L35:
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L6:
	call	png_create_info_struct@PLT
	movq	32(%rsp), %rdi
	movq	%rax, 8(%rsp)
	testq	%rax, %rax
	jne	.L7
	testq	%rdi, %rdi
	jne	.L8
.L10:
	leaq	.LC5(%rip), %rdx
	jmp	.L36
.L8:
	leaq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	png_destroy_write_struct@PLT
	jmp	.L10
.L7:
	movq	__longjmp_chk@GOTPCREL(%rip), %rsi
	movl	$200, %edx
	call	png_set_longjmp_fn@PLT
	movq	%rax, %rdi
	call	_setjmp@PLT
	endbr64
	movq	32(%rsp), %rdi
	movl	%eax, %ebp
	testl	%eax, %eax
	je	.L12
	cmpq	$0, 8(%rsp)
	jne	.L13
.L16:
	cmpq	$0, 32(%rsp)
	jne	.L14
	jmp	.L15
.L13:
	movq	8(%rsp), %rsi
	orl	$-1, %ecx
	movl	$65535, %edx
	call	png_free_data@PLT
	jmp	.L16
.L14:
	leaq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	png_destroy_write_struct@PLT
.L15:
	cmpq	$0, 16(%rsp)
	je	.L20
	movq	16(%rsp), %rdi
	call	fclose@PLT
.L20:
	leaq	.LC6(%rip), %rdx
	jmp	.L36
.L12:
	movq	16(%rsp), %rsi
	call	png_init_io@PLT
	movl	h(%rip), %ecx
	movl	w(%rip), %edx
	movl	$2, %r9d
	pushq	%rax
	.cfi_def_cfa_offset 88
	movl	$8, %r8d
	pushq	$0
	.cfi_def_cfa_offset 96
	pushq	$0
	.cfi_def_cfa_offset 104
	pushq	$0
	.cfi_def_cfa_offset 112
	movq	40(%rsp), %rsi
	movq	64(%rsp), %rdi
	call	png_set_IHDR@PLT
	movq	40(%rsp), %rsi
	movq	64(%rsp), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 80
	call	png_write_info@PLT
	imull	$3, w(%rip), %edi
	movslq	%edi, %rdi
	call	malloc@PLT
	movq	%rax, %rbx
.L21:
	cmpl	%ebp, h(%rip)
	jle	.L23
	movl	w(%rip), %ecx
	movq	24(%rsp), %rdx
	movl	%ecx, %eax
	imull	%ebp, %eax
	cltq
	leaq	(%rdx,%rax,4), %rsi
	xorl	%eax, %eax
	xorl	%edx, %edx
.L24:
	cmpl	%edx, %ecx
	jle	.L38
	cvttss2sil	(%rsi,%rdx,4), %edi
	movb	$0, 1(%rbx,%rax)
	incq	%rdx
	movb	$0, 2(%rbx,%rax)
	movb	%dil, (%rbx,%rax)
	addq	$3, %rax
	jmp	.L24
.L38:
	movq	32(%rsp), %rdi
	movq	%rbx, %rsi
	incl	%ebp
	call	png_write_row@PLT
	jmp	.L21
.L23:
	movq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	png_write_end@PLT
	cmpq	$0, 16(%rsp)
	jne	.L25
.L28:
	cmpq	$0, 8(%rsp)
	movq	32(%rsp), %rdi
	jne	.L26
	jmp	.L27
.L25:
	movq	16(%rsp), %rdi
	call	fclose@PLT
	jmp	.L28
.L26:
	movq	8(%rsp), %rsi
	orl	$-1, %ecx
	movl	$65535, %edx
	call	png_free_data@PLT
.L27:
	cmpq	$0, 32(%rsp)
	je	.L30
	leaq	32(%rsp), %rdi
	xorl	%esi, %esi
	call	png_destroy_write_struct@PLT
.L30:
	testq	%rbx, %rbx
	je	.L4
	movq	%rbx, %rdi
	call	free@PLT
.L4:
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L33
	call	__stack_chk_fail@PLT
.L33:
	addq	$56, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5941:
	.size	_Z14write_png_filePf, .-_Z14write_png_filePf
	.globl	_Z19test_complex_numberi
	.type	_Z19test_complex_numberi, @function
_Z19test_complex_numberi:
.LFB5942:
	.cfi_startproc
	endbr64
	movl	w(%rip), %ecx
	movl	%edi, %eax
	movss	4+points(%rip), %xmm1
	movss	.LC8(%rip), %xmm6
	cltd
	movss	12+points(%rip), %xmm2
	cvtsi2ssl	h(%rip), %xmm3
	idivl	%ecx
	movss	points(%rip), %xmm0
	movss	.LC9(%rip), %xmm7
	movss	.LC10(%rip), %xmm8
	subss	%xmm1, %xmm2
	divss	%xmm3, %xmm2
	cvtsi2ssl	%edx, %xmm3
	mulss	%xmm3, %xmm2
	cvtsi2ssl	%ecx, %xmm3
	addss	%xmm1, %xmm2
	movss	8+points(%rip), %xmm1
	subss	%xmm0, %xmm1
	divss	%xmm3, %xmm1
	cvtsi2ssl	%eax, %xmm3
	xorl	%eax, %eax
	mulss	%xmm3, %xmm1
	addss	%xmm0, %xmm1
	xorps	%xmm0, %xmm0
	movaps	%xmm0, %xmm3
.L45:
	movaps	%xmm3, %xmm4
	movaps	%xmm0, %xmm5
	mulss	%xmm0, %xmm5
	andps	%xmm6, %xmm4
	comiss	%xmm4, %xmm7
	movaps	%xmm3, %xmm4
	mulss	%xmm3, %xmm4
	jbe	.L40
	movaps	%xmm0, %xmm9
	andps	%xmm6, %xmm9
	comiss	%xmm9, %xmm7
	ja	.L42
.L40:
	movaps	%xmm4, %xmm9
	addss	%xmm5, %xmm9
	comiss	%xmm9, %xmm8
	jbe	.L49
.L42:
	mulss	%xmm3, %xmm0
	subss	%xmm5, %xmm4
	incl	%eax
	addss	%xmm1, %xmm4
	addss	%xmm0, %xmm0
	movaps	%xmm4, %xmm3
	addss	%xmm2, %xmm0
	cmpl	$200, %eax
	jne	.L45
	xorps	%xmm0, %xmm0
	ret
.L49:
	imull	$255, %eax, %eax
	movl	$200, %ecx
	cltd
	idivl	%ecx
	cvtsi2ssl	%eax, %xmm0
	ret
	.cfi_endproc
.LFE5942:
	.size	_Z19test_complex_numberi, .-_Z19test_complex_numberi
	.section	.rodata.str1.1
.LC11:
	.string	"createImage(): could create buffer ... "
	.text
	.globl	_Z16cpu_create_imagev
	.type	_Z16cpu_create_imagev, @function
_Z16cpu_create_imagev:
.LFB5943:
	.cfi_startproc
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	.cfi_offset 3, -24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	movslq	w(%rip), %rdi
	movslq	h(%rip), %rax
	movq	%rdi, %rbx
	imulq	%rax, %rdi
	movq	%rax, %rbp
	salq	$2, %rdi
	call	malloc@PLT
	testq	%rax, %rax
	je	.L51
	imull	%ebp, %ebx
	xorl	%r8d, %r8d
	jmp	.L52
.L51:
	movq	stderr(%rip), %rdi
	leaq	.LC11(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L52:
	movl	%r8d, %edi
	cmpl	%r8d, %ebx
	jle	.L55
	movq	%rax, 8(%rsp)
	call	_Z19test_complex_numberi
	movq	8(%rsp), %rax
	movss	%xmm0, (%rax,%r8,4)
	incq	%r8
	jmp	.L52
.L55:
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5943:
	.size	_Z16cpu_create_imagev, .-_Z16cpu_create_imagev
	.globl	_Z9cpu_solvev
	.type	_Z9cpu_solvev, @function
_Z9cpu_solvev:
.LFB5944:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	call	_Z16cpu_create_imagev
	movq	%rax, %rbx
	movq	%rax, %rdi
	call	_Z14write_png_filePf
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	free@PLT
	.cfi_endproc
.LFE5944:
	.size	_Z9cpu_solvev, .-_Z9cpu_solvev
	.globl	_Z40__device_stub__Z16gpu_create_imagePfiiS_PfiiS_
	.type	_Z40__device_stub__Z16gpu_create_imagePfiiS_PfiiS_, @function
_Z40__device_stub__Z16gpu_create_imagePfiiS_PfiiS_:
.LFB5971:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movl	%esi, 20(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 16(%rsp)
	leaq	40(%rsp), %rdx
	movq	%rcx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	20(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L58
	pushq	48(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z16gpu_create_imagePfiiS_(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 176
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L58:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L60
	call	__stack_chk_fail@PLT
.L60:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5971:
	.size	_Z40__device_stub__Z16gpu_create_imagePfiiS_PfiiS_, .-_Z40__device_stub__Z16gpu_create_imagePfiiS_PfiiS_
	.globl	_Z16gpu_create_imagePfiiS_
	.type	_Z16gpu_create_imagePfiiS_, @function
_Z16gpu_create_imagePfiiS_:
.LFB5972:
	.cfi_startproc
	endbr64
	jmp	_Z40__device_stub__Z16gpu_create_imagePfiiS_PfiiS_
	.cfi_endproc
.LFE5972:
	.size	_Z16gpu_create_imagePfiiS_, .-_Z16gpu_create_imagePfiiS_
	.section	.rodata.str1.1
.LC12:
	.string	"gpu_solve(): buffer_cpu is NULL ..."
	.text
	.globl	_Z9gpu_solvev
	.type	_Z9gpu_solvev, @function
_Z9gpu_solvev:
.LFB5945:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	pushq	%r12
	.cfi_def_cfa_offset 24
	.cfi_offset 12, -24
	pushq	%rbp
	.cfi_def_cfa_offset 32
	.cfi_offset 6, -32
	pushq	%rbx
	.cfi_def_cfa_offset 40
	.cfi_offset 3, -40
	subq	$56, %rsp
	.cfi_def_cfa_offset 96
	movslq	w(%rip), %rbx
	movslq	h(%rip), %rcx
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	movl	num_threads_arg(%rip), %r12d
	movl	%ebx, %eax
	imulq	%rcx, %rbx
	imull	%ecx, %eax
	salq	$2, %rbx
	leal	-1(%r12,%rax), %eax
	movq	%rbx, %rdi
	cltd
	idivl	%r12d
	movl	%eax, %ebp
	call	malloc@PLT
	testq	%rax, %rax
	jne	.L64
	movq	stderr(%rip), %rdi
	leaq	.LC12(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L64:
	movq	%rbx, %rsi
	movq	%rsp, %rdi
	leaq	points(%rip), %rbx
	movq	%rax, %r13
	call	cudaMalloc@PLT
	leaq	8(%rsp), %rdi
	movl	$16, %esi
	call	cudaMalloc@PLT
	movq	8(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	movl	$16, %edx
	call	cudaMemcpy@PLT
	movl	%r12d, 28(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movabsq	$4294967297, %rax
	movl	%ebp, 16(%rsp)
	movq	%rax, 32(%rsp)
	movl	36(%rsp), %ecx
	movq	%rax, 20(%rsp)
	movq	28(%rsp), %rdx
	movq	16(%rsp), %rdi
	movl	24(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L65
	movq	8(%rsp), %rcx
	movl	h(%rip), %edx
	movl	w(%rip), %esi
	movq	(%rsp), %rdi
	call	_Z40__device_stub__Z16gpu_create_imagePfiiS_PfiiS_
.L65:
	call	cudaDeviceSynchronize@PLT
	movl	w(%rip), %edx
	movq	(%rsp), %rsi
	movq	%r13, %rdi
	imull	h(%rip), %edx
	movl	$2, %ecx
	movslq	%edx, %rdx
	salq	$2, %rdx
	call	cudaMemcpy@PLT
	movq	%r13, %rdi
	call	_Z14write_png_filePf
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	%rbx, %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L66
	call	__stack_chk_fail@PLT
.L66:
	addq	$56, %rsp
	.cfi_def_cfa_offset 40
	popq	%rbx
	.cfi_def_cfa_offset 32
	popq	%rbp
	.cfi_def_cfa_offset 24
	popq	%r12
	.cfi_def_cfa_offset 16
	popq	%r13
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5945:
	.size	_Z9gpu_solvev, .-_Z9gpu_solvev
	.section	.rodata.str1.1
.LC13:
	.string	"Invalid Arguments ...\n"
.LC14:
	.string	"%f"
.LC15:
	.string	"%d"
.LC16:
	.string	"%s"
.LC18:
	.string	"%.4lf\n"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB5946:
	.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	$48, %rsp
	.cfi_def_cfa_offset 80
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	cmpl	$8, %edi
	jg	.L69
.L70:
	movq	stderr(%rip), %rdi
	leaq	.LC13(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	call	__fprintf_chk@PLT
	movl	$1, %edi
	call	exit@PLT
.L69:
	movq	8(%rsi), %rdi
	leaq	.LC14(%rip), %rbp
	xorl	%eax, %eax
	movq	%rsi, %rbx
	leaq	points(%rip), %rdx
	movq	%rbp, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	movq	16(%rbx), %rdi
	xorl	%eax, %eax
	leaq	4+points(%rip), %rdx
	movq	%rbp, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	movq	24(%rbx), %rdi
	xorl	%eax, %eax
	leaq	8+points(%rip), %rdx
	movq	%rbp, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	movq	32(%rbx), %rdi
	xorl	%eax, %eax
	leaq	12+points(%rip), %rdx
	movq	%rbp, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	movq	40(%rbx), %rdi
	leaq	.LC15(%rip), %rbp
	xorl	%eax, %eax
	leaq	w(%rip), %rdx
	movq	%rbp, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	movq	48(%rbx), %rdi
	xorl	%eax, %eax
	leaq	h(%rip), %rdx
	movq	%rbp, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	movq	56(%rbx), %rdi
	leaq	.LC16(%rip), %r12
	xorl	%eax, %eax
	leaq	cpu_gpu(%rip), %rdx
	movq	%r12, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	movq	64(%rbx), %rdi
	xorl	%eax, %eax
	leaq	num_threads_arg(%rip), %rdx
	movq	%rbp, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	movq	72(%rbx), %rdi
	xorl	%eax, %eax
	leaq	saida(%rip), %rdx
	movq	%r12, %rsi
	call	__isoc23_sscanf@PLT
	decl	%eax
	jne	.L70
	xorl	%esi, %esi
	leaq	8(%rsp), %rdi
	call	gettimeofday@PLT
	cmpb	$99, cpu_gpu(%rip)
	jne	.L71
	call	_Z9cpu_solvev
	jmp	.L72
.L71:
	call	_Z9gpu_solvev
.L72:
	xorl	%esi, %esi
	leaq	24(%rsp), %rdi
	call	gettimeofday@PLT
	movq	32(%rsp), %rax
	subq	16(%rsp), %rax
	leaq	.LC18(%rip), %rsi
	cvtsi2sdq	%rax, %xmm0
	movq	24(%rsp), %rax
	subq	8(%rsp), %rax
	divsd	.LC17(%rip), %xmm0
	cvtsi2sdq	%rax, %xmm1
	movl	$2, %edi
	movb	$1, %al
	addsd	%xmm1, %xmm0
	call	__printf_chk@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L73
	call	__stack_chk_fail@PLT
.L73:
	addq	$48, %rsp
	.cfi_def_cfa_offset 32
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%rbp
	.cfi_def_cfa_offset 16
	popq	%r12
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE5946:
	.size	main, .-main
	.section	.rodata.str1.1
.LC19:
	.string	"_Z16gpu_create_imagePfiiS_"
.LC20:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std3__45__cpo5beginE"
.LC21:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std3__45__cpo3endE"
.LC22:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std3__45__cpo6cbeginE"
.LC23:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std3__45__cpo4cendE"
.LC24:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE"
.LC25:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std3__419piecewise_constructE"
.LC26:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std3__48in_placeE"
.LC27:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std6ranges3__45__cpo4swapE"
.LC28:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std6ranges3__45__cpo9iter_moveE"
.LC29:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656794cuda3std6ranges3__45__cpo7advanceE"
.LC30:
	.string	"_ZN38_INTERNAL_22013a87_8_mbrot_cu_46a656796thrust20THRUST_200700_890_NS6system6detail10sequential3seqE"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB5974:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -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	.LC19(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z16gpu_create_imagePfiiS_(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC20(%rip), %rdx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__45__cpo5beginE(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC21(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__45__cpo3endE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC22(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__45__cpo6cbeginE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC23(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__45__cpo4cendE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC24(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC25(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__419piecewise_constructE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC26(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std3__48in_placeE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC27(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std6ranges3__45__cpo4swapE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%rdi
	.cfi_def_cfa_offset 24
	popq	%r8
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC28(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std6ranges3__45__cpo9iter_moveE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r9
	.cfi_def_cfa_offset 24
	popq	%r10
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC29(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN4cuda3std6ranges3__45__cpo7advanceE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	popq	%r11
	.cfi_def_cfa_offset 24
	popq	%rax
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC30(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$1, %r9d
	leaq	_ZN6thrust20THRUST_200700_890_NS6system6detail10sequentialL3seqE(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE5974:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.globl	saida
	.bss
	.align 32
	.type	saida, @object
	.size	saida, 256
saida:
	.zero	256
	.globl	num_threads_arg
	.align 4
	.type	num_threads_arg, @object
	.size	num_threads_arg, 4
num_threads_arg:
	.zero	4
	.globl	cpu_gpu
	.type	cpu_gpu, @object
	.size	cpu_gpu, 5
cpu_gpu:
	.zero	5
	.globl	h
	.align 4
	.type	h, @object
	.size	h, 4
h:
	.zero	4
	.globl	w
	.align 4
	.type	w, @object
	.size	w, 4
w:
	.zero	4
	.globl	points
	.align 16
	.type	points, @object
	.size	points, 16
points:
	.zero	16
	.section	.rodata
	.type	_ZN6thrust20THRUST_200700_890_NS6system6detail10sequentialL3seqE, @object
	.size	_ZN6thrust20THRUST_200700_890_NS6system6detail10sequentialL3seqE, 1
_ZN6thrust20THRUST_200700_890_NS6system6detail10sequentialL3seqE:
	.zero	1
	.weak	_ZN4cuda3std6ranges3__45__cpo7advanceE
	.section	.rodata._ZN4cuda3std6ranges3__45__cpo7advanceE,"aG",@progbits,_ZN4cuda3std6ranges3__45__cpo7advanceE,comdat
	.type	_ZN4cuda3std6ranges3__45__cpo7advanceE, @gnu_unique_object
	.size	_ZN4cuda3std6ranges3__45__cpo7advanceE, 1
_ZN4cuda3std6ranges3__45__cpo7advanceE:
	.zero	1
	.hidden	_ZN4cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE
	.weak	_ZN4cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE
	.section	.rodata._ZN4cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE,"aG",@progbits,_ZN4cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE,comdat
	.type	_ZN4cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE, @gnu_unique_object
	.size	_ZN4cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE, 1
_ZN4cuda3std3__440_GLOBAL__N__22013a87_8_mbrot_cu_46a656796ignoreE:
	.zero	1
	.weak	_ZN4cuda3std3__48in_placeE
	.section	.rodata._ZN4cuda3std3__48in_placeE,"aG",@progbits,_ZN4cuda3std3__48in_placeE,comdat
	.type	_ZN4cuda3std3__48in_placeE, @gnu_unique_object
	.size	_ZN4cuda3std3__48in_placeE, 1
_ZN4cuda3std3__48in_placeE:
	.zero	1
	.weak	_ZN4cuda3std3__45__cpo4cendE
	.section	.rodata._ZN4cuda3std3__45__cpo4cendE,"aG",@progbits,_ZN4cuda3std3__45__cpo4cendE,comdat
	.type	_ZN4cuda3std3__45__cpo4cendE, @gnu_unique_object
	.size	_ZN4cuda3std3__45__cpo4cendE, 1
_ZN4cuda3std3__45__cpo4cendE:
	.zero	1
	.weak	_ZN4cuda3std3__45__cpo6cbeginE
	.section	.rodata._ZN4cuda3std3__45__cpo6cbeginE,"aG",@progbits,_ZN4cuda3std3__45__cpo6cbeginE,comdat
	.type	_ZN4cuda3std3__45__cpo6cbeginE, @gnu_unique_object
	.size	_ZN4cuda3std3__45__cpo6cbeginE, 1
_ZN4cuda3std3__45__cpo6cbeginE:
	.zero	1
	.weak	_ZN4cuda3std3__45__cpo3endE
	.section	.rodata._ZN4cuda3std3__45__cpo3endE,"aG",@progbits,_ZN4cuda3std3__45__cpo3endE,comdat
	.type	_ZN4cuda3std3__45__cpo3endE, @gnu_unique_object
	.size	_ZN4cuda3std3__45__cpo3endE, 1
_ZN4cuda3std3__45__cpo3endE:
	.zero	1
	.weak	_ZN4cuda3std3__45__cpo5beginE
	.section	.rodata._ZN4cuda3std3__45__cpo5beginE,"aG",@progbits,_ZN4cuda3std3__45__cpo5beginE,comdat
	.type	_ZN4cuda3std3__45__cpo5beginE, @gnu_unique_object
	.size	_ZN4cuda3std3__45__cpo5beginE, 1
_ZN4cuda3std3__45__cpo5beginE:
	.zero	1
	.weak	_ZN4cuda3std3__419piecewise_constructE
	.section	.rodata._ZN4cuda3std3__419piecewise_constructE,"aG",@progbits,_ZN4cuda3std3__419piecewise_constructE,comdat
	.type	_ZN4cuda3std3__419piecewise_constructE, @gnu_unique_object
	.size	_ZN4cuda3std3__419piecewise_constructE, 1
_ZN4cuda3std3__419piecewise_constructE:
	.zero	1
	.weak	_ZN4cuda3std6ranges3__45__cpo9iter_moveE
	.section	.rodata._ZN4cuda3std6ranges3__45__cpo9iter_moveE,"aG",@progbits,_ZN4cuda3std6ranges3__45__cpo9iter_moveE,comdat
	.type	_ZN4cuda3std6ranges3__45__cpo9iter_moveE, @gnu_unique_object
	.size	_ZN4cuda3std6ranges3__45__cpo9iter_moveE, 1
_ZN4cuda3std6ranges3__45__cpo9iter_moveE:
	.zero	1
	.weak	_ZN4cuda3std6ranges3__45__cpo4swapE
	.section	.rodata._ZN4cuda3std6ranges3__45__cpo4swapE,"aG",@progbits,_ZN4cuda3std6ranges3__45__cpo4swapE,comdat
	.type	_ZN4cuda3std6ranges3__45__cpo4swapE, @gnu_unique_object
	.size	_ZN4cuda3std6ranges3__45__cpo4swapE, 1
_ZN4cuda3std6ranges3__45__cpo4swapE:
	.zero	1
	.section	.rodata.cst16,"aM",@progbits,16
	.align 16
.LC8:
	.long	2147483647
	.long	0
	.long	0
	.long	0
	.section	.rodata.cst4,"aM",@progbits,4
	.align 4
.LC9:
	.long	536870912
	.align 4
.LC10:
	.long	1073741824
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC17:
	.long	0
	.long	1097011920
	.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 <thrust/complex.h>
#include <stdio.h> 
#include <stdlib.h>
#include <png.h>
#include <sys/time.h>

#define M 200

#define DIE(...) { \
  fprintf(stderr, __VA_ARGS__); \
  exit(EXIT_FAILURE); \
}

float points[4];  // c0_real, c0_image, c1_real, c1_image
int w, h;
char cpu_gpu[5];  // do the calculations in cpu or gpu  
int num_threads_arg;
char saida[256];

void application_error(char message[256]) {
  printf ("%s\n", message);
  exit(0);
}

void write_png_file(float *buffer) {
  int i, j;
  png_bytep row = NULL;
  png_structp png_ptr;
  png_infop info_ptr;

  /* Open file for writing (binary mode) */
  FILE *fp = fopen(saida, "wb");
  if (!fp) {
    DIE("write_png_file(): Could not open file ... ");
  }

  /* Initialize write structure */
  png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
  if (!png_ptr) {
    DIE("write_png_file(): png_ptr is NULL ... ");
  }
  
  /* Initialize info structure */
  info_ptr = png_create_info_struct(png_ptr);
  if (!info_ptr) {
    if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    DIE("write_png_file(): info_ptr is NULL ... ");
  }

  /* Exception handling */
  if (setjmp(png_jmpbuf(png_ptr))) {
    if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
    if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
    if (fp != NULL) fclose(fp);
    if (row != NULL) free(row);
    DIE("write_png_file(): libpng error ... ");
  }

  png_init_io(png_ptr, fp);

  png_set_IHDR(png_ptr, info_ptr, w, h,
			8, PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,
			PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

  png_write_info(png_ptr, info_ptr);

  row = (png_bytep) malloc(3 * w * sizeof(png_byte));

  /* write image data */
  for (i = 0; i < h; ++i) {
    for (j = 0; j < w; ++j) {
      row[3 * j] = buffer[i * w + j];
      row[3 * j + 1] = 0;
      row[3 * j + 2] =  0;
    }
    png_write_row(png_ptr, row);
  }

  /* End write */
  png_write_end(png_ptr, NULL);

  if (fp != NULL) fclose(fp);
	if (info_ptr != NULL) png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
	if (png_ptr != NULL) png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
	if (row != NULL) free(row); 
}

float test_complex_number(int k) {
  int j = k / w;
  int i = k % w;

  float dx = (points[2] - points[0]) / w ;
  float dy = (points[3] - points[1]) / h;
  float image = points[1] + dy * i;
  float real = points[0] + dx * j;

  thrust::complex<float> c = thrust::complex<float>(real, image);
  thrust::complex<float> z = thrust::complex<float>(0, 0);
  int it = 0;

  while (it < M && norm(z) < 2.0) {
    z = z * z + c;
    ++it;
  }

  if (it < M) {
    return (255 * it) / M;
  } 
  
  return 0;
}

float *cpu_create_image() {
  float *buffer = (float *) malloc(sizeof(float) * w * h);
  int k;

  if (buffer == NULL) {
    DIE("createImage(): could create buffer ... ");
  }

  #pragma omp parallel for num_threads(num_threads_arg) 
  for (k = 0; k < w * h; ++k)
    buffer[k] = test_complex_number(k);
 
  return buffer;
}

void cpu_solve() {
  float *buffer;
  buffer = cpu_create_image();
  write_png_file(buffer);
  free(buffer);
}

__global__
void gpu_create_image(float *buffer, int w, int h, float *points) {
  const int globalIndex = blockDim.x*blockIdx.x + threadIdx.x;
  
  if (globalIndex < w * h) {
    int j = globalIndex / w;
    int i = globalIndex % w;

    float dx = (points[2] - points[0]) / w ;
    float dy = (points[3] - points[1]) / h;
    float image = points[1] + dy * i;
    float real = points[0] + dx * j;

    thrust::complex<float> c = thrust::complex<float>(real, image);
    thrust::complex<float> z = thrust::complex<float>(0, 0);

    int it = 0;

    while (it < M && norm(z) < 2.0) {
      z = z * z + c;
      ++it;
    }

    if (it < M) buffer[globalIndex] = (255 * it) / M;
    else buffer[globalIndex] = 0;
  } 
}


void gpu_solve() {
  const int THREADS_PER_BLOCK = num_threads_arg;
  const int NUM_BLOCKS = (w * h + THREADS_PER_BLOCK - 1) / THREADS_PER_BLOCK;
  float *buffer_cpu;
  float *buffer_gpu, *points_gpu;
 
  buffer_cpu = (float *) malloc(sizeof(float) * w * h);

  if (buffer_cpu == NULL) {
    DIE("gpu_solve(): buffer_cpu is NULL ...");
  }

  hipMalloc(&buffer_gpu, w * h * sizeof(float));
  hipMalloc(&points_gpu, 4 * sizeof(float));

  hipMemcpy(points_gpu, points, 4 * sizeof(float), hipMemcpyHostToDevice);

  gpu_create_image<<<NUM_BLOCKS, THREADS_PER_BLOCK>>>(buffer_gpu, w, h, points_gpu);
  hipDeviceSynchronize();

  hipMemcpy(buffer_cpu, buffer_gpu, w * h * sizeof(float), hipMemcpyDeviceToHost);

  write_png_file(buffer_cpu);

  hipFree(buffer_gpu);
  hipFree(points);
}

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

  struct timeval start, end;

  // Read Arguments
  if (argc < 9 
  || sscanf(argv[1], "%f", &points[0])        != 1 
  || sscanf(argv[2], "%f", &points[1])        != 1
  || sscanf(argv[3], "%f", &points[2])        != 1 
  || sscanf(argv[4], "%f", &points[3])        != 1 
  || sscanf(argv[5], "%d", &w)                != 1 
  || sscanf(argv[6], "%d", &h)                != 1
  || sscanf(argv[7], "%s", cpu_gpu)           != 1 
  || sscanf(argv[8], "%d", &num_threads_arg)  != 1
  || sscanf(argv[9], "%s", saida)             != 1) {
    DIE("Invalid Arguments ...\n");
  }

  gettimeofday(&start, NULL);
  if (cpu_gpu[0] == 'c') cpu_solve();
  else gpu_solve();
  gettimeofday(&end, NULL);

  double elapsed_time = (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec) / 10000000.0;
  printf("%.4lf\n", elapsed_time);

  return 0;
}
	.text
	.file	"mbrot.hip"
	.globl	_Z17application_errorPc         # -- Begin function _Z17application_errorPc
	.type	_Z17application_errorPc,@function
_Z17application_errorPc:                # @_Z17application_errorPc
	.cfi_startproc
# %bb.0:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	puts@PLT
	xorl	%edi, %edi
	callq	exit
.Lfunc_end0:
	.size	_Z17application_errorPc, .Lfunc_end0-_Z17application_errorPc
	.cfi_endproc
                                        # -- End function
	.globl	_Z14write_png_filePf            # -- Begin function _Z14write_png_filePf
	.type	_Z14write_png_filePf,@function
_Z14write_png_filePf:                   # @_Z14write_png_filePf
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$24, %rsp
	.cfi_def_cfa_offset 80
	.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	%rdi, %rbx
	movl	$saida, %edi
	movl	$.L.str.1, %esi
	callq	fopen
	testq	%rax, %rax
	je	.LBB1_1
# %bb.3:
	movq	%rax, %r14
	movl	$.L.str.3, %edi
	xorl	%eax, %eax
	movl	%eax, %ecx
	movq	%rcx, %rsi
	movq	%rcx, %rdx
	callq	png_create_write_struct
	movq	%rax, (%rsp)
	testq	%rax, %rax
	je	.LBB1_4
# %bb.5:
	movq	%rax, %r12
	movq	%rax, %rdi
	callq	png_create_info_struct
	testq	%rax, %rax
	je	.LBB1_6
# %bb.7:
	movq	%rax, %r15
	movl	$longjmp, %esi
	movl	$200, %edx
	movq	%r12, %rdi
	callq	png_set_longjmp_fn
	movq	%rax, %rdi
	callq	_setjmp
	movq	(%rsp), %rdi
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.11:
	movq	%r14, 16(%rsp)                  # 8-byte Spill
	movq	%r14, %rsi
	callq	png_init_io
	movq	(%rsp), %rdi
	movl	w(%rip), %edx
	movl	h(%rip), %ecx
	subq	$8, %rsp
	.cfi_adjust_cfa_offset 8
	xorl	%ebp, %ebp
	movl	%ebp, %eax
	movq	%r15, %rsi
	movl	$8, %r8d
	movl	$2, %r9d
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	pushq	%rax
	.cfi_adjust_cfa_offset 8
	callq	png_set_IHDR
	addq	$32, %rsp
	.cfi_adjust_cfa_offset -32
	movq	(%rsp), %rdi
	movq	%r15, 8(%rsp)                   # 8-byte Spill
	movq	%r15, %rsi
	callq	png_write_info
	movslq	w(%rip), %rax
	leaq	(%rax,%rax,2), %rdi
	callq	malloc
	movq	%rax, %r13
	movq	%rax, %r12
	cmpl	%ebp, h(%rip)
	jle	.LBB1_17
# %bb.12:                               # %.preheader.preheader
	leaq	2(%r13), %r14
	movl	%ebp, %r15d
.LBB1_13:                               # %.preheader
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB1_15 Depth 2
	movl	w(%rip), %eax
                                        # kill: def $rax killed $eax
	movl	%eax, %ecx
	testl	%eax, %eax
	jle	.LBB1_16
# %bb.14:                               # %.lr.ph
                                        #   in Loop: Header=BB1_13 Depth=1
	movl	%eax, %ecx
	imull	%r15d, %ecx
                                        # kill: def $rcx killed $ecx
	leaq	(%rbx,%rcx,4), %rcx
	movl	%ebp, %esi
	movq	%r14, %rdx
.LBB1_15:                               #   Parent Loop BB1_13 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	cvttss2si	(%rcx,%rsi,4), %edi
                                        # kill: def $dil killed $dil killed $edi
	movb	%dil, -2(%rdx)
	movw	$0, -1(%rdx)
	movq	%rsi, %rdi
	incq	%rdi
	addq	$3, %rdx
	movq	%rdi, %rsi
	cmpq	%rdi, %rax
	jne	.LBB1_15
.LBB1_16:                               # %._crit_edge
                                        #   in Loop: Header=BB1_13 Depth=1
	movq	(%rsp), %rdi
	movq	%r12, %rsi
	callq	png_write_row
	movl	%r15d, %eax
	incl	%eax
	movl	%eax, %r15d
	cmpl	h(%rip), %eax
	jl	.LBB1_13
.LBB1_17:                               # %._crit_edge45
	movq	(%rsp), %rdi
	xorl	%eax, %eax
	movl	%eax, %esi
	callq	png_write_end
	movq	16(%rsp), %rdi                  # 8-byte Reload
	callq	fclose
	movq	(%rsp), %rdi
	movq	8(%rsp), %rsi                   # 8-byte Reload
	movl	$65535, %edx                    # imm = 0xFFFF
	movl	$-1, %ecx
	callq	png_free_data
	cmpq	$0, (%rsp)
	je	.LBB1_19
# %bb.18:
	xorl	%eax, %eax
	movl	%eax, %esi
	movq	%rsp, %rdi
	callq	png_destroy_write_struct
.LBB1_19:
	testq	%r13, %r13
	je	.LBB1_21
# %bb.20:
	movq	%r12, %rdi
	callq	free
.LBB1_21:
	addq	$24, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB1_1:
	.cfi_def_cfa_offset 80
	movq	stderr(%rip), %rcx
	movl	$.L.str.2, %edi
	movl	$42, %esi
	jmp	.LBB1_2
.LBB1_4:
	movq	stderr(%rip), %rcx
	movl	$.L.str.4, %edi
	movl	$38, %esi
	jmp	.LBB1_2
.LBB1_6:
	xorl	%eax, %eax
	movl	%eax, %esi
	movq	%rsp, %rdi
	callq	png_destroy_write_struct
	movq	stderr(%rip), %rcx
	movl	$.L.str.5, %edi
	movl	$39, %esi
	jmp	.LBB1_2
.LBB1_8:
	movq	%r15, %rsi
	movl	$65535, %edx                    # imm = 0xFFFF
	movl	$-1, %ecx
	callq	png_free_data
	cmpq	$0, (%rsp)
	je	.LBB1_10
# %bb.9:
	xorl	%eax, %eax
	movl	%eax, %esi
	movq	%rsp, %rdi
	callq	png_destroy_write_struct
.LBB1_10:
	movq	%r14, %rdi
	callq	fclose
	movq	stderr(%rip), %rcx
	movl	$.L.str.6, %edi
	movl	$35, %esi
.LBB1_2:
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end1:
	.size	_Z14write_png_filePf, .Lfunc_end1-_Z14write_png_filePf
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst16,"aM",@progbits,16
	.p2align	4, 0x0                          # -- Begin function _Z19test_complex_numberi
.LCPI2_0:
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.long	0x7fffffff                      # float NaN
	.section	.rodata.cst4,"aM",@progbits,4
	.p2align	2, 0x0
.LCPI2_1:
	.long	0x20000000                      # float 1.08420217E-19
.LCPI2_2:
	.long	0x40800000                      # float 4
.LCPI2_3:
	.long	0x3d800000                      # float 0.0625
.LCPI2_4:
	.long	0x40000000                      # float 2
	.text
	.globl	_Z19test_complex_numberi
	.type	_Z19test_complex_numberi,@function
_Z19test_complex_numberi:               # @_Z19test_complex_numberi
	.cfi_startproc
# %bb.0:
	movl	%edi, %eax
	movl	w(%rip), %ecx
	cltd
	idivl	%ecx
	movss	points+8(%rip), %xmm2           # xmm2 = mem[0],zero,zero,zero
	movss	points(%rip), %xmm3             # xmm3 = mem[0],zero,zero,zero
	cvtsi2ss	%ecx, %xmm0
	subss	%xmm3, %xmm2
	divss	%xmm0, %xmm2
	movss	points+12(%rip), %xmm1          # xmm1 = mem[0],zero,zero,zero
	movss	points+4(%rip), %xmm4           # xmm4 = mem[0],zero,zero,zero
	subss	%xmm4, %xmm1
	cvtsi2ssl	h(%rip), %xmm5
	xorps	%xmm0, %xmm0
	cvtsi2ss	%edx, %xmm0
	divss	%xmm5, %xmm1
	mulss	%xmm1, %xmm0
	addss	%xmm4, %xmm0
	xorps	%xmm1, %xmm1
	cvtsi2ss	%eax, %xmm1
	mulss	%xmm2, %xmm1
	addss	%xmm3, %xmm1
	xorps	%xmm6, %xmm6
	xorl	%eax, %eax
	movaps	.LCPI2_0(%rip), %xmm2           # xmm2 = [NaN,NaN,NaN,NaN]
	movss	.LCPI2_1(%rip), %xmm3           # xmm3 = mem[0],zero,zero,zero
	movss	.LCPI2_2(%rip), %xmm4           # xmm4 = mem[0],zero,zero,zero
	movss	.LCPI2_3(%rip), %xmm5           # xmm5 = mem[0],zero,zero,zero
	movss	.LCPI2_4(%rip), %xmm7           # xmm7 = mem[0],zero,zero,zero
.LBB2_1:                                # =>This Inner Loop Header: Depth=1
	movaps	%xmm6, %xmm8
	andps	%xmm2, %xmm8
	ucomiss	%xmm8, %xmm3
	movaps	%xmm6, %xmm8
	shufps	$85, %xmm6, %xmm8               # xmm8 = xmm8[1,1],xmm6[1,1]
	jbe	.LBB2_4
# %bb.2:                                #   in Loop: Header=BB2_1 Depth=1
	movaps	%xmm8, %xmm9
	andps	%xmm2, %xmm9
	ucomiss	%xmm9, %xmm3
	jbe	.LBB2_4
# %bb.3:                                #   in Loop: Header=BB2_1 Depth=1
	movaps	%xmm6, %xmm10
	mulss	%xmm4, %xmm10
	movaps	%xmm8, %xmm9
	mulss	%xmm4, %xmm9
	mulss	%xmm10, %xmm10
	mulss	%xmm9, %xmm9
	addss	%xmm10, %xmm9
	mulss	%xmm5, %xmm9
	jmp	.LBB2_5
.LBB2_4:                                # %._crit_edge.i
                                        #   in Loop: Header=BB2_1 Depth=1
	movaps	%xmm6, %xmm10
	mulss	%xmm6, %xmm10
	movaps	%xmm8, %xmm9
	mulss	%xmm8, %xmm9
	addss	%xmm10, %xmm9
.LBB2_5:                                # %_ZN6thrust4normIfEET_RKNS_7complexIS1_EE.exit
                                        #   in Loop: Header=BB2_1 Depth=1
	ucomiss	%xmm9, %xmm7
	jbe	.LBB2_8
# %bb.6:                                #   in Loop: Header=BB2_1 Depth=1
	movaps	%xmm6, %xmm9
	mulss	%xmm6, %xmm9
	mulss	%xmm8, %xmm6
	mulss	%xmm8, %xmm8
	subss	%xmm8, %xmm9
	addss	%xmm6, %xmm6
	addss	%xmm1, %xmm9
	addss	%xmm0, %xmm6
	unpcklps	%xmm6, %xmm9                    # xmm9 = xmm9[0],xmm6[0],xmm9[1],xmm6[1]
	addl	$255, %eax
	movaps	%xmm9, %xmm6
	cmpl	$51000, %eax                    # imm = 0xC738
	jne	.LBB2_1
# %bb.7:
	xorps	%xmm0, %xmm0
	retq
.LBB2_8:                                # %.critedge
	movzwl	%ax, %eax
	shrl	$3, %eax
	imull	$5243, %eax, %eax               # imm = 0x147B
	shrl	$17, %eax
	xorps	%xmm0, %xmm0
	cvtsi2ss	%eax, %xmm0
	retq
.Lfunc_end2:
	.size	_Z19test_complex_numberi, .Lfunc_end2-_Z19test_complex_numberi
	.cfi_endproc
                                        # -- End function
	.globl	_Z16cpu_create_imagev           # -- Begin function _Z16cpu_create_imagev
	.type	_Z16cpu_create_imagev,@function
_Z16cpu_create_imagev:                  # @_Z16cpu_create_imagev
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%rbx
	.cfi_def_cfa_offset 32
	.cfi_offset %rbx, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movslq	w(%rip), %r15
	movslq	h(%rip), %r14
	movq	%r15, %rdi
	imulq	%r14, %rdi
	shlq	$2, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB3_5
# %bb.1:                                # %.preheader
	movq	%rax, %rbx
	imull	%r15d, %r14d
	testl	%r14d, %r14d
	jle	.LBB3_4
# %bb.2:                                # %.lr.ph.preheader
	movl	%r14d, %r15d
	xorl	%r14d, %r14d
.LBB3_3:                                # %.lr.ph
                                        # =>This Inner Loop Header: Depth=1
	movl	%r14d, %edi
	callq	_Z19test_complex_numberi
	movss	%xmm0, (%rbx,%r14,4)
	incq	%r14
	cmpq	%r14, %r15
	jne	.LBB3_3
.LBB3_4:                                # %._crit_edge
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.LBB3_5:
	.cfi_def_cfa_offset 32
	movq	stderr(%rip), %rcx
	movl	$.L.str.7, %edi
	movl	$39, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end3:
	.size	_Z16cpu_create_imagev, .Lfunc_end3-_Z16cpu_create_imagev
	.cfi_endproc
                                        # -- End function
	.globl	_Z9cpu_solvev                   # -- Begin function _Z9cpu_solvev
	.type	_Z9cpu_solvev,@function
_Z9cpu_solvev:                          # @_Z9cpu_solvev
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset %rbx, -16
	callq	_Z16cpu_create_imagev
	movq	%rax, %rbx
	movq	%rax, %rdi
	callq	_Z14write_png_filePf
	movq	%rbx, %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	free                            # TAILCALL
.Lfunc_end4:
	.size	_Z9cpu_solvev, .Lfunc_end4-_Z9cpu_solvev
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__gpu_create_imagePfiiS_ # -- Begin function _Z31__device_stub__gpu_create_imagePfiiS_
	.type	_Z31__device_stub__gpu_create_imagePfiiS_,@function
_Z31__device_stub__gpu_create_imagePfiiS_: # @_Z31__device_stub__gpu_create_imagePfiiS_
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$112, %rsp
	.cfi_def_cfa_offset 160
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	12(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	8(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	32(%rsp), %rdx
	movq	%rcx, (%rdx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z16gpu_create_imagePfiiS_, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$128, %rsp
	.cfi_adjust_cfa_offset -128
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end5:
	.size	_Z31__device_stub__gpu_create_imagePfiiS_, .Lfunc_end5-_Z31__device_stub__gpu_create_imagePfiiS_
	.cfi_endproc
                                        # -- End function
	.globl	_Z9gpu_solvev                   # -- Begin function _Z9gpu_solvev
	.type	_Z9gpu_solvev,@function
_Z9gpu_solvev:                          # @_Z9gpu_solvev
	.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
	subq	$24, %rsp
	.cfi_def_cfa_offset 64
	.cfi_offset %rbx, -40
	.cfi_offset %r12, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	movl	num_threads_arg(%rip), %r14d
	movslq	w(%rip), %rax
	movslq	h(%rip), %r15
	imulq	%rax, %r15
	leaq	(,%r15,4), %r12
	movq	%r12, %rdi
	callq	malloc
	testq	%rax, %rax
	je	.LBB6_4
# %bb.1:
	movq	%rax, %rbx
	leal	(%r14,%r15), %eax
	decl	%eax
	cltd
	idivl	%r14d
	movl	%eax, %r15d
	leaq	8(%rsp), %rdi
	movq	%r12, %rsi
	callq	hipMalloc
	leaq	16(%rsp), %r12
	movl	$16, %esi
	movq	%r12, %rdi
	callq	hipMalloc
	movq	(%r12), %rdi
	movl	$points, %esi
	movl	$16, %edx
	movl	$1, %ecx
	callq	hipMemcpy
	btsq	$32, %r15
	btsq	$32, %r14
	movq	%r15, %rdi
	movl	$1, %esi
	movq	%r14, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB6_3
# %bb.2:
	movq	8(%rsp), %rdi
	movl	w(%rip), %esi
	movl	h(%rip), %edx
	movq	16(%rsp), %rcx
	callq	_Z31__device_stub__gpu_create_imagePfiiS_
.LBB6_3:
	callq	hipDeviceSynchronize
	movq	8(%rsp), %rsi
	movslq	w(%rip), %rax
	movslq	h(%rip), %rdx
	imulq	%rax, %rdx
	shlq	$2, %rdx
	movq	%rbx, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	%rbx, %rdi
	callq	_Z14write_png_filePf
	movq	8(%rsp), %rdi
	callq	hipFree
	movl	$points, %edi
	callq	hipFree
	addq	$24, %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
.LBB6_4:
	.cfi_def_cfa_offset 64
	movq	stderr(%rip), %rcx
	movl	$.L.str.8, %edi
	movl	$35, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end6:
	.size	_Z9gpu_solvev, .Lfunc_end6-_Z9gpu_solvev
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI7_0:
	.quad	0x416312d000000000              # double 1.0E+7
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	cmpl	$9, %edi
	jl	.LBB7_14
# %bb.1:
	movq	%rsi, %rbx
	movq	8(%rsi), %rdi
	movl	$.L.str.9, %esi
	movl	$points, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.2:
	movq	16(%rbx), %rdi
	movl	$.L.str.9, %esi
	movl	$points+4, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.3:
	movq	24(%rbx), %rdi
	movl	$.L.str.9, %esi
	movl	$points+8, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.4:
	movq	32(%rbx), %rdi
	movl	$.L.str.9, %esi
	movl	$points+12, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.5:
	movq	40(%rbx), %rdi
	movl	$.L.str.10, %esi
	movl	$w, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.6:
	movq	48(%rbx), %rdi
	movl	$.L.str.10, %esi
	movl	$h, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.7:
	movq	56(%rbx), %rdi
	movl	$.L.str.11, %esi
	movl	$cpu_gpu, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.8:
	movq	64(%rbx), %rdi
	movl	$.L.str.10, %esi
	movl	$num_threads_arg, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.9:
	movq	72(%rbx), %rdi
	movl	$.L.str.11, %esi
	movl	$saida, %edx
	xorl	%eax, %eax
	callq	__isoc23_sscanf
	cmpl	$1, %eax
	jne	.LBB7_14
# %bb.10:
	movq	%rsp, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	cmpb	$99, cpu_gpu(%rip)
	jne	.LBB7_12
# %bb.11:
	callq	_Z16cpu_create_imagev
	movq	%rax, %rbx
	movq	%rax, %rdi
	callq	_Z14write_png_filePf
	movq	%rbx, %rdi
	callq	free
	jmp	.LBB7_13
.LBB7_12:
	callq	_Z9gpu_solvev
.LBB7_13:
	leaq	16(%rsp), %rbx
	movq	%rbx, %rdi
	xorl	%esi, %esi
	callq	gettimeofday
	movq	(%rbx), %rax
	movq	8(%rbx), %rcx
	subq	(%rsp), %rax
	cvtsi2sd	%rax, %xmm1
	subq	8(%rsp), %rcx
	cvtsi2sd	%rcx, %xmm0
	divsd	.LCPI7_0(%rip), %xmm0
	addsd	%xmm1, %xmm0
	movl	$.L.str.13, %edi
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB7_14:
	.cfi_def_cfa_offset 48
	movq	stderr(%rip), %rcx
	movl	$.L.str.12, %edi
	movl	$22, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$1, %edi
	callq	exit
.Lfunc_end7:
	.size	main, .Lfunc_end7-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	subq	$40, %rsp
	.cfi_def_cfa_offset 48
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	jne	.LBB8_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB8_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16gpu_create_imagePfiiS_, %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_end8:
	.size	__hip_module_ctor, .Lfunc_end8-__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	.LBB9_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
.LBB9_2:
	retq
.Lfunc_end9:
	.size	__hip_module_dtor, .Lfunc_end9-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	points,@object                  # @points
	.bss
	.globl	points
	.p2align	4, 0x0
points:
	.zero	16
	.size	points, 16

	.type	w,@object                       # @w
	.globl	w
	.p2align	2, 0x0
w:
	.long	0                               # 0x0
	.size	w, 4

	.type	h,@object                       # @h
	.globl	h
	.p2align	2, 0x0
h:
	.long	0                               # 0x0
	.size	h, 4

	.type	cpu_gpu,@object                 # @cpu_gpu
	.globl	cpu_gpu
cpu_gpu:
	.zero	5
	.size	cpu_gpu, 5

	.type	num_threads_arg,@object         # @num_threads_arg
	.globl	num_threads_arg
	.p2align	2, 0x0
num_threads_arg:
	.long	0                               # 0x0
	.size	num_threads_arg, 4

	.type	saida,@object                   # @saida
	.globl	saida
	.p2align	4, 0x0
saida:
	.zero	256
	.size	saida, 256

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

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"write_png_file(): Could not open file ... "
	.size	.L.str.2, 43

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

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"write_png_file(): png_ptr is NULL ... "
	.size	.L.str.4, 39

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"write_png_file(): info_ptr is NULL ... "
	.size	.L.str.5, 40

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"write_png_file(): libpng error ... "
	.size	.L.str.6, 36

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"createImage(): could create buffer ... "
	.size	.L.str.7, 40

	.type	_Z16gpu_create_imagePfiiS_,@object # @_Z16gpu_create_imagePfiiS_
	.section	.rodata,"a",@progbits
	.globl	_Z16gpu_create_imagePfiiS_
	.p2align	3, 0x0
_Z16gpu_create_imagePfiiS_:
	.quad	_Z31__device_stub__gpu_create_imagePfiiS_
	.size	_Z16gpu_create_imagePfiiS_, 8

	.type	.L.str.8,@object                # @.str.8
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.8:
	.asciz	"gpu_solve(): buffer_cpu is NULL ..."
	.size	.L.str.8, 36

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

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

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

	.type	.L.str.12,@object               # @.str.12
.L.str.12:
	.asciz	"Invalid Arguments ...\n"
	.size	.L.str.12, 23

	.type	.L.str.13,@object               # @.str.13
.L.str.13:
	.asciz	"%.4lf\n"
	.size	.L.str.13, 7

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16gpu_create_imagePfiiS_"
	.size	.L__unnamed_1, 27

	.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 longjmp
	.addrsig_sym _Z31__device_stub__gpu_create_imagePfiiS_
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym points
	.addrsig_sym w
	.addrsig_sym h
	.addrsig_sym cpu_gpu
	.addrsig_sym num_threads_arg
	.addrsig_sym saida
	.addrsig_sym _Z16gpu_create_imagePfiiS_
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16gpu_create_imagePfiiS_ ; -- Begin function _Z16gpu_create_imagePfiiS_
	.globl	_Z16gpu_create_imagePfiiS_
	.p2align	8
	.type	_Z16gpu_create_imagePfiiS_,@function
_Z16gpu_create_imagePfiiS_:             ; @_Z16gpu_create_imagePfiiS_
; %bb.0:
	s_clause 0x1
	s_load_b32 s2, s[0:1], 0x24
	s_load_b64 s[8:9], s[0:1], 0x8
	s_waitcnt lgkmcnt(0)
	s_and_b32 s2, s2, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1)
	v_mad_u64_u32 v[1:2], null, s15, s2, v[0:1]
	s_mul_i32 s2, s9, s8
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	v_cmp_gt_i32_e32 vcc_lo, s2, v1
	s_and_saveexec_b32 s2, vcc_lo
	s_cbranch_execz .LBB0_12
; %bb.1:
	s_ashr_i32 s10, s8, 31
	v_cvt_f32_i32_e32 v5, s9
	s_add_i32 s2, s8, s10
	v_ashrrev_i32_e32 v2, 31, v1
	s_xor_b32 s11, s2, s10
	s_load_b64 s[2:3], s[0:1], 0x10
	v_cvt_f32_u32_e32 v0, s11
	s_sub_i32 s12, 0, s11
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_4) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v0, v0
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v0
	s_waitcnt lgkmcnt(0)
	s_load_b128 s[4:7], s[2:3], 0x0
	v_cvt_u32_f32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_lo_u32 v3, s12, v0
	v_mul_hi_u32 v3, v0, v3
	s_waitcnt lgkmcnt(0)
	v_sub_f32_e64 v7, s7, s5
	v_sub_f32_e64 v6, s6, s4
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_div_scale_f32 v9, null, v5, v5, v7
	v_div_scale_f32 v16, s3, v7, v5, v7
	v_rcp_f32_e32 v12, v9
	s_waitcnt_depctr 0xfff
	v_fma_f32 v15, -v9, v12, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fmac_f32_e32 v12, v15, v12
	v_mul_f32_e32 v17, v16, v12
	v_add_nc_u32_e32 v0, v0, v3
	v_cvt_f32_i32_e32 v3, s8
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_div_scale_f32 v8, null, v3, v3, v6
	v_rcp_f32_e32 v11, v8
	s_waitcnt_depctr 0xfff
	v_fma_f32 v14, -v8, v11, 1.0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_dual_fmac_f32 v11, v14, v11 :: v_dual_add_nc_u32 v4, v1, v2
	v_xor_b32_e32 v14, s10, v2
	v_xor_b32_e32 v4, v4, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v0, v4, v0
	v_mul_lo_u32 v10, v0, s11
	v_add_nc_u32_e32 v13, 1, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_sub_nc_u32_e32 v4, v4, v10
	v_div_scale_f32 v10, vcc_lo, v6, v3, v6
	v_cmp_le_u32_e64 s2, s11, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v15, v10, v11
	v_cndmask_b32_e64 v0, v0, v13, s2
	v_subrev_nc_u32_e32 v13, s11, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_cndmask_b32_e64 v4, v4, v13, s2
	v_add_nc_u32_e32 v13, 1, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cmp_le_u32_e64 s2, s11, v4
	v_fma_f32 v4, -v8, v15, v10
	v_cndmask_b32_e64 v0, v0, v13, s2
	v_fma_f32 v13, -v9, v17, v16
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v15, v4, v11
	s_mov_b32 s2, 0
	v_xor_b32_e32 v0, v0, v14
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_fmac_f32_e32 v17, v13, v12
	v_fma_f32 v4, -v8, v15, v10
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_sub_nc_u32_e32 v0, v0, v14
	v_fma_f32 v8, -v9, v17, v16
	s_delay_alu instid0(VALU_DEP_3) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v4, v4, v11, v15
	s_mov_b32 vcc_lo, s3
                                        ; implicit-def: $sgpr3
	v_mul_lo_u32 v9, v0, s8
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_div_fmas_f32 v8, v8, v12, v17
	v_div_fixup_f32 v3, v4, v3, v6
	v_mov_b32_e32 v4, 0
	v_cvt_f32_i32_e32 v0, v0
	s_delay_alu instid0(VALU_DEP_4) | instskip(SKIP_1) | instid1(VALU_DEP_3)
	v_div_fixup_f32 v5, v8, v5, v7
	v_sub_nc_u32_e32 v9, v1, v9
	v_fma_f32 v0, v3, v0, s4
                                        ; implicit-def: $sgpr4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cvt_f32_i32_e32 v6, v9
	v_fma_f32 v3, v5, v6, s5
	v_mov_b32_e32 v5, 0
	s_mov_b32 s5, 0
.LBB0_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_2) | instid1(VALU_DEP_2)
	v_cmp_ngt_f32_e64 s6, 0x20000000, |v5|
	v_cmp_ngt_f32_e64 s7, 0x20000000, |v4|
	v_mul_f32_e32 v6, v4, v4
                                        ; implicit-def: $vgpr7
	s_or_b32 s6, s6, s7
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_and_saveexec_b32 s7, s6
	s_xor_b32 s6, exec_lo, s7
; %bb.3:                                ; %._crit_edge.i
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_fma_f32 v7, v5, v5, v6
; %bb.4:                                ; %Flow
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_and_not1_saveexec_b32 s6, s6
; %bb.5:                                ;   in Loop: Header=BB0_2 Depth=1
	v_dual_mul_f32 v7, 4.0, v4 :: v_dual_mul_f32 v8, 4.0, v5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_f32_e32 v7, v7, v7
	v_fmac_f32_e32 v7, v8, v8
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f32_e32 v7, 0x3d800000, v7
; %bb.6:                                ; %_ZN6thrust4normIfEET_RKNS_7complexIS1_EE.exit
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s6
	s_mov_b32 s7, -1
	s_or_b32 s4, s4, exec_lo
	s_mov_b32 s8, exec_lo
                                        ; implicit-def: $sgpr6
                                        ; implicit-def: $sgpr9
	v_cmpx_gt_f32_e32 2.0, v7
; %bb.7:                                ;   in Loop: Header=BB0_2 Depth=1
	v_fma_f32 v6, v5, v5, -v6
	v_mul_f32_e32 v4, v5, v4
	s_add_i32 s6, s5, 1
	s_mov_b32 s9, 0
	s_cmpk_eq_i32 s6, 0xc8
	v_add_f32_e32 v5, v0, v6
	v_fma_f32 v4, 2.0, v4, v3
	s_cselect_b32 s7, -1, 0
	s_and_not1_b32 s4, s4, exec_lo
	s_or_not1_b32 s7, s7, exec_lo
; %bb.8:                                ; %Flow67
                                        ;   in Loop: Header=BB0_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s8
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(SKIP_4) | instid1(SALU_CYCLE_1)
	s_and_b32 s7, exec_lo, s7
	v_dual_mov_b32 v6, s9 :: v_dual_mov_b32 v7, s5
	s_or_b32 s2, s7, s2
	s_and_not1_b32 s3, s3, exec_lo
	s_and_b32 s5, s4, exec_lo
	s_or_b32 s3, s3, s5
	s_mov_b32 s5, s6
	s_and_not1_b32 exec_lo, exec_lo, s2
	s_cbranch_execnz .LBB0_2
; %bb.9:                                ; %loop.exit.guard
	s_or_b32 exec_lo, exec_lo, s2
	s_and_saveexec_b32 s2, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_xor_b32 s2, exec_lo, s2
; %bb.10:                               ; %.critedge
	v_mul_lo_u16 v0, 0xff, v7
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshrrev_b16 v0, 3, v0
	v_and_b32_e32 v0, 0xffff, v0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_u32_u24_e32 v0, 0x147b, v0
	v_lshrrev_b32_e32 v0, 17, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_cvt_f32_u32_e32 v6, v0
; %bb.11:                               ; %.sink.split
	s_or_b32 exec_lo, exec_lo, s2
	s_load_b64 s[0:1], s[0:1], 0x0
	v_lshlrev_b64 v[0:1], 2, v[1:2]
	s_waitcnt lgkmcnt(0)
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_add_co_u32 v0, vcc_lo, s0, v0
	v_add_co_ci_u32_e32 v1, vcc_lo, s1, v1, vcc_lo
	global_store_b32 v[0:1], v6, off
.LBB0_12:
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16gpu_create_imagePfiiS_
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 280
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 18
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z16gpu_create_imagePfiiS_, .Lfunc_end0-_Z16gpu_create_imagePfiiS_
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 892
; NumSgprs: 18
; NumVgprs: 18
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 2
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 18
; 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
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         16
        .size:           8
        .value_kind:     global_buffer
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         28
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         36
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         38
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         40
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         42
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         44
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         46
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         88
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 280
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16gpu_create_imagePfiiS_
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z16gpu_create_imagePfiiS_.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     18
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
