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

```asm
<readmessage>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x440,%rsp
  mov    %rdi,-0x438(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  mov    $0x1000,%edi
  call   <malloc@plt>
  mov    %rax,-0x418(%rbp)
  movl   $0x1000,-0x424(%rbp)
  movl   $0x0,-0x420(%rbp)
  mov    -0x418(%rbp),%rax
  movb   $0x0,(%rax)
  jmp    L119
L43:
  lea    -0x410(%rbp),%rax
  lea    D4(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L98
  mov    -0x420(%rbp),%eax
  lea    0x3(%rax),%edx
  mov    -0x424(%rbp),%eax
  sub    $0x1,%eax
  cmp    %eax,%edx
  jl     L51
  addl   $0x1000,-0x424(%rbp)
  mov    -0x424(%rbp),%edx
  mov    -0x418(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x418(%rbp)
L51:
  mov    -0x418(%rbp),%rax
  lea    D34(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  jmp    L119
L98:
  lea    -0x410(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,-0x41c(%rbp)
  cmpl   $0x0,-0x41c(%rbp)
  je     L20
  mov    -0x41c(%rbp),%eax
  sub    $0x1,%eax
  cltq
  movzbl -0x410(%rbp,%rax,1),%eax
  cmp    $0xa,%al
  jne    L20
  mov    -0x420(%rbp),%edx
  mov    -0x41c(%rbp),%eax
  add    %eax,%edx
  mov    -0x424(%rbp),%eax
  sub    $0x1,%eax
  cmp    %eax,%edx
  jl     L110
  addl   $0x1000,-0x424(%rbp)
  mov    -0x424(%rbp),%edx
  mov    -0x418(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x418(%rbp)
L110:
  mov    -0x41c(%rbp),%eax
  sub    $0x1,%eax
  cltq
  movb   $0x0,-0x410(%rbp,%rax,1)
  lea    -0x410(%rbp),%rdx
  mov    -0x418(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  mov    -0x418(%rbp),%rax
  lea    D14(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  jmp    L119
L20:
  mov    -0x420(%rbp),%edx
  mov    -0x41c(%rbp),%eax
  add    %edx,%eax
  cmp    %eax,-0x424(%rbp)
  jg     L82
  addl   $0x1000,-0x424(%rbp)
  mov    -0x424(%rbp),%edx
  mov    -0x418(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x418(%rbp)
L82:
  lea    -0x410(%rbp),%rdx
  mov    -0x418(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
L119:
  mov    -0x438(%rbp),%rdx
  lea    -0x410(%rbp),%rax
  mov    $0x400,%esi
  mov    %rax,%rdi
  call   <fgets@plt>
  test   %rax,%rax
  jne    L43
  mov    -0x420(%rbp),%eax
  lea    0x2(%rax),%edx
  mov    -0x424(%rbp),%eax
  sub    $0x1,%eax
  cmp    %eax,%edx
  jl     L14
  addl   $0x1000,-0x424(%rbp)
  mov    -0x424(%rbp),%edx
  mov    -0x418(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x418(%rbp)
L14:
  mov    -0x418(%rbp),%rax
  lea    D39(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcat@plt>
  mov    -0x438(%rbp),%rax
  mov    %rax,%rdi
  call   <rewind@plt>
  mov    -0x418(%rbp),%rax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L101
  call   <__stack_chk_fail@plt>
L101:
  leave
  ret
```

tool_calls: name: read_data
arguments: data_tag: D4
data_type: string
name: read_data
arguments: data_tag: D34
data_type: string
name: read_data
arguments: data_tag: D14
data_type: string
name: read_data
arguments: data_tag: D39
data_type: string

tool: D4: .


tool: D34: ..


tool: D14: 


tool: D39: .


assistant: ```c
char *readmessage(FILE *file) {
  char *buffer = malloc(4096);
  ssize_t bufsize = 4096, used = 0;
  char linebuf[1024];
  int i;
  buffer[0] = '\0';
  while (fgets(linebuf, sizeof(linebuf), file)) {
    if (strcmp(linebuf, ".\n") == 0) {
      do {
        if (used + 4 > bufsize - 1) {
          buffer = realloc(buffer, bufsize += 4096);
        }
      } while (0);
      strcat(buffer, "..\r\n");
    } else {
      i = strlen(linebuf);
      if (i && linebuf[i - 1] == '\n') {
        do {
          if (used + i + 1 > bufsize - 1) {
            buffer = realloc(buffer, bufsize += 4096);
          }
        } while (0);
        linebuf[i - 1] = '\0';
        strcat(buffer, linebuf);
        strcat(buffer, "\r\n");
      } else {
        do {
          if (used + i > bufsize - 1) {
            buffer = realloc(buffer, bufsize += 4096);
          }
        } while (0);
        strcat(buffer, linebuf);
      }
    }
  }
  do {
    if (used + 3 > bufsize - 1) {
      buffer = realloc(buffer, bufsize += 4096);
    }
  } while (0);
  strcat(buffer, ".\r\n");
  rewind(file);
  return buffer;
}
```