#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 EOF;
int /*<<< orphan*/ dv_error(char *);
scalar_t__ errno;
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int dv_fgetc(FILE *stream) {
  if (errno) {
    dv_error("");
  }
  int ret = fgetc(stream);
  if (ret == EOF && ferror(stream)) {
    dv_error("Failed to read from file.");
  }
  return ret;
}


x86 assembly (clang, -O0):
<dv_fgetc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e95(%rip),%rax
cmpq   $0x0,(%rax)
je     1159 <dv_fgetc+0x29>
lea    0xec5(%rip),%rdi
call   1050 <dv_error@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%eax
jne    1196 <dv_fgetc+0x66>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1196 <dv_fgetc+0x66>
lea    0xe6f(%rip),%rdi
call   1050 <dv_error@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dv_fgetc>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9b(%rip),%rax
cmpq   $0x0,(%rax)
je     114f <dv_fgetc+0x1f>
lea    0xecf(%rip),%rdi
call   1050 <dv_error@plt>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    0x2e88(%rip),%rax
cmp    (%rax),%ebp
jne    117d <dv_fgetc+0x4d>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     117d <dv_fgetc+0x4d>
lea    0xe88(%rip),%rdi
call   1050 <dv_error@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [1 x i8] zeroinitializer
@EOF = global i32 0
@.str.1 = [26 x i8] c"Failed to read from file.\00"
define i32 @dv_fgetc(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
%4 = load i64, i64* @errno
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @dv_error(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32*, i32** %2
%10 = call i32 @fgetc(i32* %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %20
14: ; preds = %8
%15 = load i32*, i32** %2
%16 = call i64 @ferror(i32* %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @dv_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %18, %14, %8
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [1 x i8] zeroinitializer
@EOF = global i32 0
@.str.1 = [26 x i8] c"Failed to read from file.\00"
define i32 @dv_fgetc(i32* nocapture %0) {
%2 = load i64, i64* @errno
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @dv_error(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @fgetc(i32* %0)
%8 = load i32, i32* @EOF
%9 = icmp eq i32 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = tail call i64 @ferror(i32* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @dv_error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %10, %6
ret i32 %7
}