#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*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int main() {
  char str[50];
  char rev[50];
  char *sptr = str;
  char *rptr = rev;
  int i = -1;
  printf("Enter any string : ");
  gets(str);
  puts(str);
  while (*sptr) {
    sptr++;
    i++;
  }
  while (i >= 0) {
    sptr--;
    *rptr = *sptr;
    rptr++;
    --i;
  }
  *rptr = '\0';
  printf("Reverse of string is : %s", rev);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
movl   $0xffffffff,-0x94(%rbp)
ff ff ff
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
call   1050 <gets@plt>
lea    -0x40(%rbp),%rdi
call   1030 <puts@plt>
mov    -0x88(%rbp),%rax
cmpb   $0x0,(%rax)
je     11b8 <main+0x88>
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x88(%rbp)
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    1182 <main+0x52>
jmp    11bd <main+0x8d>
cmpl   $0x0,-0x94(%rbp)
jl     1214 <main+0xe4>
mov    -0x88(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    (%rax),%cl
mov    -0x90(%rbp),%rax
mov    %cl,(%rax)
mov    -0x90(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x90(%rbp)
mov    -0x94(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x94(%rbp)
jmp    11bd <main+0x8d>
mov    -0x90(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x80(%rbp),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    %rsp,%rbx
lea    0xebf(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x40(%rsp),%r14
mov    %r14,%rdi
call   1050 <gets@plt>
mov    %r14,%rdi
call   1030 <puts@plt>
cmpb   $0x0,0x40(%rsp)
je     12a5 <main+0x175>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x41(%rsp,%rax,1)
lea    0x1(%rax),%rax
jne    1170 <main+0x40>
lea    -0x2(%rax),%ecx
cmp    $0xffffffff,%ecx
jl     12a5 <main+0x175>
lea    -0x1(%rax),%rdx
lea    (%rsp,%rax,1),%rcx
add    $0x40,%rcx
mov    %rsp,%rbx
cmp    $0x1f,%edx
jb     127f <main+0x14f>
cmp    %rcx,%rbx
jae    11b7 <main+0x87>
lea    (%rsp,%rax,1),%rdx
mov    %rcx,%rsi
sub    %rax,%rsi
cmp    %rdx,%rsi
jb     127f <main+0x14f>
movabs $0x1ffffffe0,%r8
and    %rax,%r8
lea    (%rsp,%r8,1),%rbx
mov    %r8,%r9
neg    %r9
sub    %r8,%r14
mov    %r14,%rcx
add    %rax,%rcx
lea    0x10(%rsp),%rdi
xor    %edx,%edx
pxor   %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%rsp,%rdx,1),%rsi
add    $0x40,%rsi
movdqu -0x20(%rax,%rsi,1),%xmm1
movdqu -0x10(%rax,%rsi,1),%xmm2
movdqa %xmm2,%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpckhbw %xmm0,%xmm2
pshufd $0x4e,%xmm2,%xmm2
pshuflw $0x1b,%xmm2,%xmm2
pshufhw $0x1b,%xmm2,%xmm2
packuswb %xmm3,%xmm2
movdqa %xmm1,%xmm3
punpcklbw %xmm0,%xmm3
pshufd $0x4e,%xmm3,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpckhbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm3,%xmm1
movdqa %xmm2,-0x10(%rdi)
movdqa %xmm1,(%rdi)
add    $0xffffffffffffffe0,%rdx
add    $0x20,%rdi
cmp    %rdx,%r9
jne    11f0 <main+0xc0>
cmp    %r8,%rax
je     12a5 <main+0x175>
add    %rsp,%rax
add    $0xffffffffffffffff,%rax
add    $0xffffffffffffffff,%rcx
mov    %rbx,%rdx
nopl   (%rax)
movzbl (%rcx),%ebx
mov    %bl,(%rdx)
lea    0x1(%rdx),%rbx
add    $0xffffffffffffffff,%rcx
cmp    %rdx,%rax
mov    %rbx,%rdx
jne    1290 <main+0x160>
movb   $0x0,(%rbx)
lea    0xd65(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Enter any string : \00"
@.str.1 = [26 x i8] c"Reverse of string is : %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
store i8* %7, i8** %4
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
store i8* %8, i8** %5
store i32 -1, i32* %6
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%11 = call i32 @gets(i8* %10)
%12 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%13 = call i32 @puts(i8* %12)
br label %14
14: ; preds = %18, %0
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = icmp ne i8 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i32, i32* %6
%22 = add nsw i32 %21, 1
store i32 %22, i32* %6
br label %14
23: ; preds = %14
br label %24
24: ; preds = %27, %23
%25 = load i32, i32* %6
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 -1
store i8* %29, i8** %4
%30 = load i8*, i8** %4
%31 = load i8, i8* %30
%32 = load i8*, i8** %5
store i8 %31, i8* %32
%33 = load i8*, i8** %5
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %5
%35 = load i32, i32* %6
%36 = add nsw i32 %35, -1
store i32 %36, i32* %6
br label %24
37: ; preds = %24
%38 = load i8*, i8** %5
store i8 0, i8* %38
%39 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %39)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Enter any string : \00"
@.str.1 = [26 x i8] c"Reverse of string is : %s\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @gets(i8* %4)
%8 = call i32 @puts(i8* %4)
%9 = load i8, i8* %4
%10 = icmp eq i8 %9, 0
br i1 %10, label %69, label %55
11: ; preds = %55
%12 = icmp sgt i32 %56, -2
br i1 %12, label %13, label %69
13: ; preds = %11
%14 = zext i32 %59 to i64
%15 = getelementptr [50 x i8], [50 x i8]* %2, i64 0, i64 %14
%16 = add nuw nsw i64 %14, 1
%17 = icmp ult i32 %59, 31
br i1 %17, label %52, label %18
18: ; preds = %13
%19 = add nuw nsw i64 %14, 1
%20 = getelementptr [50 x i8], [50 x i8]* %2, i64 0, i64 %19
%21 = xor i64 %14, -1
%22 = getelementptr i8, i8* %58, i64 %21
%23 = icmp ult i8* %3, %58
%24 = icmp ult i8* %22, %20
%25 = and i1 %23, %24
br i1 %25, label %52, label %26
26: ; preds = %18
%27 = and i64 %16, 8589934560
%28 = getelementptr [50 x i8], [50 x i8]* %2, i64 0, i64 %27
%29 = sub nsw i64 0, %27
%30 = getelementptr i8, i8* %58, i64 %29
br label %31
31: ; preds = %31, %26
%32 = phi i64 [ 0, %26 ], [ %48, %31 ]
%33 = getelementptr [50 x i8], [50 x i8]* %2, i64 0, i64 %32
%34 = sub i64 0, %32
%35 = getelementptr inbounds i8, i8* %57, i64 %34
%36 = getelementptr inbounds i8, i8* %35, i64 -15
%37 = bitcast i8* %36 to <16 x i8>*
%38 = load <16 x i8>, <16 x i8>* %37
%39 = shufflevector <16 x i8> %38, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%40 = getelementptr inbounds i8, i8* %35, i64 -16
%41 = getelementptr inbounds i8, i8* %40, i64 -15
%42 = bitcast i8* %41 to <16 x i8>*
%43 = load <16 x i8>, <16 x i8>* %42
%44 = shufflevector <16 x i8> %43, <16 x i8> poison, <16 x i32> <i32 15, i32 14, i32 13, i32 12, i32 11, i32 10, i32 9, i32 8, i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%45 = bitcast i8* %33 to <16 x i8>*
store <16 x i8> %39, <16 x i8>* %45
%46 = getelementptr i8, i8* %33, i64 16
%47 = bitcast i8* %46 to <16 x i8>*
store <16 x i8> %44, <16 x i8>* %47
%48 = add nuw i64 %32, 32
%49 = icmp eq i64 %48, %27
br i1 %49, label %50, label %31
50: ; preds = %31
%51 = icmp eq i64 %16, %27
br i1 %51, label %69, label %52
52: ; preds = %18, %13, %50
%53 = phi i8* [ %5, %18 ], [ %5, %13 ], [ %28, %50 ]
%54 = phi i8* [ %58, %18 ], [ %58, %13 ], [ %30, %50 ]
br label %62
55: ; preds = %0, %55
%56 = phi i32 [ %59, %55 ], [ -1, %0 ]
%57 = phi i8* [ %58, %55 ], [ %4, %0 ]
%58 = getelementptr inbounds i8, i8* %57, i64 1
%59 = add nsw i32 %56, 1
%60 = load i8, i8* %58
%61 = icmp eq i8 %60, 0
br i1 %61, label %11, label %55
62: ; preds = %52, %62
%63 = phi i8* [ %67, %62 ], [ %53, %52 ]
%64 = phi i8* [ %65, %62 ], [ %54, %52 ]
%65 = getelementptr inbounds i8, i8* %64, i64 -1
%66 = load i8, i8* %65
store i8 %66, i8* %63
%67 = getelementptr inbounds i8, i8* %63, i64 1
%68 = icmp eq i8* %63, %15
br i1 %68, label %69, label %62
69: ; preds = %62, %50, %0, %11
%70 = phi i8* [ %5, %11 ], [ %5, %0 ], [ %28, %50 ], [ %67, %62 ]
store i8 0, i8* %70
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %5)
ret i32 0
}