#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(int);
int /*<<< orphan*/ delch();
int getch();
int /*<<< orphan*/ getyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ stdscr;
int getint(void) {
  int t, in, x, y;
  t = 0;
  while (1) {
    in = getch();
    if ((in >= '0') && (in <= '9')) {
      t = t * 10 + (in - '0');
      addch(in);
    }
    if ((in == 8) && (t > 0)) {
      t = t / 10;
      getyx(stdscr, y, x);
      move(y, x - 1);
      delch();
    }
    if ((in == 459) || (in == 10))
      return t;
  }
}


x86 assembly (clang, -O0):
<getint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <getch@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x30,-0x8(%rbp)
jl     1194 <getint+0x44>
cmpl   $0x39,-0x8(%rbp)
jg     1194 <getint+0x44>
imul   $0xa,-0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <addch@plt>
cmpl   $0x8,-0x8(%rbp)
jne    11df <getint+0x8f>
cmpl   $0x0,-0x4(%rbp)
jle    11df <getint+0x8f>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <getyx@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
call   1070 <move@plt>
mov    $0x0,%al
call   1040 <delch@plt>
cmpl   $0x1cb,-0x8(%rbp)
je     11f6 <getint+0xa6>
cmpl   $0xa,-0x8(%rbp)
jne    11ff <getint+0xaf>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
jmp    115f <getint+0xf>

x86 assembly (clang, -O2):
<getint>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0xcccccccd,%r15d
mov    0x2e83(%rip),%r12
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <getch@plt>
mov    %eax,%ebx
lea    -0x30(%rbx),%eax
cmp    $0x9,%eax
ja     11a0 <getint+0x50>
lea    (%r14,%r14,4),%ecx
lea    (%rax,%rcx,2),%r14d
mov    %ebx,%edi
call   1050 <addch@plt>
jmp    11ca <getint+0x7a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x8,%ebx
jne    11ca <getint+0x7a>
test   %r14d,%r14d
jle    11ca <getint+0x7a>
mov    %r14d,%r14d
imul   %r15,%r14
shr    $0x23,%r14
mov    (%r12),%edi
call   1030 <getyx@plt>
call   1070 <move@plt>
xor    %eax,%eax
call   1040 <delch@plt>
cmp    $0x1cb,%ebx
je     11d7 <getint+0x87>
cmp    $0xa,%ebx
jne    1170 <getint+0x20>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdscr = global i32 0
define i32 @getint() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
br label %5
5: ; preds = %0, %46
%6 = call i32 (...) @getch()
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp sge i32 %7, 48
br i1 %8, label %9, label %20
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp sle i32 %10, 57
br i1 %11, label %12, label %20
12: ; preds = %9
%13 = load i32, i32* %1
%14 = mul nsw i32 %13, 10
%15 = load i32, i32* %2
%16 = sub nsw i32 %15, 48
%17 = add nsw i32 %14, %16
store i32 %17, i32* %1
%18 = load i32, i32* %2
%19 = call i32 @addch(i32 %18)
br label %20
20: ; preds = %12, %9, %5
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 8
br i1 %22, label %23, label %38
23: ; preds = %20
%24 = load i32, i32* %1
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = load i32, i32* %1
%28 = sdiv i32 %27, 10
store i32 %28, i32* %1
%29 = load i32, i32* @stdscr
%30 = load i32, i32* %4
%31 = load i32, i32* %3
%32 = call i32 @getyx(i32 %29, i32 %30, i32 %31)
%33 = load i32, i32* %4
%34 = load i32, i32* %3
%35 = sub nsw i32 %34, 1
%36 = call i32 @move(i32 %33, i32 %35)
%37 = call i32 (...) @delch()
br label %38
38: ; preds = %26, %23, %20
%39 = load i32, i32* %2
%40 = icmp eq i32 %39, 459
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = load i32, i32* %2
%43 = icmp eq i32 %42, 10
br i1 %43, label %44, label %46
44: ; preds = %41, %38
%45 = load i32, i32* %1
ret i32 %45
46: ; preds = %41
br label %5
}

LLVM IR (-O2):
@stdscr = global i32 0
define i32 @getint() {
br label %1
1: ; preds = %20, %0
%2 = phi i32 [ 0, %0 ], [ %21, %20 ]
%3 = tail call i32 (...) @getch()
%4 = add i32 %3, -48
%5 = icmp ult i32 %4, 10
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = mul nsw i32 %2, 10
%8 = add nsw i32 %4, %7
%9 = tail call i32 @addch(i32 %3)
br label %20
10: ; preds = %1
%11 = icmp eq i32 %3, 8
%12 = icmp sgt i32 %2, 0
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = udiv i32 %2, 10
%16 = load i32, i32* @stdscr
%17 = tail call i32 @getyx(i32 %16, i32 undef, i32 undef)
%18 = tail call i32 @move(i32 undef, i32 undef)
%19 = tail call i32 (...) @delch()
br label %20
20: ; preds = %6, %14, %10
%21 = phi i32 [ %15, %14 ], [ %2, %10 ], [ %8, %6 ]
switch i32 %3, label %1 [
i32 459, label %22
i32 10, label %22
]
22: ; preds = %20, %20
ret i32 %21
}