#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*/ is_bindigit(int);
int /*<<< orphan*/ is_binsym(int);
int /*<<< orphan*/ is_eos(int);
bool is_bin(const char *s) {
  int current_state;
  int next_state;
  int c;
  int i;
  i = 0;
  next_state = 2;
  while (true) {
    c = s[i++];
    current_state = next_state;
    switch (current_state) {
    case 0:
      return false;
    case 1:
      return true;
    case 2:
      if (is_bindigit(c)) {
        next_state = 3;
      } else {
        next_state = 0;
      }
      break;
    case 3:
      if (is_bindigit(c)) {
        next_state = current_state;
      } else if (is_binsym(c)) {
        next_state = 4;
      } else {
        next_state = 0;
      }
    case 4:
      if (is_eos(c)) {
        next_state = 1;
      } else {
        next_state = 0;
      }
      break;
    }
  }
}


x86 assembly (clang, -O0):
<is_bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x4,%rax
ja     1240 <is_bin+0x110>
mov    -0x28(%rbp),%rax
lea    0xe7d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    1245 <is_bin+0x115>
movl   $0x1,-0x4(%rbp)
jmp    1245 <is_bin+0x115>
mov    -0x1c(%rbp),%edi
call   1040 <is_bindigit@plt>
cmp    $0x0,%eax
je     11c1 <is_bin+0x91>
movl   $0x3,-0x18(%rbp)
jmp    11c8 <is_bin+0x98>
movl   $0x0,-0x18(%rbp)
jmp    1240 <is_bin+0x110>
mov    -0x1c(%rbp),%edi
call   1040 <is_bindigit@plt>
cmp    $0x0,%eax
je     11e9 <is_bin+0xb9>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1212 <is_bin+0xe2>
mov    -0x1c(%rbp),%edi
call   1030 <is_binsym@plt>
cmp    $0x0,%eax
je     1206 <is_bin+0xd6>
movl   $0x4,-0x18(%rbp)
jmp    120d <is_bin+0xdd>
movl   $0x0,-0x18(%rbp)
jmp    1212 <is_bin+0xe2>
jmp    1217 <is_bin+0xe7>
mov    -0x1c(%rbp),%edi
call   1050 <is_eos@plt>
cmp    $0x0,%eax
je     1234 <is_bin+0x104>
movl   $0x1,-0x18(%rbp)
jmp    123b <is_bin+0x10b>
movl   $0x0,-0x18(%rbp)
jmp    1240 <is_bin+0x110>
jmp    114a <is_bin+0x1a>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_bin>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2,%eax
jmp    1155 <is_bin+0x25>
nopl   (%rax)
mov    %ebp,%edi
call   1040 <is_bindigit@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
lea    (%rcx,%rcx,2),%eax
add    $0x1,%rbx
movsbl (%rbx),%ebp
cmp    $0x2,%eax
je     1140 <is_bin+0x10>
cmp    $0x3,%eax
jne    118a <is_bin+0x5a>
mov    %ebp,%edi
call   1040 <is_bindigit@plt>
test   %eax,%eax
jne    1174 <is_bin+0x44>
mov    %ebp,%edi
call   1030 <is_binsym@plt>
mov    %ebp,%edi
call   1050 <is_eos@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
add    $0x1,%rbx
jmp    1155 <is_bin+0x25>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_bin(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %7
store i32 2, i32* %5
br label %8
8: ; preds = %1, %48
%9 = load i8*, i8** %3
%10 = load i32, i32* %7
%11 = add nsw i32 %10, 1
store i32 %11, i32* %7
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
store i32 %15, i32* %6
%16 = load i32, i32* %5
store i32 %16, i32* %4
%17 = load i32, i32* %4
switch i32 %17, label %48 [
i32 0, label %18
i32 1, label %19
i32 2, label %20
i32 3, label %27
i32 4, label %41
]
18: ; preds = %8
store i32 0, i32* %2
br label %49
19: ; preds = %8
store i32 1, i32* %2
br label %49
20: ; preds = %8
%21 = load i32, i32* %6
%22 = call i32 @is_bindigit(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 3, i32* %5
br label %26
25: ; preds = %20
store i32 0, i32* %5
br label %26
26: ; preds = %25, %24
br label %48
27: ; preds = %8
%28 = load i32, i32* %6
%29 = call i32 @is_bindigit(i32 %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i32, i32* %4
store i32 %32, i32* %5
br label %40
33: ; preds = %27
%34 = load i32, i32* %6
%35 = call i32 @is_binsym(i32 %34)
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %33
store i32 4, i32* %5
br label %39
38: ; preds = %33
store i32 0, i32* %5
br label %39
39: ; preds = %38, %37
br label %40
40: ; preds = %39, %31
br label %41
41: ; preds = %8, %40
%42 = load i32, i32* %6
%43 = call i32 @is_eos(i32 %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %41
store i32 1, i32* %5
br label %47
46: ; preds = %41
store i32 0, i32* %5
br label %47
47: ; preds = %46, %45
br label %48
48: ; preds = %8, %47, %26
br label %8
49: ; preds = %19, %18
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
define i32 @is_bin(i8* nocapture %0) {
br label %3
2: ; preds = %3
unreachable
3: ; preds = %23, %1
%4 = phi i64 [ 0, %1 ], [ %6, %23 ]
%5 = phi i32 [ 2, %1 ], [ %24, %23 ]
%6 = add nuw i64 %4, 1
%7 = getelementptr inbounds i8, i8* %0, i64 %4
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %5, label %2 [
i32 0, label %25
i32 1, label %25
i32 2, label %10
i32 3, label %14
]
10: ; preds = %3
%11 = tail call i32 @is_bindigit(i32 %9)
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 0, i32 3
br label %23
14: ; preds = %3
%15 = tail call i32 @is_bindigit(i32 %9)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @is_binsym(i32 %9)
br label %19
19: ; preds = %17, %14
%20 = tail call i32 @is_eos(i32 %9)
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %19, %10
%24 = phi i32 [ %22, %19 ], [ %13, %10 ]
br label %3
25: ; preds = %3, %3
ret i32 %5
}