// File: /workspace/github_cpp_makefile_star2_O1/AgathokakologicalBit[P]wit/src/main.cpp
// Function: main
int main(int argc, char* argv[])
{
  if (argc != 2)
  {
    char const *name = (argc > 0 ? argv[0] : "witcc");
    std::cerr << "Usage: " << name << ' ' << "<filename>" << std::endl;
    return EXIT_FAILURE;
  }
  
  std::ifstream ifs(argv[1]);
  if (!ifs)
  {
    std::cerr << "File could not be opened!\n";
    std::cerr << "Reason: " << strerror(errno) << std::endl;
    return EXIT_FAILURE;
  }
  std::string source((std::istreambuf_iterator<char>(ifs)),
                     (std::istreambuf_iterator<char>()   ));
  
  auto tokens = akbit::system::parsing::tokenize(source);
  // for (auto t : tokens)
  //   std::cout << t << std::endl;

  auto ast = akbit::system::parsing::parse(tokens);
  if (!ast) return EXIT_FAILURE;
  
  akbit::system::annotation::preprocess_ast(ast);
  akbit::system::annotation::generate_context(ast);

  dump_ast(ast, -1u, 0ul);
  std::cout << "\n\x1b[39mResult: "
    << (std::get<akbit::system::Node::module_t>(ast->value).has_errors ? "\x1b[01;41mFAILURE" : "\x1b[01;44mSUCCESS")
    << "\x1b[49m\x1b[00;39m" << std::endl;
  
  std::fstream js_output_file;
	js_output_file.open("program.out.js", std::ios::out);
  if (js_output_file)
  {
    js_output_file << akbit::system::code_generation::generate(ast, akbit::system::code_generation::GenerationTarget::Javascript, nullptr);
    js_output_file.close();
  }

  return EXIT_SUCCESS;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x4c0, %rsp            # imm = 0x4C0
cmpl $0x2, %edi
jne 0x4ea2
movq 0x8(%rsi), %rsi
leaq 0x2b8(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x3370
movq (%rbx), %rax
movq -0x18(%rax), %rcx
testb $0x5, 0x2d8(%rsp,%rcx)
je 0x4eb2
movq 0x181b1(%rip), %rdi     # 0x1cff0
leaq 0x10215(%rip), %rsi     # 0x1505b
movl $0x1a, %edx
callq 0x3240
movq 0x18199(%rip), %rbx     # 0x1cff0
leaq 0x10218(%rip), %rsi     # 0x15076
movl $0x8, %edx
movq %rbx, %rdi
callq 0x3240
callq 0x3040
movl (%rax), %edi
callq 0x30d0
testq %rax, %rax
je 0x4fff
movq %rax, %r14
movq %rax, %rdi
callq 0x3110
movq 0x1815e(%rip), %rdi     # 0x1cff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x3240
jmp 0x5016
testl %edi, %edi
jle 0x4f40
movq (%rsi), %rbx
jmp 0x4f47
movq -0x18(%rax), %rax
movq 0x3a0(%rsp,%rax), %rsi
leaq 0x80(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x70(%rsp), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x6f08
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x8298
movq %rsp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x96a4
movq (%rsp), %rax
testq %rax, %rax
je 0x504b
movq %rax, 0x30(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x5059
movq 0x18089(%rip), %rcx     # 0x1cfb8
cmpb $0x0, (%rcx)
je 0x5055
incl 0x8(%rax)
jmp 0x5059
leaq 0x100fb(%rip), %rbx     # 0x15042
movq 0x180a2(%rip), %r14     # 0x1cff0
leaq 0x100f3(%rip), %rsi     # 0x15048
movl $0x7, %edx
movq %r14, %rdi
callq 0x3240
testq %rbx, %rbx
je 0x4f83
movq %rbx, %rdi
callq 0x3110
movq 0x1807a(%rip), %rdi     # 0x1cff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3240
jmp 0x4f9b
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x3320
leaq 0xa8(%rsp), %rsi
movb $0x20, (%rsi)
movq 0x18043(%rip), %rdi     # 0x1cff0
movl $0x1, %edx
callq 0x3240
movq %rax, %rbx
leaq 0x1008f(%rip), %rsi     # 0x15050
movl $0xa, %edx
movq %rax, %rdi
callq 0x3240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3160
movl $0x1, %ebx
jmp 0x52e8
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x3320
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq 0x17fbc(%rip), %rdi     # 0x1cff0
callq 0x3030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x3160
jmp 0x52db
movl $0x1, %ebx
jmp 0x52a5
lock
incl 0x8(%rax)
leaq 0x30(%rsp), %rdi
callq 0xdb00
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5072
callq 0x6da4
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x509f
movq 0x17f27(%rip), %rcx     # 0x1cfb8
cmpb $0x0, (%rcx)
je 0x509b
incl 0x8(%rax)
jmp 0x509f
lock
incl 0x8(%rax)
leaq 0x20(%rsp), %rdi
callq 0xfacc
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x50b8
callq 0x6da4
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rsp)
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x50e5
movq 0x17ee1(%rip), %rcx     # 0x1cfb8
cmpb $0x0, (%rcx)
je 0x50e1
incl 0x8(%rax)
jmp 0x50e5
lock
incl 0x8(%rax)
leaq 0x10(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x4acc
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x5105
callq 0x6da4
movq 0x17eb4(%rip), %rdi     # 0x1cfc0
leaq 0xff6c(%rip), %rsi      # 0x1507f
movl $0xe, %edx
callq 0x3240
movq (%rsp), %rdi
addq $0x10, %rdi
callq 0x6ea4
leaq 0xff5d(%rip), %rcx      # 0x1508e
leaq 0xff66(%rip), %rsi      # 0x1509e
cmpb $0x0, 0x28(%rax)
cmovneq %rcx, %rsi
movq 0x17e79(%rip), %rdi     # 0x1cfc0
movl $0xf, %edx
callq 0x3240
movq 0x17e68(%rip), %rbx     # 0x1cfc0
leaq 0xff4f(%rip), %rsi      # 0x150ae
movl $0xd, %edx
movq %rbx, %rdi
callq 0x3240
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x31d0
movsbl %al, %esi
movq 0x17e36(%rip), %rdi     # 0x1cfc0
callq 0x3030
movq %rax, %rdi
callq 0x3160
leaq 0xa8(%rsp), %rdi
callq 0x3260
leaq 0xff11(%rip), %rsi      # 0x150bc
leaq 0xa8(%rsp), %rdi
movl $0x10, %edx
callq 0x31c0
movq 0xa8(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0xc8(%rsp,%rax)
jne 0x5296
movq (%rsp), %rax
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x51fc
movq 0x17dcc(%rip), %rcx     # 0x1cfb8
cmpb $0x0, (%rcx)
je 0x51f7
incl 0x8(%r14)
jmp 0x51fc
lock
incl 0x8(%r14)
movq %rax, 0x40(%rsp)
movq %r14, 0x48(%rsp)
testq %r14, %r14
je 0x5222
movq 0x17da6(%rip), %rax     # 0x1cfb8
cmpb $0x0, (%rax)
je 0x521d
incl 0x8(%r14)
jmp 0x5222
lock
incl 0x8(%r14)
leaq 0x50(%rsp), %rdi
leaq 0x40(%rsp), %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x12684
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x524a
callq 0x6da4
leaq 0xb8(%rsp), %rdi
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x3240
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x527c
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x31f0
testq %r14, %r14
je 0x5289
movq %r14, %rdi
callq 0x6da4
leaq 0xa8(%rsp), %rdi
callq 0x3050
leaq 0xa8(%rsp), %rdi
callq 0x3080
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x52b4
callq 0x6da4
leaq 0x90(%rsp), %rdi
callq 0x6b8c
movq 0x70(%rsp), %rdi
cmpq %r15, %rdi
je 0x52db
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x31f0
leaq 0x2b8(%rsp), %rdi
callq 0x3090
movl %ebx, %eax
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5329
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x31f0
jmp 0x5329
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x5329
callq 0x6da4
testq %r14, %r14
je 0x5365
movq %r14, %rdi
callq 0x6da4
jmp 0x5365
jmp 0x5380
movq %rax, %rbx
movq 0x18(%rsp), %rdi
jmp 0x5356
movq %rax, %rbx
movq 0x28(%rsp), %rdi
jmp 0x5356
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5383
callq 0x6da4
jmp 0x5383
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3080
jmp 0x5383
movq %rax, %rbx
jmp 0x5392
movq %rax, %rbx
jmp 0x539f
jmp 0x53bb
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5392
callq 0x6da4
leaq 0x90(%rsp), %rdi
callq 0x6b8c
movq 0x70(%rsp), %rdi
cmpq %r15, %rdi
je 0x53be
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x31f0
jmp 0x53be
movq %rax, %rbx
leaq 0x2b8(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3350
nop