// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/mbim-cm.c
// Function: requestRegistrationState
static int requestRegistrationState(UCHAR *pPSAttachedState) {
    int retval;

    *pPSAttachedState = 0;
    retval = mbim_register_state_query();
    if (retval)
        goto exit;
    mbim_update_state();

    switch (RegisterState) {
        case MBIMRegisterStateUnknown: *pPSAttachedState = 0; break;
        case MBIMRegisterStateDeregistered: *pPSAttachedState = 0; break;
        case MBIMRegisterStateSearching: *pPSAttachedState = 0; break;
        case MBIMRegisterStateHome: *pPSAttachedState = 1; break;
        case MBIMRegisterStateRoaming: *pPSAttachedState = 1; break;
        case MBIMRegisterStatePartner: *pPSAttachedState = 0; break;
        case MBIMRegisterStateDenied: *pPSAttachedState = 0; break;
        default: *pPSAttachedState = 0; break;
    }

    if (*pPSAttachedState == 0)
        goto exit;

    retval =  mbim_packet_service_query();
    if (retval)
        goto exit;

    switch (PacketServiceState) {
        case MBIMPacketServiceStateUnknown: *pPSAttachedState = 0; break;
        case MBIMPacketServiceStateAttaching: *pPSAttachedState = 0; break;
        case MBIMPacketServiceStateAttached: *pPSAttachedState = 1; break;
        case MBIMPacketServiceStateDetaching: *pPSAttachedState = 0; break;
        case MBIMPacketServiceStateDetached: *pPSAttachedState = 0; break;
        default: *pPSAttachedState = 0; break;
    }

    if (*pPSAttachedState == 0)
        mbim_packet_service_set(MBIMPacketServiceActionAttach);

exit:
    return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movb $0x0, (%rdi)
movq $0x0, 0x10(%rsp)
movq 0x1703b(%rip), %r13     # 0x29fc0
movq (%r13), %r14
callq 0xeb2f
leaq 0xf270(%rip), %rsi      # 0x22205
leaq 0xf47b(%rip), %rcx      # 0x22417
xorl %r12d, %r12d
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x17cf5(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x12fdb
callq 0xeb2f
leaq 0xf23e(%rip), %rsi      # 0x22205
leaq 0xf449(%rip), %rcx      # 0x22417
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movl $0x9, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x10b66
movq %rax, %r14
leaq 0x10(%rsp), %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x10d09
movl %eax, %ebp
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1302a
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl (%rdi), %eax
cmpl $0x3, %eax
ja 0x1302a
movl %eax, %eax
leaq 0xf7e6(%rip), %rcx      # 0x22808
movq (%rcx,%rax,8), %rax
movl (%rdi,%rax), %r12d
movl %ebp, %eax
orl %r12d, %eax
sete %al
testq %rdi, %rdi
setne %r15b
andb %al, %r15b
je 0x13043
jmp 0x13100
testq %rdi, %rdi
je 0x1305a
xorl %esi, %esi
cmpl $0x0, 0x18cdf(%rip)     # 0x2bd30
sete %sil
callq 0x10e8f
testq %r14, %r14
je 0x13067
movq %r14, %rdi
callq 0x5040
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1307f
callq 0x5040
movq $0x0, 0x10(%rsp)
movq (%r13), %r14
callq 0xeb2f
movl %r12d, (%rsp)
leaq 0xe2ca(%rip), %rsi      # 0x2135d
leaq 0xf37d(%rip), %rcx      # 0x22417
movq %r14, %rdi
movq %rax, %rdx
movl $0x781, %r8d            # imm = 0x781
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x17bf1(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x130ec
callq 0xeb2f
movl %r12d, (%rsp)
leaq 0xe28e(%rip), %rsi      # 0x2135d
leaq 0xf341(%rip), %rcx      # 0x22417
movq %r14, %rdi
movq %rax, %rdx
movl $0x781, %r8d            # imm = 0x781
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
testl %r12d, %r12d
movl $0x22b8, %eax           # imm = 0x22B8
cmovnel %r12d, %eax
testl %ebp, %ebp
cmovnel %ebp, %eax
xorl %r14d, %r14d
testb %r15b, %r15b
je 0x13145
movq 0x10(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x1311e
movl 0x34(%rax), %eax
movl %eax, 0x18de7(%rip)     # 0x2bf00
callq 0x15c62
testq %r14, %r14
je 0x1312b
movq %r14, %rdi
callq 0x5040
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x13143
callq 0x5040
movq $0x0, 0x10(%rsp)
movl %ebp, %eax
testl %eax, %eax
je 0x13158
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x15c62
movl 0x18d9d(%rip), %edx     # 0x2bf00
leal (,%rdx,8), %ecx
movabsq $0x101000000, %rsi      # imm = 0x101000000
shrq %cl, %rsi
xorl %eax, %eax
cmpl $0x7, %edx
cmovael %eax, %esi
movb %sil, (%rbx)
testb %sil, %sil
je 0x13149
movq $0x0, 0x10(%rsp)
movq (%r13), %r14
callq 0xeb2f
leaq 0xf065(%rip), %rsi      # 0x22205
leaq 0xf28a(%rip), %rcx      # 0x22431
xorl %r12d, %r12d
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x17aea(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x131e6
callq 0xeb2f
leaq 0xf033(%rip), %rsi      # 0x22205
leaq 0xf258(%rip), %rcx      # 0x22431
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movl $0xa, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x10b66
movq %rax, %r14
leaq 0x10(%rsp), %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x10d09
movl %eax, %ebp
movq (%r15), %rdi
testq %rdi, %rdi
je 0x13235
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl (%rdi), %eax
cmpl $0x3, %eax
ja 0x13235
movl %eax, %eax
leaq 0xf5db(%rip), %rcx      # 0x22808
movq (%rcx,%rax,8), %rax
movl (%rdi,%rax), %r12d
movl %ebp, %eax
orl %r12d, %eax
sete %al
testq %rdi, %rdi
setne %r15b
andb %al, %r15b
je 0x1324e
jmp 0x1330b
testq %rdi, %rdi
je 0x13265
xorl %esi, %esi
cmpl $0x0, 0x18ad4(%rip)     # 0x2bd30
sete %sil
callq 0x10e8f
testq %r14, %r14
je 0x13272
movq %r14, %rdi
callq 0x5040
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1328a
callq 0x5040
movq $0x0, 0x10(%rsp)
movq (%r13), %r14
callq 0xeb2f
movl %r12d, (%rsp)
leaq 0xe0bf(%rip), %rsi      # 0x2135d
leaq 0xf18c(%rip), %rcx      # 0x22431
movq %r14, %rdi
movq %rax, %rdx
movl $0x794, %r8d            # imm = 0x794
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x179e6(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x132f7
callq 0xeb2f
movl %r12d, (%rsp)
leaq 0xe083(%rip), %rsi      # 0x2135d
leaq 0xf150(%rip), %rcx      # 0x22431
movq %r14, %rdi
movq %rax, %rdx
movl $0x794, %r8d            # imm = 0x794
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
testl %r12d, %r12d
movl $0x22b8, %eax           # imm = 0x22B8
cmovnel %r12d, %eax
testl %ebp, %ebp
cmovnel %ebp, %eax
xorl %r14d, %r14d
testb %r15b, %r15b
je 0x13416
movq 0x10(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x133ef
movl 0x34(%rax), %eax
movl %eax, 0x18bdc(%rip)     # 0x2bf08
callq 0x15c62
movq 0x10(%rsp), %r15
cmpl $0x20, 0x2c(%r15)
jne 0x133ef
movq (%r13), %rax
movq %rax, 0x18(%rsp)
callq 0xeb2f
movl 0x38(%r15), %esi
movl $0x4, %edx
leaq 0x16761(%rip), %r12     # 0x29ac0
leaq 0xe2ae(%rip), %rcx      # 0x21614
cmpl %esi, -0x4(%rdx,%r12)
je 0x1337c
addq $0xc, %rdx
cmpq $0xd0, %rdx
jne 0x13366
jmp 0x13380
movq (%rdx,%r12), %rcx
leaq 0xf0c4(%rip), %rsi      # 0x2244b
movq 0x18(%rsp), %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x1790b(%rip), %rax     # 0x2aca8
movq (%rax), %rax
testq %rax, %rax
je 0x133ef
movq %rax, 0x18(%rsp)
callq 0xeb2f
movq 0x18(%rsp), %rdi
movl 0x38(%r15), %esi
movl $0x4, %edx
leaq 0xe250(%rip), %rcx      # 0x21614
cmpl %esi, -0x4(%rdx,%r12)
je 0x133da
addq $0xc, %rdx
cmpq $0xd0, %rdx
jne 0x133c4
jmp 0x133de
movq (%rdx,%r12), %rcx
leaq 0xf066(%rip), %rsi      # 0x2244b
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
testq %r14, %r14
je 0x133fc
movq %r14, %rdi
callq 0x5040
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x13414
callq 0x5040
movq $0x0, 0x10(%rsp)
movl %ebp, %eax
testl %eax, %eax
jne 0x13149
movl 0x18ae4(%rip), %edx     # 0x2bf08
leal (,%rdx,8), %ecx
movl $0x10000, %esi          # imm = 0x10000
shrq %cl, %rsi
xorl %eax, %eax
cmpl $0x5, %edx
cmovael %eax, %esi
movb %sil, (%rbx)
testb %sil, %sil
jne 0x13149
movq $0x0, 0x10(%rsp)
movl $0x0, 0x24(%rsp)
movq (%r13), %rbx
callq 0xeb2f
leaq 0xed9d(%rip), %rsi      # 0x22205
leaq 0xeff8(%rip), %rcx      # 0x22467
xorl %r15d, %r15d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x17822(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x134ae
callq 0xeb2f
leaq 0xed6b(%rip), %rsi      # 0x22205
leaq 0xefc6(%rip), %rcx      # 0x22467
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x24(%rsp), %rdx
movl $0xa, %edi
movl $0x1, %esi
movl $0x4, %ecx
callq 0x10b66
movq %rax, %rbx
leaq 0x10(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x10d09
movl %eax, %ebp
movq (%r14), %rdi
testq %rdi, %rdi
je 0x13506
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
addl (%rdi), %eax
cmpl $0x3, %eax
ja 0x13506
movl %eax, %eax
leaq 0xf30a(%rip), %rcx      # 0x22808
movq (%rcx,%rax,8), %rax
movl (%rdi,%rax), %r15d
movl %ebp, %eax
orl %r15d, %eax
sete %al
testq %rdi, %rdi
setne %r12b
andb %al, %r12b
jne 0x135cb
testq %rdi, %rdi
je 0x13535
xorl %esi, %esi
cmpl $0x0, 0x18804(%rip)     # 0x2bd30
sete %sil
callq 0x10e8f
testq %rbx, %rbx
je 0x13542
movq %rbx, %rdi
callq 0x5040
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1355a
callq 0x5040
movq $0x0, 0x10(%rsp)
movq (%r13), %r14
callq 0xeb2f
movl %r15d, (%rsp)
leaq 0xddef(%rip), %rsi      # 0x2135d
leaq 0xeef2(%rip), %rcx      # 0x22467
xorl %ebx, %ebx
movq %r14, %rdi
movq %rax, %rdx
movl $0x7ad, %r8d            # imm = 0x7AD
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x17714(%rip), %rax     # 0x2aca8
movq (%rax), %r14
testq %r14, %r14
je 0x135cb
callq 0xeb2f
movl %r15d, (%rsp)
leaq 0xddb1(%rip), %rsi      # 0x2135d
leaq 0xeeb4(%rip), %rcx      # 0x22467
xorl %ebx, %ebx
movq %r14, %rdi
movq %rax, %rdx
movl $0x7ad, %r8d            # imm = 0x7AD
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
testb %r12b, %r12b
je 0x1360e
movq 0x10(%rsp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x135e9
movl 0x34(%rax), %eax
movl %eax, 0x18924(%rip)     # 0x2bf08
callq 0x15c62
testq %rbx, %rbx
je 0x135f6
movq %rbx, %rdi
callq 0x5040
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1360e
callq 0x5040
movq $0x0, 0x10(%rsp)
xorl %eax, %eax
jmp 0x13149