#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 check_end_line(char *, int, int *);
char *cut_line(char *, int, int *);
int /*<<< orphan*/ free(char *);
char *my_strcat(char *, char *, int, int);
int read(int const, char *, int);
char *get_next_line(const int fd) {
  char buffer[123456];
  static char *line = NULL;
  char *result;
  int is_end_line;
  int size_read;
  static int size_line;
  int pos_end_line;
  is_end_line = 0;
  while (1) {
    pos_end_line = check_end_line(line, size_line, &is_end_line);
    if (is_end_line)
      break;
    size_read = read(fd, buffer, 123456);
    if (size_read <= 0) {
      free(line);
      return (NULL);
    }
    line = my_strcat(line, buffer, size_line, size_read);
    size_line += size_read;
  }
  result = cut_line(line, pos_end_line, &size_line);
  return (result);
}


x86 assembly (clang, -O0):
<get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e270,%rsp
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x1e25c(%rbp)
mov    0x2ee1(%rip),%rdi
mov    0x2ee3(%rip),%esi
lea    -0x1e25c(%rbp),%rdx
call   1070 <check_end_line@plt>
mov    %eax,-0x1e264(%rbp)
cmpl   $0x0,-0x1e25c(%rbp)
je     1199 <get_next_line+0x49>
jmp    1216 <get_next_line+0xc6>
mov    -0xc(%rbp),%edi
lea    -0x1e250(%rbp),%rsi
mov    $0x1e240,%edx
call   1040 <read@plt>
mov    %eax,-0x1e260(%rbp)
cmpl   $0x0,-0x1e260(%rbp)
jg     11d9 <get_next_line+0x89>
mov    0x2e89(%rip),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1241 <get_next_line+0xf1>
mov    0x2e70(%rip),%rdi
lea    -0x1e250(%rbp),%rsi
mov    0x2e6b(%rip),%edx
mov    -0x1e260(%rbp),%ecx
call   1050 <my_strcat@plt>
mov    %rax,0x2e51(%rip)
mov    -0x1e260(%rbp),%eax
add    0x2e4d(%rip),%eax
mov    %eax,0x2e47(%rip)
jmp    1168 <get_next_line+0x18>
mov    0x2e33(%rip),%rdi
mov    -0x1e264(%rbp),%esi
lea    0x2e2e(%rip),%rdx
call   1060 <cut_line@plt>
mov    %rax,-0x1e258(%rbp)
mov    -0x1e258(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1e270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1e258,%rsp
mov    %edi,%r15d
movl   $0x0,0xc(%rsp)
mov    0x2ee1(%rip),%rdi
mov    0x2ee3(%rip),%esi
lea    0xc(%rsp),%rdx
call   1070 <check_end_line@plt>
cmpl   $0x0,0xc(%rsp)
jne    11e4 <get_next_line+0x94>
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r14
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x1e240,%edx
call   1040 <read@plt>
mov    0x2ea9(%rip),%rdi
test   %eax,%eax
jle    11fb <get_next_line+0xab>
mov    %eax,%ebp
mov    0x2ea5(%rip),%edx
mov    %rbx,%rsi
mov    %eax,%ecx
call   1050 <my_strcat@plt>
mov    %rax,0x2e8c(%rip)
add    0x2e8e(%rip),%ebp
mov    %ebp,0x2e88(%rip)
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1070 <check_end_line@plt>
cmpl   $0x0,0xc(%rsp)
je     1190 <get_next_line+0x40>
mov    0x2e65(%rip),%rdi
lea    0x2e66(%rip),%rdx
mov    %eax,%esi
call   1060 <cut_line@plt>
jmp    1202 <get_next_line+0xb2>
call   1030 <free@plt>
xor    %eax,%eax
add    $0x1e258,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@get_next_line.line = internal global i8* null
@get_next_line.size_line = internal global i32 0
define i8* @get_next_line(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [123456 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i32 0, i32* %6
br label %9
9: ; preds = %1, %25
%10 = load i8*, i8** @get_next_line.line
%11 = load i32, i32* @get_next_line.size_line
%12 = call i32 @check_end_line(i8* %10, i32 %11, i32* %6)
store i32 %12, i32* %8
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
br label %34
16: ; preds = %9
%17 = load i32, i32* %3
%18 = getelementptr inbounds [123456 x i8], [123456 x i8]* %4, i64 0, i64 0
%19 = call i32 @read(i32 %17, i8* %18, i32 123456)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** @get_next_line.line
%24 = call i32 @free(i8* %23)
store i8* null, i8** %2
br label %39
25: ; preds = %16
%26 = load i8*, i8** @get_next_line.line
%27 = getelementptr inbounds [123456 x i8], [123456 x i8]* %4, i64 0, i64 0
%28 = load i32, i32* @get_next_line.size_line
%29 = load i32, i32* %7
%30 = call i8* @my_strcat(i8* %26, i8* %27, i32 %28, i32 %29)
store i8* %30, i8** @get_next_line.line
%31 = load i32, i32* %7
%32 = load i32, i32* @get_next_line.size_line
%33 = add nsw i32 %32, %31
store i32 %33, i32* @get_next_line.size_line
br label %9
34: ; preds = %15
%35 = load i8*, i8** @get_next_line.line
%36 = load i32, i32* %8
%37 = call i8* @cut_line(i8* %35, i32 %36, i32* @get_next_line.size_line)
store i8* %37, i8** %5
%38 = load i8*, i8** %5
store i8* %38, i8** %2
br label %39
39: ; preds = %34, %22
%40 = load i8*, i8** %2
ret i8* %40
}

LLVM IR (-O2):
@get_next_line.line = internal unnamed_addr global i8* null
@get_next_line.size_line = internal global i32 0
define i8* @get_next_line(i32 %0) {
%2 = alloca [123456 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [123456 x i8], [123456 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%6 = load i8*, i8** @get_next_line.line
%7 = load i32, i32* @get_next_line.size_line
%8 = call i32 @check_end_line(i8* %6, i32 %7, i32* %3)
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %1, %17
%12 = call i32 @read(i32 %0, i8* %4, i32 123456)
%13 = icmp slt i32 %12, 1
%14 = load i8*, i8** @get_next_line.line
br i1 %13, label %15, label %17
15: ; preds = %11
%16 = call i32 @free(i8* %14)
br label %29
17: ; preds = %11
%18 = load i32, i32* @get_next_line.size_line
%19 = call i8* @my_strcat(i8* %14, i8* %4, i32 %18, i32 %12)
store i8* %19, i8** @get_next_line.line
%20 = load i32, i32* @get_next_line.size_line
%21 = add nsw i32 %20, %12
store i32 %21, i32* @get_next_line.size_line
%22 = call i32 @check_end_line(i8* %19, i32 %21, i32* %3)
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 0
br i1 %24, label %11, label %25
25: ; preds = %17, %1
%26 = phi i32 [ %8, %1 ], [ %22, %17 ]
%27 = load i8*, i8** @get_next_line.line
%28 = call i8* @cut_line(i8* %27, i32 %26, i32* @get_next_line.size_line)
br label %29
29: ; preds = %25, %15
%30 = phi i8* [ %28, %25 ], [ null, %15 ]
ret i8* %30
}