#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 /*<<< orphan*/ reverse(char *);
int main(void) {
  int character, element = 0;
  char string[1000];
  while ((character = getchar()) != EOF) {
    if (element >= 1000 || character == '\n') {
      string[element] = '\0';
      reverse(string);
      printf("%s\n", string);
      element = 0;
    } else
      string[element++] = character;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e8e(%rip),%rcx
cmp    (%rcx),%eax
je     11ce <main+0x9e>
cmpl   $0x3e8,-0xc(%rbp)
jge    1179 <main+0x49>
cmpl   $0xa,-0x8(%rbp)
jne    11b0 <main+0x80>
movslq -0xc(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
call   1030 <reverse@plt>
lea    -0x400(%rbp),%rsi
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    11c9 <main+0x99>
mov    -0x8(%rbp),%eax
mov    %al,%cl
mov    -0xc(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
cltq
mov    %cl,-0x400(%rbp,%rax,1)
jmp    1149 <main+0x19>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e9d(%rip),%r15
cmp    (%r15),%eax
jne    1160 <main+0x30>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
lea    0xe96(%rip),%r14
xor    %ebp,%ebp
jmp    1195 <main+0x65>
xchg   %ax,%ax
movb   $0x0,(%rsp,%rcx,1)
mov    %rbx,%rdi
call   1030 <reverse@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%eax
je     1150 <main+0x20>
movslq %ebp,%rcx
cmp    $0x3e7,%ebp
jg     1170 <main+0x40>
cmp    $0xa,%eax
je     1170 <main+0x40>
lea    0x1(%rcx),%ebp
mov    %al,(%rsp,%rcx,1)
jmp    1189 <main+0x59>

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 [1000 x i8]
store i32 0, i32* %1
store i32 0, i32* %3
br label %5
5: ; preds = %30, %0
%6 = call i32 (...) @getchar()
store i32 %6, i32* %2
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %31
9: ; preds = %5
%10 = load i32, i32* %3
%11 = icmp sge i32 %10, 1000
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* %2
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %23
15: ; preds = %12, %9
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%20 = call i32 @reverse(i8* %19)
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 0, i32* %3
br label %30
23: ; preds = %12
%24 = load i32, i32* %2
%25 = trunc i32 %24 to i8
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %28
store i8 %25, i8* %29
br label %30
30: ; preds = %23, %15
br label %5
31: ; preds = %5
ret i32 0
}

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