#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 */
scalar_t__ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *get_next_line_from_file(FILE *fp) {
  char *line = NULL;
  size_t l = 0;
  char c = 0;
  if (fp == NULL || feof(fp)) {
    return NULL;
  }
  line = (char *)malloc(0xffff);
  memset(line, 0, 0xffff);
  c = fgetc(fp);
  l = 0;
  while (!feof(fp) && c != '\n' && c != '\r') {
    line[l] = c;
    c = fgetc(fp);
    l = (l + 1) % 0xffff;
  }
  return line;
}


x86 assembly (clang, -O0):
<get_next_line_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117e <get_next_line_from_file+0x3e>
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     118b <get_next_line_from_file+0x4b>
movq   $0x0,-0x8(%rbp)
jmp    1244 <get_next_line_from_file+0x104>
mov    $0xffff,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xffff,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <feof@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x22(%rbp)
jne    11f7 <get_next_line_from_file+0xb7>
movsbl -0x21(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x22(%rbp)
je     11f7 <get_next_line_from_file+0xb7>
movsbl -0x21(%rbp),%eax
cmp    $0xd,%eax
setne  %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    1207 <get_next_line_from_file+0xc7>
jmp    123c <get_next_line_from_file+0xfc>
mov    -0x21(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    $0xffff,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x20(%rbp)
jmp    11bd <get_next_line_from_file+0x7d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line_from_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     115a <get_next_line_from_file+0x1a>
mov    %rdi,%r15
call   1050 <feof@plt>
test   %rax,%rax
je     1169 <get_next_line_from_file+0x29>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffff,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xffff,%edx
call   1030 <memset@plt>
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <feof@plt>
test   %rax,%rax
jne    115d <get_next_line_from_file+0x1d>
xor    %ebx,%ebx
mov    $0x80008001,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
cmp    $0xa,%bpl
je     115d <get_next_line_from_file+0x1d>
cmp    $0xd,%bpl
je     115d <get_next_line_from_file+0x1d>
mov    %bpl,(%r14,%rbx,1)
mov    %r15,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebp
add    $0x1,%rbx
mov    %ebx,%eax
imul   %r12,%rax
shr    $0x2f,%rax
mov    %eax,%ecx
shl    $0x10,%ecx
sub    %ecx,%eax
add    %eax,%ebx
mov    %r15,%rdi
call   1050 <feof@plt>
test   %rax,%rax
je     11b0 <get_next_line_from_file+0x70>
jmp    115d <get_next_line_from_file+0x1d>

LLVM IR (-O0):
define i8* @get_next_line_from_file(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8
store i32* %0, i32** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i8 0, i8* %6
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = call i64 @feof(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %9, %1
store i8* null, i8** %2
br label %47
14: ; preds = %9
%15 = call i64 @malloc(i32 65535)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %4
%17 = load i8*, i8** %4
%18 = call i32 @memset(i8* %17, i32 0, i32 65535)
%19 = load i32*, i32** %3
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %6
store i64 0, i64* %5
br label %21
21: ; preds = %35, %14
%22 = load i32*, i32** %3
%23 = call i64 @feof(i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %33, label %25
25: ; preds = %21
%26 = load i8, i8* %6
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 10
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i8, i8* %6
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 13
br label %33
33: ; preds = %29, %25, %21
%34 = phi i1 [ false, %25 ], [ false, %21 ], [ %32, %29 ]
br i1 %34, label %35, label %45
35: ; preds = %33
%36 = load i8, i8* %6
%37 = load i8*, i8** %4
%38 = load i64, i64* %5
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8 %36, i8* %39
%40 = load i32*, i32** %3
%41 = call signext i8 @fgetc(i32* %40)
store i8 %41, i8* %6
%42 = load i64, i64* %5
%43 = add i64 %42, 1
%44 = urem i64 %43, 65535
store i64 %44, i64* %5
br label %21
45: ; preds = %33
%46 = load i8*, i8** %4
store i8* %46, i8** %2
br label %47
47: ; preds = %45, %13
%48 = load i8*, i8** %2
ret i8* %48
}

LLVM IR (-O2):
define i8* @get_next_line_from_file(i32* %0) {
%2 = icmp eq i32* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = tail call i64 @feof(i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %23
6: ; preds = %3
%7 = tail call i64 @malloc(i32 65535)
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @memset(i8* %8, i32 0, i32 65535)
%10 = tail call signext i8 @fgetc(i32* %0)
%11 = tail call i64 @feof(i32* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %6, %16
%14 = phi i8 [ %18, %16 ], [ %10, %6 ]
%15 = phi i64 [ %20, %16 ], [ 0, %6 ]
switch i8 %14, label %16 [
i8 13, label %23
i8 10, label %23
]
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %8, i64 %15
store i8 %14, i8* %17
%18 = tail call signext i8 @fgetc(i32* %0)
%19 = add nuw nsw i64 %15, 1
%20 = urem i64 %19, 65535
%21 = tail call i64 @feof(i32* %0)
%22 = icmp eq i64 %21, 0
br i1 %22, label %13, label %23
23: ; preds = %13, %13, %16, %6, %1, %3
%24 = phi i8* [ null, %3 ], [ null, %1 ], [ %8, %6 ], [ %8, %16 ], [ %8, %13 ], [ %8, %13 ]
ret i8* %24
}