#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int GetLineWithChars(int /*<<< orphan*/ *, int, char *);
int /*<<< orphan*/ assert(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
char *realloc(char *, int);
char *FKO_ReadLine(FILE *fp) {
  int i;
  static int len = 0;
  static char *ln = NULL;
  if (!fp) {
    if (ln)
      free(ln);
    len = 0;
    return (NULL);
  }
  if (!len) {
    ln = malloc(128);
    len = 128;
    assert(ln);
  }
  i = GetLineWithChars(fp, len, ln);
  if (!i)
    return (NULL);
  while (ln[i - 1] != '\n') {
    int len2;
    len2 = len + len;
    ln = realloc(ln, len2);
    assert(ln);
    if (!fgets(ln + i, len, fp))
      break;
    len = len2;
    for (; ln[i]; i++)
      ;
  }
  return (ln);
}


x86 assembly (clang, -O0):
<FKO_ReadLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a8 <FKO_ReadLine+0x48>
cmpq   $0x0,0x2ee1(%rip)
je     1191 <FKO_ReadLine+0x31>
mov    0x2ed4(%rip),%rdi
call   1030 <free@plt>
movl   $0x0,0x2ebd(%rip)
movq   $0x0,-0x8(%rbp)
jmp    12cb <FKO_ReadLine+0x16b>
cmpl   $0x0,0x2ea9(%rip)
jne    11dc <FKO_ReadLine+0x7c>
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,0x2e9a(%rip)
movl   $0x80,0x2e88(%rip)
mov    0x2e89(%rip),%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e72(%rip),%esi
mov    0x2e73(%rip),%rdx
call   1040 <GetLineWithChars@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    120c <FKO_ReadLine+0xac>
movq   $0x0,-0x8(%rbp)
jmp    12cb <FKO_ReadLine+0x16b>
jmp    1211 <FKO_ReadLine+0xb1>
mov    0x2e48(%rip),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     12c0 <FKO_ReadLine+0x160>
mov    0x2e24(%rip),%eax
add    0x2e1e(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e1c(%rip),%rdi
mov    -0x18(%rbp),%esi
call   1080 <realloc@plt>
mov    %rax,0x2e0d(%rip)
mov    0x2e06(%rip),%rdi
call   1060 <assert@plt>
mov    0x2dfa(%rip),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    0x2de5(%rip),%esi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    128a <FKO_ReadLine+0x12a>
jmp    12c0 <FKO_ReadLine+0x160>
mov    -0x18(%rbp),%eax
mov    %eax,0x2dc5(%rip)
mov    0x2dc6(%rip),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     12bb <FKO_ReadLine+0x15b>
jmp    12ad <FKO_ReadLine+0x14d>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1293 <FKO_ReadLine+0x133>
jmp    1211 <FKO_ReadLine+0xb1>
mov    0x2d99(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FKO_ReadLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     127c <FKO_ReadLine+0x11c>
mov    %rdi,%r14
mov    0x2edb(%rip),%esi
test   %esi,%esi
jne    11aa <FKO_ReadLine+0x4a>
mov    $0x80,%edi
call   1070 <malloc@plt>
mov    %rax,0x2ece(%rip)
movl   $0x80,0x2ebc(%rip)
mov    %rax,%rdi
call   1060 <assert@plt>
mov    0x2eae(%rip),%esi
mov    0x2eaf(%rip),%rdx
mov    %r14,%rdi
call   1040 <GetLineWithChars@plt>
test   %eax,%eax
je     1297 <FKO_ReadLine+0x137>
mov    %eax,%ebx
mov    0x2e96(%rip),%rdi
cltq
cmpb   $0xa,-0x1(%rax,%rdi,1)
je     1299 <FKO_ReadLine+0x139>
mov    0x2e7a(%rip),%r12d
movabs $0xfffffffe00000000,%r15
ff ff ff
movabs $0x100000000,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %r12d,%r12d
mov    %r12d,%esi
call   1080 <realloc@plt>
mov    %rax,0x2e4e(%rip)
mov    %rax,%rdi
call   1060 <assert@plt>
movslq %ebx,%rbp
mov    0x2e3c(%rip),%rdi
add    %rbp,%rdi
mov    0x2e2b(%rip),%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     12ab <FKO_ReadLine+0x14b>
mov    %r12d,0x2e18(%rip)
mov    0x2e19(%rip),%rdi
mov    %rbp,%rax
shl    $0x20,%rax
add    %r15,%rax
lea    -0x1(%rbp),%ebx
add    %rdi,%rbp
nopw   0x0(%rax,%rax,1)
add    %r13,%rax
add    $0x1,%ebx
cmpb   $0x0,0x0(%rbp)
lea    0x1(%rbp),%rbp
jne    1260 <FKO_ReadLine+0x100>
sar    $0x20,%rax
cmpb   $0xa,(%rdi,%rax,1)
jne    1200 <FKO_ReadLine+0xa0>
jmp    1299 <FKO_ReadLine+0x139>
mov    0x2ddd(%rip),%rdi
test   %rdi,%rdi
je     128d <FKO_ReadLine+0x12d>
call   1030 <free@plt>
movl   $0x0,0x2dc1(%rip)
xor    %edi,%edi
mov    %rdi,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dae(%rip),%rdi
jmp    1299 <FKO_ReadLine+0x139>

LLVM IR (-O0):
@FKO_ReadLine.len = internal global i32 0
@FKO_ReadLine.ln = internal global i8* null
define i8* @FKO_ReadLine(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %15, label %8
8: ; preds = %1
%9 = load i8*, i8** @FKO_ReadLine.ln
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i8*, i8** @FKO_ReadLine.ln
%13 = call i32 @free(i8* %12)
br label %14
14: ; preds = %11, %8
store i32 0, i32* @FKO_ReadLine.len
store i8* null, i8** %2
br label %74
15: ; preds = %1
%16 = load i32, i32* @FKO_ReadLine.len
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = call i8* @malloc(i32 128)
store i8* %19, i8** @FKO_ReadLine.ln
store i32 128, i32* @FKO_ReadLine.len
%20 = load i8*, i8** @FKO_ReadLine.ln
%21 = call i32 @assert(i8* %20)
br label %22
22: ; preds = %18, %15
%23 = load i32*, i32** %3
%24 = load i32, i32* @FKO_ReadLine.len
%25 = load i8*, i8** @FKO_ReadLine.ln
%26 = call i32 @GetLineWithChars(i32* %23, i32 %24, i8* %25)
store i32 %26, i32* %4
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %22
store i8* null, i8** %2
br label %74
30: ; preds = %22
br label %31
31: ; preds = %71, %30
%32 = load i8*, i8** @FKO_ReadLine.ln
%33 = load i32, i32* %4
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %32, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 10
br i1 %39, label %40, label %72
40: ; preds = %31
%41 = load i32, i32* @FKO_ReadLine.len
%42 = load i32, i32* @FKO_ReadLine.len
%43 = add nsw i32 %41, %42
store i32 %43, i32* %5
%44 = load i8*, i8** @FKO_ReadLine.ln
%45 = load i32, i32* %5
%46 = call i8* @realloc(i8* %44, i32 %45)
store i8* %46, i8** @FKO_ReadLine.ln
%47 = load i8*, i8** @FKO_ReadLine.ln
%48 = call i32 @assert(i8* %47)
%49 = load i8*, i8** @FKO_ReadLine.ln
%50 = load i32, i32* %4
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i32, i32* @FKO_ReadLine.len
%54 = load i32*, i32** %3
%55 = call i32 @fgets(i8* %52, i32 %53, i32* %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %58, label %57
57: ; preds = %40
br label %72
58: ; preds = %40
%59 = load i32, i32* %5
store i32 %59, i32* @FKO_ReadLine.len
br label %60
60: ; preds = %68, %58
%61 = load i8*, i8** @FKO_ReadLine.ln
%62 = load i32, i32* %4
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = icmp ne i8 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %60
br label %68
68: ; preds = %67
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %60
71: ; preds = %60
br label %31
72: ; preds = %57, %31
%73 = load i8*, i8** @FKO_ReadLine.ln
store i8* %73, i8** %2
br label %74
74: ; preds = %72, %29, %14
%75 = load i8*, i8** %2
ret i8* %75
}

LLVM IR (-O2):
@FKO_ReadLine.len = internal unnamed_addr global i32 0
@FKO_ReadLine.ln = internal unnamed_addr global i8* null
define i8* @FKO_ReadLine(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %3, label %9
3: ; preds = %1
%4 = load i8*, i8** @FKO_ReadLine.ln
%5 = icmp eq i8* %4, null
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = tail call i32 @free(i8* %4)
br label %8
8: ; preds = %6, %3
store i32 0, i32* @FKO_ReadLine.len
br label %61
9: ; preds = %1
%10 = load i32, i32* @FKO_ReadLine.len
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
store i8* %13, i8** @FKO_ReadLine.ln
store i32 128, i32* @FKO_ReadLine.len
%14 = tail call i32 @assert(i8* %13)
%15 = load i32, i32* @FKO_ReadLine.len
br label %16
16: ; preds = %12, %9
%17 = phi i32 [ %15, %12 ], [ %10, %9 ]
%18 = load i8*, i8** @FKO_ReadLine.ln
%19 = tail call i32 @GetLineWithChars(i32* %0, i32 %17, i8* %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %61, label %21
21: ; preds = %16
%22 = load i8*, i8** @FKO_ReadLine.ln
%23 = add nsw i32 %19, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 10
br i1 %27, label %61, label %28
28: ; preds = %21
%29 = load i32, i32* @FKO_ReadLine.len
br label %38
30: ; preds = %55
%31 = trunc i64 %56 to i32
%32 = shl i64 %56, 32
%33 = add i64 %32, -4294967296
%34 = ashr exact i64 %33, 32
%35 = getelementptr inbounds i8, i8* %54, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 10
br i1 %37, label %61, label %38
38: ; preds = %28, %30
%39 = phi i32 [ %42, %30 ], [ %29, %28 ]
%40 = phi i8* [ %54, %30 ], [ %22, %28 ]
%41 = phi i32 [ %31, %30 ], [ %19, %28 ]
%42 = shl nsw i32 %39, 1
%43 = tail call i8* @realloc(i8* %40, i32 %42)
store i8* %43, i8** @FKO_ReadLine.ln
%44 = tail call i32 @assert(i8* %43)
%45 = load i8*, i8** @FKO_ReadLine.ln
%46 = sext i32 %41 to i64
%47 = getelementptr inbounds i8, i8* %45, i64 %46
%48 = load i32, i32* @FKO_ReadLine.len
%49 = tail call i32 @fgets(i8* %47, i32 %48, i32* %0)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %38
%52 = load i8*, i8** @FKO_ReadLine.ln
br label %61
53: ; preds = %38
store i32 %42, i32* @FKO_ReadLine.len
%54 = load i8*, i8** @FKO_ReadLine.ln
br label %55
55: ; preds = %55, %53
%56 = phi i64 [ %60, %55 ], [ %46, %53 ]
%57 = getelementptr inbounds i8, i8* %54, i64 %56
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 0
%60 = add i64 %56, 1
br i1 %59, label %30, label %55
61: ; preds = %30, %21, %51, %16, %8
%62 = phi i8* [ null, %8 ], [ null, %16 ], [ %22, %21 ], [ %52, %51 ], [ %54, %30 ]
ret i8* %62
}