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     L230
  test   %rsi,%rsi
  je     L230
  mov    (%rsp),%rax
  lea    D13(%rip),%rsi
  movl   $0x0,(%rax)
  call   <fopen@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L230
  lea    0x30(%rsp),%rbx
  mov    %rax,%rdx
  mov    $0x40,%esi
  mov    %rbx,%rdi
  call   <fgets@plt>
  mov    $0x8,%edx
  lea    D0(%rip),%rsi
  mov    %rbx,%rdi
  call   <strncmp@plt>
  test   %eax,%eax
  je     L265
  mov    %rbp,%rdi
  call   <rewind@plt>
  mov    0x1c(%rsp),%edi
  mov    $0x4,%esi
  call   <calloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L87
  xor    %r12d,%r12d
  nopl   0x0(%rax,%rax,1)
L45:
  mov    %rbp,%rdx
  mov    $0x40,%esi
  mov    %rbx,%rdi
  call   <fgets@plt>
  test   %rax,%rax
  je     L180
  cmp    $0x100,%r12d
  je     L181
  movsbl 0x30(%rsp),%edi
  mov    %rbx,%r14
  test   %dil,%dil
  jne    L90
  jmp    L45
  nopl   (%rax)
L255:
  movsbl 0x1(%r14),%edi
  add    $0x1,%r14
  test   %dil,%dil
  je     L45
L90:
  call   <isspace@plt>
  test   %rax,%rax
  jne    L255
  movzbl (%r14),%eax
  test   %al,%al
  je     L45
  mov    %r14,%r15
  jmp    L275
  nopl   (%rax)
L114:
  movzbl 0x1(%r15),%eax
  lea    0x1(%r15),%rdx
  test   %al,%al
  je     L143
  mov    %rdx,%r15
L275:
  cmp    $0x3b,%al
  jne    L114
  movb   $0x0,(%r15)
  sub    $0x1,%r15
L143:
  cmp    %r14,%r15
  ja     L204
  jmp    L45
  cs nopw 0x0(%rax,%rax,1)
L288:
  movb   $0x0,(%r15)
  sub    $0x1,%r15
  cmp    %r14,%r15
  je     L45
L204:
  movsbl (%r15),%edi
  call   <isspace@plt>
  test   %rax,%rax
  jne    L288
  cmp    %r14,%r15
  jbe    L45
  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    L45
  lea    (%r12,%r12,1),%eax
  lea    0x0(,%r12,8),%esi
  mov    %r13,%rdi
  mov    %eax,0x1c(%rsp)
  call   <realloc@plt>
  test   %rax,%rax
  je     L270
  mov    %rax,%r13
  jmp    L45
L180:
  test   %r12d,%r12d
  jne    L181
L270:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    %r13,%rdi
  call   <free@plt>
L230:
  xor    %r13d,%r13d
L85:
  mov    0x78(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L220
  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)
L265:
  lea    0x1c(%rsp),%rcx
  lea    0x20(%rsp),%rdx
  mov    %rbp,%rdi
  lea    D30(%rip),%rsi
  call   <fscanf@plt>
  cmp    $0x2,%eax
  je     L116
  mov    %rbp,%rdi
  xor    %r13d,%r13d
  call   <fclose@plt>
  jmp    L85
L116:
  mov    0x1c(%rsp),%edi
  mov    $0x4,%esi
  call   <calloc@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L87
  mov    0x1c(%rsp),%eax
  test   %eax,%eax
  je     L179
  xor    %ebx,%ebx
  lea    0x2c(%rsp),%r8
  lea    0x28(%rsp),%r15
  lea    0x24(%rsp),%r12
  lea    D27(%rip),%r14
  jmp    L245
  nopl   0x0(%rax,%rax,1)
L95:
  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    L179
L245:
  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     L95
  jmp    L270
L181:
  mov    %rbp,%rdi
  call   <fclose@plt>
  mov    (%rsp),%rax
  mov    %r12d,(%rax)
  jmp    L85
L87:
  mov    %rbp,%rdi
  call   <fclose@plt>
  jmp    L85
L179:
  mov    (%rsp),%rcx
  mov    %rbp,%rdi
  mov    %eax,(%rcx)
  call   <fclose@plt>
  jmp    L85
L220:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: label: D13
type: string
name: unpack_data
arguments: label: D0
type: string
name: unpack_data
arguments: label: D30
type: string
name: unpack_data
arguments: label: D27
type: string

tool: D13: r

tool: D0: JASC-PAL

tool: D30: %d %u

tool: D27: %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;
}
```