#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*/ clearerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  FILE *fp;
  char c;
  fp = fopen("file.txt", "w");
  c = fgetc(fp);
  printf("%d\t", c);
  if (ferror(fp)) {
    printf("1-) Error in reading from file : file.txt\n");
  }
  clearerr(fp);
  if (ferror(fp)) {
    printf("2-) Error in reading from file : file.txt\n");
  }
  c = fgetc(fp);
  printf("%d\t", c);
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8a(%rip),%rdi
lea    0xe8c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11c5 <main+0x65>
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <clearerr@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ef <main+0x8f>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%esi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xed9(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <fgetc@plt>
movsbl %al,%esi
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11b9 <main+0x49>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1080 <clearerr@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11da <main+0x6a>
lea    0xe31(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
movsbl %al,%esi
lea    0xe16(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\09\00"
@.str.3 = [43 x i8] c"1-) Error in reading from file : file.txt\0A\00"
@.str.4 = [43 x i8] c"2-) Error in reading from file : file.txt\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
store i32 0, i32* %1
%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** %2
%5 = load i32*, i32** %2
%6 = call signext i8 @fgetc(i32* %5)
store i8 %6, i8* %3
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = load i32*, i32** %2
%11 = call i64 @ferror(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = load i32*, i32** %2
%17 = call i32 @clearerr(i32* %16)
%18 = load i32*, i32** %2
%19 = call i64 @ferror(i32* %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
%24 = load i32*, i32** %2
%25 = call signext i8 @fgetc(i32* %24)
store i8 %25, i8* %3
%26 = load i8, i8* %3
%27 = sext i8 %26 to i32
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = load i32*, i32** %2
%30 = call i32 @fclose(i32* %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"file.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\09\00"
@str = [42 x i8] c"2-) Error in reading from file : file.txt\00"
@str.5 = [42 x i8] c"1-) Error in reading from file : file.txt\00"
define i32 @main() {
%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 = tail call signext i8 @fgetc(i32* %1)
%3 = sext i8 %2 to i32
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %3)
%5 = tail call i64 @ferror(i32* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.5, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = tail call i32 @clearerr(i32* %1)
%11 = tail call i64 @ferror(i32* %1)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = tail call signext i8 @fgetc(i32* %1)
%17 = sext i8 %16 to i32
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = tail call i32 @fclose(i32* %1)
ret i32 0
}