#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 get_line(char *line) {
  int character, element;
  for (element = 0; element < 1000 - 2 && (character = getchar()) != '\n' &&
                    character != EOF;
       ++element)
    *line++ = character;
  *line++ = '\n';
  *line = '\0';
  return element;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x3e6,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    1161 <get_line+0x51>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0xc(%rbp)
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x11(%rbp)
je     1161 <get_line+0x51>
mov    -0xc(%rbp),%eax
mov    0x2e8f(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1171 <get_line+0x61>
jmp    1195 <get_line+0x85>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1123 <get_line+0x13>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xa,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
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    $0xa,%eax
je     115b <get_line+0x4b>
cmp    (%r15),%eax
je     115b <get_line+0x4b>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x3e6,%ebx
jne    1130 <get_line+0x20>
add    %rbx,%r14
mov    $0x3e6,%ebx
jmp    115e <get_line+0x4e>
add    %rbx,%r14
movw   $0xa,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @get_line(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
br label %5
5: ; preds = %22, %1
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 998
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = call i32 (...) @getchar()
store i32 %9, i32* %3
%10 = icmp ne i32 %9, 10
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* %3
%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* %3
%19 = trunc i32 %18 to i8
%20 = load i8*, i8** %2
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %2
store i8 %19, i8* %20
br label %22
22: ; preds = %17
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %5
25: ; preds = %15
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %2
store i8 10, i8* %26
%28 = load i8*, i8** %2
store i8 0, i8* %28
%29 = load i32, i32* %4
ret i32 %29
}

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