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


x86 assembly (clang, -O0):
<unescape>:
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     1201 <unescape+0xe1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11d1 <unescape+0xb1>
mov    -0x28(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    11d1 <unescape+0xb1>
mov    -0x28(%rbp),%rdi
add    $0x2,%rdi
lea    0xe78(%rip),%rsi
lea    -0x34(%rbp),%rdx
call   1030 <sscanf@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    11aa <unescape+0x8a>
lea    0xe5f(%rip),%rdi
call   1040 <pabort@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    11f3 <unescape+0xd3>
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    114b <unescape+0x2b>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unescape>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r15
xor    %r14d,%r14d
lea    0xec5(%rip),%r12
lea    0x4(%rsp),%r13
lea    0xebd(%rip),%rbp
jmp    1160 <unescape+0x40>
nopl   0x0(%rax)
test   %al,%al
je     1193 <unescape+0x73>
add    $0x1,%rbx
mov    %al,(%r15,%r14,1)
add    $0x1,%r14
movzbl (%rbx),%eax
cmp    $0x5c,%al
jne    1150 <unescape+0x30>
cmpb   $0x78,0x1(%rbx)
jne    1154 <unescape+0x34>
lea    0x2(%rbx),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <sscanf@plt>
test   %eax,%eax
jne    1188 <unescape+0x68>
mov    %rbp,%rdi
call   1040 <pabort@plt>
add    $0x4,%rbx
movzbl 0x4(%rsp),%eax
jmp    1158 <unescape+0x38>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%2x\00"
@.str.1 = [23 x i8] c"malformed input string\00"
define i32 @unescape(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
%12 = load i8*, i8** %5
store i8* %12, i8** %9
%13 = load i8*, i8** %4
store i8* %13, i8** %10
br label %14
14: ; preds = %50, %3
%15 = load i8*, i8** %9
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %53
18: ; preds = %14
%19 = load i8*, i8** %9
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 92
br i1 %22, label %23, label %44
23: ; preds = %18
%24 = load i8*, i8** %9
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 120
br i1 %28, label %29, label %44
29: ; preds = %23
%30 = load i8*, i8** %9
%31 = getelementptr inbounds i8, i8* %30, i64 2
%32 = call i32 @sscanf(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %11)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %37, label %35
35: ; preds = %29
%36 = call i32 @pabort(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = load i8*, i8** %9
%39 = getelementptr inbounds i8, i8* %38, i64 4
store i8* %39, i8** %9
%40 = load i32, i32* %11
%41 = trunc i32 %40 to i8
%42 = load i8*, i8** %10
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %10
store i8 %41, i8* %42
br label %50
44: ; preds = %23, %18
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %9
%47 = load i8, i8* %45
%48 = load i8*, i8** %10
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %10
store i8 %47, i8* %48
br label %50
50: ; preds = %44, %37
%51 = load i32, i32* %7
%52 = add nsw i32 %51, 1
store i32 %52, i32* %7
br label %14
53: ; preds = %14
%54 = load i32, i32* %7
ret i32 %54
}

LLVM IR (-O2):
@.str = [4 x i8] c"%2x\00"
@.str.1 = [23 x i8] c"malformed input string\00"
define i32 @unescape(i8* nocapture writeonly %0, i8* nocapture %1, i64 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
br label %6
6: ; preds = %27, %3
%7 = phi i32 [ 0, %3 ], [ %31, %27 ]
%8 = phi i8* [ %1, %3 ], [ %29, %27 ]
%9 = phi i8* [ %0, %3 ], [ %30, %27 ]
%10 = load i8, i8* %8
switch i8 %10, label %25 [
i8 0, label %32
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 %25
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 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @pabort(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
%22 = getelementptr inbounds i8, i8* %8, i64 4
%23 = load i32, i32* %4
%24 = trunc i32 %23 to i8
br label %27
25: ; preds = %6, %11
%26 = getelementptr inbounds i8, i8* %8, i64 1
br label %27
27: ; preds = %25, %21
%28 = phi i8 [ %10, %25 ], [ %24, %21 ]
%29 = phi i8* [ %26, %25 ], [ %22, %21 ]
%30 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %28, i8* %9
%31 = add nuw nsw i32 %7, 1
br label %6
32: ; preds = %6
ret i32 %7
}