#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(char);
char getch();
int /*<<< orphan*/ refresh();
int getnum() {
  char ch;
  int num = 0;
  for (ch = getch(), addch(ch), refresh(); ch >= '0' && ch <= '9';
       ch = getch(), addch(ch), refresh()) {
    num = num * 10 + ch - '0';
  }
  return num;
}


x86 assembly (clang, -O0):
<getnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getch@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <addch@plt>
mov    $0x0,%al
call   1040 <refresh@plt>
movsbl -0x1(%rbp),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x9(%rbp)
jl     1178 <getnum+0x48>
movsbl -0x1(%rbp),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%al
test   $0x1,%al
jne    1188 <getnum+0x58>
jmp    11b7 <getnum+0x87>
imul   $0xa,-0x8(%rbp),%eax
movsbl -0x1(%rbp),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getch@plt>
mov    %al,-0x1(%rbp)
movsbl -0x1(%rbp),%edi
call   1030 <addch@plt>
mov    $0x0,%al
call   1040 <refresh@plt>
jmp    1159 <getnum+0x29>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getnum>:
push   %rbp
push   %r14
push   %rbx
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <getch@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1030 <addch@plt>
xor    %eax,%eax
call   1040 <refresh@plt>
lea    -0x30(%rbx),%eax
cmp    $0x9,%al
ja     1193 <getnum+0x63>
xor    %r14d,%r14d
nopl   0x0(%rax)
movzbl %bl,%eax
lea    (%r14,%r14,4),%ecx
lea    (%rax,%rcx,2),%r14d
add    $0xffffffd0,%r14d
xor    %eax,%eax
call   1050 <getch@plt>
mov    %eax,%ebx
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <addch@plt>
xor    %eax,%eax
call   1040 <refresh@plt>
add    $0xd0,%bpl
cmp    $0xa,%bpl
jb     1160 <getnum+0x30>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @getnum() {
%1 = alloca i8
%2 = alloca i32
store i32 0, i32* %2
%3 = call signext i8 (...) @getch()
store i8 %3, i8* %1
%4 = load i8, i8* %1
%5 = call i32 @addch(i8 signext %4)
%6 = call i32 (...) @refresh()
br label %7
7: ; preds = %24, %0
%8 = load i8, i8* %1
%9 = sext i8 %8 to i32
%10 = icmp sge i32 %9, 48
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = load i8, i8* %1
%13 = sext i8 %12 to i32
%14 = icmp sle i32 %13, 57
br label %15
15: ; preds = %11, %7
%16 = phi i1 [ false, %7 ], [ %14, %11 ]
br i1 %16, label %17, label %29
17: ; preds = %15
%18 = load i32, i32* %2
%19 = mul nsw i32 %18, 10
%20 = load i8, i8* %1
%21 = sext i8 %20 to i32
%22 = add nsw i32 %19, %21
%23 = sub nsw i32 %22, 48
store i32 %23, i32* %2
br label %24
24: ; preds = %17
%25 = call signext i8 (...) @getch()
store i8 %25, i8* %1
%26 = load i8, i8* %1
%27 = call i32 @addch(i8 signext %26)
%28 = call i32 (...) @refresh()
br label %7
29: ; preds = %15
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @getnum() {
%1 = tail call signext i8 (...) @getch()
%2 = tail call i32 @addch(i8 signext %1)
%3 = tail call i32 (...) @refresh()
%4 = add i8 %1, -48
%5 = icmp ult i8 %4, 10
br i1 %5, label %6, label %18
6: ; preds = %0, %6
%7 = phi i32 [ %12, %6 ], [ 0, %0 ]
%8 = phi i8 [ %13, %6 ], [ %1, %0 ]
%9 = zext i8 %8 to i32
%10 = mul nsw i32 %7, 10
%11 = add nsw i32 %9, -48
%12 = add i32 %11, %10
%13 = tail call signext i8 (...) @getch()
%14 = tail call i32 @addch(i8 signext %13)
%15 = tail call i32 (...) @refresh()
%16 = add i8 %13, -48
%17 = icmp ult i8 %16, 10
br i1 %17, label %6, label %18
18: ; preds = %6, %0
%19 = phi i32 [ 0, %0 ], [ %12, %6 ]
ret i32 %19
}