// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/dbg_lin.c
// Function: dbg_enumerate
int dbg_enumerate(debugger_t *debuggers, int size)
{
  struct udev *udev;
  struct udev_enumerate *enumerate;
  struct udev_list_entry *devices, *dev_list_entry;
  int rsize = 0;

  udev = udev_new();
  check(udev, "unable to create udev object");

  enumerate = udev_enumerate_new(udev);
  udev_enumerate_add_match_subsystem(enumerate, "usb");
  udev_enumerate_add_match_property(enumerate, "DEVTYPE", "usb_device");

  udev_enumerate_scan_devices(enumerate);
  devices = udev_enumerate_get_list_entry(enumerate);

  udev_list_entry_foreach(dev_list_entry, devices)
  {
    const char *syspath = udev_list_entry_get_name(dev_list_entry);
    struct udev_device *dev = udev_device_new_from_syspath(udev, syspath);
    const char *path = udev_device_get_devnode(dev);
    uint8_t descriptors[4096];

    int fd = open(path, O_RDWR);

    if (fd < 0)
    {
      udev_device_unref(dev);
      continue;
    }

    int res = read(fd, descriptors, sizeof(descriptors));
    check(res > 0, "descriptors read from %s: %d", path, res);

    parse_descriptors(&debuggers[rsize], fd, descriptors, res);

    if (debuggers[rsize].versions)
    {
      debuggers[rsize].path = strdup(path);
      rsize++;
    }

    close(fd);
    udev_device_unref(dev);

    if (rsize == size)
      break;
  }

  udev_enumerate_unref(enumerate);
  udev_unref(udev);

  return rsize;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1098, %rsp           # imm = 0x1098
movl %esi, 0x8(%rsp)
movq %rdi, 0x78(%rsp)
callq 0x6110
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x5586(%rip), %rsi      # 0x13d00
xorl %eax, %eax
callq 0x793d
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x6150
movq %rax, %r14
leaq 0x5585(%rip), %rsi      # 0x13d1d
movq %rax, %rdi
callq 0x60a0
leaq 0x557a(%rip), %rsi      # 0x13d21
leaq 0x557b(%rip), %rdx      # 0x13d29
movq %r14, %rdi
callq 0x61e0
movq %r14, %rdi
callq 0x6050
movq %r14, 0x30(%rsp)
movq %r14, %rdi
callq 0x6170
movq %rax, %r14
leaq 0x88(%rsp), %rbp
leaq 0x24(%rsp), %r13
xorl %r12d, %r12d
testq %r14, %r14
je 0xeb99
movq %r14, %rdi
callq 0x61f0
movq 0x28(%rsp), %rdi
movq %rax, %rsi
callq 0x6100
movq %rax, %r15
movq %rax, %rdi
callq 0x6080
movq %rax, %rbx
movq %rax, %rdi
pushq $0x2
popq %rsi
xorl %eax, %eax
callq 0x6200
testl %eax, %eax
js 0xeb7c
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movl $0x1000, %edx           # imm = 0x1000
movl %eax, %edi
leaq 0x90(%rsp), %rsi
movl %eax, %r15d
callq 0x6140
movq %rax, %r14
xorl %edi, %edi
testl %r14d, %r14d
setg %dil
leaq 0x54e1(%rip), %rsi      # 0x13d34
movq %rbx, 0x80(%rsp)
movq %rbx, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x793d
movl %r12d, 0x4(%rsp)
movslq %r12d, %rax
movq 0x78(%rsp), %rbx
imulq $0x68, %rax, %r12
leaq 0x90(%rsp), %rax
movq %rax, 0x88(%rsp)
movl %r14d, 0x24(%rsp)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x50(%rbx,%r12)
movdqu %xmm0, 0x40(%rbx,%r12)
movdqu %xmm0, 0x30(%rbx,%r12)
movdqu %xmm0, 0x20(%rbx,%r12)
movdqu %xmm0, 0x10(%rbx,%r12)
movdqu %xmm0, (%rbx,%r12)
andq $0x0, 0x60(%rbx,%r12)
movq %rbp, %rdi
movq %r13, %rsi
pushq $0x1
popq %rdx
pushq $0x12
popq %rcx
callq 0xef43
testq %rax, %rax
movl %r15d, 0xc(%rsp)
je 0xeb53
movq %rax, %r14
addq %rbx, %r12
movzbl 0x10(%rax), %esi
movl %r15d, %edi
callq 0xef6d
movq %rax, 0x10(%r12)
movzbl 0xe(%r14), %esi
movl %r15d, %edi
callq 0xef6d
movq %rax, 0x18(%r12)
movzbl 0xf(%r14), %esi
movl %r15d, %edi
callq 0xef6d
movq %rax, 0x20(%r12)
movd 0x8(%r14), %xmm0
punpcklwd 0x53c7(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1],xmm0[2],mem[2],xmm0[3],mem[3]
movq %xmm0, 0x28(%r12)
leaq 0x60(%r12), %rax
movq %rax, 0x70(%rsp)
leaq 0x64(%r12), %rax
movq %rax, 0x68(%rsp)
leaq 0x5c(%r12), %rax
movq %rax, 0x60(%rsp)
leaq 0x58(%r12), %rax
movq %rax, 0x58(%rsp)
leaq 0x48(%r12), %rax
movq %rax, 0x50(%rsp)
leaq 0x4c(%r12), %rax
movq %rax, 0x48(%rsp)
leaq 0x44(%r12), %rax
movq %rax, 0x40(%rsp)
leaq 0x40(%r12), %rax
movq %rax, 0x38(%rsp)
pushq $0x4
popq %rbx
movq %rbp, %rdi
movq %r13, %rsi
movl %ebx, %edx
pushq $0x9
popq %rcx
callq 0xef43
testq %rax, %rax
je 0xeb30
movq %rax, %r14
cmpb $0x2, 0x4(%rax)
jne 0xe983
cmpb $0x0, 0x6(%r14)
jne 0xe983
cmpb $0x0, 0x7(%r14)
jne 0xe983
movzbl 0x5(%r14), %eax
cmpl $0xff, %eax
je 0xe9c4
cmpl $0x3, %eax
jne 0xe983
movq 0x20(%r12), %rdi
callq 0xf051
testb %al, %al
jne 0xe9ec
movzbl 0x8(%r14), %esi
movl 0xc(%rsp), %edi
callq 0xef6d
movq %rax, %rdi
callq 0xf051
testb %al, %al
je 0xe983
movq %rbp, %rdi
movq %r13, %rsi
movq %r13, %rbx
movq %rbp, %r13
pushq $0x5
popq %rbp
movl %ebp, %edx
pushq $0x7
popq %rcx
callq 0xef43
movq %rax, %r15
movq %r13, %rdi
movq %rbx, %rsi
movl %ebp, %edx
movq %r13, %rbp
movq %rbx, %r13
pushq $0x4
popq %rbx
pushq $0x7
popq %rcx
callq 0xef43
testq %r15, %r15
je 0xeb30
testq %rax, %rax
je 0xeb30
movzwl 0x4(%r15), %ecx
cmpw 0x4(%rax), %cx
jne 0xe983
cmpl $0x40, %ecx
je 0xea5b
cmpl $0x400, %ecx            # imm = 0x400
je 0xea5b
cmpl $0x200, %ecx            # imm = 0x200
jne 0xe983
movb 0x2(%r15), %dl
movb 0x2(%rax), %sil
movl %esi, %edi
xorb %dl, %dil
jns 0xe983
movzbl 0x5(%r14), %edi
cmpl $0xff, %edi
je 0xeacd
cmpl $0x3, %edi
jne 0xe983
movb 0x3(%r15), %dil
notb %dil
testb $0x3, %dil
jne 0xe983
movb 0x3(%rax), %al
notb %al
testb $0x3, %al
jne 0xe983
testb %dl, %dl
movzbl %sil, %eax
movzbl %dl, %esi
movl %eax, %edx
cmovnsl %esi, %edx
cmovnsl %eax, %esi
movq 0x50(%rsp), %rax
movq 0x48(%rsp), %rdi
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r9
pushq $0x2
popq %r10
jmp 0xeb10
movb 0x3(%r15), %dil
andb $0x3, %dil
cmpb $0x2, %dil
jne 0xe983
testb %dl, %dl
js 0xe983
movb 0x3(%rax), %r11b
andb $0x3, %r11b
movq 0x70(%rsp), %rax
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %r8
movq 0x58(%rsp), %r9
movl %ebx, %r10d
cmpb $0x2, %r11b
jne 0xe983
movzbl %dl, %edx
movl %edx, (%rax)
movzbl %sil, %eax
movl %eax, (%rdi)
movl %ecx, (%r8)
movzbl 0x2(%r14), %eax
movl %eax, (%r9)
orl %r10d, 0x30(%r12)
jmp 0xe983
cmpl $0x0, 0x30(%r12)
je 0xeb53
movq 0x80(%rsp), %rdi
callq 0x6290
movq %rax, (%r12)
movl 0x4(%rsp), %r12d
incl %r12d
jmp 0xeb58
movl 0x4(%rsp), %r12d
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r15
movl 0xc(%rsp), %edi
callq 0x6120
movq %r15, %rdi
callq 0x6260
cmpl 0x8(%rsp), %r12d
jne 0xeb84
jmp 0xeb94
movq %r15, %rdi
callq 0x6260
movq %r14, %rdi
callq 0x6210
movq %rax, %r14
jmp 0xe7de
movl 0x8(%rsp), %r12d
movq 0x30(%rsp), %rdi
callq 0x6070
movq 0x28(%rsp), %rdi
callq 0x61a0
movl %r12d, %eax
addq $0x1098, %rsp           # imm = 0x1098
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq