#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(unsigned char *);
int getc(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
scalar_t__ realloc(void *, int);
int /*<<< orphan*/ stderr;
unsigned char *get_line(FILE *fp, int c) {
  int len = 1;
  unsigned char *line = (unsigned char *)malloc(len);
  int index = 0;
  while (1) {
    if (!line) {
      fprintf(stderr, "Out of memory.\n");
      exit(1);
    }
    line[index++] = c;
    if (c == '\n')
      break;
    c = getc(fp);
    if (c == EOF) {
      free(line);
      return (unsigned char *)0;
    }
    if (index >= len) {
      len = 2 * len;
      line = (unsigned char *)realloc((void *)line, len);
    }
  }
  return line;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b3 <get_line+0x53>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0xa,-0x14(%rbp)
jne    11dc <get_line+0x7c>
jmp    123a <get_line+0xda>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2df6(%rip),%rcx
cmp    (%rcx),%eax
jne    1210 <get_line+0xb0>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1242 <get_line+0xe2>
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jl     1235 <get_line+0xd5>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x20(%rbp)
jmp    1189 <get_line+0x29>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%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    %esi,%ebp
mov    %rdi,%r14
mov    $0x1,%r15d
mov    $0x1,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11fa <get_line+0x9a>
mov    %rax,%r12
xor    %ebx,%ebx
mov    0x2e57(%rip),%r13
jmp    11a9 <get_line+0x49>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%rbx
test   %r12,%r12
je     11fa <get_line+0x9a>
mov    %bpl,(%r12,%rbx,1)
cmp    $0xa,%ebp
je     11e8 <get_line+0x88>
mov    %r14,%rdi
call   1080 <getc@plt>
cmp    0x0(%r13),%eax
je     11dd <get_line+0x7d>
mov    %eax,%ebp
lea    0x1(%rbx),%eax
cmp    %eax,%r15d
jg     11a0 <get_line+0x40>
add    %r15d,%r15d
mov    %r12,%rdi
mov    %r15d,%esi
call   1060 <realloc@plt>
mov    %rax,%r12
jmp    11a0 <get_line+0x40>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"Out of memory.\0A\00"
@EOF = global i32 0
define i8* @get_line(i32* nocapture %0, i32 %1) {
%3 = tail call i64 @malloc(i32 1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = inttoptr i64 %3 to i8*
br label %11
7: ; preds = %33, %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %5, %33
%12 = phi i64 [ 0, %5 ], [ %17, %33 ]
%13 = phi i8* [ %6, %5 ], [ %35, %33 ]
%14 = phi i32 [ 1, %5 ], [ %34, %33 ]
%15 = phi i32 [ %1, %5 ], [ %21, %33 ]
%16 = trunc i32 %15 to i8
%17 = add nuw i64 %12, 1
%18 = getelementptr inbounds i8, i8* %13, i64 %12
store i8 %16, i8* %18
%19 = icmp eq i32 %15, 10
br i1 %19, label %37, label %20
20: ; preds = %11
%21 = tail call i32 @getc(i32* %0)
%22 = load i32, i32* @EOF
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @free(i8* %13)
br label %37
26: ; preds = %20
%27 = trunc i64 %17 to i32
%28 = icmp sgt i32 %14, %27
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = shl nsw i32 %14, 1
%31 = tail call i64 @realloc(i8* %13, i32 %30)
%32 = inttoptr i64 %31 to i8*
br label %33
33: ; preds = %29, %26
%34 = phi i32 [ %30, %29 ], [ %14, %26 ]
%35 = phi i8* [ %32, %29 ], [ %13, %26 ]
%36 = icmp eq i8* %35, null
br i1 %36, label %7, label %11
37: ; preds = %11, %24
%38 = phi i8* [ null, %24 ], [ %13, %11 ]
ret i8* %38
}