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


x86 assembly (clang, -O0):
<my_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11bf <my_do+0x3f>
lea    0xe52(%rip),%rdi
call   1070 <my_putstr@plt>
movl   $0x1,-0x4(%rbp)
jmp    1257 <my_do+0xd7>
cmpl   $0x0,-0x24(%rbp)
jne    1202 <my_do+0x82>
mov    $0x0,%al
call   1040 <setsid@plt>
cmp    $0xffffffff,%eax
jne    11e5 <my_do+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    1257 <my_do+0xd7>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <execve@plt>
movl   $0x0,-0x4(%rbp)
jmp    1257 <my_do+0xd7>
mov    -0x24(%rbp),%edi
mov    0x2dcc(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rsi
call   1090 <waitpid@plt>
mov    -0x28(%rbp),%edi
call   1060 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     124b <my_do+0xcb>
mov    -0x28(%rbp),%edi
call   1080 <WTERMSIG@plt>
cmp    $0xb,%eax
jne    1246 <my_do+0xc6>
lea    0xdcd(%rip),%rdi
call   1030 <my_puterr@plt>
jmp    124b <my_do+0xcb>
jmp    1250 <my_do+0xd0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_do>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     11b4 <my_do+0x34>
cmp    $0xffffffff,%eax
jne    11d2 <my_do+0x52>
lea    0xe58(%rip),%rdi
call   1070 <my_putstr@plt>
mov    $0x1,%ebx
jmp    1218 <my_do+0x98>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <setsid@plt>
cmp    $0xffffffff,%eax
je     1213 <my_do+0x93>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <execve@plt>
jmp    1218 <my_do+0x98>
mov    0x2dff(%rip),%rcx
mov    (%rcx),%edx
lea    0x4(%rsp),%rsi
mov    %eax,%edi
call   1090 <waitpid@plt>
mov    0x4(%rsp),%edi
call   1060 <WIFSIGNALED@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1218 <my_do+0x98>
mov    0x4(%rsp),%edi
call   1080 <WTERMSIG@plt>
cmp    $0xb,%eax
jne    1218 <my_do+0x98>
lea    0xe02(%rip),%rdi
call   1030 <my_puterr@plt>
jmp    1218 <my_do+0x98>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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 @my_do(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%10 = call i32 (...) @fork()
store i32 %10, i32* %8
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @my_putstr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %42
14: ; preds = %3
%15 = load i32, i32* %8
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %26
17: ; preds = %14
%18 = call i32 (...) @setsid()
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %17
store i32 -1, i32* %4
br label %42
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = load i8**, i8*** %7
%24 = load i8**, i8*** %6
%25 = call i32 @execve(i8* %22, i8** %23, i8** %24)
store i32 0, i32* %4
br label %42
26: ; preds = %14
%27 = load i32, i32* %8
%28 = load i32, i32* @WCONTINUED
%29 = call i32 @waitpid(i32 %27, i32* %9, i32 %28)
%30 = load i32, i32* %9
%31 = call i64 @WIFSIGNALED(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %26
%34 = load i32, i32* %9
%35 = call i32 @WTERMSIG(i32 %34)
%36 = icmp eq i32 %35, 11
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = call i32 @my_puterr(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %39
39: ; preds = %37, %33
br label %40
40: ; preds = %39, %26
br label %41
41: ; preds = %40
store i32 0, i32* %4
br label %42
42: ; preds = %41, %21, %20, %12
%43 = load i32, i32* %4
ret i32 %43
}

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 @my_do(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 (...) @fork()
switch i32 %6, label %14 [
i32 -1, label %7
i32 0, label %9
]
7: ; preds = %3
%8 = tail call i32 @my_putstr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %26
9: ; preds = %3
%10 = tail call i32 (...) @setsid()
%11 = icmp eq i32 %10, -1
br i1 %11, label %26, label %12
12: ; preds = %9
%13 = tail call i32 @execve(i8* %0, i8** %2, i8** %1)
br label %26
14: ; preds = %3
%15 = load i32, i32* @WCONTINUED
%16 = call i32 @waitpid(i32 %6, i32* %4, i32 %15)
%17 = load i32, i32* %4
%18 = call i64 @WIFSIGNALED(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %26, label %20
20: ; preds = %14
%21 = load i32, i32* %4
%22 = call i32 @WTERMSIG(i32 %21)
%23 = icmp eq i32 %22, 11
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @my_puterr(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %20, %24, %14, %9, %12, %7
%27 = phi i32 [ 1, %7 ], [ 0, %12 ], [ -1, %9 ], [ 0, %14 ], [ 0, %24 ], [ 0, %20 ]
ret i32 %27
}