#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 main(void) {
  int i, lim = 1000;
  char c;
  char str[1000];
  for (i = 0; i < lim - 1; i++, c = getchar()) {
    if (c == EOF)
      if (c == '\n')
        break;
    str[i] = c;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1194 <main+0x84>
movsbl -0xd(%rbp),%eax
mov    0x2e9c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    116e <main+0x5e>
movsbl -0xd(%rbp),%eax
cmp    $0xa,%eax
jne    1169 <main+0x59>
jmp    1194 <main+0x84>
jmp    116e <main+0x5e>
mov    -0xd(%rbp),%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x400(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %al,-0xd(%rbp)
jmp    1130 <main+0x20>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x3e7,%ebx
mov    0x2ec8(%rip),%r14
jmp    113c <main+0x2c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <getchar@plt>
add    $0xffffffff,%ebx
je     1146 <main+0x36>
cmp    $0xa,%al
jne    1130 <main+0x20>
cmpb   $0xa,(%r14)
jne    1130 <main+0x20>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@EOF = global i8 0
define i32 @main() {
br label %1
1: ; preds = %0, %8
%2 = phi i8 [ undef, %0 ], [ %10, %8 ]
%3 = phi i32 [ 0, %0 ], [ %9, %8 ]
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %2, 10
%6 = icmp eq i8 %4, 10
%7 = and i1 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = add nuw nsw i32 %3, 1
%10 = tail call signext i8 (...) @getchar()
%11 = icmp eq i32 %9, 999
br i1 %11, label %12, label %1
12: ; preds = %1, %8
ret i32 0
}