user: Demonstrate the C code that generates the assembly output below:

```asm
<hexfile_build_tables>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x138,%rsp
  mov    %rdi,%rbx
  mov    %rsi,(%rsp)
  mov    %rdx,0x8(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x128(%rsp)
  xor    %eax,%eax
  movq   $0x0,0x18(%rsp)
  movw   $0x0,0x16(%rsp)
  lea    D33(%rip),%rsi
  call   <fopen@plt>
  test   %rax,%rax
  je     L59
  mov    %rax,%r15
  lea    D22(%rip),%rdi
  call   <puts@plt>
  lea    0x20(%rsp),%rdi
  mov    $0x100,%esi
  call   <bzero@plt>
  mov    $0x40,%edx
  mov    $0x0,%esi
  mov    0x8(%rsp),%rdi
  call   <memset@plt>
  mov    $0x8,%edx
  mov    $0xff,%esi
  mov    (%rsp),%rdi
  call   <memset@plt>
  mov    $0x0,%r14d
  jmp    L121
L59:
  mov    %rbx,%rsi
  lea    D1(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0xffffffff,%r14d
  jmp    L32
L54:
  lea    0x15(%rsp),%rdx
  lea    0x21(%rsp),%rdi
  lea    D37(%rip),%rsi
  call   <sscanf@plt>
  lea    0x16(%rsp),%rdx
  lea    0x23(%rsp),%rdi
  lea    D122(%rip),%rsi
  mov    $0x0,%eax
  call   <sscanf@plt>
  cmpb   $0x0,0x15(%rsp)
  je     L121
  lea    0x29(%rsp),%r12
  mov    $0x0,%ebp
  lea    D37(%rip),%r13
  jmp    L118
L71:
  movslq %ebx,%rdx
  add    (%rsp),%rdx
  mov    %r13,%rsi
  mov    %r12,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  add    $0x1,%ebp
  add    $0x2,%r12
  movzbl 0x15(%rsp),%eax
  cmp    %ebp,%eax
  jle    L121
L118:
  movzwl 0x16(%rsp),%ebx
  add    0x18(%rsp),%ebx
  add    %ebp,%ebx
  lea    0x7ff(%rbx),%eax
  cmovns %ebx,%eax
  sar    $0xb,%eax
  cltq
  add    0x8(%rsp),%rax
  cmpb   $0x0,(%rax)
  jne    L71
  movb   $0x1,(%rax)
  add    $0x1,%r14d
  mov    %r14d,%esi
  lea    D35(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L71
L86:
  lea    D62(%rip),%rdi
  call   <puts@plt>
L89:
  mov    %r15,%rdi
  call   <fclose@plt>
L32:
  mov    0x128(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L127
  mov    %r14d,%eax
  add    $0x138,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L60:
  shlq   $0xf,0x18(%rsp)
L121:
  lea    0x20(%rsp),%rdx
  lea    D76(%rip),%rsi
  mov    %r15,%rdi
  call   <fscanf@plt>
  cmp    $0x1,%eax
  jne    L89
  movb   $0x0,0x15(%rsp)
  lea    0x27(%rsp),%rdi
  mov    $0x2,%edx
  lea    D2(%rip),%rsi
  call   <memcmp@plt>
  test   %rax,%rax
  je     L54
  lea    0x27(%rsp),%rdi
  mov    $0x2,%edx
  lea    D86(%rip),%rsi
  call   <memcmp@plt>
  test   %rax,%rax
  je     L86
  lea    0x27(%rsp),%rdi
  mov    $0x2,%edx
  lea    D114(%rip),%rsi
  call   <memcmp@plt>
  test   %rax,%rax
  jne    L121
  lea    0x16(%rsp),%rdx
  lea    0x23(%rsp),%rdi
  lea    D122(%rip),%rsi
  call   <sscanf@plt>
  lea    0x18(%rsp),%rdx
  lea    0x29(%rsp),%rdi
  lea    D18(%rip),%rsi
  mov    $0x0,%eax
  call   <sscanf@plt>
  mov    0x18(%rsp),%rsi
  shl    $0xf,%rsi
  lea    D87(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    0x18(%rsp),%rax
  test   %rax,%rax
  je     L60
  sub    $0x1,%rax
  mov    %rax,0x18(%rsp)
  jmp    L60
L127:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: tag: D33
type: string
name: extract_symbolic_data
arguments: tag: D22
type: string
name: extract_symbolic_data
arguments: tag: D1
type: string
name: extract_symbolic_data
arguments: tag: D37
type: string
name: extract_symbolic_data
arguments: tag: D122
type: string
name: extract_symbolic_data
arguments: tag: D35
type: string
name: extract_symbolic_data
arguments: tag: D62
type: string
name: extract_symbolic_data
arguments: tag: D76
type: string
name: extract_symbolic_data
arguments: tag: D2
type: string
name: extract_symbolic_data
arguments: tag: D86
type: string
name: extract_symbolic_data
arguments: tag: D114
type: string
name: extract_symbolic_data
arguments: tag: D18
type: string
name: extract_symbolic_data
arguments: tag: D87
type: string

tool: D33: r

tool: D22: .ihex file ok.

tool: D1: Failed to open .ihex file %s


tool: D37: %2hhx

tool: D122: %4hx

tool: D35: Writing %d pages.

tool: D62: 
File read complete.

tool: D76: %s

tool: D2: 00

tool: D86: 01

tool: D114: 04

tool: D18: %4lx

tool: D87: 
Extended page address: 0x%8.8lX


assistant: ```c
int hexfile_build_tables(char *ihexfile, unsigned char *page_buffer, unsigned char *page_table) {
  unsigned char buffer[256];
  int length;
  int i;
  int pages;
  unsigned long ext_addr = 0;
  unsigned short int addr = 0;
  FILE *ihex_fp;
  if ((ihex_fp = (FILE *)fopen(ihexfile, "r")) == NULL) {
    printf("Failed to open .ihex file %s\n", ihexfile);
    return (-1);
  } else {
    printf(".ihex file ok.\n");
  }
  bzero(buffer, sizeof(buffer));
  memset(page_table, 0, 64);
  memset(page_buffer, 0xFF, sizeof(page_buffer));
  pages = 0;
  while ((fscanf(ihex_fp, "%s", buffer) == 1)) {
    unsigned char data_len = 0;
    if (memcmp(&buffer[7], "00", 2) == 0) {
      i = 0;
      sscanf((char *)&buffer[1], "%2hhx", &data_len);
      sscanf((char *)&(buffer[3]), "%4hx", &addr);
      while (i < data_len) {
        uint32_t absolute_address = ext_addr + addr + i;
        if (page_table[absolute_address / 2048] == 0) {
          page_table[absolute_address / 2048] = 1;
          printf("Writing %d pages.\r", ++pages);
        }
        sscanf((char *)&buffer[2 * i + 9], "%2hhx", &page_buffer[absolute_address]);
        i++;
      }
    } else if (memcmp(&buffer[7], "01", 2) == 0) {
      printf("\nFile read complete.\n");
      break;
    } else if (memcmp(&buffer[7], "04", 2) == 0) {
      sscanf((char *)&(buffer[3]), "%4hx", &addr);
      sscanf((char *)&(buffer[9]), "%4lx", &ext_addr);
      printf("\nExtended page address: 0x%8.8lX\n", ext_addr * 0x8000);
      if (ext_addr)
        ext_addr--;
      ext_addr *= 0x8000;
    }
  }
  fclose(ihex_fp);
  return (pages);
}
```