int split_radix_permutation(int i, int n, int inverse) {
  int m;
  if (n <= 2)
    return i & 1;
  m = n >> 1;
  if (!(i & m))
    return split_radix_permutation(i, m, inverse) * 2;
  m >>= 1;
  if (inverse == !(i & m))
    return split_radix_permutation(i, m, inverse) * 4 + 1;
  else
    return split_radix_permutation(i, m, inverse) * 4 - 1;
}


x86 assembly (clang, -O0):
<split_radix_permutation>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x2,-0xc(%rbp)
jg     1139 <split_radix_permutation+0x29>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <split_radix_permutation+0xb6>
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
and    -0x14(%rbp),%eax
cmp    $0x0,%eax
jne    116a <split_radix_permutation+0x5a>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <split_radix_permutation@plt>
shl    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <split_radix_permutation+0xb6>
mov    -0x14(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
and    -0x14(%rbp),%ecx
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
jne    11af <split_radix_permutation+0x9f>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <split_radix_permutation@plt>
shl    $0x2,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <split_radix_permutation+0xb6>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <split_radix_permutation@plt>
shl    $0x2,%eax
sub    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<split_radix_permutation>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%eax
cmp    $0x2,%esi
jg     111f <split_radix_permutation+0xf>
and    $0x1,%eax
jmp    115b <split_radix_permutation+0x4b>
mov    %edx,%ebx
mov    %esi,%ecx
shr    %ecx
test   %eax,%ecx
je     1149 <split_radix_permutation+0x39>
shr    $0x2,%esi
xor    %ebp,%ebp
test   %eax,%esi
sete   %bpl
mov    %eax,%edi
mov    %ebx,%edx
call   1030 <split_radix_permutation@plt>
shl    $0x2,%eax
cmp    %ebx,%ebp
jne    1158 <split_radix_permutation+0x48>
or     $0x1,%eax
jmp    115b <split_radix_permutation+0x4b>
mov    %eax,%edi
mov    %ecx,%esi
mov    %ebx,%edx
call   1030 <split_radix_permutation@plt>
add    %eax,%eax
jmp    115b <split_radix_permutation+0x4b>
add    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @split_radix_permutation(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%9 = load i32, i32* %6
%10 = icmp sle i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* %5
%13 = and i32 %12, 1
store i32 %13, i32* %4
br label %52
14: ; preds = %3
%15 = load i32, i32* %6
%16 = ashr i32 %15, 1
store i32 %16, i32* %8
%17 = load i32, i32* %5
%18 = load i32, i32* %8
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %14
%22 = load i32, i32* %5
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = call i32 @split_radix_permutation(i32 %22, i32 %23, i32 %24)
%26 = mul nsw i32 %25, 2
store i32 %26, i32* %4
br label %52
27: ; preds = %14
%28 = load i32, i32* %8
%29 = ashr i32 %28, 1
store i32 %29, i32* %8
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = load i32, i32* %8
%33 = and i32 %31, %32
%34 = icmp ne i32 %33, 0
%35 = xor i1 %34, true
%36 = zext i1 %35 to i32
%37 = icmp eq i32 %30, %36
br i1 %37, label %38, label %45
38: ; preds = %27
%39 = load i32, i32* %5
%40 = load i32, i32* %8
%41 = load i32, i32* %7
%42 = call i32 @split_radix_permutation(i32 %39, i32 %40, i32 %41)
%43 = mul nsw i32 %42, 4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %52
45: ; preds = %27
%46 = load i32, i32* %5
%47 = load i32, i32* %8
%48 = load i32, i32* %7
%49 = call i32 @split_radix_permutation(i32 %46, i32 %47, i32 %48)
%50 = mul nsw i32 %49, 4
%51 = sub nsw i32 %50, 1
store i32 %51, i32* %4
br label %52
52: ; preds = %45, %38, %21, %11
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
define i32 @split_radix_permutation(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, 3
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = and i32 %0, 1
br label %11
7: ; preds = %3
%8 = lshr i32 %1, 1
%9 = and i32 %8, %0
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %16
11: ; preds = %5, %26, %24, %13
%12 = phi i32 [ %15, %13 ], [ %25, %24 ], [ %27, %26 ], [ %6, %5 ]
ret i32 %12
13: ; preds = %7
%14 = tail call i32 @split_radix_permutation(i32 %0, i32 %8, i32 %2)
%15 = shl nsw i32 %14, 1
br label %11
16: ; preds = %7
%17 = lshr i32 %1, 2
%18 = and i32 %17, %0
%19 = icmp eq i32 %18, 0
%20 = zext i1 %19 to i32
%21 = icmp eq i32 %20, %2
%22 = tail call i32 @split_radix_permutation(i32 %0, i32 %17, i32 %2)
%23 = shl nsw i32 %22, 2
br i1 %21, label %24, label %26
24: ; preds = %16
%25 = or i32 %23, 1
br label %11
26: ; preds = %16
%27 = add nsw i32 %23, -1
br label %11
}