#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 /*<<< orphan*/ uint8_t;

/* Variables and functions */
void swab_rest_bytes(uint8_t *dst, const uint8_t *src, size_t len) {
  switch (len) {
  case 4:
    dst[0] = src[1];
    dst[1] = src[0];
    dst[2] = src[3];
    dst[3] = src[2];
    break;
  case 2:
    dst[0] = src[1];
    dst[1] = src[0];
    break;
  }
}


x86 assembly (clang, -O0):
<swab_rest_bytes>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
sub    $0x2,%rax
je     1175 <swab_rest_bytes+0x75>
jmp    1127 <swab_rest_bytes+0x27>
mov    -0x20(%rbp),%rax
sub    $0x4,%rax
jne    118f <swab_rest_bytes+0x8f>
jmp    113a <swab_rest_bytes+0x3a>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
jmp    118f <swab_rest_bytes+0x8f>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<swab_rest_bytes>:
cmp    $0x2,%rdx
je     1127 <swab_rest_bytes+0x27>
cmp    $0x4,%rdx
jne    1136 <swab_rest_bytes+0x36>
mov    0x4(%rsi),%eax
mov    %eax,(%rdi)
mov    (%rsi),%eax
mov    %eax,0x4(%rdi)
mov    0xc(%rsi),%eax
mov    %eax,0x8(%rdi)
add    $0x8,%rsi
mov    $0x3,%eax
jmp    1131 <swab_rest_bytes+0x31>
mov    0x4(%rsi),%eax
mov    %eax,(%rdi)
mov    $0x1,%eax
mov    (%rsi),%ecx
mov    %ecx,(%rdi,%rax,4)
ret

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

LLVM IR (-O2):
define void @swab_rest_bytes(i32* nocapture writeonly %0, i32* nocapture %1, i64 %2) {
switch i64 %2, label %21 [
i64 4, label %4
i64 2, label %13
]
4: ; preds = %3
%5 = getelementptr inbounds i32, i32* %1, i64 1
%6 = load i32, i32* %5
store i32 %6, i32* %0
%7 = load i32, i32* %1
%8 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %7, i32* %8
%9 = getelementptr inbounds i32, i32* %1, i64 3
%10 = load i32, i32* %9
%11 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %10, i32* %11
%12 = getelementptr inbounds i32, i32* %1, i64 2
br label %16
13: ; preds = %3
%14 = getelementptr inbounds i32, i32* %1, i64 1
%15 = load i32, i32* %14
store i32 %15, i32* %0
br label %16
16: ; preds = %4, %13
%17 = phi i32* [ %1, %13 ], [ %12, %4 ]
%18 = phi i64 [ 1, %13 ], [ 3, %4 ]
%19 = load i32, i32* %17
%20 = getelementptr inbounds i32, i32* %0, i64 %18
store i32 %19, i32* %20
br label %21
21: ; preds = %16, %3
ret void
}