#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 strlen(char *);
int main(void) {
  char chArr[100];
  char temp;
  int n;
  printf("Enter string you want to see reversed: ");
  scanf("%99[^\n]", chArr);
  n = strlen(chArr);
  for (int i = 0; i < n / 2; i++) {
    temp = chArr[i];
    chArr[i] = chArr[n - i - 1];
    chArr[n - i - 1] = temp;
  }
  printf("Reversed String: %s\n", chArr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xecd(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x78(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x80(%rbp),%eax
cmp    %ecx,%eax
jge    11d3 <main+0xa3>
movslq -0x7c(%rbp),%rax
mov    -0x70(%rbp,%rax,1),%al
mov    %al,-0x71(%rbp)
mov    -0x78(%rbp),%eax
sub    -0x7c(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x70(%rbp,%rax,1),%cl
movslq -0x7c(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x71(%rbp),%cl
mov    -0x78(%rbp),%eax
sub    -0x7c(%rbp),%eax
sub    $0x1,%eax
cltq
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    1173 <main+0x43>
lea    -0x70(%rbp),%rsi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x70,%rsp
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xede(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     11cf <main+0x9f>
mov    %eax,%r8d
shr    %r8d
cmp    $0x1,%r8d
jne    1172 <main+0x42>
xor    %edx,%edx
jmp    11b5 <main+0x85>
mov    %r8d,%esi
and    $0xfffffffe,%esi
lea    -0x2(%rax),%edi
xor    %edx,%edx
nopl   (%rax)
movzbl (%rsp,%rdx,1),%r9d
lea    0x1(%rdi),%ecx
movslq %ecx,%rcx
movzbl (%rsp,%rcx,1),%ebx
mov    %bl,(%rsp,%rdx,1)
mov    %r9b,(%rsp,%rcx,1)
movzbl 0x1(%rsp,%rdx,1),%ecx
movslq %edi,%rdi
movzbl (%rsp,%rdi,1),%ebx
mov    %bl,0x1(%rsp,%rdx,1)
mov    %cl,(%rsp,%rdi,1)
add    $0x2,%rdx
add    $0xfffffffe,%edi
cmp    %rdx,%rsi
jne    1180 <main+0x50>
test   $0x1,%r8b
je     11cf <main+0x9f>
mov    (%rsp,%rdx,1),%cl
mov    %edx,%esi
not    %esi
add    %esi,%eax
cltq
mov    (%rsp,%rax,1),%bl
mov    %bl,(%rsp,%rdx,1)
mov    %cl,(%rsp,%rax,1)
lea    0xe5a(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Enter string you want to see reversed: \00"
@.str.1 = [8 x i8] c"%99[^\0A]\00"
@.str.2 = [21 x i8] c"Reversed String: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %4
store i32 0, i32* %5
br label %11
11: ; preds = %38, %0
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = sdiv i32 %13, 2
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %41
16: ; preds = %11
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
store i8 %20, i8* %3
%21 = load i32, i32* %4
%22 = load i32, i32* %5
%23 = sub nsw i32 %21, %22
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %29
store i8 %27, i8* %30
%31 = load i8, i8* %3
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = sub nsw i32 %32, %33
%35 = sub nsw i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %36
store i8 %31, i8* %37
br label %38
38: ; preds = %16
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
br label %11
41: ; preds = %11
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"Enter string you want to see reversed: \00"
@.str.1 = [8 x i8] c"%99[^\0A]\00"
@.str.2 = [21 x i8] c"Reversed String: %s\0A\00"
define i32 @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 ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 @strlen(i8* %2)
%6 = icmp sgt i32 %5, 1
br i1 %6, label %7, label %26
7: ; preds = %0
%8 = lshr i32 %5, 1
%9 = zext i32 %8 to i64
%10 = and i64 %9, 1
%11 = icmp eq i32 %8, 1
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = and i64 %9, 2147483646
br label %28
14: ; preds = %28, %7
%15 = phi i64 [ 0, %7 ], [ %48, %28 ]
%16 = icmp eq i64 %10, 0
br i1 %16, label %26, label %17
17: ; preds = %14
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %15
%19 = load i8, i8* %18
%20 = trunc i64 %15 to i32
%21 = xor i32 %20, -1
%22 = add i32 %5, %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %23
%25 = load i8, i8* %24
store i8 %25, i8* %18
store i8 %19, i8* %24
br label %26
26: ; preds = %17, %14, %0
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret i32 0
28: ; preds = %28, %12
%29 = phi i64 [ 0, %12 ], [ %48, %28 ]
%30 = phi i64 [ 0, %12 ], [ %49, %28 ]
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %29
%32 = load i8, i8* %31
%33 = trunc i64 %29 to i32
%34 = xor i32 %33, -1
%35 = add i32 %5, %34
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %31
store i8 %32, i8* %37
%39 = or i64 %29, 1
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = trunc i64 %39 to i32
%43 = xor i32 %42, -1
%44 = add i32 %5, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %45
%47 = load i8, i8* %46
store i8 %47, i8* %40
store i8 %41, i8* %46
%48 = add nuw nsw i64 %29, 2
%49 = add i64 %30, 2
%50 = icmp eq i64 %49, %13
br i1 %50, label %14, label %28
}