#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 */
char EOF;
char getchar();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *);
int main(int argc, char const *argv[]) {
  int i = 0;
  char c, buffer[1000];
  while ((c = getchar()) != EOF && i < (1000 - 1))
    if (c != '\n') {
      buffer[i] = c;
      ++i;
    } else {
      buffer[i] = '\0';
      reverse(buffer);
      printf("%s\n", buffer);
      i = 0;
    };
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x15(%rbp)
movsbl %al,%ecx
mov    0x2e84(%rip),%rax
movsbl (%rax),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x401(%rbp)
je     1187 <main+0x57>
cmpl   $0x3e7,-0x14(%rbp)
setl   %al
mov    %al,-0x401(%rbp)
mov    -0x401(%rbp),%al
test   $0x1,%al
jne    119a <main+0x6a>
jmp    11fa <main+0xca>
movsbl -0x15(%rbp),%eax
cmp    $0xa,%eax
je     11c3 <main+0x93>
mov    -0x15(%rbp),%cl
movslq -0x14(%rbp),%rax
mov    %cl,-0x400(%rbp,%rax,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f5 <main+0xc5>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
call   1030 <reverse@plt>
lea    -0x400(%rbp),%rsi
lea    0xe17(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x14(%rbp)
jmp    1150 <main+0x20>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3e8,%rsp
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e9c(%rip),%r15
cmp    (%r15),%al
je     11aa <main+0x7a>
mov    %rsp,%r12
lea    0xea5(%rip),%r14
xor    %ebx,%ebx
nopl   (%rax)
movslq %ebx,%rbx
cmp    $0xa,%al
jne    1190 <main+0x60>
movb   $0x0,(%rsp,%rbx,1)
mov    %r12,%rdi
call   1030 <reverse@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
xor    %ebx,%ebx
jmp    1196 <main+0x66>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %al,(%rsp,%rbx,1)
add    $0x1,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r15),%al
je     11aa <main+0x7a>
cmp    $0x3e7,%ebx
jl     1160 <main+0x30>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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