// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
leaq 0x1c9d(%rip), %rax      # 0x3024
movq %rax, -0x20(%rbp)
leaq 0x1c97(%rip), %rax      # 0x3029
movq %rax, -0x28(%rbp)
leaq -0x90(%rbp), %rdi
leaq 0x39dc(%rip), %rsi      # 0x4d80
movl $0x60, %edx
callq 0x1100
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x90(%rbp), %rcx
leaq -0x14(%rbp), %r8
callq 0x1090
movl %eax, -0x18(%rbp)
cmpl $-0x1, %eax
je 0x1502
movl -0x18(%rbp), %eax
movl %eax, -0x98(%rbp)
subl $0x64, %eax
je 0x1412
jmp 0x13e5
movl -0x98(%rbp), %eax
subl $0x68, %eax
je 0x1425
jmp 0x13f2
movl -0x98(%rbp), %eax
subl $0x76, %eax
jne 0x14c1
jmp 0x1403
movl $0x1, 0x3d63(%rip)      # 0x5170
jmp 0x14fd
movq 0x3bbf(%rip), %rax      # 0x4fd8
movq (%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x14fd
jmp 0x1427
movq 0x3ba2(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
callq 0x12a0
movq -0xa0(%rbp), %rdi
movq %rax, %rdx
leaq 0x1bf8(%rip), %rsi      # 0x3046
movb $0x0, %al
callq 0x10f0
jmp 0x1457
movq 0x3b72(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
callq 0x12a0
movq -0xa8(%rbp), %rdi
movq %rax, %rdx
leaq 0x1bee(%rip), %rsi      # 0x306c
movb $0x0, %al
callq 0x10f0
jmp 0x1487
movq 0x3b42(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x12a0
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq 0x1bda(%rip), %rsi      # 0x3088
movb $0x0, %al
callq 0x10f0
movl $0x0, -0x4(%rbp)
jmp 0x165a
jmp 0x14c3
movq 0x3b06(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
callq 0x12a0
movq -0xb8(%rbp), %rdi
movq %rax, %rdx
leaq 0x1bbe(%rip), %rsi      # 0x30a8
movb $0x0, %al
callq 0x10f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x165a
jmp 0x13ae
cmpq $0x0, -0x28(%rbp)
jne 0x1545
jmp 0x150b
movq 0x3abe(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
callq 0x12a0
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
leaq 0x1b8b(%rip), %rsi      # 0x30bd
movb $0x0, %al
callq 0x10f0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x165a
jmp 0x1547
movq -0x28(%rbp), %rdi
movl $0x902, %esi            # imm = 0x902
movb $0x0, %al
callq 0x1140
movl %eax, -0x94(%rbp)
cmpl $0x0, -0x94(%rbp)
jge 0x15d1
jmp 0x1568
movq 0x3a61(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0xd8(%rbp)
callq 0x12a0
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xc8(%rbp)
callq 0x1040
movl (%rax), %edi
callq 0x1170
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rdx
movq -0xc8(%rbp), %rcx
movq %rax, %r8
leaq 0x1b20(%rip), %rsi      # 0x30db
movb $0x0, %al
callq 0x10f0
movl $0x2, %edi
callq 0x1180
jmp 0x1547
jmp 0x15d3
movq 0x39f6(%rip), %rax      # 0x4fd0
movq (%rax), %rax
movq %rax, -0xe0(%rbp)
callq 0x12a0
movq -0xe0(%rbp), %rdi
movq %rax, %rdx
movl -0x94(%rbp), %ecx
leaq 0x1afe(%rip), %rsi      # 0x30fe
movb $0x0, %al
callq 0x10f0
leaq 0x3b72(%rip), %rdi      # 0x5180
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x10c0
movl -0x94(%rbp), %edi
movl $0x1000, %esi           # imm = 0x1000
callq 0x1670
movl -0x94(%rbp), %edi
callq 0x1720
cmpl $0x0, -0x94(%rbp)
jle 0x1653
movl -0x94(%rbp), %edi
callq 0x10d0
movl $0xffffffff, -0x94(%rbp) # imm = 0xFFFFFFFF
jmp 0x1655
jmp 0x1547
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)