// File: /workspace/github_cpp_makefile_star2_O2/brianbbsu[P]TCP-Ping/src/server.cpp
// Function: main
int main(int argc, char *argv[])
{
    uint16_t port;
    po::options_description desc, desc_all;
    desc.add_options()
    ("help,h", "Print help messages");
    desc_all.add(desc);
    desc_all.add_options()
    ("port", po::value<uint16_t>(&port)->required(), "Port to listen on");
    
    po::positional_options_description pos_desc;
    pos_desc.add("port", 1);

    po::variables_map vmap;
    try{
        po::store(po::command_line_parser(argc, argv).options(desc_all).positional(pos_desc).run(), vmap);
        if(vmap.count("help"))print_help(desc);
        po::notify(vmap);
    }catch(const std::exception &ex){
        logger::log_error("Failed to parse arguments: " + std::string(ex.what()) + "\n");
        print_help(desc);
    }
    
    logger::log_info("== TCP Ping - Server - Made by Po-Hsuan Su (b08902107) ==");
    int fd = setup(port);
    
    while(1)
    {
        sockaddr_in conn_addr;
        socklen_t conn_addr_len = sizeof(conn_addr);
        int conn_fd = accept(fd, (struct sockaddr*)&conn_addr, &conn_addr_len);
        if(conn_fd < 0)
        {
            logger::log_error("Failed to establish new connection!");
            continue;
        }
        char conn_ip[INET_ADDRSTRLEN + 2];
        memset(conn_ip, 0, sizeof(conn_ip));
        inet_ntop(AF_INET, &conn_addr.sin_addr, conn_ip, INET_ADDRSTRLEN);
        logger::log_info("recv from " + std::string(conn_ip) + ":" + std::to_string(ntohs(conn_addr.sin_port)));
        shutdown(conn_fd, SHUT_RDWR);
        close(conn_fd);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x478, %rsp            # imm = 0x478
movq %rsi, %rbx
movl %edi, %ebp
movq 0xa316(%rip), %rax      # 0xffa8
movl (%rax), %r14d
movl %r14d, %r15d
shrl %r15d
leaq 0x278(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x5580
leaq 0x2f8(%rsp), %rdi
movl %r14d, %esi
movl %r15d, %edx
callq 0x5580
leaq 0x278(%rsp), %rdi
callq 0x5320
leaq 0x1d8(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x4489(%rip), %rsi      # 0xa169
leaq 0x4489(%rip), %rdx      # 0xa170
callq 0x5520
leaq 0x2f8(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x52b0
leaq 0x2f8(%rsp), %rdi
callq 0x5320
movq %rax, 0x1d8(%rsp)
leaq 0xc(%rsp), %rdi
callq 0x6303
movb $0x1, 0x8c(%rax)
leaq 0x4456(%rip), %rsi      # 0xa184
leaq 0x4454(%rip), %rcx      # 0xa189
leaq 0x1d8(%rsp), %rdi
movq %rax, %rdx
callq 0x5550
leaq 0x160(%rsp), %rdi
callq 0x5390
leaq 0x442b(%rip), %rsi      # 0xa184
leaq 0x160(%rsp), %rdi
pushq $0x1
popq %rdx
callq 0x52e0
leaq 0x1d8(%rsp), %rdi
callq 0x5110
leaq 0xa8(%rsp), %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x6346
leaq 0xa8(%rsp), %rdi
leaq 0x2f8(%rsp), %rsi
callq 0x63d6
movq %rax, %rbx
leaq 0x160(%rsp), %rsi
movq %rax, %rdi
callq 0x5480
leaq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x63f4
leaq 0x18(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
xorl %edx, %edx
callq 0x54c0
leaq 0x18(%rsp), %rdi
callq 0x66bc
leaq 0xa8(%rsp), %rdi
callq 0x6482
leaq 0x43ac(%rip), %rsi      # 0xa19b
leaq 0xa8(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x622c
leaq 0x1e8(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x64a2
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x55a8
testq %rbx, %rbx
jne 0x5fc6
leaq 0x1d8(%rsp), %rdi
callq 0x5180
leaq 0x4379(%rip), %rsi      # 0xa1bc
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rdx
callq 0x622c
leaq 0x68(%rsp), %rdi
pushq $-0x1
popq %rsi
callq 0x97e8
leaq 0x68(%rsp), %rdi
callq 0x55a8
movzwl 0xc(%rsp), %edi
callq 0x59b4
movl %eax, 0x10(%rsp)
leaq 0xa8(%rsp), %r13
leaq 0x140(%rsp), %r14
leaq 0x18(%rsp), %rbp
leaq 0x198(%rsp), %r12
movl $0x10, 0x14(%rsp)
movl 0x10(%rsp), %edi
leaq 0x40(%rsp), %rsi
leaq 0x14(%rsp), %rdx
callq 0x50e0
movl %eax, %ebx
testl %eax, %eax
js 0x5f94
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andw $0x0, 0x60(%rsp)
pushq $0x2
popq %rdi
leaq 0x44(%rsp), %rsi
movq %r14, %r15
leaq 0x50(%rsp), %r14
movq %r14, %rdx
pushq $0x10
popq %rcx
callq 0x52d0
movq %r15, %rdi
movq %r14, %rsi
leaq 0xf(%rsp), %rdx
callq 0x622c
movq %rbp, %rdi
leaq 0x431b(%rip), %rsi      # 0xa21a
movq %r15, %rdx
callq 0x6286
movq %r15, %r14
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x430e(%rip), %rdx      # 0xa225
callq 0x6267
movzwl 0x42(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %esi
leaq 0x120(%rsp), %r15
movq %r15, %rdi
callq 0x62aa
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x6573
movq %r12, %rdi
pushq $-0x1
popq %rsi
callq 0x97e8
movq %r12, %rdi
callq 0x55a8
leaq 0x120(%rsp), %rdi
callq 0x55a8
movq %r13, %rdi
callq 0x55a8
movq %rbp, %rdi
callq 0x55a8
movq %r14, %rdi
callq 0x55a8
movl %ebx, %edi
pushq $0x2
popq %rsi
callq 0x53b0
movl %ebx, %edi
callq 0x5570
jmp 0x5e97
leaq 0x1b8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x4250(%rip), %rsi      # 0xa1f6
movq %r13, %rdx
callq 0x622c
movq %rbx, %rdi
pushq $-0x1
popq %rsi
callq 0x98ca
movq %rbx, %rdi
callq 0x55a8
jmp 0x5e97
leaq 0x3f8(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x64bc
leaq 0x3f8(%rsp), %rdi
callq 0x5c11
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
jmp 0x6059
jmp 0x6063
jmp 0x6063
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x55a8
jmp 0x600e
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x55a8
jmp 0x6020
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x55a8
jmp 0x6032
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x55a8
jmp 0x6041
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
jmp 0x6059
jmp 0x6063
jmp 0x6063
jmp 0x6063
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x55a8
jmp 0x61d0
movq %rax, %rbx
jmp 0x61d0
movq %rdx, %r14
movq %rax, %rbx
leaq 0x3f8(%rsp), %rdi
callq 0x6540
jmp 0x60c6
jmp 0x60c0
movq %rdx, %r14
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x55a8
jmp 0x60c6
jmp 0x60c0
movq %rdx, %r14
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x66bc
jmp 0x60b1
movq %rdx, %r14
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x6482
jmp 0x60c6
movq %rdx, %r14
movq %rax, %rbx
cmpl $0x1, %r14d
jne 0x61d0
movq %rbx, %rdi
callq 0x5100
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x18(%rsp), %rdi
leaq 0x140(%rsp), %rdx
movq %rax, %rsi
callq 0x622c
leaq 0x40a3(%rip), %rsi      # 0xa1a0
leaq 0xa8(%rsp), %rdi
leaq 0x18(%rsp), %rdx
callq 0x6286
leaq 0x400c(%rip), %rdx      # 0xa122
leaq 0x88(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x6267
leaq 0x88(%rsp), %rdi
pushq $-0x1
popq %rsi
callq 0x98ca
leaq 0x88(%rsp), %rdi
callq 0x55a8
leaq 0xa8(%rsp), %rdi
callq 0x55a8
leaq 0x18(%rsp), %rdi
callq 0x55a8
leaq 0x378(%rsp), %rdi
leaq 0x278(%rsp), %rsi
callq 0x64bc
leaq 0x378(%rsp), %rdi
callq 0x5c11
movq %rax, %rbx
leaq 0x378(%rsp), %rdi
callq 0x6540
jmp 0x61cb
jmp 0x61c8
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x55a8
jmp 0x61aa
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x55a8
jmp 0x61bc
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x55a8
jmp 0x61cb
movq %rax, %rbx
callq 0x5460
leaq 0x1d8(%rsp), %rdi
callq 0x65da
jmp 0x61ec
movq %rax, %rdi
callq 0x6568
jmp 0x61e9
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0x660c
jmp 0x6204
jmp 0x6201
jmp 0x6201
jmp 0x6201
movq %rax, %rbx
leaq 0x2f8(%rsp), %rdi
callq 0x6540
jmp 0x6216
movq %rax, %rbx
leaq 0x278(%rsp), %rdi
callq 0x6540
movq %rbx, %rdi
callq 0x54d0
nop