#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 *);
void reverse(char *string, unsigned int length) {
  const unsigned int middle = length >> 1;
  for (unsigned int index = 0; index < middle; ++index) {
    swap(string + index, string + length - index - 1);
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    1173 <reverse+0x63>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%eax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%eax
add    %rax,%rsi
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
xor    %eax,%eax
sub    %rcx,%rax
add    %rax,%rsi
add    $0xffffffffffffffff,%rsi
call   1030 <swap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112f <reverse+0x1f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%esi
jb     1149 <reverse+0x39>
mov    %esi,%r14d
mov    %rdi,%r15
mov    %esi,%eax
shr    %r14d
lea    (%rdi,%rax,1),%rbx
add    $0xffffffffffffffff,%rbx
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
add    $0x1,%r15
add    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%r14
jne    1130 <reverse+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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