////////////////////////////////////////////////////////////////////////////
// Calculate scalar products of VectorN vectors of ElementN elements on CPU.
// Straight accumulation in double precision.
////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <cmath>
using namespace std;


void Kernel_1_CPU(int *A, int *B, int& Max_CPU, int LA, int LB, int sim, int dissim, int Gop, int Gex)					  

{
	int i,j,S1,H1,EF, H_Max	;

	int *F, *E, *H;
	F = new int [LA];
	E = new int [LA+1];
	H = new int [(LA+1)*2];
	Max_CPU = 0;

	for (j=0; j<LA; j++){
	F[j]=0;
	E[j]=0;
	}
	E[LA+1]=0;


	for (j=0; j<(2*(LA+1)); j++)
	H[j]=0;

	for (i=0; i<LB; i++)
	{
		for (j=0; j<LA; j++)
		{
			if (A[j]==B[i])
			S1=H[j]+sim;
			else 
			S1=H[j]+dissim;
			H1=max(S1,0);
			F[j]=max(F[j]-Gex,H[j+1]-Gop);
			E[j+1]=max(E[j]-Gex,H[(LA+1)+j]-Gop);
			EF=max(F[j],E[j+1]);
			H[(LA+1)+j+1]=max(EF,H1);
		}
		for (j=1; j<(LA+1); j++)
		{
			H[j]=H[(LA+1)+j];
			H_Max = H[j];

			if ((H_Max>1) && (H_Max>Max_CPU))
			{
				Max_CPU=H_Max;
			}
		}
	}
}

/*	 printf("No. Sim. Val.  Seq. A    Seq. B \n");
	 printf("-------------------------------- \n");
    for( i = 1; i < (K1_Max_Report+1); ++i)     
    {
   		 printf(" %i     %i       %i       %i \n", i, Max_CPU[K1_Max_Report-i],int(fmod(1.0*End_Point[K1_Max_Report-i],(LA+1))), int(1.0*(End_Point[K1_Max_Report-i])/(LA+1)));
    }  */



//		cout<<A[j]<<"-----"<<B[i]<<"-----"<<F[j]<<"------"<<E[j]<<endl;	

	.file	"tmpxft_002f3d8d_00000000-6_Kernel_1_CPU.cudafe1.cpp"
	.text
#APP
	.globl _ZSt21ios_base_library_initv

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB3638:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE3638:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z12Kernel_1_CPUPiS_Riiiiiii
	.type	_Z12Kernel_1_CPUPiS_Riiiiiii, @function
_Z12Kernel_1_CPUPiS_Riiiiiii:
.LFB3635:
	.cfi_startproc
	endbr64
	movabsq	$2305843009213693950, %rax
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movslq	%ecx, %rbx
	subq	$40, %rsp
	.cfi_def_cfa_offset 96
	movl	%r8d, 12(%rsp)
	movl	%r9d, 28(%rsp)
	cmpq	%rbx, %rax
	jb	.L3
	movq	%rbx, %rbp
	salq	$2, %rbx
	movq	%rdi, %r13
	movq	%rsi, %r14
	movq	%rbx, %rdi
	movq	%rdx, %r15
	call	_Znam@PLT
	leaq	4(%rbx), %rdi
	movq	%rax, 16(%rsp)
	call	_Znam@PLT
	leal	2(%rbp,%rbp), %ecx
	movslq	%ecx, %rdi
	movl	%ecx, 24(%rsp)
	movq	%rax, %r12
	salq	$2, %rdi
	call	_Znam@PLT
	xorl	%ecx, %ecx
	movq	16(%rsp), %r8
	movl	28(%rsp), %r9d
	movl	%ecx, (%r15)
	movq	%rax, %rsi
	movl	24(%rsp), %ecx
	xorl	%eax, %eax
	jmp	.L4
.L3:
	call	__cxa_throw_bad_array_new_length@PLT
.L4:
	cmpl	%eax, %ebp
	jle	.L17
	xorl	%edx, %edx
	movl	%edx, (%r8,%rax,4)
	movl	%edx, (%r12,%rax,4)
	incq	%rax
	jmp	.L4
.L17:
	xorl	%eax, %eax
	salq	$2, %rcx
	movq	%rsi, %rdi
	movl	%eax, 4(%r12,%rbx)
	xorl	%eax, %eax
	addq	%rsi, %rbx
	rep stosb
	xorl	%edi, %edi
.L6:
	cmpl	%edi, 12(%rsp)
	jle	.L18
	xorl	%edx, %edx
.L13:
	cmpl	%edx, %ebp
	jle	.L19
	movl	(%rsi,%rdx,4), %eax
	movl	96(%rsp), %r11d
	movl	(%r14,%rdi,4), %ecx
	addl	%eax, %r11d
	cmpl	%ecx, 0(%r13,%rdx,4)
	jne	.L8
	leal	(%r9,%rax), %r11d
.L8:
	movl	4(%rsi,%rdx,4), %ecx
	movl	(%r8,%rdx,4), %eax
	subl	104(%rsp), %ecx
	subl	112(%rsp), %eax
	cmpl	%eax, %ecx
	movl	(%r12,%rdx,4), %r10d
	cmovl	%eax, %ecx
	movl	4(%rbx,%rdx,4), %eax
	subl	112(%rsp), %r10d
	subl	104(%rsp), %eax
	cmpl	%r10d, %eax
	movl	%ecx, (%r8,%rdx,4)
	cmovl	%r10d, %eax
	cmpl	%eax, %ecx
	movl	%eax, 4(%r12,%rdx,4)
	cmovge	%ecx, %eax
	xorl	%ecx, %ecx
	testl	%eax, %eax
	cmovs	%ecx, %eax
	cmpl	%r11d, %eax
	cmovl	%r11d, %eax
	movl	%eax, 8(%rbx,%rdx,4)
	incq	%rdx
	jmp	.L13
.L19:
	movl	$1, %eax
.L10:
	cmpl	%eax, %ebp
	jl	.L20
	movl	4(%rbx,%rax,4), %edx
	movl	%edx, (%rsi,%rax,4)
	cmpl	$1, %edx
	jle	.L11
	cmpl	(%r15), %edx
	jle	.L11
	movl	%edx, (%r15)
.L11:
	incq	%rax
	jmp	.L10
.L20:
	incq	%rdi
	jmp	.L6
.L18:
	addq	$40, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE3635:
	.size	_Z12Kernel_1_CPUPiS_Riiiiiii, .-_Z12Kernel_1_CPUPiS_Riiiiiii
	.section	.text.startup,"ax",@progbits
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB3661:
	.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
.LFE3661:
	.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:

////////////////////////////////////////////////////////////////////////////
// Calculate scalar products of VectorN vectors of ElementN elements on CPU.
// Straight accumulation in double precision.
////////////////////////////////////////////////////////////////////////////

#include <hip/hip_runtime.h>
#include <iostream>
#include <cmath>
using namespace std;


void Kernel_1_CPU(int *A, int *B, int& Max_CPU, int LA, int LB, int sim, int dissim, int Gop, int Gex)					  

{
	int i,j,S1,H1,EF, H_Max	;

	int *F, *E, *H;
	F = new int [LA];
	E = new int [LA+1];
	H = new int [(LA+1)*2];
	Max_CPU = 0;

	for (j=0; j<LA; j++){
	F[j]=0;
	E[j]=0;
	}
	E[LA+1]=0;


	for (j=0; j<(2*(LA+1)); j++)
	H[j]=0;

	for (i=0; i<LB; i++)
	{
		for (j=0; j<LA; j++)
		{
			if (A[j]==B[i])
			S1=H[j]+sim;
			else 
			S1=H[j]+dissim;
			H1=max(S1,0);
			F[j]=max(F[j]-Gex,H[j+1]-Gop);
			E[j+1]=max(E[j]-Gex,H[(LA+1)+j]-Gop);
			EF=max(F[j],E[j+1]);
			H[(LA+1)+j+1]=max(EF,H1);
		}
		for (j=1; j<(LA+1); j++)
		{
			H[j]=H[(LA+1)+j];
			H_Max = H[j];

			if ((H_Max>1) && (H_Max>Max_CPU))
			{
				Max_CPU=H_Max;
			}
		}
	}
}

/*	 printf("No. Sim. Val.  Seq. A    Seq. B \n");
	 printf("-------------------------------- \n");
    for( i = 1; i < (K1_Max_Report+1); ++i)     
    {
   		 printf(" %i     %i       %i       %i \n", i, Max_CPU[K1_Max_Report-i],int(fmod(1.0*End_Point[K1_Max_Report-i],(LA+1))), int(1.0*(End_Point[K1_Max_Report-i])/(LA+1)));
    }  */



//		cout<<A[j]<<"-----"<<B[i]<<"-----"<<F[j]<<"------"<<E[j]<<endl;	

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

                                        # End of file scope inline assembly
	.globl	_Z12Kernel_1_CPUPiS_Riiiiiii    # -- Begin function _Z12Kernel_1_CPUPiS_Riiiiiii
	.type	_Z12Kernel_1_CPUPiS_Riiiiiii,@function
_Z12Kernel_1_CPUPiS_Riiiiiii:           # @_Z12Kernel_1_CPUPiS_Riiiiiii
	.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	$72, %rsp
	.cfi_def_cfa_offset 128
	.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	%r9d, 28(%rsp)                  # 4-byte Spill
	movl	%r8d, 8(%rsp)                   # 4-byte Spill
	movl	%ecx, %r15d
	movq	%rdx, 32(%rsp)                  # 8-byte Spill
	movq	%rsi, 56(%rsp)                  # 8-byte Spill
	movq	%rdi, 64(%rsp)                  # 8-byte Spill
	movl	%ecx, %eax
	movq	%rax, %r13
	leaq	(,%rax,4), %rdi
	testl	%ecx, %ecx
	movq	$-1, %r12
	movq	%rdi, 48(%rsp)                  # 8-byte Spill
	cmovsq	%r12, %rdi
	callq	_Znam
	movq	%rax, %rbp
	leal	1(%r15), %eax
	movl	%eax, 16(%rsp)                  # 4-byte Spill
	cltq
	movq	%rax, (%rsp)                    # 8-byte Spill
	leaq	(,%rax,4), %rdi
	leal	2(,%r15,2), %ebx
	movslq	%ebx, %r14
	shlq	$2, %r14
	cmpl	$-1, %r15d
	cmovlq	%r12, %rdi
	cmovlq	%r12, %r14
	callq	_Znam
	movq	%rax, %r12
	movq	%r14, %rdi
	callq	_Znam
	movq	%rax, %r14
	movq	32(%rsp), %rax                  # 8-byte Reload
	movl	$0, (%rax)
	movq	%r15, 40(%rsp)                  # 8-byte Spill
	testl	%r15d, %r15d
	jle	.LBB0_2
# %bb.1:                                # %._crit_edge.thread
	movq	%rbp, %rdi
	xorl	%esi, %esi
	movq	48(%rsp), %r15                  # 8-byte Reload
	movq	%r15, %rdx
	callq	memset@PLT
	movq	%r12, %rdi
	xorl	%esi, %esi
	movq	%r15, %rdx
	callq	memset@PLT
	movq	(%rsp), %rax                    # 8-byte Reload
	movl	$0, (%r12,%rax,4)
	jmp	.LBB0_3
.LBB0_2:                                # %._crit_edge
	movq	(%rsp), %rax                    # 8-byte Reload
	movl	$0, (%r12,%rax,4)
	js	.LBB0_4
.LBB0_3:                                # %.lr.ph86.preheader
	cmpl	$2, %ebx
	movl	$1, %edx
	cmovgel	%ebx, %edx
	shlq	$2, %rdx
	movq	%r14, %rdi
	xorl	%esi, %esi
	callq	memset@PLT
.LBB0_4:                                # %.preheader82
	movl	8(%rsp), %edx                   # 4-byte Reload
	testl	%edx, %edx
	movq	40(%rsp), %rdi                  # 8-byte Reload
	jle	.LBB0_27
# %bb.5:                                # %.preheader81.lr.ph
	movl	144(%rsp), %eax
	movl	136(%rsp), %ecx
	movl	16(%rsp), %r11d                 # 4-byte Reload
	movl	%edx, %edx
	movq	%rdx, (%rsp)                    # 8-byte Spill
	leaq	(%r14,%r11,4), %r8
	xorl	%ebx, %ebx
	xorl	%r10d, %r10d
	movq	%r11, 16(%rsp)                  # 8-byte Spill
.LBB0_6:                                # %.preheader81
                                        # =>This Loop Header: Depth=1
                                        #     Child Loop BB0_8 Depth 2
                                        #     Child Loop BB0_22 Depth 2
	testl	%edi, %edi
	jle	.LBB0_26
# %bb.7:                                # %.lr.ph88
                                        #   in Loop: Header=BB0_6 Depth=1
	movq	56(%rsp), %rdx                  # 8-byte Reload
	movq	%rbx, 8(%rsp)                   # 8-byte Spill
	movl	(%rdx,%rbx,4), %r11d
	movl	(%r8), %edi
	movl	(%r12), %esi
	xorl	%edx, %edx
.LBB0_8:                                #   Parent Loop BB0_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	28(%rsp), %ebx                  # 4-byte Reload
	movq	64(%rsp), %r9                   # 8-byte Reload
	cmpl	%r11d, (%r9,%rdx,4)
	je	.LBB0_10
# %bb.9:                                #   in Loop: Header=BB0_8 Depth=2
	movl	128(%rsp), %ebx
.LBB0_10:                               #   in Loop: Header=BB0_8 Depth=2
	addl	(%r14,%rdx,4), %ebx
	movl	(%rbp,%rdx,4), %r15d
	subl	%eax, %r15d
	movl	4(%r14,%rdx,4), %r9d
	subl	%ecx, %r9d
	cmpl	%r9d, %r15d
	cmovgl	%r15d, %r9d
	movl	%r9d, (%rbp,%rdx,4)
	subl	%eax, %esi
	subl	%ecx, %edi
	cmpl	%edi, %esi
	jg	.LBB0_12
# %bb.11:                               #   in Loop: Header=BB0_8 Depth=2
	movl	%edi, %esi
.LBB0_12:                               #   in Loop: Header=BB0_8 Depth=2
	movl	%esi, 4(%r12,%rdx,4)
	cmpl	%esi, %r9d
	jg	.LBB0_14
# %bb.13:                               #   in Loop: Header=BB0_8 Depth=2
	movl	%esi, %r9d
.LBB0_14:                               #   in Loop: Header=BB0_8 Depth=2
	cmpl	%r9d, %ebx
	jg	.LBB0_16
# %bb.15:                               #   in Loop: Header=BB0_8 Depth=2
	movl	%r9d, %ebx
.LBB0_16:                               #   in Loop: Header=BB0_8 Depth=2
	testl	%ebx, %ebx
	jg	.LBB0_18
# %bb.17:                               #   in Loop: Header=BB0_8 Depth=2
	xorl	%ebx, %ebx
.LBB0_18:                               #   in Loop: Header=BB0_8 Depth=2
	movl	%ebx, 4(%r8,%rdx,4)
	incq	%rdx
	movl	%ebx, %edi
	cmpq	%rdx, %r13
	jne	.LBB0_8
# %bb.19:                               # %.preheader
                                        #   in Loop: Header=BB0_6 Depth=1
	movq	40(%rsp), %rdi                  # 8-byte Reload
	testl	%edi, %edi
	movq	16(%rsp), %r11                  # 8-byte Reload
	jle	.LBB0_20
# %bb.21:                               # %.lr.ph91.preheader
                                        #   in Loop: Header=BB0_6 Depth=1
	movl	$1, %edx
	movq	32(%rsp), %r9                   # 8-byte Reload
	movq	8(%rsp), %rbx                   # 8-byte Reload
.LBB0_22:                               # %.lr.ph91
                                        #   Parent Loop BB0_6 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movl	(%r8,%rdx,4), %esi
	movl	%esi, (%r14,%rdx,4)
	cmpl	$2, %esi
	jl	.LBB0_25
# %bb.23:                               # %.lr.ph91
                                        #   in Loop: Header=BB0_22 Depth=2
	cmpl	%r10d, %esi
	jle	.LBB0_25
# %bb.24:                               #   in Loop: Header=BB0_22 Depth=2
	movl	%esi, (%r9)
	movl	%esi, %r10d
.LBB0_25:                               #   in Loop: Header=BB0_22 Depth=2
	incq	%rdx
	cmpq	%rdx, %r11
	jne	.LBB0_22
	jmp	.LBB0_26
.LBB0_20:                               #   in Loop: Header=BB0_6 Depth=1
	movq	8(%rsp), %rbx                   # 8-byte Reload
.LBB0_26:                               # %._crit_edge92
                                        #   in Loop: Header=BB0_6 Depth=1
	incq	%rbx
	cmpq	(%rsp), %rbx                    # 8-byte Folded Reload
	jne	.LBB0_6
.LBB0_27:                               # %._crit_edge100
	addq	$72, %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
.Lfunc_end0:
	.size	_Z12Kernel_1_CPUPiS_Riiiiiii, .Lfunc_end0-_Z12Kernel_1_CPUPiS_Riiiiiii
	.cfi_endproc
                                        # -- End function
	.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
