#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 /*<<< orphan*/);
char *strchr(char *, char);
int /*<<< orphan*/ strlen(char *);
char *cut_emptylines(char *text) {
  char *posi;
  char *found;
  posi = text;
  while (posi[0] && (found = strchr(posi, '\n'))) {
    if ((found[1] == '\n') || (found == text))
      memmove(found, found + 1, strlen(found));
    else
      posi++;
  }
  return text;
}


x86 assembly (clang, -O0):
<cut_emptylines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1175 <cut_emptylines+0x45>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1185 <cut_emptylines+0x55>
jmp    11e6 <cut_emptylines+0xb6>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0xa,%eax
je     11a4 <cut_emptylines+0x74>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jne    11d5 <cut_emptylines+0xa5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
jmp    11e1 <cut_emptylines+0xb1>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1144 <cut_emptylines+0x14>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cut_emptylines>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     119c <cut_emptylines+0x6c>
mov    %r14,%r15
jmp    1172 <cut_emptylines+0x42>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%r12
add    $0x1,%r12
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <memmove@plt>
cmpb   $0x0,(%r15)
je     119c <cut_emptylines+0x6c>
mov    %r15,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     119c <cut_emptylines+0x6c>
mov    %rax,%rbx
cmpb   $0xa,0x1(%rax)
je     1150 <cut_emptylines+0x20>
cmp    %r14,%rbx
je     1150 <cut_emptylines+0x20>
add    $0x1,%r15
cmpb   $0x0,(%r15)
jne    1172 <cut_emptylines+0x42>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @cut_emptylines(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %3
br label %6
6: ; preds = %38, %1
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = load i8*, i8** %3
%14 = call i8* @strchr(i8* %13, i8 signext 10)
store i8* %14, i8** %4
%15 = icmp ne i8* %14, null
br label %16
16: ; preds = %12, %6
%17 = phi i1 [ false, %6 ], [ %15, %12 ]
br i1 %17, label %18, label %39
18: ; preds = %16
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 10
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = load i8*, i8** %4
%26 = load i8*, i8** %2
%27 = icmp eq i8* %25, %26
br i1 %27, label %28, label %35
28: ; preds = %24, %18
%29 = load i8*, i8** %4
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i8*, i8** %4
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @memmove(i8* %29, i8* %31, i32 %33)
br label %38
35: ; preds = %24
%36 = load i8*, i8** %3
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %3
br label %38
38: ; preds = %35, %28
br label %6
39: ; preds = %16
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
define i8* @cut_emptylines(i8* returned %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %23, label %4
4: ; preds = %1, %19
%5 = phi i8* [ %20, %19 ], [ %0, %1 ]
%6 = tail call i8* @strchr(i8* %5, i8 signext 10)
%7 = icmp eq i8* %6, null
br i1 %7, label %23, label %8
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = load i8, i8* %9
%11 = icmp eq i8 %10, 10
%12 = icmp eq i8* %6, %0
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %17
14: ; preds = %8
%15 = tail call i32 @strlen(i8* %6)
%16 = tail call i32 @memmove(i8* %6, i8* %9, i32 %15)
br label %19
17: ; preds = %8
%18 = getelementptr inbounds i8, i8* %5, i64 1
br label %19
19: ; preds = %17, %14
%20 = phi i8* [ %5, %14 ], [ %18, %17 ]
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %4
23: ; preds = %4, %19, %1
ret i8* %0
}