user: What would the C source look like for the assembly code provided here?

```asm
<hexfile_build_tables>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x150,%rsp
  mov    %rdi,-0x138(%rbp)
  mov    %rsi,-0x140(%rbp)
  mov    %rdx,-0x148(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movq   $0x0,-0x120(%rbp)
  movw   $0x0,-0x12e(%rbp)
  mov    -0x138(%rbp),%rax
  lea    D17(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <fopen@plt>
  mov    %rax,-0x118(%rbp)
  cmpq   $0x0,-0x118(%rbp)
  jne    L23
  mov    -0x138(%rbp),%rax
  mov    %rax,%rsi
  lea    D88(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0xffffffff,%eax
  jmp    L129
L23:
  lea    D11(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  lea    -0x110(%rbp),%rax
  mov    $0x100,%esi
  mov    %rax,%rdi
  call   <bzero@plt>
  mov    -0x148(%rbp),%rax
  mov    $0x40,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  mov    -0x140(%rbp),%rax
  mov    $0x8,%edx
  mov    $0xff,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  movl   $0x0,-0x128(%rbp)
  jmp    L93
L3:
  movb   $0x0,-0x12f(%rbp)
  lea    -0x110(%rbp),%rax
  add    $0x7,%rax
  mov    $0x2,%edx
  lea    D68(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcmp@plt>
  test   %rax,%rax
  jne    L58
  movl   $0x0,-0x12c(%rbp)
  lea    -0x12f(%rbp),%rax
  lea    -0x110(%rbp),%rdx
  lea    0x1(%rdx),%rcx
  mov    %rax,%rdx
  lea    D0(%rip),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  lea    -0x12e(%rbp),%rax
  lea    -0x110(%rbp),%rdx
  lea    0x3(%rdx),%rcx
  mov    %rax,%rdx
  lea    D84(%rip),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  jmp    L11
L77:
  movzwl -0x12e(%rbp),%eax
  movzwl %ax,%edx
  mov    -0x120(%rbp),%rax
  add    %eax,%edx
  mov    -0x12c(%rbp),%eax
  add    %edx,%eax
  mov    %eax,-0x124(%rbp)
  mov    -0x124(%rbp),%eax
  lea    0x7ff(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0xb,%eax
  movslq %eax,%rdx
  mov    -0x148(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L133
  mov    -0x124(%rbp),%eax
  lea    0x7ff(%rax),%edx
  test   %eax,%eax
  cmovs  %edx,%eax
  sar    $0xb,%eax
  movslq %eax,%rdx
  mov    -0x148(%rbp),%rax
  add    %rdx,%rax
  movb   $0x1,(%rax)
  addl   $0x1,-0x128(%rbp)
  mov    -0x128(%rbp),%eax
  mov    %eax,%esi
  lea    D111(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
L133:
  mov    -0x124(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x140(%rbp),%rax
  add    %rax,%rdx
  mov    -0x12c(%rbp),%eax
  add    %eax,%eax
  add    $0x9,%eax
  lea    -0x110(%rbp),%rcx
  cltq
  add    %rcx,%rax
  lea    D0(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  addl   $0x1,-0x12c(%rbp)
L11:
  movzbl -0x12f(%rbp),%eax
  movzbl %al,%eax
  cmp    %eax,-0x12c(%rbp)
  jl     L77
  jmp    L93
L58:
  lea    -0x110(%rbp),%rax
  add    $0x7,%rax
  mov    $0x2,%edx
  lea    D120(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcmp@plt>
  test   %rax,%rax
  jne    L32
  lea    D41(%rip),%rax
  mov    %rax,%rdi
  call   <puts@plt>
  jmp    L92
L32:
  lea    -0x110(%rbp),%rax
  add    $0x7,%rax
  mov    $0x2,%edx
  lea    D10(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <memcmp@plt>
  test   %rax,%rax
  jne    L93
  lea    -0x12e(%rbp),%rax
  lea    -0x110(%rbp),%rdx
  lea    0x3(%rdx),%rcx
  mov    %rax,%rdx
  lea    D84(%rip),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  lea    -0x120(%rbp),%rax
  lea    -0x110(%rbp),%rdx
  lea    0x9(%rdx),%rcx
  mov    %rax,%rdx
  lea    D105(%rip),%rax
  mov    %rax,%rsi
  mov    %rcx,%rdi
  mov    $0x0,%eax
  call   <sscanf@plt>
  mov    -0x120(%rbp),%rax
  shl    $0xf,%rax
  mov    %rax,%rsi
  lea    D141(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x120(%rbp),%rax
  test   %rax,%rax
  je     L50
  mov    -0x120(%rbp),%rax
  sub    $0x1,%rax
  mov    %rax,-0x120(%rbp)
L50:
  mov    -0x120(%rbp),%rax
  shl    $0xf,%rax
  mov    %rax,-0x120(%rbp)
L93:
  lea    -0x110(%rbp),%rdx
  mov    -0x118(%rbp),%rax
  lea    D72(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <fscanf@plt>
  cmp    $0x1,%eax
  je     L3
L92:
  mov    -0x118(%rbp),%rax
  mov    %rax,%rdi
  call   <fclose@plt>
  mov    -0x128(%rbp),%eax
L129:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L67
  call   <__stack_chk_fail@plt>
L67:
  leave
  ret
```

tool_calls: name: retrieve_data
arguments: data_label: D17
type: string
name: retrieve_data
arguments: data_label: D88
type: string
name: retrieve_data
arguments: data_label: D11
type: string
name: retrieve_data
arguments: data_label: D68
type: string
name: retrieve_data
arguments: data_label: D0
type: string
name: retrieve_data
arguments: data_label: D84
type: string
name: retrieve_data
arguments: data_label: D111
type: string
name: retrieve_data
arguments: data_label: D120
type: string
name: retrieve_data
arguments: data_label: D41
type: string
name: retrieve_data
arguments: data_label: D10
type: string
name: retrieve_data
arguments: data_label: D105
type: string
name: retrieve_data
arguments: data_label: D141
type: string
name: retrieve_data
arguments: data_label: D72
type: string

tool: D17: r

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


tool: D11: .ihex file ok.

tool: D68: 00

tool: D0: %2hhx

tool: D84: %4hx

tool: D111: Writing %d pages.

tool: D120: 01

tool: D41: 
File read complete.

tool: D10: 04

tool: D105: %4lx

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


tool: D72: %s

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);
}
```