#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__ do_execve_test(char *, char **, int /*<<< orphan*/ *, int);
int get_bits();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sleep(int);
int main(int argc, const char *argv[]) {
  int my_err, my_status;
  pid_t my_pid, my_wait_pid;
  char *errmsg = NULL;
  char *argvs[2] = {"", NULL};
  int bits = get_bits();
  errmsg = "execve failed: from x86_64 forking and exec()ing 64-bit x86_64 "
           "process w/ 4G pagezero.\n";
  argvs[0] = "sleep-x86_64-4G";
  if (do_execve_test("helpers/sleep-x86_64-4G", argvs, NULL, 1))
    goto test_failed_exit;
  errmsg = "execve failed: from x86_64 forking and exec()ing 64-bit x86_64 "
           "process w/ 4K Pagezero.\n";
  argvs[0] = "sleep-x86_64-4K";
  if (do_execve_test("helpers/sleep-x86_64-4K", argvs, NULL, 1))
    goto test_failed_exit;
  errmsg =
      "execve failed: from x64_64 forking and exec()ing 32-bit i386 process.\n";
  argvs[0] = "sleep-i386";
  if (do_execve_test("helpers/sleep-i386", argvs, NULL, 1))
    goto test_failed_exit;
  sleep(4);
  return 0;
test_failed_exit:
  if (errmsg)
    printf("%s", errmsg);
  return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2cab(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2ca8(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    $0x0,%al
call   1050 <get_bits@plt>
mov    %eax,-0x44(%rbp)
lea    0xe7b(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xed0(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xeb9(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x1,%ecx
call   1040 <do_execve_test@plt>
cmp    $0x0,%rax
je     11bc <main+0x7c>
jmp    124e <main+0x10e>
lea    0xead(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xf02(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xeeb(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x1,%ecx
call   1040 <do_execve_test@plt>
cmp    $0x0,%rax
je     11fa <main+0xba>
jmp    124e <main+0x10e>
lea    0xedf(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xf23(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    -0x40(%rbp),%rsi
lea    0xf0c(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x1,%ecx
call   1040 <do_execve_test@plt>
cmp    $0x0,%rax
je     1238 <main+0xf8>
jmp    124e <main+0x10e>
mov    $0x4,%edi
call   1060 <sleep@plt>
movl   $0x0,-0x4(%rbp)
jmp    1270 <main+0x130>
cmpq   $0x0,-0x28(%rbp)
je     1269 <main+0x129>
mov    -0x28(%rbp),%rsi
lea    0xed6(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movaps 0x2cc4(%rip),%xmm0
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   1050 <get_bits@plt>
lea    0xf02(%rip),%rax
mov    %rax,(%rsp)
lea    0xeef(%rip),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <do_execve_test@plt>
test   %rax,%rax
je     1186 <main+0x46>
lea    0xe7c(%rip),%rsi
jmp    11e4 <main+0xa4>
lea    0xf43(%rip),%rax
mov    %rax,(%rsp)
lea    0xf30(%rip),%rdi
mov    %rsp,%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <do_execve_test@plt>
test   %rax,%rax
je     11b5 <main+0x75>
lea    0xebd(%rip),%rsi
jmp    11e4 <main+0xa4>
lea    0xf73(%rip),%rax
mov    %rax,(%rsp)
lea    0xf60(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %edx,%edx
mov    $0x1,%ecx
call   1040 <do_execve_test@plt>
test   %rax,%rax
je     11fd <main+0xbd>
lea    0xefc(%rip),%rsi
lea    0xf4f(%rip),%rdi
call   1030 <printf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x4,%edi
call   1060 <sleep@plt>
jmp    11f5 <main+0xb5>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@__const.main.argvs = [2 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [88 x i8] c"execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4G pagezero.\0A\00"
@.str.2 = [16 x i8] c"sleep-x86_64-4G\00"
@.str.3 = [24 x i8] c"helpers/sleep-x86_64-4G\00"
@.str.4 = [88 x i8] c"execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4K Pagezero.\0A\00"
@.str.5 = [16 x i8] c"sleep-x86_64-4K\00"
@.str.6 = [24 x i8] c"helpers/sleep-x86_64-4K\00"
@.str.7 = [71 x i8] c"execve failed: from x64_64 forking and exec()ing 32-bit i386 process.\0A\00"
@.str.8 = [11 x i8] c"sleep-i386\00"
@.str.9 = [19 x i8] c"helpers/sleep-i386\00"
@.str.10 = [3 x i8] c"%s\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 i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [2 x i8*]
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %10
%13 = bitcast [2 x i8*]* %11 to i8*
%14 = call i32 (...) @get_bits()
store i32 %14, i32* %12
store i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0), i8** %10
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 0
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 0
%17 = call i64 @do_execve_test(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8** %16, i32* null, i32 1)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %2
br label %34
20: ; preds = %2
store i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.4, i64 0, i64 0), i8** %10
%21 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 0
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 0
%23 = call i64 @do_execve_test(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8** %22, i32* null, i32 1)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
br label %34
26: ; preds = %20
store i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.7, i64 0, i64 0), i8** %10
%27 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 0
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8** %27
%28 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 0
%29 = call i64 @do_execve_test(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8** %28, i32* null, i32 1)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %26
br label %34
32: ; preds = %26
%33 = call i32 @sleep(i32 4)
store i32 0, i32* %3
br label %41
34: ; preds = %31, %25, %19
%35 = load i8*, i8** %10
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i8*, i8** %10
%39 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %37, %34
store i32 -1, i32* %3
br label %41
41: ; preds = %40, %32
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@__const.main.argvs = [2 x i8*] [i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i32 0, i32 0), i8* null]
@.str.1 = [88 x i8] c"execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4G pagezero.\0A\00"
@.str.2 = [16 x i8] c"sleep-x86_64-4G\00"
@.str.3 = [24 x i8] c"helpers/sleep-x86_64-4G\00"
@.str.4 = [88 x i8] c"execve failed: from x86_64 forking and exec()ing 64-bit x86_64 process w/ 4K Pagezero.\0A\00"
@.str.5 = [16 x i8] c"sleep-x86_64-4K\00"
@.str.6 = [24 x i8] c"helpers/sleep-x86_64-4K\00"
@.str.7 = [71 x i8] c"execve failed: from x64_64 forking and exec()ing 32-bit i386 process.\0A\00"
@.str.8 = [11 x i8] c"sleep-i386\00"
@.str.9 = [19 x i8] c"helpers/sleep-i386\00"
@.str.10 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i8*]
%4 = bitcast [2 x i8*]* %3 to i8*
%5 = tail call i32 (...) @get_bits()
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8** %6
%7 = call i64 @do_execve_test(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8** %6, i32* null, i32 1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %2
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i8** %6
%10 = call i64 @do_execve_test(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8** %6, i32* null, i32 1)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8** %6
%13 = call i64 @do_execve_test(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0), i8** %6, i32* null, i32 1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @sleep(i32 4)
br label %20
17: ; preds = %2, %9, %12
%18 = phi i8* [ getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([88 x i8], [88 x i8]* @.str.4, i64 0, i64 0), %9 ], [ getelementptr inbounds ([71 x i8], [71 x i8]* @.str.7, i64 0, i64 0), %12 ]
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %17, %15
%21 = phi i32 [ -1, %17 ], [ 0, %15 ]
ret i32 %21
}