#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include<chrono>
 

int main(void) {

    double gammaEulera = 0.; 
    double N = 1000000;;  

    auto start = std::chrono::high_resolution_clock::now();

        for (int i = 1; i < N; i++)
        gammaEulera = gammaEulera + (1. / (double)i); 

    gammaEulera = gammaEulera - log(N);

  auto finish = std::chrono::high_resolution_clock::now();
	std::chrono::duration<double> elapsed = finish - start;

    

    printf("Przyblizona wartosc eulera CPU wynosi %f \n",gammaEulera );
    printf("Czas wynosi %f",elapsed.count());
    return 0;
}

 
	.file	"tmpxft_0023a03a_00000000-6_euler-CPU.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3741:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3741:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC4:
	.string	"Przyblizona wartosc eulera CPU wynosi %f \n"
.LC5:
	.string	"Czas wynosi %f"
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB3734:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	subq	$16, %rsp
	.cfi_def_cfa_offset 32
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movsd	.LC1(%rip), %xmm3
	movl	$1, %edx
	xorps	%xmm0, %xmm0
	movq	%rax, %rbx
.L3:
	cvtsi2sdl	%edx, %xmm2
	movaps	%xmm3, %xmm1
	incl	%edx
	divsd	%xmm2, %xmm1
	addsd	%xmm1, %xmm0
	cmpl	$1000000, %edx
	jne	.L3
	subsd	.LC2(%rip), %xmm0
	movsd	%xmm0, 8(%rsp)
	call	_ZNSt6chrono3_V212system_clock3nowEv@PLT
	movsd	8(%rsp), %xmm0
	movl	$2, %edi
	leaq	.LC4(%rip), %rsi
	subq	%rbx, %rax
	cvtsi2sdq	%rax, %xmm1
	movb	$1, %al
	divsd	.LC3(%rip), %xmm1
	movq	%xmm1, %rbx
	call	__printf_chk@PLT
	movq	%rbx, %xmm0
	leaq	.LC5(%rip), %rsi
	movb	$1, %al
	movl	$2, %edi
	call	__printf_chk@PLT
	addq	$16, %rsp
	.cfi_def_cfa_offset 16
	xorl	%eax, %eax
	popq	%rbx
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3734:
	.size	main, .-main
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3764:
	.cfi_startproc
	endbr64
	pushq	%rax
	.cfi_def_cfa_offset 16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	movq	%rax, %rdi
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rdx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE3764:
	.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
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC1:
	.long	0
	.long	1072693248
	.align 8
.LC2:
	.long	-1718616160
	.long	1076601226
	.align 8
.LC3:
	.long	0
	.long	1104006501
	.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 <iostream>
#include <cstdlib>
#include<chrono>
 

int main(void) {

    double gammaEulera = 0.; 
    double N = 1000000;;  

    auto start = std::chrono::high_resolution_clock::now();

        for (int i = 1; i < N; i++)
        gammaEulera = gammaEulera + (1. / (double)i); 

    gammaEulera = gammaEulera - log(N);

  auto finish = std::chrono::high_resolution_clock::now();
	std::chrono::duration<double> elapsed = finish - start;

    

    printf("Przyblizona wartosc eulera CPU wynosi %f \n",gammaEulera );
    printf("Czas wynosi %f",elapsed.count());
    return 0;
}

 
	.text
	.file	"euler-CPU.hip"
                                        # Start of file scope inline assembly
	.globl	_ZSt21ios_base_library_initv

                                        # End of file scope inline assembly
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI0_0:
	.quad	0x3ff0000000000000              # double 1
.LCPI0_1:
	.quad	0xc02ba18a998fffa0              # double -13.815510557964274
.LCPI0_2:
	.quad	0x41cdcd6500000000              # double 1.0E+9
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%rbx
	.cfi_def_cfa_offset 24
	subq	$24, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -24
	.cfi_offset %rbp, -16
	movl	$999999, %ebp                   # imm = 0xF423F
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	movsd	.LCPI0_0(%rip), %xmm3           # xmm3 = mem[0],zero
	xorpd	%xmm2, %xmm2
	movq	%rax, %rbx
	movapd	%xmm3, %xmm0
.LBB0_1:                                # =>This Inner Loop Header: Depth=1
	movapd	%xmm3, %xmm1
	divsd	%xmm0, %xmm1
	addsd	%xmm1, %xmm2
	addsd	%xmm3, %xmm0
	decl	%ebp
	jne	.LBB0_1
# %bb.2:
	addsd	.LCPI0_1(%rip), %xmm2
	movsd	%xmm2, 16(%rsp)                 # 8-byte Spill
	callq	_ZNSt6chrono3_V212system_clock3nowEv
	subq	%rbx, %rax
	xorps	%xmm0, %xmm0
	cvtsi2sd	%rax, %xmm0
	divsd	.LCPI0_2(%rip), %xmm0
	movsd	%xmm0, 8(%rsp)                  # 8-byte Spill
	movl	$.L.str, %edi
	movsd	16(%rsp), %xmm0                 # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	movl	$.L.str.1, %edi
	movsd	8(%rsp), %xmm0                  # 8-byte Reload
                                        # xmm0 = mem[0],zero
	movb	$1, %al
	callq	printf
	xorl	%eax, %eax
	addq	$24, %rsp
	.cfi_def_cfa_offset 24
	popq	%rbx
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
	.cfi_endproc
                                        # -- End function
	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"Przyblizona wartosc eulera CPU wynosi %f \n"
	.size	.L.str, 43

	.type	.L.str.1,@object                # @.str.1
.L.str.1:
	.asciz	"Czas wynosi %f"
	.size	.L.str.1, 15

	.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 __hip_cuid_

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

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

	.end_amdgpu_metadata
