// File: renzibei[P]TSProxy/proxyserver.cpp
// Function: recvData(int, unsigned char*, unsigned long, std::unordered_map<int, ClientNode*, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, ClientNode*>>>&, unsigned char*)
int recvData(int sockFd, uint8_t *dst, size_t bufferSize, ClientMap &cMap, uint8_t *msgTypePtr = NULL) {
    static InnerMsg innerMsg;
    memset(&innerMsg, 0, sizeof(innerMsg));
    ClientNode *node = cMap[sockFd];
    ssize_t recvCode = recvTSPacket(sockFd, &innerMsg, constants::serverNonBlocking);
    if (recvCode < 0) {
        LogHelper::log(Error, "Fail to recv data");
        return recvCode;
    }
    
    if (innerMsg.cSeq != node->cSeq + 1 ) {
        LogHelper::log(Error, "Fail to recv data, seq error, cSeq: %llu, expected: %llu", innerMsg.cSeq, node->cSeq + 1);
        return -2;
    }
    if (innerMsg.msgType != 4 && innerMsg.msgType != 6 && innerMsg.msgType != 8) {
        LogHelper::log(Error, "Fail to recv data, msgType error, recv type :%d, expected: 4", innerMsg.msgType);
        return -3;
    }
    if (msgTypePtr != NULL) {
        *msgTypePtr = innerMsg.msgType;
    }
    if (innerMsg.dataLength > bufferSize) {
        LogHelper::log(Error, "Fail to recv data, bufferSize not enought, bufferSize :%lu, expected: %lu", bufferSize, innerMsg.dataLength);
        return -4;
    }
    memcpy(dst, innerMsg.data, innerMsg.dataLength);
    node->cSeq = innerMsg.cSeq;
    node->lastTime = time(NULL);
    return innerMsg.dataLength;
}

// Assembly:
subq $0x38, %rsp
movl %edi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %r8, 0x10(%rsp)
leaq 0x3440d(%rip), %rdi     # 0x37240
xorl %esi, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x2140
movq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x5650
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movl 0x30(%rsp), %edi
leaq 0x343df(%rip), %rsi     # 0x37240
movl $0x1, %edx
callq 0xd5b0
movq %rax, (%rsp)
cmpq $0x0, (%rsp)
jge 0x2e93
xorl %edi, %edi
leaq 0xd397(%rip), %rsi      # 0x10216
movb $0x0, %al
callq 0x28f0
movq (%rsp), %rax
movl %eax, 0x34(%rsp)
jmp 0x2fbc
movq 0x343a6(%rip), %rax     # 0x37240
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
je 0x2edb
movq 0x3438e(%rip), %rdx     # 0x37240
movq 0x8(%rsp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
xorl %edi, %edi
leaq 0xd361(%rip), %rsi      # 0x10228
movb $0x0, %al
callq 0x28f0
movl $0xfffffffe, 0x34(%rsp) # imm = 0xFFFFFFFE
jmp 0x2fbc
movzwl 0x3436e(%rip), %eax     # 0x37250
cmpl $0x4, %eax
je 0x2f23
movzwl 0x34362(%rip), %eax     # 0x37250
cmpl $0x6, %eax
je 0x2f23
movzwl 0x34356(%rip), %eax     # 0x37250
cmpl $0x8, %eax
je 0x2f23
movzwl 0x3434a(%rip), %edx     # 0x37250
xorl %edi, %edi
leaq 0xd352(%rip), %rsi      # 0x10261
movb $0x0, %al
callq 0x28f0
movl $0xfffffffd, 0x34(%rsp) # imm = 0xFFFFFFFD
jmp 0x2fbc
cmpq $0x0, 0x10(%rsp)
je 0x2f3b
movw 0x3431e(%rip), %ax      # 0x37250
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, (%rax)
movzwl 0x34310(%rip), %eax     # 0x37252
cmpq 0x20(%rsp), %rax
jbe 0x2f6f
movq 0x20(%rsp), %rdx
movzwl 0x342fd(%rip), %ecx     # 0x37252
xorl %edi, %edi
leaq 0xd340(%rip), %rsi      # 0x1029e
movb $0x0, %al
callq 0x28f0
movl $0xfffffffc, 0x34(%rsp) # imm = 0xFFFFFFFC
jmp 0x2fbc
movq 0x28(%rsp), %rdi
movzwl 0x342d7(%rip), %eax     # 0x37252
movl %eax, %edx
leaq 0x342bc(%rip), %rsi     # 0x37240
addq $0x14, %rsi
callq 0x2180
movq 0x342ac(%rip), %rcx     # 0x37240
movq 0x8(%rsp), %rax
movq %rcx, (%rax)
xorl %eax, %eax
movl %eax, %edi
callq 0x21c0
movq %rax, %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rax)
movzwl 0x3429a(%rip), %eax     # 0x37252
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)