#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__ IntFromHex(char *);
int /*<<< orphan*/ SwapChar(char *, char, char);
scalar_t__ isxdigit(char);
void URLDecode(char *pEncoded) {
  char *pDecoded;
  SwapChar(pEncoded, '+', ' ');
  pDecoded = pEncoded;
  while (*pEncoded) {
    if (*pEncoded == '%') {
      pEncoded++;
      if (isxdigit(pEncoded[0]) && isxdigit(pEncoded[1])) {
        *pDecoded++ = (char)IntFromHex(pEncoded);
        pEncoded += 2;
      }
    } else {
      *pDecoded++ = *pEncoded++;
    }
  }
  *pDecoded = '\0';
}


x86 assembly (clang, -O0):
<URLDecode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2b,%esi
mov    $0x20,%edx
call   1030 <SwapChar@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1201 <URLDecode+0xd1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11da <URLDecode+0xaa>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%rax
je     11d5 <URLDecode+0xa5>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%rax
je     11d5 <URLDecode+0xa5>
mov    -0x8(%rbp),%rdi
call   1040 <IntFromHex@plt>
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    11fc <URLDecode+0xcc>
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    1157 <URLDecode+0x27>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<URLDecode>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x2b,%esi
mov    $0x20,%edx
call   1030 <SwapChar@plt>
mov    %rbx,%r14
nopl   0x0(%rax)
add    $0x1,%rbx
movzbl -0x1(%rbx),%eax
cmp    $0x25,%al
jne    118c <URLDecode+0x5c>
movsbl (%rbx),%edi
call   1050 <isxdigit@plt>
test   %rax,%rax
je     1150 <URLDecode+0x20>
movsbl 0x1(%rbx),%edi
call   1050 <isxdigit@plt>
test   %rax,%rax
je     1150 <URLDecode+0x20>
mov    %rbx,%rdi
call   1040 <IntFromHex@plt>
mov    %al,(%r14)
add    $0x2,%rbx
add    $0x1,%r14
jmp    1150 <URLDecode+0x20>
test   %al,%al
je     1199 <URLDecode+0x69>
mov    %al,(%r14)
add    $0x1,%r14
jmp    1150 <URLDecode+0x20>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @URLDecode(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @SwapChar(i8* %4, i8 signext 43, i8 signext 32)
%6 = load i8*, i8** %2
store i8* %6, i8** %3
br label %7
7: ; preds = %45, %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %46
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 %39
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 %38
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 %38
30: ; preds = %24
%31 = load i8*, i8** %2
%32 = call i64 @IntFromHex(i8* %31)
%33 = trunc i64 %32 to i8
%34 = load i8*, i8** %3
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %3
store i8 %33, i8* %34
%36 = load i8*, i8** %2
%37 = getelementptr inbounds i8, i8* %36, i64 2
store i8* %37, i8** %2
br label %38
38: ; preds = %30, %24, %16
br label %45
39: ; preds = %11
%40 = load i8*, i8** %2
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %2
%42 = load i8, i8* %40
%43 = load i8*, i8** %3
%44 = getelementptr inbounds i8, i8* %43, i32 1
store i8* %44, i8** %3
store i8 %42, i8* %43
br label %45
45: ; preds = %39, %38
br label %7
46: ; preds = %7
%47 = load i8*, i8** %3
store i8 0, i8* %47
ret void
}

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