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

```asm
<DiscreteGamma>:
  endbr64
  movapd %xmm0,%xmm2
  pxor   %xmm7,%xmm7
  push   %r15
  mov    %rsi,%r15
  divsd  %xmm1,%xmm0
  cvtsi2sd %edx,%xmm7
  push   %r14
  mov    %rdi,%r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %edx,%ebx
  sub    $0x58,%rsp
  movsd  %xmm1,0x30(%rsp)
  movsd  %xmm7,0x28(%rsp)
  mulsd  %xmm7,%xmm0
  movsd  %xmm0,0x18(%rsp)
  test   %ecx,%ecx
  je     L91
  test   %edx,%edx
  jle    L125
  movapd %xmm7,%xmm4
  addsd  %xmm2,%xmm2
  movslq %edx,%r12
  xor    %r13d,%r13d
  addsd  %xmm7,%xmm4
  movsd  0x30(%rsp),%xmm7
  movsd  D5(%rip),%xmm5
  addsd  %xmm7,%xmm7
  movq   %xmm2,%rbp
  movsd  %xmm5,0x8(%rsp)
  movsd  %xmm4,0x20(%rsp)
  movsd  %xmm7,0x10(%rsp)
  nopl   0x0(%rax,%rax,1)
L150:
  pxor   %xmm0,%xmm0
  cvtsi2sd %r13d,%xmm0
  addsd  %xmm0,%xmm0
  addsd  0x8(%rsp),%xmm0
  divsd  0x20(%rsp),%xmm0
  cvttsd2si %xmm0,%edi
  movq   %rbp,%xmm0
  call   <InverseCDFChi2@plt>
  divsd  0x10(%rsp),%xmm0
  movsd  %xmm0,(%r15,%r13,8)
  add    $0x1,%r13
  cmp    %r12,%r13
  jne    L150
  cmp    $0x1,%ebx
  je     L265
  mov    %ebx,%edx
  lea    0x10(%r15),%rcx
  pxor   %xmm0,%xmm0
  mov    %r15,%rax
  shr    %edx
  sub    $0x1,%edx
  shl    $0x4,%rdx
  add    %rcx,%rdx
  xchg   %ax,%ax
L132:
  movsd  (%rax),%xmm1
  add    $0x10,%rax
  addsd  %xmm1,%xmm0
  movsd  -0x8(%rax),%xmm1
  addsd  %xmm1,%xmm0
  cmp    %rdx,%rax
  jne    L132
  mov    %ebx,%eax
  and    $0xfffffffe,%eax
  cmp    %ebx,%eax
  je     L131
L27:
  cltq
  movsd  0x18(%rsp),%xmm1
  addsd  (%r15,%rax,8),%xmm0
  divsd  %xmm0,%xmm1
  cmp    $0x1,%ebx
  je     L96
  lea    0x10(%r15),%rcx
L185:
  mov    %ebx,%edx
  movapd %xmm1,%xmm2
  mov    %r15,%rax
  shr    %edx
  unpcklpd %xmm2,%xmm2
  sub    $0x1,%edx
  shl    $0x4,%rdx
  add    %rcx,%rdx
  nop
L198:
  movupd (%rax),%xmm0
  add    $0x10,%rax
  mulpd  %xmm2,%xmm0
  movups %xmm0,-0x10(%rax)
  cmp    %rdx,%rax
  jne    L198
  mov    %ebx,%eax
  and    $0xfffffffe,%eax
  cmp    %ebx,%eax
  je     L187
L87:
  cltq
  lea    (%r15,%rax,8),%rax
  mulsd  (%rax),%xmm1
  movsd  %xmm1,(%rax)
L133:
  test   %ebx,%ebx
  mov    $0x1,%ecx
  movsd  0x8(%rsp),%xmm0
  divsd  0x28(%rsp),%xmm0
  cmovg  %ebx,%ecx
  cmp    $0x1,%ebx
  jle    L114
L21:
  mov    %ecx,%edx
  movapd %xmm0,%xmm1
  mov    %r14,%rax
  shr    %edx
  unpcklpd %xmm1,%xmm1
  sub    $0x1,%edx
  shl    $0x4,%rdx
  lea    0x10(%r14,%rdx,1),%rdx
  nopw   0x0(%rax,%rax,1)
L229:
  movups %xmm1,(%rax)
  add    $0x10,%rax
  cmp    %rax,%rdx
  jne    L229
  mov    %ecx,%eax
  and    $0xfffffffe,%eax
  and    $0x1,%ecx
  je     L125
L103:
  cltq
  movsd  %xmm0,(%r14,%rax,8)
L125:
  add    $0x58,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L96:
  xor    %eax,%eax
  jmp    L87
  nopw   0x0(%rax,%rax,1)
L91:
  movsd  D5(%rip),%xmm4
  movsd  %xmm2,0x10(%rsp)
  movsd  %xmm4,0x8(%rsp)
  addsd  %xmm2,%xmm4
  movapd %xmm4,%xmm0
  movsd  %xmm4,0x20(%rsp)
  call   <LnGamma@plt>
  lea    -0x1(%rbx),%eax
  mov    %eax,0x4c(%rsp)
  movsd  %xmm0,0x38(%rsp)
  test   %eax,%eax
  jle    L283
  movsd  0x30(%rsp),%xmm5
  movsd  0x10(%rsp),%xmm2
  lea    -0x2(%rbx),%ebp
  xor    %r13d,%r13d
  mov    %rbp,%r12
  movapd %xmm5,%xmm6
  addsd  %xmm2,%xmm2
  addsd  %xmm5,%xmm6
  movsd  %xmm2,0x40(%rsp)
  movsd  %xmm6,0x10(%rsp)
  nopl   0x0(%rax)
L55:
  pxor   %xmm0,%xmm0
  cvtsi2sd %r13d,%xmm0
  addsd  0x8(%rsp),%xmm0
  divsd  0x28(%rsp),%xmm0
  cvttsd2si %xmm0,%edi
  movsd  0x40(%rsp),%xmm0
  call   <InverseCDFChi2@plt>
  mov    %r13,%rdx
  divsd  0x10(%rsp),%xmm0
  movsd  %xmm0,(%r14,%r13,8)
  add    $0x1,%r13
  cmp    %rbp,%rdx
  jne    L55
  mov    %r14,%r13
  lea    0x8(%r14,%rbp,8),%rbp
  nopl   0x0(%rax)
L82:
  movsd  0x30(%rsp),%xmm0
  mulsd  0x0(%r13),%xmm0
  add    $0x8,%r13
  movsd  0x38(%rsp),%xmm2
  movsd  0x20(%rsp),%xmm1
  call   <IncompleteGamma@plt>
  movsd  %xmm0,-0x8(%r13)
  cmp    %rbp,%r13
  jne    L82
  movsd  (%r14),%xmm0
  movsd  0x18(%rsp),%xmm3
  movslq %ebx,%rax
  cmpl   $0x1,0x4c(%rsp)
  mulsd  %xmm3,%xmm0
  movsd  %xmm0,(%r15)
  movsd  0x8(%rsp),%xmm0
  subsd  -0x10(%r14,%rax,8),%xmm0
  mulsd  %xmm3,%xmm0
  movsd  %xmm0,-0x8(%r15,%rax,8)
  jle    L271
  mov    %r15,%rax
  sub    %r14,%rax
  cmp    $0x8,%rax
  jbe    L236
  cmp    $0x3,%ebx
  je     L236
  mov    %r12d,%eax
  movapd %xmm3,%xmm1
  shr    %eax
  unpcklpd %xmm1,%xmm1
  lea    -0x1(%rax),%edx
  mov    $0x8,%eax
  shl    $0x4,%rdx
  add    $0x18,%rdx
  nopl   0x0(%rax)
L179:
  movupd (%r14,%rax,1),%xmm0
  movupd -0x8(%r14,%rax,1),%xmm3
  subpd  %xmm3,%xmm0
  mulpd  %xmm1,%xmm0
  movups %xmm0,(%r15,%rax,1)
  add    $0x10,%rax
  cmp    %rdx,%rax
  jne    L179
  mov    %r12d,%eax
  or     $0x1,%eax
  and    $0x1,%r12d
  je     L271
  cltq
  movsd  (%r14,%rax,8),%xmm0
  subsd  -0x8(%r14,%rax,8),%xmm0
  mulsd  0x18(%rsp),%xmm0
  movsd  %xmm0,(%r15,%rax,8)
L271:
  test   %ebx,%ebx
  jg     L133
  jmp    L125
  nop
L187:
  test   %ebx,%ebx
  mov    $0x1,%ecx
  movsd  0x8(%rsp),%xmm0
  divsd  0x28(%rsp),%xmm0
  cmovg  %ebx,%ecx
  jmp    L21
  nopl   0x0(%rax,%rax,1)
L131:
  movsd  0x18(%rsp),%xmm1
  divsd  %xmm0,%xmm1
  jmp    L185
L114:
  xor    %eax,%eax
  jmp    L103
L265:
  pxor   %xmm0,%xmm0
  xor    %eax,%eax
  jmp    L27
L236:
  lea    -0x3(%rbx),%edx
  mov    $0x1,%eax
  add    $0x2,%rdx
  nopl   (%rax)
L142:
  movsd  (%r14,%rax,8),%xmm0
  subsd  -0x8(%r14,%rax,8),%xmm0
  mulsd  0x18(%rsp),%xmm0
  movsd  %xmm0,(%r15,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rdx
  jne    L142
  jmp    L271
L283:
  movsd  (%r14),%xmm0
  movsd  0x18(%rsp),%xmm3
  movslq %ebx,%rax
  mulsd  %xmm3,%xmm0
  movsd  %xmm0,(%r15)
  movsd  0x8(%rsp),%xmm0
  subsd  -0x10(%r14,%rax,8),%xmm0
  mulsd  %xmm3,%xmm0
  movsd  %xmm0,-0x8(%r15,%rax,8)
  jmp    L271
```

tool_calls: name: retrieve_data
arguments: data_tag: D5
type_infered: f64

tool: D5: 1

assistant: ```c
int DiscreteGamma(double freqK[], double rK[], double alpha, double beta, int K, int dgammamean) {
  int i;
  double t, factor = alpha / beta * K, lnga1;
  if (dgammamean == 0) {
    lnga1 = LnGamma(alpha + 1);
    for (i = 0; i < K - 1; i++)
      freqK[i] = InverseCDFChi2((i + 1.0) / K, 2.0 * (alpha)) / (2.0 * (beta));
    for (i = 0; i < K - 1; i++)
      freqK[i] = IncompleteGamma(freqK[i] * beta, alpha + 1, lnga1);
    rK[0] = freqK[0] * factor;
    rK[K - 1] = (1 - freqK[K - 2]) * factor;
    for (i = 1; i < K - 1; i++)
      rK[i] = (freqK[i] - freqK[i - 1]) * factor;
  } else {
    for (i = 0; i < K; i++)
      rK[i] = InverseCDFChi2((i * 2. + 1) / (2. * K), 2.0 * (alpha)) / (2.0 * (beta));
    for (i = 0, t = 0; i < K; i++)
      t += rK[i];
    for (i = 0; i < K; i++)
      rK[i] *= factor / t;
  }
  for (i = 0; i < K; i++)
    freqK[i] = 1.0 / K;
  return (0);
}
```