#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 */
size_t BUFSIZ;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *realloc(char *, size_t);
size_t strlen(char *);
char *get_line(FILE *f) {
  char *buf = NULL;
  char *new_buf = NULL;
  size_t buf_size = 0;
  size_t last = 0;
  while (!feof(f)) {
    buf_size = buf_size ? buf_size * 2 : BUFSIZ;
    new_buf = realloc(buf, buf_size);
    if (new_buf == NULL) {
      free(buf);
      return NULL;
    }
    buf = new_buf;
    if (fgets(buf + last, buf_size - last, f) == NULL) {
      free(buf);
      return NULL;
    }
    last = strlen(buf);
    if (buf[last - 1] == '\n')
      return buf;
  }
  return buf;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    119a <get_line+0x4a>
jmp    1277 <get_line+0x127>
cmpq   $0x0,-0x28(%rbp)
je     11b6 <get_line+0x66>
mov    -0x28(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11c4 <get_line+0x74>
mov    0x2e23(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11fe <get_line+0xae>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    127f <get_line+0x12f>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
sub    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
jne    123f <get_line+0xef>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    127f <get_line+0x12f>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1272 <get_line+0x122>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    127f <get_line+0x12f>
jmp    117c <get_line+0x2c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %r12d,%r12d
mov    0x2e78(%rip),%rbp
xor    %r15d,%r15d
xor    %r13d,%r13d
xchg   %ax,%ax
mov    %r14,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11d6 <get_line+0x86>
test   %r15,%r15
jne    1190 <get_line+0x40>
mov    0x0(%rbp),%r15
jmp    1193 <get_line+0x43>
nopw   0x0(%rax,%rax,1)
add    %r15,%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1070 <realloc@plt>
test   %rax,%rax
je     11db <get_line+0x8b>
mov    %rax,%rbx
mov    %rax,%rdi
add    %r13,%rdi
mov    %r15,%rsi
sub    %r13,%rsi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11e0 <get_line+0x90>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
cmpb   $0xa,-0x1(%rax,%rbx,1)
mov    %rbx,%r12
jne    1170 <get_line+0x20>
jmp    11ea <get_line+0x9a>
mov    %r12,%rbx
jmp    11ea <get_line+0x9a>
mov    %r12,%rdi
jmp    11e3 <get_line+0x93>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i64 0
define i8* @get_line(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32* %0, i32** %3
store i8* null, i8** %4
store i8* null, i8** %5
store i64 0, i64* %6
store i64 0, i64* %7
br label %8
8: ; preds = %57, %1
%9 = load i32*, i32** %3
%10 = call i32 @feof(i32* %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %58
13: ; preds = %8
%14 = load i64, i64* %6
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i64, i64* %6
%18 = mul i64 %17, 2
br label %21
19: ; preds = %13
%20 = load i64, i64* @BUFSIZ
br label %21
21: ; preds = %19, %16
%22 = phi i64 [ %18, %16 ], [ %20, %19 ]
store i64 %22, i64* %6
%23 = load i8*, i8** %4
%24 = load i64, i64* %6
%25 = call i8* @realloc(i8* %23, i64 %24)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i8*, i8** %4
%30 = call i32 @free(i8* %29)
store i8* null, i8** %2
br label %60
31: ; preds = %21
%32 = load i8*, i8** %5
store i8* %32, i8** %4
%33 = load i8*, i8** %4
%34 = load i64, i64* %7
%35 = getelementptr inbounds i8, i8* %33, i64 %34
%36 = load i64, i64* %6
%37 = load i64, i64* %7
%38 = sub i64 %36, %37
%39 = load i32*, i32** %3
%40 = call i32* @fgets(i8* %35, i64 %38, i32* %39)
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %45
42: ; preds = %31
%43 = load i8*, i8** %4
%44 = call i32 @free(i8* %43)
store i8* null, i8** %2
br label %60
45: ; preds = %31
%46 = load i8*, i8** %4
%47 = call i64 @strlen(i8* %46)
store i64 %47, i64* %7
%48 = load i8*, i8** %4
%49 = load i64, i64* %7
%50 = sub i64 %49, 1
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 10
br i1 %54, label %55, label %57
55: ; preds = %45
%56 = load i8*, i8** %4
store i8* %56, i8** %2
br label %60
57: ; preds = %45
br label %8
58: ; preds = %8
%59 = load i8*, i8** %4
store i8* %59, i8** %2
br label %60
60: ; preds = %58, %55, %42, %28
%61 = load i8*, i8** %2
ret i8* %61
}

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