#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <math.h>

__global__ void adicionarKernel(double* resultado, const double* n) {
	int i = threadIdx.x;
	double a = 1, b = 0;
	double delta = pow(b, 2) - (4 * a * (n[i] * -1));
	resultado[i] = ((b * -1) + sqrt(delta)) / 2 * a;
}

cudaError_t calcularRaizes(double* resultado, const double* n, unsigned int tam) {
	double* gpu_n;
	double* gpu_resultado;
	cudaError_t status;

	status = cudaSetDevice(0);
	if (status != cudaSuccess) {
		printf("cudaSetDevice falhou!");
		goto Falha;
	}

	status = cudaMalloc((void**)&gpu_resultado, tam * sizeof(double));
	if (status != cudaSuccess) {
		printf("cudaMalloc falhou!");
		goto Falha;
	}

	status = cudaMalloc((void**)&gpu_n, tam * sizeof(double));
	if (status != cudaSuccess) {
		printf("cudaMalloc falhou!");
		goto Falha;
	}

	status = cudaMemcpy(gpu_n, n, tam * sizeof(double), cudaMemcpyHostToDevice);
	if (status != cudaSuccess) {
		printf("cudaMemcpy falhou!");
		goto Falha;
	}

	adicionarKernel<<<1, tam>>>(gpu_resultado, gpu_n);

	status = cudaGetLastError();
	if (status != cudaSuccess) {
		printf("adicionarKernel falhou: %s", cudaGetErrorString(status));
		goto Falha;
	}

	status = cudaDeviceSynchronize();
	if (status != cudaSuccess) {
		printf("cudaDeviceSynchronize falhou: %d", status);
		goto Falha;
	}

	status = cudaMemcpy(resultado, gpu_resultado, tam * sizeof(double), cudaMemcpyDeviceToHost);
	if (status != cudaSuccess) {
		printf("cudaMemcpy falhou!");
		goto Falha;
	}

Falha:
	cudaFree(gpu_resultado);
	cudaFree(gpu_n);

	return status;
}

int main()
{
	const int tam = 10;
	const double n[tam] = { 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 };
	double resultado[tam] = { 0 };

	cudaError_t status = calcularRaizes(resultado, n, tam);
	if (status != cudaSuccess) {
		printf("calcularRaizes falhou!");
		return 1;
;	}

	printf("RESULTADO\n");
	for (int i = 0; i < tam; i++) {
		printf("Raiz de %f = %f\n", n[i], resultado[i]);
	}

	getchar();

	status = cudaDeviceReset();
	if (status != cudaSuccess) {
		printf("cudaDeviceReset falhou!");
		return 1;
	}

	return 0;
}
	.file	"tmpxft_003317df_00000000-6_raiz.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2031:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2031:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z38__device_stub__Z15adicionarKernelPdPKdPdPKd
	.type	_Z38__device_stub__Z15adicionarKernelPdPKdPdPKd, @function
_Z38__device_stub__Z15adicionarKernelPdPKdPdPKd:
.LFB2053:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z15adicionarKernelPdPKd(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L2:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2053:
	.size	_Z38__device_stub__Z15adicionarKernelPdPKdPdPKd, .-_Z38__device_stub__Z15adicionarKernelPdPKdPdPKd
	.globl	_Z15adicionarKernelPdPKd
	.type	_Z15adicionarKernelPdPKd, @function
_Z15adicionarKernelPdPKd:
.LFB2054:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z15adicionarKernelPdPKdPdPKd
	.cfi_endproc
.LFE2054:
	.size	_Z15adicionarKernelPdPKd, .-_Z15adicionarKernelPdPKd
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC1:
	.string	"cudaSetDevice falhou!"
.LC2:
	.string	"cudaMalloc falhou!"
.LC3:
	.string	"cudaMemcpy falhou!"
.LC4:
	.string	"adicionarKernel falhou: %s"
.LC5:
	.string	"cudaDeviceSynchronize falhou: %d"
	.text
	.globl	_Z14calcularRaizesPdPKdj
	.type	_Z14calcularRaizesPdPKdj, @function
_Z14calcularRaizesPdPKdj:
.LFB2027:
	.cfi_startproc
	endbr64
	pushq	%r14
	.cfi_def_cfa_offset 16
	.cfi_offset 14, -16
	movq	%rsi, %r14
	pushq	%r13
	.cfi_def_cfa_offset 24
	.cfi_offset 13, -24
	movq	%rdi, %r13
	xorl	%edi, %edi
	pushq	%r12
	.cfi_def_cfa_offset 32
	.cfi_offset 12, -32
	movl	%edx, %r12d
	pushq	%rbp
	.cfi_def_cfa_offset 40
	.cfi_offset 6, -40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	.cfi_offset 3, -48
	subq	$48, %rsp
	.cfi_def_cfa_offset 96
	movq	%fs:40, %rax
	movq	%rax, 40(%rsp)
	xorl	%eax, %eax
	call	cudaSetDevice@PLT
	leaq	.LC1(%rip), %rsi
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L21
	movl	%r12d, %ebp
	leaq	8(%rsp), %rdi
	salq	$3, %rbp
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L23
	movq	%rsp, %rdi
	movq	%rbp, %rsi
	call	cudaMalloc@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L12
.L23:
	leaq	.LC2(%rip), %rsi
	jmp	.L21
.L12:
	movq	(%rsp), %rdi
	movl	$1, %ecx
	movq	%rbp, %rdx
	movq	%r14, %rsi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	jne	.L22
	movl	%r12d, 28(%rsp)
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movl	$1, %esi
	movabsq	$4294967297, %rdi
	movq	%rdi, 32(%rsp)
	movl	36(%rsp), %ecx
	movq	28(%rsp), %rdx
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L14
	movq	(%rsp), %rsi
	movq	8(%rsp), %rdi
	call	_Z38__device_stub__Z15adicionarKernelPdPKdPdPKd
.L14:
	call	cudaGetLastError@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L15
	movl	%eax, %edi
	call	cudaGetErrorString@PLT
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	movq	%rax, %rdx
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
.L15:
	call	cudaDeviceSynchronize@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L16
	movl	%eax, %edx
	leaq	.LC5(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	jmp	.L10
.L16:
	movq	8(%rsp), %rsi
	movl	$2, %ecx
	movq	%rbp, %rdx
	movq	%r13, %rdi
	call	cudaMemcpy@PLT
	movl	%eax, %ebx
	testl	%eax, %eax
	je	.L10
.L22:
	leaq	.LC3(%rip), %rsi
.L21:
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
.L10:
	movq	8(%rsp), %rdi
	call	cudaFree@PLT
	movq	(%rsp), %rdi
	call	cudaFree@PLT
	movq	40(%rsp), %rax
	subq	%fs:40, %rax
	je	.L19
	call	__stack_chk_fail@PLT
.L19:
	addq	$48, %rsp
	.cfi_def_cfa_offset 48
	movl	%ebx, %eax
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%rbp
	.cfi_def_cfa_offset 32
	popq	%r12
	.cfi_def_cfa_offset 24
	popq	%r13
	.cfi_def_cfa_offset 16
	popq	%r14
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2027:
	.size	_Z14calcularRaizesPdPKdj, .-_Z14calcularRaizesPdPKdj
	.section	.rodata.str1.1
.LC6:
	.string	"calcularRaizes falhou!"
.LC7:
	.string	"RESULTADO\n"
.LC8:
	.string	"Raiz de %f = %f\n"
.LC9:
	.string	"cudaDeviceReset falhou!"
	.section	.rodata
	.align 32
.LC0:
	.long	0
	.long	1072693248
	.long	0
	.long	1074790400
	.long	0
	.long	1075970048
	.long	0
	.long	1076887552
	.long	0
	.long	1077477376
	.long	0
	.long	1078067200
	.long	0
	.long	1078493184
	.long	0
	.long	1078984704
	.long	0
	.long	1079263232
	.long	0
	.long	1079574528
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2028:
	.cfi_startproc
	endbr64
	pushq	%r13
	.cfi_def_cfa_offset 16
	.cfi_offset 13, -16
	movl	$20, %ecx
	movl	$10, %edx
	leaq	.LC0(%rip), %rsi
	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	$184, %rsp
	.cfi_def_cfa_offset 224
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rdi
	leaq	8(%rsp), %r12
	rep movsl
	leaq	88(%rsp), %rbp
	leaq	88(%rsp), %rdi
	movq	%r12, %rsi
	movl	$20, %ecx
	rep stosl
	movq	%rbp, %rdi
	call	_Z14calcularRaizesPdPKdj
	testl	%eax, %eax
	je	.L25
	leaq	.LC6(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	jmp	.L34
.L25:
	leaq	.LC7(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	xorl	%ebx, %ebx
	call	__printf_chk@PLT
	leaq	.LC8(%rip), %r13
.L27:
	movsd	(%r12,%rbx), %xmm0
	movq	%r13, %rsi
	movl	$2, %edi
	movb	$2, %al
	movsd	0(%rbp,%rbx), %xmm1
	addq	$8, %rbx
	call	__printf_chk@PLT
	cmpq	$80, %rbx
	jne	.L27
	call	getchar@PLT
	call	cudaDeviceReset@PLT
	movl	%eax, %edx
	xorl	%eax, %eax
	testl	%edx, %edx
	je	.L24
	leaq	.LC9(%rip), %rsi
	movl	$2, %edi
.L34:
	call	__printf_chk@PLT
	movl	$1, %eax
.L24:
	movq	168(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L29
	call	__stack_chk_fail@PLT
.L29:
	addq	$184, %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
.LFE2028:
	.size	main, .-main
	.section	.rodata.str1.1
.LC10:
	.string	"_Z15adicionarKernelPdPKd"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2056:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC10(%rip), %rdx
	movq	%rax, %rdi
	leaq	_Z15adicionarKernelPdPKd(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2056:
	.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
	.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 <stdio.h>
#include <math.h>

__global__ void adicionarKernel(double* resultado, const double* n) {
	int i = threadIdx.x;
	double a = 1, b = 0;
	double delta = pow(b, 2) - (4 * a * (n[i] * -1));
	resultado[i] = ((b * -1) + sqrt(delta)) / 2 * a;
}

hipError_t calcularRaizes(double* resultado, const double* n, unsigned int tam) {
	double* gpu_n;
	double* gpu_resultado;
	hipError_t status;

	status = hipSetDevice(0);
	if (status != hipSuccess) {
		printf("hipSetDevice falhou!");
		goto Falha;
	}

	status = hipMalloc((void**)&gpu_resultado, tam * sizeof(double));
	if (status != hipSuccess) {
		printf("hipMalloc falhou!");
		goto Falha;
	}

	status = hipMalloc((void**)&gpu_n, tam * sizeof(double));
	if (status != hipSuccess) {
		printf("hipMalloc falhou!");
		goto Falha;
	}

	status = hipMemcpy(gpu_n, n, tam * sizeof(double), hipMemcpyHostToDevice);
	if (status != hipSuccess) {
		printf("hipMemcpy falhou!");
		goto Falha;
	}

	adicionarKernel<<<1, tam>>>(gpu_resultado, gpu_n);

	status = hipGetLastError();
	if (status != hipSuccess) {
		printf("adicionarKernel falhou: %s", hipGetErrorString(status));
		goto Falha;
	}

	status = hipDeviceSynchronize();
	if (status != hipSuccess) {
		printf("hipDeviceSynchronize falhou: %d", status);
		goto Falha;
	}

	status = hipMemcpy(resultado, gpu_resultado, tam * sizeof(double), hipMemcpyDeviceToHost);
	if (status != hipSuccess) {
		printf("hipMemcpy falhou!");
		goto Falha;
	}

Falha:
	hipFree(gpu_resultado);
	hipFree(gpu_n);

	return status;
}

int main()
{
	const int tam = 10;
	const double n[tam] = { 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 };
	double resultado[tam] = { 0 };

	hipError_t status = calcularRaizes(resultado, n, tam);
	if (status != hipSuccess) {
		printf("calcularRaizes falhou!");
		return 1;
;	}

	printf("RESULTADO\n");
	for (int i = 0; i < tam; i++) {
		printf("Raiz de %f = %f\n", n[i], resultado[i]);
	}

	getchar();

	status = hipDeviceReset();
	if (status != hipSuccess) {
		printf("hipDeviceReset falhou!");
		return 1;
	}

	return 0;
}
	.text
	.file	"raiz.hip"
	.globl	_Z30__device_stub__adicionarKernelPdPKd # -- Begin function _Z30__device_stub__adicionarKernelPdPKd
	.type	_Z30__device_stub__adicionarKernelPdPKd,@function
_Z30__device_stub__adicionarKernelPdPKd: # @_Z30__device_stub__adicionarKernelPdPKd
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%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	$_Z15adicionarKernelPdPKd, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z30__device_stub__adicionarKernelPdPKd, .Lfunc_end0-_Z30__device_stub__adicionarKernelPdPKd
	.cfi_endproc
                                        # -- End function
	.globl	_Z14calcularRaizesPdPKdj        # -- Begin function _Z14calcularRaizesPdPKdj
	.type	_Z14calcularRaizesPdPKdj,@function
_Z14calcularRaizesPdPKdj:               # @_Z14calcularRaizesPdPKdj
	.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
	movl	%edx, %ebp
	movq	%rsi, %r13
	movq	%rdi, %r14
	xorl	%edi, %edi
	callq	hipSetDevice
	testl	%eax, %eax
	je	.LBB1_2
# %bb.1:
	movl	%eax, %ebx
	movl	$.L.str, %edi
	jmp	.LBB1_15
.LBB1_2:
	movl	%ebp, %r12d
	leaq	(,%r12,8), %r15
	leaq	8(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	jne	.LBB1_3
# %bb.4:
	leaq	16(%rsp), %rdi
	movq	%r15, %rsi
	callq	hipMalloc
	testl	%eax, %eax
	je	.LBB1_5
.LBB1_3:
	movl	%eax, %ebx
	movl	$.L.str.1, %edi
.LBB1_15:
	xorl	%eax, %eax
	callq	printf
.LBB1_16:
	movq	8(%rsp), %rdi
	callq	hipFree
	movq	16(%rsp), %rdi
	callq	hipFree
	movl	%ebx, %eax
	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_5:
	.cfi_def_cfa_offset 80
	movq	16(%rsp), %rdi
	movq	%r13, %rsi
	movq	%r15, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	je	.LBB1_6
.LBB1_14:
	movl	%eax, %ebx
	movl	$.L.str.2, %edi
	jmp	.LBB1_15
.LBB1_6:
	btsq	$32, %r12
	movabsq	$4294967296, %rdi               # imm = 0x100000000
	orq	$1, %rdi
	movl	$1, %esi
	movq	%r12, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB1_8
# %bb.7:
	movq	8(%rsp), %rdi
	movq	16(%rsp), %rsi
	callq	_Z30__device_stub__adicionarKernelPdPKd
.LBB1_8:
	callq	hipGetLastError
	testl	%eax, %eax
	je	.LBB1_10
# %bb.9:
	movl	%eax, %ebx
	movl	%eax, %edi
	callq	hipGetErrorString
	movl	$.L.str.3, %edi
	movq	%rax, %rsi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_16
.LBB1_10:
	callq	hipDeviceSynchronize
	testl	%eax, %eax
	je	.LBB1_12
# %bb.11:
	movl	%eax, %ebx
	movl	$.L.str.4, %edi
	movl	%eax, %esi
	xorl	%eax, %eax
	callq	printf
	jmp	.LBB1_16
.LBB1_12:
	movq	8(%rsp), %rsi
	movq	%r14, %rdi
	movq	%r15, %rdx
	movl	$2, %ecx
	callq	hipMemcpy
	testl	%eax, %eax
	jne	.LBB1_14
# %bb.13:
	xorl	%ebx, %ebx
	jmp	.LBB1_16
.Lfunc_end1:
	.size	_Z14calcularRaizesPdPKdj, .Lfunc_end1-_Z14calcularRaizesPdPKdj
	.cfi_endproc
                                        # -- End function
	.globl	main                            # -- Begin function main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$160, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -16
	leaq	80(%rsp), %rax
	movl	$10, %ecx
	movl	$.L__const.main.n, %esi
	movq	%rax, %rdi
	rep;movsq (%rsi), %es:(%rdi)
	xorps	%xmm0, %xmm0
	movq	%rsp, %rdi
	movaps	%xmm0, 64(%rdi)
	movaps	%xmm0, 48(%rdi)
	movaps	%xmm0, 32(%rdi)
	movaps	%xmm0, 16(%rdi)
	movaps	%xmm0, (%rdi)
	movq	%rax, %rsi
	movl	$10, %edx
	callq	_Z14calcularRaizesPdPKdj
	movl	$.L.str.5, %edi
	testl	%eax, %eax
	jne	.LBB2_5
# %bb.1:
	movl	$.Lstr, %edi
	callq	puts@PLT
	xorl	%ebx, %ebx
.LBB2_2:                                # =>This Inner Loop Header: Depth=1
	movsd	80(%rsp,%rbx,8), %xmm0          # xmm0 = mem[0],zero
	movsd	(%rsp,%rbx,8), %xmm1            # xmm1 = mem[0],zero
	movl	$.L.str.7, %edi
	movb	$2, %al
	callq	printf
	incq	%rbx
	cmpq	$10, %rbx
	jne	.LBB2_2
# %bb.3:
	callq	getchar
	callq	hipDeviceReset
	movl	$.L.str.8, %edi
	testl	%eax, %eax
	je	.LBB2_4
.LBB2_5:                                # %.sink.split
	xorl	%eax, %eax
	callq	printf
	movl	$1, %eax
.LBB2_6:
	addq	$160, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	retq
.LBB2_4:
	.cfi_def_cfa_offset 176
	xorl	%eax, %eax
	jmp	.LBB2_6
.Lfunc_end2:
	.size	main, .Lfunc_end2-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	.LBB3_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rdi
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB3_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z15adicionarKernelPdPKd, %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_end3:
	.size	__hip_module_ctor, .Lfunc_end3-__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	.LBB4_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
.LBB4_2:
	retq
.Lfunc_end4:
	.size	__hip_module_dtor, .Lfunc_end4-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	_Z15adicionarKernelPdPKd,@object # @_Z15adicionarKernelPdPKd
	.section	.rodata,"a",@progbits
	.globl	_Z15adicionarKernelPdPKd
	.p2align	3, 0x0
_Z15adicionarKernelPdPKd:
	.quad	_Z30__device_stub__adicionarKernelPdPKd
	.size	_Z15adicionarKernelPdPKd, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"hipSetDevice falhou!"
	.size	.L.str, 21

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"hipMalloc falhou!"
	.size	.L.str.1, 18

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"hipMemcpy falhou!"
	.size	.L.str.2, 18

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"adicionarKernel falhou: %s"
	.size	.L.str.3, 27

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"hipDeviceSynchronize falhou: %d"
	.size	.L.str.4, 32

	.type	.L__const.main.n,@object        # @__const.main.n
	.section	.rodata,"a",@progbits
	.p2align	4, 0x0
.L__const.main.n:
	.quad	0x3ff0000000000000              # double 1
	.quad	0x4010000000000000              # double 4
	.quad	0x4022000000000000              # double 9
	.quad	0x4030000000000000              # double 16
	.quad	0x4039000000000000              # double 25
	.quad	0x4042000000000000              # double 36
	.quad	0x4048800000000000              # double 49
	.quad	0x4050000000000000              # double 64
	.quad	0x4054400000000000              # double 81
	.quad	0x4059000000000000              # double 100
	.size	.L__const.main.n, 80

	.type	.L.str.5,@object                # @.str.5
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str.5:
	.asciz	"calcularRaizes falhou!"
	.size	.L.str.5, 23

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"Raiz de %f = %f\n"
	.size	.L.str.7, 17

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"hipDeviceReset falhou!"
	.size	.L.str.8, 23

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

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

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

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"RESULTADO"
	.size	.Lstr, 10

	.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 _Z30__device_stub__adicionarKernelPdPKd
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym _Z15adicionarKernelPdPKd
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z15adicionarKernelPdPKd ; -- Begin function _Z15adicionarKernelPdPKd
	.globl	_Z15adicionarKernelPdPKd
	.p2align	8
	.type	_Z15adicionarKernelPdPKd,@function
_Z15adicionarKernelPdPKd:               ; @_Z15adicionarKernelPdPKd
; %bb.0:
	s_load_b128 s[0:3], s[0:1], 0x0
	v_lshlrev_b32_e32 v8, 3, v0
	s_waitcnt lgkmcnt(0)
	global_load_b64 v[0:1], v8, s[2:3]
	s_waitcnt vmcnt(0)
	v_fma_f64 v[0:1], v[0:1], 4.0, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_cmp_gt_f64_e32 vcc_lo, 0x10000000, v[0:1]
	v_cndmask_b32_e64 v2, 0, 1, vcc_lo
	v_lshlrev_b32_e32 v2, 8, v2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ldexp_f64 v[0:1], v[0:1], v2
	v_rsq_f64_e32 v[2:3], v[0:1]
	s_waitcnt_depctr 0xfff
	v_mul_f64 v[4:5], v[0:1], v[2:3]
	v_mul_f64 v[2:3], v[2:3], 0.5
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[6:7], -v[2:3], v[4:5], 0.5
	v_fma_f64 v[4:5], v[4:5], v[6:7], v[4:5]
	v_fma_f64 v[2:3], v[2:3], v[6:7], v[2:3]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[6:7], -v[4:5], v[4:5], v[0:1]
	v_fma_f64 v[4:5], v[6:7], v[2:3], v[4:5]
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_fma_f64 v[6:7], -v[4:5], v[4:5], v[0:1]
	v_fma_f64 v[2:3], v[6:7], v[2:3], v[4:5]
	v_cndmask_b32_e64 v4, 0, 0xffffff80, vcc_lo
	v_cmp_class_f64_e64 vcc_lo, v[0:1], 0x260
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_ldexp_f64 v[2:3], v[2:3], v4
	v_dual_cndmask_b32 v1, v3, v1 :: v_dual_cndmask_b32 v0, v2, v0
	s_delay_alu instid0(VALU_DEP_1)
	v_mul_f64 v[0:1], v[0:1], 0.5
	global_store_b64 v8, v[0:1], s[0:1]
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z15adicionarKernelPdPKd
		.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 9
		.amdhsa_next_free_sgpr 4
		.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	_Z15adicionarKernelPdPKd, .Lfunc_end0-_Z15adicionarKernelPdPKd
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 240
; NumSgprs: 6
; NumVgprs: 9
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 0
; VGPRBlocks: 1
; NumSGPRsForWavesPerEU: 6
; NumVGPRsForWavesPerEU: 9
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.section	.bss,"aw",@nobits
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
    .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:           _Z15adicionarKernelPdPKd
    .private_segment_fixed_size: 0
    .sgpr_count:     6
    .sgpr_spill_count: 0
    .symbol:         _Z15adicionarKernelPdPKd.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     9
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
