#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 *);
int /*<<< orphan*/ putchar(int);
int main() {
  int c, stck[128];
  int i = 0;
  printf(
      "Type the input you want to reverse then type ctrl+d (EOF character).\n");
  while ((c = getchar()) != EOF) {
    stck[i] = c;
    i++;
  }
  while (i >= 0) {
    putchar(stck[i]);
    i--;
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x214(%rbp)
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%eax
je     1196 <main+0x66>
mov    -0x8(%rbp),%ecx
movslq -0x214(%rbp),%rax
mov    %ecx,-0x210(%rbp,%rax,4)
mov    -0x214(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x214(%rbp)
jmp    1158 <main+0x28>
jmp    119b <main+0x6b>
cmpl   $0x0,-0x214(%rbp)
jl     11cf <main+0x9f>
movslq -0x214(%rbp),%rax
mov    -0x210(%rbp,%rax,4),%edi
call   1030 <putchar@plt>
mov    -0x214(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x214(%rbp)
jmp    119b <main+0x6b>
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
lea    0xebf(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    0x2e92(%rip),%r14
cmp    (%r14),%eax
je     117b <main+0x4b>
xor    %ebx,%ebx
nopl   (%rax)
mov    %eax,(%rsp,%rbx,4)
add    $0x1,%rbx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    (%r14),%eax
jne    1160 <main+0x30>
test   $0x80000000,%ebx
jne    118e <main+0x5e>
mov    %ebx,%ebx
nopl   (%rax)
mov    (%rsp,%rbx,4),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
jb     1180 <main+0x50>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [70 x i8] c"Type the input you want to reverse then type ctrl+d (EOF character).\0A\00"
@EOF = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i32]
%4 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %4
%5 = call i32 @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %10, %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 %17
10: ; preds = %6
%11 = load i32, i32* %2
%12 = load i32, i32* %4
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [128 x i32], [128 x i32]* %3, i64 0, i64 %13
store i32 %11, i32* %14
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %6
17: ; preds = %6
br label %18
18: ; preds = %21, %17
%19 = load i32, i32* %4
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %18
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [128 x i32], [128 x i32]* %3, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = call i32 @putchar(i32 %25)
%27 = load i32, i32* %4
%28 = add nsw i32 %27, -1
store i32 %28, i32* %4
br label %18
29: ; preds = %18
%30 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@EOF = global i32 0
@str = [69 x i8] c"Type the input you want to reverse then type ctrl+d (EOF character).\00"
define i32 @main() {
%1 = alloca [128 x i32]
%2 = bitcast [128 x i32]* %1 to i8*
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 (...) @getchar()
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %10, label %13
7: ; preds = %13
%8 = and i64 %17, 2147483648
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %28
10: ; preds = %0, %7
%11 = phi i64 [ %17, %7 ], [ 0, %0 ]
%12 = and i64 %11, 4294967295
br label %21
13: ; preds = %0, %13
%14 = phi i64 [ %17, %13 ], [ 0, %0 ]
%15 = phi i32 [ %18, %13 ], [ %4, %0 ]
%16 = getelementptr inbounds [128 x i32], [128 x i32]* %1, i64 0, i64 %14
store i32 %15, i32* %16
%17 = add nuw i64 %14, 1
%18 = tail call i32 (...) @getchar()
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %7, label %13
21: ; preds = %10, %21
%22 = phi i64 [ %12, %10 ], [ %26, %21 ]
%23 = getelementptr inbounds [128 x i32], [128 x i32]* %1, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = tail call i32 @putchar(i32 %24)
%26 = add nsw i64 %22, -1
%27 = icmp eq i64 %22, 0
br i1 %27, label %28, label %21
28: ; preds = %21, %7
%29 = tail call i32 @putchar(i32 10)
ret i32 0
}