// File: /workspace/github_c_makefile_star2_O1/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
cmpl %eax, 0x156d5(%rip)     # 0x1c158
jle 0x6f84
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
leaq 0x45b22(%rip), %r13     # 0x4c5c0
xorl %eax, %eax
movb $0x5, 0x456c9(%rip)     # 0x4c170
movb 0x156a7(%rip), %cl      # 0x1c154
movb %cl, 0x456be(%rip)      # 0x4c171
movb $0x0, 0x456b8(%rip)     # 0x4c172
movl $0x3, 0x45aec(%rip)     # 0x4c5b0
movl $0x0, 0x45ae6(%rip)     # 0x4c5b4
movl $0x2, 0x45ae0(%rip)     # 0x4c5b8
cmpl 0x1567a(%rip), %eax     # 0x1c158
jge 0x6e59
movslq %eax, %rbp
leaq (,%rbp,2), %rax
addq %rbp, %rax
leaq 0x15667(%rip), %rcx     # 0x1c160
leaq (%rcx,%rax,4), %r14
addq $0x8, %r14
callq 0xf486
movl 0x45aa3(%rip), %r8d     # 0x4c5b0
movslq %r8d, %rdi
movl 0x45a9e(%rip), %ecx     # 0x4c5b4
movl %ecx, 0x14(%rsp)
movslq %ecx, %rcx
movl 0x45a95(%rip), %edx     # 0x4c5b8
movq %rdx, 0x8(%rsp)
movb 0x77ef2(%rip), %dl      # 0x7ea20
movb %dl, 0x7(%rsp)
movl 0x77eeb(%rip), %r11d    # 0x7ea24
movl 0x77ee8(%rip), %r9d     # 0x7ea28
movl 0x4561d(%rip), %r10d    # 0x4c164
movzbl -0x8(%r14), %r12d
cmpl $0x3, %r12d
jae 0x6ba0
movl $0xa3000000, 0x45608(%rip) # imm = 0xA3000000
movzbl -0x7(%r14), %esi
cmpl $0x2, %esi
ja 0x6b8e
leal -0x5d000000(%rsi), %ebx
movl %esi, %r15d
movq %r13, %rdx
leaq 0x9787(%rip), %r13      # 0x10300
movl (%r13,%r15,4), %r15d
movq %rdx, %r13
movl %ebx, 0x455dd(%rip)     # 0x4c164
movl %r15d, 0x77e96(%rip)    # 0x7ea24
cmpl $0x2, %r12d
jne 0x6bfc
movl $0x0, 0x77e86(%rip)     # 0x7ea24
jmp 0x6c03
cmpl $0x4, %r12d
jne 0x6d07
movb -0x4(%r14), %sil
leaq 0x1(%rdi), %rbx
movl %ebx, 0x459f8(%rip)     # 0x4c5b0
leaq 0x455b1(%rip), %rdx     # 0x4c170
movb %sil, (%rdi,%rdx)
movl (%r14), %ebx
movb %bl, 0x1(%rdi,%rdx)
movb %bh, 0x2(%rdi,%rdx)
movl %ebx, %esi
shrl $0x10, %esi
movb %sil, 0x3(%rdi,%rdx)
shrl $0x18, %ebx
movb %bl, 0x4(%rdi,%rdx)
addl $0x5, %edi
movl %edi, 0x459c8(%rip)     # 0x4c5b0
movl %ecx, %esi
incl %esi
movl %esi, 0x459c2(%rip)     # 0x4c5b4
movb $0x5, (%rcx,%r13)
jmp 0x6de7
orb $0x10, 0x45561(%rip)    # 0x4c164
movl 0x4555b(%rip), %ebx     # 0x4c164
cmpl %r10d, %ebx
je 0x6c5a
leaq 0x1(%rdi), %r15
movl %r15d, 0x45997(%rip)    # 0x4c5b0
leaq 0x45550(%rip), %rdx     # 0x4c170
movb $0x1, %r15b
movb %r15b, (%rdi,%rdx)
movb %bl, 0x1(%rdi,%rdx)
movb %bh, 0x2(%rdi,%rdx)
movl %ebx, %r15d
shrl $0x10, %r15d
movb %r15b, 0x3(%rdi,%rdx)
shrl $0x18, %ebx
movb %bl, 0x4(%rdi,%rdx)
addl $0x5, %edi
movl %edi, 0x45965(%rip)     # 0x4c5b0
leal 0x1(%rcx), %edi
movl %edi, 0x45960(%rip)     # 0x4c5b4
movb $0x1, %dl
movb %dl, (%rcx,%r13)
testb $0x1, 0x7(%rsp)
je 0x6c70
testl $0x3ff, %r9d            # imm = 0x3FF
je 0x6c70
cmpl -0x4(%r14), %r9d
je 0x6cbf
movslq 0x45939(%rip), %rcx     # 0x4c5b0
leaq 0x1(%rcx), %rdi
movl %edi, 0x4592f(%rip)     # 0x4c5b0
leaq 0x454e8(%rip), %rdx     # 0x4c170
movb $0x5, (%rcx,%rdx)
movl -0x4(%r14), %edi
movl %edi, 0x1(%rcx,%rdx)
addl $0x5, %ecx
movl %ecx, 0x45913(%rip)     # 0x4c5b0
movslq 0x45910(%rip), %rcx     # 0x4c5b4
leal 0x1(%rcx), %ebx
movl %ebx, 0x45907(%rip)     # 0x4c5b4
movb $0x2, (%rcx,%r13)
movl %edi, 0x77d70(%rip)     # 0x7ea28
movb $0x1, 0x77d61(%rip)     # 0x7ea20
leal -0x1(%r12), %ecx
cmpb $0x1, %cl
ja 0x6d97
movslq 0x458dc(%rip), %rdi     # 0x4c5b0
leaq 0x1(%rdi), %r15
movl %r15d, 0x458d1(%rip)    # 0x4c5b0
leaq 0x4548a(%rip), %rcx     # 0x4c170
movb $0xd, (%rdi,%rcx)
movl -0x4(%r14), %ecx
movl (%r14), %ebx
testl %esi, %esi
je 0x6d46
cmpl $0x2, %esi
je 0x6d4f
cmpl $0x1, %esi
jne 0x6d4d
shll $0x3, %ecx
andb $0x10, %cl
jmp 0x6d49
movb -0x4(%r14), %sil
orb $0x2, %sil
movl %edi, %ebx
incl %ebx
movl %ebx, 0x45897(%rip)     # 0x4c5b0
leaq 0x45450(%rip), %rbx     # 0x4c170
movb %sil, (%rdi,%rbx)
movl %ecx, %esi
incl %esi
movl %esi, 0x45886(%rip)     # 0x4c5b4
movb $0x4, (%rcx,%r13)
movq 0x8(%rsp), %rcx
addl $0x4, %ecx
movl %ecx, 0x45877(%rip)     # 0x4c5b8
jmp 0x6de7
shll $0x3, %ecx
shll %cl, %ebx
jmp 0x6d4f
xorl %ebx, %ebx
leaq 0x4541a(%rip), %rdx     # 0x4c170
movb %bl, (%r15,%rdx)
movb %bh, 0x2(%rdi,%rdx)
movl %ebx, %ecx
shrl $0x10, %ecx
movb %cl, 0x3(%rdi,%rdx)
shrl $0x18, %ebx
movb %bl, 0x4(%rdi,%rdx)
leal 0x5(%rdi), %ecx
movl %ecx, 0x45839(%rip)     # 0x4c5b0
cmpl $0x1, %r12d
sete %cl
addb %cl, %cl
addb $0x3, %cl
movslq 0x4582a(%rip), %rsi     # 0x4c5b4
leal 0x1(%rsi), %edi
movl %edi, 0x45821(%rip)     # 0x4c5b4
movb %cl, (%rsi,%r13)
testb $-0x3, %r12b
jne 0x6ddb
movslq 0x4580c(%rip), %rcx     # 0x4c5b0
leal 0x1(%rcx), %esi
movl %esi, 0x45803(%rip)     # 0x4c5b0
leaq 0x453bc(%rip), %rsi     # 0x4c170
movb $0xf, (%rcx,%rsi)
movslq 0x457f5(%rip), %rcx     # 0x4c5b4
leal 0x1(%rcx), %esi
movl %esi, 0x457ec(%rip)     # 0x4c5b4
movb $0x4, (%rcx,%r13)
movq 0x8(%rsp), %rcx
addl $0x4, %ecx
movl %ecx, 0x457dd(%rip)     # 0x4c5b8
movl 0x77c43(%rip), %ecx     # 0x7ea24
addl %ecx, 0x77c41(%rip)     # 0x7ea28
cmpl %eax, 0x457c3(%rip)     # 0x4c5b0
jg 0x6e1c
cmpl %eax, 0x457c3(%rip)     # 0x4c5b8
jg 0x6e1c
cmpl $0x100, 0x457b3(%rip)   # imm = 0x100
jge 0x6e1c
incq %rbp
movslq 0x1534b(%rip), %rax     # 0x1c158
addq $0xc, %r14
cmpq %rax, %rbp
jl 0x6b01
jmp 0x6e59
movl %r8d, 0x4578d(%rip)     # 0x4c5b0
movl 0x14(%rsp), %eax
movl %eax, 0x45787(%rip)     # 0x4c5b4
movq 0x8(%rsp), %rax
movl %eax, 0x45780(%rip)     # 0x4c5b8
movb 0x7(%rsp), %al
andb $0x1, %al
movb %al, 0x77bdc(%rip)      # 0x7ea20
movl %r11d, 0x77bd9(%rip)    # 0x7ea24
movl %r9d, 0x77bd6(%rip)     # 0x7ea28
movl %r10d, 0x4530b(%rip)    # 0x4c164
movb 0x45755(%rip), %al      # 0x4c5b4
movb %al, 0x4530d(%rip)      # 0x4c172
movl 0x45745(%rip), %edx     # 0x4c5b0
leaq 0x452fe(%rip), %rdi     # 0x4c170
movl $0x440, %esi            # imm = 0x440
callq 0xf4a0
movzbl 0x452ed(%rip), %ebp     # 0x4c170
movb 0x452e8(%rip), %al      # 0x4c171
movl 0x45725(%rip), %edx     # 0x4c5b4
cmpl %ebp, %edx
setne %cl
cmpb $0x1, %al
setne %sil
orb %cl, %sil
cmpb $0x1, %sil
jne 0x6eb6
movzbl %al, %ecx
leaq 0x92f2(%rip), %rdi      # 0x1019f
movl %ebp, %esi
xorl %eax, %eax
callq 0x7c8d
testl %ebp, %ebp
leaq 0x152a1(%rip), %r10     # 0x1c160
leaq 0x45b3a(%rip), %r11     # 0x4ca00
je 0x6f64
movl 0x4528e(%rip), %ecx     # 0x4c160
movl %ebp, %eax
xorl %edx, %edx
leaq 0x45295(%rip), %rsi     # 0x4c172
movslq %ecx, %rdi
leaq (%rdi,%rdi,2), %r8
leaq (%r10,%r8,4), %r8
movzbl (%rdx,%r13), %r9d
cmpl $0x5, %r9d
je 0x6f25
cmpl $0x4, %r9d
jne 0x6f58
movzbl 0x1(%r8), %r9d
movl 0x4(%r8), %ecx
movl (%rsi), %r8d
testl %r9d, %r9d
je 0x6f38
cmpl $0x2, %r9d
je 0x6f47
cmpl $0x1, %r9d
jne 0x6f44
shll $0x3, %ecx
andb $0x10, %cl
shrl %cl, %r8d
movzwl %r8w, %r8d
jmp 0x6f47
movl 0x8(%r8), %r8d
leal 0x1(%rdi), %ecx
movl %ecx, 0x4522e(%rip)     # 0x4c160
movl %r8d, (%r11,%rdi,4)
jmp 0x6f58
shll $0x3, %ecx
shrl %cl, %r8d
movzbl %r8b, %r8d
jmp 0x6f47
xorl %r8d, %r8d
leal 0x1(%rdi), %ecx
movl %ecx, 0x45210(%rip)     # 0x4c160
movl %r8d, (%r11,%rdi,4)
addq $0x4, %rsi
incq %rdx
cmpq %rdx, %rax
jne 0x6edd
movl 0x451f6(%rip), %eax     # 0x4c160
cmpl 0x151e8(%rip), %eax     # 0x1c158
jl 0x6aa0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl $0x0, 0x151ca(%rip)     # 0x1c158
retq