#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(unsigned char *, unsigned char *);
void byteSwap(void *array, int num) {
  unsigned char *a = (unsigned char *)array;
  int i = 0;
  for (i; i < num / 2; i++) {
    swap(&a[i], &a[num - 1 - i]);
  }
}


x86 assembly (clang, -O0):
<byteSwap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    117c <byteSwap+0x6c>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
sub    -0x1c(%rbp),%eax
cltq
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <byteSwap+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<byteSwap>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     114c <byteSwap+0x3c>
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%r12d
shr    %r12d
add    $0xffffffff,%ebx
mov    %rdi,%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 <byteSwap+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @byteSwap(i8* %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 void
}