// File: /workspace/github_c_makefile_star2_O2/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 0xe1ec
cmpl $-0x1, %eax
je 0x6f9b
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 0x6f35
movq 0x22104(%rip), %rax     # 0x28fb8
movq (%rax), %r12
callq 0xe343
movq %rax, %r13
callq 0x5070
movq %rax, %r15
movl (%rax), %ebx
movl %ebx, %edi
callq 0x5540
leaq 0x1550c(%rip), %rsi     # 0x1c3e3
movq %r12, %rdi
movq %r13, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x22db4(%rip), %rax     # 0x29ca8
movq (%rax), %r12
testq %r12, %r12
je 0x6f2c
callq 0xe343
movq %rax, %rbx
movl (%r15), %r15d
movl %r15d, %edi
callq 0x5540
leaq 0x154cd(%rip), %rsi     # 0x1c3e3
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 0x7029
leaq 0x153df(%rip), %rcx     # 0x1c328
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x2205f(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x152e1(%rip), %rsi     # 0x1c249
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x22d2a(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x7231
callq 0xe343
leaq 0x152b3(%rip), %rsi     # 0x1c249
jmp 0x7222
movq 0x22016(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
movq %rax, %r12
callq 0x5070
movq %rax, %r15
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0x153f6(%rip), %rsi     # 0x1c3bb
movq %rbx, %rdi
movq %r12, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x22cc6(%rip), %rax     # 0x29ca8
movq (%rax), %r12
pushq $-0x1
popq %rbp
testq %r12, %r12
je 0x7231
callq 0xe343
movq %rax, %r13
movl %ebp, %ebx
movl (%r15), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0x153af(%rip), %rsi     # 0x1c3bb
movq %r12, %rdi
movq %r13, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movl %ebx, %ebp
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
jmp 0x7231
cmpl $0x1a, %r14d
jne 0x7231
movq 0x21f7e(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x152af(%rip), %rsi     # 0x1c2f8
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x22c49(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x7231
callq 0xe343
leaq 0x15281(%rip), %rsi     # 0x1c2f8
jmp 0x7222
movq 0x21f35(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x1524d(%rip), %rsi     # 0x1c2df
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x22c00(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x7231
callq 0xe343
leaq 0x1521f(%rip), %rsi     # 0x1c2df
jmp 0x7222
movq 0x21eec(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x151a0(%rip), %rsi     # 0x1c27b
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x22bb7(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x7231
callq 0xe343
leaq 0x15172(%rip), %rsi     # 0x1c27b
jmp 0x7222
movq 0x21ea3(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x15170(%rip), %rsi     # 0x1c294
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x22b6e(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x7231
callq 0xe343
leaq 0x15142(%rip), %rsi     # 0x1c294
jmp 0x7222
movq 0x21e5a(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x150f5(%rip), %rsi     # 0x1c262
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x22b25(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x7231
callq 0xe343
leaq 0x150c7(%rip), %rsi     # 0x1c262
jmp 0x7222
movq 0x21e11(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x150f7(%rip), %rsi     # 0x1c2ad
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x22adc(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x7231
callq 0xe343
leaq 0x150cd(%rip), %rsi     # 0x1c2ad
jmp 0x7222
movq 0x21dcf(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x150ce(%rip), %rsi     # 0x1c2c6
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x22a9a(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x7231
callq 0xe343
leaq 0x150a4(%rip), %rsi     # 0x1c2c6
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
nop