// File: 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
subq $0xc0, %rsp
movq %rdi, -0xb0(%rbp)
movq %rdi, %rax
movq %rax, -0xa8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movb $0x0, -0x25(%rbp)
callq 0x1eb00
movq -0x10(%rbp), %rdi
callq 0x1ea20
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1ea20
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1ea50
movq %rax, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x1ea80
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0xb1(%rbp)
jne 0x2e64f
movq -0x18(%rbp), %rdi
callq 0x1ea50
movq %rax, -0x48(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1ea80
movb %al, -0xb1(%rbp)
movb -0xb1(%rbp), %al
testb $0x1, %al
jne 0x2e65e
jmp 0x2e82f
movq -0x10(%rbp), %rdi
callq 0x1ea50
movq %rax, -0x58(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x46d40
andb $0x1, %al
movb %al, -0x49(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1ea50
movq %rax, -0x68(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x46d40
andb $0x1, %al
movb %al, -0x59(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1eab0
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x1eab0
movl (%rax), %eax
movq -0x20(%rbp), %rcx
addl (%rcx), %eax
movl %eax, -0x70(%rbp)
testb $0x1, -0x49(%rbp)
jne 0x2e6cc
movl -0x24(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x2e71b
testb $0x1, -0x59(%rbp)
jne 0x2e6da
movl -0x24(%rbp), %eax
cmpl -0x70(%rbp), %eax
jge 0x2e71b
cmpl $-0x1, -0x24(%rbp)
je 0x2e71b
movq -0xb0(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x46d70
jmp 0x2e6f2
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
jmp 0x2e82a
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
callq 0x1eb50
jmp 0x2e86f
testb $0x1, -0x49(%rbp)
jne 0x2e757
movl -0x24(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jne 0x2e757
testb $0x1, -0x59(%rbp)
jne 0x2e737
movl -0x24(%rbp), %eax
cmpl -0x70(%rbp), %eax
jg 0x2e757
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x46db0
movq %rax, -0x88(%rbp)
jmp 0x2e828
testb $0x1, -0x59(%rbp)
jne 0x2e793
movl -0x24(%rbp), %eax
cmpl -0x70(%rbp), %eax
jne 0x2e793
testb $0x1, -0x49(%rbp)
jne 0x2e773
movl -0x24(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jg 0x2e793
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x46db0
movq %rax, -0x90(%rbp)
jmp 0x2e826
testb $0x1, -0x49(%rbp)
jne 0x2e7cd
movl -0x6c(%rbp), %eax
cmpl -0x70(%rbp), %eax
jl 0x2e7a7
testb $0x1, -0x59(%rbp)
je 0x2e7cd
movq -0xb0(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x46d70
jmp 0x2e7b9
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x46db0
movq %rax, -0x98(%rbp)
jmp 0x2e824
testb $0x1, -0x59(%rbp)
jne 0x2e807
movl -0x70(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jl 0x2e7e1
testb $0x1, -0x49(%rbp)
je 0x2e807
movq -0xb0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x46d70
jmp 0x2e7f3
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x46db0
movq %rax, -0xa0(%rbp)
jmp 0x2e822
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x1eae0
leaq -0x38(%rbp), %rdi
callq 0x1eae0
jmp 0x2e824
jmp 0x2e826
jmp 0x2e828
jmp 0x2e82a
jmp 0x2e606
cmpl $-0x1, -0x24(%rbp)
je 0x2e849
movq -0xb0(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0x46d70
jmp 0x2e847
jmp 0x2e849
movb $0x1, -0x25(%rbp)
testb $0x1, -0x25(%rbp)
jne 0x2e85f
movq -0xb0(%rbp), %rdi
callq 0x1eb50
movq -0xa8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x3420
nopl (%rax,%rax)