#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 */
size_t strlen(char *);
int /*<<< orphan*/ strswap(char *, char *);
void strrev(char *str) {
  size_t len = strlen(str);
  int start = 0;
  int end = len - 1;
  while (start < end) {
    strswap(str + start, str + end);
    start++;
    end--;
  }
}


x86 assembly (clang, -O0):
<strrev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1189 <strrev+0x69>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
call   1040 <strswap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <strrev+0x2b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrev>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
add    $0xffffffff,%eax
test   %eax,%eax
jle    1186 <strrev+0x66>
movabs $0xffffffff00000000,%r15
ff ff ff
mov    %eax,%r12d
lea    (%r14,%r12,1),%r13
shl    $0x20,%r12
add    %r15,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <strswap@plt>
add    $0x1,%rbx
mov    %r12,%rax
sar    $0x20,%rax
add    $0x1,%r14
add    $0xffffffffffffffff,%r13
add    %r15,%r12
cmp    %rax,%rbx
jl     1160 <strrev+0x40>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @strrev(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = trunc i64 %2 to i32
%4 = add i32 %3, -1
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = zext i32 %4 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %14, %8 ]
%10 = phi i64 [ %7, %6 ], [ %15, %8 ]
%11 = getelementptr inbounds i8, i8* %0, i64 %9
%12 = getelementptr inbounds i8, i8* %0, i64 %10
%13 = tail call i32 @strswap(i8* %11, i8* %12)
%14 = add nuw nsw i64 %9, 1
%15 = add nsw i64 %10, -1
%16 = shl i64 %15, 32
%17 = ashr exact i64 %16, 32
%18 = icmp slt i64 %14, %17
br i1 %18, label %8, label %19
19: ; preds = %8, %1
ret void
}