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

```asm
<resample_post_theta>:
  endbr64
  push   %r15
  mov    %edi,%r15d
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %esi,%ebx
  sub    $0x48,%rsp
  mov    0x80(%rsp),%rax
  mov    %edi,0xc(%rsp)
  mov    %rdx,0x20(%rsp)
  mov    0x88(%rsp),%rbp
  mov    %rax,0x38(%rsp)
  lea    0x1(%rsi),%eax
  mov    0x90(%rsp),%r13
  lea    0x0(,%rax,8),%edi
  mov    %rcx,0x10(%rsp)
  movslq %eax,%r14
  mov    %r8,0x28(%rsp)
  mov    %r9,0x30(%rsp)
  call   <malloc@plt>
  mov    %rax,%r12
  test   %r15d,%r15d
  jle    L17
  pxor   %xmm0,%xmm0
  lea    -0x8(%rax,%r14,8),%r15
  lea    -0x1(%rbx),%eax
  mov    $0x1,%r14d
  cvtsi2sd %ebx,%xmm0
  mulsd  D39(%rip),%xmm0
  lea    0x8(,%rax,8),%rax
  mov    %rax,0x18(%rsp)
  mov    %r12,%rax
  mov    %r14,%r12
  mov    %rax,%r14
  movsd  %xmm0,(%rsp)
  movsd  D45(%rip),%xmm0
  nopl   0x0(%rax,%rax,1)
L6:
  test   %ebx,%ebx
  jle    L87
  mov    0x18(%rsp),%rdx
  xor    %esi,%esi
  mov    %r14,%rdi
  call   <memset@plt>
  mov    D45(%rip),%rax
  movq   %rax,%xmm0
L87:
  mov    0x10(%rsp),%rax
  movsd  (%rsp),%xmm2
  movslq -0x4(%rax,%r12,4),%r10
  movsd  %xmm2,(%r15)
  test   %r10d,%r10d
  jle    L58
  mov    0x20(%rsp),%rax
  xor    %edi,%edi
  mov    -0x8(%rax,%r12,8),%r11
  nopl   0x0(%rax)
L52:
  mov    (%r11,%rdi,4),%edx
  test   %edx,%edx
  jle    L32
  mov    -0x8(%r13,%r12,8),%rax
  sub    $0x1,%edx
  mov    (%rax,%rdi,8),%rax
  lea    (%rax,%rdx,4),%rcx
L37:
  movsd  (%r15),%xmm1
  movslq (%rax),%rdx
  addsd  %xmm0,%xmm1
  lea    -0x8(%r14,%rdx,8),%rdx
  movsd  %xmm1,(%r15)
  movsd  (%rdx),%xmm1
  addsd  %xmm0,%xmm1
  movsd  %xmm1,(%rdx)
  mov    %rax,%rdx
  add    $0x4,%rax
  cmp    %rdx,%rcx
  jne    L37
L32:
  add    $0x1,%rdi
  cmp    %rdi,%r10
  jne    L52
L58:
  test   %rbp,%rbp
  je     L53
  movslq -0x4(%rbp,%r12,4),%rax
  cmp    $0xffffffff,%eax
  je     L73
  mov    0x30(%rsp),%rsi
  mov    %ebx,%edx
  mov    (%rsi,%rax,8),%rdi
  mov    %r14,%rsi
  call   <add_dst@plt>
  mov    D45(%rip),%rax
  movq   %rax,%xmm0
L36:
  add    $0x1,%r12
  cmp    %r12d,0xc(%rsp)
  jge    L6
  mov    %r14,%r12
L17:
  add    $0x48,%rsp
  mov    %r12,%rdi
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  jmp    1090 <free@plt>
L73:
  mov    0x28(%rsp),%rax
  mov    %ebx,%edx
  mov    %r14,%rsi
  mov    -0x8(%rax,%r12,8),%rdi
  call   <sample_Delta@plt>
  mov    0x28(%rsp),%rax
  mov    0x38(%rsp),%rsi
  mov    %ebx,%edx
  mov    -0x8(%rax,%r12,8),%rdi
  call   <add_dst@plt>
  mov    D45(%rip),%rax
  movq   %rax,%xmm0
  jmp    L36
L53:
  mov    0x28(%rsp),%rax
  mov    %ebx,%edx
  mov    %r14,%rsi
  mov    -0x8(%rax,%r12,8),%rdi
  call   <sample_Delta@plt>
  mov    D45(%rip),%rax
  movq   %rax,%xmm0
  jmp    L36
```

tool_calls: name: extract_symbolic_data
arguments: data_tag: D39
type_guessed: f64
name: extract_symbolic_data
arguments: data_tag: D45
type_guessed: f64

tool: D39: 0

tool: D45: 1

assistant: ```c
void resample_post_theta(int D, int K, int **M, int *N, double **post_theta, double **post_theta_train, double *global_topic_counts, int *entity_map, int ***z) {
  int d_9;
  double *tmpSP7;
  int n_3;
  int m_75;
  int dvv_loop_var_1;
  int i;
  tmpSP7 = (double *)malloc(sizeof(double) * (1 + ((K) + (1)) - (1)));
  for (d_9 = 1; d_9 <= D; d_9++) {
    for (dvv_loop_var_1 = 1; dvv_loop_var_1 <= K; dvv_loop_var_1++) {
      tmpSP7[dvv_loop_var_1 - 1] = 0.0;
    }
    tmpSP7[(K) + (1) - 1] = (0.0) * (((1) + (K)) - (1));
    for (n_3 = 1; n_3 <= N[d_9 - 1]; n_3++) {
      for (m_75 = 1; m_75 <= M[d_9 - 1][n_3 - 1]; m_75++) {
        tmpSP7[(K) + (1) - 1] += 1.0;
        tmpSP7[z[d_9 - 1][n_3 - 1][m_75 - 1] - 1] += 1.0;
      }
    }
    if (entity_map == NULL) {
      sample_Delta(post_theta[d_9 - 1], tmpSP7, K);
    } else if (entity_map[d_9 - 1] == -1) {
      sample_Delta(post_theta[d_9 - 1], tmpSP7, K);
      add_dst(post_theta[d_9 - 1], global_topic_counts, K);
    } else {
      add_dst(post_theta_train[entity_map[d_9 - 1]], tmpSP7, K);
    }
  }
  free(tmpSP7);
}
```