// File: /workspace/github_cpp_makefile_star2_O3/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), %r14
cmpq %r15, %r14
je 0x3bea
leaq 0x70(%rsp), %rbx
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(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x3298
movq %r13, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x22d0
movq %rbx, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movb $0x0, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2230
leaq 0xa76a(%rip), %rdi      # 0xe1c0
movq %rbp, %rsi
callq 0x8e58
leaq 0xa763(%rip), %rcx      # 0xe1c8
cmpq %rcx, %rax
je 0x3a93
leaq 0x30(%r14), %rcx
cmpl $0x0, 0x40(%rax)
movl 0x44(%rax), %eax
movl %eax, 0x38(%rsp)
je 0x3af7
leaq 0x34(%r14), %r8
movq 0x8(%rsp), %rdi
movq %r12, %rsi
leaq 0x38(%rsp), %rdx
callq 0x66b2
jmp 0x3b09
movl $0x3, 0x14(%rsp)
leaq 0xa74e(%rip), %rdi      # 0xe1f0
leaq 0x14(%rsp), %rsi
callq 0x82f6
leaq 0x28(%rsp), %rbx
movq %rbx, 0x18(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %rdi
callq 0x3298
movl 0x30(%r14), %eax
movl %eax, 0x38(%rsp)
leaq 0x50(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq 0x18(%rsp), %rax
cmpq %rbx, %rax
je 0x3b14
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0x3b1a
movq 0x8(%rsp), %rdi
movq %r12, %rsi
leaq 0x38(%rsp), %rdx
callq 0x6466
cmpl $-0x1, %eax
je 0x3b86
movl %eax, 0x38(%r14)
jmp 0x3b86
movups (%rbx), %xmm0
movups %xmm0, (%rcx)
movq 0x20(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %rbx, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
movq 0xa0(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x8a12
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
leaq 0x70(%rsp), %rbx
je 0x3b6a
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3b86
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x60(%rsp), %rdi
cmpq %rbx, %rdi
je 0x3b9d
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %r13, %rdi
movq 0xa429(%rip), %rsi      # 0xdfd0
callq 0x2270
leaq 0x120(%rsp), %rdi
callq 0x20b0
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x3bde
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x21c0
movq (%r14), %r14
cmpq %r15, %r14
jne 0x39fe
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c46
movq %rax, %r14
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x3c1d
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x3c49
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21c0
jmp 0x3c49
jmp 0x3c46
jmp 0x3c46
movq %rax, %r14
jmp 0x3c86
jmp 0x3c46
movq %rax, %r14
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x3c65
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x21c0
movq 0xa364(%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 0x3cab
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x21c0
movq %r14, %rdi
callq 0x22e0
nop