#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*/ EPERM;
int /*<<< orphan*/ debug(char *);
int /*<<< orphan*/ errno;
scalar_t__ getenv(char *);
int sys_execve(char const *, char *const *, char *const *);
int execve(const char *filename, char *const argv[], char *const envp[]) {
  if (getenv("EXEC_ALLOWED")) {
    return sys_execve(filename, argv, envp);
  }
  debug("execve: ");
  errno = EPERM;
  return -1;
}


x86 assembly (clang, -O0):
<execve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    0xeb5(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1173 <execve+0x43>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <sys_execve@plt>
mov    %eax,-0x4(%rbp)
jmp    1198 <execve+0x68>
lea    0xe93(%rip),%rdi
call   1040 <debug@plt>
mov    0x2e4a(%rip),%rax
mov    (%rax),%ecx
mov    0x2e51(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execve>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xebb(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1162 <execve+0x32>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <sys_execve@plt>
lea    0xea4(%rip),%rdi
call   1040 <debug@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    0x2e62(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"EXEC_ALLOWED\00"
@.str.1 = [9 x i8] c"execve: \00"
@EPERM = global i32 0
@errno = global i32 0
define i32 @execve(i8* %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i8**
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%8 = call i64 @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %3
%11 = load i8*, i8** %5
%12 = load i8**, i8*** %6
%13 = load i8**, i8*** %7
%14 = call i32 @sys_execve(i8* %11, i8** %12, i8** %13)
store i32 %14, i32* %4
br label %18
15: ; preds = %3
%16 = call i32 @debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @EPERM
store i32 %17, i32* @errno
store i32 -1, i32* %4
br label %18
18: ; preds = %15, %10
%19 = load i32, i32* %4
ret i32 %19
}

LLVM IR (-O2):
@.str = [13 x i8] c"EXEC_ALLOWED\00"
@.str.1 = [9 x i8] c"execve: \00"
@EPERM = global i32 0
@errno = global i32 0
define i32 @execve(i8* %0, i8** %1, i8** %2) {
%4 = tail call i64 @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @sys_execve(i8* %0, i8** %1, i8** %2)
br label %11
8: ; preds = %3
%9 = tail call i32 @debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @EPERM
store i32 %10, i32* @errno
br label %11
11: ; preds = %8, %6
%12 = phi i32 [ %7, %6 ], [ -1, %8 ]
ret i32 %12
}