#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 */
scalar_t__ eMalloc(size_t);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *nextStringLine(const char **const next) {
  char *result = NULL;
  size_t length;
  const char *end;
  ;
  for (end = *next; *end != '\n' && *end != '\0'; ++end)
    ;
  length = end - *next;
  if (length > 0) {
    result = (char *)eMalloc((size_t)(length + 1) * sizeof(char));
    strncpy(result, *next, length);
    result[length] = '\0';
  }
  if (*end == '\n')
    ++end;
  else if (*end == '\r') {
    ++end;
    if (*end == '\n')
      ++end;
  }
  *next = end;
  return result;
}


x86 assembly (clang, -O0):
<nextStringLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x21(%rbp)
je     1164 <nextStringLine+0x44>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1174 <nextStringLine+0x54>
jmp    118a <nextStringLine+0x6a>
jmp    1179 <nextStringLine+0x59>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113f <nextStringLine+0x1f>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11dc <nextStringLine+0xbc>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1040 <eMalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11fd <nextStringLine+0xdd>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    123f <nextStringLine+0x11f>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xd,%eax
jne    123a <nextStringLine+0x11a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    1235 <nextStringLine+0x115>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    123a <nextStringLine+0x11a>
jmp    123f <nextStringLine+0x11f>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nextStringLine>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%eax
test   %al,%al
je     1153 <nextStringLine+0x33>
cmp    $0xa,%al
je     1153 <nextStringLine+0x33>
add    $0x1,%rbx
jmp    1140 <nextStringLine+0x20>
lea    (%r12,%rbx,1),%r13
test   %rbx,%rbx
je     119d <nextStringLine+0x7d>
lea    0x1(%rbx),%rdi
call   1040 <eMalloc@plt>
mov    %rax,%r15
mov    (%r14),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%rbx,1)
mov    0x0(%r13),%al
cmp    $0xa,%al
je     11a4 <nextStringLine+0x84>
cmp    $0xd,%al
jne    11ac <nextStringLine+0x8c>
cmpb   $0xa,0x1(%r12,%rbx,1)
lea    0x1(%r12,%rbx,1),%rax
lea    0x2(%r12,%rbx,1),%r13
cmovne %rax,%r13
jmp    11ac <nextStringLine+0x8c>
xor    %r15d,%r15d
cmp    $0xa,%al
jne    1183 <nextStringLine+0x63>
lea    (%r12,%rbx,1),%r13
add    $0x1,%r13
mov    %r13,(%r14)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @nextStringLine(i8** nocapture %0) {
%2 = load i8*, i8** %0
br label %3
3: ; preds = %6, %1
%4 = phi i8* [ %2, %1 ], [ %7, %6 ]
%5 = load i8, i8* %4
switch i8 %5, label %6 [
i8 10, label %8
i8 0, label %8
]
6: ; preds = %3
%7 = getelementptr inbounds i8, i8* %4, i64 1
br label %3
8: ; preds = %3, %3
%9 = ptrtoint i8* %4 to i64
%10 = ptrtoint i8* %2 to i64
%11 = sub i64 %9, %10
%12 = icmp eq i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %8
%14 = add i64 %11, 1
%15 = tail call i64 @eMalloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
%17 = load i8*, i8** %0
%18 = tail call i32 @strncpy(i8* %16, i8* %17, i64 %11)
%19 = getelementptr inbounds i8, i8* %16, i64 %11
store i8 0, i8* %19
%20 = load i8, i8* %4
br label %21
21: ; preds = %13, %8
%22 = phi i8 [ %20, %13 ], [ %5, %8 ]
%23 = phi i8* [ %16, %13 ], [ null, %8 ]
switch i8 %22, label %32 [
i8 10, label %24
i8 13, label %26
]
24: ; preds = %21
%25 = getelementptr inbounds i8, i8* %4, i64 1
br label %32
26: ; preds = %21
%27 = getelementptr inbounds i8, i8* %4, i64 1
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 10
%30 = getelementptr inbounds i8, i8* %4, i64 2
%31 = select i1 %29, i8* %30, i8* %27
br label %32
32: ; preds = %26, %21, %24
%33 = phi i8* [ %25, %24 ], [ %4, %21 ], [ %31, %26 ]
store i8* %33, i8** %0
ret i8* %23
}