#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*/ saved_append_1(char const *, char const *);
char *strchr(char const *, char);
int strlen(char const *);
void saved_append(const char *s) {
  while (*s) {
    const char *end = strchr(s, '\n');
    if (!end)
      end = s + strlen(s);
    else
      ++end;
    saved_append_1(s, end);
    s = end;
  }
}


x86 assembly (clang, -O0):
<saved_append>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b2 <saved_append+0x82>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    118c <saved_append+0x5c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
jmp    1198 <saved_append+0x68>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <saved_append_1@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    113c <saved_append+0xc>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saved_append>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     117c <saved_append+0x4c>
mov    %rdi,%r14
jmp    115a <saved_append+0x2a>
xchg   %ax,%ax
mov    %rax,%rbx
add    $0x1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <saved_append_1@plt>
cmpb   $0x0,(%rbx)
mov    %rbx,%r14
je     117c <saved_append+0x4c>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1140 <saved_append+0x10>
mov    %r14,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbx
add    %r14,%rbx
jmp    1147 <saved_append+0x17>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @saved_append(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
br label %4
4: ; preds = %22, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %8, label %27
8: ; preds = %4
%9 = load i8*, i8** %2
%10 = call i8* @strchr(i8* %9, i8 signext 10)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %8
%14 = load i8*, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8* %18, i8** %3
br label %22
19: ; preds = %8
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %3
br label %22
22: ; preds = %19, %13
%23 = load i8*, i8** %2
%24 = load i8*, i8** %3
%25 = call i32 @saved_append_1(i8* %23, i8* %24)
%26 = load i8*, i8** %3
store i8* %26, i8** %2
br label %4
27: ; preds = %4
ret void
}

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