#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__ find_newline(char **, char **);
int /*<<< orphan*/ ft_bzero(char *, int);
scalar_t__ ft_strlen(char *);
char *ft_strnew(int /*<<< orphan*/);
int /*<<< orphan*/ load_line(char **, char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ push_buf(char **, char *);
int read(int const, char *, int);
int get_next_line(int const fd, char **line) {
  static char *remaining = NULL;
  char buf[512 + 1];
  int read_status;
  if (fd < 1 || !line)
    return (-1);
  ft_bzero(buf, 512 + 1);
  if (find_newline(line, &remaining))
    return (1);
  else if ((read_status = read(fd, buf, 512)) <= 0) {
    if (ft_strlen(remaining) > 0)
      load_line(line, &remaining, NULL);
    return (read_status);
  } else if (!remaining)
    remaining = ft_strnew(0);
  push_buf(&remaining, buf);
  return (get_next_line(fd, line));
}


x86 assembly (clang, -O0):
<get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jl     11a7 <get_next_line+0x27>
cmpq   $0x0,-0x10(%rbp)
jne    11b3 <get_next_line+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    128d <get_next_line+0x10d>
lea    -0x220(%rbp),%rdi
mov    $0x201,%esi
call   1030 <ft_bzero@plt>
mov    -0x10(%rbp),%rdi
lea    0x2e99(%rip),%rsi
call   1080 <find_newline@plt>
cmp    $0x0,%rax
je     11ea <get_next_line+0x6a>
movl   $0x1,-0x4(%rbp)
jmp    128d <get_next_line+0x10d>
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %eax,-0x224(%rbp)
cmp    $0x0,%eax
jg     1245 <get_next_line+0xc5>
mov    0x2e54(%rip),%rdi
call   1040 <ft_strlen@plt>
cmp    $0x0,%rax
jle    1237 <get_next_line+0xb7>
mov    -0x10(%rbp),%rdi
lea    0x2e3a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1090 <load_line@plt>
mov    -0x224(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128d <get_next_line+0x10d>
cmpq   $0x0,0x2e1b(%rip)
jne    1261 <get_next_line+0xe1>
xor    %edi,%edi
call   1060 <ft_strnew@plt>
mov    %rax,0x2e07(%rip)
jmp    1266 <get_next_line+0xe6>
jmp    126b <get_next_line+0xeb>
lea    -0x220(%rbp),%rsi
lea    0x2def(%rip),%rdi
call   1070 <push_buf@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10a0 <get_next_line@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r14
push   %rbx
sub    $0x210,%rsp
mov    $0xffffffff,%ebx
test   %edi,%edi
jle    1233 <get_next_line+0xb3>
mov    %rsi,%r14
test   %rsi,%rsi
je     1233 <get_next_line+0xb3>
mov    %edi,%ebp
mov    %rsp,%rdi
mov    $0x201,%esi
call   1030 <ft_bzero@plt>
lea    0x2eae(%rip),%rsi
mov    %r14,%rdi
call   1080 <find_newline@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1233 <get_next_line+0xb3>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x200,%edx
call   1050 <read@plt>
mov    0x2e86(%rip),%rdi
test   %eax,%eax
jle    1216 <get_next_line+0x96>
test   %rdi,%rdi
jne    11f9 <get_next_line+0x79>
xor    %edi,%edi
call   1060 <ft_strnew@plt>
mov    %rax,0x2e6f(%rip)
lea    0x2e68(%rip),%rdi
mov    %rsp,%rsi
call   1070 <push_buf@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   10a0 <get_next_line@plt>
mov    %eax,%ebx
jmp    1233 <get_next_line+0xb3>
mov    %eax,%ebx
call   1040 <ft_strlen@plt>
test   %rax,%rax
jle    1233 <get_next_line+0xb3>
lea    0x2e3f(%rip),%rsi
mov    %r14,%rdi
xor    %edx,%edx
call   1090 <load_line@plt>
mov    %ebx,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@get_next_line.remaining = internal global i8* null
define i32 @get_next_line(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [513 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = icmp ne i8** %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 -1, i32* %3
br label %48
14: ; preds = %10
%15 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%16 = call i32 @ft_bzero(i8* %15, i32 513)
%17 = load i8**, i8*** %5
%18 = call i64 @find_newline(i8** %17, i8** @get_next_line.remaining)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 1, i32* %3
br label %48
21: ; preds = %14
%22 = load i32, i32* %4
%23 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%24 = call i32 @read(i32 %22, i8* %23, i32 512)
store i32 %24, i32* %7
%25 = icmp sle i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %21
%27 = load i8*, i8** @get_next_line.remaining
%28 = call i64 @ft_strlen(i8* %27)
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = call i32 @load_line(i8** %31, i8** @get_next_line.remaining, i32* null)
br label %33
33: ; preds = %30, %26
%34 = load i32, i32* %7
store i32 %34, i32* %3
br label %48
35: ; preds = %21
%36 = load i8*, i8** @get_next_line.remaining
%37 = icmp ne i8* %36, null
br i1 %37, label %40, label %38
38: ; preds = %35
%39 = call i8* @ft_strnew(i32 0)
store i8* %39, i8** @get_next_line.remaining
br label %40
40: ; preds = %38, %35
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41
%43 = getelementptr inbounds [513 x i8], [513 x i8]* %6, i64 0, i64 0
%44 = call i32 @push_buf(i8** @get_next_line.remaining, i8* %43)
%45 = load i32, i32* %4
%46 = load i8**, i8*** %5
%47 = call i32 @get_next_line(i32 %45, i8** %46)
store i32 %47, i32* %3
br label %48
48: ; preds = %42, %33, %20, %13
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@get_next_line.remaining = internal global i8* null
define i32 @get_next_line(i32 %0, i8** %1) {
%3 = alloca [513 x i8]
%4 = getelementptr inbounds [513 x i8], [513 x i8]* %3, i64 0, i64 0
%5 = icmp sgt i32 %0, 0
%6 = icmp ne i8** %1, null
%7 = and i1 %5, %6
br i1 %7, label %8, label %28
8: ; preds = %2
%9 = call i32 @ft_bzero(i8* %4, i32 513)
%10 = call i64 @find_newline(i8** %1, i8** @get_next_line.remaining)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %8
%13 = call i32 @read(i32 %0, i8* %4, i32 512)
%14 = icmp slt i32 %13, 1
%15 = load i8*, i8** @get_next_line.remaining
br i1 %14, label %16, label %21
16: ; preds = %12
%17 = call i64 @ft_strlen(i8* %15)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %16
%20 = call i32 @load_line(i8** %1, i8** @get_next_line.remaining, i32* null)
br label %28
21: ; preds = %12
%22 = icmp eq i8* %15, null
br i1 %22, label %23, label %25
23: ; preds = %21
%24 = call i8* @ft_strnew(i32 0)
store i8* %24, i8** @get_next_line.remaining
br label %25
25: ; preds = %23, %21
%26 = call i32 @push_buf(i8** @get_next_line.remaining, i8* %4)
%27 = call i32 @get_next_line(i32 %0, i8** %1)
br label %28
28: ; preds = %16, %19, %8, %2, %25
%29 = phi i32 [ %27, %25 ], [ -1, %2 ], [ 1, %8 ], [ %13, %19 ], [ %13, %16 ]
ret i32 %29
}