// File: s0sasaki[P]ExecutableBlockchain/main.cpp
// Function: main
int main()
{
    Blockchain blockchain = Blockchain();
    VM vm = VM();
    Compiler compiler = Compiler();
    int32_t bin_data[Block::DATA_SIZE];
    char src_data1[] = "\
    : main              \n\
        1 2 3 4 * + + . \n\
    ; ";
    char src_data2[] = "\
    : square            \n\
        dup *           \n\
    ;                   \n\
    : main              \n\
        5 square .      \n\
    ; ";
    char src_data3[] = "\
    : main              \n\
        10 square .     \n\
    ; ";

    std::cout << src_data1 << std::endl;
    compiler.compile(bin_data, src_data1, blockchain.chain.size());
    vm.exec(bin_data, blockchain);
    blockchain.addBlock(Block(bin_data));
    std::cout << "Block mined: " << blockchain.chain.back().hash << std::endl;

    std::cout << src_data2 << std::endl;
    compiler.compile(bin_data, src_data2, blockchain.chain.size());
    vm.exec(bin_data, blockchain);
    blockchain.addBlock(Block(bin_data));
    std::cout << "Block mined: " << blockchain.chain.back().hash << std::endl;

    std::cout << src_data3 << std::endl;
    compiler.compile(bin_data, src_data3, blockchain.chain.size());
    vm.exec(bin_data, blockchain);
    blockchain.addBlock(Block(bin_data));
    std::cout << "Block mined: " << blockchain.chain.back().hash << std::endl;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x9490, %rsp           # imm = 0x9490
movl $0x0, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x89d0
leaq -0x51c8(%rbp), %rdi
callq 0xa500
jmp 0x25f9
xorps %xmm0, %xmm0
movaps %xmm0, -0x51f0(%rbp)
movaps %xmm0, -0x5200(%rbp)
movaps %xmm0, -0x5210(%rbp)
movaps %xmm0, -0x5220(%rbp)
movaps %xmm0, -0x5230(%rbp)
movaps %xmm0, -0x5240(%rbp)
leaq -0x5240(%rbp), %rdi
callq 0x2a70
movups 0x9a00(%rip), %xmm0     # 0xc039
movups %xmm0, -0x6257(%rbp)
movaps 0x99e9(%rip), %xmm0     # 0xc030
movaps %xmm0, -0x6260(%rbp)
movaps 0x99cb(%rip), %xmm0     # 0xc020
movaps %xmm0, -0x6270(%rbp)
movaps 0x99ad(%rip), %xmm0     # 0xc010
movaps %xmm0, -0x6280(%rbp)
leaq 0x99df(%rip), %rsi      # 0xc050
leaq -0x6310(%rbp), %rdi
movl $0x84, %edx
callq 0x21a0
movups 0x9a80(%rip), %xmm0     # 0xc109
movups %xmm0, -0x6327(%rbp)
movaps 0x9a69(%rip), %xmm0     # 0xc100
movaps %xmm0, -0x6330(%rbp)
movaps 0x9a4b(%rip), %xmm0     # 0xc0f0
movaps %xmm0, -0x6340(%rbp)
movaps 0x9a2d(%rip), %xmm0     # 0xc0e0
movaps %xmm0, -0x6350(%rbp)
movq 0xf90f(%rip), %rdi      # 0x11fd0
leaq -0x6280(%rbp), %rsi
callq 0x2210
movq %rax, -0x9448(%rbp)
jmp 0x26d6
movq -0x9448(%rbp), %rdi
movq 0xf8dc(%rip), %rsi      # 0x11fc0
callq 0x2250
jmp 0x26eb
leaq -0x28(%rbp), %rdi
callq 0x2aa0
movl %eax, %ecx
leaq -0x5240(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
leaq -0x6280(%rbp), %rdx
callq 0x3960
jmp 0x2712
leaq -0x51c8(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xad80
jmp 0x272b
leaq -0x73a0(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
callq 0x8520
jmp 0x2740
leaq -0x28(%rbp), %rdi
leaq -0x73a0(%rbp), %rsi
callq 0x8cd0
jmp 0x2752
leaq -0x73a0(%rbp), %rdi
callq 0x2ad0
movq 0xf86b(%rip), %rdi      # 0x11fd0
leaq 0x99ad(%rip), %rsi      # 0xc119
callq 0x2210
movq %rax, -0x9450(%rbp)
jmp 0x277a
leaq -0x28(%rbp), %rdi
callq 0x2b00
movq -0x9450(%rbp), %rdi
movq %rax, %rsi
callq 0x21c0
movq %rax, -0x9458(%rbp)
jmp 0x279b
movq -0x9458(%rbp), %rdi
movq 0xf817(%rip), %rsi      # 0x11fc0
callq 0x2250
jmp 0x27b0
movq 0xf819(%rip), %rdi      # 0x11fd0
leaq -0x6310(%rbp), %rsi
callq 0x2210
movq %rax, -0x9460(%rbp)
jmp 0x27cc
movq -0x9460(%rbp), %rdi
movq 0xf7e6(%rip), %rsi      # 0x11fc0
callq 0x2250
jmp 0x27e1
leaq -0x28(%rbp), %rdi
callq 0x2aa0
movl %eax, %ecx
leaq -0x5240(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
leaq -0x6310(%rbp), %rdx
callq 0x3960
jmp 0x2808
leaq -0x51c8(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xad80
jmp 0x2821
leaq -0x83f0(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
callq 0x8520
jmp 0x2836
leaq -0x28(%rbp), %rdi
leaq -0x83f0(%rbp), %rsi
callq 0x8cd0
jmp 0x2848
leaq -0x83f0(%rbp), %rdi
callq 0x2ad0
movq 0xf775(%rip), %rdi      # 0x11fd0
leaq 0x98b7(%rip), %rsi      # 0xc119
callq 0x2210
movq %rax, -0x9468(%rbp)
jmp 0x2870
leaq -0x28(%rbp), %rdi
callq 0x2b00
movq -0x9468(%rbp), %rdi
movq %rax, %rsi
callq 0x21c0
movq %rax, -0x9470(%rbp)
jmp 0x2891
movq -0x9470(%rbp), %rdi
movq 0xf721(%rip), %rsi      # 0x11fc0
callq 0x2250
jmp 0x28a6
movq 0xf723(%rip), %rdi      # 0x11fd0
leaq -0x6350(%rbp), %rsi
callq 0x2210
movq %rax, -0x9478(%rbp)
jmp 0x28c2
movq -0x9478(%rbp), %rdi
movq 0xf6f0(%rip), %rsi      # 0x11fc0
callq 0x2250
jmp 0x28d7
leaq -0x28(%rbp), %rdi
callq 0x2aa0
movl %eax, %ecx
leaq -0x5240(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
leaq -0x6350(%rbp), %rdx
callq 0x3960
jmp 0x28fe
leaq -0x51c8(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xad80
jmp 0x2917
leaq -0x9440(%rbp), %rdi
leaq -0x6240(%rbp), %rsi
callq 0x8520
jmp 0x292c
leaq -0x28(%rbp), %rdi
leaq -0x9440(%rbp), %rsi
callq 0x8cd0
jmp 0x293e
leaq -0x9440(%rbp), %rdi
callq 0x2ad0
movq 0xf67f(%rip), %rdi      # 0x11fd0
leaq 0x97c1(%rip), %rsi      # 0xc119
callq 0x2210
movq %rax, -0x9480(%rbp)
jmp 0x2966
leaq -0x28(%rbp), %rdi
callq 0x2b00
movq -0x9480(%rbp), %rdi
movq %rax, %rsi
callq 0x21c0
movq %rax, -0x9488(%rbp)
jmp 0x2987
movq -0x9488(%rbp), %rdi
movq 0xf62b(%rip), %rsi      # 0x11fc0
callq 0x2250
jmp 0x299c
movl $0x0, -0x4(%rbp)
leaq -0x5240(%rbp), %rdi
callq 0x2b40
leaq -0x28(%rbp), %rdi
callq 0x2b70
movl -0x4(%rbp), %eax
addq $0x9490, %rsp           # imm = 0x9490
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x51d0(%rbp)
movl %eax, -0x51d4(%rbp)
jmp 0x2a56
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x51d0(%rbp)
movl %eax, -0x51d4(%rbp)
jmp 0x2a4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x51d0(%rbp)
movl %eax, -0x51d4(%rbp)
leaq -0x73a0(%rbp), %rdi
callq 0x2ad0
jmp 0x2a4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x51d0(%rbp)
movl %eax, -0x51d4(%rbp)
leaq -0x83f0(%rbp), %rdi
callq 0x2ad0
jmp 0x2a4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x51d0(%rbp)
movl %eax, -0x51d4(%rbp)
leaq -0x9440(%rbp), %rdi
callq 0x2ad0
leaq -0x5240(%rbp), %rdi
callq 0x2b40
leaq -0x28(%rbp), %rdi
callq 0x2b70
movq -0x51d0(%rbp), %rdi
callq 0x2350
nopl (%rax,%rax)