// File: /workspace/github_cpp_makefile_star2_O2/yahoo[P]UDPing/src/serversession.cc
// Function: ServerSessionManager::readNextPacket(int)
int ServerSessionManager::readNextPacket (int fd) {
    char buf[MAXBUF];
    struct sockaddr_in remote;
    struct timespec tv;
    socklen_t len = sizeof(remote);
    int n=recvfrom(fd,buf,MAXBUF,0,(struct sockaddr *)&remote,&len);
    packet* ph = (packet*) buf;
    if (n < 0) {
        warn("Error receiving data");
    } else if (n < sizeof(packet)) {
        warn("Malformed packet - size %d is less than header size %ld", n, sizeof(packet));
    } else if (n != ph->size) {
        warn("Malformed packet - expected %d, got %d", ph->size, n);
    } else if (ph->protoVersion != PROTOVERSION) {
        warn("Incorrect protocol version.  Expected %d, got %d", PROTOVERSION, ph->protoVersion);
    } else {
        clock_gettime(CLOCK_REALTIME, &tv);
        dumpBuffer(buf);
        string hostName = hostMap[remote.sin_addr.s_addr];
        if (hostName.empty()) {
            struct hostent* remoteName = gethostbyaddr(&(remote.sin_addr), sizeof(struct in_addr), AF_INET);
            if (remoteName) {
                hostName = hostMap[remote.sin_addr.s_addr] = remoteName->h_name;
            } else {
                hostName = hostMap[remote.sin_addr.s_addr] =  inet_ntoa(remote.sin_addr);
            }
        }
        receivePing (ph, &tv, hostName, ntohs(remote.sin_port));
    }
    return n;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x848, %rsp            # imm = 0x848
movl %esi, %eax
movq %rdi, %r14
leaq 0x1c(%rsp), %r9
movl $0x10, (%r9)
leaq 0x70(%rsp), %rsi
movq %rsp, %r8
movl $0x7d0, %edx            # imm = 0x7D0
movl %eax, %edi
xorl %ecx, %ecx
callq 0x2220
movq %rax, %rbx
testl %ebx, %ebx
js 0x3c80
movl %ebx, %eax
andl $0x7ffffff8, %eax       # imm = 0x7FFFFFF8
cmpl $0x47, %eax
ja 0x3c93
leaq 0x2800(%rip), %rdi      # 0x646f
pushq $0x48
popq %rdx
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
jmp 0x3ddd
leaq 0x27d3(%rip), %rdi      # 0x645a
xorl %eax, %eax
callq 0x20f0
jmp 0x3ddd
movl 0xb0(%rsp), %esi
cmpl %ebx, %esi
jne 0x3d40
movzbl 0x70(%rsp), %edx
cmpl $0x1, %edx
jne 0x3d4b
leaq 0x60(%rsp), %rsi
xorl %edi, %edi
callq 0x22b0
leaq 0x70(%rsp), %rdi
callq 0x31c4
leaq 0x60(%r14), %r15
movl 0x4(%rsp), %eax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x3fa4
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
callq 0x2390
cmpq $0x0, 0x8(%r12)
jne 0x3d96
leaq 0x4(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x2
popq %rdx
callq 0x2380
testq %rax, %rax
je 0x3d5e
movq (%rax), %r12
movl 0x4(%rsp), %eax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x3fa4
movq %rax, %rdi
movq %r12, %rsi
callq 0x24a0
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x21a0
jmp 0x3d96
leaq 0x2760(%rip), %rdi      # 0x64a7
movl %ebx, %edx
jmp 0x3d55
leaq 0x277c(%rip), %rdi      # 0x64ce
pushq $0x1
popq %rsi
xorl %eax, %eax
callq 0x20f0
jmp 0x3ddd
movl 0x4(%rsp), %edi
callq 0x2150
movq %rax, %r12
movl 0x4(%rsp), %eax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x3fa4
movq %rax, %rdi
movq %r12, %rsi
callq 0x24a0
leaq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x21a0
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2390
movzwl 0x2(%rsp), %eax
rolw $0x8, %ax
movzwl %ax, %r8d
leaq 0x70(%rsp), %rsi
leaq 0x60(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
callq 0x3b6c
leaq 0x40(%rsp), %rdi
callq 0x2160
leaq 0x20(%rsp), %rdi
callq 0x2160
movl %ebx, %eax
addq $0x848, %rsp            # imm = 0x848
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x3e03
jmp 0x3e03
jmp 0x3e03
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x2160
jmp 0x3e06
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2160
movq %rbx, %rdi
callq 0x2470