#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 */
int hexdigit(int /*<<< orphan*/);
bool read_hex_utf8(char const **const src, char **const dst) {
  char const *s = *src;
  char *d = *dst;
  if ('%' != *s++)
    return false;
  int const hi = hexdigit(*s++);
  if (hi < 0)
    return false;
  int const lo = hexdigit(*s++);
  if (lo < 0)
    return false;
  char const c = hi << 4 | lo << 0;
  if ('\0' == c)
    return false;
  *d++ = c;
  *src = s;
  *dst = d;
  return true;
}


x86 assembly (clang, -O0):
<read_hex_utf8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%ecx
mov    $0x25,%eax
cmp    %ecx,%eax
je     1161 <read_hex_utf8+0x51>
movl   $0x0,-0x4(%rbp)
jmp    121d <read_hex_utf8+0x10d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
call   1030 <hexdigit@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1191 <read_hex_utf8+0x81>
movl   $0x0,-0x4(%rbp)
jmp    121d <read_hex_utf8+0x10d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl (%rax),%edi
call   1030 <hexdigit@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    11c1 <read_hex_utf8+0xb1>
movl   $0x0,-0x4(%rbp)
jmp    121d <read_hex_utf8+0x10d>
mov    -0x2c(%rbp),%eax
shl    $0x4,%eax
mov    -0x30(%rbp),%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11ec <read_hex_utf8+0xdc>
movl   $0x0,-0x4(%rbp)
jmp    121d <read_hex_utf8+0x10d>
mov    -0x31(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_hex_utf8>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%rbx
xor    %r15d,%r15d
cmpb   $0x25,(%rbx)
jne    116d <read_hex_utf8+0x5d>
mov    %rsi,%r14
mov    %rdi,%r12
mov    (%rsi),%r13
movsbl 0x1(%rbx),%edi
call   1030 <hexdigit@plt>
test   %eax,%eax
js     116d <read_hex_utf8+0x5d>
mov    %eax,%ebp
movsbl 0x2(%rbx),%edi
call   1030 <hexdigit@plt>
test   %eax,%eax
js     116d <read_hex_utf8+0x5d>
shl    $0x4,%ebp
or     %ebp,%eax
test   %al,%al
je     116d <read_hex_utf8+0x5d>
add    $0x3,%rbx
mov    %al,0x0(%r13)
add    $0x1,%r13
mov    %rbx,(%r12)
mov    %r13,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_hex_utf8(i8** %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i8** %0, i8*** %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %4
%12 = load i8*, i8** %11
store i8* %12, i8** %6
%13 = load i8**, i8*** %5
%14 = load i8*, i8** %13
store i8* %14, i8** %7
%15 = load i8*, i8** %6
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %6
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
%19 = icmp ne i32 37, %18
br i1 %19, label %20, label %21
20: ; preds = %2
store i32 0, i32* %3
br label %58
21: ; preds = %2
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
%24 = load i8, i8* %22
%25 = sext i8 %24 to i32
%26 = call i32 @hexdigit(i32 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %21
store i32 0, i32* %3
br label %58
30: ; preds = %21
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %6
%33 = load i8, i8* %31
%34 = sext i8 %33 to i32
%35 = call i32 @hexdigit(i32 %34)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %30
store i32 0, i32* %3
br label %58
39: ; preds = %30
%40 = load i32, i32* %8
%41 = shl i32 %40, 4
%42 = load i32, i32* %9
%43 = shl i32 %42, 0
%44 = or i32 %41, %43
%45 = trunc i32 %44 to i8
store i8 %45, i8* %10
%46 = load i8, i8* %10
%47 = sext i8 %46 to i32
%48 = icmp eq i32 0, %47
br i1 %48, label %49, label %50
49: ; preds = %39
store i32 0, i32* %3
br label %58
50: ; preds = %39
%51 = load i8, i8* %10
%52 = load i8*, i8** %7
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %7
store i8 %51, i8* %52
%54 = load i8*, i8** %6
%55 = load i8**, i8*** %4
store i8* %54, i8** %55
%56 = load i8*, i8** %7
%57 = load i8**, i8*** %5
store i8* %56, i8** %57
store i32 1, i32* %3
br label %58
58: ; preds = %50, %49, %38, %29, %20
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
define i32 @read_hex_utf8(i8** nocapture %0, i8** nocapture %1) {
%3 = load i8*, i8** %0
%4 = load i8*, i8** %1
%5 = load i8, i8* %3
%6 = icmp eq i8 %5, 37
br i1 %6, label %7, label %28
7: ; preds = %2
%8 = getelementptr inbounds i8, i8* %3, i64 1
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = tail call i32 @hexdigit(i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %28, label %13
13: ; preds = %7
%14 = getelementptr inbounds i8, i8* %3, i64 2
%15 = getelementptr inbounds i8, i8* %3, i64 3
%16 = load i8, i8* %14
%17 = sext i8 %16 to i32
%18 = tail call i32 @hexdigit(i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %13
%21 = shl i32 %11, 4
%22 = or i32 %18, %21
%23 = and i32 %22, 255
%24 = icmp eq i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %20
%26 = trunc i32 %22 to i8
%27 = getelementptr inbounds i8, i8* %4, i64 1
store i8 %26, i8* %4
store i8* %15, i8** %0
store i8* %27, i8** %1
br label %28
28: ; preds = %7, %25, %20, %13, %2
%29 = phi i32 [ 0, %2 ], [ 0, %7 ], [ 0, %13 ], [ 1, %25 ], [ 0, %20 ]
ret i32 %29
}