#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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ out_boot(unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, unsigned char *, int);
int main(int argc, char *argv[]) {
  int i, h1;
  unsigned char c[512];
  if (argc != 2) {
    printf("usage: analyzeboot source-bootfile\n");
    return 1;
  }
  for (i = 0; i < 256; i++)
    c[i] = 0;
  if ((h1 = open(argv[1], 0)) <= 0) {
    printf("can't open %s\n", argv[1]);
    return 2;
  }
  if (read(h1, c, 512) == 0) {
    printf("can't read %s\n", argv[1]);
    return 3;
  }
  out_boot(c);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     117d <main+0x3d>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123b <main+0xfb>
movl   $0x0,-0x14(%rbp)
cmpl   $0x100,-0x14(%rbp)
jge    11ab <main+0x6b>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x220(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1184 <main+0x44>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jg     11e8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    123b <main+0xfb>
mov    -0x18(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jne    1228 <main+0xe8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    123b <main+0xfb>
lea    -0x220(%rbp),%rdi
call   1050 <out_boot@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x200,%rsp
cmp    $0x2,%edi
jne    11fd <main+0xad>
mov    %rsi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    0x8(%rsi),%rdi
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
jle    1210 <main+0xc0>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x200,%edx
call   1050 <read@plt>
test   %rax,%rax
je     1229 <main+0xd9>
mov    %rsp,%rdi
call   1060 <out_boot@plt>
xor    %eax,%eax
jmp    1240 <main+0xf0>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    1240 <main+0xf0>
mov    0x8(%rbx),%rsi
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x2,%eax
jmp    1240 <main+0xf0>
mov    0x8(%rbx),%rsi
lea    0xddb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3,%eax
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"usage: analyzeboot source-bootfile\0A\00"
@.str.1 = [15 x i8] c"can't open %s\0A\00"
@.str.2 = [15 x i8] c"can't read %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
%8 = alloca [512 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %48
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %21, %13
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 256
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %6
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %17
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %14
24: ; preds = %14
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @open(i8* %27, i32 0)
store i32 %28, i32* %7
%29 = icmp sle i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %24
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %33)
store i32 2, i32* %3
br label %48
35: ; preds = %24
%36 = load i32, i32* %7
%37 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%38 = call i64 @read(i32 %36, i8* %37, i32 512)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %43)
store i32 3, i32* %3
br label %48
45: ; preds = %35
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%47 = call i32 @out_boot(i8* %46)
store i32 0, i32* %3
br label %48
48: ; preds = %45, %40, %30, %11
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str.1 = [15 x i8] c"can't open %s\0A\00"
@.str.2 = [15 x i8] c"can't read %s\0A\00"
@str = [35 x i8] c"usage: analyzeboot source-bootfile\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @open(i8* %9, i32 0)
%11 = icmp slt i32 %10, 1
br i1 %11, label %14, label %17
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %25
14: ; preds = %6
%15 = load i8*, i8** %8
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %25
17: ; preds = %6
%18 = call i64 @read(i32 %10, i8* %4, i32 512)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i8*, i8** %8
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %25
23: ; preds = %17
%24 = call i32 @out_boot(i8* %4)
br label %25
25: ; preds = %23, %20, %14, %12
%26 = phi i32 [ 1, %12 ], [ 2, %14 ], [ 3, %20 ], [ 0, %23 ]
ret i32 %26
}