#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 getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int geti(void) {
  int val = 0;
  int ch, digits = 0;
  while (1) {
    ch = getchar();
    if (ch == '\n' || ch == '\r') {
      putchar('\n');
      break;
    } else if ((ch == '\b' || ch == 127) && digits > 0) {
      printf("\b \b");
      val = val / 10;
      digits--;
    } else if (ch >= '0' && ch <= '9') {
      putchar(ch);
      val = val * 10 + (ch - '0');
      digits++;
    } else {
      putchar('\a');
    }
  }
  if (digits == 0) {
    return -1;
  }
  return val;
}


x86 assembly (clang, -O0):
<geti>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
je     1164 <geti+0x34>
cmpl   $0xd,-0xc(%rbp)
jne    1173 <geti+0x43>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    120e <geti+0xde>
cmpl   $0x8,-0xc(%rbp)
je     1187 <geti+0x57>
cmpl   $0x7f,-0xc(%rbp)
jne    11b9 <geti+0x89>
cmpl   $0x0,-0x10(%rbp)
jle    11b9 <geti+0x89>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1204 <geti+0xd4>
cmpl   $0x30,-0xc(%rbp)
jl     11f5 <geti+0xc5>
cmpl   $0x39,-0xc(%rbp)
jg     11f5 <geti+0xc5>
mov    -0xc(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
imul   $0xa,-0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11ff <geti+0xcf>
mov    $0x7,%edi
call   1030 <putchar@plt>
jmp    1204 <geti+0xd4>
jmp    1209 <geti+0xd9>
jmp    1146 <geti+0x16>
cmpl   $0x0,-0x10(%rbp)
jne    1224 <geti+0xf4>
movl   $0xffffffff,-0x4(%rbp)
jmp    122a <geti+0xfa>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<geti>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec2(%rip),%r14
xor    %r15d,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xd,%eax
je     11c3 <geti+0x93>
cmp    $0xa,%eax
je     11c3 <geti+0x93>
cmp    $0x8,%eax
setne  %cl
cmp    $0x7f,%eax
setne  %dl
test   %dl,%cl
jne    1175 <geti+0x45>
test   %ebp,%ebp
jg     1189 <geti+0x59>
lea    -0x30(%rax),%ebx
cmp    $0x9,%ebx
jbe    11ae <geti+0x7e>
mov    $0x7,%edi
call   1030 <putchar@plt>
jmp    1150 <geti+0x20>
mov    %r14,%rdi
call   1040 <printf@plt>
movslq %r15d,%rax
imul   $0x66666667,%rax,%r15
mov    %r15,%rax
shr    $0x3f,%rax
sar    $0x22,%r15
add    %eax,%r15d
add    $0xffffffff,%ebp
jmp    1150 <geti+0x20>
movsbl %al,%edi
call   1030 <putchar@plt>
lea    (%r15,%r15,4),%eax
lea    (%rbx,%rax,2),%r15d
add    $0x1,%ebp
jmp    1150 <geti+0x20>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x1,%ebp
sbb    %eax,%eax
or     %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"\08 \08\00"
define i32 @geti() {
br label %1
1: ; preds = %20, %0
%2 = phi i32 [ 0, %0 ], [ %21, %20 ]
%3 = phi i32 [ 0, %0 ], [ %22, %20 ]
%4 = icmp sgt i32 %3, 0
br label %5
5: ; preds = %1, %32
%6 = tail call i32 (...) @getchar()
switch i32 %6, label %11 [
i32 13, label %7
i32 10, label %7
]
7: ; preds = %5, %5
%8 = tail call i32 @putchar(i8 signext 10)
%9 = icmp eq i32 %3, 0
%10 = select i1 %9, i32 -1, i32 %2
ret i32 %10
11: ; preds = %5
%12 = icmp eq i32 %6, 8
%13 = icmp eq i32 %6, 127
%14 = or i1 %12, %13
%15 = select i1 %14, i1 %4, i1 false
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%18 = sdiv i32 %2, 10
%19 = add nsw i32 %3, -1
br label %20
20: ; preds = %16, %26
%21 = phi i32 [ %30, %26 ], [ %18, %16 ]
%22 = phi i32 [ %31, %26 ], [ %19, %16 ]
br label %1
23: ; preds = %11
%24 = add i32 %6, -48
%25 = icmp ult i32 %24, 10
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = trunc i32 %6 to i8
%28 = tail call i32 @putchar(i8 signext %27)
%29 = mul nsw i32 %2, 10
%30 = add nsw i32 %24, %29
%31 = add nsw i32 %3, 1
br label %20
32: ; preds = %23
%33 = tail call i32 @putchar(i8 signext 7)
br label %5
}