#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*/ isdigit(char);
int strlen(char *);
validate(char *a) {
  if (a[0] == '-') {
    if (strlen(a) > 4 || strlen(a) < 2) {
      return 0;
    }
    for (int x = 1; x < strlen(a); x++) {
      if (!isdigit(a[x]))
        return 0;
    }
    return 1;
  } else {
    if (strlen(a) > 3 || strlen(a) < 1) {
      return 0;
    }
    for (int x = 0; x < strlen(a); x++) {
      if (!isdigit(a[x]))
        return 0;
    }
    return 1;
  }
}


x86 assembly (clang, -O0):
<validate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11d4 <validate+0xb4>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jg     1160 <validate+0x40>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jge    116c <validate+0x4c>
movl   $0x0,-0x4(%rbp)
jmp    1267 <validate+0x147>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11c8 <validate+0xa8>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11b5 <validate+0x95>
movl   $0x0,-0x4(%rbp)
jmp    1267 <validate+0x147>
jmp    11ba <validate+0x9a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1173 <validate+0x53>
movl   $0x1,-0x4(%rbp)
jmp    1267 <validate+0x147>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jg     11f8 <validate+0xd8>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jge    1204 <validate+0xe4>
movl   $0x0,-0x4(%rbp)
jmp    1267 <validate+0x147>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    1260 <validate+0x140>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    124d <validate+0x12d>
movl   $0x0,-0x4(%rbp)
jmp    1267 <validate+0x147>
jmp    1252 <validate+0x132>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    120b <validate+0xeb>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    (%rdi),%bpl
call   1040 <strlen@plt>
xor    %r14d,%r14d
cmp    $0x2d,%bpl
jne    1198 <validate+0x78>
cmp    $0x4,%eax
jg     11e5 <validate+0xc5>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11e5 <validate+0xc5>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     1190 <validate+0x70>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11e5 <validate+0xc5>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1170 <validate+0x50>
mov    $0x1,%r14d
jmp    11e5 <validate+0xc5>
cmp    $0x3,%eax
jg     11e5 <validate+0xc5>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11e5 <validate+0xc5>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
jle    11e5 <validate+0xc5>
xor    %ebp,%ebp
nopl   (%rax)
movsbl (%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11e2 <validate+0xc2>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     11c0 <validate+0xa0>
jmp    11e5 <validate+0xc5>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @validate(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = getelementptr inbounds i8, i8* %6, i64 0
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp eq i32 %9, 45
br i1 %10, label %11, label %40
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 4
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %20
19: ; preds = %15, %11
store i32 0, i32* %2
br label %69
20: ; preds = %15
store i32 1, i32* %4
br label %21
21: ; preds = %36, %20
%22 = load i32, i32* %4
%23 = load i8*, i8** %3
%24 = call i32 @strlen(i8* %23)
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %39
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @isdigit(i8 signext %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %26
store i32 0, i32* %2
br label %69
35: ; preds = %26
br label %36
36: ; preds = %35
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %21
39: ; preds = %21
store i32 1, i32* %2
br label %69
40: ; preds = %1
%41 = load i8*, i8** %3
%42 = call i32 @strlen(i8* %41)
%43 = icmp sgt i32 %42, 3
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i8*, i8** %3
%46 = call i32 @strlen(i8* %45)
%47 = icmp slt i32 %46, 1
br i1 %47, label %48, label %49
48: ; preds = %44, %40
store i32 0, i32* %2
br label %69
49: ; preds = %44
store i32 0, i32* %5
br label %50
50: ; preds = %65, %49
%51 = load i32, i32* %5
%52 = load i8*, i8** %3
%53 = call i32 @strlen(i8* %52)
%54 = icmp slt i32 %51, %53
br i1 %54, label %55, label %68
55: ; preds = %50
%56 = load i8*, i8** %3
%57 = load i32, i32* %5
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
%60 = load i8, i8* %59
%61 = call i32 @isdigit(i8 signext %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %55
store i32 0, i32* %2
br label %69
64: ; preds = %55
br label %65
65: ; preds = %64
%66 = load i32, i32* %5
%67 = add nsw i32 %66, 1
store i32 %67, i32* %5
br label %50
68: ; preds = %50
store i32 1, i32* %2
br label %69
69: ; preds = %68, %63, %48, %39, %34, %19
%70 = load i32, i32* %2
ret i32 %70
}

LLVM IR (-O2):
define i32 @validate(i8* %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 45
%4 = tail call i32 @strlen(i8* %0)
br i1 %3, label %5, label %24
5: ; preds = %1
%6 = icmp sgt i32 %4, 4
br i1 %6, label %43, label %7
7: ; preds = %5
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp slt i32 %8, 2
br i1 %9, label %43, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp sgt i32 %11, 1
br i1 %12, label %17, label %43
13: ; preds = %17
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %23, %15
br i1 %16, label %17, label %43
17: ; preds = %10, %13
%18 = phi i64 [ %23, %13 ], [ 1, %10 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i32 @isdigit(i8 signext %20)
%22 = icmp eq i32 %21, 0
%23 = add nuw nsw i64 %18, 1
br i1 %22, label %43, label %13
24: ; preds = %1
%25 = icmp sgt i32 %4, 3
br i1 %25, label %43, label %26
26: ; preds = %24
%27 = tail call i32 @strlen(i8* %0)
%28 = icmp slt i32 %27, 1
br i1 %28, label %43, label %29
29: ; preds = %26
%30 = tail call i32 @strlen(i8* %0)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %36, label %43
32: ; preds = %36
%33 = tail call i32 @strlen(i8* %0)
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %42, %34
br i1 %35, label %36, label %43
36: ; preds = %29, %32
%37 = phi i64 [ %42, %32 ], [ 0, %29 ]
%38 = getelementptr inbounds i8, i8* %0, i64 %37
%39 = load i8, i8* %38
%40 = tail call i32 @isdigit(i8 signext %39)
%41 = icmp eq i32 %40, 0
%42 = add nuw nsw i64 %37, 1
br i1 %41, label %43, label %32
43: ; preds = %36, %32, %17, %13, %29, %10, %24, %26, %5, %7
%44 = phi i32 [ 0, %7 ], [ 0, %5 ], [ 0, %26 ], [ 0, %24 ], [ 1, %10 ], [ 1, %29 ], [ 0, %17 ], [ 1, %13 ], [ 0, %36 ], [ 1, %32 ]
ret i32 %44
}