// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0xd637(%rip), %rdi      # 0x2ff21
xorl %esi, %esi
callq 0x5460
cmpl $0x0, %eax
je 0x2296f
jmp 0x228f8
movq 0x146e1(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x168(%rbp)
callq 0x13930
movq -0x168(%rbp), %rdi
movq %rax, %rdx
leaq 0xd615(%rip), %rsi      # 0x2ff34
movb $0x0, %al
callq 0x52c0
leaq 0x1553b(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x22961
leaq 0x1552e(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x170(%rbp)
callq 0x13930
movq -0x170(%rbp), %rdi
movq %rax, %rdx
leaq 0xd5da(%rip), %rsi      # 0x2ff34
movb $0x0, %al
callq 0x52c0
jmp 0x22963
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x22d01
leaq 0xd60f(%rip), %rdi      # 0x2ff85
xorl %esi, %esi
callq 0x5460
cmpl $0x0, %eax
je 0x229fb
jmp 0x22984
movq 0x14655(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x178(%rbp)
callq 0x13930
movq -0x178(%rbp), %rdi
movq %rax, %rdx
leaq 0xd5f0(%rip), %rsi      # 0x2ff9b
movb $0x0, %al
callq 0x52c0
leaq 0x154af(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x229ed
leaq 0x154a2(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x180(%rbp)
callq 0x13930
movq -0x180(%rbp), %rdi
movq %rax, %rdx
leaq 0xd5b5(%rip), %rsi      # 0x2ff9b
movb $0x0, %al
callq 0x52c0
jmp 0x229ef
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x22d01
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x1cd(%rax), %ecx
movl $0x100, %esi            # imm = 0x100
leaq 0xd5df(%rip), %rdx      # 0x2fff7
movb $0x0, %al
callq 0x51c0
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x5450
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x209(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x209(%rax)
jge 0x22b4b
jmp 0x22a4e
movq 0x1458b(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
callq 0x13930
movq %rax, -0x198(%rbp)
leaq -0x120(%rbp), %rax
movq %rax, -0x190(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x184(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x1a0(%rbp), %rdi
movq -0x198(%rbp), %rdx
movq -0x190(%rbp), %rcx
movl -0x184(%rbp), %r8d
movq %rax, %r9
leaq 0xd560(%rip), %rsi      # 0x30018
movb $0x0, %al
callq 0x52c0
leaq 0x153a2(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x22b3d
leaq 0x15395(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x1c0(%rbp)
callq 0x13930
movq %rax, -0x1b8(%rbp)
leaq -0x120(%rbp), %rax
movq %rax, -0x1b0(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x1a4(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x1c0(%rbp), %rdi
movq -0x1b8(%rbp), %rdx
movq -0x1b0(%rbp), %rcx
movl -0x1a4(%rbp), %r8d
movq %rax, %r9
leaq 0xd4e2(%rip), %rsi      # 0x30018
movb $0x0, %al
callq 0x52c0
jmp 0x22b3f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x22d01
leaq -0x120(%rbp), %rdi
movq -0x18(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
leaq 0xd4d3(%rip), %rdx      # 0x30035
movb $0x0, %al
callq 0x51c0
leaq -0x120(%rbp), %rdi
callq 0x5170
cmpl $-0x1, %eax
jne 0x22b7c
jmp 0x22b7c
movq -0x18(%rbp), %rdi
leaq 0xd4d6(%rip), %rsi      # 0x3005d
callq 0x5480
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20d(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20d(%rax)
jne 0x22cbf
jmp 0x22bae
movq 0x1442b(%rip), %rax     # 0x36fe0
movq (%rax), %rax
movq %rax, -0x1e0(%rbp)
callq 0x13930
movq %rax, -0x1d8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1d0(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x1c4(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x1e0(%rbp), %rdi
movq -0x1d8(%rbp), %rdx
movq -0x1d0(%rbp), %rcx
movl -0x1c4(%rbp), %r8d
movq %rax, %r9
leaq 0xd403(%rip), %rsi      # 0x30018
movb $0x0, %al
callq 0x52c0
leaq 0x15245(%rip), %rax     # 0x37e68
cmpq $0x0, (%rax)
je 0x22c97
leaq 0x15238(%rip), %rax     # 0x37e68
movq (%rax), %rax
movq %rax, -0x200(%rbp)
callq 0x13930
movq %rax, -0x1f8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1f0(%rbp)
callq 0x5070
movl (%rax), %eax
movl %eax, -0x1e4(%rbp)
callq 0x5070
movl (%rax), %edi
callq 0x5540
movq -0x200(%rbp), %rdi
movq -0x1f8(%rbp), %rdx
movq -0x1f0(%rbp), %rcx
movl -0x1e4(%rbp), %r8d
movq %rax, %r9
leaq 0xd388(%rip), %rsi      # 0x30018
movb $0x0, %al
callq 0x52c0
jmp 0x22c99
movq -0x10(%rbp), %rax
movl 0x209(%rax), %edi
callq 0x5230
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x209(%rax) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x22d01
leaq -0x160(%rbp), %rdi
callq 0x5260
leaq -0x160(%rbp), %rdi
movl $0x1, %esi
callq 0x5330
movq -0x10(%rbp), %rcx
leaq -0x128(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq 0x1b(%rip), %rdx        # 0x22d10
callq 0x53e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
nopl (%rax)