#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 *calloc(size_t, int);
size_t strlen(char *);
int crlf2semicolon(char *string, char **ppoutbuf) {
  size_t size;
  char *outbuf;
  char *p = string;
  char *dp;
  size = strlen(string);
  dp = outbuf = calloc(size + 1, 1);
  while (*p != '\0') {
    if (*p == '\n') {
      *dp++ = ';';
    } else {
      *dp++ = *p;
    }
    p++;
  }
  *dp++ = '\0';
  *ppoutbuf = outbuf;
  return p - string;
}


x86 assembly (clang, -O0):
<crlf2semicolon>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11be <crlf2semicolon+0x9e>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1196 <crlf2semicolon+0x76>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x3b,(%rax)
jmp    11ad <crlf2semicolon+0x8d>
mov    -0x28(%rbp),%rax
mov    (%rax),%cl
mov    -0x30(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    115f <crlf2semicolon+0x3f>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crlf2semicolon>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rcx
xor    %eax,%eax
jmp    1157 <crlf2semicolon+0x37>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %bl,(%rcx,%rax,1)
add    $0x1,%rax
movzbl (%r15,%rax,1),%edx
mov    $0x3b,%bl
cmp    $0xa,%dl
je     1150 <crlf2semicolon+0x30>
test   %dl,%dl
je     116b <crlf2semicolon+0x4b>
mov    %edx,%ebx
jmp    1150 <crlf2semicolon+0x30>
movb   $0x0,(%rcx,%rax,1)
mov    %rcx,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @crlf2semicolon(i8* %0, i8** nocapture writeonly %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add i64 %3, 1
%5 = tail call i8* @calloc(i64 %4, i32 1)
br label %6
6: ; preds = %11, %2
%7 = phi i8* [ %0, %2 ], [ %14, %11 ]
%8 = phi i8* [ %5, %2 ], [ %13, %11 ]
%9 = load i8, i8* %7
switch i8 %9, label %10 [
i8 0, label %15
i8 10, label %11
]
10: ; preds = %6
br label %11
11: ; preds = %6, %10
%12 = phi i8 [ %9, %10 ], [ 59, %6 ]
%13 = getelementptr inbounds i8, i8* %8, i64 1
store i8 %12, i8* %8
%14 = getelementptr inbounds i8, i8* %7, i64 1
br label %6
15: ; preds = %6
store i8 0, i8* %8
store i8* %5, i8** %1
%16 = ptrtoint i8* %7 to i64
%17 = ptrtoint i8* %0 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
ret i32 %19
}