#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 */
scalar_t__ EOF;
scalar_t__ calloc(long, int);
scalar_t__ feof(int /*<<< orphan*/ *const);
char fgetc(int /*<<< orphan*/ *const);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *GetLine(FILE *const fhandle) {
  char *tmp, *tmp2;
  long i = 0;
  char c;
  tmp = (char *)calloc(1, sizeof(char));
  while (((c = fgetc(fhandle)) != 10) && (!feof(fhandle))) {
    tmp2 = tmp;
    tmp = (char *)calloc(i + 2, sizeof(char));
    strcpy(tmp, tmp2);
    free(tmp2);
    tmp[i] = c;
    i++;
    tmp[i] = '\0';
  }
  if (feof(fhandle)) {
    *tmp = (char)EOF;
  }
  return tmp;
}


x86 assembly (clang, -O0):
<GetLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x22(%rbp)
je     11a9 <GetLine+0x59>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11b9 <GetLine+0x69>
jmp    1218 <GetLine+0xc8>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x2,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x21(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1177 <GetLine+0x27>
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     123d <GetLine+0xed>
mov    0x2db6(%rip),%rax
mov    (%rax),%rax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetLine>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    $0x1,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    $0xa,%al
je     11e3 <GetLine+0x93>
mov    %eax,%r12d
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
jne    11e3 <GetLine+0x93>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r12b,-0x2(%rbp,%rbx,1)
movb   $0x0,-0x1(%rbp,%rbx,1)
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    %eax,%r12d
add    $0x1,%rbx
mov    %rbp,%r15
cmp    $0xa,%al
jne    1190 <GetLine+0x40>
mov    %rbp,%r15
mov    %r14,%rdi
call   1070 <feof@plt>
test   %rax,%rax
je     11fc <GetLine+0xac>
mov    0x2df1(%rip),%rax
mov    (%rax),%al
mov    %al,(%r15)
mov    %r15,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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