#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 count_newlines(char *);
char *get_line(char **);
char **malloc(int);
int /*<<< orphan*/ skip_newlines(char **);
char **split_newlines(char *str) {
  int splits;
  int i;
  char **tab;
  splits = count_newlines(str) + 1;
  tab = malloc(sizeof(char *) * splits);
  i = 0;
  while (i < splits) {
    if (i < (splits - 1)) {
      skip_newlines(&str);
      tab[i] = get_line(&str);
    } else
      tab[i] = 0;
    ++i;
  }
  return (tab);
}


x86 assembly (clang, -O0):
<split_newlines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <count_newlines@plt>
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d6 <split_newlines+0x96>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b8 <split_newlines+0x78>
lea    -0x8(%rbp),%rdi
call   1040 <skip_newlines@plt>
lea    -0x8(%rbp),%rdi
call   1030 <get_line@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11c8 <split_newlines+0x88>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1175 <split_newlines+0x35>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_newlines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,0x8(%rsp)
call   1060 <count_newlines@plt>
mov    %eax,%r13d
lea    0x8(,%r13,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %r13d,%r13d
js     11a6 <split_newlines+0x66>
mov    %r13d,%r12d
add    $0x1,%r13d
xor    %ebx,%ebx
lea    0x8(%rsp),%r15
jmp    119d <split_newlines+0x5d>
nop
mov    %r15,%rdi
call   1040 <skip_newlines@plt>
mov    %r15,%rdi
call   1030 <get_line@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r13
je     11a6 <split_newlines+0x66>
cmp    %r12,%rbx
jb     1180 <split_newlines+0x40>
xor    %eax,%eax
jmp    1190 <split_newlines+0x50>
mov    %r14,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8** @split_newlines(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @count_newlines(i8* %6)
%8 = add nsw i32 %7, 1
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = mul i64 8, %10
%12 = trunc i64 %11 to i32
%13 = call i8** @malloc(i32 %12)
store i8** %13, i8*** %5
store i32 0, i32* %4
br label %14
14: ; preds = %35, %1
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %38
18: ; preds = %14
%19 = load i32, i32* %4
%20 = load i32, i32* %3
%21 = sub nsw i32 %20, 1
%22 = icmp slt i32 %19, %21
br i1 %22, label %23, label %30
23: ; preds = %18
%24 = call i32 @skip_newlines(i8** %2)
%25 = call i8* @get_line(i8** %2)
%26 = load i8**, i8*** %5
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %26, i64 %28
store i8* %25, i8** %29
br label %35
30: ; preds = %18
%31 = load i8**, i8*** %5
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
store i8* null, i8** %34
br label %35
35: ; preds = %30, %23
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %14
38: ; preds = %14
%39 = load i8**, i8*** %5
ret i8** %39
}

LLVM IR (-O2):
define noalias i8** @split_newlines(i8* %0) {
%2 = alloca i8*
store i8* %0, i8** %2
%3 = tail call i32 @count_newlines(i8* %0)
%4 = shl i32 %3, 3
%5 = add i32 %4, 8
%6 = tail call i8** @malloc(i32 %5)
%7 = icmp slt i32 %3, 0
br i1 %7, label %23, label %8
8: ; preds = %1
%9 = zext i32 %3 to i64
%10 = add nuw i32 %3, 1
%11 = zext i32 %10 to i64
br label %12
12: ; preds = %8, %18
%13 = phi i64 [ 0, %8 ], [ %21, %18 ]
%14 = icmp ult i64 %13, %9
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = call i32 @skip_newlines(i8** %2)
%17 = call i8* @get_line(i8** %2)
br label %18
18: ; preds = %12, %15
%19 = phi i8* [ %17, %15 ], [ null, %12 ]
%20 = getelementptr inbounds i8*, i8** %6, i64 %13
store i8* %19, i8** %20
%21 = add nuw nsw i64 %13, 1
%22 = icmp eq i64 %21, %11
br i1 %22, label %23, label %12
23: ; preds = %18, %1
ret i8** %6
}