#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 readNextName(char *, char **, char **, unsigned int *);
unsigned int readNextValue(char *, char **, char **, unsigned char *);
unsigned int validateReference(char *, unsigned char *);
unsigned int validateIdiom(char *rule, unsigned char *idiomType) {
  char *first;
  char *last;
  unsigned char type;
  unsigned int hash;
  unsigned int result;
  result = readNextName(rule, &first, &last, &hash);
  if (result != 0) {
    return result;
  }
  if (hash != 2087876370 && hash != 2087896531 && hash != 2087890007 &&
      hash != 2087879820) {
    return validateReference(rule, idiomType);
  } else {
    result = readNextValue(last, &first, &last, &type);
    if (result != 0) {
      return result;
    }
    *idiomType = 0;
    result = readNextName(first, &first, &last, &hash);
    while (result == 0) {
      unsigned char newIdiomType = 0;
      result = readNextValue(last, &first, &last, &type);
      if (result != 0) {
        return result;
      }
      if (type == 0x06) {
        result = validateIdiom(first, &newIdiomType);
        if (result != 0) {
          return result;
        }
      }
      if (newIdiomType == 0x09 || newIdiomType == 0x0B) {
        if (*idiomType == 0x08 || *idiomType == 0x0A) {
          return 2;
        }
        *idiomType = 0x0B;
      }
      if (newIdiomType == 0x08 || newIdiomType == 0x0A) {
        if (*idiomType == 0x09 || *idiomType == 0x0B) {
          return 2;
        }
        *idiomType = 0x0A;
      }
      if (hash != 5861205 && hash != 5861211) {
        return 5;
      }
      result = readNextName(last, &first, &last, &hash);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<validateIdiom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <readNextName@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     117d <validateIdiom+0x3d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    136d <validateIdiom+0x22d>
cmpl   $0x7c727712,-0x30(%rbp)
je     11c6 <validateIdiom+0x86>
cmpl   $0x7c72c5d3,-0x30(%rbp)
je     11c6 <validateIdiom+0x86>
cmpl   $0x7c72ac57,-0x30(%rbp)
je     11c6 <validateIdiom+0x86>
cmpl   $0x7c72848c,-0x30(%rbp)
je     11c6 <validateIdiom+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <validateReference@plt>
mov    %eax,-0x4(%rbp)
jmp    136d <validateIdiom+0x22d>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x29(%rbp),%rcx
call   1040 <readNextValue@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11f3 <validateIdiom+0xb3>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    136d <validateIdiom+0x22d>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <readNextName@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    1361 <validateIdiom+0x221>
movb   $0x0,-0x35(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x29(%rbp),%rcx
call   1040 <readNextValue@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     124d <validateIdiom+0x10d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    136d <validateIdiom+0x22d>
movzbl -0x29(%rbp),%eax
cmp    $0x6,%eax
jne    1284 <validateIdiom+0x144>
mov    -0x20(%rbp),%rdi
lea    -0x35(%rbp),%rsi
call   1030 <validateIdiom@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     127f <validateIdiom+0x13f>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    136d <validateIdiom+0x22d>
jmp    1284 <validateIdiom+0x144>
movzbl -0x35(%rbp),%eax
cmp    $0x9,%eax
je     129e <validateIdiom+0x15e>
movzbl -0x35(%rbp),%eax
cmp    $0xb,%eax
jne    12d1 <validateIdiom+0x191>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x8,%eax
je     12be <validateIdiom+0x17e>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xa,%eax
jne    12ca <validateIdiom+0x18a>
movl   $0x2,-0x4(%rbp)
jmp    136d <validateIdiom+0x22d>
mov    -0x18(%rbp),%rax
movb   $0xb,(%rax)
movzbl -0x35(%rbp),%eax
cmp    $0x8,%eax
je     12eb <validateIdiom+0x1ab>
movzbl -0x35(%rbp),%eax
cmp    $0xa,%eax
jne    131e <validateIdiom+0x1de>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x9,%eax
je     130b <validateIdiom+0x1cb>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
cmp    $0xb,%eax
jne    1317 <validateIdiom+0x1d7>
movl   $0x2,-0x4(%rbp)
jmp    136d <validateIdiom+0x22d>
mov    -0x18(%rbp),%rax
movb   $0xa,(%rax)
cmpl   $0x596f55,-0x30(%rbp)
je     1344 <validateIdiom+0x204>
cmpl   $0x596f5b,-0x30(%rbp)
je     1344 <validateIdiom+0x204>
movl   $0x5,-0x4(%rbp)
jmp    136d <validateIdiom+0x22d>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <readNextName@plt>
mov    %eax,-0x34(%rbp)
jmp    1212 <validateIdiom+0xd2>
jmp    1366 <validateIdiom+0x226>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateIdiom>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %rdi,%rbx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1050 <readNextName@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    12c2 <validateIdiom+0x182>
mov    0x4(%rsp),%eax
cmp    $0x7c72ac56,%eax
jg     1190 <validateIdiom+0x50>
cmp    $0x7c727712,%eax
je     11a2 <validateIdiom+0x62>
cmp    $0x7c72848c,%eax
je     11a2 <validateIdiom+0x62>
jmp    12b5 <validateIdiom+0x175>
cmp    $0x7c72ac57,%eax
je     11a2 <validateIdiom+0x62>
cmp    $0x7c72c5d3,%eax
jne    12b5 <validateIdiom+0x175>
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1040 <readNextValue@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    12c2 <validateIdiom+0x182>
movb   $0x0,0x0(%r13)
mov    0x10(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1050 <readNextName@plt>
xor    %ebp,%ebp
test   %eax,%eax
jne    12c2 <validateIdiom+0x182>
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0x3(%rsp),%r12
lea    0x4(%rsp),%rbx
jmp    122b <validateIdiom+0xeb>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <readNextName@plt>
test   %eax,%eax
jne    12c2 <validateIdiom+0x182>
movb   $0x0,0x2(%rsp)
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1040 <readNextValue@plt>
test   %eax,%eax
jne    12c0 <validateIdiom+0x180>
cmpb   $0x6,0x3(%rsp)
jne    1261 <validateIdiom+0x121>
mov    0x10(%rsp),%rdi
lea    0x2(%rsp),%rsi
call   1030 <validateIdiom@plt>
test   %eax,%eax
jne    12c0 <validateIdiom+0x180>
movzbl 0x2(%rsp),%eax
and    $0xfd,%al
cmp    $0x8,%al
je     1281 <validateIdiom+0x141>
cmp    $0x9,%al
jne    1294 <validateIdiom+0x154>
movzbl 0x0(%r13),%ecx
mov    $0xb,%al
or     $0x2,%cl
cmp    $0xa,%cl
jne    1290 <validateIdiom+0x150>
jmp    12d3 <validateIdiom+0x193>
movzbl 0x0(%r13),%ecx
mov    $0xa,%al
or     $0x2,%cl
cmp    $0xb,%cl
je     12d3 <validateIdiom+0x193>
mov    %al,0x0(%r13)
mov    0x4(%rsp),%eax
cmp    $0x596f55,%eax
je     1210 <validateIdiom+0xd0>
cmp    $0x596f5b,%eax
je     1210 <validateIdiom+0xd0>
mov    $0x5,%ebp
jmp    12c2 <validateIdiom+0x182>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <validateReference@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x2,%ebp
jmp    12c2 <validateIdiom+0x182>

LLVM IR (-O0):
define i32 @validateIdiom(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
%12 = load i8*, i8** %4
%13 = call i32 @readNextName(i8* %12, i8** %6, i8** %7, i32* %9)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = load i32, i32* %10
store i32 %17, i32* %3
br label %121
18: ; preds = %2
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 2087876370
br i1 %20, label %21, label %34
21: ; preds = %18
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 2087896531
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i32, i32* %9
%26 = icmp ne i32 %25, 2087890007
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 2087879820
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i8*, i8** %4
%32 = load i8*, i8** %5
%33 = call i32 @validateReference(i8* %31, i8* %32)
store i32 %33, i32* %3
br label %121
34: ; preds = %27, %24, %21, %18
%35 = load i8*, i8** %7
%36 = call i32 @readNextValue(i8* %35, i8** %6, i8** %7, i8* %8)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %34
%40 = load i32, i32* %10
store i32 %40, i32* %3
br label %121
41: ; preds = %34
%42 = load i8*, i8** %5
store i8 0, i8* %42
%43 = load i8*, i8** %6
%44 = call i32 @readNextName(i8* %43, i8** %6, i8** %7, i32* %9)
store i32 %44, i32* %10
br label %45
45: ; preds = %116, %41
%46 = load i32, i32* %10
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %119
48: ; preds = %45
store i8 0, i8* %11
%49 = load i8*, i8** %7
%50 = call i32 @readNextValue(i8* %49, i8** %6, i8** %7, i8* %8)
store i32 %50, i32* %10
%51 = load i32, i32* %10
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %48
%54 = load i32, i32* %10
store i32 %54, i32* %3
br label %121
55: ; preds = %48
%56 = load i8, i8* %8
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 6
br i1 %58, label %59, label %67
59: ; preds = %55
%60 = load i8*, i8** %6
%61 = call i32 @validateIdiom(i8* %60, i8* %11)
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* %3
br label %121
66: ; preds = %59
br label %67
67: ; preds = %66, %55
%68 = load i8, i8* %11
%69 = zext i8 %68 to i32
%70 = icmp eq i32 %69, 9
br i1 %70, label %75, label %71
71: ; preds = %67
%72 = load i8, i8* %11
%73 = zext i8 %72 to i32
%74 = icmp eq i32 %73, 11
br i1 %74, label %75, label %88
75: ; preds = %71, %67
%76 = load i8*, i8** %5
%77 = load i8, i8* %76
%78 = zext i8 %77 to i32
%79 = icmp eq i32 %78, 8
br i1 %79, label %85, label %80
80: ; preds = %75
%81 = load i8*, i8** %5
%82 = load i8, i8* %81
%83 = zext i8 %82 to i32
%84 = icmp eq i32 %83, 10
br i1 %84, label %85, label %86
85: ; preds = %80, %75
store i32 2, i32* %3
br label %121
86: ; preds = %80
%87 = load i8*, i8** %5
store i8 11, i8* %87
br label %88
88: ; preds = %86, %71
%89 = load i8, i8* %11
%90 = zext i8 %89 to i32
%91 = icmp eq i32 %90, 8
br i1 %91, label %96, label %92
92: ; preds = %88
%93 = load i8, i8* %11
%94 = zext i8 %93 to i32
%95 = icmp eq i32 %94, 10
br i1 %95, label %96, label %109
96: ; preds = %92, %88
%97 = load i8*, i8** %5
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = icmp eq i32 %99, 9
br i1 %100, label %106, label %101
101: ; preds = %96
%102 = load i8*, i8** %5
%103 = load i8, i8* %102
%104 = zext i8 %103 to i32
%105 = icmp eq i32 %104, 11
br i1 %105, label %106, label %107
106: ; preds = %101, %96
store i32 2, i32* %3
br label %121
107: ; preds = %101
%108 = load i8*, i8** %5
store i8 10, i8* %108
br label %109
109: ; preds = %107, %92
%110 = load i32, i32* %9
%111 = icmp ne i32 %110, 5861205
br i1 %111, label %112, label %116
112: ; preds = %109
%113 = load i32, i32* %9
%114 = icmp ne i32 %113, 5861211
br i1 %114, label %115, label %116
115: ; preds = %112
store i32 5, i32* %3
br label %121
116: ; preds = %112, %109
%117 = load i8*, i8** %7
%118 = call i32 @readNextName(i8* %117, i8** %6, i8** %7, i32* %9)
store i32 %118, i32* %10
br label %45
119: ; preds = %45
br label %120
120: ; preds = %119
store i32 0, i32* %3
br label %121
121: ; preds = %120, %115, %106, %85, %64, %53, %39, %30, %16
%122 = load i32, i32* %3
ret i32 %122
}

LLVM IR (-O2):
define i32 @validateIdiom(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i8
%8 = bitcast i8** %3 to i8*
%9 = bitcast i8** %4 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i32 @readNextName(i8* %0, i8** %3, i8** %4, i32* %6)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %53
13: ; preds = %2
%14 = load i32, i32* %6
switch i32 %14, label %15 [
i32 2087896531, label %17
i32 2087890007, label %17
i32 2087879820, label %17
i32 2087876370, label %17
]
15: ; preds = %13
%16 = call i32 @validateReference(i8* %0, i8* %1)
br label %53
17: ; preds = %13, %13, %13, %13
%18 = load i8*, i8** %4
%19 = call i32 @readNextValue(i8* %18, i8** %3, i8** %4, i8* %5)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %17
store i8 0, i8* %1
%22 = load i8*, i8** %3
%23 = call i32 @readNextName(i8* %22, i8** %3, i8** %4, i32* %6)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %53
25: ; preds = %21, %49
store i8 0, i8* %7
%26 = load i8*, i8** %4
%27 = call i32 @readNextValue(i8* %26, i8** %3, i8** %4, i8* %5)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %47
29: ; preds = %25
%30 = load i8, i8* %5
%31 = icmp eq i8 %30, 6
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %3
%34 = call i32 @validateIdiom(i8* %33, i8* %7)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %32, %29
%37 = load i8, i8* %7
%38 = and i8 %37, -3
switch i8 %38, label %45 [
i8 9, label %39
i8 8, label %41
]
39: ; preds = %36
%40 = load i8, i8* %1
switch i8 %40, label %43 [
i8 8, label %47
i8 10, label %47
]
41: ; preds = %36
%42 = load i8, i8* %1
switch i8 %42, label %43 [
i8 9, label %47
i8 11, label %47
]
43: ; preds = %41, %39
%44 = phi i8 [ 11, %39 ], [ 10, %41 ]
store i8 %44, i8* %1
br label %45
45: ; preds = %43, %36
%46 = load i32, i32* %6
switch i32 %46, label %47 [
i32 5861211, label %49
i32 5861205, label %49
]
47: ; preds = %25, %32, %39, %39, %41, %41, %45
%48 = phi i32 [ 5, %45 ], [ 2, %41 ], [ 2, %41 ], [ 2, %39 ], [ 2, %39 ], [ %34, %32 ], [ %27, %25 ]
br label %53
49: ; preds = %45, %45
%50 = load i8*, i8** %4
%51 = call i32 @readNextName(i8* %50, i8** %3, i8** %4, i32* %6)
%52 = icmp eq i32 %51, 0
br i1 %52, label %25, label %53
53: ; preds = %49, %21, %47, %17, %2, %15
%54 = phi i32 [ %16, %15 ], [ %11, %2 ], [ %19, %17 ], [ %48, %47 ], [ 0, %21 ], [ 0, %49 ]
ret i32 %54
}