#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 *, char *, unsigned int *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, scalar_t__);
char *strpbrk(char *, char *);
void unescape(char *s) {
  unsigned int c;
  while ((s = strpbrk(s, "%+"))) {
    if (*s == '%') {
      sscanf(s + 1, "%02x", &c);
      *s++ = (char)c;
      strncpy(s, s + 2, strlen(s) + 1);
    } else if (*s == '+')
      *s++ = ' ';
  }
}


x86 assembly (clang, -O0):
<unescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea9(%rip),%rsi
call   1060 <strpbrk@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     120a <unescape+0xca>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11de <unescape+0x9e>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
lea    0xe7a(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <sscanf@plt>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <strncpy@plt>
jmp    1205 <unescape+0xc5>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1200 <unescape+0xc0>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x20,(%rax)
jmp    1205 <unescape+0xc5>
jmp    114c <unescape+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unescape>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeac(%rip),%rsi
call   1060 <strpbrk@plt>
test   %rax,%rax
je     11de <unescape+0x9e>
mov    %rax,%rbx
lea    0xe94(%rip),%r15
lea    0xe90(%rip),%r14
lea    0xc(%rsp),%r12
jmp    119a <unescape+0x5a>
nopw   0x0(%rax,%rax,1)
movb   $0x20,(%rbx)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strpbrk@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11de <unescape+0x9e>
movzbl (%rbx),%eax
cmp    $0x2b,%al
je     1180 <unescape+0x40>
cmp    $0x25,%al
jne    1187 <unescape+0x47>
lea    0x1(%rbx),%r13
mov    %r13,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
movzbl 0xc(%rsp),%eax
mov    %al,(%rbx)
add    $0x3,%rbx
mov    %r13,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %r13,%rbx
jmp    1187 <unescape+0x47>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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