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

```asm
<write_mesh_gmv_qual_mba>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  mov    %esi,%r12d
  lea    D69(%rip),%rsi
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x38,%rsp
  mov    %ecx,0x4(%rsp)
  mov    %r8,0x18(%rsp)
  mov    %r9,0x8(%rsp)
  call   <fopen@plt>
  mov    %r12d,%edx
  lea    D27(%rip),%rsi
  mov    %rax,%rbp
  mov    %rax,%rdi
  xor    %eax,%eax
  call   <fprintf@plt>
  test   %r12d,%r12d
  jle    L59
  lea    -0x1(%r12),%eax
  mov    %rbx,%r14
  lea    D148(%rip),%r12
  lea    (%rax,%rax,2),%rax
  lea    0x18(%rbx,%rax,8),%r13
  cs nopw 0x0(%rax,%rax,1)
L78:
  movsd  0x10(%r14),%xmm2
  mov    %r12,%rsi
  mov    %rbp,%rdi
  add    $0x18,%r14
  movsd  -0x10(%r14),%xmm1
  movsd  -0x18(%r14),%xmm0
  mov    $0x3,%eax
  call   <fprintf@plt>
  cmp    %r13,%r14
  jne    L78
L59:
  mov    0x70(%rsp),%edx
  lea    D182(%rip),%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fprintf@plt>
  mov    0x70(%rsp),%r10d
  test   %r10d,%r10d
  jle    L13
  mov    0x70(%rsp),%eax
  mov    0x78(%rsp),%r13
  mov    %rbx,0x20(%rsp)
  xor    %r12d,%r12d
  mov    0x80(%rsp),%r15
  lea    D51(%rip),%r14
  sub    $0x1,%eax
  shl    $0x4,%rax
  mov    %r15,%rbx
  lea    0x10(%r13,%rax,1),%rax
  mov    %rax,0x10(%rsp)
  xor    %eax,%eax
  mov    %eax,%r15d
  nopw   0x0(%rax,%rax,1)
L137:
  mov    0x4(%r13),%ecx
  mov    0xc(%r13),%r9d
  xor    %eax,%eax
  mov    %r14,%rsi
  mov    0x8(%r13),%r8d
  mov    0x0(%r13),%edx
  mov    %rbp,%rdi
  call   <fprintf@plt>
  mov    (%rbx),%eax
  cmp    %eax,%r12d
  cmovl  %eax,%r12d
  test   %eax,%eax
  mov    $0x1,%eax
  cmove  %eax,%r15d
  add    $0x10,%r13
  add    $0x4,%rbx
  cmp    0x10(%rsp),%r13
  jne    L137
  mov    0x4(%rsp),%eax
  mov    0x20(%rsp),%rbx
  mov    %r15d,0x10(%rsp)
  test   %eax,%eax
  jle    L211
L225:
  mov    0x4(%rsp),%edi
  mov    0x8(%rsp),%rcx
  lea    -0x1(%rdi),%edx
  mov    0x10(%rsp),%edi
  mov    %rcx,%rax
  lea    0x4(%rcx,%rdx,4),%rsi
  mov    $0x1,%ecx
  nopl   0x0(%rax,%rax,1)
L62:
  mov    (%rax),%edx
  cmp    %edx,%r12d
  cmovl  %edx,%r12d
  test   %edx,%edx
  cmove  %ecx,%edi
  add    $0x4,%rax
  cmp    %rax,%rsi
  jne    L62
  mov    0x70(%rsp),%edx
  mov    %edi,0x10(%rsp)
  test   %edx,%edx
  jne    L211
  mov    %rbp,%rcx
  mov    $0xb,%edx
  mov    $0x1,%esi
  lea    D142(%rip),%rdi
  call   <fwrite@plt>
L174:
  add    0x10(%rsp),%r12d
  xor    %r14d,%r14d
  mov    0x18(%rsp),%r15
  lea    D173(%rip),%r13
  mov    %r12d,%eax
  mov    %rbx,%r12
  mov    %r14,%rbx
  mov    %eax,%r14d
  nopl   0x0(%rax,%rax,1)
L216:
  mov    0x8(%rsp),%rax
  lea    D89(%rip),%rsi
  mov    %rbp,%rdi
  mov    (%rax,%rbx,4),%edx
  test   %edx,%edx
  cmove  %r14d,%edx
  xor    %eax,%eax
  add    $0x1,%rbx
  add    $0xc,%r15
  call   <fprintf@plt>
  mov    -0x4(%r15),%eax
  mov    -0xc(%r15),%esi
  mov    %rbp,%rdi
  lea    (%rax,%rax,2),%edx
  mov    -0x8(%r15),%eax
  lea    (%rsi,%rsi,2),%esi
  movslq %edx,%rdx
  movslq %esi,%rsi
  lea    (%rax,%rax,2),%eax
  movsd  -0x18(%r12,%rsi,8),%xmm0
  movsd  -0x18(%r12,%rdx,8),%xmm2
  lea    D217(%rip),%rsi
  cltq
  movsd  -0x18(%r12,%rax,8),%xmm1
  mov    $0x3,%eax
  call   <fprintf@plt>
  mov    -0x4(%r15),%eax
  mov    -0xc(%r15),%esi
  mov    %rbp,%rdi
  lea    0x1(%rax,%rax,2),%edx
  mov    -0x8(%r15),%eax
  lea    0x1(%rsi,%rsi,2),%esi
  movslq %edx,%rdx
  movslq %esi,%rsi
  lea    0x1(%rax,%rax,2),%eax
  movsd  -0x18(%r12,%rsi,8),%xmm0
  movsd  -0x18(%r12,%rdx,8),%xmm2
  mov    %r13,%rsi
  cltq
  movsd  -0x18(%r12,%rax,8),%xmm1
  mov    $0x3,%eax
  call   <fprintf@plt>
  mov    -0x4(%r15),%eax
  mov    -0xc(%r15),%esi
  mov    %rbp,%rdi
  lea    0x2(%rax,%rax,2),%edx
  mov    -0x8(%r15),%eax
  lea    0x2(%rsi,%rsi,2),%esi
  movslq %edx,%rdx
  movslq %esi,%rsi
  lea    0x2(%rax,%rax,2),%eax
  movsd  -0x18(%r12,%rsi,8),%xmm0
  movsd  -0x18(%r12,%rdx,8),%xmm2
  mov    %r13,%rsi
  cltq
  movsd  -0x18(%r12,%rax,8),%xmm1
  mov    $0x3,%eax
  call   <fprintf@plt>
  cmp    %ebx,0x4(%rsp)
  jg     L216
L121:
  mov    %rbp,%rcx
  mov    $0x8,%edx
  mov    $0x1,%esi
  lea    D193(%rip),%rdi
  call   <fwrite@plt>
  mov    %rbp,%rcx
  mov    $0x7,%edx
  mov    $0x1,%esi
  lea    D212(%rip),%rdi
  call   <fwrite@plt>
  mov    %rbp,%rdi
  call   <fclose@plt>
  add    $0x38,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L211:
  mov    0x10(%rsp),%eax
  lea    D115(%rip),%rsi
  mov    %rbp,%rdi
  lea    (%r12,%rax,1),%r15d
  xor    %eax,%eax
  mov    %r15d,%edx
  call   <fprintf@plt>
  test   %r12d,%r12d
  je     L220
  xor    %r14d,%r14d
  lea    D6(%rip),%r13
  nopl   0x0(%rax,%rax,1)
L138:
  add    $0x1,%r14d
  xor    %eax,%eax
  mov    %r13,%rsi
  mov    %rbp,%rdi
  mov    %r14d,%edx
  call   <fprintf@plt>
  cmp    %r12d,%r14d
  jne    L138
L220:
  mov    0x10(%rsp),%r8d
  test   %r8d,%r8d
  jne    L21
L186:
  mov    0x70(%rsp),%edi
  test   %edi,%edi
  jle    L52
  mov    0x70(%rsp),%eax
  mov    0x80(%rsp),%r14
  mov    %rbx,0x28(%rsp)
  lea    D42(%rip),%r13
  sub    $0x1,%eax
  mov    %r14,%rbx
  mov    %rax,0x20(%rsp)
  lea    0x4(%r14,%rax,4),%rax
  mov    %rax,%r14
  xchg   %ax,%ax
L125:
  mov    (%rbx),%edx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  test   %edx,%edx
  cmove  %r15d,%edx
  xor    %eax,%eax
  add    $0x4,%rbx
  call   <fprintf@plt>
  cmp    %rbx,%r14
  jne    L125
  mov    %rbp,%rcx
  mov    $0x12,%edx
  mov    $0x1,%esi
  mov    0x28(%rsp),%rbx
  lea    D44(%rip),%rdi
  lea    D68(%rip),%r13
  call   <fwrite@plt>
  mov    0x20(%rsp),%rax
  mov    0x78(%rsp),%r15
  shl    $0x4,%rax
  lea    0x10(%r15,%rax,1),%r14
  cs nopw 0x0(%rax,%rax,1)
L102:
  mov    0x4(%r15),%edi
  mov    0xc(%r15),%eax
  add    $0x10,%r15
  mov    -0x8(%r15),%ecx
  lea    -0x1(%rdi),%edx
  mov    -0x10(%r15),%edi
  lea    -0x1(%rax),%r8d
  sub    $0x1,%ecx
  lea    -0x1(%rdi),%esi
  mov    %rbx,%rdi
  call   <aft_tetra_qual_mba@plt>
  mov    %r13,%rsi
  mov    %rbp,%rdi
  mov    %eax,%edx
  xor    %eax,%eax
  call   <fprintf@plt>
  cmp    %r15,%r14
  jne    L102
L171:
  mov    %rbp,%rcx
  mov    $0x9,%edx
  mov    $0x1,%esi
  lea    D32(%rip),%rdi
  call   <fwrite@plt>
  mov    $0x1,%esi
  mov    %rbp,%rcx
  mov    $0xb,%edx
  lea    D142(%rip),%rdi
  call   <fwrite@plt>
  mov    0x4(%rsp),%esi
  test   %esi,%esi
  jg     L174
  jmp    L121
L13:
  mov    0x4(%rsp),%r9d
  test   %r9d,%r9d
  jg     L33
  mov    0x70(%rsp),%ecx
  test   %ecx,%ecx
  jne    L208
  mov    %rbp,%rcx
  mov    $0xb,%edx
  mov    $0x1,%esi
  lea    D142(%rip),%rdi
  call   <fwrite@plt>
  jmp    L121
L21:
  mov    %rbp,%rcx
  mov    $0x8,%edx
  mov    $0x1,%esi
  lea    D80(%rip),%rdi
  call   <fwrite@plt>
  jmp    L186
L33:
  movl   $0x0,0x10(%rsp)
  xor    %r12d,%r12d
  jmp    L225
L52:
  mov    %rbp,%rcx
  mov    $0x12,%edx
  mov    $0x1,%esi
  lea    D44(%rip),%rdi
  call   <fwrite@plt>
  jmp    L171
L208:
  xor    %edx,%edx
  lea    D115(%rip),%rsi
  mov    %rbp,%rdi
  xor    %eax,%eax
  call   <fprintf@plt>
  xor    %r12d,%r12d
  xor    %r15d,%r15d
  movl   $0x0,0x10(%rsp)
  jmp    L186
```

tool_calls: name: disassemble_data
arguments: data_tag: D69
type_infered: string
name: disassemble_data
arguments: data_tag: D27
type_infered: string
name: disassemble_data
arguments: data_tag: D148
type_infered: string
name: disassemble_data
arguments: data_tag: D182
type_infered: string
name: disassemble_data
arguments: data_tag: D51
type_infered: string
name: disassemble_data
arguments: data_tag: D142
type_infered: string
name: disassemble_data
arguments: data_tag: D173
type_infered: string
name: disassemble_data
arguments: data_tag: D89
type_infered: string
name: disassemble_data
arguments: data_tag: D217
type_infered: string
name: disassemble_data
arguments: data_tag: D193
type_infered: string
name: disassemble_data
arguments: data_tag: D212
type_infered: string
name: disassemble_data
arguments: data_tag: D115
type_infered: string
name: disassemble_data
arguments: data_tag: D6
type_infered: string
name: disassemble_data
arguments: data_tag: D42
type_infered: string
name: disassemble_data
arguments: data_tag: D44
type_infered: string
name: disassemble_data
arguments: data_tag: D68
type_infered: string
name: disassemble_data
arguments: data_tag: D32
type_infered: string
name: disassemble_data
arguments: data_tag: D80
type_infered: string

tool: D69: w

tool: D27: gmvinput ascii

nodev %5d


tool: D148:   %20.15lf %20.15lf %20.15lf


tool: D182: 
cells %5d


tool: D51:  tet 4
  %4d %4d %4d %4d


tool: D142: 

polygons


tool: D173:       %20.15lf %20.15lf %20.15lf


tool: D89: %3d 3

tool: D217:  %20.15lf %20.15lf %20.15lf


tool: D193: endpoly


tool: D212: 
endgmv

tool: D115: 
material %d 0


tool: D6: mat%d


tool: D42:  %2d

tool: D44: 

variable
qual 0


tool: D68:  %20.15lf

tool: D32: 
endvars


tool: D80: unknown


assistant: ```c
int write_mesh_gmv_qual_mba(char *fn, int nV, double *vertex, int nF, int *face, int *facematerial, int nT, int *tetra, int *tetramaterial) {
  int i, mmax = 0, unkmat = 0;
  FILE *f;
  f = fopen(fn, "w");
  fprintf(f, "gmvinput ascii\n\nnodev %5d\n", nV);
  for (i = 0; i < nV; i++) {
    fprintf(f, "  %20.15lf %20.15lf %20.15lf\n", vertex[3 * i + 0], vertex[3 * i + 1], vertex[3 * i + 2]);
  }
  fprintf(f, "\ncells %5d\n", nT);
  for (i = 0; i < nT; i++) {
    fprintf(f, " tet 4\n  %4d %4d %4d %4d\n", tetra[4 * i + 0], tetra[4 * i + 1], tetra[4 * i + 2], tetra[4 * i + 3]);
    if (mmax < tetramaterial[i])
      mmax = tetramaterial[i];
    if (tetramaterial[i] == 0)
      unkmat = 1;
  }
  for (i = 0; i < nF; i++) {
    if (mmax < facematerial[i])
      mmax = facematerial[i];
    if (facematerial[i] == 0)
      unkmat = 1;
  }
  if (nT) {
    fprintf(f, "\nmaterial %d 0\n", mmax + unkmat);
    for (i = 0; i < mmax; i++)
      fprintf(f, "mat%d\n", i + 1);
    if (unkmat)
      fprintf(f, "unknown\n");
    for (i = 0; i < nT; i++) {
      fprintf(f, " %2d", (tetramaterial[i]) ? tetramaterial[i] : mmax + unkmat);
    }
    fprintf(f, "\n\nvariable\nqual 0\n");
    for (i = 0; i < nT; i++) {
      fprintf(f, " %20.15lf", aft_tetra_qual_mba(vertex, tetra[4 * i + 0] - 1, tetra[4 * i + 1] - 1, tetra[4 * i + 2] - 1, tetra[4 * i + 3] - 1));
    }
    fprintf(f, "\nendvars\n");
  }
  fprintf(f, "\n\npolygons\n");
  for (i = 0; i < nF; i++) {
    fprintf(f, "%3d 3", (facematerial[i]) ? facematerial[i] : mmax + unkmat);
    fprintf(f, " %20.15lf %20.15lf %20.15lf\n", vertex[3 * face[3 * i + 0] + 0 - 3], vertex[3 * face[3 * i + 1] + 0 - 3], vertex[3 * face[3 * i + 2] + 0 - 3]);
    fprintf(f, "      %20.15lf %20.15lf %20.15lf\n", vertex[3 * face[3 * i + 0] + 1 - 3], vertex[3 * face[3 * i + 1] + 1 - 3], vertex[3 * face[3 * i + 2] + 1 - 3]);
    fprintf(f, "      %20.15lf %20.15lf %20.15lf\n", vertex[3 * face[3 * i + 0] + 2 - 3], vertex[3 * face[3 * i + 1] + 2 - 3], vertex[3 * face[3 * i + 2] + 2 - 3]);
  }
  fprintf(f, "endpoly\n");
  fprintf(f, "\nendgmv");
  fclose(f);
  return 0;
}
```