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


x86 assembly (clang, -O0):
<fgetc_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x10(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a2 <fgetc_t+0x42>
lea    0xe73(%rip),%rdi
call   1080 <perror@plt>
jmp    11f2 <fgetc_t+0x92>
jmp    11a7 <fgetc_t+0x47>
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     11cb <fgetc_t+0x6b>
jmp    11e9 <fgetc_t+0x89>
mov    -0xc(%rbp),%esi
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%al
test   $0x1,%al
jne    11a7 <fgetc_t+0x47>
jmp    11e9 <fgetc_t+0x89>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetc_t>:
push   %rbp
push   %r14
push   %rbx
lea    0xe95(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11cd <fgetc_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 <fgetc_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 <fgetc_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 @fgetc_t() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %3
%4 = 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* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %24
9: ; preds = %0
br label %10
10: ; preds = %20, %9
%11 = load i32*, i32** %1
%12 = call i32 @fgetc(i32* %11)
store i32 %12, i32* %2
%13 = load i32*, i32** %1
%14 = call i64 @feof(i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
br label %21
17: ; preds = %10
%18 = load i32, i32* %2
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17
br i1 true, label %10, label %21
21: ; preds = %20, %16
%22 = load i32*, i32** %1
%23 = call i32 @fclose(i32* %22)
br label %24
24: ; preds = %21, %7
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 @fgetc_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
}