// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x80, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x13e3f(%rip), %rsi     # 0x1f131
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0xac60
movl 0x190(%rbx), %esi
cmpl $0x2, %esi
jl 0xb370
decl %esi
leaq -0x80(%rbp), %rdi
callq 0xa9a0
leaq 0x13e97(%rip), %rsi     # 0x1f1b3
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0xac40
leaq 0x13d1d(%rip), %rdx     # 0x1f050
leaq -0x40(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0xa150
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %r12
movq %r12, %rsi
callq 0xa920
movq %r12, %rdi
callq 0xa370
leaq -0xa0(%rbp), %rdi
callq 0xa370
leaq -0x80(%rbp), %rdi
callq 0xa370
cmpl $0x3, %r15d
ja 0xb47b
movl %r15d, %eax
leaq 0x13c7c(%rip), %rcx     # 0x1f000
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %r14, %rdx
callq 0xae70
leaq 0xe0(%rbx), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa2a0
leaq -0x40(%rbp), %rdi
callq 0xa370
movl $0xf8, %ecx
jmp 0xb452
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %r14, %rdx
callq 0xae70
leaq 0xe0(%rbx), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa2a0
leaq -0x40(%rbp), %rdi
callq 0xa370
movb $0x1, %al
movl $0xf8, %ecx
jmp 0xb454
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %r14, %rdx
callq 0xae70
leaq 0x120(%rbx), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa2a0
leaq -0x40(%rbp), %rdi
callq 0xa370
movb $0x1, %al
movl $0x138, %ecx            # imm = 0x138
jmp 0xb454
leaq -0x40(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq %r14, %rdx
callq 0xae70
leaq 0x120(%rbx), %rdi
leaq -0x40(%rbp), %rsi
callq 0xa2a0
leaq -0x40(%rbp), %rdi
callq 0xa370
movl $0x138, %ecx            # imm = 0x138
xorl %eax, %eax
addq %rcx, %rbx
movzbl %al, %esi
movq %rbx, %rdi
callq 0xa930
leaq -0x60(%rbp), %rdi
callq 0xa370
addq $0x80, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0xa3a0
movq %rax, %r14
leaq 0x13bc9(%rip), %rsi     # 0x1f056
movq %rax, %rdi
callq 0xae20
movq 0x1ab44(%rip), %rsi     # 0x25fe0
movq 0x1ab2d(%rip), %rdx     # 0x25fd0
movq %r14, %rdi
callq 0xaca0
movq %rax, %rbx
movq %r14, %rdi
callq 0xa530
jmp 0xb4f3
jmp 0xb4be
jmp 0xb4be
jmp 0xb4be
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
jmp 0xb4e7
jmp 0xb4f0
jmp 0xb4f0
jmp 0xb4f0
jmp 0xb4f0
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0xa370
jmp 0xb4e3
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0xa370
jmp 0xb4f3
jmp 0xb4f0
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0xa370
movq %rbx, %rdi
callq 0xad00