// File: ikatanic[P]lcskpp/main.cpp
// Function: main
int main(int argc, char** argv) {
  if (argc != 5) {
    printf(
      "Compute LCSk++ of two plain texts.\n\n"
      "Usage: ./main k input1 input2 output\n\n"
      "Example: ./main 4 test/tests/test.1.A test/tests/test.1.B out\n"
      "finds LCS4++ of files `test/tests/test.1.A` and `test/tests/test.1.B`\n"
      "and writes it to `out`\n"
    );
    return 0;
  };


  int k = stoi(argv[1]);
  ifstream infile1(argv[2]);
  string A;
  getline(infile1, A);
  
  ifstream infile2(argv[3]);
  string B;
  getline(infile2, B);

  printf("Sequence 1 length: %d\n", (int)A.size());
  printf("Sequence 2 length: %d\n", (int)B.size());
  printf("Computing LCSk++..\n");
  
  vector<pair<int, int>> recon;
  int length = lcskpp(A, B, k, &recon);

  printf("LCSk++ length: %d\n", length);
  
  auto r = freopen(argv[4], "w", stdout);
  for (auto& p: recon) {
    putchar(A[p.first]);
  }
  return 0;
}

// Assembly:
subq $0x538, %rsp            # imm = 0x538
movl $0x0, 0x534(%rsp)
movl %edi, 0x530(%rsp)
movq %rsi, 0x528(%rsp)
cmpl $0x5, 0x530(%rsp)
je 0xadf9
leaq 0x139c(%rip), %rdi      # 0xc17e
movb $0x0, %al
callq 0x2040
movl $0x0, 0x534(%rsp)
jmp 0xb180
movq 0x528(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x40(%rsp)
leaq 0x4ff(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x2220
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
leaq 0x500(%rsp), %rdi
callq 0x2180
jmp 0xae35
xorl %eax, %eax
movl %eax, %esi
leaq 0x500(%rsp), %rdi
movl $0xa, %edx
callq 0xb1a0
movl %eax, 0x3c(%rsp)
jmp 0xae51
leaq 0x500(%rsp), %rdi
callq 0x20e0
leaq 0x4ff(%rsp), %rdi
callq 0x2160
movl 0x3c(%rsp), %eax
movl %eax, 0x524(%rsp)
movq 0x528(%rsp), %rax
movq 0x10(%rax), %rsi
leaq 0x2e0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movl $0x8, %edx
callq 0x2230
leaq 0x2c0(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x2190
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x2050
jmp 0xaebc
movq 0x528(%rsp), %rax
movq 0x18(%rax), %rsi
leaq 0xb8(%rsp), %rdi
movl $0x8, %edx
callq 0x2230
jmp 0xaedc
leaq 0x98(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x2190
movq 0x20(%rsp), %rsi
leaq 0xb8(%rsp), %rdi
callq 0x2050
jmp 0xaf02
leaq 0x2c0(%rsp), %rdi
callq 0x2100
movl %eax, %esi
leaq 0x134c(%rip), %rdi      # 0xc264
xorl %eax, %eax
callq 0x2040
jmp 0xaf21
leaq 0x98(%rsp), %rdi
callq 0x2100
movl %eax, %esi
leaq 0x1344(%rip), %rdi      # 0xc27b
xorl %eax, %eax
callq 0x2040
jmp 0xaf40
leaq 0x134b(%rip), %rdi      # 0xc292
xorl %eax, %eax
callq 0x2040
jmp 0xaf50
leaq 0x80(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x6210
movq 0x10(%rsp), %rcx
movl 0x524(%rsp), %edx
leaq 0x2c0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x44d0
movl %eax, 0x1c(%rsp)
jmp 0xaf89
movl 0x1c(%rsp), %eax
movl %eax, 0x7c(%rsp)
movl 0x7c(%rsp), %esi
leaq 0x130a(%rip), %rdi      # 0xc2a6
xorl %eax, %eax
callq 0x2040
jmp 0xafa5
movq 0x528(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x6000(%rip), %rax      # 0x10fb8
movq (%rax), %rdx
leaq 0x12f7(%rip), %rsi      # 0xc2b9
callq 0x2150
movq %rax, 0x8(%rsp)
jmp 0xafce
movq 0x8(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
callq 0x5b50
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rdi
callq 0x5bc0
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x6090
testb $0x1, %al
jne 0xb01b
jmp 0xb0fc
leaq 0x60(%rsp), %rdi
callq 0x60d0
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movslq (%rax), %rsi
leaq 0x2c0(%rsp), %rdi
callq 0x2240
movq %rax, (%rsp)
jmp 0xb045
movq (%rsp), %rax
movsbl (%rax), %edi
callq 0x21a0
jmp 0xb053
jmp 0xb055
leaq 0x60(%rsp), %rdi
callq 0x60e0
jmp 0xb003
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4f0(%rsp)
movl %eax, 0x4ec(%rsp)
jmp 0xb098
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4f0(%rsp)
movl %eax, 0x4ec(%rsp)
leaq 0x500(%rsp), %rdi
callq 0x20e0
leaq 0x4ff(%rsp), %rdi
callq 0x2160
jmp 0xb18f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4f0(%rsp)
movl %eax, 0x4ec(%rsp)
jmp 0xb164
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4f0(%rsp)
movl %eax, 0x4ec(%rsp)
jmp 0xb14a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4f0(%rsp)
movl %eax, 0x4ec(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x61b0
jmp 0xb14a
movl $0x0, 0x534(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x61b0
leaq 0x98(%rsp), %rdi
callq 0x20e0
leaq 0xb8(%rsp), %rdi
callq 0x2060
leaq 0x2c0(%rsp), %rdi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
callq 0x2060
jmp 0xb180
leaq 0x98(%rsp), %rdi
callq 0x20e0
leaq 0xb8(%rsp), %rdi
callq 0x2060
leaq 0x2c0(%rsp), %rdi
callq 0x20e0
leaq 0x2e0(%rsp), %rdi
callq 0x2060
jmp 0xb18f
movl 0x534(%rsp), %eax
addq $0x538, %rsp            # imm = 0x538
retq
movq 0x4f0(%rsp), %rdi
callq 0x2210
nopl (%rax)