#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 **malloc(int);
char *strchr(char *, char);
int split_lines(char *src, char ***pdst) {
  int num_lines, i;
  char *p;
  char **dst;
  num_lines = 0;
  p = src;
  while (p) {
    p = strchr(p, '\n');
    if (p) {
      p++;
      num_lines++;
    }
  }
  dst = malloc((num_lines + 1) * sizeof(char *));
  dst[0] = src;
  p = src;
  i = 1;
  while (p) {
    p = strchr(p, '\n');
    if (p) {
      *p = '\0';
      p++;
      dst[i] = p;
      i++;
    }
  }
  *pdst = dst;
  return num_lines;
}


x86 assembly (clang, -O0):
<split_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1181 <split_lines+0x61>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117c <split_lines+0x5c>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113f <split_lines+0x1f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120b <split_lines+0xeb>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1206 <split_lines+0xe6>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b2 <split_lines+0x92>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_lines>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     116b <split_lines+0x4b>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
nopl   0x0(%rax,%rax,1)
mov    $0xa,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rdi
add    $0x1,%ebp
test   %rax,%rax
jne    1140 <split_lines+0x20>
cmp    $0x1,%rax
mov    $0x1,%al
adc    $0x0,%al
movzbl %al,%r15d
and    $0x1,%r15d
add    %ebp,%r15d
jmp    116e <split_lines+0x4e>
xor    %r15d,%r15d
lea    0x8(,%r15,8),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %rbx,(%rax)
test   %rbx,%rbx
je     11c0 <split_lines+0xa0>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11c0 <split_lines+0xa0>
mov    %r12,%rbx
add    $0x8,%rbx
nop
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,(%rbx)
mov    %rax,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
add    $0x8,%rbx
test   %rax,%rax
jne    11a0 <split_lines+0x80>
mov    %r12,(%r14)
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @split_lines(i8* %0, i8*** %1) {
%3 = alloca i8*
%4 = alloca i8***
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8**
store i8* %0, i8** %3
store i8*** %1, i8**** %4
store i32 0, i32* %5
%9 = load i8*, i8** %3
store i8* %9, i8** %7
br label %10
10: ; preds = %23, %2
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load i8*, i8** %7
%15 = call i8* @strchr(i8* %14, i8 signext 10)
store i8* %15, i8** %7
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i8*, i8** %7
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %7
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %23
23: ; preds = %18, %13
br label %10
24: ; preds = %10
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = mul i64 %27, 8
%29 = trunc i64 %28 to i32
%30 = call i8** @malloc(i32 %29)
store i8** %30, i8*** %8
%31 = load i8*, i8** %3
%32 = load i8**, i8*** %8
%33 = getelementptr inbounds i8*, i8** %32, i64 0
store i8* %31, i8** %33
%34 = load i8*, i8** %3
store i8* %34, i8** %7
store i32 1, i32* %6
br label %35
35: ; preds = %54, %24
%36 = load i8*, i8** %7
%37 = icmp ne i8* %36, null
br i1 %37, label %38, label %55
38: ; preds = %35
%39 = load i8*, i8** %7
%40 = call i8* @strchr(i8* %39, i8 signext 10)
store i8* %40, i8** %7
%41 = load i8*, i8** %7
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %54
43: ; preds = %38
%44 = load i8*, i8** %7
store i8 0, i8* %44
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %7
%47 = load i8*, i8** %7
%48 = load i8**, i8*** %8
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
store i8* %47, i8** %51
%52 = load i32, i32* %6
%53 = add nsw i32 %52, 1
store i32 %53, i32* %6
br label %54
54: ; preds = %43, %38
br label %35
55: ; preds = %35
%56 = load i8**, i8*** %8
%57 = load i8***, i8**** %4
store i8** %56, i8*** %57
%58 = load i32, i32* %5
ret i32 %58
}

LLVM IR (-O2):
define i32 @split_lines(i8* %0, i8*** nocapture writeonly %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %13, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %12, %4 ], [ 0, %2 ]
%6 = phi i8* [ %9, %4 ], [ %0, %2 ]
%7 = tail call i8* @strchr(i8* %6, i8 signext 10)
%8 = icmp eq i8* %7, null
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = xor i1 %8, true
%11 = zext i1 %10 to i32
%12 = add nuw nsw i32 %5, %11
br i1 %8, label %13, label %4
13: ; preds = %4, %2
%14 = phi i32 [ 0, %2 ], [ %12, %4 ]
%15 = shl i32 %14, 3
%16 = add i32 %15, 8
%17 = tail call i8** @malloc(i32 %16)
store i8* %0, i8** %17
br i1 %3, label %30, label %18
18: ; preds = %13
%19 = tail call i8* @strchr(i8* %0, i8 signext 10)
%20 = icmp eq i8* %19, null
br i1 %20, label %30, label %21
21: ; preds = %18, %21
%22 = phi i8* [ %28, %21 ], [ %19, %18 ]
%23 = phi i32 [ %27, %21 ], [ 1, %18 ]
store i8 0, i8* %22
%24 = getelementptr inbounds i8, i8* %22, i64 1
%25 = zext i32 %23 to i64
%26 = getelementptr inbounds i8*, i8** %17, i64 %25
store i8* %24, i8** %26
%27 = add nuw nsw i32 %23, 1
%28 = tail call i8* @strchr(i8* %24, i8 signext 10)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %21
30: ; preds = %21, %18, %13
store i8** %17, i8*** %1
ret i32 %14
}