// File: /workspace/github_cpp_makefile_star2_O3/JohnWoodman[P]SHellNo/listener.cpp
// Function: listener::listener(int)
listener::listener(int port){
	this->port = port;
	string portString = to_string(port);
	const char* PORT= portString.c_str();
	memset(&hints, 0, sizeof hints);
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_PASSIVE; // use my IP

	if ((rv = getaddrinfo(NULL, PORT, &hints, &servinfo)) != 0) {
		fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
		return;
	}

	// loop through all the results and bind to the first we can
	for(p = servinfo; p != NULL; p = p->ai_next) {
		if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
			perror("server: socket");
			continue;
		}

		if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
			perror("setsockopt");
			return;
		}

		if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
			close(sockfd);
			perror("server: bind");
			continue;
		}
		break;
	}

	freeaddrinfo(servinfo); // all done with this structure

	if (p == NULL)  {
		fprintf(stderr, "server: failed to bind\n");
		return;
	}

	if (listen(sockfd, 1) == -1) {
		perror("listen");
		return;
	}

	sa.sa_handler = sigchld_handler; // reap all dead processes
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	if (sigaction(SIGCHLD, &sa, NULL) == -1) {
		perror("sigaction");
		return;
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r14d
movq %rdi, %rbx
movq $0x1, 0x180(%rdi)
movl %esi, %r15d
negl %r15d
cmovsl %esi, %r15d
movl %esi, 0x8(%rdi)
movl $0x1, %r12d
cmpl $0xa, %r15d
jb 0x140d3
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x140ca
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x140d0
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x140d3
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x14097
addl $-0x3, %r12d
jmp 0x140d3
addl $-0x2, %r12d
jmp 0x140d3
decl %r12d
shrl $0x1f, %r14d
leal (%r12,%r14), %esi
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
leaq -0x48(%rbp), %r13
movq %r13, %rdi
movl $0x2d, %edx
callq 0x5420
addq (%r13), %r14
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x14f37
movq (%r13), %rsi
leaq 0x20(%rbx), %rdx
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x30(%rbx)
movl $0x1, %eax
movl %eax, 0x28(%rbx)
movl %eax, 0x20(%rbx)
leaq 0x50(%rbx), %r14
xorl %edi, %edi
movq %r14, %rcx
callq 0x5470
movl %eax, 0x1b8(%rbx)
testl %eax, %eax
jne 0x1426f
movq 0x50(%rbx), %rax
movq %rax, 0x58(%rbx)
testq %rax, %rax
je 0x141e4
leaq 0x180(%rbx), %r15
leaq 0x2f17(%rip), %r12      # 0x1707a
leaq 0x2f2a(%rip), %r13      # 0x17094
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x50d0
movl %eax, 0x10(%rbx)
movq %r12, %rdi
cmpl $-0x1, %eax
je 0x141c9
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movq %r15, %rcx
movl $0x4, %r8d
callq 0x5640
cmpl $-0x1, %eax
je 0x1429a
movl 0x10(%rbx), %edi
movq 0x58(%rbx), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
callq 0x5090
cmpl $-0x1, %eax
jne 0x141df
movl 0x10(%rbx), %edi
callq 0x56f0
movq %r13, %rdi
callq 0x52f0
movq 0x58(%rbx), %rax
movq 0x28(%rax), %rax
movq %rax, 0x58(%rbx)
testq %rax, %rax
jne 0x1416a
movq (%r14), %rdi
jmp 0x141e6
xorl %edi, %edi
leaq -0x38(%rbp), %r15
callq 0x54b0
cmpq $0x0, 0x58(%rbx)
je 0x1427c
movl 0x10(%rbx), %edi
movl $0x1, %esi
callq 0x53d0
cmpl $-0x1, %eax
je 0x14283
leaq 0xe8(%rbx), %r14
leaq -0x212(%rip), %rax      # 0x14008
movq %rax, 0xe8(%rbx)
leaq 0xf0(%rbx), %rdi
callq 0x5450
movl $0x10000000, 0x170(%rbx) # imm = 0x10000000
movl $0x11, %edi
movq %r14, %rsi
xorl %edx, %edx
callq 0x5460
cmpl $-0x1, %eax
je 0x1428c
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x14260
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x5370
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x5874
leaq -0x38(%rbp), %r15
jmp 0x1424b
callq 0x58a4
jmp 0x1424b
leaq 0x2e2f(%rip), %rdi      # 0x170b9
jmp 0x14293
leaq 0x2e2d(%rip), %rdi      # 0x170c0
callq 0x52f0
jmp 0x1424b
leaq 0x2de8(%rip), %rdi      # 0x17089
callq 0x52f0
jmp 0x14276
jmp 0x142aa
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x142c6
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x5370
movq %rbx, %rdi
callq 0x5630