// File: /workspace/github_cpp_makefile_star2_O1/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 0x2a6e4(%rip), %rbp     # 0x2d210
movl $0x10000, %edx          # imm = 0x10000
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2120
movq %r12, %rdi
movq %r13, %rsi
callq 0x4a0e
movq (%rax), %r14
movl (%r13), %edi
movq %rbp, %rsi
movl $0x1, %edx
callq 0x6046
testq %rax, %rax
js 0x2bbe
movq 0x2a6aa(%rip), %rdx     # 0x2d210
movq (%r14), %rcx
incq %rcx
cmpq %rcx, %rdx
jne 0x2bd3
movzwl 0x2a6a8(%rip), %edx     # 0x2d220
cmpl $0x8, %edx
ja 0x2c1e
movl $0x150, %eax            # imm = 0x150
btl %edx, %eax
jae 0x2c1e
testq %r15, %r15
je 0x2b97
movb %dl, (%r15)
movzwl 0x2a684(%rip), %ecx     # 0x2d222
cmpq %rbx, %rcx
jbe 0x2beb
leaq 0x56ef(%rip), %rsi      # 0x8299
xorl %edi, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x273c
movl $0xfffffffc, %r12d      # imm = 0xFFFFFFFC
jmp 0x2c34
movq %rax, %r12
leaq 0x5649(%rip), %rsi      # 0x8211
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
jmp 0x2c34
leaq 0x5649(%rip), %rsi      # 0x8223
xorl %edi, %edi
xorl %eax, %eax
callq 0x273c
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
jmp 0x2c34
leaq 0x2a632(%rip), %rsi     # 0x2d224
movq 0x8(%rsp), %rdi
movq %rcx, %rdx
callq 0x2150
movq 0x2a60a(%rip), %rax     # 0x2d210
movq %rax, (%r14)
xorl %edi, %edi
callq 0x2190
movq %rax, 0x10(%r14)
movzwl 0x2a606(%rip), %r12d    # 0x2d222
jmp 0x2c34
leaq 0x5637(%rip), %rsi      # 0x825c
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