#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(int /*<<< orphan*/, int /*<<< orphan*/);
void reverseString(char *str) {
  char *begin = str;
  char *end = str + stringLength(str) - 1;
  while (begin < end) {
    swap(begin++, end--);
  }
}


x86 assembly (clang, -O0):
<reverseString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <stringLength@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1193 <reverseString+0x73>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    %eax,%edi
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
mov    %eax,%esi
call   1040 <swap@plt>
jmp    1159 <reverseString+0x39>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <stringLength@plt>
movslq %eax,%rcx
lea    (%r14,%rcx,1),%rbx
add    $0xffffffffffffffff,%rbx
cmp    %r14,%rbx
jbe    1171 <reverseString+0x51>
lea    (%rax,%r14,1),%ebp
add    $0xffffffff,%ebp
mov    %r14,%r15
add    $0x1,%r15
nopl   (%rax)
mov    %r14d,%edi
mov    %ebp,%esi
call   1040 <swap@plt>
add    $0xffffffffffffffff,%rbx
add    $0xffffffff,%ebp
lea    0x1(%r15),%rax
add    $0x1,%r14d
cmp    %rbx,%r15
mov    %rax,%r15
jb     1150 <reverseString+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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