#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 */
scalar_t__ isdigit(char);
char url_decode(char *p) {
  int x, i;
  char c;
  for (x = 0, i = 0; i < 2; i++) {
    x <<= (4 * i);
    c = *(++p);
    if (isdigit(c))
      x += (c - '0');
    else
      x += (c - 'a' + 10);
  }
  return x;
}


x86 assembly (clang, -O0):
<url_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
jge    119f <url_decode+0x8f>
mov    -0x10(%rbp),%ecx
shl    $0x2,%ecx
mov    -0xc(%rbp),%eax
shl    %cl,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    0x1(%rax),%al
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     117c <url_decode+0x6c>
movsbl -0x11(%rbp),%eax
sub    $0x30,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    118c <url_decode+0x7c>
movsbl -0x11(%rbp),%eax
sub    $0x61,%eax
add    $0xa,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1191 <url_decode+0x81>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112a <url_decode+0x1a>
mov    -0xc(%rbp),%eax
movsbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_decode>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
movsbl 0x1(%rdi),%ebp
mov    %ebp,%edi
call   1030 <isdigit@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,8),%ebx
add    %bpl,%bl
shl    $0x4,%bl
movsbl 0x2(%r14),%ebp
mov    %ebp,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
mov    $0xa9,%eax
mov    $0xd0,%ecx
cmove  %eax,%ecx
lea    (%rbx,%rbp,1),%eax
add    %cl,%al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @url_decode(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %34, %1
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %37
9: ; preds = %6
%10 = load i32, i32* %4
%11 = mul nsw i32 4, %10
%12 = load i32, i32* %3
%13 = shl i32 %12, %11
store i32 %13, i32* %3
%14 = load i8*, i8** %2
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %2
%16 = load i8, i8* %15
store i8 %16, i8* %5
%17 = load i8, i8* %5
%18 = call i64 @isdigit(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %9
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 48
%24 = load i32, i32* %3
%25 = add nsw i32 %24, %23
store i32 %25, i32* %3
br label %33
26: ; preds = %9
%27 = load i8, i8* %5
%28 = sext i8 %27 to i32
%29 = sub nsw i32 %28, 97
%30 = add nsw i32 %29, 10
%31 = load i32, i32* %3
%32 = add nsw i32 %31, %30
store i32 %32, i32* %3
br label %33
33: ; preds = %26, %20
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %6
37: ; preds = %6
%38 = load i32, i32* %3
%39 = trunc i32 %38 to i8
ret i8 %39
}

LLVM IR (-O2):
define signext i8 @url_decode(i8* nocapture %0) {
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %2
%4 = tail call i64 @isdigit(i8 signext %3)
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i8 9, i8 0
%7 = add i8 %6, %3
%8 = shl i8 %7, 4
%9 = getelementptr inbounds i8, i8* %0, i64 2
%10 = load i8, i8* %9
%11 = tail call i64 @isdigit(i8 signext %10)
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8 -87, i8 -48
%14 = add i8 %8, %10
%15 = add i8 %14, %13
ret i8 %15
}