#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 strlen(char *);
void remove_carriage_return(char *str) {
  if (strlen(str) > 1) {
    for (int i = 0; i < (int)strlen(str) - 2; i++) {
      if (str[i] == '\n') {
        str[i] = ' ';
      }
    }
    for (int i = (int)strlen(str) - 2; i < (int)strlen(str); i++) {
      if (str[i] == '\n')
        str[i] = 0;
    }
  }
}


x86 assembly (clang, -O0):
<remove_carriage_return>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jle    11ec <remove_carriage_return+0xdc>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    1188 <remove_carriage_return+0x78>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1175 <remove_carriage_return+0x65>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    117a <remove_carriage_return+0x6a>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1135 <remove_carriage_return+0x25>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11e7 <remove_carriage_return+0xd7>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11d4 <remove_carriage_return+0xc4>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11d9 <remove_carriage_return+0xc9>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1197 <remove_carriage_return+0x87>
jmp    11ec <remove_carriage_return+0xdc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_carriage_return>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     119f <remove_carriage_return+0x8f>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x3,%eax
jl     1162 <remove_carriage_return+0x52>
xor    %ebp,%ebp
jmp    1156 <remove_carriage_return+0x46>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0xfffffffe,%eax
cltq
cmp    %rax,%rbp
jge    1162 <remove_carriage_return+0x52>
cmpb   $0xa,(%rbx,%rbp,1)
jne    1140 <remove_carriage_return+0x30>
movb   $0x20,(%rbx,%rbp,1)
jmp    1140 <remove_carriage_return+0x30>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
add    $0xfffffffe,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %eax,%ebp
jge    119f <remove_carriage_return+0x8f>
movslq %ebp,%rbp
jmp    1193 <remove_carriage_return+0x83>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    119f <remove_carriage_return+0x8f>
cmpb   $0xa,(%rbx,%rbp,1)
jne    1180 <remove_carriage_return+0x70>
movb   $0x0,(%rbx,%rbp,1)
jmp    1180 <remove_carriage_return+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define void @remove_carriage_return(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
%7 = icmp sgt i32 %6, 1
br i1 %7, label %8, label %59
8: ; preds = %1
store i32 0, i32* %3
br label %9
9: ; preds = %29, %8
%10 = load i32, i32* %3
%11 = load i8*, i8** %2
%12 = call i32 @strlen(i8* %11)
%13 = sub nsw i32 %12, 2
%14 = icmp slt i32 %10, %13
br i1 %14, label %15, label %32
15: ; preds = %9
%16 = load i8*, i8** %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 10
br i1 %22, label %23, label %28
23: ; preds = %15
%24 = load i8*, i8** %2
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 32, i8* %27
br label %28
28: ; preds = %23, %15
br label %29
29: ; preds = %28
%30 = load i32, i32* %3
%31 = add nsw i32 %30, 1
store i32 %31, i32* %3
br label %9
32: ; preds = %9
%33 = load i8*, i8** %2
%34 = call i32 @strlen(i8* %33)
%35 = sub nsw i32 %34, 2
store i32 %35, i32* %4
br label %36
36: ; preds = %55, %32
%37 = load i32, i32* %4
%38 = load i8*, i8** %2
%39 = call i32 @strlen(i8* %38)
%40 = icmp slt i32 %37, %39
br i1 %40, label %41, label %58
41: ; preds = %36
%42 = load i8*, i8** %2
%43 = load i32, i32* %4
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = icmp eq i32 %47, 10
br i1 %48, label %49, label %54
49: ; preds = %41
%50 = load i8*, i8** %2
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 0, i8* %53
br label %54
54: ; preds = %49, %41
br label %55
55: ; preds = %54
%56 = load i32, i32* %4
%57 = add nsw i32 %56, 1
store i32 %57, i32* %4
br label %36
58: ; preds = %36
br label %59
59: ; preds = %58, %1
ret void
}

LLVM IR (-O2):
define void @remove_carriage_return(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 1
br i1 %3, label %4, label %37
4: ; preds = %1
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 2
br i1 %6, label %14, label %7
7: ; preds = %20, %4
%8 = tail call i32 @strlen(i8* %0)
%9 = add i32 %8, -2
%10 = tail call i32 @strlen(i8* %0)
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %37
12: ; preds = %7
%13 = sext i32 %9 to i64
br label %26
14: ; preds = %4, %20
%15 = phi i64 [ %21, %20 ], [ 0, %4 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 10
br i1 %18, label %19, label %20
19: ; preds = %14
store i8 32, i8* %16
br label %20
20: ; preds = %14, %19
%21 = add nuw nsw i64 %15, 1
%22 = tail call i32 @strlen(i8* %0)
%23 = add nsw i32 %22, -2
%24 = sext i32 %23 to i64
%25 = icmp slt i64 %21, %24
br i1 %25, label %14, label %7
26: ; preds = %12, %32
%27 = phi i64 [ %13, %12 ], [ %33, %32 ]
%28 = getelementptr inbounds i8, i8* %0, i64 %27
%29 = load i8, i8* %28
%30 = icmp eq i8 %29, 10
br i1 %30, label %31, label %32
31: ; preds = %26
store i8 0, i8* %28
br label %32
32: ; preds = %26, %31
%33 = add nsw i64 %27, 1
%34 = tail call i32 @strlen(i8* %0)
%35 = sext i32 %34 to i64
%36 = icmp slt i64 %33, %35
br i1 %36, label %26, label %37
37: ; preds = %32, %7, %1
ret void
}