// File: kmiya[P]Needleman-Wunsch/src/BaseAlgorithms.cpp
// Function: needleman_wunsch_basealgorithms::BaseAlgorithms::AlignmentInit(needleman_wunsch_base::Base const&, needleman_wunsch_base::Base const&)
void BaseAlgorithms::AlignmentInit(const Base &inputSequence1, const Base &inputSequence2) {
  // set penalties and parameters
  kMatch    =   1;
  kMismatch =  -1;
  kGap      =  -1;
  kMatSizeX = inputSequence1.SequenceSize();
  kMatSizeY = inputSequence2.SequenceSize();
  kMatSize  = (kMatSizeX+1) * (kMatSizeY+1);
  scoreMatrix = new Score[ kMatSize ];
  // initialize scoreMatrix
  for ( unsigned int i = 0; i < kMatSize; ++i ) {
    scoreMatrix[i].score = 0;
    scoreMatrix[i].previousX = 0;
    scoreMatrix[i].previousY = 0;
    scoreMatrix[i].XAlignWithGap = -100;
    scoreMatrix[i].YAlignWithGap = -100;
  }
  // boundary conditions
  ComesFrom(0, 0, kOrigin);
  for ( unsigned int x = 1; x <= kMatSizeX; ++x ) {
    Mat(0, x)->score = kMismatch * static_cast<int>(x);
    ComesFrom(0, x, kEdgeTop);
  }
  for ( unsigned int y = 1; y <= kMatSizeY; ++y ) {
    Mat(y, 0)->score = kMismatch * static_cast<int>(y);
    ComesFrom(y, 0, kEdgeLeft);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movl $0x1, 0x18(%rax)
movl $0xffffffff, 0x1c(%rax) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
callq 0x2870
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x18(%rbp), %rdi
callq 0x2870
movl %eax, %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x28(%rax)
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movl 0x28(%rax), %edx
addl $0x1, %edx
imull %edx, %ecx
movl %ecx, 0x2c(%rax)
movl 0x2c(%rax), %eax
movl $0x14, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2040
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x1c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x2c(%rcx), %eax
jae 0x4323
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rcx
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movl $0x0, (%rcx)
movq 0x10(%rax), %rcx
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movl $0x0, 0x4(%rcx)
movq 0x10(%rax), %rcx
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movl $0x0, 0x8(%rcx)
movq 0x10(%rax), %rcx
movl -0x1c(%rbp), %edx
imulq $0x14, %rdx, %rdx
addq %rdx, %rcx
movl $0xffffff9c, 0xc(%rcx)  # imm = 0xFFFFFF9C
movq 0x10(%rax), %rax
movl -0x1c(%rbp), %ecx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0xffffff9c, 0x10(%rax) # imm = 0xFFFFFF9C
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x429d
movq -0x38(%rbp), %rdi
movl $0x0, -0x20(%rbp)
xorl %edx, %edx
leaq -0x20(%rbp), %rcx
movl %edx, %esi
callq 0x45b0
movl $0x1, -0x24(%rbp)
movq -0x38(%rbp), %rcx
movl -0x24(%rbp), %eax
cmpl 0x24(%rcx), %eax
ja 0x438f
movq -0x38(%rbp), %rdi
movl 0x1c(%rdi), %eax
imull -0x24(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x24(%rbp), %edx
xorl %esi, %esi
callq 0x4d20
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rdi
movl %ecx, (%rax)
movl -0x24(%rbp), %edx
movl $0x1, -0x28(%rbp)
xorl %esi, %esi
leaq -0x28(%rbp), %rcx
callq 0x45b0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4342
movl $0x1, -0x2c(%rbp)
movq -0x38(%rbp), %rcx
movl -0x2c(%rbp), %eax
cmpl 0x28(%rcx), %eax
ja 0x43e3
movq -0x38(%rbp), %rdi
movl 0x1c(%rdi), %eax
imull -0x2c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x2c(%rbp), %esi
xorl %edx, %edx
callq 0x4d20
movl -0x40(%rbp), %ecx
movq -0x38(%rbp), %rdi
movl %ecx, (%rax)
movl -0x2c(%rbp), %esi
movl $0x2, -0x30(%rbp)
xorl %edx, %edx
leaq -0x30(%rbp), %rcx
callq 0x45b0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4396
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)