#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 EOF;
char getchar();
int get_line(char *arr) {
  char c;
  int len = 0;
  while ((c = getchar()) != EOF) {
    if (c == '\n') {
      break;
    }
    if (len < 1001) {
      arr[len] = c;
    }
    len += 1;
  }
  return len;
}


x86 assembly (clang, -O0):
<get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0x9(%rbp)
movsbl %al,%eax
mov    0x2eb1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     117d <get_line+0x6d>
movsbl -0x9(%rbp),%eax
cmp    $0xa,%eax
jne    1154 <get_line+0x44>
jmp    117d <get_line+0x6d>
cmpl   $0x3e9,-0x10(%rbp)
jge    116f <get_line+0x5f>
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    1123 <get_line+0x13>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_line>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     1161 <get_line+0x51>
mov    0x2ebc(%rip),%r15
cmp    (%r15),%al
je     1161 <get_line+0x51>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x3e8,%rbx
ja     114d <get_line+0x3d>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%al
je     1161 <get_line+0x51>
cmp    (%r15),%al
jne    1140 <get_line+0x30>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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