// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x150, %rsp            # imm = 0x150
movl %edi, %ebp
movl $0x1, 0x4(%rsp)
movw $0x2, 0x8(%rsp)
movl %ebp, %eax
rolw $0x8, %ax
movw %ax, 0xa(%rsp)
andl $0x0, 0xc(%rsp)
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x50b0
movl %eax, %ebx
testl %eax, %eax
jns 0x5a29
leaq 0x4662(%rip), %rsi      # 0xa05c
leaq 0x98(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0x622c
leaq 0x98(%rsp), %rdi
callq 0x99ac
leaq 0x98(%rsp), %rdi
callq 0x55a8
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
leaq 0x4(%rsp), %rcx
pushq $0x4
popq %r8
movl %ebx, %edi
callq 0x54f0
leaq 0x8(%rsp), %rsi
pushq $0x10
popq %rdx
movl %ebx, %edi
callq 0x5060
movzwl %bp, %ebp
testl %eax, %eax
jns 0x5abf
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
callq 0x62aa
leaq 0x4609(%rip), %rsi      # 0xa074
leaq 0xb8(%rsp), %rdi
movq %r14, %rdx
callq 0x6286
leaq 0x4639(%rip), %rdx      # 0xa0bb
leaq 0x78(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x6267
leaq 0x78(%rsp), %rdi
callq 0x99ac
leaq 0x78(%rsp), %rdi
callq 0x55a8
leaq 0xb8(%rsp), %rdi
callq 0x55a8
leaq 0x18(%rsp), %rdi
callq 0x55a8
pushq $0xa
popq %rsi
movl %ebx, %edi
callq 0x5300
testl %eax, %eax
jns 0x5afa
leaq 0x45bf(%rip), %rsi      # 0xa093
leaq 0x58(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0x622c
leaq 0x58(%rsp), %rdi
callq 0x99ac
leaq 0x58(%rsp), %rdi
callq 0x55a8
leaq 0x18(%rsp), %r14
movq %r14, %rdi
movl %ebp, %esi
callq 0x62aa
leaq 0x45ad(%rip), %rsi      # 0xa0bd
leaq 0xb8(%rsp), %rdi
movq %r14, %rdx
callq 0x6286
leaq 0x4530(%rip), %rdx      # 0xa057
leaq 0x38(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0x6267
leaq 0x38(%rsp), %rdi
pushq $-0x1
popq %rsi
callq 0x97e8
leaq 0x38(%rsp), %rdi
callq 0x55a8
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
callq 0x55a8
leaq 0x18(%rsp), %rdi
callq 0x55a8
movl %ebx, 0xa870(%rip)      # 0x103e0
leaq -0x22b(%rip), %rax      # 0x594c
movq %rax, (%r14)
andl $0x0, 0x88(%r14)
leaq 0xc0(%rsp), %rdi
callq 0x5350
pushq $0x2
popq %rdi
leaq 0xb8(%rsp), %rsi
xorl %edx, %edx
callq 0x5360
movl %ebx, %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
jmp 0x5c04
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x5be3
jmp 0x5bd6
jmp 0x5bea
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x5c04
jmp 0x5bfc
movq %rax, %rbx
jmp 0x5c09
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x55a8
jmp 0x5bed
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x55a8
jmp 0x5bff
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x55a8
movq %rbx, %rdi
callq 0x54d0