#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 validateSetting(unsigned int settingHash, char *rule,
                             unsigned char targetType) {
  char *first;
  char *last;
  unsigned int hash;
  unsigned char type;
  unsigned int result = readNextName(rule, &first, &last, &hash);
  while (result == 0) {
    if (hash == settingHash) {
      result = readNextValue(last, &first, &last, &type);
      if (type != targetType) {
        return 2;
      }
      return 0;
    }
    result = readNextName(last, &first, &last, &hash);
  }
  return 10;
}


x86 assembly (clang, -O0):
<validateSetting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <readNextName@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jne    11bf <validateSetting+0x9f>
mov    -0x2c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11a2 <validateSetting+0x82>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2d(%rbp),%rcx
call   1030 <readNextValue@plt>
mov    %eax,-0x34(%rbp)
movzbl -0x2d(%rbp),%eax
movzbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     1196 <validateSetting+0x76>
movl   $0x2,-0x4(%rbp)
jmp    11c6 <validateSetting+0xa6>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <validateSetting+0xa6>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <readNextName@plt>
mov    %eax,-0x34(%rbp)
jmp    114c <validateSetting+0x2c>
movl   $0xa,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validateSetting>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%r14d
mov    %rsi,%rax
mov    %edi,%ebx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %rax,%rdi
call   1040 <readNextName@plt>
mov    $0xa,%r15d
test   %eax,%eax
jne    11b2 <validateSetting+0x92>
lea    0x10(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0x4(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%rdi
cmp    %ebx,0x4(%rsp)
je     118f <validateSetting+0x6f>
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1040 <readNextName@plt>
test   %eax,%eax
je     1170 <validateSetting+0x50>
jmp    11b2 <validateSetting+0x92>
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x3(%rsp),%rcx
call   1030 <readNextValue@plt>
xor    %r15d,%r15d
cmp    %r14b,0x3(%rsp)
setne  %r15b
add    %r15d,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @validateSetting(i32 %0, i8* %1, i8 zeroext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8
%12 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8 %2, i8* %7
%13 = load i8*, i8** %6
%14 = call i32 @readNextName(i8* %13, i8** %8, i8** %9, i32* %10)
store i32 %14, i32* %12
br label %15
15: ; preds = %32, %3
%16 = load i32, i32* %12
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %35
18: ; preds = %15
%19 = load i32, i32* %10
%20 = load i32, i32* %5
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i8*, i8** %9
%24 = call i32 @readNextValue(i8* %23, i8** %8, i8** %9, i8* %11)
store i32 %24, i32* %12
%25 = load i8, i8* %11
%26 = zext i8 %25 to i32
%27 = load i8, i8* %7
%28 = zext i8 %27 to i32
%29 = icmp ne i32 %26, %28
br i1 %29, label %30, label %31
30: ; preds = %22
store i32 2, i32* %4
br label %36
31: ; preds = %22
store i32 0, i32* %4
br label %36
32: ; preds = %18
%33 = load i8*, i8** %9
%34 = call i32 @readNextName(i8* %33, i8** %8, i8** %9, i32* %10)
store i32 %34, i32* %12
br label %15
35: ; preds = %15
store i32 10, i32* %4
br label %36
36: ; preds = %35, %31, %30
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @validateSetting(i32 %0, i8* %1, i8 zeroext %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = bitcast i8** %4 to i8*
%9 = bitcast i8** %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = call i32 @readNextName(i8* %1, i8** %4, i8** %5, i32* %6)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %3, %22
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, %0
%16 = load i8*, i8** %5
br i1 %15, label %17, label %22
17: ; preds = %13
%18 = call i32 @readNextValue(i8* %16, i8** %4, i8** %5, i8* %7)
%19 = load i8, i8* %7
%20 = icmp eq i8 %19, %2
%21 = select i1 %20, i32 0, i32 2
br label %25
22: ; preds = %13
%23 = call i32 @readNextName(i8* %16, i8** %4, i8** %5, i32* %6)
%24 = icmp eq i32 %23, 0
br i1 %24, label %13, label %25
25: ; preds = %22, %3, %17
%26 = phi i32 [ %21, %17 ], [ 10, %3 ], [ 10, %22 ]
ret i32 %26
}