#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 */
typedef scalar_t__ uint;
typedef int int64_t;

/* Variables and functions */
void byte_swap_long(int64_t *buffer, uint number_of_swaps) {
  int64_t *temp = buffer;
  uint swap_loop;
  for (swap_loop = 0, temp = buffer; swap_loop < number_of_swaps;
       swap_loop++, temp++) {
    *temp = ((*temp & 0x000000ff) << 24) | ((*temp & 0x0000ff00) << 8) |
            ((*temp & 0x00ff0000) >> 8) | ((*temp & 0xff000000) >> 24);
  }
}


x86 assembly (clang, -O0):
<byte_swap_long>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1194 <byte_swap_long+0x94>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
and    $0xff,%ecx
shl    $0x18,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0xff00,%eax
shl    $0x8,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0xff0000,%eax
sar    $0x8,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
and    $0xff000000,%eax
shr    $0x18,%eax
or     %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x18(%rbp)
jmp    1124 <byte_swap_long+0x24>
pop    %rbp
ret

x86 assembly (clang, -O2):
<byte_swap_long>:
test   %rsi,%rsi
jle    11c1 <byte_swap_long+0xc1>
cmp    $0x8,%rsi
jae    1119 <byte_swap_long+0x19>
xor    %ecx,%ecx
mov    %rdi,%rax
jmp    119c <byte_swap_long+0x9c>
mov    %rsi,%rcx
and    $0xfffffffffffffff8,%rcx
lea    (%rdi,%rcx,4),%rax
xor    %edx,%edx
pxor   %xmm0,%xmm0
nopw   0x0(%rax,%rax,1)
movdqu (%rdi,%rdx,4),%xmm1
movdqu 0x10(%rdi,%rdx,4),%xmm2
movdqa %xmm1,%xmm3
punpckhbw %xmm0,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpcklbw %xmm0,%xmm1
pshuflw $0x1b,%xmm1,%xmm1
pshufhw $0x1b,%xmm1,%xmm1
packuswb %xmm3,%xmm1
movdqa %xmm2,%xmm3
punpckhbw %xmm0,%xmm3
pshuflw $0x1b,%xmm3,%xmm3
pshufhw $0x1b,%xmm3,%xmm3
punpcklbw %xmm0,%xmm2
pshuflw $0x1b,%xmm2,%xmm2
pshufhw $0x1b,%xmm2,%xmm2
packuswb %xmm3,%xmm2
movdqu %xmm1,(%rdi,%rdx,4)
movdqu %xmm2,0x10(%rdi,%rdx,4)
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    1130 <byte_swap_long+0x30>
cmp    %rsi,%rcx
je     11c1 <byte_swap_long+0xc1>
sub    %rcx,%rsi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rax,%rcx,4),%edx
bswap  %edx
mov    %edx,(%rax,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rsi
jne    11b0 <byte_swap_long+0xb0>
ret

LLVM IR (-O0):
define void @byte_swap_long(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32*
%6 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = load i32*, i32** %3
store i32* %7, i32** %5
store i64 0, i64* %6
%8 = load i32*, i32** %3
store i32* %8, i32** %5
br label %9
9: ; preds = %34, %2
%10 = load i64, i64* %6
%11 = load i64, i64* %4
%12 = icmp slt i64 %10, %11
br i1 %12, label %13, label %39
13: ; preds = %9
%14 = load i32*, i32** %5
%15 = load i32, i32* %14
%16 = and i32 %15, 255
%17 = shl i32 %16, 24
%18 = load i32*, i32** %5
%19 = load i32, i32* %18
%20 = and i32 %19, 65280
%21 = shl i32 %20, 8
%22 = or i32 %17, %21
%23 = load i32*, i32** %5
%24 = load i32, i32* %23
%25 = and i32 %24, 16711680
%26 = ashr i32 %25, 8
%27 = or i32 %22, %26
%28 = load i32*, i32** %5
%29 = load i32, i32* %28
%30 = and i32 %29, -16777216
%31 = lshr i32 %30, 24
%32 = or i32 %27, %31
%33 = load i32*, i32** %5
store i32 %32, i32* %33
br label %34
34: ; preds = %13
%35 = load i64, i64* %6
%36 = add nsw i64 %35, 1
store i64 %36, i64* %6
%37 = load i32*, i32** %5
%38 = getelementptr inbounds i32, i32* %37, i32 1
store i32* %38, i32** %5
br label %9
39: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @byte_swap_long(i32* nocapture %0, i64 %1) {
%3 = icmp sgt i64 %1, 0
br i1 %3, label %4, label %36
4: ; preds = %2
%5 = icmp ult i64 %1, 8
br i1 %5, label %25, label %6
6: ; preds = %4
%7 = and i64 %1, -8
%8 = getelementptr i32, i32* %0, i64 %7
br label %9
9: ; preds = %9, %6
%10 = phi i64 [ 0, %6 ], [ %21, %9 ]
%11 = getelementptr i32, i32* %0, i64 %10
%12 = bitcast i32* %11 to <4 x i32>*
%13 = load <4 x i32>, <4 x i32>* %12
%14 = getelementptr i32, i32* %11, i64 4
%15 = bitcast i32* %14 to <4 x i32>*
%16 = load <4 x i32>, <4 x i32>* %15
%17 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %13)
%18 = call <4 x i32> @llvm.bswap.v4i32(<4 x i32> %16)
%19 = bitcast i32* %11 to <4 x i32>*
store <4 x i32> %17, <4 x i32>* %19
%20 = bitcast i32* %14 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %20
%21 = add nuw i64 %10, 8
%22 = icmp eq i64 %21, %7
br i1 %22, label %23, label %9
23: ; preds = %9
%24 = icmp eq i64 %7, %1
br i1 %24, label %36, label %25
25: ; preds = %4, %23
%26 = phi i64 [ 0, %4 ], [ %7, %23 ]
%27 = phi i32* [ %0, %4 ], [ %8, %23 ]
br label %28
28: ; preds = %25, %28
%29 = phi i64 [ %33, %28 ], [ %26, %25 ]
%30 = phi i32* [ %34, %28 ], [ %27, %25 ]
%31 = load i32, i32* %30
%32 = tail call i32 @llvm.bswap.i32(i32 %31)
store i32 %32, i32* %30
%33 = add nuw nsw i64 %29, 1
%34 = getelementptr inbounds i32, i32* %30, i64 1
%35 = icmp eq i64 %33, %1
br i1 %35, label %36, label %28
36: ; preds = %28, %23, %2
ret void
}