#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 int uint32_t;
typedef int /*<<< orphan*/ int32_t;

/* Variables and functions */
void s32_swap(int32_t *s32, int channels) {
  int i;
  uint32_t *u32 = (uint32_t *)s32;
  for (i = 0; i < 256 * channels; i++)
    u32[i] = (u32[i] << 24) | ((u32[i] << 8) & 0xFF0000) |
             ((u32[i] >> 8) & 0xFF00) | (u32[i] >> 24);
}


x86 assembly (clang, -O0):
<s32_swap>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x8,%ecx
cmp    %ecx,%eax
jge    118c <s32_swap+0x8c>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
shl    $0x18,%edx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
shl    $0x8,%eax
and    $0xff0000,%eax
or     %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sar    $0x8,%eax
and    $0xff00,%eax
or     %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
sar    $0x18,%eax
or     %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    111a <s32_swap+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<s32_swap>:
test   %esi,%esi
jle    11fe <s32_swap+0xfe>
shl    $0x8,%esi
cmp    $0x2,%esi
mov    $0x1,%eax
cmovge %esi,%eax
cmp    $0x8,%eax
jae    1122 <s32_swap+0x22>
xor    %ecx,%ecx
jmp    11e0 <s32_swap+0xe0>
mov    %eax,%ecx
and    $0x7fffff00,%ecx
xor    %edx,%edx
pxor   %xmm0,%xmm0
movdqa 0xec8(%rip),%xmm1
nopl   0x0(%rax,%rax,1)
movdqu (%rdi,%rdx,4),%xmm2
movdqu 0x10(%rdi,%rdx,4),%xmm3
movdqa %xmm2,%xmm4
punpckhbw %xmm0,%xmm4
pshuflw $0x18,%xmm4,%xmm4
pshufhw $0x18,%xmm4,%xmm4
movdqa %xmm2,%xmm5
punpcklbw %xmm0,%xmm5
pshuflw $0x18,%xmm5,%xmm5
pshufhw $0x18,%xmm5,%xmm5
packuswb %xmm4,%xmm5
pand   %xmm1,%xmm5
movdqa %xmm3,%xmm4
punpckhbw %xmm0,%xmm4
pshuflw $0x18,%xmm4,%xmm4
pshufhw $0x18,%xmm4,%xmm4
movdqa %xmm3,%xmm6
punpcklbw %xmm0,%xmm6
pshuflw $0x18,%xmm6,%xmm6
pshufhw $0x18,%xmm6,%xmm6
packuswb %xmm4,%xmm6
pand   %xmm1,%xmm6
psrad  $0x18,%xmm2
por    %xmm5,%xmm2
psrad  $0x18,%xmm3
por    %xmm6,%xmm3
movdqu %xmm2,(%rdi,%rdx,4)
movdqu %xmm3,0x10(%rdi,%rdx,4)
add    $0x8,%rdx
cmp    %rdx,%rcx
jne    1140 <s32_swap+0x40>
cmp    %rax,%rcx
je     11fe <s32_swap+0xfe>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rdi,%rcx,4),%edx
mov    %edx,%esi
and    $0xffffff,%esi
bswap  %esi
sar    $0x18,%edx
or     %esi,%edx
mov    %edx,(%rdi,%rcx,4)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    11e0 <s32_swap+0xe0>
ret

LLVM IR (-O0):
define void @s32_swap(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
store i32* %7, i32** %6
store i32 0, i32* %5
br label %8
8: ; preds = %47, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = mul nsw i32 256, %10
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %50
13: ; preds = %8
%14 = load i32*, i32** %6
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
%19 = shl i32 %18, 24
%20 = load i32*, i32** %6
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = shl i32 %24, 8
%26 = and i32 %25, 16711680
%27 = or i32 %19, %26
%28 = load i32*, i32** %6
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = ashr i32 %32, 8
%34 = and i32 %33, 65280
%35 = or i32 %27, %34
%36 = load i32*, i32** %6
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = ashr i32 %40, 24
%42 = or i32 %35, %41
%43 = load i32*, i32** %6
%44 = load i32, i32* %5
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i32, i32* %43, i64 %45
store i32 %42, i32* %46
br label %47
47: ; preds = %13
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %8
50: ; preds = %8
ret void
}

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