#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 */
void swab(const void *bfrom, void *bto, ssize_t n) {
  const char *from = (const char *)bfrom;
  char *to = (char *)bto;
  n &= ~((ssize_t)1);
  while (n > 1) {
    const char b0 = from[--n], b1 = from[--n];
    to[n] = b0;
    to[n + 1] = b1;
  }
}


x86 assembly (clang, -O0):
<swab>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
and    $0xfffffffe,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    1184 <swab+0x84>
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x29(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x2a(%rbp)
mov    -0x29(%rbp),%dl
mov    -0x28(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x2a(%rbp),%dl
mov    -0x28(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1128 <swab+0x28>
pop    %rbp
ret

x86 assembly (clang, -O2):
<swab>:
and    $0xfffffffe,%edx
cmp    $0x2,%edx
jl     113a <swab+0x3a>
lea    0x2(%rdx),%eax
add    $0xfffffffe,%edx
lea    (%rdi,%rdx,1),%rcx
add    $0x1,%rcx
add    %rsi,%rdx
add    $0x1,%rdx
xor    %esi,%esi
nop
movzwl -0x1(%rcx,%rsi,1),%edi
rol    $0x8,%di
mov    %di,-0x1(%rdx,%rsi,1)
add    $0xfffffffffffffffe,%rsi
lea    (%rax,%rsi,1),%edi
cmp    $0x3,%edi
ja     1120 <swab+0x20>
ret

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

LLVM IR (-O2):
define void @swab(i8* nocapture %0, i8* nocapture writeonly %1, i32 %2) {
%4 = and i32 %2, -2
%5 = icmp sgt i32 %4, 1
br i1 %5, label %6, label %19
6: ; preds = %3, %6
%7 = phi i32 [ %12, %6 ], [ %4, %3 ]
%8 = add nsw i32 %7, -1
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = add nsw i32 %7, -2
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %11, i8* %16
%17 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %15, i8* %17
%18 = icmp ugt i32 %7, 3
br i1 %18, label %6, label %19
19: ; preds = %6, %3
ret void
}