#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 *_strrev(char *astr) {
  char *forwards = astr;
  int len = strlen(astr);
  if (len > 1) {
    char *backwards = astr + len - 1;
    while (forwards < backwards) {
      char temp = *forwards;
      *forwards++ = *backwards;
      *backwards-- = temp;
    }
  }
  return astr;
}


x86 assembly (clang, -O0):
<_strrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    1199 <_strrev+0x89>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1194 <_strrev+0x84>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    114d <_strrev+0x3d>
jmp    1199 <_strrev+0x89>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_strrev>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     115c <_strrev+0x4c>
mov    %eax,%eax
add    %r14,%rax
add    $0xffffffffffffffff,%rax
cmp    %r14,%rax
jbe    115c <_strrev+0x4c>
lea    0x1(%r14),%rcx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl -0x1(%rcx),%edx
movzbl (%rax),%ebx
mov    %bl,-0x1(%rcx)
mov    %dl,(%rax)
add    $0xffffffffffffffff,%rax
lea    0x1(%rcx),%rdx
cmp    %rax,%rcx
mov    %rdx,%rcx
jb     1140 <_strrev+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @_strrev(i8* returned %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 1
%4 = zext i32 %2 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = getelementptr inbounds i8, i8* %5, i64 -1
%7 = icmp ugt i8* %6, %0
%8 = select i1 %3, i1 %7, i1 false
br i1 %8, label %9, label %17
9: ; preds = %1, %9
%10 = phi i8* [ %15, %9 ], [ %6, %1 ]
%11 = phi i8* [ %14, %9 ], [ %0, %1 ]
%12 = load i8, i8* %11
%13 = load i8, i8* %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %13, i8* %11
store i8 %12, i8* %10
%15 = getelementptr inbounds i8, i8* %10, i64 -1
%16 = icmp ult i8* %14, %15
br i1 %16, label %9, label %17
17: ; preds = %9, %1
ret i8* %0
}