#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 could_be_index(char *x) {
  enum { AFTER_DIGIT, AFTER_PERIOD, AFTER_MINUS } state;
  char *p;
  if (x[0] == '.')
    return 1;
  state = AFTER_PERIOD;
  for (p = x; *p; p++) {
    switch (state) {
    case AFTER_DIGIT:
      if (isdigit(*p))
        state = AFTER_DIGIT;
      else if (*p == '-')
        state = AFTER_MINUS;
      else if (*p == '.')
        state = AFTER_PERIOD;
      else
        return 0;
      break;
    case AFTER_PERIOD:
      if (isdigit(*p))
        state = AFTER_DIGIT;
      else if (*p == '-')
        state = AFTER_MINUS;
      else
        return 0;
      break;
    case AFTER_MINUS:
      if (isdigit(*p))
        state = AFTER_DIGIT;
      else
        return 0;
      break;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<could_be_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1138 <could_be_index+0x28>
movl   $0x1,-0x4(%rbp)
jmp    129f <could_be_index+0x18f>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1298 <could_be_index+0x188>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
test   %eax,%eax
je     1189 <could_be_index+0x79>
jmp    1167 <could_be_index+0x57>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
je     11fd <could_be_index+0xed>
jmp    1178 <could_be_index+0x68>
mov    -0x24(%rbp),%eax
sub    $0x2,%eax
je     1250 <could_be_index+0x140>
jmp    1282 <could_be_index+0x172>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     11aa <could_be_index+0x9a>
movl   $0x0,-0x14(%rbp)
jmp    11f8 <could_be_index+0xe8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11c6 <could_be_index+0xb6>
movl   $0x2,-0x14(%rbp)
jmp    11f3 <could_be_index+0xe3>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11e2 <could_be_index+0xd2>
movl   $0x1,-0x14(%rbp)
jmp    11ee <could_be_index+0xde>
movl   $0x0,-0x4(%rbp)
jmp    129f <could_be_index+0x18f>
jmp    11f3 <could_be_index+0xe3>
jmp    11f8 <could_be_index+0xe8>
jmp    1282 <could_be_index+0x172>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     121e <could_be_index+0x10e>
movl   $0x0,-0x14(%rbp)
jmp    124b <could_be_index+0x13b>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    123a <could_be_index+0x12a>
movl   $0x2,-0x14(%rbp)
jmp    1246 <could_be_index+0x136>
movl   $0x0,-0x4(%rbp)
jmp    129f <could_be_index+0x18f>
jmp    124b <could_be_index+0x13b>
jmp    1282 <could_be_index+0x172>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     1271 <could_be_index+0x161>
movl   $0x0,-0x14(%rbp)
jmp    127d <could_be_index+0x16d>
movl   $0x0,-0x4(%rbp)
jmp    129f <could_be_index+0x18f>
jmp    1282 <could_be_index+0x172>
jmp    1287 <could_be_index+0x177>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1147 <could_be_index+0x37>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<could_be_index>:
push   %rbx
mov    (%rdi),%cl
mov    $0x1,%eax
test   %cl,%cl
je     11c3 <could_be_index+0xb3>
cmp    $0x2e,%cl
je     11c3 <could_be_index+0xb3>
mov    %rdi,%rbx
mov    $0x1,%eax
jmp    115c <could_be_index+0x4c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %cl,%edi
call   1030 <isdigit@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
je     11c3 <could_be_index+0xb3>
movzbl 0x1(%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     11be <could_be_index+0xae>
cmp    $0x2,%eax
je     1140 <could_be_index+0x30>
cmp    $0x1,%eax
je     11a0 <could_be_index+0x90>
test   %eax,%eax
jne    1150 <could_be_index+0x40>
movsbl %cl,%edi
call   1030 <isdigit@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    1150 <could_be_index+0x40>
movzbl (%rbx),%ecx
mov    $0x2,%eax
cmp    $0x2d,%cl
je     1150 <could_be_index+0x40>
cmp    $0x2e,%cl
jne    11ba <could_be_index+0xaa>
mov    $0x1,%eax
jmp    1150 <could_be_index+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %cl,%edi
call   1030 <isdigit@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    1150 <could_be_index+0x40>
mov    $0x2,%eax
cmpb   $0x2d,(%rbx)
je     1150 <could_be_index+0x40>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @could_be_index(i8* nocapture %0) {
%2 = load i8, i8* %0
switch i8 %2, label %3 [
i8 46, label %27
i8 0, label %27
]
3: ; preds = %1, %22
%4 = phi i8* [ %24, %22 ], [ %0, %1 ]
%5 = phi i32 [ %23, %22 ], [ 1, %1 ]
%6 = phi i8 [ %25, %22 ], [ %2, %1 ]
switch i32 %5, label %22 [
i32 0, label %7
i32 1, label %13
i32 2, label %19
]
7: ; preds = %3
%8 = tail call i32 @isdigit(i8 signext %6)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i8, i8* %4
switch i8 %11, label %27 [
i8 45, label %22
i8 46, label %12
]
12: ; preds = %10
br label %22
13: ; preds = %3
%14 = tail call i32 @isdigit(i8 signext %6)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i8, i8* %4
%18 = icmp eq i8 %17, 45
br i1 %18, label %22, label %27
19: ; preds = %3
%20 = tail call i32 @isdigit(i8 signext %6)
%21 = icmp eq i32 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19, %16, %13, %10, %7, %3, %12
%23 = phi i32 [ %5, %3 ], [ 1, %12 ], [ 0, %7 ], [ 2, %10 ], [ 0, %13 ], [ 2, %16 ], [ 0, %19 ]
%24 = getelementptr inbounds i8, i8* %4, i64 1
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 0
br i1 %26, label %27, label %3
27: ; preds = %10, %16, %19, %22, %1, %1
%28 = phi i32 [ 1, %1 ], [ 1, %1 ], [ 0, %10 ], [ 0, %16 ], [ 0, %19 ], [ 1, %22 ]
ret i32 %28
}