// File: /workspace/github_c_makefile_star2_O1/Carton32[P]quectel-CM/quectel-mbim-proxy.c
// Function: main
int main(int argc, char **argv)
{
    int optidx = 0;
    int opt;
    char *optstr = "d:vh";
    const char *device = "/dev/cdc-wdm0";

    struct option options[] = {
        {"verbose", no_argument,        NULL, 'v'},
        {"device", required_argument,   NULL, 'd'},
        {0, 0, 0, 0},
    };
    while ((opt = getopt_long(argc, argv, optstr, options, &optidx)) != -1) {
        switch (opt) {
        case 'v':
            verbose = 1;
            break;
        case 'd':
            device = optarg;
            break;
        case 'h':
            mbim_debug("-h              Show this message\n");
            mbim_debug("-v              Verbose\n");
            mbim_debug("-d [device]     MBIM device\n");
            return 0;
        default:
            mbim_debug("illegal argument\n");
            return -1;
        }
    }

    if (!device) {
        mbim_debug("Missing parameter: device\n");
        return -1;
    }

    while (1) {
        int mbim_dev_fd = open(device, O_RDWR | O_NONBLOCK | O_NOCTTY);
        if (mbim_dev_fd < 0) {
            mbim_debug("cannot open mbim_device %s: %s\n", device, strerror(errno));
            sleep(2);
            continue;
        }
        mbim_debug ("mbim_dev_fd=%d\n", mbim_dev_fd);

        memset(cm_clients, 0, sizeof(cm_clients));
        mbim_send_open_msg(mbim_dev_fd, sizeof(cm_recv_buffer));
        proxy_loop(mbim_dev_fd);
        safe_close(mbim_dev_fd);
    }

    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x2c(%rsp), %r14
movl $0x0, (%r14)
leaq 0x2a35(%rip), %rsi      # 0x3d80
leaq 0x1b0(%rsp), %r15
movl $0xc, %ecx
movq %r15, %rdi
rep  movsq (%rsi), %es:(%rdi)
leaq 0xce0(%rip), %rax       # 0x2045
movq %rax, 0x18(%rsp)
leaq 0xccf(%rip), %r12       # 0x2040
movq 0x2c60(%rip), %r13      # 0x3fd8
movl %ebp, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x1080
cmpl $0x76, %eax
jne 0x1399
movb $0x1, 0x2dc9(%rip)      # 0x4160
jmp 0x1378
cmpl $-0x1, %eax
je 0x140d
cmpl $0x64, %eax
jne 0x13ae
movq (%r13), %rax
movq %rax, 0x18(%rsp)
jmp 0x1378
cmpl $0x68, %eax
jne 0x1cea
movq 0x2c12(%rip), %r12      # 0x3fd0
movq (%r12), %r14
callq 0x127c
leaq 0xc94(%rip), %rsi       # 0x2062
leaq 0x2d0b(%rip), %r15      # 0x40e0
xorl %ebx, %ebx
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10e0
movq (%r12), %r14
callq 0x127c
leaq 0xc94(%rip), %rsi       # 0x2088
movq %r14, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x10e0
leaq 0xc9c(%rip), %r14       # 0x20a4
jmp 0x1d04
cmpq $0x0, 0x18(%rsp)
je 0x1cf8
movq 0x2bb0(%rip), %r12      # 0x3fd0
leaq 0x2d49(%rip), %rbp      # 0x4170
leaq 0xa0(%rsp), %r15
movq 0x18(%rsp), %r14
movq %r14, %rdi
movl $0x902, %esi            # imm = 0x902
xorl %eax, %eax
callq 0x1120
movl %eax, %r13d
movq (%r12), %rbx
callq 0x127c
testl %r13d, %r13d
js 0x1cb1
movq %rbx, %rdi
leaq 0xcb8(%rip), %rsi       # 0x211a
leaq 0x2c77(%rip), %r14      # 0x40e0
movq %r14, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x10e0
movl $0x100, %edx            # imm = 0x100
movq %rbp, %rdi
xorl %esi, %esi
callq 0x10b0
movaps 0xb84(%rip), %xmm0      # 0x2010
movups %xmm0, 0xa0(%rsp)
movq (%r12), %rbx
callq 0x127c
movq %rbx, %rdi
leaq 0xc86(%rip), %rsi       # 0x212d
movq %r14, %rdx
leaq 0xc85(%rip), %rcx       # 0x2136
xorl %eax, %eax
callq 0x10e0
movl %r13d, %edi
movq %r15, %rsi
movl $0x10, %edx
callq 0x1d3b
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
testl %r13d, %r13d
je 0x1c48
movl %r13d, 0x4(%rsp)
movl %r13d, 0xa0(%rsp)
movl $0x1, 0xa4(%rsp)
testl %edi, %edi
movl %edi, 0x8(%rsp)
jle 0x1540
movl %edi, 0xa8(%rsp)
movl $0x1, 0xac(%rsp)
movl $0x2, %ebx
xorl %eax, %eax
movl (%rax,%rbp), %ecx
testl %ecx, %ecx
jle 0x152d
movslq %ebx, %rbx
movl %ecx, 0xa0(%rsp,%rbx,8)
movl $0x1, 0xa4(%rsp,%rbx,8)
incl %ebx
addq $0x8, %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x150f
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
jmp 0x154a
movl $0x1, %ebx
movl $0x2710, %edx           # imm = 0x2710
movslq %ebx, %rsi
movq %r15, %rdi
callq 0x1100
testl %eax, %eax
jle 0x1c12
testl %ebx, %ebx
jle 0x1c26
movl %ebx, %eax
movq %rax, 0x20(%rsp)
xorl %r13d, %r13d
movl 0xa0(%rsp,%r13,8), %r14d
movswl 0xa6(%rsp,%r13,8), %r15d
testb $0x38, %r15b
je 0x15e0
movq (%r12), %r12
callq 0x127c
movq %r12, %rdi
leaq 0xc05(%rip), %rsi       # 0x219e
leaq 0x2b40(%rip), %rdx      # 0x40e0
leaq 0xc1b(%rip), %rcx       # 0x21c2
movl %r14d, %r8d
movl %r15d, %r9d
xorl %eax, %eax
callq 0x10e0
movl $0x7, %ebx
cmpl 0x4(%rsp), %r14d
je 0x15d4
movl $0xa, %ebx
cmpl 0x8(%rsp), %r14d
je 0x15d4
movl %r14d, %edi
callq 0x1e27
movq 0x29f5(%rip), %r12      # 0x3fd0
jmp 0x17f2
movl $0xa, %ebx
testb $0x1, %r15b
je 0x17f2
movl 0x8(%rsp), %ebx
cmpl %ebx, %r14d
jne 0x169f
movl $0x10, 0xc(%rsp)
movl %r14d, %edi
leaq 0x30(%rsp), %rsi
leaq 0xc(%rsp), %rdx
callq 0x1130
testl %eax, %eax
js 0x1715
movl %eax, %r14d
movl %eax, %edi
movl $0x3, %esi
xorl %eax, %eax
callq 0x1060
orl $0x800, %eax            # imm = 0x800
movl %r14d, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x1060
testl %eax, %eax
jns 0x167c
movq (%r12), %r15
callq 0x127c
callq 0x1040
movl (%rax), %edi
callq 0x1150
movq %r15, %rdi
leaq 0xc41(%rip), %rsi       # 0x22a9
leaq 0x2a71(%rip), %rdx      # 0x40e0
movl %r14d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x10e0
xorl %ebx, %ebx
cmpl $0x0, (%rbp,%rbx,8)
jle 0x17b2
incq %rbx
cmpq $0x20, %rbx
jne 0x167e
movl %r14d, %edi
callq 0x10c0
jmp 0x17f0
movl $0x1000, %edx           # imm = 0x1000
movl %r14d, %edi
leaq 0x2bc2(%rip), %rsi      # 0x4270
callq 0x10d0
movq %rax, %r15
testl %r15d, %r15d
jle 0x174a
cmpl 0x4(%rsp), %r14d
jne 0x1812
cmpl $-0x1, %ebx
je 0x188a
movl 0x2b9e(%rip), %r14d     # 0x4278
testl %r14d, %r14d
je 0x1a5d
movl %r14d, %eax
shrl $0x18, %eax
xorl %r12d, %r12d
cmpl %eax, 0x4(%rbp,%r12,8)
jne 0x1705
leaq (,%r12,8), %rbx
cmpl $0x0, (%rbx,%rbp)
jg 0x1a8b
incq %r12
cmpq $0x20, %r12
jne 0x16ec
movb $0x1, %al
jmp 0x1af4
movq (%r12), %r14
callq 0x127c
callq 0x1040
movl (%rax), %edi
callq 0x1150
movq %r14, %rdi
leaq 0xb59(%rip), %rsi       # 0x228d
leaq 0x29a5(%rip), %rdx      # 0x40e0
movq %rax, %rcx
xorl %eax, %eax
callq 0x10e0
jmp 0x17f0
movq (%r12), %r12
callq 0x127c
callq 0x1040
movl (%rax), %ebx
movl %ebx, %edi
callq 0x1150
movq %rax, %r10
movq %r12, %rdi
leaq 0xa5f(%rip), %rsi       # 0x21cd
leaq 0x296b(%rip), %rdx      # 0x40e0
leaq 0xa46(%rip), %rcx       # 0x21c2
movl %r14d, %r8d
movl %r15d, %r9d
xorl %eax, %eax
pushq %r10
pushq %rbx
callq 0x10e0
addq $0x10, %rsp
movl $0x7, %ebx
cmpl 0x4(%rsp), %r14d
je 0x15d4
movl %r14d, %edi
callq 0x1e27
movl $0x1, %ebx
jmp 0x15d4
movl %r14d, (%rbp,%rbx,8)
leal 0x1(%rbx), %eax
movl %eax, 0x4(%rbp,%rbx,8)
movq (%r12), %r14
callq 0x127c
movl (%rbp,%rbx,8), %r8d
movl 0x4(%rbp,%rbx,8), %r9d
movq %r14, %rdi
leaq 0xa76(%rip), %rsi       # 0x2251
leaq 0x28fe(%rip), %rdx      # 0x40e0
leaq 0xaf7(%rip), %rcx       # 0x22e0
xorl %eax, %eax
callq 0x10e0
xorl %ebx, %ebx
cmpl $0xa, %ebx
je 0x17ff
testl %ebx, %ebx
jne 0x1c2a
incq %r13
cmpq 0x20(%rsp), %r13
jne 0x156f
jmp 0x1c19
movl 0x2a60(%rip), %esi      # 0x4278
xorl %r12d, %r12d
cmpl %r14d, (%rbp,%r12,8)
je 0x1838
incq %r12
cmpq $0x20, %r12
jne 0x181b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0x20, %r12d
jmp 0x183d
movl 0x4(%rbp,%r12,8), %eax
xorl %ebx, %ebx
cmpl $-0x1, %eax
je 0x15d4
movl 0x2a22(%rip), %ecx      # 0x4270
leal -0x1(%rcx), %edx
cmpl $0x1, %edx
ja 0x19f7
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x30(%rsp)
movl $0x10, 0x34(%rsp)
movl %esi, 0x38(%rsp)
movl $0x0, 0x3c(%rsp)
movl %r14d, %edi
leaq 0x30(%rsp), %rsi
movl $0x10, %edx
jmp 0x1a53
movl $0xffffffff, 0x8(%rsp)  # imm = 0xFFFFFFFF
cmpl $0x80000001, 0x29d4(%rip) # imm = 0x80000001
jne 0x17f0
movq (%r12), %rbx
callq 0x127c
movl 0x29cb(%rip), %ecx      # 0x427c
movq %rbx, %rdi
leaq 0x93b(%rip), %rsi       # 0x21f6
leaq 0x281e(%rip), %rdx      # 0x40e0
xorl %eax, %eax
callq 0x10e0
movl $0x7, %ebx
cmpl $0x0, 0x29a7(%rip)      # 0x427c
jne 0x17f2
movl $0x1, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1170
testl %eax, %eax
js 0x1b35
movl %eax, %r14d
movl %eax, %edi
movl $0x3, %esi
xorl %eax, %eax
callq 0x1060
orl $0x800, %eax            # imm = 0x800
movl %r14d, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x1060
testl %eax, %eax
jns 0x1952
movq (%r12), %rbx
callq 0x127c
callq 0x1040
movl (%rax), %edi
callq 0x1150
movq %rbx, %rdi
leaq 0x9ce(%rip), %rsi       # 0x230c
leaq 0x279b(%rip), %rdx      # 0x40e0
movl %r14d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x10e0
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movups %xmm0, 0x8e(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movw $0x1, 0x30(%rsp)
xorl %ebx, %ebx
movb %bl, 0x32(%rsp)
movl $0x6c, %esi
leaq 0x32(%rsp), %rdi
leaq 0x9a7(%rip), %rdx       # 0x2343
leaq 0x879(%rip), %rcx       # 0x221c
xorl %eax, %eax
callq 0x1090
movb %bl, 0x32(%rsp)
movl $0x1, 0xc(%rsp)
movl %r14d, %edi
movl $0x1, %esi
movl $0x2, %edx
leaq 0xc(%rsp), %rcx
movl $0x4, %r8d
callq 0x1050
testl %eax, %eax
jns 0x1b7a
testl %r14d, %r14d
je 0x1b56
movl %r14d, %edi
callq 0x10c0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x1b59
shll $0x18, %eax
orl %esi, %eax
movl %eax, 0x2876(%rip)      # 0x4278
cmpb $0x1, 0x2757(%rip)      # 0x4160
jne 0x1a45
movq 0x25be(%rip), %rax      # 0x3fd0
movq (%rax), %r14
movl %esi, 0x10(%rsp)
callq 0x127c
movl (%rbp,%r12,8), %ecx
movl 0x4(%rbp,%r12,8), %r8d
movq %r14, %rdi
leaq 0x99c(%rip), %rsi       # 0x23ce
leaq 0x26a7(%rip), %rdx      # 0x40e0
movl 0x10(%rsp), %r9d
xorl %eax, %eax
callq 0x10e0
movl 0x4(%rsp), %edi
leaq 0x2820(%rip), %rsi      # 0x4270
movl %r15d, %edx
callq 0x1d3b
jmp 0x15d4
xorl %r14d, %r14d
movl (%r14,%rbp), %edi
testl %edi, %edi
jle 0x1a77
leaq 0x2801(%rip), %rsi      # 0x4270
movl %r15d, %edx
callq 0x1d3b
addq $0x8, %r14
xorl %ebx, %ebx
cmpq $0x100, %r14            # imm = 0x100
jne 0x1a60
jmp 0x17f2
andl $0xffffff, %r14d        # imm = 0xFFFFFF
movl %r14d, 0x27df(%rip)     # 0x4278
cmpb $0x1, 0x26c0(%rip)      # 0x4160
jne 0x1adb
movq 0x2527(%rip), %rax      # 0x3fd0
movq (%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x127c
movl (%rbx,%rbp), %ecx
movl 0x4(%rbp,%r12,8), %r8d
movq 0x10(%rsp), %rdi
leaq 0x8a7(%rip), %rsi       # 0x2371
leaq 0x260f(%rip), %rdx      # 0x40e0
movl %r14d, %r9d
xorl %eax, %eax
callq 0x10e0
movl (%rbx,%rbp), %edi
leaq 0x278b(%rip), %rsi      # 0x4270
movl %r15d, %edx
callq 0x1d3b
cmpq $0x20, %r12
sete %al
testb %al, %al
movq 0x24d3(%rip), %r12      # 0x3fd0
je 0x17f0
movq (%r12), %r15
callq 0x127c
xorl %ebx, %ebx
movq %r15, %rdi
leaq 0x885(%rip), %rsi       # 0x239d
leaq 0x25c1(%rip), %rdx      # 0x40e0
leaq 0x891(%rip), %rcx       # 0x23b7
movl %r14d, %r8d
xorl %eax, %eax
callq 0x10e0
jmp 0x17f2
movq (%r12), %rbx
callq 0x127c
callq 0x1040
movl (%rax), %edi
callq 0x1150
movq %rbx, %rdi
leaq 0x7a2(%rip), %rsi       # 0x22f6
jmp 0x1bcb
xorl %r14d, %r14d
movq (%r12), %rbx
callq 0x127c
movq %rbx, %rdi
leaq 0x7db(%rip), %rsi       # 0x2347
leaq 0x256d(%rip), %rdx      # 0x40e0
xorl %eax, %eax
callq 0x10e0
movl %r14d, %edi
leaq 0x30(%rsp), %rsi
movl $0x15, %edx
callq 0x1110
testl %eax, %eax
js 0x1b9f
movl %r14d, %edi
movl $0x4, %esi
callq 0x10f0
jmp 0x1be2
testl %r14d, %r14d
jle 0x1bac
movl %r14d, %edi
callq 0x10c0
movq (%r12), %rbx
callq 0x127c
callq 0x1040
movl (%rax), %edi
callq 0x1150
movq %rbx, %rdi
leaq 0x792(%rip), %rsi       # 0x235d
leaq 0x250e(%rip), %rdx      # 0x40e0
movq %rax, %rcx
xorl %eax, %eax
callq 0x10e0
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq (%r12), %r15
callq 0x127c
xorl %ebx, %ebx
movq %r15, %rdi
leaq 0x638(%rip), %rsi       # 0x222f
leaq 0x24e2(%rip), %rdx      # 0x40e0
movl %r14d, 0x8(%rsp)
movl %r14d, %ecx
xorl %eax, %eax
callq 0x10e0
jmp 0x17f2
movl $0x7, %ebx
jmp 0x1c37
leaq 0xa0(%rsp), %r15
movl 0x4(%rsp), %r13d
xorl %ebx, %ebx
jmp 0x1c37
leaq 0xa0(%rsp), %r15
movl 0x4(%rsp), %r13d
testl %ebx, %ebx
movl 0x8(%rsp), %edi
je 0x14db
cmpl $0x7, %ebx
jne 0x1c9b
testl %edi, %edi
jle 0x1c51
callq 0x10c0
xorl %ebx, %ebx
movl (%rbx,%rbp), %edi
testl %edi, %edi
jle 0x1c66
callq 0x10c0
movl $0xffffffff, (%rbx,%rbp) # imm = 0xFFFFFFFF
addq $0x8, %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x1c53
movq (%r12), %rbx
callq 0x127c
movq %rbx, %rdi
leaq 0x5bf(%rip), %rsi       # 0x2245
leaq 0x2453(%rip), %rdx      # 0x40e0
leaq 0x52e(%rip), %rcx       # 0x21c2
xorl %eax, %eax
callq 0x10e0
testl %r13d, %r13d
je 0x142f
movl %r13d, %edi
callq 0x10c0
jmp 0x142f
callq 0x1040
movl (%rax), %edi
callq 0x1150
movq %rbx, %rdi
leaq 0x430(%rip), %rsi       # 0x20f7
leaq 0x2412(%rip), %rdx      # 0x40e0
movq %r14, %rcx
movq %rax, %r8
xorl %eax, %eax
callq 0x10e0
movl $0x2, %edi
callq 0x1160
jmp 0x142f
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x3ce(%rip), %r14       # 0x20c4
jmp 0x1d04
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x3d5(%rip), %r14       # 0x20d9
movq 0x22c5(%rip), %rax      # 0x3fd0
movq (%rax), %r15
callq 0x127c
leaq 0x23c6(%rip), %rdx      # 0x40e0
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x10e0
movl %ebx, %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq