// File: devaigergely81[P]flex-bison-example/code_generator_implementation.cc
// Function: generate_code(std::__cxx11::list<instruction*, std::allocator<instruction*>>*)
void generate_code(std::list<instruction*>* commands) {
    std::cout << "global main" << std::endl;
    std::cout << "extern write_natural" << std::endl;
    std::cout << "extern read_natural" << std::endl;
    std::cout << "extern write_boolean" << std::endl;
    std::cout << "extern read_boolean" << std::endl;
    std::cout << std::endl;
    std::cout << "section .bss" << std::endl;
    std::map<std::string,symbol>::iterator it;
    for(it = symbol_table.begin(); it != symbol_table.end(); ++it) {
        std::cout << it->second.get_code();
    }
    std::cout << std::endl;
    std::cout << "section .text" << std::endl;
    std::cout << "main:" << std::endl;
    generate_code_of_commands(std::cout, commands);
    std::cout << "xor eax,eax" << std::endl;
    std::cout << "ret" << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq 0xd0e5(%rip), %rdi      # 0x1ffc8
leaq 0x465e(%rip), %rsi      # 0x17548
callq 0x4290
movq %rax, %rdi
movq 0xd0bf(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xd0c3(%rip), %rdi      # 0x1ffc8
leaq 0x4648(%rip), %rsi      # 0x17554
callq 0x4290
movq %rax, %rdi
movq 0xd09d(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xd0a1(%rip), %rdi      # 0x1ffc8
leaq 0x463b(%rip), %rsi      # 0x17569
callq 0x4290
movq %rax, %rdi
movq 0xd07b(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xd07f(%rip), %rdi      # 0x1ffc8
leaq 0x462d(%rip), %rsi      # 0x1757d
callq 0x4290
movq %rax, %rdi
movq 0xd059(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xd05d(%rip), %rdi      # 0x1ffc8
leaq 0x4620(%rip), %rsi      # 0x17592
callq 0x4290
movq %rax, %rdi
movq 0xd037(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xd03b(%rip), %rdi      # 0x1ffc8
movq 0xd024(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xd028(%rip), %rdi      # 0x1ffc8
leaq 0x45ff(%rip), %rsi      # 0x175a6
callq 0x4290
movq %rax, %rdi
movq 0xd002(%rip), %rsi      # 0x1ffb8
callq 0x42d0
leaq -0x10(%rbp), %rdi
callq 0x13230
leaq 0xd325(%rip), %rdi      # 0x202f0
callq 0x13250
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x10(%rbp)
leaq 0xd30d(%rip), %rdi      # 0x202f0
callq 0xfbe0
movq %rax, -0x20(%rbp)
leaq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x13280
testb $0x1, %al
jne 0x12fff
jmp 0x1305c
leaq -0x10(%rbp), %rdi
callq 0x132b0
movq %rax, %rsi
addq $0x20, %rsi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x58(%rbp)
callq 0x10d20
movq -0x58(%rbp), %rsi
movq 0xcfa1(%rip), %rdi      # 0x1ffc8
callq 0x4270
jmp 0x1302e
leaq -0x40(%rbp), %rdi
callq 0x41c0
leaq -0x10(%rbp), %rdi
callq 0x10960
jmp 0x12fdc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x41c0
jmp 0x1310d
movq 0xcf65(%rip), %rdi      # 0x1ffc8
movq 0xcf4e(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xcf52(%rip), %rdi      # 0x1ffc8
leaq 0x4536(%rip), %rsi      # 0x175b3
callq 0x4290
movq %rax, %rdi
movq 0xcf2c(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xcf30(%rip), %rdi      # 0x1ffc8
leaq 0x4522(%rip), %rsi      # 0x175c1
callq 0x4290
movq %rax, %rdi
movq 0xcf0a(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq -0x8(%rbp), %rsi
movq 0xcf0a(%rip), %rdi      # 0x1ffc8
callq 0x12b40
movq 0xcefe(%rip), %rdi      # 0x1ffc8
leaq 0x44f6(%rip), %rsi      # 0x175c7
callq 0x4290
movq %rax, %rdi
movq 0xced8(%rip), %rsi      # 0x1ffb8
callq 0x42d0
movq 0xcedc(%rip), %rdi      # 0x1ffc8
leaq 0x44e0(%rip), %rsi      # 0x175d3
callq 0x4290
movq %rax, %rdi
movq 0xceb6(%rip), %rsi      # 0x1ffb8
callq 0x42d0
addq $0x60, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x4470
nopw %cs:(%rax,%rax)