#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*/ SEEK_SET;
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int fread(char *, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseeko(int /*<<< orphan*/ *, size_t, int /*<<< orphan*/);
size_t ftello(int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ stderr;
char *FR_textline(FILE *stream) {
  char *result = NULL;
  int e;
  size_t len = 0;
  size_t offset = ftello(stream);
  char buf;
  do {
    buf = fgetc(stream);
    if (buf)
      ++len;
  } while (buf);
  fseeko(stream, offset, SEEK_SET);
  result = malloc(len + 1);
  if (result) {
    e = fread(result, len, 1, stream);
    if (!e)
      fputs("FR_textline couldn't read string when previously it could!\n",
            stderr);
    result[len] = 0;
  }
  return result;
}


x86 assembly (clang, -O0):
<FR_textline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <ftello@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %al,-0x29(%rbp)
cmpb   $0x0,-0x29(%rbp)
je     11ab <FR_textline+0x4b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11b0 <FR_textline+0x50>
cmpb   $0x0,-0x29(%rbp)
jne    1189 <FR_textline+0x29>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
call   1080 <fseeko@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1230 <FR_textline+0xd0>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1224 <FR_textline+0xc4>
mov    0x2dca(%rip),%rax
mov    (%rax),%esi
lea    0xde1(%rip),%rdi
call   1050 <fputs@plt>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FR_textline>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <ftello@plt>
mov    %rax,%r15
mov    $0xffffffffffffffff,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <fgetc@plt>
add    $0x1,%rbx
test   %al,%al
jne    1180 <FR_textline+0x20>
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <fseeko@plt>
lea    0x1(%rbx),%rdi
call   1070 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     11e6 <FR_textline+0x86>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jne    11e1 <FR_textline+0x81>
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
lea    0xe24(%rip),%rdi
call   1050 <fputs@plt>
movb   $0x0,(%r15,%rbx,1)
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [60 x i8] c"FR_textline couldn't read string when previously it could!\0A\00"
@stderr = global i32 0
define i8* @FR_textline(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i8
store i32* %0, i32** %2
store i8* null, i8** %3
store i64 0, i64* %5
%8 = load i32*, i32** %2
%9 = call i64 @ftello(i32* %8)
store i64 %9, i64* %6
br label %10
10: ; preds = %19, %1
%11 = load i32*, i32** %2
%12 = call signext i8 @fgetc(i32* %11)
store i8 %12, i8* %7
%13 = load i8, i8* %7
%14 = icmp ne i8 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i64, i64* %5
%17 = add i64 %16, 1
store i64 %17, i64* %5
br label %18
18: ; preds = %15, %10
br label %19
19: ; preds = %18
%20 = load i8, i8* %7
%21 = icmp ne i8 %20, 0
br i1 %21, label %10, label %22
22: ; preds = %19
%23 = load i32*, i32** %2
%24 = load i64, i64* %6
%25 = load i32, i32* @SEEK_SET
%26 = call i32 @fseeko(i32* %23, i64 %24, i32 %25)
%27 = load i64, i64* %5
%28 = add i64 %27, 1
%29 = call i8* @malloc(i64 %28)
store i8* %29, i8** %3
%30 = load i8*, i8** %3
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %46
32: ; preds = %22
%33 = load i8*, i8** %3
%34 = load i64, i64* %5
%35 = load i32*, i32** %2
%36 = call i32 @fread(i8* %33, i64 %34, i32 1, i32* %35)
store i32 %36, i32* %4
%37 = load i32, i32* %4
%38 = icmp ne i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %32
%40 = load i32, i32* @stderr
%41 = call i32 @fputs(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %32
%43 = load i8*, i8** %3
%44 = load i64, i64* %5
%45 = getelementptr inbounds i8, i8* %43, i64 %44
store i8 0, i8* %45
br label %46
46: ; preds = %42, %22
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [60 x i8] c"FR_textline couldn't read string when previously it could!\0A\00"
@stderr = global i32 0
define noalias i8* @FR_textline(i32* nocapture %0) {
%2 = tail call i64 @ftello(i32* %0)
br label %3
3: ; preds = %3, %1
%4 = phi i64 [ 0, %1 ], [ %7, %3 ]
%5 = tail call signext i8 @fgetc(i32* %0)
%6 = icmp eq i8 %5, 0
%7 = add i64 %4, 1
br i1 %6, label %8, label %3
8: ; preds = %3
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseeko(i32* %0, i64 %2, i32 %9)
%11 = tail call i8* @malloc(i64 %7)
%12 = icmp eq i8* %11, null
br i1 %12, label %21, label %13
13: ; preds = %8
%14 = tail call i32 @fread(i8* %11, i64 %4, i32 1, i32* %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i32 @fputs(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %13
%20 = getelementptr inbounds i8, i8* %11, i64 %4
store i8 0, i8* %20
br label %21
21: ; preds = %19, %8
ret i8* %11
}