// File: /workspace/github_cpp_makefile_star2_O3/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, -0x30(%rbp)
movq $0x0, 0x10(%rdi)
movq (%rsi), %r13
movq (%rdx), %r14
movq %r13, %rax
xorq %rsi, %rax
movq %r14, %rcx
movq %rdx, -0x40(%rbp)
xorq %rdx, %rcx
orq %rax, %rcx
je 0x3b93a
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
movq %rsi, -0x38(%rbp)
movq -0x48(%rbp), %rax
movl (%rax), %r12d
addl 0x10(%r14), %r12d
movl 0x10(%r13), %ebx
cmpq %rsi, %r13
je 0x3b7ea
cmpl %ebx, %r15d
jl 0x3b7ea
je 0x3b838
jmp 0x3b843
cmpq -0x40(%rbp), %r14
je 0x3b827
cmpl $-0x1, %r15d
je 0x3b82d
cmpl %r12d, %r15d
jge 0x3b82d
movl $0x18, %edi
callq 0x3200
movl %r15d, 0x10(%rax)
movq %rax, %rdi
movq -0x30(%rbp), %rbx
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0x3b8f9
cmpl $-0x1, %r15d
jne 0x3b7fb
cmpq -0x38(%rbp), %r13
je 0x3b843
cmpl %ebx, %r15d
jne 0x3b843
cmpq -0x40(%rbp), %r14
je 0x3b8aa
cmpl %r12d, %r15d
jle 0x3b8aa
cmpq -0x38(%rbp), %r13
sete %cl
cmpl %ebx, %r15d
setle %dl
cmpq -0x40(%rbp), %r14
setne %al
je 0x3b86d
cmpl %r12d, %r15d
jne 0x3b86d
orb %dl, %cl
je 0x3b86d
incl %r15d
movq (%r14), %r14
jmp 0x3b8f9
cmpq -0x40(%rbp), %r14
sete %cl
cmpl %r12d, %ebx
setl %dl
cmpq -0x38(%rbp), %r13
je 0x3b8b2
orb %dl, %cl
je 0x3b8b2
movl $0x18, %edi
callq 0x3200
movl %ebx, 0x10(%rax)
movq %rax, %rdi
movq -0x30(%rbp), %rbx
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
movq (%r13), %r13
jmp 0x3b8f9
incl %ebx
movq (%r13), %r13
jmp 0x3b8f6
cmpq -0x38(%rbp), %r13
sete %cl
cmpl %ebx, %r12d
setl %dl
orb %cl, %dl
andb %dl, %al
cmpb $0x1, %al
jne 0x3b8ed
movl $0x18, %edi
callq 0x3200
movl %r12d, 0x10(%rax)
movq %rax, %rdi
movq -0x30(%rbp), %rbx
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
jmp 0x3b865
incl %ebx
movq (%r13), %r13
movq (%r14), %r14
movl %ebx, %r15d
movq %r13, %rax
movq -0x38(%rbp), %rsi
xorq %rsi, %rax
movq %r14, %rcx
xorq -0x40(%rbp), %rcx
orq %rax, %rcx
jne 0x3b7cd
cmpl $-0x1, %r15d
je 0x3b93a
movl $0x18, %edi
callq 0x3200
movl %r15d, 0x10(%rax)
movq %rax, %rdi
movq -0x30(%rbp), %rbx
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
movq -0x30(%rbp), %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3b94f
movq %rax, %r14
movq -0x30(%rbp), %r15
movq (%r15), %rdi
cmpq %r15, %rdi
je 0x3b96e
movq (%rdi), %rbx
callq 0x31d0
movq %rbx, %rdi
cmpq %r15, %rbx
jne 0x3b95e
movq %r14, %rdi
callq 0x33a0