#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 /*<<< orphan*/ free(char *);
int /*<<< orphan*/ ft_strchr(char *, char);
int gnl_read_and_save(int const, char **);
int gnl_set_line(char **, char **);
int ft_get_next_line(const int fd, char **line) {
  static char *rbak = NULL;
  int res;
  res = 1;
  if (rbak == NULL)
    res = gnl_read_and_save(fd, &rbak);
  else if (!(ft_strchr(rbak, '\n')))
    res = gnl_read_and_save(fd, &rbak);
  if (rbak != NULL || res >= 0)
    res = gnl_set_line(&rbak, line);
  if (res < 1) {
    if (rbak)
      free(rbak);
    return (res);
  }
  return (res);
}


x86 assembly (clang, -O0):
<ft_get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpq   $0x0,0x2eea(%rip)
jne    117b <ft_get_next_line+0x3b>
mov    -0x8(%rbp),%edi
lea    0x2eda(%rip),%rsi
call   1050 <gnl_read_and_save@plt>
mov    %eax,-0x14(%rbp)
jmp    11ac <ft_get_next_line+0x6c>
mov    0x2ec6(%rip),%rdi
mov    $0xa,%esi
call   1060 <ft_strchr@plt>
cmp    $0x0,%eax
jne    11a7 <ft_get_next_line+0x67>
mov    -0x8(%rbp),%edi
lea    0x2ea9(%rip),%rsi
call   1050 <gnl_read_and_save@plt>
mov    %eax,-0x14(%rbp)
jmp    11ac <ft_get_next_line+0x6c>
cmpq   $0x0,0x2e94(%rip)
jne    11c4 <ft_get_next_line+0x84>
cmpl   $0x0,-0x14(%rbp)
jl     11d7 <ft_get_next_line+0x97>
mov    -0x10(%rbp),%rsi
lea    0x2e79(%rip),%rdi
call   1030 <gnl_set_line@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1206 <ft_get_next_line+0xc6>
cmpq   $0x0,0x2e5f(%rip)
je     11fb <ft_get_next_line+0xbb>
mov    0x2e52(%rip),%rdi
call   1040 <free@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    120c <ft_get_next_line+0xcc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_get_next_line>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2ef9(%rip),%rdi
test   %rdi,%rdi
je     1162 <ft_get_next_line+0x22>
mov    $0xa,%esi
call   1060 <ft_strchr@plt>
test   %eax,%eax
jne    1180 <ft_get_next_line+0x40>
lea    0x2edf(%rip),%rsi
mov    %ebp,%edi
call   1050 <gnl_read_and_save@plt>
cmpq   $0x0,0x2ed0(%rip)
jne    1180 <ft_get_next_line+0x40>
mov    %eax,%ebp
test   %eax,%eax
js     11a6 <ft_get_next_line+0x66>
lea    0x2ec1(%rip),%rdi
mov    %rbx,%rsi
call   1030 <gnl_set_line@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     11a6 <ft_get_next_line+0x66>
mov    0x2eac(%rip),%rdi
test   %rdi,%rdi
je     11a6 <ft_get_next_line+0x66>
call   1040 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@ft_get_next_line.rbak = internal global i8* null
define i32 @ft_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
store i32 1, i32* %6
%7 = load i8*, i8** @ft_get_next_line.rbak
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* %4
%11 = call i32 @gnl_read_and_save(i32 %10, i8** @ft_get_next_line.rbak)
store i32 %11, i32* %6
br label %20
12: ; preds = %2
%13 = load i8*, i8** @ft_get_next_line.rbak
%14 = call i32 @ft_strchr(i8* %13, i8 signext 10)
%15 = icmp ne i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 @gnl_read_and_save(i32 %17, i8** @ft_get_next_line.rbak)
store i32 %18, i32* %6
br label %19
19: ; preds = %16, %12
br label %20
20: ; preds = %19, %9
%21 = load i8*, i8** @ft_get_next_line.rbak
%22 = icmp ne i8* %21, null
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %6
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23, %20
%27 = load i8**, i8*** %5
%28 = call i32 @gnl_set_line(i8** @ft_get_next_line.rbak, i8** %27)
store i32 %28, i32* %6
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* %6
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %40
32: ; preds = %29
%33 = load i8*, i8** @ft_get_next_line.rbak
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** @ft_get_next_line.rbak
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %35, %32
%39 = load i32, i32* %6
store i32 %39, i32* %3
br label %42
40: ; preds = %29
%41 = load i32, i32* %6
store i32 %41, i32* %3
br label %42
42: ; preds = %40, %38
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@ft_get_next_line.rbak = internal global i8* null
define i32 @ft_get_next_line(i32 %0, i8** %1) {
%3 = load i8*, i8** @ft_get_next_line.rbak
%4 = icmp eq i8* %3, null
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @ft_strchr(i8* %3, i8 signext 10)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %5, %2
%9 = tail call i32 @gnl_read_and_save(i32 %0, i8** @ft_get_next_line.rbak)
%10 = load i8*, i8** @ft_get_next_line.rbak
%11 = icmp ne i8* %10, null
%12 = icmp sgt i32 %9, -1
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %14, label %22
14: ; preds = %5, %8
%15 = tail call i32 @gnl_set_line(i8** @ft_get_next_line.rbak, i8** %1)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = load i8*, i8** @ft_get_next_line.rbak
%19 = icmp eq i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @free(i8* %18)
br label %22
22: ; preds = %8, %14, %17, %20
%23 = phi i32 [ %15, %14 ], [ %15, %17 ], [ %15, %20 ], [ %9, %8 ]
ret i32 %23
}