#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*/ EXIT_FAILURE;
int /*<<< orphan*/ X_OK;
scalar_t__ access(char *, int /*<<< orphan*/);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *);
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
scalar_t__ switchroot(char *);
int /*<<< orphan*/ usage(int /*<<< orphan*/);
int /*<<< orphan*/ version();
int /*<<< orphan*/ warn(char *, char *);
int main(int argc, char *argv[]) {
  char *newroot, *init, **initargs;
  if (argv[1] && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h")))
    usage(stdout);
  if (argv[1] && (!strcmp(argv[1], "--version") || !strcmp(argv[1], "-V")))
    version();
  if (argc < 3)
    usage(stderr);
  newroot = argv[1];
  init = argv[2];
  initargs = &argv[2];
  if (!*newroot || !*init)
    usage(stderr);
  if (switchroot(newroot))
    errx(EXIT_FAILURE, "failed. Sorry.");
  if (access(init, X_OK))
    warn("cannot access %s", init);
  execv(init, initargs);
  err(EXIT_FAILURE, "failed to execute %s", init);
}


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    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11fd <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe3c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11ef <main+0x5f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe26(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11fd <main+0x6d>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     124d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdef(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     1246 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddc(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    124d <main+0xbd>
mov    $0x0,%al
call   1060 <version@plt>
cmpl   $0x3,-0x8(%rbp)
jge    1265 <main+0xd5>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     12a3 <main+0x113>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    12b1 <main+0x121>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <switchroot@plt>
cmp    $0x0,%rax
je     12d9 <main+0x149>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
lea    0xd43(%rip),%rsi
call   1040 <errx@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d04(%rip),%rax
mov    (%rax),%esi
call   1090 <access@plt>
cmp    $0x0,%rax
je     1305 <main+0x175>
mov    -0x20(%rbp),%rsi
lea    0xd26(%rip),%rdi
call   1030 <warn@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10b0 <execv@plt>
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd11(%rip),%rsi
call   1070 <err@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x8(%rsi),%rbp
test   %rbp,%rbp
je     1210 <main+0x80>
lea    0xe53(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11cc <main+0x3c>
lea    0xe47(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    11e3 <main+0x53>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
mov    0x8(%r15),%rbp
test   %rbp,%rbp
je     1210 <main+0x80>
lea    0xe20(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1209 <main+0x79>
lea    0xe17(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
jne    1210 <main+0x80>
xor    %eax,%eax
call   1060 <version@plt>
cmp    $0x2,%r14d
jg     1224 <main+0x94>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
mov    0x8(%r15),%rbx
mov    0x10(%r15),%rbp
cmpb   $0x0,(%rbx)
je     1237 <main+0xa7>
cmpb   $0x0,0x0(%rbp)
jne    1245 <main+0xb5>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1080 <usage@plt>
mov    %rbx,%rdi
call   10a0 <switchroot@plt>
test   %rax,%rax
je     1267 <main+0xd7>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
call   1040 <errx@plt>
add    $0x10,%r15
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1090 <access@plt>
test   %rax,%rax
je     1290 <main+0x100>
lea    0xd9e(%rip),%rdi
mov    %rbp,%rsi
call   1030 <warn@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10b0 <execv@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    0xd8c(%rip),%rsi
mov    %rbp,%rdx
call   1070 <err@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@stdout = global i32 0
@.str.2 = [10 x i8] c"--version\00"
@.str.3 = [3 x i8] c"-V\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [15 x i8] c"failed. Sorry.\00"
@X_OK = global i32 0
@.str.5 = [17 x i8] c"cannot access %s\00"
@.str.6 = [21 x i8] c"failed to execute %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %28
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @strcmp(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %19, %13
%26 = load i32, i32* @stdout
%27 = call i32 @usage(i32 %26)
br label %28
28: ; preds = %25, %19, %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %47
33: ; preds = %28
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32 @strcmp(i8* %36, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp ne i32 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %39, %33
%46 = call i32 (...) @version()
br label %47
47: ; preds = %45, %39, %28
%48 = load i32, i32* %4
%49 = icmp slt i32 %48, 3
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* @stderr
%52 = call i32 @usage(i32 %51)
br label %53
53: ; preds = %50, %47
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
store i8* %56, i8** %6
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 2
%59 = load i8*, i8** %58
store i8* %59, i8** %7
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 2
store i8** %61, i8*** %8
%62 = load i8*, i8** %6
%63 = load i8, i8* %62
%64 = icmp ne i8 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %53
%66 = load i8*, i8** %7
%67 = load i8, i8* %66
%68 = icmp ne i8 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %65, %53
%70 = load i32, i32* @stderr
%71 = call i32 @usage(i32 %70)
br label %72
72: ; preds = %69, %65
%73 = load i8*, i8** %6
%74 = call i64 @switchroot(i8* %73)
%75 = icmp ne i64 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %72
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @errx(i32 %77, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %79
79: ; preds = %76, %72
%80 = load i8*, i8** %7
%81 = load i32, i32* @X_OK
%82 = call i64 @access(i8* %80, i32 %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %79
%85 = load i8*, i8** %7
%86 = call i32 @warn(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %84, %79
%88 = load i8*, i8** %7
%89 = load i8**, i8*** %8
%90 = call i32 @execv(i8* %88, i8** %89)
%91 = load i32, i32* @EXIT_FAILURE
%92 = load i8*, i8** %7
%93 = call i32 @err(i32 %91, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %92)
%94 = load i32, i32* %3
ret i32 %94
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@stdout = global i32 0
@.str.2 = [10 x i8] c"--version\00"
@.str.3 = [3 x i8] c"-V\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.4 = [15 x i8] c"failed. Sorry.\00"
@X_OK = global i32 0
@.str.5 = [17 x i8] c"cannot access %s\00"
@.str.6 = [21 x i8] c"failed to execute %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %26, label %6
6: ; preds = %2
%7 = tail call i32 @strcmp(i8* %4, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = tail call i32 @strcmp(i8* %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %6, %9
%13 = load i32, i32* @stdout
%14 = tail call i32 @usage(i32 %13)
%15 = load i8*, i8** %3
%16 = icmp eq i8* %15, null
br i1 %16, label %26, label %17
17: ; preds = %9, %12
%18 = phi i8* [ %15, %12 ], [ %4, %9 ]
%19 = tail call i32 @strcmp(i8* %18, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = tail call i32 @strcmp(i8* %18, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %21, %17
%25 = tail call i32 (...) @version()
br label %26
26: ; preds = %2, %24, %21, %12
%27 = icmp slt i32 %0, 3
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = load i32, i32* @stderr
%30 = tail call i32 @usage(i32 %29)
br label %31
31: ; preds = %28, %26
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = load i8, i8* %32
%36 = icmp eq i8 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %31
%38 = load i8, i8* %34
%39 = icmp eq i8 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37, %31
%41 = load i32, i32* @stderr
%42 = tail call i32 @usage(i32 %41)
br label %43
43: ; preds = %40, %37
%44 = tail call i64 @switchroot(i8* %32)
%45 = icmp eq i64 %44, 0
br i1 %45, label %49, label %46
46: ; preds = %43
%47 = load i32, i32* @EXIT_FAILURE
%48 = tail call i32 @errx(i32 %47, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %49
49: ; preds = %46, %43
%50 = load i32, i32* @X_OK
%51 = tail call i64 @access(i8* %34, i32 %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %49
%54 = tail call i32 @warn(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* %34)
br label %55
55: ; preds = %53, %49
%56 = tail call i32 @execv(i8* %34, i8** %33)
%57 = load i32, i32* @EXIT_FAILURE
%58 = tail call i32 @err(i32 %57, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %34)
ret i32 0
}