#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*/);
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char **argv) {
  char input[82] = {};
  printf("Enter text to display backwards.\n");
  fgets(input, 82, stdin);
  if ((input[82 - 2] != 10) && (input[82 - 2] != 0)) {
    printf("Warning! The string you entered is more than 80 characters long! "
           "Cutting off string!\n");
    input[82 - 2] = 10;
    while (getchar() != '\n')
      ;
  }
  for (int i = (strlen(input) - 1); i >= 0; i--) {
    putchar(input[i]);
  }
  char *pinput = input + (strlen(input) - 1);
  for (int i = (strlen(input) - 1); i >= 0; i--) {
    putchar(*pinput);
    pinput--;
  }
  putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x52,%edx
call   1060 <memset@plt>
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    $0x52,%esi
call   1070 <fgets@plt>
movsbl -0x20(%rbp),%eax
cmp    $0xa,%eax
je     11f3 <main+0x93>
movsbl -0x20(%rbp),%eax
cmp    $0x0,%eax
je     11f3 <main+0x93>
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
movb   $0xa,-0x20(%rbp)
mov    $0x0,%al
call   1080 <getchar@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11ee <main+0x8e>
jmp    11d6 <main+0x76>
jmp    11f3 <main+0x93>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jl     1228 <main+0xc8>
movslq -0x74(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
mov    -0x74(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x74(%rbp)
jmp    1202 <main+0xa2>
lea    -0x70(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jl     129d <main+0x13d>
mov    -0x80(%rbp),%rax
movsbl (%rax),%edi
call   1030 <putchar@plt>
mov    -0x80(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x80(%rbp)
mov    -0x84(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x84(%rbp)
jmp    1264 <main+0x104>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x50(%rsp)
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x52,%esi
call   1060 <fgets@plt>
mov    0x50(%rsp),%al
test   %al,%al
je     11cb <main+0x7b>
cmp    $0xa,%al
je     11cb <main+0x7b>
lea    0xe72(%rip),%rdi
call   1040 <puts@plt>
movb   $0xa,0x50(%rsp)
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <getchar@plt>
cmp    $0xa,%al
jne    11c0 <main+0x70>
mov    %rsp,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11f6 <main+0xa6>
mov    %eax,%ebx
add    $0x1,%rbx
nopl   (%rax)
lea    -0x2(%rbx),%eax
movsbl (%rsp,%rax,1),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     11e0 <main+0x90>
mov    %rsp,%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    1235 <main+0xe5>
mov    %eax,%ebx
movslq %ebp,%rax
lea    (%rax,%r14,1),%rbp
add    $0xffffffffffffffff,%rbp
add    $0x1,%ebx
nop
movsbl 0x0(%rbp),%edi
call   1030 <putchar@plt>
add    $0xffffffffffffffff,%rbp
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1220 <main+0xd0>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter text to display backwards.\0A\00"
@stdin = global i32 0
@.str.1 = [86 x i8] c"Warning! The string you entered is more than 80 characters long! Cutting off string!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [82 x i8]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [82 x i8]* %6 to i8*
%11 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %12, i32 82, i32 %13)
%15 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 80
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %33
19: ; preds = %2
%20 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 80
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %19
%25 = call i32 @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 80
store i8 10, i8* %26
br label %27
27: ; preds = %31, %24
%28 = call signext i8 (...) @getchar()
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %32
31: ; preds = %27
br label %27
32: ; preds = %27
br label %33
33: ; preds = %32, %19, %2
%34 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 0
%35 = call i32 @strlen(i8* %34)
%36 = sub nsw i32 %35, 1
store i32 %36, i32* %7
br label %37
37: ; preds = %46, %33
%38 = load i32, i32* %7
%39 = icmp sge i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 %42
%44 = load i8, i8* %43
%45 = call i32 @putchar(i8 signext %44)
br label %46
46: ; preds = %40
%47 = load i32, i32* %7
%48 = add nsw i32 %47, -1
store i32 %48, i32* %7
br label %37
49: ; preds = %37
%50 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 0
%51 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 0
%52 = call i32 @strlen(i8* %51)
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %50, i64 %54
store i8* %55, i8** %8
%56 = getelementptr inbounds [82 x i8], [82 x i8]* %6, i64 0, i64 0
%57 = call i32 @strlen(i8* %56)
%58 = sub nsw i32 %57, 1
store i32 %58, i32* %9
br label %59
59: ; preds = %68, %49
%60 = load i32, i32* %9
%61 = icmp sge i32 %60, 0
br i1 %61, label %62, label %71
62: ; preds = %59
%63 = load i8*, i8** %8
%64 = load i8, i8* %63
%65 = call i32 @putchar(i8 signext %64)
%66 = load i8*, i8** %8
%67 = getelementptr inbounds i8, i8* %66, i32 -1
store i8* %67, i8** %8
br label %68
68: ; preds = %62
%69 = load i32, i32* %9
%70 = add nsw i32 %69, -1
store i32 %70, i32* %9
br label %59
71: ; preds = %59
%72 = call i32 @putchar(i8 signext 10)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@str = [33 x i8] c"Enter text to display backwards.\00"
@str.2 = [85 x i8] c"Warning! The string you entered is more than 80 characters long! Cutting off string!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [82 x i8]
%4 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %4, i32 82, i32 %6)
%8 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 80
%9 = load i8, i8* %8
switch i8 %9, label %10 [
i8 10, label %15
i8 0, label %15
]
10: ; preds = %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.2, i64 0, i64 0))
store i8 10, i8* %8
br label %12
12: ; preds = %12, %10
%13 = call signext i8 (...) @getchar()
%14 = icmp eq i8 %13, 10
br i1 %14, label %15, label %12
15: ; preds = %12, %2, %2
%16 = call i32 @strlen(i8* %4)
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = zext i32 %16 to i64
br label %28
20: ; preds = %28, %15
%21 = call i32 @strlen(i8* %4)
%22 = call i32 @strlen(i8* %4)
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = add nsw i32 %21, -1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 %26
br label %38
28: ; preds = %18, %28
%29 = phi i64 [ %19, %18 ], [ %30, %28 ]
%30 = add nsw i64 %29, -1
%31 = and i64 %30, 4294967295
%32 = getelementptr inbounds [82 x i8], [82 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = call i32 @putchar(i8 signext %33)
%35 = icmp ugt i64 %29, 1
br i1 %35, label %28, label %20
36: ; preds = %38, %20
%37 = call i32 @putchar(i8 signext 10)
ret i32 0
38: ; preds = %24, %38
%39 = phi i32 [ %41, %38 ], [ %22, %24 ]
%40 = phi i8* [ %44, %38 ], [ %27, %24 ]
%41 = add nsw i32 %39, -1
%42 = load i8, i8* %40
%43 = call i32 @putchar(i8 signext %42)
%44 = getelementptr inbounds i8, i8* %40, i64 -1
%45 = icmp ugt i32 %39, 1
br i1 %45, label %38, label %36
}