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

```asm
<BtFLZH_EncBalanceTree_r>:
  endbr64
  mov    $0x0,%eax
  test   %edx,%edx
  js     L39
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbp
  mov    %rsi,%r12
  mov    %ecx,0xc(%rsp)
  lea    0x1(%rcx),%eax
  add    %edx,%edx
  movslq %edx,%rbx
  lea    (%rdi,%rbx,2),%r15
  movswl (%r15),%edx
  mov    %r8d,0x4(%rsp)
  mov    %eax,0x8(%rsp)
  mov    %eax,%ecx
  call   <BtFLZH_EncBalanceTree_r>
  mov    %eax,%r13d
  lea    0x2(%rbp,%rbx,2),%r14
  movswl (%r14),%edx
  mov    0x4(%rsp),%r8d
  mov    0x8(%rsp),%ecx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <BtFLZH_EncBalanceTree_r>
  mov    %eax,%ecx
  cmp    %eax,%r13d
  mov    %eax,%edx
  cmovge %r13d,%edx
  lea    0x1(%rdx),%eax
  add    %r12,%rbx
  mov    %ax,(%rbx)
  mov    0xc(%rsp),%edi
  lea    (%rdi,%rax,1),%edx
  cmp    0x4(%rsp),%edx
  jle    L58
  lea    0x1(%r13),%edx
  cmp    %ecx,%edx
  jge    L15
  movzwl (%r14),%ecx
  movswl %cx,%eax
  lea    (%rax,%rax,1),%edx
  movslq %edx,%rdx
  lea    0x2(%rbp,%rdx,2),%rdi
  movzwl (%rdi),%esi
  lea    0x0(%rbp,%rdx,2),%rdx
  movzwl (%rdx),%r8d
  mov    %r8w,(%rdi)
  movzwl (%r15),%edi
  mov    %di,(%rdx)
L2:
  mov    %cx,(%r15)
  mov    %si,(%r14)
  add    %eax,%eax
  cltq
  movzwl 0x0(%rbp,%rax,2),%esi
  movzwl 0x2(%rbp,%rax,2),%ecx
  mov    $0x0,%edx
  test   %si,%si
  js     L22
  movswq %si,%rsi
  movswl (%r12,%rsi,2),%edx
L22:
  mov    $0x0,%esi
  test   %cx,%cx
  js     L35
  movswq %cx,%rcx
  movswl (%r12,%rcx,2),%esi
L35:
  cmp    %esi,%edx
  cmovl  %esi,%edx
  add    $0x1,%edx
  mov    %dx,(%r12,%rax,1)
  movzwl (%r15),%ecx
  movzwl (%r14),%edx
  mov    $0x0,%eax
  test   %cx,%cx
  js     L67
  movswq %cx,%rcx
  movswl (%r12,%rcx,2),%eax
L67:
  mov    $0x0,%ecx
  test   %dx,%dx
  js     L86
  movswq %dx,%rdx
  movswl (%r12,%rdx,2),%ecx
L86:
  cmp    %ecx,%eax
  cmovl  %ecx,%eax
  add    $0x1,%eax
  mov    %ax,(%rbx)
L58:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L15:
  add    $0x1,%ecx
  cmp    %r13d,%ecx
  jge    L58
  movzwl (%r15),%esi
  movswl %si,%eax
  lea    (%rax,%rax,1),%edx
  movslq %edx,%rdx
  lea    0x0(%rbp,%rdx,2),%rdi
  movzwl (%rdi),%ecx
  lea    0x2(%rbp,%rdx,2),%rdx
  movzwl (%rdx),%r8d
  mov    %r8w,(%rdi)
  movzwl (%r14),%edi
  mov    %di,(%rdx)
  jmp    L2
L39:
  ret
```

assistant: ```c
int BtFLZH_EncBalanceTree_r(short *nodes, short *nlen, int root, int h, int ml) {
  int h0, h1, h2, h3;
  int l0, l1, l2;
  if (root < 0) {
    return (0);
  }
  h1 = BtFLZH_EncBalanceTree_r(nodes, nlen, nodes[root * 2 + 0], h + 1, ml);
  h2 = BtFLZH_EncBalanceTree_r(nodes, nlen, nodes[root * 2 + 1], h + 1, ml);
  h0 = ((h1 > h2) ? h1 : h2) + 1;
  nlen[root] = h0;
  if ((h + h0) <= ml) {
    return (h0);
  }
  if ((h1 + 1) < h2) {
    l0 = nodes[root * 2 + 1];
    l1 = nodes[l0 * 2 + 1];
    nodes[l0 * 2 + 1] = nodes[l0 * 2 + 0];
    nodes[l0 * 2 + 0] = nodes[root * 2 + 0];
    nodes[root * 2 + 0] = l0;
    nodes[root * 2 + 1] = l1;
  } else if ((h2 + 1) < h1) {
    l0 = nodes[root * 2 + 0];
    l1 = nodes[l0 * 2 + 0];
    nodes[l0 * 2 + 0] = nodes[l0 * 2 + 1];
    nodes[l0 * 2 + 1] = nodes[root * 2 + 1];
    nodes[root * 2 + 0] = l1;
    nodes[root * 2 + 1] = l0;
  } else {
    return (h0);
  }
  l1 = nodes[l0 * 2 + 0];
  l2 = nodes[l0 * 2 + 1];
  h1 = (l1 < 0) ? 0 : nlen[l1];
  h2 = (l2 < 0) ? 0 : nlen[l2];
  h3 = ((h1 > h2) ? h1 : h2) + 1;
  nlen[l0] = h3;
  l1 = nodes[root * 2 + 0];
  l2 = nodes[root * 2 + 1];
  h1 = (l1 < 0) ? 0 : nlen[l1];
  h2 = (l2 < 0) ? 0 : nlen[l2];
  h0 = ((h1 > h2) ? h1 : h2) + 1;
  nlen[root] = h0;
  return (h0);
}
```