#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 /*<<< orphan*/ sscanf(char const *, char *, int *);
void url_decode(const char *s, char *t, int length) {
  while (*s && length > 1) {
    if (*s == '%') {
      int x;
      sscanf(s + 1, "%2x", &x);
      *t++ = x;
      s += 3;
    } else {
      *t++ = *s++;
    }
    length--;
  }
  *t = 0;
}


x86 assembly (clang, -O0):
<url_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1142 <url_decode+0x32>
cmpl   $0x1,-0x14(%rbp)
setg   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1152 <url_decode+0x42>
jmp    11d1 <url_decode+0xc1>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11a1 <url_decode+0x91>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xe8f(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
jmp    11c3 <url_decode+0xb3>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1123 <url_decode+0x13>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<url_decode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    (%rdi),%al
test   %al,%al
je     117f <url_decode+0x6f>
mov    %edx,%r15d
cmp    $0x2,%edx
jl     117f <url_decode+0x6f>
mov    %rdi,%r14
lea    0xec8(%rip),%r12
lea    0xc(%rsp),%r13
nopl   (%rax)
cmp    $0x25,%al
jne    1160 <url_decode+0x50>
lea    0x1(%r14),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <sscanf@plt>
movzbl 0xc(%rsp),%eax
mov    %al,(%rbx)
add    $0x3,%r14
jmp    1166 <url_decode+0x56>
add    $0x1,%r14
mov    %al,(%rbx)
add    $0x1,%rbx
movzbl (%r14),%eax
test   %al,%al
je     117f <url_decode+0x6f>
lea    -0x1(%r15),%ecx
cmp    $0x2,%r15d
mov    %ecx,%r15d
jg     1140 <url_decode+0x30>
movb   $0x0,(%rbx)
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 @url_decode(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %39, %3
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 1
br label %16
16: ; preds = %13, %8
%17 = phi i1 [ false, %8 ], [ %15, %13 ]
br i1 %17, label %18, label %42
18: ; preds = %16
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 37
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %7)
%27 = load i32, i32* %7
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %5
store i8 %28, i8* %29
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 3
store i8* %32, i8** %4
br label %39
33: ; preds = %18
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %4
%36 = load i8, i8* %34
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %5
store i8 %36, i8* %37
br label %39
39: ; preds = %33, %23
%40 = load i32, i32* %6
%41 = add nsw i32 %40, -1
store i32 %41, i32* %6
br label %8
42: ; preds = %16
%43 = load i8*, i8** %5
store i8 0, i8* %43
ret void
}

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