// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r15
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, 0x8(%rsp)
leaq 0x14(%rsp), %r13
movl %edi, (%r13)
leaq 0x296e8(%rip), %rbp     # 0x2c210
movl $0x10000, %edx          # imm = 0x10000
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2120
movq %r12, %rdi
movq %r13, %rsi
callq 0x48c8
movq (%rax), %r14
movl (%r13), %edi
movq %rbp, %rsi
movl $0x1, %edx
callq 0x5e5d
testq %rax, %rax
js 0x2bba
movq 0x296ae(%rip), %rdx     # 0x2c210
movq (%r14), %rcx
incq %rcx
cmpq %rcx, %rdx
jne 0x2bcf
movzwl 0x296ac(%rip), %edx     # 0x2c220
cmpl $0x8, %edx
ja 0x2c1a
movl $0x150, %eax            # imm = 0x150
btl %edx, %eax
jae 0x2c1a
testq %r15, %r15
je 0x2b93
movb %dl, (%r15)
movzwl 0x29688(%rip), %ecx     # 0x2c222
cmpq %rbx, %rcx
jbe 0x2be7
leaq 0x46f3(%rip), %rsi      # 0x7299
xorl %edi, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x273c
movl $0xfffffffc, %r12d      # imm = 0xFFFFFFFC
jmp 0x2c30
movq %rax, %r12
leaq 0x464d(%rip), %rsi      # 0x7211
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
jmp 0x2c30
leaq 0x464d(%rip), %rsi      # 0x7223
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
jmp 0x2c30
leaq 0x29636(%rip), %rsi     # 0x2c224
movq 0x8(%rsp), %rdi
movq %rcx, %rdx
callq 0x2150
movq 0x2960e(%rip), %rax     # 0x2c210
movq %rax, (%r14)
xorl %edi, %edi
callq 0x2190
movq %rax, 0x10(%r14)
movzwl 0x2960a(%rip), %r12d    # 0x2c222
jmp 0x2c30
leaq 0x463b(%rip), %rsi      # 0x725c
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
movl $0xfffffffd, %r12d      # imm = 0xFFFFFFFD
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq