#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 strlen(char *);
char *Reverse(char *str) {
  register int i;
  register int j;
  static char area[1024];
  j = i = strlen(str);
  while (*str) {
    area[--i] = *str++;
  }
  area[j] = '\0';
  return (area);
}


x86 assembly (clang, -O0):
<Reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1164 <Reverse+0x54>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%dl
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
movslq %eax,%rcx
lea    0x2ee4(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    112b <Reverse+0x1b>
movslq -0x10(%rbp),%rcx
lea    0x2ed1(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2ec6(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Reverse>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    (%rbx),%dl
movslq %eax,%rcx
test   %dl,%dl
je     1151 <Reverse+0x41>
lea    0x2f17(%rip),%rax
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %dl,(%rax)
movzbl (%rbx),%edx
add    $0xffffffffffffffff,%rax
add    $0x1,%rbx
test   %dl,%dl
jne    1140 <Reverse+0x30>
lea    0x2ee8(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
pop    %rbx
ret

LLVM IR (-O0):
@Reverse.area = internal global [1024 x i8] zeroinitializer
define i8* @Reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
store i32 %6, i32* %4
br label %7
7: ; preds = %11, %1
%8 = load i8*, i8** %2
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %7
%12 = load i8*, i8** %2
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %2
%14 = load i8, i8* %12
%15 = load i32, i32* %3
%16 = add nsw i32 %15, -1
store i32 %16, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* @Reverse.area, i64 0, i64 %17
store i8 %14, i8* %18
br label %7
19: ; preds = %7
%20 = load i32, i32* %4
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* @Reverse.area, i64 0, i64 %21
store i8 0, i8* %22
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Reverse.area, i64 0, i64 0)
}

LLVM IR (-O2):
@Reverse.area = internal global [1024 x i8] zeroinitializer
define i8* @Reverse(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
%5 = sext i32 %2 to i64
br i1 %4, label %15, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %11, %6 ], [ %5, %1 ]
%8 = phi i8 [ %13, %6 ], [ %3, %1 ]
%9 = phi i8* [ %10, %6 ], [ %0, %1 ]
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = add i64 %7, -1
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* @Reverse.area, i64 0, i64 %11
store i8 %8, i8* %12
%13 = load i8, i8* %10
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6, %1
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* @Reverse.area, i64 0, i64 %5
store i8 0, i8* %16
ret i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @Reverse.area, i64 0, i64 0)
}