#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 readchar();
int /*<<< orphan*/ writechar(char);
int /*<<< orphan*/ writestr(char *);
void readnumstr(char *b, int sz) {
  char c;
  char *p;
  p = b;
  c = readchar();
  while (c != '\r') {
    if (c == 8 && p > b) {
      p--;
      writestr("\b \b");
    } else if (((c >= '0' && c <= '9') || c == '-') && p < (b + sz - 1)) {
      *p++ = c;
      writechar(c);
    } else
      writechar('\a');
    c = readchar();
  }
  *p = '\0';
}


x86 assembly (clang, -O0):
<readnumstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <readchar@plt>
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%eax
cmp    $0xd,%eax
je     1219 <readnumstr+0xe9>
movsbl -0xd(%rbp),%eax
cmp    $0x8,%eax
jne    1196 <readnumstr+0x66>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    1196 <readnumstr+0x66>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
lea    0xe74(%rip),%rdi
call   1050 <writestr@plt>
jmp    120a <readnumstr+0xda>
movsbl -0xd(%rbp),%eax
cmp    $0x30,%eax
jl     11b0 <readnumstr+0x80>
movsbl -0xd(%rbp),%eax
cmp    $0x39,%eax
jle    11bd <readnumstr+0x8d>
movsbl -0xd(%rbp),%eax
cmp    $0x2d,%eax
jne    11fb <readnumstr+0xcb>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rdx
add    %rdx,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jae    11fb <readnumstr+0xcb>
mov    -0xd(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movsbl -0xd(%rbp),%edi
call   1040 <writechar@plt>
jmp    1205 <readnumstr+0xd5>
mov    $0x7,%edi
call   1040 <writechar@plt>
jmp    120a <readnumstr+0xda>
mov    $0x0,%al
call   1030 <readchar@plt>
mov    %al,-0xd(%rbp)
jmp    1151 <readnumstr+0x21>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readnumstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
xor    %eax,%eax
call   1030 <readchar@plt>
movslq %ebp,%rcx
lea    (%r15,%rcx,1),%rbp
add    $0xffffffffffffffff,%rbp
lea    0xeab(%rip),%r14
mov    %r15,%rbx
jmp    1171 <readnumstr+0x41>
nopw   0x0(%rax,%rax,1)
mov    $0x7,%edi
call   1040 <writechar@plt>
xor    %eax,%eax
call   1030 <readchar@plt>
cmp    $0x8,%al
je     1180 <readnumstr+0x50>
cmp    $0xd,%al
jne    11a0 <readnumstr+0x70>
jmp    11c2 <readnumstr+0x92>
nopl   0x0(%rax,%rax,1)
cmp    %r15,%rbx
jbe    11a0 <readnumstr+0x70>
add    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
call   1050 <writestr@plt>
jmp    116a <readnumstr+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x30(%rax),%ecx
cmp    $0xa,%cl
setae  %cl
cmp    $0x2d,%al
setne  %dl
test   %cl,%dl
jne    1160 <readnumstr+0x30>
cmp    %rbp,%rbx
jae    1160 <readnumstr+0x30>
mov    %al,(%rbx)
add    $0x1,%rbx
movsbl %al,%edi
jmp    1165 <readnumstr+0x35>
movb   $0x0,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"\08 \08\00"
define void @readnumstr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %6
%8 = call signext i8 (...) @readchar()
store i8 %8, i8* %5
br label %9
9: ; preds = %54, %2
%10 = load i8, i8* %5
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 13
br i1 %12, label %13, label %56
13: ; preds = %9
%14 = load i8, i8* %5
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 8
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i8*, i8** %6
%19 = load i8*, i8** %3
%20 = icmp ugt i8* %18, %19
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 -1
store i8* %23, i8** %6
%24 = call i32 @writestr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %54
25: ; preds = %17, %13
%26 = load i8, i8* %5
%27 = sext i8 %26 to i32
%28 = icmp sge i32 %27, 48
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8, i8* %5
%31 = sext i8 %30 to i32
%32 = icmp sle i32 %31, 57
br i1 %32, label %37, label %33
33: ; preds = %29, %25
%34 = load i8, i8* %5
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 45
br i1 %36, label %37, label %51
37: ; preds = %33, %29
%38 = load i8*, i8** %6
%39 = load i8*, i8** %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
%43 = getelementptr inbounds i8, i8* %42, i64 -1
%44 = icmp ult i8* %38, %43
br i1 %44, label %45, label %51
45: ; preds = %37
%46 = load i8, i8* %5
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %6
store i8 %46, i8* %47
%49 = load i8, i8* %5
%50 = call i32 @writechar(i8 signext %49)
br label %53
51: ; preds = %37, %33
%52 = call i32 @writechar(i8 signext 7)
br label %53
53: ; preds = %51, %45
br label %54
54: ; preds = %53, %21
%55 = call signext i8 (...) @readchar()
store i8 %55, i8* %5
br label %9
56: ; preds = %9
%57 = load i8*, i8** %6
store i8 0, i8* %57
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"\08 \08\00"
define void @readnumstr(i8* writeonly %0, i32 %1) {
%3 = tail call signext i8 (...) @readchar()
%4 = sext i32 %1 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
br label %7
7: ; preds = %27, %2
%8 = phi i8 [ %3, %2 ], [ %29, %27 ]
%9 = phi i8* [ %0, %2 ], [ %28, %27 ]
switch i8 %8, label %15 [
i8 13, label %30
i8 8, label %10
]
10: ; preds = %7
%11 = icmp ugt i8* %9, %0
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = getelementptr inbounds i8, i8* %9, i64 -1
%14 = tail call i32 @writestr(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %27
15: ; preds = %7, %10
%16 = add i8 %8, -48
%17 = icmp ult i8 %16, 10
%18 = icmp eq i8 %8, 45
%19 = or i1 %18, %17
%20 = icmp ult i8* %9, %6
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %8, i8* %9
%24 = tail call i32 @writechar(i8 signext %8)
br label %27
25: ; preds = %15
%26 = tail call i32 @writechar(i8 signext 7)
br label %27
27: ; preds = %22, %25, %12
%28 = phi i8* [ %13, %12 ], [ %23, %22 ], [ %9, %25 ]
%29 = tail call signext i8 (...) @readchar()
br label %7
30: ; preds = %7
store i8 0, i8* %9
ret void
}