#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *bfile;
  int ch;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <file>\n", argv[0]);
    return EXIT_FAILURE;
  }
  bfile = fopen(argv[1], "rb");
  if (!bfile) {
    fprintf(stderr, "Could not open `%s'.\n", argv[1]);
    return EXIT_FAILURE;
  }
  while ((ch = fgetc(bfile)) != EOF)
    printf("%02x \n", ch);
  if (ferror(bfile)) {
    fprintf(stderr, "Error reading from `%s'.\n", argv[1]);
    return EXIT_FAILURE;
  }
  fclose(bfile);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ad <main+0x4d>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe69(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1288 <main+0x128>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe56(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fe <main+0x9e>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe2d(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1288 <main+0x128>
jmp    1203 <main+0xa3>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dd2(%rip),%rcx
cmp    (%rcx),%eax
je     1232 <main+0xd2>
mov    -0x1c(%rbp),%esi
lea    0xe03(%rip),%rdi
call   1050 <printf@plt>
jmp    1203 <main+0xa3>
mov    -0x18(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1273 <main+0x113>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdd5(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1288 <main+0x128>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11eb <main+0x8b>
mov    0x8(%r14),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1200 <main+0xa0>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e51(%rip),%r12
cmp    (%r12),%eax
je     11c8 <main+0x68>
lea    0xe87(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r12),%eax
jne    11b0 <main+0x50>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     122e <main+0xce>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe49(%rip),%rsi
jmp    1214 <main+0xb4>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe02(%rip),%rsi
jmp    1214 <main+0xb4>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe01(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2d8b(%rip),%rax
jmp    1220 <main+0xc0>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"Could not open `%s'.\0A\00"
@EOF = global i32 0
@.str.3 = [7 x i8] c"%02x \0A\00"
@.str.4 = [26 x i8] c"Error reading from `%s'.\0A\00"
@EXIT_SUCCESS = global i32 0
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
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %17
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 @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
store i32 %16, i32* %3
br label %55
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %21, i32** %6
%22 = load i32*, i32** %6
%23 = icmp ne i32* %22, null
br i1 %23, label %31, label %24
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %55
31: ; preds = %17
br label %32
32: ; preds = %37, %31
%33 = load i32*, i32** %6
%34 = call i32 @fgetc(i32* %33)
store i32 %34, i32* %7
%35 = load i32, i32* @EOF
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %32
%38 = load i32, i32* %7
%39 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %38)
br label %32
40: ; preds = %32
%41 = load i32*, i32** %6
%42 = call i64 @ferror(i32* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = load i32, i32* @EXIT_FAILURE
store i32 %50, i32* %3
br label %55
51: ; preds = %40
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
%54 = load i32, i32* @EXIT_SUCCESS
store i32 %54, i32* %3
br label %55
55: ; preds = %51, %44, %24, %10
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [22 x i8] c"Could not open `%s'.\0A\00"
@EOF = global i32 0
@.str.3 = [7 x i8] c"%02x \0A\00"
@.str.4 = [26 x i8] c"Error reading from `%s'.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %36
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %17, label %13
13: ; preds = %8
%14 = tail call i32 @fgetc(i32* %11)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %27, label %21
17: ; preds = %8
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %9
%20 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %36
21: ; preds = %13, %21
%22 = phi i32 [ %24, %21 ], [ %14, %13 ]
%23 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = tail call i32 @fgetc(i32* %11)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %21
27: ; preds = %21, %13
%28 = tail call i64 @ferror(i32* %11)
%29 = icmp eq i64 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %9
%33 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %32)
br label %36
34: ; preds = %27
%35 = tail call i32 @fclose(i32* %11)
br label %36
36: ; preds = %34, %30, %17, %4
%37 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %30 ], [ @EXIT_SUCCESS, %34 ], [ @EXIT_FAILURE, %17 ]
%38 = load i32, i32* %37
ret i32 %38
}