#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*/ putchar(int);
void reverse() {
  int i = 0;
  int max = 1000;
  int out[max];
  int in;
  while ((in = getchar()) != EOF && i < max) {
    out[i] = in;
    i++;
  }
  while (i >= 0) {
    putchar(out[i]);
    i--;
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
xor    %eax,%eax
mov    0x2e76(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x29(%rbp)
je     1189 <reverse+0x69>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1199 <reverse+0x79>
jmp    11b5 <reverse+0x95>
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%edx
movslq -0x4(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115d <reverse+0x3d>
jmp    11ba <reverse+0x9a>
cmpl   $0x0,-0x4(%rbp)
jl     11e2 <reverse+0xc2>
mov    -0x28(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1030 <putchar@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <reverse+0x9a>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %rbx
sub    $0xfa0,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    0x2eac(%rip),%r14
cmp    (%r14),%eax
je     1170 <reverse+0x50>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,(%rsp,%r15,4)
lea    0x1(%r15),%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    (%r14),%eax
je     1170 <reverse+0x50>
cmp    $0x3e7,%r15
mov    %rbx,%r15
jb     1150 <reverse+0x30>
mov    (%rsp,%rbx,4),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
jb     1170 <reverse+0x50>
add    $0xfa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define void @reverse() {
%1 = alloca [1000 x i32]
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %7, label %9
5: ; preds = %9
%6 = and i64 %13, 4294967295
br label %7
7: ; preds = %0, %5
%8 = phi i64 [ %6, %5 ], [ 0, %0 ]
br label %19
9: ; preds = %0, %9
%10 = phi i64 [ %13, %9 ], [ 0, %0 ]
%11 = phi i32 [ %14, %9 ], [ %2, %0 ]
%12 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %10
store i32 %11, i32* %12
%13 = add nuw nsw i64 %10, 1
%14 = tail call i32 (...) @getchar()
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
%17 = icmp ult i64 %10, 999
%18 = select i1 %16, i1 %17, i1 false
br i1 %18, label %9, label %5
19: ; preds = %7, %19
%20 = phi i64 [ %24, %19 ], [ %8, %7 ]
%21 = getelementptr inbounds [1000 x i32], [1000 x i32]* %1, i64 0, i64 %20
%22 = load i32, i32* %21
%23 = tail call i32 @putchar(i32 %22)
%24 = add nsw i64 %20, -1
%25 = icmp eq i64 %20, 0
br i1 %25, label %26, label %19
26: ; preds = %19
ret void
}