#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 *gp_alloc(int, char *);
int strlen(char const *);
char *expand_newline(const char *in) {
  char *tmpstr = gp_alloc(2 * strlen(in), "enl");
  const char *s = in;
  char *t = tmpstr;
  do {
    if (*s == '\n') {
      *t++ = '\\';
      *t++ = 'n';
    } else
      *t++ = *s;
  } while (*s++);
  return tmpstr;
}


x86 assembly (clang, -O0):
<expand_newline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
shl    $0x1,%edi
lea    0xebf(%rip),%rsi
call   1040 <gp_alloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1193 <expand_newline+0x73>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x5c,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x6e,(%rax)
jmp    11aa <expand_newline+0x8a>
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11af <expand_newline+0x8f>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,(%rax)
jne    115a <expand_newline+0x3a>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expand_newline>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    (%rax,%rax,1),%edi
lea    0xecd(%rip),%rsi
call   1040 <gp_alloc@plt>
mov    %rax,%rcx
jmp    114f <expand_newline+0x2f>
nopl   (%rax)
mov    %dl,(%rcx)
add    $0x1,%rcx
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
je     1162 <expand_newline+0x42>
movzbl (%rbx),%edx
cmp    $0xa,%dl
jne    1140 <expand_newline+0x20>
movw   $0x6e5c,(%rcx)
add    $0x2,%rcx
jmp    1146 <expand_newline+0x26>
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"enl\00"
define i8* @expand_newline(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = mul nsw i32 2, %7
%9 = call i8* @gp_alloc(i32 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %3
%10 = load i8*, i8** %2
store i8* %10, i8** %4
%11 = load i8*, i8** %3
store i8* %11, i8** %5
br label %12
12: ; preds = %28, %1
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 10
br i1 %16, label %17, label %22
17: ; preds = %12
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
store i8 92, i8* %18
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
store i8 110, i8* %20
br label %27
22: ; preds = %12
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
store i8 %24, i8* %25
br label %27
27: ; preds = %22, %17
br label %28
28: ; preds = %27
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %4
%31 = load i8, i8* %29
%32 = icmp ne i8 %31, 0
br i1 %32, label %12, label %33
33: ; preds = %28
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [4 x i8] c"enl\00"
define i8* @expand_newline(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 1
%4 = tail call i8* @gp_alloc(i32 %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %14, %1
%6 = phi i8* [ %0, %1 ], [ %16, %14 ]
%7 = phi i8* [ %4, %1 ], [ %15, %14 ]
%8 = load i8, i8* %6
%9 = icmp eq i8 %8, 10
%10 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %9, label %11, label %13
11: ; preds = %5
store i8 92, i8* %7
%12 = getelementptr inbounds i8, i8* %7, i64 2
store i8 110, i8* %10
br label %14
13: ; preds = %5
store i8 %8, i8* %7
br label %14
14: ; preds = %11, %13
%15 = phi i8* [ %12, %11 ], [ %10, %13 ]
%16 = getelementptr inbounds i8, i8* %6, i64 1
%17 = load i8, i8* %6
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %5
19: ; preds = %14
ret i8* %4
}