void swap_long(a) long *a;
{
  union {
    long val;
    unsigned short wrds[2];
  } swapper;
  unsigned short tmp;
  swapper.val = *a;
  tmp = swapper.wrds[0];
  swapper.wrds[0] = swapper.wrds[1];
  swapper.wrds[1] = tmp;
  swap_short(&swapper.wrds[0]);
  swap_short(&swapper.wrds[1]);
  *a = swapper.val;
}


x86 assembly (clang, -O0):
<swap_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%ax
mov    %ax,-0x12(%rbp)
mov    -0xe(%rbp),%ax
mov    %ax,-0x10(%rbp)
mov    -0x12(%rbp),%ax
mov    %ax,-0xe(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <swap_short@plt>
lea    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    $0x0,%al
call   1030 <swap_short@plt>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<swap_long>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    (%rdi),%rax
mov    %rax,(%rsp)
lea    0x2(%rsp),%r14
mov    %rax,%rcx
shr    $0x10,%rcx
mov    %cx,(%rsp)
mov    %ax,0x2(%rsp)
mov    %rsp,%rdi
xor    %eax,%eax
call   1030 <swap_short@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <swap_short@plt>
mov    (%rsp),%rax
mov    %rax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%union.anon = type { i64 }
define void @swap_long(i64* %0) {
%2 = alloca i64*
%3 = alloca %union.anon
%4 = alloca i16
store i64* %0, i64** %2
%5 = load i64*, i64** %2
%6 = load i64, i64* %5
%7 = bitcast %union.anon* %3 to i64*
store i64 %6, i64* %7
%8 = bitcast %union.anon* %3 to [2 x i16]*
%9 = getelementptr inbounds [2 x i16], [2 x i16]* %8, i64 0, i64 0
%10 = load i16, i16* %9
store i16 %10, i16* %4
%11 = bitcast %union.anon* %3 to [2 x i16]*
%12 = getelementptr inbounds [2 x i16], [2 x i16]* %11, i64 0, i64 1
%13 = load i16, i16* %12
%14 = bitcast %union.anon* %3 to [2 x i16]*
%15 = getelementptr inbounds [2 x i16], [2 x i16]* %14, i64 0, i64 0
store i16 %13, i16* %15
%16 = load i16, i16* %4
%17 = bitcast %union.anon* %3 to [2 x i16]*
%18 = getelementptr inbounds [2 x i16], [2 x i16]* %17, i64 0, i64 1
store i16 %16, i16* %18
%19 = bitcast %union.anon* %3 to [2 x i16]*
%20 = getelementptr inbounds [2 x i16], [2 x i16]* %19, i64 0, i64 0
%21 = call i32 (i16*, ...) bitcast (i32 (...)* @swap_short to i32 (i16*, ...)*)(i16* %20)
%22 = bitcast %union.anon* %3 to [2 x i16]*
%23 = getelementptr inbounds [2 x i16], [2 x i16]* %22, i64 0, i64 1
%24 = call i32 (i16*, ...) bitcast (i32 (...)* @swap_short to i32 (i16*, ...)*)(i16* %23)
%25 = bitcast %union.anon* %3 to i64*
%26 = load i64, i64* %25
%27 = load i64*, i64** %2
store i64 %26, i64* %27
ret void
}

LLVM IR (-O2):
%union.anon = type { i64 }
define void @swap_long(i64* nocapture %0) {
%2 = alloca %union.anon
%3 = bitcast %union.anon* %2 to i8*
%4 = load i64, i64* %0
%5 = getelementptr inbounds %union.anon, %union.anon* %2, i64 0, i32 0
store i64 %4, i64* %5
%6 = bitcast %union.anon* %2 to [2 x i16]*
%7 = bitcast %union.anon* %2 to i16*
%8 = trunc i64 %4 to i16
%9 = getelementptr inbounds [2 x i16], [2 x i16]* %6, i64 0, i64 1
%10 = lshr i64 %4, 16
%11 = trunc i64 %10 to i16
store i16 %11, i16* %7
store i16 %8, i16* %9
%12 = call i32 (i16*, ...) bitcast (i32 (...)* @swap_short to i32 (i16*, ...)*)(i16* %7)
%13 = call i32 (i16*, ...) bitcast (i32 (...)* @swap_short to i32 (i16*, ...)*)(i16* %9)
%14 = load i64, i64* %5
store i64 %14, i64* %0
ret void
}