#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*/ int32_t;

/* Variables and functions */
int /*<<< orphan*/ vfs_eof(int);
int /*<<< orphan*/ vfs_ferrno(int);
int vfs_read(int, unsigned char *, int);
int vfs_getc(int fd) {
  unsigned char c = 0xFF;
  int32_t res;
  if (!vfs_eof(fd)) {
    if (1 != vfs_read(fd, &c, 1)) {
      ("getc errno %i\n", vfs_ferrno(fd));
      return -1;
    } else {
      return (int)c;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<vfs_getc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movb   $0xff,-0x9(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <vfs_eof@plt>
cmp    $0x0,%eax
jne    1190 <vfs_getc+0x60>
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <vfs_read@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%eax
je     1184 <vfs_getc+0x54>
mov    -0x8(%rbp),%edi
call   1050 <vfs_ferrno@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <vfs_getc+0x67>
movzbl -0x9(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1197 <vfs_getc+0x67>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vfs_getc>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movb   $0xff,0x7(%rsp)
call   1040 <vfs_eof@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
jne    116c <vfs_getc+0x3c>
lea    0x7(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <vfs_read@plt>
cmp    $0x1,%eax
jne    1165 <vfs_getc+0x35>
movzbl 0x7(%rsp),%ebx
jmp    116c <vfs_getc+0x3c>
mov    %ebp,%edi
call   1050 <vfs_ferrno@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"getc errno %i\0A\00"
define i32 @vfs_getc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i32
store i32 %0, i32* %3
store i8 -1, i8* %4
%6 = load i32, i32* %3
%7 = call i32 @vfs_eof(i32 %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %19, label %9
9: ; preds = %1
%10 = load i32, i32* %3
%11 = call i32 @vfs_read(i32 %10, i8* %4, i32 1)
%12 = icmp ne i32 1, %11
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %3
%15 = call i32 @vfs_ferrno(i32 %14)
store i32 -1, i32* %2
br label %20
16: ; preds = %9
%17 = load i8, i8* %4
%18 = zext i8 %17 to i32
store i32 %18, i32* %2
br label %20
19: ; preds = %1
store i32 -1, i32* %2
br label %20
20: ; preds = %19, %16, %13
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
define i32 @vfs_getc(i32 %0) {
%2 = alloca i8
store i8 -1, i8* %2
%3 = tail call i32 @vfs_eof(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = call i32 @vfs_read(i32 %0, i8* %2, i32 1)
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = call i32 @vfs_ferrno(i32 %0)
br label %13
10: ; preds = %5
%11 = load i8, i8* %2
%12 = zext i8 %11 to i32
br label %13
13: ; preds = %1, %10, %8
%14 = phi i32 [ -1, %8 ], [ %12, %10 ], [ -1, %1 ]
ret i32 %14
}