// File: /workspace/github_cpp_makefile_star2_O2/temelmertcan[P]multgen/src/adders.cpp
// Function: create_ks_adder(int, bool, std::queue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::deque<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>&)
void create_ks_adder (int size, bool carryin, std::queue<string>& verilog){

  int index = 0;

  string* g = new string[size];
  string* p = new string[size];

  string* gtmp = new string[size];
  string* ptmp = new string[size];

  ppx_preprocess(size,  carryin, index, "KS", gtmp, ptmp, verilog);
  pgtmp_to_pg(size, gtmp, g);
  pgtmp_to_pg(size, ptmp, p);

  verilog.push("\n// Kogge-Stone Adder \n");

  int stage=0;

  // ks steps
  for (int diff = 1; diff < size; diff *= 2){
    verilog.push("");
    verilog.push("// KS stage " + to_string(++stage));

    for (int i=diff; i < size; i++){

      string new_p = "p_" + to_string(stage)+ "_" + to_string(i);
      string new_g = "g_" + to_string(stage)+ "_" + to_string(i);

      verilog.push ("wire logic "+ new_p + ";");
      verilog.push ("wire logic "+ new_g + ";");

      verilog.push ("assign "+ new_p + " = " + p[i] + " & " + p[i-diff] + ";");
      verilog.push ("assign "+ new_g + " = (" + p[i] + " & " + g[i-diff] + ") | " + g[i] + ";");

      gtmp[i] =  new_g;
      ptmp[i] =  new_p;
    }

    pgtmp_to_pg(size, gtmp, g);
    pgtmp_to_pg(size, ptmp, p);
  }

  verilog.push("");
  verilog.push("// KS postprocess ");

  ppx_postprocess (size, index, g, p, verilog);

  delete[] p;
  delete[] g;

  delete[] ptmp;
  delete[] gtmp;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdx, %r12
movl %esi, %ebx
movl %edi, -0x64(%rbp)
movslq %edi, %r13
movq %r13, %r15
shlq $0x5, %r15
leaq 0x8(%r15), %rax
testl %r13d, %r13d
pushq $-0x1
popq %r14
cmovnsq %rax, %r14
movq %r14, %rdi
callq 0x2030
leaq 0x8(%rax), %rcx
movq %rcx, -0x90(%rbp)
movq %r13, (%rax)
movq %r13, -0x30(%rbp)
testl %r13d, %r13d
je 0x16bef
addq $0x18, %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
addq $0x20, %rax
addq $-0x20, %r15
jne 0x16bd9
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
movq %r14, %rdi
callq 0x2030
leaq 0x8(%rax), %rcx
movq %rcx, -0x98(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
testl %ecx, %ecx
je 0x16c3d
leaq 0x18(%rax), %rdx
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb $0x0, (%rdx)
addq $0x20, %rdx
addq $-0x20, %rcx
jne 0x16c27
movq %rax, -0x120(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq %r14, %rdi
callq 0x2030
leaq 0x8(%rax), %rcx
movq %rcx, -0xf0(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
testl %ecx, %ecx
movl -0x64(%rbp), %r15d
je 0x16c96
addq $0x18, %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
addq $0x20, %rax
addq $-0x20, %rcx
jne 0x16c80
movq -0xf0(%rbp), %rax
movq %rax, -0x80(%rbp)
movq %r14, %rdi
callq 0x2030
leaq 0x8(%rax), %rcx
movq %rcx, -0xe8(%rbp)
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
testl %ecx, %ecx
je 0x16ce1
addq $0x18, %rax
movq -0x30(%rbp), %rcx
shlq $0x5, %rcx
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
addq $0x20, %rax
addq $-0x20, %rcx
jne 0x16ccb
movq -0xe8(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq 0x1a9ec(%rip), %rsi     # 0x316df
leaq -0x1e0(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x20b0
movq %r12, (%rsp)
movzbl %bl, %esi
leaq -0x1e0(%rbp), %rcx
leaq -0x80(%rbp), %r8
leaq -0x78(%rbp), %r9
movl %r15d, %edi
callq 0x13d7c
leaq -0x1e0(%rbp), %rdi
callq 0x20f0
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
movl %r15d, %edi
callq 0x14ae8
leaq -0x78(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
movl %r15d, %edi
callq 0x14ae8
leaq 0x1bf69(%rip), %rsi     # 0x32cc3
leaq -0x50(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x20b0
leaq -0x50(%rbp), %rsi
movq %r12, %rdi
callq 0x120e4
leaq -0x50(%rbp), %rdi
callq 0x20f0
pushq $0x1
popq %rax
movq $0x0, -0x70(%rbp)
leaq -0x180(%rbp), %r14
leaq 0x1c949(%rip), %r13     # 0x336e1
movq %r12, -0x58(%rbp)
movl %eax, -0x68(%rbp)
cmpl %r15d, %eax
jge 0x172e4
leaq -0x50(%rbp), %rdi
leaq 0x1c81e(%rip), %rsi     # 0x335d1
leaq -0xc0(%rbp), %rdx
callq 0x20b0
movq %r12, %rbx
movq %r12, %rdi
leaq -0x50(%rbp), %rsi
callq 0x120e4
movl -0x68(%rbp), %r15d
leaq -0x50(%rbp), %rdi
callq 0x20f0
movq -0x70(%rbp), %rsi
incl %esi
leaq -0xc0(%rbp), %r12
movq %r12, %rdi
movq %rsi, -0x70(%rbp)
callq 0x11c73
leaq -0x50(%rbp), %rdi
leaq 0x1bedc(%rip), %rsi     # 0x32cdb
movq %r12, %rdx
callq 0x11d49
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
callq 0x120e4
leaq -0x50(%rbp), %rdi
callq 0x20f0
leaq -0xc0(%rbp), %rdi
callq 0x20f0
movslq %r15d, %rcx
movq %rcx, %rdx
shlq $0x5, %rdx
movq -0x98(%rbp), %rax
addq %rdx, %rax
movq %rax, -0x140(%rbp)
movq -0x90(%rbp), %rax
addq %rdx, %rax
movq %rax, -0x138(%rbp)
movq -0xf0(%rbp), %rax
addq %rdx, %rax
movq %rax, -0x130(%rbp)
addq -0xe8(%rbp), %rdx
movq %rdx, -0x128(%rbp)
xorl %r15d, %r15d
cmpq -0x30(%rbp), %rcx
jge 0x172ac
movq %r15, -0x60(%rbp)
movq %rcx, -0xa0(%rbp)
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
movq -0x70(%rbp), %rsi
callq 0x11c73
movq %r14, %rdi
leaq 0x1b711(%rip), %rsi     # 0x325b9
movq %rbx, %rdx
callq 0x11d49
leaq -0xc0(%rbp), %rdi
movq %r14, %rsi
leaq 0x1c285(%rip), %rdx     # 0x33146
callq 0x11ba1
leaq -0x118(%rbp), %r15
movq %r15, %rdi
movq -0xa0(%rbp), %rsi
callq 0x11c73
leaq -0x50(%rbp), %rdi
leaq -0xc0(%rbp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x11bca
movq %r15, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
callq 0x20f0
movq %r15, %rdi
movq -0x70(%rbp), %rsi
callq 0x11c73
movq %rbx, %rdi
leaq 0x1bd43(%rip), %rsi     # 0x32c72
movq %r15, %rdx
callq 0x11d49
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x1c202(%rip), %rdx     # 0x33146
callq 0x11ba1
leaq -0x160(%rbp), %rbx
movq %rbx, %rdi
movq -0xa0(%rbp), %rsi
callq 0x11c73
leaq -0xc0(%rbp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x11bca
movq %rbx, %rdi
callq 0x20f0
movq %r14, %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rbx
movq %rbx, %rdi
callq 0x20f0
leaq -0x118(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
leaq 0x1bcb3(%rip), %rsi     # 0x32c59
leaq -0x50(%rbp), %rdx
callq 0x11cd3
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x11ba1
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x120e4
movq %r14, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
movq %rbx, %rdi
leaq 0x1bc76(%rip), %rsi     # 0x32c59
leaq -0xc0(%rbp), %rdx
callq 0x11cd3
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x11ba1
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x120e4
movq %r14, %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
callq 0x20f0
leaq -0x1a0(%rbp), %rbx
movq %rbx, %rdi
leaq 0x1b581(%rip), %rsi     # 0x325af
leaq -0x50(%rbp), %rdx
callq 0x11cd3
leaq -0x1c0(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x1b208(%rip), %rdx     # 0x32253
callq 0x11ba1
movq %r13, %r12
movq %r14, %r13
movq -0x140(%rbp), %rax
movq -0x60(%rbp), %rcx
leaq (%rax,%rcx), %rbx
leaq -0x160(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x11d77
leaq -0x118(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
leaq 0x1c0f7(%rip), %rdx     # 0x33185
callq 0x11ba1
movq -0x98(%rbp), %rax
movq -0x60(%rbp), %rcx
leaq (%rax,%rcx), %rdx
leaq -0xe0(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x11d77
movq %r13, %r15
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x11ba1
movq -0x58(%rbp), %rdi
movq %r15, %rsi
callq 0x120e4
movq %r15, %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
callq 0x20f0
leaq -0x118(%rbp), %rdi
callq 0x20f0
leaq -0x160(%rbp), %rdi
callq 0x20f0
leaq -0x1c0(%rbp), %rdi
callq 0x20f0
leaq -0x1a0(%rbp), %rdi
callq 0x20f0
leaq -0x200(%rbp), %r14
movq %r14, %rdi
leaq 0x1b489(%rip), %rsi     # 0x325af
leaq -0xc0(%rbp), %rdx
callq 0x11cd3
leaq -0x220(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
leaq 0x1b361(%rip), %rdx     # 0x324a7
callq 0x11ba1
leaq -0x1a0(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x11d77
leaq -0x1c0(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x1c011(%rip), %rdx     # 0x33185
callq 0x11ba1
movq -0x90(%rbp), %rax
movq -0x60(%rbp), %rcx
leaq (%rax,%rcx), %rdx
leaq -0x160(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11d77
leaq -0x118(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x1beba(%rip), %rdx     # 0x33068
callq 0x11ba1
movq -0x138(%rbp), %rax
movq -0x60(%rbp), %rcx
leaq (%rax,%rcx), %rdx
leaq -0xe0(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x11d77
movq %r13, %rbx
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %r13
movq %r12, %rdx
callq 0x11ba1
movq -0x58(%rbp), %rdi
movq %rbx, %rsi
callq 0x120e4
movq %rbx, %r14
movq %rbx, %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
callq 0x20f0
leaq -0x118(%rbp), %rdi
callq 0x20f0
leaq -0x160(%rbp), %rdi
callq 0x20f0
leaq -0x1c0(%rbp), %rdi
callq 0x20f0
leaq -0x1a0(%rbp), %rdi
callq 0x20f0
leaq -0x220(%rbp), %rdi
callq 0x20f0
leaq -0x200(%rbp), %rdi
callq 0x20f0
movq -0x130(%rbp), %rax
movq -0x60(%rbp), %r15
leaq (%rax,%r15), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x2130
leaq -0x50(%rbp), %rbx
movq -0x128(%rbp), %rax
leaq (%rax,%r15), %rdi
movq %rbx, %rsi
callq 0x2130
leaq -0xc0(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
movq -0xa0(%rbp), %rcx
incq %rcx
addq $0x20, %r15
jmp 0x16e76
movl -0x64(%rbp), %r15d
movl %r15d, %edi
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x14ae8
movl %r15d, %edi
leaq -0x78(%rbp), %rsi
leaq -0xf8(%rbp), %rdx
callq 0x14ae8
movl -0x68(%rbp), %eax
addl %eax, %eax
movq -0x58(%rbp), %r12
jmp 0x16d9c
leaq 0x1c2e6(%rip), %rsi     # 0x335d1
leaq -0x50(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x20b0
leaq -0x50(%rbp), %rsi
movq %r12, %rdi
callq 0x120e4
leaq -0x50(%rbp), %rdi
callq 0x20f0
leaq 0x1b9d1(%rip), %rsi     # 0x32ce8
leaq -0x50(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
callq 0x20b0
leaq -0x50(%rbp), %rsi
movq %r12, %rdi
callq 0x120e4
leaq -0x50(%rbp), %rdi
callq 0x20f0
leaq -0x88(%rbp), %rdx
movl %r15d, %edi
movq %r12, %r8
callq 0x146e9
movq -0x120(%rbp), %r15
movq (%r15), %rbx
testq %rbx, %rbx
je 0x17377
shlq $0x5, %rbx
movq %r15, %r14
addq $-0x18, %r14
leaq (%r14,%rbx), %rdi
callq 0x20f0
addq $-0x20, %rbx
jne 0x17368
movq %r15, %rdi
callq 0x2230
movq -0x88(%rbp), %r14
testq %r14, %r14
je 0x173b7
leaq -0x8(%r14), %rbx
movq -0x8(%r14), %r15
testq %r15, %r15
je 0x173af
addq $-0x20, %r14
shlq $0x5, %r15
leaq (%r14,%r15), %rdi
callq 0x20f0
addq $-0x20, %r15
jne 0x173a0
movq %rbx, %rdi
callq 0x2230
movq -0x78(%rbp), %r14
testq %r14, %r14
je 0x173ec
leaq -0x8(%r14), %rbx
movq -0x8(%r14), %r15
testq %r15, %r15
je 0x173e4
addq $-0x20, %r14
shlq $0x5, %r15
leaq (%r14,%r15), %rdi
callq 0x20f0
addq $-0x20, %r15
jne 0x173d5
movq %rbx, %rdi
callq 0x2230
movq -0x80(%rbp), %r14
testq %r14, %r14
je 0x17421
leaq -0x8(%r14), %rbx
movq -0x8(%r14), %r15
testq %r15, %r15
je 0x17419
addq $-0x20, %r14
shlq $0x5, %r15
leaq (%r14,%r15), %rdi
callq 0x20f0
addq $-0x20, %r15
jne 0x1740a
movq %rbx, %rdi
callq 0x2230
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x175fe
jmp 0x1747b
jmp 0x175fe
jmp 0x1747b
jmp 0x175fe
jmp 0x1747b
movq %rax, %rbx
leaq -0x1e0(%rbp), %rdi
jmp 0x17646
jmp 0x1747b
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x20f0
jmp 0x1746a
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
jmp 0x17646
jmp 0x175fe
movq %rax, %rbx
jmp 0x1764b
movq %rax, %rbx
jmp 0x1750e
jmp 0x17633
movq %rax, %rbx
jmp 0x174f6
movq %rax, %rbx
jmp 0x17541
movq %rax, %rbx
jmp 0x174ea
movq %rax, %rbx
jmp 0x17502
movq %rax, %rbx
jmp 0x174c3
movq %rax, %rbx
jmp 0x1755e
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
callq 0x20f0
jmp 0x174de
movq %rax, %rbx
jmp 0x1751a
movq %rax, %rbx
jmp 0x17535
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x20f0
leaq -0x160(%rbp), %rdi
callq 0x20f0
leaq -0x1c0(%rbp), %rdi
callq 0x20f0
leaq -0x1a0(%rbp), %rdi
callq 0x20f0
leaq -0x220(%rbp), %rdi
callq 0x20f0
leaq -0x200(%rbp), %rdi
jmp 0x175f7
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
callq 0x20f0
leaq -0x118(%rbp), %rdi
callq 0x20f0
jmp 0x17552
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x20f0
leaq -0x1c0(%rbp), %rdi
callq 0x20f0
leaq -0x1a0(%rbp), %rdi
jmp 0x175f7
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x20f0
jmp 0x175c2
jmp 0x175a4
jmp 0x17633
jmp 0x17633
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x20f0
jmp 0x17612
movq %rax, %rbx
jmp 0x175f0
movq %rax, %rbx
jmp 0x1761e
jmp 0x17633
movq %rax, %rbx
jmp 0x1762a
movq %rax, %rbx
jmp 0x1756a
jmp 0x175e1
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0x20f0
jmp 0x175d3
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x20f0
jmp 0x17606
movq %rax, %rbx
leaq -0x180(%rbp), %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
callq 0x20f0
jmp 0x17636
movq %rax, %rbx
jmp 0x17642
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
jmp 0x1763d
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x20f0
leaq -0x180(%rbp), %rdi
callq 0x20f0
leaq -0xe0(%rbp), %rdi
jmp 0x17646
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x20f0
leaq -0x50(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2330