// File: Sooryakiran[P]dotV/src/verilog.cpp
// Function: Chip::declare(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int)
void Chip::declare(wire e, int type){
    /*------------------------------------------------------------------------------------------

    This function is used to populate the Chip ports when declared.
    example :   declare("my_input", CHIP_INPUTS);
                declare("my_output", CHIP_OUTPUT); 
                declare("my_output_reg", CHIP_OUTPUT_REG);
    

    Param : c (wire), a port/wire name.
    Param : type (int), port type, 0 for CHIP_INPUTS, 1 for CHIP_OUTPUTS, 2 for CHIP_INPUT_REG 
            and 3 for CHIP_OUTPUT_REG.
    Returns : None
    ------------------------------------------------------------------------------------------*/
   
    string pre = "";
    if(this->n_bits > 1){
        pre = "[" + to_string(this->n_bits -1) + ": 0] ";
    } 
    
    if(type == CHIP_INPUTS){
        this->input_names.push_back(pre + e);
        this->is_input_reg.push_back(false);
    }
    else if(type == CHIP_OUTPUTS){
        this->output_names.push_back(pre + e);
        this->is_output_reg.push_back(false);
    }
    else if(type == CHIP_INPUTS_REG){
        this->input_names.push_back(pre + e);
        this->is_input_reg.push_back(true);
    }
    else if(type == CHIP_OUTPUTS_REG){
        this->output_names.push_back(pre + e);
        this->is_output_reg.push_back(true);
    }
    else{
        throw invalid_argument( "Invalid type for port." );
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rsi, -0x148(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x1da80
movq -0x138(%rbp), %rdx
leaq 0x289bb(%rip), %rsi     # 0x47111
leaq -0x38(%rbp), %rdi
callq 0x1d8a0
jmp 0x1e761
leaq -0x39(%rbp), %rdi
callq 0x1ca40
movq -0x140(%rbp), %rax
cmpl $0x1, 0x190(%rax)
jle 0x1e862
movq -0x140(%rbp), %rax
movl 0x190(%rax), %esi
decl %esi
leaq -0xb0(%rbp), %rdi
callq 0x1ced0
jmp 0x1e79b
leaq 0x289f1(%rip), %rsi     # 0x47193
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x1d820
jmp 0x1e7b7
leaq 0x28872(%rip), %rdx     # 0x47030
leaq -0x70(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x1b430
jmp 0x1e7d0
leaq -0x38(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x1cd30
leaq -0x70(%rbp), %rdi
callq 0x1bea0
leaq -0x90(%rbp), %rdi
callq 0x1bea0
leaq -0xb0(%rbp), %rdi
callq 0x1bea0
jmp 0x1e862
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x1ca40
jmp 0x1eb22
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1eb19
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x1e851
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x1bea0
leaq -0xb0(%rbp), %rdi
callq 0x1bea0
jmp 0x1eb19
cmpl $0x0, -0x14(%rbp)
jne 0x1e8f3
movq -0x148(%rbp), %rdx
movq -0x140(%rbp), %rax
addq $0xe0, %rax
movq %rax, -0x150(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1dee0
jmp 0x1e899
movq -0x150(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1c1b0
jmp 0x1e8ae
leaq -0xd0(%rbp), %rdi
callq 0x1bea0
movq -0x140(%rbp), %rdi
addq $0xf8, %rdi
xorl %esi, %esi
callq 0x1cdf0
jmp 0x1e8d1
jmp 0x1eb07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x1bea0
jmp 0x1eb19
cmpl $0x1, -0x14(%rbp)
jne 0x1e984
movq -0x148(%rbp), %rdx
movq -0x140(%rbp), %rax
addq $0x120, %rax            # imm = 0x120
movq %rax, -0x158(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1dee0
jmp 0x1e92a
movq -0x158(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x1c1b0
jmp 0x1e93f
leaq -0xf0(%rbp), %rdi
callq 0x1bea0
movq -0x140(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
xorl %esi, %esi
callq 0x1cdf0
jmp 0x1e962
jmp 0x1eb05
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x1bea0
jmp 0x1eb19
cmpl $0x2, -0x14(%rbp)
jne 0x1ea18
movq -0x148(%rbp), %rdx
movq -0x140(%rbp), %rax
addq $0xe0, %rax
movq %rax, -0x160(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1dee0
jmp 0x1e9bb
movq -0x160(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x1c1b0
jmp 0x1e9d0
leaq -0x110(%rbp), %rdi
callq 0x1bea0
movq -0x140(%rbp), %rdi
addq $0xf8, %rdi
movl $0x1, %esi
callq 0x1cdf0
jmp 0x1e9f6
jmp 0x1eb03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x1bea0
jmp 0x1eb19
cmpl $0x3, -0x14(%rbp)
jne 0x1eaa6
movq -0x148(%rbp), %rdx
movq -0x140(%rbp), %rax
addq $0x120, %rax            # imm = 0x120
movq %rax, -0x168(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1dee0
jmp 0x1ea4f
movq -0x168(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x1c1b0
jmp 0x1ea64
leaq -0x130(%rbp), %rdi
callq 0x1bea0
movq -0x140(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movl $0x1, %esi
callq 0x1cdf0
jmp 0x1ea8a
jmp 0x1eb01
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x1bea0
jmp 0x1eb19
movl $0x10, %edi
callq 0x1bb60
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x170(%rbp)
leaq 0x28572(%rip), %rsi     # 0x47036
callq 0x1de20
jmp 0x1eacb
movq -0x170(%rbp), %rdi
movq 0x34507(%rip), %rsi     # 0x52fe0
movq 0x344f0(%rip), %rdx     # 0x52fd0
callq 0x1d900
jmp 0x1eb2b
movq -0x170(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x1c0d0
jmp 0x1eb19
jmp 0x1eb03
jmp 0x1eb05
jmp 0x1eb07
leaq -0x38(%rbp), %rdi
callq 0x1bea0
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x1bea0
movq -0x48(%rbp), %rdi
callq 0x1da60
nopl (%rax,%rax)