user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<setup_multistage_tree>:
  endbr64
  push   %r13
  mov    %esi,%r13d
  push   %r12
  mov    %edx,%r12d
  push   %rbp
  mov    %edi,%ebp
  push   %rbx
  mov    %rcx,%rbx
  sub    $0x8,%rsp
  call   <ipow@plt>
  mov    %r12d,%edx
  mov    %r13d,%esi
  mov    %ebp,%edi
  call   <calculate_number_of_nodes@plt>
  test   %r12d,%r12d
  jle    L109
  movd   %ebp,%xmm2
  xor    %r8d,%r8d
  xor    %edi,%edi
  mov    $0x1,%edx
  movdqa D6(%rip),%xmm0
  pshufd $0x0,%xmm2,%xmm1
  nop
L141:
  mov    %edi,%r9d
  add    %edx,%edi
  test   %edx,%edx
  jle    L161
  lea    -0x1(%rdx),%eax
  cmp    %r8d,%r13d
  jg     L1
  cmp    $0x2,%eax
  jbe    L44
  movslq %r9d,%rax
  lea    (%rbx,%rax,4),%rcx
  mov    %edx,%eax
  shr    $0x2,%eax
  lea    -0x1(%rax),%esi
  lea    0x10(%rcx),%rax
  shl    $0x4,%rsi
  add    %rax,%rsi
  jmp    L154
  xchg   %ax,%ax
L72:
  add    $0x10,%rax
L154:
  movups %xmm0,(%rcx)
  mov    %rax,%rcx
  cmp    %rax,%rsi
  jne    L72
  mov    %edx,%eax
  and    $0xfffffffc,%eax
  test   $0x3,%dl
  je     L210
L125:
  lea    (%rax,%r9,1),%ecx
  movslq %ecx,%rcx
  movl   $0x1,(%rbx,%rcx,4)
  lea    0x1(%rax),%ecx
  cmp    %ecx,%edx
  jle    L210
  add    %r9d,%ecx
  add    $0x2,%eax
  movslq %ecx,%rcx
  movl   $0x1,(%rbx,%rcx,4)
  cmp    %edx,%eax
  jge    L210
  add    %r9d,%eax
  cltq
  movl   $0x1,(%rbx,%rax,4)
L210:
  add    $0x1,%r8d
  cmp    %r8d,%r12d
  jg     L141
  test   %edx,%edx
  jle    L197
  add    $0x8,%rsp
  movslq %edx,%rdx
  movslq %edi,%rdi
  xor    %esi,%esi
  lea    (%rbx,%rdi,4),%rdi
  shl    $0x2,%rdx
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  jmp    1080 <memset@plt>
  nopw   0x0(%rax,%rax,1)
L1:
  cmp    $0x2,%eax
  jbe    L91
  movslq %r9d,%rax
  lea    (%rbx,%rax,4),%rcx
  mov    %edx,%eax
  shr    $0x2,%eax
  lea    -0x1(%rax),%esi
  lea    0x10(%rcx),%rax
  shl    $0x4,%rsi
  add    %rax,%rsi
  jmp    L112
  nopl   (%rax)
L36:
  add    $0x10,%rax
L112:
  movups %xmm1,(%rcx)
  mov    %rax,%rcx
  cmp    %rsi,%rax
  jne    L36
  mov    %edx,%eax
  and    $0xfffffffc,%eax
  test   $0x3,%dl
  je     L46
L133:
  lea    (%r9,%rax,1),%ecx
  movslq %ecx,%rcx
  mov    %ebp,(%rbx,%rcx,4)
  lea    0x1(%rax),%ecx
  cmp    %ecx,%edx
  jle    L46
  add    %r9d,%ecx
  add    $0x2,%eax
  movslq %ecx,%rcx
  mov    %ebp,(%rbx,%rcx,4)
  cmp    %eax,%edx
  jle    L46
  add    %r9d,%eax
  cltq
  mov    %ebp,(%rbx,%rax,4)
L46:
  imul   %ebp,%edx
  jmp    L210
L109:
  movl   $0x0,(%rbx)
L197:
  add    $0x8,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L161:
  add    $0x1,%r8d
  cmp    %r8d,%r12d
  jle    L197
  xor    %edx,%edx
  jmp    L210
L44:
  xor    %eax,%eax
  jmp    L125
L91:
  xor    %eax,%eax
  jmp    L133
```

tool_calls: name: disassemble_data
arguments: label: D6
type_guessed: byte[16]

tool: {"D6": [0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x01,0x00,0x00,0x00]}

assistant: ```c
void setup_multistage_tree(int md, int Nr, int Nh, int *nk) {
  int num_scenarios = ipow(md, Nr);
  int num_nodes = calculate_number_of_nodes(md, Nr, Nh);
  int nodes_in_next_stage;
  int nodes_in_stage = 1;
  int idx = 0;
  for (int kk = 0; kk < Nh; kk++) {
    nodes_in_next_stage = 0;
    for (int ii = 0; ii < nodes_in_stage; ii++) {
      if (kk < Nr) {
        nk[idx + ii] = md;
      } else {
        nk[idx + ii] = 1;
      }
      nodes_in_next_stage += nk[idx + ii];
    }
    idx += nodes_in_stage;
    nodes_in_stage = nodes_in_next_stage;
  }
  for (int ii = 0; ii < nodes_in_stage; ii++) {
    nk[idx + ii] = 0;
  }
}
```