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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *fgetln_(FILE *stream, size_t *len) {
  static char *linep = NULL;
  static size_t linecap = 0;
  ssize_t length = getline(&linep, &linecap, stream);
  if (length == -1) {
    free(linep);
    linep = NULL;
    linecap = 0;
    length = 0;
  }
  if (len)
    *len = length;
  return linep;
}


x86 assembly (clang, -O0):
<fgetln_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
lea    0x2efd(%rip),%rdi
lea    0x2efe(%rip),%rsi
call   1040 <getline@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    117d <fgetln_+0x5d>
mov    0x2edd(%rip),%rdi
call   1030 <free@plt>
movq   $0x0,0x2ecd(%rip)
movq   $0x0,0x2eca(%rip)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1193 <fgetln_+0x73>
movslq -0x14(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e9e(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetln_>:
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rdx
lea    0x2f0a(%rip),%rdi
lea    0x2f0b(%rip),%rsi
call   1040 <getline@plt>
cmp    $0xffffffff,%eax
je     1152 <fgetln_+0x32>
test   %rbx,%rbx
je     1149 <fgetln_+0x29>
cltq
mov    %rax,(%rbx)
mov    0x2ee8(%rip),%rax
pop    %rbx
ret
mov    0x2edf(%rip),%rdi
call   1030 <free@plt>
movq   $0x0,0x2ecf(%rip)
movq   $0x0,0x2ecc(%rip)
xor    %eax,%eax
test   %rbx,%rbx
jne    1144 <fgetln_+0x24>
jmp    1149 <fgetln_+0x29>

LLVM IR (-O0):
@fgetln_.linep = internal global i8* null
@fgetln_.linecap = internal global i64 0
define i8* @fgetln_(i32* %0, i64* %1) {
%3 = alloca i32*
%4 = alloca i64*
%5 = alloca i32
store i32* %0, i32** %3
store i64* %1, i64** %4
%6 = load i32*, i32** %3
%7 = call i32 @getline(i8** @fgetln_.linep, i64* @fgetln_.linecap, i32* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** @fgetln_.linep
%12 = call i32 @free(i8* %11)
store i8* null, i8** @fgetln_.linep
store i64 0, i64* @fgetln_.linecap
store i32 0, i32* %5
br label %13
13: ; preds = %10, %2
%14 = load i64*, i64** %4
%15 = icmp ne i64* %14, null
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = load i64*, i64** %4
store i64 %18, i64* %19
br label %20
20: ; preds = %16, %13
%21 = load i8*, i8** @fgetln_.linep
ret i8* %21
}

LLVM IR (-O2):
@fgetln_.linep = internal global i8* null
@fgetln_.linecap = internal global i64 0
define i8* @fgetln_(i32* %0, i64* writeonly %1) {
%3 = tail call i32 @getline(i8** @fgetln_.linep, i64* @fgetln_.linecap, i32* %0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i8*, i8** @fgetln_.linep
%7 = tail call i32 @free(i8* %6)
store i8* null, i8** @fgetln_.linep
store i64 0, i64* @fgetln_.linecap
br label %8
8: ; preds = %5, %2
%9 = phi i32 [ 0, %5 ], [ %3, %2 ]
%10 = icmp eq i64* %1, null
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = sext i32 %9 to i64
store i64 %12, i64* %1
br label %13
13: ; preds = %11, %8
%14 = load i8*, i8** @fgetln_.linep
ret i8* %14
}