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 D55(%rip),%xmm0
  jbe    L67
  addsd  D0(%rip),%xmm0
  pxor   %xmm1,%xmm1
  cvtsd2ss %xmm0,%xmm0
  ucomiss %xmm0,%xmm1
  ja     L8
  sqrtss %xmm0,%xmm0
L75:
  cvtss2sd %xmm0,%xmm0
  movapd %xmm0,%xmm2
  mov    $0x1,%esi
  xor    %eax,%eax
  movsd  D43(%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)
L66:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L33
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L67:
  mov    D29(%rip),%rax
  mov    $0x1,%esi
  mov    $0x1,%edi
  movl   $0x0,0x30(%rsp)
  mov    %rax,0x28(%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     L72
  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 0x28(%rsp,%rax,4),%rax
  lea    0x0(%rbp,%rax,8),%rdx
  movslq 0x28(%rsp,%rax,4),%r12
  mov    %rax,%r14
  mov    %rdx,0x8(%rsp)
  mov    %r12,%r13
  shl    $0x3,%r12
L28:
  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  D0(%rip),%xmm0
  pxor   %xmm1,%xmm1
  cvtsd2ss %xmm0,%xmm0
  ucomiss %xmm0,%xmm1
  ja     L49
  sqrtss %xmm0,%xmm0
L54:
  pxor   %xmm1,%xmm1
  mov    (%rsp),%rax
  mov    %r14d,%esi
  mov    %r13d,%edi
  cvtss2sd %xmm0,%xmm1
  mulsd  D43(%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  D34(%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    L66
  nopl   (%rax)
L72:
  mov    %rbp,0x8(%rsp)
  mov    $0x8,%r12d
  xor    %r14d,%r14d
  mov    $0x1,%r13d
  movq   $0x10,(%rsp)
  mov    $0x2,%r15d
  jmp    L28
L33:
  call   <__stack_chk_fail@plt>
L8:
  call   <sqrtf@plt>
  jmp    L75
L49:
  call   <sqrtf@plt>
  jmp    L54
```

tool_calls: name: unpack_data
arguments: data_label: D55
type: f64[2]
name: unpack_data
arguments: data_label: D0
type: f64
name: unpack_data
arguments: data_label: D43
type: f64
name: unpack_data
arguments: data_label: D29
type: byte[8]
name: unpack_data
arguments: data_label: D34
type: byte[4]

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

tool: D0: 1

tool: D43: 0.5

tool: {"D29": [0x01,0x00,0x00,0x00,0x02,0x00,0x00,0x00]}

tool: {"D34": [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;
  }
}
```