#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 */
char *strpbrk(char *, char *);
int split_lines(char *s, char **lines, int n) {
  int i = 1;
  char *next = s;
  while (i < n && (next = strpbrk(next, "\n")) != NULL) {
    *next = '\0';
    lines[i++] = ++next;
  }
  lines[0] = s;
  return i;
}


x86 assembly (clang, -O0):
<split_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x21(%rbp)
jge    1161 <split_lines+0x51>
mov    -0x20(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1030 <strpbrk@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1171 <split_lines+0x61>
jmp    119f <split_lines+0x8f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    1132 <split_lines+0x22>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_lines>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x1,%ebx
cmp    $0x2,%edx
jl     1169 <split_lines+0x59>
mov    %edx,%r12d
mov    $0x1,%ebx
mov    %r14,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rax,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1169 <split_lines+0x59>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <split_lines+0x30>
mov    %r12d,%ebx
mov    %r14,(%r15)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @split_lines(i8* %0, i8** %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 %2, i32* %6
store i32 1, i32* %7
%9 = load i8*, i8** %4
store i8* %9, i8** %8
br label %10
10: ; preds = %20, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %6
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i8*, i8** %8
%16 = call i8* @strpbrk(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %8
%17 = icmp ne i8* %16, null
br label %18
18: ; preds = %14, %10
%19 = phi i1 [ false, %10 ], [ %17, %14 ]
br i1 %19, label %20, label %29
20: ; preds = %18
%21 = load i8*, i8** %8
store i8 0, i8* %21
%22 = load i8*, i8** %8
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %8
%24 = load i8**, i8*** %5
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds i8*, i8** %24, i64 %27
store i8* %23, i8** %28
br label %10
29: ; preds = %18
%30 = load i8*, i8** %4
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
store i8* %30, i8** %32
%33 = load i32, i32* %7
ret i32 %33
}

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