user: Please show me the C implementation that matches the assembly code listed below:

```asm
<encode_pulse_distance>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %esi,-0x2c(%rbp)
  mov    %rdx,-0x38(%rbp)
  mov    %rcx,-0x40(%rbp)
  movl   $0x0,-0x1c(%rbp)
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x84d,%edx
  lea    D10(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x753,%edx
  lea    D58(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
  mov    -0x28(%rbp),%rax
  mov    $0x4,%edx
  lea    D49(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,-0x14(%rbp)
  mov    -0x28(%rbp),%rax
  mov    $0x0,%edx
  lea    D109(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  test   %eax,%eax
  je     L53
  movl   $0x0,-0x18(%rbp)
  jmp    L54
L14:
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x271,%edx
  lea    D5(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
  mov    -0x18(%rbp),%eax
  mov    -0x2c(%rbp),%edx
  mov    %eax,%ecx
  sar    %cl,%edx
  mov    %edx,%eax
  and    $0x1,%eax
  test   %eax,%eax
  je     L70
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x659,%edx
  lea    D22(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
  jmp    L79
L70:
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x177,%edx
  lea    D74(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
L79:
  addl   $0x1,-0x18(%rbp)
L54:
  mov    -0x18(%rbp),%eax
  cmp    -0x14(%rbp),%eax
  jl     L14
  jmp    L77
L53:
  mov    -0x14(%rbp),%eax
  sub    $0x1,%eax
  mov    %eax,-0x18(%rbp)
  jmp    L89
L84:
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x271,%edx
  lea    D5(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
  mov    -0x18(%rbp),%eax
  mov    -0x2c(%rbp),%edx
  mov    %eax,%ecx
  sar    %cl,%edx
  mov    %edx,%eax
  and    $0x1,%eax
  test   %eax,%eax
  je     L9
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x659,%edx
  lea    D22(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
  jmp    L15
L9:
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x177,%edx
  lea    D74(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
L15:
  subl   $0x1,-0x18(%rbp)
L89:
  cmpl   $0x0,-0x18(%rbp)
  jns    L84
L77:
  mov    -0x1c(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x38(%rbp),%rax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  mov    $0x271,%edx
  lea    D46(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <keymap_param@plt>
  mov    %eax,(%rbx)
  mov    -0x40(%rbp),%rax
  mov    -0x1c(%rbp),%edx
  mov    %edx,(%rax)
  nop
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: read_data
arguments: tag: D10
type_guessed: string
name: read_data
arguments: tag: D58
type_guessed: string
name: read_data
arguments: tag: D49
type_guessed: string
name: read_data
arguments: tag: D109
type_guessed: string
name: read_data
arguments: tag: D5
type_guessed: string
name: read_data
arguments: tag: D22
type_guessed: string
name: read_data
arguments: tag: D74
type_guessed: string
name: read_data
arguments: tag: D46
type_guessed: string

tool: D10: header_pulse

tool: D58: header_space

tool: D49: bits

tool: D109: reverse

tool: D5: bit_pulse

tool: D22: bit_1_space

tool: D74: bit_0_space

tool: D46: 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;
}
```