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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x14,-0xc(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11bd <main+0x8d>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xa,%eax
jne    1186 <main+0x56>
jmp    11bd <main+0x8d>
mov    -0x10(%rbp),%eax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
jne    119d <main+0x6d>
jmp    11bd <main+0x8d>
mov    -0x10(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x8(%rbp)
cltq
mov    %cl,-0x30(%rbp,%rax,1)
jmp    11b8 <main+0x88>
jmp    115d <main+0x2d>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rsi
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    0x2eab(%rip),%r14
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1163 <main+0x43>
cmp    (%r14),%eax
je     1163 <main+0x43>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x13,%rbx
jne    1140 <main+0x20>
mov    $0x13,%ebx
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0xe90(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
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 [20 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
store i32 20, i32* %3
%6 = bitcast [20 x i8]* %5 to i8*
br label %7
7: ; preds = %29, %0
%8 = load i32, i32* %2
%9 = load i32, i32* %3
%10 = sub nsw i32 %9, 1
%11 = icmp slt i32 %8, %10
br i1 %11, label %12, label %30
12: ; preds = %7
%13 = call i32 (...) @getchar()
store i32 %13, i32* %4
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %16
15: ; preds = %12
br label %30
16: ; preds = %12
%17 = load i32, i32* %4
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
br label %30
21: ; preds = %16
%22 = load i32, i32* %4
%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 [20 x i8], [20 x i8]* %5, i64 0, i64 %26
store i8 %23, i8* %27
br label %28
28: ; preds = %21
br label %29
29: ; preds = %28
br label %7
30: ; preds = %20, %15, %7
%31 = load i32, i32* %2
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %32
store i8 0, i8* %33
%34 = getelementptr inbounds [20 x i8], [20 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 [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %0, %10
%4 = phi i64 [ 0, %0 ], [ %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 = %3
%11 = trunc i32 %5 to i8
%12 = add nuw nsw i64 %4, 1
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %4
store i8 %11, i8* %13
%14 = icmp eq i64 %12, 19
br i1 %14, label %15, label %3
15: ; preds = %3, %10
%16 = phi i64 [ %4, %3 ], [ 19, %10 ]
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
ret i32 0
}