#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_oct(char *, char *);
void nflip_endian(void *ptr, size_t size) {
  size_t i;
  char *tab;
  if (ptr == NULL || size < 2)
    return;
  i = 0;
  tab = (char *)ptr;
  while (i < (size / 2)) {
    swap_oct(&tab[i], &tab[size - i - 1]);
    i++;
  }
}


x86 assembly (clang, -O0):
<nflip_endian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1136 <nflip_endian+0x26>
cmpq   $0x2,-0x10(%rbp)
jae    113b <nflip_endian+0x2b>
jmp    1191 <nflip_endian+0x81>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jae    1191 <nflip_endian+0x81>
mov    -0x20(%rbp),%rdi
add    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rax
sub    -0x18(%rbp),%rax
sub    $0x1,%rax
add    %rax,%rsi
call   1030 <swap_oct@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    114b <nflip_endian+0x3b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nflip_endian>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     1159 <nflip_endian+0x49>
mov    %rsi,%r14
cmp    $0x2,%rsi
jb     1159 <nflip_endian+0x49>
mov    %rdi,%r15
lea    (%r14,%rdi,1),%rbx
add    $0xffffffffffffffff,%rbx
shr    %r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1030 <swap_oct@plt>
add    $0x1,%r15
add    $0xffffffffffffffff,%rbx
add    $0xffffffffffffffff,%r14
jne    1140 <nflip_endian+0x30>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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