#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 cs(char *);
int /*<<< orphan*/ ft_bzero(char *, int);
int /*<<< orphan*/ ft_strdel(char **);
char *ft_strdup(char *);
char *ft_strjoin(char *, char *);
scalar_t__ malloc(int);
int processline(int, char **, char ***);
int read(int const, char *, int);
int get_next_line(const int fd, char **line) {
  char buffer[2017 + 1];
  int ret;
  static char *str[42];
  char *swap;
  ret = 1;
  if (!line || fd > 42 || fd < 0 || 2017 < 1)
    return (-1);
  if (!str[fd]) {
    if (!(str[fd] = (char *)malloc(sizeof(char) * 2017)))
      return (-1);
    ft_bzero(str[fd], 2017);
  }
  while (cs(str[fd]) == -1 && ret) {
    if ((ret = read(fd, buffer, 2017)) == -1)
      return (-1);
    buffer[ret] = '\0';
    swap = ft_strdup(str[fd]);
    ft_strdel(&str[fd]);
    str[fd] = ft_strjoin(swap, buffer);
    ft_strdel(&swap);
  }
  return (processline(ret, &str[fd], &line));
}


x86 assembly (clang, -O0):
<get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x804(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11bb <get_next_line+0x3b>
cmpl   $0x2a,-0x8(%rbp)
jg     11bb <get_next_line+0x3b>
cmpl   $0x0,-0x8(%rbp)
jge    11c7 <get_next_line+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <get_next_line+0x1be>
movslq -0x8(%rbp),%rcx
lea    0x2e9e(%rip),%rax
cmpq   $0x0,(%rax,%rcx,8)
jne    1225 <get_next_line+0xa5>
mov    $0x7e1,%edi
call   1070 <malloc@plt>
movslq -0x8(%rbp),%rdx
lea    0x2e7e(%rip),%rcx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    120c <get_next_line+0x8c>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <get_next_line+0x1be>
movslq -0x8(%rbp),%rcx
lea    0x2e59(%rip),%rax
mov    (%rax,%rcx,8),%rdi
mov    $0x7e1,%esi
call   1030 <ft_bzero@plt>
jmp    122a <get_next_line+0xaa>
movslq -0x8(%rbp),%rcx
lea    0x2e3b(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1080 <cs@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x811(%rbp)
jne    1261 <get_next_line+0xe1>
cmpl   $0x0,-0x804(%rbp)
setne  %al
mov    %al,-0x811(%rbp)
mov    -0x811(%rbp),%al
test   $0x1,%al
jne    1274 <get_next_line+0xf4>
jmp    131a <get_next_line+0x19a>
mov    -0x8(%rbp),%edi
lea    -0x800(%rbp),%rsi
mov    $0x7e1,%edx
call   1040 <read@plt>
mov    %eax,-0x804(%rbp)
cmp    $0xffffffff,%eax
jne    12a3 <get_next_line+0x123>
movl   $0xffffffff,-0x4(%rbp)
jmp    133e <get_next_line+0x1be>
movslq -0x804(%rbp),%rax
movb   $0x0,-0x800(%rbp,%rax,1)
movslq -0x8(%rbp),%rcx
lea    0x2db3(%rip),%rax
mov    (%rax,%rcx,8),%rdi
call   1060 <ft_strdup@plt>
mov    %rax,-0x810(%rbp)
movslq -0x8(%rbp),%rax
lea    0x2d98(%rip),%rdi
shl    $0x3,%rax
add    %rax,%rdi
call   1050 <ft_strdel@plt>
mov    -0x810(%rbp),%rdi
lea    -0x800(%rbp),%rsi
call   10a0 <ft_strjoin@plt>
mov    %rax,%rdx
movslq -0x8(%rbp),%rcx
lea    0x2d6b(%rip),%rax
mov    %rdx,(%rax,%rcx,8)
lea    -0x810(%rbp),%rdi
call   1050 <ft_strdel@plt>
jmp    122a <get_next_line+0xaa>
mov    -0x804(%rbp),%edi
movslq -0x8(%rbp),%rax
lea    0x2d45(%rip),%rsi
shl    $0x3,%rax
add    %rax,%rsi
lea    -0x10(%rbp),%rdx
call   1090 <processline@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7f8,%rsp
mov    %rsi,0x8(%rsp)
mov    $0xffffffff,%r14d
cmp    $0x2a,%edi
ja     1202 <get_next_line+0x82>
test   %rsi,%rsi
je     1202 <get_next_line+0x82>
mov    %edi,%r15d
mov    %edi,%eax
lea    0x2ebe(%rip),%rcx
lea    (%rcx,%rax,8),%rbx
mov    (%rcx,%rax,8),%rdi
test   %rdi,%rdi
jne    11e1 <get_next_line+0x61>
mov    $0x7e1,%edi
call   1070 <malloc@plt>
mov    %rax,(%rbx)
test   %rax,%rax
je     1202 <get_next_line+0x82>
mov    %rax,%rdi
mov    $0x7e1,%esi
call   1030 <ft_bzero@plt>
mov    (%rbx),%rdi
call   1080 <cs@plt>
mov    $0x1,%ebp
cmp    $0xffffffff,%eax
je     1217 <get_next_line+0x97>
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <processline@plt>
mov    %eax,%r14d
mov    %r14d,%eax
add    $0x7f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%r12
mov    %rsp,%r13
nop
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x7e1,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     1202 <get_next_line+0x82>
mov    %eax,%ebp
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    (%rbx),%rdi
call   1060 <ft_strdup@plt>
mov    %rax,(%rsp)
mov    %rbx,%rdi
call   1050 <ft_strdel@plt>
mov    (%rsp),%rdi
mov    %r12,%rsi
call   10a0 <ft_strjoin@plt>
mov    %rax,(%rbx)
mov    %r13,%rdi
call   1050 <ft_strdel@plt>
mov    (%rbx),%rdi
call   1080 <cs@plt>
test   %ebp,%ebp
je     11f0 <get_next_line+0x70>
cmp    $0xffffffff,%eax
je     1220 <get_next_line+0xa0>
jmp    11f0 <get_next_line+0x70>

LLVM IR (-O0):
@get_next_line.str = internal global [42 x i8*] zeroinitializer
define i32 @get_next_line(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2018 x i8]
%7 = alloca i32
%8 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
%9 = load i8**, i8*** %5
%10 = icmp ne i8** %9, null
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 42
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %11, %2
store i32 -1, i32* %3
br label %83
18: ; preds = %14
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %20
%22 = load i8*, i8** %21
%23 = icmp ne i8* %22, null
br i1 %23, label %38, label %24
24: ; preds = %18
%25 = call i64 @malloc(i32 2017)
%26 = inttoptr i64 %25 to i8*
%27 = load i32, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %28
store i8* %26, i8** %29
%30 = icmp ne i8* %26, null
br i1 %30, label %32, label %31
31: ; preds = %24
store i32 -1, i32* %3
br label %83
32: ; preds = %24
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %34
%36 = load i8*, i8** %35
%37 = call i32 @ft_bzero(i8* %36, i32 2017)
br label %38
38: ; preds = %32, %18
br label %39
39: ; preds = %57, %38
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @cs(i8* %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br label %49
49: ; preds = %46, %39
%50 = phi i1 [ false, %39 ], [ %48, %46 ]
br i1 %50, label %51, label %77
51: ; preds = %49
%52 = load i32, i32* %4
%53 = getelementptr inbounds [2018 x i8], [2018 x i8]* %6, i64 0, i64 0
%54 = call i32 @read(i32 %52, i8* %53, i32 2017)
store i32 %54, i32* %7
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %57
56: ; preds = %51
store i32 -1, i32* %3
br label %83
57: ; preds = %51
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [2018 x i8], [2018 x i8]* %6, i64 0, i64 %59
store i8 0, i8* %60
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %62
%64 = load i8*, i8** %63
%65 = call i8* @ft_strdup(i8* %64)
store i8* %65, i8** %8
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %67
%69 = call i32 @ft_strdel(i8** %68)
%70 = load i8*, i8** %8
%71 = getelementptr inbounds [2018 x i8], [2018 x i8]* %6, i64 0, i64 0
%72 = call i8* @ft_strjoin(i8* %70, i8* %71)
%73 = load i32, i32* %4
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %74
store i8* %72, i8** %75
%76 = call i32 @ft_strdel(i8** %8)
br label %39
77: ; preds = %49
%78 = load i32, i32* %7
%79 = load i32, i32* %4
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %80
%82 = call i32 @processline(i32 %78, i8** %81, i8*** %5)
store i32 %82, i32* %3
br label %83
83: ; preds = %77, %56, %31, %17
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@get_next_line.str = internal global [42 x i8*] zeroinitializer
define i32 @get_next_line(i32 %0, i8** %1) {
%3 = alloca i8**
%4 = alloca [2018 x i8]
%5 = alloca i8*
store i8** %1, i8*** %3
%6 = getelementptr inbounds [2018 x i8], [2018 x i8]* %4, i64 0, i64 0
%7 = bitcast i8** %5 to i8*
%8 = icmp eq i8** %1, null
%9 = icmp ugt i32 %0, 42
%10 = or i1 %9, %8
br i1 %10, label %47, label %11
11: ; preds = %2
%12 = zext i32 %0 to i64
%13 = getelementptr inbounds [42 x i8*], [42 x i8*]* @get_next_line.str, i64 0, i64 %12
%14 = load i8*, i8** %13
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %23
16: ; preds = %11
%17 = tail call i64 @malloc(i32 2017)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %13
%19 = icmp eq i64 %17, 0
br i1 %19, label %47, label %20
20: ; preds = %16
%21 = tail call i32 @ft_bzero(i8* %18, i32 2017)
%22 = load i8*, i8** %13
br label %23
23: ; preds = %20, %11
%24 = phi i8* [ %22, %20 ], [ %14, %11 ]
%25 = call i32 @cs(i8* %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %44
27: ; preds = %23, %30
%28 = call i32 @read(i32 %0, i8* %6, i32 2017)
%29 = icmp eq i32 %28, -1
br i1 %29, label %47, label %30
30: ; preds = %27
%31 = sext i32 %28 to i64
%32 = getelementptr inbounds [2018 x i8], [2018 x i8]* %4, i64 0, i64 %31
store i8 0, i8* %32
%33 = load i8*, i8** %13
%34 = call i8* @ft_strdup(i8* %33)
store i8* %34, i8** %5
%35 = call i32 @ft_strdel(i8** %13)
%36 = load i8*, i8** %5
%37 = call i8* @ft_strjoin(i8* %36, i8* %6)
store i8* %37, i8** %13
%38 = call i32 @ft_strdel(i8** %5)
%39 = load i8*, i8** %13
%40 = call i32 @cs(i8* %39)
%41 = icmp eq i32 %40, -1
%42 = icmp ne i32 %28, 0
%43 = and i1 %42, %41
br i1 %43, label %27, label %44
44: ; preds = %30, %23
%45 = phi i32 [ 1, %23 ], [ %28, %30 ]
%46 = call i32 @processline(i32 %45, i8** %13, i8*** %3)
br label %47
47: ; preds = %27, %16, %2, %44
%48 = phi i32 [ %46, %44 ], [ -1, %2 ], [ -1, %16 ], [ -1, %27 ]
ret i32 %48
}