#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 *str) {
  char tmp;
  int i;
  for (i = 0; i < (my_strlen(str) / 2); i++) {
    tmp = str[i];
    str[i] = str[my_strlen(str) - i - 1];
    str[my_strlen(str) - i - 1] = tmp;
  }
  return (str);
}


x86 assembly (clang, -O0):
<my_revstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11bd <my_revstr+0xad>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x9(%rbp),%al
mov    %al,-0x21(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x21(%rbp),%dl
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1123 <my_revstr+0x13>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_revstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <my_strlen@plt>
cmp    $0x2,%eax
jl     117a <my_revstr+0x6a>
mov    $0xffffffff,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%r15d
mov    %r14,%rdi
call   1030 <my_strlen@plt>
add    %ebp,%eax
cltq
movzbl (%r14,%rax,1),%eax
mov    %al,(%r14,%rbx,1)
mov    %r14,%rdi
call   1030 <my_strlen@plt>
add    %ebp,%eax
cltq
mov    %r15b,(%r14,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rax
add    $0xffffffff,%ebp
cmp    %rax,%rbx
jl     1130 <my_revstr+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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