LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x745fa(%rip), %eax     # 0x823b8
addl $0x0, %eax
movl %eax, -0x4(%rbp)
movl $0x0, -0xc(%rbp)
movq 0x745fe(%rip), %rax     # 0x823d0
movq %rax, -0x20(%rbp)
movl 0x745ec(%rip), %eax     # 0x823c8
movl %eax, -0x24(%rbp)
callq 0xe3e0
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x76e0
movzbl %al, %eax
andl $0x3, %eax
cmpl $0x2, %eax
je 0xde07
leaq 0x95a2(%rip), %rdi      # 0x173a2
movb $0x0, %al
callq 0x8970
movl $0x100, %edi            # imm = 0x100
callq 0x8ae0
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xdf06
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7800
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jbe 0xde43
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x2c(%rbp)
jmp 0xde49
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x8(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xded2
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0xdec5
movl -0x4(%rbp), %esi
addl -0x28(%rbp), %esi
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
leaq 0x89c6(%rip), %rdi      # 0x1686d
movb $0x0, %al
callq 0x8630
movq -0x18(%rbp), %rdi
callq 0x8b30
leaq 0x9c0a(%rip), %rdi      # 0x17ac8
movb $0x0, %al
callq 0x8970
jmp 0xdec7
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xde56
movl -0x4(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x4(%rbp)
movl -0xc(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0xc(%rbp)
movl -0x8(%rbp), %ecx
movl -0x24(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rbp)
leaq 0x6975(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0xde15
movq -0x18(%rbp), %rdi
callq 0x8b30
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl 0x7448a(%rip), %eax     # 0x823b8
addl $0x0, %eax
movl %eax, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movq 0x7448e(%rip), %rax     # 0x823d0
movq %rax, -0x10(%rbp)
movl 0x74470(%rip), %eax     # 0x823bc
movl %eax, -0x14(%rbp)
callq 0xe3e0
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x76e0
movzbl %al, %eax
andl $0x3, %eax
cmpl $0x2, %eax
je 0xdf77
leaq 0x9464(%rip), %rdi      # 0x173d4
movb $0x0, %al
callq 0x8970
jmp 0xdf79
cmpl $0x0, -0x14(%rbp)
je 0xdfc7
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
movl -0x8(%rbp), %eax
addq %rax, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7800
movl -0x4(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x8(%rbp)
movl -0x14(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
movl %eax, -0x14(%rbp)
leaq 0x68b1(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0xdf79
movq 0x743e2(%rip), %rdi     # 0x823b0
movq -0x10(%rbp), %rsi
movl 0x743e4(%rip), %edx     # 0x823bc
callq 0x8c40
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
xorl %eax, %eax
cmpl -0x8(%rbp), %eax
je 0xe017
movl $0x2, %eax
cmpl -0x8(%rbp), %eax
jne 0xe020
movl $0x804000, -0x14(%rbp)  # imm = 0x804000
jmp 0xe048
movl $0x1, %eax
cmpl -0x8(%rbp), %eax
je 0xe034
movl $0x3, %eax
cmpl -0x8(%rbp), %eax
jne 0xe03d
movl $0x80c000, -0x14(%rbp)  # imm = 0x80C000
jmp 0xe046
movl $0x0, -0x4(%rbp)
jmp 0xe065
jmp 0xe048
callq 0xe3e0
movl -0x14(%rbp), %edi
movq -0x10(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7800
movl $0x100, -0x4(%rbp)      # imm = 0x100
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
xorl %edi, %edi
callq 0x6ef0
movl $0xa, %edi
callq 0x8a90
callq 0x6800
movl $0x41002101, %edi       # imm = 0x41002101
movl $0x2, %esi
callq 0x7770
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl $0x2710, -0xc(%rbp)     # imm = 0x2710
cmpl $0x0, -0xc(%rbp)
jle 0xe31e
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x76e0
movzbl %al, %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xe311
jmp 0xe31e
jmp 0xe313
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xe2f2
xorl %eax, %eax
cmpl -0xc(%rbp), %eax
jne 0xe333
leaq 0x8f6e(%rip), %rdi      # 0x1729a
movb $0x0, %al
callq 0x8970
movl $0x41002124, %edi       # imm = 0x41002124
callq 0x7740
movl %eax, -0x8(%rbp)
movl -0x8(%rbp), %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
movl $0xec000000, %eax       # imm = 0xEC000000
cmpl %ecx, %eax
je 0xe363
movl -0x8(%rbp), %esi
leaq 0x8f52(%rip), %rdi      # 0x172ae
movb $0x0, %al
callq 0x8970
movl -0x8(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x10(%rbp)
cmpl $-0x1, -0x4(%rbp)
je 0xe390
movl -0x4(%rbp), %eax
cmpl -0x10(%rbp), %eax
je 0xe390
movl -0x10(%rbp), %esi
movl -0x4(%rbp), %edx
leaq 0x8f4c(%rip), %rdi      # 0x172d5
movb $0x0, %al
callq 0x8970
movl -0x10(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
testb $0x1, 0x73ffd(%rip)     # 0x823ec
jne 0xe434
callq 0xe270
movl $0xaa, %edi
callq 0xe2a0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0xe2e0
movl %eax, -0x4(%rbp)
movl $0x39, %eax
cmpl -0x4(%rbp), %eax
je 0xe42d
movl -0x4(%rbp), %esi
leaq 0x8ee5(%rip), %rdi      # 0x17306
movl $0x39, %edx
movb $0x0, %al
callq 0x8970
movb $0x1, 0x73fb8(%rip)     # 0x823ec
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x4, %esi
callq 0x77d0
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x10004, %esi          # imm = 0x10004
callq 0x77d0
callq 0xead0
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
callq 0x77d0
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x73d02(%rip), %eax     # 0x82420
addl $0x8000000, %eax        # imm = 0x8000000
movl %eax, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movq 0x73d04(%rip), %rax     # 0x82438
movq %rax, -0x18(%rbp)
movl 0x73cf2(%rip), %eax     # 0x82430
movl %eax, -0x1c(%rbp)
movl 0x73cd9(%rip), %eax     # 0x82420
movl $0x800, %ecx            # imm = 0x800
cltd
idivl %ecx
movl %eax, -0xc(%rbp)
movl -0x1c(%rbp), %eax
addl $0x800, %eax            # imm = 0x800
subl $0x1, %eax
shrl $0xb, %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x10(%rbp), %eax
jae 0xe822
movl -0xc(%rbp), %esi
addl -0x20(%rbp), %esi
shll $0x3, %esi
orl $0x2, %esi
movl $0x40022014, %edi       # imm = 0x40022014
callq 0x77d0
movl -0xc(%rbp), %esi
addl -0x20(%rbp), %esi
shll $0x3, %esi
orl $0x2, %esi
orl $0x10000, %esi          # imm = 0x10000
movl $0x40022014, %edi       # imm = 0x40022014
callq 0x77d0
callq 0xead0
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x1, %esi
callq 0x77d0
movl $0x0, -0x24(%rbp)
cmpl $0x8, -0x24(%rbp)
jge 0xe801
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rsi
movl -0x8(%rbp), %eax
addq %rax, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x79c0
movl -0x4(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x8(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xe7c3
leaq 0x6067(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
callq 0xead0
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xe76a
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
callq 0x77d0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x73bd2(%rip), %eax     # 0x82420
addl $0x8000000, %eax        # imm = 0x8000000
movl %eax, -0x4(%rbp)
movl $0x0, -0xc(%rbp)
movq 0x73bd4(%rip), %rax     # 0x82438
movq %rax, -0x20(%rbp)
movl 0x73bc2(%rip), %eax     # 0x82430
movl %eax, -0x24(%rbp)
movl $0x100, %edi            # imm = 0x100
callq 0x8ae0
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xe97f
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7800
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jbe 0xe8ad
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x2c(%rbp)
jmp 0xe8b3
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x8(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xe93c
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0xe92f
movl -0x4(%rbp), %esi
addl -0x28(%rbp), %esi
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
leaq 0x7f5c(%rip), %rdi      # 0x1686d
movb $0x0, %al
callq 0x8630
movq -0x18(%rbp), %rdi
callq 0x8b30
leaq 0x91a0(%rip), %rdi      # 0x17ac8
movb $0x0, %al
callq 0x8970
jmp 0xe931
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xe8c0
movl -0x4(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x4(%rbp)
movl -0xc(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0xc(%rbp)
movl -0x8(%rbp), %ecx
movl -0x24(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0xc(%rbp), %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xe97a
leaq 0x5efc(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0xe87f
movq -0x18(%rbp), %rdi
callq 0x8b30
addq $0x30, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl 0x73a82(%rip), %eax     # 0x82420
addl $0x8000000, %eax        # imm = 0x8000000
movl %eax, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movq 0x73a84(%rip), %rax     # 0x82438
movq %rax, -0x10(%rbp)
movl 0x73a66(%rip), %eax     # 0x82424
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xea0f
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
movl -0x8(%rbp), %eax
addq %rax, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7800
movl -0x4(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x8(%rbp)
movl -0x14(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
movl %eax, -0x14(%rbp)
leaq 0x5e69(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0xe9c1
movq 0x73a02(%rip), %rdi     # 0x82418
movq -0x10(%rbp), %rsi
movl 0x73a04(%rip), %edx     # 0x82424
callq 0x8c40
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x40022010, %edi       # imm = 0x40022010
callq 0x7740
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0xeaee
jmp 0xead8
movl $0x40022010, %edi       # imm = 0x40022010
callq 0x7740
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
andl $0xc3fa, %eax           # imm = 0xC3FA
cmpl $0x0, %eax
je 0xeb19
movl -0x4(%rbp), %esi
leaq 0x898f(%rip), %rdi      # 0x174a1
movb $0x0, %al
callq 0x8970
addq $0x10, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl 0x736a2(%rip), %eax     # 0x82490
movl $0x1000, %ecx           # imm = 0x1000
cltd
idivl %ecx
movl %eax, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0xee44
movl -0x8(%rbp), %esi
shll $0x3, %esi
orl $0x2, %esi
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x77d0
movl -0x8(%rbp), %esi
shll $0x3, %esi
orl $0x2, %esi
orl $0x10000, %esi          # imm = 0x10000
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x77d0
callq 0xf2c0
movl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x8(%rbp)
jmp 0xee00
movl $0x58004014, %edi       # imm = 0x58004014
xorl %esi, %esi
callq 0x77d0
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x58004010, %edi       # imm = 0x58004010
callq 0x7740
andl $0x50000, %eax          # imm = 0x50000
cmpl $0x0, %eax
je 0xf2de
jmp 0xf2c8
movl $0x58004010, %edi       # imm = 0x58004010
callq 0x7740
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
andl $0xc3fa, %eax           # imm = 0xC3FA
cmpl $0x0, %eax
je 0xf309
movl -0x4(%rbp), %esi
leaq 0x819f(%rip), %rdi      # 0x174a1
movb $0x0, %al
callq 0x8970
addq $0x10, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
movl $0x40023c10, %edi       # imm = 0x40023C10
movl $0x8004, %esi           # imm = 0x8004
callq 0x77d0
movl $0x40023c10, %edi       # imm = 0x40023C10
movl $0x18004, %esi          # imm = 0x18004
callq 0x77d0
callq 0xfc40
movl $0x40023c10, %edi       # imm = 0x40023C10
xorl %esi, %esi
callq 0x77d0
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x7740
movl %eax, -0x4(%rbp)
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x7740
movl %eax, -0x8(%rbp)
movl -0x4(%rbp), %eax
orl $0xff00, %eax           # imm = 0xFF00
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %esi
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x77d0
movl -0x4(%rbp), %esi
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x77d0
movl -0x4(%rbp), %esi
orl $0x2, %esi
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x77d0
callq 0xfc40
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x7740
movl %eax, -0x4(%rbp)
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x7740
movl %eax, -0x8(%rbp)
movl -0x4(%rbp), %eax
andl $0xffff00ff, %eax       # imm = 0xFFFF00FF
orl $0xaa00, %eax           # imm = 0xAA00
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %esi
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x77d0
movl -0x4(%rbp), %esi
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x77d0
movl -0x4(%rbp), %esi
orl $0x2, %esi
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x77d0
callq 0xfc40
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x72c3a(%rip), %eax     # 0x824c8
addl $0x8000000, %eax        # imm = 0x8000000
movl %eax, -0x4(%rbp)
movl $0x0, -0xc(%rbp)
movq 0x72c3c(%rip), %rax     # 0x824e0
movq %rax, -0x20(%rbp)
movl 0x72c2a(%rip), %eax     # 0x824d8
movl %eax, -0x24(%rbp)
movl $0x100, %edi            # imm = 0x100
callq 0x8ae0
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0xf9bf
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7800
cmpl $0x100, -0x24(%rbp)     # imm = 0x100
jbe 0xf8ed
movl $0x100, %eax            # imm = 0x100
movl %eax, -0x2c(%rbp)
jmp 0xf8f3
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x8(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0xf97c
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0xf96f
movl -0x4(%rbp), %esi
addl -0x28(%rbp), %esi
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
leaq 0x6f1c(%rip), %rdi      # 0x1686d
movb $0x0, %al
callq 0x8630
movq -0x18(%rbp), %rdi
callq 0x8b30
leaq 0x8160(%rip), %rdi      # 0x17ac8
movb $0x0, %al
callq 0x8970
jmp 0xf971
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xf900
movl -0x4(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x4(%rbp)
movl -0xc(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0xc(%rbp)
movl -0x8(%rbp), %ecx
movl -0x24(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0xc(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xf9ba
leaq 0x4ebc(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0xf8bf
movq -0x18(%rbp), %rdi
callq 0x8b30
addq $0x30, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl 0x72aea(%rip), %eax     # 0x824c8
addl $0x8000000, %eax        # imm = 0x8000000
movl %eax, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movq 0x72aec(%rip), %rax     # 0x824e0
movq %rax, -0x10(%rbp)
movl 0x72ace(%rip), %eax     # 0x824cc
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %edi
movl $0x100, %esi            # imm = 0x100
callq 0x8a70
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0xfa6e
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
movl -0x8(%rbp), %eax
addq %rax, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7800
movl -0x4(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x8(%rbp)
movl -0x14(%rbp), %eax
subl $0x100, %eax            # imm = 0x100
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xfa6c
leaq 0x4e0a(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0xfa11
movq 0x72a4b(%rip), %rdi     # 0x824c0
movq -0x10(%rbp), %rsi
movl 0x72a4d(%rip), %edx     # 0x824cc
callq 0x8c40
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_fuse_read
static int target_fuse_read(int section, uint8_t *data)
{
  uint32_t value;

  if (0 == section)
    value = dap_read_word(FMC_OBCTL0);
  else if (1 == section)
    value = dap_read_word(FMC_OBCTL1);
  else
    return 0;

  data[0] = value;
  data[1] = value >> 8;
  data[2] = value >> 16;
  data[3] = value >> 24;

  return 4;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %eax, %eax
cmpl -0x8(%rbp), %eax
jne 0xfab5
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x7740
movl %eax, -0x14(%rbp)
jmp 0xfad9
movl $0x1, %eax
cmpl -0x8(%rbp), %eax
jne 0xface
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x7740
movl %eax, -0x14(%rbp)
jmp 0xfad7
movl $0x0, -0x4(%rbp)
jmp 0xfb18
jmp 0xfad9
movl -0x14(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movl -0x14(%rbp), %eax
shrl $0x8, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x14(%rbp), %eax
shrl $0x10, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x2(%rax)
movl -0x14(%rbp), %eax
shrl $0x18, %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x3(%rax)
movl $0x4, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x3(%rax), %eax
shll $0x18, %eax
movq -0x10(%rbp), %rcx
movzbl 0x2(%rcx), %ecx
shll $0x10, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl (%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x14(%rbp)
cmpl $0x2, -0x4(%rbp)
setl %al
movzbl %al, %edi
andl $0x1, %edi
leaq 0x6d18(%rip), %rsi      # 0x1689c
xorl %eax, %eax
callq 0x8880
xorl %eax, %eax
cmpl -0x4(%rbp), %eax
jne 0xfba7
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x7740
movl %eax, -0x1c(%rbp)
jmp 0xfbba
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x7740
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
andl $-0x4, %eax
movl %eax, -0x18(%rbp)
movl -0x1c(%rbp), %esi
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x77d0
movl -0x18(%rbp), %esi
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x77d0
movl -0x18(%rbp), %esi
orl $0x2, %esi
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x77d0
callq 0xfc40
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl $0x40023c0c, %edi       # imm = 0x40023C0C
callq 0x7740
andl $0x10000, %eax          # imm = 0x10000
cmpl $0x0, %eax
je 0xfc5e
jmp 0xfc48
movl $0x40023c0c, %edi       # imm = 0x40023C0C
callq 0x7740
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
andl $0x1d2, %eax            # imm = 0x1D2
cmpl $0x0, %eax
je 0xfc89
movl -0x4(%rbp), %esi
leaq 0x79ac(%rip), %rdi      # 0x1762e
movb $0x0, %al
callq 0x8970
addq $0x10, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x9, %esi
callq 0x77d0
movl $0x4000c004, %edi       # imm = 0x4000C004
xorl %esi, %esi
callq 0x77d0
movl $0x23, %edi
movl $0x140, %esi            # imm = 0x140
callq 0x10510
movl 0x7262c(%rip), %eax     # 0x82500
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %esi
movl $0x4000c004, %edi       # imm = 0x4000C004
callq 0x77d0
movl $0x23, %edi
movl $0x140, %esi            # imm = 0x140
callq 0x10510
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x9, %esi
callq 0x77d0
movl $0x4000c01c, %edi       # imm = 0x4000C01C
movl $0x1, %esi
callq 0x77d0
movl $0x4000c004, %edi       # imm = 0x4000C004
xorl %esi, %esi
callq 0x77d0
movl $0x26, %edi
movl $0x140, %esi            # imm = 0x140
callq 0x10510
movl $0x4000c01c, %edi       # imm = 0x4000C01C
xorl %esi, %esi
callq 0x77d0
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl 0x723d2(%rip), %eax     # 0x82520
movl %eax, -0x4(%rbp)
movl $0x0, -0xc(%rbp)
movq 0x723d9(%rip), %rax     # 0x82538
movq %rax, -0x20(%rbp)
movl 0x723c7(%rip), %eax     # 0x82530
movl %eax, -0x24(%rbp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x8ae0
movq %rax, -0x18(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x1027a
movl -0x4(%rbp), %edi
movq -0x18(%rbp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7800
cmpl $0x1000, -0x24(%rbp)    # imm = 0x1000
jbe 0x101a8
movl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x2c(%rbp)
jmp 0x101ae
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x8(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x10237
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
movq -0x18(%rbp), %rcx
movslq -0x28(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x1022a
movl -0x4(%rbp), %esi
addl -0x28(%rbp), %esi
movq -0x20(%rbp), %rax
movl -0xc(%rbp), %ecx
addl -0x28(%rbp), %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %edx
movq -0x18(%rbp), %rax
movslq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
leaq 0x6661(%rip), %rdi      # 0x1686d
movb $0x0, %al
callq 0x8630
movq -0x18(%rbp), %rdi
callq 0x8b30
leaq 0x78a5(%rip), %rdi      # 0x17ac8
movb $0x0, %al
callq 0x8970
jmp 0x1022c
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x101bb
movl -0x4(%rbp), %eax
addl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x4(%rbp)
movl -0xc(%rbp), %eax
addl $0x1000, %eax           # imm = 0x1000
movl %eax, -0xc(%rbp)
movl -0x8(%rbp), %ecx
movl -0x24(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0xc(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x10275
leaq 0x4601(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0x1017a
movq -0x18(%rbp), %rdi
callq 0x8b30
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movl 0x72282(%rip), %eax     # 0x82520
movl %eax, -0x4(%rbp)
movl $0x0, -0x8(%rbp)
movq 0x72289(%rip), %rax     # 0x82538
movq %rax, -0x10(%rbp)
movl 0x7226b(%rip), %eax     # 0x82524
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x10319
movl -0x4(%rbp), %edi
movq -0x10(%rbp), %rsi
movl -0x8(%rbp), %eax
addq %rax, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7800
movl -0x4(%rbp), %eax
addl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x4(%rbp)
movl -0x8(%rbp), %eax
addl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x8(%rbp)
movl -0x14(%rbp), %eax
subl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x10317
leaq 0x455f(%rip), %rdi      # 0x1486f
movb $0x0, %al
callq 0x8630
jmp 0x102bc
movq 0x721f8(%rip), %rdi     # 0x82518
movq -0x10(%rbp), %rsi
movl 0x721fa(%rip), %edx     # 0x82524
callq 0x8c40
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/ataradov[P]edbg/target_nu_m480.c
// Function: target_fuse_read
static int target_fuse_read(int section, uint8_t *data)
{
  uint32_t *value = (uint32_t *)data;

  if (section >= CONFIG_COUNT)
    return 0;

  dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN);

  *value = fmc_read(CONFIG0 + section * CONFIG_SIZE);

  return CONFIG_SIZE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x4, -0x8(%rbp)
jl 0x10366
movl $0x0, -0x4(%rbp)
jmp 0x10395
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x1, %esi
callq 0x77d0
movl -0x8(%rbp), %edi
shll $0x2, %edi
addl $0x300000, %edi         # imm = 0x300000
callq 0x104b0
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movl $0x4, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
cmpl $0x4, -0x4(%rbp)
jl 0x103ba
jmp 0x10464
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x11, %esi
callq 0x77d0
movl $0x0, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jge 0x103fc
movl -0x24(%rbp), %edi
shll $0x2, %edi
addl $0x300000, %edi         # imm = 0x300000
callq 0x104b0
movl %eax, %ecx
movslq -0x24(%rbp), %rax
movl %ecx, -0x20(%rbp,%rax,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x103d0
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movslq -0x4(%rbp), %rax
movl %ecx, -0x20(%rbp,%rax,4)
movl -0x20(%rbp), %eax
orl $0x800, %eax            # imm = 0x800
movl %eax, -0x20(%rbp)
movl $0x4000c004, %edi       # imm = 0x4000C004
movl $0x300000, %esi         # imm = 0x300000
callq 0x77d0
movl $0x22, %edi
movl $0x50, %esi
callq 0x10510
movl $0x0, -0x28(%rbp)
cmpl $0x4, -0x28(%rbp)
jge 0x10464
movl -0x28(%rbp), %edi
shll $0x2, %edi
addl $0x300000, %edi         # imm = 0x300000
movslq -0x28(%rbp), %rax
movl -0x20(%rbp,%rax,4), %esi
callq 0x10590
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1043a
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl $0x4000c00c, %edi       # imm = 0x4000C00C
xorl %esi, %esi
callq 0x77d0
movl -0x4(%rbp), %esi
movl $0x4000c004, %edi       # imm = 0x4000C004
callq 0x77d0
movl $0x4000c008, %edi       # imm = 0x4000C008
xorl %esi, %esi
callq 0x77d0
movl $0x4000c010, %edi       # imm = 0x4000C010
movl $0x1, %esi
callq 0x77d0
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x7740
cmpl $0x0, %eax
je 0x10500
jmp 0x104ef
movl $0x4000c008, %edi       # imm = 0x4000C008
callq 0x7740
addq $0x10, %rsp
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl -0x4(%rbp), %esi
movl $0x4000c00c, %edi       # imm = 0x4000C00C
callq 0x77d0
movl $0x4000c010, %edi       # imm = 0x4000C010
movl $0x1, %esi
callq 0x77d0
cmpl $0x0, -0x8(%rbp)
je 0x10548
movl -0x8(%rbp), %edi
callq 0x8a90
jmp 0x1054a
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x7740
cmpl $0x0, %eax
je 0x1055b
jmp 0x1054a
movl $0x4000c040, %edi       # imm = 0x4000C040
callq 0x7740
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x10584
movl -0x4(%rbp), %esi
leaq 0x71fc(%rip), %rdi      # 0x17779
movb $0x0, %al
callq 0x8970
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl $0x4000c00c, %edi       # imm = 0x4000C00C
movl $0x21, %esi
callq 0x77d0
movl -0x4(%rbp), %esi
movl $0x4000c004, %edi       # imm = 0x4000C004
callq 0x77d0
movl -0x8(%rbp), %esi
movl $0x4000c008, %edi       # imm = 0x4000C008
callq 0x77d0
movl $0x4000c010, %edi       # imm = 0x4000C010
movl $0x1, %esi
callq 0x77d0
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x7740
cmpl $0x0, %eax
je 0x105e7
jmp 0x105d6
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/ataradov[P]edbg/target_lattice_lcmxo2.c
// Function: target_select
static void target_select(target_options_t *options)
{
  uint32_t chain[MAX_CHAIN_COUNT];
  int chain_count;

  dap_connect(DAP_INTERFACE_JTAG);

  chain_count = dap_jtag_scan_chain(chain, MAX_CHAIN_COUNT);

  verbose("Detected JTAG chain:\n");
  for (int i = 0; i < chain_count; i++)
    verbose("  %d: 0x%08x\n", i, chain[i]);

  if (chain_count == 0)
    error_exit("no devices detected in the JTAG chain");

  if (chain_count > 1)
    error_exit("more than one device detected in the JTAG chain");

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

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

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

    return;
  }

  error_exit("unknown target device (IDCODE = 0x%08x)", chain[0]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl $0x2, %edi
callq 0x6480
leaq -0x20(%rbp), %rdi
movl $0x5, %esi
callq 0x8430
movl %eax, -0x24(%rbp)
leaq 0x7192(%rip), %rdi      # 0x177b0
movb $0x0, %al
callq 0x8630
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x10658
movl -0x28(%rbp), %esi
movslq -0x28(%rbp), %rax
movl -0x20(%rbp,%rax,4), %edx
leaq 0x7180(%rip), %rdi      # 0x177c6
movb $0x0, %al
callq 0x8630
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1062c
cmpl $0x0, -0x24(%rbp)
jne 0x1066c
leaq 0x716f(%rip), %rdi      # 0x177d4
movb $0x0, %al
callq 0x8970
cmpl $0x1, -0x24(%rbp)
jle 0x10680
leaq 0x7181(%rip), %rdi      # 0x177fa
movb $0x0, %al
callq 0x8970
movl $0x0, -0x2c(%rbp)
cmpl $0x3, -0x2c(%rbp)
jge 0x10727
movslq -0x2c(%rbp), %rcx
leaq 0xef74(%rip), %rax      # 0x1f610
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x20(%rbp), %eax
je 0x106ac
jmp 0x10719
movslq -0x2c(%rbp), %rcx
leaq 0xef59(%rip), %rax      # 0x1f610
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rsi
leaq 0x620c(%rip), %rdi      # 0x168d5
movb $0x0, %al
callq 0x8630
movslq -0x2c(%rbp), %rcx
leaq 0xef35(%rip), %rax      # 0x1f610
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, 0x71e54(%rip)     # 0x82540
movq 0x8(%rax), %rcx
movq %rcx, 0x71e51(%rip)     # 0x82548
movq 0x10(%rax), %rax
movq %rax, 0x71e4e(%rip)     # 0x82550
movq -0x8(%rbp), %rsi
leaq 0x71e4b(%rip), %rdi     # 0x82558
movl $0x38, %edx
callq 0x61a0
jmp 0x10738
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x10687
movl -0x20(%rbp), %esi
leaq 0x70f9(%rip), %rdi      # 0x1782a
movb $0x0, %al
callq 0x8970
addq $0x30, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/ataradov[P]edbg/target_lattice_lcmxo2.c
// Function: target_deselect
static void target_deselect(void)
{
  dap_jtag_write_ir(CMD_ISC_PROGRAM_DONE, IR_LENGTH);
  dap_jtag_idle(1000);
  poll_busy_flag();

  dap_jtag_write_ir(CMD_ISC_DISABLE, IR_LENGTH);
  dap_jtag_idle(8);

  dap_jtag_write_ir(CMD_ISC_NOOP, IR_LENGTH);
  dap_jtag_idle(100);

  dap_jtag_write_ir(CMD_LSC_REFRESH, IR_LENGTH);
  dap_jtag_idle(8);

  dap_jtag_write_ir(CMD_ISC_NOOP, IR_LENGTH);
  dap_jtag_idle(100);

  dap_jtag_flush();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movl $0x5e, %edi
movl $0x8, %esi
callq 0x8260
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x81e0
callq 0x10d20
movl $0x26, %edi
movl $0x8, %esi
callq 0x8260
movl $0x8, %edi
callq 0x81e0
movl $0xff, %edi
movl $0x8, %esi
callq 0x8260
movl $0x64, %edi
callq 0x81e0
movl $0x79, %edi
movl $0x8, %esi
callq 0x8260
movl $0x8, %edi
callq 0x81e0
movl $0xff, %edi
movl $0x8, %esi
callq 0x8260
movl $0x64, %edi
callq 0x81e0
callq 0x7bc0
popq %rbp
retq
nopl (%rax)