#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 kcscan();
int /*<<< orphan*/ kpc(char);
char *cscan() {
  int len = 0, i = 0, max = 1024 * 1024;
  char c;
  static unsigned char buffer[1024 * 1024];
  kpc('_');
  do {
    c = kcscan();
    if (c == '\n') {
      kpc('\b');
      kpc(c);
      break;
    } else if (c == '\b') {
      if (len > 0) {
        len--;
        i--;
        kpc('\b');
        kpc('\b');
        kpc('_');
      }
    } else {
      len++;
      kpc('\b');
      kpc(c);
      kpc('_');
      if (i < max)
        buffer[i++] = c;
      else
        break;
    }
  } while (1);
  buffer[i] = '\0';
  return buffer;
}


x86 assembly (clang, -O0):
<cscan>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x100000,-0xc(%rbp)
mov    $0x5f,%edi
call   1040 <kpc@plt>
mov    $0x0,%al
call   1030 <kcscan@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    1176 <cscan+0x56>
mov    $0x8,%edi
call   1040 <kpc@plt>
movsbl -0xd(%rbp),%edi
call   1040 <kpc@plt>
jmp    1237 <cscan+0x117>
movsbl -0xd(%rbp),%eax
cmp    $0x8,%eax
jne    11c2 <cscan+0xa2>
cmpl   $0x0,-0x4(%rbp)
jle    11bd <cscan+0x9d>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    $0x8,%edi
call   1040 <kpc@plt>
mov    $0x8,%edi
call   1040 <kpc@plt>
mov    $0x5f,%edi
call   1040 <kpc@plt>
jmp    121e <cscan+0xfe>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    $0x8,%edi
call   1040 <kpc@plt>
movsbl -0xd(%rbp),%edi
call   1040 <kpc@plt>
mov    $0x5f,%edi
call   1040 <kpc@plt>
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1214 <cscan+0xf4>
mov    -0xd(%rbp),%dl
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
movslq %eax,%rcx
lea    0x2e34(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    1219 <cscan+0xf9>
jmp    1237 <cscan+0x117>
jmp    121e <cscan+0xfe>
jmp    1223 <cscan+0x103>
jmp    1228 <cscan+0x108>
mov    $0x1,%al
test   $0x1,%al
jne    1147 <cscan+0x27>
jmp    1237 <cscan+0x117>
movslq -0x8(%rbp),%rcx
lea    0x2dfe(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2df3(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cscan>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x5f,%edi
call   1040 <kpc@plt>
lea    0x2f07(%rip),%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   1030 <kcscan@plt>
cmp    $0x8,%al
jne    1176 <cscan+0x56>
test   %ebp,%ebp
jle    1140 <cscan+0x20>
add    $0xffffffff,%ebp
add    $0xffffffff,%r15d
mov    $0x8,%edi
call   1040 <kpc@plt>
mov    $0x8,%edi
call   1040 <kpc@plt>
mov    $0x5f,%edi
call   1040 <kpc@plt>
jmp    1140 <cscan+0x20>
mov    %eax,%ebx
movslq %r15d,%r12
mov    $0x8,%edi
cmp    $0xa,%al
je     11b1 <cscan+0x91>
call   1040 <kpc@plt>
movsbl %bl,%edi
call   1040 <kpc@plt>
mov    $0x5f,%edi
call   1040 <kpc@plt>
cmp    $0xfffff,%r15d
jg     11c0 <cscan+0xa0>
add    $0x1,%ebp
add    $0x1,%r15d
mov    %bl,(%r12,%r14,1)
jmp    1140 <cscan+0x20>
call   1040 <kpc@plt>
mov    $0xa,%edi
call   1040 <kpc@plt>
movb   $0x0,(%r12,%r14,1)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@cscan.buffer = internal global [1048576 x i8] zeroinitializer
define i8* @cscan() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1048576, i32* %3
%5 = call i32 @kpc(i8 signext 95)
br label %6
6: ; preds = %51, %0
%7 = call signext i8 (...) @kcscan()
store i8 %7, i8* %4
%8 = load i8, i8* %4
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 10
br i1 %10, label %11, label %15
11: ; preds = %6
%12 = call i32 @kpc(i8 signext 8)
%13 = load i8, i8* %4
%14 = call i32 @kpc(i8 signext %13)
br label %52
15: ; preds = %6
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 8
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = load i32, i32* %1
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i32, i32* %1
%24 = add nsw i32 %23, -1
store i32 %24, i32* %1
%25 = load i32, i32* %2
%26 = add nsw i32 %25, -1
store i32 %26, i32* %2
%27 = call i32 @kpc(i8 signext 8)
%28 = call i32 @kpc(i8 signext 8)
%29 = call i32 @kpc(i8 signext 95)
br label %30
30: ; preds = %22, %19
br label %49
31: ; preds = %15
%32 = load i32, i32* %1
%33 = add nsw i32 %32, 1
store i32 %33, i32* %1
%34 = call i32 @kpc(i8 signext 8)
%35 = load i8, i8* %4
%36 = call i32 @kpc(i8 signext %35)
%37 = call i32 @kpc(i8 signext 95)
%38 = load i32, i32* %2
%39 = load i32, i32* %3
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %47
41: ; preds = %31
%42 = load i8, i8* %4
%43 = load i32, i32* %2
%44 = add nsw i32 %43, 1
store i32 %44, i32* %2
%45 = sext i32 %43 to i64
%46 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* @cscan.buffer, i64 0, i64 %45
store i8 %42, i8* %46
br label %48
47: ; preds = %31
br label %52
48: ; preds = %41
br label %49
49: ; preds = %48, %30
br label %50
50: ; preds = %49
br label %51
51: ; preds = %50
br i1 true, label %6, label %52
52: ; preds = %51, %47, %11
%53 = load i32, i32* %2
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* @cscan.buffer, i64 0, i64 %54
store i8 0, i8* %55
ret i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @cscan.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@cscan.buffer = internal global [1048576 x i8] zeroinitializer
define i8* @cscan() {
%1 = tail call i32 @kpc(i8 signext 95)
br label %2
2: ; preds = %18, %0
%3 = phi i32 [ 0, %0 ], [ %19, %18 ]
%4 = phi i32 [ 0, %0 ], [ %20, %18 ]
%5 = icmp sgt i32 %4, 0
br label %6
6: ; preds = %2, %11
%7 = tail call signext i8 (...) @kcscan()
switch i8 %7, label %21 [
i8 10, label %8
i8 8, label %11
]
8: ; preds = %6
%9 = tail call i32 @kpc(i8 signext 8)
%10 = tail call i32 @kpc(i8 signext 10)
br label %31
11: ; preds = %6
br i1 %5, label %12, label %6
12: ; preds = %11
%13 = add nsw i32 %4, -1
%14 = add nsw i32 %3, -1
%15 = tail call i32 @kpc(i8 signext 8)
%16 = tail call i32 @kpc(i8 signext 8)
%17 = tail call i32 @kpc(i8 signext 95)
br label %18
18: ; preds = %12, %26
%19 = phi i32 [ %28, %26 ], [ %14, %12 ]
%20 = phi i32 [ %27, %26 ], [ %13, %12 ]
br label %2
21: ; preds = %6
%22 = tail call i32 @kpc(i8 signext 8)
%23 = tail call i32 @kpc(i8 signext %7)
%24 = tail call i32 @kpc(i8 signext 95)
%25 = icmp slt i32 %3, 1048576
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = add nsw i32 %4, 1
%28 = add nsw i32 %3, 1
%29 = sext i32 %3 to i64
%30 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* @cscan.buffer, i64 0, i64 %29
store i8 %7, i8* %30
br label %18
31: ; preds = %21, %8
%32 = sext i32 %3 to i64
%33 = getelementptr inbounds [1048576 x i8], [1048576 x i8]* @cscan.buffer, i64 0, i64 %32
store i8 0, i8* %33
ret i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @cscan.buffer, i64 0, i64 0)
}