#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 execve(char *, char **, char **);
int /*<<< orphan*/ printf(char *);
int main() {
  char *argv[2];
  char *envp[1];
  argv[0] = "date";
  argv[1] = NULL;
  envp[0] = NULL;
  if (-1 == execve("/usr/bin/date", argv, envp))
    printf("execve() failed.\n");
  printf("We should not be here.\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xed3(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    0xea7(%rip),%rdi
call   1040 <execve@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1179 <main+0x59>
lea    0xe9a(%rip),%rdi
call   1030 <printf@plt>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0xede(%rip),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xeb7(%rip),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1040 <execve@plt>
cmp    $0xffffffff,%eax
jne    1169 <main+0x49>
lea    0xec1(%rip),%rdi
call   1030 <puts@plt>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"date\00"
@.str.1 = [14 x i8] c"/usr/bin/date\00"
@.str.2 = [18 x i8] c"execve() failed.\0A\00"
@.str.3 = [24 x i8] c"We should not be here.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i8*]
%3 = alloca [1 x i8*]
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 1
store i8* null, i8** %5
%6 = getelementptr inbounds [1 x i8*], [1 x i8*]* %3, i64 0, i64 0
store i8* null, i8** %6
%7 = getelementptr inbounds [2 x i8*], [2 x i8*]* %2, i64 0, i64 0
%8 = getelementptr inbounds [1 x i8*], [1 x i8*]* %3, i64 0, i64 0
%9 = call i32 @execve(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %7, i8** %8)
%10 = icmp eq i32 -1, %9
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
%14 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@.str = [5 x i8] c"date\00"
@.str.1 = [14 x i8] c"/usr/bin/date\00"
@str = [23 x i8] c"We should not be here.\00"
@str.4 = [17 x i8] c"execve() failed.\00"
define i32 @main() {
%1 = alloca [2 x i8*]
%2 = alloca [1 x i8*]
%3 = bitcast [2 x i8*]* %1 to i8*
%4 = bitcast [1 x i8*]* %2 to i8*
%5 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [2 x i8*], [2 x i8*]* %1, i64 0, i64 1
store i8* null, i8** %6
%7 = getelementptr inbounds [1 x i8*], [1 x i8*]* %2, i64 0, i64 0
store i8* null, i8** %7
%8 = call i32 @execve(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %5, i8** %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
ret i32 0
}