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

/* Variables and functions */
char getc(int /*<<< orphan*/);
int /*<<< orphan*/ os_flush();
int /*<<< orphan*/ stdin;
char os_readchar(int millis) {
  static int count = 0;
  char c;
  os_flush();
  if (millis == 0)
    return 0;
  if (++count < 1024)
    return 0;
  count = 0;
  c = getc(stdin);
  if (c != '\n') {
    while (getc(stdin) != '\n') {
    }
  }
  return c;
}


x86 assembly (clang, -O0):
<os_readchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <os_flush@plt>
cmpl   $0x0,-0x8(%rbp)
jne    1145 <os_readchar+0x25>
movb   $0x0,-0x1(%rbp)
jmp    11bf <os_readchar+0x9f>
mov    0x2ee9(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2ee0(%rip)
cmp    $0x400,%eax
jge    1168 <os_readchar+0x48>
movb   $0x0,-0x1(%rbp)
jmp    11bf <os_readchar+0x9f>
movl   $0x0,0x2ec2(%rip)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     11b9 <os_readchar+0x99>
jmp    1195 <os_readchar+0x75>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11b4 <os_readchar+0x94>
jmp    1195 <os_readchar+0x75>
jmp    11b9 <os_readchar+0x99>
mov    -0x9(%rbp),%al
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_readchar>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <os_flush@plt>
test   %ebp,%ebp
je     117f <os_readchar+0x5f>
mov    0x2efb(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2ef2(%rip)
cmp    $0x3ff,%eax
jge    114d <os_readchar+0x2d>
xor    %ebx,%ebx
jmp    117f <os_readchar+0x5f>
movl   $0x0,0x2edd(%rip)
mov    0x2e8a(%rip),%rbp
mov    0x0(%rbp),%edi
call   1040 <getc@plt>
mov    $0xa,%bl
cmp    $0xa,%al
je     117f <os_readchar+0x5f>
mov    %eax,%r14d
nop
mov    0x0(%rbp),%edi
call   1040 <getc@plt>
cmp    $0xa,%al
jne    1170 <os_readchar+0x50>
mov    %r14d,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@os_readchar.count = internal global i32 0
@stdin = global i32 0
define signext i8 @os_readchar(i32 %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %3
%5 = call i32 (...) @os_flush()
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i8 0, i8* %2
br label %30
9: ; preds = %1
%10 = load i32, i32* @os_readchar.count
%11 = add nsw i32 %10, 1
store i32 %11, i32* @os_readchar.count
%12 = icmp slt i32 %11, 1024
br i1 %12, label %13, label %14
13: ; preds = %9
store i8 0, i8* %2
br label %30
14: ; preds = %9
store i32 0, i32* @os_readchar.count
%15 = load i32, i32* @stdin
%16 = call signext i8 @getc(i32 %15)
store i8 %16, i8* %4
%17 = load i8, i8* %4
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 10
br i1 %19, label %20, label %28
20: ; preds = %14
br label %21
21: ; preds = %26, %20
%22 = load i32, i32* @stdin
%23 = call signext i8 @getc(i32 %22)
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %21
br label %21
27: ; preds = %21
br label %28
28: ; preds = %27, %14
%29 = load i8, i8* %4
store i8 %29, i8* %2
br label %30
30: ; preds = %28, %13, %8
%31 = load i8, i8* %2
ret i8 %31
}

LLVM IR (-O2):
@os_readchar.count = internal unnamed_addr global i32 0
@stdin = global i32 0
define signext i8 @os_readchar(i32 %0) {
%2 = tail call i32 (...) @os_flush()
%3 = icmp eq i32 %0, 0
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = load i32, i32* @os_readchar.count
%6 = add nsw i32 %5, 1
store i32 %6, i32* @os_readchar.count
%7 = icmp slt i32 %5, 1023
br i1 %7, label %16, label %8
8: ; preds = %4
store i32 0, i32* @os_readchar.count
%9 = load i32, i32* @stdin
%10 = tail call signext i8 @getc(i32 %9)
%11 = icmp eq i8 %10, 10
br i1 %11, label %16, label %12
12: ; preds = %8, %12
%13 = load i32, i32* @stdin
%14 = tail call signext i8 @getc(i32 %13)
%15 = icmp eq i8 %14, 10
br i1 %15, label %16, label %12
16: ; preds = %12, %8, %4, %1
%17 = phi i8 [ 0, %1 ], [ 0, %4 ], [ 10, %8 ], [ %10, %12 ]
ret i8 %17
}