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

```asm
<encode_pulse_distance>:
  endbr64
  push   %r15
  mov    %rdi,%r15
  push   %r14
  push   %r13
  mov    %esi,%r13d
  lea    D8(%rip),%rsi
  push   %r12
  mov    %rdx,%r12
  mov    $0x84d,%edx
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rcx,0x18(%rsp)
  call   <keymap_param@plt>
  mov    $0x753,%edx
  lea    D34(%rip),%rsi
  mov    %r15,%rdi
  mov    %eax,(%r12)
  call   <keymap_param@plt>
  mov    $0x4,%edx
  lea    D40(%rip),%rsi
  mov    %r15,%rdi
  mov    %eax,0x4(%r12)
  call   <keymap_param@plt>
  xor    %edx,%edx
  lea    D37(%rip),%rsi
  mov    %r15,%rdi
  mov    %eax,0x14(%rsp)
  mov    %eax,%ebx
  call   <keymap_param@plt>
  test   %eax,%eax
  je     L0
  test   %ebx,%ebx
  jle    L44
  movslq %ebx,%rax
  lea    D55(%rip),%r14
  xor    %ebx,%ebx
  mov    %rax,0x8(%rsp)
  lea    D49(%rip),%rbp
  nopl   0x0(%rax)
L91:
  mov    $0x271,%edx
  mov    %r14,%rsi
  mov    %r15,%rdi
  call   <keymap_param@plt>
  bt     %ebx,%r13d
  mov    %eax,0x8(%r12,%rbx,8)
  jae    L77
  mov    $0x659,%edx
  mov    %rbp,%rsi
  mov    %r15,%rdi
  call   <keymap_param@plt>
  mov    %eax,0xc(%r12,%rbx,8)
  add    $0x1,%rbx
  cmp    0x8(%rsp),%rbx
  jne    L91
L14:
  mov    0x14(%rsp),%eax
  lea    0x2(%rax,%rax,1),%ebx
  movslq %ebx,%rax
  add    $0x1,%ebx
  shl    $0x2,%rax
L94:
  mov    %r15,%rdi
  mov    $0x271,%edx
  lea    D85(%rip),%rsi
  add    %rax,%r12
  call   <keymap_param@plt>
  mov    %eax,(%r12)
  mov    0x18(%rsp),%rax
  mov    %ebx,(%rax)
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L0:
  mov    0x14(%rsp),%ebx
  sub    $0x1,%ebx
  js     L44
  lea    0x8(%r12),%rbp
  lea    D55(%rip),%r14
  nopl   0x0(%rax)
L43:
  mov    $0x271,%edx
  mov    %r14,%rsi
  mov    %r15,%rdi
  call   <keymap_param@plt>
  bt     %ebx,%r13d
  mov    $0x659,%edx
  lea    D49(%rip),%rsi
  mov    %eax,0x0(%rbp)
  jb     L96
  mov    $0x177,%edx
  lea    D77(%rip),%rsi
L96:
  mov    %r15,%rdi
  sub    $0x1,%ebx
  add    $0x8,%rbp
  call   <keymap_param@plt>
  mov    %eax,-0x4(%rbp)
  cmp    $0xffffffff,%ebx
  jne    L43
  jmp    L14
  nopl   (%rax)
L77:
  mov    $0x177,%edx
  lea    D77(%rip),%rsi
  mov    %r15,%rdi
  call   <keymap_param@plt>
  mov    %eax,0xc(%r12,%rbx,8)
  add    $0x1,%rbx
  cmp    %rbx,0x8(%rsp)
  jne    L91
  jmp    L14
  nopl   (%rax)
L44:
  mov    $0x3,%ebx
  mov    $0x8,%eax
  jmp    L94
```

tool_calls: name: unpack_data
arguments: label: D8
datatype: string
name: unpack_data
arguments: label: D34
datatype: string
name: unpack_data
arguments: label: D40
datatype: string
name: unpack_data
arguments: label: D37
datatype: string
name: unpack_data
arguments: label: D55
datatype: string
name: unpack_data
arguments: label: D49
datatype: string
name: unpack_data
arguments: label: D85
datatype: string
name: unpack_data
arguments: label: D77
datatype: string

tool: D8: header_pulse

tool: D34: header_space

tool: D40: bits

tool: D37: reverse

tool: D55: bit_pulse

tool: D49: bit_1_space

tool: D85: trailer_pulse

tool: D77: bit_0_space

assistant: ```c
void encode_pulse_distance(struct keymap *map, uint32_t scancode, int *buf, int *length) {
  int len = 0, bits, i;
  buf[len++] = keymap_param(map, "header_pulse", 2125);
  buf[len++] = keymap_param(map, "header_space", 1875);
  bits = keymap_param(map, "bits", 4);
  if (keymap_param(map, "reverse", 0)) {
    for (i = 0; i < bits; i++) {
      buf[len++] = keymap_param(map, "bit_pulse", 625);
      if (scancode & (1 << i))
        buf[len++] = keymap_param(map, "bit_1_space", 1625);
      else
        buf[len++] = keymap_param(map, "bit_0_space", 375);
    }
  } else {
    for (i = bits - 1; i >= 0; i--) {
      buf[len++] = keymap_param(map, "bit_pulse", 625);
      if (scancode & (1 << i))
        buf[len++] = keymap_param(map, "bit_1_space", 1625);
      else
        buf[len++] = keymap_param(map, "bit_0_space", 375);
    }
  }
  buf[len++] = keymap_param(map, "trailer_pulse", 625);
  *length = len;
}
```