#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 */
scalar_t__ EFAULT;
scalar_t__ errno;
int execve(char const *, char **, char **);
int /*<<< orphan*/ printf(char *);
int main(int argc, const char **argv, const char **envp) {
  int r;
  char **badptr_argv = (char **)-1;
  char *badptr = (char *)-1;
  char *bad_argv[] = {badptr, NULL};
  char *good_argv[] = {"DUMMY", NULL};
  char *bad_envp[] = {badptr, NULL};
  char *good_envp[] = {"DUMMY", NULL};
  r = execve(badptr, good_argv, good_envp);
  if (r == -1 && errno == EFAULT)
    printf("execve(invalid-path) correctly returned error\n");
  r = execve(argv[0], badptr_argv, good_envp);
  if (r == -1 && errno == EFAULT)
    printf("execve(invalid-argv-ptr) correctly returned error\n");
  r = execve(argv[0], good_argv, badptr_argv);
  if (r == -1 && errno == EFAULT)
    printf("execve(invalid-envp-ptr) correctly returned error\n");
  r = execve(argv[0], bad_argv, good_envp);
  if (r == -1 && errno == EFAULT)
    printf("execve(invalid-argv) correctly returned error\n");
  r = execve(argv[0], good_argv, bad_envp);
  if (r == -1 && errno == EFAULT)
    printf("execve(invalid-envp) correctly returned error\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
mov    0x2c89(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c86(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x60(%rbp)
movq   $0x0,-0x58(%rbp)
mov    0x2c73(%rip),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c70(%rip),%rax
mov    %rax,-0x68(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1040 <execve@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e0 <main+0xc0>
mov    0x2e17(%rip),%rax
mov    (%rax),%rax
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%rax
jne    11e0 <main+0xc0>
lea    0xe2b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1040 <execve@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1227 <main+0x107>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rax
mov    0x2de6(%rip),%rcx
cmp    (%rcx),%rax
jne    1227 <main+0x107>
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <execve@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    126e <main+0x14e>
mov    0x2d89(%rip),%rax
mov    (%rax),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
jne    126e <main+0x14e>
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x70(%rbp),%rdx
call   1040 <execve@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12b5 <main+0x195>
mov    0x2d42(%rip),%rax
mov    (%rax),%rax
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
jne    12b5 <main+0x195>
lea    0xdeb(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1040 <execve@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12fc <main+0x1dc>
mov    0x2cfb(%rip),%rax
mov    (%rax),%rax
mov    0x2d11(%rip),%rcx
cmp    (%rcx),%rax
jne    12fc <main+0x1dc>
lea    0xdd3(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
movq   $0xffffffffffffffff,0x30(%rsp)
ff ff
movq   $0x0,0x38(%rsp)
movaps 0x2cbf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movq   $0xffffffffffffffff,0x20(%rsp)
ff ff
movq   $0x0,0x28(%rsp)
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%rsi
mov    %rsp,%rdx
mov    $0xffffffffffffffff,%rdi
call   1040 <execve@plt>
cmp    $0xffffffff,%eax
jne    1197 <main+0x77>
mov    0x2e5c(%rip),%rax
mov    (%rax),%rax
mov    0x2e72(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <main+0x77>
lea    0xf34(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
mov    %rsp,%rdx
mov    $0xffffffffffffffff,%rsi
call   1040 <execve@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0xb0>
mov    0x2e23(%rip),%rax
mov    (%rax),%rax
mov    0x2e39(%rip),%rcx
cmp    (%rcx),%rax
jne    11d0 <main+0xb0>
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
lea    0x10(%rsp),%rsi
mov    $0xffffffffffffffff,%rdx
call   1040 <execve@plt>
cmp    $0xffffffff,%eax
jne    120b <main+0xeb>
mov    0x2de8(%rip),%rax
mov    (%rax),%rax
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%rax
jne    120b <main+0xeb>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
lea    0x30(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <execve@plt>
cmp    $0xffffffff,%eax
jne    1242 <main+0x122>
mov    0x2db1(%rip),%rax
mov    (%rax),%rax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%rax
jne    1242 <main+0x122>
lea    0xdf7(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rdi
lea    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
call   1040 <execve@plt>
cmp    $0xffffffff,%eax
jne    127b <main+0x15b>
mov    0x2d78(%rip),%rax
mov    (%rax),%rax
mov    0x2d8e(%rip),%rcx
cmp    (%rcx),%rax
jne    127b <main+0x15b>
lea    0xd90(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"DUMMY\00"
@__const.main.good_argv = [2 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* null]
@__const.main.good_envp = [2 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* null]
@errno = global i64 0
@EFAULT = global i64 0
@.str.1 = [47 x i8] c"execve(invalid-path) correctly returned error\0A\00"
@.str.2 = [51 x i8] c"execve(invalid-argv-ptr) correctly returned error\0A\00"
@.str.3 = [51 x i8] c"execve(invalid-envp-ptr) correctly returned error\0A\00"
@.str.4 = [47 x i8] c"execve(invalid-argv) correctly returned error\0A\00"
@.str.5 = [47 x i8] c"execve(invalid-envp) correctly returned error\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i8*
%11 = alloca [2 x i8*]
%12 = alloca [2 x i8*]
%13 = alloca [2 x i8*]
%14 = alloca [2 x i8*]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i8** inttoptr (i64 -1 to i8**), i8*** %9
store i8* inttoptr (i64 -1 to i8*), i8** %10
%15 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 0
%16 = load i8*, i8** %10
store i8* %16, i8** %15
%17 = getelementptr inbounds i8*, i8** %15, i64 1
store i8* null, i8** %17
%18 = bitcast [2 x i8*]* %12 to i8*
%19 = getelementptr inbounds [2 x i8*], [2 x i8*]* %13, i64 0, i64 0
%20 = load i8*, i8** %10
store i8* %20, i8** %19
%21 = getelementptr inbounds i8*, i8** %19, i64 1
store i8* null, i8** %21
%22 = bitcast [2 x i8*]* %14 to i8*
%23 = load i8*, i8** %10
%24 = getelementptr inbounds [2 x i8*], [2 x i8*]* %12, i64 0, i64 0
%25 = getelementptr inbounds [2 x i8*], [2 x i8*]* %14, i64 0, i64 0
%26 = call i32 @execve(i8* %23, i8** %24, i8** %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %35
29: ; preds = %3
%30 = load i64, i64* @errno
%31 = load i64, i64* @EFAULT
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %29, %3
%36 = load i8**, i8*** %6
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = load i8**, i8*** %9
%40 = getelementptr inbounds [2 x i8*], [2 x i8*]* %14, i64 0, i64 0
%41 = call i32 @execve(i8* %38, i8** %39, i8** %40)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %50
44: ; preds = %35
%45 = load i64, i64* @errno
%46 = load i64, i64* @EFAULT
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0))
br label %50
50: ; preds = %48, %44, %35
%51 = load i8**, i8*** %6
%52 = getelementptr inbounds i8*, i8** %51, i64 0
%53 = load i8*, i8** %52
%54 = getelementptr inbounds [2 x i8*], [2 x i8*]* %12, i64 0, i64 0
%55 = load i8**, i8*** %9
%56 = call i32 @execve(i8* %53, i8** %54, i8** %55)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %65
59: ; preds = %50
%60 = load i64, i64* @errno
%61 = load i64, i64* @EFAULT
%62 = icmp eq i64 %60, %61
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0))
br label %65
65: ; preds = %63, %59, %50
%66 = load i8**, i8*** %6
%67 = getelementptr inbounds i8*, i8** %66, i64 0
%68 = load i8*, i8** %67
%69 = getelementptr inbounds [2 x i8*], [2 x i8*]* %11, i64 0, i64 0
%70 = getelementptr inbounds [2 x i8*], [2 x i8*]* %14, i64 0, i64 0
%71 = call i32 @execve(i8* %68, i8** %69, i8** %70)
store i32 %71, i32* %8
%72 = load i32, i32* %8
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %80
74: ; preds = %65
%75 = load i64, i64* @errno
%76 = load i64, i64* @EFAULT
%77 = icmp eq i64 %75, %76
br i1 %77, label %78, label %80
78: ; preds = %74
%79 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
br label %80
80: ; preds = %78, %74, %65
%81 = load i8**, i8*** %6
%82 = getelementptr inbounds i8*, i8** %81, i64 0
%83 = load i8*, i8** %82
%84 = getelementptr inbounds [2 x i8*], [2 x i8*]* %12, i64 0, i64 0
%85 = getelementptr inbounds [2 x i8*], [2 x i8*]* %13, i64 0, i64 0
%86 = call i32 @execve(i8* %83, i8** %84, i8** %85)
store i32 %86, i32* %8
%87 = load i32, i32* %8
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %95
89: ; preds = %80
%90 = load i64, i64* @errno
%91 = load i64, i64* @EFAULT
%92 = icmp eq i64 %90, %91
br i1 %92, label %93, label %95
93: ; preds = %89
%94 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0))
br label %95
95: ; preds = %93, %89, %80
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"DUMMY\00"
@__const.main.good_envp = [2 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* null]
@errno = global i64 0
@EFAULT = global i64 0
@str = [46 x i8] c"execve(invalid-envp) correctly returned error\00"
@str.6 = [46 x i8] c"execve(invalid-argv) correctly returned error\00"
@str.7 = [50 x i8] c"execve(invalid-envp-ptr) correctly returned error\00"
@str.8 = [50 x i8] c"execve(invalid-argv-ptr) correctly returned error\00"
@str.9 = [46 x i8] c"execve(invalid-path) correctly returned error\00"
define i32 @main(i32 %0, i8** nocapture %1, i8** nocapture readnone %2) {
%4 = alloca [2 x i8*]
%5 = alloca [2 x i8*]
%6 = alloca [2 x i8*]
%7 = alloca [2 x i8*]
%8 = bitcast [2 x i8*]* %4 to i8*
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 0
store i8* inttoptr (i64 -1 to i8*), i8** %9
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %4, i64 0, i64 1
store i8* null, i8** %10
%11 = bitcast [2 x i8*]* %5 to i8*
%12 = bitcast [2 x i8*]* %6 to i8*
%13 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
store i8* inttoptr (i64 -1 to i8*), i8** %13
%14 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 1
store i8* null, i8** %14
%15 = bitcast [2 x i8*]* %7 to i8*
%16 = getelementptr inbounds [2 x i8*], [2 x i8*]* %5, i64 0, i64 0
%17 = getelementptr inbounds [2 x i8*], [2 x i8*]* %7, i64 0, i64 0
%18 = call i32 @execve(i8* inttoptr (i64 -1 to i8*), i8** %16, i8** %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %3
%21 = load i64, i64* @errno
%22 = load i64, i64* @EFAULT
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.9, i64 0, i64 0))
br label %26
26: ; preds = %24, %20, %3
%27 = load i8*, i8** %1
%28 = call i32 @execve(i8* %27, i8** inttoptr (i64 -1 to i8**), i8** %17)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %36
30: ; preds = %26
%31 = load i64, i64* @errno
%32 = load i64, i64* @EFAULT
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %36
34: ; preds = %30
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.8, i64 0, i64 0))
br label %36
36: ; preds = %34, %30, %26
%37 = load i8*, i8** %1
%38 = call i32 @execve(i8* %37, i8** %16, i8** inttoptr (i64 -1 to i8**))
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %46
40: ; preds = %36
%41 = load i64, i64* @errno
%42 = load i64, i64* @EFAULT
%43 = icmp eq i64 %41, %42
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.7, i64 0, i64 0))
br label %46
46: ; preds = %44, %40, %36
%47 = load i8*, i8** %1
%48 = call i32 @execve(i8* %47, i8** %9, i8** %17)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %56
50: ; preds = %46
%51 = load i64, i64* @errno
%52 = load i64, i64* @EFAULT
%53 = icmp eq i64 %51, %52
br i1 %53, label %54, label %56
54: ; preds = %50
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.6, i64 0, i64 0))
br label %56
56: ; preds = %54, %50, %46
%57 = load i8*, i8** %1
%58 = call i32 @execve(i8* %57, i8** %16, i8** %13)
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %66
60: ; preds = %56
%61 = load i64, i64* @errno
%62 = load i64, i64* @EFAULT
%63 = icmp eq i64 %61, %62
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
br label %66
66: ; preds = %64, %60, %56
ret i32 0
}