// File: /workspace/github_cpp_makefile_star2_O2/MisakiFx[P]P2PDownload/./httplib.h
// Function: int httplib::detail::create_socket<httplib::Server::create_server_socket(char const*, int, int) const::'lambda'(int, addrinfo&)>(char const*, int, httplib::Server::create_server_socket(char const*, int, int) const::'lambda'(int, addrinfo&), int)
socket_t create_socket(const char *host, int port, Fn fn,
                    int socket_flags = 0) {
#ifdef _WIN32
#define SO_SYNCHRONOUS_NONALERT 0x20
#define SO_OPENTYPE 0x7008

                int opt = SO_SYNCHRONOUS_NONALERT;
                setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&opt,
                        sizeof(opt));
#endif

                // Get address info
                struct addrinfo hints;
                struct addrinfo *result;

                memset(&hints, 0, sizeof(struct addrinfo));
                hints.ai_family = AF_UNSPEC;
                hints.ai_socktype = SOCK_STREAM;
                hints.ai_flags = socket_flags;
                hints.ai_protocol = 0;

                auto service = std::to_string(port);

                if (getaddrinfo(host, service.c_str(), &hints, &result)) {
                    return INVALID_SOCKET;
                }

                for (auto rp = result; rp; rp = rp->ai_next) {
                    // Create a socket
                    auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
                    if (sock == INVALID_SOCKET) { continue; }

                    // Make 'reuse address' option available
                    int yes = 1;
                    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes));

                    // bind or connect
                    if (fn(sock, *rp)) {
                        freeaddrinfo(result);
                        return sock;
                    }

                    close_socket(sock);
                }

                freeaddrinfo(result);
                return INVALID_SOCKET;
            }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r14
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %r15
movaps %xmm0, (%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, 0x20(%r15)
movl $0x1, 0x8(%r15)
movl %edx, (%r15)
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x14f1c
movq (%rbx), %rsi
leaq -0x38(%rbp), %rbx
movq %r14, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x86d0
pushq $-0x1
popq %r15
testl %eax, %eax
jne 0x14eeb
leaq -0x30(%rbp), %r12
pushq $0x4
popq %r13
leaq -0x29(%rbp), %r14
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x14ed3
movl 0x4(%rbx), %edi
movl 0x8(%rbx), %esi
movl 0xc(%rbx), %edx
callq 0x80f0
cmpl $-0x1, %eax
je 0x14ecd
movl %eax, %r15d
movl $0x1, -0x30(%rbp)
movl %eax, %edi
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
movq %r12, %rcx
movl %r13d, %r8d
callq 0x89a0
movq %r14, %rdi
movl %r15d, %esi
movq %rbx, %rdx
callq 0x14f7c
testb %al, %al
jne 0x14ee2
movl %r15d, %edi
callq 0x8a60
addq $0x28, %rbx
jmp 0x14e7b
movq -0x38(%rbp), %rdi
callq 0x8730
pushq $-0x1
popq %r15
jmp 0x14eeb
movq -0x38(%rbp), %rdi
callq 0x8730
leaq -0x58(%rbp), %rdi
callq 0x8aa8
movl %r15d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14f08
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x8aa8
movq %rbx, %rdi
callq 0x8990