#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 readNextString(char *, char **, char **, unsigned int *);
unsigned int readNextValue(char *, char **, char **, unsigned char *);
unsigned int validateReference(char *rule, unsigned char *referenceType) {
  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 != 5861212) {
    *referenceType = 0x09;
    result = readNextString(last, &first, &last, &hash);
    if (result != 0) {
      return result;
    }
  } else {
    *referenceType = 0x08;
    if (readNextString(last, &first, &last, &hash) != 0) {
      result = readNextValue(last, &first, &last, &type);
      if (result != 0) {
        return result;
      }
      unsigned int result = readNextName(first, &first, &last, &hash);
      while (result == 0) {
        switch (hash) {
        case 2090536006:
          result = readNextString(last, &first, &last, &hash);
          break;
        case 5863474:
          result = readNextValue(last, &first, &last, &type);
          break;
        default:
          result = readNextValue(last, &first, &last, &type);
          break;
        }
        if (result != 0) {
          return result;
        }
        result = readNextName(last, &first, &last, &hash);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<validateReference>:
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     116d <validateReference+0x3d>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <validateReference+0x1b5>
cmpl   $0x596f5c,-0x30(%rbp)
je     11b3 <validateReference+0x83>
mov    -0x18(%rbp),%rax
movb   $0x9,(%rax)
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <readNextString@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11ae <validateReference+0x7e>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <validateReference+0x1b5>
jmp    12de <validateReference+0x1ae>
mov    -0x18(%rbp),%rax
movb   $0x8,(%rax)
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <readNextString@plt>
cmp    $0x0,%eax
je     12d9 <validateReference+0x1a9>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x29(%rbp),%rcx
call   1030 <readNextValue@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1205 <validateReference+0xd5>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <validateReference+0x1b5>
mov    -0x20(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <readNextName@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    12d4 <validateReference+0x1a4>
mov    -0x30(%rbp),%eax
mov    %eax,-0x3c(%rbp)
sub    $0x597832,%eax
je     126d <validateReference+0x13d>
jmp    123d <validateReference+0x10d>
mov    -0x3c(%rbp),%eax
sub    $0x7c9b0c46,%eax
jne    128a <validateReference+0x15a>
jmp    1250 <validateReference+0x120>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1040 <readNextString@plt>
mov    %eax,-0x38(%rbp)
jmp    12a2 <validateReference+0x172>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x29(%rbp),%rcx
call   1030 <readNextValue@plt>
mov    %eax,-0x38(%rbp)
jmp    12a2 <validateReference+0x172>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x29(%rbp),%rcx
call   1030 <readNextValue@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
je     12b7 <validateReference+0x187>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12e5 <validateReference+0x1b5>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   1050 <readNextName@plt>
mov    %eax,-0x38(%rbp)
jmp    121d <validateReference+0xed>
jmp    12d9 <validateReference+0x1a9>
jmp    12de <validateReference+0x1ae>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateReference>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1050 <readNextName@plt>
test   %eax,%eax
jne    1269 <validateReference+0x139>
cmpl   $0x596f5c,0x4(%rsp)
jne    1247 <validateReference+0x117>
movb   $0x8,(%rbx)
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1040 <readNextString@plt>
test   %eax,%eax
je     1267 <validateReference+0x137>
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1030 <readNextValue@plt>
test   %eax,%eax
jne    1269 <validateReference+0x139>
mov    0x10(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1050 <readNextName@plt>
test   %eax,%eax
jne    1267 <validateReference+0x137>
lea    0x10(%rsp),%r14
lea    0x8(%rsp),%rbx
lea    0x3(%rsp),%r15
lea    0x4(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x4(%rsp),%eax
cmp    $0x597832,%eax
je     1217 <validateReference+0xe7>
cmp    $0x7c9b0c46,%eax
jne    1217 <validateReference+0xe7>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1040 <readNextString@plt>
jmp    122a <validateReference+0xfa>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1030 <readNextValue@plt>
test   %eax,%eax
jne    1269 <validateReference+0x139>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1050 <readNextName@plt>
test   %eax,%eax
je     11f0 <validateReference+0xc0>
jmp    1267 <validateReference+0x137>
movb   $0x9,(%rbx)
mov    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1040 <readNextString@plt>
test   %eax,%eax
jne    1269 <validateReference+0x139>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @validateReference(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 i32
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 %70
18: ; preds = %2
%19 = load i32, i32* %9
%20 = icmp ne i32 %19, 5861212
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i8*, i8** %5
store i8 9, i8* %22
%23 = load i8*, i8** %7
%24 = call i32 @readNextString(i8* %23, i8** %6, i8** %7, i32* %9)
store i32 %24, i32* %10
%25 = load i32, i32* %10
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = load i32, i32* %10
store i32 %28, i32* %3
br label %70
29: ; preds = %21
br label %69
30: ; preds = %18
%31 = load i8*, i8** %5
store i8 8, i8* %31
%32 = load i8*, i8** %7
%33 = call i32 @readNextString(i8* %32, i8** %6, i8** %7, i32* %9)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %68
35: ; preds = %30
%36 = load i8*, i8** %7
%37 = call i32 @readNextValue(i8* %36, i8** %6, i8** %7, i8* %8)
store i32 %37, i32* %10
%38 = load i32, i32* %10
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = load i32, i32* %10
store i32 %41, i32* %3
br label %70
42: ; preds = %35
%43 = load i8*, i8** %6
%44 = call i32 @readNextName(i8* %43, i8** %6, i8** %7, i32* %9)
store i32 %44, i32* %11
br label %45
45: ; preds = %64, %42
%46 = load i32, i32* %11
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %67
48: ; preds = %45
%49 = load i32, i32* %9
switch i32 %49, label %56 [
i32 2090536006, label %50
i32 5863474, label %53
]
50: ; preds = %48
%51 = load i8*, i8** %7
%52 = call i32 @readNextString(i8* %51, i8** %6, i8** %7, i32* %9)
store i32 %52, i32* %11
br label %59
53: ; preds = %48
%54 = load i8*, i8** %7
%55 = call i32 @readNextValue(i8* %54, i8** %6, i8** %7, i8* %8)
store i32 %55, i32* %11
br label %59
56: ; preds = %48
%57 = load i8*, i8** %7
%58 = call i32 @readNextValue(i8* %57, i8** %6, i8** %7, i8* %8)
store i32 %58, i32* %11
br label %59
59: ; preds = %56, %53, %50
%60 = load i32, i32* %11
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = load i32, i32* %11
store i32 %63, i32* %3
br label %70
64: ; preds = %59
%65 = load i8*, i8** %7
%66 = call i32 @readNextName(i8* %65, i8** %6, i8** %7, i32* %9)
store i32 %66, i32* %11
br label %45
67: ; preds = %45
br label %68
68: ; preds = %67, %30
br label %69
69: ; preds = %68, %29
store i32 0, i32* %3
br label %70
70: ; preds = %69, %62, %40, %27, %16
%71 = load i32, i32* %3
ret i32 %71
}

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