#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 *);
scalar_t__ ft_strlen(char *);
int read(int, char *, int);
int ft_read_txt(int fd, char **line, char *buff) {
  int res;
  int ret;
  while ((res = read(fd, buff, 256)) > 0) {
    buff[res] = '\0';
    ret = ft_cp_buff(line, buff);
    if (ret == -1)
      return (-1);
    if (ft_check_line(buff))
      return (1);
  }
  if (res == 0) {
    if (ft_strlen(*line))
      return (1);
    return (0);
  }
  return (-1);
}


x86 assembly (clang, -O0):
<ft_read_txt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x100,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    11c6 <ft_read_txt+0x86>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <ft_cp_buff@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11a2 <ft_read_txt+0x62>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <ft_read_txt+0xc5>
mov    -0x18(%rbp),%rdi
call   1040 <ft_check_line@plt>
cmp    $0x0,%rax
je     11c1 <ft_read_txt+0x81>
movl   $0x1,-0x4(%rbp)
jmp    1205 <ft_read_txt+0xc5>
jmp    1153 <ft_read_txt+0x13>
cmpl   $0x0,-0x1c(%rbp)
jne    11fe <ft_read_txt+0xbe>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <ft_strlen@plt>
cmp    $0x0,%rax
je     11f2 <ft_read_txt+0xb2>
movl   $0x1,-0x4(%rbp)
jmp    1205 <ft_read_txt+0xc5>
movl   $0x0,-0x4(%rbp)
jmp    1205 <ft_read_txt+0xc5>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_read_txt>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1050 <read@plt>
test   %eax,%eax
jle    118d <ft_read_txt+0x4d>
mov    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <ft_cp_buff@plt>
cmp    $0xffffffff,%eax
je     11a9 <ft_read_txt+0x69>
mov    %rbx,%rdi
call   1040 <ft_check_line@plt>
test   %rax,%rax
je     1150 <ft_read_txt+0x10>
mov    $0x1,%eax
jmp    11ae <ft_read_txt+0x6e>
mov    $0xffffffff,%eax
jne    11ae <ft_read_txt+0x6e>
mov    (%r14),%rdi
call   1030 <ft_strlen@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    11ae <ft_read_txt+0x6e>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ft_read_txt(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
br label %10
10: ; preds = %31, %3
%11 = load i32, i32* %5
%12 = load i8*, i8** %7
%13 = call i32 @read(i32 %11, i8* %12, i32 256)
store i32 %13, i32* %8
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %10
%16 = load i8*, i8** %7
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 0, i8* %19
%20 = load i8**, i8*** %6
%21 = load i8*, i8** %7
%22 = call i32 @ft_cp_buff(i8** %20, i8* %21)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %15
store i32 -1, i32* %4
br label %43
26: ; preds = %15
%27 = load i8*, i8** %7
%28 = call i64 @ft_check_line(i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 1, i32* %4
br label %43
31: ; preds = %26
br label %10
32: ; preds = %10
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %32
%36 = load i8**, i8*** %6
%37 = load i8*, i8** %36
%38 = call i64 @ft_strlen(i8* %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %35
store i32 1, i32* %4
br label %43
41: ; preds = %35
store i32 0, i32* %4
br label %43
42: ; preds = %32
store i32 -1, i32* %4
br label %43
43: ; preds = %42, %41, %40, %30, %25
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
define i32 @ft_read_txt(i32 %0, i8** %1, i8* %2) {
br label %4
4: ; preds = %12, %3
%5 = tail call i32 @read(i32 %0, i8* %2, i32 256)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = zext i32 %5 to i64
%9 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 0, i8* %9
%10 = tail call i32 @ft_cp_buff(i8** %1, i8* %2)
%11 = icmp eq i32 %10, -1
br i1 %11, label %22, label %12
12: ; preds = %7
%13 = tail call i64 @ft_check_line(i8* %2)
%14 = icmp eq i64 %13, 0
br i1 %14, label %4, label %22
15: ; preds = %4
%16 = icmp eq i32 %5, 0
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = load i8*, i8** %1
%19 = tail call i64 @ft_strlen(i8* %18)
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %12, %7, %15, %17
%23 = phi i32 [ %21, %17 ], [ -1, %15 ], [ 1, %12 ], [ -1, %7 ]
ret i32 %23
}