#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int dup2(int, int /*<<< orphan*/);
int exec_path(char **, char **, char **);
int setsid();
int /*<<< orphan*/ wait(int *);
int wait_father(int p[2], char **env, char **s2, char **path) {
  int status;
  wait(&status);
  close(p[1]);
  if ((dup2(p[0], 0)) == -1)
    return (-1);
  if ((setsid()) == -1)
    return (-1);
  if ((exec_path(env, s2, path)) == -1)
    return (-1);
  return (0);
}


x86 assembly (clang, -O0):
<wait_father>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x2c(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    119f <wait_father+0x4f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <wait_father+0x98>
mov    $0x0,%al
call   1050 <setsid@plt>
cmp    $0xffffffff,%eax
jne    11bb <wait_father+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <wait_father+0x98>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <exec_path@plt>
cmp    $0xffffffff,%eax
jne    11e1 <wait_father+0x91>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e8 <wait_father+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_father>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x4(%rsp),%rdi
call   1070 <wait@plt>
mov    0x4(%rbp),%edi
call   1040 <close@plt>
mov    0x0(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11ae <wait_father+0x5e>
xor    %eax,%eax
call   1050 <setsid@plt>
cmp    $0xffffffff,%eax
je     11ae <wait_father+0x5e>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <exec_path@plt>
xor    %ebp,%ebp
cmp    $0xffffffff,%eax
sete   %bpl
neg    %ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wait_father(i32* %0, i8** %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i32
store i32* %0, i32** %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i8** %3, i8*** %9
%11 = call i32 @wait(i32* %10)
%12 = load i32*, i32** %6
%13 = getelementptr inbounds i32, i32* %12, i64 1
%14 = load i32, i32* %13
%15 = call i32 @close(i32 %14)
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
%19 = call i32 @dup2(i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %4
store i32 -1, i32* %5
br label %34
22: ; preds = %4
%23 = call i32 (...) @setsid()
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 -1, i32* %5
br label %34
26: ; preds = %22
%27 = load i8**, i8*** %7
%28 = load i8**, i8*** %8
%29 = load i8**, i8*** %9
%30 = call i32 @exec_path(i8** %27, i8** %28, i8** %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 -1, i32* %5
br label %34
33: ; preds = %26
store i32 0, i32* %5
br label %34
34: ; preds = %33, %32, %25, %21
%35 = load i32, i32* %5
ret i32 %35
}

LLVM IR (-O2):
define i32 @wait_father(i32* nocapture %0, i8** %1, i8** %2, i8** %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
%7 = call i32 @wait(i32* %5)
%8 = getelementptr inbounds i32, i32* %0, i64 1
%9 = load i32, i32* %8
%10 = call i32 @close(i32 %9)
%11 = load i32, i32* %0
%12 = call i32 @dup2(i32 %11, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %21, label %14
14: ; preds = %4
%15 = call i32 (...) @setsid()
%16 = icmp eq i32 %15, -1
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = call i32 @exec_path(i8** %1, i8** %2, i8** %3)
%19 = icmp eq i32 %18, -1
%20 = sext i1 %19 to i32
br label %21
21: ; preds = %17, %14, %4
%22 = phi i32 [ -1, %4 ], [ -1, %14 ], [ %20, %17 ]
ret i32 %22
}