#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 *restrict _src, void *restrict _dest, ssize_t n) {
  const char *src = _src;
  char *dest = _dest;
  for (; n > 1; 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    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    1169 <swab+0x69>
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    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    111f <swab+0x1f>
pop    %rbp
ret

x86 assembly (clang, -O2):
<swab>:
cmp    $0x2,%edx
jl     112c <swab+0x2c>
add    $0x2,%edx
xor    %eax,%eax
nopw   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    $0xfffffffe,%edx
cmp    $0x3,%edx
ja     1110 <swab+0x10>
ret

LLVM IR (-O0):
define void @swab(i8* noalias %0, i8* noalias %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %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 i32, i32* %6
%13 = icmp sgt i32 %12, 1
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 i32, i32* %6
%31 = sub nsw i32 %30, 2
store i32 %31, i32* %6
br label %11
32: ; preds = %11
ret void
}

LLVM IR (-O2):
define void @swab(i8* noalias nocapture %0, i8* noalias nocapture writeonly %1, i32 %2) {
%4 = icmp sgt i32 %2, 1
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 i32 [ %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 i32 %8, -2
%16 = icmp ugt i32 %8, 3
br i1 %16, label %5, label %17
17: ; preds = %5, %3
ret void
}