#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 */
#define EOF 128
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ console();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgetln(int /*<<< orphan*/, size_t *);
char getchar();
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdin;
int input(bool echo) {
  char c = getchar();
  size_t len;
  switch (c) {
  case EOF:
    exit(EXIT_SUCCESS);
  case '!':
    console();
    return input(echo);
  case '#':
    fgetln(stdin, &len);
    return input(echo);
  default:
    if (echo) {
      putchar(c);
    }
    return c;
  }
}


x86 assembly (clang, -O0):
<input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x21,%eax
je     11bc <input+0x5c>
jmp    118a <input+0x2a>
mov    -0x1c(%rbp),%eax
sub    $0x23,%eax
je     11d3 <input+0x73>
jmp    119b <input+0x3b>
mov    -0x1c(%rbp),%eax
sub    $0x80,%eax
jne    11f5 <input+0x95>
jmp    11ae <input+0x4e>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1060 <console@plt>
mov    -0x8(%rbp),%edi
call   1040 <input@plt>
mov    %eax,-0x4(%rbp)
jmp    120f <input+0xaf>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1070 <fgetln@plt>
mov    -0x8(%rbp),%edi
call   1040 <input@plt>
mov    %eax,-0x4(%rbp)
jmp    120f <input+0xaf>
cmpl   $0x0,-0x8(%rbp)
je     1208 <input+0xa8>
movsbl -0x9(%rbp),%edi
call   1030 <putchar@plt>
movsbl -0x9(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
movsbl %al,%ebp
cmp    $0x23,%ebp
je     117d <input+0x2d>
cmp    $0x21,%ebp
jne    1199 <input+0x49>
xor    %eax,%eax
call   1060 <console@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <input@plt>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1070 <fgetln@plt>
mov    %ebx,%edi
call   1040 <input@plt>
mov    %eax,%ebp
jmp    11a4 <input+0x54>
test   %ebx,%ebx
je     11a4 <input+0x54>
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@stdin = global i32 0
define i32 @input(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
%5 = alloca i64
store i32 %0, i32* %3
%6 = call signext i8 (...) @getchar()
store i8 %6, i8* %4
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
switch i32 %8, label %21 [
i32 128, label %9
i32 33, label %12
i32 35, label %16
]
9: ; preds = %1
%10 = load i32, i32* @EXIT_SUCCESS
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = call i32 (...) @console()
%14 = load i32, i32* %3
%15 = call i32 @input(i32 %14)
store i32 %15, i32* %2
br label %30
16: ; preds = %1
%17 = load i32, i32* @stdin
%18 = call i32 @fgetln(i32 %17, i64* %5)
%19 = load i32, i32* %3
%20 = call i32 @input(i32 %19)
store i32 %20, i32* %2
br label %30
21: ; preds = %1
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i8, i8* %4
%26 = call i32 @putchar(i8 signext %25)
br label %27
27: ; preds = %24, %21
%28 = load i8, i8* %4
%29 = sext i8 %28 to i32
store i32 %29, i32* %2
br label %30
30: ; preds = %27, %16, %12
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@stdin = global i32 0
define i32 @input(i32 %0) {
%2 = alloca i64
%3 = tail call signext i8 (...) @getchar()
%4 = bitcast i64* %2 to i8*
%5 = sext i8 %3 to i32
switch i32 %5, label %13 [
i32 35, label %9
i32 33, label %6
]
6: ; preds = %1
%7 = tail call i32 (...) @console()
%8 = tail call i32 @input(i32 %0)
br label %17
9: ; preds = %1
%10 = load i32, i32* @stdin
%11 = call i32 @fgetln(i32 %10, i64* %2)
%12 = call i32 @input(i32 %0)
br label %17
13: ; preds = %1
%14 = icmp eq i32 %0, 0
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = tail call i32 @putchar(i8 signext %3)
br label %17
17: ; preds = %13, %15, %9, %6
%18 = phi i32 [ %8, %6 ], [ %12, %9 ], [ %5, %15 ], [ %5, %13 ]
ret i32 %18
}