#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ feof(int /*<<< orphan*/);
char *fgets(char *, unsigned long, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ malloc(unsigned long);
char *realloc(char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
char *getline_unlim() {
  enum { FGETS_BUFSIZE = 30 };
  int flag_newline = 0;
  unsigned long block_size = FGETS_BUFSIZE;
  char *line = (char *)malloc(block_size * sizeof(char));
  char *character;
  char *result;
  while (!flag_newline && !feof(stdin)) {
    result = fgets(line + strlen(line), block_size, stdin);
    if (!result) {
      if (!feof(stdin)) {
        fprintf(stderr, "%s", strerror(errno));
        exit(EXIT_FAILURE);
      }
    } else {
      character = strchr(line, '\n');
      if (character) {
        *character = '\0';
        flag_newline = 1;
      } else {
        block_size *= 2;
        line = realloc(line, strlen(line) + block_size);
      }
    }
  }
  return line;
}


x86 assembly (clang, -O0):
<getline_unlim>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1e,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
shl    $0x0,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x4(%rbp)
mov    %al,-0x29(%rbp)
jne    11e0 <getline_unlim+0x50>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11f0 <getline_unlim+0x60>
jmp    12ed <getline_unlim+0x15d>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    0x2dd3(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1281 <getline_unlim+0xf1>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
call   1070 <feof@plt>
cmp    $0x0,%eax
jne    127c <getline_unlim+0xec>
mov    0x2d8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xd97(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    12e8 <getline_unlim+0x158>
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     12b1 <getline_unlim+0x121>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    12e3 <getline_unlim+0x153>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
cltq
add    -0x10(%rbp),%rax
mov    %eax,%esi
call   1090 <realloc@plt>
mov    %rax,-0x18(%rbp)
jmp    12e8 <getline_unlim+0x158>
jmp    11b8 <getline_unlim+0x28>
mov    -0x18(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline_unlim>:
push   %r15
push   %r14
push   %rbx
mov    $0x1e,%r14d
mov    $0x1e,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x2e39(%rip),%r15
jmp    11cc <getline_unlim+0x3c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
call   1070 <feof@plt>
test   %eax,%eax
je     1230 <getline_unlim+0xa0>
mov    (%r15),%edi
call   1070 <feof@plt>
test   %eax,%eax
jne    1227 <getline_unlim+0x97>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rdi
add    %rbx,%rdi
mov    (%r15),%edx
mov    %r14,%rsi
call   1050 <fgets@plt>
test   %rax,%rax
je     11c0 <getline_unlim+0x30>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
jne    1224 <getline_unlim+0x94>
add    %r14,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
lea    (%r14,%rax,1),%esi
mov    %rbx,%rdi
call   1090 <realloc@plt>
mov    %rax,%rbx
jmp    11cc <getline_unlim+0x3c>
movb   $0x0,(%rax)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2da1(%rip),%rax
mov    (%rax),%ebx
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdb2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @getline_unlim() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %1
store i64 30, i64* %2
%6 = load i64, i64* %2
%7 = mul i64 %6, 1
%8 = call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
br label %10
10: ; preds = %62, %0
%11 = load i32, i32* %1
%12 = icmp ne i32 %11, 0
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = load i32, i32* @stdin
%15 = call i32 @feof(i32 %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br label %18
18: ; preds = %13, %10
%19 = phi i1 [ false, %10 ], [ %17, %13 ]
br i1 %19, label %20, label %63
20: ; preds = %18
%21 = load i8*, i8** %3
%22 = load i8*, i8** %3
%23 = call i32 @strlen(i8* %22)
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i64, i64* %2
%27 = load i32, i32* @stdin
%28 = call i8* @fgets(i8* %25, i64 %26, i32 %27)
store i8* %28, i8** %5
%29 = load i8*, i8** %5
%30 = icmp ne i8* %29, null
br i1 %30, label %43, label %31
31: ; preds = %20
%32 = load i32, i32* @stdin
%33 = call i32 @feof(i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %42, label %35
35: ; preds = %31
%36 = load i32, i32* @stderr
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %31
br label %62
43: ; preds = %20
%44 = load i8*, i8** %3
%45 = call i8* @strchr(i8* %44, i8 signext 10)
store i8* %45, i8** %4
%46 = load i8*, i8** %4
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = load i8*, i8** %4
store i8 0, i8* %49
store i32 1, i32* %1
br label %61
50: ; preds = %43
%51 = load i64, i64* %2
%52 = mul i64 %51, 2
store i64 %52, i64* %2
%53 = load i8*, i8** %3
%54 = load i8*, i8** %3
%55 = call i32 @strlen(i8* %54)
%56 = sext i32 %55 to i64
%57 = load i64, i64* %2
%58 = add i64 %56, %57
%59 = trunc i64 %58 to i32
%60 = call i8* @realloc(i8* %53, i32 %59)
store i8* %60, i8** %3
br label %61
61: ; preds = %50, %48
br label %62
62: ; preds = %61, %42
br label %10
63: ; preds = %18
%64 = load i8*, i8** %3
ret i8* %64
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str = [3 x i8] c"%s\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @getline_unlim() {
%1 = tail call i64 @malloc(i64 30)
%2 = inttoptr i64 %1 to i8*
%3 = load i32, i32* @stdin
%4 = tail call i32 @feof(i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %42
6: ; preds = %0, %36
%7 = phi i8* [ %37, %36 ], [ %2, %0 ]
%8 = phi i64 [ %38, %36 ], [ 30, %0 ]
%9 = tail call i32 @strlen(i8* %7)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = load i32, i32* @stdin
%13 = tail call i8* @fgets(i8* %11, i64 %8, i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %26
15: ; preds = %6
%16 = load i32, i32* @stdin
%17 = tail call i32 @feof(i32 %16)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = tail call i8* @strerror(i32 %21)
%23 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %6
%27 = tail call i8* @strchr(i8* dereferenceable(1) %7, i8 signext 10)
%28 = icmp eq i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %26
store i8 0, i8* %27
br label %42
30: ; preds = %26
%31 = shl i64 %8, 1
%32 = tail call i32 @strlen(i8* %7)
%33 = trunc i64 %31 to i32
%34 = add i32 %32, %33
%35 = tail call i8* @realloc(i8* %7, i32 %34)
br label %36
36: ; preds = %30, %15
%37 = phi i8* [ %35, %30 ], [ %7, %15 ]
%38 = phi i64 [ %31, %30 ], [ %8, %15 ]
%39 = load i32, i32* @stdin
%40 = tail call i32 @feof(i32 %39)
%41 = icmp eq i32 %40, 0
br i1 %41, label %6, label %42
42: ; preds = %36, %0, %29
%43 = phi i8* [ %7, %29 ], [ %2, %0 ], [ %37, %36 ]
ret i8* %43
}