#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 */
char *ft_strdup(char *);
int ft_strlen(char *);
scalar_t__ get_part(char **, char **);
int /*<<< orphan*/ malloc_more(char **, int);
int read(int const, char *, int);
int get_next_line(int const fd, char **line) {
  static char *buf = NULL;
  int ret;
  int i;
  i = 0;
  if (buf == NULL)
    buf = ft_strdup("");
  if (get_part(&buf, line))
    return (1);
  i = ft_strlen(buf);
  malloc_more(&buf, 8);
  ret = read(fd, buf + i, 8);
  if (ret == -1)
    return (-1);
  buf[i + ret] = '\0';
  if (ret != 0)
    return (get_next_line(fd, line));
  if (*buf == '\0')
    return (0);
  *line = ft_strdup(buf);
  buf = ft_strdup(buf + i + ret);
  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)
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,0x2eda(%rip)
jne    1197 <get_next_line+0x37>
lea    0xe75(%rip),%rdi
call   1060 <ft_strdup@plt>
mov    %rax,0x2ec1(%rip)
mov    -0x10(%rbp),%rsi
lea    0x2eb6(%rip),%rdi
call   1040 <get_part@plt>
cmp    $0x0,%rax
je     11bd <get_next_line+0x5d>
movl   $0x1,-0x4(%rbp)
jmp    12a0 <get_next_line+0x140>
mov    0x2e94(%rip),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,-0x18(%rbp)
lea    0x2e85(%rip),%rdi
mov    $0x8,%esi
call   1070 <malloc_more@plt>
mov    -0x8(%rbp),%edi
mov    0x2e71(%rip),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    $0x8,%edx
call   1050 <read@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1211 <get_next_line+0xb1>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a0 <get_next_line+0x140>
mov    0x2e40(%rip),%rax
mov    -0x18(%rbp),%ecx
add    -0x14(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x14(%rbp)
je     1243 <get_next_line+0xe3>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1080 <get_next_line@plt>
mov    %eax,-0x4(%rbp)
jmp    12a0 <get_next_line+0x140>
mov    0x2e0e(%rip),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1262 <get_next_line+0x102>
movl   $0x0,-0x4(%rbp)
jmp    12a0 <get_next_line+0x140>
mov    0x2def(%rip),%rdi
call   1060 <ft_strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2dd9(%rip),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1060 <ft_strdup@plt>
mov    %rax,0x2dbf(%rip)
movl   $0x1,-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   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r13d
lea    0x2ee8(%rip),%r12
mov    $0x1,%ebp
nopl   (%rax)
cmpq   $0x0,0x2ed8(%rip)
jne    118d <get_next_line+0x3d>
lea    0xe7f(%rip),%rdi
call   1060 <ft_strdup@plt>
mov    %rax,0x2ec3(%rip)
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <get_part@plt>
test   %rax,%rax
jne    122a <get_next_line+0xda>
mov    0x2ea8(%rip),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%r15d
mov    %r12,%rdi
mov    $0x8,%esi
call   1070 <malloc_more@plt>
movslq %r15d,%rbx
mov    0x2e89(%rip),%rsi
add    %rbx,%rsi
mov    %r13d,%edi
mov    $0x8,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     1221 <get_next_line+0xd1>
mov    0x2e6d(%rip),%rcx
add    %eax,%r15d
movslq %r15d,%rdx
movb   $0x0,(%rcx,%rdx,1)
test   %eax,%eax
jne    1170 <get_next_line+0x20>
mov    0x2e54(%rip),%rdi
cmpb   $0x0,(%rdi)
je     1228 <get_next_line+0xd8>
call   1060 <ft_strdup@plt>
mov    %rax,(%r14)
add    0x2e40(%rip),%rbx
mov    %rbx,%rdi
call   1060 <ft_strdup@plt>
mov    %rax,0x2e31(%rip)
jmp    122a <get_next_line+0xda>
mov    $0xffffffff,%ebp
jmp    122a <get_next_line+0xda>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@get_next_line.buf = internal global i8* null
@.str = [1 x i8] zeroinitializer
define i32 @get_next_line(i32 %0, i8** %1) {
br label %3
3: ; preds = %20, %2
%4 = load i8*, i8** @get_next_line.buf
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i8* @ft_strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** @get_next_line.buf
br label %8
8: ; preds = %6, %3
%9 = tail call i64 @get_part(i8** @get_next_line.buf, i8** %1)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %35
11: ; preds = %8
%12 = load i8*, i8** @get_next_line.buf
%13 = tail call i32 @ft_strlen(i8* %12)
%14 = tail call i32 @malloc_more(i8** @get_next_line.buf, i32 8)
%15 = load i8*, i8** @get_next_line.buf
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds i8, i8* %15, i64 %16
%18 = tail call i32 @read(i32 %0, i8* %17, i32 8)
%19 = icmp eq i32 %18, -1
br i1 %19, label %35, label %20
20: ; preds = %11
%21 = load i8*, i8** @get_next_line.buf
%22 = add nsw i32 %18, %13
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
%25 = icmp eq i32 %18, 0
br i1 %25, label %26, label %3
26: ; preds = %20
%27 = load i8*, i8** @get_next_line.buf
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %26
%31 = tail call i8* @ft_strdup(i8* %27)
store i8* %31, i8** %1
%32 = load i8*, i8** @get_next_line.buf
%33 = getelementptr inbounds i8, i8* %32, i64 %16
%34 = tail call i8* @ft_strdup(i8* %33)
store i8* %34, i8** @get_next_line.buf
br label %35
35: ; preds = %11, %8, %26, %30
%36 = phi i32 [ 1, %30 ], [ 0, %26 ], [ -1, %11 ], [ 1, %8 ]
ret i32 %36
}