#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 */
unsigned char *malloc(scalar_t__);
scalar_t__ strlen(unsigned char *);
unsigned char *string_unescape(unsigned char *in) {
  unsigned char *c;
  unsigned char *out;
  out = malloc(strlen(in) + 1);
  for (c = out; *in; in++) {
    switch (*in) {
    case '\\':
      ++in;
      switch (*in) {
      case 'n':
        *c++ = '\n';
        break;
      default:
        *c++ = *in;
      }
      break;
    default:
      *c++ = *in;
    }
  }
  *c = '\0';
  return out;
}


x86 assembly (clang, -O0):
<string_unescape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ec <string_unescape+0xcc>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
sub    $0x5c,%al
jne    11bf <string_unescape+0x9f>
jmp    116d <string_unescape+0x4d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%al
sub    $0x6e,%al
jne    11a3 <string_unescape+0x83>
jmp    118c <string_unescape+0x6c>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xa,(%rax)
jmp    11ba <string_unescape+0x9a>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11d6 <string_unescape+0xb6>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    11db <string_unescape+0xbb>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    114d <string_unescape+0x2d>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_unescape>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1040 <malloc@plt>
mov    $0xa,%edx
mov    %rax,%rcx
jmp    115a <string_unescape+0x3a>
nopl   0x0(%rax)
movzbl 0x1(%rbx),%esi
add    $0x1,%rbx
cmp    $0x6e,%sil
cmove  %edx,%esi
mov    %sil,(%rcx)
add    $0x1,%rcx
add    $0x1,%rbx
movzbl (%rbx),%esi
cmp    $0x5c,%sil
je     1140 <string_unescape+0x20>
test   %sil,%sil
jne    114f <string_unescape+0x2f>
movb   $0x0,(%rcx)
pop    %rbx
ret

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

LLVM IR (-O2):
define noalias i8* @string_unescape(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add nsw i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
br label %5
5: ; preds = %14, %1
%6 = phi i8* [ %4, %1 ], [ %17, %14 ]
%7 = phi i8* [ %0, %1 ], [ %18, %14 ]
%8 = load i8, i8* %7
switch i8 %8, label %14 [
i8 0, label %19
i8 92, label %9
]
9: ; preds = %5
%10 = getelementptr inbounds i8, i8* %7, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 110
%13 = select i1 %12, i8 10, i8 %11
br label %14
14: ; preds = %5, %9
%15 = phi i8 [ %13, %9 ], [ %8, %5 ]
%16 = phi i8* [ %10, %9 ], [ %7, %5 ]
store i8 %15, i8* %6
%17 = getelementptr inbounds i8, i8* %6, i64 1
%18 = getelementptr inbounds i8, i8* %16, i64 1
br label %5
19: ; preds = %5
store i8 0, i8* %6
ret i8* %4
}