#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 */
scalar_t__ EOF;
int /*<<< orphan*/ add_character(char);
int /*<<< orphan*/ clear_buffer();
int /*<<< orphan*/ delete_last_character();
int /*<<< orphan*/ isvalidansi(char);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ write_back();
bool read_and_parse_character() {
  char c;
  if (scanf("%c", &c) == EOF)
    return false;
  switch (c) {
  case 4:
    return false;
  case 10:
    clear_buffer();
    break;
  case 127:
    delete_last_character();
    break;
  default:
    if (isvalidansi(c))
      add_character(c);
  }
  write_back();
  return true;
}


x86 assembly (clang, -O0):
<read_and_parse_character>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe91(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1060 <scanf@plt>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    1194 <read_and_parse_character+0x34>
movl   $0x0,-0x4(%rbp)
jmp    121d <read_and_parse_character+0xbd>
movsbl -0x5(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x4,%eax
je     11cb <read_and_parse_character+0x6b>
jmp    11a9 <read_and_parse_character+0x49>
mov    -0xc(%rbp),%eax
sub    $0xa,%eax
je     11d7 <read_and_parse_character+0x77>
jmp    11ba <read_and_parse_character+0x5a>
mov    -0xc(%rbp),%eax
sub    $0x7f,%eax
je     11e3 <read_and_parse_character+0x83>
jmp    11ef <read_and_parse_character+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    121d <read_and_parse_character+0xbd>
mov    $0x0,%al
call   1040 <clear_buffer@plt>
jmp    120f <read_and_parse_character+0xaf>
mov    $0x0,%al
call   1050 <delete_last_character@plt>
jmp    120f <read_and_parse_character+0xaf>
movsbl -0x5(%rbp),%edi
call   1030 <isvalidansi@plt>
cmp    $0x0,%eax
je     120a <read_and_parse_character+0xaa>
movsbl -0x5(%rbp),%edi
call   1070 <add_character@plt>
jmp    120f <read_and_parse_character+0xaf>
mov    $0x0,%al
call   1080 <write_back@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_and_parse_character>:
push   %rax
lea    0xe98(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1060 <scanf@plt>
mov    %rax,%rcx
mov    0x2e6c(%rip),%rdx
xor    %eax,%eax
cmp    (%rdx),%rcx
je     11c8 <read_and_parse_character+0x68>
movsbl 0x7(%rsp),%edi
cmp    $0x4,%edi
je     11c8 <read_and_parse_character+0x68>
cmp    $0x7f,%edi
je     11a0 <read_and_parse_character+0x40>
cmp    $0xa,%edi
jne    11a9 <read_and_parse_character+0x49>
xor    %eax,%eax
call   1040 <clear_buffer@plt>
jmp    11bc <read_and_parse_character+0x5c>
xor    %eax,%eax
call   1050 <delete_last_character@plt>
jmp    11bc <read_and_parse_character+0x5c>
call   1030 <isvalidansi@plt>
test   %eax,%eax
je     11bc <read_and_parse_character+0x5c>
movsbl 0x7(%rsp),%edi
call   1070 <add_character@plt>
xor    %eax,%eax
call   1080 <write_back@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @read_and_parse_character() {
%1 = alloca i32
%2 = alloca i8
%3 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = load i64, i64* @EOF
%5 = icmp eq i64 %3, %4
br i1 %5, label %6, label %7
6: ; preds = %0
store i32 0, i32* %1
br label %25
7: ; preds = %0
%8 = load i8, i8* %2
%9 = sext i8 %8 to i32
switch i32 %9, label %15 [
i32 4, label %10
i32 10, label %11
i32 127, label %13
]
10: ; preds = %7
store i32 0, i32* %1
br label %25
11: ; preds = %7
%12 = call i32 (...) @clear_buffer()
br label %23
13: ; preds = %7
%14 = call i32 (...) @delete_last_character()
br label %23
15: ; preds = %7
%16 = load i8, i8* %2
%17 = call i32 @isvalidansi(i8 signext %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8, i8* %2
%21 = call i32 @add_character(i8 signext %20)
br label %22
22: ; preds = %19, %15
br label %23
23: ; preds = %22, %13, %11
%24 = call i32 (...) @write_back()
store i32 1, i32* %1
br label %25
25: ; preds = %23, %10, %6
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @read_and_parse_character() {
%1 = alloca i8
%2 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = load i64, i64* @EOF
%4 = icmp eq i64 %2, %3
br i1 %4, label %20, label %5
5: ; preds = %0
%6 = load i8, i8* %1
%7 = sext i8 %6 to i32
switch i32 %7, label %12 [
i32 4, label %20
i32 10, label %8
i32 127, label %10
]
8: ; preds = %5
%9 = call i32 (...) @clear_buffer()
br label %18
10: ; preds = %5
%11 = call i32 (...) @delete_last_character()
br label %18
12: ; preds = %5
%13 = call i32 @isvalidansi(i8 signext %6)
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i8, i8* %1
%17 = call i32 @add_character(i8 signext %16)
br label %18
18: ; preds = %12, %15, %10, %8
%19 = call i32 (...) @write_back()
br label %20
20: ; preds = %5, %0, %18
%21 = phi i32 [ 1, %18 ], [ 0, %0 ], [ 0, %5 ]
ret i32 %21
}