#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 */
char EOF;
char fgetc(int /*<<< orphan*/ *);
scalar_t__ malloc(unsigned int);
char *realloc(char *, unsigned int);
char *get_line(FILE *file) {
  char ch;
  unsigned int buff_length = 16;
  unsigned int line_length = 0;
  char *buff = (char *)malloc(buff_length);
  while (EOF != (ch = fgetc(file))) {
    if (ch == '\n')
      break;
    buff[line_length] = ch;
    line_length++;
    if (line_length == buff_length - 1) {
      buff_length *= 2;
      buff = realloc(buff, buff_length);
    }
  }
  buff = realloc(buff, line_length + 1);
  buff[line_length] = '\0';
  return buff;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x10,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e8b(%rip),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,%cl
mov    -0x24(%rbp),%eax
mov    %cl,-0x9(%rbp)
movsbl %cl,%ecx
cmp    %ecx,%eax
je     11d6 <get_line+0xa6>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1191 <get_line+0x61>
jmp    11d6 <get_line+0xa6>
mov    -0x9(%rbp),%dl
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11d1 <get_line+0xa1>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
jmp    1156 <get_line+0x26>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1050 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x30,%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
mov    $0x10,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    0x2e96(%rip),%r13
mov    0x0(%r13),%bl
mov    %r14,%rdi
call   1030 <fgetc@plt>
xor    %ebp,%ebp
cmp    %al,%bl
je     11a8 <get_line+0x78>
cmp    $0xa,%al
je     11a8 <get_line+0x78>
mov    $0x10,%r12d
xor    %ebp,%ebp
mov    %ebp,%ecx
mov    %al,(%r15,%rcx,1)
add    $0x1,%ebp
lea    -0x1(%r12),%eax
cmp    %eax,%ebp
jne    1193 <get_line+0x63>
add    %r12d,%r12d
mov    %r15,%rdi
mov    %r12d,%esi
call   1050 <realloc@plt>
mov    %rax,%r15
movzbl 0x0(%r13),%ebx
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    %al,%bl
je     11a8 <get_line+0x78>
cmp    $0xa,%al
jne    1170 <get_line+0x40>
lea    0x1(%rbp),%esi
mov    %r15,%rdi
call   1050 <realloc@plt>
mov    %ebp,%ecx
movb   $0x0,(%rax,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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