#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 */
char esc2chr(char const);
size_t strlen(char const *);
char *xmalloc(size_t);
char *descr_decode(const char *s) {
  size_t slen;
  const char *sp;
  const char *send;
  char *buf = NULL;
  size_t bufsize = 0;
  char *bufp;
  slen = strlen(s);
  send = s + slen - 1;
  for (sp = s + 1; sp < send;) {
    bufsize += 1;
    if (*sp == '\\')
      sp += 2;
    else
      ++sp;
  }
  bufsize += 1;
  buf = xmalloc(bufsize);
  for (sp = s + 1, bufp = buf; sp < send; ++sp, ++bufp) {
    if (*sp == '\\')
      *bufp = esc2chr(*++sp);
    else
      *bufp = *sp;
  }
  *bufp++ = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<descr_decode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11c1 <descr_decode+0x91>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11b0 <descr_decode+0x80>
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    11bc <descr_decode+0x8c>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1175 <descr_decode+0x45>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    125f <descr_decode+0x12f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1231 <descr_decode+0x101>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl 0x1(%rax),%edi
call   1050 <esc2chr@plt>
mov    %al,%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
jmp    123d <descr_decode+0x10d>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x38(%rbp),%rax
mov    %cl,(%rax)
jmp    1242 <descr_decode+0x112>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11ee <descr_decode+0xbe>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<descr_decode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r13
call   1030 <strlen@plt>
cmp    $0x3,%rax
jl     11b8 <descr_decode+0x88>
mov    %rax,%r15
lea    (%rax,%r13,1),%r12
add    $0xffffffffffffffff,%r12
add    $0x1,%r13
mov    $0x1,%edi
mov    %r13,%rax
xchg   %ax,%ax
xor    %ecx,%ecx
cmpb   $0x5c,(%rax)
sete   %cl
add    %rcx,%rax
add    $0x1,%rax
add    $0x1,%rdi
cmp    %r12,%rax
jb     1160 <descr_decode+0x30>
call   1040 <xmalloc@plt>
mov    %rax,%r14
mov    %rax,%rbx
cmp    $0x3,%r15
jge    119f <descr_decode+0x6f>
jmp    11c8 <descr_decode+0x98>
nopl   0x0(%rax,%rax,1)
mov    %al,(%rbx)
add    $0x1,%r13
add    $0x1,%rbx
cmp    %r12,%r13
jae    11c8 <descr_decode+0x98>
movzbl 0x0(%r13),%eax
cmp    $0x5c,%al
jne    1190 <descr_decode+0x60>
movsbl 0x1(%r13),%edi
add    $0x1,%r13
call   1050 <esc2chr@plt>
jmp    1190 <descr_decode+0x60>
mov    $0x1,%edi
call   1040 <xmalloc@plt>
mov    %rax,%r14
mov    %rax,%rbx
movb   $0x0,(%rbx)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @descr_decode(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, -1
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = icmp sgt i64 %2, 2
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i8* @xmalloc(i64 1)
br label %35
9: ; preds = %1, %9
%10 = phi i64 [ %16, %9 ], [ 1, %1 ]
%11 = phi i8* [ %15, %9 ], [ %5, %1 ]
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 92
%14 = select i1 %13, i64 2, i64 1
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = add i64 %10, 1
%17 = icmp ult i8* %15, %4
br i1 %17, label %9, label %18
18: ; preds = %9
%19 = tail call i8* @xmalloc(i64 %16)
br i1 %6, label %20, label %35
20: ; preds = %18, %29
%21 = phi i8* [ %33, %29 ], [ %19, %18 ]
%22 = phi i8* [ %32, %29 ], [ %5, %18 ]
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 92
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = getelementptr inbounds i8, i8* %22, i64 1
%27 = load i8, i8* %26
%28 = tail call signext i8 @esc2chr(i8 signext %27)
br label %29
29: ; preds = %20, %25
%30 = phi i8 [ %28, %25 ], [ %23, %20 ]
%31 = phi i8* [ %26, %25 ], [ %22, %20 ]
store i8 %30, i8* %21
%32 = getelementptr inbounds i8, i8* %31, i64 1
%33 = getelementptr inbounds i8, i8* %21, i64 1
%34 = icmp ult i8* %32, %4
br i1 %34, label %20, label %35
35: ; preds = %29, %7, %18
%36 = phi i8* [ %19, %18 ], [ %8, %7 ], [ %19, %29 ]
%37 = phi i8* [ %19, %18 ], [ %8, %7 ], [ %33, %29 ]
store i8 0, i8* %37
ret i8* %36
}