#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*/ memmove(char *, char *, int);
int strlen(char *);
char *strstr(char *, char *);
void removeNewlines(char *s) {
  while (s = strstr(s, "\n")) {
    memmove(s, s + strlen("\n"), 1 + strlen(s + strlen("\n")));
  }
}


x86 assembly (clang, -O0):
<removeNewlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     11bf <removeNewlines+0x8f>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe8f(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe6b(%rip),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
cltq
add    %rax,%rdi
call   1030 <strlen@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1040 <memmove@plt>
jmp    113c <removeNewlines+0xc>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<removeNewlines>:
push   %r15
push   %r14
push   %rbx
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1194 <removeNewlines+0x64>
mov    %rax,%rbx
lea    0xeb2(%rip),%r14
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%r15
add    %rbx,%r15
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1050 <memmove@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1150 <removeNewlines+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define void @removeNewlines(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
br label %3
3: ; preds = %7, %1
%4 = load i8*, i8** %2
%5 = call i8* @strstr(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %20
7: ; preds = %3
%8 = load i8*, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 1, %17
%19 = call i32 @memmove(i8* %8, i8* %12, i32 %18)
br label %3
20: ; preds = %3
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define void @removeNewlines(i8* %0) {
%2 = tail call i8* @strchr(i8* dereferenceable(1) %0, i32 10)
%3 = icmp eq i8* %2, null
br i1 %3, label %17, label %4
4: ; preds = %1, %4
%5 = phi i8* [ %15, %4 ], [ %2, %1 ]
%6 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %5, i64 %7
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %5, i64 %10
%12 = tail call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = tail call i32 @memmove(i8* %5, i8* %8, i32 %13)
%15 = tail call i8* @strchr(i8* dereferenceable(1) %5, i32 10)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %4
17: ; preds = %4, %1
ret void
}