#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 */
char getchar();
scalar_t__ malloc(int);
char *GetInputLine(void) {
  char *line;
  char tmp;
  int count = 0;
  line = (char *)malloc(4096);
  while ((tmp = getchar()) != '\n') {
    line[count] = tmp;
    count++;
  }
  line[count + 1] = '\0';
  return line;
}


x86 assembly (clang, -O0):
<GetInputLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x10(%rbp)
mov    $0x1000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     116f <GetInputLine+0x4f>
mov    -0x9(%rbp),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    113d <GetInputLine+0x1d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetInputLine>:
push   %r14
push   %rbx
push   %rax
mov    $0x1000,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <getchar@plt>
mov    $0x1,%ecx
cmp    $0xa,%al
je     1166 <GetInputLine+0x46>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %al,-0x1(%r14,%rbx,1)
xor    %eax,%eax
call   1030 <getchar@plt>
add    $0x1,%rbx
cmp    $0xa,%al
jne    1150 <GetInputLine+0x30>
mov    %ebx,%ecx
movb   $0x0,(%r14,%rcx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @GetInputLine() {
%1 = alloca i8*
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %3
%4 = call i64 @malloc(i32 4096)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %1
br label %6
6: ; preds = %10, %0
%7 = call signext i8 (...) @getchar()
store i8 %7, i8* %2
%8 = sext i8 %7 to i32
%9 = icmp ne i32 %8, 10
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = load i8, i8* %2
%12 = load i8*, i8** %1
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
store i8 %11, i8* %15
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %6
18: ; preds = %6
%19 = load i8*, i8** %1
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8 0, i8* %23
%24 = load i8*, i8** %1
ret i8* %24
}

LLVM IR (-O2):
define i8* @GetInputLine() {
%1 = tail call i64 @malloc(i32 4096)
%2 = inttoptr i64 %1 to i8*
%3 = tail call signext i8 (...) @getchar()
%4 = icmp eq i8 %3, 10
br i1 %4, label %15, label %5
5: ; preds = %0, %5
%6 = phi i64 [ %9, %5 ], [ 0, %0 ]
%7 = phi i8 [ %10, %5 ], [ %3, %0 ]
%8 = getelementptr inbounds i8, i8* %2, i64 %6
store i8 %7, i8* %8
%9 = add nuw i64 %6, 1
%10 = tail call signext i8 (...) @getchar()
%11 = icmp eq i8 %10, 10
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = add i64 %6, 2
%14 = and i64 %13, 4294967295
br label %15
15: ; preds = %12, %0
%16 = phi i64 [ 1, %0 ], [ %14, %12 ]
%17 = getelementptr inbounds i8, i8* %2, i64 %16
store i8 0, i8* %17
ret i8* %2
}