// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/quectel-mbim-proxy.c
// Function: handle_client_request
static int handle_client_request(int mbim_dev_fd, int client_fd, void *pdata, int len)
{
    int i;
    int client_idx = -1;
    int ret;
    MBIM_MESSAGE_HEADER *pRequest = (MBIM_MESSAGE_HEADER *)pdata;
    unsigned int  TransactionId = le32toh(pRequest->TransactionId);

    for (i = 0; i < CM_MAX_CLIENT; i++) {
        if (cm_clients[i].client_fd == client_fd) {
            client_idx = cm_clients[i].client_idx;
            break;
        }
    }

    if (client_idx == -1) {
        goto error;
    }

    if (le32toh(pRequest->MessageType) == MBIM_OPEN_MSG
        || le32toh(pRequest->MessageType) == MBIM_CLOSE_MSG) {
        MBIM_OPEN_DONE_T OpenDone;
        OpenDone.MessageHeader.MessageType = htole32(le32toh(pRequest->MessageType) | 0x80000000);
        OpenDone.MessageHeader.MessageLength = htole32(sizeof(OpenDone));
        OpenDone.MessageHeader.TransactionId = htole32(TransactionId);
        OpenDone.Status = htole32(0);
        non_block_write (client_fd, &OpenDone, sizeof(OpenDone));
        return 0;
    }

    /* transfer TransicationID to proxy transicationID and record in sender list */
    pRequest->TransactionId = htole32(TransactionId | (client_idx << TID_SHIFT));
    if (verbose) mbim_debug("REQ client_fd=%d, client_idx=%d, tid=%u\n",
        cm_clients[i].client_fd, cm_clients[i].client_idx, TransactionId);
    ret = non_block_write (mbim_dev_fd, pRequest, len);
    if (ret == len)
        return 0;

error:
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl 0x8(%rax), %edi
callq 0x1c60
movl %eax, -0x34(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x20, -0x20(%rbp)
jge 0x2514
movslq -0x20(%rbp), %rcx
leaq 0x2c95(%rip), %rax      # 0x5180
movl (%rax,%rcx,8), %eax
cmpl -0xc(%rbp), %eax
jne 0x2507
movslq -0x20(%rbp), %rcx
leaq 0x2c82(%rip), %rax      # 0x5180
movl 0x4(%rax,%rcx,8), %eax
movl %eax, -0x24(%rbp)
jmp 0x2514
jmp 0x2509
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x24da
cmpl $-0x1, -0x24(%rbp)
jne 0x251f
jmp 0x262e
movq -0x30(%rbp), %rax
movl (%rax), %edi
callq 0x1c60
cmpl $0x1, %eax
je 0x253f
movq -0x30(%rbp), %rax
movl (%rax), %edi
callq 0x1c60
cmpl $0x2, %eax
jne 0x2599
movq -0x30(%rbp), %rax
movl (%rax), %edi
callq 0x1c60
movl %eax, %edi
orl $0x80000000, %edi       # imm = 0x80000000
callq 0x1c60
movl %eax, -0x44(%rbp)
movl $0x10, %edi
callq 0x1c60
movl %eax, -0x40(%rbp)
movl -0x34(%rbp), %edi
callq 0x1c60
movl %eax, -0x3c(%rbp)
xorl %edi, %edi
callq 0x1c60
movl %eax, -0x38(%rbp)
movl -0xc(%rbp), %edi
leaq -0x44(%rbp), %rsi
movl $0x10, %edx
callq 0x1c70
movl $0x0, -0x4(%rbp)
jmp 0x2635
movl -0x34(%rbp), %edi
movl -0x24(%rbp), %eax
shll $0x18, %eax
orl %eax, %edi
callq 0x1c60
movl %eax, %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
cmpl $0x0, 0x2bb7(%rip)      # 0x5170
je 0x2609
jmp 0x25bd
movq 0x2a0c(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0x50(%rbp)
callq 0x12a0
movq -0x50(%rbp), %rdi
movq %rax, %rdx
movslq -0x20(%rbp), %rcx
leaq 0x2b9e(%rip), %rax      # 0x5180
movl (%rax,%rcx,8), %ecx
movslq -0x20(%rbp), %rsi
leaq 0x2b90(%rip), %rax      # 0x5180
movl 0x4(%rax,%rsi,8), %r8d
movl -0x34(%rbp), %r9d
leaq 0xdb2(%rip), %rsi       # 0x33b2
movb $0x0, %al
callq 0x10f0
jmp 0x2609
movl -0x8(%rbp), %edi
movq -0x30(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x1c70
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x262c
movl $0x0, -0x4(%rbp)
jmp 0x2635
jmp 0x262e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq