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

/* Variables and functions */
int read(int, char *, int);
int config_getc(int f) {
  static char buf[8192];
  static int size = 0;
  static int ptr = 0;
  if (ptr == size) {
    ptr = 0;
    size = read(f, buf, sizeof(buf));
  }
  if (0 == size)
    return -1;
  return buf[ptr++];
}


x86 assembly (clang, -O0):
<config_getc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    0x4f23(%rip),%eax
cmp    0x4f19(%rip),%eax
jne    1151 <config_getc+0x41>
movl   $0x0,0x4f0d(%rip)
mov    -0x8(%rbp),%edi
lea    0x2eff(%rip),%rsi
mov    $0x2000,%edx
call   1030 <read@plt>
mov    %eax,0x4eef(%rip)
xor    %eax,%eax
cmp    0x4ee7(%rip),%eax
jne    116b <config_getc+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    118d <config_getc+0x7d>
mov    0x4ed3(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x4ec8(%rip)
movslq %eax,%rcx
lea    0x2eba(%rip),%rax
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<config_getc>:
push   %rax
mov    0x4f29(%rip),%eax
cmp    %eax,0x4f27(%rip)
jne    1140 <config_getc+0x30>
movl   $0x0,0x4f1b(%rip)
lea    0x2f10(%rip),%rsi
mov    $0x2000,%edx
call   1030 <read@plt>
mov    %eax,0x4f00(%rip)
test   %eax,%eax
je     1161 <config_getc+0x51>
movslq 0x4ef9(%rip),%rax
lea    0x1(%rax),%ecx
mov    %ecx,0x4ef0(%rip)
lea    0x2ee5(%rip),%rcx
movsbl (%rax,%rcx,1),%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret

LLVM IR (-O0):
@config_getc.buf = internal global [8192 x i8] zeroinitializer
@config_getc.size = internal global i32 0
@config_getc.ptr = internal global i32 0
define i32 @config_getc(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* @config_getc.ptr
%5 = load i32, i32* @config_getc.size
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %1
store i32 0, i32* @config_getc.ptr
%8 = load i32, i32* %3
%9 = call i32 @read(i32 %8, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @config_getc.buf, i64 0, i64 0), i32 8192)
store i32 %9, i32* @config_getc.size
br label %10
10: ; preds = %7, %1
%11 = load i32, i32* @config_getc.size
%12 = icmp eq i32 0, %11
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 -1, i32* %2
br label %21
14: ; preds = %10
%15 = load i32, i32* @config_getc.ptr
%16 = add nsw i32 %15, 1
store i32 %16, i32* @config_getc.ptr
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [8192 x i8], [8192 x i8]* @config_getc.buf, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
store i32 %20, i32* %2
br label %21
21: ; preds = %14, %13
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@config_getc.buf = internal global [8192 x i8] zeroinitializer
@config_getc.size = internal unnamed_addr global i32 0
@config_getc.ptr = internal unnamed_addr global i32 0
define i32 @config_getc(i32 %0) {
%2 = load i32, i32* @config_getc.ptr
%3 = load i32, i32* @config_getc.size
%4 = icmp eq i32 %2, %3
br i1 %4, label %5, label %7
5: ; preds = %1
store i32 0, i32* @config_getc.ptr
%6 = tail call i32 @read(i32 %0, i8* getelementptr inbounds ([8192 x i8], [8192 x i8]* @config_getc.buf, i64 0, i64 0), i32 8192)
store i32 %6, i32* @config_getc.size
br label %7
7: ; preds = %5, %1
%8 = phi i32 [ %6, %5 ], [ %3, %1 ]
%9 = icmp eq i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %7
%11 = load i32, i32* @config_getc.ptr
%12 = add nsw i32 %11, 1
store i32 %12, i32* @config_getc.ptr
%13 = sext i32 %11 to i64
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* @config_getc.buf, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
br label %17
17: ; preds = %7, %10
%18 = phi i32 [ %16, %10 ], [ -1, %7 ]
ret i32 %18
}