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

/* Variables and functions */
void swab(const void *restrict _src, void *restrict _dest, ssize_t n) {
  const char *src = _src;
  char *dest = _dest;
  for (; n > 0; n -= 2) {
    dest[0] = src[1];
    dest[1] = src[0];
    dest += 2;
    src += 2;
  }
}


x86 assembly (clang, -O0):
<swab>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    116e <swab+0x6e>
mov    -0x20(%rbp),%rax
mov    0x1(%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x2,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <swab+0x20>
pop    %rbp
ret

x86 assembly (clang, -O2):
<swab>:
test   %rdx,%rdx
jle    112e <swab+0x2e>
add    $0x2,%rdx
xor    %eax,%eax
nopl   0x0(%rax,%rax,1)
movzbl 0x1(%rdi,%rax,1),%ecx
mov    %cl,(%rsi,%rax,1)
movzbl (%rdi,%rax,1),%ecx
mov    %cl,0x1(%rsi,%rax,1)
add    $0x2,%rax
add    $0xfffffffffffffffe,%rdx
cmp    $0x2,%rdx
ja     1110 <swab+0x10>
ret

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

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