// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdi, %rbx
movq $0x1, 0x180(%rdi)
movl %esi, 0x8(%rdi)
leaq -0x48(%rbp), %r14
movq %r14, %rdi
callq 0x13019
movq (%r14), %rsi
leaq 0x20(%rbx), %rdx
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rbx)
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x30(%rbx)
pushq $0x1
popq %rax
movl %eax, 0x28(%rbx)
movl %eax, 0x20(%rbx)
leaq 0x50(%rbx), %r15
xorl %edi, %edi
movq %r15, %rcx
callq 0x5480
movl %eax, 0x1b8(%rbx)
testl %eax, %eax
jne 0x12795
leaq 0x180(%rbx), %r14
leaq 0x29dd(%rip), %r12      # 0x1507a
pushq $0x4
popq %r13
movq (%r15), %rax
movq %rax, 0x58(%rbx)
testq %rax, %rax
je 0x12718
movl 0x4(%rax), %edi
movl 0x8(%rax), %esi
movl 0xc(%rax), %edx
callq 0x50e0
movl %eax, 0x10(%rbx)
movq %r12, %rdi
cmpl $-0x1, %eax
je 0x12709
movl %eax, %edi
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
movq %r14, %rcx
movl %r13d, %r8d
callq 0x5670
cmpl $-0x1, %eax
je 0x127f1
movl 0x10(%rbx), %edi
movq 0x58(%rbx), %rax
movq 0x18(%rax), %rsi
movl 0x10(%rax), %edx
callq 0x5080
cmpl $-0x1, %eax
jne 0x12718
movl 0x10(%rbx), %edi
callq 0x5710
leaq 0x298b(%rip), %rdi      # 0x15094
callq 0x5320
movq 0x58(%rbx), %r15
addq $0x28, %r15
jmp 0x126a1
movq 0x50(%rbx), %rdi
callq 0x54d0
cmpq $0x0, 0x58(%rbx)
je 0x127bc
movl 0x10(%rbx), %edi
pushq $0x1
popq %rsi
callq 0x5400
cmpl $-0x1, %eax
je 0x127da
leaq 0xe8(%rbx), %r14
leaq -0x17a(%rip), %rax      # 0x125d4
movq %rax, 0xe8(%rbx)
leaq 0xf0(%rbx), %rdi
callq 0x5460
movl $0x10000000, 0x170(%rbx) # imm = 0x10000000
pushq $0x11
popq %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x5470
cmpl $-0x1, %eax
je 0x127e3
leaq -0x48(%rbp), %rdi
callq 0x51e0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xc814(%rip), %rcx      # 0x1efb0
movq (%rcx), %rbx
movl %eax, %edi
callq 0x5510
leaq 0x28bc(%rip), %rsi      # 0x15069
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5560
jmp 0x1277d
movq 0xc7ed(%rip), %rax      # 0x1efb0
movq (%rax), %rcx
leaq 0x28d4(%rip), %rdi      # 0x150a1
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
callq 0x56f0
jmp 0x1277d
leaq 0x28d8(%rip), %rdi      # 0x150b9
jmp 0x127ea
leaq 0x28d6(%rip), %rdi      # 0x150c0
callq 0x5320
jmp 0x1277d
leaq 0x2891(%rip), %rdi      # 0x15089
jmp 0x127ea
jmp 0x127fc
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x51e0
movq %rbx, %rdi
callq 0x5660