#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *realloc(char *, int);
int /*<<< orphan*/ strchr(char *, char);
char *readLine(FILE *file) {
  char *buffer = NULL;
  int size = 0;
  int incr = 63;
  do {
    char *tmp = realloc(buffer, size + incr + 1);
    if (!tmp) {
      free(buffer);
      return NULL;
    }
    buffer = tmp;
    if (!fgets(buffer + size, incr + 1, file)) {
      free(buffer);
      return NULL;
    }
    size += incr;
  } while (!strchr(buffer + (size - incr), '\n'));
  return buffer;
}


x86 assembly (clang, -O0):
<readLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x3f,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
add    -0x20(%rbp),%esi
add    $0x1,%esi
call   1060 <realloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1199 <readLine+0x59>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1214 <readLine+0xd4>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x20(%rbp),%esi
add    $0x1,%esi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11da <readLine+0x9a>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1214 <readLine+0xd4>
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
cltq
add    %rax,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1162 <readLine+0x22>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLine>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
xor    %r13d,%r13d
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x40(%r13),%esi
mov    %r15,%rdi
call   1060 <realloc@plt>
test   %rax,%rax
je     11a8 <readLine+0x68>
mov    %rax,%r12
mov    %rax,%rbx
add    %r13,%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     11ad <readLine+0x6d>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
add    $0x3f,%r13
mov    %r12,%r15
test   %eax,%eax
je     1160 <readLine+0x20>
jmp    11b8 <readLine+0x78>
mov    %r15,%rdi
jmp    11b0 <readLine+0x70>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %r12d,%r12d
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @readLine(i32* nocapture %0) {
br label %2
2: ; preds = %18, %1
%3 = phi i64 [ %5, %18 ], [ 0, %1 ]
%4 = phi i8* [ %8, %18 ], [ null, %1 ]
%5 = add nuw i64 %3, 63
%6 = trunc i64 %3 to i32
%7 = add i32 %6, 64
%8 = tail call i8* @realloc(i8* %4, i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = tail call i32 @free(i8* %4)
br label %21
12: ; preds = %2
%13 = getelementptr inbounds i8, i8* %8, i64 %3
%14 = tail call i32 @fgets(i8* %13, i32 64, i32* %0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = tail call i32 @free(i8* %8)
br label %21
18: ; preds = %12
%19 = tail call i32 @strchr(i8* %13, i8 signext 10)
%20 = icmp eq i32 %19, 0
br i1 %20, label %2, label %21
21: ; preds = %18, %10, %16
%22 = phi i8* [ null, %16 ], [ null, %10 ], [ %8, %18 ]
ret i8* %22
}