#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 from_hex(char const);
scalar_t__ isxdigit(char const);
void decode_url(char *to, const char *from) {
  while (*from) {
    if (*from == '%' && isxdigit(*(from + 1)) && isxdigit(*(from + 2))) {
      *to++ = from_hex(*(from + 1)) << 4 | from_hex(*(from + 2));
      from += 3;
      continue;
    }
    *to++ = *from++;
  }
  *to = 0;
}


x86 assembly (clang, -O0):
<decode_url>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ed <decode_url+0xcd>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11c6 <decode_url+0xa6>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isxdigit@plt>
cmp    $0x0,%rax
je     11c6 <decode_url+0xa6>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <isxdigit@plt>
cmp    $0x0,%rax
je     11c6 <decode_url+0xa6>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <from_hex@plt>
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1040 <from_hex@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
or     %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <decode_url+0x10>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1130 <decode_url+0x10>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_url>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
jmp    1142 <decode_url+0x22>
nopl   0x0(%rax)
test   %al,%al
je     118b <decode_url+0x6b>
movzbl (%rbx),%eax
add    $0x1,%rbx
mov    %al,(%r14)
add    $0x1,%r14
movzbl (%rbx),%eax
cmp    $0x25,%al
jne    1130 <decode_url+0x10>
movsbl 0x1(%rbx),%edi
call   1030 <isxdigit@plt>
test   %rax,%rax
je     1134 <decode_url+0x14>
movsbl 0x2(%rbx),%edi
call   1030 <isxdigit@plt>
test   %rax,%rax
je     1134 <decode_url+0x14>
movsbl 0x1(%rbx),%edi
call   1040 <from_hex@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x2(%rbx),%edi
call   1040 <from_hex@plt>
or     %ebp,%eax
mov    %al,(%r14)
add    $0x3,%rbx
add    $0x1,%r14
jmp    1142 <decode_url+0x22>
movb   $0x0,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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