user: Converte this assembly snippet into its equivalent C code:

```asm
<CalculateTangentSpace>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0xb8,%rsp
  mov    %esi,0x54(%rsp)
  mov    %rdx,%rbp
  mov    %rcx,0x20(%rsp)
  mov    %r8,0x58(%rsp)
  mov    %r9,0x28(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0xa8(%rsp)
  xor    %eax,%eax
  test   %r9,%r9
  setne  %dl
  test   %rcx,%rcx
  setne  %al
  test   %al,%dl
  je     L59
  mov    %edi,%ebx
  mov    %esi,%r15d
  test   %r8,%r8
  je     L59
  mov    %esi,%r12d
  shl    $0x4,%r12d
  mov    %r12d,%edi
  call   <malloc@plt>
  mov    %rax,0x48(%rsp)
  mov    %r12d,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  lea    (%r15,%r15,2),%r12d
  shl    $0x2,%r12d
  mov    %r12d,%edi
  call   <malloc@plt>
  mov    %rax,%r14
  mov    %rax,0x30(%rsp)
  mov    %r12d,%edi
  call   <malloc@plt>
  mov    %rax,%r15
  mov    %rax,0x38(%rsp)
  mov    %r12d,%edx
  mov    $0x0,%esi
  mov    %r14,%rdi
  call   <memset@plt>
  mov    %r12d,%edx
  mov    $0x0,%esi
  mov    %r15,%rdi
  call   <memset@plt>
  test   %ebx,%ebx
  jle    L58
  mov    %rbp,%r15
  lea    -0x1(%rbx),%eax
  lea    (%rax,%rax,2),%rax
  lea    0xc(%rbp,%rax,4),%rax
  mov    %rax,0x40(%rsp)
L50:
  mov    (%r15),%eax
  lea    (%rax,%rax,2),%ebp
  movslq %ebp,%rbp
  shl    $0x2,%rbp
  mov    0x28(%rsp),%rcx
  lea    (%rcx,%rbp,1),%r12
  mov    0x4(%r15),%eax
  lea    (%rax,%rax,2),%ebx
  movslq %ebx,%rbx
  shl    $0x2,%rbx
  lea    (%rcx,%rbx,1),%rax
  mov    %rax,0x8(%rsp)
  mov    0x8(%r15),%eax
  lea    (%rax,%rax,2),%eax
  cltq
  lea    0x0(,%rax,4),%r14
  add    %r14,%rcx
  mov    %rcx,0x10(%rsp)
  mov    0x20(%rsp),%rax
  lea    (%rax,%rbp,1),%r13
  lea    (%rax,%r14,1),%rdx
  mov    %rdx,0x18(%rsp)
  lea    (%rax,%rbx,1),%rsi
  lea    0x6c(%rsp),%rdi
  mov    %r13,%rdx
  call   <sub3d@plt>
  lea    0x78(%rsp),%rdi
  mov    %r13,%rdx
  mov    0x18(%rsp),%rsi
  call   <sub3d@plt>
  lea    0x84(%rsp),%rdi
  mov    %r12,%rdx
  mov    0x8(%rsp),%rsi
  call   <sub3d@plt>
  lea    0x90(%rsp),%rdi
  mov    %r12,%rdx
  mov    0x10(%rsp),%rsi
  call   <sub3d@plt>
  movss  0x94(%rsp),%xmm0
  movss  0x88(%rsp),%xmm1
  movaps %xmm0,%xmm2
  mulss  0x84(%rsp),%xmm2
  movaps %xmm1,%xmm3
  mulss  0x90(%rsp),%xmm3
  subss  %xmm3,%xmm2
  movss  D24(%rip),%xmm3
  divss  %xmm2,%xmm3
  movaps %xmm0,%xmm2
  mulss  0x6c(%rsp),%xmm2
  movaps %xmm1,%xmm4
  mulss  0x78(%rsp),%xmm4
  subss  %xmm4,%xmm2
  mulss  %xmm3,%xmm2
  movss  %xmm2,0x9c(%rsp)
  movaps %xmm0,%xmm2
  mulss  0x70(%rsp),%xmm2
  movaps %xmm1,%xmm4
  mulss  0x7c(%rsp),%xmm4
  subss  %xmm4,%xmm2
  mulss  %xmm3,%xmm2
  movss  %xmm2,0xa0(%rsp)
  mulss  0x74(%rsp),%xmm0
  mulss  0x80(%rsp),%xmm1
  subss  %xmm1,%xmm0
  mulss  %xmm3,%xmm0
  movss  %xmm0,0xa4(%rsp)
  mov    0x30(%rsp),%r13
  lea    0x0(%r13,%rbp,1),%rdi
  lea    0x9c(%rsp),%r12
  mov    %r12,%rdx
  mov    %rdi,%rsi
  call   <add3d@plt>
  lea    0x0(%r13,%rbx,1),%rdi
  mov    %r12,%rdx
  mov    %rdi,%rsi
  call   <add3d@plt>
  lea    0x0(%r13,%r14,1),%rdi
  mov    %r12,%rdx
  mov    %rdi,%rsi
  call   <add3d@plt>
  mov    0x38(%rsp),%r13
  lea    0x0(%r13,%rbp,1),%rdi
  mov    %r12,%rdx
  mov    %rdi,%rsi
  call   <add3d@plt>
  lea    0x0(%r13,%rbx,1),%rdi
  mov    %r12,%rdx
  mov    %rdi,%rsi
  call   <add3d@plt>
  lea    0x0(%r13,%r14,1),%rdi
  mov    %r12,%rdx
  mov    %rdi,%rsi
  call   <add3d@plt>
  add    $0xc,%r15
  cmp    0x40(%rsp),%r15
  jne    L50
L58:
  mov    0x54(%rsp),%eax
  test   %eax,%eax
  jle    L76
  mov    0x58(%rsp),%r12
  mov    0x30(%rsp),%rbx
  mov    0x48(%rsp),%rdx
  mov    %rdx,%r13
  mov    0x38(%rsp),%rbp
  mov    %eax,%eax
  shl    $0x4,%rax
  add    %rdx,%rax
  mov    %rax,0x10(%rsp)
  lea    0x9c(%rsp),%r15
L12:
  mov    %rbx,%rsi
  mov    %r12,%rdi
  call   <dot3d@plt>
  mov    %r12,%rsi
  mov    %r15,%rdi
  call   <scale3d@plt>
  lea    0x90(%rsp),%r14
  mov    %r15,%rdx
  mov    %rbx,%rsi
  mov    %r14,%rdi
  call   <sub3d@plt>
  mov    %r13,0x8(%rsp)
  mov    %r14,%rsi
  mov    %r13,%rdi
  call   <normalize3d@plt>
  mov    %rbx,%rdx
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   <cross3d@plt>
  mov    %rbp,%rsi
  mov    %r14,%rdi
  call   <dot3d@plt>
  pxor   %xmm5,%xmm5
  cmpltss %xmm5,%xmm0
  movss  D0(%rip),%xmm1
  andps  %xmm0,%xmm1
  movss  D24(%rip),%xmm7
  andnps %xmm7,%xmm0
  orps   %xmm0,%xmm1
  mov    0x8(%rsp),%rax
  movss  %xmm1,0xc(%rax)
  add    $0xc,%r12
  add    $0xc,%rbx
  add    $0x10,%r13
  add    $0xc,%rbp
  cmp    0x10(%rsp),%r13
  jne    L12
  jmp    L76
L59:
  movq   $0x0,0x48(%rsp)
L76:
  mov    0xa8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L19
  mov    0x48(%rsp),%rax
  add    $0xb8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L19:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: parse_data
arguments: tag: D24
type_guessed: f32
name: parse_data
arguments: tag: D0
type_guessed: byte[4]

tool: D24: 1

tool: {"D0": [0x00,0x00,0x80,0xbf]}

assistant: ```c
float *CalculateTangentSpace(int Triangles, int VertexCount, int *Indices, float *verts, float *normals, float *texs) {
  int i;
  float *tans = 0;
  if (normals && texs && verts) {
    tans = malloc(VertexCount * sizeof(float) * 4);
    memset(tans, 0, VertexCount * sizeof(float) * 4);
    float *tan1 = malloc(VertexCount * sizeof(float) * 3);
    float *tan2 = malloc(VertexCount * sizeof(float) * 3);
    memset(tan1, 0, VertexCount * sizeof(float) * 3);
    memset(tan2, 0, VertexCount * sizeof(float) * 3);
    for (i = 0; i < Triangles; i++) {
      int v1 = Indices[i * 3 + 0];
      int v2 = Indices[i * 3 + 1];
      int v3 = Indices[i * 3 + 2];
      float *t1 = &texs[v1 * 3];
      float *t2 = &texs[v2 * 3];
      float *t3 = &texs[v3 * 3];
      float *p1 = &verts[v1 * 3];
      float *p2 = &verts[v2 * 3];
      float *p3 = &verts[v3 * 3];
      float vec1[3];
      float vec2[3];
      float tex1[3];
      float tex2[3];
      sub3d(vec1, p2, p1);
      sub3d(vec2, p3, p1);
      sub3d(tex1, t2, t1);
      sub3d(tex2, t3, t1);
      float r = 1.0f / (tex1[0] * tex2[1] - tex2[0] * tex1[1]);
      float sdir[3] = {(tex2[1] * vec1[0] - tex1[1] * vec2[0]) * r, (tex2[1] * vec1[1] - tex1[1] * vec2[1]) * r, (tex2[1] * vec1[2] - tex1[1] * vec2[2]) * r};
      float tdir[3] = {(tex1[0] * vec2[0] - tex2[0] * vec1[0]) * r, (tex1[0] * vec2[1] - tex2[0] * vec1[1]) * r, (tex1[0] * vec2[2] - tex2[0] * vec1[2]) * r};
      add3d(&tan1[v1 * 3], &tan1[v1 * 3], sdir);
      add3d(&tan1[v2 * 3], &tan1[v2 * 3], sdir);
      add3d(&tan1[v3 * 3], &tan1[v3 * 3], sdir);
      add3d(&tan2[v1 * 3], &tan2[v1 * 3], sdir);
      add3d(&tan2[v2 * 3], &tan2[v2 * 3], sdir);
      add3d(&tan2[v3 * 3], &tan2[v3 * 3], sdir);
    }
    for (i = 0; i < VertexCount; i++) {
      const float *n = &normals[i * 3];
      const float *t = &tan1[i * 3];
      float tmp[3];
      float tdn[3];
      float thisdot = dot3d(n, t);
      scale3d(tdn, n, thisdot);
      sub3d(tmp, t, tdn);
      normalize3d(&tans[i * 4], tmp);
      cross3d(tmp, n, t);
      tans[i * 4 + 3] = (dot3d(tmp, &tan2[i * 3]) < 0) ? -1 : 1;
    }
  }
  return tans;
}
```