LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm3.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(get_flash_addr(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;

    verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x74ae7(%rip), %ebx     # 0x7eaf0
movq 0x74af8(%rip), %rax     # 0x7eb08
movq %rax, 0x10(%rsp)
movl 0x74ae4(%rip), %r12d    # 0x7eb00
movl $0x100, %edi            # imm = 0x100
callq 0x7dba
movq %rax, %r14
testl %r12d, %r12d
je 0xa0e8
xorl %r15d, %r15d
movl %r15d, 0x8(%rsp)
movl %r15d, %r15d
addq 0x10(%rsp), %r15
movl %ebx, %edi
callq 0xa2af
movl %eax, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7258
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r12d
movl $0x100, %ebp            # imm = 0x100
movl %r12d, 0xc(%rsp)
cmovbl %r12d, %ebp
cmpl $0x1, %ebp
movl %ebp, %r12d
adcl $0x0, %r12d
xorl %r13d, %r13d
movzbl (%r15,%r13), %edx
movzbl (%r14,%r13), %ecx
cmpb %cl, %dl
je 0xa0b1
leal (%rbx,%r13), %esi
leaq 0x8779(%rip), %rdi      # 0x1280d
xorl %eax, %eax
callq 0x7a78
movq %r14, %rdi
callq 0x7de7
leaq 0x99ce(%rip), %rdi      # 0x13a78
xorl %eax, %eax
callq 0x7c8d
incq %r13
cmpq %r13, %r12
jne 0xa07b
addq $0x100, %rbx            # imm = 0x100
movl 0x8(%rsp), %r15d
addl $0x100, %r15d           # imm = 0x100
leaq 0x674c(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
movl 0xc(%rsp), %r12d
subl %ebp, %r12d
jne 0xa035
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7de7
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm3.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(get_flash_addr(addr), &buf[offs], FLASH_PAGE_SIZE);

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

    verbose(".");
  }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x749fb(%rip), %rbx     # 0x7eb08
movl 0x749e1(%rip), %ebp     # 0x7eaf4
testl %ebp, %ebp
je 0xa159
movl 0x749d2(%rip), %r15d    # 0x7eaf0
leaq 0x66fa(%rip), %r14      # 0x1081f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
callq 0xa2af
movl %r12d, %esi
addq %rbx, %rsi
movl %eax, %edi
movl $0x100, %edx            # imm = 0x100
callq 0x7258
addl $0x100, %r12d           # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
cmpl %r12d, %ebp
jne 0xa128
movq 0x74988(%rip), %rdi     # 0x7eae8
movl 0x7498e(%rip), %edx     # 0x7eaf4
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7e95
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm3.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(get_eefc_base(0)), CMD_GGPB);
  while (0 == (dap_read_word(EEFC_FSR(get_eefc_base(0))) & FSR_FRDY));
  gpnvm = dap_read_word(EEFC_FRR(get_eefc_base(0)));

  data[0] = gpnvm;

  return GPNVM_SIZE;
}

// Assembly:
xorl %eax, %eax
testl %edi, %edi
jle 0xa17d
retq
pushq %rbx
movq %rsi, %rbx
xorl %edi, %edi
callq 0xa233
leal 0x4(%rax), %edi
movl $0x5a00000d, %esi       # imm = 0x5A00000D
callq 0x723e
xorl %edi, %edi
callq 0xa233
leal 0x8(%rax), %edi
callq 0x71ef
testb $0x1, %al
je 0xa195
xorl %edi, %edi
callq 0xa233
leal 0xc(%rax), %edi
callq 0x71ef
movb %al, (%rbx)
movl $0x1, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm3.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t gpnvm = 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(get_eefc_base(0)), CMD_SGPB | (i << 8));
    else
      dap_write_word(EEFC_FCR(get_eefc_base(0)), CMD_CGPB | (i << 8));
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movzbl (%rsi), %ebx
xorl %eax, %eax
testl %edi, %edi
sete %al
leaq 0x8667(%rip), %rsi      # 0x1283c
xorl %ebp, %ebp
movl %eax, %edi
xorl %eax, %eax
callq 0x7bb4
xorl %r14d, %r14d
xorl %edi, %edi
callq 0xa233
leal 0x4(%rax), %edi
btl %r14d, %ebx
movl %ebp, %esi
sbbl $-0x1, %esi
addl $0x5a00000b, %esi       # imm = 0x5A00000B
callq 0x723e
incl %r14d
addl $0x100, %ebp            # imm = 0x100
cmpl $0x800, %ebp            # imm = 0x800
jne 0xa1e3
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm3.c
// Function: get_eefc_base
static uint32_t get_eefc_base(uint32_t addr)
{
  uint32_t flash_addr = get_flash_addr(addr);

  for (int i = 0; i < target_device.n_planes; i++)
  {
    uint32_t a = target_device.plane[i].addr;
    uint32_t s = target_device.plane[i].size;

    if (a <= flash_addr && flash_addr < (a + s))
      return target_device.plane[i].eefc_base;
  }

  error_exit("internal error in get_eefc_base()");

  return 0;
}

// Assembly:
pushq %rbx
callq 0xa2af
movslq 0x7487c(%rip), %rdx     # 0x7eabc
testq %rdx, %rdx
setg %cl
jle 0xa296
movq %rdx, %rsi
negq %rsi
leaq 0x74873(%rip), %rdi     # 0x7eac8
movl $0x1, %r8d
movl -0x4(%rdi), %r10d
movb $0x1, %r9b
cmpl %eax, %r10d
ja 0xa275
addl (%rdi), %r10d
cmpl %r10d, %eax
jae 0xa275
movl -0x8(%rdi), %ebx
xorl %r9d, %r9d
testb %r9b, %r9b
je 0xa296
cmpq %rdx, %r8
setb %cl
addq $0xc, %rdi
leaq (%rsi,%r8), %r9
incq %r9
incq %r8
cmpq $0x1, %r9
jne 0xa25b
jmp 0xa296
testb $0x1, %cl
jne 0xa2ab
leaq 0x86fe(%rip), %rdi      # 0x129a0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x7c8d
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm3.c
// Function: get_flash_addr
static uint32_t get_flash_addr(uint32_t addr)
{
  uint32_t offs = addr;

  for (int i = 0; i < target_device.n_planes; i++)
  {
    if (offs >= target_device.plane[i].size)
      offs -= target_device.plane[i].size;
    else
      return target_device.plane[i].addr + offs;
  }

  error_exit("internal error in get_flash_addr()");

  return 0;
}

// Assembly:
pushq %rbx
movslq 0x74805(%rip), %rcx     # 0x7eabc
testq %rcx, %rcx
setg %dl
jle 0xa306
movl %edi, %ebx
movl 0x74801(%rip), %esi     # 0x7eac8
cmpl %edi, %esi
jbe 0xa2d4
leaq 0x747ee(%rip), %rax     # 0x7eac0
jmp 0xa2fe
movl $0x1, %edx
leaq 0x747e0(%rip), %rax     # 0x7eac0
cmpq %rdx, %rcx
je 0xa303
subl %esi, %ebx
movl 0x14(%rax), %esi
incq %rdx
addq $0xc, %rax
cmpl %esi, %ebx
jae 0xa2e0
decq %rdx
cmpq %rcx, %rdx
setb %dl
addl 0x4(%rax), %ebx
jmp 0xa306
seta %dl
testb %dl, %dl
jne 0xa31a
leaq 0x86b1(%rip), %rdi      # 0x129c2
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x7c8d
movl %ebx, %eax
popq %rbx
retq
nop
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm4.c
// Function: target_erase
static void target_erase(void)
{
  for (uint32_t plane = 0; plane < target_device.n_planes; plane++)
    dap_write_word(EEFC_FCR(plane), CMD_EA);

  for (uint32_t plane = 0; plane < target_device.n_planes; plane++)
    while (0 == (dap_read_word(EEFC_FSR(plane)) & FSR_FRDY));
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
cmpl $0x0, 0x745b1(%rip)     # 0x7eb28
je 0xa59c
xorl %ebp, %ebp
movl $0x400e0a04, %ebx       # imm = 0x400E0A04
movl %ebx, %edi
movl $0x5a000005, %esi       # imm = 0x5A000005
callq 0x723e
incl %ebp
addl $0x200, %ebx            # imm = 0x200
cmpl 0x7458e(%rip), %ebp     # 0x7eb28
jb 0xa580
cmpl $0x0, 0x74585(%rip)     # 0x7eb28
je 0xa5c7
xorl %ebp, %ebp
movl %ebp, %ebx
shll $0x9, %ebx
addl $0x400e0a08, %ebx       # imm = 0x400E0A08
movl %ebx, %edi
callq 0x71ef
testb $0x1, %al
je 0xa5b2
incl %ebp
cmpl 0x74563(%rip), %ebp     # 0x7eb28
jb 0xa5a7
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm4.c
// Function: target_program
static void target_program(void)
{
  uint32_t addr = FLASH_START + target_options.offset;
  uint32_t number_of_pages, plane, page_offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.file_size;

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

  for (uint32_t page = 0; page < number_of_pages; page += PAGES_IN_ERASE_BLOCK)
  {
    plane = (page + page_offset) / (target_device.flash_size / FLASH_PAGE_SIZE);

    dap_write_word(EEFC_FCR(plane), CMD_EPA | (((page_offset + page) | 2) << 8));
    while (0 == (dap_read_word(EEFC_FSR(plane)) & FSR_FRDY));

    verbose(".");
  }

  verbose(",");

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    dap_write_block(addr, &buf[offs], FLASH_PAGE_SIZE);
    addr += FLASH_PAGE_SIZE;
    offs += FLASH_PAGE_SIZE;

    plane = (page + page_offset) / (target_device.flash_size / FLASH_PAGE_SIZE);

    dap_write_word(EEFC_FCR(plane), CMD_WP | ((page + page_offset) << 8));
    while (0 == (dap_read_word(EEFC_FSR(plane)) & FSR_FRDY));

    verbose(".");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x74557(%rip), %ebx     # 0x7eb48
movl $0x1ff, %ecx            # imm = 0x1FF
leal (%rbx,%rcx), %r12d
addl 0x74558(%rip), %ecx     # 0x7eb58
movq 0x74559(%rip), %rax     # 0x7eb60
movq %rax, 0x10(%rsp)
movl %ecx, %ebp
shrl $0x9, %ebp
testl %ebx, %ebx
cmovnsl %ebx, %r12d
sarl $0x9, %r12d
movq %rcx, 0x8(%rsp)
cmpl $0x200, %ecx            # imm = 0x200
jb 0xa687
leaq 0x61f0(%rip), %r14      # 0x1081f
xorl %r13d, %r13d
leal (%r12,%r13), %esi
movl 0x744f0(%rip), %ecx     # 0x7eb2c
shrl $0x9, %ecx
movl %esi, %eax
xorl %edx, %edx
divl %ecx
movl %eax, %r15d
shll $0x9, %r15d
leal 0x400e0a04(%r15), %edi
shll $0x8, %esi
orl $0x5a000207, %esi       # imm = 0x5A000207
callq 0x723e
addl $0x400e0a08, %r15d      # imm = 0x400E0A08
movl %r15d, %edi
callq 0x71ef
testb $0x1, %al
je 0xa668
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
addl $0x10, %r13d
cmpl %ebp, %r13d
jb 0xa632
leaq 0x873e(%rip), %rdi      # 0x12dcc
xorl %eax, %eax
callq 0x7a78
cmpl $0x200, 0x8(%rsp)       # imm = 0x200
jb 0xa729
addl $0x400000, %ebx         # imm = 0x400000
xorl %r14d, %r14d
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
leaq (%rax,%r14), %rsi
movl %ebx, %edi
movl $0x200, %edx            # imm = 0x200
callq 0x73b6
addl $0x200, %ebx            # imm = 0x200
leal (%r12,%r13), %esi
movl 0x74458(%rip), %ecx     # 0x7eb2c
shrl $0x9, %ecx
movl %esi, %eax
xorl %edx, %edx
divl %ecx
movl %eax, %r15d
shll $0x9, %r15d
leal 0x400e0a04(%r15), %edi
shll $0x8, %esi
orl $0x5a000001, %esi       # imm = 0x5A000001
callq 0x723e
addl $0x400e0a08, %r15d      # imm = 0x400E0A08
movl %r15d, %edi
callq 0x71ef
testb $0x1, %al
je 0xa700
addq $0x200, %r14            # imm = 0x200
leaq 0x6105(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
incl %r13d
cmpl %ebp, %r13d
jne 0xa6af
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm4.c
// Function: target_verify
static void target_verify(void)
{
  uint32_t addr = FLASH_START + 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;

    verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x743fc(%rip), %ebx     # 0x7eb48
movq 0x7440d(%rip), %rax     # 0x7eb60
movq %rax, 0x10(%rsp)
movl 0x743f9(%rip), %r15d    # 0x7eb58
movl $0x200, %edi            # imm = 0x200
callq 0x7dba
movq %rax, %r14
testl %r15d, %r15d
je 0xa82a
addl $0x400000, %ebx         # imm = 0x400000
leaq 0x92f6(%rip), %r13      # 0x13a78
xorl %ebp, %ebp
movl %ebp, 0x8(%rsp)
movl %ebp, %ebp
addq 0x10(%rsp), %rbp
movl %ebx, %edi
movq %r14, %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x7258
movl $0x200, %eax            # imm = 0x200
cmpl %eax, %r15d
movl %r15d, 0xc(%rsp)
cmovbl %r15d, %eax
cmpl $0x1, %eax
movl %eax, 0x4(%rsp)
movl %eax, %r15d
adcl $0x0, %r15d
xorl %r12d, %r12d
movzbl (%rbp,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xa7f3
leal (%rbx,%r12), %esi
leaq 0x8033(%rip), %rdi      # 0x1280d
xorl %eax, %eax
callq 0x7a78
movq %r14, %rdi
callq 0x7de7
movq %r13, %rdi
xorl %eax, %eax
callq 0x7c8d
incq %r12
cmpq %r12, %r15
jne 0xa7c0
addq $0x200, %rbx            # imm = 0x200
movl 0x8(%rsp), %ebp
addl $0x200, %ebp            # imm = 0x200
leaq 0x600c(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
movl 0xc(%rsp), %r15d
subl 0x4(%rsp), %r15d
jne 0xa784
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7de7
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm4.c
// Function: target_read
static void target_read(void)
{
  uint32_t addr = FLASH_START + 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;

    verbose(".");
  }

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x74311(%rip), %rbx     # 0x7eb60
movl 0x742f7(%rip), %ebp     # 0x7eb4c
testl %ebp, %ebp
je 0xa89a
movl $0x400000, %r15d        # imm = 0x400000
addl 0x742e2(%rip), %r15d    # 0x7eb48
leaq 0x5fb2(%rip), %r14      # 0x1081f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x7258
addl $0x200, %r12d           # imm = 0x200
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
cmpl %r12d, %ebp
jne 0xa870
movq 0x7429f(%rip), %rdi     # 0x7eb40
movl 0x742a5(%rip), %edx     # 0x7eb4c
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7e95
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm4.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(0), CMD_GGPB);
  while (0 == (dap_read_word(EEFC_FSR(0)) & FSR_FRDY));
  gpnvm = dap_read_word(EEFC_FRR(0));

  data[0] = gpnvm;

  return GPNVM_SIZE;
}

// Assembly:
xorl %eax, %eax
testl %edi, %edi
jle 0xa8be
retq
pushq %rbx
movq %rsi, %rbx
movl $0x400e0a04, %edi       # imm = 0x400E0A04
movl $0x5a00000d, %esi       # imm = 0x5A00000D
callq 0x723e
movl $0x400e0a08, %edi       # imm = 0x400E0A08
callq 0x71ef
testb $0x1, %al
je 0xa8d1
movl $0x400e0a0c, %edi       # imm = 0x400E0A0C
callq 0x71ef
movb %al, (%rbx)
movl $0x1, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm4.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t gpnvm = 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(0), CMD_SGPB | (i << 8));
    else
      dap_write_word(EEFC_FCR(0), CMD_CGPB | (i << 8));
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movzbl (%rsi), %ebx
xorl %eax, %eax
testl %edi, %edi
sete %al
leaq 0x7f35(%rip), %rsi      # 0x1283c
xorl %ebp, %ebp
movl %eax, %edi
xorl %eax, %eax
callq 0x7bb4
xorl %r14d, %r14d
btl %r14d, %ebx
movl %ebp, %esi
sbbl $-0x1, %esi
addl $0x5a00000b, %esi       # imm = 0x5A00000B
movl $0x400e0a04, %edi       # imm = 0x400E0A04
callq 0x723e
incl %r14d
addl $0x100, %ebp            # imm = 0x100
cmpl $0x800, %ebp            # imm = 0x800
jne 0xa915
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm7.c
// Function: target_deselect
static void target_deselect(void)
{
  dap_write_word(DHCSR, DHCSR_DBGKEY);
  dap_write_word(DEMCR, 0);
  dap_reset_target_hw(1);

  target_free_options(&target_options);
}

// Assembly:
pushq %rax
movl $0xe000edf0, %edi       # imm = 0xE000EDF0
movl $0xa05f0000, %esi       # imm = 0xA05F0000
callq 0x723e
movl $0xe000edfc, %edi       # imm = 0xE000EDFC
xorl %esi, %esi
callq 0x723e
movl $0x1, %edi
callq 0x6fe8
leaq 0x74022(%rip), %rdi     # 0x7eb88
popq %rax
jmp 0x8ffc
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_atmel_cm7.c
// Function: target_program
static void target_program(void)
{
  uint32_t addr = FLASH_START + target_options.offset;
  uint32_t number_of_pages, page_offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.file_size;

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

  for (uint32_t page = 0; page < number_of_pages; page += PAGES_IN_ERASE_BLOCK)
  {
    dap_write_word(EEFC_FCR, CMD_EPA | (((page_offset + page) | 2) << 8));
    while (0 == (dap_read_word(EEFC_FSR) & FSR_FRDY));

    verbose(".");
  }

  verbose(",");

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    dap_write_block(addr, &buf[offs], FLASH_PAGE_SIZE);
    addr += FLASH_PAGE_SIZE;
    offs += FLASH_PAGE_SIZE;

    dap_write_word(EEFC_FCR, CMD_WP | ((page + page_offset) << 8));
    while (0 == (dap_read_word(EEFC_FSR) & FSR_FRDY));

    verbose(".");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x73ff4(%rip), %ebx     # 0x7eba0
movl $0x1ff, %eax            # imm = 0x1FF
leal (%rbx,%rax), %r15d
addl 0x73ff5(%rip), %eax     # 0x7ebb0
movq 0x73ff6(%rip), %r12     # 0x7ebb8
movl %eax, %ebp
shrl $0x9, %ebp
testl %ebx, %ebx
cmovnsl %ebx, %r15d
sarl $0x9, %r15d
movq %rax, (%rsp)
cmpl $0x200, %eax            # imm = 0x200
jb 0xac1e
leaq 0x5c3c(%rip), %r14      # 0x1081f
xorl %r13d, %r13d
leal (%r15,%r13), %esi
shll $0x8, %esi
orl $0x5a000207, %esi       # imm = 0x5A000207
movl $0x400e0c04, %edi       # imm = 0x400E0C04
callq 0x723e
movl $0x400e0c08, %edi       # imm = 0x400E0C08
callq 0x71ef
testb $0x1, %al
je 0xabfd
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
addl $0x10, %r13d
cmpl %ebp, %r13d
jb 0xabe6
leaq 0x81a7(%rip), %rdi      # 0x12dcc
xorl %eax, %eax
callq 0x7a78
cmpl $0x200, (%rsp)          # imm = 0x200
jb 0xac99
addl $0x400000, %ebx         # imm = 0x400000
xorl %r13d, %r13d
xorl %r14d, %r14d
leaq (%r12,%r13), %rsi
movl %ebx, %edi
movl $0x200, %edx            # imm = 0x200
callq 0x73b6
addl $0x200, %ebx            # imm = 0x200
leal (%r14,%r15), %esi
shll $0x8, %esi
orl $0x5a000001, %esi       # imm = 0x5A000001
movl $0x400e0c04, %edi       # imm = 0x400E0C04
callq 0x723e
movl $0x400e0c08, %edi       # imm = 0x400E0C08
callq 0x71ef
testb $0x1, %al
je 0xac6e
addq $0x200, %r13            # imm = 0x200
leaq 0x5b95(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
incl %r14d
cmpl %ebp, %r14d
jne 0xac41
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xae2e
retq
pushq %rbx
movq %rsi, %rbx
movl $0x400e0c04, %edi       # imm = 0x400E0C04
movl $0x5a00000d, %esi       # imm = 0x5A00000D
callq 0x723e
movl $0x400e0c08, %edi       # imm = 0x400E0C08
callq 0x71ef
testb $0x1, %al
je 0xae41
movl $0x400e0c0c, %edi       # imm = 0x400E0C0C
callq 0x71ef
movw %ax, (%rbx)
movl $0x2, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x79c4(%rip), %rsi      # 0x1283c
xorl %ebp, %ebp
movl %eax, %edi
xorl %eax, %eax
callq 0x7bb4
xorl %r14d, %r14d
btl %r14d, %ebx
movl %ebp, %esi
sbbl $-0x1, %esi
addl $0x5a00000b, %esi       # imm = 0x5A00000B
movl $0x400e0c04, %edi       # imm = 0x400E0C04
callq 0x723e
incl %r14d
addl $0x100, %ebp            # imm = 0x100
cmpl $0x900, %ebp            # imm = 0x900
jne 0xae86
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x720d
movl $0x64, %edi
callq 0x7d74
movl $0x41002101, %edi       # imm = 0x41002101
callq 0x71b5
testb $0x1, %al
je 0xb028
xorl %edi, %edi
callq 0x6fe8
movl $0xa, %edi
callq 0x7d74
callq 0x6789
popq %rax
jmp 0xb3f9
// File: /workspace/github_c_makefile_star2_O1/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 0x7509(%rip), %rsi      # 0x1283c
movl %eax, %edi
xorl %eax, %eax
callq 0x7bb4
movl $0x41004014, %edi       # imm = 0x41004014
movl $0x804000, %esi         # imm = 0x804000
callq 0x723e
movl $0x41004004, %edi       # imm = 0x41004004
movl $0xa500, %esi           # imm = 0xA500
callq 0x7224
movl $0x41004012, %edi       # imm = 0x41004012
callq 0x71d0
testb $0x1, %al
je 0xb35a
movl $0x41004004, %edi       # imm = 0x41004004
movl $0xa515, %esi           # imm = 0xA515
callq 0x7224
movl $0x41004012, %edi       # imm = 0x41004012
callq 0x71d0
testb $0x1, %al
je 0xb377
movl $0x804000, %ebp         # imm = 0x804000
xorl %r14d, %r14d
movl $0x41004014, %edi       # imm = 0x41004014
movl $0x804000, %esi         # imm = 0x804000
callq 0x723e
movl %ebp, %edi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x73b6
movl $0x41004004, %edi       # imm = 0x41004004
movl $0xa504, %esi           # imm = 0xA504
callq 0x7224
movl $0x41004012, %edi       # imm = 0x41004012
callq 0x71d0
testb $0x1, %al
je 0xb3ba
addl $0x10, %ebp
addq $0x10, %rbx
incl %r14d
cmpl $0x20, %r14d
jne 0xb38d
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xb9da
movl $0x41002118, %edi       # imm = 0x41002118
callq 0x71ef
movl %eax, %ecx
andl $0xfffff0ff, %ecx       # imm = 0xFFFFF0FF
movl %eax, %edx
shrl $0x8, %edx
andl $0xf, %edx
xorl %r14d, %r14d
leaq 0xf577(%rip), %r15      # 0x1a9e0
cmpl %ecx, (%r14,%r15)
je 0xb491
addq $0x28, %r14
cmpq $0x2f8, %r14            # imm = 0x2F8
jne 0xb469
leaq 0x6bde(%rip), %rdi      # 0x12061
movl %eax, %esi
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
jmp 0x7c8d
movq 0x10(%r14,%r15), %rsi
addl $0x41, %edx
leaq 0x6b86(%rip), %rdi      # 0x12026
xorl %eax, %eax
callq 0x7a78
movq 0x20(%r14,%r15), %rax
movq %rax, 0x73785(%rip)     # 0x7ec38
movups (%r14,%r15), %xmm0
movups 0x10(%r14,%r15), %xmm1
movups %xmm1, 0x73763(%rip)    # 0x7ec28
movups %xmm0, 0x7374c(%rip)    # 0x7ec18
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm0, 0x73762(%rip)    # 0x7ec40
movups %xmm1, 0x7376b(%rip)    # 0x7ec50
movups %xmm2, 0x73774(%rip)    # 0x7ec60
movq 0x30(%rbx), %rax
movq %rax, 0x73779(%rip)     # 0x7ec70
leaq 0x73742(%rip), %rdi     # 0x7ec40
movzbl 0x7372f(%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, 0x73753(%rip)     # 0x7ec78
movl %edx, 0x73751(%rip)     # 0x7ec7c
movl %esi, 0x7374f(%rip)     # 0x7ec80
movl %eax, 0x7374d(%rip)     # 0x7ec84
movl 0x736f3(%rip), %esi     # 0x7ec30
movl $0x100, %edx            # imm = 0x100
popq %rbx
popq %r14
popq %r15
jmp 0x8edf
// File: /workspace/github_c_makefile_star2_O1/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 0xb9da
movl $0xa, %edi
callq 0x7d74
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71b5
testb %al, %al
js 0xb58c
movl $0x55, %edi
callq 0xba01
movl $0x20, %edi
callq 0xba24
jmp 0xb5a6
movl $0x41002124, %edi       # imm = 0x41002124
callq 0x71ef
leaq 0x7c6c(%rip), %rdi      # 0x13209
movl %eax, %esi
xorl %eax, %eax
callq 0x62f0
cmpb $0x1, 0x73687(%rip)     # 0x7ec34
jne 0xb5d9
movl $0xe2, %edi
callq 0xba01
movl $0x24, %edi
callq 0xba24
callq 0xbaad
callq 0xbaad
callq 0xbaad
callq 0xbaad
jmp 0xb5ed
movl $0xe3, %edi
callq 0xba01
movl $0x24, %edi
callq 0xba24
movl $0x21, %edi
popq %rax
jmp 0xba24
// File: /workspace/github_c_makefile_star2_O1/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 0x73628(%rip), %ebx     # 0x7ec58
movq 0x73639(%rip), %r15     # 0x7ec70
movl 0x7362b(%rip), %ebp     # 0x7ec68
callq 0xbacd
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71b5
andb $0x3, %al
cmpb $0x2, %al
je 0xb660
leaq 0x7cb3(%rip), %rdi      # 0x1330c
xorl %eax, %eax
callq 0x7c8d
addl $0xff, %ebp
movl 0x73610(%rip), %edi     # 0x7ec7c
xorl %esi, %esi
callq 0x720d
cmpl $0x100, %ebp            # imm = 0x100
jb 0xb6e6
shrl $0x8, %ebp
leaq 0x519a(%rip), %r14      # 0x1081f
xorl %r12d, %r12d
xorl %r13d, %r13d
movl 0x735f3(%rip), %edi     # 0x7ec84
movl %ebx, %esi
callq 0x723e
movl 0x735da(%rip), %edi     # 0x7ec78
movl $0xa502, %esi           # imm = 0xA502
callq 0x7224
movl 0x735d2(%rip), %edi     # 0x7ec80
callq 0x71b5
testb $0x4, %al
je 0xb6a8
leaq (%r15,%r12), %rsi
movl %ebx, %edi
movl $0x100, %edx            # imm = 0x100
callq 0x73b6
addl $0x100, %ebx            # imm = 0x100
addq $0x100, %r12            # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
incl %r13d
cmpl %ebp, %r13d
jne 0xb68b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x7354f(%rip), %ebx     # 0x7ec58
movq 0x73560(%rip), %rax     # 0x7ec70
movq %rax, 0x10(%rsp)
movl 0x7354c(%rip), %r15d    # 0x7ec68
callq 0xbacd
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71b5
andb $0x3, %al
cmpb $0x2, %al
je 0xb73f
leaq 0x7c1d(%rip), %rdi      # 0x13355
xorl %eax, %eax
callq 0x7c8d
movl $0x100, %edi            # imm = 0x100
callq 0x7dba
movq %rax, %r14
testl %r15d, %r15d
je 0xb804
leaq 0x831c(%rip), %r13      # 0x13a78
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 0x7258
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %r15d
movl %r15d, 0xc(%rsp)
cmovbl %r15d, %eax
cmpl $0x1, %eax
movl %eax, 0x4(%rsp)
movl %eax, %r15d
adcl $0x0, %r15d
xorl %r12d, %r12d
movzbl (%rbp,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xb7cd
leal (%rbx,%r12), %esi
leaq 0x7059(%rip), %rdi      # 0x1280d
xorl %eax, %eax
callq 0x7a78
movq %r14, %rdi
callq 0x7de7
movq %r13, %rdi
xorl %eax, %eax
callq 0x7c8d
incq %r12
cmpq %r12, %r15
jne 0xb79a
addq $0x100, %rbx            # imm = 0x100
movl 0x8(%rsp), %ebp
addl $0x100, %ebp            # imm = 0x100
leaq 0x5032(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
movl 0xc(%rsp), %r15d
subl 0x4(%rsp), %r15d
jne 0xb75e
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7de7
// File: /workspace/github_c_makefile_star2_O1/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 0x7342f(%rip), %r15d    # 0x7ec58
movq 0x73440(%rip), %rbx     # 0x7ec70
movl 0x73426(%rip), %ebp     # 0x7ec5c
callq 0xbacd
movl $0x41002102, %edi       # imm = 0x41002102
callq 0x71b5
andb $0x3, %al
cmpb $0x2, %al
je 0xb859
leaq 0x7b35(%rip), %rdi      # 0x13387
xorl %eax, %eax
callq 0x7c8d
testl %ebp, %ebp
je 0xb891
leaq 0x4fbb(%rip), %r14      # 0x1081f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7258
addl $0x100, %r12d           # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
cmpl %r12d, %ebp
jne 0xb867
movq 0x733b8(%rip), %rdi     # 0x7ec50
movl 0x733be(%rip), %edx     # 0x7ec5c
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7e95
// File: /workspace/github_c_makefile_star2_O1/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 0xb8c9
xorl %ebp, %ebp
cmpl $0x1, %edi
jne 0xb8e9
movl $0x80c000, %r14d        # imm = 0x80C000
jmp 0xb8cf
movl $0x804000, %r14d        # imm = 0x804000
callq 0xbacd
movl $0x100, %ebp            # imm = 0x100
movl %r14d, %edi
movq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7258
movl %ebp, %eax
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xb95b
movl $0x804000, %ebp         # imm = 0x804000
movl %edi, %eax
leaq 0x777f(%rip), %rcx      # 0x13088
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x8(%rbx), %rdi
movl 0x7331c(%rip), %esi     # 0x7ec38
addl $-0x8, %esi
callq 0x8c94
movslq 0x7330d(%rip), %rcx     # 0x7ec38
movl %eax, (%rbx,%rcx)
jmp 0xb96b
movq %rbx, %rdi
movl $0x8, %esi
callq 0x8c94
movl %eax, 0x8(%rbx)
leaq 0xe0(%rbx), %rdx
movq %rbx, %rdi
movl $0xe0, %esi
callq 0x89dc
movl $0x80c000, %ebp         # imm = 0x80C000
jmp 0xb96b
leaq 0x6eda(%rip), %rdi      # 0x1283c
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x7c8d
callq 0xbacd
movl 0x73306(%rip), %edi     # 0x7ec7c
xorl %esi, %esi
callq 0x720d
movl 0x73301(%rip), %edi     # 0x7ec84
movl %ebp, %esi
callq 0x723e
movl 0x732e8(%rip), %edi     # 0x7ec78
movl $0xa502, %esi           # imm = 0xA502
callq 0x7224
movl 0x732e0(%rip), %edi     # 0x7ec80
callq 0x71b5
testb $0x4, %al
je 0xb99a
movl %ebp, %edi
movq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x73b6
// File: /workspace/github_c_makefile_star2_O1/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 0x6fe8
movl $0xa, %edi
callq 0x7d74
callq 0x6789
movl $0x41002101, %edi       # imm = 0x41002101
movl $0x2, %esi
popq %rax
jmp 0x720d
// File: /workspace/github_c_makefile_star2_O1/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 0x71b5
decl %ebp
testb %al, %al
js 0xba45
cmpl $0x1, %ebp
ja 0xba2e
xorl %ebp, %ebp
testl %ebp, %ebp
jne 0xba57
leaq 0x77fd(%rip), %rdi      # 0x1324d
xorl %eax, %eax
callq 0x7c8d
movl $0x41002124, %edi       # imm = 0x41002124
callq 0x71ef
movl %eax, %ebp
andl $0xffffff00, %eax       # imm = 0xFFFFFF00
cmpl $0xec000000, %eax       # imm = 0xEC000000
je 0xba7f
leaq 0x77eb(%rip), %rdi      # 0x13261
movl %ebp, %esi
xorl %eax, %eax
callq 0x7c8d
movzbl %bpl, %ebp
cmpl $-0x1, %ebx
sete %al
cmpl %ebx, %ebp
sete %cl
orb %al, %cl
jne 0xbaa4
leaq 0x77ef(%rip), %rdi      # 0x13288
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x7c8d
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x723e
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x10004, %esi          # imm = 0x10004
callq 0x723e
callq 0xbff9
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
popq %rax
jmp 0x723e
// File: /workspace/github_c_makefile_star2_O1/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 0x72f77(%rip), %r14d    # 0x7ecc0
movl $0x7ff, %r15d           # imm = 0x7FF
leal (%r14,%r15), %eax
testl %r14d, %r14d
cmovnsl %r14d, %eax
movq %rax, (%rsp)
addl 0x72f6b(%rip), %r15d    # 0x7ecd0
cmpl $0x800, %r15d           # imm = 0x800
jb 0xbe1f
movq 0x72f5f(%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 0x723e
orl $0x10002, %ebp          # imm = 0x10002
movl $0x40022014, %edi       # imm = 0x40022014
movl %ebp, %esi
callq 0x723e
callq 0xbff9
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x1, %esi
callq 0x723e
xorl %ebp, %ebp
leal (%r14,%rbp), %edi
leal (%r12,%rbp), %esi
addq %r13, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x73b6
addl $0x100, %ebp            # imm = 0x100
cmpl $0x800, %ebp            # imm = 0x800
jne 0xbdd8
leaq 0x4a1d(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
callq 0xbff9
incl %ebx
addl %ebp, %r14d
addl %ebp, %r12d
cmpl %r15d, %ebx
jne 0xbd94
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x723e
// File: /workspace/github_c_makefile_star2_O1/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 0x72e73(%rip), %ebx     # 0x7ecc0
movq 0x72e84(%rip), %rax     # 0x7ecd8
movq %rax, 0x10(%rsp)
movl 0x72e71(%rip), %ebp     # 0x7ecd0
movl $0x100, %edi            # imm = 0x100
callq 0x7dba
movq %rax, %r14
testl %ebp, %ebp
je 0xbf2f
addl $0x8000000, %ebx        # imm = 0x8000000
leaq 0x7bf7(%rip), %r13      # 0x13a78
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 0x7258
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %ebp
movl %ebp, 0xc(%rsp)
cmovbl %ebp, %eax
cmpl $0x1, %eax
movl %eax, 0x4(%rsp)
movl %eax, %ebp
adcl $0x0, %ebp
xorl %r12d, %r12d
movzbl (%r15,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xbeef
leal (%rbx,%r12), %esi
leaq 0x6937(%rip), %rdi      # 0x1280d
xorl %eax, %eax
callq 0x7a78
movq %r14, %rdi
callq 0x7de7
movq %r13, %rdi
xorl %eax, %eax
callq 0x7c8d
incq %r12
cmpq %r12, %rbp
jne 0xbebd
movl 0x8(%rsp), %r15d
addl $0x100, %r15d           # imm = 0x100
testl $0x700, %r15d           # imm = 0x700
jne 0xbf1a
leaq 0x490c(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
addq $0x100, %rbx            # imm = 0x100
movl 0xc(%rsp), %ebp
subl 0x4(%rsp), %ebp
jne 0xbe84
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7de7
// File: /workspace/github_c_makefile_star2_O1/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 0x72d84(%rip), %rbx     # 0x7ecd8
movl 0x72d6a(%rip), %ebp     # 0x7ecc4
testl %ebp, %ebp
je 0xbf9f
movl $0x8000000, %r15d       # imm = 0x8000000
addl 0x72d55(%rip), %r15d    # 0x7ecc0
leaq 0x48ad(%rip), %r14      # 0x1081f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7258
addl $0x100, %r12d           # imm = 0x100
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
cmpl %r12d, %ebp
jne 0xbf75
movq 0x72d12(%rip), %rdi     # 0x7ecb8
movl 0x72d18(%rip), %edx     # 0x7ecc4
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7e95
// File: /workspace/github_c_makefile_star2_O1/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 0x71ef
btl $0x10, %eax
jb 0xbffa
movl $0x40022010, %edi       # imm = 0x40022010
callq 0x71ef
testl $0xc3fa, %eax           # imm = 0xC3FA
je 0xc02c
leaq 0x7432(%rip), %rdi      # 0x13454
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7c8d
popq %rax
retq
nop