user: Converte this assembly snippet into its equivalent C code:

```asm
<encode_pulse_distance>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbp
  mov    %esi,%r14d
  mov    %rdx,%r13
  mov    %rcx,0x8(%rsp)
  mov    $0x84d,%edx
  lea    D100(%rip),%rsi
  call   <keymap_param@plt>
  mov    %eax,0x0(%r13)
  mov    $0x753,%edx
  lea    D16(%rip),%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,0x4(%r13)
  mov    $0x4,%edx
  lea    D95(%rip),%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,%ebx
  mov    %eax,0x4(%rsp)
  mov    $0x0,%edx
  lea    D106(%rip),%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  test   %eax,%eax
  je     L25
  test   %ebx,%ebx
  jle    L40
  mov    %ebx,%r15d
  mov    $0x0,%ebx
  lea    D87(%rip),%r12
  jmp    L29
L8:
  mov    $0x177,%edx
  lea    D69(%rip),%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,0xc(%r13,%rbx,8)
L24:
  add    $0x1,%rbx
  cmp    %r15,%rbx
  je     L12
L29:
  mov    $0x271,%edx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,0x8(%r13,%rbx,8)
  bt     %ebx,%r14d
  jae    L8
  mov    $0x659,%edx
  lea    D12(%rip),%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,0xc(%r13,%rbx,8)
  jmp    L24
L12:
  mov    0x4(%rsp),%eax
  lea    0x2(%rax,%rax,1),%ebx
L127:
  movslq %ebx,%rax
  lea    0x0(%r13,%rax,4),%r12
  mov    $0x271,%edx
  lea    D73(%rip),%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%r12)
  add    $0x1,%ebx
  mov    0x8(%rsp),%rax
  mov    %ebx,(%rax)
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L25:
  mov    0x4(%rsp),%ebx
  sub    $0x1,%ebx
  js     L48
  lea    0xc(%r13),%r12
  lea    D87(%rip),%r15
  jmp    L66
L50:
  mov    $0x177,%edx
  lea    D69(%rip),%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%r12)
L46:
  sub    $0x1,%ebx
  add    $0x8,%r12
  cmp    $0xffffffff,%ebx
  je     L102
L66:
  mov    $0x271,%edx
  mov    %r15,%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,-0x4(%r12)
  bt     %ebx,%r14d
  jae    L50
  mov    $0x659,%edx
  lea    D12(%rip),%rsi
  mov    %rbp,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%r12)
  jmp    L46
L102:
  mov    0x4(%rsp),%eax
  lea    0x2(%rax,%rax,1),%ebx
  jmp    L127
L40:
  mov    $0x2,%ebx
  jmp    L127
L48:
  mov    $0x2,%ebx
  jmp    L127
```

tool_calls: name: extract_symbolic_data
arguments: label: D100
data_type: string
name: extract_symbolic_data
arguments: label: D16
data_type: string
name: extract_symbolic_data
arguments: label: D95
data_type: string
name: extract_symbolic_data
arguments: label: D106
data_type: string
name: extract_symbolic_data
arguments: label: D87
data_type: string
name: extract_symbolic_data
arguments: label: D69
data_type: string
name: extract_symbolic_data
arguments: label: D12
data_type: string
name: extract_symbolic_data
arguments: label: D73
data_type: string

tool: D100: header_pulse

tool: D16: header_space

tool: D95: bits

tool: D106: reverse

tool: D87: bit_pulse

tool: D69: bit_0_space

tool: D12: bit_1_space

tool: D73: trailer_pulse

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;
}
```