#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);
  int halfLength = length / 2;
  for (int charId = 0; charId < halfLength; ++charId) {
    swap(&str[charId], &str[length - charId - 1]);
  }
}


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
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1189 <reverseString+0x69>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rsi
call   1040 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114d <reverseString+0x2d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <stringLength@plt>
cmp    $0x2,%eax
jl     116c <reverseString+0x4c>
mov    %eax,%ebx
mov    %eax,%r12d
shr    %r12d
add    $0xffffffff,%ebx
mov    %r14,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %ebx,%rbx
lea    (%r14,%rbx,1),%rsi
mov    %r15,%rdi
call   1040 <swap@plt>
add    $0xffffffff,%ebx
add    $0x1,%r15
add    $0xffffffffffffffff,%r12
jne    1150 <reverseString+0x30>
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
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @stringLength(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 2
store i32 %9, i32* %4
store i32 0, i32* %5
br label %10
10: ; preds = %27, %1
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %30
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* %5
%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 = load i32, i32* %5
%22 = sub nsw i32 %20, %21
%23 = sub nsw i32 %22, 1
%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* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %10
30: ; preds = %10
ret void
}

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