#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*/ printf(char *);
int /*<<< orphan*/ rgb_store(int);
int /*<<< orphan*/ *stdin;
void ReadFile(char *name) {
  FILE *inFile;
  int c = 0;
  if (name == 0) {
    inFile = stdin;
  } else {
    inFile = fopen(name, "rb");
  }
  if (inFile != NULL) {
    c = fgetc(inFile);
    while (c != EOF) {
      rgb_store(c);
      c = fgetc(inFile);
    }
    (void)fclose(inFile);
  } else {
    printf("fileopen failed!\n");
  }
}


x86 assembly (clang, -O0):
<ReadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1181 <ReadFile+0x31>
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
jmp    1195 <ReadFile+0x45>
mov    -0x8(%rbp),%rdi
lea    0xe74(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e5 <ReadFile+0x95>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%eax
je     11d7 <ReadFile+0x87>
mov    -0x14(%rbp),%edi
call   1050 <rgb_store@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
jmp    11ac <ReadFile+0x5c>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11f1 <ReadFile+0xa1>
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadFile>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11b3 <ReadFile+0x63>
lea    0xea0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rbx,%rbx
je     11c2 <ReadFile+0x72>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    0x2e64(%rip),%r14
cmp    (%r14),%eax
je     11a4 <ReadFile+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1050 <rgb_store@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%eax
jne    1190 <ReadFile+0x40>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fclose@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%rbx
test   %rbx,%rbx
jne    116d <ReadFile+0x1d>
lea    0xe3a(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <puts@plt>

LLVM IR (-O0):
@stdin = global i32* null
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.1 = [18 x i8] c"fileopen failed!\0A\00"
define void @ReadFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%5 = load i8*, i8** %2
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load i32*, i32** @stdin
store i32* %8, i32** %3
br label %12
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %3
br label %12
12: ; preds = %9, %7
%13 = load i32*, i32** %3
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %30
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = call i32 @fgetc(i32* %16)
store i32 %17, i32* %4
br label %18
18: ; preds = %22, %15
%19 = load i32, i32* %4
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %27
22: ; preds = %18
%23 = load i32, i32* %4
%24 = call i32 @rgb_store(i32 %23)
%25 = load i32*, i32** %3
%26 = call i32 @fgetc(i32* %25)
store i32 %26, i32* %4
br label %18
27: ; preds = %18
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
br label %32
30: ; preds = %12
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %27
ret void
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@str = [17 x i8] c"fileopen failed!\00"
define void @ReadFile(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = load i32*, i32** @stdin
br label %7
5: ; preds = %1
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = phi i32* [ %4, %3 ], [ %6, %5 ]
%9 = icmp eq i32* %8, null
br i1 %9, label %22, label %10
10: ; preds = %7
%11 = tail call i32 @fgetc(i32* %8)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %20, label %14
14: ; preds = %10, %14
%15 = phi i32 [ %17, %14 ], [ %11, %10 ]
%16 = tail call i32 @rgb_store(i32 %15)
%17 = tail call i32 @fgetc(i32* %8)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %14
20: ; preds = %14, %10
%21 = tail call i32 @fclose(i32* %8)
br label %24
22: ; preds = %7
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
ret void
}