#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ bswap_16(unsigned short);
void swab(const void *source, void *dest, ssize_t count) {
  const unsigned short *from = source, *from_end = from + (count >> 1);
  unsigned short junk;
  unsigned short *to = dest;
  while (from < from_end) {
    junk = *from++;
    *to++ = bswap_16(junk);
  }
}


x86 assembly (clang, -O0):
<swab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
sar    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x1,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1192 <swab+0x82>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x2,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%ax
mov    %ax,-0x2a(%rbp)
movzwl -0x2a(%rbp),%edi
call   1030 <bswap_16@plt>
mov    %ax,%cx
mov    -0x38(%rbp),%rax
mov    %rax,%rdx
add    $0x2,%rdx
mov    %rdx,-0x38(%rbp)
mov    %cx,(%rax)
jmp    114b <swab+0x3b>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swab>:
push   %r15
push   %r14
push   %rbx
sar    %edx
movslq %edx,%rax
lea    (%rdi,%rax,2),%r15
cmp    %rdi,%r15
jbe    1149 <swab+0x39>
mov    %rsi,%r14
mov    %rdi,%rbx
nopl   0x0(%rax)
movzwl (%rbx),%edi
add    $0x2,%rbx
call   1030 <bswap_16@plt>
mov    %ax,(%r14)
add    $0x2,%r14
cmp    %r15,%rbx
jb     1130 <swab+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @swab(i8* %0, i8* nocapture writeonly %1, i32 %2) {
%4 = bitcast i8* %0 to i16*
%5 = ashr i32 %2, 1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i16, i16* %4, i64 %6
%8 = icmp ugt i16* %7, %4
br i1 %8, label %9, label %20
9: ; preds = %3
%10 = bitcast i8* %1 to i16*
br label %11
11: ; preds = %9, %11
%12 = phi i16* [ %18, %11 ], [ %10, %9 ]
%13 = phi i16* [ %14, %11 ], [ %4, %9 ]
%14 = getelementptr inbounds i16, i16* %13, i64 1
%15 = load i16, i16* %13
%16 = tail call i32 @bswap_16(i16 zeroext %15)
%17 = trunc i32 %16 to i16
%18 = getelementptr inbounds i16, i16* %12, i64 1
store i16 %17, i16* %12
%19 = icmp ult i16* %14, %7
br i1 %19, label %11, label %20
20: ; preds = %11, %3
ret void
}