user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<quatd_from_mat3d>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x48,%rsp
  movsd  (%rsi),%xmm0
  addsd  0x20(%rsi),%xmm0
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  addsd  0x40(%rsi),%xmm0
  comisd D46(%rip),%xmm0
  jbe    L60
  addsd  D21(%rip),%xmm0
  pxor   %xmm1,%xmm1
  cvtsd2ss %xmm0,%xmm0
  ucomiss %xmm0,%xmm1
  ja     L34
  sqrtss %xmm0,%xmm0
L71:
  cvtss2sd %xmm0,%xmm0
  movapd %xmm0,%xmm2
  mov    $0x1,%esi
  xor    %eax,%eax
  movsd  D51(%rip),%xmm1
  mov    $0x2,%edi
  mulsd  %xmm1,%xmm2
  divsd  %xmm0,%xmm1
  movsd  %xmm2,0x18(%rbp)
  movsd  %xmm1,(%rsp)
  call   <mat3_getIndex@plt>
  mov    $0x2,%esi
  mov    $0x1,%edi
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  xor    %eax,%eax
  movsd  %xmm0,0x8(%rsp)
  call   <mat3_getIndex@plt>
  movsd  0x8(%rsp),%xmm0
  mov    $0x2,%esi
  xor    %edi,%edi
  cltq
  subsd  (%rbx,%rax,8),%xmm0
  mulsd  (%rsp),%xmm0
  xor    %eax,%eax
  movsd  %xmm0,0x0(%rbp)
  call   <mat3_getIndex@plt>
  xor    %esi,%esi
  mov    $0x2,%edi
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  xor    %eax,%eax
  movsd  %xmm0,0x8(%rsp)
  call   <mat3_getIndex@plt>
  movsd  0x8(%rsp),%xmm0
  mov    $0x2,%esi
  mov    $0x1,%edi
  cltq
  subsd  (%rbx,%rax,8),%xmm0
  mulsd  (%rsp),%xmm0
  xor    %eax,%eax
  movsd  %xmm0,0x8(%rbp)
  call   <mat3_getIndex@plt>
  mov    $0x1,%esi
  xor    %edi,%edi
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  xor    %eax,%eax
  movsd  %xmm0,0x8(%rsp)
  call   <mat3_getIndex@plt>
  movsd  0x8(%rsp),%xmm0
  cltq
  subsd  (%rbx,%rax,8),%xmm0
  mulsd  (%rsp),%xmm0
  movsd  %xmm0,0x10(%rbp)
L17:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L88
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L60:
  movabs $0x200000001,%rax
  mov    $0x1,%esi
  mov    $0x1,%edi
  movl   $0x0,0x34(%rsp)
  mov    %rax,0x2c(%rsp)
  xor    %eax,%eax
  call   <mat3_getIndex@plt>
  xor    %esi,%esi
  xor    %edi,%edi
  cltq
  mov    (%rbx,%rax,8),%r12
  xor    %eax,%eax
  call   <mat3_getIndex@plt>
  mov    $0x2,%esi
  mov    $0x2,%edi
  cltq
  movq   %r12,%xmm4
  movsd  (%rbx,%rax,8),%xmm0
  comisd %xmm0,%xmm4
  movsd  %xmm0,(%rsp)
  seta   %r15b
  xor    %eax,%eax
  call   <mat3_getIndex@plt>
  movzbl %r15b,%r15d
  cltq
  mov    %r15d,%esi
  mov    %r15d,%edi
  mov    (%rbx,%rax,8),%r13
  xor    %eax,%eax
  call   <mat3_getIndex@plt>
  cltq
  movq   %r13,%xmm5
  comisd (%rbx,%rax,8),%xmm5
  ja     L4
  movsd  (%rsp),%xmm0
  movq   %r12,%xmm6
  xor    %r13d,%r13d
  comisd %xmm0,%xmm6
  seta   %r13b
  lea    0x0(,%r13,8),%rax
  mov    %rax,(%rsp)
  movslq %r15d,%rax
  movslq 0x2c(%rsp,%rax,4),%rax
  lea    0x0(%rbp,%rax,8),%rdx
  movslq 0x2c(%rsp,%rax,4),%r12
  mov    %rax,%r14
  mov    %rdx,0x8(%rsp)
  mov    %r12,%r13
  shl    $0x3,%r12
L64:
  mov    %r15d,%esi
  mov    %r15d,%edi
  xor    %eax,%eax
  call   <mat3_getIndex@plt>
  mov    %r14d,%esi
  mov    %r14d,%edi
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  xor    %eax,%eax
  movsd  %xmm0,0x18(%rsp)
  call   <mat3_getIndex@plt>
  mov    %r13d,%esi
  mov    %r13d,%edi
  cltq
  movsd  (%rbx,%rax,8),%xmm1
  xor    %eax,%eax
  movsd  %xmm1,0x10(%rsp)
  call   <mat3_getIndex@plt>
  movsd  0x10(%rsp),%xmm1
  movsd  0x18(%rsp),%xmm0
  cltq
  addsd  (%rbx,%rax,8),%xmm1
  subsd  %xmm1,%xmm0
  addsd  D21(%rip),%xmm0
  pxor   %xmm1,%xmm1
  cvtsd2ss %xmm0,%xmm0
  ucomiss %xmm0,%xmm1
  ja     L85
  sqrtss %xmm0,%xmm0
L5:
  pxor   %xmm1,%xmm1
  mov    (%rsp),%rax
  mov    %r14d,%esi
  mov    %r13d,%edi
  cvtss2sd %xmm0,%xmm1
  mulsd  D51(%rip),%xmm1
  movss  %xmm0,0x10(%rsp)
  movsd  %xmm1,0x0(%rbp,%rax,1)
  xor    %eax,%eax
  call   <mat3_getIndex@plt>
  mov    %r13d,%esi
  mov    %r14d,%edi
  cltq
  movsd  (%rbx,%rax,8),%xmm2
  xor    %eax,%eax
  movsd  %xmm2,(%rsp)
  call   <mat3_getIndex@plt>
  movsd  (%rsp),%xmm2
  mov    %r15d,%esi
  mov    %r14d,%edi
  movss  0x10(%rsp),%xmm0
  movss  D54(%rip),%xmm1
  cltq
  pxor   %xmm3,%xmm3
  subsd  (%rbx,%rax,8),%xmm2
  xor    %eax,%eax
  divss  %xmm0,%xmm1
  movapd %xmm2,%xmm0
  cvtss2sd %xmm1,%xmm3
  mulsd  %xmm3,%xmm0
  movsd  %xmm3,(%rsp)
  movsd  %xmm0,0x18(%rbp)
  call   <mat3_getIndex@plt>
  mov    %r14d,%esi
  mov    %r15d,%edi
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  xor    %eax,%eax
  movsd  %xmm0,0x10(%rsp)
  call   <mat3_getIndex@plt>
  movsd  0x10(%rsp),%xmm0
  mov    %r15d,%esi
  mov    %r13d,%edi
  cltq
  addsd  (%rbx,%rax,8),%xmm0
  mulsd  (%rsp),%xmm0
  mov    0x8(%rsp),%rax
  movsd  %xmm0,(%rax)
  xor    %eax,%eax
  call   <mat3_getIndex@plt>
  mov    %r13d,%esi
  mov    %r15d,%edi
  cltq
  movsd  (%rbx,%rax,8),%xmm0
  xor    %eax,%eax
  movsd  %xmm0,0x8(%rsp)
  call   <mat3_getIndex@plt>
  movsd  0x8(%rsp),%xmm0
  cltq
  addsd  (%rbx,%rax,8),%xmm0
  mulsd  (%rsp),%xmm0
  movsd  %xmm0,0x0(%rbp,%r12,1)
  jmp    L17
  nopl   0x0(%rax,%rax,1)
L4:
  mov    %rbp,0x8(%rsp)
  mov    $0x8,%r12d
  xor    %r14d,%r14d
  mov    $0x1,%r13d
  movq   $0x10,(%rsp)
  mov    $0x2,%r15d
  jmp    L64
L88:
  call   <__stack_chk_fail@plt>
L34:
  call   <sqrtf@plt>
  jmp    L71
L85:
  call   <sqrtf@plt>
  jmp    L5
```

tool_calls: name: unpack_data
arguments: data_tag: D46
data_type: f64[2]
name: unpack_data
arguments: data_tag: D21
data_type: f64
name: unpack_data
arguments: data_tag: D51
data_type: f64
name: unpack_data
arguments: data_tag: D54
data_type: byte[4]

tool: {"D46": [0.0,1.0]}

tool: D21: 1

tool: D51: 0.5

tool: {"D54": [0x00,0x00,0x00,0x3f]}

assistant: ```c
void quatd_from_mat3d(double quat[4], const double matrix[9]) {
  int X = 0, Y = 1, Z = 2, W = 3;
  double trace = matrix[0] + matrix[4] + matrix[8];
  if (trace > 0.0) {
    double s = sqrtf(trace + 1.0);
    quat[W] = s * 0.5;
    s = 0.5 / s;
    quat[X] = (matrix[mat3_getIndex(Z, Y)] - matrix[mat3_getIndex(Y, Z)]) * s;
    quat[Y] = (matrix[mat3_getIndex(X, Z)] - matrix[mat3_getIndex(Z, X)]) * s;
    quat[Z] = (matrix[mat3_getIndex(Y, Z)] - matrix[mat3_getIndex(X, Y)]) * s;
  } else {
    int next[3] = {Y, Z, X};
    int i = X;
    if (matrix[mat3_getIndex(Y, Y)] > matrix[mat3_getIndex(X, X)])
      i = Y;
    if (matrix[mat3_getIndex(Z, Z)] > matrix[mat3_getIndex(i, i)])
      i = Z;
    int j = next[i];
    int k = next[j];
    float s = sqrtf((matrix[mat3_getIndex(i, i)] - (matrix[mat3_getIndex(j, j)] + matrix[mat3_getIndex(k, k)])) + 1.0);
    quat[i] = s * 0.5;
    s = 0.5 / s;
    quat[W] = (matrix[mat3_getIndex(k, j)] - matrix[mat3_getIndex(j, k)]) * s;
    quat[j] = (matrix[mat3_getIndex(j, i)] + matrix[mat3_getIndex(i, j)]) * s;
    quat[k] = (matrix[mat3_getIndex(k, i)] + matrix[mat3_getIndex(i, k)]) * s;
  }
}
```