#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__ ft_check_line(char *);
int ft_cp_buff(char **, char *);
int ft_init_line(char **);
int ft_read_txt(int const, char **, char *);
scalar_t__ ft_strlen(char *);
int get_next_line(int const fd, char **line) {
  int ret;
  static char buff[32 + 1];
  ret = ft_init_line(line);
  if (ret == -1)
    return (-1);
  if (ft_strlen(buff)) {
    ret = ft_cp_buff(line, buff);
    if (ret == -1)
      return (-1);
    if (ft_check_line(buff))
      return (1);
  }
  ret = ft_read_txt(fd, line, buff);
  if (ret == -1)
    return (-1);
  else if (ret == 0)
    return (0);
  else
    return (1);
}


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),%rdi
call   1060 <ft_init_line@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1181 <get_next_line+0x31>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <get_next_line+0xe0>
lea    0x2ed8(%rip),%rdi
call   1030 <ft_strlen@plt>
cmp    $0x0,%rax
je     11e7 <get_next_line+0x97>
mov    -0x10(%rbp),%rdi
lea    0x2ebe(%rip),%rsi
call   1070 <ft_cp_buff@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c0 <get_next_line+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <get_next_line+0xe0>
lea    0x2e99(%rip),%rdi
call   1040 <ft_check_line@plt>
cmp    $0x0,%rax
je     11e2 <get_next_line+0x92>
movl   $0x1,-0x4(%rbp)
jmp    1230 <get_next_line+0xe0>
jmp    11e7 <get_next_line+0x97>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0x2e6b(%rip),%rdx
call   1050 <ft_read_txt@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1213 <get_next_line+0xc3>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <get_next_line+0xe0>
cmpl   $0x0,-0x14(%rbp)
jne    1229 <get_next_line+0xd9>
movl   $0x0,-0x4(%rbp)
jmp    1230 <get_next_line+0xe0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1060 <ft_init_line@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11c7 <get_next_line+0x77>
lea    0x2eed(%rip),%rdi
call   1030 <ft_strlen@plt>
test   %rax,%rax
je     11a7 <get_next_line+0x57>
lea    0x2edc(%rip),%rsi
mov    %rbx,%rdi
call   1070 <ft_cp_buff@plt>
cmp    $0xffffffff,%eax
je     11c7 <get_next_line+0x77>
lea    0x2ec8(%rip),%rdi
call   1040 <ft_check_line@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11c7 <get_next_line+0x77>
lea    0x2eb2(%rip),%rdx
mov    %r14d,%edi
mov    %rbx,%rsi
call   1050 <ft_read_txt@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
cmp    $0xffffffff,%eax
cmove  %eax,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@get_next_line.buff = internal global [33 x i8] zeroinitializer
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 = call i32 @ft_init_line(i8** %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %38
12: ; preds = %2
%13 = call i64 @ft_strlen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @get_next_line.buff, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i8**, i8*** %5
%17 = call i32 @ft_cp_buff(i8** %16, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @get_next_line.buff, i64 0, i64 0))
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 -1, i32* %3
br label %38
21: ; preds = %15
%22 = call i64 @ft_check_line(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @get_next_line.buff, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 1, i32* %3
br label %38
25: ; preds = %21
br label %26
26: ; preds = %25, %12
%27 = load i32, i32* %4
%28 = load i8**, i8*** %5
%29 = call i32 @ft_read_txt(i32 %27, i8** %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @get_next_line.buff, i64 0, i64 0))
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 -1, i32* %3
br label %38
33: ; preds = %26
%34 = load i32, i32* %6
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %33
store i32 0, i32* %3
br label %38
37: ; preds = %33
store i32 1, i32* %3
br label %38
38: ; preds = %37, %36, %32, %24, %20, %11
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@get_next_line.buff = internal global [33 x i8] zeroinitializer
define i32 @get_next_line(i32 %0, i8** %1) {
%3 = tail call i32 @ft_init_line(i8** %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = tail call i64 @ft_strlen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @get_next_line.buff, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = tail call i32 @ft_cp_buff(i8** %1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @get_next_line.buff, i64 0, i64 0))
%10 = icmp eq i32 %9, -1
br i1 %10, label %20, label %11
11: ; preds = %8
%12 = tail call i64 @ft_check_line(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @get_next_line.buff, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %11, %5
%15 = tail call i32 @ft_read_txt(i32 %0, i8** %1, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @get_next_line.buff, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i32
%18 = icmp eq i32 %15, -1
%19 = select i1 %18, i32 -1, i32 %17
br label %20
20: ; preds = %14, %11, %8, %2
%21 = phi i32 [ -1, %2 ], [ -1, %8 ], [ 1, %11 ], [ %19, %14 ]
ret i32 %21
}