#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__ isxdigit(char);
int /*<<< orphan*/ sscanf(char *, char *, int *);
void urlDecode(char *p) {
  char *pD, str[3];
  int i;
  pD = p;
  while (*p) {
    if (*p == '%') {
      p++;
      if (isxdigit(p[0]) && isxdigit(p[1])) {
        str[0] = p[0];
        str[1] = p[1];
        str[2] = 0;
        sscanf(p, "%02X", &i);
        *pD++ = (char)i;
        p += 2;
      } else
        *pD++ = '%';
    } else if (*p == '+') {
      *pD++ = ' ';
      p++;
    } else {
      *pD++ = *p++;
    }
  }
  *pD = '\0';
}


x86 assembly (clang, -O0):
<urlDecode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1252 <urlDecode+0x132>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11f3 <urlDecode+0xd3>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%rax
je     11dc <urlDecode+0xbc>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <isxdigit@plt>
cmp    $0x0,%rax
je     11dc <urlDecode+0xbc>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x13(%rbp)
mov    -0x8(%rbp),%rax
mov    0x1(%rax),%al
mov    %al,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe54(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    11ee <urlDecode+0xce>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x25,(%rax)
jmp    124d <urlDecode+0x12d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1226 <urlDecode+0x106>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x20,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1248 <urlDecode+0x128>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    124d <urlDecode+0x12d>
jmp    1134 <urlDecode+0x14>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<urlDecode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r13
lea    0xec9(%rip),%r14
lea    0xc(%rsp),%r15
mov    %rdi,%rbx
jmp    115d <urlDecode+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x20,0x0(%r13)
add    $0x1,%rbx
add    $0x1,%r13
movzbl (%rbx),%eax
cmp    $0x25,%al
je     1180 <urlDecode+0x60>
cmp    $0x2b,%al
je     1150 <urlDecode+0x30>
test   %al,%al
je     11e1 <urlDecode+0xc1>
add    $0x1,%rbx
mov    %al,0x0(%r13)
add    $0x1,%r13
jmp    115d <urlDecode+0x3d>
nopw   0x0(%rax,%rax,1)
lea    0x1(%rbx),%r12
movsbl 0x1(%rbx),%edi
call   1040 <isxdigit@plt>
test   %rax,%rax
je     11d0 <urlDecode+0xb0>
movsbl 0x2(%rbx),%edi
call   1040 <isxdigit@plt>
test   %rax,%rax
je     11d0 <urlDecode+0xb0>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <sscanf@plt>
movzbl 0xc(%rsp),%eax
mov    %al,0x0(%r13)
add    $0x3,%rbx
add    $0x1,%r13
jmp    115d <urlDecode+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movb   $0x25,0x0(%r13)
add    $0x1,%r13
mov    %r12,%rbx
jmp    115d <urlDecode+0x3d>
movb   $0x0,0x0(%r13)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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