// 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, int)
void Chip::declare(wire e, int type, int width){
    /*------------------------------------------------------------------------------------------

    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.
    Param : width (int), Bit width of port. If no width is specified, it is assumed to be of the
            parent Chip's width.
    Returns : None
    ------------------------------------------------------------------------------------------*/ 
    
    string pre = "";
    if(width>1){
        pre = "[" + to_string(width -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 %ecx, %r12d
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x13c08(%rip), %rsi     # 0x1f131
leaq -0x60(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0xac60
cmpl $0x2, %r12d
jl 0xb5a6
decl %r12d
leaq -0x80(%rbp), %rdi
movl %r12d, %esi
callq 0xa9a0
leaq 0x13c61(%rip), %rsi     # 0x1f1b3
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0xac40
leaq 0x13ae7(%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 0xb6b1
movl %r15d, %eax
leaq 0x13a56(%rip), %rcx     # 0x1f010
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 0xb688
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 0xb68a
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 0xb68a
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 0x13993(%rip), %rsi     # 0x1f056
movq %rax, %rdi
callq 0xae20
movq 0x1a90e(%rip), %rsi     # 0x25fe0
movq 0x1a8f7(%rip), %rdx     # 0x25fd0
movq %r14, %rdi
callq 0xaca0
movq %rax, %rbx
movq %r14, %rdi
callq 0xa530
jmp 0xb729
jmp 0xb6f4
jmp 0xb6f4
jmp 0xb6f4
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
jmp 0xb71d
jmp 0xb726
jmp 0xb726
jmp 0xb726
jmp 0xb726
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0xa370
jmp 0xb719
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0xa370
jmp 0xb729
jmp 0xb726
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0xa370
movq %rbx, %rdi
callq 0xad00