// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
andl $0x0, 0x46857(%rip)     # 0x4d160
andl $0x0, 0x46854(%rip)     # 0x4d164
leaq 0x16849(%rip), %r10     # 0x1d160
leaq 0x46ca2(%rip), %r15     # 0x4d5c0
xorl %ecx, %ecx
cmpl 0x16832(%rip), %ecx     # 0x1d158
jge 0x6db1
movb $0x5, 0x4683d(%rip)     # 0x4d170
movb 0x1681b(%rip), %al      # 0x1d154
movb %al, 0x46832(%rip)      # 0x4d171
movb $0x0, 0x4682c(%rip)     # 0x4d172
andl $0x0, 0x46c67(%rip)     # 0x4d5b4
movl $0x3, 0x46c59(%rip)     # 0x4d5b0
movl $0x2, 0x46c57(%rip)     # 0x4d5b8
movslq %ecx, %r13
imulq $0xc, %r13, %rbx
addq %r10, %rbx
decq %r13
xorl %r12d, %r12d
pushq $0x3
popq %rdx
movslq 0x167dd(%rip), %rax     # 0x1d158
incq %r13
cmpq %rax, %r13
jge 0x6cb5
callq 0xed14
movl %eax, 0xc(%rsp)
movl 0x46c1a(%rip), %ebp     # 0x4d5b0
movslq %ebp, %rax
movl 0x46c15(%rip), %esi     # 0x4d5b4
movslq %esi, %r14
movl 0x46c10(%rip), %ecx     # 0x4d5b8
movq %rcx, 0x20(%rsp)
movb 0x7906c(%rip), %r15b    # 0x7fa20
movl 0x79069(%rip), %r8d     # 0x7fa24
movl 0x79066(%rip), %r9d     # 0x7fa28
movl 0x4679b(%rip), %r10d    # 0x4d164
movzbl (%rbx), %ecx
cmpl $0x3, %ecx
movl %r9d, 0x10(%rsp)
movl %esi, 0x1c(%rsp)
movl %r8d, 0x18(%rsp)
movl %r10d, 0x14(%rsp)
movb %r15b, 0xb(%rsp)
jae 0x6a22
movl $0xa3000000, 0x46771(%rip) # imm = 0xA3000000
movzbl 0x1(%rbx), %edx
movl $0xa3000000, %edi       # imm = 0xA3000000
testl %edx, %edx
je 0x6abb
cmpl $0x1, %edx
je 0x6aab
cmpl $0x2, %edx
jne 0x6ac4
movl $0xa3000002, %edi       # imm = 0xA3000002
pushq $0x4
jmp 0x6ab2
cmpl $0x4, %ecx
jne 0x6a61
movb 0x4(%rbx), %cl
movl %eax, %edx
incl %edx
movl %edx, 0x46b7c(%rip)     # 0x4d5b0
leaq 0x46735(%rip), %rdx     # 0x4d170
movb %cl, (%rax,%rdx)
movl 0x8(%rbx), %edi
callq 0x771e
movl %r14d, %r12d
incl %r12d
movl %r12d, 0x46b61(%rip)    # 0x4d5b4
leaq 0x46b66(%rip), %r15     # 0x4d5c0
movb $0x5, (%r14,%r15)
jmp 0x6aa2
movb 0x4(%rbx), %cl
orb $0x2, %cl
movl %eax, %edx
incl %edx
movl %edx, 0x46b3f(%rip)     # 0x4d5b0
leaq 0x466f8(%rip), %rdx     # 0x4d170
movb %cl, (%rax,%rdx)
movl %r14d, %r12d
incl %r12d
movl %r12d, 0x46b2c(%rip)    # 0x4d5b4
leaq 0x46b31(%rip), %r15     # 0x4d5c0
movb $0x4, (%r14,%r15)
movq 0x20(%rsp), %rax
addl $0x4, %eax
movl %eax, 0x46b16(%rip)     # 0x4d5b8
movl 0xc(%rsp), %ecx
jmp 0x6c47
movl $0xa3000001, %edi       # imm = 0xA3000001
pushq $0x2
popq %rdx
movl %edi, 0x466ab(%rip)     # 0x4d164
jmp 0x6abe
pushq $0x1
popq %rdx
movl %edx, 0x78f60(%rip)     # 0x7fa24
cmpb $0x2, %cl
jne 0x6ad2
andl $0x0, 0x78f54(%rip)     # 0x7fa24
jmp 0x6adb
orl $0x10, %edi
movl %edi, 0x46689(%rip)     # 0x4d164
movl %esi, %r12d
cmpl %r10d, %edi
je 0x6b1a
leal 0x1(%rax), %ecx
movl %ecx, 0x46ac4(%rip)     # 0x4d5b0
leaq 0x4667d(%rip), %rcx     # 0x4d170
movb $0x1, %dl
movb %dl, (%rax,%rcx)
callq 0x771e
leal 0x1(%r14), %r12d
movl %r12d, 0x46aac(%rip)    # 0x4d5b4
leaq 0x46ab1(%rip), %rax     # 0x4d5c0
movb $0x1, %cl
movb %cl, (%r14,%rax)
movl 0x10(%rsp), %r9d
movl 0x4(%rbx), %edi
testb $0x1, %r15b
je 0x6b3c
testw $0x3ff, %r9w            # imm = 0x3FF
je 0x6b3c
cmpl %edi, %r9d
jne 0x6b3c
movl %r9d, %ecx
leaq 0x46a86(%rip), %r15     # 0x4d5c0
jmp 0x6b89
movslq 0x46a6d(%rip), %rax     # 0x4d5b0
leal 0x1(%rax), %ecx
movl %ecx, 0x46a64(%rip)     # 0x4d5b0
leaq 0x4661d(%rip), %rcx     # 0x4d170
movb $0x5, (%rax,%rcx)
callq 0x771e
movslq %r12d, %rax
leal 0x1(%r12), %edx
movl %edx, 0x46a4a(%rip)     # 0x4d5b4
leaq 0x46a4f(%rip), %r15     # 0x4d5c0
movb $0x2, (%rax,%r15)
movl 0x4(%rbx), %ecx
movl %ecx, 0x78ea9(%rip)     # 0x7fa28
movb $0x1, 0x78e9a(%rip)     # 0x7fa20
movl %edx, %r12d
movb (%rbx), %al
leal -0x1(%rax), %edx
cmpb $0x1, %dl
ja 0x6bfb
movslq 0x46a16(%rip), %rax     # 0x4d5b0
leal 0x1(%rax), %edx
movl %edx, 0x46a0d(%rip)     # 0x4d5b0
leaq 0x465c6(%rip), %rdx     # 0x4d170
movb $0xd, (%rax,%rdx)
movzbl 0x1(%rbx), %eax
movl 0x8(%rbx), %edi
testl %eax, %eax
je 0x6bcb
cmpl $0x2, %eax
je 0x6bd4
cmpl $0x1, %eax
jne 0x6bd2
shll $0x3, %ecx
andb $0x10, %cl
jmp 0x6bce
shll $0x3, %ecx
shll %cl, %edi
jmp 0x6bd4
xorl %edi, %edi
callq 0x771e
movb (%rbx), %al
cmpb $0x1, %al
sete %cl
addb %cl, %cl
addb $0x3, %cl
movslq 0x469c8(%rip), %rdx     # 0x4d5b4
leal 0x1(%rdx), %r12d
movl %r12d, 0x469bd(%rip)    # 0x4d5b4
movb %cl, (%rdx,%r15)
testb $-0x3, %al
jne 0x6c37
movslq 0x469aa(%rip), %rax     # 0x4d5b0
leal 0x1(%rax), %ecx
movl %ecx, 0x469a1(%rip)     # 0x4d5b0
leaq 0x4655a(%rip), %rcx     # 0x4d170
movb $0xf, (%rax,%rcx)
movslq %r12d, %rax
leal 0x1(%r12), %ecx
movl %ecx, 0x4698c(%rip)     # 0x4d5b4
movb $0x4, (%rax,%r15)
addl $0x4, 0x46984(%rip)     # 0x4d5b8
movl %ecx, %r12d
movl 0xc(%rsp), %ecx
movl 0x78de3(%rip), %eax     # 0x7fa24
addl %eax, 0x78de1(%rip)     # 0x7fa28
movl 0x46963(%rip), %edx     # 0x4d5b0
cmpl %ecx, %edx
jg 0x6c6a
cmpl %ecx, 0x46961(%rip)     # 0x4d5b8
jg 0x6c6a
addq $0xc, %rbx
cmpl $0x100, %r12d           # imm = 0x100
jl 0x6974
movl %ebp, 0x46940(%rip)     # 0x4d5b0
movl 0x1c(%rsp), %eax
movl %eax, 0x4693a(%rip)     # 0x4d5b4
movq 0x20(%rsp), %rcx
movl %ecx, 0x46933(%rip)     # 0x4d5b8
movb 0xb(%rsp), %cl
andb $0x1, %cl
movb %cl, 0x78d8e(%rip)      # 0x7fa20
movl 0x18(%rsp), %ecx
movl %ecx, 0x78d88(%rip)     # 0x7fa24
movl 0x10(%rsp), %ecx
movl %ecx, 0x78d82(%rip)     # 0x7fa28
movl 0x14(%rsp), %ecx
movl %ecx, 0x464b4(%rip)     # 0x4d164
movl %ebp, %edx
movl %eax, %r12d
movb %r12b, 0x464b6(%rip)    # 0x4d172
leaq 0x464ad(%rip), %rdi     # 0x4d170
movl $0x440, %esi            # imm = 0x440
callq 0xed2e
movzbl 0x4649c(%rip), %ebp     # 0x4d170
movb 0x46497(%rip), %al      # 0x4d171
movl 0x468d4(%rip), %edx     # 0x4d5b4
cmpl %ebp, %edx
setne %cl
cmpb $0x1, %al
setne %sil
orb %cl, %sil
cmpb $0x1, %sil
jne 0x6d07
movzbl %al, %ecx
leaq 0x94a1(%rip), %rdi      # 0x1019f
movl %ebp, %esi
xorl %eax, %eax
callq 0x7a0e
movl 0x46453(%rip), %ecx     # 0x4d160
movl %ebp, %eax
xorl %edx, %edx
leaq 0x4645a(%rip), %rsi     # 0x4d172
leaq 0x16441(%rip), %r10     # 0x1d160
leaq 0x46cda(%rip), %r11     # 0x4da00
cmpq %rdx, %rax
je 0x6920
movslq %ecx, %rdi
imulq $0xc, %rdi, %r8
addq %r10, %r8
movzbl (%rdx,%r15), %r9d
cmpl $0x5, %r9d
je 0x6d76
cmpl $0x4, %r9d
jne 0x6da9
movzbl 0x1(%r8), %r9d
movl 0x4(%r8), %ecx
movl (%rsi), %r8d
testl %r9d, %r9d
je 0x6d89
cmpl $0x2, %r9d
je 0x6d98
cmpl $0x1, %r9d
jne 0x6d95
shll $0x3, %ecx
andb $0x10, %cl
shrl %cl, %r8d
movzwl %r8w, %r8d
jmp 0x6d98
movl 0x8(%r8), %r8d
leal 0x1(%rdi), %ecx
movl %ecx, 0x463dd(%rip)     # 0x4d160
movl %r8d, (%r11,%rdi,4)
jmp 0x6da9
shll $0x3, %ecx
shrl %cl, %r8d
movzbl %r8b, %r8d
jmp 0x6d98
xorl %r8d, %r8d
leal 0x1(%rdi), %ecx
movl %ecx, 0x463bf(%rip)     # 0x4d160
movl %r8d, (%r11,%rdi,4)
addq $0x4, %rsi
incq %rdx
jmp 0x6d26
andl $0x0, 0x163a0(%rip)     # 0x1d158
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq