#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 cgiDecode(char *in, char *out, int inLength) {
  char c;
  int i;
  for (i = 0; i < inLength; ++i) {
    c = *in++;
    if (c == '+')
      *out++ = ' ';
    else if (c == '%') {
      int code;
      if (sscanf(in, "%2x", &code) != 1)
        code = '?';
      in += 2;
      i += 2;
      *out++ = code;
    } else
      *out++ = c;
  }
  *out++ = 0;
}


x86 assembly (clang, -O0):
<cgiDecode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11fb <cgiDecode+0xeb>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%eax
cmp    $0x2b,%eax
jne    116e <cgiDecode+0x5e>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x20,(%rax)
jmp    11e8 <cgiDecode+0xd8>
movsbl -0x15(%rbp),%eax
cmp    $0x25,%eax
jne    11cf <cgiDecode+0xbf>
mov    -0x8(%rbp),%rdi
lea    0xe7a(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <sscanf@plt>
cmp    $0x1,%eax
je     119f <cgiDecode+0x8f>
movl   $0x3f,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11e3 <cgiDecode+0xd3>
mov    -0x15(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11e8 <cgiDecode+0xd8>
jmp    11ed <cgiDecode+0xdd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112a <cgiDecode+0x1a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgiDecode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
test   %edx,%edx
jle    1199 <cgiDecode+0x89>
mov    %edx,%r12d
mov    %rdi,%rbp
xor    %ebx,%ebx
lea    0xecf(%rip),%r14
lea    0x4(%rsp),%r15
jmp    1153 <cgiDecode+0x43>
nopl   0x0(%rax,%rax,1)
mov    %al,0x0(%r13)
add    $0x1,%r13
add    $0x1,%ebx
mov    %rdi,%rbp
cmp    %r12d,%ebx
jge    1199 <cgiDecode+0x89>
lea    0x1(%rbp),%rdi
movzbl 0x0(%rbp),%eax
cmp    $0x25,%al
je     1170 <cgiDecode+0x60>
cmp    $0x2b,%al
jne    1140 <cgiDecode+0x30>
movb   $0x20,0x0(%r13)
jmp    1144 <cgiDecode+0x34>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <sscanf@plt>
mov    $0x3f,%ecx
cmp    $0x1,%eax
jne    1189 <cgiDecode+0x79>
mov    0x4(%rsp),%ecx
add    $0x3,%rbp
add    $0x2,%ebx
mov    %cl,0x0(%r13)
mov    %rbp,%rdi
jmp    1144 <cgiDecode+0x34>
movb   $0x0,0x0(%r13)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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