unsigned int nibble_swap(unsigned int number) {
  unsigned int new_number = 0;
  new_number |= ((number & 0xF0000000) >> (28 - 0));
  new_number |= ((number & 0x0F000000) >> (24 - 4));
  new_number |= ((number & 0x00F00000) >> (20 - 8));
  new_number |= ((number & 0x000F0000) >> (16 - 12));
  new_number |= ((number & 0x0000F000) << (16 - 12));
  new_number |= ((number & 0x00000F00) << (20 - 8));
  new_number |= ((number & 0x000000F0) << (24 - 4));
  new_number |= ((number & 0x0000000F) << (28 - 0));
  return new_number;
}


x86 assembly (clang, -O0):
<nibble_swap>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf0000000,%eax
shr    $0x1c,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf000000,%eax
shr    $0x14,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf00000,%eax
shr    $0xc,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf0000,%eax
shr    $0x4,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf000,%eax
shl    $0x4,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf00,%eax
shl    $0xc,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf0,%eax
shl    $0x14,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf,%eax
shl    $0x1c,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<nibble_swap>:
mov    %edi,%eax
shr    $0x1c,%eax
mov    %edi,%r8d
shr    $0x14,%r8d
and    $0xf0,%r8d
mov    %edi,%r9d
shr    $0xc,%r9d
and    $0xf00,%r9d
mov    %edi,%r10d
shr    $0x4,%r10d
and    $0xf000,%r10d
mov    %edi,%ecx
shl    $0x4,%ecx
and    $0xf0000,%ecx
mov    %edi,%edx
shl    $0xc,%edx
and    $0xf00000,%edx
mov    %edi,%esi
shl    $0x14,%esi
and    $0xf000000,%esi
shl    $0x1c,%edi
or     %edi,%eax
or     %r8d,%eax
or     %r9d,%eax
or     %r10d,%eax
or     %ecx,%eax
or     %edx,%eax
or     %esi,%eax
ret

LLVM IR (-O0):
define i32 @nibble_swap(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = and i32 %4, -268435456
%6 = lshr i32 %5, 28
%7 = load i32, i32* %3
%8 = or i32 %7, %6
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = and i32 %9, 251658240
%11 = lshr i32 %10, 20
%12 = load i32, i32* %3
%13 = or i32 %12, %11
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = and i32 %14, 15728640
%16 = lshr i32 %15, 12
%17 = load i32, i32* %3
%18 = or i32 %17, %16
store i32 %18, i32* %3
%19 = load i32, i32* %2
%20 = and i32 %19, 983040
%21 = lshr i32 %20, 4
%22 = load i32, i32* %3
%23 = or i32 %22, %21
store i32 %23, i32* %3
%24 = load i32, i32* %2
%25 = and i32 %24, 61440
%26 = shl i32 %25, 4
%27 = load i32, i32* %3
%28 = or i32 %27, %26
store i32 %28, i32* %3
%29 = load i32, i32* %2
%30 = and i32 %29, 3840
%31 = shl i32 %30, 12
%32 = load i32, i32* %3
%33 = or i32 %32, %31
store i32 %33, i32* %3
%34 = load i32, i32* %2
%35 = and i32 %34, 240
%36 = shl i32 %35, 20
%37 = load i32, i32* %3
%38 = or i32 %37, %36
store i32 %38, i32* %3
%39 = load i32, i32* %2
%40 = and i32 %39, 15
%41 = shl i32 %40, 28
%42 = load i32, i32* %3
%43 = or i32 %42, %41
store i32 %43, i32* %3
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
define i32 @nibble_swap(i32 %0) {
%2 = lshr i32 %0, 28
%3 = lshr i32 %0, 20
%4 = and i32 %3, 240
%5 = lshr i32 %0, 12
%6 = and i32 %5, 3840
%7 = lshr i32 %0, 4
%8 = and i32 %7, 61440
%9 = shl i32 %0, 4
%10 = and i32 %9, 983040
%11 = shl i32 %0, 12
%12 = and i32 %11, 15728640
%13 = shl i32 %0, 20
%14 = and i32 %13, 251658240
%15 = shl i32 %0, 28
%16 = or i32 %15, %2
%17 = or i32 %16, %4
%18 = or i32 %17, %6
%19 = or i32 %18, %8
%20 = or i32 %19, %10
%21 = or i32 %20, %12
%22 = or i32 %21, %14
ret i32 %22
}