// File: /workspace/github_c_makefile_star2_O0/ataradov[P]edbg/target_st_stm32wb55.c
// Function: target_program
static void target_program(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t offs = 0;
  uint32_t start_page, number_of_pages;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.file_size;

  start_page = target_options.offset / FLASH_PAGE_SIZE;
  number_of_pages = (size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE;

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    dap_write_word(FLASH_CR, FLASH_CR_PER | FLASH_CR_PNB(start_page + page));
    dap_write_word(FLASH_CR, FLASH_CR_PER | FLASH_CR_PNB(start_page + page) | FLASH_CR_STRT);
    flash_wait_done();

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

  verbose(",");

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    dap_write_word(FLASH_CR, FLASH_CR_PG);

    for (int i = 0; i < (FLASH_PAGE_SIZE / FLASH_ROW_SIZE); i++)
    {
      dap_write_block(addr, &buf[offs], FLASH_ROW_SIZE);
      addr += FLASH_ROW_SIZE;
      offs += FLASH_ROW_SIZE;
    }

    if (0 == (page % STATUS_INTERVAL))
      verbose(".");

    flash_wait_done();
  }

  dap_write_word(FLASH_CR, 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x735c2(%rip), %eax     # 0x82470
addl $0x8000000, %eax        # imm = 0x8000000
movl %eax, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movq 0x735c4(%rip), %rax     # 0x82488
movq %rax, -0x18(%rbp)
movl 0x735b2(%rip), %eax     # 0x82480
movl %eax, -0x1c(%rbp)
movl 0x73599(%rip), %eax     # 0x82470
movl $0x1000, %ecx           # imm = 0x1000
cltd
idivl %ecx
movl %eax, -0xc(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1000, %eax           # imm = 0x1000
subl $0x1, %eax
shrl $0xc, %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0xef60
movl -0xc(%rbp), %esi
addl -0x20(%rbp), %esi
shll $0x3, %esi
orl $0x2, %esi
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x77d0
movl -0xc(%rbp), %esi
addl -0x20(%rbp), %esi
shll $0x3, %esi
orl $0x2, %esi
orl $0x10000, %esi          # imm = 0x10000
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x77d0
callq 0xf2c0
movl -0x20(%rbp), %ecx
andl $0x3, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xef53
leaq 0x5923(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0xef55
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xeefa
leaq 0x7ec5(%rip), %rdi      # 0x16e2c
movb $0x0, %al
callq 0x8630
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0xf002
movl $0x58004014, %edi       # imm = 0x58004014
movl $0x1, %esi
callq 0x77d0
movl $0x0, -0x28(%rbp)
cmpl $0x8, -0x28(%rbp)
jge 0xefd5
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rsi
movl -0x8(%rbp), %eax
addq %rax, %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x79c0
movl -0x4(%rbp), %eax
addl $0x200, %eax            # imm = 0x200
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %eax
addl $0x200, %eax            # imm = 0x200
movl %eax, -0x8(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xef97
movl -0x24(%rbp), %ecx
andl $0x3, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xefef
leaq 0x5887(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
callq 0xf2c0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xef75
movl $0x58004014, %edi       # imm = 0x58004014
xorl %esi, %esi
callq 0x77d0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)