#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__ EBADF;
scalar_t__ ENOENT;
int /*<<< orphan*/ __procfdname(char *, int);
scalar_t__ errno;
int /*<<< orphan*/ execve(char *, char *const *, char *const *);
int fexecve(int fd, char *const argv[], char *const envp[]) {
  char buf[15 + 3 * sizeof(int)];
  __procfdname(buf, fd);
  execve(buf, argv, envp);
  if (errno == ENOENT)
    errno = EBADF;
  return -1;
}


x86 assembly (clang, -O0):
<fexecve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1030 <__procfdname@plt>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <execve@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    117e <fexecve+0x5e>
mov    0x2e67(%rip),%rax
mov    (%rax),%rcx
mov    0x2e65(%rip),%rax
mov    %rcx,(%rax)
mov    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fexecve>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%esi
mov    %rsp,%r15
mov    %r15,%rdi
call   1030 <__procfdname@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <execve@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%rcx
mov    0x2e6d(%rip),%rdx
cmp    (%rdx),%rcx
jne    116d <fexecve+0x4d>
mov    0x2e71(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,(%rax)
mov    $0xffffffff,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ENOENT = global i64 0
@EBADF = global i64 0
define i32 @fexecve(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca [27 x i8]
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%8 = getelementptr inbounds [27 x i8], [27 x i8]* %7, i64 0, i64 0
%9 = load i32, i32* %4
%10 = call i32 @__procfdname(i8* %8, i32 %9)
%11 = getelementptr inbounds [27 x i8], [27 x i8]* %7, i64 0, i64 0
%12 = load i8**, i8*** %5
%13 = load i8**, i8*** %6
%14 = call i32 @execve(i8* %11, i8** %12, i8** %13)
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOENT
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = load i64, i64* @EBADF
store i64 %19, i64* @errno
br label %20
20: ; preds = %18, %3
ret i32 -1
}

LLVM IR (-O2):
@errno = global i64 0
@ENOENT = global i64 0
@EBADF = global i64 0
define i32 @fexecve(i32 %0, i8** %1, i8** %2) {
%4 = alloca [27 x i8]
%5 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%6 = call i32 @__procfdname(i8* %5, i32 %0)
%7 = call i32 @execve(i8* %5, i8** %1, i8** %2)
%8 = load i64, i64* @errno
%9 = load i64, i64* @ENOENT
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load i64, i64* @EBADF
store i64 %12, i64* @errno
br label %13
13: ; preds = %11, %3
ret i32 -1
}