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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x84(%rbp)
ff ff ff
movl   $0x0,-0x88(%rbp)
lea    0xeb3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xecc(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
cltq
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1188 <main+0x68>
jmp    1164 <main+0x44>
jmp    118d <main+0x6d>
cmpl   $0x0,-0x84(%rbp)
jl     11cb <main+0xab>
mov    -0x84(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x84(%rbp)
cltq
mov    -0x40(%rbp,%rax,1),%cl
mov    -0x88(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x88(%rbp)
cltq
mov    %cl,-0x80(%rbp,%rax,1)
jmp    118d <main+0x6d>
movslq -0x88(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xecd(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xee8(%rip),%rdi
lea    0x40(%rsp),%r14
mov    %r14,%rsi
call   1040 <scanf@plt>
mov    $0xffffffff,%eax
movabs $0xffffffff00000000,%rcx
ff ff ff
movabs $0x100000000,%rdx
nopl   0x0(%rax)
add    %rdx,%rcx
add    $0x1,%eax
cmpb   $0x0,0x40(%rsp,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1170 <main+0x50>
lea    -0x2(%rbx),%edx
xor    %esi,%esi
cmp    $0xffffffff,%edx
jl     1336 <main+0x216>
sar    $0x20,%rcx
test   %eax,%eax
mov    $0x0,%r11d
cmovs  %eax,%r11d
neg    %r11d
add    %rbx,%r11
cmp    $0x8,%r11d
jb     1307 <main+0x1e7>
lea    -0x1(%rbx),%r9
mov    %r11d,%r8d
xor    %r10d,%r10d
cmp    $0x20,%r11d
jae    11c6 <main+0xa6>
xor    %esi,%esi
jmp    128c <main+0x16c>
mov    %r8d,%esi
and    $0xffffffe0,%esi
movslq %r9d,%rdx
lea    (%rsp,%rdx,1),%rdi
add    $0x30,%rdi
test   %eax,%eax
mov    $0x0,%edx
cmovs  %eax,%edx
mov    %ebx,%r15d
sub    %edx,%r15d
and    $0xffffffe0,%r15d
pxor   %xmm0,%xmm0
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movdqu -0x10(%rdi),%xmm1
movdqu (%rdi),%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,(%rsp,%rdx,1)
movdqa %xmm1,0x10(%rsp,%rdx,1)
add    $0x20,%rdx
add    $0xffffffffffffffe0,%rdi
cmp    %rdx,%r15
jne    1200 <main+0xe0>
cmp    %r8,%rsi
je     1333 <main+0x213>
test   $0x18,%r8b
je     1304 <main+0x1e4>
mov    %rsi,%rdx
mov    %r8d,%esi
and    $0xfffffff8,%esi
sub    %rsi,%rcx
mov    %rdx,%rdi
neg    %rdi
lea    (%rsp,%rdi,1),%r15
add    $0x40,%r15
movslq %r9d,%rdi
test   %eax,%eax
cmovs  %eax,%r10d
add    %r15,%rdi
add    $0xfffffffffffffff8,%rdi
mov    %ebx,%r9d
sub    %r10d,%r9d
and    $0xfffffff8,%r9d
pxor   %xmm0,%xmm0
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movq   (%rdi),%xmm1
punpcklbw %xmm0,%xmm1
pshufd $0x4e,%xmm1,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm1,%xmm1
movq   %xmm1,(%rsp,%rdx,1)
add    $0x8,%rdx
add    $0xfffffffffffffff8,%rdi
cmp    %rdx,%r9
jne    12d0 <main+0x1b0>
cmp    %r8,%rsi
jne    1307 <main+0x1e7>
jmp    1333 <main+0x213>
sub    %rsi,%rcx
add    %r14,%rcx
add    $0xffffffffffffffff,%rcx
xor    %edx,%edx
test   %eax,%eax
cmovs  %eax,%edx
sub    %edx,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%rcx),%eax
mov    %al,(%rsp,%rsi,1)
add    $0x1,%rsi
add    $0xffffffffffffffff,%rcx
cmp    %rsi,%rbx
jne    1320 <main+0x200>
mov    %r11d,%esi
movb   $0x0,(%rsp,%rsi,1)
lea    0xcd3(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [20 x i8] c"Enter any string : \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [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]* %1, i64 0, i64 0
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %7
7: ; preds = %7, %0
%8 = phi i64 [ %9, %7 ], [ -1, %0 ]
%9 = add nsw i64 %8, 1
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %13, label %7
13: ; preds = %7
%14 = trunc i64 %8 to i32
%15 = trunc i64 %9 to i32
%16 = icmp sgt i32 %14, -2
br i1 %16, label %17, label %87
17: ; preds = %13
%18 = shl i64 %9, 32
%19 = ashr exact i64 %18, 32
%20 = add i32 %15, 1
%21 = call i32 @llvm.smin.i32(i32 %15, i32 0)
%22 = sub i32 %20, %21
%23 = zext i32 %22 to i64
%24 = icmp ult i32 %22, 8
br i1 %24, label %73, label %25
25: ; preds = %17
%26 = icmp ult i32 %22, 32
br i1 %26, label %54, label %27
27: ; preds = %25
%28 = and i64 %23, 4294967264
br label %29
29: ; preds = %29, %27
%30 = phi i64 [ 0, %27 ], [ %46, %29 ]
%31 = xor i64 %30, -1
%32 = add i64 %19, %31
%33 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %32
%34 = getelementptr inbounds i8, i8* %33, i64 -15
%35 = bitcast i8* %34 to <16 x i8>*
%36 = load <16 x i8>, <16 x i8>* %35
%37 = shufflevector <16 x i8> %36, <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>
%38 = getelementptr inbounds i8, i8* %33, i64 -31
%39 = bitcast i8* %38 to <16 x i8>*
%40 = load <16 x i8>, <16 x i8>* %39
%41 = shufflevector <16 x i8> %40, <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>
%42 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %30
%43 = bitcast i8* %42 to <16 x i8>*
store <16 x i8> %37, <16 x i8>* %43
%44 = getelementptr inbounds i8, i8* %42, i64 16
%45 = bitcast i8* %44 to <16 x i8>*
store <16 x i8> %41, <16 x i8>* %45
%46 = add nuw i64 %30, 32
%47 = icmp eq i64 %46, %28
br i1 %47, label %48, label %29
48: ; preds = %29
%49 = icmp eq i64 %28, %23
br i1 %49, label %85, label %50
50: ; preds = %48
%51 = sub nsw i64 %19, %28
%52 = and i64 %23, 24
%53 = icmp eq i64 %52, 0
br i1 %53, label %73, label %54
54: ; preds = %25, %50
%55 = phi i64 [ %28, %50 ], [ 0, %25 ]
%56 = and i64 %23, 4294967288
%57 = sub nsw i64 %19, %56
br label %58
58: ; preds = %58, %54
%59 = phi i64 [ %55, %54 ], [ %69, %58 ]
%60 = xor i64 %59, -1
%61 = add i64 %19, %60
%62 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %61
%63 = getelementptr inbounds i8, i8* %62, i64 -7
%64 = bitcast i8* %63 to <8 x i8>*
%65 = load <8 x i8>, <8 x i8>* %64
%66 = shufflevector <8 x i8> %65, <8 x i8> poison, <8 x i32> <i32 7, i32 6, i32 5, i32 4, i32 3, i32 2, i32 1, i32 0>
%67 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %59
%68 = bitcast i8* %67 to <8 x i8>*
store <8 x i8> %66, <8 x i8>* %68
%69 = add nuw i64 %59, 8
%70 = icmp eq i64 %69, %56
br i1 %70, label %71, label %58
71: ; preds = %58
%72 = icmp eq i64 %56, %23
br i1 %72, label %85, label %73
73: ; preds = %17, %50, %71
%74 = phi i64 [ %19, %17 ], [ %51, %50 ], [ %57, %71 ]
%75 = phi i64 [ 0, %17 ], [ %28, %50 ], [ %56, %71 ]
br label %76
76: ; preds = %73, %76
%77 = phi i64 [ %79, %76 ], [ %74, %73 ]
%78 = phi i64 [ %82, %76 ], [ %75, %73 ]
%79 = add nsw i64 %77, -1
%80 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %79
%81 = load i8, i8* %80
%82 = add nuw nsw i64 %78, 1
%83 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %78
store i8 %81, i8* %83
%84 = icmp eq i64 %82, %23
br i1 %84, label %85, label %76
85: ; preds = %76, %71, %48
%86 = zext i32 %22 to i64
br label %87
87: ; preds = %13, %85
%88 = phi i64 [ %86, %85 ], [ 0, %13 ]
%89 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %88
store i8 0, i8* %89
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %4)
ret i32 0
}