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

```asm
<bm_load_palette>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x88,%rsp
  mov    %rsi,(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x78(%rsp)
  xor    %eax,%eax
  movl   $0x8,0x1c(%rsp)
  test   %rdi,%rdi
  je     L164
  test   %rsi,%rsi
  je     L164
  movl   $0x0,(%rsi)
  lea    D9(%rip),%rsi
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L164
  lea    0x30(%rsp),%rbx
  mov    %rax,%rdx
  mov    $0x40,%esi
  mov    %rbx,%rdi
  call   <fgets@plt>
  mov    $0x8,%edx
  lea    D10(%rip),%rsi
  mov    %rbx,%rdi
  call   <strncmp@plt>
  test   %eax,%eax
  je     L46
  mov    %rbp,%rdi
  call   <rewind@plt>
  mov    0x1c(%rsp),%edi
  mov    $0x4,%esi
  call   <calloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L109
  xor    %r12d,%r12d
  nopw   0x0(%rax,%rax,1)
L139:
  mov    %rbp,%rdx
  mov    $0x40,%esi
  mov    %rbx,%rdi
  call   <fgets@plt>
  test   %rax,%rax
  je     L341
  cmp    $0x100,%r12d
  je     L200
  movsbl 0x30(%rsp),%edi
  mov    %rbx,%r14
  test   %dil,%dil
  jne    L333
  jmp    L139
  nopl   (%rax)
L265:
  movsbl 0x1(%r14),%edi
  add    $0x1,%r14
  test   %dil,%dil
  je     L139
L333:
  call   <isspace@plt>
  test   %rax,%rax
  jne    L265
  movzbl (%r14),%eax
  test   %al,%al
  je     L139
  mov    %r14,%r15
  jmp    L268
  nopl   (%rax)
L158:
  movzbl 0x1(%r15),%eax
  lea    0x1(%r15),%rdx
  test   %al,%al
  je     L80
  mov    %rdx,%r15
L268:
  cmp    $0x3b,%al
  jne    L158
  movb   $0x0,(%r15)
  sub    $0x1,%r15
L80:
  cmp    %r14,%r15
  ja     L220
  jmp    L139
  cs nopw 0x0(%rax,%rax,1)
L190:
  movb   $0x0,(%r15)
  sub    $0x1,%r15
  cmp    %r14,%r15
  je     L139
L220:
  movsbl (%r15),%edi
  call   <isspace@plt>
  test   %rax,%rax
  jne    L190
  cmp    %r14,%r15
  jbe    L139
  mov    %r14,%rdi
  lea    0x1(%r12),%r15d
  lea    0x0(%r13,%r12,4),%r12
  call   <bm_atoi@plt>
  mov    %eax,(%r12)
  mov    %r15d,%r12d
  cmp    %r12d,0x1c(%rsp)
  jne    L139
  lea    (%r12,%r12,1),%eax
  lea    0x0(,%r12,8),%esi
  mov    %r13,%rdi
  mov    %eax,0x1c(%rsp)
  call   <realloc@plt>
  test   %rax,%rax
  je     L171
  mov    %rax,%r13
  jmp    L139
L341:
  test   %r12d,%r12d
  jne    L200
L171:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r13,%rdi
  call   <free@plt>
L164:
  xor    %r13d,%r13d
L43:
  mov    0x78(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L19
  add    $0x88,%rsp
  mov    %r13,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  cs nopw 0x0(%rax,%rax,1)
L46:
  lea    0x1c(%rsp),%rcx
  lea    0x20(%rsp),%rdx
  mov    %rbp,%rdi
  lea    D26(%rip),%rsi
  call   <fscanf@plt>
  cmp    $0x2,%eax
  je     L167
  mov    %rbp,%rdi
  xor    %r13d,%r13d
  call   <fclose@plt>
  jmp    L43
L167:
  mov    0x1c(%rsp),%edi
  mov    $0x4,%esi
  call   <calloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L109
  mov    0x1c(%rsp),%eax
  test   %eax,%eax
  je     L36
  xor    %ebx,%ebx
  lea    0x2c(%rsp),%r8
  lea    0x28(%rsp),%r15
  lea    0x24(%rsp),%r12
  lea    D7(%rip),%r14
  jmp    L346
  nopl   0x0(%rax,%rax,1)
L160:
  mov    0x24(%rsp),%eax
  mov    0x28(%rsp),%edx
  mov    %ebx,%ecx
  add    $0x1,%ebx
  mov    0x8(%rsp),%r8
  shl    $0x10,%eax
  shl    $0x8,%edx
  or     %edx,%eax
  or     0x2c(%rsp),%eax
  mov    %eax,0x0(%r13,%rcx,4)
  mov    0x1c(%rsp),%eax
  cmp    %ebx,%eax
  jbe    L36
L346:
  xor    %eax,%eax
  mov    %r15,%rcx
  mov    %r12,%rdx
  mov    %r14,%rsi
  mov    %rbp,%rdi
  mov    %r8,0x8(%rsp)
  call   <fscanf@plt>
  cmp    $0x3,%eax
  je     L160
  jmp    L171
L200:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    (%rsp),%rax
  mov    %r12d,(%rax)
  jmp    L43
L109:
  mov    %rbp,%rdi
  call   <fclose@plt>
  jmp    L43
L36:
  mov    (%rsp),%rcx
  mov    %rbp,%rdi
  mov    %eax,(%rcx)
  call   <fclose@plt>
  jmp    L43
L19:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: data_tag: D9
data_type: string
name: retrieve_data
arguments: data_tag: D10
data_type: string
name: retrieve_data
arguments: data_tag: D26
data_type: string
name: retrieve_data
arguments: data_tag: D7
data_type: string

tool: D9: r

tool: D10: JASC-PAL

tool: D26: %d %u

tool: D7: %u %u %u

assistant: ```c
unsigned int *bm_load_palette(const char *filename, unsigned int *npal) {
  unsigned int *pal = NULL, n = 0, an = 8;
  FILE *f = NULL;
  char buf[64];
  if (!filename || !npal)
    return NULL;
  *npal = 0;
  f = fopen(filename, "r");
  if (!f)
    return NULL;
  fgets(buf, sizeof buf, f);
  if (!strncmp(buf, "JASC-PAL", 8)) {
    int version;
    if (fscanf(f, "%d %u", &version, &an) != 2)
      goto error;
    (void)version;
    pal = calloc(an, sizeof *pal);
    if (!pal)
      goto error;
    for (n = 0; n < an; n++) {
      unsigned int r, g, b;
      if (fscanf(f, "%u %u %u", &r, &g, &b) != 3)
        goto error;
      pal[n] = (r << 16) | (g << 8) | b;
    }
    *npal = an;
    fclose(f);
    return pal;
  } else
    rewind(f);
  pal = calloc(an, sizeof *pal);
  if (!pal)
    goto error;
  while (fgets(buf, sizeof buf, f) && n < 256) {
    char *s, *e, *c = buf;
    while (*c && isspace(*c))
      c++;
    s = c;
    if (!*s)
      continue;
    while (*c) {
      if (*c == ';') {
        *c = '\0';
        break;
      }
      c++;
    }
    e = c - 1;
    while (e > s && isspace(*e)) {
      *e = '\0';
      e--;
    }
    if (e <= s)
      continue;
    pal[n++] = bm_atoi(s);
    if (n == an) {
      an <<= 1;
      void *tmp = realloc(pal, an * sizeof *pal);
      if (!tmp)
        goto error;
      pal = tmp;
    }
  }
  if (n == 0)
    goto error;
  fclose(f);
  *npal = n;
  return pal;
error:
  fclose(f);
  if (pal)
    free(pal);
  return NULL;
}
```