#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 */
typedef int /*<<< orphan*/ character;

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char);
char *realloc(char *, int);
scalar_t__ scanf(char *, char *);
int main() {
  char *character;
  int i = 0;
  int size = 10;
  character = malloc(sizeof(character) * size);
  while (scanf("%c", (character + i)) != EOF) {
    i++;
    if (i == size) {
      size *= 2;
      character = realloc(character, size);
    }
  }
  char printing[i];
  for (; i >= 0; i--) {
    printf("%c", *(character + i));
  }
  free(character);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xa,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x14(%rbp),%rax
add    %rax,%rsi
lea    0xe6e(%rip),%rdi
call   1070 <scanf@plt>
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%rax
je     11da <main+0x8a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11d5 <main+0x85>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <realloc@plt>
mov    %rax,-0x10(%rbp)
jmp    1180 <main+0x30>
mov    -0x14(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1218 <main+0xc8>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xdff(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11e8 <main+0x98>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0x50,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xe94(%rip),%rdi
mov    %rax,%rsi
call   1070 <scanf@plt>
mov    0x2e6d(%rip),%r12
cmp    (%r12),%rax
jne    1185 <main+0x35>
xor    %ebx,%ebx
jmp    11da <main+0x8a>
mov    $0xa,%ebp
mov    $0x1,%ebx
lea    0xe6a(%rip),%r14
jmp    11b6 <main+0x66>
nopl   0x0(%rax,%rax,1)
lea    (%r15,%rbx,1),%rsi
mov    %r14,%rdi
call   1070 <scanf@plt>
add    $0x1,%rbx
cmp    (%r12),%rax
je     11ce <main+0x7e>
mov    %ebp,%eax
cmp    %rax,%rbx
jne    11a0 <main+0x50>
add    %ebp,%ebp
mov    %r15,%rdi
mov    %ebp,%esi
call   1060 <realloc@plt>
mov    %rax,%r15
jmp    11a0 <main+0x50>
add    $0xffffffffffffffff,%rbx
test   $0x80000000,%ebx
jne    1203 <main+0xb3>
mov    %ebx,%ebx
lea    0xe1d(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r15,%rbx,1),%esi
mov    %rbp,%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
jb     11f0 <main+0xa0>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %3
store i32 10, i32* %4
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 8, %8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
store i8* %11, i8** %2
br label %12
12: ; preds = %32, %0
%13 = load i8*, i8** %2
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i64, i64* @EOF
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %33
20: ; preds = %12
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load i32, i32* %4
%28 = mul nsw i32 %27, 2
store i32 %28, i32* %4
%29 = load i8*, i8** %2
%30 = load i32, i32* %4
%31 = call i8* @realloc(i8* %29, i32 %30)
store i8* %31, i8** %2
br label %32
32: ; preds = %26, %20
br label %12
33: ; preds = %12
%34 = load i32, i32* %3
%35 = zext i32 %34 to i64
%36 = call i8* @llvm.stacksave()
store i8* %36, i8** %5
%37 = alloca i8, i64 %35
store i64 %35, i64* %6
br label %38
38: ; preds = %48, %33
%39 = load i32, i32* %3
%40 = icmp sge i32 %39, 0
br i1 %40, label %41, label %51
41: ; preds = %38
%42 = load i8*, i8** %2
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %46)
br label %48
48: ; preds = %41
%49 = load i32, i32* %3
%50 = add nsw i32 %49, -1
store i32 %50, i32* %3
br label %38
51: ; preds = %38
%52 = load i8*, i8** %2
%53 = call i32 @free(i8* %52)
%54 = load i8*, i8** %5
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@EOF = global i64 0
define i32 @main() {
%1 = tail call dereferenceable_or_null(80) i8* @malloc(i32 80)
%2 = tail call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = load i64, i64* @EOF
%4 = icmp eq i64 %2, %3
br i1 %4, label %8, label %12
5: ; preds = %22
%6 = and i64 %16, 2147483648
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %36
8: ; preds = %0, %5
%9 = phi i8* [ %24, %5 ], [ %1, %0 ]
%10 = phi i64 [ %16, %5 ], [ 0, %0 ]
%11 = and i64 %10, 4294967295
br label %29
12: ; preds = %0, %22
%13 = phi i64 [ %16, %22 ], [ 0, %0 ]
%14 = phi i8* [ %24, %22 ], [ %1, %0 ]
%15 = phi i32 [ %23, %22 ], [ 10, %0 ]
%16 = add nuw i64 %13, 1
%17 = zext i32 %15 to i64
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = shl nsw i32 %15, 1
%21 = tail call i8* @realloc(i8* %14, i32 %20)
br label %22
22: ; preds = %19, %12
%23 = phi i32 [ %20, %19 ], [ %15, %12 ]
%24 = phi i8* [ %21, %19 ], [ %14, %12 ]
%25 = getelementptr inbounds i8, i8* %24, i64 %16
%26 = tail call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i64, i64* @EOF
%28 = icmp eq i64 %26, %27
br i1 %28, label %5, label %12
29: ; preds = %8, %29
%30 = phi i64 [ %11, %8 ], [ %34, %29 ]
%31 = getelementptr inbounds i8, i8* %9, i64 %30
%32 = load i8, i8* %31
%33 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %32)
%34 = add nsw i64 %30, -1
%35 = icmp eq i64 %30, 0
br i1 %35, label %36, label %29
36: ; preds = %29, %5
%37 = phi i8* [ %24, %5 ], [ %9, %29 ]
%38 = tail call i32 @free(i8* %37)
ret i32 0
}