// File: Rjerk[P]ratabase/Server.cpp
// Function: ratabase::Server::serverInit()
void Server::serverInit()
{
    if (port_ < 1024 || port_ > 65535) {
        LOG_FATAL << "Server::serverInit: Invalid port";
    }

    struct sockaddr_in servaddr;
    ::bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(port_);
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);

    if ((servsock_ = ::socket(PF_INET, SOCK_STREAM, 0)) < 0) {
        LOG_FATAL << "make socket error";
    }

    const int on = 1;
    ::setsockopt(servsock_, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
    if (::setsockopt(servsock_, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)) == -1) {
        LOG_ERROR << "setsockopt REUSEPORT failed.";
    }

    sockets::bindOrDie(servsock_, (struct sockaddr* ) &servaddr);

    sockets::listenOrDie(servsock_);
}

// Assembly:
subq $0x508, %rsp            # imm = 0x508
movq %rdi, 0x500(%rsp)
movq 0x500(%rsp), %rax
movq %rax, 0x38(%rsp)
cmpl $0x400, (%rax)          # imm = 0x400
jl 0x8115
movq 0x38(%rsp), %rax
cmpl $0xffff, (%rax)         # imm = 0xFFFF
jle 0x819d
leaq 0xbf61(%rip), %rsi      # 0x1407d
leaq 0xbf79(%rip), %rcx      # 0x1409c
leaq 0x378(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movl $0x27, %edx
movl $0x5, %r8d
callq 0x11e00
movq 0x28(%rsp), %rdi
callq 0x121a0
movq %rax, 0x30(%rsp)
jmp 0x8151
movq 0x30(%rsp), %rdi
addq $0x10, %rdi
leaq 0xbf46(%rip), %rsi      # 0x140a7
callq 0x3390
jmp 0x8168
leaq 0x378(%rsp), %rdi
callq 0x12060
jmp 0x819d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x370(%rsp)
movl %eax, 0x36c(%rsp)
leaq 0x378(%rsp), %rdi
callq 0x12060
jmp 0x8388
leaq 0x35c(%rsp), %rdi
movl $0x10, %esi
callq 0x3580
movq 0x38(%rsp), %rax
movw $0x2, 0x35c(%rsp)
movl (%rax), %eax
movzwl %ax, %edi
callq 0x3070
movw %ax, 0x35e(%rsp)
xorl %edi, %edi
callq 0x32f0
movl %eax, 0x360(%rsp)
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x30f0
movq 0x38(%rsp), %rcx
movl %eax, 0x4(%rcx)
cmpl $0x0, %eax
jge 0x8288
leaq 0xbe76(%rip), %rsi      # 0x1407d
leaq 0xbe8e(%rip), %rcx      # 0x1409c
leaq 0x1d0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movl $0x31, %edx
movl $0x5, %r8d
callq 0x11e00
movq 0x18(%rsp), %rdi
callq 0x121a0
movq %rax, 0x20(%rsp)
jmp 0x823c
movq 0x20(%rsp), %rdi
addq $0x10, %rdi
leaq 0xbe7c(%rip), %rsi      # 0x140c8
callq 0x3390
jmp 0x8253
leaq 0x1d0(%rsp), %rdi
callq 0x12060
jmp 0x8288
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x370(%rsp)
movl %eax, 0x36c(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x12060
jmp 0x8388
movq 0x38(%rsp), %rax
movl $0x1, 0x1cc(%rsp)
movl 0x4(%rax), %edi
movl $0x1, %esi
movl $0x2, %edx
leaq 0x1cc(%rsp), %rcx
movl $0x4, %r8d
callq 0x35b0
movq 0x38(%rsp), %rax
movl 0x4(%rax), %edi
movl $0x1, %esi
movl $0xf, %edx
leaq 0x1cc(%rsp), %rcx
movl $0x4, %r8d
callq 0x35b0
cmpl $-0x1, %eax
jne 0x835e
leaq 0xbd94(%rip), %rsi      # 0x1407d
leaq 0xbdac(%rip), %rcx      # 0x1409c
leaq 0x40(%rsp), %rdi
movq %rdi, 0x8(%rsp)
movl $0x37, %edx
movl $0x4, %r8d
callq 0x11e00
movq 0x8(%rsp), %rdi
callq 0x121a0
movq %rax, 0x10(%rsp)
jmp 0x831b
movq 0x10(%rsp), %rdi
addq $0x10, %rdi
leaq 0xbdaf(%rip), %rsi      # 0x140da
callq 0x3390
jmp 0x8332
leaq 0x40(%rsp), %rdi
callq 0x12060
jmp 0x835e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x370(%rsp)
movl %eax, 0x36c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x12060
jmp 0x8388
movq 0x38(%rsp), %rax
movl 0x4(%rax), %edi
leaq 0x35c(%rsp), %rsi
callq 0x12b10
movq 0x38(%rsp), %rax
movl 0x4(%rax), %edi
callq 0x12bd0
addq $0x508, %rsp            # imm = 0x508
retq
movq 0x370(%rsp), %rdi
callq 0x3590
nopw %cs:(%rax,%rax)