user: 请从给定的汇编指令推导出C源代码:

```asm
<rdiscrete>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %edi,-0x44(%rbp)
  mov    %rsi,-0x50(%rbp)
  pxor   %xmm0,%xmm0
  movsd  %xmm0,-0x20(%rbp)
  mov    -0x44(%rbp),%eax
  cltq
  shl    $0x3,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x18(%rbp)
  movl   $0x0,-0x30(%rbp)
  jmp    L107
L28:
  mov    -0x30(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  movsd  -0x20(%rbp),%xmm1
  addsd  %xmm1,%xmm0
  movsd  %xmm0,-0x20(%rbp)
  addl   $0x1,-0x30(%rbp)
L107:
  mov    -0x30(%rbp),%eax
  cmp    -0x44(%rbp),%eax
  jl     L28
  movl   $0x0,-0x2c(%rbp)
  jmp    L100
L30:
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x2c(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  divsd  -0x20(%rbp),%xmm0
  movsd  %xmm0,(%rax)
  addl   $0x1,-0x2c(%rbp)
L100:
  mov    -0x2c(%rbp),%eax
  cmp    -0x44(%rbp),%eax
  jl     L30
  mov    -0x44(%rbp),%eax
  add    $0x1,%eax
  cltq
  shl    $0x3,%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x10(%rbp)
  mov    -0x10(%rbp),%rax
  pxor   %xmm0,%xmm0
  movsd  %xmm0,(%rax)
  movl   $0x1,-0x28(%rbp)
  jmp    L105
L36:
  mov    -0x28(%rbp),%eax
  cltq
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  mov    -0x28(%rbp),%eax
  cltq
  shl    $0x3,%rax
  lea    -0x8(%rax),%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  mov    -0x28(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  addsd  %xmm1,%xmm0
  movsd  %xmm0,(%rax)
  addl   $0x1,-0x28(%rbp)
L105:
  mov    -0x28(%rbp),%eax
  cmp    -0x44(%rbp),%eax
  jl     L36
  mov    -0x44(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movsd  D3(%rip),%xmm0
  movsd  %xmm0,(%rax)
  mov    $0x0,%eax
  call   <runif@plt>
  movq   %xmm0,%rax
  mov    %rax,-0x8(%rbp)
  movl   $0x0,-0x24(%rbp)
  jmp    L21
L17:
  mov    -0x24(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm1
  movsd  -0x8(%rbp),%xmm0
  comisd %xmm1,%xmm0
  jb     L90
  mov    -0x24(%rbp),%eax
  cltq
  add    $0x1,%rax
  lea    0x0(,%rax,8),%rdx
  mov    -0x10(%rbp),%rax
  add    %rdx,%rax
  movsd  (%rax),%xmm0
  comisd -0x8(%rbp),%xmm0
  jb     L90
  mov    -0x24(%rbp),%eax
  mov    %eax,-0x34(%rbp)
  jmp    L37
L90:
  addl   $0x1,-0x24(%rbp)
L21:
  mov    -0x24(%rbp),%eax
  cmp    -0x44(%rbp),%eax
  jl     L17
L37:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x10(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x34(%rbp),%eax
  leave
  ret
```

tool_calls: name: parse_data
arguments: tag: D3
type_infered: f32[2]

tool: {"D3": [0.0,1.875]}

assistant: ```c
int rdiscrete(int M, double *prob_original) {
  double sum = 0;
  int ans;
  double *prob = (double *)malloc(M * sizeof(double));
  for (int i = 0; i < M; i++) {
    sum += prob_original[i];
  }
  for (int i = 0; i < M; i++) {
    prob[i] = prob_original[i] / sum;
  }
  double *cum_prob = (double *)malloc((M + 1) * sizeof(double));
  cum_prob[0] = 0;
  for (int i = 1; i < M; i++) {
    cum_prob[i] = cum_prob[i - 1] + prob[i - 1];
  }
  cum_prob[M] = 1;
  double u = runif();
  for (int i = 0; i < M; i++) {
    if ((u >= cum_prob[i]) && (u <= cum_prob[i + 1])) {
      ans = i;
      break;
    }
  }
  free(prob);
  free(cum_prob);
  return ans;
}
```