// File: /workspace/github_cpp_makefile_star2_O3/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 0x4e05
movq 0x8(%rsi), %rsi
leaq 0x2b8(%rsp), %rbx
movq %rbx, %rdi
movl $0x8, %edx
callq 0x3370
movq (%rbx), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x2d8(%rsp,%rax)
je 0x4e51
movq 0x1824e(%rip), %rdi     # 0x1cff0
leaq 0x102b2(%rip), %rsi     # 0x1505b
movl $0x1a, %edx
callq 0x3240
movq 0x18236(%rip), %rbx     # 0x1cff0
leaq 0x102b5(%rip), %rsi     # 0x15076
movl $0x8, %edx
movq %rbx, %rdi
callq 0x3240
callq 0x3040
movl (%rax), %edi
callq 0x30d0
testq %rax, %rax
je 0x4f78
movq %rax, %r14
movq %rax, %rdi
callq 0x3110
movq 0x181fb(%rip), %rdi     # 0x1cff0
movq %r14, %rsi
movq %rax, %rdx
callq 0x3240
jmp 0x4f8f
testl %edi, %edi
jle 0x4edb
movq (%rsi), %rbx
movq 0x181d9(%rip), %r14     # 0x1cff0
leaq 0x1022a(%rip), %rsi     # 0x15048
movl $0x7, %edx
movq %r14, %rdi
callq 0x3240
testq %rbx, %rbx
jne 0x4efa
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x3320
jmp 0x4f14
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 0x6ee0
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x82be
movq %rsp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x96c9
movq (%rsp), %rax
testq %rax, %rax
je 0x4fc4
movq %rax, 0x40(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x4fd2
movq 0x180ee(%rip), %rcx     # 0x1cfb8
cmpb $0x0, (%rcx)
je 0x4fce
incl 0x8(%rax)
jmp 0x4fd2
movq 0x1810e(%rip), %rdi     # 0x1cff0
leaq 0x1015f(%rip), %rsi     # 0x15048
movl $0x7, %edx
callq 0x3240
leaq 0x10148(%rip), %rbx     # 0x15042
movq %rbx, %rdi
callq 0x3110
movq 0x180e7(%rip), %rdi     # 0x1cff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3240
leaq 0xa8(%rsp), %rsi
movb $0x20, (%rsi)
movq 0x180ca(%rip), %rdi     # 0x1cff0
movl $0x1, %edx
callq 0x3240
movq %rax, %rbx
leaq 0x10116(%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 0x526c
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 0x18043(%rip), %rdi     # 0x1cff0
callq 0x3030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x3160
jmp 0x525f
movl $0x1, %ebx
jmp 0x5229
lock
incl 0x8(%rax)
leaq 0x40(%rsp), %rdi
callq 0xdaf4
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x4feb
callq 0x6d78
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x30(%rsp)
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x5018
movq 0x17fae(%rip), %rcx     # 0x1cfb8
cmpb $0x0, (%rcx)
je 0x5014
incl 0x8(%rax)
jmp 0x5018
lock
incl 0x8(%rax)
leaq 0x30(%rsp), %rdi
callq 0xfbd4
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x5031
callq 0x6d78
movq (%rsp), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x505e
movq 0x17f68(%rip), %rcx     # 0x1cfb8
cmpb $0x0, (%rcx)
je 0x505a
incl 0x8(%rax)
jmp 0x505e
lock
incl 0x8(%rax)
leaq 0x20(%rsp), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
xorl %edx, %edx
callq 0x4a2c
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x507e
callq 0x6d78
movq 0x17f3b(%rip), %rdi     # 0x1cfc0
leaq 0xfff3(%rip), %rsi      # 0x1507f
movl $0xe, %edx
callq 0x3240
movq (%rsp), %rdi
addq $0x10, %rdi
callq 0x6e7d
leaq 0xffe4(%rip), %rcx      # 0x1508e
leaq 0xffed(%rip), %rsi      # 0x1509e
cmpb $0x0, 0x28(%rax)
cmovneq %rcx, %rsi
movq 0x17f00(%rip), %rdi     # 0x1cfc0
movl $0xf, %edx
callq 0x3240
movq 0x17eef(%rip), %rbx     # 0x1cfc0
leaq 0xffd6(%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 0x17ebd(%rip), %rdi     # 0x1cfc0
callq 0x3030
movq %rax, %rdi
callq 0x3160
leaq 0xa8(%rsp), %rdi
callq 0x3260
leaq 0xff98(%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 0x521a
movq (%rsp), %rax
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x517a
movq 0x17e53(%rip), %rcx     # 0x1cfb8
cmpb $0x0, (%rcx)
je 0x518a
incl 0x8(%r14)
movq %rax, 0x10(%rsp)
movq %r14, 0x18(%rsp)
jmp 0x51a2
movq %rax, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
jmp 0x51a6
lock
incl 0x8(%r14)
cmpb $0x0, (%rcx)
movq %rax, 0x10(%rsp)
movq %r14, 0x18(%rsp)
je 0x527b
incl 0x8(%r14)
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x1273c
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x51ce
callq 0x6d78
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 0x5200
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x31f0
testq %r14, %r14
je 0x520d
movq %r14, %rdi
callq 0x6d78
leaq 0xa8(%rsp), %rdi
callq 0x3050
leaq 0xa8(%rsp), %rdi
callq 0x3080
xorl %ebx, %ebx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5238
callq 0x6d78
leaq 0x90(%rsp), %rdi
callq 0x6b54
movq 0x70(%rsp), %rdi
cmpq %r15, %rdi
je 0x525f
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
lock
incl 0x8(%r14)
jmp 0x51a6
movq %rax, %rbx
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x52b7
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x31f0
jmp 0x52b7
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x52b7
callq 0x6d78
testq %r14, %r14
je 0x52f3
movq %r14, %rdi
callq 0x6d78
jmp 0x52f3
jmp 0x530e
movq %rax, %rbx
movq 0x28(%rsp), %rdi
jmp 0x52e4
movq %rax, %rbx
movq 0x38(%rsp), %rdi
jmp 0x52e4
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x5311
callq 0x6d78
jmp 0x5311
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x3080
jmp 0x5311
movq %rax, %rbx
jmp 0x5320
movq %rax, %rbx
jmp 0x532d
jmp 0x5349
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x5320
callq 0x6d78
leaq 0x90(%rsp), %rdi
callq 0x6b54
movq 0x70(%rsp), %rdi
cmpq %r15, %rdi
je 0x534c
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x31f0
jmp 0x534c
movq %rax, %rbx
leaq 0x2b8(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3350
nop