#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*/ ft_memccpy(char *, char *, char, int);
char *ft_strchr(char *, char);
int /*<<< orphan*/ ft_strdel(char **);
char *ft_strjoin(char *, char *);
int ft_strlen(char *);
char *ft_strnew(int);
int ft_cp_buff(char **line, char *buff) {
  char *c;
  char *tmp;
  int len;
  len = ft_strlen(buff);
  tmp = ft_strnew(len);
  if (!tmp)
    return (-1);
  ft_memccpy(tmp, buff, '\n', len);
  c = ft_strchr(tmp, '\n');
  if (c)
    *c = '\0';
  c = *line;
  *line = ft_strjoin(*line, tmp);
  ft_strdel(&c);
  ft_strdel(&tmp);
  if (!*line)
    return (-1);
  return (1);
}


x86 assembly (clang, -O0):
<ft_cp_buff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <ft_strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <ft_strnew@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119f <ft_cp_buff+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <ft_cp_buff+0xd0>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%ecx
mov    $0xa,%edx
call   1070 <ft_memccpy@plt>
mov    -0x28(%rbp),%rdi
mov    $0xa,%esi
call   1060 <ft_strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d8 <ft_cp_buff+0x78>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <ft_strjoin@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x20(%rbp),%rdi
call   1040 <ft_strdel@plt>
lea    -0x28(%rbp),%rdi
call   1040 <ft_strdel@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1229 <ft_cp_buff+0xc9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1230 <ft_cp_buff+0xd0>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_cp_buff>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <ft_strlen@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <ft_strnew@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     11ec <ft_cp_buff+0x8c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
mov    $0xa,%edx
mov    %ebp,%ecx
call   1070 <ft_memccpy@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <ft_strchr@plt>
test   %rax,%rax
je     11ba <ft_cp_buff+0x5a>
movb   $0x0,(%rax)
mov    0x8(%rsp),%rbx
mov    (%r14),%rdi
mov    %rdi,0x10(%rsp)
mov    %rbx,%rsi
call   1080 <ft_strjoin@plt>
mov    %rax,(%r14)
lea    0x10(%rsp),%rdi
call   1040 <ft_strdel@plt>
lea    0x8(%rsp),%rdi
call   1040 <ft_strdel@plt>
cmpq   $0x1,(%r14)
sbb    %eax,%eax
or     $0x1,%eax
jmp    11f1 <ft_cp_buff+0x91>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @ft_cp_buff(i8** %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8** %0, i8*** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @ft_strlen(i8* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = call i8* @ft_strnew(i32 %11)
store i8* %12, i8** %7
%13 = load i8*, i8** %7
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %2
store i32 -1, i32* %3
br label %42
16: ; preds = %2
%17 = load i8*, i8** %7
%18 = load i8*, i8** %5
%19 = load i32, i32* %8
%20 = call i32 @ft_memccpy(i8* %17, i8* %18, i8 signext 10, i32 %19)
%21 = load i8*, i8** %7
%22 = call i8* @ft_strchr(i8* %21, i8 signext 10)
store i8* %22, i8** %6
%23 = load i8*, i8** %6
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = load i8*, i8** %6
store i8 0, i8* %26
br label %27
27: ; preds = %25, %16
%28 = load i8**, i8*** %4
%29 = load i8*, i8** %28
store i8* %29, i8** %6
%30 = load i8**, i8*** %4
%31 = load i8*, i8** %30
%32 = load i8*, i8** %7
%33 = call i8* @ft_strjoin(i8* %31, i8* %32)
%34 = load i8**, i8*** %4
store i8* %33, i8** %34
%35 = call i32 @ft_strdel(i8** %6)
%36 = call i32 @ft_strdel(i8** %7)
%37 = load i8**, i8*** %4
%38 = load i8*, i8** %37
%39 = icmp ne i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %27
store i32 -1, i32* %3
br label %42
41: ; preds = %27
store i32 1, i32* %3
br label %42
42: ; preds = %41, %40, %15
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @ft_cp_buff(i8** nocapture %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = tail call i32 @ft_strlen(i8* %1)
%8 = tail call i8* @ft_strnew(i32 %7)
store i8* %8, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %25, label %10
10: ; preds = %2
%11 = tail call i32 @ft_memccpy(i8* %8, i8* %1, i8 signext 10, i32 %7)
%12 = tail call i8* @ft_strchr(i8* %8, i8 signext 10)
%13 = icmp eq i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %10
store i8 0, i8* %12
%15 = load i8*, i8** %4
br label %16
16: ; preds = %14, %10
%17 = phi i8* [ %15, %14 ], [ %8, %10 ]
%18 = load i8*, i8** %0
store i8* %18, i8** %3
%19 = tail call i8* @ft_strjoin(i8* %18, i8* %17)
store i8* %19, i8** %0
%20 = call i32 @ft_strdel(i8** %3)
%21 = call i32 @ft_strdel(i8** %4)
%22 = load i8*, i8** %0
%23 = icmp eq i8* %22, null
%24 = select i1 %23, i32 -1, i32 1
br label %25
25: ; preds = %16, %2
%26 = phi i32 [ -1, %2 ], [ %24, %16 ]
ret i32 %26
}