// File: /workspace/github_cpp_makefile_star2_O3/mniip[P]sandbox/main.cpp
// Function: main
int main(int argc, char **argv)
{
	if(argc < 3 || (std::string(argv[2]) == "kill" && argc < 4))
	{
		fprintf(stderr, "Usage: %s <config.conf> <ident> [prog [args...]]\n", argv[0]);
		fprintf(stderr, "       %s <config.conf> kill <ident>\n", argv[0]);
		abort();
	}

	ident = std::string(argv[2]) == "kill" ? argv[3] : argv[2];
	read_conf(argv[1]);

	if(std::string(argv[2]) == "kill")
	{
		kill_session();
		printf("Done\n");
		exit(EXIT_SUCCESS);
	}

	try_connect();

	signal(SIGUSR1, ignore);

	int pid = fork();
	if(pid < 0)
		panic_errno("fork");

	if(!pid)
	{
		if(pipe(in_pipe))
			panic_errno("pipe");
		if(pipe(out_pipe))
			panic_errno("pipe");
		if(argc >= 4)
		{
			main_process = sandbox.spawn_process(argv[3], argc - 3, argv + 3, set_limits);
		}
		else
		{
			std::vector<char *> av;
			for(std::vector<std::string>::iterator i = conf_arg.begin(), end = conf_arg.end(); i != end; i++)
				av.push_back(&(*i)[0]);
			main_process = sandbox.spawn_process(conf_program.c_str(), av.size(), av.data(), set_limits);
		}
		close(in_pipe[0]);
		close(out_pipe[1]);
		feed_in = new std::thread(feed_data, fileno(stdin), in_pipe[1], true, !conf_wakeup);
		feed_out = new std::thread(feed_data, out_pipe[0], fileno(stdout), false, false);
		sandbox.event_loop();
		exit(0);
	}
	else
	{
		signal(SIGUSR1, detach);
		wait(NULL);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %rbx
cmpl $0x3, %edi
jl 0x5342
movl %edi, %ebp
movq 0x10(%rbx), %rsi
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x55d4
leaq 0x9454(%rip), %rsi      # 0xe507
movq %r14, %rdi
callq 0x4110
movl %ebp, %ecx
xorl $0x3, %ecx
orl %eax, %ecx
sete %r15b
movq (%r14), %rdi
leaq 0x20(%rsp), %r12
cmpq %r12, %rdi
je 0x50e0
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43e0
testb %r15b, %r15b
jne 0x5342
movq 0x10(%rbx), %rsi
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x55d4
leaq 0x9401(%rip), %rsi      # 0xe507
movq %r14, %rdi
callq 0x4110
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
movq 0x10(%rbx,%rcx,8), %rax
leaq 0xe34f(%rip), %rcx      # 0x13470
movq %rax, (%rcx)
movq (%r14), %rdi
cmpq %r12, %rdi
je 0x5139
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43e0
movq 0x8(%rbx), %rsi
leaq 0x98(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x55d4
leaq 0x98(%rsp), %rdi
callq 0xc2d0
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x517d
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x43e0
movq 0x10(%rbx), %rsi
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x55d4
leaq 0x936d(%rip), %rsi      # 0xe507
movq %r15, %rdi
callq 0x4110
movl %eax, %r14d
movq (%r15), %rdi
cmpq %r12, %rdi
je 0x51ba
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x43e0
testl %r14d, %r14d
je 0x534a
addq $0x18, %rbx
callq 0xb921
leaq -0x15d(%rip), %rsi      # 0x5076
movl $0xa, %edi
callq 0x4480
callq 0x40f0
testl %eax, %eax
js 0x52cd
jne 0x5316
leaq 0xe281(%rip), %r14      # 0x13478
movq %r14, %rdi
callq 0x4540
testl %eax, %eax
jne 0x5362
leaq 0xe272(%rip), %r15      # 0x13480
movq %r15, %rdi
callq 0x4540
testl %eax, %eax
jne 0x53af
cmpl $0x3, %ebp
jne 0x53fb
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0xe291(%rip), %rax      # 0x134d0
movq (%rax), %r13
movq 0x8(%rax), %rbp
xorl %ecx, %ecx
movl $0x0, %edx
cmpq %rbp, %r13
je 0x5283
leaq 0x10(%rsp), %rbx
leaq 0x8(%rsp), %r12
movq (%r13), %rax
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xa1a0
addq $0x20, %r13
cmpq %rbp, %r13
jne 0x525c
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
leaq 0xe226(%rip), %rax      # 0x134b0
movq (%rax), %rsi
subq %rcx, %rdx
shrq $0x3, %rdx
leaq 0xe1a5(%rip), %rdi      # 0x13440
leaq -0x3a6(%rip), %r8       # 0x4efc
callq 0x5612
movl %eax, 0xe18b(%rip)      # 0x13438
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x541f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x43e0
jmp 0x541f
leaq 0x88(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x9284(%rip), %rsi      # 0xe564
leaq 0x9281(%rip), %rdx      # 0xe568
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x9234
movq %rbx, %rdi
callq 0xa3cc
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0x5316
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x43e0
leaq -0x2af(%rip), %rsi      # 0x506e
movl $0xa, %edi
callq 0x4480
xorl %edi, %edi
callq 0x44c0
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x4820
callq 0xbc11
leaq 0x9431(%rip), %rdi      # 0xe787
callq 0x4650
xorl %edi, %edi
callq 0x44a0
leaq 0x68(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x91f6(%rip), %rsi      # 0xe569
leaq 0x91f3(%rip), %rdx      # 0xe56d
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x9234
movq %r15, %rdi
callq 0xa3cc
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x5207
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x43e0
jmp 0x5207
leaq 0x48(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x91aa(%rip), %rsi      # 0xe569
leaq 0x91a7(%rip), %rdx      # 0xe56d
leaq 0x38(%rsp), %r12
movq %r12, %rdi
callq 0x9234
movq %r12, %rdi
callq 0xa3cc
movq 0x38(%rsp), %rdi
cmpq %r13, %rdi
je 0x521e
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x43e0
jmp 0x521e
movq (%rbx), %rsi
addl $-0x3, %ebp
leaq 0xe038(%rip), %rdi      # 0x13440
leaq -0x513(%rip), %r8       # 0x4efc
movl %ebp, %edx
movq %rbx, %rcx
callq 0x5612
movl %eax, 0xe019(%rip)      # 0x13438
movl (%r14), %edi
callq 0x47e0
movl 0x4(%r15), %edi
callq 0x47e0
movl $0x8, %edi
callq 0x43d0
movq %rax, %r15
movq 0xdb6c(%rip), %rax      # 0x12fb0
movq (%rax), %rdi
callq 0x4420
leaq 0x10(%rsp), %rdx
movl %eax, (%rdx)
leaq 0x8(%rsp), %r8
movb $0x1, (%r8)
leaq 0xe185(%rip), %rax      # 0x135e8
movb (%rax), %al
xorb $0x1, %al
leaq 0x7(%rsp), %r9
movb %al, (%r9)
addq $0x4, %r14
leaq 0x5cfe(%rip), %rsi      # 0xb178
movq %r15, %rdi
movq %r14, %rcx
callq 0x57ca
leaq 0xdffc(%rip), %rax      # 0x13488
movq %r15, (%rax)
movl $0x8, %edi
callq 0x43d0
movq %rax, %r14
movq 0xdae5(%rip), %rax      # 0x12f88
movq (%rax), %rdi
callq 0x4420
leaq 0x10(%rsp), %rcx
movl %eax, (%rcx)
xorl %eax, %eax
leaq 0x8(%rsp), %r8
movb %al, (%r8)
leaq 0x7(%rsp), %r9
movb %al, (%r9)
leaq 0x5cad(%rip), %rsi      # 0xb178
leaq 0xdfae(%rip), %rdx      # 0x13480
movq %r14, %rdi
callq 0x5866
leaq 0xdfaf(%rip), %rax      # 0x13490
movq %r14, (%rax)
leaq 0xdf55(%rip), %rdi      # 0x13440
callq 0x5902
jmp 0x535b
jmp 0x5507
movq %rax, %rbx
movl $0x8, %esi
movq %r14, %rdi
jmp 0x5589
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5593
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
jmp 0x5589
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r13, %rdi
je 0x5593
movq 0x48(%rsp), %rsi
jmp 0x5586
movq %rax, %rbx
movl $0x8, %esi
movq %r15, %rdi
jmp 0x5589
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r12, %rdi
je 0x5593
movq 0x68(%rsp), %rsi
jmp 0x5586
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0x5593
movq 0x88(%rsp), %rsi
jmp 0x5586
movq %rax, %rbx
leaq 0xa8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5593
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x43e0
jmp 0x5593
movq %rax, %rbx
movq %rbx, %rdi
callq 0x4770
nop