// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rdi, %rbx
movb $0x0, (%rdi)
andq $0x0, 0x8(%rsp)
movq 0x16b82(%rip), %r13     # 0x28fb8
movq (%r13), %r14
callq 0xe343
leaq 0xddfc(%rip), %rsi      # 0x20242
leaq 0xe007(%rip), %rcx      # 0x20454
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x17847(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x12489
callq 0xe343
leaq 0xddcd(%rip), %rsi      # 0x20242
leaq 0xdfd8(%rip), %rcx      # 0x20454
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
pushq $0x9
popq %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1022b
movq %rax, %r15
leaq 0x8(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x103ea
movl %eax, %ebp
movq (%r14), %r12
movq %r12, %rdi
callq 0x1055f
movl %eax, %r14d
testq %r12, %r12
je 0x12525
testl %ebp, %ebp
jne 0x12525
testl %r14d, %r14d
jne 0x12525
cmpl $0x0, 0x2c(%r12)
je 0x124ea
movl 0x34(%r12), %eax
movl %eax, 0x18a20(%rip)     # 0x2af00
callq 0x14cde
movq 0x8(%rsp), %r12
movq %r15, %rdi
callq 0x5040
movq %r12, %rdi
callq 0x5040
callq 0x14cde
movl 0x189fb(%rip), %eax     # 0x2af00
cmpq $0x6, %rax
ja 0x1251b
leaq 0xce3a(%rip), %rcx      # 0x1f34c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, (%rbx)
xorl %eax, %eax
jmp 0x125e1
testq %r12, %r12
je 0x12546
xorl %esi, %esi
cmpl $0x0, 0x187fd(%rip)     # 0x2ad30
sete %sil
movq %r12, %rdi
callq 0x10583
movq 0x8(%rsp), %rbx
jmp 0x12548
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x5040
testq %rbx, %rbx
je 0x12563
movq %rbx, %rdi
callq 0x5040
andq $0x0, 0x8(%rsp)
movq (%r13), %rbx
callq 0xe343
movl %r14d, (%rsp)
leaq 0xce2a(%rip), %rsi      # 0x1f3a1
leaq 0xded6(%rip), %rcx      # 0x20454
movq %rbx, %rdi
movq %rax, %rdx
movl $0x781, %r8d            # imm = 0x781
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x1770d(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x125d0
callq 0xe343
movl %r14d, (%rsp)
leaq 0xcdee(%rip), %rsi      # 0x1f3a1
leaq 0xde9a(%rip), %rcx      # 0x20454
movq %rbx, %rdi
movq %rax, %rdx
movl $0x781, %r8d            # imm = 0x781
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
testl %r14d, %r14d
movl $0x22b8, %eax           # imm = 0x22B8
cmovnel %r14d, %eax
testl %ebp, %ebp
cmovnel %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, (%rbx)
andq $0x0, 0x8(%rsp)
movq (%r13), %r14
callq 0xe343
leaq 0xdc39(%rip), %rsi      # 0x20242
leaq 0xde5e(%rip), %rcx      # 0x2046e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x17684(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x1264c
callq 0xe343
leaq 0xdc0a(%rip), %rsi      # 0x20242
leaq 0xde2f(%rip), %rcx      # 0x2046e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
pushq $0xa
popq %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1022b
movq %rax, %r14
leaq 0x8(%rsp), %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x103ea
movl %eax, %ebp
movq (%r15), %r12
movq %r12, %rdi
callq 0x1055f
movl %eax, %r15d
testq %r12, %r12
je 0x12750
testl %ebp, %ebp
jne 0x12750
testl %r15d, %r15d
jne 0x12750
cmpl $0x0, 0x2c(%r12)
je 0x1272f
movl 0x34(%r12), %eax
movl %eax, 0x18855(%rip)     # 0x2af08
callq 0x14cde
movq 0x8(%rsp), %r12
cmpl $0x20, 0x2c(%r12)
jne 0x1272f
movq (%r13), %r15
callq 0xe343
movq %rax, %rbp
movl 0x38(%r12), %edi
callq 0x14c13
leaq 0xdda6(%rip), %rsi      # 0x20488
movq %r15, %rdi
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x52c0
leaq 0x175af(%rip), %rax     # 0x29ca8
movq (%rax), %r15
testq %r15, %r15
je 0x1272a
callq 0xe343
movq %rax, %rbp
movl 0x38(%r12), %edi
callq 0x14c13
leaq 0xdd6e(%rip), %rsi      # 0x20488
movq %r15, %rdi
movq %rbp, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x52c0
movq 0x8(%rsp), %r12
movq %r14, %rdi
callq 0x5040
movq %r12, %rdi
callq 0x5040
cmpl $0x2, 0x187c2(%rip)     # 0x2af08
jne 0x12778
movb $0x1, (%rbx)
jmp 0x1251e
testq %r12, %r12
je 0x1285c
xorl %esi, %esi
cmpl $0x0, 0x185ce(%rip)     # 0x2ad30
sete %sil
movq %r12, %rdi
callq 0x10583
movq 0x8(%rsp), %rbx
jmp 0x1285e
movb $0x0, (%rbx)
andq $0x0, 0x8(%rsp)
andl $0x0, 0x14(%rsp)
movq (%r13), %rbx
callq 0xe343
leaq 0xdaac(%rip), %rsi      # 0x20242
leaq 0xdd07(%rip), %rcx      # 0x204a4
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x174f7(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x127d9
callq 0xe343
leaq 0xda7d(%rip), %rsi      # 0x20242
leaq 0xdcd8(%rip), %rcx      # 0x204a4
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
pushq $0xa
popq %rdi
pushq $0x1
popq %rsi
leaq 0x14(%rsp), %rdx
pushq $0x4
popq %rcx
callq 0x1022b
movq %rax, %r14
leaq 0x8(%rsp), %r15
movq %rax, %rdi
movq %r15, %rsi
movl $0x7530, %edx           # imm = 0x7530
callq 0x103ea
movl %eax, %ebx
movq (%r15), %r15
movq %r15, %rdi
callq 0x1055f
movl %eax, %ebp
testq %r15, %r15
je 0x128f7
testl %ebx, %ebx
jne 0x128f7
testl %ebp, %ebp
jne 0x128f7
cmpl $0x0, 0x2c(%r15)
je 0x12847
movl 0x34(%r15), %eax
movl %eax, 0x186cb(%rip)     # 0x2af08
callq 0x14cde
movq 0x8(%rsp), %r15
movq %r14, %rdi
callq 0x5040
movq %r15, %rdi
callq 0x5040
jmp 0x1251e
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x5040
testq %rbx, %rbx
je 0x12879
movq %rbx, %rdi
callq 0x5040
andq $0x0, 0x8(%rsp)
movq (%r13), %rbx
callq 0xe343
movl %r15d, (%rsp)
leaq 0xcb14(%rip), %rsi      # 0x1f3a1
leaq 0xdbda(%rip), %rcx      # 0x2046e
movq %rbx, %rdi
movq %rax, %rdx
movl $0x794, %r8d            # imm = 0x794
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x173f7(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
testq %rbx, %rbx
je 0x128e6
callq 0xe343
movl %r15d, (%rsp)
leaq 0xcad8(%rip), %rsi      # 0x1f3a1
leaq 0xdb9e(%rip), %rcx      # 0x2046e
movq %rbx, %rdi
movq %rax, %rdx
movl $0x794, %r8d            # imm = 0x794
movl %ebp, %r9d
xorl %eax, %eax
callq 0x52c0
testl %r15d, %r15d
movl $0x22b8, %eax           # imm = 0x22B8
cmovnel %r15d, %eax
jmp 0x125dc
testq %r15, %r15
je 0x12918
xorl %esi, %esi
cmpl $0x0, 0x1842b(%rip)     # 0x2ad30
sete %sil
movq %r15, %rdi
callq 0x10583
movq 0x8(%rsp), %r15
jmp 0x1291b
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x5040
testq %r15, %r15
je 0x12936
movq %r15, %rdi
callq 0x5040
andq $0x0, 0x8(%rsp)
movq (%r13), %r14
callq 0xe343
movl %ebp, (%rsp)
leaq 0xca58(%rip), %rsi      # 0x1f3a1
leaq 0xdb54(%rip), %rcx      # 0x204a4
movq %r14, %rdi
movq %rax, %rdx
movl $0x7ad, %r8d            # imm = 0x7AD
movl %ebx, %r9d
xorl %eax, %eax
callq 0x52c0
leaq 0x1733b(%rip), %rax     # 0x29ca8
movq (%rax), %r14
testq %r14, %r14
je 0x1251e
callq 0xe343
movl %ebp, (%rsp)
leaq 0xca19(%rip), %rsi      # 0x1f3a1
leaq 0xdb15(%rip), %rcx      # 0x204a4
movq %r14, %rdi
movq %rax, %rdx
movl $0x7ad, %r8d            # imm = 0x7AD
movl %ebx, %r9d
xorl %eax, %eax
callq 0x52c0
jmp 0x1251e