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

```asm
<main>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x38,%rsp
  mov    %rsi,%r13
  mov    %rdx,(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x1028(%rsp)
  xor    %eax,%eax
  cmp    $0x2,%edi
  jle    L154
L22:
  lea    0x20(%rsp),%rbx
  mov    $0x1000,%edx
  mov    $0x0,%esi
  mov    %rbx,%rdi
  call   <memset@plt>
  mov    0x8(%r13),%rsi
  mov    $0x1000,%edx
  mov    %rbx,%rdi
  call   <strncpy@plt>
  mov    0x10(%r13),%rdi
  call   <atoi@plt>
  mov    %eax,%ebp
  mov    $0x1,%edi
  call   <dup@plt>
  mov    %eax,0xc(%rsp)
  test   %ebp,%ebp
  jle    L25
  mov    $0x0,%ebx
  lea    0x18(%rsp),%r15
  lea    -0x1(%rbp),%r14d
  jmp    L113
L154:
  lea    D17(%rip),%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L22
L159:
  lea    D23(%rip),%rdi
  call   <puts@plt>
  mov    $0x1,%edi
  call   <exit@plt>
  jmp    L56
L57:
  mov    $0x1,%esi
  mov    0xc(%rsp),%edi
  call   <dup2@plt>
  mov    0x1c(%rsp),%edi
  call   <close@plt>
L2:
  lea    0x8(%r13),%rsi
  lea    0x20(%rsp),%r12
  mov    (%rsp),%rdx
  mov    %r12,%rdi
  call   <execve@plt>
  mov    %r12,%rsi
  lea    D25(%rip),%rdi
  mov    $0x0,%eax
  call   <printf@plt>
  mov    $0x1,%edi
  call   <exit@plt>
L110:
  lea    0x1(%rbx),%eax
  cmp    %eax,%ebp
  je     L103
  mov    %eax,%ebx
L113:
  mov    %r15,%rdi
  call   <pipe@plt>
  test   %eax,%eax
  js     L159
L56:
  mov    $0x0,%eax
  call   <fork@plt>
  test   %rax,%rax
  jne    L59
  mov    $0x1,%edi
  call   <close@plt>
  cmp    %ebx,%r14d
  jle    L57
  mov    $0x1,%esi
  mov    0x1c(%rsp),%edi
  call   <dup2@plt>
  jmp    L2
L59:
  mov    $0x0,%edi
  call   <close@plt>
  cmp    %ebx,%r14d
  jg     L49
L39:
  mov    0x18(%rsp),%edi
  call   <close@plt>
  mov    0x1c(%rsp),%edi
  call   <close@plt>
  jmp    L110
L49:
  mov    $0x0,%esi
  mov    0x18(%rsp),%edi
  call   <dup2@plt>
  jmp    L39
L103:
  mov    $0x1,%edi
  call   <close@plt>
  mov    $0x1,%esi
  mov    0xc(%rsp),%edi
  call   <dup2@plt>
  mov    $0x0,%ebp
  lea    0x14(%rsp),%r12
L24:
  mov    %r12,%rdi
  call   <wait@plt>
  mov    %ebp,%eax
  add    $0x1,%ebp
  cmp    %eax,%ebx
  jne    L24
L124:
  mov    $0x0,%edi
  call   <exit@plt>
  mov    0x1028(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L99
  mov    $0x0,%eax
  add    $0x1038,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L25:
  mov    $0x1,%edi
  call   <close@plt>
  mov    $0x1,%esi
  mov    0xc(%rsp),%edi
  call   <dup2@plt>
  jmp    L124
L99:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: tag: D17
type: string
name: disassemble_data
arguments: tag: D23
type: string
name: disassemble_data
arguments: tag: D25
type: string

tool: D17: usage: pipe-4 executable-file number-of-procs

tool: D23: error creating pipe

tool: D25: parent error: %s didn't exec


assistant: ```c
int main(int argc, char **argv, char **envp) {
  pid_t child_id;
  int child_status;
  int pipe_desc[2];
  char read_buffer[4096];
  int err;
  char file_name[4096];
  int proc_count;
  int i;
  int last_stdout;
  if (argc < 3) {
    printf("usage: pipe-4 executable-file number-of-procs\n");
    exit(1);
  }
  memset(file_name, 0, sizeof(file_name));
  strncpy(file_name, argv[1], sizeof(file_name));
  proc_count = atoi(argv[2]);
  last_stdout = dup(1);
  for (i = 0; i < proc_count; i++) {
    err = pipe(pipe_desc);
    if (err < 0) {
      printf("error creating pipe\n");
      exit(1);
    }
    child_id = fork();
    if (child_id == 0) {
      close(1);
      if (i < (proc_count - 1)) {
        dup2(pipe_desc[1], 1);
      } else {
        dup2(last_stdout, 1);
        close(pipe_desc[1]);
      }
      err = execve(file_name, &argv[1], envp);
      printf("parent error: %s didn't exec\n", file_name);
      exit(1);
    } else {
      close(0);
      if (i < (proc_count - 1)) {
        dup2(pipe_desc[0], 0);
      }
      close(pipe_desc[0]);
      close(pipe_desc[1]);
    }
  }
  close(1);
  dup2(last_stdout, 1);
  for (i = 0; i < proc_count; i++) {
    child_id = wait(&child_status);
  }
  exit(0);
}
```