#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 EINTR;
int EOF;
int errno;
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int _mini_fgetc(FILE *stream) {
  int c, errno_orig = errno;
  do {
    errno = 0;
    c = fgetc(stream);
  } while (c == EOF && errno == EINTR);
  if (c != EOF || feof(stream)) {
    errno = errno_orig;
  }
  return c;
}


x86 assembly (clang, -O0):
<_mini_fgetc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e99(%rip),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    0x2e8b(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
jne    1180 <_mini_fgetc+0x60>
mov    0x2e69(%rip),%rax
mov    (%rax),%eax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1138 <_mini_fgetc+0x18>
mov    -0xc(%rbp),%eax
mov    0x2e53(%rip),%rcx
cmp    (%rcx),%eax
jne    11b0 <_mini_fgetc+0x90>
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     11bc <_mini_fgetc+0x9c>
mov    -0x10(%rbp),%ecx
mov    0x2e1e(%rip),%rax
mov    %ecx,(%rax)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_mini_fgetc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2ea3(%rip),%r14
mov    (%r14),%r15d
mov    0x2ea9(%rip),%r12
mov    0x2e8a(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
movl   $0x0,(%r14)
mov    %rbx,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
mov    (%r12),%eax
cmp    %eax,%ebp
jne    1172 <_mini_fgetc+0x52>
mov    0x0(%r13),%ecx
cmp    %ecx,(%r14)
je     1150 <_mini_fgetc+0x30>
cmp    %eax,%ebp
jne    1183 <_mini_fgetc+0x63>
mov    %rbx,%rdi
call   1040 <feof@plt>
test   %rax,%rax
je     1186 <_mini_fgetc+0x66>
mov    %r15d,(%r14)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@EOF = global i32 0
@EINTR = global i32 0
define i32 @_mini_fgetc(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = load i32, i32* @errno
store i32 %5, i32* %4
br label %6
6: ; preds = %17, %1
store i32 0, i32* @errno
%7 = load i32*, i32** %2
%8 = call i32 @fgetc(i32* %7)
store i32 %8, i32* %3
br label %9
9: ; preds = %6
%10 = load i32, i32* %3
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* @errno
%15 = load i32, i32* @EINTR
%16 = icmp eq i32 %14, %15
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ false, %9 ], [ %16, %13 ]
br i1 %18, label %6, label %19
19: ; preds = %17
%20 = load i32, i32* %3
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br i1 %22, label %27, label %23
23: ; preds = %19
%24 = load i32*, i32** %2
%25 = call i64 @feof(i32* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23, %19
%28 = load i32, i32* %4
store i32 %28, i32* @errno
br label %29
29: ; preds = %27, %23
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@errno = global i32 0
@EOF = global i32 0
@EINTR = global i32 0
define i32 @_mini_fgetc(i32* nocapture %0) {
%2 = load i32, i32* @errno
br label %3
3: ; preds = %3, %1
store i32 0, i32* @errno
%4 = tail call i32 @fgetc(i32* %0)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
%7 = load i32, i32* @errno
%8 = load i32, i32* @EINTR
%9 = icmp eq i32 %7, %8
%10 = select i1 %6, i1 %9, i1 false
br i1 %10, label %3, label %11
11: ; preds = %3
br i1 %6, label %12, label %15
12: ; preds = %11
%13 = tail call i64 @feof(i32* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %12, %11
store i32 %2, i32* @errno
br label %16
16: ; preds = %15, %12
ret i32 %4
}