#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 /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  int i, n;
  char s[21];
  fgets(s, 21, stdin);
  n = strlen(s);
  for (i = n; i >= 0; i--)
    printf("%c", s[i]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
mov    0x2e9e(%rip),%rax
mov    (%rax),%edx
mov    $0x15,%esi
call   1050 <fgets@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1195 <main+0x65>
movslq -0x8(%rbp),%rax
lea    0xe83(%rip),%rdi
movsbl -0x30(%rbp,%rax,1),%esi
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1168 <main+0x38>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2eaa(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x15,%esi
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     1182 <main+0x52>
mov    %eax,%ebx
lea    0xe9b(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
add    $0xffffffffffffffff,%rbx
jb     1170 <main+0x40>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [21 x i8]
store i32 0, i32* %1
%5 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 21, i32 %6)
%8 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
store i32 %10, i32* %2
br label %11
11: ; preds = %20, %0
%12 = load i32, i32* %2
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %11
%15 = load i32, i32* %2
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [21 x i8], [21 x i8]* %4, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %18)
br label %20
20: ; preds = %14
%21 = load i32, i32* %2
%22 = add nsw i32 %21, -1
store i32 %22, i32* %2
br label %11
23: ; preds = %11
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca [21 x i8]
%2 = getelementptr inbounds [21 x i8], [21 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i32 @fgets(i8* %2, i32 21, i32 %3)
%5 = call i32 @strlen(i8* %2)
%6 = icmp sgt i32 %5, -1
br i1 %6, label %7, label %16
7: ; preds = %0
%8 = zext i32 %5 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ %8, %7 ], [ %14, %9 ]
%11 = getelementptr inbounds [21 x i8], [21 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = add nsw i64 %10, -1
%15 = icmp eq i64 %10, 0
br i1 %15, label %16, label %9
16: ; preds = %9, %0
ret i32 0
}