#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*/ tmpCharacter;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
char EOF;
int /*<<< orphan*/ free(char *);
char getc(int /*<<< orphan*/ *);
char *realloc(char *, size_t);
char *getLine(FILE *stream) {
  char *lineOld = NULL, *lineUpdated = NULL;
  size_t tmpSize = 0;
  int index = 0;
  char tmpCharacter;
  while (1) {
    tmpCharacter = getc(stream);
    tmpSize += sizeof(tmpCharacter);
    lineUpdated = realloc(lineOld, tmpSize);
    if (lineUpdated == NULL) {
      free(lineOld);
      lineOld = lineUpdated;
      break;
    } else {
      lineOld = lineUpdated;
    }
    if (tmpCharacter == EOF || tmpCharacter == '\n') {
      lineOld[index] = '\0';
      break;
    } else {
      lineOld[index++] = tmpCharacter;
    }
  }
  return lineOld;
}


x86 assembly (clang, -O0):
<getLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %al,-0x25(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a5 <getLine+0x75>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    11fe <getLine+0xce>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsbl -0x25(%rbp),%eax
mov    0x2e30(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11d0 <getLine+0xa0>
movsbl -0x25(%rbp),%eax
cmp    $0xa,%eax
jne    11e1 <getLine+0xb1>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11fe <getLine+0xce>
mov    -0x25(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    115b <getLine+0x2b>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1060 <getc@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     11ad <getLine+0x6d>
mov    %rax,%r15
xor    %ebx,%ebx
mov    0x2e78(%rip),%r12
cmp    $0xa,%bpl
je     11b9 <getLine+0x79>
cmp    (%r12),%bpl
je     11b9 <getLine+0x79>
lea    0x1(%rbx),%r13
mov    %bpl,(%r15,%rbx,1)
mov    %r14,%rdi
call   1060 <getc@plt>
mov    %eax,%ebp
add    $0x2,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <realloc@plt>
mov    %r15,%rdi
mov    %r13,%rbx
mov    %rax,%r15
test   %rax,%rax
jne    1170 <getLine+0x30>
jmp    11af <getLine+0x6f>
xor    %edi,%edi
call   1030 <free@plt>
xor    %r15d,%r15d
jmp    11c0 <getLine+0x80>
mov    %ebx,%eax
movb   $0x0,(%r15,%rax,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 i8 0
define i8* @getLine(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca i8
store i32* %0, i32** %2
store i8* null, i8** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i32 0, i32* %6
br label %8
8: ; preds = %1, %46
%9 = load i32*, i32** %2
%10 = call signext i8 @getc(i32* %9)
store i8 %10, i8* %7
%11 = load i64, i64* %5
%12 = add i64 %11, 1
store i64 %12, i64* %5
%13 = load i8*, i8** %3
%14 = load i64, i64* %5
%15 = call i8* @realloc(i8* %13, i64 %14)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %8
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
%21 = load i8*, i8** %4
store i8* %21, i8** %3
br label %47
22: ; preds = %8
%23 = load i8*, i8** %4
store i8* %23, i8** %3
br label %24
24: ; preds = %22
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = load i8, i8* @EOF
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %26, %28
br i1 %29, label %34, label %30
30: ; preds = %24
%31 = load i8, i8* %7
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 10
br i1 %33, label %34, label %39
34: ; preds = %30, %24
%35 = load i8*, i8** %3
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 0, i8* %38
br label %47
39: ; preds = %30
%40 = load i8, i8* %7
%41 = load i8*, i8** %3
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
%44 = sext i32 %42 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 %40, i8* %45
br label %46
46: ; preds = %39
br label %8
47: ; preds = %34, %18
%48 = load i8*, i8** %3
ret i8* %48
}

LLVM IR (-O2):
@EOF = global i8 0
define noalias i8* @getLine(i32* nocapture %0) {
%2 = tail call signext i8 @getc(i32* %0)
%3 = tail call dereferenceable_or_null(1) i8* @malloc(i64 1)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %8
5: ; preds = %20, %1
%6 = phi i8* [ null, %1 ], [ %10, %20 ]
%7 = tail call i32 @free(i8* %6)
br label %27
8: ; preds = %1, %20
%9 = phi i64 [ %21, %20 ], [ 0, %1 ]
%10 = phi i8* [ %25, %20 ], [ %3, %1 ]
%11 = phi i64 [ %24, %20 ], [ 1, %1 ]
%12 = phi i8 [ %23, %20 ], [ %2, %1 ]
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
%15 = icmp eq i8 %12, 10
%16 = or i1 %15, %14
br i1 %16, label %17, label %20
17: ; preds = %8
%18 = and i64 %9, 4294967295
%19 = getelementptr inbounds i8, i8* %10, i64 %18
store i8 0, i8* %19
br label %27
20: ; preds = %8
%21 = add nuw i64 %9, 1
%22 = getelementptr inbounds i8, i8* %10, i64 %9
store i8 %12, i8* %22
%23 = tail call signext i8 @getc(i32* %0)
%24 = add nuw i64 %11, 1
%25 = tail call i8* @realloc(i8* %10, i64 %24)
%26 = icmp eq i8* %25, null
br i1 %26, label %5, label %8
27: ; preds = %17, %5
%28 = phi i8* [ %10, %17 ], [ null, %5 ]
ret i8* %28
}