#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 my_strrev(char *begin) {
  char temp;
  char *end;
  end = begin + strlen(begin) - 1;
  while (end > begin) {
    temp = *end;
    *end = *begin;
    *begin = temp;
    end--;
    begin++;
  }
}


x86 assembly (clang, -O0):
<my_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
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    118a <my_strrev+0x7a>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x9(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1141 <my_strrev+0x31>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_strrev>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    114c <my_strrev+0x3c>
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rax),%ecx
movzbl -0x1(%rbx),%edx
mov    %dl,(%rax)
mov    %cl,-0x1(%rbx)
add    $0xffffffffffffffff,%rax
lea    0x1(%rbx),%rcx
cmp    %rbx,%rax
mov    %rcx,%rbx
ja     1130 <my_strrev+0x20>
pop    %rbx
ret

LLVM IR (-O0):
define void @my_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
%10 = getelementptr inbounds i8, i8* %9, i64 -1
store i8* %10, i8** %4
br label %11
11: ; preds = %15, %1
%12 = load i8*, i8** %4
%13 = load i8*, i8** %2
%14 = icmp ugt i8* %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
store i8 %17, i8* %3
%18 = load i8*, i8** %2
%19 = load i8, i8* %18
%20 = load i8*, i8** %4
store i8 %19, i8* %20
%21 = load i8, i8* %3
%22 = load i8*, i8** %2
store i8 %21, i8* %22
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 -1
store i8* %24, i8** %4
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %2
br label %11
27: ; preds = %11
ret void
}

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