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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x200,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11b2 <main+0x92>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jne    1171 <main+0x51>
movl   $0x0,-0x10(%rbp)
jmp    11ad <main+0x8d>
mov    -0xc(%rbp),%eax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%eax
jne    118f <main+0x6f>
movl   $0x0,-0x10(%rbp)
jmp    11a8 <main+0x88>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cltq
mov    %cl,-0x210(%rbp,%rax,1)
jmp    11ad <main+0x8d>
jmp    1140 <main+0x20>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x210(%rbp,%rax,1)
lea    -0x210(%rbp),%rsi
lea    0xe34(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    $0x200,%ebx
mov    0x2eb1(%rip),%r14
xor    %ebp,%ebp
jmp    1149 <main+0x29>
nopl   0x0(%rax,%rax,1)
xor    %ebx,%ebx
lea    -0x1(%rbx),%eax
cmp    %eax,%ebp
jge    1165 <main+0x45>
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1140 <main+0x20>
cmp    (%r14),%eax
je     1140 <main+0x20>
movslq %ebp,%rcx
add    $0x1,%ebp
mov    %al,(%rsp,%rcx,1)
jmp    1142 <main+0x22>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
lea    0xe8d(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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