#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*/ flushinp();
int getch();
int /*<<< orphan*/ printw(char *, ...);
int /*<<< orphan*/ refresh();
scalar_t__ strcmp(char *, char *);
long strtol(char *, char **, int);
long get_num(int maxlen) {
  char number[maxlen + 1];
  int input, character = 0;
  long amount;
  while ((input = getch()) != '\n') {
    if (((input == 8) || (input == 127)) && (character == 0)) {
      refresh();
    } else if ((input == 8) || (input == 127)) {
      printw("%c", 8);
      printw(" ");
      printw("%c", 8);
      number[character] = '\0';
      character--;
      refresh();
    } else if (character >= maxlen) {
      refresh();
    } else if (input == '\33') {
      flushinp();
      refresh();
    } else if (((input == 'A') || (input == 'a')) && (character == 0) &&
               (maxlen > 1)) {
      printw("%c", input);
      number[character] = input;
      character++;
      refresh();
    } else if ((input < 48) || (input > 57)) {
      refresh();
    } else {
      printw("%c", input);
      number[character] = input;
      character++;
      refresh();
    }
  }
  number[character] = '\0';
  if ((strcmp(number, "A") == 0) || (strcmp(number, "a") == 0)) {
    amount = -1;
  } else {
    amount = strtol(number, (char **)NULL, 10);
  }
  return amount;
}


x86 assembly (clang, -O0):
<get_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1070 <getch@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xa,%eax
je     1343 <get_num+0x1e3>
cmpl   $0x8,-0x1c(%rbp)
je     11c2 <get_num+0x62>
cmpl   $0x7f,-0x1c(%rbp)
jne    11d8 <get_num+0x78>
cmpl   $0x0,-0x20(%rbp)
jne    11d8 <get_num+0x78>
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    133e <get_num+0x1de>
cmpl   $0x8,-0x1c(%rbp)
je     11ec <get_num+0x8c>
cmpl   $0x7f,-0x1c(%rbp)
jne    1241 <get_num+0xe1>
lea    0xe0d(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1050 <printw@plt>
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printw@plt>
lea    0xdec(%rip),%rdi
mov    $0x8,%esi
mov    $0x0,%al
call   1050 <printw@plt>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    1339 <get_num+0x1d9>
mov    -0x20(%rbp),%eax
cmp    -0x4(%rbp),%eax
jl     1259 <get_num+0xf9>
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    1334 <get_num+0x1d4>
cmpl   $0x1b,-0x1c(%rbp)
jne    1276 <get_num+0x116>
mov    $0x0,%al
call   1080 <flushinp@plt>
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    132f <get_num+0x1cf>
cmpl   $0x41,-0x1c(%rbp)
je     128a <get_num+0x12a>
cmpl   $0x61,-0x1c(%rbp)
jne    12d4 <get_num+0x174>
cmpl   $0x0,-0x20(%rbp)
jne    12d4 <get_num+0x174>
cmpl   $0x1,-0x4(%rbp)
jle    12d4 <get_num+0x174>
mov    -0x1c(%rbp),%esi
lea    0xd58(%rip),%rdi
mov    $0x0,%al
call   1050 <printw@plt>
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %cl,%dl
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    132a <get_num+0x1ca>
cmpl   $0x30,-0x1c(%rbp)
jl     12e8 <get_num+0x188>
cmpl   $0x39,-0x1c(%rbp)
jle    12f4 <get_num+0x194>
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    1325 <get_num+0x1c5>
mov    -0x1c(%rbp),%esi
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1050 <printw@plt>
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %cl,%dl
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1060 <refresh@plt>
jmp    132a <get_num+0x1ca>
jmp    132f <get_num+0x1cf>
jmp    1334 <get_num+0x1d4>
jmp    1339 <get_num+0x1d9>
jmp    133e <get_num+0x1de>
jmp    119b <get_num+0x3b>
mov    -0x30(%rbp),%rdi
movslq -0x20(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
lea    0xcaf(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     137f <get_num+0x21f>
mov    -0x30(%rbp),%rdi
lea    0xc97(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    138c <get_num+0x22c>
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
jmp    13a2 <get_num+0x242>
mov    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_num>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,-0x30(%rbp)
lea    0x1(%rdi),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
xor    %r14d,%r14d
xor    %eax,%eax
call   1070 <getch@plt>
cmp    $0xa,%eax
jne    11f1 <get_num+0x91>
movslq %r14d,%rax
movb   $0x0,0x0(%r13,%rax,1)
lea    0xe60(%rip),%rsi
mov    %r13,%rdi
call   1030 <strcmp@plt>
mov    $0xffffffffffffffff,%rbx
test   %rax,%rax
je     11df <get_num+0x7f>
lea    0xe47(%rip),%rsi
mov    %r13,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11df <get_num+0x7f>
mov    %r13,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    %rbx,%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
lea    0xe06(%rip),%r15
xor    %r12d,%r12d
jmp    1258 <get_num+0xf8>
nop
mov    %r15,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printw@plt>
lea    0xded(%rip),%rdi
xor    %eax,%eax
call   1050 <printw@plt>
mov    %r15,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1050 <printw@plt>
movslq %r12d,%rax
movb   $0x0,0x0(%r13,%rax,1)
add    $0xffffffff,%r12d
mov    %r12d,%r14d
xor    %eax,%eax
call   1060 <refresh@plt>
xor    %eax,%eax
call   1070 <getch@plt>
mov    %eax,%ebx
mov    %r14d,%r12d
cmp    $0xa,%eax
je     1195 <get_num+0x35>
cmp    $0x8,%ebx
setne  %al
cmp    $0x7f,%ebx
setne  %cl
test   %cl,%al
jne    1273 <get_num+0x113>
mov    $0x0,%r14d
test   %r12d,%r12d
je     123c <get_num+0xdc>
cmp    $0x7f,%ebx
je     1200 <get_num+0xa0>
cmp    $0x8,%ebx
je     1200 <get_num+0xa0>
cmp    -0x30(%rbp),%r12d
jge    1239 <get_num+0xd9>
cmp    $0x1b,%ebx
jne    1291 <get_num+0x131>
xor    %eax,%eax
call   1080 <flushinp@plt>
jmp    1239 <get_num+0xd9>
cmpl   $0x2,-0x30(%rbp)
jl     12c1 <get_num+0x161>
mov    %ebx,%eax
and    $0xffffffdf,%eax
cmp    $0x41,%eax
jne    12c1 <get_num+0x161>
test   %r12d,%r12d
jne    12c1 <get_num+0x161>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printw@plt>
mov    %bl,0x0(%r13)
mov    $0x1,%r14d
jmp    123c <get_num+0xdc>
lea    -0x3a(%rbx),%eax
cmp    $0xfffffff6,%eax
jb     1239 <get_num+0xd9>
mov    %r15,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printw@plt>
movslq %r12d,%rax
mov    %bl,0x0(%r13,%rax,1)
add    $0x1,%r12d
jmp    1239 <get_num+0xd9>

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"A\00"
@.str.3 = [2 x i8] c"a\00"
define i64 @get_num(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
store i32 %0, i32* %2
%8 = load i32, i32* %2
%9 = add nsw i32 %8, 1
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %3
%12 = alloca i8, i64 %10
store i64 %10, i64* %4
store i32 0, i32* %6
br label %13
13: ; preds = %102, %1
%14 = call i32 (...) @getch()
store i32 %14, i32* %5
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %103
16: ; preds = %13
%17 = load i32, i32* %5
%18 = icmp eq i32 %17, 8
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = load i32, i32* %5
%21 = icmp eq i32 %20, 127
br i1 %21, label %22, label %27
22: ; preds = %19, %16
%23 = load i32, i32* %6
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 (...) @refresh()
br label %102
27: ; preds = %22, %19
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 8
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, 127
br i1 %32, label %33, label %43
33: ; preds = %30, %27
%34 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 8)
%35 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 8)
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %12, i64 %38
store i8 0, i8* %39
%40 = load i32, i32* %6
%41 = add nsw i32 %40, -1
store i32 %41, i32* %6
%42 = call i32 (...) @refresh()
br label %101
43: ; preds = %30
%44 = load i32, i32* %6
%45 = load i32, i32* %2
%46 = icmp sge i32 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 (...) @refresh()
br label %100
49: ; preds = %43
%50 = load i32, i32* %5
%51 = icmp eq i32 %50, 27
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 (...) @flushinp()
%54 = call i32 (...) @refresh()
br label %99
55: ; preds = %49
%56 = load i32, i32* %5
%57 = icmp eq i32 %56, 65
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = load i32, i32* %5
%60 = icmp eq i32 %59, 97
br i1 %60, label %61, label %78
61: ; preds = %58, %55
%62 = load i32, i32* %6
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %78
64: ; preds = %61
%65 = load i32, i32* %2
%66 = icmp sgt i32 %65, 1
br i1 %66, label %67, label %78
67: ; preds = %64
%68 = load i32, i32* %5
%69 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %5
%71 = trunc i32 %70 to i8
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %12, i64 %73
store i8 %71, i8* %74
%75 = load i32, i32* %6
%76 = add nsw i32 %75, 1
store i32 %76, i32* %6
%77 = call i32 (...) @refresh()
br label %98
78: ; preds = %64, %61, %58
%79 = load i32, i32* %5
%80 = icmp slt i32 %79, 48
br i1 %80, label %84, label %81
81: ; preds = %78
%82 = load i32, i32* %5
%83 = icmp sgt i32 %82, 57
br i1 %83, label %84, label %86
84: ; preds = %81, %78
%85 = call i32 (...) @refresh()
br label %97
86: ; preds = %81
%87 = load i32, i32* %5
%88 = call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %5
%90 = trunc i32 %89 to i8
%91 = load i32, i32* %6
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %12, i64 %92
store i8 %90, i8* %93
%94 = load i32, i32* %6
%95 = add nsw i32 %94, 1
store i32 %95, i32* %6
%96 = call i32 (...) @refresh()
br label %97
97: ; preds = %86, %84
br label %98
98: ; preds = %97, %67
br label %99
99: ; preds = %98, %52
br label %100
100: ; preds = %99, %47
br label %101
101: ; preds = %100, %33
br label %102
102: ; preds = %101, %25
br label %13
103: ; preds = %13
%104 = load i32, i32* %6
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %12, i64 %105
store i8 0, i8* %106
%107 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%108 = icmp eq i64 %107, 0
br i1 %108, label %112, label %109
109: ; preds = %103
%110 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%111 = icmp eq i64 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %109, %103
store i64 -1, i64* %7
br label %115
113: ; preds = %109
%114 = call i64 @strtol(i8* %12, i8** null, i32 10)
store i64 %114, i64* %7
br label %115
115: ; preds = %113, %112
%116 = load i64, i64* %7
%117 = load i8*, i8** %3
ret i64 %116
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [2 x i8] c"A\00"
@.str.3 = [2 x i8] c"a\00"
define i64 @get_num(i32 %0) {
%2 = add nsw i32 %0, 1
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32 (...) @getch()
%6 = icmp eq i32 %5, 10
br i1 %6, label %53, label %7
7: ; preds = %1
%8 = icmp sgt i32 %0, 1
br label %9
9: ; preds = %7, %48
%10 = phi i32 [ %5, %7 ], [ %51, %48 ]
%11 = phi i32 [ 0, %7 ], [ %49, %48 ]
%12 = icmp eq i32 %10, 8
%13 = icmp eq i32 %10, 127
%14 = or i1 %12, %13
%15 = icmp eq i32 %11, 0
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %48, label %17
17: ; preds = %9
switch i32 %10, label %25 [
i32 127, label %18
i32 8, label %18
]
18: ; preds = %17, %17
%19 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 8)
%20 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 8)
%22 = sext i32 %11 to i64
%23 = getelementptr inbounds i8, i8* %4, i64 %22
store i8 0, i8* %23
%24 = add nsw i32 %11, -1
br label %48
25: ; preds = %17
%26 = icmp slt i32 %11, %0
br i1 %26, label %27, label %48
27: ; preds = %25
%28 = icmp eq i32 %10, 27
br i1 %28, label %29, label %31
29: ; preds = %27
%30 = tail call i32 (...) @flushinp()
br label %48
31: ; preds = %27
%32 = and i32 %10, -33
%33 = icmp eq i32 %32, 65
%34 = select i1 %33, i1 %15, i1 false
%35 = and i1 %8, %34
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%38 = trunc i32 %10 to i8
store i8 %38, i8* %4
br label %48
39: ; preds = %31
%40 = add i32 %10, -58
%41 = icmp ult i32 %40, -10
br i1 %41, label %48, label %42
42: ; preds = %39
%43 = tail call i32 (i8*, ...) @printw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %10)
%44 = trunc i32 %10 to i8
%45 = sext i32 %11 to i64
%46 = getelementptr inbounds i8, i8* %4, i64 %45
store i8 %44, i8* %46
%47 = add nsw i32 %11, 1
br label %48
48: ; preds = %39, %25, %9, %18, %29, %42, %36
%49 = phi i32 [ %24, %18 ], [ %11, %29 ], [ 1, %36 ], [ %47, %42 ], [ 0, %9 ], [ %11, %25 ], [ %11, %39 ]
%50 = tail call i32 (...) @refresh()
%51 = tail call i32 (...) @getch()
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %9
53: ; preds = %48, %1
%54 = phi i32 [ 0, %1 ], [ %49, %48 ]
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %4, i64 %55
store i8 0, i8* %56
%57 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %64, label %59
59: ; preds = %53
%60 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %64, label %62
62: ; preds = %59
%63 = call i64 @strtol(i8* nocapture %4, i8** null, i32 10)
br label %64
64: ; preds = %53, %59, %62
%65 = phi i64 [ %63, %62 ], [ -1, %59 ], [ -1, %53 ]
ret i64 %65
}