#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 getc(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main() {
  int number = 0;
  char c = 0;
  printf("Please enter a digit between 0 and 99: ");
  c = getc(stdin);
  if (c < '0' || c > '9') {
    printf("Invalid number!\n");
    return 1;
  }
  number += (c - '0');
  c = getc(stdin);
  if (c == '\n') {
    printf("Got %d\n", number);
    return 0;
  }
  if (c < '0' || c > '9') {
    printf("Invalid number!\n");
    return 1;
  }
  number *= 10;
  number += (c - '0');
  c = getc(stdin);
  if (c != '\n') {
    printf("Invalid number!\n");
    return 1;
  }
  printf("Got %d\n", number);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jl     1173 <main+0x53>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
jle    118d <main+0x6d>
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126d <main+0x14d>
movsbl -0x9(%rbp),%eax
sub    $0x30,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    11d5 <main+0xb5>
mov    -0x8(%rbp),%esi
lea    0xe77(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    126d <main+0x14d>
movsbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jl     11ef <main+0xcf>
movsbl -0x9(%rbp),%eax
cmp    $0x39,%eax
jle    1209 <main+0xe9>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126d <main+0x14d>
imul   $0xa,-0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movsbl -0x9(%rbp),%eax
sub    $0x30,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1040 <getc@plt>
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
je     1255 <main+0x135>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    126d <main+0x14d>
mov    -0x8(%rbp),%esi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e9f(%rip),%r14
mov    (%r14),%edi
call   1050 <getc@plt>
lea    -0x3a(%rax),%ecx
cmp    $0xf5,%cl
jbe    11ac <main+0x7c>
movzbl %al,%ebx
add    $0xffffffd0,%ebx
mov    (%r14),%edi
call   1050 <getc@plt>
cmp    $0xa,%al
jne    1178 <main+0x48>
lea    0xeb6(%rip),%rdi
xor    %ebp,%ebp
mov    %ebx,%esi
jmp    11a3 <main+0x73>
mov    %eax,%ebp
lea    -0x3a(%rbp),%eax
cmp    $0xf5,%al
jbe    11ac <main+0x7c>
mov    (%r14),%edi
call   1050 <getc@plt>
cmp    $0xa,%al
jne    11ac <main+0x7c>
movsbl %bpl,%eax
lea    (%rbx,%rbx,4),%ecx
lea    (%rax,%rcx,2),%esi
add    $0xffffffd0,%esi
lea    0xe87(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11bd <main+0x8d>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Please enter a digit between 0 and 99: \00"
@stdin = global i32 0
@.str.1 = [17 x i8] c"Invalid number!\0A\00"
@.str.2 = [8 x i8] c"Got %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
store i8 0, i8* %3
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @stdin
%6 = call signext i8 @getc(i32 %5)
store i8 %6, i8* %3
%7 = load i8, i8* %3
%8 = sext i8 %7 to i32
%9 = icmp slt i32 %8, 48
br i1 %9, label %14, label %10
10: ; preds = %0
%11 = load i8, i8* %3
%12 = sext i8 %11 to i32
%13 = icmp sgt i32 %12, 57
br i1 %13, label %14, label %16
14: ; preds = %10, %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %58
16: ; preds = %10
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = sub nsw i32 %18, 48
%20 = load i32, i32* %2
%21 = add nsw i32 %20, %19
store i32 %21, i32* %2
%22 = load i32, i32* @stdin
%23 = call signext i8 @getc(i32 %22)
store i8 %23, i8* %3
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %30
27: ; preds = %16
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %28)
store i32 0, i32* %1
br label %58
30: ; preds = %16
%31 = load i8, i8* %3
%32 = sext i8 %31 to i32
%33 = icmp slt i32 %32, 48
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i8, i8* %3
%36 = sext i8 %35 to i32
%37 = icmp sgt i32 %36, 57
br i1 %37, label %38, label %40
38: ; preds = %34, %30
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %58
40: ; preds = %34
%41 = load i32, i32* %2
%42 = mul nsw i32 %41, 10
store i32 %42, i32* %2
%43 = load i8, i8* %3
%44 = sext i8 %43 to i32
%45 = sub nsw i32 %44, 48
%46 = load i32, i32* %2
%47 = add nsw i32 %46, %45
store i32 %47, i32* %2
%48 = load i32, i32* @stdin
%49 = call signext i8 @getc(i32 %48)
store i8 %49, i8* %3
%50 = load i8, i8* %3
%51 = sext i8 %50 to i32
%52 = icmp ne i32 %51, 10
br i1 %52, label %53, label %55
53: ; preds = %40
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %1
br label %58
55: ; preds = %40
%56 = load i32, i32* %2
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %56)
store i32 0, i32* %1
br label %58
58: ; preds = %55, %53, %38, %27, %14
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
@.str = [40 x i8] c"Please enter a digit between 0 and 99: \00"
@stdin = global i32 0
@.str.2 = [8 x i8] c"Got %d\0A\00"
@str.4 = [16 x i8] c"Invalid number!\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @stdin
%3 = tail call signext i8 @getc(i32 %2)
%4 = add i8 %3, -58
%5 = icmp ult i8 %4, -10
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
br label %33
8: ; preds = %0
%9 = zext i8 %3 to i32
%10 = add nsw i32 %9, -48
%11 = load i32, i32* @stdin
%12 = tail call signext i8 @getc(i32 %11)
%13 = sext i8 %12 to i32
%14 = icmp eq i8 %12, 10
br i1 %14, label %15, label %17
15: ; preds = %8
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %33
17: ; preds = %8
%18 = add i8 %12, -58
%19 = icmp ult i8 %18, -10
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
br label %33
22: ; preds = %17
%23 = load i32, i32* @stdin
%24 = tail call signext i8 @getc(i32 %23)
%25 = icmp eq i8 %24, 10
br i1 %25, label %28, label %26
26: ; preds = %22
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0))
br label %33
28: ; preds = %22
%29 = mul nuw nsw i32 %10, 10
%30 = add nsw i32 %29, -48
%31 = add nsw i32 %30, %13
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %28, %26, %20, %15, %6
%34 = phi i32 [ 1, %6 ], [ 0, %15 ], [ 1, %20 ], [ 1, %26 ], [ 0, %28 ]
ret i32 %34
}