#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 clean_buff(int const, char **, char ***);
int /*<<< orphan*/ free(char *);
char *ft_memalloc(int);
int /*<<< orphan*/ get_buff(int const, char **, char ***);
int read(int const, char *, int);
scalar_t__ set_line(char **, char **, int *);
int get_next_line(const int fd, char **line) {
  static char *buff_storage[8192];
  char *buff;
  int size;
  if (fd >= 8192 || !line || fd < 0)
    return (-1);
  get_buff(fd, &buff, &buff_storage);
  if (read(fd, buff, 0) == -1)
    return (clean_buff(fd, &buff, &buff_storage) - 1);
  if (!(*line = ft_memalloc(1)))
    return (-1);
  size = 0;
  while (42)
    if (set_line(&buff, line, &size))
      return (1);
    else if (read(fd, buff, 32) == 0) {
      if (size == 0)
        free(*line);
      return ((size == 0) ? clean_buff(fd, &buff, &buff_storage) : 1);
    }
}


x86 assembly (clang, -O0):
<get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2000,-0x8(%rbp)
jge    1191 <get_next_line+0x31>
cmpq   $0x0,-0x10(%rbp)
je     1191 <get_next_line+0x31>
cmpl   $0x0,-0x8(%rbp)
jge    119d <get_next_line+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <get_next_line+0x151>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    0x2eb5(%rip),%rdx
call   1080 <get_buff@plt>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
xor    %edx,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    11e5 <get_next_line+0x85>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    0x2e8b(%rip),%rdx
call   1040 <clean_buff@plt>
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    12b1 <get_next_line+0x151>
mov    $0x1,%edi
call   1070 <ft_memalloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    120c <get_next_line+0xac>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b1 <get_next_line+0x151>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rdx
call   1050 <set_line@plt>
cmp    $0x0,%rax
je     123a <get_next_line+0xda>
movl   $0x1,-0x4(%rbp)
jmp    12b1 <get_next_line+0x151>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x20,%edx
call   1060 <read@plt>
cmp    $0x0,%eax
jne    12a7 <get_next_line+0x147>
cmpl   $0x0,-0x1c(%rbp)
jne    126a <get_next_line+0x10a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    128f <get_next_line+0x12f>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    0x2dde(%rip),%rdx
call   1040 <clean_buff@plt>
mov    %eax,-0x20(%rbp)
jmp    129c <get_next_line+0x13c>
mov    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    129c <get_next_line+0x13c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12b1 <get_next_line+0x151>
jmp    12ac <get_next_line+0x14c>
jmp    1213 <get_next_line+0xb3>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebp
cmp    $0x1fff,%edi
ja     124d <get_next_line+0xed>
mov    %rsi,%r14
test   %rsi,%rsi
je     124d <get_next_line+0xed>
mov    %edi,%ebx
lea    0x2ece(%rip),%rdx
lea    0x8(%rsp),%rsi
call   1080 <get_buff@plt>
mov    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     1235 <get_next_line+0xd5>
mov    $0x1,%edi
call   1070 <ft_memalloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     124d <get_next_line+0xed>
movl   $0x0,0x4(%rsp)
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
mov    $0x1,%ebp
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <set_line@plt>
test   %rax,%rax
jne    124d <get_next_line+0xed>
mov    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x20,%edx
call   1060 <read@plt>
test   %eax,%eax
jne    11e0 <get_next_line+0x80>
cmpl   $0x0,0x4(%rsp)
jne    124d <get_next_line+0xed>
mov    (%r14),%rdi
call   1030 <free@plt>
cmpl   $0x0,0x4(%rsp)
jne    124d <get_next_line+0xed>
lea    0x2e3b(%rip),%rdx
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1040 <clean_buff@plt>
mov    %eax,%ebp
jmp    124d <get_next_line+0xed>
lea    0x2e24(%rip),%rdx
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
call   1040 <clean_buff@plt>
mov    %eax,%ebp
add    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@get_next_line.buff_storage = internal global [8192 x i8*] zeroinitializer
define i32 @get_next_line(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sge i32 %8, 8192
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = icmp ne i8** %11, null
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13, %10, %2
store i32 -1, i32* %3
br label %62
17: ; preds = %13
%18 = load i32, i32* %4
%19 = call i32 @get_buff(i32 %18, i8** %6, i8*** bitcast ([8192 x i8*]* @get_next_line.buff_storage to i8***))
%20 = load i32, i32* %4
%21 = load i8*, i8** %6
%22 = call i32 @read(i32 %20, i8* %21, i32 0)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i32, i32* %4
%26 = call i32 @clean_buff(i32 %25, i8** %6, i8*** bitcast ([8192 x i8*]* @get_next_line.buff_storage to i8***))
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %3
br label %62
28: ; preds = %17
%29 = call i8* @ft_memalloc(i32 1)
%30 = load i8**, i8*** %5
store i8* %29, i8** %30
%31 = icmp ne i8* %29, null
br i1 %31, label %33, label %32
32: ; preds = %28
store i32 -1, i32* %3
br label %62
33: ; preds = %28
store i32 0, i32* %7
br label %34
34: ; preds = %33, %61
%35 = load i8**, i8*** %5
%36 = call i64 @set_line(i8** %6, i8** %35, i32* %7)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 1, i32* %3
br label %62
39: ; preds = %34
%40 = load i32, i32* %4
%41 = load i8*, i8** %6
%42 = call i32 @read(i32 %40, i8* %41, i32 32)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %60
44: ; preds = %39
%45 = load i32, i32* %7
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %51
47: ; preds = %44
%48 = load i8**, i8*** %5
%49 = load i8*, i8** %48
%50 = call i32 @free(i8* %49)
br label %51
51: ; preds = %47, %44
%52 = load i32, i32* %7
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* %4
%56 = call i32 @clean_buff(i32 %55, i8** %6, i8*** bitcast ([8192 x i8*]* @get_next_line.buff_storage to i8***))
br label %58
57: ; preds = %51
br label %58
58: ; preds = %57, %54
%59 = phi i32 [ %56, %54 ], [ 1, %57 ]
store i32 %59, i32* %3
br label %62
60: ; preds = %39
br label %61
61: ; preds = %60
br label %34
62: ; preds = %58, %38, %32, %24, %16
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@get_next_line.buff_storage = internal global [8192 x i8*] zeroinitializer
define i32 @get_next_line(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i8** %1, null
%8 = icmp ugt i32 %0, 8191
%9 = or i1 %8, %7
br i1 %9, label %39, label %10
10: ; preds = %2
%11 = call i32 @get_buff(i32 %0, i8** %3, i8*** bitcast ([8192 x i8*]* @get_next_line.buff_storage to i8***))
%12 = load i8*, i8** %3
%13 = call i32 @read(i32 %0, i8* %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = call i32 @clean_buff(i32 %0, i8** %3, i8*** bitcast ([8192 x i8*]* @get_next_line.buff_storage to i8***))
%17 = add nsw i32 %16, -1
br label %39
18: ; preds = %10
%19 = call i8* @ft_memalloc(i32 1)
store i8* %19, i8** %1
%20 = icmp eq i8* %19, null
br i1 %20, label %39, label %21
21: ; preds = %18
store i32 0, i32* %4
br label %22
22: ; preds = %25, %21
%23 = call i64 @set_line(i8** %3, i8** %1, i32* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %39
25: ; preds = %22
%26 = load i8*, i8** %3
%27 = call i32 @read(i32 %0, i8* %26, i32 32)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %22
29: ; preds = %25
%30 = load i32, i32* %4
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i8*, i8** %1
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @clean_buff(i32 %0, i8** %3, i8*** bitcast ([8192 x i8*]* @get_next_line.buff_storage to i8***))
br label %39
39: ; preds = %22, %29, %37, %32, %18, %2, %15
%40 = phi i32 [ %17, %15 ], [ -1, %2 ], [ -1, %18 ], [ %38, %37 ], [ 1, %32 ], [ 1, %29 ], [ 1, %22 ]
ret i32 %40
}