#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 */
char strtol(char *, int /*<<< orphan*/, int);
void url_decode(char *dst, const char *src) {
  for (;;) {
    if (src[0] == '%' && src[1] && src[2]) {
      char hexbuf[3];
      hexbuf[0] = src[1];
      hexbuf[1] = src[2];
      hexbuf[2] = '\0';
      *dst = strtol(&hexbuf[0], 0, 16);
      src += 3;
    } else if (src[0] == '+') {
      *dst = ' ';
      src++;
    } else {
      *dst = *src;
      src++;
      if (*dst == '\0')
        break;
    }
    dst++;
  }
}


x86 assembly (clang, -O0):
<url_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1193 <url_decode+0x83>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1193 <url_decode+0x83>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
je     1193 <url_decode+0x83>
mov    -0x10(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x13(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2(%rax),%al
mov    %al,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
lea    -0x13(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
jmp    11f2 <url_decode+0xe2>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    11bb <url_decode+0xab>
mov    -0x8(%rbp),%rax
movb   $0x20,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11ed <url_decode+0xdd>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e8 <url_decode+0xd8>
jmp    1203 <url_decode+0xf3>
jmp    11ed <url_decode+0xdd>
jmp    11f2 <url_decode+0xe2>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1120 <url_decode+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_decode>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xd(%rsp),%r15
jmp    113c <url_decode+0x2c>
cs nopw 0x0(%rax,%rax,1)
movb   $0x20,(%r14)
add    $0x1,%rbx
add    $0x1,%r14
movzbl (%rbx),%eax
cmp    $0x2b,%al
je     1130 <url_decode+0x20>
cmp    $0x25,%al
jne    1180 <url_decode+0x70>
movzbl 0x1(%rbx),%eax
test   %al,%al
je     1190 <url_decode+0x80>
movzbl 0x2(%rbx),%ecx
test   %cl,%cl
je     1190 <url_decode+0x80>
mov    %al,0xd(%rsp)
mov    %cl,0xe(%rsp)
movb   $0x0,0xf(%rsp)
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1030 <strtol@plt>
mov    %al,(%r14)
add    $0x3,%rbx
add    $0x1,%r14
jmp    113c <url_decode+0x2c>
mov    %al,(%r14)
test   %al,%al
jne    1134 <url_decode+0x24>
jmp    119e <url_decode+0x8e>
nopl   0x0(%rax)
add    $0x1,%rbx
movb   $0x25,(%r14)
add    $0x1,%r14
jmp    113c <url_decode+0x2c>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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