#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 */
struct list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ list_add(struct list *, char *);
struct list *list_create();
char *malloc(size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
struct list *list_split_lines(const char *s) {
  struct list *result = list_create();
  const char *p = s;
  const char *q;
  while (*p) {
    while (*p == '\n')
      p++;
    if (!*p)
      break;
    q = p + 1;
    while (!(*q == '\n' || *q == '\0'))
      q++;
    char *data = malloc((size_t)(q - p + 2));
    strncpy(data, p, (size_t)(q - p));
    data[q - p] = '\0';
    list_add(result, data);
    p = q;
  }
  return result;
}


x86 assembly (clang, -O0):
<list_split_lines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <list_create@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     1255 <list_split_lines+0x115>
jmp    1171 <list_split_lines+0x31>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1192 <list_split_lines+0x52>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1171 <list_split_lines+0x31>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11a4 <list_split_lines+0x64>
jmp    1255 <list_split_lines+0x115>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
mov    $0x1,%al
cmp    $0xa,%ecx
mov    %al,-0x29(%rbp)
je     11d5 <list_split_lines+0x95>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    11e7 <list_split_lines+0xa7>
jmp    11f8 <list_split_lines+0xb8>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b0 <list_split_lines+0x70>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
sub    %rax,%rdi
add    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rax
sub    %rax,%rdx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <list_add@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    115f <list_split_lines+0x1f>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_split_lines>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %eax,%eax
call   1040 <list_create@plt>
mov    %rax,%r14
mov    (%r15),%al
jmp    1191 <list_split_lines+0x51>
nopw   0x0(%rax,%rax,1)
lea    0x2(%rbx),%rdi
call   1050 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r12,%rbx,1)
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <list_add@plt>
mov    (%r15,%rbx,1),%al
add    %rbx,%r15
test   %al,%al
je     11c4 <list_split_lines+0x84>
cmp    $0xa,%al
jne    11a6 <list_split_lines+0x66>
movzbl 0x1(%r15),%eax
add    $0x1,%r15
cmp    $0xa,%al
je     1199 <list_split_lines+0x59>
test   %al,%al
je     11c4 <list_split_lines+0x84>
xor    %ebx,%ebx
nopl   0x0(%rax)
movzbl 0x1(%r15,%rbx,1),%eax
add    $0x1,%rbx
cmp    $0xa,%al
je     1160 <list_split_lines+0x20>
test   %al,%al
jne    11b0 <list_split_lines+0x70>
jmp    1160 <list_split_lines+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.list = type { i32 }
define %struct.list* @list_split_lines(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.list*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
%7 = call %struct.list* (...) @list_create()
store %struct.list* %7, %struct.list** %3
%8 = load i8*, i8** %2
store i8* %8, i8** %4
br label %9
9: ; preds = %46, %1
%10 = load i8*, i8** %4
%11 = load i8, i8* %10
%12 = icmp ne i8 %11, 0
br i1 %12, label %13, label %73
13: ; preds = %9
br label %14
14: ; preds = %19, %13
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
br label %14
22: ; preds = %14
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = icmp ne i8 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %22
br label %73
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8* %29, i8** %5
br label %30
30: ; preds = %43, %27
%31 = load i8*, i8** %5
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %40, label %35
35: ; preds = %30
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br label %40
40: ; preds = %35, %30
%41 = phi i1 [ true, %30 ], [ %39, %35 ]
%42 = xor i1 %41, true
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = load i8*, i8** %5
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %5
br label %30
46: ; preds = %40
%47 = load i8*, i8** %5
%48 = load i8*, i8** %4
%49 = ptrtoint i8* %47 to i64
%50 = ptrtoint i8* %48 to i64
%51 = sub i64 %49, %50
%52 = add nsw i64 %51, 2
%53 = call i8* @malloc(i64 %52)
store i8* %53, i8** %6
%54 = load i8*, i8** %6
%55 = load i8*, i8** %4
%56 = load i8*, i8** %5
%57 = load i8*, i8** %4
%58 = ptrtoint i8* %56 to i64
%59 = ptrtoint i8* %57 to i64
%60 = sub i64 %58, %59
%61 = call i32 @strncpy(i8* %54, i8* %55, i64 %60)
%62 = load i8*, i8** %6
%63 = load i8*, i8** %5
%64 = load i8*, i8** %4
%65 = ptrtoint i8* %63 to i64
%66 = ptrtoint i8* %64 to i64
%67 = sub i64 %65, %66
%68 = getelementptr inbounds i8, i8* %62, i64 %67
store i8 0, i8* %68
%69 = load %struct.list*, %struct.list** %3
%70 = load i8*, i8** %6
%71 = call i32 @list_add(%struct.list* %69, i8* %70)
%72 = load i8*, i8** %5
store i8* %72, i8** %4
br label %9
73: ; preds = %26, %9
%74 = load %struct.list*, %struct.list** %3
ret %struct.list* %74
}

LLVM IR (-O2):
%struct.list = type { i32 }
define %struct.list* @list_split_lines(i8* %0) {
%2 = tail call %struct.list* (...) @list_create()
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %29, label %5
5: ; preds = %1, %11
%6 = phi i8 [ %12, %11 ], [ %3, %1 ]
%7 = phi i8* [ %13, %11 ], [ %0, %1 ]
switch i8 %6, label %14 [
i8 10, label %8
i8 0, label %29
]
8: ; preds = %5
%9 = getelementptr inbounds i8, i8* %7, i64 1
%10 = load i8, i8* %9
br label %11
11: ; preds = %8, %18
%12 = phi i8 [ %10, %8 ], [ %27, %18 ]
%13 = phi i8* [ %9, %8 ], [ %16, %18 ]
br label %5
14: ; preds = %5, %14
%15 = phi i8* [ %16, %14 ], [ %7, %5 ]
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
switch i8 %17, label %14 [
i8 10, label %18
i8 0, label %18
]
18: ; preds = %14, %14
%19 = ptrtoint i8* %16 to i64
%20 = ptrtoint i8* %7 to i64
%21 = sub i64 %19, %20
%22 = add nsw i64 %21, 2
%23 = tail call i8* @malloc(i64 %22)
%24 = tail call i32 @strncpy(i8* %23, i8* %7, i64 %21)
%25 = getelementptr inbounds i8, i8* %23, i64 %21
store i8 0, i8* %25
%26 = tail call i32 @list_add(%struct.list* %2, i8* %23)
%27 = load i8, i8* %16
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %11
29: ; preds = %18, %5, %1
ret %struct.list* %2
}