#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 */
typedef int /*<<< orphan*/ line;

/* Variables and functions */
scalar_t__ malloc(size_t);
size_t strcspn(char *, char const *);
size_t strspn(char *, char const *);
const char **sep_text_lines(char *text, size_t *ret_nlines) {
  static const char delims[] = "\r\n";
  size_t nlines = 0;
  const char **lines;
  char *line;
  size_t i;
  line = text;
  while (line[1]) {
    line = &line[strcspn(line, delims)];
    if (line[0])
      nlines += 1;
    line = &line[strspn(line, delims)];
  }
  lines = (const char **)malloc(nlines * sizeof(line));
  line = text;
  for (i = 0; i < nlines; ++i) {
    line = &line[strspn(line, delims)];
    lines[i] = line;
    line = &line[strcspn(line, delims)];
    line[0] = '\0';
    line = &line[1];
  }
  *ret_nlines = nlines;
  return lines;
}


x86 assembly (clang, -O0):
<sep_text_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,0x1(%rax)
je     11c8 <sep_text_lines+0x98>
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     119d <sep_text_lines+0x6d>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe50(%rip),%rsi
call   1030 <strspn@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    1150 <sep_text_lines+0x20>
mov    -0x18(%rbp),%rdi
shl    $0x3,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1277 <sep_text_lines+0x147>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdf6(%rip),%rsi
call   1030 <strspn@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   1040 <strcspn@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11e9 <sep_text_lines+0xb9>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sep_text_lines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
cmpb   $0x0,0x1(%rdi)
je     121a <sep_text_lines+0xea>
mov    %rbx,(%rsp)
xor    %r14d,%r14d
mov    %rdi,0x10(%rsp)
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rbp
mov    %rbx,%rdi
lea    0xe93(%rip),%r13
mov    %r13,%rsi
call   1040 <strcspn@plt>
lea    (%rbx,%rax,1),%r12
movzbl (%rbx,%rax,1),%r15d
cmp    $0x1,%r15b
sbb    $0xffffffffffffffff,%r14
mov    %r12,%rdi
mov    %r13,%rsi
call   1030 <strspn@plt>
lea    (%r12,%rax,1),%rbx
cmpb   $0x0,0x1(%rax,%r12,1)
jne    1160 <sep_text_lines+0x30>
lea    0x0(,%r14,8),%rdi
call   1050 <malloc@plt>
mov    %r14,0x8(%rsp)
test   %r14,%r14
je     1226 <sep_text_lines+0xf6>
cmp    $0x1,%r15b
mov    %rbp,%r14
sbb    $0xffffffffffffffff,%r14
xor    %r15d,%r15d
mov    %rax,%r12
mov    0x10(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xe26(%rip),%r13
mov    %r13,%rsi
call   1030 <strspn@plt>
mov    %rax,%rbx
add    %rbp,%rbx
mov    %rbx,(%r12,%r15,8)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcspn@plt>
movb   $0x0,(%rax,%rbx,1)
lea    (%rax,%rbx,1),%rbp
add    $0x1,%rbp
add    $0x1,%r15
cmp    %r15,%r14
jne    11d0 <sep_text_lines+0xa0>
mov    (%rsp),%rbx
mov    %r12,%rax
mov    0x8(%rsp),%r13
jmp    122d <sep_text_lines+0xfd>
xor    %r13d,%r13d
xor    %edi,%edi
call   1050 <malloc@plt>
jmp    122d <sep_text_lines+0xfd>
xor    %r13d,%r13d
mov    (%rsp),%rbx
mov    %r13,(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@sep_text_lines.delims = internal constant [3 x i8] c"\0D\0A\00"
define i8** @sep_text_lines(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i64
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i64* %1, i64** %4
store i64 0, i64* %5
%9 = load i8*, i8** %3
store i8* %9, i8** %7
br label %10
10: ; preds = %27, %2
%11 = load i8*, i8** %7
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = load i8*, i8** %7
%17 = load i8*, i8** %7
%18 = call i64 @strcspn(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @sep_text_lines.delims, i64 0, i64 0))
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = icmp ne i8 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %15
%25 = load i64, i64* %5
%26 = add i64 %25, 1
store i64 %26, i64* %5
br label %27
27: ; preds = %24, %15
%28 = load i8*, i8** %7
%29 = load i8*, i8** %7
%30 = call i64 @strspn(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @sep_text_lines.delims, i64 0, i64 0))
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8* %31, i8** %7
br label %10
32: ; preds = %10
%33 = load i64, i64* %5
%34 = mul i64 %33, 8
%35 = call i64 @malloc(i64 %34)
%36 = inttoptr i64 %35 to i8**
store i8** %36, i8*** %6
%37 = load i8*, i8** %3
store i8* %37, i8** %7
store i64 0, i64* %8
br label %38
38: ; preds = %59, %32
%39 = load i64, i64* %8
%40 = load i64, i64* %5
%41 = icmp ult i64 %39, %40
br i1 %41, label %42, label %62
42: ; preds = %38
%43 = load i8*, i8** %7
%44 = load i8*, i8** %7
%45 = call i64 @strspn(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @sep_text_lines.delims, i64 0, i64 0))
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8* %46, i8** %7
%47 = load i8*, i8** %7
%48 = load i8**, i8*** %6
%49 = load i64, i64* %8
%50 = getelementptr inbounds i8*, i8** %48, i64 %49
store i8* %47, i8** %50
%51 = load i8*, i8** %7
%52 = load i8*, i8** %7
%53 = call i64 @strcspn(i8* %52, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @sep_text_lines.delims, i64 0, i64 0))
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8* %54, i8** %7
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i64 0
store i8 0, i8* %56
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8* %58, i8** %7
br label %59
59: ; preds = %42
%60 = load i64, i64* %8
%61 = add i64 %60, 1
store i64 %61, i64* %8
br label %38
62: ; preds = %38
%63 = load i64, i64* %5
%64 = load i64*, i64** %4
store i64 %63, i64* %64
%65 = load i8**, i8*** %6
ret i8** %65
}

LLVM IR (-O2):
@sep_text_lines.delims = internal constant [3 x i8] c"\0D\0A\00"
define i8** @sep_text_lines(i8* %0, i64* nocapture writeonly %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 1
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i64 @malloc(i64 0)
%8 = inttoptr i64 %7 to i8**
br label %39
9: ; preds = %2, %9
%10 = phi i8* [ %19, %9 ], [ %0, %2 ]
%11 = phi i64 [ %17, %9 ], [ 0, %2 ]
%12 = tail call i64 @strcspn(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @sep_text_lines.delims, i64 0, i64 0))
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
%16 = zext i1 %15 to i64
%17 = add i64 %11, %16
%18 = tail call i64 @strspn(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @sep_text_lines.delims, i64 0, i64 0))
%19 = getelementptr inbounds i8, i8* %13, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %9
23: ; preds = %9
%24 = shl i64 %17, 3
%25 = tail call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to i8**
%27 = icmp eq i64 %17, 0
br i1 %27, label %39, label %28
28: ; preds = %23, %28
%29 = phi i64 [ %37, %28 ], [ 0, %23 ]
%30 = phi i8* [ %36, %28 ], [ %0, %23 ]
%31 = tail call i64 @strspn(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @sep_text_lines.delims, i64 0, i64 0))
%32 = getelementptr inbounds i8, i8* %30, i64 %31
%33 = getelementptr inbounds i8*, i8** %26, i64 %29
store i8* %32, i8** %33
%34 = tail call i64 @strcspn(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @sep_text_lines.delims, i64 0, i64 0))
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 0, i8* %35
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = add nuw i64 %29, 1
%38 = icmp eq i64 %37, %17
br i1 %38, label %39, label %28
39: ; preds = %28, %6, %23
%40 = phi i8** [ %8, %6 ], [ %26, %23 ], [ %26, %28 ]
%41 = phi i64 [ 0, %6 ], [ 0, %23 ], [ %17, %28 ]
store i64 %41, i64* %1
ret i8** %40
}