user: Translate the below assembly code into C programming language:

```asm
<write_as_matrix>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rsi,0x20(%rsp)
  mov    %r8,0x28(%rsp)
  mov    %r9,%rbp
  mov    0x88(%rsp),%r15
  mov    (%rdx),%edx
  mov    %edx,0x4(%rsp)
  mov    (%rcx),%r14d
  mov    0x78(%rsp),%rdx
  cmpl   $0x0,(%rdx)
  je     L70
  lea    D1(%rip),%rsi
  mov    (%rdi),%rdi
  call   <fopen@plt>
  mov    %rax,%r12
L230:
  test   %r12,%r12
  je     L202
  mov    0xa8(%rsp),%rax
  cmpl   $0x0,(%rax)
  je     L119
  test   %r14d,%r14d
  jle    L236
  mov    %r14d,%r13d
  mov    $0x1,%ebx
  mov    %r14d,0x8(%rsp)
  mov    0x80(%rsp),%r14
  jmp    L217
L70:
  lea    D19(%rip),%rsi
  mov    (%rdi),%rdi
  call   <fopen@plt>
  mov    %rax,%r12
  jmp    L230
L220:
  add    $0x1,%rbx
L217:
  mov    -0x8(%rbp,%rbx,8),%rsi
  mov    (%r14),%edx
  mov    %r12,%rdi
  call   <put_name@plt>
  cmp    %r13,%rbx
  je     L69
  test   %ebx,%ebx
  je     L220
  mov    %r12,%rsi
  mov    (%r15),%rdi
  call   <fputs@plt>
  jmp    L220
L69:
  mov    0x8(%rsp),%r14d
L236:
  mov    %r12,%rsi
  mov    0x90(%rsp),%rax
  mov    (%rax),%rdi
  call   <fputs@plt>
L119:
  mov    0x4(%rsp),%eax
  test   %eax,%eax
  jle    L64
  mov    %eax,%ecx
  mov    %rcx,0x18(%rsp)
  movq   $0x0,0x10(%rsp)
  cltq
  mov    %rax,0x8(%rsp)
  mov    %r14d,0x4(%rsp)
  mov    0x70(%rsp),%r14
  jmp    L123
L205:
  mov    0x28(%rsp),%rax
  mov    0x10(%rsp),%rdx
  mov    (%rax,%rdx,8),%rsi
  mov    0x80(%rsp),%rax
  mov    (%rax),%edx
  mov    %r12,%rdi
  call   <put_name@plt>
  mov    %r12,%rsi
  mov    (%r15),%rdi
  call   <fputs@plt>
  jmp    L75
L151:
  mov    %r12,%rsi
  mov    0x98(%rsp),%rax
  mov    (%rax),%rdi
  call   <fputs@plt>
  mov    %r12,%rsi
  mov    (%r15),%rdi
  call   <fputs@plt>
  mov    %r12,%rsi
  mov    0x98(%rsp),%rax
  mov    (%rax),%rdi
  call   <fputs@plt>
  jmp    L83
L235:
  test   %r13d,%r13d
  jne    L154
  mov    %r12,%rsi
  mov    0x98(%rsp),%rax
  mov    (%rax),%rdi
  call   <fputs@plt>
  jmp    L83
L154:
  add    $0x2f,%edi
  movsbl %dil,%edi
  mov    %r12,%rsi
  call   <fputc@plt>
  jmp    L83
L139:
  mov    %r12,%rsi
  mov    0x90(%rsp),%rax
  mov    (%rax),%rdi
  call   <fputs@plt>
  addq   $0x1,0x10(%rsp)
  mov    0x10(%rsp),%rax
  cmp    %rax,0x18(%rsp)
  je     L64
L123:
  mov    0xa0(%rsp),%rax
  cmpl   $0x0,(%rax)
  jne    L205
L75:
  cmpl   $0x0,0x4(%rsp)
  jle    L139
  mov    0x20(%rsp),%rbp
  add    0x10(%rsp),%rbp
  mov    $0x0,%ebx
  jmp    L175
L64:
  mov    %r12,%rdi
  call   <fclose@plt>
  mov    $0x0,%edx
L114:
  mov    0xb0(%rsp),%rax
  mov    %edx,(%rax)
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L202:
  mov    $0x1,%edx
  jmp    L114
L108:
  mov    %r12,%rsi
  mov    $0x32,%edi
  call   <fputc@plt>
  mov    %r12,%rsi
  mov    (%r15),%rdi
  call   <fputs@plt>
  mov    $0x32,%edi
L135:
  mov    %r12,%rsi
  call   <fputc@plt>
L83:
  add    $0x1,%ebx
  cmp    %ebx,0x4(%rsp)
  je     L139
  test   %ebx,%ebx
  je     L47
  mov    %r12,%rsi
  mov    (%r15),%rdi
  call   <fputs@plt>
L47:
  add    0x8(%rsp),%rbp
L175:
  movzbl 0x0(%rbp),%edi
  movsbl %dil,%r13d
  cmpl   $0x0,(%r14)
  je     L235
  test   %r13d,%r13d
  je     L151
  cmp    $0x2,%r13d
  jg     L108
  mov    %r12,%rsi
  mov    $0x31,%edi
  call   <fputc@plt>
  mov    %r12,%rsi
  mov    (%r15),%rdi
  call   <fputs@plt>
  cmp    $0x1,%r13d
  setg   %dil
  movzbl %dil,%edi
  add    $0x31,%edi
  jmp    L135
```

tool_calls: name: unpack_data
arguments: label: D1
datatype: string
name: unpack_data
arguments: label: D19
datatype: string

tool: D1: a

tool: D19: w

assistant: ```c
void write_as_matrix(char **file, char *x, int *N, int *M, char **rnames, char **cnames, int *asalleles, int *append, int *quote, char **sep, char **eol, char **na, int *row_names, int *col_names, int *iferror) {
  int zerom = (int)'0' - 1;
  int nrow = *N;
  int ncol = *M;
  FILE *outfile;
  int i = 0, j = 0, ij = 0;
  if (*append)
    outfile = fopen(*file, "a");
  else
    outfile = fopen(*file, "w");
  if (!outfile) {
    *iferror = 1;
    return;
  }
  if (*col_names) {
    for (i = 0; i < ncol; i++) {
      if (i)
        fputs(*sep, outfile);
      put_name(outfile, cnames[i], *quote);
    }
    fputs(*eol, outfile);
  }
  for (i = 0; i < nrow; i++) {
    if (*row_names) {
      put_name(outfile, rnames[i], *quote);
      fputs(*sep, outfile);
    }
    for (j = 0, ij = i; j < ncol; j++, ij += nrow) {
      if (j)
        fputs(*sep, outfile);
      int g = (int)x[ij];
      if (*asalleles) {
        if (!g) {
          fputs(*na, outfile);
          fputs(*sep, outfile);
          fputs(*na, outfile);
        } else {
          fputc(g < 3 ? '1' : '2', outfile);
          fputs(*sep, outfile);
          fputc(g < 2 ? '1' : '2', outfile);
        }
      } else {
        if (!g)
          fputs(*na, outfile);
        else {
          g += zerom;
          fputc((char)g, outfile);
        }
      }
    }
    fputs(*eol, outfile);
  }
  fclose(outfile);
  *iferror = 0;
  return;
}
```