#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
void feof_t() {
  FILE *fp;
  int c;
  fp = fopen("file.txt", "r");
  if (fp == NULL) {
    perror("Error in opening file");
    return;
  }
  while (1) {
    c = fgetc(fp);
    if (feof(fp)) {
      break;
    }
    printf("%c", c);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<feof_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    119b <feof_t+0x3b>
lea    0xe7a(%rip),%rdi
call   1080 <perror@plt>
jmp    11e1 <feof_t+0x81>
jmp    11a0 <feof_t+0x40>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11c4 <feof_t+0x64>
jmp    11d8 <feof_t+0x78>
mov    -0xc(%rbp),%esi
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
jmp    11a0 <feof_t+0x40>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<feof_t>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11cd <feof_t+0x6d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    11c1 <feof_t+0x61>
lea    0xe84(%rip),%r14
nopl   (%rax)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %rax,%rax
je     11a0 <feof_t+0x40>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xe37(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1080 <perror@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"Error in opening file\00"
@.str.3 = [3 x i8] c"%c\00"
define void @feof_t() {
%1 = alloca i32*
%2 = alloca i32
%3 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %22
8: ; preds = %0
br label %9
9: ; preds = %8, %16
%10 = load i32*, i32** %1
%11 = call i32 @fgetc(i32* %10)
store i32 %11, i32* %2
%12 = load i32*, i32** %1
%13 = call i64 @feof(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
br label %19
16: ; preds = %9
%17 = load i32, i32* %2
%18 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %9
19: ; preds = %15
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %19, %6
ret void
}

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