#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 *malloc(scalar_t__);
scalar_t__ strlen(char *);
char *minstrdup(char *str) {
  char *dest = malloc(strlen(str) + 1);
  char *d2 = dest;
  if (dest) {
    while (*str) {
      if (*str == '\\') {
        str++;
        if (*str == '\\') {
          *dest++ = '\\';
          str++;
        } else if (*str == 'n') {
          *dest++ = '\n';
          str++;
        }
      } else {
        *dest++ = *str++;
      }
    }
    *dest = 0;
  }
  return d2;
}


x86 assembly (clang, -O0):
<minstrdup>:
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,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     121f <minstrdup+0xff>
jmp    115d <minstrdup+0x3d>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1218 <minstrdup+0xf8>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11f1 <minstrdup+0xd1>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11b9 <minstrdup+0x99>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x5c,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <minstrdup+0xcc>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x6e,%eax
jne    11e7 <minstrdup+0xc7>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0xa,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11ec <minstrdup+0xcc>
jmp    1213 <minstrdup+0xf3>
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    115d <minstrdup+0x3d>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<minstrdup>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     118c <minstrdup+0x6c>
mov    %rax,%rcx
add    $0x1,%rbx
xchg   %ax,%ax
movzbl -0x1(%rbx),%edx
cmp    $0x5c,%dl
jne    1170 <minstrdup+0x50>
movzbl (%rbx),%edx
add    $0x1,%rbx
cmp    $0x6e,%dl
je     1180 <minstrdup+0x60>
cmp    $0x5c,%dl
jne    1140 <minstrdup+0x20>
movb   $0x5c,(%rcx)
add    $0x1,%rcx
jmp    113a <minstrdup+0x1a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %dl,%dl
je     1189 <minstrdup+0x69>
mov    %dl,(%rcx)
add    $0x1,%rcx
jmp    113a <minstrdup+0x1a>
nopl   0x0(%rax)
movb   $0xa,(%rcx)
add    $0x1,%rcx
jmp    113a <minstrdup+0x1a>
movb   $0x0,(%rcx)
pop    %rbx
ret

LLVM IR (-O0):
define i8* @minstrdup(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** %3
%9 = load i8*, i8** %3
store i8* %9, i8** %4
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %55
12: ; preds = %1
br label %13
13: ; preds = %52, %12
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %53
17: ; preds = %13
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 92
br i1 %21, label %22, label %46
22: ; preds = %17
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %2
%25 = load i8*, i8** %2
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 92
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i8*, i8** %3
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %3
store i8 92, i8* %30
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %2
br label %45
34: ; preds = %22
%35 = load i8*, i8** %2
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 110
br i1 %38, label %39, label %44
39: ; preds = %34
%40 = load i8*, i8** %3
%41 = getelementptr inbounds i8, i8* %40, i32 1
store i8* %41, i8** %3
store i8 10, i8* %40
%42 = load i8*, i8** %2
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %2
br label %44
44: ; preds = %39, %34
br label %45
45: ; preds = %44, %29
br label %52
46: ; preds = %17
%47 = load i8*, i8** %2
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %2
%49 = load i8, i8* %47
%50 = load i8*, i8** %3
%51 = getelementptr inbounds i8, i8* %50, i32 1
store i8* %51, i8** %3
store i8 %49, i8* %50
br label %52
52: ; preds = %46, %45
br label %13
53: ; preds = %13
%54 = load i8*, i8** %3
store i8 0, i8* %54
br label %55
55: ; preds = %53, %1
%56 = load i8*, i8** %4
ret i8* %56
}

LLVM IR (-O2):
define noalias i8* @minstrdup(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)
%5 = icmp eq i8* %4, null
br i1 %5, label %25, label %6
6: ; preds = %1, %17
%7 = phi i8* [ %19, %17 ], [ %4, %1 ]
%8 = phi i8* [ %18, %17 ], [ %0, %1 ]
br label %9
9: ; preds = %6, %12
%10 = phi i8* [ %13, %12 ], [ %8, %6 ]
%11 = load i8, i8* %10
switch i8 %11, label %22 [
i8 0, label %24
i8 92, label %12
]
12: ; preds = %9
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = load i8, i8* %13
switch i8 %14, label %9 [
i8 92, label %15
i8 110, label %20
]
15: ; preds = %12
store i8 92, i8* %7
%16 = getelementptr inbounds i8, i8* %10, i64 2
br label %17
17: ; preds = %15, %20, %22
%18 = phi i8* [ %23, %22 ], [ %21, %20 ], [ %16, %15 ]
%19 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
20: ; preds = %12
store i8 10, i8* %7
%21 = getelementptr inbounds i8, i8* %10, i64 2
br label %17
22: ; preds = %9
%23 = getelementptr inbounds i8, i8* %10, i64 1
store i8 %11, i8* %7
br label %17
24: ; preds = %9
store i8 0, i8* %7
br label %25
25: ; preds = %24, %1
ret i8* %4
}