#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 /*<<< orphan*/ free(char *);
size_t getline(char **, size_t *, int /*<<< orphan*/ *);
char *fgetln(FILE *fp, size_t *lenp) {
  char *__fgetln_int_buf = NULL;
  size_t __fgetln_int_len = 0;
  if (((*lenp) = getline(&__fgetln_int_buf, &__fgetln_int_len, fp)) == -1) {
    if (__fgetln_int_buf != NULL) {
      free(__fgetln_int_buf);
    }
    __fgetln_int_buf = NULL;
    __fgetln_int_len = 0;
    (*lenp) = 0;
  }
  return __fgetln_int_buf;
}


x86 assembly (clang, -O0):
<fgetln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <getline@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0xffffffffffffffff,%rax
jne    1191 <fgetln+0x71>
cmpq   $0x0,-0x18(%rbp)
je     1176 <fgetln+0x56>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetln>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rdx
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1040 <getline@plt>
mov    %rax,%rcx
mov    %rax,(%rbx)
mov    (%rsp),%rax
cmp    $0xffffffffffffffff,%rcx
jne    116f <fgetln+0x4f>
test   %rax,%rax
je     1166 <fgetln+0x46>
mov    %rax,%rdi
call   1030 <free@plt>
movq   $0x0,(%rbx)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i8* @fgetln(i32* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = call i64 @getline(i8** %3, i64* %4, i32* %0)
store i64 %7, i64* %1
%8 = icmp eq i64 %7, -1
%9 = load i8*, i8** %3
br i1 %8, label %10, label %15
10: ; preds = %2
%11 = icmp eq i8* %9, null
br i1 %11, label %14, label %12
12: ; preds = %10
%13 = call i32 @free(i8* %9)
br label %14
14: ; preds = %12, %10
store i64 0, i64* %1
br label %15
15: ; preds = %2, %14
%16 = phi i8* [ null, %14 ], [ %9, %2 ]
ret i8* %16
}