#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 *);
scalar_t__ strncmp(char *, char *, int);
int strspn(char *, char *);
int isconstant(char *p) {
  int len = strlen(p);
  if (strspn(p, "0123456789") == len)
    return 1;
  if (len > 4 && strncmp(p, "0bin", 4) == 0 && strspn(p + 4, "01") == (len - 4))
    return 1;
  if (len > 4 && strncmp(p, "0hex", 4) == 0 &&
      strspn(p + 4, "0123456789ABCDEFabcdef") == (len - 4))
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<isconstant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1050 <strspn@plt>
cmp    -0x14(%rbp),%eax
jne    116d <isconstant+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    1222 <isconstant+0xf2>
cmpl   $0x4,-0x14(%rbp)
jle    11c4 <isconstant+0x94>
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11c4 <isconstant+0x94>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
lea    0xe6b(%rip),%rsi
call   1050 <strspn@plt>
mov    -0x14(%rbp),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jne    11c4 <isconstant+0x94>
movl   $0x1,-0x4(%rbp)
jmp    1222 <isconstant+0xf2>
cmpl   $0x4,-0x14(%rbp)
jle    121b <isconstant+0xeb>
mov    -0x10(%rbp),%rdi
lea    0xe3a(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    121b <isconstant+0xeb>
mov    -0x10(%rbp),%rdi
add    $0x4,%rdi
lea    0xe1c(%rip),%rsi
call   1050 <strspn@plt>
mov    -0x14(%rbp),%ecx
sub    $0x4,%ecx
cmp    %ecx,%eax
jne    121b <isconstant+0xeb>
movl   $0x1,-0x4(%rbp)
jmp    1222 <isconstant+0xf2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isconstant>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    %eax,%ebx
lea    0xebb(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strspn@plt>
mov    $0x1,%r14d
cmp    %ebx,%eax
je     11c2 <isconstant+0x92>
cmp    $0x5,%ebx
jl     11bf <isconstant+0x8f>
lea    0xea8(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    118c <isconstant+0x5c>
lea    0x4(%rbp),%rdi
lea    0xe90(%rip),%rsi
call   1050 <strspn@plt>
lea    -0x4(%rbx),%ecx
cmp    %ecx,%eax
je     11c2 <isconstant+0x92>
lea    0xe80(%rip),%rsi
mov    %rbp,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11bf <isconstant+0x8f>
add    $0x4,%rbp
lea    0xe68(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strspn@plt>
add    $0xfffffffc,%ebx
cmp    %ebx,%eax
je     11c2 <isconstant+0x92>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"0123456789\00"
@.str.1 = [5 x i8] c"0bin\00"
@.str.2 = [3 x i8] c"01\00"
@.str.3 = [5 x i8] c"0hex\00"
@.str.4 = [23 x i8] c"0123456789ABCDEFabcdef\00"
define i32 @isconstant(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @strspn(i8* %7, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* %4
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %43
12: ; preds = %1
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 4
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = call i64 @strncmp(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 4
%22 = call i32 @strspn(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 4
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %19
store i32 1, i32* %2
br label %43
27: ; preds = %19, %15, %12
%28 = load i32, i32* %4
%29 = icmp sgt i32 %28, 4
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = load i8*, i8** %3
%32 = call i64 @strncmp(i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i64 4
%37 = call i32 @strspn(i8* %36, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* %4
%39 = sub nsw i32 %38, 4
%40 = icmp eq i32 %37, %39
br i1 %40, label %41, label %42
41: ; preds = %34
store i32 1, i32* %2
br label %43
42: ; preds = %34, %30, %27
store i32 0, i32* %2
br label %43
43: ; preds = %42, %41, %26, %11
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [11 x i8] c"0123456789\00"
@.str.1 = [5 x i8] c"0bin\00"
@.str.2 = [3 x i8] c"01\00"
@.str.3 = [5 x i8] c"0hex\00"
@.str.4 = [23 x i8] c"0123456789ABCDEFabcdef\00"
define i32 @isconstant(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strspn(i8* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, %2
br i1 %4, label %24, label %5
5: ; preds = %1
%6 = icmp sgt i32 %2, 4
br i1 %6, label %7, label %23
7: ; preds = %5
%8 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 4)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %0, i64 4
%12 = tail call i32 @strspn(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = add nsw i32 %2, -4
%14 = icmp eq i32 %12, %13
br i1 %14, label %24, label %15
15: ; preds = %7, %10
%16 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %0, i64 4
%20 = tail call i32 @strspn(i8* %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%21 = add nsw i32 %2, -4
%22 = icmp eq i32 %20, %21
br i1 %22, label %24, label %23
23: ; preds = %5, %18, %15
br label %24
24: ; preds = %18, %10, %1, %23
%25 = phi i32 [ 0, %23 ], [ 1, %1 ], [ 1, %10 ], [ 1, %18 ]
ret i32 %25
}