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

/* Variables and functions */
int EOF;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
int main(int argc, char *argv[]) {
  u_char byte;
  int retval;
  FILE *file;
  if (argc < 2) {
    fprintf(stderr, "Error - No filename given.\n");
    exit(1);
  }
  if ((file = fopen(argv[1], "r")) == NULL) {
    fprintf(stderr, "Error - Unable to open file: %s.\n", strerror(errno));
    exit(1);
  }
  errno = 0;
  while ((retval = fscanf(file, "%c", &byte)) > 0)
    fprintf(stdout, "\\x%02x", byte);
  if ((retval = EOF) && errno)
    fprintf(stderr, "Error - Unable to read from file: %s.\n", strerror(errno));
  fclose(file);
  return (0);
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11a1 <main+0x41>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11fc <main+0x9c>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2dcd(%rip),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    0xe2b(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <fscanf@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    1249 <main+0xe9>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    120a <main+0xaa>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     129e <main+0x13e>
mov    0x2d6b(%rip),%rax
cmpq   $0x0,(%rax)
je     129e <main+0x13e>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d4e(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1252 <main+0xf2>
mov    0x8(%rsi),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1273 <main+0x113>
mov    %rax,%rbx
mov    0x2e39(%rip),%r13
movq   $0x0,0x0(%r13)
lea    0xe9a(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
test   %eax,%eax
jle    1203 <main+0xa3>
mov    0x2e0a(%rip),%rbp
lea    0xe7e(%rip),%r14
lea    0xe74(%rip),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
mov    0x4(%rsp),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
test   %eax,%eax
jg     11e0 <main+0x80>
mov    0x2dde(%rip),%rax
cmpl   $0x0,(%rax)
je     1239 <main+0xd9>
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     1239 <main+0xd9>
mov    0x2db9(%rip),%rax
mov    (%rax),%ebp
call   1080 <strerror@plt>
lea    0xe1d(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d4d(%rip),%rax
mov    (%rax),%rdi
call   1080 <strerror@plt>
lea    0xd8c(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"Error - No filename given.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Error - Unable to open file: %s.\0A\00"
@errno = global i64 0
@.str.3 = [3 x i8] c"%c\00"
@stdout = global i32 0
@.str.4 = [7 x i8] c"\\x%02x\00"
@EOF = global i32 0
@.str.5 = [39 x i8] c"Error - Unable to read from file: %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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %8
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i64, i64* @errno
%24 = call i8* @strerror(i64 %23)
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %15
store i64 0, i64* @errno
br label %28
28: ; preds = %32, %27
%29 = load i32*, i32** %8
%30 = call i32 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
store i32 %30, i32* %7
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i32, i32* @stdout
%34 = load i32, i32* %6
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %34)
br label %28
36: ; preds = %28
%37 = load i32, i32* @EOF
store i32 %37, i32* %7
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = load i64, i64* @errno
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i32, i32* @stderr
%44 = load i64, i64* @errno
%45 = call i8* @strerror(i64 %44)
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %42, %39, %36
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"Error - No filename given.\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [34 x i8] c"Error - Unable to open file: %s.\0A\00"
@errno = global i64 0
@.str.3 = [3 x i8] c"%c\00"
@stdout = global i32 0
@.str.4 = [7 x i8] c"\\x%02x\00"
@EOF = global i32 0
@.str.5 = [39 x i8] c"Error - Unable to read from file: %s.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i64, i64* @errno
%18 = tail call i8* @strerror(i64 %17)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %10
store i64 0, i64* @errno
%22 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21, %24
%25 = load i32, i32* @stdout
%26 = load i32, i32* %3
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%29 = icmp sgt i32 %28, 0
br i1 %29, label %24, label %30
30: ; preds = %24, %21
%31 = load i32, i32* @EOF
%32 = icmp ne i32 %31, 0
%33 = load i64, i64* @errno
%34 = icmp ne i64 %33, 0
%35 = select i1 %32, i1 %34, i1 false
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load i32, i32* @stderr
%38 = call i8* @strerror(i64 %33)
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %36, %30
%41 = call i32 @fclose(i32* %13)
ret i32 0
}