#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_strdel(char **);
int ft_strlen(char *);
char *ft_strncpy(char *, char *, int);
scalar_t__ malloc(int);
int gnl_dump_line(const int length, char **rbak) {
  int blen;
  char *new;
  if ((*rbak) == NULL)
    return (0);
  blen = ft_strlen(*rbak);
  if (blen == 0) {
    ft_strdel(rbak);
    return (0);
  }
  if (length == -1) {
    ft_strdel(rbak);
    return (1);
  }
  new = (char *)malloc(sizeof(char) * (blen - length + 1));
  if (!new)
    return (-1);
  new = ft_strncpy(new, ((*rbak) + length), (blen - length));
  new[blen - length] = '\0';
  free(*rbak);
  *rbak = new;
  return (1);
}


x86 assembly (clang, -O0):
<gnl_dump_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1179 <gnl_dump_line+0x29>
movl   $0x0,-0x4(%rbp)
jmp    1247 <gnl_dump_line+0xf7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <ft_strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11a7 <gnl_dump_line+0x57>
mov    -0x10(%rbp),%rdi
call   1050 <ft_strdel@plt>
movl   $0x0,-0x4(%rbp)
jmp    1247 <gnl_dump_line+0xf7>
cmpl   $0xffffffff,-0x8(%rbp)
jne    11c6 <gnl_dump_line+0x76>
mov    -0x10(%rbp),%rdi
call   1050 <ft_strdel@plt>
movl   $0x1,-0x4(%rbp)
jmp    1247 <gnl_dump_line+0xf7>
mov    -0x14(%rbp),%eax
sub    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f7 <gnl_dump_line+0xa7>
movl   $0xffffffff,-0x4(%rbp)
jmp    1247 <gnl_dump_line+0xf7>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
movslq -0x8(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
sub    -0x8(%rbp),%edx
call   1070 <ft_strncpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    -0x8(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gnl_dump_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    (%rsi),%rdi
xor    %ebx,%ebx
test   %rdi,%rdi
je     11cd <gnl_dump_line+0x7d>
mov    %rsi,%r15
call   1040 <ft_strlen@plt>
test   %eax,%eax
je     11af <gnl_dump_line+0x5f>
cmp    $0xffffffff,%r14d
je     11b9 <gnl_dump_line+0x69>
mov    %eax,%ebp
sub    %r14d,%ebp
lea    0x1(%rbp),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11c8 <gnl_dump_line+0x78>
movslq %r14d,%rsi
add    (%r15),%rsi
mov    %rax,%rdi
mov    %ebp,%edx
call   1070 <ft_strncpy@plt>
mov    %rax,%rbx
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    (%r15),%rdi
call   1030 <free@plt>
mov    %rbx,(%r15)
jmp    11c1 <gnl_dump_line+0x71>
mov    %r15,%rdi
call   1050 <ft_strdel@plt>
jmp    11cd <gnl_dump_line+0x7d>
mov    %r15,%rdi
call   1050 <ft_strdel@plt>
mov    $0x1,%ebx
jmp    11cd <gnl_dump_line+0x7d>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @gnl_dump_line(i32 %0, i8** %1) {
%3 = load i8*, i8** %1
%4 = icmp eq i8* %3, null
br i1 %4, label %29, label %5
5: ; preds = %2
%6 = tail call i32 @ft_strlen(i8* %3)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @ft_strdel(i8** %1)
br label %29
10: ; preds = %5
%11 = icmp eq i32 %0, -1
br i1 %11, label %12, label %14
12: ; preds = %10
%13 = tail call i32 @ft_strdel(i8** %1)
br label %29
14: ; preds = %10
%15 = sub nsw i32 %6, %0
%16 = add nsw i32 %15, 1
%17 = tail call i64 @malloc(i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %14
%20 = inttoptr i64 %17 to i8*
%21 = load i8*, i8** %1
%22 = sext i32 %0 to i64
%23 = getelementptr inbounds i8, i8* %21, i64 %22
%24 = tail call i8* @ft_strncpy(i8* %20, i8* %23, i32 %15)
%25 = sext i32 %15 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %1
%28 = tail call i32 @free(i8* %27)
store i8* %24, i8** %1
br label %29
29: ; preds = %14, %2, %19, %12, %8
%30 = phi i32 [ 0, %8 ], [ 1, %12 ], [ 1, %19 ], [ 0, %2 ], [ -1, %14 ]
ret i32 %30
}