user: 请将以下的汇编代码转换成C语言代码:

```asm
<csamplestatepath>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x58,%rsp
  mov    %edi,%esi
  mov    %rdx,%rdi
  mov    %ecx,-0x50(%rbp)
  mov    %r9,-0x78(%rbp)
  mov    0x10(%rbp),%rax
  mov    %rax,-0x58(%rbp)
  mov    0x18(%rbp),%rax
  mov    %rax,-0x68(%rbp)
  mov    0x20(%rbp),%r12
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    %esi,-0x4c(%rbp)
  mov    %esi,%eax
  cltd
  idiv   %ecx
  test   %edx,%edx
  jne    L20
  mov    %esi,%eax
  cltd
  idiv   %ecx
  mov    %ecx,%r13d
L134:
  mov    -0x4c(%rbp),%ebx
  sub    %r13d,%ebx
  movslq 0x28(%rbp),%rdx
  lea    0xf(,%rdx,8),%rdx
  mov    %rdx,%rsi
  and    $0xfffffffffffffff0,%rsi
  and    $0xfffffffffffff000,%rdx
  mov    %rsp,%rcx
  sub    %rdx,%rcx
L118:
  cmp    %rcx,%rsp
  je     L137
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L118
L20:
  mov    %edx,%r13d
  mov    -0x4c(%rbp),%eax
  cltd
  idivl  -0x50(%rbp)
  add    $0x1,%eax
  jmp    L134
L137:
  mov    %rsi,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  je     L45
  orq    $0x0,-0x8(%rsp,%rdx,1)
L45:
  lea    0x7(%rsp),%rsi
  mov    %rsi,%rdx
  shr    $0x3,%rdx
  and    $0xfffffffffffffff8,%rsi
  cltq
  lea    0x0(,%rax,8),%r14
  mov    (%rdi,%rax,8),%rcx
  movsd  (%rcx),%xmm0
  movsd  %xmm0,0x0(,%rdx,8)
  cmpl   $0x1,0x28(%rbp)
  jle    L60
  mov    0x28(%rbp),%edx
  mov    $0x1,%eax
L120:
  movsd  -0x8(%rsi,%rax,8),%xmm0
  addsd  (%rcx,%rax,8),%xmm0
  movsd  %xmm0,(%rsi,%rax,8)
  add    $0x1,%rax
  cmp    %rdx,%rax
  jne    L120
L60:
  movslq -0x4c(%rbp),%rax
  mov    -0x58(%rbp),%rcx
  lea    -0x4(%rcx,%rax,4),%r15
  mov    0x28(%rbp),%edx
  mov    $0x0,%edi
  call   <sample@plt>
  mov    %eax,(%r15)
  test   %ebx,%ebx
  js     L105
  mov    -0x50(%rbp),%eax
  neg    %eax
  cltq
  mov    %rax,-0x70(%rbp)
  movslq %ebx,%rax
  mov    %rax,-0x48(%rbp)
  lea    (%r12,%r14,1),%rax
  mov    %rax,-0x60(%rbp)
  mov    -0x58(%rbp),%rcx
  lea    0x4(%rcx),%rax
  mov    %rax,-0x80(%rbp)
  jmp    L40
L96:
  mov    -0x68(%rbp),%rax
  mov    0x4(%rax),%r12d
  movslq %r14d,%rax
  mov    -0x60(%rbp),%rcx
  mov    (%rcx),%rdx
  mov    (%rdx,%rax,8),%rsi
  mov    0x28(%rbp),%edx
  mov    $0x0,%edi
  call   <samplebinsearch@plt>
  mov    -0x58(%rbp),%rcx
  mov    %eax,(%rcx)
  mov    $0x0,%r15d
L90:
  mov    -0x4c(%rbp),%eax
  add    %r13d,%eax
  lea    -0x2(%rax),%edx
  cmp    %edx,%r15d
  jge    L129
  movslq %r14d,%r14
  shl    $0x3,%r14
  movslq %r15d,%rdx
  lea    0x0(,%rdx,4),%rcx
  mov    -0x58(%rbp),%rdi
  lea    (%rdi,%rcx,1),%rbx
  mov    -0x68(%rbp),%rdi
  lea    0x8(%rdi,%rcx,1),%r13
  sub    $0x3,%eax
  sub    %r15d,%eax
  add    %rdx,%rax
  mov    -0x80(%rbp),%rcx
  lea    (%rcx,%rax,4),%r15
  mov    %r12d,%eax
  mov    -0x78(%rbp),%r12
L18:
  cltq
  movslq (%rbx),%rdx
  mov    (%r12,%rax,8),%rax
  mov    (%rax,%rdx,8),%rax
  mov    (%rax,%r14,1),%rsi
  mov    0x28(%rbp),%edx
  mov    $0x0,%edi
  call   <samplebinsearch@plt>
  mov    %eax,0x4(%rbx)
  mov    0x0(%r13),%eax
  add    $0x4,%rbx
  add    $0x4,%r13
  cmp    %r15,%rbx
  jne    L18
L129:
  mov    -0x70(%rbp),%rcx
  add    %rcx,-0x48(%rbp)
  mov    -0x48(%rbp),%rax
  subq   $0x8,-0x60(%rbp)
  test   %eax,%eax
  js     L105
  mov    -0x50(%rbp),%r13d
L40:
  mov    -0x4c(%rbp),%eax
  mov    -0x48(%rbp),%rcx
  mov    %ecx,-0x4c(%rbp)
  cltq
  mov    -0x58(%rbp),%rdi
  mov    -0x4(%rdi,%rax,4),%r14d
  test   %ecx,%ecx
  jle    L96
  lea    -0x1(%rcx),%r15d
  mov    -0x68(%rbp),%rax
  mov    (%rax,%rcx,4),%r12d
  movslq %r15d,%rax
  lea    (%rdi,%rax,4),%rbx
  movslq %r14d,%rax
  mov    -0x60(%rbp),%rcx
  mov    (%rcx),%rdx
  mov    (%rdx,%rax,8),%rsi
  mov    0x28(%rbp),%edx
  mov    $0x0,%edi
  call   <samplebinsearch@plt>
  mov    %eax,(%rbx)
  jmp    L90
L105:
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L117
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L117:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
void csamplestatepath(int T, int *obs, double **fwds, int R, double ***mats, double ****rmats, int *states, int *storedpos, double ***sneak, int N) {
  double *distribution;
  int pos, cs, js, je;
  int p, s, e;
  int md = T % R;
  if (md == 0) {
    md = R;
    p = T / R;
  } else {
    p = T / R + 1;
  }
  e = T;
  s = T - md;
  double tmp[N];
  tmp[0] = fwds[p][0];
  int i;
  for (i = 1; i < N; i++)
    tmp[i] = tmp[i - 1] + fwds[p][i];
  states[e - 1] = sample(0, tmp, N);
  while (s >= 0) {
    p--;
    cs = states[e - 1];
    if (s > 0) {
      js = s - 1;
      pos = storedpos[s];
      states[js] = samplebinsearch(0, sneak[p + 1][cs], N);
    } else {
      js = 0;
      pos = storedpos[1];
      states[js] = samplebinsearch(0, sneak[p + 1][cs], N);
    }
    je = md + s - 2;
    for (; js < je; js++) {
      distribution = rmats[pos][states[js]][cs];
      states[js + 1] = samplebinsearch(0, distribution, N);
      pos = storedpos[js + 2];
    }
    md = R;
    s -= md;
    e = s + md;
  }
}
```