#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*/ getch();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
void main() {
  char str[100], temp;
  int i, j = 0, len = 0;
  printf("\n Enter the string :");
  gets(str);
  for (i = 0; str[i] != '\0'; i++) {
    len++;
  }
  i = 0;
  j = len - 1;
  while (i < j) {
    temp = str[i];
    str[i] = str[j];
    str[j] = temp;
    i++;
    j--;
  }
  printf("\n Reverse string is :%s", str);
  getch();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x7c(%rbp)
movl   $0x0,-0x80(%rbp)
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <gets@plt>
movl   $0x0,-0x78(%rbp)
movslq -0x78(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1190 <main+0x60>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1167 <main+0x37>
movl   $0x0,-0x78(%rbp)
mov    -0x80(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x7c(%rbp),%eax
jge    11e9 <main+0xb9>
movslq -0x78(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x71(%rbp)
movslq -0x7c(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%cl
movslq -0x78(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x71(%rbp),%cl
movslq -0x7c(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
mov    -0x7c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7c(%rbp)
jmp    11a0 <main+0x70>
lea    -0x70(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getch@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <gets@plt>
mov    (%rsp),%cl
test   %cl,%cl
je     11b0 <main+0x80>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
cmpb   $0x0,0x1(%rsp,%rax,1)
lea    0x1(%rax),%rax
jne    1160 <main+0x30>
cmp    $0x2,%eax
jl     11b0 <main+0x80>
mov    %eax,%eax
mov    -0x1(%rax,%rbx,1),%dl
mov    %dl,(%rsp)
mov    %cl,-0x1(%rax,%rbx,1)
cmp    $0x4,%rax
jb     11b0 <main+0x80>
add    $0xfffffffffffffffe,%rax
mov    $0x2,%ecx
nopl   0x0(%rax)
movzbl -0x1(%rsp,%rcx,1),%edx
movzbl (%rsp,%rax,1),%ebx
mov    %bl,-0x1(%rsp,%rcx,1)
mov    %dl,(%rsp,%rax,1)
add    $0xffffffffffffffff,%rax
lea    0x1(%rcx),%rdx
cmp    %rax,%rcx
mov    %rdx,%rcx
jl     1190 <main+0x60>
lea    0xe5e(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getch@plt>
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\0A Enter the string :\00"
@.str.1 = [24 x i8] c"\0A Reverse string is :%s\00"
define void @main() {
%1 = alloca [100 x i8]
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %4
store i32 0, i32* %5
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%8 = call i32 @gets(i8* %7)
store i32 0, i32* %3
br label %9
9: ; preds = %19, %0
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %9
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %19
19: ; preds = %16
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %9
22: ; preds = %9
store i32 0, i32* %3
%23 = load i32, i32* %5
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %4
br label %25
25: ; preds = %29, %22
%26 = load i32, i32* %3
%27 = load i32, i32* %4
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %49
29: ; preds = %25
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %31
%33 = load i8, i8* %32
store i8 %33, i8* %2
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = load i32, i32* %3
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %39
store i8 %37, i8* %40
%41 = load i8, i8* %2
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %43
store i8 %41, i8* %44
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
store i32 %46, i32* %3
%47 = load i32, i32* %4
%48 = add nsw i32 %47, -1
store i32 %48, i32* %4
br label %25
49: ; preds = %25
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %50)
%52 = call i32 (...) @getch()
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"\0A Enter the string :\00"
@.str.1 = [24 x i8] c"\0A Reverse string is :%s\00"
define void @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @gets(i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %36, label %19
7: ; preds = %19
%8 = trunc i64 %21 to i32
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %36
10: ; preds = %7
%11 = and i64 %21, 4294967295
%12 = add nsw i64 %11, -1
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %12
%15 = load i8, i8* %14
store i8 %15, i8* %13
store i8 %5, i8* %14
%16 = icmp ugt i64 %11, 3
br i1 %16, label %17, label %36
17: ; preds = %10
%18 = add nsw i64 %11, -2
br label %25
19: ; preds = %0, %19
%20 = phi i64 [ %21, %19 ], [ 0, %0 ]
%21 = add nuw nsw i64 %20, 1
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %7, label %19
25: ; preds = %17, %25
%26 = phi i64 [ %18, %17 ], [ %34, %25 ]
%27 = phi i64 [ 1, %17 ], [ %33, %25 ]
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %27
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %26
%32 = load i8, i8* %31
store i8 %32, i8* %30
store i8 %29, i8* %31
%33 = add nuw nsw i64 %27, 1
%34 = add nsw i64 %26, -1
%35 = icmp slt i64 %33, %34
br i1 %35, label %25, label %36
36: ; preds = %25, %10, %0, %7
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%38 = call i32 (...) @getch()
ret void
}