#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 sscanf(char *, char *, int *);
void unencode(char *src, char *last, char *dest) {
  for (; src != last; src++, dest++)
    if (*src == '+')
      *dest = ' ';
    else if (*src == '%') {
      int code;
      if (sscanf(src + 1, "%2x", &code) != 1)
        code = '?';
      *dest = code;
      src += 2;
    } else
      *dest = *src;
  *dest = '\n';
  *++dest = '\0';
}


x86 assembly (clang, -O0):
<unencode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     11d5 <unencode+0xc5>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    114e <unencode+0x3e>
mov    -0x18(%rbp),%rax
movb   $0x20,(%rax)
jmp    11b3 <unencode+0xa3>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11a2 <unencode+0x92>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xe93(%rip),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     1186 <unencode+0x76>
movl   $0x3f,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    11ae <unencode+0x9e>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
jmp    11b3 <unencode+0xa3>
jmp    11b8 <unencode+0xa8>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1124 <unencode+0x14>
mov    -0x18(%rbp),%rax
movb   $0xa,(%rax)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,0x1(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unencode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
cmp    %rsi,%rdi
je     1196 <unencode+0x86>
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xece(%rip),%r12
lea    0xc(%rsp),%r13
jmp    1150 <unencode+0x40>
nopl   0x0(%rax)
mov    %al,(%r15)
add    $0x1,%rbx
add    $0x1,%r15
cmp    %r14,%rbx
je     1196 <unencode+0x86>
movzbl (%rbx),%eax
cmp    $0x25,%al
je     1170 <unencode+0x60>
cmp    $0x2b,%al
jne    1140 <unencode+0x30>
movb   $0x20,(%r15)
jmp    1143 <unencode+0x33>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0x1(%rbx),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <sscanf@plt>
mov    $0x3f,%ecx
cmp    $0x1,%eax
jne    118d <unencode+0x7d>
mov    0xc(%rsp),%ecx
mov    %cl,(%r15)
add    $0x2,%rbx
jmp    1143 <unencode+0x33>
movw   $0xa,(%r15)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%2x\00"
define void @unencode(i8* %0, i8* readnone %1, i8* nocapture writeonly %2) {
%4 = alloca i32
%5 = icmp eq i8* %0, %1
br i1 %5, label %27, label %6
6: ; preds = %3
%7 = bitcast i32* %4 to i8*
br label %8
8: ; preds = %6, %22
%9 = phi i8* [ %2, %6 ], [ %25, %22 ]
%10 = phi i8* [ %0, %6 ], [ %24, %22 ]
%11 = load i8, i8* %10
switch i8 %11, label %21 [
i8 43, label %12
i8 37, label %13
]
12: ; preds = %8
store i8 32, i8* %9
br label %22
13: ; preds = %8
%14 = getelementptr inbounds i8, i8* %10, i64 1
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
%16 = icmp eq i32 %15, 1
%17 = load i32, i32* %4
%18 = trunc i32 %17 to i8
%19 = select i1 %16, i8 %18, i8 63
store i8 %19, i8* %9
%20 = getelementptr inbounds i8, i8* %10, i64 2
br label %22
21: ; preds = %8
store i8 %11, i8* %9
br label %22
22: ; preds = %12, %21, %13
%23 = phi i8* [ %10, %12 ], [ %20, %13 ], [ %10, %21 ]
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = getelementptr inbounds i8, i8* %9, i64 1
%26 = icmp eq i8* %24, %1
br i1 %26, label %27, label %8
27: ; preds = %22, %3
%28 = phi i8* [ %2, %3 ], [ %25, %22 ]
store i8 10, i8* %28
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 0, i8* %29
ret void
}