// File: /workspace/github_c_makefile_star2_O0/Carton32[P]quectel-CM/device.c
// Function: detect_path_cdc_wdm_or_qcqmi
static int detect_path_cdc_wdm_or_qcqmi(char *path, char *devname, size_t bufsize)
{
    size_t offset = strlen(path);
    char tmp[32];
    
    devname[0] = 0;

    if (access(path, R_OK))
        return -1;

    path[offset] = '\0';
    strcat(path, "/GobiQMI");
    if (!access(path, R_OK))
        goto step_1;

    path[offset] = '\0';
    strcat(path, "/usbmisc");
    if (!access(path, R_OK))
        goto step_1;

    path[offset] = '\0';
    strcat(path, "/usb");
    if (!access(path, R_OK))
        goto step_1;

    return -1;

step_1: 
    /* get device(qcqmiX|cdc-wdmX) */
    if (debug_qmi) dbg_time("%s", path);
    dir_get_child(path, tmp, sizeof(tmp), NULL);
    if (tmp[0] == '\0')
        return -1;

    /* There is a chance that, no device(qcqmiX|cdc-wdmX) is generated. We should warn user about that! */
    snprintf(devname, bufsize, "/dev/%s", tmp);
    if (access(devname, R_OK | F_OK) && errno == ENOENT)
    {
        int major, minor;

        dbg_time("access %s  failed, errno: %d (%s)", devname, errno, strerror(errno));
        strcat(path, "/");
        strcat(path, tmp);
        strcat(path, "/uevent");
        major = conf_get_val(path, "MAJOR");
        minor = conf_get_val(path, "MINOR");

        if(major == CM_INVALID_VAL || minor == CM_INVALID_VAL)
            dbg_time("get major and minor failed");
         else if (mknod(devname, S_IFCHR|0666, (((major & 0xfff) << 8) | (minor & 0xff) | ((minor & 0xfff00) << 12))))
            dbg_time("please mknod %s c %d %d", devname, major, minor);
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5160
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5460
cmpl $0x0, %eax
je 0x2178a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21b86
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
leaq 0xe960(%rip), %rsi      # 0x30101
callq 0x54d0
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5460
cmpl $0x0, %eax
jne 0x217bb
jmp 0x21829
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
leaq 0xe938(%rip), %rsi      # 0x3010a
callq 0x54d0
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5460
cmpl $0x0, %eax
jne 0x217ec
jmp 0x21829
movq -0x10(%rbp), %rax
movq -0x28(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
leaq 0xe793(%rip), %rsi      # 0x2ff96
callq 0x54d0
movq -0x10(%rbp), %rdi
movl $0x4, %esi
callq 0x5460
cmpl $0x0, %eax
jne 0x2181d
jmp 0x21829
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21b86
leaq 0x15d5c(%rip), %rax     # 0x3758c
cmpl $0x0, (%rax)
je 0x218a0
jmp 0x21837
movq 0x157a2(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x60(%rbp)
callq 0x13930
movq -0x60(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
leaq 0xa852(%rip), %rsi      # 0x2c0ae
movb $0x0, %al
callq 0x52c0
leaq 0x165fe(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x2189c
leaq 0x165f1(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x68(%rbp)
callq 0x13930
movq -0x68(%rbp), %rdi
movq %rax, %rdx
movq -0x10(%rbp), %rcx
leaq 0xa819(%rip), %rsi      # 0x2c0ae
movb $0x0, %al
callq 0x52c0
jmp 0x2189e
jmp 0x218a0
movq -0x10(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0x20, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x21280
movsbl -0x50(%rbp), %eax
cmpl $0x0, %eax
jne 0x218cb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x21b86
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x50(%rbp), %rcx
leaq 0xe267(%rip), %rdx      # 0x2fb45
movb $0x0, %al
callq 0x51c0
movq -0x18(%rbp), %rdi
movl $0x4, %esi
callq 0x5460
cmpl $0x0, %eax
je 0x21b7f
callq 0x5070
cmpl $0x2, (%rax)
jne 0x21b7f
jmp 0x2190c
movq 0x156cd(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x88(%rbp)
callq 0x13930
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x6c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rdx
movq -0x78(%rbp), %rcx
movl -0x6c(%rbp), %r8d
movq %rax, %r9
leaq 0xe7b2(%rip), %rsi      # 0x30113
movb $0x0, %al
callq 0x52c0
leaq 0x164f9(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x219e3
leaq 0x164ec(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xa8(%rbp)
callq 0x13930
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rdx
movq -0x98(%rbp), %rcx
movl -0x8c(%rbp), %r8d
movq %rax, %r9
leaq 0xe737(%rip), %rsi      # 0x30113
movb $0x0, %al
callq 0x52c0
jmp 0x219e5
movq -0x10(%rbp), %rdi
leaq 0xc776(%rip), %rsi      # 0x2e166
callq 0x54d0
movq -0x10(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x54d0
movq -0x10(%rbp), %rdi
leaq 0xe72e(%rip), %rsi      # 0x3013b
callq 0x54d0
movq -0x10(%rbp), %rdi
leaq 0xe726(%rip), %rsi      # 0x30143
callq 0x23060
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xe719(%rip), %rsi      # 0x30149
callq 0x23060
movl %eax, -0x58(%rbp)
cmpl $-0x1, -0x54(%rbp)
je 0x21a44
cmpl $-0x1, -0x58(%rbp)
jne 0x21ab6
jmp 0x21a46
movq 0x15593(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xb0(%rbp)
callq 0x13930
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq 0xe6e2(%rip), %rsi      # 0x3014f
movb $0x0, %al
callq 0x52c0
leaq 0x163ed(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x21aaf
leaq 0x163e0(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
callq 0x13930
movq -0xb8(%rbp), %rdi
movq %rax, %rdx
leaq 0xe6a7(%rip), %rsi      # 0x3014f
movb $0x0, %al
callq 0x52c0
jmp 0x21ab1
jmp 0x21b7d
movq -0x18(%rbp), %rdi
movl -0x54(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
shll $0x8, %eax
movl -0x58(%rbp), %ecx
andl $0xff, %ecx
orl %ecx, %eax
movl -0x58(%rbp), %ecx
andl $0xfff00, %ecx          # imm = 0xFFF00
shll $0xc, %ecx
orl %ecx, %eax
movslq %eax, %rdx
movl $0x21b6, %esi           # imm = 0x21B6
callq 0x52d0
cmpl $0x0, %eax
je 0x21b7b
jmp 0x21af6
movq 0x154e3(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
callq 0x13930
movq -0xc0(%rbp), %rdi
movq %rax, %rdx
movq -0x18(%rbp), %rcx
movl -0x54(%rbp), %r8d
movl -0x58(%rbp), %r9d
leaq 0xe647(%rip), %rsi      # 0x30170
movb $0x0, %al
callq 0x52c0
leaq 0x16331(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x21b77
leaq 0x16324(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
callq 0x13930
movq -0xc8(%rbp), %rdi
movq %rax, %rdx
movq -0x18(%rbp), %rcx
movl -0x54(%rbp), %r8d
movl -0x58(%rbp), %r9d
leaq 0xe600(%rip), %rsi      # 0x30170
movb $0x0, %al
callq 0x52c0
jmp 0x21b79
jmp 0x21b7b
jmp 0x21b7d
jmp 0x21b7f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)