#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 *, unsigned int *);
int strlen(char *);
char *esl_url_decode(char *s) {
  char *o;
  unsigned int tmp;
  for (o = s; *s; s++, o++) {
    if (*s == '%' && strlen(s) > 2 && sscanf(s + 1, "%2x", &tmp) == 1) {
      *o = (char)tmp;
      s += 2;
    } else {
      *o = *s;
    }
  }
  *o = '\0';
  return s;
}


x86 assembly (clang, -O0):
<esl_url_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ce <esl_url_decode+0xae>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11a0 <esl_url_decode+0x80>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jle    11a0 <esl_url_decode+0x80>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xe8e(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    11a0 <esl_url_decode+0x80>
mov    -0x14(%rbp),%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x8(%rbp)
jmp    11ac <esl_url_decode+0x8c>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    11b1 <esl_url_decode+0x91>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1134 <esl_url_decode+0x14>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<esl_url_decode>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xece(%rip),%r14
lea    0x4(%rsp),%r15
mov    %rdi,%r12
jmp    1153 <esl_url_decode+0x33>
nopl   0x0(%rax)
test   %al,%al
je     118a <esl_url_decode+0x6a>
movzbl (%rbx),%eax
mov    %al,(%r12)
add    $0x1,%rbx
add    $0x1,%r12
movzbl (%rbx),%eax
cmp    $0x25,%al
jne    1140 <esl_url_decode+0x20>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jl     1144 <esl_url_decode+0x24>
lea    0x1(%rbx),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <sscanf@plt>
cmp    $0x1,%eax
jne    1144 <esl_url_decode+0x24>
movzbl 0x4(%rsp),%eax
mov    %al,(%r12)
add    $0x2,%rbx
jmp    114b <esl_url_decode+0x2b>
movb   $0x0,(%r12)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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