#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*/ WCONTINUED;
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ execution_pipe(char **, char **, char **, char **);
int fork();
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ my_puterr(char *);
int /*<<< orphan*/ my_putstr(char *);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int pipe_fork(char **s1, char **s2, char **env, char **path) {
  pid_t pid;
  int statue;
  if ((pid = fork()) == -1) {
    my_putstr("Fork is dead\n");
    return (1);
  }
  if (pid == 0) {
    execution_pipe(s1, s2, env, path);
    free(path);
    return (0);
  } else {
    waitpid(pid, &statue, WCONTINUED);
    if (WIFSIGNALED(statue)) {
      if (WTERMSIG(statue) == 11)
        my_puterr("Segmentation Fault (Core dumped)\n");
    }
  }
  free(path);
  return (0);
}


x86 assembly (clang, -O0):
<pipe_fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    11c3 <pipe_fork+0x43>
lea    0xe4e(%rip),%rdi
call   1070 <my_putstr@plt>
movl   $0x1,-0x4(%rbp)
jmp    1255 <pipe_fork+0xd5>
cmpl   $0x0,-0x2c(%rbp)
jne    11f7 <pipe_fork+0x77>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <execution_pipe@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1255 <pipe_fork+0xd5>
mov    -0x2c(%rbp),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rsi
call   1090 <waitpid@plt>
mov    -0x30(%rbp),%edi
call   1060 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1240 <pipe_fork+0xc0>
mov    -0x30(%rbp),%edi
call   1080 <WTERMSIG@plt>
cmp    $0xb,%eax
jne    123b <pipe_fork+0xbb>
lea    0xdd8(%rip),%rdi
call   1040 <my_puterr@plt>
jmp    1240 <pipe_fork+0xc0>
jmp    1245 <pipe_fork+0xc5>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_fork>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11bd <pipe_fork+0x3d>
cmp    $0xffffffff,%eax
jne    11d8 <pipe_fork+0x58>
lea    0xe4f(%rip),%rdi
call   1070 <my_putstr@plt>
mov    $0x1,%ebp
jmp    121f <pipe_fork+0x9f>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <execution_pipe@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    121f <pipe_fork+0x9f>
mov    0x2df9(%rip),%rcx
mov    (%rcx),%edx
lea    0xc(%rsp),%rsi
mov    %eax,%edi
call   1090 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1060 <WIFSIGNALED@plt>
test   %rax,%rax
je     1215 <pipe_fork+0x95>
mov    0xc(%rsp),%edi
call   1080 <WTERMSIG@plt>
cmp    $0xb,%eax
jne    1215 <pipe_fork+0x95>
lea    0xdfe(%rip),%rdi
call   1040 <my_puterr@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Fork is dead\0A\00"
@WCONTINUED = global i32 0
@.str.1 = [34 x i8] c"Segmentation Fault (Core dumped)\0A\00"
define i32 @pipe_fork(i8** %0, i8** %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i32
%11 = alloca i32
store i8** %0, i8*** %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
%12 = call i32 (...) @fork()
store i32 %12, i32* %10
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = call i32 @my_putstr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %45
16: ; preds = %4
%17 = load i32, i32* %10
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i8**, i8*** %6
%21 = load i8**, i8*** %7
%22 = load i8**, i8*** %8
%23 = load i8**, i8*** %9
%24 = call i32 @execution_pipe(i8** %20, i8** %21, i8** %22, i8** %23)
%25 = load i8**, i8*** %9
%26 = call i32 @free(i8** %25)
store i32 0, i32* %5
br label %45
27: ; preds = %16
%28 = load i32, i32* %10
%29 = load i32, i32* @WCONTINUED
%30 = call i32 @waitpid(i32 %28, i32* %11, i32 %29)
%31 = load i32, i32* %11
%32 = call i64 @WIFSIGNALED(i32 %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %27
%35 = load i32, i32* %11
%36 = call i32 @WTERMSIG(i32 %35)
%37 = icmp eq i32 %36, 11
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @my_puterr(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
br label %41
41: ; preds = %40, %27
br label %42
42: ; preds = %41
%43 = load i8**, i8*** %9
%44 = call i32 @free(i8** %43)
store i32 0, i32* %5
br label %45
45: ; preds = %42, %19, %14
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@.str = [14 x i8] c"Fork is dead\0A\00"
@WCONTINUED = global i32 0
@.str.1 = [34 x i8] c"Segmentation Fault (Core dumped)\0A\00"
define i32 @pipe_fork(i8** %0, i8** %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = tail call i32 (...) @fork()
switch i32 %7, label %13 [
i32 -1, label %8
i32 0, label %10
]
8: ; preds = %4
%9 = tail call i32 @my_putstr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %27
10: ; preds = %4
%11 = tail call i32 @execution_pipe(i8** %0, i8** %1, i8** %2, i8** %3)
%12 = tail call i32 @free(i8** %3)
br label %27
13: ; preds = %4
%14 = load i32, i32* @WCONTINUED
%15 = call i32 @waitpid(i32 %7, i32* %5, i32 %14)
%16 = load i32, i32* %5
%17 = call i64 @WIFSIGNALED(i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %13
%20 = load i32, i32* %5
%21 = call i32 @WTERMSIG(i32 %20)
%22 = icmp eq i32 %21, 11
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @my_puterr(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %13, %23, %19
%26 = call i32 @free(i8** %3)
br label %27
27: ; preds = %25, %10, %8
%28 = phi i32 [ 1, %8 ], [ 0, %10 ], [ 0, %25 ]
ret i32 %28
}