// File: /workspace/github_cpp_makefile_star2_O1/Lartu[P]coraldb/source/coraldb.cpp
// Function: start_socket()
void start_socket()
{
    // Create socket
    int sockfd;
    if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
    {
        err_socket_creation(strerror(errno));
        exit(1);
    }
    // Bind Socket
    struct sockaddr_in address;
    memset(&address, 0, sizeof(address));
    address.sin_family = AF_INET;
    address.sin_addr.s_addr = INADDR_ANY;
    address.sin_port = htons(global_port);
    socklen_t len = sizeof(address);
    if (bind(sockfd, (struct sockaddr *)&address, len) < 0)
    {
        err_socket_creation(strerror(errno));
        exit(1);
    }
    getsockname(sockfd, (struct sockaddr *)&address, &len);
    global_port = ntohs(address.sin_port);
    // Inform the user
    std::cout << "CoralDB running on port " << global_port << ", backed to " << global_filename << std::endl;
    // Listen socket
    int new_socket_fd;
    if (listen(sockfd, 256) < 0)
    {
        err_socket_read(strerror(errno));
    }
    while (true)
    {
        if ((new_socket_fd = accept(sockfd, (struct sockaddr *)&address, &len)) < 0)
        {
            err_socket_accept(strerror(errno));
        }
        std::thread child_thread(handle_socket, new_socket_fd);
        child_thread.detach();
    }
    close(sockfd);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x3080
testl %eax, %eax
js 0x543c
movl %eax, %r15d
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %rsi
movaps %xmm0, (%rsi)
movw $0x2, (%rsi)
movl $0x0, 0x4(%rsi)
movzwl 0x4e88(%rip), %eax      # 0xa2a4
rolw $0x8, %ax
movw %ax, 0x2(%rsi)
movl $0x10, -0x2c(%rbp)
movl %r15d, %edi
movl $0x10, %edx
callq 0x3050
testl %eax, %eax
jns 0x545a
callq 0x3040
movl (%rax), %edi
callq 0x3110
movq %rax, %rdi
callq 0x38f6
movl $0x1, %edi
callq 0x3360
leaq -0x50(%rbp), %rbx
leaq -0x2c(%rbp), %rdx
movl %r15d, %edi
movq %rbx, %rsi
callq 0x32b0
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x4e26(%rip)      # 0xa2a4
movq 0x4b4b(%rip), %rbx      # 0x9fd0
leaq 0x2006(%rip), %rsi      # 0x7492
movl $0x18, %edx
movq %rbx, %rdi
callq 0x3330
movl 0x4e05(%rip), %esi      # 0xa2a4
movq %rbx, %rdi
callq 0x31f0
movq %rax, %rbx
leaq 0x1ffa(%rip), %rsi      # 0x74ab
movl $0xc, %edx
movq %rax, %rdi
callq 0x3330
movq 0x4eab(%rip), %rsi      # 0xa370
movq 0x4eac(%rip), %rdx      # 0xa378
movq %rbx, %rdi
callq 0x3330
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32f0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3200
movl %r15d, %r14d
movl %r15d, %edi
movl $0x100, %esi            # imm = 0x100
callq 0x3320
testl %eax, %eax
jns 0x5526
callq 0x3040
movl (%rax), %edi
callq 0x3110
movq %rax, %rdi
callq 0x3983
leaq -0x2c(%rbp), %r15
leaq -0x2e2(%rip), %r12      # 0x524f
leaq -0x38(%rbp), %r13
leaq -0x30(%rbp), %rbx
movl %r14d, %edi
leaq -0x50(%rbp), %rsi
movq %r15, %rdx
callq 0x30e0
movl %eax, -0x30(%rbp)
testl %eax, %eax
jns 0x5563
callq 0x3040
movl (%rax), %edi
callq 0x3110
movq %rax, %rdi
callq 0x3a10
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x573a
movq %r13, %rdi
callq 0x3490
cmpq $0x0, -0x38(%rbp)
je 0x5539
jmp 0x5591
cmpq $0x0, -0x38(%rbp)
jne 0x5591
movq %rax, %rdi
callq 0x34a0
callq 0x30b0