// File: /workspace/github_cpp_makefile_star2_O2/fpavetic[P]lcskpp/lcskpp.cpp
// Function: fill_lcskpp_reconstruction(std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>> const&, int, std::vector<int, std::allocator<int>> const&, int, int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>*)
static void fill_lcskpp_reconstruction(
    const vector<pair<int, int> >& matches,
    const int k,
    const vector<int>& prev_idx,
    const int last_idx,
    const int lcskpp_len,
    vector<pair<int, int> >* lcskpp_recon) {
  assert(lcskpp_recon != NULL);
  lcskpp_recon->clear();
  lcskpp_recon->reserve(lcskpp_len);

  for (int i = last_idx; i != -1; i = prev_idx[i]) {
    int r = matches[i].first+k-1;
    int c = matches[i].second+k-1;

    if (prev_idx[i] == -1 || 
        (matches[prev_idx[i]].first + k <= matches[i].first &&
         matches[prev_idx[i]].second + k <= matches[i].second)) {
      // Taking the entire match ...
      for (int j = 0; j < k; ++j, --r, --c) {
        lcskpp_recon->push_back(make_pair(r, c));
      }
    } else { 
      // ... otherwise it is a continuation. Only the
      // difference is taken.
      int curr = i;
      int prev = prev_idx[i];

      int curr_secondary_diag = 
        (matches[curr].first + matches[curr].second) / 2;
      int prev_secondary_diag = 
        (matches[prev].first + matches[prev].second) / 2;
      assert(prev_secondary_diag < curr_secondary_diag);

      for (int j = prev_secondary_diag; 
           j < curr_secondary_diag; ++j, --r, --c) {
        lcskpp_recon->push_back(make_pair(r, c));
      }
    }
  }

  reverse(lcskpp_recon->begin(), lcskpp_recon->end());
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, %rbx
movl %ecx, %ebp
movq %rdx, 0x18(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, 0x30(%rsp)
movq (%r9), %rax
cmpq %rax, 0x8(%r9)
je 0x3a5f
movq %rax, 0x8(%rbx)
movslq %r8d, %rsi
movq %rbx, %rdi
callq 0x49e8
movq 0x8(%rsp), %rax
leal -0x1(%rax), %ecx
movq %rcx, 0x28(%rsp)
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
movl %ecx, 0x14(%rsp)
leaq 0x20(%rsp), %r13
cmpl $-0x1, %ebp
je 0x3b5e
movslq %ebp, %r15
movq 0x30(%rsp), %rax
movq (%rax), %rcx
movl (%rcx,%r15,8), %edx
movl 0x4(%rcx,%r15,8), %eax
movq 0x28(%rsp), %rsi
leal (%rsi,%rdx), %r14d
leal (%rsi,%rax), %r12d
movq 0x18(%rsp), %rsi
movq (%rsi), %rsi
movslq (%rsi,%r15,4), %rdi
cmpq $-0x1, %rdi
je 0x3ae0
movl (%rcx,%rdi,8), %esi
movl 0x4(%rcx,%rdi,8), %ecx
movq 0x8(%rsp), %rdi
addl %esi, %edi
cmpl %edx, %edi
jg 0x3b0e
movq 0x8(%rsp), %rdi
addl %ecx, %edi
cmpl %eax, %edi
jg 0x3b0e
movl 0x14(%rsp), %ebp
subl $0x1, %ebp
jb 0x3b4d
movq %r12, %rax
shlq $0x20, %rax
movl %r14d, %ecx
orq %rax, %rcx
movq %rcx, 0x20(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4220
decl %r14d
decl %r12d
jmp 0x3ae4
addl %edx, %eax
cltd
pushq $0x2
popq %rdi
idivl %edi
movl %eax, %ebp
addl %esi, %ecx
movl %ecx, %eax
cltd
idivl %edi
subl %eax, %ebp
jg 0x3b48
jmp 0x3b79
movq %r12, %rax
shlq $0x20, %rax
movl %r14d, %ecx
orq %rax, %rcx
movq %rcx, 0x20(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4220
decl %r14d
decl %r12d
subl $0x1, %ebp
jae 0x3b25
movq 0x18(%rsp), %rax
movq (%rax), %rax
movl (%rax,%r15,4), %ebp
jmp 0x3a87
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
callq 0x4a7c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2920(%rip), %rdi      # 0x64a0
leaq 0x2529(%rip), %rsi      # 0x60b0
leaq 0x2882(%rip), %rcx      # 0x6410
movl $0x92, %edx
callq 0x20c0