#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 len(char *);
int /*<<< orphan*/ printf(char *, char *);
void reverseString(char a[]) {
  int m, i;
  m = len(a);
  char x[m];
  for (i = 0; i < m; i++)
    x[i] = a[i];
  for (i = 0; a[i] != '\0'; i++) {
    a[i] = x[m - 1];
    m--;
  }
  printf("The reverse string is %s\n", a);
}


x86 assembly (clang, -O0):
<reverseString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <len@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1195 <reverseString+0x75>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1165 <reverseString+0x45>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11e3 <reverseString+0xc3>
mov    -0x28(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    119c <reverseString+0x7c>
mov    -0x8(%rbp),%rsi
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseString>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <len@plt>
mov    %eax,%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
test   %eax,%eax
jle    1168 <reverseString+0x38>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <memcpy@plt>
cmpb   $0x0,(%r15)
je     1193 <reverseString+0x63>
movslq %r14d,%rax
lea    0x1(%r15),%rcx
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
nopl   0x0(%rax)
movzbl (%rax),%edx
mov    %dl,-0x1(%rcx)
add    $0xffffffffffffffff,%rax
cmpb   $0x0,(%rcx)
lea    0x1(%rcx),%rcx
jne    1180 <reverseString+0x50>
lea    0xe66(%rip),%rdi
mov    %r15,%rsi
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

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

LLVM IR (-O2):
@.str = [26 x i8] c"The reverse string is %s\0A\00"
define void @reverseString(i8* %0) {
%2 = tail call i32 @len(i8* %0)
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %7
6: ; preds = %1
br label %7
7: ; preds = %6, %1
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %7
%11 = sext i32 %2 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %19, %12 ]
%14 = phi i64 [ %11, %10 ], [ %16, %12 ]
%15 = phi i8* [ %0, %10 ], [ %20, %12 ]
%16 = add i64 %14, -1
%17 = getelementptr inbounds i8, i8* %4, i64 %16
%18 = load i8, i8* %17
store i8 %18, i8* %15
%19 = add nuw nsw i64 %13, 1
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %12
23: ; preds = %12, %7
%24 = tail call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
ret void
}