#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 */
char EOF;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char ch;
  FILE *fp;
  fp = fopen("showme.txt", "r");
  if (fp == NULL) {
    printf("Could not open file\n");
    exit(EXIT_FAILURE);
  }
  while ((ch = fgetc(fp)) != EOF)
    printf("%c", ch);
  printf("\n");
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119d <main+0x4d>
lea    0xe85(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11a2 <main+0x52>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
mov    0x2e30(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11da <main+0x8a>
movsbl -0x5(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a2 <main+0x52>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11d1 <main+0x71>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    0x2e5a(%rip),%r14
cmp    (%r14),%al
je     11b5 <main+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%al
jne    11a0 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe35(%rip),%rdi
call   1040 <puts@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"showme.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"Could not open file\0A\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = call i32 @exit(i32 %9)
unreachable
11: ; preds = %0
br label %12
12: ; preds = %19, %11
%13 = load i32*, i32** %3
%14 = call signext i8 @fgetc(i32* %13)
store i8 %14, i8* %2
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %15, %17
br i1 %18, label %19, label %23
19: ; preds = %12
%20 = load i8, i8* %2
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %12
23: ; preds = %12
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"showme.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@EOF = global i8 0
@str = [20 x i8] c"Could not open file\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 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 signext i8 @fgetc(i32* %1)
%5 = load i8, i8* @EOF
%6 = icmp eq i8 %4, %5
br i1 %6, label %18, label %11
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3, %11
%12 = phi i8 [ %15, %11 ], [ %4, %3 ]
%13 = sext i8 %12 to i32
%14 = tail call i32 @putchar(i32 %13)
%15 = tail call signext i8 @fgetc(i32* %1)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %18, label %11
18: ; preds = %11, %3
%19 = tail call i32 @putchar(i32 10)
%20 = tail call i32 @fclose(i32* %1)
ret i32 0
}