#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 /*<<< orphan*/ addch(char);
int /*<<< orphan*/ clearok(int /*<<< orphan*/, int);
int /*<<< orphan*/ clrtoeol();
int getch();
int /*<<< orphan*/ getyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ islower(int);
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stdscr;
void getword(char *q) {
  int ch, col, done, i, row;
  char *p;
  done = 0;
  i = 0;
  p = q;
  addch('[');
  refresh();
  while (!done && i < 40 - 1) {
    ch = getch() & 0177;
    switch (ch) {
    case '\177':
    case '\010':
      if (p == q)
        break;
      p--;
      getyx(stdscr, row, col);
      move(row, col - 1);
      clrtoeol();
      break;
    case '\025':
    case '\027':
      if (p == q)
        break;
      getyx(stdscr, row, col);
      move(row, col - (int)(p - q));
      p = q;
      clrtoeol();
      break;
    case ' ':
    case '\n':
    case '\r':
      done = 1;
      break;
    case '\014':
    case '\022':
      clearok(stdscr, 1);
      refresh();
      break;
    default:
      if (islower(ch)) {
        *p++ = ch;
        addch(ch);
        i++;
      }
      break;
    }
    refresh();
  }
  *p = '\0';
  addch(']');
  refresh();
}


x86 assembly (clang, -O0):
<getword>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x5b,%edi
call   1060 <addch@plt>
mov    $0x0,%al
call   1070 <refresh@plt>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x29(%rbp)
jne    11cc <getword+0x4c>
cmpl   $0x27,-0x18(%rbp)
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11dc <getword+0x5c>
jmp    139c <getword+0x21c>
xor    %eax,%eax
call   1080 <getch@plt>
and    $0x7f,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
sub    $0x8,%eax
je     1285 <getword+0x105>
jmp    11fd <getword+0x7d>
mov    -0x30(%rbp),%eax
sub    $0xa,%eax
je     1325 <getword+0x1a5>
jmp    120e <getword+0x8e>
mov    -0x30(%rbp),%eax
sub    $0xc,%eax
je     1331 <getword+0x1b1>
jmp    121f <getword+0x9f>
mov    -0x30(%rbp),%eax
sub    $0xd,%eax
je     1325 <getword+0x1a5>
jmp    1230 <getword+0xb0>
mov    -0x30(%rbp),%eax
sub    $0x12,%eax
je     1331 <getword+0x1b1>
jmp    1241 <getword+0xc1>
mov    -0x30(%rbp),%eax
sub    $0x15,%eax
je     12d2 <getword+0x152>
jmp    1252 <getword+0xd2>
mov    -0x30(%rbp),%eax
sub    $0x17,%eax
je     12d2 <getword+0x152>
jmp    1263 <getword+0xe3>
mov    -0x30(%rbp),%eax
sub    $0x20,%eax
je     1325 <getword+0x1a5>
jmp    1274 <getword+0xf4>
mov    -0x30(%rbp),%eax
sub    $0x7f,%eax
jne    1350 <getword+0x1d0>
jmp    1285 <getword+0x105>
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    1298 <getword+0x118>
jmp    1390 <getword+0x210>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <getyx@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
call   10a0 <move@plt>
mov    $0x0,%al
call   1090 <clrtoeol@plt>
jmp    1390 <getword+0x210>
mov    -0x28(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    12e5 <getword+0x165>
jmp    1390 <getword+0x210>
mov    0x2cfc(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <getyx@plt>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
sub    %eax,%esi
call   10a0 <move@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1090 <clrtoeol@plt>
jmp    1390 <getword+0x210>
movl   $0x1,-0x14(%rbp)
jmp    1390 <getword+0x210>
mov    0x2cb0(%rip),%rax
mov    (%rax),%edi
mov    $0x1,%esi
call   1030 <clearok@plt>
mov    $0x0,%al
call   1070 <refresh@plt>
jmp    1390 <getword+0x210>
mov    -0xc(%rbp),%edi
call   1040 <islower@plt>
cmp    $0x0,%eax
je     138b <getword+0x20b>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
movsbl %al,%edi
call   1060 <addch@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1390 <getword+0x210>
mov    $0x0,%al
call   1070 <refresh@plt>
jmp    11b3 <getword+0x33>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x5d,%edi
call   1060 <addch@plt>
mov    $0x0,%al
call   1070 <refresh@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getword>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x5b,%edi
call   1060 <addch@plt>
xor    %eax,%eax
call   1070 <refresh@plt>
mov    0x2e42(%rip),%r15
lea    0xe53(%rip),%r12
mov    %r14,%rbp
xor    %r13d,%r13d
jmp    11e5 <getword+0x65>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%edi
mov    $0x1,%esi
call   1030 <clearok@plt>
xor    %eax,%eax
call   1070 <refresh@plt>
xor    %eax,%eax
call   1070 <refresh@plt>
cmp    $0x27,%r13d
jge    1285 <getword+0x105>
xor    %eax,%eax
call   1080 <getch@plt>
mov    %eax,%ebx
and    $0x7f,%ebx
lea    -0x8(%rbx),%eax
cmp    $0x18,%eax
ja     1220 <getword+0xa0>
movslq (%r12,%rax,4),%rax
add    %r12,%rax
jmp    *%rax
cmp    %r14,%rbp
je     1250 <getword+0xd0>
mov    (%r15),%edi
call   1050 <getyx@plt>
call   10a0 <move@plt>
xor    %eax,%eax
call   1090 <clrtoeol@plt>
mov    %r14,%rbp
jmp    11d4 <getword+0x54>
cmp    $0x7f,%ebx
jne    1258 <getword+0xd8>
cmp    %r14,%rbp
je     1250 <getword+0xd0>
add    $0xffffffffffffffff,%rbp
mov    (%r15),%edi
call   1050 <getyx@plt>
call   10a0 <move@plt>
xor    %eax,%eax
call   1090 <clrtoeol@plt>
jmp    11d4 <getword+0x54>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rbp
jmp    11d4 <getword+0x54>
mov    %ebx,%edi
call   1040 <islower@plt>
test   %eax,%eax
je     11d4 <getword+0x54>
mov    %bl,0x0(%rbp)
add    $0x1,%rbp
mov    %ebx,%edi
call   1060 <addch@plt>
add    $0x1,%r13d
jmp    11d4 <getword+0x54>
xor    %eax,%eax
call   1070 <refresh@plt>
movb   $0x0,0x0(%rbp)
mov    $0x5d,%edi
call   1060 <addch@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <refresh@plt>

LLVM IR (-O0):
@stdscr = global i32 0
define void @getword(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %5
store i32 0, i32* %6
%9 = load i8*, i8** %2
store i8* %9, i8** %8
%10 = call i32 @addch(i8 signext 91)
%11 = call i32 (...) @refresh()
br label %12
12: ; preds = %83, %1
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = load i32, i32* %6
%17 = icmp slt i32 %16, 39
br label %18
18: ; preds = %15, %12
%19 = phi i1 [ false, %12 ], [ %17, %15 ]
br i1 %19, label %20, label %85
20: ; preds = %18
%21 = call i32 (...) @getch()
%22 = and i32 %21, 127
store i32 %22, i32* %3
%23 = load i32, i32* %3
switch i32 %23, label %68 [
i32 127, label %24
i32 8, label %24
i32 21, label %41
i32 23, label %41
i32 32, label %63
i32 10, label %63
i32 13, label %63
i32 12, label %64
i32 18, label %64
]
24: ; preds = %20, %20
%25 = load i8*, i8** %8
%26 = load i8*, i8** %2
%27 = icmp eq i8* %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
br label %83
29: ; preds = %24
%30 = load i8*, i8** %8
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %8
%32 = load i32, i32* @stdscr
%33 = load i32, i32* %7
%34 = load i32, i32* %4
%35 = call i32 @getyx(i32 %32, i32 %33, i32 %34)
%36 = load i32, i32* %7
%37 = load i32, i32* %4
%38 = sub nsw i32 %37, 1
%39 = call i32 @move(i32 %36, i32 %38)
%40 = call i32 (...) @clrtoeol()
br label %83
41: ; preds = %20, %20
%42 = load i8*, i8** %8
%43 = load i8*, i8** %2
%44 = icmp eq i8* %42, %43
br i1 %44, label %45, label %46
45: ; preds = %41
br label %83
46: ; preds = %41
%47 = load i32, i32* @stdscr
%48 = load i32, i32* %7
%49 = load i32, i32* %4
%50 = call i32 @getyx(i32 %47, i32 %48, i32 %49)
%51 = load i32, i32* %7
%52 = load i32, i32* %4
%53 = load i8*, i8** %8
%54 = load i8*, i8** %2
%55 = ptrtoint i8* %53 to i64
%56 = ptrtoint i8* %54 to i64
%57 = sub i64 %55, %56
%58 = trunc i64 %57 to i32
%59 = sub nsw i32 %52, %58
%60 = call i32 @move(i32 %51, i32 %59)
%61 = load i8*, i8** %2
store i8* %61, i8** %8
%62 = call i32 (...) @clrtoeol()
br label %83
63: ; preds = %20, %20, %20
store i32 1, i32* %5
br label %83
64: ; preds = %20, %20
%65 = load i32, i32* @stdscr
%66 = call i32 @clearok(i32 %65, i32 1)
%67 = call i32 (...) @refresh()
br label %83
68: ; preds = %20
%69 = load i32, i32* %3
%70 = call i32 @islower(i32 %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %82
72: ; preds = %68
%73 = load i32, i32* %3
%74 = trunc i32 %73 to i8
%75 = load i8*, i8** %8
%76 = getelementptr inbounds i8, i8* %75, i32 1
store i8* %76, i8** %8
store i8 %74, i8* %75
%77 = load i32, i32* %3
%78 = trunc i32 %77 to i8
%79 = call i32 @addch(i8 signext %78)
%80 = load i32, i32* %6
%81 = add nsw i32 %80, 1
store i32 %81, i32* %6
br label %82
82: ; preds = %72, %68
br label %83
83: ; preds = %82, %64, %63, %46, %45, %29, %28
%84 = call i32 (...) @refresh()
br label %12
85: ; preds = %18
%86 = load i8*, i8** %8
store i8 0, i8* %86
%87 = call i32 @addch(i8 signext 93)
%88 = call i32 (...) @refresh()
ret void
}

LLVM IR (-O2):
@stdscr = global i32 0
define void @getword(i8* writeonly %0) {
%2 = tail call i32 @addch(i8 signext 91)
%3 = tail call i32 (...) @refresh()
br label %4
4: ; preds = %1, %38
%5 = phi i8* [ %0, %1 ], [ %40, %38 ]
%6 = phi i32 [ 0, %1 ], [ %39, %38 ]
%7 = tail call i32 (...) @getch()
%8 = and i32 %7, 127
switch i32 %8, label %28 [
i32 127, label %9
i32 8, label %9
i32 21, label %17
i32 23, label %17
i32 32, label %36
i32 10, label %36
i32 13, label %36
i32 12, label %24
i32 18, label %24
]
9: ; preds = %4, %4
%10 = icmp eq i8* %5, %0
br i1 %10, label %38, label %11
11: ; preds = %9
%12 = getelementptr inbounds i8, i8* %5, i64 -1
%13 = load i32, i32* @stdscr
%14 = tail call i32 @getyx(i32 %13, i32 undef, i32 undef)
%15 = tail call i32 @move(i32 undef, i32 undef)
%16 = tail call i32 (...) @clrtoeol()
br label %38
17: ; preds = %4, %4
%18 = icmp eq i8* %5, %0
br i1 %18, label %38, label %19
19: ; preds = %17
%20 = load i32, i32* @stdscr
%21 = tail call i32 @getyx(i32 %20, i32 undef, i32 undef)
%22 = tail call i32 @move(i32 undef, i32 undef)
%23 = tail call i32 (...) @clrtoeol()
br label %38
24: ; preds = %4, %4
%25 = load i32, i32* @stdscr
%26 = tail call i32 @clearok(i32 %25, i32 1)
%27 = tail call i32 (...) @refresh()
br label %38
28: ; preds = %4
%29 = tail call i32 @islower(i32 %8)
%30 = icmp eq i32 %29, 0
br i1 %30, label %38, label %31
31: ; preds = %28
%32 = trunc i32 %8 to i8
%33 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %32, i8* %5
%34 = tail call i32 @addch(i8 signext %32)
%35 = add nsw i32 %6, 1
br label %38
36: ; preds = %4, %4, %4
%37 = tail call i32 (...) @refresh()
br label %43
38: ; preds = %28, %31, %17, %9, %24, %19, %11
%39 = phi i32 [ %6, %28 ], [ %35, %31 ], [ %6, %17 ], [ %6, %9 ], [ %6, %24 ], [ %6, %19 ], [ %6, %11 ]
%40 = phi i8* [ %5, %28 ], [ %33, %31 ], [ %0, %17 ], [ %0, %9 ], [ %5, %24 ], [ %0, %19 ], [ %12, %11 ]
%41 = tail call i32 (...) @refresh()
%42 = icmp slt i32 %39, 39
br i1 %42, label %4, label %43
43: ; preds = %38, %36
%44 = phi i8* [ %5, %36 ], [ %40, %38 ]
store i8 0, i8* %44
%45 = tail call i32 @addch(i8 signext 93)
%46 = tail call i32 (...) @refresh()
ret void
}