#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 LittleShort(short);
void S_ByteSwapRawSamples(int samples, int width, int s_channels, short *data) {
  int i;
  if (width != 2) {
    return;
  }
  if (LittleShort(256) == 256) {
    return;
  }
  if (s_channels == 2) {
    i = samples << 1;
  } else {
    i = samples;
  }
  do {
    *data = LittleShort(*data);
    data++;
  } while (--i);
}


x86 assembly (clang, -O0):
<S_ByteSwapRawSamples>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1134 <S_ByteSwapRawSamples+0x24>
jmp    11a5 <S_ByteSwapRawSamples+0x95>
mov    $0x100,%edi
call   1030 <LittleShort@plt>
cmp    $0x100,%eax
jne    114e <S_ByteSwapRawSamples+0x3e>
jmp    11a5 <S_ByteSwapRawSamples+0x95>
cmpl   $0x2,-0xc(%rbp)
jne    1166 <S_ByteSwapRawSamples+0x56>
mov    -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    116c <S_ByteSwapRawSamples+0x5c>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <S_ByteSwapRawSamples+0x61>
mov    -0x18(%rbp),%rax
movswl (%rax),%edi
call   1030 <LittleShort@plt>
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    1171 <S_ByteSwapRawSamples+0x61>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<S_ByteSwapRawSamples>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%esi
jne    1156 <S_ByteSwapRawSamples+0x46>
mov    %rcx,%rbx
mov    %edx,%ebp
mov    %edi,%r14d
mov    $0x100,%edi
call   1030 <LittleShort@plt>
cmp    $0x100,%eax
je     1156 <S_ByteSwapRawSamples+0x46>
cmp    $0x2,%ebp
sete   %cl
shl    %cl,%r14d
xor    %ebp,%ebp
nopl   (%rax)
movswl (%rbx,%rbp,2),%edi
call   1030 <LittleShort@plt>
mov    %ax,(%rbx,%rbp,2)
add    $0x1,%rbp
cmp    %ebp,%r14d
jne    1140 <S_ByteSwapRawSamples+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @S_ByteSwapRawSamples(i32 %0, i32 %1, i32 %2, i16* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i16*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i16* %3, i16** %8
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %4
br label %38
13: ; preds = %4
%14 = call i32 @LittleShort(i16 signext 256)
%15 = icmp eq i32 %14, 256
br i1 %15, label %16, label %17
16: ; preds = %13
br label %38
17: ; preds = %13
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 2
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %5
%22 = shl i32 %21, 1
store i32 %22, i32* %9
br label %25
23: ; preds = %17
%24 = load i32, i32* %5
store i32 %24, i32* %9
br label %25
25: ; preds = %23, %20
br label %26
26: ; preds = %34, %25
%27 = load i16*, i16** %8
%28 = load i16, i16* %27
%29 = call i32 @LittleShort(i16 signext %28)
%30 = trunc i32 %29 to i16
%31 = load i16*, i16** %8
store i16 %30, i16* %31
%32 = load i16*, i16** %8
%33 = getelementptr inbounds i16, i16* %32, i32 1
store i16* %33, i16** %8
br label %34
34: ; preds = %26
%35 = load i32, i32* %9
%36 = add nsw i32 %35, -1
store i32 %36, i32* %9
%37 = icmp ne i32 %36, 0
br i1 %37, label %26, label %38
38: ; preds = %12, %16, %34
ret void
}

LLVM IR (-O2):
define void @S_ByteSwapRawSamples(i32 %0, i32 %1, i32 %2, i16* nocapture %3) {
%5 = icmp eq i32 %1, 2
br i1 %5, label %6, label %22
6: ; preds = %4
%7 = tail call i32 @LittleShort(i16 signext 256)
%8 = icmp eq i32 %7, 256
br i1 %8, label %22, label %9
9: ; preds = %6
%10 = icmp eq i32 %2, 2
%11 = zext i1 %10 to i32
%12 = shl i32 %0, %11
br label %13
13: ; preds = %13, %9
%14 = phi i16* [ %3, %9 ], [ %19, %13 ]
%15 = phi i32 [ %12, %9 ], [ %20, %13 ]
%16 = load i16, i16* %14
%17 = tail call i32 @LittleShort(i16 signext %16)
%18 = trunc i32 %17 to i16
store i16 %18, i16* %14
%19 = getelementptr inbounds i16, i16* %14, i64 1
%20 = add nsw i32 %15, -1
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %13
22: ; preds = %13, %6, %4
ret void
}