#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*/ exit(int);
char *fgets(char *, int const, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strtol(char *, char **, int);
int get_number(void) {
  char *number, *r;
  const int size = 4;
  int value, x;
  number = (char *)malloc(sizeof(char) * size);
  if (number == NULL) {
    fprintf(stderr, "Unable to allocate memory\n");
    exit(1);
  }
  r = fgets(number, size, stdin);
  if (r == NULL) {
    fprintf(stderr, "Input error\n");
    exit(1);
  }
  value = strtol(number, &r, 10);
  if (r == number) {
    fprintf(stderr, "Invalid input\n");
    exit(1);
  }
  if (value < 0 || value > 99) {
    printf("%d is out of range\n", value);
    exit(1);
  }
  for (x = 0; x < 4; x++)
    *(number + x) = '\0';
  free(number);
  return (value);
}


x86 assembly (clang, -O0):
<get_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x4,-0x14(%rbp)
mov    $0x4,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11b7 <get_number+0x47>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1050 <fgets@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11fc <get_number+0x8c>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe2e(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    123e <get_number+0xce>
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jl     1252 <get_number+0xe2>
cmpl   $0x63,-0x18(%rbp)
jle    126b <get_number+0xfb>
mov    -0x18(%rbp),%esi
lea    0xddb(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    1296 <get_number+0x126>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1272 <get_number+0x102>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_number>:
push   %rbp
push   %rbx
push   %rax
mov    $0x4,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     11d8 <get_number+0x68>
mov    %rax,%rbx
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <fgets@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     11ea <get_number+0x7a>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1070 <strtol@plt>
cmp    %rbx,(%rsp)
je     11fc <get_number+0x8c>
mov    %eax,%ebp
cmp    $0x63,%eax
ja     121b <get_number+0xab>
movl   $0x0,(%rbx)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
jmp    120c <get_number+0x9c>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
jmp    120c <get_number+0x9c>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe1c(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe15(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Unable to allocate memory\0A\00"
@stdin = global i32 0
@.str.1 = [13 x i8] c"Input error\0A\00"
@.str.2 = [15 x i8] c"Invalid input\0A\00"
@.str.3 = [20 x i8] c"%d is out of range\0A\00"
define i32 @get_number() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 4, i32* %3
%6 = call i64 @malloc(i32 4)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = load i8*, i8** %1
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = load i8*, i8** %1
%16 = load i32, i32* @stdin
%17 = call i8* @fgets(i8* %15, i32 4, i32 %16)
store i8* %17, i8** %2
%18 = load i8*, i8** %2
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %14
%25 = load i8*, i8** %1
%26 = call i32 @strtol(i8* %25, i8** %2, i32 10)
store i32 %26, i32* %4
%27 = load i8*, i8** %2
%28 = load i8*, i8** %1
%29 = icmp eq i8* %27, %28
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %24
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 0
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 99
br i1 %39, label %40, label %44
40: ; preds = %37, %34
%41 = load i32, i32* %4
%42 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %41)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
store i32 0, i32* %5
br label %45
45: ; preds = %53, %44
%46 = load i32, i32* %5
%47 = icmp slt i32 %46, 4
br i1 %47, label %48, label %56
48: ; preds = %45
%49 = load i8*, i8** %1
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
store i8 0, i8* %52
br label %53
53: ; preds = %48
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %45
56: ; preds = %45
%57 = load i8*, i8** %1
%58 = call i32 @free(i8* %57)
%59 = load i32, i32* %4
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Unable to allocate memory\0A\00"
@stdin = global i32 0
@.str.1 = [13 x i8] c"Input error\0A\00"
@.str.2 = [15 x i8] c"Invalid input\0A\00"
@.str.3 = [20 x i8] c"%d is out of range\0A\00"
define i32 @get_number() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = tail call i64 @malloc(i32 4)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @stdin
%12 = tail call i8* @fgets(i8* %4, i32 4, i32 %11)
store i8* %12, i8** %1
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = call i32 @strtol(i8* %4, i8** %1, i32 10)
%20 = load i8*, i8** %1
%21 = icmp eq i8* %20, %4
br i1 %21, label %22, label %26
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = icmp ugt i32 %19, 99
br i1 %27, label %31, label %28
28: ; preds = %26
%29 = inttoptr i64 %3 to i32*
store i32 0, i32* %29
%30 = tail call i32 @free(i8* %4)
ret i32 %19
31: ; preds = %26
%32 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%33 = tail call i32 @exit(i32 1)
unreachable
}