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

```asm
<DiscreteGamma>:
  endbr64
  movapd %xmm0,%xmm2
  pxor   %xmm6,%xmm6
  push   %r15
  divsd  %xmm1,%xmm0
  cvtsi2sd %edx,%xmm6
  push   %r14
  push   %r13
  push   %r12
  mov    %edx,%r12d
  push   %rbp
  mov    %rdi,%rbp
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x48,%rsp
  movsd  %xmm1,0x30(%rsp)
  movsd  %xmm6,0x20(%rsp)
  mulsd  %xmm6,%xmm0
  movsd  %xmm0,0x28(%rsp)
  test   %ecx,%ecx
  je     L66
  test   %edx,%edx
  jle    L60
  addsd  %xmm2,%xmm2
  movsd  0x20(%rsp),%xmm7
  mov    %edx,%r14d
  xor    %r13d,%r13d
  movsd  D8(%rip),%xmm5
  lea    -0x1(%rdx),%r15d
  movsd  %xmm2,0x10(%rsp)
  movapd %xmm7,%xmm2
  addsd  %xmm7,%xmm2
  movsd  %xmm5,(%rsp)
  movsd  %xmm2,0x18(%rsp)
  movsd  0x30(%rsp),%xmm2
  addsd  %xmm2,%xmm2
  movsd  %xmm2,0x8(%rsp)
  cs nopw 0x0(%rax,%rax,1)
L123:
  pxor   %xmm0,%xmm0
  cvtsi2sd %r13d,%xmm0
  addsd  %xmm0,%xmm0
  addsd  (%rsp),%xmm0
  divsd  0x18(%rsp),%xmm0
  cvttsd2si %xmm0,%edi
  movsd  0x10(%rsp),%xmm0
  call   <InverseCDFChi2@plt>
  divsd  0x8(%rsp),%xmm0
  movsd  %xmm0,(%rbx,%r13,8)
  add    $0x1,%r13
  cmp    %r14,%r13
  jne    L123
  lea    0x8(%rbx,%r15,8),%rdx
  mov    %rbx,%rax
  pxor   %xmm0,%xmm0
  nopl   0x0(%rax,%rax,1)
L33:
  addsd  (%rax),%xmm0
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L33
  movsd  0x28(%rsp),%xmm1
  divsd  %xmm0,%xmm1
  nopw   0x0(%rax,%rax,1)
L11:
  movsd  (%rbx),%xmm0
  add    $0x8,%rbx
  mulsd  %xmm1,%xmm0
  movsd  %xmm0,-0x8(%rbx)
  cmp    %rdx,%rbx
  jne    L11
L127:
  xor    %eax,%eax
  movsd  (%rsp),%xmm0
  divsd  0x20(%rsp),%xmm0
  nopl   0x0(%rax,%rax,1)
L89:
  movsd  %xmm0,0x0(%rbp,%rax,8)
  add    $0x1,%rax
  cmp    %eax,%r12d
  jg     L89
L60:
  add    $0x48,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L66:
  movsd  D8(%rip),%xmm4
  movsd  %xmm2,0x8(%rsp)
  lea    -0x1(%r12),%r14d
  movsd  %xmm4,(%rsp)
  addsd  %xmm2,%xmm4
  movapd %xmm4,%xmm0
  movsd  %xmm4,0x10(%rsp)
  call   <LnGamma@plt>
  movsd  %xmm0,0x18(%rsp)
  test   %r14d,%r14d
  jle    L121
  movsd  0x30(%rsp),%xmm3
  movsd  0x8(%rsp),%xmm2
  lea    -0x2(%r12),%r13d
  xor    %r15d,%r15d
  movapd %xmm3,%xmm5
  addsd  %xmm2,%xmm2
  addsd  %xmm3,%xmm5
  movsd  %xmm2,0x38(%rsp)
  movsd  %xmm5,0x8(%rsp)
  cs nopw 0x0(%rax,%rax,1)
L58:
  pxor   %xmm0,%xmm0
  cvtsi2sd %r15d,%xmm0
  addsd  (%rsp),%xmm0
  divsd  0x20(%rsp),%xmm0
  cvttsd2si %xmm0,%edi
  movsd  0x38(%rsp),%xmm0
  call   <InverseCDFChi2@plt>
  mov    %r15,%rax
  divsd  0x8(%rsp),%xmm0
  movsd  %xmm0,0x0(%rbp,%r15,8)
  add    $0x1,%r15
  cmp    %rax,%r13
  jne    L58
  mov    %rbp,%r15
  lea    0x8(%rbp,%r13,8),%r13
  nopl   0x0(%rax)
L132:
  movsd  0x30(%rsp),%xmm0
  mulsd  (%r15),%xmm0
  add    $0x8,%r15
  movsd  0x18(%rsp),%xmm2
  movsd  0x10(%rsp),%xmm1
  call   <IncompleteGamma@plt>
  movsd  %xmm0,-0x8(%r15)
  cmp    %r15,%r13
  jne    L132
  movsd  0x0(%rbp),%xmm0
  movsd  0x28(%rsp),%xmm5
  movslq %r12d,%rax
  mulsd  %xmm5,%xmm0
  movsd  %xmm0,(%rbx)
  movsd  (%rsp),%xmm0
  subsd  -0x10(%rbp,%rax,8),%xmm0
  mulsd  %xmm5,%xmm0
  movsd  %xmm0,-0x8(%rbx,%rax,8)
  cmp    $0x1,%r14d
  jle    L100
  lea    -0x3(%r12),%edx
  mov    $0x1,%eax
  add    $0x2,%rdx
  nopw   0x0(%rax,%rax,1)
L38:
  movsd  0x0(%rbp,%rax,8),%xmm0
  subsd  -0x8(%rbp,%rax,8),%xmm0
  mulsd  0x28(%rsp),%xmm0
  movsd  %xmm0,(%rbx,%rax,8)
  add    $0x1,%rax
  cmp    %rax,%rdx
  jne    L38
L100:
  test   %r12d,%r12d
  jg     L127
  jmp    L60
L121:
  movsd  0x0(%rbp),%xmm0
  movsd  0x28(%rsp),%xmm7
  movslq %r12d,%rax
  mulsd  %xmm7,%xmm0
  movsd  %xmm0,(%rbx)
  movsd  (%rsp),%xmm0
  subsd  -0x10(%rbp,%rax,8),%xmm0
  mulsd  %xmm7,%xmm0
  movsd  %xmm0,-0x8(%rbx,%rax,8)
  jmp    L100
```

tool_calls: name: read_data
arguments: tag: D8
data_type: f64

tool: D8: 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);
}
```