// File: /workspace/github_cpp_makefile_star2_O1/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 0x1400f
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x14006
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x1400c
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x1400f
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x13fd3
addl $-0x3, %r12d
jmp 0x1400f
addl $-0x2, %r12d
jmp 0x1400f
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 0x14e6d
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), %rcx
xorl %edi, %edi
callq 0x5470
movl %eax, 0x1b8(%rbx)
testl %eax, %eax
jne 0x141a5
movq 0x50(%rbx), %rax
movq %rax, 0x58(%rbx)
testq %rax, %rax
je 0x14118
leaq 0x180(%rbx), %r14
leaq 0x2fde(%rip), %r15      # 0x1707a
leaq 0x2ff1(%rip), %r12      # 0x17094
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x50d0
movl %eax, 0x10(%rbx)
movq %r15, %rdi
cmpl $-0x1, %eax
je 0x14102
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movq %r14, %rcx
movl $0x4, %r8d
callq 0x5640
cmpl $-0x1, %eax
je 0x141d0
movl 0x10(%rbx), %edi
movq 0x58(%rbx), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
callq 0x5090
cmpl $-0x1, %eax
jne 0x14118
movl 0x10(%rbx), %edi
callq 0x56f0
movq %r12, %rdi
callq 0x52f0
movq 0x58(%rbx), %rax
movq 0x28(%rax), %rax
movq %rax, 0x58(%rbx)
testq %rax, %rax
jne 0x140a3
movq 0x50(%rbx), %rdi
callq 0x54b0
cmpq $0x0, 0x58(%rbx)
leaq -0x38(%rbp), %r15
je 0x141b2
movl 0x10(%rbx), %edi
movl $0x1, %esi
callq 0x53d0
cmpl $-0x1, %eax
je 0x141b9
leaq 0xe8(%rbx), %r14
leaq -0x20c(%rip), %rax      # 0x13f44
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 0x141c2
movq -0x48(%rbp), %rdi
cmpq %r15, %rdi
je 0x14196
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 0x587a
leaq -0x38(%rbp), %r15
jmp 0x14181
callq 0x58aa
jmp 0x14181
leaq 0x2ef9(%rip), %rdi      # 0x170b9
jmp 0x141c9
leaq 0x2ef7(%rip), %rdi      # 0x170c0
callq 0x52f0
jmp 0x14181
leaq 0x2eb2(%rip), %rdi      # 0x17089
callq 0x52f0
jmp 0x141ac
jmp 0x141e0
movq %rax, %rbx
movq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
cmpq %rax, %rdi
je 0x141fc
movq -0x38(%rbp), %rsi
incq %rsi
callq 0x5370
movq %rbx, %rdi
callq 0x5630