// File: /workspace/github_cpp_makefile_star2_O1/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 $0x28, %rsp
movq %rcx, -0x48(%rbp)
movq %rdi, 0x8(%rdi)
movq %rdi, (%rdi)
movq %rdi, -0x38(%rbp)
movq $0x0, 0x10(%rdi)
movq (%rsi), %r13
movq (%rdx), %r14
movq %r13, %rax
xorq %rsi, %rax
movq %r14, %rcx
movq %rdx, -0x30(%rbp)
xorq %rdx, %rcx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
orq %rax, %rcx
je 0x3bb2e
movq %rsi, -0x40(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %r15d
addl 0x10(%r14), %r15d
movl 0x10(%r13), %ebx
cmpq %rsi, %r13
je 0x3ba20
cmpl %ebx, %r12d
jl 0x3ba20
cmpq -0x30(%rbp), %r14
sete %al
cmpl %r15d, %r12d
setle %cl
cmpq -0x40(%rbp), %r13
je 0x3ba33
cmpl %ebx, %r12d
jne 0x3ba33
orb %cl, %al
je 0x3ba33
incl %ebx
movq (%r13), %r13
movl %ebx, %r12d
jmp 0x3bb04
cmpq -0x30(%rbp), %r14
je 0x3ba5d
cmpl $-0x1, %r12d
je 0x3b9f6
cmpl %r15d, %r12d
jl 0x3ba63
jmp 0x3b9f6
cmpq -0x40(%rbp), %r13
sete %al
cmpl %ebx, %r12d
setle %cl
cmpq -0x30(%rbp), %r14
je 0x3ba8c
cmpl %r15d, %r12d
jne 0x3ba8c
orb %cl, %al
je 0x3ba8c
incl %r15d
movq (%r14), %r14
movl %r15d, %r12d
jmp 0x3bb04
cmpl $-0x1, %r12d
je 0x3b9f6
movl $0x18, %edi
callq 0x3200
movl %r12d, 0x10(%rax)
movq %rax, %rdi
movq -0x38(%rbp), %rbx
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x3bb04
cmpq -0x30(%rbp), %r14
sete %al
cmpl %r15d, %ebx
setl %cl
cmpq -0x40(%rbp), %r13
je 0x3bac9
orb %cl, %al
je 0x3bac9
movl $0x18, %edi
callq 0x3200
movl %ebx, 0x10(%rax)
movq %rax, %rdi
movq -0x38(%rbp), %rbx
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
movq (%r13), %r13
jmp 0x3bb04
cmpq -0x40(%rbp), %r13
sete %al
cmpl %ebx, %r15d
setl %cl
cmpq -0x30(%rbp), %r14
je 0x3bb20
orb %cl, %al
je 0x3bb20
movl $0x18, %edi
callq 0x3200
movl %r15d, 0x10(%rax)
movq %rax, %rdi
movq -0x38(%rbp), %rbx
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
movq (%r14), %r14
movq %r13, %rax
movq -0x40(%rbp), %rsi
xorq %rsi, %rax
movq %r14, %rcx
xorq -0x30(%rbp), %rcx
orq %rax, %rcx
jne 0x3b9dd
jmp 0x3bb2e
incl %ebx
movq (%r13), %r13
movq (%r14), %r14
jmp 0x3ba18
cmpl $-0x1, %r12d
movq -0x38(%rbp), %rbx
je 0x3bb55
movl $0x18, %edi
callq 0x3200
movl %r12d, 0x10(%rax)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3bb69
movq %rax, %r14
movq -0x38(%rbp), %r15
movq (%r15), %rdi
cmpq %r15, %rdi
je 0x3bb88
movq (%rdi), %rbx
callq 0x31d0
movq %rbx, %rdi
cmpq %r15, %rbx
jne 0x3bb78
movq %r14, %rdi
callq 0x33a0