#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ putchar(int);
void printVersion(void) {
  FILE *fp;
  int c;
  fp = fopen("./version", "r");
  if (fp != NULL) {
    while ((c = fgetc(fp)) != EOF)
      putchar(c);
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<printVersion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb4(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a0 <printVersion+0x60>
jmp    116f <printVersion+0x2f>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%eax
je     1197 <printVersion+0x57>
mov    -0xc(%rbp),%edi
call   1030 <putchar@plt>
jmp    116f <printVersion+0x2f>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printVersion>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11a3 <printVersion+0x63>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e7a(%rip),%r14
cmp    (%r14),%eax
je     1194 <printVersion+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%eax
jne    1180 <printVersion+0x40>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [10 x i8] c"./version\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define void @printVersion() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %18
6: ; preds = %0
br label %7
7: ; preds = %12, %6
%8 = load i32*, i32** %1
%9 = call i32 @fgetc(i32* %8)
store i32 %9, i32* %2
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i32, i32* %2
%14 = call i32 @putchar(i32 %13)
br label %7
15: ; preds = %7
%16 = load i32*, i32** %1
%17 = call i32 @fclose(i32* %16)
br label %18
18: ; preds = %15, %0
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"./version\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define void @printVersion() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 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 %15, label %3
3: ; preds = %0
%4 = tail call i32 @fgetc(i32* %1)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %13, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %10, %7 ], [ %4, %3 ]
%9 = tail call i32 @putchar(i32 %8)
%10 = tail call i32 @fgetc(i32* %1)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %7
13: ; preds = %7, %3
%14 = tail call i32 @fclose(i32* %1)
br label %15
15: ; preds = %13, %0
ret void
}