unsigned long ieee_swcr_to_fpcr(unsigned long sw) {
  unsigned long fp;
  fp = (sw & ((1UL << 17) | (1UL << 18) | (1UL << 19) | (1UL << 20) |
              (1UL << 21) | (1UL << 22)))
       << 35;
  fp |= (sw & (1UL << 12)) << 36;
  fp |= (sw & ((1UL << 17) | (1UL << 18) | (1UL << 19) | (1UL << 20) |
               (1UL << 21) | (1UL << 22))
             ? (1UL << 63)
             : 0);
  fp |= (~sw & ((1UL << 1) | (1UL << 2) | (1UL << 3))) << 48;
  fp |= (~sw & ((1UL << 4) | (1UL << 5))) << 57;
  fp |= (sw & (1UL << 13) ? (1UL << 60) | (1UL << 61) : 0);
  fp |= (~sw & (1UL << 6)) << 41;
  return fp;
}


x86 assembly (clang, -O0):
<ieee_swcr_to_fpcr>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
and    $0x7e0000,%rax
shl    $0x23,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
and    $0x1000,%rax
shl    $0x24,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
and    $0x7e0000,%rdx
xor    %eax,%eax
movabs $0x8000000000000000,%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
xor    $0xffffffffffffffff,%rax
and    $0xe,%rax
shl    $0x30,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
xor    $0xffffffffffffffff,%rax
and    $0x30,%rax
shl    $0x39,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
and    $0x2000,%rdx
xor    %eax,%eax
movabs $0x3000000000000000,%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
xor    $0xffffffffffffffff,%rax
and    $0x40,%rax
shl    $0x29,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ieee_swcr_to_fpcr>:
mov    %edi,%eax
and    $0x7e0000,%eax
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
shl    $0x23,%rax
mov    %edi,%edx
and    $0x1000,%edx
shl    $0x24,%rdx
or     %rax,%rdx
shl    $0x3f,%rcx
or     %rdx,%rcx
mov    %rdi,%rax
not    %rax
mov    %eax,%edx
and    $0xe,%edx
shl    $0x30,%rdx
or     %rcx,%rdx
mov    %eax,%ecx
and    $0x30,%ecx
shl    $0x39,%rcx
or     %rdx,%rcx
shl    $0x32,%rdi
sar    $0x3f,%rdi
movabs $0x3000000000000000,%rdx
and    %rdi,%rdx
and    $0x40,%eax
shl    $0x29,%rax
or     %rdx,%rax
or     %rcx,%rax
ret

LLVM IR (-O0):
define i64 @ieee_swcr_to_fpcr(i64 %0) {
%2 = alloca i64
%3 = alloca i64
store i64 %0, i64* %2
%4 = load i64, i64* %2
%5 = and i64 %4, 8257536
%6 = shl i64 %5, 35
store i64 %6, i64* %3
%7 = load i64, i64* %2
%8 = and i64 %7, 4096
%9 = shl i64 %8, 36
%10 = load i64, i64* %3
%11 = or i64 %10, %9
store i64 %11, i64* %3
%12 = load i64, i64* %2
%13 = and i64 %12, 8257536
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i64 -9223372036854775808, i64 0
%17 = load i64, i64* %3
%18 = or i64 %17, %16
store i64 %18, i64* %3
%19 = load i64, i64* %2
%20 = xor i64 %19, -1
%21 = and i64 %20, 14
%22 = shl i64 %21, 48
%23 = load i64, i64* %3
%24 = or i64 %23, %22
store i64 %24, i64* %3
%25 = load i64, i64* %2
%26 = xor i64 %25, -1
%27 = and i64 %26, 48
%28 = shl i64 %27, 57
%29 = load i64, i64* %3
%30 = or i64 %29, %28
store i64 %30, i64* %3
%31 = load i64, i64* %2
%32 = and i64 %31, 8192
%33 = icmp ne i64 %32, 0
%34 = zext i1 %33 to i64
%35 = select i1 %33, i64 3458764513820540928, i64 0
%36 = load i64, i64* %3
%37 = or i64 %36, %35
store i64 %37, i64* %3
%38 = load i64, i64* %2
%39 = xor i64 %38, -1
%40 = and i64 %39, 64
%41 = shl i64 %40, 41
%42 = load i64, i64* %3
%43 = or i64 %42, %41
store i64 %43, i64* %3
%44 = load i64, i64* %3
ret i64 %44
}

LLVM IR (-O2):
define i64 @ieee_swcr_to_fpcr(i64 %0) {
%2 = and i64 %0, 8257536
%3 = shl nuw nsw i64 %2, 35
%4 = shl i64 %0, 36
%5 = and i64 %4, 281474976710656
%6 = or i64 %3, %5
%7 = icmp eq i64 %2, 0
%8 = select i1 %7, i64 0, i64 -9223372036854775808
%9 = or i64 %6, %8
%10 = xor i64 %0, -1
%11 = shl i64 %10, 48
%12 = and i64 %11, 3940649673949184
%13 = or i64 %9, %12
%14 = shl i64 %10, 57
%15 = and i64 %14, 6917529027641081856
%16 = or i64 %13, %15
%17 = and i64 %0, 8192
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i64 0, i64 3458764513820540928
%20 = shl i64 %10, 41
%21 = and i64 %20, 140737488355328
%22 = or i64 %19, %21
%23 = or i64 %22, %16
ret i64 %23
}