#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();
void mgetline(char line[]) {
  int i = 0;
  int c;
  while ((c = getchar()) && c != '\n' && c != EOF) {
    line[i++] = c;
  }
  line[i] = '\n';
}


x86 assembly (clang, -O0):
<mgetline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     115e <mgetline+0x4e>
xor    %eax,%eax
cmpl   $0xa,-0x10(%rbp)
mov    %al,-0x11(%rbp)
je     115e <mgetline+0x4e>
mov    -0x10(%rbp),%eax
mov    0x2e92(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    116e <mgetline+0x5e>
jmp    118d <mgetline+0x7d>
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)
jmp    1123 <mgetline+0x13>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movb   $0xa,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mgetline>:
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>
test   %eax,%eax
je     114f <mgetline+0x3f>
cmp    $0xa,%eax
je     114f <mgetline+0x3f>
cmp    (%r15),%eax
je     114f <mgetline+0x3f>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
jmp    1130 <mgetline+0x20>
mov    %ebx,%eax
movb   $0xa,(%r14,%rax,1)
pop    %rbx
pop    %r14
pop    %r15
ret

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

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