#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);
char *ft_strdup(char *);
char *ft_strjoin(char *, char *);
char *ft_strnew(int);
int read(int, char *, int);
int read_next_line(char **n_ret, int fd) {
  char *buf;
  int nb_read;
  char *temp;
  buf = ft_strnew(10);
  nb_read = 10;
  while (ft_strchr(*n_ret, '\n') == NULL && nb_read == 10) {
    if ((nb_read = read(fd, buf, 10)) == -1)
      return (-1);
    buf[nb_read] = '\0';
    temp = ft_strjoin(*n_ret, buf);
    free(*n_ret);
    *n_ret = ft_strdup(temp);
    free(temp);
  }
  free(buf);
  return (nb_read);
}


x86 assembly (clang, -O0):
<read_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0xa,%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x20(%rbp)
movl   $0xa,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0xa,%esi
call   1070 <ft_strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x31(%rbp)
jne    11b1 <read_next_line+0x51>
cmpl   $0xa,-0x24(%rbp)
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11c1 <read_next_line+0x61>
jmp    1237 <read_next_line+0xd7>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <read@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11ea <read_next_line+0x8a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1246 <read_next_line+0xe6>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <ft_strjoin@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1060 <ft_strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    1184 <read_next_line+0x24>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_next_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r12
mov    $0xa,%ebx
mov    $0xa,%edi
call   1050 <ft_strnew@plt>
mov    %rax,%r15
mov    (%r12),%rdi
mov    $0xa,%esi
call   1070 <ft_strchr@plt>
xchg   %ax,%ax
test   %rax,%rax
jne    11f2 <read_next_line+0x92>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     11fc <read_next_line+0x9c>
mov    %eax,%ebx
cltq
movb   $0x0,(%r15,%rax,1)
mov    (%r12),%rdi
mov    %r15,%rsi
call   1080 <ft_strjoin@plt>
mov    %rax,%rbp
mov    (%r12),%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1060 <ft_strdup@plt>
mov    %rax,(%r12)
mov    %rbp,%rdi
call   1030 <free@plt>
mov    (%r12),%rdi
mov    $0xa,%esi
call   1070 <ft_strchr@plt>
cmp    $0xa,%ebx
je     1190 <read_next_line+0x30>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1201 <read_next_line+0xa1>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_next_line(i8** %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8** %0, i8*** %4
store i32 %1, i32* %5
%9 = call i8* @ft_strnew(i32 10)
store i8* %9, i8** %6
store i32 10, i32* %7
br label %10
10: ; preds = %26, %2
%11 = load i8**, i8*** %4
%12 = load i8*, i8** %11
%13 = call i32* @ft_strchr(i8* %12, i8 signext 10)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 10
br label %18
18: ; preds = %15, %10
%19 = phi i1 [ false, %10 ], [ %17, %15 ]
br i1 %19, label %20, label %43
20: ; preds = %18
%21 = load i32, i32* %5
%22 = load i8*, i8** %6
%23 = call i32 @read(i32 %21, i8* %22, i32 10)
store i32 %23, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 -1, i32* %3
br label %47
26: ; preds = %20
%27 = load i8*, i8** %6
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i8**, i8*** %4
%32 = load i8*, i8** %31
%33 = load i8*, i8** %6
%34 = call i8* @ft_strjoin(i8* %32, i8* %33)
store i8* %34, i8** %8
%35 = load i8**, i8*** %4
%36 = load i8*, i8** %35
%37 = call i32 @free(i8* %36)
%38 = load i8*, i8** %8
%39 = call i8* @ft_strdup(i8* %38)
%40 = load i8**, i8*** %4
store i8* %39, i8** %40
%41 = load i8*, i8** %8
%42 = call i32 @free(i8* %41)
br label %10
43: ; preds = %18
%44 = load i8*, i8** %6
%45 = call i32 @free(i8* %44)
%46 = load i32, i32* %7
store i32 %46, i32* %3
br label %47
47: ; preds = %43, %25
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
define i32 @read_next_line(i8** nocapture %0, i32 %1) {
%3 = tail call i8* @ft_strnew(i32 10)
%4 = load i8*, i8** %0
%5 = tail call i32* @ft_strchr(i8* %4, i8 signext 10)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %24
7: ; preds = %2, %10
%8 = tail call i32 @read(i32 %1, i8* %3, i32 10)
%9 = icmp eq i32 %8, -1
br i1 %9, label %27, label %10
10: ; preds = %7
%11 = sext i32 %8 to i64
%12 = getelementptr inbounds i8, i8* %3, i64 %11
store i8 0, i8* %12
%13 = load i8*, i8** %0
%14 = tail call i8* @ft_strjoin(i8* %13, i8* %3)
%15 = load i8*, i8** %0
%16 = tail call i32 @free(i8* %15)
%17 = tail call i8* @ft_strdup(i8* %14)
store i8* %17, i8** %0
%18 = tail call i32 @free(i8* %14)
%19 = load i8*, i8** %0
%20 = tail call i32* @ft_strchr(i8* %19, i8 signext 10)
%21 = icmp eq i32* %20, null
%22 = icmp eq i32 %8, 10
%23 = and i1 %22, %21
br i1 %23, label %7, label %24
24: ; preds = %10, %2
%25 = phi i32 [ 10, %2 ], [ %8, %10 ]
%26 = tail call i32 @free(i8* %3)
br label %27
27: ; preds = %7, %24
%28 = phi i32 [ %25, %24 ], [ -1, %7 ]
ret i32 %28
}