#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*/ errmsg(int, int /*<<< orphan*/, int, 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 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))
    errmsg(1, EXIT_FAILURE, 0, "failed. Sorry.");
  if (access(init, X_OK))
    errmsg(0, 0, 1, "cannot access %s", init);
  execv(init, initargs);
  errmsg(1, EXIT_FAILURE, 1, "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     11dd <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5c(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
je     11cf <main+0x5f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe46(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    11dd <main+0x6d>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1060 <usage@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     122d <main+0xbd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0f(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
je     1226 <main+0xb6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdfc(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    122d <main+0xbd>
mov    $0x0,%al
call   1040 <version@plt>
cmpl   $0x3,-0x8(%rbp)
jge    1245 <main+0xd5>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1060 <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     1283 <main+0x113>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1291 <main+0x121>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
call   1060 <usage@plt>
mov    -0x18(%rbp),%rdi
call   1080 <switchroot@plt>
cmp    $0x0,%rax
je     12c2 <main+0x152>
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
xor    %edx,%edx
lea    0xd5c(%rip),%rcx
mov    $0x0,%al
call   1050 <errmsg@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0x0,%rax
je     12f9 <main+0x189>
mov    -0x20(%rbp),%r8
xor    %esi,%esi
mov    $0x1,%edx
lea    0xd36(%rip),%rcx
mov    %esi,%edi
mov    $0x0,%al
call   1050 <errmsg@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1090 <execv@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%r8
mov    $0x1,%edx
lea    0xd18(%rip),%rcx
mov    %edx,%edi
mov    $0x0,%al
call   1050 <errmsg@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x8(%rsi),%rbx
test   %rbx,%rbx
je     11ec <main+0x7c>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11a8 <main+0x38>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    11bf <main+0x4f>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1060 <usage@plt>
mov    0x8(%r14),%rbx
test   %rbx,%rbx
je     11ec <main+0x7c>
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
je     11e5 <main+0x75>
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    11ec <main+0x7c>
xor    %eax,%eax
call   1040 <version@plt>
cmp    $0x2,%ebp
jg     11ff <main+0x8f>
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1060 <usage@plt>
mov    0x8(%r14),%rbp
mov    0x10(%r14),%rbx
cmpb   $0x0,0x0(%rbp)
je     1212 <main+0xa2>
cmpb   $0x0,(%rbx)
jne    1220 <main+0xb0>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
call   1060 <usage@plt>
mov    %rbp,%rdi
call   1080 <switchroot@plt>
test   %rax,%rax
je     124b <main+0xdb>
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
lea    0xdda(%rip),%rcx
mov    $0x1,%edi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <errmsg@plt>
add    $0x10,%r14
mov    0x2d92(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <access@plt>
test   %rax,%rax
je     127f <main+0x10f>
lea    0xdba(%rip),%rcx
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <errmsg@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <execv@plt>
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
lea    0xd9d(%rip),%rcx
mov    $0x1,%edi
mov    $0x1,%edx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <errmsg@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
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 (i32, i32, i32, i8*, ...) @errmsg(i32 1, i32 %77, i32 0, 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 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, 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 (i32, i32, i32, i8*, ...) @errmsg(i32 1, i32 %91, i32 1, 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 (i32, i32, i32, i8*, ...) @errmsg(i32 1, i32 %47, i32 0, 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 (i32, i32, i32, i8*, ...) @errmsg(i32 0, i32 0, i32 1, 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 (i32, i32, i32, i8*, ...) @errmsg(i32 1, i32 %57, i32 1, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i8* %34)
ret i32 0
}