#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 EOF;
int /*<<< orphan*/ free(char *);
int getc(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
scalar_t__ realloc(char *, size_t);
char *read_file_line(FILE *strm) {
  size_t i = 0;
  size_t len = 8;
  char *rv = (char *)malloc(len);
  int tmp;
  while (1) {
    if (i == len) {
      len *= 2;
      rv = (char *)realloc(rv, len);
    }
    tmp = getc(strm);
    if ((tmp == EOF) && (i == 0)) {
      free(rv);
      return NULL;
    }
    if ((tmp == '\n') || (tmp == EOF)) {
      rv[i] = '\0';
      return rv;
    }
    rv[i++] = tmp;
  }
}


x86 assembly (clang, -O0):
<read_file_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x8,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1194 <read_file_line+0x54>
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e3e(%rip),%rcx
cmp    (%rcx),%eax
jne    11d3 <read_file_line+0x93>
cmpq   $0x0,-0x18(%rbp)
jne    11d3 <read_file_line+0x93>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1228 <read_file_line+0xe8>
cmpl   $0xa,-0x2c(%rbp)
je     11ef <read_file_line+0xaf>
mov    -0x2c(%rbp),%eax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%eax
jne    1208 <read_file_line+0xc8>
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1228 <read_file_line+0xe8>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x18(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    1169 <read_file_line+0x29>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x8,%r13d
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
xor    %ebx,%ebx
mov    0x2e7e(%rip),%r12
xor    %ebp,%ebp
cmp    %r13,%rbp
jne    1191 <read_file_line+0x51>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %rax,%r15
mov    %rbx,%r13
mov    %r14,%rdi
call   1060 <getc@plt>
mov    (%r12),%ecx
cmp    %ecx,%eax
jne    11a6 <read_file_line+0x66>
test   %rbp,%rbp
je     11c2 <read_file_line+0x82>
cmp    $0xa,%eax
je     11cf <read_file_line+0x8f>
cmp    %ecx,%eax
je     11cf <read_file_line+0x8f>
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
add    $0x2,%rbx
cmp    %r13,%rbp
je     1180 <read_file_line+0x40>
jmp    1191 <read_file_line+0x51>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %r15d,%r15d
jmp    11d4 <read_file_line+0x94>
movb   $0x0,(%r15,%rbp,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @read_file_line(i32* nocapture %0) {
%2 = tail call i64 @malloc(i64 8)
%3 = inttoptr i64 %2 to i8*
br label %4
4: ; preds = %28, %1
%5 = phi i64 [ 0, %1 ], [ %30, %28 ]
%6 = phi i64 [ 8, %1 ], [ %14, %28 ]
%7 = phi i8* [ %3, %1 ], [ %15, %28 ]
%8 = icmp eq i64 %5, %6
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = shl i64 %5, 1
%11 = tail call i64 @realloc(i8* %7, i64 %10)
%12 = inttoptr i64 %11 to i8*
br label %13
13: ; preds = %9, %4
%14 = phi i64 [ %10, %9 ], [ %6, %4 ]
%15 = phi i8* [ %12, %9 ], [ %7, %4 ]
%16 = tail call i32 @getc(i32* %0)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
%19 = icmp eq i64 %5, 0
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = tail call i32 @free(i8* %15)
br label %32
23: ; preds = %13
%24 = icmp eq i32 %16, 10
%25 = select i1 %24, i1 true, i1 %18
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = getelementptr inbounds i8, i8* %15, i64 %5
store i8 0, i8* %27
br label %32
28: ; preds = %23
%29 = trunc i32 %16 to i8
%30 = add i64 %5, 1
%31 = getelementptr inbounds i8, i8* %15, i64 %5
store i8 %29, i8* %31
br label %4
32: ; preds = %26, %21
%33 = phi i8* [ null, %21 ], [ %15, %26 ]
ret i8* %33
}