#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 /*<<< orphan*/ swap(char *, char *);
char *reverseStr(char *str, int length) {
  int pos;
  for (pos = 0; pos < length / 2; pos++)
    swap(&str[pos], &str[length - pos - 1]);
  return str;
}


x86 assembly (clang, -O0):
<reverseStr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-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
jge    1174 <reverseStr+0x64>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
sub    $0x1,%eax
cltq
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <reverseStr+0x16>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverseStr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmp    $0x2,%esi
jl     114c <reverseStr+0x3c>
mov    %esi,%ebx
mov    %esi,%r12d
shr    %r12d
add    $0xffffffff,%ebx
mov    %r14,%r15
xchg   %ax,%ax
movslq %ebx,%rbx
lea    (%r14,%rbx,1),%rsi
mov    %r15,%rdi
call   1030 <swap@plt>
add    $0xffffffff,%ebx
add    $0x1,%r15
add    $0xffffffffffffffff,%r12
jne    1130 <reverseStr+0x20>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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