// File: /workspace/github_cpp_makefile_star2_O3/JohnCGriffin[P]BrainForked/bf_main.cpp
// Function: main
int main(int argc, char** argv)
{
    bool dump = argc > 1 && !strcmp("-dump",argv[1]);
    if(dump){
	argc--;
	argv++;
    }
    std::ifstream ifs;

    if(argc == 2){
	ifs.open(argv[1]);
	if(!ifs){
	    std::cerr << "could not open " << argv[1] << std::endl;
	    return 1;
	}
    }

    std::istream& is(argc == 2 ? ifs : std::cin);

    auto instrs = bf::load_instructions(is);

    if(dump){
	auto while_level = 0;
	for(unsigned i=0; i<instrs.size(); i++){
	    auto instr = instrs[i];
	    if(instr.action == bf::TRUEJUMP){
		while_level--;
	    }
	    std::cout.width(6);
	    std::cout << i << " ";
	    for(int j=0; j<while_level; j++){
		std::cout << "	";
	    }
	    std::cout << instr.action << " " << instr.val << "\n";
	    if(instr.action == bf::FALSEJUMP){
		while_level++;
	    }
	}
	return 0;
    }

#ifdef PROFILER

    std::thread profiler([&]{
			     while(!current_loop) ;
			     while(current_loop){
				 auto count = counts[current_loop];
				 if(count > 500000){
				     break;
				 }
				 counts[current_loop]++;
				 std::this_thread::yield();
				 std::cout << std::flush;
			     }
			 });

    bf::execute(instrs);
    current_loop = 0;

    profiler.join();

    for(auto entry : counts){
	std::cout << entry.second << " " << entry.first
		  << " " << instrs.at(entry.first).val + entry.first << "\n";
    }
#else

    bf::execute(instrs);

#endif

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
cmpl $0x1, %edi
jle 0x25ba
movq %rsi, %rbx
movl %edi, %ebp
movq 0x8(%rsi), %rsi
leaq 0x3b0a(%rip), %rdi      # 0x6020
callq 0x2220
movl %eax, %r14d
xorl %r12d, %r12d
testl %eax, %eax
sete %r12b
subl %r12d, %ebp
leaq 0x40(%rsp), %rdi
callq 0x21d0
cmpl $0x2, %ebp
jne 0x25d0
xorl %r15d, %r15d
testl %r14d, %r14d
sete %r15b
shll $0x3, %r15d
movq 0x8(%rbx,%r15), %rsi
leaq 0x40(%rsp), %r14
movq %r14, %rdi
movl $0x8, %edx
callq 0x20f0
movq 0x40(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x60(%rsp,%rax)
je 0x25d7
movq 0x6a77(%rip), %r14      # 0x8ff0
leaq 0x3aa6(%rip), %rsi      # 0x6026
movl $0xf, %edx
movq %r14, %rdi
callq 0x21e0
movq 0x8(%rbx,%r15), %rbx
testq %rbx, %rbx
je 0x28b1
movq %rbx, %rdi
callq 0x20a0
movq 0x6a46(%rip), %rdi      # 0x8ff0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x21e0
jmp 0x28c9
leaq 0x40(%rsp), %rdi
callq 0x21d0
movq 0x6a0d(%rip), %r14      # 0x8fd8
xorl %r12d, %r12d
jmp 0x25d7
movq 0x6a01(%rip), %r14      # 0x8fd8
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x3974
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
movl $0x1, %edx
callq 0x4200
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rsi
movaps (%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0x2646
subq %rdi, %rsi
callq 0x21b0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2646
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rsi
cmpq %rcx, %rsi
je 0x2734
xorl %r13d, %r13d
movq %rsp, %rbx
leaq 0x3c(%rsp), %r15
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpl $0x2, (%rcx,%r13)
jne 0x26b7
movl %r14d, 0x3c(%rsp)
movq 0x8(%rsp), %rax
cmpq 0x10(%rsp), %rax
je 0x269f
movl %r14d, (%rax)
addq $0x4, %rax
movq %rax, 0x8(%rsp)
jmp 0x26b7
movq %rbx, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x30c4
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rsi
movq %rsi, %rdx
subq %rcx, %rdx
sarq $0x4, %rdx
cmpq %r14, %rdx
jbe 0x28fb
cmpl $0x10, (%rcx,%r13)
jne 0x2707
movq 0x8(%rsp), %rdi
movslq -0x4(%rdi), %rax
cmpq %rax, %rdx
jbe 0x290c
addq $-0x4, %rdi
movl %r14d, %r8d
subl %eax, %r8d
movq %rax, %r9
shlq $0x4, %r9
movw %r8w, 0x4(%rcx,%r9)
addl %ebp, %eax
movw %ax, 0x4(%rcx,%r13)
movq %rdi, 0x8(%rsp)
incq %r14
decl %ebp
addq $0x10, %r13
cmpq %rdx, %r14
jb 0x2679
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2734
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
movq 0x28(%rsp), %rsi
movl $0xf, (%rsp)
movw $0x0, 0x4(%rsp)
movq $0x0, 0x8(%rsp)
cmpq 0x30(%rsp), %rsi
je 0x2761
movups (%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x28(%rsp)
jmp 0x276e
leaq 0x20(%rsp), %rdi
movq %rsp, %rdx
callq 0x3200
testb %r12b, %r12b
je 0x2870
movq 0x20(%rsp), %rdi
cmpq %rdi, 0x28(%rsp)
je 0x287f
xorl %ebx, %ebx
movq 0x6830(%rip), %r14      # 0x8fc0
leaq 0x389f(%rip), %r12      # 0x6036
xorl %ebp, %ebp
movq %rbx, %rax
shlq $0x4, %rax
movups (%rdi,%rax), %xmm0
movaps %xmm0, (%rsp)
xorl %r13d, %r13d
cmpl $0x10, (%rsp)
sete %r15b
movq (%r14), %rax
movq -0x18(%rax), %rax
movq $0x6, 0x10(%r14,%rax)
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2120
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3857(%rip), %rsi      # 0x6034
callq 0x21e0
movb %r15b, %r13b
subl %r13d, %ebp
movl %ebp, %r15d
testl %ebp, %ebp
jle 0x2804
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rsi
callq 0x21e0
decl %r15d
jne 0x27ef
movq %r14, %rdi
movq %rsp, %rsi
callq 0x374c
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3813(%rip), %rsi      # 0x6034
callq 0x21e0
movswl 0x4(%rsp), %esi
movq %r13, %rdi
callq 0x2180
movl $0x1, %edx
movq %rax, %rdi
leaq 0x37f6(%rip), %rsi      # 0x6038
callq 0x21e0
xorl %eax, %eax
cmpl $0x2, (%rsp)
sete %al
addl %eax, %ebp
incl %ebx
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
subq %rdi, %rax
sarq $0x4, %rax
cmpq %rbx, %rax
ja 0x2799
jmp 0x287f
leaq 0x20(%rsp), %rdi
callq 0x2977
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2891
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
xorl %ebx, %ebx
leaq 0x40(%rsp), %rdi
callq 0x2050
movl %ebx, %eax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r14,%rax), %rdi
movl 0x20(%r14,%rax), %esi
orl $0x1, %esi
callq 0x22c0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x2190
movsbl %al, %esi
movq 0x6709(%rip), %rdi      # 0x8ff0
callq 0x2030
movl $0x1, %ebx
movq %rax, %rdi
callq 0x2130
jmp 0x2893
leaq 0x3738(%rip), %rdi      # 0x603a
movq %r14, %rsi
xorl %eax, %eax
callq 0x2270
leaq 0x3727(%rip), %rdi      # 0x603a
movq %rax, %rsi
xorl %eax, %eax
callq 0x2270
jmp 0x294b
jmp 0x294b
jmp 0x294b
jmp 0x2925
movq %rax, %rbx
jmp 0x2965
jmp 0x292e
jmp 0x292e
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x294e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
jmp 0x294e
jmp 0x294b
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2965
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21b0
leaq 0x40(%rsp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x22e0