#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*/ getch();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char);
void guide() {
  char ch;
  FILE *fp = fopen("guide.txt", "r");
  if (fp == NULL)
    perror("fopen failed");
  else {
    while ((ch = fgetc(fp)) != EOF) {
      printf("%c", ch);
    }
  }
  fclose(fp);
  getch();
  getch();
}


x86 assembly (clang, -O0):
<guide>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    119b <guide+0x3b>
lea    0xe7b(%rip),%rdi
call   1080 <perror@plt>
jmp    11db <guide+0x7b>
jmp    11a0 <guide+0x40>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x1(%rbp)
movsbl %al,%eax
mov    0x2e32(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d6 <guide+0x76>
lea    0xe51(%rip),%rdi
movsbl -0x1(%rbp),%esi
call   1040 <printf@plt>
jmp    11a0 <guide+0x40>
jmp    11db <guide+0x7b>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    $0x0,%al
call   1060 <getch@plt>
mov    $0x0,%al
call   1060 <getch@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guide>:
push   %r15
push   %r14
push   %rbx
lea    0xe94(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11d3 <guide+0x73>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e59(%rip),%r15
cmp    (%r15),%al
je     11b8 <guide+0x58>
lea    0xe7e(%rip),%r14
nopl   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%al
jne    11a0 <guide+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
call   1060 <getch@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <getch@plt>
lea    0xe32(%rip),%rdi
call   1080 <perror@plt>
jmp    11b8 <guide+0x58>

LLVM IR (-O0):
@.str = [10 x i8] c"guide.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen failed\00"
@EOF = global i8 0
@.str.3 = [3 x i8] c"%c\00"
define void @guide() {
%1 = alloca i8
%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** %2
%4 = load i32*, i32** %2
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %20
8: ; preds = %0
br label %9
9: ; preds = %16, %8
%10 = load i32*, i32** %2
%11 = call signext i8 @fgetc(i32* %10)
store i8 %11, i8* %1
%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 %19
16: ; preds = %9
%17 = load i8, i8* %1
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %17)
br label %9
19: ; preds = %9
br label %20
20: ; preds = %19, %6
%21 = load i32*, i32** %2
%22 = call i32 @fclose(i32* %21)
%23 = call i32 (...) @getch()
%24 = call i32 (...) @getch()
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"guide.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [13 x i8] c"fopen failed\00"
@EOF = global i8 0
@.str.3 = [3 x i8] c"%c\00"
define void @guide() {
%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 %15, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %15
9: ; preds = %3, %9
%10 = phi i8 [ %12, %9 ], [ %4, %3 ]
%11 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %10)
%12 = tail call signext i8 @fgetc(i32* %1)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %15, label %9
15: ; preds = %9, %3, %7
%16 = tail call i32 @fclose(i32* %1)
%17 = tail call i32 (...) @getch()
%18 = tail call i32 (...) @getch()
ret void
}