// File: /workspace/github_c_makefile_star2_O0/ataradov[P]edbg/target_rpi_rp2040.c
// Function: target_verify
static void target_verify(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t block_size;
  uint32_t offs = 0;
  uint8_t *bufb;
  uint8_t *bufa = target_options.file_data;
  uint32_t size = target_options.file_size;
  int sector = 0;

  bufb = buf_alloc(FLASH_SECTOR_SIZE);

  spi_xip_mode();

  while (size)
  {
    dap_read_block(addr, bufb, FLASH_SECTOR_SIZE);

    block_size = (size > FLASH_SECTOR_SIZE) ? FLASH_SECTOR_SIZE : size;

    for (int i = 0; i < (int)block_size; i++)
    {
      if (bufa[offs + i] != bufb[i])
      {
        verbose("\nat address 0x%x expected 0x%02x, read 0x%02x\n",
            addr + i - FLASH_ADDR, bufa[offs + i], bufb[i]);
        buf_free(bufb);
        error_exit("verification failed");
      }
    }

    addr += FLASH_SECTOR_SIZE;
    offs += FLASH_SECTOR_SIZE;
    size -= block_size;

    if (0 == (sector++ % STATUS_INTERVAL))
      verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x7104a(%rip), %eax     # 0x825a8
addl $0x13000000, %eax       # imm = 0x13000000
movl %eax, -0x4(%rbp)
movl $0x0, -0xc(%rbp)
movq 0x7104c(%rip), %rax     # 0x825c0
movq %rax, -0x20(%rbp)
movl 0x7103a(%rip), %eax     # 0x825b8
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x8ae0
movq %rax, -0x18(%rbp)
callq 0x11fd0
cmpl $0x0, -0x24(%rbp)
je 0x116ae
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7800
cmpl $0x1000, -0x24(%rbp)    # imm = 0x1000
jbe 0x115c9
movl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x30(%rbp)
jmp 0x115cf
movl -0x24(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x8(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x11661
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x11651
movl -0x4(%rbp), %esi
addl -0x2c(%rbp), %esi
subl $0x13000000, %esi       # imm = 0x13000000
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x2c(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
leaq 0x523a(%rip), %rdi      # 0x1686d
movb $0x0, %al
callq 0x8630
movq -0x18(%rbp), %rdi
callq 0x8b30
leaq 0x647e(%rip), %rdi      # 0x17ac8
movb $0x0, %al
callq 0x8970
jmp 0x11653
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x115dc
movl -0x4(%rbp), %eax
addl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x4(%rbp)
movl -0xc(%rbp), %eax
addl $0x1000, %eax           # imm = 0x1000
movl %eax, -0xc(%rbp)
movl -0x8(%rbp), %ecx
movl -0x24(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x28(%rbp)
movl $0x4, %ecx
cltd
idivl %ecx
xorl %eax, %eax
cmpl %edx, %eax
jne 0x116a9
leaq 0x31cd(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0x1159b
movq -0x18(%rbp), %rdi
callq 0x8b30
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)