void test_urldecode() {
  char *param = "%26bla+r";
  char dest[128] = {
      0,
  };
  do {
    if (!(urldecode(dest, param, 128))) {
      printf("\033[31m  [%s] failed: %s  \033[0m\n",
             "urldecode(dest, param, 128)", "Failed to decode.");
      printf("\033[31m  %s -> FAILED  \033[0m\n", __func__);
      return;
    }
  } while (0);
  do {
    if (strcmp(dest, "&bla r")) {
      printf("\033[31m  expected [%s == %s] \033[0m\n", "dest", "\"&bla r\"");
      printf("\033[31m  a = \"%s\" \033[0m\n", dest);
      printf("\033[31m  b = \"%s\" \033[0m\n", "&bla r");
      printf("\033[31m  %s -> FAILED \033[0m\n", __func__);
      return;
    }
  } while (0);
  printf("\033[32m  %s -> OK \033[0m\n", __func__);
}


x86 assembly (clang, -O0):
<test_urldecode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1040 <memset@plt>
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x80,%edx
mov    $0x0,%al
call   1060 <urldecode@plt>
cmp    $0x0,%eax
jne    11bf <test_urldecode+0x7f>
lea    0xe79(%rip),%rdi
lea    0xe90(%rip),%rsi
lea    0xea5(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xea9(%rip),%rdi
lea    0xebd(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125f <test_urldecode+0x11f>
jmp    11c4 <test_urldecode+0x84>
jmp    11c9 <test_urldecode+0x89>
lea    -0x90(%rbp),%rdi
lea    0xea8(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     1245 <test_urldecode+0x105>
lea    0xe9a(%rip),%rdi
lea    0xeb4(%rip),%rsi
lea    0xeb2(%rip),%rdx
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeae(%rip),%rdi
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xeaf(%rip),%rdi
lea    0xe37(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    125f <test_urldecode+0x11f>
jmp    124a <test_urldecode+0x10a>
lea    0xeaa(%rip),%rdi
lea    0xe18(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_urldecode>:
sub    $0x88,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xea8(%rip),%rsi
mov    %rsp,%rdi
mov    $0x80,%edx
xor    %eax,%eax
call   1040 <urldecode@plt>
test   %eax,%eax
je     11cb <test_urldecode+0xab>
mov    $0x616c6226,%eax
xor    (%rsp),%eax
mov    $0x722061,%ecx
xor    0x3(%rsp),%ecx
or     %eax,%ecx
je     11f0 <test_urldecode+0xd0>
lea    0xeff(%rip),%rdi
lea    0xf19(%rip),%rsi
lea    0xf17(%rip),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf12(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf17(%rip),%rdi
lea    0xec4(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xf18(%rip),%rdi
jmp    11f7 <test_urldecode+0xd7>
lea    0xe37(%rip),%rdi
lea    0xe4e(%rip),%rsi
lea    0xe63(%rip),%rdx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe67(%rip),%rdi
jmp    11f7 <test_urldecode+0xd7>
lea    0xf04(%rip),%rdi
lea    0xe72(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x88,%rsp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%26bla+r\00"
@.str.1 = [30 x i8] c"\1B[31m [%s] failed: %s \1B[0m\0A\00"
@.str.2 = [28 x i8] c"urldecode(dest, param, 128)\00"
@.str.3 = [18 x i8] c"Failed to decode.\00"
@.str.4 = [27 x i8] c"\1B[31m %s -> FAILED \1B[0m\0A\00"
@__func__.test_urldecode = [15 x i8] c"test_urldecode\00"
@.str.5 = [7 x i8] c"&bla r\00"
@.str.6 = [33 x i8] c"\1B[31m expected [%s == %s] \1B[0m\0A\00"
@.str.7 = [5 x i8] c"dest\00"
@.str.8 = [9 x i8] c"\22&bla r\22\00"
@.str.9 = [22 x i8] c"\1B[31m a = \22%s\22 \1B[0m\0A\00"
@.str.10 = [22 x i8] c"\1B[31m b = \22%s\22 \1B[0m\0A\00"
@.str.11 = [26 x i8] c"\1B[31m %s -> FAILED \1B[0m\0A\00"
@.str.12 = [22 x i8] c"\1B[32m %s -> OK \1B[0m\0A\00"
define void @test_urldecode() {
%1 = alloca i8*
%2 = alloca [128 x i8]
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %1
%3 = bitcast [128 x i8]* %2 to i8*
br label %4
4: ; preds = %0
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = load i8*, i8** %1
%7 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @urldecode to i32 (i8*, i8*, i32, ...)*)(i8* %5, i8* %6, i32 128)
%8 = icmp ne i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__func__.test_urldecode, i64 0, i64 0))
br label %27
12: ; preds = %4
br label %13
13: ; preds = %12
br label %14
14: ; preds = %13
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%16 = call i32 @strcmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%20 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__func__.test_urldecode, i64 0, i64 0))
br label %27
24: ; preds = %14
br label %25
25: ; preds = %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__func__.test_urldecode, i64 0, i64 0))
br label %27
27: ; preds = %25, %18, %9
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"%26bla+r\00"
@.str.1 = [30 x i8] c"\1B[31m [%s] failed: %s \1B[0m\0A\00"
@.str.2 = [28 x i8] c"urldecode(dest, param, 128)\00"
@.str.3 = [18 x i8] c"Failed to decode.\00"
@.str.4 = [27 x i8] c"\1B[31m %s -> FAILED \1B[0m\0A\00"
@__func__.test_urldecode = [15 x i8] c"test_urldecode\00"
@.str.5 = [7 x i8] c"&bla r\00"
@.str.6 = [33 x i8] c"\1B[31m expected [%s == %s] \1B[0m\0A\00"
@.str.7 = [5 x i8] c"dest\00"
@.str.8 = [9 x i8] c"\22&bla r\22\00"
@.str.9 = [22 x i8] c"\1B[31m a = \22%s\22 \1B[0m\0A\00"
@.str.10 = [22 x i8] c"\1B[31m b = \22%s\22 \1B[0m\0A\00"
@.str.11 = [26 x i8] c"\1B[31m %s -> FAILED \1B[0m\0A\00"
@.str.12 = [22 x i8] c"\1B[32m %s -> OK \1B[0m\0A\00"
define void @test_urldecode() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @urldecode to i32 (i8*, i8*, i32, ...)*)(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 128)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %14
7: ; preds = %0
%8 = call i32 @bcmp(i8* dereferenceable(7) %2, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i64 7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0), i8* %2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %14
14: ; preds = %7, %10, %5
%15 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), %10 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.12, i64 0, i64 0), %7 ]
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %15, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @__func__.test_urldecode, i64 0, i64 0))
ret void
}