#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 getch();
int getc(void) {
  int current_pos = 0, buffer[2];
  buffer[0] = -1;
  while (buffer[current_pos] != '\n') {
    if (buffer[current_pos] == '\b') {
      if (current_pos > 1)
        current_pos--;
    } else if (current_pos < 2)
      current_pos++;
    buffer[current_pos] = getch();
  }
  return buffer[1];
}


x86 assembly (clang, -O0):
<getc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movslq -0x4(%rbp),%rax
cmpl   $0xa,-0xc(%rbp,%rax,4)
je     118a <getc+0x7a>
movslq -0x4(%rbp),%rax
cmpl   $0x8,-0xc(%rbp,%rax,4)
jne    115c <getc+0x4c>
cmpl   $0x1,-0x4(%rbp)
jle    1157 <getc+0x47>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    1174 <getc+0x64>
cmpl   $0x2,-0x4(%rbp)
jge    116f <getc+0x5f>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1174 <getc+0x64>
mov    $0x0,%al
call   1030 <getch@plt>
mov    %eax,%ecx
movslq -0x4(%rbp),%rax
mov    %ecx,-0xc(%rbp,%rax,4)
jmp    1126 <getc+0x16>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getc>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%eax
mov    $0x1,%r14d
mov    $0x2,%ebp
xor    %ebx,%ebx
jmp    1144 <getc+0x34>
nopl   0x0(%rax)
test   %ebx,%ebx
cmovg  %r14d,%ebx
xor    %eax,%eax
call   1030 <getch@plt>
movslq %ebx,%rcx
mov    %eax,0x8(%rsp,%rcx,4)
cmp    $0x8,%eax
je     1130 <getc+0x20>
cmp    $0xa,%eax
je     115b <getc+0x4b>
cmp    $0x2,%ebx
lea    0x1(%rbx),%eax
cmovge %ebp,%eax
mov    %eax,%ebx
jmp    1136 <getc+0x26>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getc() {
%1 = alloca i32
%2 = alloca [2 x i32]
store i32 0, i32* %1
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
store i32 -1, i32* %3
br label %4
4: ; preds = %30, %0
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 %6
%8 = load i32, i32* %7
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %35
10: ; preds = %4
%11 = load i32, i32* %1
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 8
br i1 %15, label %16, label %23
16: ; preds = %10
%17 = load i32, i32* %1
%18 = icmp sgt i32 %17, 1
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %1
%21 = add nsw i32 %20, -1
store i32 %21, i32* %1
br label %22
22: ; preds = %19, %16
br label %30
23: ; preds = %10
%24 = load i32, i32* %1
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* %1
%28 = add nsw i32 %27, 1
store i32 %28, i32* %1
br label %29
29: ; preds = %26, %23
br label %30
30: ; preds = %29, %22
%31 = call i32 (...) @getch()
%32 = load i32, i32* %1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 %33
store i32 %31, i32* %34
br label %4
35: ; preds = %4
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%37 = load i32, i32* %36
ret i32 %37
}

LLVM IR (-O2):
define i32 @getc() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
br label %3
3: ; preds = %13, %0
%4 = phi i32 [ -1, %0 ], [ %15, %13 ]
%5 = phi i32 [ 0, %0 ], [ %14, %13 ]
switch i32 %4, label %9 [
i32 10, label %18
i32 8, label %6
]
6: ; preds = %3
%7 = icmp slt i32 %5, 1
%8 = select i1 %7, i32 %5, i32 1
br label %13
9: ; preds = %3
%10 = icmp slt i32 %5, 2
%11 = add nsw i32 %5, 1
%12 = select i1 %10, i32 %11, i32 2
br label %13
13: ; preds = %9, %6
%14 = phi i32 [ %8, %6 ], [ %12, %9 ]
%15 = tail call i32 (...) @getch()
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 %16
store i32 %15, i32* %17
br label %3
18: ; preds = %3
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%20 = load i32, i32* %19
ret i32 %20
}