// File: /workspace/github_cpp_makefile_star2_O2/mniip[P]sandbox/wakeup.cpp
// Function: do_wakeup()
void do_wakeup()
{
	pthread_cancel(feed_in->native_handle());
	feed_in->join();
	fcntl(out_pipe[0], F_SETFL, fcntl(out_pipe[0], F_GETFL) | O_NONBLOCK);
	pthread_kill(feed_out->native_handle(), SIGUSR1);
	feed_out->join();
	fcntl(out_pipe[0], F_SETFL, fcntl(out_pipe[0], F_GETFL) & ~O_NONBLOCK);
	delete feed_in;
	delete feed_out;
	if(old_client != -1)
		close(old_client);
	else
	{
		kill(getppid(), SIGUSR1);
		close(fileno(stdin));
		close(fileno(stdout));
		close(fileno(stderr));
	}
	unset_timer();

	int server = socket(AF_UNIX, SOCK_STREAM, 0);
	if(server < 0)
		panic_errno("socket");

	struct sockaddr_un addr;
	memset(&addr, 0, sizeof addr);
	addr.sun_family = AF_UNIX;
	strncpy(addr.sun_path, (conf_sockdir + "/socket_" + ident).c_str(), sizeof addr.sun_path - 1);
	if(bind(server, (struct sockaddr *)&addr, sizeof addr))
		panic_errno("bind");

	if(listen(server, 1))
		panic_errno("listen");

	int client = accept(server, NULL, NULL);
	if(client < 0)
		panic_errno("accept");

	close(server);
	unlink((conf_sockdir + "/socket_" + ident).c_str());

	feed_in = new std::thread(feed_data, client, in_pipe[1], false, !conf_wakeup);
	feed_out = new std::thread(feed_data, out_pipe[0], client, false, false);

	old_client = client;
	set_timer();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq 0x8aca(%rip), %rax      # 0x12498
movq (%rax), %rdi
callq 0x45a0
movq 0x8abb(%rip), %rdi      # 0x12498
callq 0x4740
movl 0x8aa7(%rip), %r14d     # 0x12490
pushq $0x3
popq %rbx
movl %r14d, %edi
movl %ebx, %esi
xorl %eax, %eax
callq 0x4290
orl $0x800, %eax            # imm = 0x800
pushq $0x4
popq %rbp
movl %r14d, %edi
movl %ebp, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x4290
movq 0x8a8b(%rip), %rax      # 0x124a0
movq (%rax), %rdi
pushq $0xa
popq %rsi
callq 0x4510
movq 0x8a79(%rip), %rdi      # 0x124a0
callq 0x4740
movl 0x8a5d(%rip), %r14d     # 0x12490
movl %r14d, %edi
movl %ebx, %esi
xorl %eax, %eax
callq 0x4290
andl $0xfffff7ff, %eax       # imm = 0xFFFFF7FF
movl %r14d, %edi
movl %ebp, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x4290
movq 0x8a3f(%rip), %rbx      # 0x12498
testq %rbx, %rbx
je 0x9a66
movq %rbx, %rdi
callq 0xa35e
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x4420
movq 0x8a28(%rip), %rbx      # 0x124a0
testq %rbx, %rbx
je 0x9a85
movq %rbx, %rdi
callq 0xa35e
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x4420
movl 0x899a(%rip), %edi      # 0x12430
cmpl $-0x1, %edi
jne 0x9ae7
callq 0x45b0
pushq $0xa
popq %rsi
movl %eax, %edi
callq 0x45d0
movq 0x850f(%rip), %rax      # 0x11fc0
movq (%rax), %rdi
callq 0x4450
movl %eax, %edi
callq 0x4800
movq 0x84d9(%rip), %rax      # 0x11fa0
movq (%rax), %rdi
callq 0x4450
movl %eax, %edi
callq 0x4800
movq 0x84fb(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
callq 0x4450
movl %eax, %edi
callq 0x4800
callq 0x997e
pushq $0x1
popq %rdi
movl %edi, %esi
xorl %edx, %edx
callq 0x4100
movl %eax, %ebx
testl %eax, %eax
jns 0x9b39
leaq 0x2dfc(%rip), %rsi      # 0xc906
leaq 0xa8(%rsp), %rdi
leaq 0xca(%rsp), %rdx
callq 0x5422
leaq 0xa8(%rsp), %rdi
callq 0x8e3a
leaq 0xa8(%rsp), %rdi
callq 0x4828
andw $0x0, 0x136(%rsp)
movw $0x1, 0xca(%rsp)
leaq 0x8a85(%rip), %rsi      # 0x125d8
leaq 0x2db3(%rip), %rdx      # 0xc90d
leaq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x8a05
movq 0x8912(%rip), %rdx      # 0x12480
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x9084
leaq 0xcc(%rsp), %rdi
leaq 0x8(%rsp), %r14
movq (%r14), %rsi
pushq $0x6b
popq %rdx
callq 0x4240
movq %r14, %rdi
callq 0x4828
leaq 0x28(%rsp), %rdi
callq 0x4828
leaq 0xca(%rsp), %rsi
pushq $0x6e
popq %rdx
movl %ebx, %edi
callq 0x4090
testl %eax, %eax
je 0x9bee
leaq 0x2d54(%rip), %rsi      # 0xc916
leaq 0x88(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5422
leaq 0x88(%rsp), %rdi
callq 0x8e3a
leaq 0x88(%rsp), %rdi
callq 0x4828
pushq $0x1
popq %rsi
movl %ebx, %edi
callq 0x4470
testl %eax, %eax
je 0x9c26
leaq 0x2d18(%rip), %rsi      # 0xc91b
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5422
leaq 0x68(%rsp), %rdi
callq 0x8e3a
leaq 0x68(%rsp), %rdi
callq 0x4828
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4180
movl %eax, 0x4(%rsp)
testl %eax, %eax
jns 0x9c63
leaq 0x2ce2(%rip), %rsi      # 0xc922
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5422
leaq 0x48(%rsp), %rdi
callq 0x8e3a
leaq 0x48(%rsp), %rdi
callq 0x4828
movl %ebx, %edi
callq 0x4800
leaq 0x8967(%rip), %rsi      # 0x125d8
leaq 0x2c95(%rip), %rdx      # 0xc90d
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
callq 0x8a05
movq 0x87f4(%rip), %rdx      # 0x12480
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x9084
leaq 0x8(%rsp), %rbx
movq (%rbx), %rdi
callq 0x4210
movq %rbx, %rdi
callq 0x4828
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x4828
pushq $0x8
popq %rdi
callq 0x4410
movq %rax, %r14
movb $0x0, (%rbx)
leaq 0x8928(%rip), %rax      # 0x125f8
movb (%rax), %al
xorb $0x1, %al
movb %al, (%r15)
leaq -0x4c2(%rip), %rsi      # 0x981c
leaq 0x87a7(%rip), %rcx      # 0x1248c
leaq 0x4(%rsp), %rdx
leaq 0x8(%rsp), %r8
leaq 0x28(%rsp), %r9
movq %r14, %rdi
callq 0xa36c
movq %r14, 0x8795(%rip)      # 0x12498
pushq $0x8
popq %rdi
callq 0x4410
movq %rax, %r14
xorl %eax, %eax
leaq 0x8(%rsp), %r8
movb %al, (%r8)
leaq 0x28(%rsp), %r9
movb %al, (%r9)
leaq -0x50b(%rip), %rsi      # 0x981c
leaq 0x8762(%rip), %rdx      # 0x12490
leaq 0x4(%rsp), %rcx
movq %r14, %rdi
callq 0xa36c
movq %r14, 0x875e(%rip)      # 0x124a0
movl 0x4(%rsp), %eax
movl %eax, 0x86e4(%rip)      # 0x12430
callq 0x993b
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x9db4
jmp 0x9d93
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x9db4
jmp 0x9d93
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x9db4
jmp 0x9d93
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x9db4
movq %rax, %rbx
jmp 0x9db9
jmp 0x9d9a
movq %rax, %rbx
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x4420
jmp 0x9db9
jmp 0x9dac
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4828
movq %rbx, %rdi
callq 0x4770