#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 **calloc(int, int);
char *strchr(char *, char);
int rtv_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 = calloc(num_lines, 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):
<rtv_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 <rtv_split_lines+0x61>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117c <rtv_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 <rtv_split_lines+0x1f>
mov    -0x14(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@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     1205 <rtv_split_lines+0xe5>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1200 <rtv_split_lines+0xe0>
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    11ac <rtv_split_lines+0x8c>
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):
<rtv_split_lines>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     11c2 <rtv_split_lines+0xa2>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
nop
mov    $0xa,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rdi
add    $0x1,%ebp
test   %rax,%rax
jne    1140 <rtv_split_lines+0x20>
cmp    $0x1,%rax
mov    $0x1,%al
adc    $0x0,%al
movzbl %al,%r12d
and    $0x1,%r12d
add    %ebp,%r12d
mov    %r12d,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %rbx,(%rax)
test   %rbx,%rbx
je     11d7 <rtv_split_lines+0xb7>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11d7 <rtv_split_lines+0xb7>
mov    %r15,%rbx
add    $0x8,%rbx
nopw   0x0(%rax,%rax,1)
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 <rtv_split_lines+0x80>
jmp    11d7 <rtv_split_lines+0xb7>
xor    %r12d,%r12d
xor    %edi,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %rbx,(%rax)
mov    %r15,(%r14)
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @rtv_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 = call i8** @calloc(i32 %25, i32 8)
store i8** %26, i8*** %8
%27 = load i8*, i8** %3
%28 = load i8**, i8*** %8
%29 = getelementptr inbounds i8*, i8** %28, i64 0
store i8* %27, i8** %29
%30 = load i8*, i8** %3
store i8* %30, i8** %7
store i32 1, i32* %6
br label %31
31: ; preds = %50, %24
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %51
34: ; preds = %31
%35 = load i8*, i8** %7
%36 = call i8* @strchr(i8* %35, i8 signext 10)
store i8* %36, i8** %7
%37 = load i8*, i8** %7
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %50
39: ; preds = %34
%40 = load i8*, i8** %7
store i8 0, i8* %40
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %7
%43 = load i8*, i8** %7
%44 = load i8**, i8*** %8
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8*, i8** %44, i64 %46
store i8* %43, i8** %47
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %50
50: ; preds = %39, %34
br label %31
51: ; preds = %31
%52 = load i8**, i8*** %8
%53 = load i8***, i8**** %4
store i8** %52, i8*** %53
%54 = load i32, i32* %5
ret i32 %54
}

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