#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*/ _ith_element(void *, int, int);
int /*<<< orphan*/ _swap_elems(int /*<<< orphan*/, int /*<<< orphan*/, int,
                               void *);
void _reverse(void *array, int elem_size, int array_len, void *buffer) {
  int i;
  for (i = 0; i < array_len / 2; ++i) {
    _swap_elems(_ith_element(array, (i), elem_size),
                _ith_element(array, (array_len - 1 - i), elem_size), elem_size,
                buffer);
  }
}


x86 assembly (clang, -O0):
<_reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11a1 <_reverse+0x81>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <_ith_element@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
sub    -0x1c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <_ith_element@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1030 <_swap_elems@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113d <_reverse+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_reverse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edx
jl     1189 <_reverse+0x69>
mov    %rcx,%r14
mov    %edx,%ebp
mov    %esi,%r12d
mov    %rdi,%r15
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
mov    %eax,0x4(%rsp)
add    $0xffffffff,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    %r15,%rdi
mov    %ebx,%esi
mov    %r12d,%edx
call   1040 <_ith_element@plt>
mov    %eax,%r13d
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12d,%edx
call   1040 <_ith_element@plt>
mov    %r13d,%edi
mov    %eax,%esi
mov    %r12d,%edx
mov    %r14,%rcx
call   1030 <_swap_elems@plt>
add    $0x1,%ebx
add    $0xffffffff,%ebp
cmp    %ebx,0x4(%rsp)
jne    1150 <_reverse+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @_reverse(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32 0, i32* %9
br label %10
10: ; preds = %30, %4
%11 = load i32, i32* %9
%12 = load i32, i32* %7
%13 = sdiv i32 %12, 2
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %33
15: ; preds = %10
%16 = load i8*, i8** %5
%17 = load i32, i32* %9
%18 = load i32, i32* %6
%19 = call i32 @_ith_element(i8* %16, i32 %17, i32 %18)
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = sub nsw i32 %21, 1
%23 = load i32, i32* %9
%24 = sub nsw i32 %22, %23
%25 = load i32, i32* %6
%26 = call i32 @_ith_element(i8* %20, i32 %24, i32 %25)
%27 = load i32, i32* %6
%28 = load i8*, i8** %8
%29 = call i32 @_swap_elems(i32 %19, i32 %26, i32 %27, i8* %28)
br label %30
30: ; preds = %15
%31 = load i32, i32* %9
%32 = add nsw i32 %31, 1
store i32 %32, i32* %9
br label %10
33: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @_reverse(i8* %0, i32 %1, i32 %2, i8* %3) {
%5 = sdiv i32 %2, 2
%6 = icmp sgt i32 %2, 1
br i1 %6, label %7, label %16
7: ; preds = %4, %7
%8 = phi i32 [ %14, %7 ], [ 0, %4 ]
%9 = tail call i32 @_ith_element(i8* %0, i32 %8, i32 %1)
%10 = xor i32 %8, -1
%11 = add i32 %10, %2
%12 = tail call i32 @_ith_element(i8* %0, i32 %11, i32 %1)
%13 = tail call i32 @_swap_elems(i32 %9, i32 %12, i32 %1, i8* %3)
%14 = add nuw nsw i32 %8, 1
%15 = icmp eq i32 %14, %5
br i1 %15, label %16, label %7
16: ; preds = %7, %4
ret void
}