// File: /workspace/github_cpp_makefile_star2_O2/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 0x51b1
movl %edi, %ebp
movq 0x10(%rbx), %rsi
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x5422
leaq 0x751b(%rip), %rsi      # 0xc507
movq %r15, %rdi
callq 0x5414
movl %eax, %r14d
movq %r15, %rdi
callq 0x4828
cmpl $0x3, %ebp
jne 0x500d
testb %r14b, %r14b
jne 0x51b1
movq 0x10(%rbx), %rsi
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x5422
leaq 0x74dd(%rip), %rsi      # 0xc507
movq %r14, %rdi
callq 0x5414
movzbl %al, %eax
movq 0x10(%rbx,%rax,8), %rax
leaq 0xd43f(%rip), %rcx      # 0x12480
movq %rax, (%rcx)
movq %r14, %rdi
callq 0x4828
movq 0x8(%rbx), %rsi
leaq 0x98(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x5422
leaq 0x98(%rsp), %rdi
callq 0xa420
leaq 0x98(%rsp), %rdi
callq 0x4828
movq 0x10(%rbx), %rsi
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x5422
leaq 0x746e(%rip), %rsi      # 0xc507
movq %r14, %rdi
callq 0x5414
movl %eax, %r15d
movq %r14, %rdi
callq 0x4828
testb %r15b, %r15b
jne 0x51e5
addq $0x18, %rbx
callq 0x9dc1
leaq -0x116(%rip), %rsi      # 0x4faf
pushq $0xa
popq %rdi
callq 0x4490
callq 0x4130
testl %eax, %eax
js 0x515d
jne 0x5187
leaq 0xd3a1(%rip), %r14      # 0x12488
movq %r14, %rdi
callq 0x4570
testl %eax, %eax
jne 0x51fd
leaq 0xd392(%rip), %r15      # 0x12490
movq %r15, %rdi
callq 0x4570
testl %eax, %eax
jne 0x522c
cmpl $0x3, %ebp
jne 0x525b
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0xd3b2(%rip), %rax      # 0x124e0
movq (%rax), %r13
movq 0x8(%rax), %rbp
leaq 0x8(%rsp), %r12
cmpq %rbp, %r13
je 0x5281
movq (%r13), %rax
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x8bce
addq $0x20, %r13
jmp 0x513a
leaq 0x7400(%rip), %rsi      # 0xc564
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x5422
leaq 0x78(%rsp), %rdi
callq 0x8e3a
leaq 0x78(%rsp), %rdi
callq 0x4828
leaq -0x1e7(%rip), %rsi      # 0x4fa7
pushq $0xa
popq %rdi
callq 0x4490
xorl %edi, %edi
callq 0x44d0
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xce20(%rip), %r14      # 0x11fd8
movq (%r14), %rdi
movq (%rbx), %rdx
leaq 0x7347(%rip), %rsi      # 0xc50c
xorl %eax, %eax
callq 0x45e0
movq (%r14), %rdi
movq (%rbx), %rdx
leaq 0x7365(%rip), %rsi      # 0xc53e
xorl %eax, %eax
callq 0x45e0
callq 0x4280
callq 0x9f82
leaq 0x7596(%rip), %rdi      # 0xc787
callq 0x4660
xorl %edi, %edi
callq 0x44b0
leaq 0x7365(%rip), %rsi      # 0xc569
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x5422
leaq 0x58(%rsp), %rdi
callq 0x8e3a
leaq 0x58(%rsp), %rdi
callq 0x4828
jmp 0x50f7
leaq 0x7336(%rip), %rsi      # 0xc569
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x5422
leaq 0x38(%rsp), %rdi
callq 0x8e3a
leaq 0x38(%rsp), %rdi
callq 0x4828
jmp 0x510e
movq (%rbx), %rsi
addl $-0x3, %ebp
leaq 0xd1e8(%rip), %rdi      # 0x12450
leaq -0x433(%rip), %r8       # 0x4e3c
movl %ebp, %edx
movq %rbx, %rcx
callq 0x545e
movl %eax, 0xd1c9(%rip)      # 0x12448
jmp 0x52bf
leaq 0xd238(%rip), %rax      # 0x124c0
movq (%rax), %rsi
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rdx
subq %rcx, %rdx
shrq $0x3, %rdx
leaq 0xd1ad(%rip), %rdi      # 0x12450
leaq -0x46e(%rip), %r8       # 0x4e3c
callq 0x545e
movl %eax, 0xd193(%rip)      # 0x12448
leaq 0x10(%rsp), %rdi
callq 0x8b9a
movl (%r14), %edi
callq 0x4800
movl 0x4(%r15), %edi
callq 0x4800
pushq $0x8
popq %rdi
callq 0x4410
movq %rax, %r15
movq 0xccde(%rip), %rax      # 0x11fc0
movq (%rax), %rdi
callq 0x4450
leaq 0x10(%rsp), %rdx
movl %eax, (%rdx)
leaq 0x8(%rsp), %r8
movb $0x1, (%r8)
leaq 0xd2f7(%rip), %rax      # 0x125f8
movb (%rax), %al
xorb $0x1, %al
leaq 0x7(%rsp), %r9
movb %al, (%r9)
addq $0x4, %r14
leaq 0x4504(%rip), %rsi      # 0x981c
movq %r15, %rdi
movq %r14, %rcx
callq 0x55cc
leaq 0xd16e(%rip), %rax      # 0x12498
movq %r15, (%rax)
pushq $0x8
popq %rdi
callq 0x4410
movq %rax, %r14
movq 0xcc61(%rip), %rax      # 0x11fa0
movq (%rax), %rdi
callq 0x4450
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 0x44b5(%rip), %rsi      # 0x981c
leaq 0xd122(%rip), %rdx      # 0x12490
movq %r14, %rdi
callq 0x5664
leaq 0xd123(%rip), %rax      # 0x124a0
movq %r14, (%rax)
leaq 0xd0c9(%rip), %rdi      # 0x12450
callq 0x56fc
jmp 0x51f6
jmp 0x53a8
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r14, %rdi
jmp 0x53c0
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x53ec
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x8b9a
jmp 0x53f6
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r15, %rdi
callq 0x4420
jmp 0x53f6
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x53ec
jmp 0x53f3
jmp 0x53f3
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x53ec
jmp 0x53f3
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x4828
jmp 0x53f6
movq %rax, %rbx
movq %rbx, %rdi
callq 0x4770