// File: /workspace/github_c_makefile_star2_O0/ataradov[P]edbg/dap.c
// Function: dap_read_block
void dap_read_block(uint32_t addr, uint8_t *data, int size)
{
  uint32_t ptr = addr;
  uint32_t rem = size;
  int cnt = 0;

  if (size == 0)
    return;

  while (rem && (ptr % sizeof(uint32_t)))
  {
    dap_read_byte_req(ptr);
    ptr += sizeof(uint8_t);
    rem -= sizeof(uint8_t);
  }

  while (rem >= sizeof(uint32_t))
  {
    dap_read_word_req(ptr);
    ptr += sizeof(uint32_t);
    rem -= sizeof(uint32_t);
  }

  while (rem)
  {
    dap_read_byte_req(ptr);
    ptr += sizeof(uint8_t);
    rem -= sizeof(uint8_t);
  }

  dap_transfer();

  while (size && (addr % sizeof(uint32_t)))
  {
    *data = dap_response[cnt++];
    data += sizeof(uint8_t);
    addr += sizeof(uint8_t);
    size -= sizeof(uint8_t);
  }

  while (size >= (int)sizeof(uint32_t))
  {
    *(uint32_t *)data = dap_response[cnt++];
    data += sizeof(uint32_t);
    size -= sizeof(uint32_t);
  }

  while (size)
  {
    *data = dap_response[cnt++];
    data += sizeof(uint8_t);
    size -= sizeof(uint8_t);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x7830
jmp 0x79b1
jmp 0x7832
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x21(%rbp)
je 0x784e
movl -0x18(%rbp), %eax
andq $0x3, %rax
cmpq $0x0, %rax
setne %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
testb $0x1, %al
jne 0x7857
jmp 0x7875
movl -0x18(%rbp), %edi
callq 0x6fe0
movl -0x18(%rbp), %eax
addq $0x1, %rax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
subq $0x1, %rax
movl %eax, -0x1c(%rbp)
jmp 0x7832
jmp 0x7877
movl -0x1c(%rbp), %eax
cmpq $0x4, %rax
jb 0x789e
movl -0x18(%rbp), %edi
callq 0x7030
movl -0x18(%rbp), %eax
addq $0x4, %rax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
subq $0x4, %rax
movl %eax, -0x1c(%rbp)
jmp 0x7877
jmp 0x78a0
cmpl $0x0, -0x1c(%rbp)
je 0x78c4
movl -0x18(%rbp), %edi
callq 0x6fe0
movl -0x18(%rbp), %eax
addq $0x1, %rax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %eax
subq $0x1, %rax
movl %eax, -0x1c(%rbp)
jmp 0x78a0
callq 0x6c70
xorl %eax, %eax
cmpl $0x0, -0x14(%rbp)
movb %al, -0x22(%rbp)
je 0x78e5
movl -0x4(%rbp), %eax
andq $0x3, %rax
cmpq $0x0, %rax
setne %al
movb %al, -0x22(%rbp)
movb -0x22(%rbp), %al
testb $0x1, %al
jne 0x78ee
jmp 0x7931
movl -0x20(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x20(%rbp)
movslq %eax, %rcx
leaq 0x4885d(%rip), %rax     # 0x50160
movl (%rax,%rcx,4), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movl -0x4(%rbp), %eax
addq $0x1, %rax
movl %eax, -0x4(%rbp)
movslq -0x14(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x14(%rbp)
jmp 0x78c9
jmp 0x7933
cmpl $0x4, -0x14(%rbp)
jl 0x7970
movl -0x20(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x20(%rbp)
movslq %eax, %rcx
leaq 0x48812(%rip), %rax     # 0x50160
movl (%rax,%rcx,4), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x10(%rbp)
movslq -0x14(%rbp), %rax
subq $0x4, %rax
movl %eax, -0x14(%rbp)
jmp 0x7933
jmp 0x7972
cmpl $0x0, -0x14(%rbp)
je 0x79b1
movl -0x20(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x20(%rbp)
movslq %eax, %rcx
leaq 0x487d3(%rip), %rax     # 0x50160
movl (%rax,%rcx,4), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
movslq -0x14(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x14(%rbp)
jmp 0x7972
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)