#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*/ execve(char *, char **, char *const *);
int /*<<< orphan*/ perror(char *);
int main(const int argc, const char *const argv[], char *const envp[]) {
  char *a[3];
  a[0] = ("/bin/sh");
  a[1] = ("/sbin/pinit");
  a[2] = NULL;
  execve(("/bin/busybox"), a, envp);
  perror(("/bin/busybox"));
  a[1] = ("/bin/sh");
  execve(("/bin/busybox"), a, envp);
  perror(("/bin/busybox"));
  a[0] = ("/bin/sh");
  execve(("/bin/sh"), a, envp);
  perror(("/bin/sh"));
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xebf(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xebc(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xead(%rip),%rdi
call   1030 <execve@plt>
lea    0xea1(%rip),%rdi
call   1040 <perror@plt>
lea    0xe81(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe82(%rip),%rdi
call   1030 <execve@plt>
lea    0xe76(%rip),%rdi
call   1040 <perror@plt>
lea    0xe56(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe43(%rip),%rdi
call   1030 <execve@plt>
lea    0xe37(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
lea    0xecb(%rip),%r14
mov    %r14,(%rsp)
lea    0xec8(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xebf(%rip),%r15
mov    %rsp,%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <execve@plt>
mov    %r15,%rdi
call   1040 <perror@plt>
mov    %r14,0x8(%rsp)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <execve@plt>
mov    %r15,%rdi
call   1040 <perror@plt>
mov    %r14,(%rsp)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1030 <execve@plt>
mov    %r14,%rdi
call   1040 <perror@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [12 x i8] c"/sbin/pinit\00"
@.str.2 = [13 x i8] c"/bin/busybox\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [3 x i8*]
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %10
%11 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 2
store i8* null, i8** %11
%12 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%13 = load i8**, i8*** %7
%14 = call i32 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %12, i8** %13)
%15 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%18 = load i8**, i8*** %7
%19 = call i32 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %17, i8** %18)
%20 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds [3 x i8*], [3 x i8*]* %8, i64 0, i64 0
%23 = load i8**, i8*** %7
%24 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %22, i8** %23)
%25 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
ret i32 1
}

LLVM IR (-O2):
@.str = [8 x i8] c"/bin/sh\00"
@.str.1 = [12 x i8] c"/sbin/pinit\00"
@.str.2 = [13 x i8] c"/bin/busybox\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** %2) {
%4 = alloca [3 x i8*]
%5 = bitcast [3 x i8*]* %4 to i8*
%6 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 2
store i8* null, i8** %8
%9 = call i32 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %6, i8** %2)
%10 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %7
%11 = call i32 @execve(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8** %6, i8** %2)
%12 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6
%13 = call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6, i8** %2)
%14 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
ret i32 1
}