#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) {
  int a = 0;
  int length = 0;
  char *str2 = str;
  str2 += (strlen(str) - 1);
  length = strlen(str);
  while ((str2 - str) > 0) {
    a = *str;
    *str = *str2;
    *str2 = a;
    str++;
    str2--;
  }
  return str - length / 2;
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
sub    $0x1,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x0,%rax
jle    11ad <reverse+0x9d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    115a <reverse+0x4a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rdx
xor    %ecx,%ecx
sub    %rdx,%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%r14d
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%r14d
jl     1159 <reverse+0x49>
add    $0xffffffff,%r14d
lea    (%rbx,%r14,1),%rcx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rbx),%esi
movzbl (%rcx),%edx
mov    %dl,(%rbx)
mov    %sil,(%rcx)
add    $0x1,%rbx
add    $0xffffffffffffffff,%rcx
add    $0xfffffffffffffffe,%r14
jg     1140 <reverse+0x30>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
neg    %ecx
movslq %ecx,%rax
add    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @reverse(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = load i8*, i8** %2
store i8* %6, i8** %5
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = sub nsw i32 %8, 1
%10 = load i8*, i8** %5
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %10, i64 %11
store i8* %12, i8** %5
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %4
br label %15
15: ; preds = %22, %1
%16 = load i8*, i8** %5
%17 = load i8*, i8** %2
%18 = ptrtoint i8* %16 to i64
%19 = ptrtoint i8* %17 to i64
%20 = sub i64 %18, %19
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %15
%23 = load i8*, i8** %2
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
store i32 %25, i32* %3
%26 = load i8*, i8** %5
%27 = load i8, i8* %26
%28 = load i8*, i8** %2
store i8 %27, i8* %28
%29 = load i32, i32* %3
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %5
store i8 %30, i8* %31
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %2
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 -1
store i8* %35, i8** %5
br label %15
36: ; preds = %15
%37 = load i8*, i8** %2
%38 = load i32, i32* %4
%39 = sdiv i32 %38, 2
%40 = sext i32 %39 to i64
%41 = sub i64 0, %40
%42 = getelementptr inbounds i8, i8* %37, i64 %41
ret i8* %42
}

LLVM IR (-O2):
define i8* @reverse(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %2, 1
br i1 %4, label %5, label %20
5: ; preds = %1
%6 = add nsw i32 %2, -1
%7 = zext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
br label %9
9: ; preds = %5, %9
%10 = phi i8* [ %15, %9 ], [ %8, %5 ]
%11 = phi i8* [ %14, %9 ], [ %0, %5 ]
%12 = load i8, i8* %11
%13 = load i8, i8* %10
store i8 %13, i8* %11
store i8 %12, i8* %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = getelementptr inbounds i8, i8* %10, i64 -1
%16 = ptrtoint i8* %15 to i64
%17 = ptrtoint i8* %14 to i64
%18 = sub i64 %16, %17
%19 = icmp sgt i64 %18, 0
br i1 %19, label %9, label %20
20: ; preds = %9, %1
%21 = phi i8* [ %0, %1 ], [ %14, %9 ]
%22 = sdiv i32 %3, -2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
ret i8* %24
}