#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*/ exit(int /*<<< orphan*/);
char getch();
int /*<<< orphan*/ putchar(char);
void inputnumstr(char *a, int len) {
  int i = 0;
  char b;
getchnumstr:
  while ((b = getch()) != 13) {
    if (b == 3) {
      exit(0);
    }
    if (b != 127) {
      if (i > len) {
        goto getchnumstr;
      }
      if (b >= '0' && b <= '9') {
        putchar(b);
        a[i] = b;
        i++;
      }
    } else {
      if (i > 0) {
        i--;
        putchar('\b');
        putchar(' ');
        putchar('\b');
      }
    }
  }
  if (i == 0) {
    goto getchnumstr;
  }
  a[i] = '\0';
  putchar('\n');
}


x86 assembly (clang, -O0):
<inputnumstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    114b <inputnumstr+0x1b>
mov    $0x0,%al
call   1040 <getch@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0xd,%eax
je     120d <inputnumstr+0xdd>
movsbl -0x11(%rbp),%eax
cmp    $0x3,%eax
jne    1175 <inputnumstr+0x45>
xor    %edi,%edi
call   1050 <exit@plt>
movsbl -0x11(%rbp),%eax
cmp    $0x7f,%eax
je     11d2 <inputnumstr+0xa2>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1193 <inputnumstr+0x63>
jmp    1146 <inputnumstr+0x16>
movsbl -0x11(%rbp),%eax
cmp    $0x30,%eax
jl     11cd <inputnumstr+0x9d>
movsbl -0x11(%rbp),%eax
cmp    $0x39,%eax
jg     11cd <inputnumstr+0x9d>
movsbl -0x11(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x11(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1208 <inputnumstr+0xd8>
cmpl   $0x0,-0x10(%rbp)
jle    1203 <inputnumstr+0xd3>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
jmp    1208 <inputnumstr+0xd8>
jmp    114b <inputnumstr+0x1b>
cmpl   $0x0,-0x10(%rbp)
jne    121c <inputnumstr+0xec>
jmp    1146 <inputnumstr+0x16>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputnumstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %eax,%eax
jmp    1173 <inputnumstr+0x43>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    $0x8,%edi
call   1030 <putchar@plt>
mov    %ebp,%eax
mov    %eax,%ebp
jmp    1184 <inputnumstr+0x54>
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jg     1150 <inputnumstr+0x20>
xor    %eax,%eax
call   1040 <getch@plt>
cmp    $0x7f,%al
je     1180 <inputnumstr+0x50>
mov    %eax,%ebx
cmp    $0xd,%al
je     11c0 <inputnumstr+0x90>
cmp    $0x3,%bl
je     11e5 <inputnumstr+0xb5>
cmp    %r15d,%ebp
jg     1184 <inputnumstr+0x54>
lea    -0x30(%rbx),%eax
cmp    $0x9,%al
ja     1184 <inputnumstr+0x54>
movsbl %bl,%edi
call   1030 <putchar@plt>
movslq %ebp,%rax
mov    %bl,(%r14,%rax,1)
add    $0x1,%ebp
mov    %ebp,%eax
jmp    1173 <inputnumstr+0x43>
nopl   0x0(%rax)
mov    $0x0,%eax
test   %ebp,%ebp
je     1173 <inputnumstr+0x43>
movslq %ebp,%rax
movb   $0x0,(%r14,%rax,1)
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
define void @inputnumstr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %60, %26, %2
br label %8
8: ; preds = %56, %7
%9 = call signext i8 (...) @getch()
store i8 %9, i8* %6
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 13
br i1 %11, label %12, label %57
12: ; preds = %8
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 3
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %12
%19 = load i8, i8* %6
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 127
br i1 %21, label %22, label %46
22: ; preds = %18
%23 = load i32, i32* %5
%24 = load i32, i32* %4
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22
br label %7
27: ; preds = %22
%28 = load i8, i8* %6
%29 = sext i8 %28 to i32
%30 = icmp sge i32 %29, 48
br i1 %30, label %31, label %45
31: ; preds = %27
%32 = load i8, i8* %6
%33 = sext i8 %32 to i32
%34 = icmp sle i32 %33, 57
br i1 %34, label %35, label %45
35: ; preds = %31
%36 = load i8, i8* %6
%37 = call i32 @putchar(i8 signext %36)
%38 = load i8, i8* %6
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %45
45: ; preds = %35, %31, %27
br label %56
46: ; preds = %18
%47 = load i32, i32* %5
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %46
%50 = load i32, i32* %5
%51 = add nsw i32 %50, -1
store i32 %51, i32* %5
%52 = call i32 @putchar(i8 signext 8)
%53 = call i32 @putchar(i8 signext 32)
%54 = call i32 @putchar(i8 signext 8)
br label %55
55: ; preds = %49, %46
br label %56
56: ; preds = %55, %45
br label %8
57: ; preds = %8
%58 = load i32, i32* %5
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %57
br label %7
61: ; preds = %57
%62 = load i8*, i8** %3
%63 = load i32, i32* %5
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
%66 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
define void @inputnumstr(i8* nocapture writeonly %0, i32 %1) {
br label %3
3: ; preds = %20, %2
%4 = phi i32 [ 0, %2 ], [ %21, %20 ]
%5 = icmp sgt i32 %4, 0
%6 = icmp sle i32 %4, %1
br label %7
7: ; preds = %23, %3
%8 = tail call signext i8 (...) @getch()
switch i8 %8, label %11 [
i8 13, label %29
i8 3, label %9
i8 127, label %22
]
9: ; preds = %7
%10 = tail call i32 @exit(i32 0)
unreachable
11: ; preds = %7
%12 = add i8 %8, -48
%13 = icmp ult i8 %12, 10
%14 = select i1 %6, i1 %13, i1 false
br i1 %14, label %15, label %23
15: ; preds = %11
%16 = tail call i32 @putchar(i8 signext %8)
%17 = sext i32 %4 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 %8, i8* %18
%19 = add nsw i32 %4, 1
br label %20
20: ; preds = %15, %24, %29
%21 = phi i32 [ 0, %29 ], [ %25, %24 ], [ %19, %15 ]
br label %3
22: ; preds = %7
br i1 %5, label %24, label %23
23: ; preds = %22, %11
br label %7
24: ; preds = %22
%25 = add nsw i32 %4, -1
%26 = tail call i32 @putchar(i8 signext 8)
%27 = tail call i32 @putchar(i8 signext 32)
%28 = tail call i32 @putchar(i8 signext 8)
br label %20
29: ; preds = %7
%30 = icmp eq i32 %4, 0
br i1 %30, label %20, label %31
31: ; preds = %29
%32 = sext i32 %4 to i64
%33 = getelementptr inbounds i8, i8* %0, i64 %32
store i8 0, i8* %33
%34 = tail call i32 @putchar(i8 signext 10)
ret void
}