#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 my_strlen(char *);
char *my_revstr(char *src) {
  char *p1;
  char *p2;
  char tmp;
  p1 = src;
  p2 = p1 + my_strlen(src) - 2;
  while (p1 < p2) {
    tmp = *p1;
    *p1 = *p2;
    *p2 = tmp;
    p1++;
    p2--;
  }
  return (src);
}


x86 assembly (clang, -O0):
<my_revstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xfffffffffffffffe,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1192 <my_revstr+0x82>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x19(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x19(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1149 <my_revstr+0x39>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_revstr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <my_strlen@plt>
cltq
lea    (%r14,%rax,1),%rcx
add    $0xfffffffffffffffe,%rcx
cmp    %r14,%rcx
jbe    115c <my_revstr+0x4c>
add    %r14,%rax
add    $0xfffffffffffffffd,%rax
mov    %r14,%rcx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%rcx),%edx
movzbl 0x1(%rax),%ebx
mov    %bl,(%rcx)
mov    %dl,0x1(%rax)
add    $0x1,%rcx
lea    -0x1(%rax),%rdx
cmp    %rax,%rcx
mov    %rdx,%rax
jb     1140 <my_revstr+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i8* @my_revstr(i8* returned %0) {
%2 = tail call i32 @my_strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = getelementptr inbounds i8, i8* %4, i64 -2
%6 = icmp ugt i8* %5, %0
br i1 %6, label %7, label %15
7: ; preds = %1, %7
%8 = phi i8* [ %12, %7 ], [ %0, %1 ]
%9 = phi i8* [ %13, %7 ], [ %5, %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* %8, i64 1
%13 = getelementptr inbounds i8, i8* %9, i64 -1
%14 = icmp ult i8* %12, %13
br i1 %14, label %7, label %15
15: ; preds = %7, %1
ret i8* %0
}