#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int pipe(int *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int fds[2];
  pid_t pid;
  if (pipe(fds) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day09/lswc.c",
              21, "pipe", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if ((pid = fork()) == -1)
    do {
      fprintf(stderr, "[%s][%d]:%s %s\n",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/"
              "master/apue/day09/lswc.c",
              23, "fork", strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  if (pid == 0) {
    close(fds[0]);
    dup2(fds[1], 1);
    close(fds[1]);
    execlp("ls", "ls", NULL);
    fprintf(stderr, "execlp err:%s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  close(fds[1]);
  dup2(fds[0], 0);
  close(fds[0]);
  execlp("wc", "wc", "-w", NULL);
  fprintf(stderr, "execlp err:%s\n", strerror(errno));
  exit(EXIT_FAILURE);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11f5 <main+0x75>
jmp    11a6 <main+0x26>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%r9
lea    0xe33(%rip),%rsi
lea    0xe3c(%rip),%rdx
mov    $0x15,%ecx
lea    0xec3(%rip),%r8
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    125c <main+0xdc>
jmp    120d <main+0x8d>
mov    0x2dcc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%r9
lea    0xdcc(%rip),%rsi
lea    0xdd5(%rip),%rdx
mov    $0x17,%ecx
lea    0xe61(%rip),%r8
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x10(%rbp)
jne    12d4 <main+0x154>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe23(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1080 <execlp@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
lea    0xdca(%rip),%rsi
lea    0xdc6(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1080 <execlp@plt>
mov    0x2ccf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11c9 <main+0x49>
mov    0x2e45(%rip),%rax
mov    (%rax),%ebx
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe4e(%rip),%rsi
lea    0xe57(%rip),%rdx
lea    0xee3(%rip),%r8
mov    %ebx,%edi
mov    $0x15,%ecx
jmp    120c <main+0x8c>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     121b <main+0x9b>
cmp    $0xffffffff,%eax
jne    1250 <main+0xd0>
mov    0x2e00(%rip),%rax
mov    (%rax),%ebx
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe09(%rip),%rsi
lea    0xe12(%rip),%rdx
lea    0xea3(%rip),%r8
mov    %ebx,%edi
mov    $0x17,%ecx
mov    %rax,%r9
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12b1 <main+0x131>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
lea    0xe6b(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <execlp@plt>
jmp    1287 <main+0x107>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
lea    0xe4b(%rip),%rdi
lea    0xe47(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1080 <execlp@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%ebx
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe0b(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day09/lswc.c\00"
@.str.2 = [5 x i8] c"pipe\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"fork\00"
@.str.4 = [3 x i8] c"ls\00"
@.str.5 = [15 x i8] c"execlp err:%s\0A\00"
@.str.6 = [3 x i8] c"wc\00"
@.str.7 = [3 x i8] c"-w\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %0
br label %8
8: ; preds = %7
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; No predecessors!
br label %16
16: ; preds = %15, %0
%17 = call i32 (...) @fork()
store i32 %17, i32* %3
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %28
19: ; preds = %16
br label %20
20: ; preds = %19
%21 = load i32, i32* @stderr
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; No predecessors!
br label %28
28: ; preds = %27, %16
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %48
31: ; preds = %28
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @dup2(i32 %36, i32 1)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* null)
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %28
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%53 = load i32, i32* %52
%54 = call i32 @dup2(i32 %53, i32 0)
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%56 = load i32, i32* %55
%57 = call i32 @close(i32 %56)
%58 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* null)
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %61)
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [147 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/drsin/linuxCoreLearn/refs/heads/master/apue/day09/lswc.c\00"
@.str.2 = [5 x i8] c"pipe\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [5 x i8] c"fork\00"
@.str.4 = [3 x i8] c"ls\00"
@.str.5 = [15 x i8] c"execlp err:%s\0A\00"
@.str.6 = [3 x i8] c"wc\00"
@.str.7 = [3 x i8] c"-w\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = call i32 (...) @fork()
switch i32 %14, label %37 [
i32 -1, label %15
i32 0, label %22
]
15: ; preds = %13
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([147 x i8], [147 x i8]* @.str.1, i64 0, i64 0), i32 23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %13
%23 = load i32, i32* %3
%24 = call i32 @close(i32 %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @dup2(i32 %26, i32 1)
%28 = load i32, i32* %25
%29 = call i32 @close(i32 %28)
%30 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* null)
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %13
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = load i32, i32* %3
%42 = call i32 @dup2(i32 %41, i32 0)
%43 = load i32, i32* %3
%44 = call i32 @close(i32 %43)
%45 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* null)
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
}