#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*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdout;
int main() {
  FILE *myfile;
  char c;
  myfile = fopen("consume.c", "r");
  if (!myfile) {
    puts("Some kind of a file error\n");
    return 1;
  }
  while ((c = fgetc(myfile)) != EOF)
    fputc(c, stdout);
  fclose(myfile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1199 <main+0x49>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e8 <main+0x98>
jmp    119e <main+0x4e>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e34(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d8 <main+0x88>
mov    -0x11(%rbp),%al
mov    0x2e0f(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    119e <main+0x4e>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b4 <main+0x64>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e69(%rip),%r14
cmp    (%r14),%al
je     11a8 <main+0x58>
mov    0x2e4d(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r15),%esi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%al
jne    1190 <main+0x40>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    11c5 <main+0x75>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"consume.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Some kind of a file error\0A\00"
@EOF = global i8 0
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
%4 = 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* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %24
9: ; preds = %0
br label %10
10: ; preds = %17, %9
%11 = load i32*, i32** %2
%12 = call signext i8 @fgetc(i32* %11)
store i8 %12, i8* %3
%13 = sext i8 %12 to i32
%14 = load i8, i8* @EOF
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %13, %15
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = load i8, i8* %3
%19 = load i32, i32* @stdout
%20 = call i32 @fputc(i8 signext %18, i32 %19)
br label %10
21: ; preds = %10
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
store i32 0, i32* %1
br label %24
24: ; preds = %21, %7
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [10 x i8] c"consume.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [27 x i8] c"Some kind of a file error\0A\00"
@EOF = global i8 0
@stdout = global i32 0
define i32 @main() {
%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 %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 %16, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
br label %18
9: ; preds = %3, %9
%10 = phi i8 [ %13, %9 ], [ %4, %3 ]
%11 = load i32, i32* @stdout
%12 = tail call i32 @fputc(i8 signext %10, i32 %11)
%13 = tail call signext i8 @fgetc(i32* %1)
%14 = load i8, i8* @EOF
%15 = icmp eq i8 %13, %14
br i1 %15, label %16, label %9
16: ; preds = %9, %3
%17 = tail call i32 @fclose(i32* %1)
br label %18
18: ; preds = %16, %7
%19 = phi i32 [ 0, %16 ], [ 1, %7 ]
ret i32 %19
}