#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 gauged_writer_hex_decode(char const);
void gauged_writer_url_decode(char *dst, const char *src, size_t len) {
  while (len-- && (*dst = *src++)) {
    if (*dst == '+') {
      *dst = ' ';
    } else if (*dst == '%' && src[0] && src[1] && len >= 2) {
      *dst = (gauged_writer_hex_decode(src[0]) << 4) |
             gauged_writer_hex_decode(src[1]);
      src += 2;
      len -= 2;
    }
    dst++;
  }
  *dst = '\0';
}


x86 assembly (clang, -O0):
<gauged_writer_url_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rcx
mov    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1165 <gauged_writer_url_decode+0x55>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    -0x8(%rbp),%rcx
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1175 <gauged_writer_url_decode+0x65>
jmp    1229 <gauged_writer_url_decode+0x119>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1191 <gauged_writer_url_decode+0x81>
mov    -0x8(%rbp),%rax
movb   $0x20,(%rax)
jmp    1218 <gauged_writer_url_decode+0x108>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1213 <gauged_writer_url_decode+0x103>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1213 <gauged_writer_url_decode+0x103>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1213 <gauged_writer_url_decode+0x103>
cmpq   $0x2,-0x18(%rbp)
jb     1213 <gauged_writer_url_decode+0x103>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <gauged_writer_hex_decode@plt>
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <gauged_writer_hex_decode@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
or     %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    1218 <gauged_writer_url_decode+0x108>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1124 <gauged_writer_url_decode+0x14>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gauged_writer_url_decode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
test   %rdx,%rdx
je     11ae <gauged_writer_url_decode+0x9e>
mov    %rdx,%r14
mov    %rsi,%rbx
jmp    1143 <gauged_writer_url_decode+0x33>
nopl   0x0(%rax,%rax,1)
movb   $0x20,(%r15)
add    $0x1,%r15
mov    %rax,%r14
mov    %rcx,%rbx
test   %rax,%rax
je     11ae <gauged_writer_url_decode+0x9e>
lea    -0x1(%r14),%rax
lea    0x1(%rbx),%rcx
movzbl (%rbx),%edx
mov    %dl,(%r15)
cmp    $0x25,%dl
je     1170 <gauged_writer_url_decode+0x60>
cmp    $0x2b,%dl
je     1130 <gauged_writer_url_decode+0x20>
test   %dl,%dl
jne    1134 <gauged_writer_url_decode+0x24>
jmp    11ae <gauged_writer_url_decode+0x9e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%rcx),%edx
test   %dl,%dl
je     1134 <gauged_writer_url_decode+0x24>
cmpb   $0x0,0x2(%rbx)
je     1134 <gauged_writer_url_decode+0x24>
cmp    $0x2,%rax
jb     1134 <gauged_writer_url_decode+0x24>
movsbl %dl,%edi
call   1030 <gauged_writer_hex_decode@plt>
mov    %eax,%ebp
shl    $0x4,%ebp
movsbl 0x2(%rbx),%edi
call   1030 <gauged_writer_hex_decode@plt>
or     %ebp,%eax
mov    %al,(%r15)
add    $0x3,%rbx
add    $0xfffffffffffffffd,%r14
mov    %rbx,%rcx
mov    %r14,%rax
jmp    1134 <gauged_writer_url_decode+0x24>
movb   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @gauged_writer_url_decode(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
br label %7
7: ; preds = %65, %3
%8 = load i64, i64* %6
%9 = add i64 %8, -1
store i64 %9, i64* %6
%10 = icmp ne i64 %8, 0
br i1 %10, label %11, label %18
11: ; preds = %7
%12 = load i8*, i8** %5
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %5
%14 = load i8, i8* %12
%15 = load i8*, i8** %4
store i8 %14, i8* %15
%16 = sext i8 %14 to i32
%17 = icmp ne i32 %16, 0
br label %18
18: ; preds = %11, %7
%19 = phi i1 [ false, %7 ], [ %17, %11 ]
br i1 %19, label %20, label %68
20: ; preds = %18
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 43
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i8*, i8** %4
store i8 32, i8* %26
br label %65
27: ; preds = %20
%28 = load i8*, i8** %4
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 37
br i1 %31, label %32, label %64
32: ; preds = %27
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i64 0
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %64
38: ; preds = %32
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i64 1
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %64
44: ; preds = %38
%45 = load i64, i64* %6
%46 = icmp uge i64 %45, 2
br i1 %46, label %47, label %64
47: ; preds = %44
%48 = load i8*, i8** %5
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = call i32 @gauged_writer_hex_decode(i8 signext %50)
%52 = shl i32 %51, 4
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 1
%55 = load i8, i8* %54
%56 = call i32 @gauged_writer_hex_decode(i8 signext %55)
%57 = or i32 %52, %56
%58 = trunc i32 %57 to i8
%59 = load i8*, i8** %4
store i8 %58, i8* %59
%60 = load i8*, i8** %5
%61 = getelementptr inbounds i8, i8* %60, i64 2
store i8* %61, i8** %5
%62 = load i64, i64* %6
%63 = sub i64 %62, 2
store i64 %63, i64* %6
br label %64
64: ; preds = %47, %44, %38, %32, %27
br label %65
65: ; preds = %64, %25
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %4
br label %7
68: ; preds = %18
%69 = load i8*, i8** %4
store i8 0, i8* %69
ret void
}

LLVM IR (-O2):
define void @gauged_writer_url_decode(i8* nocapture writeonly %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i64 %2, 0
br i1 %4, label %36, label %5
5: ; preds = %3, %31
%6 = phi i64 [ %33, %31 ], [ %2, %3 ]
%7 = phi i8* [ %32, %31 ], [ %1, %3 ]
%8 = phi i8* [ %34, %31 ], [ %0, %3 ]
%9 = add i64 %6, -1
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %7
store i8 %11, i8* %8
switch i8 %11, label %31 [
i8 0, label %36
i8 43, label %12
i8 37, label %13
]
12: ; preds = %5
store i8 32, i8* %8
br label %31
13: ; preds = %5
%14 = load i8, i8* %10
%15 = icmp eq i8 %14, 0
br i1 %15, label %31, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %7, i64 2
%18 = load i8, i8* %17
%19 = icmp ne i8 %18, 0
%20 = icmp ugt i64 %9, 1
%21 = select i1 %19, i1 %20, i1 false
br i1 %21, label %22, label %31
22: ; preds = %16
%23 = tail call i32 @gauged_writer_hex_decode(i8 signext %14)
%24 = shl i32 %23, 4
%25 = load i8, i8* %17
%26 = tail call i32 @gauged_writer_hex_decode(i8 signext %25)
%27 = or i32 %26, %24
%28 = trunc i32 %27 to i8
store i8 %28, i8* %8
%29 = getelementptr inbounds i8, i8* %7, i64 3
%30 = add i64 %6, -3
br label %31
31: ; preds = %5, %13, %16, %22, %12
%32 = phi i8* [ %10, %12 ], [ %29, %22 ], [ %10, %16 ], [ %10, %13 ], [ %10, %5 ]
%33 = phi i64 [ %9, %12 ], [ %30, %22 ], [ %9, %16 ], [ %9, %13 ], [ %9, %5 ]
%34 = getelementptr inbounds i8, i8* %8, i64 1
%35 = icmp eq i64 %33, 0
br i1 %35, label %36, label %5
36: ; preds = %31, %5, %3
%37 = phi i8* [ %0, %3 ], [ %8, %5 ], [ %34, %31 ]
store i8 0, i8* %37
ret void
}