#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 */
char *RevertString(char *str, int length) {
  char *pStart = str;
  char *pEnd = str + length - 1;
  char chTemp;
  if (NULL != str) {
    while (pStart < pEnd) {
      chTemp = *pStart;
      *pStart++ = *pEnd;
      *pEnd-- = chTemp;
    }
  }
  return str;
}


x86 assembly (clang, -O0):
<RevertString>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
je     1183 <RevertString+0x83>
jmp    1137 <RevertString+0x37>
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    117e <RevertString+0x7e>
mov    -0x18(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x21(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    1137 <RevertString+0x37>
jmp    1183 <RevertString+0x83>
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<RevertString>:
mov    %rdi,%rax
test   %rdi,%rdi
je     113d <RevertString+0x3d>
movslq %esi,%rcx
add    %rax,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rax,%rcx
jbe    113d <RevertString+0x3d>
lea    0x1(%rax),%rdi
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rdi),%esi
movzbl (%rcx),%edx
mov    %dl,-0x1(%rdi)
mov    %sil,(%rcx)
add    $0xffffffffffffffff,%rcx
lea    0x1(%rdi),%rdx
cmp    %rcx,%rdi
mov    %rdx,%rdi
jb     1120 <RevertString+0x20>
ret

LLVM IR (-O0):
define i8* @RevertString(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = load i8*, i8** %3
store i8* %8, i8** %5
%9 = load i8*, i8** %3
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %9, i64 %11
%13 = getelementptr inbounds i8, i8* %12, i64 -1
store i8* %13, i8** %6
%14 = load i8*, i8** %3
%15 = icmp ne i8* null, %14
br i1 %15, label %16, label %32
16: ; preds = %2
br label %17
17: ; preds = %21, %16
%18 = load i8*, i8** %5
%19 = load i8*, i8** %6
%20 = icmp ult i8* %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i8*, i8** %5
%23 = load i8, i8* %22
store i8 %23, i8* %7
%24 = load i8*, i8** %6
%25 = load i8, i8* %24
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %5
store i8 %25, i8* %26
%28 = load i8, i8* %7
%29 = load i8*, i8** %6
%30 = getelementptr inbounds i8, i8* %29, i32 -1
store i8* %30, i8** %6
store i8 %28, i8* %29
br label %17
31: ; preds = %17
br label %32
32: ; preds = %31, %2
%33 = load i8*, i8** %3
ret i8* %33
}

LLVM IR (-O2):
define i8* @RevertString(i8* returned %0, i32 %1) {
%3 = sext i32 %1 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = icmp ne i8* %0, null
%6 = getelementptr inbounds i8, i8* %4, i64 -1
%7 = icmp ugt i8* %6, %0
%8 = select i1 %5, i1 %7, i1 false
br i1 %8, label %9, label %17
9: ; preds = %2, %9
%10 = phi i8* [ %15, %9 ], [ %6, %2 ]
%11 = phi i8* [ %14, %9 ], [ %0, %2 ]
%12 = load i8, i8* %11
%13 = load i8, i8* %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
store i8 %13, i8* %11
store i8 %12, i8* %10
%15 = getelementptr inbounds i8, i8* %10, i64 -1
%16 = icmp ult i8* %14, %15
br i1 %16, label %9, label %17
17: ; preds = %9, %2
ret i8* %0
}