// File: /workspace/github_c_makefile_star2_O1/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 $0x1048, %rsp           # imm = 0x1048
movl %esi, 0x14(%rsp)
movq %rdi, 0x30(%rsp)
callq 0x6110
movq %rax, %rbx
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x4de7(%rip), %rsi      # 0x13cf1
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x7bb4
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0x6150
movq %rax, %rbx
leaq 0x4de3(%rip), %rsi      # 0x13d0e
movq %rax, %rdi
callq 0x60a0
leaq 0x4dd8(%rip), %rsi      # 0x13d12
leaq 0x4dd9(%rip), %rdx      # 0x13d1a
movq %rbx, %rdi
callq 0x61e0
movq %rbx, %rdi
callq 0x6050
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x6160
testq %rax, %rax
je 0xf30b
movq %rax, %r13
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x61f0
movq 0x18(%rsp), %rdi
movq %rax, %rsi
callq 0x6100
movq %rax, %rbx
movq %rax, %rdi
callq 0x6080
movq %rax, %r12
movq %rax, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x6200
testl %eax, %eax
js 0xf042
movl %eax, %ebp
movq %rbx, 0x20(%rsp)
movl $0x1000, %edx           # imm = 0x1000
movl %eax, %edi
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
callq 0x6140
movq %rax, %r15
xorl %edi, %edi
testl %r15d, %r15d
setg %dil
leaq 0x4d50(%rip), %rsi      # 0x13d25
movq %r12, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x7bb4
movl %r14d, 0x10(%rsp)
movslq %r14d, %rax
imulq $0x68, %rax, %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax), %r11
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%rcx,%rax)
movups %xmm0, 0x40(%rcx,%rax)
movups %xmm0, 0x30(%rcx,%rax)
movups %xmm0, 0x20(%rcx,%rax)
movups %xmm0, 0x10(%rcx,%rax)
movups %xmm0, (%rcx,%rax)
movq $0x0, 0x60(%rcx,%rax)
movq %rbx, %rax
cmpl $0x12, %r15d
jl 0xf051
movzbl (%rax), %ecx
subl %ecx, %r15d
cmpb $0x1, 0x1(%rax)
leaq (%rcx,%rax), %rbx
cmoveq %rax, %r14
movq %rbx, %rax
jne 0xf023
jmp 0xf057
movq %rbx, %rdi
callq 0x6260
xorl %eax, %eax
jmp 0xf2f3
movq %rax, %rbx
xorl %r14d, %r14d
movq %r12, 0x38(%rsp)
testq %r14, %r14
je 0xf2b1
movzbl 0x10(%r14), %esi
movl %ebp, %edi
movq %r11, 0x8(%rsp)
callq 0xf6b5
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rcx)
movzbl 0xe(%r14), %esi
movl %ebp, %edi
callq 0xf6b5
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rcx)
movzbl 0xf(%r14), %esi
movl %ebp, %edi
callq 0xf6b5
movq 0x8(%rsp), %r11
movq %rax, 0x20(%r11)
movzwl 0x8(%r14), %eax
movl %eax, 0x28(%r11)
movzwl 0xa(%r14), %eax
movl %eax, 0x2c(%r11)
cmpl $0x9, %r15d
jge 0xf0c6
xorl %r12d, %r12d
jmp 0xf0da
movzbl (%rbx), %eax
subl %eax, %r15d
cmpb $0x4, 0x1(%rbx)
cmoveq %rbx, %r12
leaq (%rax,%rbx), %rbx
jne 0xf0bb
movb $0x1, %r14b
testq %r12, %r12
je 0xf0fd
cmpb $0x2, 0x4(%r12)
jne 0xf0fa
cmpb $0x0, 0x6(%r12)
jne 0xf0fa
cmpb $0x0, 0x7(%r12)
je 0xf107
xorl %r14d, %r14d
testb %r14b, %r14b
je 0xf0bb
jmp 0xf2b1
movzbl 0x5(%r12), %eax
cmpl $0xff, %eax
je 0xf119
cmpl $0x3, %eax
jne 0xf0fa
movq 0x20(%r11), %rdi
leaq 0x4db3(%rip), %rsi      # 0x13ed7
callq 0x62c0
testq %rax, %rax
jne 0xf153
movzbl 0x8(%r12), %esi
movl %ebp, %edi
callq 0xf6b5
movq %rax, %rdi
leaq 0x4d92(%rip), %rsi      # 0x13ed7
callq 0x62c0
testq %rax, %rax
je 0xf2a4
movq 0x8(%rsp), %r11
cmpl $0x7, %r15d
jl 0xf177
movzbl (%rbx), %ecx
subl %ecx, %r15d
cmpb $0x5, 0x1(%rbx)
leaq (%rcx,%rbx), %rdx
cmoveq %rbx, %rax
movq %rdx, %rbx
jne 0xf158
jmp 0xf17c
movq %rbx, %rdx
xorl %eax, %eax
cmpl $0x7, %r15d
jl 0xf19b
movzbl (%rdx), %esi
subl %esi, %r15d
cmpb $0x5, 0x1(%rdx)
leaq (%rsi,%rdx), %rbx
cmoveq %rdx, %rcx
movq %rbx, %rdx
jne 0xf17c
jmp 0xf1a0
movq %rdx, %rbx
xorl %ecx, %ecx
testq %rax, %rax
je 0xf0fd
testq %rcx, %rcx
je 0xf0fd
movzwl 0x4(%rax), %edx
cmpw 0x4(%rcx), %dx
jne 0xf0fa
cmpl $0x40, %edx
je 0xf1d9
cmpl $0x400, %edx            # imm = 0x400
je 0xf1d9
cmpl $0x200, %edx            # imm = 0x200
jne 0xf0fa
movzbl 0x2(%rax), %esi
movzbl 0x2(%rcx), %edi
movl %edi, %r8d
xorb %sil, %r8b
jns 0xf0fa
movzbl 0x5(%r12), %r8d
cmpl $0xff, %r8d
je 0xf25e
cmpl $0x3, %r8d
jne 0xf0fa
movb 0x3(%rax), %r9b
notb %r9b
testb $0x3, %r9b
jne 0xf0fa
movb 0x3(%rcx), %r9b
notb %r9b
testb $0x3, %r9b
jne 0xf0fa
testb %sil, %sil
movl %edi, %r9d
cmovnsl %esi, %r9d
movl %esi, %r10d
cmovnsl %edi, %r10d
movl %r9d, 0x48(%r11)
movl %r10d, 0x4c(%r11)
movl %edx, 0x44(%r11)
movzbl 0x2(%r12), %r9d
movl %r9d, 0x40(%r11)
orb $0x2, 0x30(%r11)
cmpb $-0x1, %r8b
jne 0xf0fa
movb 0x3(%rax), %al
andb $0x3, %al
cmpb $0x2, %al
jne 0xf0fa
xorl %r14d, %r14d
testb %sil, %sil
js 0xf0fd
movb 0x3(%rcx), %al
andb $0x3, %al
cmpb $0x2, %al
jne 0xf0fd
movl %esi, 0x60(%r11)
movl %edi, 0x64(%r11)
movl %edx, 0x5c(%r11)
movzbl 0x2(%r12), %eax
movl %eax, 0x58(%r11)
orb $0x4, 0x30(%r11)
jmp 0xf0fa
xorl %r14d, %r14d
movq 0x8(%rsp), %r11
jmp 0xf0fd
cmpl $0x0, 0x30(%r11)
je 0xf2d2
movq 0x38(%rsp), %rdi
movq %r11, %rbx
callq 0x6290
movq %rax, (%rbx)
movl 0x10(%rsp), %r14d
incl %r14d
jmp 0xf2d7
movl 0x10(%rsp), %r14d
movq 0x20(%rsp), %rbx
movl %ebp, %edi
callq 0x6120
movq %rbx, %rdi
callq 0x6260
cmpl 0x14(%rsp), %r14d
sete %al
testb %al, %al
jne 0xf30b
movq %r13, %rdi
callq 0x6210
movq %rax, %r13
testq %rax, %rax
jne 0xef6d
movq 0x28(%rsp), %rdi
callq 0x6070
movq 0x18(%rsp), %rdi
callq 0x6190
movl %r14d, %eax
addq $0x1048, %rsp           # imm = 0x1048
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq