// File: /workspace/github_c_makefile_star2_O3/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 0xaecb(%rip), %rdi      # 0x22cf4
xorl %esi, %esi
callq 0x5450
testl %eax, %eax
je 0x17e79
movq 0x12185(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0xaebd(%rip), %rsi      # 0x22d07
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x12e4a(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rbx, %rbx
je 0x17edb
callq 0xea3b
leaq 0xae90(%rip), %rsi      # 0x22d07
jmp 0x17ece
leaq 0xaed8(%rip), %rdi      # 0x22d58
xorl %esi, %esi
callq 0x5450
testl %eax, %eax
je 0x17eef
movq 0x1212e(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xea3b
leaq 0xaecd(%rip), %rsi      # 0x22d6e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x12df3(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rbx, %rbx
je 0x17edb
callq 0xea3b
leaq 0xaea0(%rip), %rsi      # 0x22d6e
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 0xaece(%rip), %rdx      # 0x22dca
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 0x5440
movl %eax, 0x209(%rbx)
testl %eax, %eax
js 0x17fa1
leaq 0xaedb(%rip), %rdx      # 0x22e08
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 0xaedb(%rip), %rsi      # 0x22e30
movq %r14, %rdi
callq 0x5470
movq %rax, 0x20d(%rbx)
testq %rax, %rax
je 0x18030
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x5260
movq %r14, %rdi
movl $0x1, %esi
callq 0x5330
leaq 0x13f(%rip), %rdx       # 0x180cd
movq %rsp, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x53d0
jmp 0x17edb
movq 0x12018(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xea3b
movq %rax, %r15
callq 0x5070
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0xae20(%rip), %rsi      # 0x22deb
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rdx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x12cbe(%rip), %rax     # 0x2aca8
movq (%rax), %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x17edb
callq 0xea3b
movq %rax, %r15
movl (%rbx), %ebx
movl %ebx, %edi
callq 0x5530
leaq 0xadd8(%rip), %rsi      # 0x22deb
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rdx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
jmp 0x17edb
movq 0x11f89(%rip), %rax     # 0x29fc0
movq (%rax), %r12
callq 0xea3b
movq %rax, %r13
callq 0x5070
movq %rax, %r15
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0xad91(%rip), %rsi      # 0x22deb
movq %r12, %rdi
movq %r13, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x12c31(%rip), %rax     # 0x2aca8
movq (%rax), %r12
testq %r12, %r12
je 0x180ae
callq 0xea3b
movq %rax, %r13
movl (%r15), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0xad53(%rip), %rsi      # 0x22deb
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
movl $0xffffffff, 0x209(%rbx) # imm = 0xFFFFFFFF
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x17edb