// File: /workspace/github_c_makefile_star2_O2/Carton32[P]quectel-CM/device.c
// Function: ql_capture_usbmon_log
int ql_capture_usbmon_log(PROFILE_T *profile, const char *log_path)
{
    char usbmon_path[256];
    pthread_t pt;
    pthread_attr_t attr;

    if (access("/sys/module/usbmon", F_OK)) {
        dbg_time("usbmon is not load, please execute \"modprobe usbmon\" or \"insmod usbmon.ko\"");
        return -1;
    }

    if (access("/sys/kernel/debug/usb", F_OK)) {
        dbg_time("debugfs is not mount, please execute \"mount -t debugfs none_debugs /sys/kernel/debug\"");
        return -1;
    }

    snprintf(usbmon_path, sizeof(usbmon_path), "/sys/kernel/debug/usb/usbmon/%du", profile->usb_dev.busnum);
    profile->usbmon_fd = open(usbmon_path, O_RDONLY);
    if (profile->usbmon_fd < 0) {
        dbg_time("open %s error(%d) (%s)", usbmon_path, errno, strerror(errno));
        return -1;
    }

    snprintf(usbmon_path, sizeof(usbmon_path), "cat /sys/kernel/debug/usb/devices >> %s", log_path);
    if (system(usbmon_path) == -1) {};

    profile->usbmon_logfile_fp = fopen(log_path, "wb");
    if (!profile->usbmon_logfile_fp) {
      dbg_time("open %s error(%d) (%s)", log_path, errno, strerror(errno));
      close(profile->usbmon_fd);
      profile->usbmon_fd = -1;
      return -1;
    }

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    pthread_create(&pt, &attr, catch_log, (void *)profile);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x9fd2(%rip), %rdi      # 0x20d14
xorl %esi, %esi
callq 0x5460
testl %eax, %eax
je 0x16d90
movq 0x12264(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x9fc4(%rip), %rsi      # 0x20d27
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x12f31(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
pushq $-0x1
popq %rbp
testq %rbx, %rbx
je 0x16df0
callq 0xe343
leaq 0x9f99(%rip), %rsi      # 0x20d27
jmp 0x16de3
leaq 0x9fe1(%rip), %rdi      # 0x20d78
xorl %esi, %esi
callq 0x5460
testl %eax, %eax
je 0x16e04
movq 0x1220f(%rip), %rax     # 0x28fb8
movq (%rax), %rbx
callq 0xe343
leaq 0x9fd6(%rip), %rsi      # 0x20d8e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x12edc(%rip), %rax     # 0x29ca8
movq (%rax), %rbx
pushq $-0x1
popq %rbp
testq %rbx, %rbx
je 0x16df0
callq 0xe343
leaq 0x9fab(%rip), %rsi      # 0x20d8e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x1cd(%rbx), %ecx
leaq 0x9fd9(%rip), %rdx      # 0x20dea
leaq 0x40(%rsp), %r15
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
xorl %eax, %eax
callq 0x51c0
movq %r15, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x5450
movl %eax, 0x209(%rbx)
testl %eax, %eax
js 0x16eb4
leaq 0x9fe6(%rip), %rdx      # 0x20e28
xorl %ebp, %ebp
leaq 0x40(%rsp), %r15
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x51c0
movq %r15, %rdi
callq 0x5170
leaq 0x9fe6(%rip), %rsi      # 0x20e50
movq %r14, %rdi
callq 0x5480
movq %rax, 0x20d(%rbx)
testq %rax, %rax
je 0x16f41
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x5260
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5330
leaq 0x138(%rip), %rdx       # 0x16fd9
movq %rsp, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x53e0
jmp 0x16df0
movq 0x120fd(%rip), %rax     # 0x28fb8
movq (%rax), %r14
callq 0xe343
movq %rax, %r15
callq 0x5070
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0x9f2d(%rip), %rsi      # 0x20e0b
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rdx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x12dab(%rip), %rax     # 0x29ca8
movq (%rax), %r14
pushq $-0x1
popq %rbp
testq %r14, %r14
je 0x16df0
callq 0xe343
movq %rax, %r15
movl (%rbx), %ebx
movl %ebx, %edi
callq 0x5540
leaq 0x9ee7(%rip), %rsi      # 0x20e0b
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rdx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
jmp 0x16df0
movq 0x12070(%rip), %rax     # 0x28fb8
movq (%rax), %r12
callq 0xe343
movq %rax, %r13
callq 0x5070
movq %rax, %r15
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0x9ea0(%rip), %rsi      # 0x20e0b
movq %r12, %rdi
movq %r13, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x12d20(%rip), %rax     # 0x29ca8
movq (%rax), %r12
testq %r12, %r12
je 0x16fbf
callq 0xe343
movq %rax, %r13
movl (%r15), %ebp
movl %ebp, %edi
callq 0x5540
leaq 0x9e62(%rip), %rsi      # 0x20e0b
movq %r12, %rdi
movq %r13, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
movl 0x209(%rbx), %edi
callq 0x5230
orl $-0x1, 0x209(%rbx)
pushq $-0x1
popq %rbp
jmp 0x16df0