#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 */
int EOF;
int getchar();
int getcharline(char to[]) {
  int i = 0, c = -1;
  while (1) {
    c = getchar();
    if (c != EOF)
      to[i++] = c;
    if (c == EOF || c == '\n')
      break;
  }
  to[i] = '\0';
  return i;
}


x86 assembly (clang, -O0):
<getcharline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2eaa(%rip),%rcx
cmp    (%rcx),%eax
je     1160 <getcharline+0x50>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0xc(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
mov    0x2e7e(%rip),%rcx
cmp    (%rcx),%eax
je     117c <getcharline+0x6c>
cmpl   $0xa,-0x10(%rbp)
jne    1181 <getcharline+0x71>
jmp    1186 <getcharline+0x76>
jmp    112a <getcharline+0x1a>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getcharline>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2ec9(%rip),%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    (%r15),%eax
je     114e <getcharline+0x3e>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%eax
je     114e <getcharline+0x3e>
cmp    (%r15),%eax
jne    1130 <getcharline+0x20>
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @getcharline(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 -1, i32* %4
br label %5
5: ; preds = %1, %26
%6 = call i32 (...) @getchar()
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* @EOF
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = load i32, i32* %4
%12 = trunc i32 %11 to i8
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = add nsw i32 %14, 1
store i32 %15, i32* %3
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 %12, i8* %17
br label %18
18: ; preds = %10, %5
%19 = load i32, i32* %4
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i32, i32* %4
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %26
25: ; preds = %22, %18
br label %27
26: ; preds = %22
br label %5
27: ; preds = %25
%28 = load i8*, i8** %2
%29 = load i32, i32* %3
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 0, i8* %31
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @getcharline(i8* nocapture writeonly %0) {
br label %2
2: ; preds = %7, %1
%3 = phi i32 [ 0, %1 ], [ %9, %7 ]
%4 = tail call i32 (...) @getchar()
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %16, label %7
7: ; preds = %2
%8 = trunc i32 %4 to i8
%9 = add nuw nsw i32 %3, 1
%10 = zext i32 %3 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 %8, i8* %11
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %4, %12
%14 = icmp eq i32 %4, 10
%15 = or i1 %14, %13
br i1 %15, label %16, label %2
16: ; preds = %2, %7
%17 = phi i32 [ %9, %7 ], [ %3, %2 ]
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
store i8 0, i8* %19
ret i32 %17
}