#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++;
      if (*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     1217 <rtv_split_lines+0xf7>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1212 <rtv_split_lines+0xf2>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     120d <rtv_split_lines+0xed>
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    1212 <rtv_split_lines+0xf2>
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   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
test   %rdi,%rdi
je     11c8 <rtv_split_lines+0xa8>
mov    $0xffffffff,%ebx
mov    %rbp,%rdi
xchg   %ax,%ax
mov    $0xa,%esi
call   1030 <strchr@plt>
lea    0x1(%rax),%rdi
add    $0x1,%ebx
test   %rax,%rax
jne    1140 <rtv_split_lines+0x20>
cmp    $0x1,%rax
mov    $0x1,%al
adc    $0x0,%al
movzbl %al,%r15d
and    $0x1,%r15d
add    %ebx,%r15d
mov    %r15d,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,(%rax)
test   %rbp,%rbp
je     11dd <rtv_split_lines+0xbd>
mov    %rbp,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11dd <rtv_split_lines+0xbd>
mov    $0x1,%ebp
jmp    11af <rtv_split_lines+0x8f>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11dd <rtv_split_lines+0xbd>
movb   $0x0,(%rax)
lea    0x1(%rax),%rdi
cmpb   $0x0,0x1(%rax)
je     11a0 <rtv_split_lines+0x80>
movslq %ebp,%rbp
mov    %rdi,(%rbx,%rbp,8)
add    $0x1,%ebp
jmp    11a0 <rtv_split_lines+0x80>
xor    %r15d,%r15d
xor    %edi,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,(%rax)
mov    %rbx,(%r14)
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
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 = %55, %24
%32 = load i8*, i8** %7
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %56
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 %55
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* %43
%45 = icmp ne i8 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %39
%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 = %46, %39
br label %55
55: ; preds = %54, %34
br label %31
56: ; preds = %31
%57 = load i8**, i8*** %8
%58 = load i8***, i8**** %4
store i8** %57, i8*** %58
%59 = load i32, i32* %5
ret i32 %59
}

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 %34
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 %34, 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 %34, label %20
20: ; preds = %17, %30
%21 = phi i8* [ %32, %30 ], [ %18, %17 ]
%22 = phi i32 [ %31, %30 ], [ 1, %17 ]
store i8 0, i8* %21
%23 = getelementptr inbounds i8, i8* %21, i64 1
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = sext i32 %22 to i64
%28 = getelementptr inbounds i8*, i8** %16, i64 %27
store i8* %23, i8** %28
%29 = add nsw i32 %22, 1
br label %30
30: ; preds = %20, %26
%31 = phi i32 [ %29, %26 ], [ %22, %20 ]
%32 = tail call i8* @strchr(i8* %23, i8 signext 10)
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %20
34: ; preds = %30, %17, %4, %15
%35 = phi i8** [ %5, %4 ], [ %16, %15 ], [ %16, %17 ], [ %16, %30 ]
%36 = phi i32 [ 0, %4 ], [ %14, %15 ], [ %14, %17 ], [ %14, %30 ]
store i8** %35, i8*** %1
ret i32 %36
}