#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 */
unsigned short spdif_swab_u16(unsigned short);
int bs_conv_swab16(const unsigned char *in_buf, int size,
                   unsigned char *out_buf) {
  unsigned short *in16;
  unsigned short *out16;
  int i;
  if (size & 1)
    out_buf[size++] = 0;
  in16 = (unsigned short *)in_buf;
  out16 = (unsigned short *)out_buf;
  i = size >> 1;
  while (i--)
    out16[i] = spdif_swab_u16(in16[i]);
  return size;
}


x86 assembly (clang, -O0):
<bs_conv_swab16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1148 <bs_conv_swab16+0x38>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x2c(%rbp)
cmp    $0x0,%eax
je     119a <bs_conv_swab16+0x8a>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movzwl (%rax,%rcx,2),%edi
call   1030 <spdif_swab_u16@plt>
mov    %ax,%dx
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    1161 <bs_conv_swab16+0x51>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bs_conv_swab16>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbp
test   $0x1,%r14b
je     1132 <bs_conv_swab16+0x22>
movslq %r14d,%rax
add    $0x1,%r14d
movb   $0x0,(%r15,%rax,1)
cmp    $0x2,%r14d
jb     1156 <bs_conv_swab16+0x46>
mov    %r14d,%eax
sar    %eax
movslq %eax,%rbx
movzwl -0x2(%rbp,%rbx,2),%edi
call   1030 <spdif_swab_u16@plt>
mov    %ax,-0x2(%r15,%rbx,2)
add    $0xffffffffffffffff,%rbx
jne    1140 <bs_conv_swab16+0x30>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bs_conv_swab16(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i16*
%8 = alloca i16*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = load i32, i32* %5
%11 = and i32 %10, 1
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = load i32, i32* %5
%16 = add nsw i32 %15, 1
store i32 %16, i32* %5
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
store i8 0, i8* %18
br label %19
19: ; preds = %13, %3
%20 = load i8*, i8** %4
%21 = bitcast i8* %20 to i16*
store i16* %21, i16** %7
%22 = load i8*, i8** %6
%23 = bitcast i8* %22 to i16*
store i16* %23, i16** %8
%24 = load i32, i32* %5
%25 = ashr i32 %24, 1
store i32 %25, i32* %9
br label %26
26: ; preds = %30, %19
%27 = load i32, i32* %9
%28 = add nsw i32 %27, -1
store i32 %28, i32* %9
%29 = icmp ne i32 %27, 0
br i1 %29, label %30, label %41
30: ; preds = %26
%31 = load i16*, i16** %7
%32 = load i32, i32* %9
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i16, i16* %31, i64 %33
%35 = load i16, i16* %34
%36 = call zeroext i16 @spdif_swab_u16(i16 zeroext %35)
%37 = load i16*, i16** %8
%38 = load i32, i32* %9
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i16, i16* %37, i64 %39
store i16 %36, i16* %40
br label %26
41: ; preds = %26
%42 = load i32, i32* %5
ret i32 %42
}

LLVM IR (-O2):
define i32 @bs_conv_swab16(i8* nocapture %0, i32 %1, i8* nocapture writeonly %2) {
%4 = and i32 %1, 1
%5 = icmp eq i32 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = add nsw i32 %1, 1
%8 = sext i32 %1 to i64
%9 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 0, i8* %9
br label %10
10: ; preds = %6, %3
%11 = phi i32 [ %7, %6 ], [ %1, %3 ]
%12 = bitcast i8* %0 to i16*
%13 = bitcast i8* %2 to i16*
%14 = icmp ult i32 %11, 2
br i1 %14, label %26, label %15
15: ; preds = %10
%16 = ashr i32 %11, 1
%17 = sext i32 %16 to i64
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ %17, %15 ], [ %20, %18 ]
%20 = add nsw i64 %19, -1
%21 = getelementptr inbounds i16, i16* %12, i64 %20
%22 = load i16, i16* %21
%23 = tail call zeroext i16 @spdif_swab_u16(i16 zeroext %22)
%24 = getelementptr inbounds i16, i16* %13, i64 %20
store i16 %23, i16* %24
%25 = icmp eq i64 %20, 0
br i1 %25, label %26, label %18
26: ; preds = %18, %10
ret i32 %11
}