#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 ft_check_buffer(char *, int, char **);
int /*<<< orphan*/ ft_strclr(char *);
scalar_t__ ft_strlen(char *);
char *ft_strnew(int);
int read(int const, char *, int);
int get_next_line(int const fd, char **line) {
  static char buffer[256 + 1];
  static int cursor;
  static int end;
  int status;
  if (*line)
    ft_strclr(*line);
  else
    *line = ft_strnew(1);
  cursor = ft_check_buffer(buffer, cursor, line);
  if (cursor >= 0)
    return (1);
  while ((status = read(fd, buffer, 256)) > 0) {
    cursor = 0;
    cursor = ft_check_buffer(buffer, cursor, line);
    if (cursor >= 0)
      return (1);
  }
  if (!end && ft_strlen(*line)) {
    end = 1;
    return (1);
  }
  return (status);
}


x86 assembly (clang, -O0):
<get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     117e <get_next_line+0x2e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <ft_strclr@plt>
jmp    1192 <get_next_line+0x42>
mov    $0x1,%edi
call   1060 <ft_strnew@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2fcc(%rip),%esi
mov    -0x10(%rbp),%rdx
lea    0x2ebd(%rip),%rdi
call   1070 <ft_check_buffer@plt>
mov    %eax,0x2fb6(%rip)
cmpl   $0x0,0x2faf(%rip)
jl     11c7 <get_next_line+0x77>
movl   $0x1,-0x4(%rbp)
jmp    126f <get_next_line+0x11f>
jmp    11cc <get_next_line+0x7c>
mov    -0x8(%rbp),%edi
lea    0x2e8a(%rip),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1230 <get_next_line+0xe0>
movl   $0x0,0x2f6e(%rip)
mov    0x2f68(%rip),%esi
mov    -0x10(%rbp),%rdx
lea    0x2e59(%rip),%rdi
call   1070 <ft_check_buffer@plt>
mov    %eax,0x2f52(%rip)
cmpl   $0x0,0x2f4b(%rip)
jl     122b <get_next_line+0xdb>
movl   $0x1,-0x4(%rbp)
jmp    126f <get_next_line+0x11f>
jmp    11cc <get_next_line+0x7c>
cmpl   $0x0,0x2f31(%rip)
jne    1269 <get_next_line+0x119>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <ft_strlen@plt>
cmp    $0x0,%rax
je     1269 <get_next_line+0x119>
movl   $0x1,0x2f0b(%rip)
movl   $0x1,-0x4(%rbp)
jmp    126f <get_next_line+0x11f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%r14d
mov    (%rsi),%rdi
test   %rdi,%rdi
je     116c <get_next_line+0x1c>
call   1030 <ft_strclr@plt>
jmp    1179 <get_next_line+0x29>
mov    $0x1,%edi
call   1060 <ft_strnew@plt>
mov    %rax,(%r15)
mov    0x2fe5(%rip),%esi
lea    0x2eda(%rip),%rdi
mov    %r15,%rdx
call   1070 <ft_check_buffer@plt>
mov    %eax,0x2fd0(%rip)
test   %eax,%eax
jns    11f6 <get_next_line+0xa6>
lea    0x2ec1(%rip),%rbx
nop
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    11d7 <get_next_line+0x87>
movl   $0x0,0x2fa6(%rip)
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1070 <ft_check_buffer@plt>
mov    %eax,0x2f93(%rip)
test   %eax,%eax
js     11a0 <get_next_line+0x50>
jmp    11f6 <get_next_line+0xa6>
mov    %eax,%ebp
cmpb   $0x0,0x2f88(%rip)
jne    11fb <get_next_line+0xab>
mov    (%r15),%rdi
call   1040 <ft_strlen@plt>
test   %rax,%rax
je     11fb <get_next_line+0xab>
movb   $0x1,0x2f72(%rip)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@get_next_line.buffer = internal global [257 x i8] zeroinitializer
@get_next_line.cursor = internal unnamed_addr global i32 0
@get_next_line.end = internal unnamed_addr global i1 false
define i32 @get_next_line(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @ft_strclr(i8* %3)
br label %9
7: ; preds = %2
%8 = tail call i8* @ft_strnew(i32 1)
store i8* %8, i8** %1
br label %9
9: ; preds = %7, %5
%10 = load i32, i32* @get_next_line.cursor
%11 = tail call i32 @ft_check_buffer(i8* getelementptr inbounds ([257 x i8], [257 x i8]* @get_next_line.buffer, i64 0, i64 0), i32 %10, i8** %1)
store i32 %11, i32* @get_next_line.cursor
%12 = icmp sgt i32 %11, -1
br i1 %12, label %26, label %13
13: ; preds = %9, %16
%14 = tail call i32 @read(i32 %0, i8* getelementptr inbounds ([257 x i8], [257 x i8]* @get_next_line.buffer, i64 0, i64 0), i32 256)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
store i32 0, i32* @get_next_line.cursor
%17 = tail call i32 @ft_check_buffer(i8* getelementptr inbounds ([257 x i8], [257 x i8]* @get_next_line.buffer, i64 0, i64 0), i32 0, i8** %1)
store i32 %17, i32* @get_next_line.cursor
%18 = icmp sgt i32 %17, -1
br i1 %18, label %26, label %13
19: ; preds = %13
%20 = load i1, i1* @get_next_line.end
br i1 %20, label %26, label %21
21: ; preds = %19
%22 = load i8*, i8** %1
%23 = tail call i64 @ft_strlen(i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21
store i1 true, i1* @get_next_line.end
br label %26
26: ; preds = %16, %19, %21, %9, %25
%27 = phi i32 [ 1, %25 ], [ 1, %9 ], [ %14, %21 ], [ %14, %19 ], [ 1, %16 ]
ret i32 %27
}