// File: /workspace/github_cpp_makefile_star2_O1/fpavetic[P]lcskpp/lcskpp.cpp
// Function: lcskpp_sparse_slow(std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>> const&, int, int*, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>*)
static void lcskpp_sparse_slow(
    const vector<pair<int, int> >& matches,
    const int k, int* lcskpp_length,
    vector<pair<int, int> >* lcskpp_reconstruction) {
  assert(is_sorted(matches.begin(), matches.end()));

  if (matches.empty()) {
    *lcskpp_length = 0;
    if (lcskpp_reconstruction) lcskpp_reconstruction->clear();
  } else {
    int n = matches.size();
    vector<int> dp(n);
    vector<int> recon(n);
    int best_idx = 0;
    *lcskpp_length = 0;
    
    for (int i = 0; i < n; ++i) {
      dp[i] = k;
      recon[i] = -1;

      int end_row_i = matches[i].first+k-1;
      int end_col_i = matches[i].second+k-1;

      int primary_diagonal_i = end_row_i - end_col_i;
      int secondary_diagonal_i = (end_row_i + end_col_i)/2;

      for (int j = i-1; j >= 0; --j) {
        if (matches[j].first + k <= matches[i].first &&
            matches[j].second + k <= matches[i].second) {
          // 1) Taking the entire match interval and continuing
          // another match which 'ended'.
          if (dp[j] + k > dp[i]) {
            dp[i] = dp[j] + k;
            recon[i] = j;
          }
        } else {
          // 2) Continuation on the same primary diagonal.
          int end_row_j = matches[j].first+k-1;
          int end_col_j = matches[j].second+k-1;
          int primary_diagonal_j = end_row_j - end_col_j;
          int secondary_diagonal_j = (end_row_j + end_col_j)/2;
	  
          if (primary_diagonal_i == primary_diagonal_j &&
              secondary_diagonal_i > secondary_diagonal_j &&
              secondary_diagonal_i - secondary_diagonal_j < k) {
            if (dp[j] + secondary_diagonal_i - secondary_diagonal_j 
                > dp[i]) {
              dp[i] = 
                dp[j] + secondary_diagonal_i - secondary_diagonal_j;
              recon[i] = j;
            }
          }
        }
      }

      if (dp[i] > *lcskpp_length) {
        best_idx = i;
        *lcskpp_length = dp[i];
      }
    }

    if (lcskpp_reconstruction) {
      fill_lcskpp_reconstruction(matches, k, recon, best_idx, 
                                 *lcskpp_length, 
                                 lcskpp_reconstruction);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %rbx
movq %rdx, 0x8(%rsp)
movl %esi, %r14d
movq %rdi, %r15
movq (%rdi), %rax
movq 0x8(%rdi), %rbp
movq %rbp, %rcx
cmpq %rbp, %rax
je 0x3286
leaq 0x8(%rax), %rcx
cmpq %rbp, %rcx
je 0x3286
movl -0x8(%rcx), %edx
movl (%rcx), %esi
cmpl %edx, %esi
jl 0x3286
jg 0x3280
movl 0x4(%rcx), %edx
cmpl -0x4(%rcx), %edx
jl 0x3286
addq $0x8, %rcx
jmp 0x3268
cmpq %rbp, %rcx
jne 0x346f
cmpq %rbp, %rax
je 0x33f5
subq %rax, %rbp
shrq $0x3, %rbp
movslq %ebp, %r13
leaq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %r13, %rsi
callq 0x3f96
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
movq %r13, %rsi
callq 0x3f96
movq %rbx, 0x18(%rsp)
movq 0x8(%rsp), %rax
movl $0x0, (%rax)
testl %ebp, %ebp
movq %r15, 0x10(%rsp)
jle 0x3414
movq 0x40(%rsp), %rax
movq 0x28(%rsp), %rdx
movq (%r15), %rsi
leal -0x2(,%r14,2), %ecx
movq %rcx, 0x20(%rsp)
leal -0x2(%r14), %r8d
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
xorl %r9d, %r9d
movq $-0x1, %rbx
movl $0x0, (%rsp)
movl %r14d, (%rax,%r9,4)
movl $0xffffffff, (%rdx,%r9,4) # imm = 0xFFFFFFFF
testq %r9, %r9
je 0x33cc
movl (%rsi,%r9,8), %r11d
movl 0x4(%rsi,%r9,8), %ecx
movq 0x20(%rsp), %rdi
addl %r11d, %edi
subl %ecx, %r11d
addl %ecx, %edi
movl %edi, %r13d
shrl $0x1f, %r13d
addl %edi, %r13d
sarl %r13d
movq %rbx, %r10
movl %r10d, %r15d
movl (%rsi,%r15,8), %ecx
leal (%rcx,%r14), %edi
cmpl (%rsi,%r9,8), %edi
jg 0x3373
movl 0x4(%rsi,%r15,8), %r12d
addl %r14d, %r12d
cmpl 0x4(%rsi,%r9,8), %r12d
jle 0x33a7
movl 0x4(%rsi,%r15,8), %r12d
subl %r12d, %ecx
cmpl %ecx, %r11d
jne 0x33bc
addl %r8d, %edi
addl %r12d, %edi
movl %edi, %ecx
shrl $0x1f, %ecx
addl %edi, %ecx
sarl %ecx
movl %r13d, %edi
subl %ecx, %edi
jle 0x33bc
movl %r13d, %r12d
subl %ecx, %r12d
cmpl %r14d, %r12d
jge 0x33bc
addl (%rax,%r15,4), %edi
jmp 0x33ae
movl (%rax,%r15,4), %edi
addl %r14d, %edi
cmpl (%rax,%r9,4), %edi
jle 0x33bc
movl %edi, (%rax,%r9,4)
movl %r10d, (%rdx,%r9,4)
leaq -0x1(%r10), %rcx
incq %r10
cmpq $0x1, %r10
movq %rcx, %r10
jg 0x3353
movl (%rax,%r9,4), %ecx
movq 0x8(%rsp), %rdi
cmpl (%rdi), %ecx
jle 0x33e4
movq 0x8(%rsp), %rdi
movl %ecx, (%rdi)
movl %r9d, (%rsp)
incq %r9
incq %rbx
cmpq %rbp, %r9
jne 0x3318
jmp 0x341b
movq 0x8(%rsp), %rax
movl $0x0, (%rax)
testq %rbx, %rbx
je 0x3460
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x3460
movq %rax, 0x8(%rbx)
jmp 0x3460
movl $0x0, (%rsp)
movq 0x18(%rsp), %r9
testq %r9, %r9
je 0x3442
movq 0x8(%rsp), %rax
movl (%rax), %r8d
leaq 0x28(%rsp), %rdx
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movl (%rsp), %ecx
callq 0x3dc8
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3451
callq 0x2130
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3460
callq 0x2130
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2f6c(%rip), %rdi      # 0x63e2
leaq 0x2c2e(%rip), %rsi      # 0x60ab
leaq 0x2f88(%rip), %rcx      # 0x640c
movl $0xf9, %edx
callq 0x20b0
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x34a5
callq 0x2130
jmp 0x34a5
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x34b4
callq 0x2130
movq %rbx, %rdi
callq 0x21f0