#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*/ assert(int);
void *blockIndex(void const *const, size_t const, size_t const);
int /*<<< orphan*/ swap(void *const, void *const, size_t const);
void reverse(const void *const addr, const size_t num_elems,
             const size_t elem_size) {
  assert(((addr)) && "Unexpected null pointer.");
  ;
  assert(((elem_size) != 0) && "Expected non-zero.");
  for (int i = 0; i < num_elems / 2; ++i) {
    void *const p1 = blockIndex(addr, i, elem_size);
    void *const p2 = blockIndex(addr, num_elems - i - 1, elem_size);
    swap(p1, p2, elem_size);
  }
}


x86 assembly (clang, -O0):
<reverse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x31(%rbp)
je     115e <reverse+0x2e>
mov    $0x1,%al
mov    %al,-0x31(%rbp)
jmp    115e <reverse+0x2e>
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x32(%rbp)
je     1185 <reverse+0x55>
mov    $0x1,%al
mov    %al,-0x32(%rbp)
jmp    1185 <reverse+0x55>
mov    -0x32(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
mov    -0x10(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jae    1202 <reverse+0xd2>
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <blockIndex@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
sub    %rax,%rsi
sub    $0x1,%rsi
mov    -0x18(%rbp),%rdx
call   1040 <blockIndex@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <swap@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1199 <reverse+0x69>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reverse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
xor    %edi,%edi
test   %r15,%r15
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
cmp    $0x2,%r12
jb     11ba <reverse+0x8a>
mov    %r12,%rbp
shr    %rbp
add    $0xffffffffffffffff,%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <blockIndex@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
call   1040 <blockIndex@plt>
mov    %r13,%rdi
mov    %rax,%rsi
mov    %r14,%rdx
call   1050 <swap@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r12
cmp    %rbx,%rbp
jne    1180 <reverse+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Unexpected null pointer.\00"
@.str.1 = [19 x i8] c"Expected non-zero.\00"
define void @reverse(i8* %0, i64 %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %3
br label %13
13: ; preds = %12, %3
%14 = phi i1 [ false, %3 ], [ true, %12 ]
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i64, i64* %6
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %13
br label %20
20: ; preds = %19, %13
%21 = phi i1 [ false, %13 ], [ true, %19 ]
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
store i32 0, i32* %7
br label %24
24: ; preds = %48, %20
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = load i64, i64* %5
%28 = udiv i64 %27, 2
%29 = icmp ult i64 %26, %28
br i1 %29, label %30, label %51
30: ; preds = %24
%31 = load i8*, i8** %4
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = load i64, i64* %6
%35 = call i8* @blockIndex(i8* %31, i64 %33, i64 %34)
store i8* %35, i8** %8
%36 = load i8*, i8** %4
%37 = load i64, i64* %5
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = sub i64 %37, %39
%41 = sub i64 %40, 1
%42 = load i64, i64* %6
%43 = call i8* @blockIndex(i8* %36, i64 %41, i64 %42)
store i8* %43, i8** %9
%44 = load i8*, i8** %8
%45 = load i8*, i8** %9
%46 = load i64, i64* %6
%47 = call i32 @swap(i8* %44, i8* %45, i64 %46)
br label %48
48: ; preds = %30
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %24
51: ; preds = %24
ret void
}

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