#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 */
scalar_t__ EOF;
int /*<<< orphan*/ freopen(char *, char *, int /*<<< orphan*/);
char getchar();
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ putchar(char);
scalar_t__ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char str[1000];
  freopen("./sample.txt", "r", stdin);
  while (scanf("%s", str) != EOF) {
    char c = getchar();
    int len = strlen(str);
    int i;
    for (i = len - 1; i >= 0; --i) {
      printf("%c", str[i]);
    }
    putchar(c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%edx
lea    0xe7e(%rip),%rdi
lea    0xe84(%rip),%rsi
call   1060 <freopen@plt>
lea    -0x3f0(%rbp),%rsi
lea    0xe73(%rip),%rdi
call   1080 <scanf@plt>
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
je     122c <main+0xcc>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x3f1(%rbp)
lea    -0x3f0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x3f8(%rbp)
mov    -0x3f8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x3fc(%rbp)
cmpl   $0x0,-0x3fc(%rbp)
jl     121b <main+0xbb>
movslq -0x3fc(%rbp),%rax
lea    0xe18(%rip),%rdi
movsbl -0x3f0(%rbp,%rax,1),%esi
ff
call   1050 <printf@plt>
mov    -0x3fc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3fc(%rbp)
jmp    11df <main+0x7f>
movsbl -0x3f1(%rbp),%edi
call   1030 <putchar@plt>
jmp    118e <main+0x2e>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
lea    0xe7f(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1060 <freopen@plt>
lea    0xe7b(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
mov    0x2e3d(%rip),%r12
cmp    (%r12),%rax
jne    11bd <main+0x5d>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r14
lea    0xe4b(%rip),%rbx
lea    0xe41(%rip),%r15
jmp    11ea <main+0x8a>
movsbl %r13b,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
cmp    (%r12),%rax
je     11a9 <main+0x49>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%r13d
mov    %r14,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    11d0 <main+0x70>
mov    %eax,%ebp
add    $0x1,%rbp
cs nopw 0x0(%rax,%rax,1)
lea    -0x2(%rbp),%eax
movsbl (%rsp,%rax,1),%esi
mov    %rbx,%rdi
call   1050 <printf@plt>
add    $0xffffffffffffffff,%rbp
cmp    $0x1,%rbp
ja     1210 <main+0xb0>
jmp    11d0 <main+0x70>

LLVM IR (-O0):
@.str = [13 x i8] c"./sample.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.3 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [1000 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @stdin
%7 = call i32 @freopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %8
8: ; preds = %31, %0
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%10 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i64, i64* @EOF
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %34
13: ; preds = %8
%14 = call signext i8 (...) @getchar()
store i8 %14, i8* %3
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
store i32 %18, i32* %5
br label %19
19: ; preds = %28, %13
%20 = load i32, i32* %5
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %19
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %5
%30 = add nsw i32 %29, -1
store i32 %30, i32* %5
br label %19
31: ; preds = %19
%32 = load i8, i8* %3
%33 = call i32 @putchar(i8 signext %32)
br label %8
34: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"./sample.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.3 = [3 x i8] c"%c\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = tail call i32 @freopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %27, label %8
8: ; preds = %0, %22
%9 = call signext i8 (...) @getchar()
%10 = call i32 @strlen(i8* %2)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = zext i32 %10 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ %13, %12 ], [ %16, %14 ]
%16 = add nsw i64 %15, -1
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8 signext %19)
%21 = icmp ugt i64 %15, 1
br i1 %21, label %14, label %22
22: ; preds = %14, %8
%23 = call i32 @putchar(i8 signext %9)
%24 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %8
27: ; preds = %22, %0
ret i32 0
}