#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 */
struct lookahead_state {
  int dummy;
};

/* Variables and functions */
int _lookahead_getc(struct lookahead_state *);
int /*<<< orphan*/ _lookahead_revert(struct lookahead_state *, unsigned int);
unsigned int _lookahead_tell(struct lookahead_state *);
unsigned int _parse_hex(struct lookahead_state *lookahead) {
  int c;
  unsigned int n;
  c = _lookahead_getc(lookahead);
  if (c != '0') {
    _lookahead_revert(lookahead, 0);
    return 0;
  }
  c = _lookahead_getc(lookahead);
  if (c != 'x' && c != 'X') {
    _lookahead_revert(lookahead, 0);
    return 0;
  }
  for (n = 2;;) {
    unsigned int pos = _lookahead_tell(lookahead);
    c = _lookahead_getc(lookahead);
    if ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
        (c >= 'A' && c <= 'F')) {
      n++;
    } else {
      _lookahead_revert(lookahead, pos);
      break;
    }
  }
  if (n > 2) {
    return n;
  }
  _lookahead_revert(lookahead, 0);
  return 0;
}


x86 assembly (clang, -O0):
<_parse_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_lookahead_getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x30,-0x14(%rbp)
je     1169 <_parse_hex+0x39>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <_lookahead_revert@plt>
movl   $0x0,-0x4(%rbp)
jmp    1246 <_parse_hex+0x116>
mov    -0x10(%rbp),%rdi
call   1030 <_lookahead_getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x78,-0x14(%rbp)
je     11a0 <_parse_hex+0x70>
cmpl   $0x58,-0x14(%rbp)
je     11a0 <_parse_hex+0x70>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <_lookahead_revert@plt>
movl   $0x0,-0x4(%rbp)
jmp    1246 <_parse_hex+0x116>
movl   $0x2,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <_lookahead_tell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_lookahead_getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x30,-0x14(%rbp)
jl     11d3 <_parse_hex+0xa3>
cmpl   $0x39,-0x14(%rbp)
jle    11fb <_parse_hex+0xcb>
cmpl   $0x61,-0x14(%rbp)
jl     11e7 <_parse_hex+0xb7>
cmpl   $0x66,-0x14(%rbp)
jle    11fb <_parse_hex+0xcb>
cmpl   $0x41,-0x14(%rbp)
jl     1209 <_parse_hex+0xd9>
cmpl   $0x46,-0x14(%rbp)
jg     1209 <_parse_hex+0xd9>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    121a <_parse_hex+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <_lookahead_revert@plt>
jmp    121f <_parse_hex+0xef>
jmp    11a7 <_parse_hex+0x77>
cmpl   $0x2,-0x18(%rbp)
jbe    1234 <_parse_hex+0x104>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1246 <_parse_hex+0x116>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <_lookahead_revert@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_parse_hex>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <_lookahead_getc@plt>
cmp    $0x30,%eax
jne    11ac <_parse_hex+0x7c>
mov    %rbx,%rdi
call   1030 <_lookahead_getc@plt>
and    $0xffffffdf,%eax
cmp    $0x58,%eax
jne    11ac <_parse_hex+0x7c>
mov    $0x2,%ebp
movabs $0x3f0000003f,%r15
jmp    1173 <_parse_hex+0x43>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <_lookahead_tell@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <_lookahead_getc@plt>
lea    -0x30(%rax),%ecx
cmp    $0xa,%ecx
jb     1170 <_parse_hex+0x40>
add    $0xffffffbf,%eax
cmp    $0x25,%eax
ja     119c <_parse_hex+0x6c>
bt     %rax,%r15
jb     1170 <_parse_hex+0x40>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1040 <_lookahead_revert@plt>
cmp    $0x2,%ebp
ja     11b8 <_parse_hex+0x88>
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <_lookahead_revert@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.lookahead_state = type { i32 }
define i32 @_parse_hex(%struct.lookahead_state* %0) {
%2 = alloca i32
%3 = alloca %struct.lookahead_state*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store %struct.lookahead_state* %0, %struct.lookahead_state** %3
%7 = load %struct.lookahead_state*, %struct.lookahead_state** %3
%8 = call i32 @_lookahead_getc(%struct.lookahead_state* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 48
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load %struct.lookahead_state*, %struct.lookahead_state** %3
%13 = call i32 @_lookahead_revert(%struct.lookahead_state* %12, i32 0)
store i32 0, i32* %2
br label %64
14: ; preds = %1
%15 = load %struct.lookahead_state*, %struct.lookahead_state** %3
%16 = call i32 @_lookahead_getc(%struct.lookahead_state* %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 120
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 88
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load %struct.lookahead_state*, %struct.lookahead_state** %3
%24 = call i32 @_lookahead_revert(%struct.lookahead_state* %23, i32 0)
store i32 0, i32* %2
br label %64
25: ; preds = %19, %14
store i32 2, i32* %5
br label %26
26: ; preds = %55, %25
%27 = load %struct.lookahead_state*, %struct.lookahead_state** %3
%28 = call i32 @_lookahead_tell(%struct.lookahead_state* %27)
store i32 %28, i32* %6
%29 = load %struct.lookahead_state*, %struct.lookahead_state** %3
%30 = call i32 @_lookahead_getc(%struct.lookahead_state* %29)
store i32 %30, i32* %4
%31 = load i32, i32* %4
%32 = icmp sge i32 %31, 48
br i1 %32, label %33, label %36
33: ; preds = %26
%34 = load i32, i32* %4
%35 = icmp sle i32 %34, 57
br i1 %35, label %48, label %36
36: ; preds = %33, %26
%37 = load i32, i32* %4
%38 = icmp sge i32 %37, 97
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %4
%41 = icmp sle i32 %40, 102
br i1 %41, label %48, label %42
42: ; preds = %39, %36
%43 = load i32, i32* %4
%44 = icmp sge i32 %43, 65
br i1 %44, label %45, label %51
45: ; preds = %42
%46 = load i32, i32* %4
%47 = icmp sle i32 %46, 70
br i1 %47, label %48, label %51
48: ; preds = %45, %39, %33
%49 = load i32, i32* %5
%50 = add i32 %49, 1
store i32 %50, i32* %5
br label %55
51: ; preds = %45, %42
%52 = load %struct.lookahead_state*, %struct.lookahead_state** %3
%53 = load i32, i32* %6
%54 = call i32 @_lookahead_revert(%struct.lookahead_state* %52, i32 %53)
br label %56
55: ; preds = %48
br label %26
56: ; preds = %51
%57 = load i32, i32* %5
%58 = icmp ugt i32 %57, 2
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = load i32, i32* %5
store i32 %60, i32* %2
br label %64
61: ; preds = %56
%62 = load %struct.lookahead_state*, %struct.lookahead_state** %3
%63 = call i32 @_lookahead_revert(%struct.lookahead_state* %62, i32 0)
store i32 0, i32* %2
br label %64
64: ; preds = %61, %59, %22, %11
%65 = load i32, i32* %2
ret i32 %65
}

LLVM IR (-O2):
%struct.lookahead_state = type { i32 }
define i32 @_parse_hex(%struct.lookahead_state* %0) {
%2 = tail call i32 @_lookahead_getc(%struct.lookahead_state* %0)
%3 = icmp eq i32 %2, 48
br i1 %3, label %4, label %21
4: ; preds = %1
%5 = tail call i32 @_lookahead_getc(%struct.lookahead_state* %0)
%6 = and i32 %5, -33
%7 = icmp eq i32 %6, 88
br i1 %7, label %8, label %21
8: ; preds = %4, %16
%9 = phi i32 [ %17, %16 ], [ 2, %4 ]
%10 = tail call i32 @_lookahead_tell(%struct.lookahead_state* %0)
%11 = tail call i32 @_lookahead_getc(%struct.lookahead_state* %0)
%12 = freeze i32 %11
%13 = add i32 %12, -48
%14 = icmp ult i32 %13, 10
br i1 %14, label %16, label %15
15: ; preds = %8
switch i32 %12, label %18 [
i32 102, label %16
i32 101, label %16
i32 100, label %16
i32 99, label %16
i32 98, label %16
i32 97, label %16
i32 70, label %16
i32 69, label %16
i32 68, label %16
i32 67, label %16
i32 66, label %16
i32 65, label %16
]
16: ; preds = %8, %15, %15, %15, %15, %15, %15, %15, %15, %15, %15, %15, %15
%17 = add i32 %9, 1
br label %8
18: ; preds = %15
%19 = tail call i32 @_lookahead_revert(%struct.lookahead_state* %0, i32 %10)
%20 = icmp ugt i32 %9, 2
br i1 %20, label %23, label %21
21: ; preds = %18, %4, %1
%22 = tail call i32 @_lookahead_revert(%struct.lookahead_state* %0, i32 0)
br label %23
23: ; preds = %21, %18
%24 = phi i32 [ %9, %18 ], [ 0, %21 ]
ret i32 %24
}