// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/GobiNetCM.c
// Function: GobiNetGetClientID
static int GobiNetGetClientID(const char *qcqmi, UCHAR QMIType) {
    int ClientId;
    ClientId = cm_open_dev(qcqmi);
    if (ClientId == -1) {
        dbg_time("failed to open %s, errno: %d (%s)", qcqmi, errno, strerror(errno));
        return -1;
    }

    if (ioctl(ClientId, IOCTL_QMI_GET_SERVICE_FILE, QMIType) != 0) {
        dbg_time("failed to get ClientID for 0x%02x errno: %d (%s)", QMIType, errno, strerror(errno));
        close(ClientId);
        ClientId = 0;
    }

    switch (QMIType) {
        case QMUX_TYPE_WDS: dbg_time("Get clientWDS = %d", ClientId); break;
        case QMUX_TYPE_DMS: dbg_time("Get clientDMS = %d", ClientId); break;
        case QMUX_TYPE_NAS: dbg_time("Get clientNAS = %d", ClientId); break;
        case QMUX_TYPE_QOS: dbg_time("Get clientQOS = %d", ClientId); break;
        case QMUX_TYPE_WMS: dbg_time("Get clientWMS = %d", ClientId); break;
        case QMUX_TYPE_PDS: dbg_time("Get clientPDS = %d", ClientId); break;
        case QMUX_TYPE_UIM: dbg_time("Get clientUIM = %d", ClientId); break;
        case QMUX_TYPE_WDS_ADMIN: dbg_time("Get clientWDA = %d", ClientId);
        break;
        default: break;
    }

    return ClientId;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
callq 0xe9cc
cmpl $-0x1, %eax
je 0x7197
movl %eax, %ebp
movzbl %bl, %r14d
movl $0x8be1, %esi           # imm = 0x8BE1
movl %eax, %edi
movl %r14d, %edx
xorl %eax, %eax
callq 0x5210
testl %eax, %eax
je 0x7131
movq 0x22f10(%rip), %rax     # 0x29fc0
movq (%rax), %r12
callq 0xeb2f
movq %rax, %r13
callq 0x5070
movq %rax, %r15
movl (%rax), %ebx
movl %ebx, %edi
callq 0x5530
leaq 0x17310(%rip), %rsi     # 0x1e3e3
movq %r12, %rdi
movq %r13, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x23bb8(%rip), %rax     # 0x2aca8
movq (%rax), %r12
testq %r12, %r12
je 0x7128
callq 0xeb2f
movq %rax, %rbx
movl (%r15), %r15d
movl %r15d, %edi
callq 0x5530
leaq 0x172d1(%rip), %rsi     # 0x1e3e3
movq %r12, %rdi
movq %rbx, %rdx
movl %r14d, %ecx
movl %r15d, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movl %ebp, %edi
callq 0x5230
xorl %ebp, %ebp
leal -0x1(%r14), %eax
cmpl $0xa, %eax
ja 0x7228
leaq 0x171e3(%rip), %rcx     # 0x1e328
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x22e6b(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x170e5(%rip), %rsi     # 0x1e249
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23b2e(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7430
callq 0xeb2f
leaq 0x170b7(%rip), %rsi     # 0x1e249
jmp 0x7421
movq 0x22e22(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
movq %rax, %r12
callq 0x5070
movq %rax, %r15
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0x171fa(%rip), %rsi     # 0x1e3bb
movq %rbx, %rdi
movq %r12, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x23aca(%rip), %rax     # 0x2aca8
movq (%rax), %r12
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r12, %r12
je 0x7430
callq 0xeb2f
movq %rax, %r13
movl (%r15), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0x171b3(%rip), %rsi     # 0x1e3bb
movq %r12, %rdi
movq %r13, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
jmp 0x7430
cmpl $0x1a, %r14d
jne 0x7430
movq 0x22d87(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x170b0(%rip), %rsi     # 0x1e2f8
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23a4a(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7430
callq 0xeb2f
leaq 0x17082(%rip), %rsi     # 0x1e2f8
jmp 0x7421
movq 0x22d3e(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x1704e(%rip), %rsi     # 0x1e2df
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23a01(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7430
callq 0xeb2f
leaq 0x17020(%rip), %rsi     # 0x1e2df
jmp 0x7421
movq 0x22cf5(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x16fa1(%rip), %rsi     # 0x1e27b
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x239b8(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7430
callq 0xeb2f
leaq 0x16f73(%rip), %rsi     # 0x1e27b
jmp 0x7421
movq 0x22cac(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x16f71(%rip), %rsi     # 0x1e294
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x2396f(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7430
callq 0xeb2f
leaq 0x16f43(%rip), %rsi     # 0x1e294
jmp 0x7421
movq 0x22c63(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x16ef6(%rip), %rsi     # 0x1e262
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23926(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7430
callq 0xeb2f
leaq 0x16ec8(%rip), %rsi     # 0x1e262
jmp 0x7421
movq 0x22c1a(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x16ef8(%rip), %rsi     # 0x1e2ad
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x238dd(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7430
callq 0xeb2f
leaq 0x16ece(%rip), %rsi     # 0x1e2ad
jmp 0x7421
movq 0x22bd8(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0x16ecf(%rip), %rsi     # 0x1e2c6
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x2389b(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7430
callq 0xeb2f
leaq 0x16ea5(%rip), %rsi     # 0x1e2c6
movq %r14, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)