/********************************************************************************
 * Trabalho 2: Programação Paralela para Processador Many-core (GPU) Usando CUDA
 * Professora: Nahri Moreano
 * Aluno: Ian Haranaka | RGA: 2018.1904.009-7
 * Comando de compilação: nvcc dist_par.cu -o dist_par
 ********************************************************************************/

#include <iostream>
#include <fstream>
#include <iomanip>

const int MAX_THREADS = 1024;

char *AlocaSequencia(int n);
__global__ void InicializaMatriz(int n, int m, int *D);
__global__ void CalculaDistanciaEdicao(int num_linhas, int num_colunas,
                                      int antidiag_bloco, int n, int m,
                                      char *S, char *R, int *D);

int main(int argc, char *argv[])
{
  std::ifstream entrada (argv[1]);
  int n, m, resultado = 0;
  char *h_S, *h_R;

  // Leitura do arquivo de entrada
  if (entrada.is_open())
  {
    entrada >> n >> m;

    h_S = AlocaSequencia(n);
    h_R = AlocaSequencia(m);
    entrada >> &(h_S[1]) >> &(h_R[1]);

    entrada.close();
  }
  else
  {
    std::cout << "Arquivo não encontrado!" << std::endl;
    return -1;
  }

  int tam_vetor = (n+1) * (m+1);
  // Número de blocos por linha e por coluna
  int num_blocos_n = (n + MAX_THREADS - 1) / MAX_THREADS;
  int num_blocos_m = (m + MAX_THREADS - 1) / MAX_THREADS;

  // Aloca a matriz e as strings na GPU
  int *d_D;
  char *d_S, *d_R;
  cudaMalloc((void **)&d_D, tam_vetor * sizeof(int));
  cudaMalloc(&d_S, (n+2) * sizeof(char));
  cudaMalloc(&d_R, (m+2) * sizeof(char));

  // Inicio da medição de tempo
  cudaEvent_t d_ini, d_fim;
  cudaEventCreate(&d_ini);
  cudaEventCreate(&d_fim);
  cudaEventRecord(d_ini, 0);

  // Copia as strings para a memória global da GPU
  cudaMemcpy(d_S, h_S, (n+2) * sizeof(char), cudaMemcpyHostToDevice);
  cudaMemcpy(d_R, h_R, (m+2) * sizeof(char), cudaMemcpyHostToDevice);

  InicializaMatriz<<<1, 1>>>(n, m, d_D);
  cudaDeviceSynchronize();

  int threads_por_bloco = (n < MAX_THREADS ? n : MAX_THREADS);
  int num_antidiag = num_blocos_n + num_blocos_m - 1;
  int num_linhas = threads_por_bloco;
  int num_colunas = (m < 1024 ? m : 1024);

  // Para cada antidiagonal por bloco
  for (int antidiag = 0; antidiag < num_antidiag; ++antidiag)
  {
    CalculaDistanciaEdicao<<<num_blocos_n, threads_por_bloco>>>
    (num_linhas, num_colunas, antidiag, n, m, d_S, d_R, d_D);

    cudaDeviceSynchronize();
  }

  cudaMemcpy(&resultado, &d_D[tam_vetor - 1], sizeof(int), cudaMemcpyDeviceToHost);

  // Fim da medição de tempo
  cudaEventRecord(d_fim, 0);
  cudaEventSynchronize(d_fim);
  float d_tempo;
  cudaEventElapsedTime(&d_tempo, d_ini, d_fim);
  cudaEventDestroy(d_ini);
  cudaEventDestroy(d_fim);

  std::cout << std::fixed << std::setprecision(2);
  std::cout << "Tempo de execução: " << d_tempo << " ms" << std::endl;
  std::cout << "Distância de edição: " << resultado << std::endl;

  // Libera a matriz e as strings
  delete[] h_S;
  delete[] h_R;
  cudaFree(d_D);
  cudaFree(d_S);
  cudaFree(d_R);

  return 0;
}

char *AlocaSequencia(int n)
{
  char *seq = new (std::nothrow) char[n+2];

  if (seq == nullptr)
    std::cout << "Erro na alocação de memória!" << std::endl;

  seq[0] = ' ';
  return seq;
}

__global__ void InicializaMatriz(int n, int m, int *D)
{
  for (int i = 0, j = 0; i < (n+1) * (m+1); i += m+1, ++j)
    D[i] = j;
  for (int j = 0; j <= m; ++j)
    D[j] = j;
}

__global__ void CalculaDistanciaEdicao(int num_linhas, int num_colunas,
                                      int antidiag_bloco, int n, int m,
                                      char *S, char *R, int *D)
{
  // A quantidade de colunas que se deve pular para chegar até as células do bloco
  int deslocamento_col = (antidiag_bloco * num_colunas) - (blockIdx.x * num_colunas);
  int num_antidiag = num_linhas + num_colunas - 1;
  int i = (blockIdx.x * num_linhas) + threadIdx.x + 1, j;
  int a, b, c, t, min;

  // Se o bloco é válido - Isto implica em dizer se o bloco contém parte da matriz
  if (deslocamento_col >= 0 && deslocamento_col < m)
  {
    for (int antidiag = 2; antidiag <= num_antidiag + 1; antidiag++)
    {
      j = deslocamento_col + antidiag - (threadIdx.x + 1);
      // Se é uma célula válida
      if (i <= n && j > deslocamento_col && j <= deslocamento_col + num_colunas)
      {
        t = (S[i] != R[j] ? 1 : 0);
        a = D[i*(m+1)+j-1] + 1;
        b = D[(i-1)*(m+1)+j] + 1;
        c = D[(i-1)*(m+1)+j-1] + t;

        min = (a < b ? a : b);
        min = (c < min ? c : min);
        D[i*(m+1)+j] = min;
      }
      __syncthreads();
    }
  }
}

	.file	"tmpxft_003aaf9b_00000000-6_dist_par.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.section	.text._ZSt5fixedRSt8ios_base,"axG",@progbits,_ZSt5fixedRSt8ios_base,comdat
	.weak	_ZSt5fixedRSt8ios_base
	.type	_ZSt5fixedRSt8ios_base, @function
_ZSt5fixedRSt8ios_base:
.LFB3285:
	.cfi_startproc
	endbr64
	movl	24(%rdi), %edx
	movq	%rdi, %rax
	andl	$-261, %edx
	orl	$4, %edx
	movl	%edx, 24(%rdi)
	ret
	.cfi_endproc
.LFE3285:
	.size	_ZSt5fixedRSt8ios_base, .-_ZSt5fixedRSt8ios_base
	.text
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB4009:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE4009:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"Erro na aloca\303\247\303\243o de mem\303\263ria!"
	.text
	.globl	_Z14AlocaSequenciai
	.type	_Z14AlocaSequenciai, @function
_Z14AlocaSequenciai:
.LFB4006:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	addl	$2, %edi
	leaq	_ZSt7nothrow(%rip), %rsi
	movslq	%edi, %rdi
	call	_ZnamRKSt9nothrow_t@PLT
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.L4
	leaq	_ZSt4cout(%rip), %rdi
	leaq	.LC0(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
.L4:
	movq	%rbx, %rax
	movb	$32, (%rbx)
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4006:
	.size	_Z14AlocaSequenciai, .-_Z14AlocaSequenciai
	.globl	_Z38__device_stub__Z16InicializaMatriziiPiiiPi
	.type	_Z38__device_stub__Z16InicializaMatriziiPiiiPi, @function
_Z38__device_stub__Z16InicializaMatriziiPiiiPi:
.LFB4031:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movl	%edi, 12(%rsp)
	leaq	24(%rsp), %rcx
	leaq	32(%rsp), %rdi
	movl	%esi, 8(%rsp)
	leaq	44(%rsp), %rsi
	movq	%rdx, (%rsp)
	leaq	16(%rsp), %rdx
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	12(%rsp), %rax
	movl	$1, 40(%rsp)
	movq	%rax, 80(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 32(%rsp)
	movq	%rax, 44(%rsp)
	movl	$1, 52(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L7
	pushq	24(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z16InicializaMatriziiPi(%rip), %rdi
	pushq	24(%rsp)
	.cfi_def_cfa_offset 144
	movq	60(%rsp), %rcx
	movl	68(%rsp), %r8d
	movq	48(%rsp), %rsi
	movl	56(%rsp), %edx
	leaq	96(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L7:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L9
	call	__stack_chk_fail@PLT
.L9:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4031:
	.size	_Z38__device_stub__Z16InicializaMatriziiPiiiPi, .-_Z38__device_stub__Z16InicializaMatriziiPiiiPi
	.globl	_Z16InicializaMatriziiPi
	.type	_Z16InicializaMatriziiPi, @function
_Z16InicializaMatriziiPi:
.LFB4032:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z16InicializaMatriziiPiiiPi
	.cfi_endproc
.LFE4032:
	.size	_Z16InicializaMatriziiPi, .-_Z16InicializaMatriziiPi
	.globl	_Z51__device_stub__Z22CalculaDistanciaEdicaoiiiiiPcS_PiiiiiiPcS_Pi
	.type	_Z51__device_stub__Z22CalculaDistanciaEdicaoiiiiiPcS_PiiiiiiPcS_Pi, @function
_Z51__device_stub__Z22CalculaDistanciaEdicaoiiiiiPcS_PiiiiiiPcS_Pi:
.LFB4033:
	.cfi_startproc
	endbr64
	subq	$200, %rsp
	.cfi_def_cfa_offset 208
	movq	208(%rsp), %rax
	movl	%edi, 44(%rsp)
	leaq	72(%rsp), %rdi
	movl	%esi, 40(%rsp)
	leaq	84(%rsp), %rsi
	movq	%rax, 8(%rsp)
	movq	216(%rsp), %rax
	movl	%edx, 36(%rsp)
	leaq	56(%rsp), %rdx
	movl	%ecx, 32(%rsp)
	leaq	64(%rsp), %rcx
	movl	%r8d, 28(%rsp)
	movq	%r9, 16(%rsp)
	movq	%rax, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 184(%rsp)
	xorl	%eax, %eax
	leaq	44(%rsp), %rax
	movl	$1, 80(%rsp)
	movq	%rax, 120(%rsp)
	leaq	40(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	36(%rsp), %rax
	movq	%rax, 136(%rsp)
	leaq	32(%rsp), %rax
	movq	%rax, 144(%rsp)
	leaq	28(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 160(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 168(%rsp)
	movq	%rsp, %rax
	movq	%rax, 176(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 72(%rsp)
	movq	%rax, 84(%rsp)
	movl	$1, 92(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L12
	pushq	64(%rsp)
	.cfi_def_cfa_offset 216
	leaq	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi(%rip), %rdi
	pushq	64(%rsp)
	.cfi_def_cfa_offset 224
	movq	100(%rsp), %rcx
	movl	108(%rsp), %r8d
	movq	88(%rsp), %rsi
	movl	96(%rsp), %edx
	leaq	136(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 216
	popq	%rdx
	.cfi_def_cfa_offset 208
.L12:
	movq	184(%rsp), %rax
	subq	%fs:40, %rax
	je	.L14
	call	__stack_chk_fail@PLT
.L14:
	addq	$200, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4033:
	.size	_Z51__device_stub__Z22CalculaDistanciaEdicaoiiiiiPcS_PiiiiiiPcS_Pi, .-_Z51__device_stub__Z22CalculaDistanciaEdicaoiiiiiPcS_PiiiiiiPcS_Pi
	.globl	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
	.type	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi, @function
_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi:
.LFB4034:
	.cfi_startproc
	endbr64
	jmp	_Z51__device_stub__Z22CalculaDistanciaEdicaoiiiiiPcS_PiiiiiiPcS_Pi
	.cfi_endproc
.LFE4034:
	.size	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi, .-_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
	.section	.rodata.str1.1
.LC1:
	.string	"_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi"
.LC2:
	.string	"_Z16InicializaMatriziiPi"
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB4036:
	.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	.LC1(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi(%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	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC2(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z16InicializaMatriziiPi(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE4036:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.text._ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_,"axG",@progbits,_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_,comdat
	.weak	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_
	.type	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_, @function
_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_:
.LFB4360:
	.cfi_startproc
	endbr64
	movabsq	$9223372036854775807, %rdx
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	movq	%rdi, %rbx
	call	_ZSt17__istream_extractRSiPcl@PLT
	movq	%rbx, %rax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE4360:
	.size	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_, .-_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_
	.section	.rodata.str1.1
.LC3:
	.string	"Arquivo n\303\243o encontrado!"
.LC4:
	.string	"Tempo de execu\303\247\303\243o: "
.LC5:
	.string	" ms"
.LC6:
	.string	"Dist\303\242ncia de edi\303\247\303\243o: "
	.section	.text.startup
	.globl	main
	.type	main, @function
main:
.LFB4005:
	.cfi_startproc
	.cfi_personality 0x9b,DW.ref.__gxx_personality_v0
	.cfi_lsda 0x1b,.LLSDA4005
	endbr64
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset 6, -16
	movl	$8, %edx
	movq	%rsp, %rbp
	.cfi_def_cfa_register 6
	pushq	%r15
	pushq	%r14
	pushq	%r13
	pushq	%r12
	pushq	%rbx
	subq	$648, %rsp
	.cfi_offset 15, -24
	.cfi_offset 14, -32
	.cfi_offset 13, -40
	.cfi_offset 12, -48
	.cfi_offset 3, -56
	movq	8(%rsi), %rsi
	movq	%fs:40, %rax
	movq	%rax, -56(%rbp)
	xorl	%eax, %eax
	leaq	-576(%rbp), %rax
	movq	%rax, %rdi
	movq	%rax, -664(%rbp)
.LEHB0:
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode@PLT
.LEHE0:
	xorl	%ecx, %ecx
	leaq	-456(%rbp), %rdi
	movl	%ecx, -644(%rbp)
	call	_ZNKSt12__basic_fileIcE7is_openEv@PLT
	testb	%al, %al
	je	.L22
	movq	-664(%rbp), %rdi
	leaq	-652(%rbp), %rsi
.LEHB1:
	call	_ZNSirsERi@PLT
	movq	%rax, %rdi
	leaq	-648(%rbp), %rsi
	call	_ZNSirsERi@PLT
	movl	-652(%rbp), %edi
	call	_Z14AlocaSequenciai
	movl	-648(%rbp), %edi
	movq	%rax, -672(%rbp)
	call	_Z14AlocaSequenciai
	movq	%rax, %rbx
	movq	-672(%rbp), %rax
	movq	-664(%rbp), %rdi
	leaq	1(%rax), %rsi
	call	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_
	movq	%rax, %rdi
	leaq	1(%rbx), %rsi
	call	_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_
	movq	-664(%rbp), %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv@PLT
	jmp	.L52
.L22:
	leaq	.LC3(%rip), %rsi
	leaq	_ZSt4cout(%rip), %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	orl	$-1, %ebx
	jmp	.L24
.L52:
	movl	-652(%rbp), %ecx
	movl	$1024, %edi
	movl	-648(%rbp), %esi
	leal	1023(%rcx), %eax
	incl	%ecx
	cltd
	idivl	%edi
	movl	%eax, %r13d
	leal	1023(%rsi), %eax
	incl	%esi
	cltd
	imull	%esi, %ecx
	idivl	%edi
	movslq	%ecx, %rcx
	leaq	-640(%rbp), %rdi
	movl	%eax, %r14d
	leaq	0(,%rcx,4), %rax
	movq	%rax, %rsi
	movq	%rax, -680(%rbp)
	call	cudaMalloc@PLT
	movl	-652(%rbp), %eax
	leaq	-632(%rbp), %rdi
	leal	2(%rax), %esi
	movslq	%esi, %rsi
	call	cudaMalloc@PLT
	movl	-648(%rbp), %eax
	leaq	-624(%rbp), %rdi
	leal	2(%rax), %esi
	movslq	%esi, %rsi
	call	cudaMalloc@PLT
	leaq	-616(%rbp), %rdi
	call	cudaEventCreate@PLT
	leaq	-608(%rbp), %rdi
	call	cudaEventCreate@PLT
	movq	-616(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movl	-652(%rbp), %eax
	movq	-672(%rbp), %rsi
	movl	$1, %ecx
	movq	-632(%rbp), %rdi
	leal	2(%rax), %edx
	movslq	%edx, %rdx
	call	cudaMemcpy@PLT
	movl	-648(%rbp), %eax
	movq	-624(%rbp), %rdi
	movl	$1, %ecx
	movq	%rbx, %rsi
	leal	2(%rax), %edx
	movslq	%edx, %rdx
	call	cudaMemcpy@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %ecx
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movl	$1, -580(%rbp)
	movq	%rdi, %rdx
	movq	%rdi, -588(%rbp)
	movq	%rdi, -600(%rbp)
	movl	$1, -592(%rbp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	je	.L25
.L27:
	call	cudaDeviceSynchronize@PLT
	movl	-652(%rbp), %r12d
	movl	$1024, %eax
	movl	-648(%rbp), %edx
	movabsq	$4294967297, %r15
	cmpl	%eax, %r12d
	cmovg	%eax, %r12d
	leal	-1(%r13,%r14), %eax
	movl	%eax, -684(%rbp)
	movl	$1024, %eax
	cmpl	%eax, %edx
	cmovle	%edx, %eax
	xorl	%r14d, %r14d
	movl	%eax, -688(%rbp)
	jmp	.L28
.L25:
	movq	-640(%rbp), %rdx
	movl	-648(%rbp), %esi
	movl	-652(%rbp), %edi
	call	_Z38__device_stub__Z16InicializaMatriziiPiiiPi
	jmp	.L27
.L32:
	movq	%r15, -584(%rbp)
	movl	-580(%rbp), %ecx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%r15, -596(%rbp)
	movl	-592(%rbp), %esi
	movl	%r12d, -588(%rbp)
	movq	-588(%rbp), %rdx
	movl	%r13d, -600(%rbp)
	movq	-600(%rbp), %rdi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	je	.L29
.L31:
	call	cudaDeviceSynchronize@PLT
	incl	%r14d
.L28:
	movl	-684(%rbp), %eax
	cmpl	%eax, %r14d
	jl	.L32
	jmp	.L53
.L29:
	pushq	-640(%rbp)
	movl	-648(%rbp), %r8d
	movl	%r14d, %edx
	movl	%r12d, %edi
	movl	-652(%rbp), %ecx
	pushq	-624(%rbp)
	movl	-688(%rbp), %esi
	movq	-632(%rbp), %r9
	.cfi_escape 0x2e,0x10
	call	_Z51__device_stub__Z22CalculaDistanciaEdicaoiiiiiPcS_PiiiiiiPcS_Pi
	popq	%rax
	popq	%rdx
	jmp	.L31
.L53:
	movq	-680(%rbp), %rcx
	movq	-640(%rbp), %rax
	movl	$4, %edx
	leaq	-644(%rbp), %rdi
	leaq	-4(%rax,%rcx), %rsi
	movl	$2, %ecx
	.cfi_escape 0x2e,0
	call	cudaMemcpy@PLT
	movq	-608(%rbp), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	-608(%rbp), %rdi
	call	cudaEventSynchronize@PLT
	movq	-608(%rbp), %rdx
	movq	-616(%rbp), %rsi
	leaq	-588(%rbp), %rdi
	call	cudaEventElapsedTime@PLT
	movq	-616(%rbp), %rdi
	call	cudaEventDestroy@PLT
	movq	-608(%rbp), %rdi
	call	cudaEventDestroy@PLT
	leaq	_ZSt4cout(%rip), %r12
	leaq	_ZSt5fixedRSt8ios_base(%rip), %rsi
	movq	%r12, %rdi
	call	_ZNSolsEPFRSt8ios_baseS0_E@PLT
	movq	(%rax), %rdx
	leaq	.LC4(%rip), %rsi
	movq	%r12, %rdi
	movq	-24(%rdx), %rdx
	movq	$2, 8(%rax,%rdx)
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	cvtss2sd	-588(%rbp), %xmm0
	call	_ZNSo9_M_insertIdEERSoT_@PLT
	movq	%rax, %rdi
	leaq	.LC5(%rip), %rsi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	leaq	.LC6(%rip), %rsi
	movq	%r12, %rdi
	call	_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@PLT
	movl	-644(%rbp), %esi
	movq	%rax, %rdi
	call	_ZNSolsEi@PLT
	movq	%rax, %rdi
	call	_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@PLT
	cmpq	$0, -672(%rbp)
	je	.L33
	movq	-672(%rbp), %rdi
	call	_ZdaPv@PLT
.L33:
	testq	%rbx, %rbx
	je	.L34
	movq	%rbx, %rdi
	call	_ZdaPv@PLT
.L34:
	movq	-640(%rbp), %rdi
	call	cudaFree@PLT
	movq	-632(%rbp), %rdi
	call	cudaFree@PLT
	movq	-624(%rbp), %rdi
	call	cudaFree@PLT
.LEHE1:
	xorl	%ebx, %ebx
.L24:
	movq	-664(%rbp), %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	je	.L37
	jmp	.L50
.L39:
	endbr64
	movq	%rax, %rbx
.L35:
	movq	-664(%rbp), %rdi
	call	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev@PLT
	movq	-56(%rbp), %rax
	subq	%fs:40, %rax
	jne	.L50
	movq	%rbx, %rdi
.LEHB2:
	call	_Unwind_Resume@PLT
.LEHE2:
.L50:
	call	__stack_chk_fail@PLT
.L37:
	leaq	-40(%rbp), %rsp
	movl	%ebx, %eax
	popq	%rbx
	popq	%r12
	popq	%r13
	popq	%r14
	popq	%r15
	popq	%rbp
	.cfi_def_cfa 7, 8
	ret
	.cfi_endproc
.LFE4005:
	.globl	__gxx_personality_v0
	.section	.gcc_except_table,"a",@progbits
.LLSDA4005:
	.byte	0xff
	.byte	0xff
	.byte	0x1
	.uleb128 .LLSDACSE4005-.LLSDACSB4005
.LLSDACSB4005:
	.uleb128 .LEHB0-.LFB4005
	.uleb128 .LEHE0-.LEHB0
	.uleb128 0
	.uleb128 0
	.uleb128 .LEHB1-.LFB4005
	.uleb128 .LEHE1-.LEHB1
	.uleb128 .L39-.LFB4005
	.uleb128 0
	.uleb128 .LEHB2-.LFB4005
	.uleb128 .LEHE2-.LEHB2
	.uleb128 0
	.uleb128 0
.LLSDACSE4005:
	.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
	.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:

/********************************************************************************
 * Trabalho 2: Programação Paralela para Processador Many-core (GPU) Usando CUDA
 * Professora: Nahri Moreano
 * Aluno: Ian Haranaka | RGA: 2018.1904.009-7
 * Comando de compilação: nvcc dist_par.cu -o dist_par
 ********************************************************************************/


#include <hip/hip_runtime.h>
#include <iostream>
#include <fstream>
#include <iomanip>

const int MAX_THREADS = 1024;

char *AlocaSequencia(int n);
__global__ void InicializaMatriz(int n, int m, int *D);
__global__ void CalculaDistanciaEdicao(int num_linhas, int num_colunas,
                                      int antidiag_bloco, int n, int m,
                                      char *S, char *R, int *D);

int main(int argc, char *argv[])
{
  std::ifstream entrada (argv[1]);
  int n, m, resultado = 0;
  char *h_S, *h_R;

  // Leitura do arquivo de entrada
  if (entrada.is_open())
  {
    entrada >> n >> m;

    h_S = AlocaSequencia(n);
    h_R = AlocaSequencia(m);
    entrada >> &(h_S[1]) >> &(h_R[1]);

    entrada.close();
  }
  else
  {
    std::cout << "Arquivo não encontrado!" << std::endl;
    return -1;
  }

  int tam_vetor = (n+1) * (m+1);
  // Número de blocos por linha e por coluna
  int num_blocos_n = (n + MAX_THREADS - 1) / MAX_THREADS;
  int num_blocos_m = (m + MAX_THREADS - 1) / MAX_THREADS;

  // Aloca a matriz e as strings na GPU
  int *d_D;
  char *d_S, *d_R;
  hipMalloc((void **)&d_D, tam_vetor * sizeof(int));
  hipMalloc(&d_S, (n+2) * sizeof(char));
  hipMalloc(&d_R, (m+2) * sizeof(char));

  // Inicio da medição de tempo
  hipEvent_t d_ini, d_fim;
  hipEventCreate(&d_ini);
  hipEventCreate(&d_fim);
  hipEventRecord(d_ini, 0);

  // Copia as strings para a memória global da GPU
  hipMemcpy(d_S, h_S, (n+2) * sizeof(char), hipMemcpyHostToDevice);
  hipMemcpy(d_R, h_R, (m+2) * sizeof(char), hipMemcpyHostToDevice);

  InicializaMatriz<<<1, 1>>>(n, m, d_D);
  hipDeviceSynchronize();

  int threads_por_bloco = (n < MAX_THREADS ? n : MAX_THREADS);
  int num_antidiag = num_blocos_n + num_blocos_m - 1;
  int num_linhas = threads_por_bloco;
  int num_colunas = (m < 1024 ? m : 1024);

  // Para cada antidiagonal por bloco
  for (int antidiag = 0; antidiag < num_antidiag; ++antidiag)
  {
    CalculaDistanciaEdicao<<<num_blocos_n, threads_por_bloco>>>
    (num_linhas, num_colunas, antidiag, n, m, d_S, d_R, d_D);

    hipDeviceSynchronize();
  }

  hipMemcpy(&resultado, &d_D[tam_vetor - 1], sizeof(int), hipMemcpyDeviceToHost);

  // Fim da medição de tempo
  hipEventRecord(d_fim, 0);
  hipEventSynchronize(d_fim);
  float d_tempo;
  hipEventElapsedTime(&d_tempo, d_ini, d_fim);
  hipEventDestroy(d_ini);
  hipEventDestroy(d_fim);

  std::cout << std::fixed << std::setprecision(2);
  std::cout << "Tempo de execução: " << d_tempo << " ms" << std::endl;
  std::cout << "Distância de edição: " << resultado << std::endl;

  // Libera a matriz e as strings
  delete[] h_S;
  delete[] h_R;
  hipFree(d_D);
  hipFree(d_S);
  hipFree(d_R);

  return 0;
}

char *AlocaSequencia(int n)
{
  char *seq = new (std::nothrow) char[n+2];

  if (seq == nullptr)
    std::cout << "Erro na alocação de memória!" << std::endl;

  seq[0] = ' ';
  return seq;
}

__global__ void InicializaMatriz(int n, int m, int *D)
{
  for (int i = 0, j = 0; i < (n+1) * (m+1); i += m+1, ++j)
    D[i] = j;
  for (int j = 0; j <= m; ++j)
    D[j] = j;
}

__global__ void CalculaDistanciaEdicao(int num_linhas, int num_colunas,
                                      int antidiag_bloco, int n, int m,
                                      char *S, char *R, int *D)
{
  // A quantidade de colunas que se deve pular para chegar até as células do bloco
  int deslocamento_col = (antidiag_bloco * num_colunas) - (blockIdx.x * num_colunas);
  int num_antidiag = num_linhas + num_colunas - 1;
  int i = (blockIdx.x * num_linhas) + threadIdx.x + 1, j;
  int a, b, c, t, min;

  // Se o bloco é válido - Isto implica em dizer se o bloco contém parte da matriz
  if (deslocamento_col >= 0 && deslocamento_col < m)
  {
    for (int antidiag = 2; antidiag <= num_antidiag + 1; antidiag++)
    {
      j = deslocamento_col + antidiag - (threadIdx.x + 1);
      // Se é uma célula válida
      if (i <= n && j > deslocamento_col && j <= deslocamento_col + num_colunas)
      {
        t = (S[i] != R[j] ? 1 : 0);
        a = D[i*(m+1)+j-1] + 1;
        b = D[(i-1)*(m+1)+j] + 1;
        c = D[(i-1)*(m+1)+j-1] + t;

        min = (a < b ? a : b);
        min = (c < min ? c : min);
        D[i*(m+1)+j] = min;
      }
      __syncthreads();
    }
  }
}

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

                                        # End of file scope inline assembly
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
.Lfunc_begin0:
	.cfi_startproc
	.cfi_personality 3, __gxx_personality_v0
	.cfi_lsda 3, .Lexception0
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$616, %rsp                      # imm = 0x268
	.cfi_def_cfa_offset 672
	.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	8(%rsi), %rsi
	.cfi_escape 0x2e, 0x00
	leaq	96(%rsp), %rdi
	movl	$8, %edx
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1EPKcSt13_Ios_Openmode
	movl	$0, 20(%rsp)
	leaq	216(%rsp), %rdi
	.cfi_escape 0x2e, 0x00
	callq	_ZNKSt12__basic_fileIcE7is_openEv
	testb	%al, %al
	je	.LBB0_52
# %bb.1:
.Ltmp8:
	.cfi_escape 0x2e, 0x00
	leaq	96(%rsp), %rdi
	leaq	16(%rsp), %rsi
	callq	_ZNSirsERi
.Ltmp9:
# %bb.2:
.Ltmp10:
	.cfi_escape 0x2e, 0x00
	leaq	12(%rsp), %rsi
	movq	%rax, %rdi
	callq	_ZNSirsERi
.Ltmp11:
# %bb.3:
	movl	16(%rsp), %edi
.Ltmp12:
	.cfi_escape 0x2e, 0x00
	callq	_Z14AlocaSequenciai
.Ltmp13:
# %bb.4:
	movq	%rax, %r15
	movl	12(%rsp), %edi
.Ltmp14:
	.cfi_escape 0x2e, 0x00
	callq	_Z14AlocaSequenciai
.Ltmp15:
# %bb.5:
	movq	%rax, %r12
	leaq	1(%r15), %rsi
.Ltmp16:
	.cfi_escape 0x2e, 0x00
	leaq	96(%rsp), %rdi
	movabsq	$9223372036854775807, %rdx      # imm = 0x7FFFFFFFFFFFFFFF
	callq	_ZSt17__istream_extractRSiPcl
.Ltmp17:
# %bb.6:                                # %_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_.exit
	leaq	1(%r12), %rsi
.Ltmp18:
	.cfi_escape 0x2e, 0x00
	leaq	96(%rsp), %rdi
	movabsq	$9223372036854775807, %rdx      # imm = 0x7FFFFFFFFFFFFFFF
	callq	_ZSt17__istream_extractRSiPcl
.Ltmp19:
# %bb.7:                                # %_ZStrsIcSt11char_traitsIcEERSt13basic_istreamIT_T0_ES6_PS3_.exit53
.Ltmp20:
	.cfi_escape 0x2e, 0x00
	leaq	96(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEE5closeEv
.Ltmp21:
# %bb.8:
	movl	16(%rsp), %ebx
	leal	1(%rbx), %eax
	movl	12(%rsp), %r14d
	leal	1(%r14), %ecx
	imull	%eax, %ecx
	movl	$1023, %eax                     # imm = 0x3FF
	leal	(%rbx,%rax), %edx
	movl	$2046, %esi                     # imm = 0x7FE
	addl	%esi, %ebx
	testl	%edx, %edx
	cmovnsl	%edx, %ebx
	addl	%r14d, %eax
	addl	%esi, %r14d
	testl	%eax, %eax
	cmovnsl	%eax, %r14d
	movslq	%ecx, %rax
	movq	%rax, 88(%rsp)                  # 8-byte Spill
	leaq	(,%rax,4), %rsi
.Ltmp23:
	.cfi_escape 0x2e, 0x00
	leaq	32(%rsp), %rdi
	callq	hipMalloc
.Ltmp24:
# %bb.9:
	movslq	16(%rsp), %rsi
	addq	$2, %rsi
.Ltmp25:
	.cfi_escape 0x2e, 0x00
	leaq	56(%rsp), %rdi
	callq	hipMalloc
.Ltmp26:
# %bb.10:                               # %_ZL9hipMallocIcE10hipError_tPPT_m.exit
	movslq	12(%rsp), %rsi
	addq	$2, %rsi
.Ltmp27:
	.cfi_escape 0x2e, 0x00
	leaq	48(%rsp), %rdi
	callq	hipMalloc
.Ltmp28:
# %bb.11:                               # %_ZL9hipMallocIcE10hipError_tPPT_m.exit58
.Ltmp30:
	.cfi_escape 0x2e, 0x00
	leaq	40(%rsp), %rdi
	callq	hipEventCreate
.Ltmp31:
# %bb.12:
.Ltmp32:
	.cfi_escape 0x2e, 0x00
	leaq	24(%rsp), %rdi
	callq	hipEventCreate
.Ltmp33:
# %bb.13:
	movq	40(%rsp), %rdi
.Ltmp34:
	.cfi_escape 0x2e, 0x00
	xorl	%esi, %esi
	callq	hipEventRecord
.Ltmp35:
# %bb.14:
	movq	56(%rsp), %rdi
	movslq	16(%rsp), %rdx
	addq	$2, %rdx
.Ltmp36:
	.cfi_escape 0x2e, 0x00
	movq	%r15, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp37:
# %bb.15:
	movq	48(%rsp), %rdi
	movslq	12(%rsp), %rdx
	addq	$2, %rdx
.Ltmp38:
	.cfi_escape 0x2e, 0x00
	movq	%r12, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
.Ltmp39:
# %bb.16:
.Ltmp40:
	.cfi_escape 0x2e, 0x00
	movabsq	$4294967297, %rdi               # imm = 0x100000001
	movl	$1, %esi
	movq	%rdi, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp41:
# %bb.17:
	testl	%eax, %eax
	jne	.LBB0_19
# %bb.18:
	movl	16(%rsp), %edi
	movl	12(%rsp), %esi
	movq	32(%rsp), %rdx
.Ltmp42:
	.cfi_escape 0x2e, 0x00
	callq	_Z31__device_stub__InicializaMatriziiPi
.Ltmp43:
.LBB0_19:
.Ltmp44:
	.cfi_escape 0x2e, 0x00
	callq	hipDeviceSynchronize
.Ltmp45:
# %bb.20:
	movq	%r12, 72(%rsp)                  # 8-byte Spill
	movq	%r15, 80(%rsp)                  # 8-byte Spill
	sarl	$10, %ebx
	sarl	$10, %r14d
	movl	16(%rsp), %ebp
	movl	$1024, %r15d                    # imm = 0x400
	cmpl	%r15d, %ebp
	cmovgel	%r15d, %ebp
	leal	(%rbx,%r14), %eax
	decl	%eax
	movl	12(%rsp), %ecx
	cmpl	%r15d, %ecx
	cmovll	%ecx, %r15d
	testl	%eax, %eax
	jle	.LBB0_27
# %bb.21:                               # %.lr.ph
	movl	%ebx, %r12d
	btsq	$32, %r12
	movl	%ebp, %r13d
	btsq	$32, %r13
	addl	%ebx, %r14d
	decl	%r14d
	xorl	%ebx, %ebx
.LBB0_22:                               # =>This Inner Loop Header: Depth=1
.Ltmp47:
	.cfi_escape 0x2e, 0x00
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%r13, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
.Ltmp48:
# %bb.23:                               #   in Loop: Header=BB0_22 Depth=1
	testl	%eax, %eax
	jne	.LBB0_25
# %bb.24:                               #   in Loop: Header=BB0_22 Depth=1
	movl	16(%rsp), %ecx
	movl	12(%rsp), %r8d
	movq	56(%rsp), %r9
.Ltmp49:
	.cfi_escape 0x2e, 0x10
	movl	%ebp, %edi
	movl	%r15d, %esi
	movl	%ebx, %edx
	pushq	32(%rsp)
	.cfi_adjust_cfa_offset 8
	pushq	56(%rsp)
	.cfi_adjust_cfa_offset 8
	callq	_Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.Ltmp50:
.LBB0_25:                               #   in Loop: Header=BB0_22 Depth=1
.Ltmp51:
	.cfi_escape 0x2e, 0x00
	callq	hipDeviceSynchronize
.Ltmp52:
# %bb.26:                               #   in Loop: Header=BB0_22 Depth=1
	incl	%ebx
	cmpl	%ebx, %r14d
	jne	.LBB0_22
.LBB0_27:                               # %._crit_edge
	movq	32(%rsp), %rax
	movq	88(%rsp), %rcx                  # 8-byte Reload
	leaq	(%rax,%rcx,4), %rsi
	addq	$-4, %rsi
.Ltmp54:
	.cfi_escape 0x2e, 0x00
	leaq	20(%rsp), %rdi
	movl	$4, %edx
	movl	$2, %ecx
	callq	hipMemcpy
.Ltmp55:
# %bb.28:
	movq	24(%rsp), %rdi
.Ltmp56:
	.cfi_escape 0x2e, 0x00
	xorl	%esi, %esi
	callq	hipEventRecord
.Ltmp57:
# %bb.29:
	movq	24(%rsp), %rdi
.Ltmp58:
	.cfi_escape 0x2e, 0x00
	callq	hipEventSynchronize
.Ltmp59:
# %bb.30:
	movq	40(%rsp), %rsi
	movq	24(%rsp), %rdx
.Ltmp61:
	.cfi_escape 0x2e, 0x00
	leaq	68(%rsp), %rdi
	callq	hipEventElapsedTime
.Ltmp62:
	movq	80(%rsp), %r14                  # 8-byte Reload
	movq	72(%rsp), %r15                  # 8-byte Reload
# %bb.31:
	movq	40(%rsp), %rdi
.Ltmp63:
	.cfi_escape 0x2e, 0x00
	callq	hipEventDestroy
.Ltmp64:
# %bb.32:
	movq	24(%rsp), %rdi
.Ltmp65:
	.cfi_escape 0x2e, 0x00
	callq	hipEventDestroy
.Ltmp66:
# %bb.33:
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rcx
	movl	$-261, %edx                     # imm = 0xFEFB
	andl	_ZSt4cout+24(%rcx), %edx
	orl	$4, %edx
	movl	%edx, _ZSt4cout+24(%rcx)
	movq	-24(%rax), %rax
	movq	$2, _ZSt4cout+8(%rax)
.Ltmp67:
	.cfi_escape 0x2e, 0x00
	movl	$_ZSt4cout, %edi
	movl	$.L.str.1, %esi
	movl	$21, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp68:
# %bb.34:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit61
	cvtss2sd	68(%rsp), %xmm0
.Ltmp69:
	.cfi_escape 0x2e, 0x00
	movl	$_ZSt4cout, %edi
	callq	_ZNSo9_M_insertIdEERSoT_
.Ltmp70:
# %bb.35:                               # %_ZNSolsEf.exit
.Ltmp71:
	movq	%rax, %rbx
	.cfi_escape 0x2e, 0x00
	movl	$.L.str.2, %esi
	movl	$3, %edx
	movq	%rax, %rdi
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp72:
# %bb.36:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit64
	movq	(%rbx), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
.Ltmp73:
	.cfi_escape 0x2e, 0x00
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp74:
# %bb.37:                               # %.noexc74
.Ltmp75:
	.cfi_escape 0x2e, 0x00
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
.Ltmp76:
# %bb.38:                               # %.noexc75
.Ltmp77:
	.cfi_escape 0x2e, 0x00
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp78:
# %bb.39:                               # %_ZNSolsEPFRSoS_E.exit66
.Ltmp79:
	.cfi_escape 0x2e, 0x00
	movl	$_ZSt4cout, %edi
	movl	$.L.str.3, %esi
	movl	$24, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp80:
# %bb.40:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit68
	movl	20(%rsp), %esi
.Ltmp81:
	.cfi_escape 0x2e, 0x00
	movl	$_ZSt4cout, %edi
	callq	_ZNSolsEi
.Ltmp82:
# %bb.41:
	movq	%rax, %rbx
	movq	(%rax), %rax
	movq	-24(%rax), %rdi
	addq	%rbx, %rdi
.Ltmp83:
	.cfi_escape 0x2e, 0x00
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp84:
# %bb.42:                               # %.noexc78
.Ltmp85:
	.cfi_escape 0x2e, 0x00
	movsbl	%al, %esi
	movq	%rbx, %rdi
	callq	_ZNSo3putEc
.Ltmp86:
# %bb.43:                               # %.noexc79
.Ltmp87:
	.cfi_escape 0x2e, 0x00
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp88:
# %bb.44:                               # %_ZNSolsEPFRSoS_E.exit70
	testq	%r14, %r14
	je	.LBB0_46
# %bb.45:
	.cfi_escape 0x2e, 0x00
	movq	%r14, %rdi
	callq	_ZdaPv
.LBB0_46:
	testq	%r15, %r15
	je	.LBB0_48
# %bb.47:
	.cfi_escape 0x2e, 0x00
	movq	%r15, %rdi
	callq	_ZdaPv
.LBB0_48:
	movq	32(%rsp), %rdi
.Ltmp89:
	.cfi_escape 0x2e, 0x00
	callq	hipFree
.Ltmp90:
# %bb.49:
	movq	56(%rsp), %rdi
.Ltmp91:
	.cfi_escape 0x2e, 0x00
	callq	hipFree
.Ltmp92:
# %bb.50:
	movq	48(%rsp), %rdi
.Ltmp93:
	.cfi_escape 0x2e, 0x00
	callq	hipFree
.Ltmp94:
# %bb.51:
	xorl	%ebx, %ebx
	jmp	.LBB0_56
.LBB0_52:
.Ltmp0:
	.cfi_escape 0x2e, 0x00
	movl	$_ZSt4cout, %ebx
	movl	$_ZSt4cout, %edi
	movl	$.L.str, %esi
	movl	$24, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
.Ltmp1:
# %bb.53:                               # %_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc.exit
	movq	_ZSt4cout(%rip), %rax
	addq	-24(%rax), %rbx
.Ltmp2:
	.cfi_escape 0x2e, 0x00
	movq	%rbx, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
.Ltmp3:
# %bb.54:                               # %.noexc71
.Ltmp4:
	.cfi_escape 0x2e, 0x00
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
.Ltmp5:
# %bb.55:                               # %.noexc72
	movl	$-1, %ebx
.Ltmp6:
	.cfi_escape 0x2e, 0x00
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.Ltmp7:
.LBB0_56:                               # %_ZNSolsEPFRSoS_E.exit
	.cfi_escape 0x2e, 0x00
	leaq	96(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	movl	%ebx, %eax
	addq	$616, %rsp                      # imm = 0x268
	.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_60:
	.cfi_def_cfa_offset 672
.Ltmp60:
	jmp	.LBB0_63
.LBB0_57:
.Ltmp29:
	jmp	.LBB0_63
.LBB0_58:
.Ltmp46:
	jmp	.LBB0_63
.LBB0_62:
.Ltmp22:
	jmp	.LBB0_63
.LBB0_61:
.Ltmp95:
	jmp	.LBB0_63
.LBB0_59:
.Ltmp53:
.LBB0_63:
	movq	%rax, %rbx
	.cfi_escape 0x2e, 0x00
	leaq	96(%rsp), %rdi
	callq	_ZNSt14basic_ifstreamIcSt11char_traitsIcEED1Ev
	.cfi_escape 0x2e, 0x00
	movq	%rbx, %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 .Ltmp8-.Lfunc_begin0           #   Call between .Lfunc_begin0 and .Ltmp8
	.byte	0                               #     has no landing pad
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp8-.Lfunc_begin0           # >> Call Site 2 <<
	.uleb128 .Ltmp21-.Ltmp8                 #   Call between .Ltmp8 and .Ltmp21
	.uleb128 .Ltmp22-.Lfunc_begin0          #     jumps to .Ltmp22
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp23-.Lfunc_begin0          # >> Call Site 3 <<
	.uleb128 .Ltmp28-.Ltmp23                #   Call between .Ltmp23 and .Ltmp28
	.uleb128 .Ltmp29-.Lfunc_begin0          #     jumps to .Ltmp29
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp30-.Lfunc_begin0          # >> Call Site 4 <<
	.uleb128 .Ltmp45-.Ltmp30                #   Call between .Ltmp30 and .Ltmp45
	.uleb128 .Ltmp46-.Lfunc_begin0          #     jumps to .Ltmp46
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp47-.Lfunc_begin0          # >> Call Site 5 <<
	.uleb128 .Ltmp52-.Ltmp47                #   Call between .Ltmp47 and .Ltmp52
	.uleb128 .Ltmp53-.Lfunc_begin0          #     jumps to .Ltmp53
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp54-.Lfunc_begin0          # >> Call Site 6 <<
	.uleb128 .Ltmp59-.Ltmp54                #   Call between .Ltmp54 and .Ltmp59
	.uleb128 .Ltmp60-.Lfunc_begin0          #     jumps to .Ltmp60
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp61-.Lfunc_begin0          # >> Call Site 7 <<
	.uleb128 .Ltmp94-.Ltmp61                #   Call between .Ltmp61 and .Ltmp94
	.uleb128 .Ltmp95-.Lfunc_begin0          #     jumps to .Ltmp95
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp0-.Lfunc_begin0           # >> Call Site 8 <<
	.uleb128 .Ltmp7-.Ltmp0                  #   Call between .Ltmp0 and .Ltmp7
	.uleb128 .Ltmp22-.Lfunc_begin0          #     jumps to .Ltmp22
	.byte	0                               #   On action: cleanup
	.uleb128 .Ltmp7-.Lfunc_begin0           # >> Call Site 9 <<
	.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
	.text
	.globl	_Z14AlocaSequenciai             # -- Begin function _Z14AlocaSequenciai
	.type	_Z14AlocaSequenciai,@function
_Z14AlocaSequenciai:                    # @_Z14AlocaSequenciai
	.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
	addl	$2, %edi
	movslq	%edi, %rdi
	movl	$_ZSt7nothrow, %esi
	callq	_ZnamRKSt9nothrow_t
	movq	%rax, %rbx
	testq	%rax, %rax
	jne	.LBB1_2
# %bb.1:
	movl	$_ZSt4cout, %r14d
	movl	$_ZSt4cout, %edi
	movl	$.L.str.4, %esi
	movl	$31, %edx
	callq	_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l
	movq	_ZSt4cout(%rip), %rax
	movq	-24(%rax), %rdi
	addq	%r14, %rdi
	movl	$10, %esi
	callq	_ZNKSt9basic_iosIcSt11char_traitsIcEE5widenEc
	movsbl	%al, %esi
	movl	$_ZSt4cout, %edi
	callq	_ZNSo3putEc
	movq	%rax, %rdi
	callq	_ZNSo5flushEv
.LBB1_2:
	movb	$32, (%rbx)
	movq	%rbx, %rax
	addq	$8, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z14AlocaSequenciai, .Lfunc_end1-_Z14AlocaSequenciai
	.cfi_endproc
                                        # -- End function
	.globl	_Z31__device_stub__InicializaMatriziiPi # -- Begin function _Z31__device_stub__InicializaMatriziiPi
	.type	_Z31__device_stub__InicializaMatriziiPi,@function
_Z31__device_stub__InicializaMatriziiPi: # @_Z31__device_stub__InicializaMatriziiPi
	.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	$96, %rsp
	.cfi_def_cfa_offset 144
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	4(%rsp), %rax
	movl	%edi, (%rax)
	movq	%rsp, %rcx
	movl	%esi, (%rcx)
	leaq	24(%rsp), %rsi
	movq	%rdx, (%rsi)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	movq	%rsi, 16(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	16(%rsp), %r12
	leaq	8(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z16InicializaMatriziiPi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$112, %rsp
	.cfi_adjust_cfa_offset -112
	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_end2:
	.size	_Z31__device_stub__InicializaMatriziiPi, .Lfunc_end2-_Z31__device_stub__InicializaMatriziiPi
	.cfi_endproc
                                        # -- End function
	.globl	_Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi # -- Begin function _Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi
	.type	_Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi,@function
_Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi: # @_Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	20(%rsp), %rax
	movl	%edi, (%rax)
	leaq	16(%rsp), %rdi
	movl	%esi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	40(%rsp), %r8
	movq	%r9, (%r8)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	192(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	200(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	32(%rsp), %r12
	leaq	24(%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	$_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	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_end3:
	.size	_Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi, .Lfunc_end3-_Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi
	.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:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z16InicializaMatriziiPi, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__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	.LBB5_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
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Arquivo n\303\243o encontrado!"
	.size	.L.str, 25

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

	.type	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi,@object # @_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
	.globl	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
	.p2align	3, 0x0
_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi:
	.quad	_Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi
	.size	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi, 8

	.type	.L.str.1,@object                # @.str.1
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.1:
	.asciz	"Tempo de execu\303\247\303\243o: "
	.size	.L.str.1, 22

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

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Dist\303\242ncia de edi\303\247\303\243o: "
	.size	.L.str.3, 25

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Erro na aloca\303\247\303\243o de mem\303\263ria!"
	.size	.L.str.4, 32

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z16InicializaMatriziiPi"
	.size	.L__unnamed_1, 25

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi"
	.size	.L__unnamed_2, 38

	.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 __gxx_personality_v0
	.addrsig_sym _Z31__device_stub__InicializaMatriziiPi
	.addrsig_sym _Z37__device_stub__CalculaDistanciaEdicaoiiiiiPcS_Pi
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Unwind_Resume
	.addrsig_sym _ZSt4cout
	.addrsig_sym _Z16InicializaMatriziiPi
	.addrsig_sym _Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
	.addrsig_sym _ZSt7nothrow
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z16InicializaMatriziiPi ; -- Begin function _Z16InicializaMatriziiPi
	.globl	_Z16InicializaMatriziiPi
	.p2align	8
	.type	_Z16InicializaMatriziiPi,@function
_Z16InicializaMatriziiPi:               ; @_Z16InicializaMatriziiPi
; %bb.0:
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_add_i32 s0, s0, 1
	s_add_i32 s4, s1, 1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_mul_i32 s0, s4, s0
	s_cmp_lt_i32 s0, 1
	s_cbranch_scc1 .LBB0_3
; %bb.1:                                ; %.lr.ph.preheader
	v_mov_b32_e32 v0, 0
	s_ashr_i32 s5, s4, 31
	s_mov_b64 s[8:9], s[2:3]
	s_lshl_b64 s[6:7], s[4:5], 2
	s_mov_b32 s5, 0
	s_mov_b32 s10, 0
.LBB0_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	v_mov_b32_e32 v1, s5
	s_add_i32 s10, s10, s4
	s_add_i32 s5, s5, 1
	global_store_b32 v0, v1, s[8:9]
	s_add_u32 s8, s8, s6
	s_addc_u32 s9, s9, s7
	s_cmp_ge_i32 s10, s0
	s_cbranch_scc0 .LBB0_2
.LBB0_3:                                ; %.preheader
	s_cmp_lt_i32 s1, 0
	s_mov_b32 s0, 0
	s_cbranch_scc1 .LBB0_6
; %bb.4:                                ; %.lr.ph21.preheader
	v_mov_b32_e32 v0, 0
.LBB0_5:                                ; %.lr.ph21
                                        ; =>This Inner Loop Header: Depth=1
	v_mov_b32_e32 v1, s0
	s_add_i32 s0, s0, 1
	global_store_b32 v0, v1, s[2:3]
	s_add_u32 s2, s2, 4
	s_addc_u32 s3, s3, 0
	s_cmp_eq_u32 s4, s0
	s_cbranch_scc0 .LBB0_5
.LBB0_6:                                ; %._crit_edge
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z16InicializaMatriziiPi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 16
		.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 2
		.amdhsa_next_free_sgpr 11
		.amdhsa_reserve_vcc 0
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z16InicializaMatriziiPi, .Lfunc_end0-_Z16InicializaMatriziiPi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 156
; NumSgprs: 11
; NumVgprs: 2
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 1
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 11
; NumVGPRsForWavesPerEU: 2
; 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
	.protected	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi ; -- Begin function _Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
	.globl	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
	.p2align	8
	.type	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi,@function
_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi:  ; @_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
; %bb.0:
	s_clause 0x1
	s_load_b128 s[8:11], s[0:1], 0x0
	s_load_b32 s13, s[0:1], 0x10
	s_waitcnt lgkmcnt(0)
	s_sub_i32 s10, s10, s15
	s_add_i32 s12, s9, s8
	s_mul_i32 s10, s10, s9
	s_delay_alu instid0(SALU_CYCLE_1)
	s_cmp_lt_i32 s10, 0
	s_cselect_b32 s2, -1, 0
	s_cmp_ge_i32 s10, s13
	s_cselect_b32 s3, -1, 0
	s_cmp_lt_i32 s12, 2
	s_cselect_b32 s4, -1, 0
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_or_b32 s2, s2, s4
	s_or_b32 s2, s2, s3
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_b32 vcc_lo, exec_lo, s2
	s_cbranch_vccnz .LBB1_5
; %bb.1:                                ; %.lr.ph
	s_clause 0x1
	s_load_b128 s[4:7], s[0:1], 0x18
	s_load_b64 s[2:3], s[0:1], 0x28
	v_mad_u64_u32 v[3:4], null, s15, s8, v[0:1]
	v_sub_nc_u32_e32 v5, s10, v0
	s_add_i32 s1, s10, s9
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_add_nc_u32_e32 v4, 1, v3
	v_ashrrev_i32_e32 v6, 31, v3
	v_mad_u64_u32 v[0:1], null, v3, s13, v[3:4]
	v_mad_u64_u32 v[1:2], null, v4, s13, v[4:5]
	v_cmp_lt_i32_e32 vcc_lo, s11, v4
	s_waitcnt lgkmcnt(0)
	v_add_co_u32 v2, s0, s4, v3
	s_delay_alu instid0(VALU_DEP_1)
	v_add_co_ci_u32_e64 v3, s0, s5, v6, s0
	v_add_nc_u32_e32 v4, 1, v5
	s_add_i32 s4, s12, -1
	s_xor_b32 s5, vcc_lo, -1
.LBB1_2:                                ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_1)
	v_cmp_lt_i32_e32 vcc_lo, s10, v4
	v_cmp_ge_i32_e64 s0, s1, v4
	s_and_b32 s8, s5, vcc_lo
	s_delay_alu instid0(VALU_DEP_1) | instid1(SALU_CYCLE_1)
	s_and_b32 s8, s8, s0
	s_delay_alu instid0(SALU_CYCLE_1)
	s_and_saveexec_b32 s0, s8
	s_cbranch_execz .LBB1_4
; %bb.3:                                ;   in Loop: Header=BB1_2 Depth=1
	v_add_nc_u32_e32 v5, v1, v4
	v_add_nc_u32_e32 v7, v0, v4
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_ashrrev_i32_e32 v6, 31, v5
	v_ashrrev_i32_e32 v8, 31, v7
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_lshlrev_b64 v[5:6], 2, v[5:6]
	v_lshlrev_b64 v[7:8], 2, v[7:8]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v5, vcc_lo, s2, v5
	v_add_co_ci_u32_e32 v6, vcc_lo, s3, v6, vcc_lo
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_4)
	v_add_co_u32 v7, vcc_lo, s2, v7
	v_add_co_ci_u32_e32 v8, vcc_lo, s3, v8, vcc_lo
	global_load_u8 v9, v[2:3], off offset:1
	s_clause 0x1
	global_load_b32 v10, v[5:6], off offset:-4
	global_load_b64 v[7:8], v[7:8], off offset:-4
	global_load_u8 v11, v4, s[6:7]
	s_waitcnt vmcnt(2)
	v_add_nc_u32_e32 v10, 1, v10
	s_waitcnt vmcnt(1)
	v_add_nc_u32_e32 v8, 1, v8
	s_waitcnt vmcnt(0)
	v_cmp_ne_u16_e32 vcc_lo, v9, v11
	v_add_co_ci_u32_e32 v7, vcc_lo, 0, v7, vcc_lo
	s_delay_alu instid0(VALU_DEP_1)
	v_min3_i32 v7, v7, v10, v8
	global_store_b32 v[5:6], v7, off
.LBB1_4:                                ;   in Loop: Header=BB1_2 Depth=1
	s_or_b32 exec_lo, exec_lo, s0
	v_add_nc_u32_e32 v4, 1, v4
	s_add_i32 s4, s4, -1
	s_waitcnt_vscnt null, 0x0
	s_cmp_lg_u32 s4, 0
	s_barrier
	buffer_gl0_inv
	s_cbranch_scc1 .LBB1_2
.LBB1_5:                                ; %.loopexit
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 48
		.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 12
		.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_end1:
	.size	_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi, .Lfunc_end1-_Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 428
; NumSgprs: 18
; NumVgprs: 12
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 12
; 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:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 16
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z16InicializaMatriziiPi
    .private_segment_fixed_size: 0
    .sgpr_count:     11
    .sgpr_spill_count: 0
    .symbol:         _Z16InicializaMatriziiPi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     2
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .offset:         0
        .size:           4
        .value_kind:     by_value
      - .offset:         4
        .size:           4
        .value_kind:     by_value
      - .offset:         8
        .size:           4
        .value_kind:     by_value
      - .offset:         12
        .size:           4
        .value_kind:     by_value
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .address_space:  global
        .offset:         24
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         32
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         40
        .size:           8
        .value_kind:     global_buffer
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 48
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z22CalculaDistanciaEdicaoiiiiiPcS_Pi
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z22CalculaDistanciaEdicaoiiiiiPcS_Pi.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     12
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
