#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 /*<<< orphan*/ _q_x2c(char, char);
size_t _q_urldecode(char *str) {
  if (str == NULL) {
    return 0;
  }
  char *pEncPt, *pBinPt = str;
  for (pEncPt = str; *pEncPt != '\0'; pEncPt++) {
    switch (*pEncPt) {
    case '+': {
      *pBinPt++ = ' ';
      break;
    }
    case '%': {
      *pBinPt++ = _q_x2c(*(pEncPt + 1), *(pEncPt + 2));
      pEncPt += 2;
      break;
    }
    default: {
      *pBinPt++ = *pEncPt;
      break;
    }
    }
  }
  *pBinPt = '\0';
  return (pBinPt - str);
}


x86 assembly (clang, -O0):
<_q_urldecode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1134 <_q_urldecode+0x24>
movq   $0x0,-0x8(%rbp)
jmp    1212 <_q_urldecode+0x102>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11fc <_q_urldecode+0xec>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
sub    $0x25,%eax
je     1194 <_q_urldecode+0x84>
jmp    116c <_q_urldecode+0x5c>
mov    -0x24(%rbp),%eax
sub    $0x2b,%eax
jne    11cf <_q_urldecode+0xbf>
jmp    117d <_q_urldecode+0x6d>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x20,(%rax)
jmp    11e6 <_q_urldecode+0xd6>
mov    -0x18(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x18(%rbp),%rax
movsbl %cl,%edi
movsbl 0x2(%rax),%esi
call   1030 <_q_x2c@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    11e6 <_q_urldecode+0xd6>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11eb <_q_urldecode+0xdb>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <_q_urldecode+0x34>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_q_urldecode>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     116e <_q_urldecode+0x5e>
mov    %rdi,%r14
mov    (%rdi),%al
mov    %rdi,%r15
test   %al,%al
je     1165 <_q_urldecode+0x55>
mov    %r14,%r15
mov    %r14,%rbx
jmp    1145 <_q_urldecode+0x35>
xchg   %ax,%ax
mov    $0x20,%al
mov    %al,(%r15)
add    $0x1,%r15
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     1165 <_q_urldecode+0x55>
movsbl %al,%ecx
cmp    $0x2b,%ecx
je     1130 <_q_urldecode+0x20>
cmp    $0x25,%ecx
jne    1132 <_q_urldecode+0x22>
movsbl 0x1(%rbx),%edi
movsbl 0x2(%rbx),%esi
add    $0x2,%rbx
call   1030 <_q_x2c@plt>
jmp    1132 <_q_urldecode+0x22>
movb   $0x0,(%r15)
sub    %r14,%r15
jmp    1171 <_q_urldecode+0x61>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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