LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: target_select
static void target_select(target_options_t *options)
{
  uint32_t dsu_did, id, rev;

  reset_with_extension();

  dsu_did = dap_read_word(DSU_DID);
  id = dsu_did & DEVICE_ID_MASK;
  rev = (dsu_did >> DEVICE_REV_SHIFT) & DEVICE_REV_MASK;

  for (int i = 0; i < ARRAY_SIZE(devices); i++)
  {
    if (devices[i].dsu_did != id)
      continue;

    verbose("Target: %s (Rev %c)\n", devices[i].name, 'A' + rev);

    target_device = devices[i];
    target_options = *options;

    if (target_device.trust_zone)
    {
      NVMCTRL_CTRLA  = NVMCTRL_NSEC_CTRLA + NVMCTRL_SEC_OFFSET;
      NVMCTRL_CTRLB  = NVMCTRL_NSEC_CTRLB + NVMCTRL_SEC_OFFSET;
      NVMCTRL_CTRLC  = NVMCTRL_NSEC_CTRLC + NVMCTRL_SEC_OFFSET;
      NVMCTRL_STATUS = NVMCTRL_NSEC_STATUS + NVMCTRL_SEC_OFFSET;
      NVMCTRL_ADDR   = NVMCTRL_NSEC_ADDR + NVMCTRL_SEC_OFFSET;
    }
    else
    {
      NVMCTRL_CTRLA  = NVMCTRL_NSEC_CTRLA;
      NVMCTRL_CTRLB  = NVMCTRL_NSEC_CTRLB;
      NVMCTRL_CTRLC  = NVMCTRL_NSEC_CTRLC;
      NVMCTRL_STATUS = NVMCTRL_NSEC_STATUS;
      NVMCTRL_ADDR   = NVMCTRL_NSEC_ADDR;
    }

    target_check_options(&target_options, target_device.flash_size, FLASH_ROW_SIZE);

    return;
  }

  error_exit("unknown target device (DSU_DID = 0x%08x)", dsu_did);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0xb4cc
movl $0x41002118, %edi       # imm = 0x41002118
callq 0x6fe1
movl %eax, %ecx
andl $0xfffff0ff, %ecx       # imm = 0xFFFFF0FF
movl %eax, %edx
shrl $0x8, %edx
andl $0xf, %edx
pushq $-0x28
popq %rsi
leaq 0x10a5b(%rip), %r14     # 0x1b9e0
leaq 0x28(%rsi), %r15
cmpq $0x2f8, %r15            # imm = 0x2F8
je 0xb05b
cmpl %ecx, 0x28(%rsi,%r14)
movq %r15, %rsi
jne 0xaf85
movq 0x10(%r15,%r14), %rsi
addl $0x41, %edx
leaq 0x7067(%rip), %rdi      # 0x12016
xorl %eax, %eax
callq 0x773c
movq 0x20(%r15,%r14), %rax
movq %rax, 0x74c76(%rip)     # 0x7fc38
movups (%r15,%r14), %xmm0
movups 0x10(%r15,%r14), %xmm1
movups %xmm1, 0x74c54(%rip)    # 0x7fc28
movups %xmm0, 0x74c3d(%rip)    # 0x7fc18
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm0, 0x74c53(%rip)    # 0x7fc40
movups %xmm1, 0x74c5c(%rip)    # 0x7fc50
movups %xmm2, 0x74c65(%rip)    # 0x7fc60
movq 0x30(%rbx), %rax
movq %rax, 0x74c6a(%rip)     # 0x7fc70
leaq 0x74c33(%rip), %rdi     # 0x7fc40
movzbl 0x74c20(%rip), %eax     # 0x7fc34
shll $0xc, %eax
leal 0x41004000(%rax), %ecx
leal 0x41004008(%rax), %edx
leal 0x41004018(%rax), %esi
orl $0x4100401c, %eax       # imm = 0x4100401C
movl %ecx, 0x74c44(%rip)     # 0x7fc78
movl %edx, 0x74c42(%rip)     # 0x7fc7c
movl %esi, 0x74c40(%rip)     # 0x7fc80
movl %eax, 0x74c3e(%rip)     # 0x7fc84
movl 0x74be4(%rip), %esi     # 0x7fc30
movl $0x100, %edx            # imm = 0x100
popq %rbx
popq %r14
popq %r15
jmp 0x8b8e
leaq 0x6fef(%rip), %rdi      # 0x12051
movl %eax, %esi
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x7a0e
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: target_erase
static void target_erase(void)
{
  reset_with_extension();

  sleep_ms(10);

  if (dap_read_byte(DSU_STATUSB) & DSU_STATUSB_BCCD1)
  {
    uint32_t status = dap_read_word(DSU_BCC1);
    warning("BootROM indicated an error (STATUS = 0x%08x), still trying to erase", status);
  }
  else
  {
    bootrom_command(CMD_INIT);
    bootrom_expect(SIG_COMM);
  }

  if (target_device.trust_zone)
  {
    bootrom_command(CMD_CE2);
    bootrom_expect(SIG_CMD_VALID);

    // TODO: Take this value from a command line argument
    bootrom_data(0xffffffff);
    bootrom_data(0xffffffff);
    bootrom_data(0xffffffff);
    bootrom_data(0xffffffff);
  }
  else
  {
    bootrom_command(CMD_CHIPERASE);
    bootrom_expect(SIG_CMD_VALID);
  }

  bootrom_expect(SIG_CMD_SUCCESS);
}

// Assembly:
pushq %rax
callq 0xb4cc
pushq $0xa
popq %rdi
callq 0x7aeb
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x6fba
testb %al, %al
js 0xb0aa
pushq $0x55
popq %rdi
callq 0xb4ef
pushq $0x20
popq %rdi
callq 0xb512
jmp 0xb0c4
movl $0x41002124, %edi       # imm = 0x41002124
callq 0x6fe1
leaq 0x813e(%rip), %rdi      # 0x131f9
movl %eax, %esi
xorl %eax, %eax
callq 0x7878
cmpb $0x1, 0x74b69(%rip)     # 0x7fc34
jne 0xb0f5
movl $0xe2, %edi
callq 0xb4ef
pushq $0x24
popq %rdi
callq 0xb512
callq 0xb594
callq 0xb594
callq 0xb594
callq 0xb594
jmp 0xb107
movl $0xe3, %edi
callq 0xb4ef
pushq $0x24
popq %rdi
callq 0xb512
pushq $0x21
popq %rdi
popq %rax
jmp 0xb512
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: target_program
static void target_program(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t offs = 0;
  uint32_t number_of_rows;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.file_size;

  bootrom_park();

  if ((dap_read_byte(DSU_STATUSB) & 0x03) != 0x02)
    error_exit("device is locked (DAL is not 2), perform a chip erase before programming");

  number_of_rows = (size + FLASH_ROW_SIZE - 1) / FLASH_ROW_SIZE;

  dap_write_byte(NVMCTRL_CTRLC, 0); // Enable automatic write

  for (uint32_t row = 0; row < number_of_rows; row++)
  {
    dap_write_word(NVMCTRL_ADDR, addr);

    dap_write_half(NVMCTRL_CTRLA, NVMCTRL_CMD_ER);
    while (0 == (dap_read_byte(NVMCTRL_STATUS) & NVMCTRL_STATUS_READY));

    dap_write_block(addr, &buf[offs], FLASH_ROW_SIZE);

    addr += FLASH_ROW_SIZE;
    offs += FLASH_ROW_SIZE;

    verbose(".");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x74b10(%rip), %ebx     # 0x7fc58
movq 0x74b21(%rip), %r15     # 0x7fc70
movl 0x74b13(%rip), %ebp     # 0x7fc68
callq 0xb5b2
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x6fba
andb $0x3, %al
cmpb $0x2, %al
je 0xb178
leaq 0x818b(%rip), %rdi      # 0x132fc
xorl %eax, %eax
callq 0x7a0e
addl $0xff, %ebp
shrl $0x8, %ebp
movl 0x74af5(%rip), %edi     # 0x7fc7c
xorl %esi, %esi
callq 0x6ff4
leaq 0x567a(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
xorl %r13d, %r13d
cmpl %ebp, %r13d
je 0xb1f8
movl 0x74ade(%rip), %edi     # 0x7fc84
movl %ebx, %esi
callq 0x700c
movl 0x74ac5(%rip), %edi     # 0x7fc78
movl $0xa502, %esi           # imm = 0xA502
callq 0x7000
movl 0x74abd(%rip), %edi     # 0x7fc80
callq 0x6fba
testb $0x4, %al
je 0xb1bd
leaq (%r15,%r12), %rsi
movl %ebx, %edi
movl $0x100, %edx            # imm = 0x100
callq 0x70ef
addl $0x100, %ebx            # imm = 0x100
addq $0x100, %r12            # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x773c
incl %r13d
jmp 0xb19b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.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;

  bootrom_park();

  if ((dap_read_byte(DSU_STATUSB) & 0x03) != 0x02)
    error_exit("device is locked (DAL is not 2), unable to verify");

  bufb = buf_alloc(FLASH_ROW_SIZE);

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

    block_size = (size > FLASH_ROW_SIZE) ? FLASH_ROW_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, bufa[offs + i], bufb[i]);
        buf_free(bufb);
        error_exit("verification failed");
      }
    }

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

    verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x74a40(%rip), %ebx     # 0x7fc58
movq 0x74a51(%rip), %rbp     # 0x7fc70
movl 0x74a42(%rip), %r13d    # 0x7fc68
callq 0xb5b2
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x6fba
andb $0x3, %al
cmpb $0x2, %al
je 0xb249
leaq 0x8103(%rip), %rdi      # 0x13345
xorl %eax, %eax
callq 0x7a0e
movl $0x100, %edi            # imm = 0x100
callq 0x7b1b
movq %rax, %r14
xorl %r15d, %r15d
testl %r13d, %r13d
je 0xb2fa
movl %ebx, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7018
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r13d
movl $0x100, %r12d           # imm = 0x100
movl %r13d, 0x4(%rsp)
cmovbl %r13d, %r12d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0xb2cf
leal (%r15,%r13), %eax
movzbl (%rbp,%rax), %edx
movzbl (%r14,%r13), %ecx
cmpb %cl, %dl
je 0xb2ca
leal (%rbx,%r13), %esi
leaq 0x7550(%rip), %rdi      # 0x127fd
xorl %eax, %eax
callq 0x773c
movq %r14, %rdi
callq 0x7b3c
leaq 0x87a5(%rip), %rdi      # 0x13a68
xorl %eax, %eax
callq 0x7a0e
incq %r13
jmp 0xb28b
movl $0x100, %eax            # imm = 0x100
addq %rax, %rbx
movl 0x4(%rsp), %r13d
subl %r12d, %r13d
leaq 0x5529(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x773c
movl $0x100, %eax            # imm = 0x100
addq %rax, %r15
jmp 0xb259
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7b3c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: target_read
static void target_read(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.size;

  bootrom_park();

  if ((dap_read_byte(DSU_STATUSB) & 0x03) != 0x02)
    error_exit("device is locked (DAL is not 2), unable to read");

  while (size)
  {
    dap_read_block(addr, &buf[offs], FLASH_ROW_SIZE);

    addr += FLASH_ROW_SIZE;
    offs += FLASH_ROW_SIZE;
    size -= FLASH_ROW_SIZE;

    verbose(".");
  }

  save_file(target_options.name, buf, target_options.size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl 0x74939(%rip), %r15d    # 0x7fc58
movq 0x7494a(%rip), %rbx     # 0x7fc70
movl 0x74930(%rip), %ebp     # 0x7fc5c
callq 0xb5b2
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x6fba
andb $0x3, %al
cmpb $0x2, %al
je 0xb34f
leaq 0x802f(%rip), %rdi      # 0x13377
xorl %eax, %eax
callq 0x7a0e
leaq 0x54b9(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
cmpl %r12d, %ebp
je 0xb385
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7018
addl $0x100, %r12d           # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x773c
jmp 0xb359
movq 0x748c4(%rip), %rdi     # 0x7fc50
movl 0x748ca(%rip), %edx     # 0x7fc5c
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7bf8
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: target_fuse_read
static int target_fuse_read(int section, uint8_t *data)
{
  uint32_t addr = 0;

  if (0 == section || 2 == section)
    addr = USER_ROW_ADDR;
  else if (1 == section || 3 == section)
    addr = BOCOR_ROW_ADDR;
  else
    return 0;

  bootrom_park();

  dap_read_block(addr, data, FLASH_ROW_SIZE);

  return FLASH_ROW_SIZE;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
andl $-0x3, %edi
je 0xb3bd
xorl %ebp, %ebp
cmpl $0x1, %edi
jne 0xb3dd
movl $0x80c000, %r14d        # imm = 0x80C000
jmp 0xb3c3
movl $0x804000, %r14d        # imm = 0x804000
callq 0xb5b2
movl $0x100, %ebp            # imm = 0x100
movl %r14d, %edi
movq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7018
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t addr = 0;

  if (0 == section)
  {
    uint32_t crc = crc32(&data[8], target_device.crc_offset-8);

    data[target_device.crc_offset + 0] = crc;
    data[target_device.crc_offset + 1] = crc >> 8;
    data[target_device.crc_offset + 2] = crc >> 16;
    data[target_device.crc_offset + 3] = crc >> 24;

    addr = USER_ROW_ADDR;
  }
  else if (1 == section)
  {
    uint32_t crc = crc32(data, 8);

    data[8]  = crc;
    data[9]  = crc >> 8;
    data[10] = crc >> 16;
    data[11] = crc >> 24;

    sha256(data, FLASH_ROW_SIZE-32, &data[FLASH_ROW_SIZE-32]);

    addr = BOCOR_ROW_ADDR;
  }
  else if (2 == section)
  {
    addr = USER_ROW_ADDR;
  }
  else if (3 == section)
  {
    addr = BOCOR_ROW_ADDR;
  }
  else
    error_exit("internal: incorrect section index in target_fuse_write()");

  bootrom_park();

  dap_write_byte(NVMCTRL_CTRLC, 0);
  dap_write_word(NVMCTRL_ADDR, addr);
  dap_write_half(NVMCTRL_CTRLA, NVMCTRL_CMD_ER);
  while (0 == (dap_read_byte(NVMCTRL_STATUS) & NVMCTRL_STATUS_READY));

  dap_write_block(addr, data, FLASH_ROW_SIZE);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rsi, %rbx
cmpl $0x3, %edi
ja 0xb44d
movl $0x804000, %ebp         # imm = 0x804000
movl %edi, %eax
leaq 0x7c7b(%rip), %rcx      # 0x13078
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8(%rbx), %rdi
movl 0x74828(%rip), %esi     # 0x7fc38
addl $-0x8, %esi
callq 0x8994
movslq 0x74819(%rip), %rcx     # 0x7fc38
movl %eax, (%rbx,%rcx)
jmp 0xb45d
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x8994
movl %eax, 0x8(%rbx)
leaq 0xe0(%rbx), %rdx
movq %rbx, %rdi
movl $0xe0, %esi
callq 0x86d8
movl $0x80c000, %ebp         # imm = 0x80C000
jmp 0xb45d
leaq 0x73d8(%rip), %rdi      # 0x1282c
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x7a0e
callq 0xb5b2
movl 0x74814(%rip), %edi     # 0x7fc7c
xorl %esi, %esi
callq 0x6ff4
movl 0x7480f(%rip), %edi     # 0x7fc84
movl %ebp, %esi
callq 0x700c
movl 0x747f6(%rip), %edi     # 0x7fc78
movl $0xa502, %esi           # imm = 0xA502
callq 0x7000
movl 0x747ee(%rip), %edi     # 0x7fc80
callq 0x6fba
testb $0x4, %al
je 0xb48c
movl %ebp, %edi
movq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x70ef
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: reset_with_extension
static void reset_with_extension(void)
{
  dap_reset_target_hw(0);
  sleep_ms(10);
  dap_reset_link();
  dap_write_byte(DSU_STATUSA, DSU_STATUSA_CRSTEXT);
}

// Assembly:
pushq %rax
xorl %edi, %edi
callq 0x6e14
pushq $0xa
popq %rdi
callq 0x7aeb
callq 0x664a
pushq $0x2
popq %rsi
movl $0x41002101, %edi       # imm = 0x41002101
popq %rax
jmp 0x6ff4
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: bootrom_expect
static int bootrom_expect(int status)
{
  uint32_t v;
  int i, res;

  for (i = 10000; i > 0; i--)
  {
    if (dap_read_byte(DSU_STATUSB) & DSU_STATUSB_BCCD1)
      break;
  }

  if (0 == i)
    error_exit("no BootROM response");

  v = dap_read_word(DSU_BCC1);

  if (SIG_PREFIX != (v & 0xffffff00))
    error_exit("invalid BootROM response prefix 0x%08x", v);

  res = v & 0xff;

  if (status != -1 && status != res)
    error_exit("invalid BootROM response 0x%02x, expected 0x%02x", res, status);

  return res;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %edi, %ebx
movl $0xffffd8ef, %ebp       # imm = 0xFFFFD8EF
incl %ebp
je 0xb530
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x6fba
testb %al, %al
jns 0xb51c
jmp 0xb53e
leaq 0x7d06(%rip), %rdi      # 0x1323d
xorl %eax, %eax
callq 0x7a0e
movl $0x41002124, %edi       # imm = 0x41002124
callq 0x6fe1
movl %eax, %ebp
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0xec000000, %eax       # imm = 0xEC000000
je 0xb566
leaq 0x7cf4(%rip), %rdi      # 0x13251
movl %ebp, %esi
xorl %eax, %eax
callq 0x7a0e
movzbl %bpl, %ebp
cmpl $-0x1, %ebx
sete %al
cmpl %ebx, %ebp
sete %cl
orb %al, %cl
jne 0xb58b
leaq 0x7cf8(%rip), %rdi      # 0x13278
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x7a0e
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_mchp_cm23.c
// Function: bootrom_park
static void bootrom_park(void)
{
  static bool in_park_mode = false;
  int response;

  if (!in_park_mode)
  {
    reset_with_extension();

    bootrom_command(CMD_EXIT);
    response = bootrom_expect(-1);

    if (SIG_BOOTOK != response)
    {
      error_exit("invalid BootROM response 0x%02x, expected 0x%02x. Check that device is not locked.",
          response, SIG_BOOTOK);
    }

    in_park_mode = true;
  }
}

// Assembly:
cmpb $0x0, 0x746cf(%rip)     # 0x7fc88
jne 0xb5f6
pushq %rax
callq 0xb4cc
movl $0xaa, %edi
callq 0xb4ef
pushq $-0x1
popq %rdi
callq 0xb512
cmpl $0x39, %eax
je 0xb5eb
leaq 0x7cca(%rip), %rdi      # 0x132a9
pushq $0x39
popq %rdx
movl %eax, %esi
xorl %eax, %eax
callq 0x7a0e
movb $0x1, 0x74696(%rip)     # 0x7fc88
addq $0x8, %rsp
retq
nop
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_st_stm32g0.c
// Function: target_erase
static void target_erase(void)
{
  dap_write_word(FLASH_CR, FLASH_CR_MER1);
  dap_write_word(FLASH_CR, FLASH_CR_MER1 | FLASH_CR_STRT);
  flash_wait_done();
  dap_write_word(FLASH_CR, 0);
}

// Assembly:
pushq %rax
pushq $0x4
popq %rsi
movl $0x40022014, %edi       # imm = 0x40022014
callq 0x700c
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x10004, %esi          # imm = 0x10004
callq 0x700c
callq 0xbab0
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
popq %rax
jmp 0x700c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_st_stm32g0.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++)
  {
    // Erase 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();

    dap_write_word(FLASH_CR, FLASH_CR_PG);

    // Program Page
    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;
    }

    verbose(".");

    flash_wait_done();
  }

  dap_write_word(FLASH_CR, 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x7449d(%rip), %eax     # 0x7fcc0
leal 0x8000000(%rax), %ebp
movq 0x744a8(%rip), %r12     # 0x7fcd8
movl $0x800, %ecx            # imm = 0x800
cltd
idivl %ecx
movq %rax, 0x8(%rsp)
movl $0x7ff, %eax            # imm = 0x7FF
addl 0x74488(%rip), %eax     # 0x7fcd0
shrl $0xb, %eax
movl %eax, 0x4(%rsp)
xorl %ebx, %ebx
xorl %ecx, %ecx
cmpl 0x4(%rsp), %ecx
je 0xb8fd
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rsp)
addl %ecx, %eax
leal 0x2(,%rax,8), %esi
movl %eax, %r15d
shll $0x3, %r15d
movl $0x40022014, %edi       # imm = 0x40022014
callq 0x700c
orl $0x10002, %r15d         # imm = 0x10002
movl $0x40022014, %edi       # imm = 0x40022014
movl %r15d, %esi
callq 0x700c
callq 0xbab0
movl $0x40022014, %edi       # imm = 0x40022014
pushq $0x1
popq %rsi
callq 0x700c
xorl %r13d, %r13d
leal (%rbx,%r13), %r14d
leal (%rbp,%r13), %r15d
cmpl $0x800, %r13d           # imm = 0x800
je 0xb8d8
movl %r14d, %esi
addq %r12, %rsi
movl %r15d, %edi
movl $0x100, %edx            # imm = 0x100
callq 0x70ef
addl $0x100, %r13d           # imm = 0x100
jmp 0xb8aa
leaq 0x4f30(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x773c
callq 0xbab0
movq 0x10(%rsp), %rcx
incl %ecx
movl %r14d, %ebx
movl %r15d, %ebp
jmp 0xb853
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x700c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_st_stm32g0.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;

  bufb = buf_alloc(FLASH_ROW_SIZE);

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

    block_size = (size > FLASH_ROW_SIZE) ? FLASH_ROW_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, bufa[offs + i], bufb[i]);
        buf_free(bufb);
        error_exit("verification failed");
      }
    }

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

    if (0 == (offs % FLASH_PAGE_SIZE))
      verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x8000000, %ebx        # imm = 0x8000000
addl 0x74393(%rip), %ebx     # 0x7fcc0
movq 0x743a4(%rip), %rbp     # 0x7fcd8
movl 0x74395(%rip), %r13d    # 0x7fcd0
movl $0x100, %edi            # imm = 0x100
callq 0x7b1b
movq %rax, %r14
xorl %r15d, %r15d
testl %r13d, %r13d
je 0xb9f3
movl %ebx, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7018
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r13d
movl $0x100, %r12d           # imm = 0x100
movl %r13d, 0x4(%rsp)
cmovbl %r13d, %r12d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0xb9c1
leal (%r15,%r13), %eax
movzbl (%rbp,%rax), %edx
movzbl (%r14,%r13), %ecx
cmpb %cl, %dl
je 0xb9bc
leal (%rbx,%r13), %esi
leaq 0x6e5e(%rip), %rdi      # 0x127fd
xorl %eax, %eax
callq 0x773c
movq %r14, %rdi
callq 0x7b3c
leaq 0x80b3(%rip), %rdi      # 0x13a68
xorl %eax, %eax
callq 0x7a0e
incq %r13
jmp 0xb97d
movl $0x100, %eax            # imm = 0x100
addq %rax, %rbx
addq %rax, %r15
movl 0x4(%rsp), %r13d
subl %r12d, %r13d
testw $0x700, %r15w           # imm = 0x700
jne 0xb94b
leaq 0x4e28(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x773c
jmp 0xb94b
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7b3c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_st_stm32g0.c
// Function: target_read
static void target_read(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.size;

  while (size)
  {
    dap_read_block(addr, &buf[offs], FLASH_ROW_SIZE);

    addr += FLASH_ROW_SIZE;
    offs += FLASH_ROW_SIZE;
    size -= FLASH_ROW_SIZE;

    verbose(".");
  }

  save_file(target_options.name, buf, target_options.size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl $0x8000000, %r15d       # imm = 0x8000000
addl 0x742a2(%rip), %r15d    # 0x7fcc0
movq 0x742b3(%rip), %rbx     # 0x7fcd8
movl 0x74299(%rip), %ebp     # 0x7fcc4
leaq 0x4ddd(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
cmpl %r12d, %ebp
je 0xba61
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7018
addl $0x100, %r12d           # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x773c
jmp 0xba35
movq 0x74250(%rip), %rdi     # 0x7fcb8
movl 0x74256(%rip), %edx     # 0x7fcc4
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7bf8
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_st_stm32g0.c
// Function: flash_wait_done
static void flash_wait_done(void)
{
  uint32_t sr;

  while (dap_read_word(FLASH_SR) & FLASH_SR_BSY1);

  sr = dap_read_word(FLASH_SR);

  if (sr & FLASH_SR_ALL_ERRORS)
    error_exit("flash operation failed. FLASH_SR = 0x%08x", sr);
}

// Assembly:
pushq %rax
movl $0x40022010, %edi       # imm = 0x40022010
callq 0x6fe1
btl $0x10, %eax
jb 0xbab1
movl $0x40022010, %edi       # imm = 0x40022010
callq 0x6fe1
testw $0xc3fa, %ax            # imm = 0xC3FA
je 0xbae2
leaq 0x796c(%rip), %rdi      # 0x13444
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7a0e
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_st_stm32wb55.c
// Function: target_erase
static void target_erase(void)
{
  int num_pages = target_flash_size / FLASH_PAGE_SIZE;

  // Mass Erase is not supported from the CPU1, so do a manual erase.
  for (int page = 0; page < num_pages; page++)
  {
    dap_write_word(FLASH_CR, FLASH_CR_PER | FLASH_CR_PNB(page));
    dap_write_word(FLASH_CR, FLASH_CR_PER | FLASH_CR_PNB(page) | FLASH_CR_STRT);
    flash_wait_done();
  }

  dap_write_word(FLASH_CR, 0);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl 0x74029(%rip), %ebx     # 0x7fd18
shrl $0x9, %ebx
andl $-0x8, %ebx
xorl %r14d, %r14d
cmpl %r14d, %ebx
je 0xbd29
leal 0x2(%r14), %esi
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x700c
movl %r14d, %esi
orl $0x10002, %esi          # imm = 0x10002
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x700c
callq 0xc02a
addl $0x8, %r14d
jmp 0xbcf8
movl $0x58004014, %edi       # imm = 0x58004014
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x700c
// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x73f8f(%rip), %ebx     # 0x7fcf8
movq 0x73fa0(%rip), %r12     # 0x7fd10
movl $0x1000, %ecx           # imm = 0x1000
movl %ebx, %eax
cltd
idivl %ecx
movl %eax, %r14d
movl $0xfff, %r15d           # imm = 0xFFF
addl 0x73f7e(%rip), %r15d    # 0x7fd08
shrl $0xc, %r15d
shll $0x3, %r14d
leaq 0x4a76(%rip), %r13      # 0x1080f
xorl %ebp, %ebp
cmpl %ebp, %r15d
je 0xbdde
leal 0x2(%r14), %esi
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x700c
movl %r14d, %esi
orl $0x10002, %esi          # imm = 0x10002
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x700c
callq 0xc02a
testb $0x3, %bpl
jne 0xbdd6
movq %r13, %rdi
xorl %eax, %eax
callq 0x773c
incl %ebp
addl $0x8, %r14d
jmp 0xbd9b
addl $0x8000000, %ebx        # imm = 0x8000000
leaq 0x6fd1(%rip), %rdi      # 0x12dbc
xorl %eax, %eax
callq 0x773c
xorl %ebp, %ebp
xorl %r13d, %r13d
movl %r15d, (%rsp)
cmpl %r15d, %r13d
je 0xbe70
movl %r13d, 0x4(%rsp)
movl $0x58004014, %edi       # imm = 0x58004014
pushq $0x1
popq %rsi
callq 0x700c
xorl %r13d, %r13d
leal (%rbp,%r13), %r14d
leal (%rbx,%r13), %r15d
cmpl $0x1000, %r13d          # imm = 0x1000
je 0xbe43
movl %r14d, %esi
addq %r12, %rsi
movl %r15d, %edi
movl $0x200, %edx            # imm = 0x200
callq 0x70ef
addl $0x200, %r13d           # imm = 0x200
jmp 0xbe15
movl 0x4(%rsp), %r13d
testb $0x3, %r13b
jne 0xbe5c
leaq 0x49ba(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x773c
callq 0xc02a
incl %r13d
movl %r14d, %ebp
movl %r15d, %ebx
movl (%rsp), %r15d
jmp 0xbdfb
movl $0x58004014, %edi       # imm = 0x58004014
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x700c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_st_stm32wb55.c
// Function: flash_wait_done
static void flash_wait_done(void)
{
  uint32_t sr;

  while (dap_read_word(FLASH_SR) & (FLASH_SR_BSY | FLASH_SR_CFGBSY));

  sr = dap_read_word(FLASH_SR);

  if (sr & FLASH_SR_ALL_ERRORS)
    error_exit("flash operation failed. FLASH_SR = 0x%08x", sr);
}

// Assembly:
pushq %rax
movl $0x58004010, %edi       # imm = 0x58004010
callq 0x6fe1
testl $0x50000, %eax          # imm = 0x50000
jne 0xc02b
movl $0x58004010, %edi       # imm = 0x58004010
callq 0x6fe1
testw $0xc3fa, %ax            # imm = 0xC3FA
je 0xc05d
leaq 0x73f1(%rip), %rdi      # 0x13444
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7a0e
popq %rax
retq
nop
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_erase
static void target_erase(void)
{
  dap_write_word(FMC_CTL, FMC_CTL_MER0 | FMC_CTL_MER1);
  dap_write_word(FMC_CTL, FMC_CTL_MER0 | FMC_CTL_MER1 | FMC_CTL_START);
  flash_wait_done();
  dap_write_word(FMC_CTL, 0);
}

// Assembly:
pushq %rax
movl $0x40023c10, %edi       # imm = 0x40023C10
movl $0x8004, %esi           # imm = 0x8004
callq 0x700c
movl $0x40023c10, %edi       # imm = 0x40023C10
movl $0x18004, %esi          # imm = 0x18004
callq 0x700c
callq 0xc68a
movl $0x40023c10, %edi       # imm = 0x40023C10
xorl %esi, %esi
popq %rax
jmp 0x700c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_lock
static void target_lock(void)
{
  uint32_t ob0 = dap_read_word(FMC_OBCTL0);
  uint32_t ob1 = dap_read_word(FMC_OBCTL1);

  ob0 |= FMC_OBCTL0_SPC(0xff); // Set low level security

  dap_write_word(FMC_OBCTL1, ob1);
  dap_write_word(FMC_OBCTL0, ob0);
  dap_write_word(FMC_OBCTL0, ob0 | FMC_OBCTL0_OB_START);
  flash_wait_done();
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x6fe1
movl %eax, %ebx
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x6fe1
movl %ebx, %ebp
orl $0xff00, %ebp           # imm = 0xFF00
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %eax, %esi
callq 0x700c
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x700c
orl $0xff02, %ebx           # imm = 0xFF02
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebx, %esi
callq 0x700c
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xc68a
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_unlock
static void target_unlock(void)
{
  uint32_t ob0 = dap_read_word(FMC_OBCTL0);
  uint32_t ob1 = dap_read_word(FMC_OBCTL1);

  ob0 = (ob0 & ~FMC_OBCTL0_SPC(0xff)) | FMC_OBCTL0_SPC(0xaa);

  dap_write_word(FMC_OBCTL1, ob1);
  dap_write_word(FMC_OBCTL0, ob0);
  dap_write_word(FMC_OBCTL0, ob0 | FMC_OBCTL0_OB_START);
  flash_wait_done();
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x6fe1
movl %eax, %ebx
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x6fe1
andl $0xffff00ff, %ebx       # imm = 0xFFFF00FF
leal 0xaa00(%rbx), %ebp
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %eax, %esi
callq 0x700c
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x700c
orl $0xaa02, %ebx           # imm = 0xAA02
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebx, %esi
callq 0x700c
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xc68a
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_gd_gd32f4xx.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;

  bufb = buf_alloc(FLASH_ALIGN_SIZE);

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

    block_size = (size > FLASH_ALIGN_SIZE) ? FLASH_ALIGN_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, bufa[offs + i], bufb[i]);
        buf_free(bufb);
        error_exit("verification failed");
      }
    }

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

    if (0 == (offs % (FLASH_ALIGN_SIZE * 64)))
      verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl $0x8000000, %ebx        # imm = 0x8000000
addl 0x738ba(%rip), %ebx     # 0x7fd38
movq 0x738cb(%rip), %rbp     # 0x7fd50
movl 0x738bc(%rip), %r13d    # 0x7fd48
movl $0x100, %edi            # imm = 0x100
callq 0x7b1b
movq %rax, %r14
xorl %r15d, %r15d
testl %r13d, %r13d
je 0xc544
movl %ebx, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7018
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r13d
movl $0x100, %r12d           # imm = 0x100
movl %r13d, 0x4(%rsp)
cmovbl %r13d, %r12d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0xc512
leal (%r15,%r13), %eax
movzbl (%rbp,%rax), %edx
movzbl (%r14,%r13), %ecx
cmpb %cl, %dl
je 0xc50d
leal (%rbx,%r13), %esi
leaq 0x630d(%rip), %rdi      # 0x127fd
xorl %eax, %eax
callq 0x773c
movq %r14, %rdi
callq 0x7b3c
leaq 0x7562(%rip), %rdi      # 0x13a68
xorl %eax, %eax
callq 0x7a0e
incq %r13
jmp 0xc4ce
movl $0x100, %eax            # imm = 0x100
addq %rax, %rbx
addq %rax, %r15
movl 0x4(%rsp), %r13d
subl %r12d, %r13d
testw $0x3f00, %r15w          # imm = 0x3F00
jne 0xc49c
leaq 0x42d7(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x773c
jmp 0xc49c
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7b3c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_read
static void target_read(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.size;

  size = round_up(size, FLASH_ALIGN_SIZE);

  while (size)
  {
    dap_read_block(addr, &buf[offs], FLASH_ALIGN_SIZE);

    addr += FLASH_ALIGN_SIZE;
    offs += FLASH_ALIGN_SIZE;
    size -= FLASH_ALIGN_SIZE;

    if (0 == (offs % (FLASH_ALIGN_SIZE * 64)))
      verbose(".");
  }

  save_file(target_options.name, buf, target_options.size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl $0x8000000, %r15d       # imm = 0x8000000
addl 0x737c9(%rip), %r15d    # 0x7fd38
movq 0x737da(%rip), %rbx     # 0x7fd50
movl 0x737c0(%rip), %edi     # 0x7fd3c
movl $0x100, %esi            # imm = 0x100
callq 0x7adc
movl %eax, %ebp
leaq 0x4280(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
cmpl %r12d, %ebp
je 0xc5c6
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7018
addl $0x100, %r12d           # imm = 0x100
testw $0x3f00, %r12w          # imm = 0x3F00
jne 0xc592
movq %r14, %rdi
xorl %eax, %eax
callq 0x773c
jmp 0xc592
movq 0x73763(%rip), %rdi     # 0x7fd30
movl 0x73769(%rip), %edx     # 0x7fd3c
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7bf8
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t value = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];
  uint32_t ob0, ob1;

  check(section < OPTIONS_COUNT, "internal: incorrect section index in target_fuse_write()");

  if (0 == section)
  {
    ob0 = value;
    ob1 = dap_read_word(FMC_OBCTL1);
  }
  else
  {
    ob0 = dap_read_word(FMC_OBCTL0);
    ob1 = value;
  }

  ob0 &= ~(FMC_OBCTL0_OB_LK | FMC_OBCTL0_OB_START);

  dap_write_word(FMC_OBCTL1, ob1);
  dap_write_word(FMC_OBCTL0, ob0);
  dap_write_word(FMC_OBCTL0, ob0 | FMC_OBCTL0_OB_START);
  flash_wait_done();
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %edi, %ebp
movl (%rsi), %ebx
xorl %edi, %edi
cmpl $0x2, %ebp
setl %dil
leaq 0x620b(%rip), %rsi      # 0x1282c
xorl %eax, %eax
callq 0x793d
testl %ebp, %ebp
je 0xc63a
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x6fe1
movl %eax, %ebp
jmp 0xc648
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x6fe1
movl %ebx, %ebp
movl %eax, %ebx
andl $-0x4, %ebp
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %ebx, %esi
callq 0x700c
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x700c
orl $0x2, %ebp
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x700c
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xc68a
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: flash_wait_done
static void flash_wait_done(void)
{
  uint32_t stat;

  while (dap_read_word(FMC_STAT) & FMC_STAT_BUSY);

  stat = dap_read_word(FMC_STAT);

  if (stat & FMC_STAT_ALL_ERRORS)
    error_exit("flash operation failed. FMC_STAT = 0x%08x", stat);
}

// Assembly:
pushq %rax
movl $0x40023c0c, %edi       # imm = 0x40023C0C
callq 0x6fe1
btl $0x10, %eax
jb 0xc68b
movl $0x40023c0c, %edi       # imm = 0x40023C0C
callq 0x6fe1
testw $0x1d2, %ax             # imm = 0x1D2
je 0xc6bc
leaq 0x6f1f(%rip), %rdi      # 0x135d1
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7a0e
popq %rax
retq
nop
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_nu_m480.c
// Function: target_erase
static void target_erase(void)
{
  dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN | FMC_ISPCTL_APUEN);

  // Bank 0
  dap_write_word(FMC_ISPADDR, 0);
  fmc_cmd(FMC_ISPCMD_BANK_ERASE, BANK_ERASE_TIME);

  // Bank 1
  dap_write_word(FMC_ISPADDR, target_device.flash_size / 2);
  fmc_cmd(FMC_ISPCMD_BANK_ERASE, BANK_ERASE_TIME);
}

// Assembly:
pushq %rbx
pushq $0x9
popq %rsi
movl $0x4000c000, %edi       # imm = 0x4000C000
callq 0x700c
movl $0x4000c004, %edi       # imm = 0x4000C004
xorl %esi, %esi
callq 0x700c
pushq $0x23
popq %rbx
movl %ebx, %edi
movl $0x140, %esi            # imm = 0x140
callq 0xccf7
movl 0x734fc(%rip), %eax     # 0x7fd70
pushq $0x2
popq %rcx
cltd
idivl %ecx
movl $0x4000c004, %edi       # imm = 0x4000C004
movl %eax, %esi
callq 0x700c
movl %ebx, %edi
movl $0x140, %esi            # imm = 0x140
popq %rbx
jmp 0xccf7
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_nu_m480.c
// Function: target_unlock
static void target_unlock(void)
{
  dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN | FMC_ISPCTL_APUEN);
  dap_write_word(FMC_UNDOCUMENTED, 1);

  dap_write_word(FMC_ISPADDR, 0);
  fmc_cmd(FMC_ISPCMD_MASS_ERASE, BANK_ERASE_TIME);

  dap_write_word(FMC_UNDOCUMENTED, 0);
}

// Assembly:
pushq %rax
pushq $0x9
popq %rsi
movl $0x4000c000, %edi       # imm = 0x4000C000
callq 0x700c
pushq $0x1
popq %rsi
movl $0x4000c01c, %edi       # imm = 0x4000C01C
callq 0x700c
movl $0x4000c004, %edi       # imm = 0x4000C004
xorl %esi, %esi
callq 0x700c
pushq $0x26
popq %rdi
movl $0x140, %esi            # imm = 0x140
callq 0xccf7
movl $0x4000c01c, %edi       # imm = 0x4000C01C
xorl %esi, %esi
popq %rax
jmp 0x700c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_nu_m480.c
// Function: target_verify
static void target_verify(void)
{
  uint32_t 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;

  bufb = buf_alloc(FLASH_PAGE_SIZE);

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

    block_size = (size > FLASH_PAGE_SIZE) ? FLASH_PAGE_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, bufa[offs + i], bufb[i]);
        buf_free(bufb);
        error_exit("verification failed");
      }
    }

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

    if (0 == (offs % (FLASH_PAGE_SIZE * STATUS_INTERVAL)))
      verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x73316(%rip), %ebx     # 0x7fd90
movq 0x73327(%rip), %rbp     # 0x7fda8
movl 0x73318(%rip), %r13d    # 0x7fda0
movl $0x1000, %edi           # imm = 0x1000
callq 0x7b1b
movq %rax, %r14
xorl %r15d, %r15d
testl %r13d, %r13d
je 0xcb40
movl %ebx, %edi
movq %r14, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7018
movl $0x1000, %eax           # imm = 0x1000
cmpl %eax, %r13d
movl $0x1000, %r12d          # imm = 0x1000
movl %r13d, 0x4(%rsp)
cmovbl %r13d, %r12d
xorl %r13d, %r13d
cmpq %r13, %r12
je 0xcb0e
leal (%r15,%r13), %eax
movzbl (%rbp,%rax), %edx
movzbl (%r14,%r13), %ecx
cmpb %cl, %dl
je 0xcb09
leal (%rbx,%r13), %esi
leaq 0x5d11(%rip), %rdi      # 0x127fd
xorl %eax, %eax
callq 0x773c
movq %r14, %rdi
callq 0x7b3c
leaq 0x6f66(%rip), %rdi      # 0x13a68
xorl %eax, %eax
callq 0x7a0e
incq %r13
jmp 0xcaca
movl $0x1000, %eax           # imm = 0x1000
addq %rax, %rbx
addq %rax, %r15
movl 0x4(%rsp), %r13d
subl %r12d, %r13d
testw $0x3000, %r15w          # imm = 0x3000
jne 0xca98
leaq 0x3cdb(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x773c
jmp 0xca98
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7b3c
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_nu_m480.c
// Function: target_read
static void target_read(void)
{
  uint32_t addr = target_options.offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.size;

  while (size)
  {
    dap_read_block(addr, &buf[offs], FLASH_PAGE_SIZE);

    addr += FLASH_PAGE_SIZE;
    offs += FLASH_PAGE_SIZE;
    size -= FLASH_PAGE_SIZE;

    if (0 == (offs % (FLASH_PAGE_SIZE * STATUS_INTERVAL)))
      verbose(".");
  }

  save_file(target_options.name, buf, target_options.size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl 0x7322b(%rip), %r15d    # 0x7fd90
movq 0x7323c(%rip), %rbx     # 0x7fda8
movl 0x73222(%rip), %ebp     # 0x7fd94
leaq 0x3c96(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
cmpl %r12d, %ebp
je 0xcbb0
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7018
addl $0x1000, %r12d          # imm = 0x1000
testw $0x3000, %r12w          # imm = 0x3000
jne 0xcb7c
movq %r14, %rdi
xorl %eax, %eax
callq 0x773c
jmp 0xcb7c
movq 0x731d1(%rip), %rdi     # 0x7fd88
movl 0x731d7(%rip), %edx     # 0x7fd94
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7bf8
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_nu_m480.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t config[CONFIG_COUNT];

  if (section >= CONFIG_COUNT)
    return;

  dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN | FMC_ISPCTL_CFGUEN);

  for (int i = 0; i < CONFIG_COUNT; i++)
    config[i] = fmc_read(CONFIG0 + i*4);

  config[section] = *(uint32_t *)data;
  config[0] |= CONFIG0_ICELOCK; // Make sure ICE is never locked for now

  dap_write_word(FMC_ISPADDR, CONFIG0);
  fmc_cmd(FMC_ISPCMD_PAGE_ERASE, PAGE_ERASE_TIME);

  for (int i = 0; i < CONFIG_COUNT; i++)
    fmc_write(CONFIG0 + i*4, config[i]);
}

// Assembly:
cmpl $0x3, %edi
jg 0xcc99
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movl %edi, %ebx
pushq $0x11
popq %rsi
movl $0x4000c000, %edi       # imm = 0x4000C000
callq 0x700c
xorl %r15d, %r15d
cmpq $0x10, %r15
je 0xcc4a
movl %r15d, %edi
orl $0x300000, %edi         # imm = 0x300000
callq 0xccaa
movl %eax, (%rsp,%r15)
addq $0x4, %r15
jmp 0xcc2c
movl (%r14), %eax
movslq %ebx, %rcx
movl %eax, (%rsp,%rcx,4)
orb $0x8, 0x1(%rsp)
movl $0x4000c004, %edi       # imm = 0x4000C004
movl $0x300000, %esi         # imm = 0x300000
callq 0x700c
pushq $0x22
popq %rdi
pushq $0x50
popq %rsi
callq 0xccf7
xorl %ebx, %ebx
cmpq $0x10, %rbx
je 0xcc90
movl (%rsp,%rbx), %esi
movl %ebx, %edi
orl $0x300000, %edi         # imm = 0x300000
callq 0xcd57
addq $0x4, %rbx
jmp 0xcc74
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_nu_m480.c
// Function: fmc_read
static uint32_t fmc_read(uint32_t addr)
{
  dap_write_word(FMC_ISPCMD, FMC_ISPCMD_READ);
  dap_write_word(FMC_ISPADDR, addr);
  dap_write_word(FMC_ISPDAT, 0);
  dap_write_word(FMC_ISPTRG, FMC_ISPTRG_ISPGO);
  while (dap_read_word(FMC_ISPTRG));
  return dap_read_word(FMC_ISPDAT);
}

// Assembly:
pushq %rbx
movl %edi, %ebx
movl $0x4000c00c, %edi       # imm = 0x4000C00C
xorl %esi, %esi
callq 0x700c
movl $0x4000c004, %edi       # imm = 0x4000C004
movl %ebx, %esi
callq 0x700c
movl $0x4000c008, %edi       # imm = 0x4000C008
xorl %esi, %esi
callq 0x700c
pushq $0x1
popq %rsi
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x700c
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x6fe1
testl %eax, %eax
jne 0xccde
movl $0x4000c008, %edi       # imm = 0x4000C008
popq %rbx
jmp 0x6fe1
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_nu_m480.c
// Function: fmc_cmd
static void fmc_cmd(int cmd, int delay)
{
  uint32_t sts;

  dap_write_word(FMC_ISPCMD, cmd);
  dap_write_word(FMC_ISPTRG, FMC_ISPTRG_ISPGO);

  if (delay)
    sleep_ms(delay);

  while (dap_read_word(FMC_ISPTRG));

  sts = dap_read_word(FMC_ISPSTS);
  if (sts & FMC_ISPSTS_ISPFF)
    error_exit("flash error while executing command 0x%02x", cmd);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebp
movl %edi, %ebx
movl $0x4000c00c, %edi       # imm = 0x4000C00C
movl %ebx, %esi
callq 0x700c
pushq $0x1
popq %rsi
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x700c
movl %ebp, %edi
callq 0x7aeb
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x6fe1
testl %eax, %eax
jne 0xcd1e
movl $0x4000c040, %edi       # imm = 0x4000C040
callq 0x6fe1
testb $0x40, %al
jne 0xcd41
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x69d1(%rip), %rdi      # 0x13719
movl %ebx, %esi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x7a0e
// File: /workspace/github_c_makefile_star2_O2/ataradov[P]edbg/target_nu_m480.c
// Function: fmc_write
static void fmc_write(uint32_t addr, uint32_t data)
{
  dap_write_word(FMC_ISPCMD, FMC_ISPCMD_32B_PROG);
  dap_write_word(FMC_ISPADDR, addr);
  dap_write_word(FMC_ISPDAT, data);
  dap_write_word(FMC_ISPTRG, FMC_ISPTRG_ISPGO);
  while (dap_read_word(FMC_ISPTRG));
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %ebp
pushq $0x21
popq %rsi
movl $0x4000c00c, %edi       # imm = 0x4000C00C
callq 0x700c
movl $0x4000c004, %edi       # imm = 0x4000C004
movl %ebp, %esi
callq 0x700c
movl $0x4000c008, %edi       # imm = 0x4000C008
movl %ebx, %esi
callq 0x700c
pushq $0x1
popq %rsi
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x700c
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x6fe1
testl %eax, %eax
jne 0xcd90
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax)