user: Please show me the C implementation that matches the assembly code listed below:

```asm
<qfits_card_build>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x398,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x388(%rsp)
  xor    %eax,%eax
  test   %rdi,%rdi
  je     L49
  mov    %rdi,%rbx
  mov    %rsi,%rbp
  mov    %rdx,%r13
  mov    %rcx,%r12
  test   %rsi,%rsi
  je     L49
  mov    $0x50,%edx
  mov    $0x20,%esi
  call   <memset@plt>
  lea    D58(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  je     L32
  lea    D9(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  je     L199
  lea    D74(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcmp@plt>
  test   %eax,%eax
  jne    L161
L199:
  mov    %rbp,%rdx
  lea    D52(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  test   %r13,%r13
  je     L49
  mov    %r13,%rdi
  call   <strlen@plt>
  mov    $0x48,%edx
  cmp    %edx,%eax
  cmovle %eax,%edx
  lea    0x8(%rbx),%rdi
  mov    %r13,%rsi
  call   <strncpy@plt>
L49:
  mov    0x388(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L149
  add    $0x398,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L32:
  movl   $0x444e45,(%rbx)
  jmp    L49
L161:
  mov    $0x8,%edx
  lea    D97(%rip),%rsi
  mov    %rbp,%rdi
  call   <strncmp@plt>
  test   %eax,%eax
  je     L199
  test   %r13,%r13
  je     L289
  mov    %r13,%rdi
  call   <strlen@plt>
  test   %eax,%eax
  jg     L131
  movb   $0x0,(%rsp)
  jmp    L276
L289:
  movb   $0x0,(%rsp)
L276:
  test   %r12,%r12
  je     L183
  lea    0x120(%rsp),%rdi
  mov    %r12,%rsi
  call   <strcpy@plt>
L249:
  mov    $0x8,%edx
  lea    D111(%rip),%rsi
  mov    %rbp,%rdi
  call   <strncmp@plt>
  mov    %eax,%r12d
  mov    %rsp,%rdi
  call   <qfits_is_int@plt>
  test   %rax,%rax
  je     L311
L137:
  test   %r12d,%r12d
  jne    L53
  mov    %rsp,%rcx
  lea    0x180(%rsp),%rdi
  lea    0x120(%rsp),%r8
  mov    %rbp,%rdx
  lea    D106(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
L328:
  lea    0x180(%rsp),%rsi
  mov    $0x50,%edx
  mov    %rbx,%rdi
  call   <strncpy@plt>
  movb   $0x0,0x50(%rbx)
  jmp    L49
L131:
  mov    %rsp,%rdi
  mov    %r13,%rsi
  call   <strcpy@plt>
  jmp    L276
L183:
  lea    0x120(%rsp),%rdi
  lea    D88(%rip),%rsi
  call   <strcpy@plt>
  jmp    L249
L311:
  mov    %rsp,%rdi
  call   <qfits_is_float@plt>
  test   %rax,%rax
  jne    L137
  mov    %rsp,%rdi
  call   <qfits_is_boolean@plt>
  test   %rax,%rax
  jne    L137
  mov    %rsp,%rdi
  call   <qfits_is_complex@plt>
  test   %rax,%rax
  jne    L137
  cmpb   $0x0,(%rsp)
  jne    L9
  test   %r12d,%r12d
  jne    L60
  lea    0x120(%rsp),%rcx
  lea    0x180(%rsp),%rdi
  mov    %rbp,%rdx
  lea    D13(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
L232:
  lea    0x180(%rsp),%rsi
  mov    $0x50,%edx
  mov    %rbx,%rdi
  call   <strncpy@plt>
  movb   $0x0,0x50(%rbx)
  jmp    L49
L53:
  mov    %rsp,%rcx
  lea    0x180(%rsp),%rdi
  lea    0x120(%rsp),%r8
  mov    %rbp,%rdx
  lea    D123(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
  jmp    L328
L60:
  lea    0x120(%rsp),%rcx
  lea    0x180(%rsp),%rdi
  mov    %rbp,%rdx
  lea    D86(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
  jmp    L232
L9:
  lea    0xc0(%rsp),%rdi
  mov    $0x51,%edx
  mov    $0x0,%esi
  call   <memset@plt>
  mov    %rsp,%rdi
  call   <qfits_pretty_string@plt>
  mov    %rax,%rsi
  lea    0x60(%rsp),%rdi
  call   <strcpy@plt>
  movzbl 0x60(%rsp),%edx
  test   %dl,%dl
  je     L283
  lea    0x61(%rsp),%rcx
  mov    $0x0,%eax
  jmp    L236
L46:
  movslq %eax,%rdx
  movb   $0x27,0xc0(%rsp,%rdx,1)
  add    $0x1,%eax
  movslq %eax,%rdx
  movb   $0x27,0xc0(%rsp,%rdx,1)
L45:
  add    $0x1,%eax
  add    $0x1,%rcx
  movzbl -0x1(%rcx),%edx
  test   %dl,%dl
  je     L283
L236:
  cmp    $0x27,%dl
  je     L46
  movslq %eax,%rsi
  mov    %dl,0xc0(%rsp,%rsi,1)
  jmp    L45
L283:
  test   %r12d,%r12d
  jne    L261
  lea    0xc0(%rsp),%r12
  lea    0x180(%rsp),%rdi
  lea    0x120(%rsp),%r8
  mov    %r12,%rcx
  mov    %rbp,%rdx
  lea    D72(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %eax,%ebp
  mov    %r12,%rdi
  call   <strlen@plt>
  add    %eax,%ebp
  cmp    $0x4c,%ebp
  jle    L302
  movb   $0x27,0x1cf(%rsp)
  jmp    L302
L261:
  lea    0xc0(%rsp),%rcx
  lea    0x180(%rsp),%rdi
  lea    0x120(%rsp),%r8
  mov    %rbp,%rdx
  lea    D22(%rip),%rsi
  mov    $0x0,%eax
  call   <sprintf@plt>
L302:
  lea    0x180(%rsp),%rsi
  mov    $0x50,%edx
  mov    %rbx,%rdi
  call   <strncpy@plt>
  movb   $0x0,0x50(%rbx)
  jmp    L49
L149:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: data_tag: D58
type_infered: string
name: parse_data
arguments: data_tag: D9
type_infered: string
name: parse_data
arguments: data_tag: D74
type_infered: string
name: parse_data
arguments: data_tag: D52
type_infered: string
name: parse_data
arguments: data_tag: D97
type_infered: string
name: parse_data
arguments: data_tag: D111
type_infered: string
name: parse_data
arguments: data_tag: D106
type_infered: string
name: parse_data
arguments: data_tag: D88
type_infered: string
name: parse_data
arguments: data_tag: D13
type_infered: string
name: parse_data
arguments: data_tag: D123
type_infered: string
name: parse_data
arguments: data_tag: D86
type_infered: string
name: parse_data
arguments: data_tag: D72
type_infered: string
name: parse_data
arguments: data_tag: D22
type_infered: string

tool: D58: END

tool: D9: HISTORY

tool: D74: COMMENT

tool: D52: %s 

tool: D97:         

tool: D111: HIERARCH

tool: D106: %-29s= %s / %s

tool: D88: no comment

tool: D13: %-29s=                    / %s

tool: D123: %-8.8s= %20s / %-48s

tool: D86: %-8.8s=                      / %-48s

tool: D72: %-29s= '%s' / %s

tool: D22: %-8.8s= '%-8s' / %s

assistant: ```c
void qfits_card_build(char *line, const char *key, const char *val, const char *com) {
  int len;
  int hierarch = 0;
  char cval[81];
  char cval2[81];
  char cval_q[81];
  char ccom[81];
  char safe_line[512];
  int i, j;
  if (line == NULL || key == NULL)
    return;
  memset(line, ' ', 80);
  if (key == NULL)
    return;
  if (!strcmp(key, "END")) {
    sprintf(line, "END");
    return;
  }
  if (!strcmp(key, "HISTORY") || !strcmp(key, "COMMENT") || !strncmp(key, "        ", 8)) {
    sprintf(line, "%s ", key);
    if (val == NULL)
      return;
    len = strlen(val);
    if (len > 72)
      len = 72;
    strncpy(line + 8, val, len);
    return;
  }
  if (val == NULL)
    cval[0] = (char)0;
  else if (strlen(val) < 1)
    cval[0] = (char)0;
  else
    strcpy(cval, val);
  if (com == NULL)
    strcpy(ccom, "no comment");
  else
    strcpy(ccom, com);
  if (!strncmp(key, "HIERARCH", 8))
    hierarch++;
  if (qfits_is_int(cval) || qfits_is_float(cval) || qfits_is_boolean(cval) || qfits_is_complex(cval)) {
    if (hierarch)
      sprintf(safe_line, "%-29s= %s / %s", key, cval, ccom);
    else
      sprintf(safe_line, "%-8.8s= %20s / %-48s", key, cval, ccom);
    strncpy(line, safe_line, 80);
    line[80] = (char)0;
    return;
  }
  if (cval[0] == 0) {
    if (hierarch) {
      sprintf(safe_line, "%-29s=                    / %s", key, ccom);
    } else {
      sprintf(safe_line, "%-8.8s=                      / %-48s", key, ccom);
    }
    strncpy(line, safe_line, 80);
    line[80] = (char)0;
    return;
  }
  memset(cval_q, 0, 81);
  strcpy(cval2, qfits_pretty_string(cval));
  j = 0;
  i = 0;
  while (cval2[i] != (char)0) {
    if (cval2[i] == '\'') {
      cval_q[j] = '\'';
      j++;
      cval_q[j] = '\'';
    } else {
      cval_q[j] = cval2[i];
    }
    i++;
    j++;
  }
  if (hierarch) {
    sprintf(safe_line, "%-29s= '%s' / %s", key, cval_q, ccom);
    if (strlen(key) + strlen(cval_q) + 3 >= 80)
      safe_line[79] = '\'';
  } else {
    sprintf(safe_line, "%-8.8s= '%-8s' / %s", key, cval_q, ccom);
  }
  strncpy(line, safe_line, 80);
  line[80] = (char)0;
  return;
}
```