#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 *GetString(void) {
  char *line, ch;
  int i = 0;
  line = (char *)malloc(64 + 1);
  while ((ch = getchar()) != '\n') {
    *(line + i) = ch;
    i++;
    if (i == 64)
      break;
  }
  *(line + i) = '\0';
  return (line);
}


x86 assembly (clang, -O0):
<GetString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x10(%rbp)
mov    $0x41,%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     117e <GetString+0x5e>
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)
cmpl   $0x40,-0x10(%rbp)
jne    1179 <GetString+0x59>
jmp    117e <GetString+0x5e>
jmp    113d <GetString+0x1d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetString>:
push   %r14
push   %rbx
push   %rax
mov    $0x41,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     115e <GetString+0x3e>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x40,%rbx
jne    1140 <GetString+0x20>
mov    $0x40,%ebx
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @GetString() {
%1 = alloca i8*
%2 = alloca i8
%3 = alloca i32
store i32 0, i32* %3
%4 = call i64 @malloc(i32 65)
%5 = inttoptr i64 %4 to i8*
store i8* %5, i8** %1
br label %6
6: ; preds = %21, %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 %22
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
%18 = load i32, i32* %3
%19 = icmp eq i32 %18, 64
br i1 %19, label %20, label %21
20: ; preds = %10
br label %22
21: ; preds = %10
br label %6
22: ; preds = %20, %6
%23 = load i8*, i8** %1
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
%27 = load i8*, i8** %1
ret i8* %27
}

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