#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ reverse(char *);
int main() {
  int ch;
  char buf[1000] = {
      0,
  };
  int idx = 0;
  while ((ch = getchar()) != EOF) {
    if (ch != '\n') {
      buf[idx] = ch;
      idx++;
      if (idx >= 1000) {
        printf("ERROR: No buf remaining\n");
        exit(0);
      }
    } else {
      buf[idx] = '\0';
      reverse(buf);
      puts(buf);
      idx = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x3f0(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1060 <memset@plt>
movl   $0x0,-0x3f4(%rbp)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%eax
je     1232 <main+0xd2>
cmpl   $0xa,-0x8(%rbp)
je     11fc <main+0x9c>
mov    -0x8(%rbp),%eax
mov    %al,%cl
movslq -0x3f4(%rbp),%rax
mov    %cl,-0x3f0(%rbp,%rax,1)
mov    -0x3f4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3f4(%rbp)
cmpl   $0x3e8,-0x3f4(%rbp)
jl     11f7 <main+0x97>
lea    0xe15(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    122d <main+0xcd>
movslq -0x3f4(%rbp),%rax
movb   $0x0,-0x3f0(%rbp,%rax,1)
lea    -0x3f0(%rbp),%rdi
call   1030 <reverse@plt>
lea    -0x3f0(%rbp),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x3f4(%rbp)
jmp    118f <main+0x2f>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
mov    %rsp,%rdi
mov    $0x3e8,%edx
xor    %esi,%esi
call   1050 <memset@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
mov    0x2e70(%rip),%r14
cmp    (%r14),%eax
jne    118b <main+0x3b>
xor    %eax,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rsp,%rbx
xor    %ebp,%ebp
jmp    11c2 <main+0x72>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movb   $0x0,(%rsp,%rcx,1)
mov    %rbx,%rdi
call   1030 <reverse@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    (%r14),%eax
je     117d <main+0x2d>
movslq %ebp,%rcx
cmp    $0xa,%eax
je     11a0 <main+0x50>
mov    %al,(%rsp,%rcx,1)
cmp    $0x3e7,%ebp
jge    11da <main+0x8a>
add    $0x1,%ebp
jmp    11b6 <main+0x66>
lea    0xe1f(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@EOF = global i32 0
@str = [24 x i8] c"ERROR: No buf remaining\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 %29, label %6
6: ; preds = %0, %24
%7 = phi i32 [ %26, %24 ], [ %3, %0 ]
%8 = phi i32 [ %25, %24 ], [ 0, %0 ]
%9 = icmp eq i32 %7, 10
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = trunc i32 %7 to i8
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %12
store i8 %11, i8* %13
%14 = add nsw i32 %8, 1
%15 = icmp sgt i32 %8, 998
br i1 %15, label %16, label %24
16: ; preds = %10
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %6
%20 = sext i32 %8 to i64
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 @reverse(i8* %2)
%23 = call i32 @puts(i8* %2)
br label %24
24: ; preds = %10, %19
%25 = phi i32 [ %14, %10 ], [ 0, %19 ]
%26 = call i32 (...) @getchar()
%27 = load i32, i32* @EOF
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %6
29: ; preds = %24, %0
ret i32 0
}