#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 *);
void clearerr_t() {
  FILE *fp;
  char c;
  fp = fopen("file.txt", "w");
  c = fgetc(fp);
  if (ferror(fp)) {
    printf("Error in reading from file : file.txt\n");
  }
  clearerr(fp);
  if (ferror(fp)) {
    printf("Error in reading from file : file.txt\n");
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<clearerr_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    0xe93(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11aa <clearerr_t+0x4a>
lea    0xe66(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <clearerr@plt>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11d2 <clearerr_t+0x72>
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clearerr_t>:
push   %rbx
lea    0xeb7(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1198 <clearerr_t+0x38>
lea    0xe6f(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1070 <clearerr@plt>
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     11b9 <clearerr_t+0x59>
lea    0xe4e(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <fclose@plt>

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

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