// File: /workspace/github_c_makefile_star2_O0/ataradov[P]edbg/dbg_lin.c
// Function: dbg_dap_cmd
int dbg_dap_cmd(uint8_t *data, int resp_size, int req_size)
{
  uint8_t cmd = data[0];
  struct usbdevfs_urb urb = { 0 };
  struct usbdevfs_urb *purb = NULL;
  uint8_t buf[DBG_MAX_EP_SIZE];
  int res;

  memset(buf, 0xff, sizeof(buf));
  memcpy(buf, data, req_size);

  // TX
  urb.endpoint      = g_debugger->use_v2 ? g_debugger->v2_tx_ep : g_debugger->v1_tx_ep;
  urb.type          = g_debugger->use_v2 ? USBDEVFS_URB_TYPE_BULK : USBDEVFS_URB_TYPE_INTERRUPT;
  urb.buffer        = buf;
  urb.buffer_length = g_debugger->use_v2 ? req_size : g_debugger->v1_ep_size;

  res = ioctl(g_debugger_fd, USBDEVFS_SUBMITURB, &urb);
  check(res >= 0, "ioctl(SUBMITURB) for TX: %d", res);

  res = ioctl(g_debugger_fd, USBDEVFS_REAPURB, &purb);
  check(res >= 0, "ioctl(REAPURB) for TX: %d", res);
  check(urb.actual_length == urb.buffer_length, "incomplete buffer TX: request = %d, actual = %d",
      urb.buffer_length, urb.actual_length);

  // RX
  urb.endpoint      = g_debugger->use_v2 ? g_debugger->v2_rx_ep : g_debugger->v1_rx_ep;
  urb.type          = g_debugger->use_v2 ? USBDEVFS_URB_TYPE_BULK : USBDEVFS_URB_TYPE_INTERRUPT;
  urb.buffer        = buf;
  urb.buffer_length = g_debugger->use_v2 ? g_debugger->v2_ep_size : g_debugger->v1_ep_size;

  res = ioctl(g_debugger_fd, USBDEVFS_SUBMITURB, &urb);
  check(res >= 0, "ioctl(SUBMITURB) for RX: %d", res);

  res = ioctl(g_debugger_fd, USBDEVFS_REAPURB, &purb);
  check(res >= 0, "ioctl(REAPURB) for RX: %d", res);

  // Result
  check(urb.actual_length, "empty response received");

  if (buf[0] != cmd)
    error_exit("invalid response received: request = 0x%02x, response = 0x%02x", cmd, buf[0]);

  memcpy(data, &buf[1], (resp_size < (urb.actual_length - 1)) ? resp_size : (urb.actual_length - 1));

  return urb.actual_length - 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movb (%rax), %al
movb %al, -0x11(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x60f0
movq $0x0, -0x58(%rbp)
leaq -0x460(%rbp), %rdi
movl $0xff, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x60f0
leaq -0x460(%rbp), %rdi
movq -0x8(%rbp), %rsi
movslq -0x10(%rbp), %rdx
callq 0x61a0
movq 0x6f4f1(%rip), %rax     # 0x82628
testb $0x1, 0x34(%rax)
je 0x1314f
movq 0x6f4e4(%rip), %rax     # 0x82628
movl 0x60(%rax), %eax
movl %eax, -0x468(%rbp)
jmp 0x1315f
movq 0x6f4d2(%rip), %rax     # 0x82628
movl 0x48(%rax), %eax
movl %eax, -0x468(%rbp)
movl -0x468(%rbp), %eax
movb %al, -0x4f(%rbp)
movq 0x6f4b9(%rip), %rax     # 0x82628
movb 0x34(%rax), %dl
movl $0x1, %eax
movl $0x3, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x50(%rbp)
leaq -0x460(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x6f491(%rip), %rax     # 0x82628
testb $0x1, 0x34(%rax)
je 0x131a8
movl -0x10(%rbp), %eax
movl %eax, -0x46c(%rbp)
jmp 0x131b8
movq 0x6f479(%rip), %rax     # 0x82628
movl 0x44(%rax), %eax
movl %eax, -0x46c(%rbp)
movl -0x46c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl 0xc6c9(%rip), %edi      # 0x1f890
movl $0x8038550a, %esi       # imm = 0x8038550A
leaq -0x50(%rbp), %rdx
movb $0x0, %al
callq 0x6100
movl %eax, -0x464(%rbp)
cmpl $0x0, -0x464(%rbp)
setge %al
movl -0x464(%rbp), %edx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4bfd(%rip), %rsi      # 0x17df7
xorl %eax, %eax
callq 0x8880
movl 0xc689(%rip), %edi      # 0x1f890
movl $0x4008550c, %esi       # imm = 0x4008550C
leaq -0x58(%rbp), %rdx
movb $0x0, %al
callq 0x6100
movl %eax, -0x464(%rbp)
cmpl $0x0, -0x464(%rbp)
setge %al
movl -0x464(%rbp), %edx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4bd9(%rip), %rsi      # 0x17e13
xorl %eax, %eax
callq 0x8880
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
sete %al
movl -0x38(%rbp), %edx
movl -0x34(%rbp), %ecx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4bd0(%rip), %rsi      # 0x17e2d
xorl %eax, %eax
callq 0x8880
movq 0x6f3bd(%rip), %rax     # 0x82628
testb $0x1, 0x34(%rax)
je 0x13283
movq 0x6f3b0(%rip), %rax     # 0x82628
movl 0x64(%rax), %eax
movl %eax, -0x470(%rbp)
jmp 0x13293
movq 0x6f39e(%rip), %rax     # 0x82628
movl 0x4c(%rax), %eax
movl %eax, -0x470(%rbp)
movl -0x470(%rbp), %eax
movb %al, -0x4f(%rbp)
movq 0x6f385(%rip), %rax     # 0x82628
movb 0x34(%rax), %dl
movl $0x1, %eax
movl $0x3, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x50(%rbp)
leaq -0x460(%rbp), %rax
movq %rax, -0x40(%rbp)
movq 0x6f35d(%rip), %rax     # 0x82628
testb $0x1, 0x34(%rax)
je 0x132e3
movq 0x6f350(%rip), %rax     # 0x82628
movl 0x5c(%rax), %eax
movl %eax, -0x474(%rbp)
jmp 0x132f3
movq 0x6f33e(%rip), %rax     # 0x82628
movl 0x44(%rax), %eax
movl %eax, -0x474(%rbp)
movl -0x474(%rbp), %eax
movl %eax, -0x38(%rbp)
movl 0xc58e(%rip), %edi      # 0x1f890
movl $0x8038550a, %esi       # imm = 0x8038550A
leaq -0x50(%rbp), %rdx
movb $0x0, %al
callq 0x6100
movl %eax, -0x464(%rbp)
cmpl $0x0, -0x464(%rbp)
setge %al
movl -0x464(%rbp), %edx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4b28(%rip), %rsi      # 0x17e5d
xorl %eax, %eax
callq 0x8880
movl 0xc54e(%rip), %edi      # 0x1f890
movl $0x4008550c, %esi       # imm = 0x4008550C
leaq -0x58(%rbp), %rdx
movb $0x0, %al
callq 0x6100
movl %eax, -0x464(%rbp)
cmpl $0x0, -0x464(%rbp)
setge %al
movl -0x464(%rbp), %edx
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4b04(%rip), %rsi      # 0x17e79
xorl %eax, %eax
callq 0x8880
cmpl $0x0, -0x34(%rbp)
setne %al
movzbl %al, %edi
andl $0x1, %edi
leaq 0x4b03(%rip), %rsi      # 0x17e93
xorl %eax, %eax
callq 0x8880
movzbl -0x460(%rbp), %eax
movzbl -0x11(%rbp), %ecx
cmpl %ecx, %eax
je 0x133bf
movzbl -0x11(%rbp), %esi
movzbl -0x460(%rbp), %edx
leaq 0x4af3(%rip), %rdi      # 0x17eab
movb $0x0, %al
callq 0x8970
movq -0x8(%rbp), %rax
movq %rax, -0x488(%rbp)
leaq -0x460(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x480(%rbp)
movl -0xc(%rbp), %eax
movl -0x34(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x133f4
movl -0xc(%rbp), %eax
movl %eax, -0x48c(%rbp)
jmp 0x13400
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48c(%rbp)
movq -0x480(%rbp), %rsi
movq -0x488(%rbp), %rdi
movl -0x48c(%rbp), %eax
movslq %eax, %rdx
callq 0x61a0
movl -0x34(%rbp), %eax
subl $0x1, %eax
addq $0x490, %rsp            # imm = 0x490
popq %rbp
retq
nopl (%rax,%rax)