#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 **);
int /*<<< orphan*/ perror(char *);
void exec_init(char **argv, char **envp) {
  char *const init_name = "init";
  char *const sh_name = "sh";
  argv[0] = init_name;
  execve("/sbin/init", argv, envp);
  execve("/etc/init", argv, envp);
  execve("/bin/init", argv, envp);
  argv[0] = sh_name;
  execve("/bin/sh", argv, envp);
  perror("unable to exec init");
}


x86 assembly (clang, -O0):
<exec_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeff(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xee2(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
lea    0xee5(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe9d(%rip),%rdi
call   1030 <execve@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe94(%rip),%rdi
call   1030 <execve@plt>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe8a(%rip),%rdi
call   1030 <execve@plt>
mov    -0x8(%rbp),%rax
lea    0xe89(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe72(%rip),%rdi
call   1030 <execve@plt>
lea    0xe6e(%rip),%rdi
call   1040 <perror@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exec_init>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xf05(%rip),%rax
mov    %rax,(%rdi)
lea    0xec5(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <execve@plt>
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <execve@plt>
lea    0xeb6(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <execve@plt>
lea    0xeb3(%rip),%rax
mov    %rax,(%rbx)
lea    0xea4(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <execve@plt>
lea    0xe9a(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <perror@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"init\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [11 x i8] c"/sbin/init\00"
@.str.3 = [10 x i8] c"/etc/init\00"
@.str.4 = [10 x i8] c"/bin/init\00"
@.str.5 = [8 x i8] c"/bin/sh\00"
@.str.6 = [20 x i8] c"unable to exec init\00"
define void @exec_init(i8** %0, i8** %1) {
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %0
%3 = tail call i32 @execve(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %0, i8** %1)
%4 = tail call i32 @execve(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %0, i8** %1)
%5 = tail call i32 @execve(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8** %0, i8** %1)
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %0
%6 = tail call i32 @execve(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %0, i8** %1)
%7 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
ret void
}