// File: /workspace/github_cpp_makefile_star2_O2/temelmertcan[P]multgen/src/pp_gen.cpp
// Function: merge_extra_ones_indices(std::__cxx11::list<int, std::allocator<int>> const&, std::__cxx11::list<int, std::allocator<int>> const&, int const&)
std::list<int> merge_extra_ones_indices (const std::list<int>& extra_ones_indices1,
                                         const std::list<int>& extra_ones_indices2,
                                         const int& offset2){


 
    

  int carry = -1;

  std::list<int> result;

  for (auto it1 = extra_ones_indices1.begin(), it2 = extra_ones_indices2.begin() ;
       it1 != extra_ones_indices1.end() || it2 != extra_ones_indices2.end();){

    bool end1 = (it1 == extra_ones_indices1.end());
    bool end2 = (it2 == extra_ones_indices2.end());

    int val1 = *it1;
    int val2 = *it2 + offset2;

    //cout << "lst1: " << val1 << ", lst2:" << val2 << ", carry: " << carry << "." << endl;

    if ((end1 || carry < val1) && (end2 || carry < val2) && carry != -1){
      result.push_back(carry);
      carry = -1;
    } else if (!end1 && carry == val1 && (end2 || carry <= val2)) {
      carry = val1 + 1;
      it1++;
    } else if (!end2 && carry == val2 && (end1 || carry <= val1)) {
      carry = val2 + 1;
      it2++;
    } else if (!end1 && (val1 < val2 || end2)) {
      result.push_back(val1);
      it1++;
    } else if (!end2 && (val2 < val1 || end1)) {
      result.push_back(val2);
      it2++;
    } else {
      //cout << "here" << endl;
      carry = val1 + 1;
      ++it1;
      ++it2;
    }
  }

  if (carry != -1)
    result.push_back(carry);


  // { // Print some stuff for debugging.
  //   cout << "Merging two extra ones indices:" << endl;
  //   cout << "extra_ones_indices1 " ;
  //   for (auto e: extra_ones_indices1)
  //     cout << e << " ";
  //   cout << endl;
  //   cout << "extra_ones_indices2 " ;
  //   for (auto e: extra_ones_indices2)
  //     cout << e << " ";
  //   cout << endl;
  //   cout << "result: " ;
  //   for (auto e: result)
  //     cout << e << " ";
  //   cout << endl;
  // }
  

  return result;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
leaq -0x2c(%rbp), %rax
orl $-0x1, (%rax)
movq %rdi, 0x8(%rdi)
movq %rdi, (%rdi)
movq %rdi, -0x38(%rbp)
andq $0x0, 0x10(%rdi)
movq (%rsi), %r13
movq (%rdx), %rbx
movq %r13, %rax
xorq %r12, %rax
movq %rbx, %rcx
xorq %r15, %rcx
orq %rax, %rcx
je 0x1983b
cmpq %r12, %r13
sete %sil
movl 0x10(%r13), %eax
movl %eax, -0x40(%rbp)
movl (%r14), %ecx
addl 0x10(%rbx), %ecx
movl %ecx, -0x3c(%rbp)
movl -0x2c(%rbp), %edx
cmpl %eax, %edx
setl %dil
orb %sil, %dil
cmpb $0x1, %dil
jne 0x19781
cmpq %r15, %rbx
je 0x197ec
cmpl %ecx, %edx
setl %sil
cmpl $-0x1, %edx
setne %dil
testb %dil, %sil
jne 0x197f1
cmpq %r12, %r13
je 0x1979e
cmpq %r15, %rbx
sete %sil
cmpl %ecx, %edx
setle %dil
cmpl %eax, %edx
jne 0x1979e
orb %dil, %sil
je 0x1979e
incl %eax
movl %eax, -0x2c(%rbp)
jmp 0x197e3
cmpq %r15, %rbx
je 0x197c0
cmpq %r12, %r13
sete %sil
cmpl %eax, %edx
setle %dil
cmpl %ecx, %edx
jne 0x197c0
orb %dil, %sil
je 0x197c0
incl %ecx
movl %ecx, -0x2c(%rbp)
jmp 0x19833
cmpq %r15, %rbx
sete %dl
cmpl %ecx, %eax
setl %sil
cmpq %r12, %r13
je 0x19807
orb %sil, %dl
je 0x19807
movq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x279ac
movq (%r13), %r13
jmp 0x19723
cmpl $-0x1, %edx
je 0x1977c
movq -0x38(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x279ac
orl $-0x1, -0x2c(%rbp)
jmp 0x19723
cmpq %r12, %r13
sete %dl
cmpl %eax, %ecx
setl %cl
cmpq %r15, %rbx
je 0x1982a
orb %cl, %dl
je 0x1982a
movq -0x38(%rbp), %rdi
leaq -0x3c(%rbp), %rsi
callq 0x279ac
jmp 0x19833
incl %eax
movl %eax, -0x2c(%rbp)
movq (%r13), %r13
movq (%rbx), %rbx
jmp 0x19723
cmpl $-0x1, -0x2c(%rbp)
movq -0x38(%rbp), %rbx
je 0x19851
leaq -0x2c(%rbp), %rsi
movq %rbx, %rdi
callq 0x279ac
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x19865
movq %rax, %r14
movq -0x38(%rbp), %rdi
callq 0x11f0c
movq %r14, %rdi
callq 0x2330