#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 COLS;
scalar_t__ LINES;
int /*<<< orphan*/ clrtoeol();
int /*<<< orphan*/ colon_process(char *);
int /*<<< orphan*/ display();
int getch();
int /*<<< orphan*/ move(scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ mvaddstr(scalar_t__, int, char *);
int /*<<< orphan*/ refresh();
int colon_mode(void) {
  char buf[132];
  char *bp = buf;
  int c;
  mvaddstr(LINES - 1, 0, ":");
  clrtoeol();
  refresh();
  *bp = 0;
  while (1) {
    c = getch();
    if (c < 0 || c > 255 || c == 27)
      break;
    if (c == '\n' || c == '\r') {
      colon_process(buf);
      break;
    }
    if (c == 8 || c == 127) {
      if (bp != buf)
        *--bp = 0;
    } else {
      if (bp < buf + 130 && bp < buf + COLS - 2) {
        *bp++ = c;
        *bp = 0;
      }
    }
    mvaddstr(LINES - 1, 1, buf);
    clrtoeol();
    refresh();
  }
  move(LINES - 1, 0);
  clrtoeol();
  display();
  return 0;
}


x86 assembly (clang, -O0):
<colon_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    -0x90(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%rdi
sub    $0x1,%rdi
xor    %esi,%esi
lea    0xe60(%rip),%rdx
call   1080 <mvaddstr@plt>
mov    $0x0,%al
call   1070 <clrtoeol@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
mov    -0x98(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x0,%al
call   1060 <getch@plt>
mov    %eax,-0x9c(%rbp)
cmpl   $0x0,-0x9c(%rbp)
jl     11f4 <colon_mode+0x84>
cmpl   $0xff,-0x9c(%rbp)
jg     11f4 <colon_mode+0x84>
cmpl   $0x1b,-0x9c(%rbp)
jne    11f9 <colon_mode+0x89>
jmp    1319 <colon_mode+0x1a9>
cmpl   $0xa,-0x9c(%rbp)
je     1213 <colon_mode+0xa3>
cmpl   $0xd,-0x9c(%rbp)
jne    1224 <colon_mode+0xb4>
lea    -0x90(%rbp),%rdi
call   1030 <colon_process@plt>
jmp    1319 <colon_mode+0x1a9>
cmpl   $0x8,-0x9c(%rbp)
je     123e <colon_mode+0xce>
cmpl   $0x7f,-0x9c(%rbp)
jne    1273 <colon_mode+0x103>
mov    -0x98(%rbp),%rax
lea    -0x90(%rbp),%rcx
cmp    %rcx,%rax
je     126e <colon_mode+0xfe>
mov    -0x98(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x98(%rbp)
movb   $0x0,-0x1(%rax)
jmp    12e7 <colon_mode+0x177>
mov    -0x98(%rbp),%rax
lea    -0x90(%rbp),%rcx
add    $0x82,%rcx
cmp    %rcx,%rax
jae    12e2 <colon_mode+0x172>
mov    -0x98(%rbp),%rax
lea    -0x90(%rbp),%rcx
mov    0x2d3a(%rip),%rdx
movslq (%rdx),%rdx
add    %rdx,%rcx
add    $0xfffffffffffffffe,%rcx
cmp    %rcx,%rax
jae    12e2 <colon_mode+0x172>
mov    -0x9c(%rbp),%eax
mov    %al,%cl
mov    -0x98(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x98(%rbp)
mov    %cl,(%rax)
mov    -0x98(%rbp),%rax
movb   $0x0,(%rax)
jmp    12e7 <colon_mode+0x177>
mov    0x2cfa(%rip),%rax
mov    (%rax),%rdi
sub    $0x1,%rdi
lea    -0x90(%rbp),%rdx
mov    $0x1,%esi
call   1080 <mvaddstr@plt>
mov    $0x0,%al
call   1070 <clrtoeol@plt>
mov    $0x0,%al
call   1050 <refresh@plt>
jmp    11bd <colon_mode+0x4d>
mov    0x2cc8(%rip),%rax
mov    (%rax),%rdi
sub    $0x1,%rdi
xor    %esi,%esi
call   1090 <move@plt>
mov    $0x0,%al
call   1070 <clrtoeol@plt>
mov    $0x0,%al
call   1040 <display@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<colon_mode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x90,%rsp
mov    0x2e61(%rip),%r14
mov    (%r14),%rdi
add    $0xffffffffffffffff,%rdi
lea    0xe6b(%rip),%rdx
xor    %esi,%esi
call   1080 <mvaddstr@plt>
xor    %eax,%eax
call   1070 <clrtoeol@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
movb   $0x0,(%rsp)
xor    %eax,%eax
call   1060 <getch@plt>
cmp    $0xff,%eax
ja     1286 <colon_mode+0x116>
cmp    $0x1b,%eax
je     1286 <colon_mode+0x116>
mov    %rsp,%r13
lea    0x82(%rsp),%r15
mov    0x2e05(%rip),%r12
mov    %r13,%rcx
xchg   %ax,%ax
cmp    $0xc,%eax
jg     1200 <colon_mode+0x90>
cmp    $0x8,%eax
je     1205 <colon_mode+0x95>
cmp    $0xa,%eax
jne    1218 <colon_mode+0xa8>
jmp    127e <colon_mode+0x10e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0x7f,%eax
jne    1213 <colon_mode+0xa3>
mov    %r13,%rbx
cmp    %r13,%rcx
je     1240 <colon_mode+0xd0>
add    $0xffffffffffffffff,%rcx
jmp    1233 <colon_mode+0xc3>
cmp    $0xd,%eax
je     127e <colon_mode+0x10e>
cmp    %r15,%rcx
jae    123b <colon_mode+0xcb>
movslq (%r12),%rdx
add    %rsp,%rdx
add    $0xfffffffffffffffe,%rdx
cmp    %rdx,%rcx
jae    123b <colon_mode+0xcb>
mov    %al,(%rcx)
add    $0x1,%rcx
mov    %rcx,%rbx
movb   $0x0,(%rcx)
jmp    1240 <colon_mode+0xd0>
mov    %rcx,%rbx
xchg   %ax,%ax
mov    (%r14),%rdi
add    $0xffffffffffffffff,%rdi
mov    $0x1,%esi
mov    %r13,%rdx
call   1080 <mvaddstr@plt>
xor    %eax,%eax
call   1070 <clrtoeol@plt>
xor    %eax,%eax
call   1050 <refresh@plt>
xor    %eax,%eax
call   1060 <getch@plt>
cmp    $0xff,%eax
ja     1286 <colon_mode+0x116>
mov    %rbx,%rcx
cmp    $0x1b,%eax
jne    11e0 <colon_mode+0x70>
jmp    1286 <colon_mode+0x116>
mov    %rsp,%rdi
call   1030 <colon_process@plt>
mov    (%r14),%rdi
add    $0xffffffffffffffff,%rdi
xor    %esi,%esi
call   1090 <move@plt>
xor    %eax,%eax
call   1070 <clrtoeol@plt>
xor    %eax,%eax
call   1040 <display@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LINES = global i64 0
@.str = [2 x i8] c":\00"
@COLS = global i32 0
define i32 @colon_mode() {
%1 = alloca [132 x i8]
%2 = alloca i8*
%3 = alloca i32
%4 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 0
store i8* %4, i8** %2
%5 = load i64, i64* @LINES
%6 = sub nsw i64 %5, 1
%7 = call i32 @mvaddstr(i64 %6, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%8 = call i32 (...) @clrtoeol()
%9 = call i32 (...) @refresh()
%10 = load i8*, i8** %2
store i8 0, i8* %10
br label %11
11: ; preds = %0, %65
%12 = call i32 (...) @getch()
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %11
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 255
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 27
br i1 %20, label %21, label %22
21: ; preds = %18, %15, %11
br label %72
22: ; preds = %18
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 10
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, 13
br i1 %27, label %28, label %31
28: ; preds = %25, %22
%29 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 0
%30 = call i32 @colon_process(i8* %29)
br label %72
31: ; preds = %25
%32 = load i32, i32* %3
%33 = icmp eq i32 %32, 8
br i1 %33, label %37, label %34
34: ; preds = %31
%35 = load i32, i32* %3
%36 = icmp eq i32 %35, 127
br i1 %36, label %37, label %45
37: ; preds = %34, %31
%38 = load i8*, i8** %2
%39 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 0
%40 = icmp ne i8* %38, %39
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i8*, i8** %2
%43 = getelementptr inbounds i8, i8* %42, i32 -1
store i8* %43, i8** %2
store i8 0, i8* %43
br label %44
44: ; preds = %41, %37
br label %65
45: ; preds = %34
%46 = load i8*, i8** %2
%47 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 0
%48 = getelementptr inbounds i8, i8* %47, i64 130
%49 = icmp ult i8* %46, %48
br i1 %49, label %50, label %64
50: ; preds = %45
%51 = load i8*, i8** %2
%52 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 0
%53 = load i32, i32* @COLS
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = getelementptr inbounds i8, i8* %55, i64 -2
%57 = icmp ult i8* %51, %56
br i1 %57, label %58, label %64
58: ; preds = %50
%59 = load i32, i32* %3
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %2
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %2
store i8 %60, i8* %61
%63 = load i8*, i8** %2
store i8 0, i8* %63
br label %64
64: ; preds = %58, %50, %45
br label %65
65: ; preds = %64, %44
%66 = load i64, i64* @LINES
%67 = sub nsw i64 %66, 1
%68 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 0
%69 = call i32 @mvaddstr(i64 %67, i32 1, i8* %68)
%70 = call i32 (...) @clrtoeol()
%71 = call i32 (...) @refresh()
br label %11
72: ; preds = %28, %21
%73 = load i64, i64* @LINES
%74 = sub nsw i64 %73, 1
%75 = call i32 @move(i64 %74, i32 0)
%76 = call i32 (...) @clrtoeol()
%77 = call i32 (...) @display()
ret i32 0
}

LLVM IR (-O2):
@LINES = global i64 0
@.str = [2 x i8] c":\00"
@COLS = global i32 0
define i32 @colon_mode() {
%1 = alloca [132 x i8]
%2 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 0
%3 = load i64, i64* @LINES
%4 = add nsw i64 %3, -1
%5 = tail call i32 @mvaddstr(i64 %4, i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (...) @clrtoeol()
%7 = tail call i32 (...) @refresh()
store i8 0, i8* %2
%8 = call i32 (...) @getch()
%9 = icmp ugt i32 %8, 255
%10 = icmp eq i32 %8, 27
%11 = or i1 %9, %10
br i1 %11, label %47, label %12
12: ; preds = %0
%13 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 130
br label %14
14: ; preds = %12, %36
%15 = phi i32 [ %8, %12 ], [ %43, %36 ]
%16 = phi i8* [ %2, %12 ], [ %37, %36 ]
switch i32 %15, label %23 [
i32 13, label %17
i32 10, label %17
i32 127, label %19
i32 8, label %19
]
17: ; preds = %14, %14
%18 = call i32 @colon_process(i8* %2)
br label %47
19: ; preds = %14, %14
%20 = icmp eq i8* %16, %2
br i1 %20, label %36, label %21
21: ; preds = %19
%22 = getelementptr inbounds i8, i8* %16, i64 -1
br label %34
23: ; preds = %14
%24 = icmp ult i8* %16, %13
%25 = load i32, i32* @COLS
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [132 x i8], [132 x i8]* %1, i64 0, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 -2
%29 = icmp ult i8* %16, %28
%30 = select i1 %24, i1 %29, i1 false
br i1 %30, label %31, label %36
31: ; preds = %23
%32 = trunc i32 %15 to i8
%33 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %32, i8* %16
br label %34
34: ; preds = %21, %31
%35 = phi i8* [ %33, %31 ], [ %22, %21 ]
store i8 0, i8* %35
br label %36
36: ; preds = %34, %23, %19
%37 = phi i8* [ %2, %19 ], [ %16, %23 ], [ %35, %34 ]
%38 = load i64, i64* @LINES
%39 = add nsw i64 %38, -1
%40 = call i32 @mvaddstr(i64 %39, i32 1, i8* %2)
%41 = call i32 (...) @clrtoeol()
%42 = call i32 (...) @refresh()
%43 = call i32 (...) @getch()
%44 = icmp ugt i32 %43, 255
%45 = icmp eq i32 %43, 27
%46 = or i1 %44, %45
br i1 %46, label %47, label %14
47: ; preds = %36, %0, %17
%48 = load i64, i64* @LINES
%49 = add nsw i64 %48, -1
%50 = call i32 @move(i64 %49, i32 0)
%51 = call i32 (...) @clrtoeol()
%52 = call i32 (...) @display()
ret i32 0
}