// File: /workspace/github_cpp_makefile_star2_O2/pollow[P]MIPSClide/assembler.cpp
// Function: Assembler::print(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::ostream&)
void Assembler::print(string type, ostream &out) {

#ifdef DEBUG
    for(auto i = statements.begin(); i != statements.end(); i++) {
        cout << setfill('0') << setw(4) << i-statements.begin() << " : " << *i << endl;
    }
#endif

    if ( type == "coe" ) {
        out << "memory_initialization_radix=16;" << endl << "memory_initialization_vector=" << endl;
        for(auto i : machine_code) {
            out << setfill('0') << setw(8) << hex << i << ',' << endl;
        }
        out << "00000000;" << endl;
    } else if ( type == "plain" ) {
        for(auto i : machine_code) {
            out << setfill('0') << setw(8) << hex << i << endl;
        }
    } else {
        throw invalid_argument("Output type could only be 'coe' or 'plain'");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, -0x30(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdi, %r14
movq 0x20(%rdi), %r12
pushq $0x30
popq %r13
leaq 0x10a90(%rip), %r15     # 0x1c41b
movq %r12, %rbx
cmpq 0x28(%r14), %rbx
je 0xb9ee
movq 0x1e60d(%rip), %rdi     # 0x29fa8
movl %r13d, %esi
callq 0x5480
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0x4, 0x10(%rax,%rcx)
movq %r12, %rsi
subq 0x20(%r14), %rsi
sarq $0x5, %rsi
movq %rax, %rdi
callq 0x52f0
movq %rax, %rdi
movq %r15, %rsi
callq 0x5300
movq %rax, %rdi
movq %rbx, %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5180
addq $0x20, %rbx
addq $0x20, %r12
jmp 0xb98e
leaq 0x10a2a(%rip), %rsi     # 0x1c41f
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0xbdb1
testb %al, %al
je 0xbaa5
leaq 0x10a13(%rip), %rsi     # 0x1c423
movq -0x30(%rbp), %rdi
callq 0x5300
movq %rax, %rdi
callq 0x5180
leaq 0x10a1b(%rip), %rsi     # 0x1c443
movq %rax, %rdi
callq 0x5300
movq %rax, %rdi
callq 0x5180
movq 0x50(%r14), %r12
movq 0x58(%r14), %r13
pushq $0x30
popq %rbx
pushq $0x2c
popq %r14
cmpq %r13, %r12
je 0xbb15
movl (%r12), %r15d
movq -0x30(%rbp), %rdi
movl %ebx, %esi
callq 0x5480
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x8, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movq %r15, %rsi
callq 0x5220
movq %rax, %rdi
movl %r14d, %esi
callq 0x53a0
movq %rax, %rdi
callq 0x5180
addq $0x4, %r12
jmp 0xba47
leaq 0x109bf(%rip), %rsi     # 0x1c46b
movq %rbx, %rdi
callq 0xbdb1
testb %al, %al
je 0xbb4a
movq 0x50(%r14), %r15
movq 0x58(%r14), %r12
pushq $0x30
popq %rbx
cmpq %r12, %r15
je 0xbb3b
movl (%r15), %r14d
movq -0x30(%rbp), %rdi
movl %ebx, %esi
callq 0x5480
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x8, 0x10(%rax,%rdx)
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rax,%rcx)
movq %rax, %rdi
movq %r14, %rsi
callq 0x5220
movq %rax, %rdi
callq 0x5180
addq $0x4, %r15
jmp 0xbac7
leaq 0x10945(%rip), %rsi     # 0x1c461
movq -0x30(%rbp), %rdi
callq 0x5300
movq %rax, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5180
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x10
popq %rdi
callq 0x5190
movq %rax, %rbx
leaq 0x10915(%rip), %rsi     # 0x1c471
movq %rax, %rdi
callq 0x55c0
movq 0x1e465(%rip), %rsi     # 0x29fd0
movq 0x1e446(%rip), %rdx     # 0x29fb8
movq %rbx, %rdi
callq 0x5510
movq %rax, %r14
movq %rbx, %rdi
callq 0x5260
movq %r14, %rdi
callq 0x5560
nop