int i2s_sf_sclkdiv(int div, int *out) {
  int d;
  switch (div) {
  case 1:
    *out |= (8 << 20);
    return 0;
  case 3:
    *out |= (9 << 20);
    return 0;
  default:
    if (div % 2) {
      return -1;
    }
    d = div / 2 - 1;
    if (d == 8 || d == 9) {
      return -1;
    }
    *out |= (((div / 2 - 1) << 20) & (0xF << 20));
    return 0;
  }
}


x86 assembly (clang, -O0):
<i2s_sf_sclkdiv>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0x1,%eax
je     1130 <i2s_sf_sclkdiv+0x30>
jmp    111f <i2s_sf_sclkdiv+0x1f>
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
je     114a <i2s_sf_sclkdiv+0x4a>
jmp    1164 <i2s_sf_sclkdiv+0x64>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
or     $0x800000,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11dd <i2s_sf_sclkdiv+0xdd>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
or     $0x900000,%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
jmp    11dd <i2s_sf_sclkdiv+0xdd>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1184 <i2s_sf_sclkdiv+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <i2s_sf_sclkdiv+0xdd>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x8,-0x14(%rbp)
je     11a9 <i2s_sf_sclkdiv+0xa9>
cmpl   $0x9,-0x14(%rbp)
jne    11b5 <i2s_sf_sclkdiv+0xb5>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <i2s_sf_sclkdiv+0xdd>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
sub    $0x1,%ecx
shl    $0x14,%ecx
and    $0xf00000,%ecx
mov    -0x10(%rbp),%rax
or     (%rax),%ecx
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2s_sf_sclkdiv>:
cmp    $0x1,%edi
je     1111 <i2s_sf_sclkdiv+0x11>
cmp    $0x3,%edi
jne    1118 <i2s_sf_sclkdiv+0x18>
mov    $0x900000,%ecx
jmp    113f <i2s_sf_sclkdiv+0x3f>
mov    $0x800000,%ecx
jmp    113f <i2s_sf_sclkdiv+0x3f>
mov    $0xffffffff,%eax
test   $0x1,%dil
jne    1143 <i2s_sf_sclkdiv+0x43>
mov    %edi,%ecx
shr    $0x1f,%ecx
add    %edi,%ecx
sar    %ecx
add    $0xffffffff,%ecx
mov    %ecx,%edx
and    $0xfffffffe,%edx
cmp    $0x8,%edx
je     1143 <i2s_sf_sclkdiv+0x43>
and    $0xf,%ecx
shl    $0x14,%ecx
or     %ecx,(%rsi)
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @i2s_sf_sclkdiv(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%7 = load i32, i32* %4
switch i32 %7, label %16 [
i32 1, label %8
i32 3, label %12
]
8: ; preds = %2
%9 = load i32*, i32** %5
%10 = load i32, i32* %9
%11 = or i32 %10, 8388608
store i32 %11, i32* %9
store i32 0, i32* %3
br label %40
12: ; preds = %2
%13 = load i32*, i32** %5
%14 = load i32, i32* %13
%15 = or i32 %14, 9437184
store i32 %15, i32* %13
store i32 0, i32* %3
br label %40
16: ; preds = %2
%17 = load i32, i32* %4
%18 = srem i32 %17, 2
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 -1, i32* %3
br label %40
21: ; preds = %16
%22 = load i32, i32* %4
%23 = sdiv i32 %22, 2
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 8
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 9
br i1 %29, label %30, label %31
30: ; preds = %27, %21
store i32 -1, i32* %3
br label %40
31: ; preds = %27
%32 = load i32, i32* %4
%33 = sdiv i32 %32, 2
%34 = sub nsw i32 %33, 1
%35 = shl i32 %34, 20
%36 = and i32 %35, 15728640
%37 = load i32*, i32** %5
%38 = load i32, i32* %37
%39 = or i32 %38, %36
store i32 %39, i32* %37
store i32 0, i32* %3
br label %40
40: ; preds = %31, %30, %20, %12, %8
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
define i32 @i2s_sf_sclkdiv(i32 %0, i32* nocapture %1) {
switch i32 %0, label %4 [
i32 1, label %15
i32 3, label %3
]
3: ; preds = %2
br label %15
4: ; preds = %2
%5 = and i32 %0, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = sdiv i32 %0, 2
%9 = add nsw i32 %8, -1
%10 = and i32 %9, -2
%11 = icmp eq i32 %10, 8
br i1 %11, label %19, label %12
12: ; preds = %7
%13 = shl i32 %9, 20
%14 = and i32 %13, 15728640
br label %15
15: ; preds = %2, %3, %12
%16 = phi i32 [ %14, %12 ], [ 9437184, %3 ], [ 8388608, %2 ]
%17 = load i32, i32* %1
%18 = or i32 %17, %16
store i32 %18, i32* %1
br label %19
19: ; preds = %15, %7, %4
%20 = phi i32 [ -1, %4 ], [ -1, %7 ], [ 0, %15 ]
ret i32 %20
}