#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 */
typedef size_t ssize_t;

/* Variables and functions */
char *ft_find(char *, size_t);
int get_line(char **, char *, char **, size_t *);
int /*<<< orphan*/ last_ret(int, size_t);
int /*<<< orphan*/ merge(char **, char *, size_t, size_t *);
size_t read(int, char *, int);
int ft_getnextline(int fd, char **line) {
  static char *buff = NULL;
  static size_t bsize = 0;
  char buf[1024 + 1];
  char *find;
  ssize_t ret;
  while (1) {
    if ((find = ft_find(buff, bsize)))
      return (get_line(&buff, find, line, &bsize));
    if ((ret = read(fd, buf, 1024)) == 0 && buff) {
      last_ret(1, 0);
      return (get_line(&buff, buff + bsize, line, &bsize));
    } else if (ret > 0) {
      last_ret(1, ret);
      buf[ret] = 0;
      merge(&buff, buf, ret, &bsize);
    } else
      return ((!ret) ? 0 : -1);
  }
}


x86 assembly (clang, -O0):
<ft_getnextline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2ee7(%rip),%rdi
mov    0x2ee8(%rip),%rsi
call   1070 <ft_find@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
je     11ac <ft_getnextline+0x5c>
mov    -0x428(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0x2eb8(%rip),%rdi
lea    0x2eb9(%rip),%rcx
call   1030 <get_line@plt>
mov    %eax,-0x4(%rbp)
jmp    129b <ft_getnextline+0x14b>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
jne    121a <ft_getnextline+0xca>
cmpq   $0x0,0x2e77(%rip)
je     121a <ft_getnextline+0xca>
mov    $0x1,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <last_ret@plt>
mov    0x2e5c(%rip),%rsi
add    0x2e5d(%rip),%rsi
mov    -0x10(%rbp),%rdx
lea    0x2e4a(%rip),%rdi
lea    0x2e4b(%rip),%rcx
call   1030 <get_line@plt>
mov    %eax,-0x4(%rbp)
jmp    129b <ft_getnextline+0x14b>
cmpq   $0x0,-0x430(%rbp)
jbe    126e <ft_getnextline+0x11e>
mov    -0x430(%rbp),%rsi
mov    $0x1,%edi
call   1050 <last_ret@plt>
mov    -0x430(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
mov    -0x430(%rbp),%rdx
lea    0x2df3(%rip),%rdi
lea    0x2df4(%rip),%rcx
call   1060 <merge@plt>
jmp    1291 <ft_getnextline+0x141>
cmpq   $0x0,-0x430(%rbp)
setne  %dl
xor    $0xff,%dl
mov    $0xffffffff,%eax
xor    %ecx,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    129b <ft_getnextline+0x14b>
jmp    1296 <ft_getnextline+0x146>
jmp    1162 <ft_getnextline+0x12>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_getnextline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2ee3(%rip),%rdi
mov    0x2ee4(%rip),%rsi
call   1070 <ft_find@plt>
test   %rax,%rax
je     11a9 <ft_getnextline+0x59>
lea    0x2ecb(%rip),%rdi
lea    0x2ecc(%rip),%rcx
mov    %rax,%rsi
mov    %r14,%rdx
call   1030 <get_line@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r13
lea    0x2e9d(%rip),%r15
lea    0x2e9e(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r13,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11e1 <ft_getnextline+0x91>
cmpq   $0x0,0x2e71(%rip)
jne    1225 <ft_getnextline+0xd5>
test   %rbx,%rbx
je     1252 <ft_getnextline+0x102>
mov    $0x1,%edi
mov    %rbx,%rsi
call   1050 <last_ret@plt>
movb   $0x0,(%rsp,%rbx,1)
mov    %r15,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1060 <merge@plt>
mov    0x2e41(%rip),%rdi
mov    0x2e42(%rip),%rsi
call   1070 <ft_find@plt>
test   %rax,%rax
je     11c0 <ft_getnextline+0x70>
jmp    117e <ft_getnextline+0x2e>
mov    $0x1,%edi
xor    %esi,%esi
call   1050 <last_ret@plt>
lea    0x2e18(%rip),%rdi
mov    0x2e11(%rip),%rsi
lea    0x2e12(%rip),%rcx
add    0x2e0b(%rip),%rsi
jmp    118f <ft_getnextline+0x3f>
xor    %eax,%eax
jmp    1197 <ft_getnextline+0x47>

LLVM IR (-O0):
@ft_getnextline.buff = internal global i8* null
@ft_getnextline.bsize = internal global i64 0
define i32 @ft_getnextline(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1025 x i8]
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %2, %51
%10 = load i8*, i8** @ft_getnextline.buff
%11 = load i64, i64* @ft_getnextline.bsize
%12 = call i8* @ft_find(i8* %10, i64 %11)
store i8* %12, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i8*, i8** %7
%16 = load i8**, i8*** %5
%17 = call i32 @get_line(i8** @ft_getnextline.buff, i8* %15, i8** %16, i64* @ft_getnextline.bsize)
store i32 %17, i32* %3
br label %52
18: ; preds = %9
%19 = load i32, i32* %4
%20 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%21 = call i64 @read(i32 %19, i8* %20, i32 1024)
store i64 %21, i64* %8
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %18
%24 = load i8*, i8** @ft_getnextline.buff
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = call i32 @last_ret(i32 1, i64 0)
%28 = load i8*, i8** @ft_getnextline.buff
%29 = load i64, i64* @ft_getnextline.bsize
%30 = getelementptr inbounds i8, i8* %28, i64 %29
%31 = load i8**, i8*** %5
%32 = call i32 @get_line(i8** @ft_getnextline.buff, i8* %30, i8** %31, i64* @ft_getnextline.bsize)
store i32 %32, i32* %3
br label %52
33: ; preds = %23, %18
%34 = load i64, i64* %8
%35 = icmp ugt i64 %34, 0
br i1 %35, label %36, label %44
36: ; preds = %33
%37 = load i64, i64* %8
%38 = call i32 @last_ret(i32 1, i64 %37)
%39 = load i64, i64* %8
%40 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 %39
store i8 0, i8* %40
%41 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%42 = load i64, i64* %8
%43 = call i32 @merge(i8** @ft_getnextline.buff, i8* %41, i64 %42, i64* @ft_getnextline.bsize)
br label %50
44: ; preds = %33
%45 = load i64, i64* %8
%46 = icmp ne i64 %45, 0
%47 = xor i1 %46, true
%48 = zext i1 %47 to i64
%49 = select i1 %47, i32 0, i32 -1
store i32 %49, i32* %3
br label %52
50: ; preds = %36
br label %51
51: ; preds = %50
br label %9
52: ; preds = %44, %26, %14
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@ft_getnextline.buff = internal global i8* null
@ft_getnextline.bsize = internal global i64 0
define i32 @ft_getnextline(i32 %0, i8** %1) {
%3 = alloca [1025 x i8]
%4 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%5 = load i8*, i8** @ft_getnextline.buff
%6 = load i64, i64* @ft_getnextline.bsize
%7 = call i8* @ft_find(i8* %5, i64 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %12, label %9
9: ; preds = %25, %2
%10 = phi i8* [ %7, %2 ], [ %31, %25 ]
%11 = call i32 @get_line(i8** @ft_getnextline.buff, i8* %10, i8** %1, i64* @ft_getnextline.bsize)
br label %33
12: ; preds = %2, %25
%13 = call i64 @read(i32 %0, i8* %4, i32 1024)
%14 = icmp eq i64 %13, 0
%15 = load i8*, i8** @ft_getnextline.buff
%16 = icmp ne i8* %15, null
%17 = select i1 %14, i1 %16, i1 false
br i1 %17, label %18, label %24
18: ; preds = %12
%19 = call i32 @last_ret(i32 1, i64 0)
%20 = load i8*, i8** @ft_getnextline.buff
%21 = load i64, i64* @ft_getnextline.bsize
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = call i32 @get_line(i8** @ft_getnextline.buff, i8* %22, i8** %1, i64* @ft_getnextline.bsize)
br label %33
24: ; preds = %12
br i1 %14, label %33, label %25
25: ; preds = %24
%26 = call i32 @last_ret(i32 1, i64 %13)
%27 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %27
%28 = call i32 @merge(i8** @ft_getnextline.buff, i8* %4, i64 %13, i64* @ft_getnextline.bsize)
%29 = load i8*, i8** @ft_getnextline.buff
%30 = load i64, i64* @ft_getnextline.bsize
%31 = call i8* @ft_find(i8* %29, i64 %30)
%32 = icmp eq i8* %31, null
br i1 %32, label %12, label %9
33: ; preds = %24, %18, %9
%34 = phi i32 [ %11, %9 ], [ %23, %18 ], [ 0, %24 ]
ret i32 %34
}