#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 decode_hex(char);
void nginx_unescape(char *inp) {
  char *outp = inp;
  while (*inp) {
    if (*inp == '\\' && *(inp + 1) == 'x') {
      *outp++ = (decode_hex(*(inp + 2)) << 4) + decode_hex(*(inp + 3));
      inp += 4;
    } else {
      *outp++ = *inp++;
    }
  }
  *outp = 0;
}


x86 assembly (clang, -O0):
<nginx_unescape>:
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     11c4 <nginx_unescape+0xb4>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    119d <nginx_unescape+0x8d>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    119d <nginx_unescape+0x8d>
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <decode_hex@plt>
shl    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1030 <decode_hex@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%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    $0x4,%rax
mov    %rax,-0x8(%rbp)
jmp    11bf <nginx_unescape+0xaf>
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)
jmp    1124 <nginx_unescape+0x14>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nginx_unescape>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    %rdi,%rbp
jmp    1147 <nginx_unescape+0x37>
nopl   0x0(%rax)
movsbl 0x2(%rbx),%edi
call   1030 <decode_hex@plt>
mov    %eax,%r14d
shl    $0x4,%r14d
movsbl 0x3(%rbx),%edi
call   1030 <decode_hex@plt>
add    %r14d,%eax
mov    %al,0x0(%rbp)
add    $0x4,%rbx
add    $0x1,%rbp
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1160 <nginx_unescape+0x50>
test   %al,%al
jne    1166 <nginx_unescape+0x56>
jmp    1173 <nginx_unescape+0x63>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmpb   $0x78,0x1(%rbx)
je     1120 <nginx_unescape+0x10>
add    $0x1,%rbx
mov    %al,0x0(%rbp)
add    $0x1,%rbp
jmp    1147 <nginx_unescape+0x37>
movb   $0x0,0x0(%rbp)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @nginx_unescape(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
store i8* %4, i8** %3
br label %5
5: ; preds = %42, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = icmp ne i8 %7, 0
br i1 %8, label %9, label %43
9: ; preds = %5
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 92
br i1 %13, label %14, label %36
14: ; preds = %9
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 120
br i1 %19, label %20, label %36
20: ; preds = %14
%21 = load i8*, i8** %2
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = load i8, i8* %22
%24 = call i32 @decode_hex(i8 signext %23)
%25 = shl i32 %24, 4
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 3
%28 = load i8, i8* %27
%29 = call i32 @decode_hex(i8 signext %28)
%30 = add nsw i32 %25, %29
%31 = trunc i32 %30 to i8
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
store i8 %31, i8* %32
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i64 4
store i8* %35, i8** %2
br label %42
36: ; preds = %14, %9
%37 = load i8*, i8** %2
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %2
%39 = load i8, i8* %37
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %3
store i8 %39, i8* %40
br label %42
42: ; preds = %36, %20
br label %5
43: ; preds = %5
%44 = load i8*, i8** %3
store i8 0, i8* %44
ret void
}

LLVM IR (-O2):
define void @nginx_unescape(i8* nocapture %0) {
br label %2
2: ; preds = %23, %1
%3 = phi i8* [ %0, %1 ], [ %24, %23 ]
%4 = phi i8* [ %0, %1 ], [ %25, %23 ]
%5 = load i8, i8* %3
switch i8 %5, label %21 [
i8 0, label %26
i8 92, label %6
]
6: ; preds = %2
%7 = getelementptr inbounds i8, i8* %3, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 120
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %3, i64 2
%12 = load i8, i8* %11
%13 = tail call i32 @decode_hex(i8 signext %12)
%14 = shl i32 %13, 4
%15 = getelementptr inbounds i8, i8* %3, i64 3
%16 = load i8, i8* %15
%17 = tail call i32 @decode_hex(i8 signext %16)
%18 = add nsw i32 %17, %14
%19 = trunc i32 %18 to i8
store i8 %19, i8* %4
%20 = getelementptr inbounds i8, i8* %3, i64 4
br label %23
21: ; preds = %2, %6
%22 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %5, i8* %4
br label %23
23: ; preds = %21, %10
%24 = phi i8* [ %20, %10 ], [ %22, %21 ]
%25 = getelementptr inbounds i8, i8* %4, i64 1
br label %2
26: ; preds = %2
store i8 0, i8* %4
ret void
}