LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/ataradov[P]edbg/target_atmel_cm7.c
// Function: target_fuse_read
static int target_fuse_read(int section, uint8_t *data)
{
  uint32_t gpnvm;

  if (section > 0)
    return 0;

  dap_write_word(EEFC_FCR, CMD_GGPB);
  while (0 == (dap_read_word(EEFC_FSR) & FSR_FRDY));
  gpnvm = dap_read_word(EEFC_FRR);

  data[0] = gpnvm;
  data[1] = gpnvm >> 8;

  return GPNVM_SIZE;
}

// Assembly:
xorl %eax, %eax
testl %edi, %edi
jle 0xae29
retq
pushq %rbx
movq %rsi, %rbx
movl $0x400e0c04, %edi       # imm = 0x400E0C04
movl $0x5a00000d, %esi       # imm = 0x5A00000D
callq 0x7269
movl $0x400e0c08, %edi       # imm = 0x400E0C08
callq 0x721a
testb $0x1, %al
je 0xae3c
movl $0x400e0c0c, %edi       # imm = 0x400E0C0C
callq 0x721a
movw %ax, (%rbx)
movl $0x2, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/ataradov[P]edbg/target_atmel_cm7.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t gpnvm = (data[1] << 8) | data[0];

  check(0 == section, "internal: incorrect section index in target_fuse_write()");

  for (int i = 0; i < GPNVM_SIZE_BITS; i++)
  {
    if (gpnvm & (1 << i))
      dap_write_word(EEFC_FCR, CMD_SGPB | (i << 8));
    else
      dap_write_word(EEFC_FCR, CMD_CGPB | (i << 8));
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movzwl (%rsi), %ebx
xorl %eax, %eax
testl %edi, %edi
sete %al
leaq 0x79b9(%rip), %rsi      # 0x1282c
xorl %ebp, %ebp
movl %eax, %edi
xorl %eax, %eax
callq 0x7bcc
xorl %r14d, %r14d
btl %r14d, %ebx
movl %ebp, %esi
sbbl $-0x1, %esi
addl $0x5a00000b, %esi       # imm = 0x5A00000B
movl $0x400e0c04, %edi       # imm = 0x400E0C04
callq 0x7269
incl %r14d
addl $0x100, %ebp            # imm = 0x100
cmpl $0x900, %ebp            # imm = 0x900
jne 0xae81
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/ataradov[P]edbg/target_atmel_cm4v2.c
// Function: target_erase
static void target_erase(void)
{
  dap_write_byte(DSU_CTRL, DSU_CTRL_CE); // Chip erase
  sleep_ms(100);
  while (0 == (dap_read_byte(DSU_STATUSA) & DSU_STATUSA_DONE));

  reset_with_extension();
  finish_reset();
}

// Assembly:
pushq %rax
movl $0x41002100, %edi       # imm = 0x41002100
movl $0x10, %esi
callq 0x7238
movl $0x64, %edi
callq 0x7d8c
movl $0x41002101, %edi       # imm = 0x41002101
callq 0x71e0
testb $0x1, %al
je 0xb020
xorl %edi, %edi
callq 0x7013
movl $0xa, %edi
callq 0x7d8c
callq 0x6789
popq %rax
jmp 0xb3eb
// File: /workspace/github_c_makefile_star2_O3/ataradov[P]edbg/target_atmel_cm4v2.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t addr = USER_ROW_ADDR;

  check(0 == section, "internal: incorrect section index in target_fuse_write()");

  dap_write_word(NVMCTRL_ADDR, USER_ROW_ADDR);

  dap_write_half(NVMCTRL_CTRLB, NVMCTRL_CMD_EP);
  while (0 == (dap_read_half(NVMCTRL_STATUS) & NVMCTRL_STATUS_READY));

  dap_write_half(NVMCTRL_CTRLB, NVMCTRL_CMD_PBC);
  while (0 == (dap_read_half(NVMCTRL_STATUS) & NVMCTRL_STATUS_READY));

  for (int i = 0; i < (USER_ROW_SIZE / USER_ROW_PAGE_SIZE); i++)
  {
    dap_write_word(NVMCTRL_ADDR, USER_ROW_ADDR);

    dap_write_block(addr, data, USER_ROW_PAGE_SIZE);

    dap_write_half(NVMCTRL_CTRLB, NVMCTRL_CMD_WQW);
    while (0 == (dap_read_half(NVMCTRL_STATUS) & NVMCTRL_STATUS_READY));

    addr += USER_ROW_PAGE_SIZE;
    data += USER_ROW_PAGE_SIZE;
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
xorl %eax, %eax
testl %edi, %edi
sete %al
leaq 0x7507(%rip), %rsi      # 0x1282c
movl %eax, %edi
xorl %eax, %eax
callq 0x7bcc
movl $0x41004014, %edi       # imm = 0x41004014
movl $0x804000, %esi         # imm = 0x804000
callq 0x7269
movl $0x41004004, %edi       # imm = 0x41004004
movl $0xa500, %esi           # imm = 0xA500
callq 0x724f
movl $0x41004012, %edi       # imm = 0x41004012
callq 0x71fb
testb $0x1, %al
je 0xb34c
movl $0x41004004, %edi       # imm = 0x41004004
movl $0xa515, %esi           # imm = 0xA515
callq 0x724f
movl $0x41004012, %edi       # imm = 0x41004012
callq 0x71fb
testb $0x1, %al
je 0xb369
movl $0x804000, %ebp         # imm = 0x804000
xorl %r14d, %r14d
movl $0x41004014, %edi       # imm = 0x41004014
movl $0x804000, %esi         # imm = 0x804000
callq 0x7269
movl %ebp, %edi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x73df
movl $0x41004004, %edi       # imm = 0x41004004
movl $0xa504, %esi           # imm = 0xA504
callq 0x724f
movl $0x41004012, %edi       # imm = 0x41004012
callq 0x71fb
testb $0x1, %al
je 0xb3ac
addl $0x10, %ebp
addq $0x10, %rbx
incl %r14d
cmpl $0x20, %r14d
jne 0xb37f
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0xb9c4
movl $0x41002118, %edi       # imm = 0x41002118
callq 0x721a
movl %eax, %ecx
andl $0xfffff0ff, %ecx       # imm = 0xFFFFF0FF
movl %eax, %edx
shrl $0x8, %edx
andl $0xf, %edx
xorl %r14d, %r14d
leaq 0xf583(%rip), %r15      # 0x1a9e0
cmpl %ecx, (%r14,%r15)
je 0xb485
addq $0x28, %r14
cmpq $0x2f8, %r14            # imm = 0x2F8
jne 0xb45d
leaq 0x6bda(%rip), %rdi      # 0x12051
movl %eax, %esi
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x7ca5
movq 0x10(%r14,%r15), %rsi
addl $0x41, %edx
leaq 0x6b82(%rip), %rdi      # 0x12016
xorl %eax, %eax
callq 0x7a90
movq 0x20(%r14,%r15), %rax
movq %rax, 0x73791(%rip)     # 0x7ec38
movups (%r14,%r15), %xmm0
movups 0x10(%r14,%r15), %xmm1
movups %xmm1, 0x7376f(%rip)    # 0x7ec28
movups %xmm0, 0x73758(%rip)    # 0x7ec18
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm0, 0x7376e(%rip)    # 0x7ec40
movups %xmm1, 0x73777(%rip)    # 0x7ec50
movups %xmm2, 0x73780(%rip)    # 0x7ec60
movq 0x30(%rbx), %rax
movq %rax, 0x73785(%rip)     # 0x7ec70
leaq 0x7374e(%rip), %rdi     # 0x7ec40
movzbl 0x7373b(%rip), %eax     # 0x7ec34
shll $0xc, %eax
leal 0x41004000(%rax), %ecx
leal 0x41004008(%rax), %edx
leal 0x41004018(%rax), %esi
orl $0x4100401c, %eax       # imm = 0x4100401C
movl %ecx, 0x7375f(%rip)     # 0x7ec78
movl %edx, 0x7375d(%rip)     # 0x7ec7c
movl %esi, 0x7375b(%rip)     # 0x7ec80
movl %eax, 0x73759(%rip)     # 0x7ec84
movl 0x736ff(%rip), %esi     # 0x7ec30
movl $0x100, %edx            # imm = 0x100
popq %rbx
popq %r14
popq %r15
jmp 0x8ec8
// File: /workspace/github_c_makefile_star2_O3/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 0xb9c4
movl $0xa, %edi
callq 0x7d8c
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71e0
testb %al, %al
js 0xb580
movl $0x55, %edi
callq 0xb9eb
movl $0x20, %edi
callq 0xba0e
jmp 0xb59a
movl $0x41002124, %edi       # imm = 0x41002124
callq 0x721a
leaq 0x7c68(%rip), %rdi      # 0x131f9
movl %eax, %esi
xorl %eax, %eax
callq 0x62f0
cmpb $0x1, 0x73693(%rip)     # 0x7ec34
jne 0xb5cd
movl $0xe2, %edi
callq 0xb9eb
movl $0x24, %edi
callq 0xba0e
callq 0xba91
callq 0xba91
callq 0xba91
callq 0xba91
jmp 0xb5e1
movl $0xe3, %edi
callq 0xb9eb
movl $0x24, %edi
callq 0xba0e
movl $0x21, %edi
popq %rax
jmp 0xba0e
// File: /workspace/github_c_makefile_star2_O3/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 0x73634(%rip), %ebx     # 0x7ec58
movq 0x73645(%rip), %r15     # 0x7ec70
movl 0x73637(%rip), %ebp     # 0x7ec68
callq 0xbab1
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71e0
andb $0x3, %al
cmpb $0x2, %al
je 0xb654
leaq 0x7caf(%rip), %rdi      # 0x132fc
xorl %eax, %eax
callq 0x7ca5
addl $0xff, %ebp
movl 0x7361c(%rip), %edi     # 0x7ec7c
xorl %esi, %esi
callq 0x7238
cmpl $0x100, %ebp            # imm = 0x100
jb 0xb6da
shrl $0x8, %ebp
leaq 0x5196(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
xorl %r13d, %r13d
movl 0x735ff(%rip), %edi     # 0x7ec84
movl %ebx, %esi
callq 0x7269
movl 0x735e6(%rip), %edi     # 0x7ec78
movl $0xa502, %esi           # imm = 0xA502
callq 0x724f
movl 0x735de(%rip), %edi     # 0x7ec80
callq 0x71e0
testb $0x4, %al
je 0xb69c
leaq (%r15,%r12), %rsi
movl %ebx, %edi
movl $0x100, %edx            # imm = 0x100
callq 0x73df
addl $0x100, %ebx            # imm = 0x100
addq $0x100, %r12            # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a90
incl %r13d
cmpl %ebp, %r13d
jne 0xb67f
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movl 0x7355b(%rip), %ebx     # 0x7ec58
movq 0x7356c(%rip), %rax     # 0x7ec70
movq %rax, 0x10(%rsp)
movl 0x73558(%rip), %r12d    # 0x7ec68
callq 0xbab1
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71e0
andb $0x3, %al
cmpb $0x2, %al
je 0xb733
leaq 0x7c19(%rip), %rdi      # 0x13345
xorl %eax, %eax
callq 0x7ca5
movl $0x100, %edi            # imm = 0x100
callq 0x7dd2
movq %rax, %r14
testl %r12d, %r12d
je 0xb7ee
leaq 0x8318(%rip), %r13      # 0x13a68
xorl %ebp, %ebp
movl %ebp, 0x8(%rsp)
movl %ebp, %ebp
addq 0x10(%rsp), %rbp
movl %ebx, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7283
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r12d
movl $0x100, %r15d           # imm = 0x100
movl %r12d, 0xc(%rsp)
cmovbl %r12d, %r15d
xorl %r12d, %r12d
movzbl (%rbp,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xb7b9
leal (%rbx,%r12), %esi
leaq 0x705d(%rip), %rdi      # 0x127fd
xorl %eax, %eax
callq 0x7a90
movq %r14, %rdi
callq 0x7df5
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ca5
incq %r12
cmpq %r12, %r15
jne 0xb786
addq $0x100, %rbx            # imm = 0x100
movl 0x8(%rsp), %ebp
addl $0x100, %ebp            # imm = 0x100
leaq 0x5036(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x7a90
movl 0xc(%rsp), %r12d
subl %r15d, %r12d
jne 0xb752
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7df5
// File: /workspace/github_c_makefile_star2_O3/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 0x73445(%rip), %r15d    # 0x7ec58
movq 0x73456(%rip), %rbx     # 0x7ec70
movl 0x7343c(%rip), %ebp     # 0x7ec5c
callq 0xbab1
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71e0
andb $0x3, %al
cmpb $0x2, %al
je 0xb843
leaq 0x7b3b(%rip), %rdi      # 0x13377
xorl %eax, %eax
callq 0x7ca5
testl %ebp, %ebp
je 0xb87b
leaq 0x4fc1(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7283
addl $0x100, %r12d           # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a90
cmpl %r12d, %ebp
jne 0xb851
movq 0x733ce(%rip), %rdi     # 0x7ec50
movl 0x733d4(%rip), %edx     # 0x7ec5c
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7ea3
// File: /workspace/github_c_makefile_star2_O3/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 0xb8b3
xorl %ebp, %ebp
cmpl $0x1, %edi
jne 0xb8d3
movl $0x80c000, %r14d        # imm = 0x80C000
jmp 0xb8b9
movl $0x804000, %r14d        # imm = 0x804000
callq 0xbab1
movl $0x100, %ebp            # imm = 0x100
movl %r14d, %edi
movq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7283
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0xb945
movl $0x804000, %ebp         # imm = 0x804000
movl %edi, %eax
leaq 0x7785(%rip), %rcx      # 0x13078
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8(%rbx), %rdi
movl 0x73332(%rip), %esi     # 0x7ec38
addl $-0x8, %esi
callq 0x8cac
movslq 0x73323(%rip), %rcx     # 0x7ec38
movl %eax, (%rbx,%rcx)
jmp 0xb955
movq %rbx, %rdi
movl $0x8, %esi
callq 0x8cac
movl %eax, 0x8(%rbx)
leaq 0xe0(%rbx), %rdx
movq %rbx, %rdi
movl $0xe0, %esi
callq 0x89d8
movl $0x80c000, %ebp         # imm = 0x80C000
jmp 0xb955
leaq 0x6ee0(%rip), %rdi      # 0x1282c
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x7ca5
callq 0xbab1
movl 0x7331c(%rip), %edi     # 0x7ec7c
xorl %esi, %esi
callq 0x7238
movl 0x73317(%rip), %edi     # 0x7ec84
movl %ebp, %esi
callq 0x7269
movl 0x732fe(%rip), %edi     # 0x7ec78
movl $0xa502, %esi           # imm = 0xA502
callq 0x724f
movl 0x732f6(%rip), %edi     # 0x7ec80
callq 0x71e0
testb $0x4, %al
je 0xb984
movl %ebp, %edi
movq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x73df
// File: /workspace/github_c_makefile_star2_O3/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 0x7013
movl $0xa, %edi
callq 0x7d8c
callq 0x6789
movl $0x41002101, %edi       # imm = 0x41002101
movl $0x2, %esi
popq %rax
jmp 0x7238
// File: /workspace/github_c_makefile_star2_O3/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 $0x2711, %ebp           # imm = 0x2711
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71e0
testb %al, %al
js 0xba3b
decl %ebp
cmpl $0x1, %ebp
ja 0xba18
leaq 0x7809(%rip), %rdi      # 0x1323d
xorl %eax, %eax
callq 0x7ca5
movl $0x41002124, %edi       # imm = 0x41002124
callq 0x721a
movl %eax, %ebp
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0xec000000, %eax       # imm = 0xEC000000
je 0xba63
leaq 0x77f7(%rip), %rdi      # 0x13251
movl %ebp, %esi
xorl %eax, %eax
callq 0x7ca5
movzbl %bpl, %ebp
cmpl $-0x1, %ebx
sete %al
cmpl %ebx, %ebp
sete %cl
orb %al, %cl
jne 0xba88
leaq 0x77fb(%rip), %rdi      # 0x13278
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x7ca5
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x4, %esi
callq 0x7269
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x10004, %esi          # imm = 0x10004
callq 0x7269
callq 0xbfde
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
popq %rax
jmp 0x7269
// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movl 0x72f89(%rip), %r14d    # 0x7ecc0
movl $0x7ff, %r15d           # imm = 0x7FF
leal (%r14,%r15), %eax
testl %r14d, %r14d
cmovnsl %r14d, %eax
movq %rax, (%rsp)
addl 0x72f7d(%rip), %r15d    # 0x7ecd0
cmpl $0x800, %r15d           # imm = 0x800
jb 0xbe0d
movq 0x72f71(%rip), %r13     # 0x7ecd8
movq (%rsp), %rax
sarl $0xb, %eax
movq %rax, (%rsp)
shrl $0xb, %r15d
addl $0x8000000, %r14d       # imm = 0x8000000
xorl %ebx, %ebx
xorl %r12d, %r12d
movq (%rsp), %rax
addl %ebx, %eax
leal 0x2(,%rax,8), %esi
movl %eax, %ebp
shll $0x3, %ebp
movl $0x40022014, %edi       # imm = 0x40022014
callq 0x7269
orl $0x10002, %ebp          # imm = 0x10002
movl $0x40022014, %edi       # imm = 0x40022014
movl %ebp, %esi
callq 0x7269
callq 0xbfde
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x1, %esi
callq 0x7269
xorl %ebp, %ebp
leal (%r14,%rbp), %edi
leal (%r12,%rbp), %esi
addq %r13, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x73df
addl $0x100, %ebp            # imm = 0x100
cmpl $0x800, %ebp            # imm = 0x800
jne 0xbdc6
leaq 0x4a1f(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x7a90
callq 0xbfde
incl %ebx
addl %ebp, %r14d
addl %ebp, %r12d
cmpl %r15d, %ebx
jne 0xbd82
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7269
// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movl 0x72e85(%rip), %ebx     # 0x7ecc0
movq 0x72e96(%rip), %rax     # 0x7ecd8
movq %rax, 0x10(%rsp)
movl 0x72e82(%rip), %r12d    # 0x7ecd0
movl $0x100, %edi            # imm = 0x100
callq 0x7dd2
movq %rax, %r14
testl %r12d, %r12d
je 0xbf1b
addl $0x8000000, %ebx        # imm = 0x8000000
leaq 0x7bf7(%rip), %r13      # 0x13a68
xorl %r15d, %r15d
movl %r15d, 0x8(%rsp)
movl %r15d, %r15d
addq 0x10(%rsp), %r15
movl %ebx, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7283
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r12d
movl $0x100, %ebp            # imm = 0x100
movl %r12d, 0xc(%rsp)
cmovbl %r12d, %ebp
xorl %r12d, %r12d
movzbl (%r15,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xbedb
leal (%rbx,%r12), %esi
leaq 0x693b(%rip), %rdi      # 0x127fd
xorl %eax, %eax
callq 0x7a90
movq %r14, %rdi
callq 0x7df5
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ca5
incq %r12
cmpq %r12, %rbp
jne 0xbea9
movl 0x8(%rsp), %r15d
addl $0x100, %r15d           # imm = 0x100
testl $0x700, %r15d           # imm = 0x700
jne 0xbf06
leaq 0x4910(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x7a90
addq $0x100, %rbx            # imm = 0x100
movl 0xc(%rsp), %r12d
subl %ebp, %r12d
jne 0xbe74
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7df5
// File: /workspace/github_c_makefile_star2_O3/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
movq 0x72d98(%rip), %rbx     # 0x7ecd8
movl 0x72d7e(%rip), %ebp     # 0x7ecc4
testl %ebp, %ebp
je 0xbf93
movl $0x8000000, %r15d       # imm = 0x8000000
addl 0x72d69(%rip), %r15d    # 0x7ecc0
leaq 0x48b1(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7283
addl $0x100, %r12d           # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a90
cmpl %r12d, %ebp
jne 0xbf61
movl 0x72d33(%rip), %edx     # 0x7ecc4
jmp 0xbf95
xorl %edx, %edx
movq 0x72d1c(%rip), %rdi     # 0x7ecb8
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7ea3
// File: /workspace/github_c_makefile_star2_O3/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 0x721a
btl $0x10, %eax
jb 0xbfdf
movl $0x40022010, %edi       # imm = 0x40022010
callq 0x721a
testl $0xc3fa, %eax           # imm = 0xC3FA
je 0xc011
leaq 0x743d(%rip), %rdi      # 0x13444
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7ca5
popq %rax
retq
nop
// File: /workspace/github_c_makefile_star2_O3/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 0x72af1(%rip), %ebx     # 0x7ed18
cmpl $0x1000, %ebx           # imm = 0x1000
jb 0xc267
shrl $0xc, %ebx
shll $0x3, %ebx
xorl %r14d, %r14d
leal 0x2(%r14), %esi
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x7269
movl %r14d, %esi
orl $0x10002, %esi          # imm = 0x10002
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x7269
callq 0xc58e
addl $0x8, %r14d
cmpl %r14d, %ebx
jne 0xc238
movl $0x58004014, %edi       # imm = 0x58004014
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x7269
// File: /workspace/github_c_makefile_star2_O3/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 0x72a50(%rip), %r14d    # 0x7ecf8
movl $0xfff, %r12d           # imm = 0xFFF
leal (%r14,%r12), %r13d
testl %r14d, %r14d
cmovnsl %r14d, %r13d
addl 0x72a48(%rip), %r12d    # 0x7ed08
cmpl $0x1000, %r12d          # imm = 0x1000
jae 0xc2dc
leaq 0x6aec(%rip), %rdi      # 0x12dbc
xorl %eax, %eax
callq 0x7a90
jmp 0xc3b5
addl $0x8000000, %r14d       # imm = 0x8000000
movq 0x72a26(%rip), %r15     # 0x7ed10
sarl $0xc, %r13d
movl %r12d, %ebp
shrl $0xc, %ebp
shll $0x3, %r13d
xorl %ebx, %ebx
leal 0x2(%r13), %esi
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x7269
movl %r13d, %esi
orl $0x10002, %esi          # imm = 0x10002
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x7269
callq 0xc58e
testb $0x3, %bl
jne 0xc333
leaq 0x44e3(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x7a90
incl %ebx
addl $0x8, %r13d
cmpl %ebx, %ebp
jne 0xc2fa
leaq 0x6a78(%rip), %rdi      # 0x12dbc
xorl %eax, %eax
callq 0x7a90
cmpl $0x1000, %r12d          # imm = 0x1000
jb 0xc3b5
xorl %r12d, %r12d
xorl %r13d, %r13d
movl $0x58004014, %edi       # imm = 0x58004014
movl $0x1, %esi
callq 0x7269
xorl %ebx, %ebx
leal (%r14,%rbx), %edi
leal (%rbx,%r13), %esi
addq %r15, %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x73df
addl $0x200, %ebx            # imm = 0x200
cmpl $0x1000, %ebx           # imm = 0x1000
jne 0xc36b
testb $0x3, %r12b
jne 0xc3a2
leaq 0x4474(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x7a90
addl %ebx, %r14d
addl %ebx, %r13d
callq 0xc58e
incl %r12d
cmpl %ebp, %r12d
jne 0xc35a
movl $0x58004014, %edi       # imm = 0x58004014
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7269
// File: /workspace/github_c_makefile_star2_O3/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 0x721a
testl $0x50000, %eax          # imm = 0x50000
jne 0xc58f
movl $0x58004010, %edi       # imm = 0x58004010
callq 0x721a
testl $0xc3fa, %eax           # imm = 0xC3FA
je 0xc5c2
leaq 0x6e8c(%rip), %rdi      # 0x13444
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7ca5
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x7269
movl $0x40023c10, %edi       # imm = 0x40023C10
movl $0x18004, %esi          # imm = 0x18004
callq 0x7269
callq 0xcc33
movl $0x40023c10, %edi       # imm = 0x40023C10
xorl %esi, %esi
popq %rax
jmp 0x7269
// File: /workspace/github_c_makefile_star2_O3/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 0x721a
movl %eax, %ebx
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x721a
movl %ebx, %ebp
orl $0xff00, %ebp           # imm = 0xFF00
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %eax, %esi
callq 0x7269
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x7269
orl $0xff02, %ebx           # imm = 0xFF02
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebx, %esi
callq 0x7269
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xcc33
// File: /workspace/github_c_makefile_star2_O3/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 0x721a
movl %eax, %ebx
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x721a
andl $0xffff00ff, %ebx       # imm = 0xFFFF00FF
leal 0xaa00(%rbx), %ebp
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %eax, %esi
callq 0x7269
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x7269
orl $0xaa02, %ebx           # imm = 0xAA02
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebx, %esi
callq 0x7269
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xcc33
// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movl 0x72331(%rip), %ebx     # 0x7ed38
movq 0x72342(%rip), %rax     # 0x7ed50
movq %rax, 0x10(%rsp)
movl 0x7232e(%rip), %r12d    # 0x7ed48
movl $0x100, %edi            # imm = 0x100
callq 0x7dd2
movq %rax, %r14
testl %r12d, %r12d
je 0xcae7
addl $0x8000000, %ebx        # imm = 0x8000000
leaq 0x702b(%rip), %r13      # 0x13a68
xorl %r15d, %r15d
movl %r15d, 0x8(%rsp)
movl %r15d, %r15d
addq 0x10(%rsp), %r15
movl %ebx, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7283
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r12d
movl $0x100, %ebp            # imm = 0x100
movl %r12d, 0xc(%rsp)
cmovbl %r12d, %ebp
xorl %r12d, %r12d
movzbl (%r15,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xcaa7
leal (%rbx,%r12), %esi
leaq 0x5d6f(%rip), %rdi      # 0x127fd
xorl %eax, %eax
callq 0x7a90
movq %r14, %rdi
callq 0x7df5
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ca5
incq %r12
cmpq %r12, %rbp
jne 0xca75
movl 0x8(%rsp), %r15d
addl $0x100, %r15d           # imm = 0x100
testl $0x3f00, %r15d          # imm = 0x3F00
jne 0xcad2
leaq 0x3d44(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x7a90
addq $0x100, %rbx            # imm = 0x100
movl 0xc(%rsp), %r12d
subl %ebp, %r12d
jne 0xca40
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7df5
// File: /workspace/github_c_makefile_star2_O3/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 0x7222c(%rip), %r15d    # 0x7ed38
movq 0x7223d(%rip), %rbx     # 0x7ed50
movl 0x72223(%rip), %edi     # 0x7ed3c
movl $0x100, %esi            # imm = 0x100
callq 0x7d7d
testl %eax, %eax
je 0xcb6d
movl %eax, %ebp
addl $0x8000000, %r15d       # imm = 0x8000000
leaq 0x3cd8(%rip), %r14      # 0x1080f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7283
addl $0x100, %r12d           # imm = 0x100
testl $0x3f00, %r12d          # imm = 0x3F00
jne 0xcb68
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a90
cmpl %r12d, %ebp
jne 0xcb3a
movq 0x721bc(%rip), %rdi     # 0x7ed30
movl 0x721c2(%rip), %edx     # 0x7ed3c
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7ea3
// File: /workspace/github_c_makefile_star2_O3/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 0x5c62(%rip), %rsi      # 0x1282c
xorl %eax, %eax
callq 0x7bcc
testl %ebp, %ebp
je 0xcbe3
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x721a
movl %eax, %ebp
jmp 0xcbf1
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x721a
movl %ebx, %ebp
movl %eax, %ebx
andl $-0x4, %ebp
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %ebx, %esi
callq 0x7269
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x7269
orl $0x2, %ebp
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x7269
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xcc33
// File: /workspace/github_c_makefile_star2_O3/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 0x721a
btl $0x10, %eax
jb 0xcc34
movl $0x40023c0c, %edi       # imm = 0x40023C0C
callq 0x721a
testl $0x1d2, %eax            # imm = 0x1D2
je 0xcc66
leaq 0x6975(%rip), %rdi      # 0x135d1
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7ca5
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O3/ataradov[P]edbg/target_nu_m480.c
// Function: target_select
static void target_select(target_options_t *options)
{
  uint32_t idcode;
  bool locked;

  dap_disconnect();
  dap_connect(DAP_INTERFACE_SWD);
  dap_reset_pin(0);
  dap_reset_link();

  // Stop the core
  dap_write_word(DHCSR, DHCSR_DBGKEY | DHCSR_DEBUGEN | DHCSR_HALT);
  dap_write_word(DEMCR, DEMCR_VC_CORERESET);
  dap_write_word(AIRCR, AIRCR_VECTKEY | AIRCR_SYSRESETREQ);

  dap_reset_pin(1);
  sleep_ms(10);

  idcode = dap_read_word(SYS_PDID);

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

    verbose("Target: %s\n", devices[i].name);

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

    target_check_options(&target_options, devices[i].flash_size, FLASH_PAGE_SIZE);

    dap_write_word(SYS_REGLCTL, 0x59);
    dap_write_word(SYS_REGLCTL, 0x16);
    dap_write_word(SYS_REGLCTL, 0x88);

    dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN);

    locked = (0 == (fmc_read(CONFIG0) & CONFIG0_LOCK));

    if (locked && !options->unlock)
      error_exit("target is locked, unlock is necessary");

    return;
  }

  error_exit("unknown target device (SYS_PDID = 0x%08x)", idcode);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x65ab
movl $0x1, %edi
callq 0x654e
xorl %edi, %edi
callq 0x709f
callq 0x6789
movl $0xe000edf0, %edi       # imm = 0xE000EDF0
movl $0xa05f0003, %esi       # imm = 0xA05F0003
callq 0x7269
movl $0xe000edfc, %edi       # imm = 0xE000EDFC
movl $0x1, %esi
callq 0x7269
movl $0xe000ed0c, %edi       # imm = 0xE000ED0C
movl $0x5fa0004, %esi        # imm = 0x5FA0004
callq 0x7269
movl $0x1, %edi
callq 0x709f
movl $0xa, %edi
callq 0x7d8c
movl $0x40000000, %edi       # imm = 0x40000000
callq 0x721a
cmpl $0xd48410, %eax         # imm = 0xD48410
jne 0xcda1
leaq 0x5b81(%rip), %rdi      # 0x12865
leaq 0x6a24(%rip), %rsi      # 0x1370f
xorl %eax, %eax
callq 0x7a90
movaps 0xe027(%rip), %xmm0     # 0x1ad20
movups %xmm0, 0x72068(%rip)    # 0x7ed68
movaps 0xe009(%rip), %xmm0     # 0x1ad10
movups %xmm0, 0x7204a(%rip)    # 0x7ed58
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm0, 0x72058(%rip)    # 0x7ed78
movups %xmm1, 0x72061(%rip)    # 0x7ed88
movups %xmm2, 0x7206a(%rip)    # 0x7ed98
movq 0x30(%rbx), %rax
movq %rax, 0x7206f(%rip)     # 0x7eda8
leaq 0x72038(%rip), %rdi     # 0x7ed78
movl $0x80000, %esi          # imm = 0x80000
movl $0x1000, %edx           # imm = 0x1000
callq 0x8ec8
movl $0x40000100, %edi       # imm = 0x40000100
movl $0x59, %esi
callq 0x7269
movl $0x40000100, %edi       # imm = 0x40000100
movl $0x16, %esi
callq 0x7269
movl $0x40000100, %edi       # imm = 0x40000100
movl $0x88, %esi
callq 0x7269
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x1, %esi
callq 0x7269
movl $0x300000, %edi         # imm = 0x300000
callq 0xd28f
testb $0x2, %al
jne 0xcd9f
cmpb $0x0, 0x8(%rbx)
je 0xcdb2
popq %rbx
retq
leaq 0x6938(%rip), %rdi      # 0x136e0
movl %eax, %esi
xorl %eax, %eax
popq %rbx
jmp 0x7ca5
leaq 0x5272(%rip), %rdi      # 0x1202b
xorl %eax, %eax
popq %rbx
jmp 0x7ca5
// File: /workspace/github_c_makefile_star2_O3/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 %rax
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x9, %esi
callq 0x7269
movl $0x4000c004, %edi       # imm = 0x4000C004
xorl %esi, %esi
callq 0x7269
movl $0x23, %edi
movl $0x140, %esi            # imm = 0x140
callq 0xd2de
movl 0x71f55(%rip), %eax     # 0x7ed70
movl %eax, %esi
shrl $0x1f, %esi
addl %eax, %esi
sarl %esi
movl $0x4000c004, %edi       # imm = 0x4000C004
callq 0x7269
movl $0x23, %edi
movl $0x140, %esi            # imm = 0x140
popq %rax
jmp 0xd2de
// File: /workspace/github_c_makefile_star2_O3/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
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x9, %esi
callq 0x7269
movl $0x4000c01c, %edi       # imm = 0x4000C01C
movl $0x1, %esi
callq 0x7269
movl $0x4000c004, %edi       # imm = 0x4000C004
xorl %esi, %esi
callq 0x7269
movl $0x26, %edi
movl $0x140, %esi            # imm = 0x140
callq 0xd2de
movl $0x4000c01c, %edi       # imm = 0x4000C01C
xorl %esi, %esi
popq %rax
jmp 0x7269
// File: /workspace/github_c_makefile_star2_O3/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
subq $0x18, %rsp
movl 0x71d4e(%rip), %ebx     # 0x7ed90
movq 0x71d5f(%rip), %rax     # 0x7eda8
movq %rax, 0x10(%rsp)
movl 0x71d4b(%rip), %r12d    # 0x7eda0
movl $0x1000, %edi           # imm = 0x1000
callq 0x7dd2
movq %rax, %r14
testl %r12d, %r12d
je 0xd11c
leaq 0x69f6(%rip), %r13      # 0x13a68
xorl %r15d, %r15d
movl %r15d, 0x8(%rsp)
movl %r15d, %r15d
addq 0x10(%rsp), %r15
movl %ebx, %edi
movq %r14, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7283
movl $0x1000, %eax           # imm = 0x1000
cmpl %eax, %r12d
movl $0x1000, %ebp           # imm = 0x1000
movl %r12d, 0xc(%rsp)
cmovbl %r12d, %ebp
xorl %r12d, %r12d
movzbl (%r15,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xd0dc
leal (%rbx,%r12), %esi
leaq 0x573a(%rip), %rdi      # 0x127fd
xorl %eax, %eax
callq 0x7a90
movq %r14, %rdi
callq 0x7df5
movq %r13, %rdi
xorl %eax, %eax
callq 0x7ca5
incq %r12
cmpq %r12, %rbp
jne 0xd0aa
movl 0x8(%rsp), %r15d
addl $0x1000, %r15d          # imm = 0x1000
testl $0x3000, %r15d          # imm = 0x3000
jne 0xd107
leaq 0x370f(%rip), %rdi      # 0x1080f
xorl %eax, %eax
callq 0x7a90
addq $0x1000, %rbx           # imm = 0x1000
movl 0xc(%rsp), %r12d
subl %ebp, %r12d
jne 0xd075
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7df5