// File: /workspace/github_cpp_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x848, %rsp            # imm = 0x848
movl %esi, %eax
movq %rdi, %r14
leaq 0x3c(%rsp), %r9
movl $0x10, (%r9)
leaq 0x70(%rsp), %rsi
movq %rsp, %r8
movl $0x7d0, %edx            # imm = 0x7D0
movl %eax, %edi
xorl %ecx, %ecx
callq 0x3240
movq %rax, %rbx
testl %ebx, %ebx
js 0x5375
movl %ebx, %eax
andl $0x7ffffff8, %eax       # imm = 0x7FFFFFF8
cmpl $0x47, %eax
ja 0x5388
leaq 0x3135(%rip), %rdi      # 0x8497
movl $0x48, %edx
movl %ebx, %esi
xorl %eax, %eax
callq 0x3100
jmp 0x547e
leaq 0x3106(%rip), %rdi      # 0x8482
xorl %eax, %eax
callq 0x3100
jmp 0x547e
movl 0xb0(%rsp), %esi
cmpl %ebx, %esi
jne 0x5460
movzbl 0x70(%rsp), %edx
cmpl $0x1, %edx
jne 0x546b
leaq 0x60(%rsp), %rsi
xorl %edi, %edi
callq 0x32c0
leaq 0x70(%rsp), %rdi
callq 0x4614
leaq 0x60(%r14), %r15
movl 0x4(%rsp), %eax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x56f0
leaq 0x28(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x41c4
cmpq $0x0, 0x8(%r12)
jne 0x54ca
leaq 0x4(%rsp), %rdi
movl $0x4, %esi
movl $0x2, %edx
callq 0x33b0
testq %rax, %rax
je 0x5492
movq (%rax), %r12
movl 0x4(%rsp), %eax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x56f0
movq %rax, %r15
movq 0x8(%rax), %r13
movq %r12, %rdi
callq 0x3150
movq %r15, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x3420
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x31a0
jmp 0x54ca
leaq 0x3068(%rip), %rdi      # 0x84cf
movl %ebx, %edx
jmp 0x5477
leaq 0x3084(%rip), %rdi      # 0x84f6
movl $0x1, %esi
xorl %eax, %eax
callq 0x3100
movl %ebx, %eax
addq $0x848, %rsp            # imm = 0x848
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%rsp), %edi
callq 0x3160
movq %rax, %r12
movl 0x4(%rsp), %eax
leaq 0x10(%rsp), %rsi
movq %rax, (%rsi)
movq %r15, %rdi
callq 0x56f0
movq %rax, %rdi
movq %r12, %rsi
callq 0x33a0
leaq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x31a0
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x41c4
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 0x520e
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x551d
callq 0x32f0
movq 0x18(%rsp), %rdi
cmpq %rbp, %rdi
je 0x547e
callq 0x32f0
jmp 0x547e
jmp 0x554f
jmp 0x554f
jmp 0x554f
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x5552
callq 0x32f0
jmp 0x5552
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %rbp, %rdi
je 0x5561
callq 0x32f0
movq %rbx, %rdi
callq 0x34b0
nop