// File: /workspace/github_c_makefile_star2_O1/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 0xac79(%rip), %rdi      # 0x22cd4
xorl %esi, %esi
callq 0x5450
testl %eax, %eax
je 0x180ab
movq 0x11f53(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0xac6b(%rip), %rsi      # 0x22ce7
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x12c18(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rbx, %rbx
je 0x1810d
callq 0xeb2f
leaq 0xac3e(%rip), %rsi      # 0x22ce7
jmp 0x18100
leaq 0xac86(%rip), %rdi      # 0x22d38
xorl %esi, %esi
callq 0x5450
testl %eax, %eax
je 0x18121
movq 0x11efc(%rip), %rax     # 0x29fc0
movq (%rax), %rbx
callq 0xeb2f
leaq 0xac7b(%rip), %rsi      # 0x22d4e
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x52c0
leaq 0x12bc1(%rip), %rax     # 0x2aca8
movq (%rax), %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rbx, %rbx
je 0x1810d
callq 0xeb2f
leaq 0xac4e(%rip), %rsi      # 0x22d4e
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 0xac7c(%rip), %rdx      # 0x22daa
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 0x181d3
leaq 0xac89(%rip), %rdx      # 0x22de8
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 0xac89(%rip), %rsi      # 0x22e10
movq %r14, %rdi
callq 0x5470
movq %rax, 0x20d(%rbx)
testq %rax, %rax
je 0x18262
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x5260
movq %r14, %rdi
movl $0x1, %esi
callq 0x5330
leaq 0x13f(%rip), %rdx       # 0x182ff
movq %rsp, %rdi
movq %r14, %rsi
movq %rbx, %rcx
callq 0x53d0
jmp 0x1810d
movq 0x11de6(%rip), %rax     # 0x29fc0
movq (%rax), %r14
callq 0xeb2f
movq %rax, %r15
callq 0x5070
movq %rax, %rbx
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0xabce(%rip), %rsi      # 0x22dcb
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rdx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x12a8c(%rip), %rax     # 0x2aca8
movq (%rax), %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x1810d
callq 0xeb2f
movq %rax, %r15
movl (%rbx), %ebx
movl %ebx, %edi
callq 0x5530
leaq 0xab86(%rip), %rsi      # 0x22dcb
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rdx
movl %ebx, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
jmp 0x1810d
movq 0x11d57(%rip), %rax     # 0x29fc0
movq (%rax), %r12
callq 0xeb2f
movq %rax, %r13
callq 0x5070
movq %rax, %r15
movl (%rax), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0xab3f(%rip), %rsi      # 0x22dcb
movq %r12, %rdi
movq %r13, %rdx
movq %r14, %rcx
movl %ebp, %r8d
movq %rax, %r9
xorl %eax, %eax
callq 0x52c0
leaq 0x129ff(%rip), %rax     # 0x2aca8
movq (%rax), %r12
testq %r12, %r12
je 0x182e0
callq 0xeb2f
movq %rax, %r13
movl (%r15), %ebp
movl %ebp, %edi
callq 0x5530
leaq 0xab01(%rip), %rsi      # 0x22dcb
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 0x1810d