#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 */
char *malloc(int);
int my_len(char *);
char *my_realloc(char *, int);
int read(int const, char *, int);
char *get_next_line(const int fd) {
  static int last = 1;
  static int rd = 0;
  static int i = 0;
  static char *res = NULL;
  static char buf[5];
  if (buf[my_len(buf) - rd] == '\0') {
    if ((rd = read(fd, buf, 5)) <= 0)
      return (res = (last-- && buf[my_len(buf) - rd - 1] != 10) ? res : NULL);
    buf[rd] = '\0';
  }
  if ((res = (i == 0) ? malloc(sizeof(*res) * 5 + 1)
                      : my_realloc(res, sizeof(*res) * 5 + 1)) == NULL)
    return (NULL);
  while (buf[my_len(buf) - rd] && buf[my_len(buf) - rd] != '\n')
    res[i++] = buf[my_len(buf) - rd--];
  res[i] = '\0';
  if (buf[my_len(buf) - rd] == '\n') {
    i = 0;
    rd--;
    return (res);
  }
  return (get_next_line(fd));
}


x86 assembly (clang, -O0):
<get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
lea    0x2f06(%rip),%rdi
call   1030 <my_len@plt>
sub    0x2eeb(%rip),%eax
movslq %eax,%rcx
lea    0x2ef1(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    122e <get_next_line+0xde>
mov    -0xc(%rbp),%edi
lea    0x2eda(%rip),%rsi
mov    $0x5,%edx
call   1040 <read@plt>
mov    %eax,0x2eba(%rip)
cmp    $0x0,%eax
jg     121c <get_next_line+0xcc>
mov    0x2e9b(%rip),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x2e90(%rip)
cmp    $0x0,%eax
je     11fd <get_next_line+0xad>
lea    0x2ea0(%rip),%rdi
call   1030 <my_len@plt>
sub    0x2e85(%rip),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2e88(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11fd <get_next_line+0xad>
mov    0x2e6c(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1208 <get_next_line+0xb8>
xor    %eax,%eax
mov    %rax,-0x18(%rbp)
jmp    1208 <get_next_line+0xb8>
mov    -0x18(%rbp),%rax
mov    %rax,0x2e4d(%rip)
mov    %rax,-0x8(%rbp)
jmp    13b0 <get_next_line+0x260>
movslq 0x2e35(%rip),%rcx
lea    0x2e3e(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,0x2e27(%rip)
jne    124e <get_next_line+0xfe>
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
jmp    1263 <get_next_line+0x113>
mov    0x2e0b(%rip),%rdi
mov    $0x6,%esi
call   1060 <my_realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,0x2df2(%rip)
cmp    $0x0,%rax
jne    1285 <get_next_line+0x135>
movq   $0x0,-0x8(%rbp)
jmp    13b0 <get_next_line+0x260>
jmp    128a <get_next_line+0x13a>
lea    0x2dd7(%rip),%rdi
call   1030 <my_len@plt>
sub    0x2dbc(%rip),%eax
movslq %eax,%rcx
lea    0x2dc2(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     12e1 <get_next_line+0x191>
lea    0x2da9(%rip),%rdi
call   1030 <my_len@plt>
sub    0x2d8e(%rip),%eax
movslq %eax,%rcx
lea    0x2d94(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    12f1 <get_next_line+0x1a1>
jmp    1340 <get_next_line+0x1f0>
lea    0x2d70(%rip),%rdi
call   1030 <my_len@plt>
mov    0x2d55(%rip),%ecx
mov    %ecx,%edx
add    $0xffffffff,%edx
mov    %edx,0x2d4a(%rip)
sub    %ecx,%eax
movslq %eax,%rcx
lea    0x2d4e(%rip),%rax
mov    (%rax,%rcx,1),%dl
mov    0x2d3c(%rip),%rax
mov    0x2d32(%rip),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,0x2d27(%rip)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    128a <get_next_line+0x13a>
mov    0x2d19(%rip),%rax
movslq 0x2d0e(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0x2d0f(%rip),%rdi
call   1030 <my_len@plt>
sub    0x2cf4(%rip),%eax
movslq %eax,%rcx
lea    0x2cfa(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    13a4 <get_next_line+0x254>
movl   $0x0,0x2cd7(%rip)
mov    0x2ccd(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2cc4(%rip)
mov    0x2cc5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    13b0 <get_next_line+0x260>
mov    -0xc(%rbp),%edi
call   1070 <get_next_line@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
lea    0x2f13(%rip),%rbx
xor    %r14d,%r14d
jmp    118e <get_next_line+0x4e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2ef1(%rip),%rax
movslq 0x2ee6(%rip),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    %rbx,%rdi
call   1030 <my_len@plt>
mov    0x2ed0(%rip),%ecx
sub    %ecx,%eax
cltq
cmpb   $0xa,(%rax,%rbx,1)
je     1297 <get_next_line+0x157>
mov    %rbx,%rdi
call   1030 <my_len@plt>
movslq 0x2eb3(%rip),%rcx
cltq
sub    %rcx,%rax
cmpb   $0x0,(%rax,%rbx,1)
je     11d0 <get_next_line+0x90>
cmpl   $0x0,0x2ea5(%rip)
je     11fc <get_next_line+0xbc>
mov    0x2ea0(%rip),%rdi
mov    $0x6,%esi
call   1060 <my_realloc@plt>
jmp    1206 <get_next_line+0xc6>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1040 <read@plt>
mov    %eax,0x2e6b(%rip)
test   %eax,%eax
jle    12b3 <get_next_line+0x173>
mov    %eax,%eax
movb   $0x0,(%rax,%rbx,1)
cmpl   $0x0,0x2e5a(%rip)
jne    11b1 <get_next_line+0x71>
mov    $0x6,%edi
call   1050 <malloc@plt>
mov    %rax,0x2e4b(%rip)
test   %rax,%rax
je     12f1 <get_next_line+0x1b1>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <my_len@plt>
movslq 0x2e21(%rip),%rcx
cltq
sub    %rcx,%rax
cmpb   $0x0,(%rax,%rbx,1)
je     1160 <get_next_line+0x20>
mov    %rbx,%rdi
call   1030 <my_len@plt>
movslq 0x2e03(%rip),%rcx
cltq
sub    %rcx,%rax
cmpb   $0xa,(%rax,%rbx,1)
je     1160 <get_next_line+0x20>
mov    %rbx,%rdi
call   1030 <my_len@plt>
mov    0x2de6(%rip),%ecx
lea    -0x1(%rcx),%edx
mov    %edx,0x2ddd(%rip)
sub    %ecx,%eax
cltq
movzbl (%rax,%rbx,1),%eax
mov    0x2dd6(%rip),%rcx
movslq 0x2dcb(%rip),%rdx
lea    0x1(%rdx),%esi
mov    %esi,0x2dc2(%rip)
mov    %al,(%rcx,%rdx,1)
jmp    1220 <get_next_line+0xe0>
movl   $0x0,0x2db3(%rip)
add    $0xffffffff,%ecx
mov    %ecx,0x2da6(%rip)
mov    0x2da7(%rip),%r14
jmp    12f1 <get_next_line+0x1b1>
subl   $0x1,0x2d86(%rip)
jb     12e7 <get_next_line+0x1a7>
mov    %rbx,%rdi
call   1030 <my_len@plt>
mov    0x2d86(%rip),%ecx
not    %ecx
add    %eax,%ecx
movslq %ecx,%rax
cmpb   $0xa,(%rax,%rbx,1)
je     12e7 <get_next_line+0x1a7>
mov    0x2d7a(%rip),%r14
mov    %r14,0x2d73(%rip)
jmp    12f1 <get_next_line+0x1b1>
xor    %r14d,%r14d
mov    %r14,0x2d67(%rip)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@get_next_line.last = internal global i32 1
@get_next_line.rd = internal global i32 0
@get_next_line.i = internal global i32 0
@get_next_line.res = internal global i8* null
@get_next_line.buf = internal global [5 x i8] zeroinitializer
define i8* @get_next_line(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%5 = load i32, i32* @get_next_line.rd
%6 = sub nsw i32 %4, %5
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %39
12: ; preds = %1
%13 = load i32, i32* %3
%14 = call i32 @read(i32 %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0), i32 5)
store i32 %14, i32* @get_next_line.rd
%15 = icmp sle i32 %14, 0
br i1 %15, label %16, label %35
16: ; preds = %12
%17 = load i32, i32* @get_next_line.last
%18 = add nsw i32 %17, -1
store i32 %18, i32* @get_next_line.last
%19 = icmp ne i32 %17, 0
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%22 = load i32, i32* @get_next_line.rd
%23 = sub nsw i32 %21, %22
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %28, 10
br i1 %29, label %30, label %32
30: ; preds = %20
%31 = load i8*, i8** @get_next_line.res
br label %33
32: ; preds = %20, %16
br label %33
33: ; preds = %32, %30
%34 = phi i8* [ %31, %30 ], [ null, %32 ]
store i8* %34, i8** @get_next_line.res
store i8* %34, i8** %2
br label %105
35: ; preds = %12
%36 = load i32, i32* @get_next_line.rd
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %35, %1
%40 = load i32, i32* @get_next_line.i
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i8* @malloc(i32 6)
br label %47
44: ; preds = %39
%45 = load i8*, i8** @get_next_line.res
%46 = call i8* @my_realloc(i8* %45, i32 6)
br label %47
47: ; preds = %44, %42
%48 = phi i8* [ %43, %42 ], [ %46, %44 ]
store i8* %48, i8** @get_next_line.res
%49 = icmp eq i8* %48, null
br i1 %49, label %50, label %51
50: ; preds = %47
store i8* null, i8** %2
br label %105
51: ; preds = %47
br label %52
52: ; preds = %72, %51
%53 = call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%54 = load i32, i32* @get_next_line.rd
%55 = sub nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %70
61: ; preds = %52
%62 = call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%63 = load i32, i32* @get_next_line.rd
%64 = sub nsw i32 %62, %63
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp ne i32 %68, 10
br label %70
70: ; preds = %61, %52
%71 = phi i1 [ false, %52 ], [ %69, %61 ]
br i1 %71, label %72, label %85
72: ; preds = %70
%73 = call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%74 = load i32, i32* @get_next_line.rd
%75 = add nsw i32 %74, -1
store i32 %75, i32* @get_next_line.rd
%76 = sub nsw i32 %73, %74
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = load i8*, i8** @get_next_line.res
%81 = load i32, i32* @get_next_line.i
%82 = add nsw i32 %81, 1
store i32 %82, i32* @get_next_line.i
%83 = sext i32 %81 to i64
%84 = getelementptr inbounds i8, i8* %80, i64 %83
store i8 %79, i8* %84
br label %52
85: ; preds = %70
%86 = load i8*, i8** @get_next_line.res
%87 = load i32, i32* @get_next_line.i
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
store i8 0, i8* %89
%90 = call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%91 = load i32, i32* @get_next_line.rd
%92 = sub nsw i32 %90, %91
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %93
%95 = load i8, i8* %94
%96 = sext i8 %95 to i32
%97 = icmp eq i32 %96, 10
br i1 %97, label %98, label %102
98: ; preds = %85
store i32 0, i32* @get_next_line.i
%99 = load i32, i32* @get_next_line.rd
%100 = add nsw i32 %99, -1
store i32 %100, i32* @get_next_line.rd
%101 = load i8*, i8** @get_next_line.res
store i8* %101, i8** %2
br label %105
102: ; preds = %85
%103 = load i32, i32* %3
%104 = call i8* @get_next_line(i32 %103)
store i8* %104, i8** %2
br label %105
105: ; preds = %102, %98, %50, %33
%106 = load i8*, i8** %2
ret i8* %106
}

LLVM IR (-O2):
@get_next_line.last = internal unnamed_addr global i32 1
@get_next_line.rd = internal unnamed_addr global i32 0
@get_next_line.i = internal unnamed_addr global i32 0
@get_next_line.res = internal unnamed_addr global i8* null
@get_next_line.buf = internal global [5 x i8] zeroinitializer
define i8* @get_next_line(i32 %0) {
br label %2
2: ; preds = %80, %1
%3 = tail call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%4 = load i32, i32* @get_next_line.rd
%5 = sub nsw i32 %3, %4
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %2
%11 = tail call i32 @read(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0), i32 5)
store i32 %11, i32* @get_next_line.rd
%12 = icmp slt i32 %11, 1
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32, i32* @get_next_line.last
%15 = add nsw i32 %14, -1
store i32 %15, i32* @get_next_line.last
%16 = icmp eq i32 %14, 0
br i1 %16, label %28, label %17
17: ; preds = %13
%18 = tail call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%19 = load i32, i32* @get_next_line.rd
%20 = xor i32 %19, -1
%21 = add i32 %18, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 10
%26 = load i8*, i8** @get_next_line.res
%27 = select i1 %25, i8* null, i8* %26
br label %28
28: ; preds = %17, %13
%29 = phi i8* [ null, %13 ], [ %27, %17 ]
store i8* %29, i8** @get_next_line.res
br label %95
30: ; preds = %10
%31 = zext i32 %11 to i64
%32 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %30, %2
%34 = load i32, i32* @get_next_line.i
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = tail call dereferenceable_or_null(6) i8* @malloc(i32 6)
br label %41
38: ; preds = %33
%39 = load i8*, i8** @get_next_line.res
%40 = tail call i8* @my_realloc(i8* %39, i32 6)
br label %41
41: ; preds = %38, %36
%42 = phi i8* [ %37, %36 ], [ %40, %38 ]
store i8* %42, i8** @get_next_line.res
%43 = icmp eq i8* %42, null
br i1 %43, label %95, label %44
44: ; preds = %41
%45 = tail call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%46 = load i32, i32* @get_next_line.rd
%47 = sub nsw i32 %45, %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %48
%50 = load i8, i8* %49
%51 = icmp eq i8 %50, 0
br i1 %51, label %80, label %52
52: ; preds = %44, %60
%53 = tail call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%54 = load i32, i32* @get_next_line.rd
%55 = sub nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %56
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 10
br i1 %59, label %80, label %60
60: ; preds = %52
%61 = tail call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%62 = load i32, i32* @get_next_line.rd
%63 = add nsw i32 %62, -1
store i32 %63, i32* @get_next_line.rd
%64 = sub nsw i32 %61, %62
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = load i8*, i8** @get_next_line.res
%69 = load i32, i32* @get_next_line.i
%70 = add nsw i32 %69, 1
store i32 %70, i32* @get_next_line.i
%71 = sext i32 %69 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
store i8 %67, i8* %72
%73 = tail call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%74 = load i32, i32* @get_next_line.rd
%75 = sub nsw i32 %73, %74
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = icmp eq i8 %78, 0
br i1 %79, label %80, label %52
80: ; preds = %52, %60, %44
%81 = load i8*, i8** @get_next_line.res
%82 = load i32, i32* @get_next_line.i
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %81, i64 %83
store i8 0, i8* %84
%85 = tail call i32 @my_len(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 0))
%86 = load i32, i32* @get_next_line.rd
%87 = sub nsw i32 %85, %86
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [5 x i8], [5 x i8]* @get_next_line.buf, i64 0, i64 %88
%90 = load i8, i8* %89
%91 = icmp eq i8 %90, 10
br i1 %91, label %92, label %2
92: ; preds = %80
store i32 0, i32* @get_next_line.i
%93 = add nsw i32 %86, -1
store i32 %93, i32* @get_next_line.rd
%94 = load i8*, i8** @get_next_line.res
br label %95
95: ; preds = %41, %92, %28
%96 = phi i8* [ %29, %28 ], [ %94, %92 ], [ null, %41 ]
ret i8* %96
}