user: What is the c source code of the assembly code below?

```asm
<rt_modbus_read_input_table>:
  endbr64
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbp
  mov    %fs:0x28,%rax
  mov    %rax,0x8(%rsp)
  xor    %eax,%eax
  lea    D37(%rip),%rdi
  call   <printf@plt>
  lea    0x8(%rbp),%rsi
  mov    %rsp,%rbx
  mov    $0x2,%edx
  mov    %rbx,%rdi
  call   <memcpy@plt>
  mov    %rbx,%rdi
  call   <swap16@plt>
  lea    0x10(%rbp),%rsi
  lea    0x4(%rsp),%rbx
  mov    $0x2,%edx
  mov    %rbx,%rdi
  call   <memcpy@plt>
  mov    %rbx,%rdi
  call   <swap16@plt>
  mov    0x4(%rsp),%edx
  cmp    $0x80,%edx
  jg     L78
  lea    0x7(%rdx),%r12d
  test   %edx,%edx
  cmovns %edx,%r12d
  sar    $0x3,%r12d
  mov    %edx,%ecx
  sar    $0x1f,%ecx
  shr    $0x1d,%ecx
  lea    (%rdx,%rcx,1),%eax
  and    $0x7,%eax
  sub    %ecx,%eax
  test   %eax,%eax
  setg   %al
  movzbl %al,%eax
  add    %eax,%r12d
  mov    %r12d,0x8(%rbp)
  mov    %r12d,%esi
  lea    D17(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  lea    0xc(%rbp),%rax
  test   %r12d,%r12d
  jle    L76
  lea    0x3(%r12),%edx
  lea    0x0(%rbp,%rdx,4),%rdx
L10:
  add    $0x4,%rax
  movl   $0x0,-0x4(%rax)
  cmp    %rax,%rdx
  jne    L10
L76:
  cmpl   $0x0,0x4(%rsp)
  jle    L87
  mov    $0x0,%ebx
  mov    $0x1,%r13d
  jmp    L26
L78:
  lea    D0(%rip),%rdi
  call   <puts@plt>
  mov    0x4(%rsp),%edx
  mov    (%rsp),%esi
  lea    D31(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  movl   $0x82,0x4(%rbp)
  movl   $0x4,0x8(%rbp)
  mov    $0xffff,%edx
  mov    $0x5,%esi
  mov    %rbp,%rdi
  call   <add_CRC@plt>
  mov    $0x5,%r12d
  jmp    L33
L2:
  add    $0x1,%ebx
  cmp    %ebx,0x4(%rsp)
  jle    L87
L26:
  mov    %ebx,%edi
  add    (%rsp),%edi
  call   <read_di@plt>
  test   %eax,%eax
  je     L2
  lea    0x7(%rbx),%eax
  test   %ebx,%ebx
  cmovns %ebx,%eax
  sar    $0x3,%eax
  add    $0x3,%eax
  cltq
  mov    %ebx,%ecx
  and    $0x7,%ecx
  mov    %r13d,%edx
  shl    %cl,%edx
  or     %edx,0x0(%rbp,%rax,4)
  jmp    L2
L87:
  add    $0x5,%r12d
  mov    $0xffff,%edx
  mov    %r12d,%esi
  mov    %rbp,%rdi
  call   <add_CRC@plt>
L33:
  mov    0x8(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L14
  mov    %r12d,%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L14:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: label: D37
datatype: string
name: read_data
arguments: label: D17
datatype: string
name: read_data
arguments: label: D0
datatype: string
name: read_data
arguments: label: D31
datatype: string

tool: D37: In Read Input Table, n = %d


tool: D17: In Read Input Table, byte count = %d, num_points = %d


tool: D0: *** Too many points specified!

tool: D31: Start %u, Num %u


assistant: ```c
int rt_modbus_read_input_table(uint8_t *buf, int n) {
  uint16_t start_point;
  uint16_t num_points;
  int byte_count;
  uint8_t *p;
  int i;
  uint8_t val;
  int byte, bit;
  uint8_t mask;
  printf("In Read Input Table, n = %d\n", n);
  memcpy(&start_point, buf + 2, 2);
  swap16(&start_point);
  memcpy(&num_points, buf + 4, 2);
  swap16(&num_points);
  if (num_points > 128) {
    printf("*** Too many points specified!\n");
    printf("Start %u, Num %u\n", start_point, num_points);
    buf[1] = 128 + (0x02);
    buf[2] = 4;
    add_CRC(buf, 5, 0xffff);
    return 5;
  }
  byte_count = num_points / 8;
  if ((num_points % 8) > 0) {
    byte_count++;
  }
  buf[2] = byte_count;
  printf("In Read Input Table, byte count = %d, num_points = %d\n", byte_count, num_points);
  p = buf + 3;
  for (i = 0; i < byte_count; i++) {
    *(p++) = 0x00;
  }
  for (i = 0; i < num_points; i++) {
    val = read_di(i + start_point);
    if (val) {
      byte = i / 8;
      bit = i % 8;
      mask = 1 << bit;
      buf[byte + 3] |= mask;
    }
  }
  add_CRC(buf, 5 + byte_count, 0xffff);
  return (5 + byte_count);
}
```