#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 */
int EOF;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getc(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int getchar1(void) {
  char s[1];
  int c, i = 0, maxLength = 2;
  while ((--maxLength > 0) && ((c = getc(stdin)) != EOF) && (c != '\n'))
    s[i++] = c;
  fflush(stdin);
  return s[0];
}


x86 assembly (clang, -O0):
<getchar1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0xc(%rbp)
movl   $0x2,-0x10(%rbp)
mov    -0x10(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
jle    117e <getchar1+0x5e>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x8(%rbp)
xor    %eax,%eax
mov    0x2e77(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x11(%rbp)
je     117e <getchar1+0x5e>
cmpl   $0xa,-0x8(%rbp)
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    118e <getchar1+0x6e>
jmp    11a9 <getchar1+0x89>
mov    -0x8(%rbp),%eax
mov    %al,%cl
mov    -0xc(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
cltq
mov    %cl,-0x1(%rbp,%rax,1)
jmp    1136 <getchar1+0x16>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1030 <fflush@plt>
movsbl -0x1(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getchar1>:
push   %rbp
push   %r14
push   %rbx
mov    0x2ebd(%rip),%rbp
mov    0x0(%rbp),%edi
call   1040 <getc@plt>
mov    %eax,%ebx
mov    0x2ea4(%rip),%rax
xor    %r14d,%r14d
cmp    (%rax),%ebx
mov    0x0(%rbp),%edi
movsbl %bl,%ebp
cmove  %r14d,%ebp
call   1030 <fflush@plt>
cmp    $0xa,%ebx
cmove  %r14d,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@EOF = global i32 0
define i32 @getchar1() {
%1 = alloca [1 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %3
store i32 2, i32* %4
br label %5
5: ; preds = %19, %0
%6 = load i32, i32* %4
%7 = add nsw i32 %6, -1
store i32 %7, i32* %4
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = load i32, i32* @stdin
%11 = call i32 @getc(i32 %10)
store i32 %11, i32* %2
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = load i32, i32* %2
%16 = icmp ne i32 %15, 10
br label %17
17: ; preds = %14, %9, %5
%18 = phi i1 [ false, %9 ], [ false, %5 ], [ %16, %14 ]
br i1 %18, label %19, label %26
19: ; preds = %17
%20 = load i32, i32* %2
%21 = trunc i32 %20 to i8
%22 = load i32, i32* %3
%23 = add nsw i32 %22, 1
store i32 %23, i32* %3
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 %24
store i8 %21, i8* %25
br label %5
26: ; preds = %17
%27 = load i32, i32* @stdin
%28 = call i32 @fflush(i32 %27)
%29 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
ret i32 %31
}

LLVM IR (-O2):
@stdin = global i32 0
@EOF = global i32 0
define i32 @getchar1() {
%1 = load i32, i32* @stdin
%2 = tail call i32 @getc(i32 %1)
%3 = load i32, i32* @EOF
%4 = icmp ne i32 %2, %3
%5 = icmp ne i32 %2, 10
%6 = and i1 %5, %4
%7 = load i32, i32* @stdin
%8 = tail call i32 @fflush(i32 %7)
%9 = shl i32 %2, 24
%10 = ashr exact i32 %9, 24
%11 = select i1 %6, i32 %10, i32 0
ret i32 %11
}