#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 *);
int unespcape(char *_dst, char *_src, size_t len) {
  int ret = 0;
  char *src = _src;
  char *dst = _dst;
  unsigned int ch;
  while (*src) {
    if (*src == '\\' && *(src + 1) == 'x') {
      sscanf(src + 2, "%2x", &ch);
      src += 4;
      *dst++ = (unsigned char)ch;
    } else {
      *dst++ = *src++;
    }
    ret++;
  }
  return ret;
}


x86 assembly (clang, -O0):
<unespcape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11d8 <unespcape+0xc8>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11a8 <unespcape+0x98>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    11a8 <unespcape+0x98>
mov    -0x28(%rbp),%rdi
add    $0x2,%rdi
lea    0xe88(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x28(%rbp)
mov    -0x34(%rbp),%eax
mov    %al,%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
jmp    11ca <unespcape+0xba>
mov    -0x28(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x28(%rbp)
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113b <unespcape+0x2b>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unespcape>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %r14d,%r14d
lea    0xed3(%rip),%r12
lea    0xc(%rsp),%r13
jmp    1160 <unespcape+0x50>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
lea    0x2(%rbx),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <sscanf@plt>
add    $0x4,%rbx
movzbl 0xc(%rsp),%eax
mov    %al,(%r15,%r14,1)
add    $0x1,%r14
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     1170 <unespcape+0x60>
test   %al,%al
jne    1176 <unespcape+0x66>
jmp    117c <unespcape+0x6c>
nopl   (%rax)
cmpb   $0x78,0x1(%rbx)
je     1140 <unespcape+0x30>
add    $0x1,%rbx
jmp    1158 <unespcape+0x48>
mov    %r14d,%eax
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 i32 @unespcape(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
%11 = load i8*, i8** %5
store i8* %11, i8** %8
%12 = load i8*, i8** %4
store i8* %12, i8** %9
br label %13
13: ; preds = %44, %3
%14 = load i8*, i8** %8
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %47
17: ; preds = %13
%18 = load i8*, i8** %8
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 92
br i1 %21, label %22, label %38
22: ; preds = %17
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 120
br i1 %27, label %28, label %38
28: ; preds = %22
%29 = load i8*, i8** %8
%30 = getelementptr inbounds i8, i8* %29, i64 2
%31 = call i32 @sscanf(i8* %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %10)
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 4
store i8* %33, i8** %8
%34 = load i32, i32* %10
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %9
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %9
store i8 %35, i8* %36
br label %44
38: ; preds = %22, %17
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %8
%41 = load i8, i8* %39
%42 = load i8*, i8** %9
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %9
store i8 %41, i8* %42
br label %44
44: ; preds = %38, %28
%45 = load i32, i32* %7
%46 = add nsw i32 %45, 1
store i32 %46, i32* %7
br label %13
47: ; preds = %13
%48 = load i32, i32* %7
ret i32 %48
}

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