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

```asm
<DiscreteGamma>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,%rbp
  mov    %rsi,%rbx
  movsd  %xmm0,0x28(%rsp)
  movsd  %xmm1,(%rsp)
  mov    %edx,%r12d
  pxor   %xmm2,%xmm2
  cvtsi2sd %edx,%xmm2
  movsd  %xmm2,0x18(%rsp)
  divsd  %xmm1,%xmm0
  mulsd  %xmm2,%xmm0
  movsd  %xmm0,0x20(%rsp)
  test   %ecx,%ecx
  je     L119
  test   %edx,%edx
  jle    L75
  movsd  0x28(%rsp),%xmm6
  addsd  %xmm6,%xmm6
  movsd  %xmm6,0x8(%rsp)
  movsd  0x18(%rsp),%xmm2
  movapd %xmm2,%xmm7
  addsd  %xmm2,%xmm7
  movsd  %xmm7,0x10(%rsp)
  lea    -0x1(%rdx),%r15d
  mov    %edx,%r14d
  mov    $0x0,%r13d
L86:
  pxor   %xmm0,%xmm0
  cvtsi2sd %r13d,%xmm0
  addsd  %xmm0,%xmm0
  addsd  D1(%rip),%xmm0
  divsd  0x10(%rsp),%xmm0
  cvttsd2si %xmm0,%edi
  movsd  0x8(%rsp),%xmm0
  call   <InverseCDFChi2@plt>
  movsd  (%rsp),%xmm3
  movapd %xmm3,%xmm1
  addsd  %xmm3,%xmm1
  divsd  %xmm1,%xmm0
  movsd  %xmm0,(%rbx,%r13,8)
  add    $0x1,%r13
  cmp    %r14,%r13
  jne    L86
  mov    %rbx,%rax
  lea    0x8(%rbx,%r15,8),%rdx
  pxor   %xmm0,%xmm0
L128:
  addsd  (%rbx),%xmm0
  add    $0x8,%rbx
  cmp    %rdx,%rbx
  jne    L128
  movsd  0x20(%rsp),%xmm1
  divsd  %xmm0,%xmm1
L92:
  movapd %xmm1,%xmm0
  mulsd  (%rax),%xmm0
  movsd  %xmm0,(%rax)
  add    $0x8,%rax
  cmp    %rdx,%rax
  jne    L92
L56:
  movsd  D1(%rip),%xmm0
  divsd  0x18(%rsp),%xmm0
  mov    $0x0,%eax
L97:
  movsd  %xmm0,0x0(%rbp,%rax,8)
  add    $0x1,%rax
  cmp    %eax,%r12d
  jg     L97
L75:
  mov    $0x0,%eax
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L119:
  movsd  0x28(%rsp),%xmm6
  addsd  D1(%rip),%xmm6
  movapd %xmm6,%xmm0
  movsd  %xmm6,0x8(%rsp)
  call   <LnGamma@plt>
  movsd  %xmm0,0x10(%rsp)
  lea    -0x1(%r12),%r15d
  test   %r15d,%r15d
  jle    L70
  movsd  0x28(%rsp),%xmm7
  addsd  %xmm7,%xmm7
  movsd  %xmm7,0x28(%rsp)
  lea    -0x2(%r12),%r14d
  mov    $0x0,%r13d
L24:
  pxor   %xmm0,%xmm0
  cvtsi2sd %r13d,%xmm0
  addsd  D1(%rip),%xmm0
  divsd  0x18(%rsp),%xmm0
  cvttsd2si %xmm0,%edi
  movsd  0x28(%rsp),%xmm0
  call   <InverseCDFChi2@plt>
  movsd  (%rsp),%xmm5
  movapd %xmm5,%xmm1
  addsd  %xmm5,%xmm1
  divsd  %xmm1,%xmm0
  movsd  %xmm0,0x0(%rbp,%r13,8)
  mov    %r13,%rax
  add    $0x1,%r13
  cmp    %rax,%r14
  jne    L24
  mov    %rbp,%r13
  lea    0x8(%rbp,%r14,8),%r14
L22:
  movsd  (%rsp),%xmm0
  mulsd  0x0(%r13),%xmm0
  movsd  0x10(%rsp),%xmm2
  movsd  0x8(%rsp),%xmm1
  call   <IncompleteGamma@plt>
  movsd  %xmm0,0x0(%r13)
  add    $0x8,%r13
  cmp    %r14,%r13
  jne    L22
L70:
  movsd  0x20(%rsp),%xmm4
  movapd %xmm4,%xmm0
  mulsd  0x0(%rbp),%xmm0
  movsd  %xmm0,(%rbx)
  movslq %r12d,%rax
  movsd  D1(%rip),%xmm0
  subsd  -0x10(%rbp,%rax,8),%xmm0
  mulsd  %xmm4,%xmm0
  movsd  %xmm0,-0x8(%rbx,%rax,8)
  cmp    $0x1,%r15d
  jle    L12
  lea    -0x3(%r12),%edx
  add    $0x2,%rdx
  mov    $0x1,%eax
L42:
  movsd  0x0(%rbp,%rax,8),%xmm0
  subsd  -0x8(%rbp,%rax,8),%xmm0
  mulsd  0x20(%rsp),%xmm0
  movsd  %xmm0,(%rbx,%rax,8)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L42
L12:
  test   %r12d,%r12d
  jg     L56
  jmp    L75
```

tool_calls: name: unpack_data
arguments: data_tag: D1
type_guessed: f64

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