#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 strlen(char *);
int validate_number(char *number) {
  if (strlen(number) > 10)
    return 2;
  int i = 0;
  int err = 0;
  while (i < strlen(number)) {
    int ascii = (int)number[i];
    if (ascii < 48 || ascii > 57) {
      err = 1;
    }
    i++;
  }
  if (err)
    return 2;
  return 0;
}


x86 assembly (clang, -O0):
<validate_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0xa,%eax
jle    113a <validate_number+0x2a>
movl   $0x2,-0x4(%rbp)
jmp    11b9 <validate_number+0xa9>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    119c <validate_number+0x8c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x30,-0x1c(%rbp)
jl     1187 <validate_number+0x77>
cmpl   $0x39,-0x1c(%rbp)
jle    118e <validate_number+0x7e>
movl   $0x1,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <validate_number+0x38>
cmpl   $0x0,-0x18(%rbp)
je     11b2 <validate_number+0xa2>
movl   $0x2,-0x4(%rbp)
jmp    11b9 <validate_number+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_number>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    $0xa,%ecx
jg     117d <validate_number+0x6d>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    117b <validate_number+0x6b>
xor    %ebx,%ebx
mov    $0x1,%r15d
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%eax
add    $0xc6,%al
cmp    $0xf6,%al
cmovb  %r15d,%ebp
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1150 <validate_number+0x40>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
add    %eax,%eax
jmp    117d <validate_number+0x6d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @validate_number(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = icmp sgt i32 %8, 10
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 2, i32* %2
br label %38
11: ; preds = %1
store i32 0, i32* %4
store i32 0, i32* %5
br label %12
12: ; preds = %30, %11
%13 = load i32, i32* %4
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %13, %15
br i1 %16, label %17, label %33
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
store i32 %23, i32* %6
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 48
br i1 %25, label %29, label %26
26: ; preds = %17
%27 = load i32, i32* %6
%28 = icmp sgt i32 %27, 57
br i1 %28, label %29, label %30
29: ; preds = %26, %17
store i32 1, i32* %5
br label %30
30: ; preds = %29, %26
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %12
33: ; preds = %12
%34 = load i32, i32* %5
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 2, i32* %2
br label %38
37: ; preds = %33
store i32 0, i32* %2
br label %38
38: ; preds = %37, %36, %10
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
define i32 @validate_number(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 10
br i1 %3, label %22, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %4, %7
%8 = phi i64 [ %15, %7 ], [ 0, %4 ]
%9 = phi i32 [ %14, %7 ], [ 0, %4 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = add i8 %11, -58
%13 = icmp ult i8 %12, -10
%14 = select i1 %13, i32 1, i32 %9
%15 = add nuw nsw i64 %8, 1
%16 = tail call i32 @strlen(i8* %0)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %7, label %19
19: ; preds = %7
%20 = icmp eq i32 %14, 0
%21 = select i1 %20, i32 0, i32 2
br label %22
22: ; preds = %4, %19, %1
%23 = phi i32 [ 2, %1 ], [ 0, %4 ], [ %21, %19 ]
ret i32 %23
}