#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 */
unsigned int readNextArrayValue(char *, char **, char **, unsigned char *);
unsigned int readNextName(char *, char **, char **, unsigned int *);
unsigned int readNextValue(char *, char **, char **, unsigned char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
unsigned int validateExpression(char *);
unsigned int validateAlgebra(char *rule) {
  char *first;
  char *last;
  char *lastArrayValue;
  unsigned int hash;
  unsigned char type;
  unsigned char reenter = 0;
  unsigned int result =
      readNextArrayValue(rule, &first, &lastArrayValue, &type);
  while (result == 0) {
    result = readNextName(first, &first, &last, &hash);
    unsigned int nameLength = last - first;
    if (nameLength >= 4) {
      if (!strncmp("$all", last - 4, 4)) {
        nameLength = nameLength - 4;
        reenter = 1;
      } else if (!strncmp("$any", last - 4, 4)) {
        nameLength = nameLength - 4;
        reenter = 1;
      } else if (!strncmp("$not", last - 4, 4)) {
        nameLength = nameLength - 4;
      }
      if (nameLength == 0) {
        return 9;
      }
    }
    result = readNextValue(last, &first, &last, &type);
    if (result != 0) {
      return result;
    }
    if (!reenter) {
      result = validateExpression(first);
    } else {
      result = validateAlgebra(first);
      reenter = 0;
    }
    if (result != 0) {
      return result;
    }
    result = readNextArrayValue(lastArrayValue, &first, &lastArrayValue, &type);
  }
  return (result == 100 ? 0 : result);
}


x86 assembly (clang, -O0):
<validateAlgebra>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movb   $0x0,-0x2e(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2d(%rbp),%rcx
call   1040 <readNextArrayValue@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1304 <validateAlgebra+0x1a4>
mov    -0x18(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1070 <readNextName@plt>
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x38(%rbp)
cmpl   $0x4,-0x38(%rbp)
jb     127a <validateAlgebra+0x11a>
mov    -0x20(%rbp),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe2f(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11f6 <validateAlgebra+0x96>
mov    -0x38(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x38(%rbp)
movb   $0x1,-0x2e(%rbp)
jmp    125f <validateAlgebra+0xff>
mov    -0x20(%rbp),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xe00(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    122a <validateAlgebra+0xca>
mov    -0x38(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x38(%rbp)
movb   $0x1,-0x2e(%rbp)
jmp    125a <validateAlgebra+0xfa>
mov    -0x20(%rbp),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xdd1(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1255 <validateAlgebra+0xf5>
mov    -0x38(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x38(%rbp)
jmp    125a <validateAlgebra+0xfa>
jmp    125f <validateAlgebra+0xff>
cmpl   $0x0,-0x38(%rbp)
jne    1275 <validateAlgebra+0x115>
movl   $0x9,-0x4(%rbp)
jmp    1324 <validateAlgebra+0x1c4>
jmp    127a <validateAlgebra+0x11a>
mov    -0x20(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
lea    -0x2d(%rbp),%rcx
call   1060 <readNextValue@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12a7 <validateAlgebra+0x147>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1324 <validateAlgebra+0x1c4>
cmpb   $0x0,-0x2e(%rbp)
jne    12c2 <validateAlgebra+0x162>
mov    -0x18(%rbp),%rdi
call   1050 <validateExpression@plt>
mov    %eax,-0x34(%rbp)
jmp    12d2 <validateAlgebra+0x172>
mov    -0x18(%rbp),%rdi
call   1080 <validateAlgebra@plt>
mov    %eax,-0x34(%rbp)
movb   $0x0,-0x2e(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     12e7 <validateAlgebra+0x187>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1324 <validateAlgebra+0x1c4>
mov    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2d(%rbp),%rcx
call   1040 <readNextArrayValue@plt>
mov    %eax,-0x34(%rbp)
jmp    1188 <validateAlgebra+0x28>
cmpl   $0x64,-0x34(%rbp)
jne    1318 <validateAlgebra+0x1b8>
xor    %eax,%eax
mov    %eax,-0x3c(%rbp)
jmp    131e <validateAlgebra+0x1be>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateAlgebra>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0x10(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x7(%rsp),%rcx
call   1040 <readNextArrayValue@plt>
mov    %eax,%ecx
test   %eax,%eax
je     119f <validateAlgebra+0x3f>
xor    %eax,%eax
cmp    $0x64,%ecx
cmovne %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%r14
lea    0x24(%rsp),%r15
lea    0x7(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r15,%rcx
call   1070 <readNextName@plt>
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%eax
mov    %esi,%r12d
sub    %eax,%r12d
cmp    $0x4,%r12d
jb     1260 <validateAlgebra+0x100>
add    $0xfffffffffffffffc,%rsi
lea    0xe0d(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
mov    $0x1,%r13b
test   %eax,%eax
je     1250 <validateAlgebra+0xf0>
mov    0x8(%rsp),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xdf1(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1250 <validateAlgebra+0xf0>
mov    0x8(%rsp),%rsi
add    $0xfffffffffffffffc,%rsi
lea    0xdd8(%rip),%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
xor    %r13d,%r13d
test   %eax,%eax
jne    1263 <validateAlgebra+0x103>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x4,%r12d
jne    1263 <validateAlgebra+0x103>
jmp    12d1 <validateAlgebra+0x171>
nopl   0x0(%rax,%rax,1)
xor    %r13d,%r13d
mov    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1060 <readNextValue@plt>
test   %eax,%eax
jne    1190 <validateAlgebra+0x30>
mov    0x10(%rsp),%rdi
test   %r13b,%r13b
je     12a0 <validateAlgebra+0x140>
call   1080 <validateAlgebra@plt>
test   %eax,%eax
je     12ad <validateAlgebra+0x14d>
jmp    1190 <validateAlgebra+0x30>
cs nopw 0x0(%rax,%rax,1)
call   1050 <validateExpression@plt>
test   %eax,%eax
jne    1190 <validateAlgebra+0x30>
mov    0x18(%rsp),%rdi
mov    %rbx,%rsi
lea    0x18(%rsp),%rdx
mov    %rbp,%rcx
call   1040 <readNextArrayValue@plt>
test   %eax,%eax
je     11c0 <validateAlgebra+0x60>
mov    %eax,%ecx
jmp    1188 <validateAlgebra+0x28>
mov    $0x9,%eax
jmp    1190 <validateAlgebra+0x30>

LLVM IR (-O0):
@.str = [5 x i8] c"$all\00"
@.str.1 = [5 x i8] c"$any\00"
@.str.2 = [5 x i8] c"$not\00"
define i32 @validateAlgebra(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %3
store i8 0, i8* %9
%12 = load i8*, i8** %3
%13 = call i32 @readNextArrayValue(i8* %12, i8** %4, i8** %6, i8* %8)
store i32 %13, i32* %10
br label %14
14: ; preds = %80, %1
%15 = load i32, i32* %10
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %83
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i32 @readNextName(i8* %18, i8** %4, i8** %5, i32* %7)
store i32 %19, i32* %10
%20 = load i8*, i8** %5
%21 = load i8*, i8** %4
%22 = ptrtoint i8* %20 to i64
%23 = ptrtoint i8* %21 to i64
%24 = sub i64 %22, %23
%25 = trunc i64 %24 to i32
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = icmp uge i32 %26, 4
br i1 %27, label %28, label %59
28: ; preds = %17
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 -4
%31 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %30, i32 4)
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load i32, i32* %11
%35 = sub i32 %34, 4
store i32 %35, i32* %11
store i8 1, i8* %9
br label %54
36: ; preds = %28
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 -4
%39 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 4)
%40 = icmp ne i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %36
%42 = load i32, i32* %11
%43 = sub i32 %42, 4
store i32 %43, i32* %11
store i8 1, i8* %9
br label %53
44: ; preds = %36
%45 = load i8*, i8** %5
%46 = getelementptr inbounds i8, i8* %45, i64 -4
%47 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %46, i32 4)
%48 = icmp ne i32 %47, 0
br i1 %48, label %52, label %49
49: ; preds = %44
%50 = load i32, i32* %11
%51 = sub i32 %50, 4
store i32 %51, i32* %11
br label %52
52: ; preds = %49, %44
br label %53
53: ; preds = %52, %41
br label %54
54: ; preds = %53, %33
%55 = load i32, i32* %11
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54
store i32 9, i32* %2
br label %91
58: ; preds = %54
br label %59
59: ; preds = %58, %17
%60 = load i8*, i8** %5
%61 = call i32 @readNextValue(i8* %60, i8** %4, i8** %5, i8* %8)
store i32 %61, i32* %10
%62 = load i32, i32* %10
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = load i32, i32* %10
store i32 %65, i32* %2
br label %91
66: ; preds = %59
%67 = load i8, i8* %9
%68 = icmp ne i8 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %66
%70 = load i8*, i8** %4
%71 = call i32 @validateExpression(i8* %70)
store i32 %71, i32* %10
br label %75
72: ; preds = %66
%73 = load i8*, i8** %4
%74 = call i32 @validateAlgebra(i8* %73)
store i32 %74, i32* %10
store i8 0, i8* %9
br label %75
75: ; preds = %72, %69
%76 = load i32, i32* %10
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %75
%79 = load i32, i32* %10
store i32 %79, i32* %2
br label %91
80: ; preds = %75
%81 = load i8*, i8** %6
%82 = call i32 @readNextArrayValue(i8* %81, i8** %4, i8** %6, i8* %8)
store i32 %82, i32* %10
br label %14
83: ; preds = %14
%84 = load i32, i32* %10
%85 = icmp eq i32 %84, 100
br i1 %85, label %86, label %87
86: ; preds = %83
br label %89
87: ; preds = %83
%88 = load i32, i32* %10
br label %89
89: ; preds = %87, %86
%90 = phi i32 [ 0, %86 ], [ %88, %87 ]
store i32 %90, i32* %2
br label %91
91: ; preds = %89, %78, %64, %57
%92 = load i32, i32* %2
ret i32 %92
}

LLVM IR (-O2):
@.str = [5 x i8] c"$all\00"
@.str.1 = [5 x i8] c"$any\00"
@.str.2 = [5 x i8] c"$not\00"
define i32 @validateAlgebra(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8
%7 = bitcast i8** %2 to i8*
%8 = bitcast i8** %3 to i8*
%9 = bitcast i8** %4 to i8*
%10 = bitcast i32* %5 to i8*
%11 = call i32 @readNextArrayValue(i8* %0, i8** %2, i8** %4, i8* %6)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %59
13: ; preds = %1, %55
%14 = load i8*, i8** %2
%15 = call i32 @readNextName(i8* %14, i8** %2, i8** %3, i32* %5)
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = trunc i64 %20 to i32
%22 = icmp ugt i32 %21, 3
br i1 %22, label %23, label %40
23: ; preds = %13
%24 = getelementptr inbounds i8, i8* %16, i64 -4
%25 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %24, i32 4)
%26 = icmp eq i32 %25, 0
br i1 %26, label %37, label %27
27: ; preds = %23
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 -4
%30 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 4)
%31 = icmp eq i32 %30, 0
br i1 %31, label %37, label %32
32: ; preds = %27
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 -4
%35 = call i32 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %34, i32 4)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %27, %23, %32
%38 = phi i8 [ 0, %32 ], [ 1, %23 ], [ 1, %27 ]
%39 = icmp eq i32 %21, 4
br i1 %39, label %63, label %40
40: ; preds = %32, %37, %13
%41 = phi i8 [ %38, %37 ], [ 0, %13 ], [ 0, %32 ]
%42 = load i8*, i8** %3
%43 = call i32 @readNextValue(i8* %42, i8** %2, i8** %3, i8* %6)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %63
45: ; preds = %40
%46 = icmp eq i8 %41, 0
%47 = load i8*, i8** %2
br i1 %46, label %48, label %50
48: ; preds = %45
%49 = call i32 @validateExpression(i8* %47)
br label %52
50: ; preds = %45
%51 = call i32 @validateAlgebra(i8* %47)
br label %52
52: ; preds = %50, %48
%53 = phi i32 [ %51, %50 ], [ %49, %48 ]
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %63
55: ; preds = %52
%56 = load i8*, i8** %4
%57 = call i32 @readNextArrayValue(i8* %56, i8** %2, i8** %4, i8* %6)
%58 = icmp eq i32 %57, 0
br i1 %58, label %13, label %59
59: ; preds = %55, %1
%60 = phi i32 [ %11, %1 ], [ %57, %55 ]
%61 = icmp eq i32 %60, 100
%62 = select i1 %61, i32 0, i32 %60
br label %63
63: ; preds = %52, %40, %37, %59
%64 = phi i32 [ %62, %59 ], [ 9, %37 ], [ %43, %40 ], [ %53, %52 ]
ret i32 %64
}