// File: /workspace/github_c_makefile_star2_O3/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 0xe8d8
cmpl $-0x1, %eax
je 0x70a9
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 0x7043
movq 0x22ffe(%rip), %rax     # 0x29fc0
movq (%rax), %r12
callq 0xea3b
movq %rax, %r13
callq 0x5070
movq %rax, %r15
movl (%rax), %ebx
movl %ebx, %edi
callq 0x5530
leaq 0x173fe(%rip), %rsi     # 0x1e3e3
movq %r12, %rdi
movq %r13, %rdx
movl %r14d, %ecx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x23ca6(%rip), %rax     # 0x2aca8
movq (%rax), %r12
testq %r12, %r12
je 0x703a
callq 0xea3b
movq %rax, %rbx
movl (%r15), %r15d
movl %r15d, %edi
callq 0x5530
leaq 0x173bf(%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 0x713a
leaq 0x172d1(%rip), %rcx     # 0x1e328
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x22f59(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x171d3(%rip), %rsi     # 0x1e249
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23c1c(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7342
callq 0xea3b
leaq 0x171a5(%rip), %rsi     # 0x1e249
jmp 0x7333
movq 0x22f10(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
movq %rax, %r12
callq 0x5070
movq %rax, %r15
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0x172e8(%rip), %rsi     # 0x1e3bb
movq %rbx, %rdi
movq %r12, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x23bb8(%rip), %rax     # 0x2aca8
movq (%rax), %r12
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r12, %r12
je 0x7342
callq 0xea3b
movq %rax, %r13
movl (%r15), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0x172a1(%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 0x7342
cmpl $0x1a, %r14d
jne 0x7342
movq 0x22e75(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x1719e(%rip), %rsi     # 0x1e2f8
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23b38(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7342
callq 0xea3b
leaq 0x17170(%rip), %rsi     # 0x1e2f8
jmp 0x7333
movq 0x22e2c(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x1713c(%rip), %rsi     # 0x1e2df
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23aef(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7342
callq 0xea3b
leaq 0x1710e(%rip), %rsi     # 0x1e2df
jmp 0x7333
movq 0x22de3(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x1708f(%rip), %rsi     # 0x1e27b
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23aa6(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7342
callq 0xea3b
leaq 0x17061(%rip), %rsi     # 0x1e27b
jmp 0x7333
movq 0x22d9a(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x1705f(%rip), %rsi     # 0x1e294
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23a5d(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7342
callq 0xea3b
leaq 0x17031(%rip), %rsi     # 0x1e294
jmp 0x7333
movq 0x22d51(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x16fe4(%rip), %rsi     # 0x1e262
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23a14(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7342
callq 0xea3b
leaq 0x16fb6(%rip), %rsi     # 0x1e262
jmp 0x7333
movq 0x22d08(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x16fe6(%rip), %rsi     # 0x1e2ad
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x239cb(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7342
callq 0xea3b
leaq 0x16fbc(%rip), %rsi     # 0x1e2ad
jmp 0x7333
movq 0x22cc6(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0x16fbd(%rip), %rsi     # 0x1e2c6
movq %rbx, %rdi
movq %rax, %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x52c0
leaq 0x23989(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x7342
callq 0xea3b
leaq 0x16f93(%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
nop