#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 cstate {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ die(struct cstate *, char *);
int hex(struct cstate *g, int c) {
  if (c >= '0' && c <= '9')
    return c - '0';
  if (c >= 'a' && c <= 'f')
    return c - 'a' + 0xA;
  if (c >= 'A' && c <= 'F')
    return c - 'A' + 0xA;
  die(g, "invalid escape sequence");
  return 0;
}


x86 assembly (clang, -O0):
<hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x30,-0x14(%rbp)
jl     1141 <hex+0x31>
cmpl   $0x39,-0x14(%rbp)
jg     1141 <hex+0x31>
mov    -0x14(%rbp),%eax
sub    $0x30,%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <hex+0x92>
cmpl   $0x61,-0x14(%rbp)
jl     1166 <hex+0x56>
cmpl   $0x66,-0x14(%rbp)
jg     1166 <hex+0x56>
mov    -0x14(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <hex+0x92>
cmpl   $0x41,-0x14(%rbp)
jl     118b <hex+0x7b>
cmpl   $0x46,-0x14(%rbp)
jg     118b <hex+0x7b>
mov    -0x14(%rbp),%eax
sub    $0x41,%eax
add    $0xa,%eax
mov    %eax,-0x4(%rbp)
jmp    11a2 <hex+0x92>
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1030 <die@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex>:
lea    -0x30(%rsi),%eax
cmp    $0xa,%eax
jb     1147 <hex+0x37>
lea    -0x61(%rsi),%eax
cmp    $0x5,%eax
ja     1126 <hex+0x16>
add    $0xffffffa9,%esi
mov    %esi,%eax
ret
lea    -0x41(%rsi),%eax
cmp    $0x5,%eax
ja     1134 <hex+0x24>
add    $0xffffffc9,%esi
mov    %esi,%eax
ret
push   %rax
lea    0xec4(%rip),%rsi
call   1030 <die@plt>
xor    %eax,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
%struct.cstate = type { i32 }
@.str = [24 x i8] c"invalid escape sequence\00"
define i32 @hex(%struct.cstate* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.cstate*
%5 = alloca i32
store %struct.cstate* %0, %struct.cstate** %4
store i32 %1, i32* %5
%6 = load i32, i32* %5
%7 = icmp sge i32 %6, 48
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* %5
%10 = icmp sle i32 %9, 57
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* %5
%13 = sub nsw i32 %12, 48
store i32 %13, i32* %3
br label %37
14: ; preds = %8, %2
%15 = load i32, i32* %5
%16 = icmp sge i32 %15, 97
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = load i32, i32* %5
%19 = icmp sle i32 %18, 102
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %5
%22 = sub nsw i32 %21, 97
%23 = add nsw i32 %22, 10
store i32 %23, i32* %3
br label %37
24: ; preds = %17, %14
%25 = load i32, i32* %5
%26 = icmp sge i32 %25, 65
br i1 %26, label %27, label %34
27: ; preds = %24
%28 = load i32, i32* %5
%29 = icmp sle i32 %28, 70
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* %5
%32 = sub nsw i32 %31, 65
%33 = add nsw i32 %32, 10
store i32 %33, i32* %3
br label %37
34: ; preds = %27, %24
%35 = load %struct.cstate*, %struct.cstate** %4
%36 = call i32 @die(%struct.cstate* %35, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %37
37: ; preds = %34, %30, %20, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.cstate = type { i32 }
@.str = [24 x i8] c"invalid escape sequence\00"
define i32 @hex(%struct.cstate* %0, i32 %1) {
%3 = add i32 %1, -48
%4 = icmp ult i32 %3, 10
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = add i32 %1, -97
%7 = icmp ult i32 %6, 6
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = add nsw i32 %1, -87
br label %17
10: ; preds = %5
%11 = add i32 %1, -65
%12 = icmp ult i32 %11, 6
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = add nsw i32 %1, -55
br label %17
15: ; preds = %10
%16 = tail call i32 @die(%struct.cstate* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %2, %15, %13, %8
%18 = phi i32 [ %9, %8 ], [ %14, %13 ], [ 0, %15 ], [ %3, %2 ]
ret i32 %18
}