#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 *);
void strrev(char *str) {
  char *tail, tmp;
  tail = str + strlen(str);
  while (tail > str) {
    tmp = *--tail;
    *tail = *str;
    *str++ = tmp;
  }
}


x86 assembly (clang, -O0):
<strrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    1185 <strrev+0x75>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
mov    -0x1(%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    113d <strrev+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrev>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    114a <strrev+0x3a>
mov    %eax,%eax
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cs nopw 0x0(%rax,%rax,1)
movzbl (%rax),%ecx
movzbl (%rbx),%edx
mov    %dl,(%rax)
mov    %cl,(%rbx)
add    $0x1,%rbx
lea    -0x1(%rax),%rcx
cmp    %rbx,%rax
mov    %rcx,%rax
ja     1130 <strrev+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @strrev(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %5, i64 %8
store i8* %9, i8** %3
br label %10
10: ; preds = %14, %1
%11 = load i8*, i8** %3
%12 = load i8*, i8** %2
%13 = icmp ugt i8* %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 -1
store i8* %16, i8** %3
%17 = load i8, i8* %16
store i8 %17, i8* %4
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = load i8*, i8** %3
store i8 %19, i8* %20
%21 = load i8, i8* %4
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %2
store i8 %21, i8* %22
br label %10
24: ; preds = %10
ret void
}

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