#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(str, "%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)
lea    -0x13(%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,%rbx
lea    0xec9(%rip),%r14
lea    0x9(%rsp),%r15
lea    0xc(%rsp),%r12
mov    %rdi,%r13
jmp    115d <urlDecode+0x3d>
cs nopw 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     11f2 <urlDecode+0xd2>
add    $0x1,%rbx
mov    %al,0x0(%r13)
add    $0x1,%r13
jmp    115d <urlDecode+0x3d>
xchg   %ax,%ax
movsbl 0x1(%rbx),%edi
call   1040 <isxdigit@plt>
test   %rax,%rax
je     11e0 <urlDecode+0xc0>
movsbl 0x2(%rbx),%edi
call   1040 <isxdigit@plt>
test   %rax,%rax
je     11e0 <urlDecode+0xc0>
movzbl 0x1(%rbx),%eax
mov    %al,0x9(%rsp)
movzbl 0x2(%rbx),%eax
mov    %al,0xa(%rsp)
movb   $0x0,0xb(%rsp)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%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)
add    $0x1,%rbx
movb   $0x25,0x0(%r13)
add    $0x1,%r13
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 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%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 [3 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 1
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 2
br label %8
8: ; preds = %34, %1
%9 = phi i8* [ %0, %1 ], [ %35, %34 ]
%10 = phi i8* [ %0, %1 ], [ %36, %34 ]
%11 = load i8, i8* %9
switch i8 %11, label %32 [
i8 0, label %37
i8 37, label %12
i8 43, label %30
]
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %9, i64 1
%14 = load i8, i8* %13
%15 = call i64 @isxdigit(i8 signext %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %29, label %17
17: ; preds = %12
%18 = getelementptr inbounds i8, i8* %9, i64 2
%19 = load i8, i8* %18
%20 = call i64 @isxdigit(i8 signext %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %29, label %22
22: ; preds = %17
%23 = load i8, i8* %13
store i8 %23, i8* %4
%24 = load i8, i8* %18
store i8 %24, i8* %6
store i8 0, i8* %7
%25 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %3)
%26 = load i32, i32* %3
%27 = trunc i32 %26 to i8
store i8 %27, i8* %10
%28 = getelementptr inbounds i8, i8* %9, i64 3
br label %34
29: ; preds = %17, %12
store i8 37, i8* %10
br label %34
30: ; preds = %8
store i8 32, i8* %10
%31 = getelementptr inbounds i8, i8* %9, i64 1
br label %34
32: ; preds = %8
%33 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %11, i8* %10
br label %34
34: ; preds = %30, %32, %22, %29
%35 = phi i8* [ %28, %22 ], [ %13, %29 ], [ %31, %30 ], [ %33, %32 ]
%36 = getelementptr inbounds i8, i8* %10, i64 1
br label %8
37: ; preds = %8
store i8 0, i8* %10
ret void
}