#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/);
int reboot(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char *);
int /*<<< orphan*/ sync();
int syscall(int, int, int, scalar_t__, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int bzfd = -1;
  int initfd = -1;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s <bzImage> <initrd> <command line>\n", argv[0]);
    return 1;
  }
  if ((bzfd = open(argv[1], O_RDONLY)) == -1) {
    fprintf(stderr, "Cannot open %s: %s\n", argv[1], strerror(errno));
    return 2;
  }
  if ((initfd = open(argv[2], O_RDONLY)) == -1) {
    fprintf(stderr, "Cannot open %s: %s\n", argv[2], strerror(errno));
    return 2;
  }
  if (syscall(320, bzfd, initfd, strlen(argv[3]) + 1, argv[3], 0) == -1) {
    fprintf(stderr, "kexec_file_load failed: %s\n", strerror(errno));
    return 7;
  }
  close(initfd);
  close(bzfd);
  sync();
  if (reboot(0x45584543) == -1) {
    fprintf(stderr, "reboot failed: %s\n", strerror(errno));
    return 8;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11d8 <main+0x58>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1399 <main+0x219>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e01(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1244 <main+0xc4>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1399 <main+0x219>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d95(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    12b0 <main+0x130>
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %rax,%rcx
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1399 <main+0x219>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <strlen@plt>
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%edx
mov    %rax,%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%r8
mov    $0x140,%edi
xor    %r9d,%r9d
call   1060 <syscall@plt>
cmp    $0xffffffff,%eax
jne    132e <main+0x1ae>
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xd26(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x7,-0x4(%rbp)
jmp    1399 <main+0x219>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    $0x0,%al
call   1070 <sync@plt>
mov    $0x45584543,%edi
call   1090 <reboot@plt>
cmp    $0xffffffff,%eax
jne    1392 <main+0x212>
mov    0x2c79(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xcde(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x8,-0x4(%rbp)
jmp    1399 <main+0x219>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    1253 <main+0xd3>
mov    0x8(%rbx),%rdi
mov    0x2e4a(%rip),%r14
mov    (%r14),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1274 <main+0xf4>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
mov    (%r14),%esi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1283 <main+0x103>
mov    %eax,%r14d
mov    0x18(%rbx),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rcx
xor    %ebx,%ebx
mov    $0x140,%edi
mov    %ebp,%esi
mov    %r14d,%edx
mov    %r15,%r8
xor    %r9d,%r9d
call   1060 <syscall@plt>
cmp    $0xffffffff,%eax
je     12c6 <main+0x146>
mov    %r14d,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
call   1070 <sync@plt>
mov    $0x45584543,%edi
call   1090 <reboot@plt>
cmp    $0xffffffff,%eax
jne    12b9 <main+0x139>
mov    0x2daf(%rip),%rax
mov    (%rax),%ebx
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xe1d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x8,%ebx
jmp    12b9 <main+0x139>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd9a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%ebx
jmp    12b9 <main+0x139>
mov    0x2d5d(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
jmp    1290 <main+0x110>
mov    0x2d4e(%rip),%rax
mov    (%rax),%ebp
mov    0x10(%rbx),%rbx
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd88(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d0b(%rip),%rax
mov    (%rax),%ebx
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd5d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x7,%ebx
jmp    12b9 <main+0x139>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"Usage: %s <bzImage> <initrd> <command line>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Cannot open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [28 x i8] c"kexec_file_load failed: %s\0A\00"
@.str.3 = [19 x i8] c"reboot failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 4
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 1, i32* %3
br label %78
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i32, i32* @O_RDONLY
%21 = call i32 @open(i8* %19, i32 %20)
store i32 %21, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %31
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29)
store i32 2, i32* %3
br label %78
31: ; preds = %16
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* %34, i32 %35)
store i32 %36, i32* %7
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %46
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %42, i8* %44)
store i32 2, i32* %3
br label %78
46: ; preds = %31
%47 = load i32, i32* %6
%48 = load i32, i32* %7
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = call i64 @strlen(i8* %51)
%53 = add nsw i64 %52, 1
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = call i32 @syscall(i32 320, i32 %47, i32 %48, i64 %53, i8* %56, i32 0)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %64
59: ; preds = %46
%60 = load i32, i32* @stderr
%61 = load i32, i32* @errno
%62 = call i8* @strerror(i32 %61)
%63 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %62)
store i32 7, i32* %3
br label %78
64: ; preds = %46
%65 = load i32, i32* %7
%66 = call i32 @close(i32 %65)
%67 = load i32, i32* %6
%68 = call i32 @close(i32 %67)
%69 = call i32 (...) @sync()
%70 = call i32 @reboot(i32 1163412803)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %77
72: ; preds = %64
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %75)
store i32 8, i32* %3
br label %78
77: ; preds = %64
store i32 0, i32* %3
br label %78
78: ; preds = %77, %72, %59, %38, %23, %10
%79 = load i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"Usage: %s <bzImage> <initrd> <command line>\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [20 x i8] c"Cannot open %s: %s\0A\00"
@errno = global i32 0
@.str.2 = [28 x i8] c"kexec_file_load failed: %s\0A\00"
@.str.3 = [19 x i8] c"reboot failed: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %55
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* %10, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %9
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %18)
br label %55
20: ; preds = %8
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = tail call i32 @open(i8* %22, i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %21
%29 = load i32, i32* @errno
%30 = tail call i8* @strerror(i32 %29)
%31 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %30)
br label %55
32: ; preds = %20
%33 = getelementptr inbounds i8*, i8** %1, i64 3
%34 = load i8*, i8** %33
%35 = tail call i64 @strlen(i8* dereferenceable(1) %34)
%36 = add nsw i64 %35, 1
%37 = tail call i32 @syscall(i32 320, i32 %12, i32 %24, i64 %36, i8* %34, i32 0)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %44
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = tail call i8* @strerror(i32 %41)
%43 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %55
44: ; preds = %32
%45 = tail call i32 @close(i32 %24)
%46 = tail call i32 @close(i32 %12)
%47 = tail call i32 (...) @sync()
%48 = tail call i32 @reboot(i32 1163412803)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %55
50: ; preds = %44
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = tail call i8* @strerror(i32 %52)
%54 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %44, %50, %39, %26, %14, %4
%56 = phi i32 [ 1, %4 ], [ 2, %14 ], [ 2, %26 ], [ 7, %39 ], [ 8, %50 ], [ 0, %44 ]
ret i32 %56
}