#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 /*<<< orphan*/ pid_t;

/* Variables and functions */
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ check_ld_bind();
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int status = 0;
  pid_t pid;
  check_ld_bind();
  if ((pid = fork()) == 0) {
    check_ld_bind();
    if (argc > 1 && strcmp(argv[1], "-child") == 0) {
      char *childArgvArray[2];
      childArgvArray[0] = argv[0];
      childArgvArray[1] = NULL;
      fprintf(stderr, "Going to execv...\n");
      execv(childArgvArray[0], childArgvArray);
      fprintf(stderr, "execv failed, existing...\n");
    }
  } else {
    waitpid(pid, &status, 0);
    if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
      fprintf(stderr, " Child has returned with exit error (pid:%d)\n",
              getpid());
      return 1;
    }
  }
  fprintf(stderr, "LD_BIND_NOW was not found in %d\n", getpid());
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1040 <check_ld_bind@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    1249 <main+0xb9>
mov    $0x0,%al
call   1040 <check_ld_bind@plt>
cmpl   $0x1,-0x8(%rbp)
jle    1244 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe19(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1244 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   10a0 <execv@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    12b1 <main+0x121>
mov    -0x18(%rbp),%edi
lea    -0x14(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    -0x14(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%eax
je     127a <main+0xea>
mov    -0x14(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     12ac <main+0x11c>
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x34(%rbp),%edi
mov    %eax,%edx
lea    0xd9c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12de <main+0x14e>
jmp    12b1 <main+0x121>
mov    0x2d28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%edx
lea    0xd93(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
movl   $0x0,0xc(%rsp)
xor    %eax,%eax
call   1040 <check_ld_bind@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     11f3 <main+0x63>
lea    0xc(%rsp),%rsi
mov    %eax,%edi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    0xc(%rsp),%edi
call   1090 <WIFEXITED@plt>
mov    $0x1,%r14d
lea    0xe5a(%rip),%rbx
test   %eax,%eax
je     1265 <main+0xd5>
mov    0xc(%rsp),%edi
call   1070 <WEXITSTATUS@plt>
test   %rax,%rax
jne    1265 <main+0xd5>
jmp    125b <main+0xcb>
xor    %eax,%eax
call   1040 <check_ld_bind@plt>
cmp    $0x2,%ebp
jl     125b <main+0xcb>
mov    0x8(%rbx),%rdi
lea    0xdf6(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    125b <main+0xcb>
mov    (%rbx),%rbx
mov    %rbx,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2db4(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xdd1(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   10a0 <execv@plt>
mov    0x0(%rbp),%edi
lea    0xdc6(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %r14d,%r14d
lea    0xdfe(%rip),%rbx
mov    0x2d74(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"-child\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Going to execv...\0A\00"
@.str.2 = [27 x i8] c"execv failed, existing...\0A\00"
@.str.3 = [46 x i8] c" Child has returned with exit error (pid:%d)\0A\00"
@.str.4 = [33 x i8] c"LD_BIND_NOW was not found in %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i8*]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = call i32 (...) @check_ld_bind()
%10 = call i32 (...) @fork()
store i32 %10, i32* %7
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %37
12: ; preds = %2
%13 = call i32 (...) @check_ld_bind()
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 1
br i1 %15, label %16, label %36
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 0
store i8* %25, i8** %26
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 1
store i8* null, i8** %27
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%30 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 0
%31 = load i8*, i8** %30
%32 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 0
%33 = call i32 @execv(i8* %31, i8** %32)
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %22, %16, %12
br label %52
37: ; preds = %2
%38 = load i32, i32* %7
%39 = call i32 @waitpid(i32 %38, i32* %6, i32 0)
%40 = load i32, i32* %6
%41 = call i32 @WIFEXITED(i32 %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %37
%44 = load i32, i32* %6
%45 = call i64 @WEXITSTATUS(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %43, %37
%48 = load i32, i32* @stderr
%49 = call i32 (...) @getpid()
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %49)
store i32 1, i32* %3
br label %56
51: ; preds = %43
br label %52
52: ; preds = %51, %36
%53 = load i32, i32* @stderr
%54 = call i32 (...) @getpid()
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i32 %54)
store i32 0, i32* %3
br label %56
56: ; preds = %52, %47
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str = [7 x i8] c"-child\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"Going to execv...\0A\00"
@.str.2 = [27 x i8] c"execv failed, existing...\0A\00"
@.str.3 = [46 x i8] c" Child has returned with exit error (pid:%d)\0A\00"
@.str.4 = [33 x i8] c"LD_BIND_NOW was not found in %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [2 x i8*]
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = tail call i32 (...) @check_ld_bind()
%7 = tail call i32 (...) @fork()
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %2
%10 = tail call i32 (...) @check_ld_bind()
%11 = icmp sgt i32 %0, 1
br i1 %11, label %12, label %36
12: ; preds = %9
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %12
%18 = bitcast [2 x i8*]* %4 to i8*
%19 = load i8*, i8** %1
%20 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
store i8* %19, i8** %20
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 1
store i8* null, i8** %21
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @execv(i8* %19, i8** %20)
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %36
27: ; preds = %2
%28 = call i32 @waitpid(i32 %7, i32* %3, i32 0)
%29 = load i32, i32* %3
%30 = call i32 @WIFEXITED(i32 %29)
%31 = icmp eq i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = load i32, i32* %3
%34 = call i64 @WEXITSTATUS(i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32, %9, %12, %17
br label %37
37: ; preds = %27, %32, %36
%38 = phi i8* [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), %36 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), %32 ], [ getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), %27 ]
%39 = phi i32 [ 0, %36 ], [ 1, %32 ], [ 1, %27 ]
%40 = load i32, i32* @stderr
%41 = call i32 (...) @getpid()
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* %38, i32 %41)
ret i32 %39
}