void skl_wrpll_get_multipliers(unsigned int p, unsigned int *p0,
                               unsigned int *p1, unsigned int *p2) {
  if (p % 2 == 0) {
    unsigned int half = p / 2;
    if (half == 1 || half == 2 || half == 3 || half == 5) {
      *p0 = 2;
      *p1 = 1;
      *p2 = half;
    } else if (half % 2 == 0) {
      *p0 = 2;
      *p1 = half / 2;
      *p2 = 2;
    } else if (half % 3 == 0) {
      *p0 = 3;
      *p1 = half / 3;
      *p2 = 2;
    } else if (half % 7 == 0) {
      *p0 = 7;
      *p1 = half / 7;
      *p2 = 2;
    }
  } else if (p == 3 || p == 9) {
    *p0 = 3;
    *p1 = 1;
    *p2 = p / 3;
  } else if (p == 5 || p == 7) {
    *p0 = p;
    *p1 = 1;
    *p2 = 1;
  } else if (p == 15) {
    *p0 = 3;
    *p1 = 1;
    *p2 = 5;
  } else if (p == 21) {
    *p0 = 7;
    *p1 = 1;
    *p2 = 3;
  } else if (p == 35) {
    *p0 = 7;
    *p1 = 1;
    *p2 = 5;
  }
}


x86 assembly (clang, -O0):
<skl_wrpll_get_multipliers>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    123c <skl_wrpll_get_multipliers+0x13c>
mov    -0x4(%rbp),%eax
shr    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
je     1153 <skl_wrpll_get_multipliers+0x53>
cmpl   $0x2,-0x24(%rbp)
je     1153 <skl_wrpll_get_multipliers+0x53>
cmpl   $0x3,-0x24(%rbp)
je     1153 <skl_wrpll_get_multipliers+0x53>
cmpl   $0x5,-0x24(%rbp)
jne    1175 <skl_wrpll_get_multipliers+0x75>
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1237 <skl_wrpll_get_multipliers+0x137>
mov    -0x24(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11a9 <skl_wrpll_get_multipliers+0xa9>
mov    -0x10(%rbp),%rax
movl   $0x2,(%rax)
mov    -0x24(%rbp),%ecx
shr    $0x1,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
jmp    1232 <skl_wrpll_get_multipliers+0x132>
mov    -0x24(%rbp),%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    11eb <skl_wrpll_get_multipliers+0xeb>
mov    -0x10(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x24(%rbp),%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
jmp    122d <skl_wrpll_get_multipliers+0x12d>
mov    -0x24(%rbp),%eax
mov    $0x7,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x0,%edx
jne    1228 <skl_wrpll_get_multipliers+0x128>
mov    -0x10(%rbp),%rax
movl   $0x7,(%rax)
mov    -0x24(%rbp),%eax
mov    $0x7,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x2,(%rax)
jmp    122d <skl_wrpll_get_multipliers+0x12d>
jmp    1232 <skl_wrpll_get_multipliers+0x132>
jmp    1237 <skl_wrpll_get_multipliers+0x137>
jmp    134e <skl_wrpll_get_multipliers+0x24e>
cmpl   $0x3,-0x4(%rbp)
je     1250 <skl_wrpll_get_multipliers+0x150>
cmpl   $0x9,-0x4(%rbp)
jne    127d <skl_wrpll_get_multipliers+0x17d>
mov    -0x10(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x3,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1349 <skl_wrpll_get_multipliers+0x249>
cmpl   $0x5,-0x4(%rbp)
je     1291 <skl_wrpll_get_multipliers+0x191>
cmpl   $0x7,-0x4(%rbp)
jne    12b3 <skl_wrpll_get_multipliers+0x1b3>
mov    -0x4(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
jmp    1344 <skl_wrpll_get_multipliers+0x244>
cmpl   $0xf,-0x4(%rbp)
jne    12e0 <skl_wrpll_get_multipliers+0x1e0>
mov    -0x10(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x5,(%rax)
jmp    133f <skl_wrpll_get_multipliers+0x23f>
cmpl   $0x15,-0x4(%rbp)
jne    130d <skl_wrpll_get_multipliers+0x20d>
mov    -0x10(%rbp),%rax
movl   $0x7,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x3,(%rax)
jmp    133a <skl_wrpll_get_multipliers+0x23a>
cmpl   $0x23,-0x4(%rbp)
jne    1335 <skl_wrpll_get_multipliers+0x235>
mov    -0x10(%rbp),%rax
movl   $0x7,(%rax)
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x5,(%rax)
jmp    133a <skl_wrpll_get_multipliers+0x23a>
jmp    133f <skl_wrpll_get_multipliers+0x23f>
jmp    1344 <skl_wrpll_get_multipliers+0x244>
jmp    1349 <skl_wrpll_get_multipliers+0x249>
jmp    134e <skl_wrpll_get_multipliers+0x24e>
pop    %rbp
ret

x86 assembly (clang, -O2):
<skl_wrpll_get_multipliers>:
test   $0x1,%dil
jne    112b <skl_wrpll_get_multipliers+0x2b>
mov    %edi,%r8d
shr    %r8d
cmp    $0x5,%r8d
ja     116e <skl_wrpll_get_multipliers+0x6e>
mov    $0x2e,%eax
bt     %r8d,%eax
jae    116e <skl_wrpll_get_multipliers+0x6e>
movl   $0x2,(%rsi)
movl   $0x1,(%rdx)
jmp    1150 <skl_wrpll_get_multipliers+0x50>
cmp    $0x9,%edi
je     1135 <skl_wrpll_get_multipliers+0x35>
cmp    $0x3,%edi
jne    1154 <skl_wrpll_get_multipliers+0x54>
movl   $0x3,(%rsi)
movl   $0x1,(%rdx)
movzbl %dil,%eax
imul   $0xab,%eax,%r8d
shr    $0x9,%r8d
mov    %r8d,(%rcx)
ret
mov    %edi,%eax
and    $0xfffffffd,%eax
cmp    $0x5,%eax
jne    1187 <skl_wrpll_get_multipliers+0x87>
mov    %edi,(%rsi)
movl   $0x1,(%rdx)
mov    $0x1,%r8d
jmp    1150 <skl_wrpll_get_multipliers+0x50>
test   $0x2,%dil
jne    119e <skl_wrpll_get_multipliers+0x9e>
movl   $0x2,(%rsi)
shr    $0x2,%edi
mov    %edi,(%rdx)
mov    $0x2,%r8d
jmp    1150 <skl_wrpll_get_multipliers+0x50>
cmp    $0x23,%edi
je     11da <skl_wrpll_get_multipliers+0xda>
cmp    $0x15,%edi
je     11f1 <skl_wrpll_get_multipliers+0xf1>
cmp    $0xf,%edi
jne    1153 <skl_wrpll_get_multipliers+0x53>
movl   $0x3,(%rsi)
jmp    11e0 <skl_wrpll_get_multipliers+0xe0>
imul   $0xaaaaaaab,%r8d,%eax
cmp    $0x55555555,%eax
jbe    1208 <skl_wrpll_get_multipliers+0x108>
imul   $0xb6db6db7,%r8d,%eax
cmp    $0x24924924,%eax
ja     1153 <skl_wrpll_get_multipliers+0x53>
movl   $0x7,(%rsi)
mov    $0x92492493,%eax
imul   %r8,%rax
shr    $0x22,%rax
mov    %eax,(%rdx)
mov    $0x2,%r8d
jmp    1150 <skl_wrpll_get_multipliers+0x50>
movl   $0x7,(%rsi)
movl   $0x1,(%rdx)
mov    $0x5,%r8d
jmp    1150 <skl_wrpll_get_multipliers+0x50>
movl   $0x7,(%rsi)
movl   $0x1,(%rdx)
mov    $0x3,%r8d
jmp    1150 <skl_wrpll_get_multipliers+0x50>
movl   $0x3,(%rsi)
mov    %edi,%eax
mov    $0xaaaaaaab,%esi
imul   %rax,%rsi
shr    $0x22,%rsi
mov    %esi,(%rdx)
mov    $0x2,%r8d
jmp    1150 <skl_wrpll_get_multipliers+0x50>

LLVM IR (-O0):
define void @skl_wrpll_get_multipliers(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%10 = load i32, i32* %5
%11 = urem i32 %10, 2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %66
13: ; preds = %4
%14 = load i32, i32* %5
%15 = udiv i32 %14, 2
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, 1
br i1 %17, label %27, label %18
18: ; preds = %13
%19 = load i32, i32* %9
%20 = icmp eq i32 %19, 2
br i1 %20, label %27, label %21
21: ; preds = %18
%22 = load i32, i32* %9
%23 = icmp eq i32 %22, 3
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load i32, i32* %9
%26 = icmp eq i32 %25, 5
br i1 %26, label %27, label %32
27: ; preds = %24, %21, %18, %13
%28 = load i32*, i32** %6
store i32 2, i32* %28
%29 = load i32*, i32** %7
store i32 1, i32* %29
%30 = load i32, i32* %9
%31 = load i32*, i32** %8
store i32 %30, i32* %31
br label %65
32: ; preds = %24
%33 = load i32, i32* %9
%34 = urem i32 %33, 2
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %32
%37 = load i32*, i32** %6
store i32 2, i32* %37
%38 = load i32, i32* %9
%39 = udiv i32 %38, 2
%40 = load i32*, i32** %7
store i32 %39, i32* %40
%41 = load i32*, i32** %8
store i32 2, i32* %41
br label %64
42: ; preds = %32
%43 = load i32, i32* %9
%44 = urem i32 %43, 3
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %52
46: ; preds = %42
%47 = load i32*, i32** %6
store i32 3, i32* %47
%48 = load i32, i32* %9
%49 = udiv i32 %48, 3
%50 = load i32*, i32** %7
store i32 %49, i32* %50
%51 = load i32*, i32** %8
store i32 2, i32* %51
br label %63
52: ; preds = %42
%53 = load i32, i32* %9
%54 = urem i32 %53, 7
%55 = icmp eq i32 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %52
%57 = load i32*, i32** %6
store i32 7, i32* %57
%58 = load i32, i32* %9
%59 = udiv i32 %58, 7
%60 = load i32*, i32** %7
store i32 %59, i32* %60
%61 = load i32*, i32** %8
store i32 2, i32* %61
br label %62
62: ; preds = %56, %52
br label %63
63: ; preds = %62, %46
br label %64
64: ; preds = %63, %36
br label %65
65: ; preds = %64, %27
br label %115
66: ; preds = %4
%67 = load i32, i32* %5
%68 = icmp eq i32 %67, 3
br i1 %68, label %72, label %69
69: ; preds = %66
%70 = load i32, i32* %5
%71 = icmp eq i32 %70, 9
br i1 %71, label %72, label %78
72: ; preds = %69, %66
%73 = load i32*, i32** %6
store i32 3, i32* %73
%74 = load i32*, i32** %7
store i32 1, i32* %74
%75 = load i32, i32* %5
%76 = udiv i32 %75, 3
%77 = load i32*, i32** %8
store i32 %76, i32* %77
br label %114
78: ; preds = %69
%79 = load i32, i32* %5
%80 = icmp eq i32 %79, 5
br i1 %80, label %84, label %81
81: ; preds = %78
%82 = load i32, i32* %5
%83 = icmp eq i32 %82, 7
br i1 %83, label %84, label %89
84: ; preds = %81, %78
%85 = load i32, i32* %5
%86 = load i32*, i32** %6
store i32 %85, i32* %86
%87 = load i32*, i32** %7
store i32 1, i32* %87
%88 = load i32*, i32** %8
store i32 1, i32* %88
br label %113
89: ; preds = %81
%90 = load i32, i32* %5
%91 = icmp eq i32 %90, 15
br i1 %91, label %92, label %96
92: ; preds = %89
%93 = load i32*, i32** %6
store i32 3, i32* %93
%94 = load i32*, i32** %7
store i32 1, i32* %94
%95 = load i32*, i32** %8
store i32 5, i32* %95
br label %112
96: ; preds = %89
%97 = load i32, i32* %5
%98 = icmp eq i32 %97, 21
br i1 %98, label %99, label %103
99: ; preds = %96
%100 = load i32*, i32** %6
store i32 7, i32* %100
%101 = load i32*, i32** %7
store i32 1, i32* %101
%102 = load i32*, i32** %8
store i32 3, i32* %102
br label %111
103: ; preds = %96
%104 = load i32, i32* %5
%105 = icmp eq i32 %104, 35
br i1 %105, label %106, label %110
106: ; preds = %103
%107 = load i32*, i32** %6
store i32 7, i32* %107
%108 = load i32*, i32** %7
store i32 1, i32* %108
%109 = load i32*, i32** %8
store i32 5, i32* %109
br label %110
110: ; preds = %106, %103
br label %111
111: ; preds = %110, %99
br label %112
112: ; preds = %111, %92
br label %113
113: ; preds = %112, %84
br label %114
114: ; preds = %113, %72
br label %115
115: ; preds = %114, %65
ret void
}

LLVM IR (-O2):
define void @skl_wrpll_get_multipliers(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
%5 = and i32 %0, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %25
7: ; preds = %4
%8 = lshr i32 %0, 1
switch i32 %8, label %10 [
i32 5, label %9
i32 3, label %9
i32 2, label %9
i32 1, label %9
]
9: ; preds = %7, %7, %7, %7
store i32 2, i32* %1
store i32 1, i32* %2
br label %38
10: ; preds = %7
%11 = and i32 %0, 2
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
store i32 2, i32* %1
%14 = lshr i32 %0, 2
store i32 %14, i32* %2
br label %38
15: ; preds = %10
%16 = urem i32 %8, 3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
store i32 3, i32* %1
%19 = udiv i32 %0, 6
store i32 %19, i32* %2
br label %38
20: ; preds = %15
%21 = urem i32 %8, 7
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %40
23: ; preds = %20
store i32 7, i32* %1
%24 = udiv i32 %0, 14
store i32 %24, i32* %2
br label %38
25: ; preds = %4
switch i32 %0, label %30 [
i32 9, label %26
i32 3, label %26
]
26: ; preds = %25, %25
store i32 3, i32* %1
store i32 1, i32* %2
%27 = trunc i32 %0 to i8
%28 = udiv i8 %27, 3
%29 = zext i8 %28 to i32
br label %38
30: ; preds = %25
%31 = and i32 %0, -3
%32 = icmp eq i32 %31, 5
br i1 %32, label %33, label %34
33: ; preds = %30
store i32 %0, i32* %1
store i32 1, i32* %2
br label %38
34: ; preds = %30
switch i32 %0, label %40 [
i32 15, label %35
i32 21, label %36
i32 35, label %37
]
35: ; preds = %34
store i32 3, i32* %1
store i32 1, i32* %2
br label %38
36: ; preds = %34
store i32 7, i32* %1
store i32 1, i32* %2
br label %38
37: ; preds = %34
store i32 7, i32* %1
store i32 1, i32* %2
br label %38
38: ; preds = %33, %36, %37, %35, %26, %13, %23, %18, %9
%39 = phi i32 [ %8, %9 ], [ 2, %18 ], [ 2, %23 ], [ 2, %13 ], [ %29, %26 ], [ 5, %35 ], [ 5, %37 ], [ 3, %36 ], [ 1, %33 ]
store i32 %39, i32* %3
br label %40
40: ; preds = %38, %34, %20
ret void
}