#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 */
scalar_t__ malloc(int);
int strlen(char *);
char *removeNL(char *input) {
  int length = strlen(input);
  int i;
  char *newCommand = (char *)malloc(sizeof(char) * length);
  for (i = 0; i < length; i++) {
    if (input[i] == '\n') {
      newCommand[i] = '\0';
      break;
    }
    newCommand[i] = input[i];
  }
  return newCommand;
}


x86 assembly (clang, -O0):
<removeNL>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a8 <removeNL+0x88>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1184 <removeNL+0x64>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11a8 <removeNL+0x88>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1152 <removeNL+0x32>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeNL>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <malloc@plt>
test   %ebx,%ebx
jle    115c <removeNL+0x3c>
mov    %ebx,%ecx
xor    %edx,%edx
nopl   0x0(%rax)
movzbl 0x0(%rbp,%rdx,1),%ebx
cmp    $0xa,%bl
je     1158 <removeNL+0x38>
mov    %bl,(%rax,%rdx,1)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1140 <removeNL+0x20>
jmp    115c <removeNL+0x3c>
movb   $0x0,(%rax,%rdx,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @removeNL(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @malloc(i32 %2)
%4 = inttoptr i64 %3 to i8*
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %20
6: ; preds = %1
%7 = zext i32 %2 to i64
br label %8
8: ; preds = %6, %16
%9 = phi i64 [ 0, %6 ], [ %18, %16 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = and i64 %9, 4294967295
%15 = getelementptr inbounds i8, i8* %4, i64 %14
store i8 0, i8* %15
br label %20
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %4, i64 %9
store i8 %11, i8* %17
%18 = add nuw nsw i64 %9, 1
%19 = icmp eq i64 %18, %7
br i1 %19, label %20, label %8
20: ; preds = %16, %1, %13
ret i8* %4
}