#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 */
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
scalar_t__ strtol(char *, char **, int);
int ILibInPlaceHTTPUnEscape(char *data) {
  char hex[3];
  char *stp;
  int src_x = 0;
  int dst_x = 0;
  int length = (int)strlen(data);
  hex[2] = 0;
  while (src_x < length) {
    if (strncmp(data + src_x, "%", 1) == 0) {
      hex[0] = data[src_x + 1];
      hex[1] = data[src_x + 2];
      data[dst_x] = (char)strtol(hex, &stp, 16);
      dst_x += 1;
      src_x += 3;
    } else if (src_x != dst_x) {
      data[dst_x] = data[src_x];
      src_x += 1;
      dst_x += 1;
    } else {
      src_x += 1;
      dst_x += 1;
    }
  }
  return (dst_x);
}


x86 assembly (clang, -O0):
<ILibInPlaceHTTPUnEscape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
movb   $0x0,-0x9(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    123d <ILibInPlaceHTTPUnEscape+0x10d>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    0xe88(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11e8 <ILibInPlaceHTTPUnEscape+0xb8>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xb(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0xa(%rbp)
lea    -0xb(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x1c(%rbp)
jmp    1238 <ILibInPlaceHTTPUnEscape+0x108>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     1221 <ILibInPlaceHTTPUnEscape+0xf1>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1233 <ILibInPlaceHTTPUnEscape+0x103>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1238 <ILibInPlaceHTTPUnEscape+0x108>
jmp    115a <ILibInPlaceHTTPUnEscape+0x2a>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ILibInPlaceHTTPUnEscape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %rax,%r15
movb   $0x0,0xf(%rsp)
xor    %ebx,%ebx
test   %r15d,%r15d
jle    11d4 <ILibInPlaceHTTPUnEscape+0xa4>
xor    %ebp,%ebp
jmp    119c <ILibInPlaceHTTPUnEscape+0x6c>
nopl   0x0(%rax)
movzbl 0x1(%r12,%r14,1),%eax
mov    %al,0xd(%rsp)
movzbl 0x2(%r12,%r14,1),%eax
mov    %al,0xe(%rsp)
lea    0xd(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    $0x3,%ecx
mov    %al,(%r14,%rbx,1)
add    %ecx,%ebp
add    $0x1,%rbx
cmp    %r15d,%ebp
jge    11d4 <ILibInPlaceHTTPUnEscape+0xa4>
movslq %ebp,%r12
lea    (%r14,%r12,1),%r13
mov    %r13,%rdi
lea    0xe53(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1160 <ILibInPlaceHTTPUnEscape+0x30>
mov    %ebp,%eax
mov    $0x1,%ecx
cmp    %rax,%rbx
je     1191 <ILibInPlaceHTTPUnEscape+0x61>
movzbl 0x0(%r13),%eax
mov    $0x1,%ecx
jmp    118d <ILibInPlaceHTTPUnEscape+0x5d>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"%\00"
define i32 @ILibInPlaceHTTPUnEscape(i8* %0) {
%2 = alloca i8*
%3 = alloca [3 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
store i32 0, i32* %6
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
%10 = trunc i64 %9 to i32
store i32 %10, i32* %7
%11 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 2
store i8 0, i8* %11
br label %12
12: ; preds = %73, %1
%13 = load i32, i32* %5
%14 = load i32, i32* %7
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %74
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = call i64 @strncmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %49
23: ; preds = %16
%24 = load i8*, i8** %2
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
store i8 %29, i8* %30
%31 = load i8*, i8** %2
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 2
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
%36 = load i8, i8* %35
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 1
store i8 %36, i8* %37
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %3, i64 0, i64 0
%39 = call i64 @strtol(i8* %38, i8** %4, i32 16)
%40 = trunc i64 %39 to i8
%41 = load i8*, i8** %2
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 3
store i32 %48, i32* %5
br label %73
49: ; preds = %16
%50 = load i32, i32* %5
%51 = load i32, i32* %6
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %67
53: ; preds = %49
%54 = load i8*, i8** %2
%55 = load i32, i32* %5
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = load i8*, i8** %2
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
store i8 %58, i8* %62
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 1
store i32 %64, i32* %5
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %72
67: ; preds = %49
%68 = load i32, i32* %5
%69 = add nsw i32 %68, 1
store i32 %69, i32* %5
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 1
store i32 %71, i32* %6
br label %72
72: ; preds = %67, %53
br label %73
73: ; preds = %72, %23
br label %12
74: ; preds = %12
%75 = load i32, i32* %6
ret i32 %75
}

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