#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int main01(void) {
  FILE *p = fopen("D:\\temp\\a.txt", "r");
  if (p == NULL) {
    printf("error\n");
  } else {
    char c = 0;
    while ((c = getc(p)) != EOF) {
      printf("%c", c);
    }
    fclose(p);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main01>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117d <main01+0x3d>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c2 <main01+0x82>
movb   $0x0,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
mov    0x2e51(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11b9 <main01+0x79>
movsbl -0x9(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1181 <main01+0x41>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main01>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xeb0(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11af <main01+0x5f>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getc@plt>
mov    0x2e6a(%rip),%r14
cmp    (%r14),%al
je     11a5 <main01+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    (%r14),%al
jne    1190 <main01+0x40>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11bb <main01+0x6b>
lea    0xe58(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"D:\\temp\\a.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [7 x i8] c"error\0A\00"
@EOF = global i8 0
@.str.3 = [3 x i8] c"%c\00"
define i32 @main01() {
%1 = alloca i32*
%2 = alloca i8
%3 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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 eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %23
8: ; preds = %0
store i8 0, i8* %2
br label %9
9: ; preds = %16, %8
%10 = load i32*, i32** %1
%11 = call signext i8 @getc(i32* %10)
store i8 %11, i8* %2
%12 = sext i8 %11 to i32
%13 = load i8, i8* @EOF
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %12, %14
br i1 %15, label %16, label %20
16: ; preds = %9
%17 = load i8, i8* %2
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %9
20: ; preds = %9
%21 = load i32*, i32** %1
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %20, %6
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"D:\\temp\\a.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i8 0
@str = [6 x i8] c"error\00"
define i32 @main01() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 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 @getc(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 ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %18
9: ; preds = %3, %9
%10 = phi i8 [ %13, %9 ], [ %4, %3 ]
%11 = sext i8 %10 to i32
%12 = tail call i32 @putchar(i32 %11)
%13 = tail call signext i8 @getc(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
ret i32 0
}