char *url_decode(char *str) {
  char *pstr = str, *buf = malloc(strlen(str) + 1), *pbuf = buf;
  if (!buf)
    fatal_int("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/hlzz/dotfiles/refs/heads/master/dev/"
              "netdata/src/url.c",
              __FUNCTION__, 63, "Cannot allocate memory.");
  while (*pstr) {
    if (*pstr == '%') {
      if (pstr[1] && pstr[2]) {
        *pbuf++ = from_hex(pstr[1]) << 4 | from_hex(pstr[2]);
        pstr += 2;
      }
    } else if (*pstr == '+')
      *pbuf++ = ' ';
    else
      *pbuf++ = *pstr;
    pstr++;
  }
  *pbuf = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<url_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a1 <url_decode+0x61>
lea    0xe79(%rip),%rdi
lea    0xf02(%rip),%rsi
mov    $0x3f,%edx
lea    0xf01(%rip),%rcx
mov    $0x0,%al
call   1060 <fatal_int@plt>
jmp    11a6 <url_decode+0x66>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1288 <url_decode+0x148>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1234 <url_decode+0xf4>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     122f <url_decode+0xef>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
je     122f <url_decode+0xef>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
mov    $0x0,%al
call   1050 <from_hex@plt>
shl    $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
mov    $0x0,%al
call   1050 <from_hex@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
or     %ecx,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
jmp    1277 <url_decode+0x137>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    125b <url_decode+0x11b>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x20,(%rax)
jmp    1272 <url_decode+0x132>
mov    -0x10(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1277 <url_decode+0x137>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11a6 <url_decode+0x66>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_decode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1181 <url_decode+0x41>
lea    0xe99(%rip),%rdi
lea    0xf22(%rip),%rsi
lea    0xf26(%rip),%rcx
mov    $0x3f,%edx
xor    %eax,%eax
call   1060 <fatal_int@plt>
mov    %r14,%rbp
jmp    119d <url_decode+0x5d>
cs nopw 0x0(%rax,%rax,1)
mov    $0x20,%al
mov    %al,0x0(%rbp)
add    $0x1,%rbp
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x25,%al
je     11b0 <url_decode+0x70>
cmp    $0x2b,%al
je     1190 <url_decode+0x50>
test   %al,%al
jne    1192 <url_decode+0x52>
jmp    11df <url_decode+0x9f>
xchg   %ax,%ax
movsbl 0x1(%rbx),%edi
test   %edi,%edi
je     1199 <url_decode+0x59>
cmpb   $0x0,0x2(%rbx)
je     1199 <url_decode+0x59>
add    $0x2,%rbx
xor    %eax,%eax
call   1050 <from_hex@plt>
mov    %eax,%r15d
shl    $0x4,%r15d
movsbl (%rbx),%edi
xor    %eax,%eax
call   1050 <from_hex@plt>
or     %r15d,%eax
jmp    1192 <url_decode+0x52>
movb   $0x0,0x0(%rbp)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/hlzz/dotfiles/refs/heads/master/dev/netdata/src/url.c\00"
@__FUNCTION__.url_decode = [11 x i8] c"url_decode\00"
@.str.1 = [24 x i8] c"Cannot allocate memory.\00"
define i8* @url_decode(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
%7 = load i8*, i8** %2
%8 = call i64 @strlen(i8* %7)
%9 = add i64 %8, 1
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
store i8* %11, i8** %5
%12 = load i8*, i8** %4
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 (i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @fatal_int to i32 (i8*, i8*, i32, i8*, ...)*)(i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__FUNCTION__.url_decode, i64 0, i64 0), i32 63, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
br label %17
17: ; preds = %71, %16
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %74
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 37
br i1 %25, label %26, label %57
26: ; preds = %21
%27 = load i8*, i8** %3
%28 = getelementptr inbounds i8, i8* %27, i64 1
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %56
32: ; preds = %26
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i64 2
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %56
38: ; preds = %32
%39 = load i8*, i8** %3
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = call i32 (i32, ...) bitcast (i32 (...)* @from_hex to i32 (i32, ...)*)(i32 %42)
%44 = shl i32 %43, 4
%45 = load i8*, i8** %3
%46 = getelementptr inbounds i8, i8* %45, i64 2
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = call i32 (i32, ...) bitcast (i32 (...)* @from_hex to i32 (i32, ...)*)(i32 %48)
%50 = or i32 %44, %49
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %5
store i8 %51, i8* %52
%54 = load i8*, i8** %3
%55 = getelementptr inbounds i8, i8* %54, i64 2
store i8* %55, i8** %3
br label %56
56: ; preds = %38, %32, %26
br label %71
57: ; preds = %21
%58 = load i8*, i8** %3
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp eq i32 %60, 43
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i8*, i8** %5
%64 = getelementptr inbounds i8, i8* %63, i32 1
store i8* %64, i8** %5
store i8 32, i8* %63
br label %70
65: ; preds = %57
%66 = load i8*, i8** %3
%67 = load i8, i8* %66
%68 = load i8*, i8** %5
%69 = getelementptr inbounds i8, i8* %68, i32 1
store i8* %69, i8** %5
store i8 %67, i8* %68
br label %70
70: ; preds = %65, %62
br label %71
71: ; preds = %70, %56
%72 = load i8*, i8** %3
%73 = getelementptr inbounds i8, i8* %72, i32 1
store i8* %73, i8** %3
br label %17
74: ; preds = %17
%75 = load i8*, i8** %5
store i8 0, i8* %75
%76 = load i8*, i8** %4
ret i8* %76
}

LLVM IR (-O2):
@.str = [144 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/hlzz/dotfiles/refs/heads/master/dev/netdata/src/url.c\00"
@__FUNCTION__.url_decode = [11 x i8] c"url_decode\00"
@.str.1 = [24 x i8] c"Cannot allocate memory.\00"
define i8* @url_decode(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i8*, i8*, i32, i8*, ...) bitcast (i32 (...)* @fatal_int to i32 (i8*, i8*, i32, i8*, ...)*)(i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__FUNCTION__.url_decode, i64 0, i64 0), i32 63, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
br label %9
9: ; preds = %8, %35
%10 = phi i8* [ %38, %35 ], [ %0, %8 ]
%11 = phi i8* [ %37, %35 ], [ %4, %8 ]
%12 = load i8, i8* %10
switch i8 %12, label %30 [
i8 0, label %39
i8 37, label %13
i8 43, label %31
]
13: ; preds = %9
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i8 %15, 0
br i1 %17, label %35, label %18
18: ; preds = %13
%19 = getelementptr inbounds i8, i8* %10, i64 2
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %35, label %22
22: ; preds = %18
%23 = tail call i32 (i32, ...) bitcast (i32 (...)* @from_hex to i32 (i32, ...)*)(i32 %16)
%24 = shl i32 %23, 4
%25 = load i8, i8* %19
%26 = sext i8 %25 to i32
%27 = tail call i32 (i32, ...) bitcast (i32 (...)* @from_hex to i32 (i32, ...)*)(i32 %26)
%28 = or i32 %27, %24
%29 = trunc i32 %28 to i8
br label %31
30: ; preds = %9
br label %31
31: ; preds = %9, %22, %30
%32 = phi i8 [ %12, %30 ], [ %29, %22 ], [ 32, %9 ]
%33 = phi i8* [ %10, %30 ], [ %19, %22 ], [ %10, %9 ]
%34 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %32, i8* %11
br label %35
35: ; preds = %31, %13, %18
%36 = phi i8* [ %10, %18 ], [ %10, %13 ], [ %33, %31 ]
%37 = phi i8* [ %11, %18 ], [ %11, %13 ], [ %34, %31 ]
%38 = getelementptr inbounds i8, i8* %36, i64 1
br label %9
39: ; preds = %9
store i8 0, i8* %11
ret i8* %4
}