#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char, char, char, char, char);
int /*<<< orphan*/ stderr;
int main(void) {
  char buffer[5] = {0};
  int i;
  FILE *fp = fopen("myfile", "rb");
  if (fp == NULL) {
    perror("Failed to open file \"myfile\"");
    return EXIT_FAILURE;
  }
  for (i = 0; i < 5; i++) {
    int rc = getc(fp);
    if (rc == EOF) {
      fputs("An error occured while reading the file. \n", stderr);
      return EXIT_FAILURE;
    }
    buffer[i] = rc;
  }
  fclose(fp);
  printf("The bytes read were... %x%x%x%x\n", buffer[0], buffer[1], buffer[2],
         buffer[3], buffer[4]);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x9(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1060 <memset@plt>
lea    0xe6a(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ce <main+0x5e>
lea    0xe52(%rip),%rdi
call   1080 <perror@plt>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127f <main+0x10f>
movl   $0x0,-0x10(%rbp)
cmpl   $0x5,-0x10(%rbp)
jge    123e <main+0xce>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2df3(%rip),%rcx
cmp    (%rcx),%eax
jne    1223 <main+0xb3>
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127f <main+0x10f>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
movslq -0x10(%rbp),%rax
mov    %cl,-0x9(%rbp,%rax,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11d5 <main+0x65>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x9(%rbp),%sil
mov    -0x8(%rbp),%dl
mov    -0x7(%rbp),%cl
mov    -0x6(%rbp),%al
lea    0xdf7(%rip),%rdi
movsbl %sil,%esi
movsbl %dl,%edx
movsbl %cl,%ecx
movsbl %al,%r8d
movsbl -0x5(%rbp),%r9d
call   1040 <printf@plt>
mov    0x2d4e(%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   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8e(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     120f <main+0xaf>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <getc@plt>
mov    0x2e4f(%rip),%r13
cmp    0x0(%r13),%eax
je     11e2 <main+0x82>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    0x0(%r13),%eax
je     11e2 <main+0x82>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    0x0(%r13),%eax
je     11e2 <main+0x82>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    0x0(%r13),%eax
je     11e2 <main+0x82>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    0x0(%r13),%eax
jne    121d <main+0xbd>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    0xe35(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf4(%rip),%rdi
call   1070 <perror@plt>
jmp    11f7 <main+0x97>
mov    %rbx,%rdi
mov    %eax,%ebx
call   1030 <fclose@plt>
movsbl %bpl,%esi
movsbl %r14b,%edx
movsbl %r15b,%ecx
movsbl %r12b,%r8d
movsbl %bl,%r9d
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
mov    0x2d7a(%rip),%rax
jmp    11fe <main+0x9e>

LLVM IR (-O0):
@.str = [7 x i8] c"myfile\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [29 x i8] c"Failed to open file \22myfile\22\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@.str.3 = [43 x i8] c"An error occured while reading the file. \0A\00"
@stderr = global i32 0
@.str.4 = [33 x i8] c"The bytes read were... %x%x%x%x\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [5 x i8]
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [5 x i8]* %2 to i8*
%7 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %1
br label %51
13: ; preds = %0
store i32 0, i32* %3
br label %14
14: ; preds = %33, %13
%15 = load i32, i32* %3
%16 = icmp slt i32 %15, 5
br i1 %16, label %17, label %36
17: ; preds = %14
%18 = load i32*, i32** %4
%19 = call i32 @getc(i32* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load i32, i32* @EOF
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = call i32 @fputs(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %1
br label %51
27: ; preds = %17
%28 = load i32, i32* %5
%29 = trunc i32 %28 to i8
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 %31
store i8 %29, i8* %32
br label %33
33: ; preds = %27
%34 = load i32, i32* %3
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
br label %14
36: ; preds = %14
%37 = load i32*, i32** %4
%38 = call i32 @fclose(i32* %37)
%39 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%40 = load i8, i8* %39
%41 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 1
%42 = load i8, i8* %41
%43 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 2
%44 = load i8, i8* %43
%45 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 3
%46 = load i8, i8* %45
%47 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
%48 = load i8, i8* %47
%49 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8 signext %40, i8 signext %42, i8 signext %44, i8 signext %46, i8 signext %48)
%50 = load i32, i32* @EXIT_SUCCESS
store i32 %50, i32* %1
br label %51
51: ; preds = %36, %23, %10
%52 = load i32, i32* %1
ret i32 %52
}

LLVM IR (-O2):
@.str = [7 x i8] c"myfile\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [29 x i8] c"Failed to open file \22myfile\22\00"
@EXIT_FAILURE = global i32 0
@EOF = global i32 0
@.str.3 = [43 x i8] c"An error occured while reading the file. \0A\00"
@stderr = global i32 0
@.str.4 = [33 x i8] c"The bytes read were... %x%x%x%x\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call i32 @getc(i32* %1)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %9, label %12
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %36
9: ; preds = %27, %22, %17, %12, %3
%10 = load i32, i32* @stderr
%11 = tail call i32 @fputs(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %10)
br label %36
12: ; preds = %3
%13 = trunc i32 %4 to i8
%14 = tail call i32 @getc(i32* %1)
%15 = load i32, i32* @EOF
%16 = icmp eq i32 %14, %15
br i1 %16, label %9, label %17
17: ; preds = %12
%18 = trunc i32 %14 to i8
%19 = tail call i32 @getc(i32* %1)
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %9, label %22
22: ; preds = %17
%23 = trunc i32 %19 to i8
%24 = tail call i32 @getc(i32* %1)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %9, label %27
27: ; preds = %22
%28 = tail call i32 @getc(i32* %1)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %9, label %31
31: ; preds = %27
%32 = trunc i32 %24 to i8
%33 = trunc i32 %28 to i8
%34 = tail call i32 @fclose(i32* %1)
%35 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8 signext %13, i8 signext %18, i8 signext %23, i8 signext %32, i8 signext %33)
br label %36
36: ; preds = %9, %31, %7
%37 = phi i32* [ @EXIT_FAILURE, %7 ], [ @EXIT_SUCCESS, %31 ], [ @EXIT_FAILURE, %9 ]
%38 = load i32, i32* %37
ret i32 %38
}