// File: /workspace/github_c_makefile_star2_O3/ataradov[P]edbg/dap.c
// Function: dap_transfer
void dap_transfer(void)
{
  int count, status;
  uint32_t *data;

  dap_response_count = 0;
  dap_csw = 0;

  while (dap_response_count < dap_request_count)
  {
    dap_buf[0] = ID_DAP_TRANSFER;
    dap_buf[1] = dap_jtag_index;
    dap_buf[2] = 0; // Request size (placeholder)

    dap_buf_size = 3;
    dap_ops_size = 0;
    dap_response_size = 2; // count and status

    for (int i = dap_response_count; i < dap_request_count; i++)
    {
      if (!buffer_request(&dap_request[i]))
        break;
    }

    dap_buf[2] = dap_ops_size;

    //verbose("--- %d / %d, req_cnt = %d, resp_cnt = %d, resp_size = %d\n",
    //  dap_ops_size, dap_buf_size, dap_request_count, dap_response_count, dap_response_size);

    dbg_dap_cmd(dap_buf, sizeof(dap_buf), dap_buf_size);

    count  = dap_buf[0];
    status = dap_buf[1];
    data   = (uint32_t *)&dap_buf[2];

    if (dap_ops_size != count || DAP_TRANSFER_OK != status)
      error_exit("invalid response during transfer (count = %d/%d, status = %d)", count, dap_ops_size, status);

    for (int i = 0; i < count; i++)
    {
      dap_request_t *req = &dap_request[dap_response_count];

      if (OP_READ == dap_ops[i])
      {
        dap_response[dap_response_count++] = from_lane(req->size, req->addr, *data);
        data++;
      }
      else if (OP_WRITE == dap_ops[i])
      {
        dap_response[dap_response_count++] = req->data;
      }
    }
  }

  dap_request_count = 0;
}

// Assembly:
xorl %eax, %eax
movl %eax, 0x456e9(%rip)     # 0x4c160
movl %eax, 0x456e7(%rip)     # 0x4c164
movl 0x156d5(%rip), %eax     # 0x1c158
testl %eax, %eax
jle 0x6faf
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x156c0(%rip), %r10     # 0x1c160
leaq 0x45b19(%rip), %r13     # 0x4c5c0
xorl %ecx, %ecx
movb $0x5, 0x456c0(%rip)     # 0x4c170
movb 0x1569e(%rip), %dl      # 0x1c154
movb %dl, 0x456b5(%rip)      # 0x4c171
movb $0x0, 0x456af(%rip)     # 0x4c172
movl $0x3, 0x45ae3(%rip)     # 0x4c5b0
movl $0x0, 0x45add(%rip)     # 0x4c5b4
movl $0x2, 0x45ad7(%rip)     # 0x4c5b8
cmpl %eax, %ecx
jge 0x6e40
movslq %ecx, %rbp
leaq (,%rbp,2), %rax
addq %rbp, %rax
leaq (%r10,%rax,4), %r15
addq $0x8, %r15
callq 0xf458
movl %eax, %r14d
movl 0x45aa3(%rip), %edi     # 0x4c5b0
movslq %edi, %rbx
movl 0x45a9d(%rip), %r11d    # 0x4c5b4
movslq %r11d, %r9
movl 0x45a98(%rip), %esi     # 0x4c5b8
movb 0x77efa(%rip), %al      # 0x7ea20
movb %al, 0xf(%rsp)
movl 0x77ef4(%rip), %eax     # 0x7ea24
movl 0x77ef2(%rip), %ecx     # 0x7ea28
movl %ecx, 0x10(%rsp)
movl 0x45624(%rip), %ecx     # 0x4c164
movl %ecx, 0x18(%rsp)
movzbl -0x8(%r15), %r12d
cmpl $0x3, %r12d
movl %eax, 0x24(%rsp)
jae 0x6b94
movl $0xa3000000, 0x45607(%rip) # imm = 0xA3000000
movzbl -0x7(%r15), %ecx
movl $0xa3000000, %r13d      # imm = 0xA3000000
testl %ecx, %ecx
je 0x6c31
cmpl $0x1, %ecx
je 0x6c1d
movl %eax, %edx
cmpl $0x2, %ecx
jne 0x6c3c
movl $0x4, %edx
movl $0xa3000002, %r13d      # imm = 0xA3000002
jmp 0x6c28
cmpl $0x4, %r12d
jne 0x6be5
movb -0x4(%r15), %al
leaq 0x455cb(%rip), %rdx     # 0x4c170
movb %al, (%rbx,%rdx)
movl (%r15), %eax
movb %al, 0x1(%rbx,%rdx)
movb %ah, 0x2(%rbx,%rdx)
movl %eax, %ecx
shrl $0x10, %ecx
movb %cl, 0x3(%rbx,%rdx)
shrl $0x18, %eax
movb %al, 0x4(%rbx,%rdx)
addl $0x5, %ebx
movl %ebx, 0x459e4(%rip)     # 0x4c5b0
movl %r9d, %ecx
incl %ecx
movl %ecx, 0x459dd(%rip)     # 0x4c5b4
movb $0x5, (%r9,%r13)
movl %esi, %eax
movl %ebx, %edx
jmp 0x6e15
movb -0x4(%r15), %al
orb $0x2, %al
movl %ebx, %edx
incl %edx
movl %edx, 0x459bb(%rip)     # 0x4c5b0
leaq 0x45574(%rip), %rcx     # 0x4c170
movb %al, (%rbx,%rcx)
movl %r9d, %ecx
incl %ecx
movl %ecx, 0x459aa(%rip)     # 0x4c5b4
movb $0x4, (%r9,%r13)
leal 0x4(%rsi), %eax
movl %eax, 0x459a0(%rip)     # 0x4c5b8
jmp 0x6e15
movl $0x2, %edx
movl $0xa3000001, %r13d      # imm = 0xA3000001
movl %r13d, 0x45535(%rip)    # 0x4c164
jmp 0x6c36
movl $0x1, %edx
movl %edx, 0x77de8(%rip)     # 0x7ea24
cmpb $0x2, %r12b
jne 0x6c56
movl $0x0, 0x77dd8(%rip)     # 0x7ea24
movl $0x0, 0x14(%rsp)
jmp 0x6c65
movl %edx, 0x14(%rsp)
orl $0x10, %r13d
movl %r13d, 0x454ff(%rip)    # 0x4c164
movl %r11d, %r10d
movl %edi, %edx
cmpl 0x18(%rsp), %r13d
movq %rsi, %r8
je 0x6cad
leaq 0x454f5(%rip), %rdx     # 0x4c170
movb $0x1, %sil
movb %sil, (%rbx,%rdx)
movb %r13b, 0x1(%rbx,%rdx)
xorl %eax, %eax
movb %al, 0x2(%rbx,%rdx)
movb %al, 0x3(%rbx,%rdx)
movb $-0x5d, 0x4(%rbx,%rdx)
addl $0x5, %ebx
leal 0x1(%r9), %r10d
leaq 0x4591c(%rip), %rax     # 0x4c5c0
movb %sil, (%r9,%rax)
movq %r8, %rsi
movl %ebx, %edx
movl -0x4(%r15), %ebx
testb $0x1, 0xf(%rsp)
je 0x6cd7
testl $0x3ff, 0x10(%rsp)      # imm = 0x3FF
je 0x6cd7
cmpl %ebx, 0x10(%rsp)
jne 0x6cd7
movl 0x10(%rsp), %eax
movl %eax, %ebx
leaq 0x458eb(%rip), %r13     # 0x4c5c0
jmp 0x6d1e
movslq %edx, %rdx
leaq 0x4548f(%rip), %rsi     # 0x4c170
movb $0x5, (%rdx,%rsi)
movb %bl, 0x1(%rdx,%rsi)
movb %bh, 0x2(%rdx,%rsi)
movl %ebx, %eax
shrl $0x10, %eax
movb %al, 0x3(%rdx,%rsi)
movl %ebx, %eax
shrl $0x18, %eax
movb %al, 0x4(%rdx,%rsi)
movq %r8, %rsi
addl $0x5, %edx
movslq %r10d, %rax
incl %r10d
leaq 0x458ae(%rip), %r13     # 0x4c5c0
movb $0x2, (%rax,%r13)
movb $0x1, 0x77d02(%rip)     # 0x7ea20
leal -0x1(%r12), %eax
cmpb $0x1, %al
ja 0x6dda
movslq %edx, %rsi
leaq 0x4543b(%rip), %rax     # 0x4c170
movb $0xd, (%rsi,%rax)
movl (%r15), %eax
testl %ecx, %ecx
movl %edi, 0x20(%rsp)
movl %r11d, 0x1c(%rsp)
je 0x6d5f
cmpl $0x2, %ecx
je 0x6d6c
cmpl $0x1, %ecx
jne 0x6d6a
leal (,%rbx,8), %ecx
andb $0x10, %cl
jmp 0x6d66
leal (,%rbx,8), %ecx
shll %cl, %eax
jmp 0x6d6c
xorl %eax, %eax
movl %eax, %r9d
shrl $0x10, %r9d
movl %eax, %r13d
shrl $0x18, %r13d
leal 0x5(%rsi), %edx
cmpb $0x1, %r12b
sete %r11b
addb %r11b, %r11b
addb $0x3, %r11b
leal 0x1(%r10), %ecx
leaq 0x453d9(%rip), %rdi     # 0x4c170
movb %al, 0x1(%rsi,%rdi)
movb %ah, 0x2(%rsi,%rdi)
movb %r9b, 0x3(%rsi,%rdi)
movb %r13b, 0x4(%rsi,%rdi)
movl %edx, 0x45801(%rip)     # 0x4c5b0
movl %ecx, 0x457ff(%rip)     # 0x4c5b4
movslq %r10d, %rax
leaq 0x45801(%rip), %r13     # 0x4c5c0
movb %r11b, (%rax,%r13)
movl %ecx, %r10d
movq %r8, %rsi
movl %esi, %eax
cmpb $0x2, %r12b
movl 0x20(%rsp), %edi
movl 0x1c(%rsp), %r11d
jne 0x6e0b
movslq %edx, %rax
incl %edx
movl %edx, 0x457cb(%rip)     # 0x4c5b0
leaq 0x45384(%rip), %rcx     # 0x4c170
movb $0xf, (%rax,%rcx)
leal 0x1(%r10), %ecx
movl %ecx, 0x457ba(%rip)     # 0x4c5b4
movslq %r10d, %rax
movb $0x4, (%rax,%r13)
leal 0x4(%rsi), %eax
movl %eax, 0x457ad(%rip)     # 0x4c5b8
addl 0x14(%rsp), %ebx
movl %ebx, 0x77c13(%rip)     # 0x7ea28
cmpl %r14d, %edx
jg 0x6e49
cmpl %r14d, %eax
jg 0x6e49
cmpl $0x100, %ecx            # imm = 0x100
jge 0x6e49
incq %rbp
movslq 0x15327(%rip), %rax     # 0x1c158
addq $0xc, %r15
cmpq %rax, %rbp
jl 0x6aff
jmp 0x6e8b
xorl %ecx, %ecx
movl $0x3, %edx
jmp 0x6e8b
movl %edi, 0x45761(%rip)     # 0x4c5b0
movl %r11d, 0x4575e(%rip)    # 0x4c5b4
movl %esi, 0x4575c(%rip)     # 0x4c5b8
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0x77bb8(%rip)      # 0x7ea20
movl 0x24(%rsp), %eax
movl %eax, 0x77bb2(%rip)     # 0x7ea24
movl 0x10(%rsp), %eax
movl %eax, 0x77bac(%rip)     # 0x7ea28
movl 0x18(%rsp), %eax
movl %eax, 0x452de(%rip)     # 0x4c164
movl %edi, %edx
movl %r11d, %ecx
movb %cl, 0x452e1(%rip)      # 0x4c172
leaq 0x452d8(%rip), %rdi     # 0x4c170
movl $0x440, %esi            # imm = 0x440
callq 0xf472
movzbl 0x452c7(%rip), %ebp     # 0x4c170
movb 0x452c2(%rip), %al      # 0x4c171
movl 0x456ff(%rip), %edx     # 0x4c5b4
cmpl %ebp, %edx
setne %cl
cmpb $0x1, %al
setne %sil
orb %cl, %sil
cmpb $0x1, %sil
jne 0x6edc
movzbl %al, %ecx
leaq 0x92cc(%rip), %rdi      # 0x1019f
movl %ebp, %esi
xorl %eax, %eax
callq 0x7ca5
movl 0x4527e(%rip), %ecx     # 0x4c160
testl %ebp, %ebp
leaq 0x45b15(%rip), %r11     # 0x4ca00
je 0x6f8c
movl %ebp, %eax
xorl %edx, %edx
leaq 0x45276(%rip), %rsi     # 0x4c172
leaq 0x1525d(%rip), %r10     # 0x1c160
movslq %ecx, %rdi
leaq (%rdi,%rdi,2), %r8
leaq (%r10,%r8,4), %r8
movzbl (%rdx,%r13), %r9d
cmpl $0x5, %r9d
je 0x6f4b
cmpl $0x4, %r9d
jne 0x6f7e
movzbl 0x1(%r8), %r9d
movl 0x4(%r8), %ecx
movl (%rsi), %r8d
testl %r9d, %r9d
je 0x6f5e
cmpl $0x2, %r9d
je 0x6f6d
cmpl $0x1, %r9d
jne 0x6f6a
shll $0x3, %ecx
andb $0x10, %cl
shrl %cl, %r8d
movzwl %r8w, %r8d
jmp 0x6f6d
movl 0x8(%r8), %r8d
leal 0x1(%rdi), %ecx
movl %ecx, 0x45208(%rip)     # 0x4c160
movl %r8d, (%r11,%rdi,4)
jmp 0x6f7e
shll $0x3, %ecx
shrl %cl, %r8d
movzbl %r8b, %r8d
jmp 0x6f6d
xorl %r8d, %r8d
leal 0x1(%rdi), %ecx
movl %ecx, 0x451ea(%rip)     # 0x4c160
movl %r8d, (%r11,%rdi,4)
addq $0x4, %rsi
incq %rdx
cmpq %rdx, %rax
jne 0x6f03
jmp 0x6f93
leaq 0x151cd(%rip), %r10     # 0x1c160
movl 0x151bf(%rip), %eax     # 0x1c158
cmpl %eax, %ecx
jl 0x6aa9
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl $0x0, 0x1519f(%rip)     # 0x1c158
retq