#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char read_num = '0';
  int num = 0;
  printf("Type chars\n");
  while (read_num <= 57 && read_num >= 48) {
    printf("> ");
    num = num * 10 + (read_num - 48);
    scanf(" %c", &read_num);
  }
  if (num != 0)
    printf("%d\n", num);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x30,-0x5(%rbp)
movl   $0x0,-0xc(%rbp)
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsbl -0x5(%rbp),%ecx
xor    %eax,%eax
cmp    $0x39,%ecx
mov    %al,-0xd(%rbp)
jg     1167 <main+0x47>
movsbl -0x5(%rbp),%eax
cmp    $0x30,%eax
setge  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1177 <main+0x57>
jmp    11aa <main+0x8a>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
imul   $0xa,-0xc(%rbp),%eax
movsbl -0x5(%rbp),%ecx
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
lea    0xe73(%rip),%rdi
lea    -0x5(%rbp),%rsi
call   1040 <scanf@plt>
jmp    1148 <main+0x28>
cmpl   $0x0,-0xc(%rbp)
je     11c5 <main+0xa5>
mov    -0xc(%rbp),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movb   $0x30,0x7(%rsp)
lea    0xec7(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%r14
lea    0xeac(%rip),%r15
lea    0x7(%rsp),%r12
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    (%rbx,%rbx,4),%eax
movsbl 0x7(%rsp),%ecx
lea    (%rcx,%rax,2),%ebx
add    $0xffffffd0,%ebx
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
movzbl 0x7(%rsp),%eax
add    $0xd0,%al
cmp    $0xa,%al
jb     1160 <main+0x30>
test   %ebx,%ebx
je     11a2 <main+0x72>
lea    0xe6e(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [12 x i8] c"Type chars\0A\00"
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %1
store i8 48, i8* %2
store i32 0, i32* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %15, %0
%6 = load i8, i8* %2
%7 = sext i8 %6 to i32
%8 = icmp sle i32 %7, 57
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i8, i8* %2
%11 = sext i8 %10 to i32
%12 = icmp sge i32 %11, 48
br label %13
13: ; preds = %9, %5
%14 = phi i1 [ false, %5 ], [ %12, %9 ]
br i1 %14, label %15, label %24
15: ; preds = %13
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* %3
%18 = mul nsw i32 %17, 10
%19 = load i8, i8* %2
%20 = sext i8 %19 to i32
%21 = sub nsw i32 %20, 48
%22 = add nsw i32 %18, %21
store i32 %22, i32* %3
%23 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %5
24: ; preds = %13
%25 = load i32, i32* %3
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %3
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %27, %24
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"> \00"
@.str.2 = [4 x i8] c" %c\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@str = [11 x i8] c"Type chars\00"
define i32 @main() {
%1 = alloca i8
store i8 48, i8* %1
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ %10, %3 ], [ 0, %0 ]
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = mul nsw i32 %4, 10
%7 = load i8, i8* %1
%8 = sext i8 %7 to i32
%9 = add i32 %6, -48
%10 = add i32 %9, %8
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%12 = load i8, i8* %1
%13 = add i8 %12, -48
%14 = icmp ult i8 %13, 10
br i1 %14, label %3, label %15
15: ; preds = %3
%16 = icmp eq i32 %10, 0
br i1 %16, label %19, label %17
17: ; preds = %15
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %10)
br label %19
19: ; preds = %17, %15
ret i32 0
}