#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 stringLength(char *);
int /*<<< orphan*/ swap(char *, char *);
void reverseString(char *str) {
  int length = stringLength(str);
  for (int i = length - 1; i >= length / 2; --i) {
    swap(&str[i], &str[(length - 1) - i]);
  }
}


x86 assembly (clang, -O0):
<reverseString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <stringLength@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jl     118f <reverseString+0x6f>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
sub    -0x10(%rbp),%eax
cltq
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <reverseString+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <stringLength@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
cmp    %ecx,%eax
jle    117c <reverseString+0x5c>
movslq %eax,%r15
add    $0xffffffff,%eax
cltq
movslq %ecx,%r12
lea    (%r15,%rbx,1),%r14
add    $0xffffffffffffffff,%r14
sub    %r15,%rax
add    %rax,%rbx
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
add    $0xffffffffffffffff,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <swap@plt>
add    $0xffffffffffffffff,%r14
add    $0x1,%rbx
cmp    %r12,%r15
jg     1160 <reverseString+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @reverseString(i8* %0) {
%2 = tail call i32 @stringLength(i8* %0)
%3 = sdiv i32 %2, 2
%4 = icmp sgt i32 %2, %3
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = add nsw i32 %2, -1
%7 = sext i32 %2 to i64
%8 = sext i32 %6 to i64
%9 = sext i32 %3 to i64
br label %11
10: ; preds = %11, %1
ret void
11: ; preds = %5, %11
%12 = phi i64 [ %7, %5 ], [ %13, %11 ]
%13 = add nsw i64 %12, -1
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = sub nsw i64 %8, %13
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = tail call i32 @swap(i8* %14, i8* %16)
%18 = icmp sgt i64 %13, %9
br i1 %18, label %11, label %10
}