#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*/ assert(int /*<<< orphan*/);
char *calloc(int, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
char *backslash_return(char *str) {
  int i;
  int len;
  char *nstr = NULL;
  for (i = len = 0; str[i]; ++i, ++len)
    if (str[i] == '\n')
      ++len;
  nstr = calloc(len + 1, sizeof(char));
  assert(nstr != NULL);
  while (*str) {
    if (*str == '\n')
      sprintf(nstr, "%s\\n", nstr);
    else
      sprintf(nstr, "%s%c", nstr, *str);
    ++str;
  }
  return nstr;
}


x86 assembly (clang, -O0):
<backslash_return>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     119e <backslash_return+0x6e>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1182 <backslash_return+0x52>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1187 <backslash_return+0x57>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1152 <backslash_return+0x22>
mov    -0x10(%rbp),%edi
add    $0x1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     122a <backslash_return+0xfa>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11fc <backslash_return+0xcc>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
jmp    1219 <backslash_return+0xe9>
mov    -0x18(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <backslash_return+0x94>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<backslash_return>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %edi,%edi
mov    %rbx,%rax
jmp    115a <backslash_return+0x2a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%edi
add    $0x1,%edi
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0xa,%cl
je     1150 <backslash_return+0x20>
test   %cl,%cl
jne    1153 <backslash_return+0x23>
add    $0x1,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1040 <assert@plt>
lea    0xe75(%rip),%r15
lea    0xe73(%rip),%r12
jmp    11b4 <backslash_return+0x84>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
add    $0x1,%rbx
movsbl (%rbx),%ecx
cmp    $0xa,%ecx
je     11a0 <backslash_return+0x70>
test   %cl,%cl
je     11d6 <backslash_return+0xa6>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
add    $0x1,%rbx
jmp    11b4 <backslash_return+0x84>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c"%s\\n\00"
@.str.1 = [5 x i8] c"%s%c\00"
define i8* @backslash_return(i8* nocapture %0) {
br label %2
2: ; preds = %9, %1
%3 = phi i64 [ %11, %9 ], [ 0, %1 ]
%4 = phi i32 [ %12, %9 ], [ 0, %1 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = load i8, i8* %5
switch i8 %6, label %9 [
i8 0, label %13
i8 10, label %7
]
7: ; preds = %2
%8 = add nsw i32 %4, 1
br label %9
9: ; preds = %2, %7
%10 = phi i32 [ %8, %7 ], [ %4, %2 ]
%11 = add nuw i64 %3, 1
%12 = add nsw i32 %10, 1
br label %2
13: ; preds = %2
%14 = add nsw i32 %4, 1
%15 = tail call i8* @calloc(i32 %14, i32 1)
%16 = icmp ne i8* %15, null
%17 = zext i1 %16 to i32
%18 = tail call i32 @assert(i32 %17)
br label %19
19: ; preds = %27, %13
%20 = phi i8* [ %0, %13 ], [ %28, %27 ]
%21 = load i8, i8* %20
switch i8 %21, label %24 [
i8 0, label %29
i8 10, label %22
]
22: ; preds = %19
%23 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %27
24: ; preds = %19
%25 = sext i8 %21 to i32
%26 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %15, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %25)
br label %27
27: ; preds = %24, %22
%28 = getelementptr inbounds i8, i8* %20, i64 1
br label %19
29: ; preds = %19
ret i8* %15
}