// File: /workspace/github_cpp_makefile_star2_O1/metopa[P]HTTP_Server/src/network/CPortObtainer.cpp
// Function: CPortObtainer::CSocketWrapper::CSocketWrapper(addrinfo*, char const*)
CPortObtainer::CSocketWrapper::CSocketWrapper( addrinfo * servinfo, const char * port ) {
	int yes = 1;

	for ( addrinfo * it = servinfo; it != nullptr; it = it->ai_next ) {
		if ( ( sockfd_m = socket( it->ai_family, it->ai_socktype, it->ai_protocol ) ) == -1 ) {
			Log.ger<>( DEBUG_NETWORK, port, "socket() returned error:", strerror( errno ) );
			continue;
		}

		if ( setsockopt( sockfd_m, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof( int ) ) == -1 ) {
			throw PortInitializationException( "setsockopt()", strerror( errno ), port, sockfd_m );
		}

		if ( bind( sockfd_m, it->ai_addr, it->ai_addrlen ) == -1 ) {
			close( sockfd_m );
			sockfd_m = -1;
			Log.ger<>( DEBUG_NETWORK, "Function bind() returned error on port", port, strerror( errno ) );
			continue;
		}
		break;
	}

	if ( sockfd_m == -1 )
		throw PortInitializationException( "socket()", "Function failed on all addrinfo structures", port );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r14
movq %rdx, 0x8(%rsp)
movl $0x1, 0x14(%rsp)
testq %rsi, %rsi
je 0x12af5
movq %rsi, %rbx
leaq 0xfba3(%rip), %r15      # 0x225c8
leaq 0x8(%rsp), %r13
leaq 0x18(%rsp), %rbp
leaq 0x14(%rsp), %r12
movl 0x4(%rbx), %edi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
callq 0x5100
movl %eax, (%r14)
cmpl $-0x1, %eax
je 0x12abd
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movq %r12, %rcx
movl $0x4, %r8d
callq 0x5740
cmpl $-0x1, %eax
je 0x12b0e
movl (%r14), %edi
movq 0x18(%rbx), %rsi
movl 0x10(%rbx), %edx
callq 0x50a0
cmpl $-0x1, %eax
jne 0x12af5
movl (%r14), %edi
callq 0x57c0
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
callq 0x5060
movl (%rax), %edi
callq 0x51b0
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movl $0x5, %esi
leaq 0x5fc4(%rip), %rdx      # 0x18a74
movq %r13, %rcx
movq %rbp, %r8
callq 0x1308c
jmp 0x12ae8
callq 0x5060
movl (%rax), %edi
callq 0x51b0
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movl $0x5, %esi
movq %r13, %rdx
leaq 0x5f6e(%rip), %rcx      # 0x18a4e
movq %rbp, %r8
callq 0x12f76
movq 0x28(%rbx), %rbx
testq %rbx, %rbx
jne 0x12a34
cmpl $-0x1, (%r14)
je 0x12b9e
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x50, %edi
callq 0x5200
movq %rax, %rbx
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x5f3c(%rip), %rsi      # 0x18a67
leaq 0x5f41(%rip), %rdx      # 0x18a73
leaq 0x18(%rsp), %rdi
callq 0x8f0e
callq 0x5060
movl (%rax), %edi
callq 0x51b0
leaq 0x38(%rsp), %rdi
leaq 0x7(%rsp), %rdx
movq %rax, %rsi
callq 0x7bea
movq 0x8(%rsp), %rcx
movl (%r14), %r8d
movb $0x1, %bpl
leaq 0x18(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
callq 0x131da
leaq 0xee4a(%rip), %rax      # 0x219c8
movq %rax, (%rbx)
xorl %ebp, %ebp
leaq 0xecc6(%rip), %rsi      # 0x21850
leaq 0x129(%rip), %rdx       # 0x12cba
movq %rbx, %rdi
callq 0x5700
jmp 0x12c30
movl $0x50, %edi
callq 0x5200
movq %rax, %rbx
leaq 0x28(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x5ee0(%rip), %rsi      # 0x18a9b
leaq 0x5ee1(%rip), %rdx      # 0x18aa3
leaq 0x18(%rsp), %rdi
callq 0x8f0e
leaq 0x48(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x5ec7(%rip), %rsi      # 0x18aa4
leaq 0x5eea(%rip), %rdx      # 0x18ace
leaq 0x38(%rsp), %rdi
callq 0x8f0e
movb $0x1, %bpl
movq 0x8(%rsp), %rcx
leaq 0x18(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
movl $0xfffffffe, %r8d       # imm = 0xFFFFFFFE
callq 0x131da
leaq 0xedb3(%rip), %rax      # 0x219c8
movq %rax, (%rbx)
xorl %ebp, %ebp
leaq 0xec2f(%rip), %rsi      # 0x21850
leaq 0x92(%rip), %rdx        # 0x12cba
movq %rbx, %rdi
callq 0x5700
movq %rax, %r14
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
jne 0x12c54
jmp 0x12c69
jmp 0x12c63
jmp 0x12c82
movq %rax, %r14
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12c69
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x53f0
jmp 0x12c69
movq %rax, %r14
movb $0x1, %bpl
movq 0x18(%rsp), %rdi
cmpq %r15, %rdi
je 0x12c88
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x53f0
jmp 0x12c88
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x12c95
movq %rbx, %rdi
callq 0x52e0
movq %r14, %rdi
callq 0x5730
nop