#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*/ STDERR_FILENO;
int /*<<< orphan*/ errno;
int execve(char const *, char *const *, char *const *);
int my_strlen(char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ xwrite(int /*<<< orphan*/, char *, int);
int xexecve(const char *filename, char *const argv[], char *const envp[]) {
  int ret;
  char *err;
  ret = execve(filename, argv, envp);
  if (ret == -1) {
    err = strerror(errno);
    xwrite(STDERR_FILENO, "execve failed: ", sizeof("execve failed: "));
    xwrite(STDERR_FILENO, err, my_strlen(err));
    xwrite(STDERR_FILENO, "\n", 1);
  }
  return (ret);
}


x86 assembly (clang, -O0):
<xexecve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <execve@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e3 <xexecve+0xa3>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    $0x10,%edx
call   1040 <xwrite@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <xwrite@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%rip),%rsi
mov    $0x1,%edx
call   1040 <xwrite@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xexecve>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1050 <execve@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11aa <xexecve+0x6a>
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%r14
mov    0x2e6d(%rip),%r15
mov    (%r15),%edi
lea    0xe8b(%rip),%rsi
mov    $0x10,%edx
call   1040 <xwrite@plt>
mov    (%r15),%ebp
mov    %r14,%rdi
call   1030 <my_strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <xwrite@plt>
mov    (%r15),%edi
lea    0xe70(%rip),%rsi
mov    $0x1,%edx
call   1040 <xwrite@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@STDERR_FILENO = global i32 0
@.str = [16 x i8] c"execve failed: \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @xexecve(i8* %0, i8** %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%9 = load i8*, i8** %4
%10 = load i8**, i8*** %5
%11 = load i8**, i8*** %6
%12 = call i32 @execve(i8* %9, i8** %10, i8** %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %27
15: ; preds = %3
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
store i8* %17, i8** %8
%18 = load i32, i32* @STDERR_FILENO
%19 = call i32 @xwrite(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 16)
%20 = load i32, i32* @STDERR_FILENO
%21 = load i8*, i8** %8
%22 = load i8*, i8** %8
%23 = call i32 @my_strlen(i8* %22)
%24 = call i32 @xwrite(i32 %20, i8* %21, i32 %23)
%25 = load i32, i32* @STDERR_FILENO
%26 = call i32 @xwrite(i32 %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %27
27: ; preds = %15, %3
%28 = load i32, i32* %7
ret i32 %28
}

LLVM IR (-O2):
@errno = global i32 0
@STDERR_FILENO = global i32 0
@.str = [16 x i8] c"execve failed: \00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @xexecve(i8* %0, i8** %1, i8** %2) {
%4 = tail call i32 @execve(i8* %0, i8** %1, i8** %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = load i32, i32* @STDERR_FILENO
%10 = tail call i32 @xwrite(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 16)
%11 = load i32, i32* @STDERR_FILENO
%12 = tail call i32 @my_strlen(i8* %8)
%13 = tail call i32 @xwrite(i32 %11, i8* %8, i32 %12)
%14 = load i32, i32* @STDERR_FILENO
%15 = tail call i32 @xwrite(i32 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %16
16: ; preds = %6, %3
ret i32 %4
}