#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 char *from, char *to, ssize_t n) {
  if (n & 1) {
    *(to++) = *(from++);
    n--;
  }
  while ((n -= 2) >= 0) {
    register char c = *(from++);
    *(to++) = *(from++);
    *(to++) = c;
  }
}


x86 assembly (clang, -O0):
<__swab>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1149 <__swab+0x49>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    114e <__swab+0x4e>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     11af <__swab+0xaf>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x15(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
jmp    114e <__swab+0x4e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<__swab>:
test   $0x1,%dl
je     1114 <__swab+0x14>
mov    (%rdi),%al
add    $0x1,%rdi
mov    %al,(%rsi)
add    $0x1,%rsi
add    $0xffffffff,%edx
cmp    $0x2,%edx
jl     1138 <__swab+0x38>
add    $0x2,%edx
xor    %eax,%eax
xchg   %ax,%ax
movzwl (%rdi,%rax,1),%ecx
rol    $0x8,%cx
mov    %cx,(%rsi,%rax,1)
add    $0x2,%rax
add    $0xfffffffe,%edx
cmp    $0x3,%edx
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
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = and i32 %8, 1
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = getelementptr inbounds i8, i8* %12, i32 1
store i8* %13, i8** %4
%14 = load i8, i8* %12
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
store i8 %14, i8* %15
%17 = load i32, i32* %6
%18 = add nsw i32 %17, -1
store i32 %18, i32* %6
br label %19
19: ; preds = %11, %3
br label %20
20: ; preds = %24, %19
%21 = load i32, i32* %6
%22 = sub nsw i32 %21, 2
store i32 %22, i32* %6
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %36
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %4
%27 = load i8, i8* %25
store i8 %27, i8* %7
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
%30 = load i8, i8* %28
%31 = load i8*, i8** %5
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %5
store i8 %30, i8* %31
%33 = load i8, i8* %7
%34 = load i8*, i8** %5
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %5
store i8 %33, i8* %34
br label %20
36: ; preds = %20
ret void
}

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