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

```asm
<main>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  lea    -0x1c(%rbp),%rax
  mov    %rax,%rdi
  call   <pipe@plt>
  test   %rax,%rax
  jns    L7
  lea    D16(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  mov    $0x1,%eax
  jmp    L40
L7:
  mov    $0x0,%eax
  call   <fork@plt>
  mov    %rax,-0x30(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  jns    L32
  lea    D0(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  mov    $0x1,%eax
  jmp    L40
L32:
  cmpq   $0x0,-0x30(%rbp)
  jle    L26
  mov    -0x1c(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  mov    $0x1,%edi
  call   <sleep@plt>
  mov    -0x18(%rbp),%eax
  mov    $0xc,%edx
  lea    D31(%rip),%rcx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <write@plt>
  mov    %eax,-0x34(%rbp)
  mov    -0x34(%rbp),%eax
  mov    %eax,%esi
  lea    D26(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  jmp    L69
L26:
  mov    -0x18(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
  mov    -0x1c(%rbp),%eax
  lea    -0x14(%rbp),%rcx
  mov    $0xc8,%edx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <read@plt>
  mov    %eax,-0x38(%rbp)
  lea    -0x14(%rbp),%rdx
  mov    -0x38(%rbp),%eax
  mov    %eax,%esi
  lea    D20(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    -0x1c(%rbp),%eax
  lea    -0x14(%rbp),%rcx
  mov    $0xc8,%edx
  mov    %rcx,%rsi
  mov    %eax,%edi
  call   <read@plt>
  mov    %eax,-0x38(%rbp)
  lea    -0x14(%rbp),%rdx
  mov    -0x38(%rbp),%eax
  mov    %eax,%esi
  lea    D20(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  lea    D36(%rip),%rax
  mov    %rax,%rsi
  lea    D58(%rip),%rax
  mov    %rax,%rdi
  call   <popen@plt>
  mov    %rax,-0x28(%rbp)
  jmp    L38
L77:
  lea    -0x14(%rbp),%rax
  mov    %rax,%rsi
  lea    D80(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <printf@plt>
L38:
  mov    -0x28(%rbp),%rdx
  lea    -0x14(%rbp),%rax
  mov    $0xc8,%esi
  mov    %rax,%rdi
  call   <fgets@plt>
  test   %rax,%rax
  jne    L77
L69:
  mov    $0x0,%eax
L40:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L15
  call   <__stack_chk_fail@plt>
L15:
  leave
  ret
```

tool_calls: name: disassemble_data
arguments: tag: D16
type_infered: string
name: disassemble_data
arguments: tag: D0
type_infered: string
name: disassemble_data
arguments: tag: D31
type_infered: string
name: disassemble_data
arguments: tag: D26
type_infered: string
name: disassemble_data
arguments: tag: D20
type_infered: string
name: disassemble_data
arguments: tag: D36
type_infered: string
name: disassemble_data
arguments: tag: D58
type_infered: string
name: disassemble_data
arguments: tag: D80
type_infered: string

tool: D16: failed pipe.

tool: D0: failed fork.

tool: D31: hello sonico!

tool: D26: write return %d.


tool: D20: read return %d, %s.


tool: D36: r

tool: D58: echo "hello sonico!"

tool: D80: fgets: %s


assistant: ```c
int main() {
  int fd[2];
  if (pipe(fd) < 0) {
    perror("failed pipe.");
    return 1;
  }
  pid_t pid = fork();
  if (pid < 0) {
    perror("failed fork.");
    return 1;
  } else if (pid > 0) {
    close(fd[0]);
    sleep(1);
    int write_ret = write(fd[1], "hello sonico!", 12);
    printf("write return %d.\n", write_ret);
  } else {
    close(fd[1]);
    char line[12];
    int n = read(fd[0], line, 200);
    printf("read return %d, %s.\n", n, line);
    n = read(fd[0], line, 200);
    printf("read return %d, %s.\n", n, line);
    FILE *fpin = popen("echo \"hello sonico!\"", "r");
    while (fgets(line, 200, fpin) != NULL) {
      printf("fgets: %s\n", line);
    }
  }
  return 0;
}
```