#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 /*<<< orphan*/ printf(char *, char *);
int main() {
  int i = 0;
  int lim = 1000;
  int c = 0;
  char s[lim];
  while (i < lim - 1) {
    c = getchar();
    if (c == '\n') {
      break;
    } else if (c == EOF) {
      break;
    } else {
      s[i] = c;
      i++;
    }
  }
  printf("Line is: %s\n", s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x3e8,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11ce <main+0xae>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jne    1194 <main+0x74>
jmp    11ce <main+0xae>
mov    -0x10(%rbp),%eax
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
jne    11ab <main+0x8b>
jmp    11ce <main+0xae>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %cl,%dl
movslq -0x8(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11c9 <main+0xa9>
jmp    116a <main+0x4a>
mov    -0x28(%rbp),%rsi
lea    0xe27(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    0x2eb7(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1161 <main+0x41>
cmp    (%r14),%eax
je     1161 <main+0x41>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x3e7,%rbx
jne    1140 <main+0x20>
lea    0xe98(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [13 x i8] c"Line is: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
store i32 1000, i32* %3
store i32 0, i32* %4
%7 = load i32, i32* %3
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %5
%10 = alloca i8, i64 %8
store i64 %8, i64* %6
br label %11
11: ; preds = %35, %0
%12 = load i32, i32* %2
%13 = load i32, i32* %3
%14 = sub nsw i32 %13, 1
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %36
16: ; preds = %11
%17 = call i32 (...) @getchar()
store i32 %17, i32* %4
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %21
20: ; preds = %16
br label %36
21: ; preds = %16
%22 = load i32, i32* %4
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %21
br label %36
26: ; preds = %21
%27 = load i32, i32* %4
%28 = trunc i32 %27 to i8
%29 = load i32, i32* %2
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %10, i64 %30
store i8 %28, i8* %31
%32 = load i32, i32* %2
%33 = add nsw i32 %32, 1
store i32 %33, i32* %2
br label %34
34: ; preds = %26
br label %35
35: ; preds = %34
br label %11
36: ; preds = %25, %20, %11
%37 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %10)
%38 = load i8*, i8** %5
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [13 x i8] c"Line is: %s\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
br label %2
2: ; preds = %0, %9
%3 = phi i64 [ 0, %0 ], [ %12, %9 ]
%4 = tail call i32 (...) @getchar()
%5 = icmp eq i32 %4, 10
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %4, %6
%8 = select i1 %5, i1 true, i1 %7
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = trunc i32 %4 to i8
%11 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %3
store i8 %10, i8* %11
%12 = add nuw nsw i64 %3, 1
%13 = icmp eq i64 %12, 999
br i1 %13, label %14, label %2
14: ; preds = %2, %9
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %15)
ret i32 0
}