#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_END;
int /*<<< orphan*/ SEEK_SET;
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int parse_line_from_file_nolock(FILE *f, char **linep, int *sizep) {
  fseek(f, 0, SEEK_END);
  (*sizep) = ftell(f);
  (*linep) = (char *)malloc((*sizep) + 1);
  if ((*linep) == NULL)
    return 2;
  fseek(f, 0, SEEK_SET);
  int read = fread((*linep), 1, (*sizep), f);
  if (read < (*sizep)) {
    free((*linep));
    return 3;
  }
  (*linep)[*sizep] = 0;
  return 0;
}


x86 assembly (clang, -O0):
<parse_line_from_file_nolock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11bb <parse_line_from_file_nolock+0x6b>
movl   $0x2,-0x4(%rbp)
jmp    122d <parse_line_from_file_nolock+0xdd>
mov    -0x10(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%rcx
cmp    (%rcx),%eax
jge    1214 <parse_line_from_file_nolock+0xc4>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x3,-0x4(%rbp)
jmp    122d <parse_line_from_file_nolock+0xdd>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_line_from_file_nolock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,(%r15)
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     11c9 <parse_line_from_file_nolock+0x79>
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    (%r14),%rdi
mov    (%r15),%edx
mov    $0x1,%esi
mov    %rbx,%rcx
call   1040 <fread@plt>
movslq (%r15),%rcx
mov    (%r14),%rdi
cmp    %ecx,%eax
jge    11d0 <parse_line_from_file_nolock+0x80>
call   1030 <free@plt>
mov    $0x3,%ebp
jmp    11d4 <parse_line_from_file_nolock+0x84>
mov    $0x2,%ebp
jmp    11d4 <parse_line_from_file_nolock+0x84>
movb   $0x0,(%rdi,%rcx,1)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @parse_line_from_file_nolock(i32* %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %5
store i8** %1, i8*** %6
store i32* %2, i32** %7
%9 = load i32*, i32** %5
%10 = load i32, i32* @SEEK_END
%11 = call i32 @fseek(i32* %9, i32 0, i32 %10)
%12 = load i32*, i32** %5
%13 = call i32 @ftell(i32* %12)
%14 = load i32*, i32** %7
store i32 %13, i32* %14
%15 = load i32*, i32** %7
%16 = load i32, i32* %15
%17 = add nsw i32 %16, 1
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = load i8**, i8*** %6
store i8* %19, i8** %20
%21 = load i8**, i8*** %6
%22 = load i8*, i8** %21
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %25
24: ; preds = %3
store i32 2, i32* %4
br label %50
25: ; preds = %3
%26 = load i32*, i32** %5
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %26, i32 0, i32 %27)
%29 = load i8**, i8*** %6
%30 = load i8*, i8** %29
%31 = load i32*, i32** %7
%32 = load i32, i32* %31
%33 = load i32*, i32** %5
%34 = call i32 @fread(i8* %30, i32 1, i32 %32, i32* %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = load i32*, i32** %7
%37 = load i32, i32* %36
%38 = icmp slt i32 %35, %37
br i1 %38, label %39, label %43
39: ; preds = %25
%40 = load i8**, i8*** %6
%41 = load i8*, i8** %40
%42 = call i32 @free(i8* %41)
store i32 3, i32* %4
br label %50
43: ; preds = %25
%44 = load i8**, i8*** %6
%45 = load i8*, i8** %44
%46 = load i32*, i32** %7
%47 = load i32, i32* %46
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
store i8 0, i8* %49
store i32 0, i32* %4
br label %50
50: ; preds = %43, %39, %24
%51 = load i32, i32* %4
ret i32 %51
}

LLVM IR (-O2):
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @parse_line_from_file_nolock(i32* nocapture %0, i8** nocapture %1, i32* nocapture %2) {
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %0, i32 0, i32 %4)
%6 = tail call i32 @ftell(i32* %0)
store i32 %6, i32* %2
%7 = add nsw i32 %6, 1
%8 = tail call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %1
%10 = icmp eq i64 %8, 0
br i1 %10, label %25, label %11
11: ; preds = %3
%12 = load i32, i32* @SEEK_SET
%13 = tail call i32 @fseek(i32* %0, i32 0, i32 %12)
%14 = load i8*, i8** %1
%15 = load i32, i32* %2
%16 = tail call i32 @fread(i8* %14, i32 1, i32 %15, i32* %0)
%17 = load i32, i32* %2
%18 = icmp slt i32 %16, %17
%19 = load i8*, i8** %1
br i1 %18, label %20, label %22
20: ; preds = %11
%21 = tail call i32 @free(i8* %19)
br label %25
22: ; preds = %11
%23 = sext i32 %17 to i64
%24 = getelementptr inbounds i8, i8* %19, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %20, %22, %3
%26 = phi i32 [ 2, %3 ], [ 3, %20 ], [ 0, %22 ]
ret i32 %26
}