// File: /workspace/github_cpp_makefile_star2_O1/saumya-prakash[P]AssemblerEmulator/Assembler.cpp
// Function: Assembler::second_pass()
void Assembler::second_pass()
{
    for(list<struct line>::iterator it=lines.begin(); it!=lines.end(); ++it)
    {
        string s = it->s;

        istringstream iss(s);

        string mnemonic;

        iss>>mnemonic;

        map<string, pair<unsigned, unsigned> >::iterator mt=optab.find(mnemonic);

        if(mt==optab.end())     // unknown mnemonic error
        {
            errors.insert({it->line_no, Error(3)});
            continue;           // process next line
        } 

        unsigned i_type = mt->second.first;
        unsigned opcode = mt->second.second;

        if(i_type==0)   // 0-operand mnemonic
        {
            unsigned res = encode_zeroth(s, opcode, it->line_no);

            if(res!=0xffffffff)
                it->encoding = res;
        }

        else        // 1-operand mnemonic
        {
            unsigned res = encode_first(s, opcode, it->line_no, it->addr);

            if(res!=0xffffffff)
                it->encoding = res;
        }
    }


    return ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
leaq 0x60(%rdi), %r15
movq %rdi, 0x8(%rsp)
movq 0x60(%rdi), %rbx
cmpq %r15, %rbx
je 0x3bf3
leaq 0x70(%rsp), %r14
movq 0x8(%rsp), %rax
addq $0xc8, %rax
movq %rax, 0xa0(%rsp)
leaq 0x80(%rsp), %r12
leaq 0xa8(%rsp), %r13
leaq 0x60(%rsp), %rbp
leaq 0x90(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x10(%rbx), %rsi
movq 0x18(%rbx), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x32b6
movq %r13, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x22d0
movq %r14, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movb $0x0, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2230
leaq 0xa760(%rip), %rdi      # 0xe1c0
movq %rbp, %rsi
callq 0x8ef4
leaq 0xa759(%rip), %rcx      # 0xe1c8
cmpq %rcx, %rax
je 0x3a9d
leaq 0x30(%rbx), %rcx
cmpl $0x0, 0x40(%rax)
movl 0x44(%rax), %eax
movl %eax, 0x38(%rsp)
je 0x3b00
leaq 0x34(%rbx), %r8
movq 0x8(%rsp), %rdi
movq %r12, %rsi
leaq 0x38(%rsp), %rdx
callq 0x6732
jmp 0x3b12
movl $0x3, 0x14(%rsp)
leaq 0xa744(%rip), %rdi      # 0xe1f0
leaq 0x14(%rsp), %rsi
callq 0x839a
leaq 0x28(%rsp), %r14
movq %r14, 0x18(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0x32b6
movl 0x30(%rbx), %eax
movl %eax, 0x38(%rsp)
leaq 0x50(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq 0x18(%rsp), %rax
cmpq %r14, %rax
je 0x3b1c
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0x3b23
movq 0x8(%rsp), %rdi
movq %r12, %rsi
leaq 0x38(%rsp), %rdx
callq 0x64e6
cmpl $-0x1, %eax
je 0x3b8f
movl %eax, 0x38(%rbx)
jmp 0x3b8f
movups (%r14), %xmm0
movups %xmm0, (%rcx)
movq 0x20(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %r14, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
movq 0xa0(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x8ab0
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
leaq 0x70(%rsp), %r14
je 0x3b73
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3b8f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x60(%rsp), %rdi
cmpq %r14, %rdi
je 0x3ba6
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %r13, %rdi
movq 0xa420(%rip), %rsi      # 0xdfd0
callq 0x2270
leaq 0x120(%rsp), %rdi
callq 0x20b0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x3be7
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x21c0
movq (%rbx), %rbx
cmpq %r15, %rbx
jne 0x3a08
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c4f
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3c26
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3c52
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x3c52
jmp 0x3c4f
jmp 0x3c4f
movq %rax, %rbx
jmp 0x3c8f
jmp 0x3c4f
movq %rax, %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x3c6e
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0xa35b(%rip), %rsi      # 0xdfd0
leaq 0xa8(%rsp), %rdi
callq 0x2270
leaq 0x120(%rsp), %rdi
callq 0x20b0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x3cb4
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x22e0