#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 mafsain(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/ls_wc.c",
              25, "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/ls_wc.c",
              27, "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):
<mafsain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11ee <mafsain+0x6e>
jmp    119f <mafsain+0x1f>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%r9
lea    0xe3a(%rip),%rsi
lea    0xe43(%rip),%rdx
mov    $0x19,%ecx
lea    0xecb(%rip),%r8
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    1255 <mafsain+0xd5>
jmp    1206 <mafsain+0x86>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%r9
lea    0xdd3(%rip),%rsi
lea    0xddc(%rip),%rdx
mov    $0x1b,%ecx
lea    0xe69(%rip),%r8
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpl   $0x0,-0xc(%rbp)
jne    12cd <mafsain+0x14d>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
lea    0xe2b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1080 <execlp@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xdd3(%rip),%rsi
lea    0xdcf(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1080 <execlp@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xd87(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<mafsain>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11c9 <mafsain+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    0xee4(%rip),%r8
mov    %ebx,%edi
mov    $0x19,%ecx
jmp    120c <mafsain+0x8c>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     121b <mafsain+0x9b>
cmp    $0xffffffff,%eax
jne    1250 <mafsain+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    0xea4(%rip),%r8
mov    %ebx,%edi
mov    $0x1b,%ecx
mov    %rax,%r9
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12b1 <mafsain+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    0xe6c(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1080 <execlp@plt>
jmp    1287 <mafsain+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    0xe4d(%rip),%rdi
lea    0xe49(%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    0xe0c(%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 = [148 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/ls_wc.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 = [16 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 @mafsain() {
%1 = alloca [2 x i32]
%2 = alloca i32
%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 %15
6: ; preds = %0
br label %7
7: ; preds = %6
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 25, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; No predecessors!
br label %15
15: ; preds = %14, %0
%16 = call i32 (...) @fork()
store i32 %16, i32* %2
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %27
18: ; preds = %15
br label %19
19: ; preds = %18
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; No predecessors!
br label %27
27: ; preds = %26, %15
%28 = load i32, i32* %2
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %47
30: ; preds = %27
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @dup2(i32 %35, i32 1)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = 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)
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %43)
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %27
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%49 = load i32, i32* %48
%50 = call i32 @close(i32 %49)
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%52 = load i32, i32* %51
%53 = call i32 @dup2(i32 %52, i32 0)
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%55 = load i32, i32* %54
%56 = call i32 @close(i32 %55)
%57 = 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)
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %60)
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"[%s][%d]:%s %s\0A\00"
@.str.1 = [148 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/ls_wc.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 = [16 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 @mafsain() {
%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 ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 25, 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 ([148 x i8], [148 x i8]* @.str.1, i64 0, i64 0), i32 27, 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 ([16 x i8], [16 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 ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
}