#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_strdel(char **);
char *ft_strdup(char *);
int /*<<< orphan*/ ft_strlen(char const *);
char *ft_strnew(int /*<<< orphan*/);
char *ft_strstr(char *, char const *);
int /*<<< orphan*/ gnd_extract_content(char **, char **, char *,
                                       int /*<<< orphan*/);
int gnd_read(int const, char **);
int get_next_delim(const int fd, char **line, const char *delim) {
  static char *stock = NULL;
  int value;
  char *ptr;
  value = 0;
  if (stock == NULL)
    stock = ft_strnew(0);
  if ((ptr = ft_strstr(stock, delim)) != NULL)
    gnd_extract_content(&stock, line, ptr, ft_strlen(delim));
  else {
    while ((value = gnd_read(fd, &stock)) > 0) {
      if ((ptr = ft_strstr(stock, delim)) != NULL) {
        gnd_extract_content(&stock, line, ptr, ft_strlen(delim));
        return (value);
      }
    }
    *line = ft_strdup(stock);
    ft_strdel(&stock);
    value = -1;
  }
  return (value);
}


x86 assembly (clang, -O0):
<get_next_delim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,0x2ece(%rip)
jne    11a6 <get_next_delim+0x36>
xor    %edi,%edi
call   1070 <ft_strnew@plt>
mov    %rax,0x2eba(%rip)
mov    0x2eb3(%rip),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <ft_strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11f8 <get_next_delim+0x88>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ft_strlen@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
lea    0x2e72(%rip),%rdi
call   1040 <gnd_extract_content@plt>
jmp    129e <get_next_delim+0x12e>
jmp    11fd <get_next_delim+0x8d>
mov    -0x8(%rbp),%edi
lea    0x2e59(%rip),%rsi
call   1030 <gnd_read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    1275 <get_next_delim+0x105>
mov    0x2e41(%rip),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <ft_strstr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1270 <get_next_delim+0x100>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <ft_strlen@plt>
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
lea    0x2e00(%rip),%rdi
call   1040 <gnd_extract_content@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12a4 <get_next_delim+0x134>
jmp    11fd <get_next_delim+0x8d>
mov    0x2de4(%rip),%rdi
call   1080 <ft_strdup@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    0x2dce(%rip),%rdi
call   1060 <ft_strdel@plt>
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_delim>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r13
mov    %rsi,%r14
mov    %edi,%r15d
mov    0x2ed5(%rip),%rdi
test   %rdi,%rdi
jne    11a1 <get_next_delim+0x31>
xor    %edi,%edi
call   1070 <ft_strnew@plt>
mov    %rax,%rdi
mov    %rax,0x2ebf(%rip)
mov    %r13,%rsi
call   1090 <ft_strstr@plt>
test   %rax,%rax
je     11d1 <get_next_delim+0x61>
mov    %rax,%rbx
mov    %r13,%rdi
call   1050 <ft_strlen@plt>
lea    0x2ea0(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1040 <gnd_extract_content@plt>
xor    %ebp,%ebp
jmp    123f <get_next_delim+0xcf>
lea    0x2e88(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %r12,%rsi
call   1030 <gnd_read@plt>
mov    0x2e6e(%rip),%rdi
test   %eax,%eax
jle    1226 <get_next_delim+0xb6>
mov    %eax,%ebp
mov    %r13,%rsi
call   1090 <ft_strstr@plt>
test   %rax,%rax
je     11e0 <get_next_delim+0x70>
mov    %rax,%rbx
mov    %r13,%rdi
call   1050 <ft_strlen@plt>
lea    0x2e49(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1040 <gnd_extract_content@plt>
jmp    123f <get_next_delim+0xcf>
call   1080 <ft_strdup@plt>
mov    %rax,(%r14)
lea    0x2e2b(%rip),%rdi
call   1060 <ft_strdel@plt>
mov    $0xffffffff,%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_delim.stock = internal global i8* null
define i32 @get_next_delim(i32 %0, i8** %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8* %2, i8** %7
store i32 0, i32* %8
%10 = load i8*, i8** @get_next_delim.stock
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i8* @ft_strnew(i32 0)
store i8* %13, i8** @get_next_delim.stock
br label %14
14: ; preds = %12, %3
%15 = load i8*, i8** @get_next_delim.stock
%16 = load i8*, i8** %7
%17 = call i8* @ft_strstr(i8* %15, i8* %16)
store i8* %17, i8** %9
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i8**, i8*** %6
%21 = load i8*, i8** %9
%22 = load i8*, i8** %7
%23 = call i32 @ft_strlen(i8* %22)
%24 = call i32 @gnd_extract_content(i8** @get_next_delim.stock, i8** %20, i8* %21, i32 %23)
br label %48
25: ; preds = %14
br label %26
26: ; preds = %42, %25
%27 = load i32, i32* %5
%28 = call i32 @gnd_read(i32 %27, i8** @get_next_delim.stock)
store i32 %28, i32* %8
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %43
30: ; preds = %26
%31 = load i8*, i8** @get_next_delim.stock
%32 = load i8*, i8** %7
%33 = call i8* @ft_strstr(i8* %31, i8* %32)
store i8* %33, i8** %9
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %42
35: ; preds = %30
%36 = load i8**, i8*** %6
%37 = load i8*, i8** %9
%38 = load i8*, i8** %7
%39 = call i32 @ft_strlen(i8* %38)
%40 = call i32 @gnd_extract_content(i8** @get_next_delim.stock, i8** %36, i8* %37, i32 %39)
%41 = load i32, i32* %8
store i32 %41, i32* %4
br label %50
42: ; preds = %30
br label %26
43: ; preds = %26
%44 = load i8*, i8** @get_next_delim.stock
%45 = call i8* @ft_strdup(i8* %44)
%46 = load i8**, i8*** %6
store i8* %45, i8** %46
%47 = call i32 @ft_strdel(i8** @get_next_delim.stock)
store i32 -1, i32* %8
br label %48
48: ; preds = %43, %19
%49 = load i32, i32* %8
store i32 %49, i32* %4
br label %50
50: ; preds = %48, %35
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@get_next_delim.stock = internal global i8* null
define i32 @get_next_delim(i32 %0, i8** %1, i8* %2) {
%4 = load i8*, i8** @get_next_delim.stock
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i8* @ft_strnew(i32 0)
store i8* %7, i8** @get_next_delim.stock
br label %8
8: ; preds = %6, %3
%9 = phi i8* [ %7, %6 ], [ %4, %3 ]
%10 = tail call i8* @ft_strstr(i8* %9, i8* %2)
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call i32 @ft_strlen(i8* %2)
%14 = tail call i32 @gnd_extract_content(i8** @get_next_delim.stock, i8** %1, i8* %10, i32 %13)
br label %28
15: ; preds = %8, %19
%16 = tail call i32 @gnd_read(i32 %0, i8** @get_next_delim.stock)
%17 = icmp sgt i32 %16, 0
%18 = load i8*, i8** @get_next_delim.stock
br i1 %17, label %19, label %25
19: ; preds = %15
%20 = tail call i8* @ft_strstr(i8* %18, i8* %2)
%21 = icmp eq i8* %20, null
br i1 %21, label %15, label %22
22: ; preds = %19
%23 = tail call i32 @ft_strlen(i8* %2)
%24 = tail call i32 @gnd_extract_content(i8** @get_next_delim.stock, i8** %1, i8* %20, i32 %23)
br label %28
25: ; preds = %15
%26 = tail call i8* @ft_strdup(i8* %18)
store i8* %26, i8** %1
%27 = tail call i32 @ft_strdel(i8** @get_next_delim.stock)
br label %28
28: ; preds = %12, %25, %22
%29 = phi i32 [ %16, %22 ], [ 0, %12 ], [ -1, %25 ]
ret i32 %29
}