// File: /workspace/github_cpp_makefile_star2_O1/brianbbsu[P]TCP-Ping/src/server.cpp
// Function: setup(unsigned short)
int setup(uint16_t port){
    int fd, enable = 1;
    sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = htonl(INADDR_ANY);

    if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)quit("Failed to creat socket!");
    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int));
    if(bind(fd, (sockaddr*)&addr, sizeof(addr)) < 0)quit("Failed to bind socket on port " + std::to_string(port) + "!");
    if(listen(fd, 10) < 0)quit("Failed to start listening for connection!");
    
    logger::log_info("Listing on port " + std::to_string(port) + " ...");
    
    server_socket_fd = fd;
    struct sigaction sa;
    sa.sa_handler = sigint_handler;
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);
    sigaction(SIGINT, &sa, NULL);

    return fd;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %edi, %ebp
movl $0x1, 0xc(%rsp)
movw $0x2, 0x70(%rsp)
movl %ebp, %eax
rolw $0x8, %ax
movw %ax, 0x72(%rsp)
movl $0x0, 0x74(%rsp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x50c0
movl %eax, %ebx
testl %eax, %eax
jns 0x5bad
leaq 0xb0(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x54e6(%rip), %rsi      # 0xb057
leaq 0x54f6(%rip), %rdx      # 0xb06e
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
callq 0x775e
movq %r14, %rdi
callq 0xae9a
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x5bad
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x52c0
movl $0x1, %r15d
leaq 0xc(%rsp), %rcx
movl %ebx, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x5500
leaq 0x70(%rsp), %rsi
movl %ebx, %edi
movl $0x10, %edx
callq 0x5070
movzwl %bp, %r14d
testl %eax, %eax
jns 0x5d62
cmpw $0xa, %bp
jb 0x5c1e
movl $0x2, %r15d
cmpw $0x64, %bp
jb 0x5c1e
movl $0x3, %r15d
cmpl $0x3e8, %r14d           # imm = 0x3E8
jb 0x5c1e
cmpl $0x2710, %r14d          # imm = 0x2710
movl $0x5, %r15d
sbbl $0x0, %r15d
movl %r15d, %esi
leaq 0x20(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movl $0x2d, %edx
callq 0x5350
movq (%r12), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x6f4f
leaq 0x541d(%rip), %rcx      # 0xb06f
movl $0x1e, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5330
leaq 0xd0(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5c94
movq %rdx, 0xc0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xd0(%rsp)
jmp 0x5c9b
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0xc0(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x53f5(%rip), %rsi      # 0xb0b6
callq 0x5550
leaq 0x60(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5cee
movq %rdx, 0x50(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x60(%rsp)
jmp 0x5cf6
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
leaq 0x50(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
callq 0xae9a
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x5d2e
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x52c0
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
je 0x5d4b
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x52c0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x5d62
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x52c0
movl %ebx, %edi
movl $0xa, %esi
callq 0x5320
testl %eax, %eax
jns 0x5dc2
leaq 0x90(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x5308(%rip), %rsi      # 0xb08e
leaq 0x532a(%rip), %rdx      # 0xb0b7
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x775e
movq %r15, %rdi
callq 0xae9a
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x5dc2
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x52c0
movl $0x1, %r15d
cmpw $0xa, %bp
jb 0x5dfa
movl $0x2, %r15d
cmpw $0x64, %bp
jb 0x5dfa
movl $0x3, %r15d
cmpl $0x3e8, %r14d           # imm = 0x3E8
jb 0x5dfa
cmpl $0x2710, %r14d          # imm = 0x2710
movl $0x5, %r15d
sbbl $0x0, %r15d
movl %r15d, %esi
leaq 0x20(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x10(%rsp), %r12
movq %r12, %rdi
movl $0x2d, %edx
callq 0x5350
movq (%r12), %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x6f4f
leaq 0x528a(%rip), %rcx      # 0xb0b8
movl $0x10, %r8d
movq %r12, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5330
leaq 0xd0(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5e70
movq %rdx, 0xc0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xd0(%rsp)
jmp 0x5e77
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0xc0(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x51b5(%rip), %rsi      # 0xb052
callq 0x5550
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x5ec9
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x5ed0
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x30(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0xabf0
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x5f0d
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x52c0
movq 0xc0(%rsp), %rdi
cmpq %r14, %rdi
je 0x5f2a
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x52c0
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x5f41
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x52c0
movl %ebx, 0xa499(%rip)      # 0x103e0
leaq -0x4c2(%rip), %rax      # 0x5a8c
leaq 0xc8(%rsp), %rdi
movq %rax, -0x8(%rdi)
movl $0x0, 0x80(%rdi)
callq 0x5390
leaq 0xc0(%rsp), %rsi
movl $0x2, %edi
xorl %edx, %edx
callq 0x53a0
movl %ebx, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x5fce
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x52c0
jmp 0x5fce
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r12, %rdi
je 0x6051
movq 0x90(%rsp), %rsi
jmp 0x6049
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
cmpq %r15, %rdi
jne 0x6025
jmp 0x603a
jmp 0x6037
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r15, %rdi
je 0x6051
movq 0xb0(%rsp), %rsi
jmp 0x6049
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x6018
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x52c0
jmp 0x6018
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
cmpq %r14, %rdi
je 0x603a
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x52c0
jmp 0x603a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r13, %rdi
je 0x6051
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x52c0
movq %rbx, %rdi
callq 0x54e0