#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;
scalar_t__ calloc(int /*<<< orphan*/, int);
char fgetc(int /*<<< orphan*/ *);
scalar_t__ realloc(char *, int);
char *readLine(FILE *file) {
  char *line = (char *)calloc(0, sizeof(char));
  ;
  char ch;
  int len = 0;
  while ((ch = fgetc(file)) != EOF && ch != '\n') {
    line = (char *)realloc(line, sizeof(char) * (len + 2));
    line[len++] = ch;
    line[len] = '\0';
  }
  return line;
}


x86 assembly (clang, -O0):
<readLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%ecx
mov    0x2e7f(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x19(%rbp)
je     1186 <readLine+0x56>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1196 <readLine+0x66>
jmp    11da <readLine+0xaa>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1050 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1153 <readLine+0x23>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %edi,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    $0xa,%al
je     11a1 <readLine+0x71>
mov    %eax,%ebx
mov    0x2e86(%rip),%r13
cmp    0x0(%r13),%al
je     11a1 <readLine+0x71>
mov    $0x1,%r12d
xchg   %ax,%ax
mov    %r12,%rbp
add    $0x1,%r12
mov    %r15,%rdi
mov    %r12d,%esi
call   1050 <realloc@plt>
mov    %rax,%r15
mov    %bl,-0x1(%rax,%rbp,1)
movb   $0x0,(%rax,%rbp,1)
mov    %r14,%rdi
call   1030 <fgetc@plt>
cmp    $0xa,%al
je     11a1 <readLine+0x71>
mov    %eax,%ebx
cmp    0x0(%r13),%al
jne    1170 <readLine+0x40>
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* @readLine(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
store i32* %0, i32** %2
%6 = call i64 @calloc(i32 0, i32 1)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
store i32 0, i32* %5
br label %8
8: ; preds = %21, %1
%9 = load i32*, i32** %2
%10 = call signext i8 @fgetc(i32* %9)
store i8 %10, i8* %4
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %11, %13
br i1 %14, label %15, label %19
15: ; preds = %8
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 10
br label %19
19: ; preds = %15, %8
%20 = phi i1 [ false, %8 ], [ %18, %15 ]
br i1 %20, label %21, label %40
21: ; preds = %19
%22 = load i8*, i8** %3
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 2
%25 = sext i32 %24 to i64
%26 = mul i64 1, %25
%27 = trunc i64 %26 to i32
%28 = call i64 @realloc(i8* %22, i32 %27)
%29 = inttoptr i64 %28 to i8*
store i8* %29, i8** %3
%30 = load i8, i8* %4
%31 = load i8*, i8** %3
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 %30, i8* %35
%36 = load i8*, i8** %3
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
br label %8
40: ; preds = %19
%41 = load i8*, i8** %3
ret i8* %41
}

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