// File: yuryu[P]tfoecho/server.cpp
// Function: server(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void server(const std::string &port)
{
    FD sfd(open_socket(port));
    
    struct epoll_event ev, events[MAX_EVENTS];

    FD epollfd(epoll_create1(0));
    if( epollfd == -1 )
    {
        cerror("epoll_create1");
        std::exit(EXIT_FAILURE);
    }
    ev.events = EPOLLIN;
    ev.data.fd = sfd;
    if( epoll_ctl(epollfd, EPOLL_CTL_ADD, sfd, &ev) == -1 )
    {
        perror("epoll_ctl: EPOLL_CTL_ADD");
        std::exit(EXIT_FAILURE);
    }

    while( 1 )
    {
        const int nfds = epoll_wait(epollfd, events, MAX_EVENTS, -1);
        if( nfds == -1 )
        {
            if( errno == EINTR ) continue;
            cerror("epoll_wait");
            std::exit(EXIT_FAILURE);
        }

        for( int i = 0; i < nfds; ++i )
        {
            if( events[i].data.fd == sfd )
                accept_and_register(sfd, epollfd);
            else
                process_client_socket(events[i].data.fd, epollfd);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x2420
movl %eax, %esi
leaq -0xc(%rbp), %rdi
callq 0x2d40
xorl %edi, %edi
callq 0x2220
movl %eax, %esi
leaq -0x1a4(%rbp), %rdi
callq 0x2d40
jmp 0x293a
leaq -0x1a4(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1c0(%rbp)
jmp 0x294e
movl -0x1c0(%rbp), %eax
cmpl $-0x1, %eax
jne 0x29ab
leaq 0x1716(%rip), %rdi      # 0x4076
callq 0x25f0
jmp 0x2967
movl $0x1, %edi
callq 0x21f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
jmp 0x2b88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x1b0(%rbp)
movl %eax, -0x1b4(%rbp)
leaq -0x1a4(%rbp), %rdi
callq 0x2d70
jmp 0x2b88
movl $0x1, -0x18(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1c4(%rbp)
jmp 0x29c3
movl -0x1c4(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x1a4(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1c8(%rbp)
jmp 0x29e0
leaq -0xc(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1cc(%rbp)
jmp 0x29f1
movl -0x1cc(%rbp), %edx
movl -0x1c8(%rbp), %edi
movl $0x1, %esi
leaq -0x18(%rbp), %rcx
callq 0x2240
cmpl $-0x1, %eax
jne 0x2a28
leaq 0x1623(%rip), %rdi      # 0x403a
callq 0x2170
jmp 0x2a1e
movl $0x1, %edi
callq 0x21f0
jmp 0x2a2a
jmp 0x2a2c
leaq -0x1a4(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1d0(%rbp)
jmp 0x2a40
movl -0x1d0(%rbp), %edi
leaq -0x1a0(%rbp), %rsi
movl $0x20, %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x20d0
movl %eax, -0x1d4(%rbp)
jmp 0x2a64
movl -0x1d4(%rbp), %eax
movl %eax, -0x1b8(%rbp)
cmpl $-0x1, -0x1b8(%rbp)
jne 0x2a9d
callq 0x2030
cmpl $0x4, (%rax)
jne 0x2a85
jmp 0x2a2a
leaq 0x15f8(%rip), %rdi      # 0x4084
callq 0x25f0
jmp 0x2a93
movl $0x1, %edi
callq 0x21f0
movl $0x0, -0x1bc(%rbp)
movl -0x1bc(%rbp), %eax
cmpl -0x1b8(%rbp), %eax
jge 0x2b83
movslq -0x1bc(%rbp), %rax
leaq (%rax,%rax,2), %rax
movl -0x19c(%rbp,%rax,4), %eax
movl %eax, -0x1dc(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1d8(%rbp)
jmp 0x2ae2
movl -0x1dc(%rbp), %eax
movl -0x1d8(%rbp), %ecx
cmpl %ecx, %eax
jne 0x2b2c
leaq -0xc(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1e0(%rbp)
jmp 0x2b03
leaq -0x1a4(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1e4(%rbp)
jmp 0x2b17
movl -0x1e4(%rbp), %esi
movl -0x1e0(%rbp), %edi
callq 0x2650
jmp 0x2b2a
jmp 0x2b6d
movslq -0x1bc(%rbp), %rax
leaq (%rax,%rax,2), %rax
movl -0x19c(%rbp,%rax,4), %eax
movl %eax, -0x1ec(%rbp)
leaq -0x1a4(%rbp), %rdi
callq 0x2d60
movl %eax, -0x1e8(%rbp)
jmp 0x2b58
movl -0x1e8(%rbp), %esi
movl -0x1ec(%rbp), %edi
callq 0x2700
jmp 0x2b6b
jmp 0x2b6d
jmp 0x2b6f
movl -0x1bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x2aa7
jmp 0x2a2a
leaq -0xc(%rbp), %rdi
callq 0x2d70
movq -0x1b0(%rbp), %rdi
callq 0x2290
nopl (%rax)