#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 _char_htoi(char);
void urldecode(char *src) {
  char c, *s, *d;
  for (d = s = src; *s; s++, d++) {
    c = *s;
    if (c == '%') {
      c = *++s;
      if (c == '%')
        c = '%';
      else {
        c = _char_htoi(c) << 4 | _char_htoi(*++s);
      }
      *d = c;
    } else {
      *d = c;
    }
  }
  *d = '\0';
}


x86 assembly (clang, -O0):
<urldecode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     11e0 <urldecode+0xd0>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x25,%eax
jne    11b5 <urldecode+0xa5>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    0x1(%rax),%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x25,%eax
jne    1176 <urldecode+0x66>
movb   $0x25,-0x9(%rbp)
jmp    11a7 <urldecode+0x97>
movsbl -0x9(%rbp),%edi
call   1030 <_char_htoi@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%edi
call   1030 <_char_htoi@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
mov    -0x9(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    11be <urldecode+0xae>
mov    -0x9(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
jmp    11c3 <urldecode+0xb3>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1128 <urldecode+0x18>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<urldecode>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    %rdi,%rbp
jmp    112f <urldecode+0x1f>
nopl   0x0(%rax)
test   %al,%al
je     1171 <urldecode+0x61>
mov    %al,0x0(%rbp)
add    $0x1,%rbx
add    $0x1,%rbp
movzbl (%rbx),%eax
cmp    $0x25,%al
jne    1120 <urldecode+0x10>
movzbl 0x1(%rbx),%eax
cmp    $0x25,%al
jne    1150 <urldecode+0x40>
add    $0x1,%rbx
mov    $0x25,%al
jmp    1124 <urldecode+0x14>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
call   1030 <_char_htoi@plt>
mov    %eax,%r14d
shl    $0x4,%r14d
movsbl 0x2(%rbx),%edi
add    $0x2,%rbx
call   1030 <_char_htoi@plt>
or     %r14d,%eax
jmp    1124 <urldecode+0x14>
movb   $0x0,0x0(%rbp)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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