// File: lukewagner[P]asmjs2wasm/src/main.cpp
// Function: main
int
main(int argc, char** argv)
try
{
  cin.exceptions(ios::failbit | ios::badbit);
  cout.exceptions(ios::failbit | ios::badbit);

  string chars;
  getline(cin, chars, '\0');

  memory::Pool pool;
  const asmjs_ast::Func& asmjs = parser::parse_asmjs(pool, chars);
  const wasm_ast::Module& wasm = emitter::emit_wasm(pool, asmjs);

  cout << wasm;

  return 0;
}
catch(const ios::failure& err)
{
  cerr << "Failed with runtime error: " << err.what() << endl;
  return -1;
}
catch(const runtime_error& err)
{
  cerr << "Failed with runtime error: " << err.what() << endl;
  return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x1ee50(%rip), %rax     # 0x21fd0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movl $0x4, %edi
movl $0x1, %esi
callq 0x3440
movl %eax, -0x8c(%rbp)
jmp 0x31a8
movl -0x8c(%rbp), %esi
movq -0x98(%rbp), %rdi
callq 0x2060
jmp 0x31bc
movq 0x1edf5(%rip), %rax     # 0x21fb8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0xa8(%rbp)
movl $0x4, %edi
movl $0x1, %esi
callq 0x3440
movl %eax, -0x9c(%rbp)
jmp 0x31eb
movl -0x9c(%rbp), %esi
movq -0xa8(%rbp), %rdi
callq 0x2060
jmp 0x31ff
leaq -0x40(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x2220
movq -0xb0(%rbp), %rsi
movq 0x1edb3(%rip), %rdi     # 0x21fd0
xorl %edx, %edx
callq 0x22e0
jmp 0x3226
leaq -0x68(%rbp), %rdi
callq 0x3460
jmp 0x3231
leaq -0x68(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x39f0
movq %rax, -0xb8(%rbp)
jmp 0x3247
movq -0xb8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0xf710
movq %rax, -0xc0(%rbp)
jmp 0x3268
movq -0xc0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rsi
movq 0x1ed3a(%rip), %rdi     # 0x21fb8
callq 0xf7b0
jmp 0x3285
movl $0x0, -0x4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x34a0
leaq -0x40(%rbp), %rdi
callq 0x2100
jmp 0x3417
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x32dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
jmp 0x32d4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x34a0
leaq -0x40(%rbp), %rdi
callq 0x2100
movl -0x1c(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl $0x2, %ecx
cmpl %ecx, %eax
jne 0x3369
movq -0x18(%rbp), %rdi
callq 0x20a0
movq %rax, -0x88(%rbp)
movq 0x1ece2(%rip), %rdi     # 0x21fe8
leaq 0x11cf7(%rip), %rsi     # 0x15004
callq 0x21a0
movq %rax, -0xd0(%rbp)
jmp 0x331b
movq -0x88(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x21a0
movq %rax, -0xd8(%rbp)
jmp 0x3343
movq -0xd8(%rbp), %rdi
movq 0x1ec4f(%rip), %rsi     # 0x21fa0
callq 0x21d0
jmp 0x3358
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
callq 0x2290
jmp 0x3417
movl -0xc4(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3423
movq -0x18(%rbp), %rdi
callq 0x20a0
movq %rax, -0x80(%rbp)
movq 0x1ec58(%rip), %rdi     # 0x21fe8
leaq 0x11c6d(%rip), %rsi     # 0x15004
callq 0x21a0
movq %rax, -0xe0(%rbp)
jmp 0x33a5
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
callq 0x21a0
movq %rax, -0xe8(%rbp)
jmp 0x33ca
movq -0xe8(%rbp), %rdi
movq 0x1ebc8(%rip), %rsi     # 0x21fa0
callq 0x21d0
jmp 0x33df
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
callq 0x2290
jmp 0x3417
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x2290
jmp 0x3400
jmp 0x3423
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
callq 0x2290
jmp 0x3415
jmp 0x3423
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
movq -0x18(%rbp), %rdi
callq 0x22b0
movq %rax, %rdi
callq 0x34c0
nopw %cs:(%rax,%rax)
nop