// File: kmiya[P]Needleman-Wunsch/src/BaseAlgorithms.cpp
// Function: needleman_wunsch_basealgorithms::BaseAlgorithms::TracebackRecursive(int, int, needleman_wunsch_base::Base const&, needleman_wunsch_base::Base const&)
void BaseAlgorithms::TracebackRecursive(const int y, const int x,
                                        const Base &inputSequence1, const Base &inputSequence2) {
  cout << "(" << y << "," << x << ")->";
  if ( !y && !x ) {
    cout << "Tracebacking end.\n\n";
    return;
  }
  TracebackRecursive(Mat(y, x)->previousY, Mat(y, x)->previousX,
                     inputSequence1, inputSequence2);
  // insert gaps
  if ( Mat(y, x)->XAlignWithGap ) {
    resultX->SetBase(g);
    if ( !y ) { // first string
      resultY->SetBase(inputSequence2.GetBase(y));
    } else {
      resultY->SetBase(inputSequence2.GetBase(y-1));
    }
  } else if ( Mat(y, x)->YAlignWithGap ) {
    if ( !x ) { // first string
      resultX->SetBase(inputSequence1.GetBase(x));
    } else {
      resultX->SetBase(inputSequence1.GetBase(x-1));
    }
    resultY->SetBase(g);
  } else { // if bases matched
    resultX->SetBase(inputSequence1.GetBase(x-1));
    resultY->SetBase(inputSequence2.GetBase(y-1));
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq 0x4777(%rip), %rdi      # 0x8fd0
leaq 0x1896(%rip), %rsi      # 0x60f6
callq 0x21b0
movq %rax, %rdi
movl -0xc(%rbp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x186c(%rip), %rsi      # 0x60e6
callq 0x21b0
movq %rax, %rdi
movl -0x10(%rbp), %esi
callq 0x2320
movq %rax, %rdi
leaq 0x1864(%rip), %rsi      # 0x60f8
callq 0x21b0
cmpl $0x0, -0xc(%rbp)
jne 0x48bd
cmpl $0x0, -0x10(%rbp)
jne 0x48bd
movq 0x4724(%rip), %rdi      # 0x8fd0
leaq 0x1849(%rip), %rsi      # 0x60fc
callq 0x21b0
jmp 0x4a39
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x4d20
movq -0x28(%rbp), %rdi
movl 0x8(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x4d20
movl -0x2c(%rbp), %esi
movq -0x28(%rbp), %rdi
movl 0x4(%rax), %edx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
callq 0x4830
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x4d20
cmpl $0x0, 0xc(%rax)
je 0x4974
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movl $0x4, %esi
callq 0x2810
cmpl $0x0, -0xc(%rbp)
jne 0x4949
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
callq 0x2840
movq -0x38(%rbp), %rdi
movl %eax, %esi
callq 0x2810
jmp 0x496f
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
subl $0x1, %esi
callq 0x2840
movq -0x40(%rbp), %rdi
movl %eax, %esi
callq 0x2810
jmp 0x4a39
movq -0x28(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x4d20
cmpl $0x0, 0x10(%rax)
je 0x49ec
cmpl $0x0, -0x10(%rbp)
jne 0x49b3
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x2840
movq -0x48(%rbp), %rdi
movl %eax, %esi
callq 0x2810
jmp 0x49d8
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
subl $0x1, %esi
callq 0x2840
movq -0x50(%rbp), %rdi
movl %eax, %esi
callq 0x2810
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x4, %esi
callq 0x2810
jmp 0x4a37
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rdi
movl -0x10(%rbp), %esi
subl $0x1, %esi
callq 0x2840
movq -0x60(%rbp), %rdi
movl %eax, %esi
callq 0x2810
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
movl -0xc(%rbp), %esi
subl $0x1, %esi
callq 0x2840
movq -0x58(%rbp), %rdi
movl %eax, %esi
callq 0x2810
jmp 0x4a39
addq $0x60, %rsp
popq %rbp
retq
nop