// File: /workspace/github_cpp_makefile_star2_O2/temelmertcan[P]multgen/src/pp_gen.cpp
// Function: create_signedpp(int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>**&, int&, int&, std::__cxx11::list<int, std::allocator<int>>&, 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_signedpp (int m, int n,
                      string**& pp_matrix,
                      int& pp_dim1,
                      int& pp_dim2,
                      std::list<int>& extra_ones_indices,
		   
                      std::queue<string>& verilog){

  pp_dim1 = m+1;
  pp_dim2 = n+m;

  pp_matrix = new string*[pp_dim1];
  for (int i = 0; i < pp_dim1; i++){
    pp_matrix[i] = new string[pp_dim2];
    for (int j = 0; j < pp_dim2; j++)
      pp_matrix[i][j] = "";
  }

  // if (m != n) {
  //   cout << "Simple signed partial products are only supported when IN1 and IN2 has the same dimensions." << endl;
  //   return;
  // }


  for (int i = 0; i<m; i++)
    verilog.push ( "wire logic [" + to_string(n-1) + ":0] pp" + to_string(i) + ";");

  for (int i = 0; i < m; i++){
    pp_matrix[i] = new string[pp_dim2];
    for (int j = 0; j < i; j++){
      pp_matrix[i][j] = "";
    }
    for (int j = 0; j < n; j++){
      string cur;
      cur = "pp" + to_string(i) + "[" + to_string(j) + "]";
      pp_matrix[i][j+i] = cur;
    }

    for (int j = n+i; j < pp_dim2; j++){
      pp_matrix[i][j] = "";
    }

    if (i==m-1)
      verilog.push ("assign pp" + to_string(i)  + " = ~({"
                    + to_string(n)
                    + "{IN1["
                    + to_string(i)
                    + "]}} & IN2) ^ ((1'b1)<<" + to_string(n-1) + ");");
    else
      verilog.push ("assign pp" + to_string(i)  + " = ({"
                    + to_string(n)
                    + "{IN1["
                    + to_string(i)
                    + "]}} & IN2) ^ ((1'b1)<<" + to_string(n-1) + ");");
  }

  std::list<int> extra_ones_indices1;
  for (int i = n-1; i<m-1+n-1; i++)
    extra_ones_indices1.push_back (i);
  std::list<int> extra_ones_indices2;
  for (int i = m-1; i<m-1+n-1; i++)
    extra_ones_indices2.push_back (i);

  extra_ones_indices = merge_extra_ones_indices(extra_ones_indices1,extra_ones_indices2,0);

  // extra_ones_indices.push_back(n);
  // extra_ones_indices.push_back(m+n-1);
  // pp_matrix[m][n] = "1'b1";
  // pp_matrix[m][m+n-1] = "1'b1";

  // print_pp(pp_matrix, pp_dim1, pp_dim2, verilog, true);

  //print_pp(pp_matrix, pp_dim1, pp_dim2);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movq %r9, -0x160(%rbp)
movq %rdx, %rbx
leal 0x1(%rdi), %eax
movl %eax, (%rcx)
movq %rdi, -0x48(%rbp)
movq %rsi, -0x40(%rbp)
leal (%rsi,%rdi), %r15d
movq %r8, -0xa0(%rbp)
movl %r15d, (%r8)
movq %rcx, -0x30(%rbp)
movslq (%rcx), %r13
leaq (,%r13,8), %rdi
testq %r13, %r13
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rbx, -0x38(%rbp)
movq %rax, (%rbx)
xorl %r12d, %r12d
leaq 0x19335(%rip), %r14     # 0x335d1
movslq %r13d, %rax
cmpq %rax, %r12
jge 0x1a339
movslq %r15d, %rbx
movq %rbx, %r13
shlq $0x5, %r13
leaq 0x8(%r13), %rdi
testl %ebx, %ebx
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rbx, (%rax)
testl %ebx, %ebx
je 0x1a2e5
leaq 0x18(%rax), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rcx
addq $-0x20, %r13
jne 0x1a2cf
addq $0x8, %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movq %rax, (%rcx,%r12,8)
xorl %r13d, %r13d
xorl %ebx, %ebx
movslq %r15d, %rax
cmpq %rax, %rbx
jge 0x1a32a
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r12,8), %rdi
addq %r13, %rdi
movq %r14, %rsi
callq 0x2350
incq %rbx
movq -0xa0(%rbp), %rax
movl (%rax), %r15d
addq $0x20, %r13
jmp 0x1a2f9
incq %r12
movq -0x30(%rbp), %rax
movl (%rax), %r13d
jmp 0x1a29c
movq -0x40(%rbp), %rax
decl %eax
movq %rax, -0x50(%rbp)
xorl %ebx, %ebx
movq -0x48(%rbp), %rax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movl %ecx, -0x30(%rbp)
leaq -0x108(%rbp), %r12
leaq -0xc0(%rbp), %r13
leaq -0x70(%rbp), %r15
cmpl %ebx, -0x30(%rbp)
je 0x1a436
movq %r12, %r14
leaq -0xe8(%rbp), %r12
movq %r12, %rdi
movq -0x50(%rbp), %rsi
callq 0x11c73
movq %r14, %rdi
leaq 0x17b9c(%rip), %rsi     # 0x31f2d
movq %r12, %rdx
callq 0x11d49
leaq -0x90(%rbp), %rdi
movq %r14, %rsi
leaq 0x18b83(%rip), %rdx     # 0x32f2d
callq 0x11ba1
movq %r14, %r12
leaq -0x138(%rbp), %r14
movq %r14, %rdi
movl %ebx, %esi
callq 0x11c73
movq %r13, %rdi
leaq -0x90(%rbp), %rsi
movq %r14, %rdx
callq 0x11bca
movq %r15, %rdi
movq %r13, %rsi
leaq 0x192ff(%rip), %rdx     # 0x336e1
callq 0x11ba1
movq 0x10(%rbp), %rdi
movq %r15, %rsi
callq 0x120e4
movq %r15, %rdi
callq 0x20f0
movq %r13, %rdi
callq 0x20f0
leaq -0x138(%rbp), %rdi
callq 0x20f0
leaq -0x90(%rbp), %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
leaq -0xe8(%rbp), %rdi
callq 0x20f0
incl %ebx
jmp 0x1a368
movq -0x48(%rbp), %r13
decl %r13d
movq $0x0, -0x98(%rbp)
movq -0x40(%rbp), %rax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, -0x180(%rbp)
movl -0x30(%rbp), %ecx
movq %rcx, -0x168(%rbp)
xorl %ecx, %ecx
movl %eax, %r15d
movq -0x50(%rbp), %r14
movq %r13, -0x48(%rbp)
movq %rcx, -0x30(%rbp)
cmpq -0x168(%rbp), %rcx
je 0x1a9a6
movq -0xa0(%rbp), %rax
movslq (%rax), %r14
movq %r14, %rbx
shlq $0x5, %rbx
leaq 0x8(%rbx), %rdi
testq %r14, %r14
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %r14, (%rax)
testq %r14, %r14
je 0x1a4cb
leaq 0x18(%rax), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rcx
addq $-0x20, %rbx
jne 0x1a4b5
movl %r15d, -0xc4(%rbp)
movslq %r15d, %rcx
movq %rcx, -0x178(%rbp)
shlq $0x5, %rcx
movq %rcx, -0x170(%rbp)
addq $0x8, %rax
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movq -0x30(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
xorl %r12d, %r12d
leaq -0x158(%rbp), %r14
leaq -0x138(%rbp), %rbx
cmpq %r12, -0x98(%rbp)
je 0x1a538
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq %r12, %rdi
leaq 0x190a4(%rip), %rsi     # 0x335d1
callq 0x2350
addq $0x20, %r12
jmp 0x1a50b
movq -0x98(%rbp), %r12
movq %r12, -0x110(%rbp)
xorl %eax, %eax
movq -0x30(%rbp), %r13
cmpq %rax, -0x180(%rbp)
leaq -0x90(%rbp), %r12
je 0x1a686
movq %rax, -0x118(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x70(%rbp)
andq $0x0, -0x68(%rbp)
movb $0x0, -0x60(%rbp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x11c73
leaq -0xe8(%rbp), %r15
movq %r15, %rdi
leaq 0x1899d(%rip), %rsi     # 0x32f31
movq %rbx, %rdx
callq 0x11d49
leaq -0x108(%rbp), %rdi
movq %r15, %rsi
leaq 0x17edd(%rip), %rdx     # 0x3248a
callq 0x11ba1
movq %r14, %rbx
movq %r14, %rdi
movq -0x118(%rbp), %rsi
callq 0x11c73
movq %r12, %rdi
leaq -0x108(%rbp), %rsi
movq %rbx, %rdx
callq 0x11bca
leaq -0xc0(%rbp), %r14
movq %r14, %rdi
movq %r12, %rsi
leaq 0x1782f(%rip), %rdx     # 0x31e19
callq 0x11ba1
movq %r15, %r13
leaq -0x70(%rbp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x2210
movq %r14, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
movq %rbx, %rdi
leaq -0x138(%rbp), %rbx
callq 0x20f0
leaq -0x108(%rbp), %rdi
callq 0x20f0
movq %r13, %rdi
movq -0x30(%rbp), %r13
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq (%rax,%r13,8), %rdi
movq -0x110(%rbp), %r14
addq %r14, %rdi
movq %r15, %rsi
callq 0x2130
movq %r15, %rdi
callq 0x20f0
movq -0x118(%rbp), %rax
incq %rax
addq $0x20, %r14
movq %r14, -0x110(%rbp)
leaq -0x158(%rbp), %r14
jmp 0x1a54c
movq -0x48(%rbp), %r13
movq -0x178(%rbp), %rbx
movq -0x170(%rbp), %r14
movq -0xa0(%rbp), %rax
movslq (%rax), %rax
cmpq %rax, %rbx
jge 0x1a6ce
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq %r14, %rdi
leaq 0x18f11(%rip), %rsi     # 0x335d1
callq 0x2350
incq %rbx
addq $0x20, %r14
jmp 0x1a698
movq -0x30(%rbp), %rsi
leaq -0x200(%rbp), %r14
movq %r14, %rdi
cmpq %r13, %rsi
jne 0x1a7f8
movl %r13d, %esi
callq 0x11c73
leaq -0x220(%rbp), %rbx
movq %rbx, %rdi
leaq 0x18836(%rip), %rsi     # 0x32f34
movq %r14, %rdx
callq 0x11d49
movq -0x50(%rbp), %r14
leaq -0x158(%rbp), %rdi
movq %rbx, %rsi
leaq 0x18833(%rip), %rdx     # 0x32f4e
callq 0x11ba1
leaq -0x1e0(%rbp), %r12
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x11c73
leaq -0x138(%rbp), %rbx
movq %rbx, %rdi
leaq -0x158(%rbp), %rsi
movq %r12, %rdx
callq 0x11bca
leaq -0xe8(%rbp), %rdi
movq %rbx, %rsi
leaq 0x17c30(%rip), %rdx     # 0x3238d
callq 0x11ba1
leaq -0x1c0(%rbp), %r15
movq %r15, %rdi
movl %r13d, %esi
callq 0x11c73
leaq -0x108(%rbp), %r12
movq %r12, %rdi
leaq -0xe8(%rbp), %rsi
movq %r15, %rdx
callq 0x11bca
leaq -0x90(%rbp), %rdi
movq %r12, %rsi
leaq 0x187b7(%rip), %rdx     # 0x32f55
callq 0x11ba1
leaq -0x1a0(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x11c73
leaq -0xc0(%rbp), %r12
movq %r12, %rdi
leaq -0x90(%rbp), %r15
movq %r15, %rsi
movq %rbx, %rdx
callq 0x11bca
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x18efe(%rip), %rdx     # 0x336e0
callq 0x11ba1
movq 0x10(%rbp), %rdi
movq %rbx, %rsi
callq 0x120e4
jmp 0x1a904
callq 0x11c73
leaq -0x220(%rbp), %rbx
movq %rbx, %rdi
leaq 0x18726(%rip), %rsi     # 0x32f34
movq %r14, %rdx
callq 0x11d49
movq -0x50(%rbp), %r14
leaq -0x158(%rbp), %rdi
movq %rbx, %rsi
leaq 0x18741(%rip), %rdx     # 0x32f6c
callq 0x11ba1
leaq -0x1e0(%rbp), %r12
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x11c73
leaq -0x138(%rbp), %rbx
movq %rbx, %rdi
leaq -0x158(%rbp), %rsi
movq %r12, %rdx
callq 0x11bca
leaq -0xe8(%rbp), %rdi
movq %rbx, %rsi
leaq 0x17b20(%rip), %rdx     # 0x3238d
callq 0x11ba1
leaq -0x1c0(%rbp), %r15
movq %r15, %rdi
movq -0x30(%rbp), %rsi
callq 0x11c73
leaq -0x108(%rbp), %r12
movq %r12, %rdi
leaq -0xe8(%rbp), %rsi
movq %r15, %rdx
callq 0x11bca
leaq -0x90(%rbp), %rdi
movq %r12, %rsi
leaq 0x186a6(%rip), %rdx     # 0x32f55
callq 0x11ba1
leaq -0x1a0(%rbp), %rbx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x11c73
leaq -0xc0(%rbp), %r12
movq %r12, %rdi
leaq -0x90(%rbp), %r15
movq %r15, %rsi
movq %rbx, %rdx
callq 0x11bca
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x18ded(%rip), %rdx     # 0x336e0
callq 0x11ba1
movq 0x10(%rbp), %rdi
movq %rbx, %rsi
callq 0x120e4
movq %rbx, %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x20f0
leaq -0x1a0(%rbp), %rdi
callq 0x20f0
movq %r15, %rdi
callq 0x20f0
leaq -0x108(%rbp), %rdi
callq 0x20f0
leaq -0x1c0(%rbp), %rdi
callq 0x20f0
leaq -0xe8(%rbp), %rdi
callq 0x20f0
leaq -0x138(%rbp), %rdi
callq 0x20f0
leaq -0x1e0(%rbp), %rdi
callq 0x20f0
leaq -0x158(%rbp), %rdi
callq 0x20f0
leaq -0x220(%rbp), %rdi
callq 0x20f0
leaq -0x200(%rbp), %rdi
callq 0x20f0
movq -0x30(%rbp), %rcx
incq %rcx
movl -0xc4(%rbp), %r15d
incl %r15d
addq $0x20, -0x98(%rbp)
jmp 0x1a474
leaq -0x70(%rbp), %rax
movq %rax, -0x68(%rbp)
movq %rax, -0x70(%rbp)
andq $0x0, -0x60(%rbp)
leal (%r14,%r13), %r15d
leaq -0xc0(%rbp), %rbx
movl %r14d, -0xc0(%rbp)
cmpl %r15d, %r14d
jge 0x1a9e6
leaq -0x70(%rbp), %rdi
movq %rbx, %rsi
callq 0x279ac
movl -0xc0(%rbp), %r14d
incl %r14d
jmp 0x1a9c2
movq %rbx, -0xb8(%rbp)
movq %rbx, -0xc0(%rbp)
andq $0x0, -0xb0(%rbp)
leaq -0x90(%rbp), %r14
movl %r13d, -0x90(%rbp)
cmpl %r15d, %r13d
jge 0x1aa26
movq %rbx, %rdi
movq %r14, %rsi
callq 0x279ac
movl -0x90(%rbp), %r13d
incl %r13d
jmp 0x1aa03
leaq -0x108(%rbp), %rcx
andl $0x0, (%rcx)
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x196ec
leaq -0x90(%rbp), %rbx
movq -0x160(%rbp), %rdi
movq %rbx, %rsi
callq 0x123de
movq %rbx, %rdi
callq 0x11f0c
leaq -0xc0(%rbp), %rdi
callq 0x11f0c
leaq -0x70(%rbp), %rdi
callq 0x11f0c
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1ab7c
jmp 0x1aaa1
jmp 0x1aaa8
jmp 0x1aac3
jmp 0x1aad0
jmp 0x1aadd
jmp 0x1aab3
jmp 0x1aae7
jmp 0x1aabb
movq %rax, %rbx
jmp 0x1ab10
jmp 0x1aacb
movq %rax, %rbx
jmp 0x1aaf8
jmp 0x1aad8
jmp 0x1aae2
jmp 0x1aaec
movq %rax, %rbx
jmp 0x1ab64
movq %rax, %rbx
jmp 0x1ab4c
movq %rax, %rbx
jmp 0x1ab70
movq %rax, %rbx
jmp 0x1ab34
movq %rax, %rbx
jmp 0x1ab58
movq %rax, %rbx
jmp 0x1ab1c
movq %rax, %rbx
jmp 0x1ab40
movq %rax, %rbx
jmp 0x1ab04
movq %rax, %rbx
jmp 0x1ab28
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x20f0
leaq -0xc0(%rbp), %rdi
callq 0x20f0
leaq -0x1a0(%rbp), %rdi
callq 0x20f0
leaq -0x90(%rbp), %rdi
callq 0x20f0
leaq -0x108(%rbp), %rdi
callq 0x20f0
leaq -0x1c0(%rbp), %rdi
callq 0x20f0
leaq -0xe8(%rbp), %rdi
callq 0x20f0
leaq -0x138(%rbp), %rdi
callq 0x20f0
leaq -0x1e0(%rbp), %rdi
callq 0x20f0
leaq -0x158(%rbp), %rdi
callq 0x20f0
leaq -0x220(%rbp), %rdi
callq 0x20f0
leaq -0x200(%rbp), %rdi
jmp 0x1ac5a
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x11f0c
jmp 0x1ab90
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x11f0c
jmp 0x1ac5f
movq %rax, %rbx
jmp 0x1abd1
movq %rax, %rbx
jmp 0x1abc5
movq %rax, %rbx
jmp 0x1abb9
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x20f0
leaq -0xc0(%rbp), %rdi
callq 0x20f0
leaq -0x138(%rbp), %rdi
callq 0x20f0
leaq -0x90(%rbp), %rdi
callq 0x20f0
jmp 0x1abe7
movq %rax, %rbx
jmp 0x1abf3
movq %rax, %rbx
leaq -0x108(%rbp), %rdi
callq 0x20f0
leaq -0xe8(%rbp), %rdi
jmp 0x1ac5a
movq %rax, %rbx
jmp 0x1ac21
movq %rax, %rbx
jmp 0x1ac15
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x20f0
leaq -0x158(%rbp), %rdi
callq 0x20f0
leaq -0x108(%rbp), %rdi
callq 0x20f0
jmp 0x1ac3e
jmp 0x1ac31
movq %rax, %rbx
jmp 0x1ac56
movq %rax, %rbx
jmp 0x1ac4a
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x20f0
leaq -0x138(%rbp), %rdi
callq 0x20f0
leaq -0x70(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2330