void milliHertzToFnum(unsigned int milliHertz, unsigned int *fnum,
                      unsigned int *block, unsigned int conversionFactor) {
  if (milliHertz <= 0) {
    *block = 0;
    *fnum = 0;
    return;
  }
  if (milliHertz > 6208431) {
    *block = 7;
    *fnum = 1023;
    return;
  }
  if (milliHertz > 3104215)
    *block = 7;
  else if (milliHertz > 1552107)
    *block = 6;
  else if (milliHertz > 776053)
    *block = 5;
  else if (milliHertz > 388026)
    *block = 4;
  else if (milliHertz > 194013)
    *block = 3;
  else if (milliHertz > 97006)
    *block = 2;
  else if (milliHertz > 48503)
    *block = 1;
  else
    *block = 0;
  *fnum = ((unsigned long long)milliHertz << (20 - *block)) /
              (conversionFactor * 1000.0) +
          0.5;
  if (*fnum > 1023) {
    (*block)++;
    *fnum = ((unsigned long long)milliHertz << (20 - *block)) /
                (conversionFactor * 1000.0) +
            0.5;
  }
  return;
}


x86 assembly (clang, -O0):
<milliHertzToFnum>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpl   $0x0,-0x4(%rbp)
ja     1135 <milliHertzToFnum+0x35>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    1337 <milliHertzToFnum+0x237>
cmpl   $0x5ebbaf,-0x4(%rbp)
jbe    115b <milliHertzToFnum+0x5b>
mov    -0x18(%rbp),%rax
movl   $0x7,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3ff,(%rax)
jmp    1337 <milliHertzToFnum+0x237>
cmpl   $0x2f5dd7,-0x4(%rbp)
jbe    1177 <milliHertzToFnum+0x77>
mov    -0x18(%rbp),%rax
movl   $0x7,(%rax)
jmp    1247 <milliHertzToFnum+0x147>
cmpl   $0x17aeeb,-0x4(%rbp)
jbe    1193 <milliHertzToFnum+0x93>
mov    -0x18(%rbp),%rax
movl   $0x6,(%rax)
jmp    1242 <milliHertzToFnum+0x142>
cmpl   $0xbd775,-0x4(%rbp)
jbe    11af <milliHertzToFnum+0xaf>
mov    -0x18(%rbp),%rax
movl   $0x5,(%rax)
jmp    123d <milliHertzToFnum+0x13d>
cmpl   $0x5ebba,-0x4(%rbp)
jbe    11cb <milliHertzToFnum+0xcb>
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
jmp    1238 <milliHertzToFnum+0x138>
cmpl   $0x2f5dd,-0x4(%rbp)
jbe    11e7 <milliHertzToFnum+0xe7>
mov    -0x18(%rbp),%rax
movl   $0x3,(%rax)
jmp    1233 <milliHertzToFnum+0x133>
cmpl   $0x17aee,-0x4(%rbp)
jbe    1203 <milliHertzToFnum+0x103>
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
jmp    122e <milliHertzToFnum+0x12e>
cmpl   $0xbd77,-0x4(%rbp)
jbe    121f <milliHertzToFnum+0x11f>
mov    -0x18(%rbp),%rax
movl   $0x1,(%rax)
jmp    1229 <milliHertzToFnum+0x129>
mov    -0x18(%rbp),%rax
movl   $0x0,(%rax)
jmp    122e <milliHertzToFnum+0x12e>
jmp    1233 <milliHertzToFnum+0x133>
jmp    1238 <milliHertzToFnum+0x138>
jmp    123d <milliHertzToFnum+0x13d>
jmp    1242 <milliHertzToFnum+0x142>
jmp    1247 <milliHertzToFnum+0x147>
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%dl
mov    $0x14,%cl
sub    %dl,%cl
shl    %cl,%rax
movq   %rax,%xmm0
movaps 0xd9d(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xda1(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x1c(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xd92(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  0xd8a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x3ff,(%rax)
jbe    1332 <milliHertzToFnum+0x232>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%dl
mov    $0x14,%cl
sub    %dl,%cl
shl    %cl,%rax
movq   %rax,%xmm0
movaps 0xd1a(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xd1e(%rip),%xmm1
subpd  %xmm1,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
mov    -0x1c(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xd0f(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  0xd07(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1337 <milliHertzToFnum+0x237>
pop    %rbp
ret

x86 assembly (clang, -O2):
<milliHertzToFnum>:
test   %edi,%edi
je     111c <milliHertzToFnum+0x1c>
cmp    $0x5ebbb0,%edi
jb     1129 <milliHertzToFnum+0x29>
movl   $0x7,(%rdx)
mov    $0x3ff,%eax
jmp    123b <milliHertzToFnum+0x13b>
movl   $0x0,(%rdx)
xor    %eax,%eax
jmp    123b <milliHertzToFnum+0x13b>
mov    %ecx,%r9d
cmp    $0x2f5dd7,%edi
jbe    1141 <milliHertzToFnum+0x41>
mov    $0xd,%ecx
mov    $0x7,%r8d
jmp    11bf <milliHertzToFnum+0xbf>
cmp    $0x17aeeb,%edi
jbe    1156 <milliHertzToFnum+0x56>
mov    $0xe,%ecx
mov    $0x6,%r8d
jmp    11bf <milliHertzToFnum+0xbf>
cmp    $0xbd775,%edi
jbe    116b <milliHertzToFnum+0x6b>
mov    $0xf,%ecx
mov    $0x5,%r8d
jmp    11bf <milliHertzToFnum+0xbf>
cmp    $0x5ebba,%edi
jbe    1180 <milliHertzToFnum+0x80>
mov    $0x10,%ecx
mov    $0x4,%r8d
jmp    11bf <milliHertzToFnum+0xbf>
cmp    $0x2f5dd,%edi
jbe    1195 <milliHertzToFnum+0x95>
mov    $0x11,%ecx
mov    $0x3,%r8d
jmp    11bf <milliHertzToFnum+0xbf>
cmp    $0x17aee,%edi
jbe    11aa <milliHertzToFnum+0xaa>
mov    $0x12,%ecx
mov    $0x2,%r8d
jmp    11bf <milliHertzToFnum+0xbf>
xor    %r8d,%r8d
cmp    $0xbd78,%edi
setae  %r8b
mov    $0x14,%ecx
sub    %r8,%rcx
mov    %edi,%eax
mov    %rax,%rdi
shl    %cl,%rdi
cvtsi2sd %rdi,%xmm1
mov    %r9d,%ecx
cvtsi2sd %rcx,%xmm0
mulsd  0xe24(%rip),%xmm0
mov    %r8d,(%rdx)
divsd  %xmm0,%xmm1
addsd  0xe1d(%rip),%xmm1
cvttsd2si %xmm1,%rcx
mov    %ecx,(%rsi)
cmp    $0x400,%ecx
jb     123d <milliHertzToFnum+0x13d>
mov    (%rdx),%edi
mov    $0x13,%cl
sub    %dil,%cl
add    $0x1,%edi
shl    %cl,%rax
movq   %rax,%xmm1
punpckldq 0xdfc(%rip),%xmm1
subpd  0xe04(%rip),%xmm1
mov    %edi,(%rdx)
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
divsd  %xmm0,%xmm2
addsd  0xdd2(%rip),%xmm2
cvttsd2si %xmm2,%rax
mov    %eax,(%rsi)
ret

LLVM IR (-O0):
define void @milliHertzToFnum(i32 %0, i32* %1, i32* %2, i32 %3) {
%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
store i32 %3, i32* %8
%9 = load i32, i32* %5
%10 = icmp ule i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %4
%12 = load i32*, i32** %7
store i32 0, i32* %12
%13 = load i32*, i32** %6
store i32 0, i32* %13
br label %102
14: ; preds = %4
%15 = load i32, i32* %5
%16 = icmp ugt i32 %15, 6208431
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32*, i32** %7
store i32 7, i32* %18
%19 = load i32*, i32** %6
store i32 1023, i32* %19
br label %102
20: ; preds = %14
%21 = load i32, i32* %5
%22 = icmp ugt i32 %21, 3104215
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = load i32*, i32** %7
store i32 7, i32* %24
br label %63
25: ; preds = %20
%26 = load i32, i32* %5
%27 = icmp ugt i32 %26, 1552107
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32*, i32** %7
store i32 6, i32* %29
br label %62
30: ; preds = %25
%31 = load i32, i32* %5
%32 = icmp ugt i32 %31, 776053
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32*, i32** %7
store i32 5, i32* %34
br label %61
35: ; preds = %30
%36 = load i32, i32* %5
%37 = icmp ugt i32 %36, 388026
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i32*, i32** %7
store i32 4, i32* %39
br label %60
40: ; preds = %35
%41 = load i32, i32* %5
%42 = icmp ugt i32 %41, 194013
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = load i32*, i32** %7
store i32 3, i32* %44
br label %59
45: ; preds = %40
%46 = load i32, i32* %5
%47 = icmp ugt i32 %46, 97006
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = load i32*, i32** %7
store i32 2, i32* %49
br label %58
50: ; preds = %45
%51 = load i32, i32* %5
%52 = icmp ugt i32 %51, 48503
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = load i32*, i32** %7
store i32 1, i32* %54
br label %57
55: ; preds = %50
%56 = load i32*, i32** %7
store i32 0, i32* %56
br label %57
57: ; preds = %55, %53
br label %58
58: ; preds = %57, %48
br label %59
59: ; preds = %58, %43
br label %60
60: ; preds = %59, %38
br label %61
61: ; preds = %60, %33
br label %62
62: ; preds = %61, %28
br label %63
63: ; preds = %62, %23
%64 = load i32, i32* %5
%65 = zext i32 %64 to i64
%66 = load i32*, i32** %7
%67 = load i32, i32* %66
%68 = sub i32 20, %67
%69 = zext i32 %68 to i64
%70 = shl i64 %65, %69
%71 = uitofp i64 %70 to double
%72 = load i32, i32* %8
%73 = uitofp i32 %72 to double
%74 = fmul double %73, 1.000000e+03
%75 = fdiv double %71, %74
%76 = fadd double %75, 5.000000e-01
%77 = fptoui double %76 to i32
%78 = load i32*, i32** %6
store i32 %77, i32* %78
%79 = load i32*, i32** %6
%80 = load i32, i32* %79
%81 = icmp ugt i32 %80, 1023
br i1 %81, label %82, label %101
82: ; preds = %63
%83 = load i32*, i32** %7
%84 = load i32, i32* %83
%85 = add i32 %84, 1
store i32 %85, i32* %83
%86 = load i32, i32* %5
%87 = zext i32 %86 to i64
%88 = load i32*, i32** %7
%89 = load i32, i32* %88
%90 = sub i32 20, %89
%91 = zext i32 %90 to i64
%92 = shl i64 %87, %91
%93 = uitofp i64 %92 to double
%94 = load i32, i32* %8
%95 = uitofp i32 %94 to double
%96 = fmul double %95, 1.000000e+03
%97 = fdiv double %93, %96
%98 = fadd double %97, 5.000000e-01
%99 = fptoui double %98 to i32
%100 = load i32*, i32** %6
store i32 %99, i32* %100
br label %101
101: ; preds = %82, %63
br label %102
102: ; preds = %101, %17, %11
ret void
}

LLVM IR (-O2):
define void @milliHertzToFnum(i32 %0, i32* nocapture writeonly %1, i32* nocapture %2, i32 %3) {
%5 = icmp eq i32 %0, 0
br i1 %5, label %6, label %7
6: ; preds = %4
store i32 0, i32* %2
br label %48
7: ; preds = %4
%8 = icmp ugt i32 %0, 6208431
br i1 %8, label %9, label %10
9: ; preds = %7
store i32 7, i32* %2
br label %48
10: ; preds = %7
%11 = icmp ugt i32 %0, 3104215
br i1 %11, label %26, label %12
12: ; preds = %10
%13 = icmp ugt i32 %0, 1552107
br i1 %13, label %26, label %14
14: ; preds = %12
%15 = icmp ugt i32 %0, 776053
br i1 %15, label %26, label %16
16: ; preds = %14
%17 = icmp ugt i32 %0, 388026
br i1 %17, label %26, label %18
18: ; preds = %16
%19 = icmp ugt i32 %0, 194013
br i1 %19, label %26, label %20
20: ; preds = %18
%21 = icmp ugt i32 %0, 97006
br i1 %21, label %26, label %22
22: ; preds = %20
%23 = icmp ugt i32 %0, 48503
%24 = zext i1 %23 to i32
%25 = select i1 %23, i64 19, i64 20
br label %26
26: ; preds = %22, %20, %18, %16, %14, %12, %10
%27 = phi i32 [ 7, %10 ], [ 6, %12 ], [ 5, %14 ], [ 4, %16 ], [ 3, %18 ], [ 2, %20 ], [ %24, %22 ]
%28 = phi i64 [ 13, %10 ], [ 14, %12 ], [ 15, %14 ], [ 16, %16 ], [ 17, %18 ], [ 18, %20 ], [ %25, %22 ]
store i32 %27, i32* %2
%29 = zext i32 %0 to i64
%30 = shl nuw nsw i64 %29, %28
%31 = uitofp i64 %30 to double
%32 = uitofp i32 %3 to double
%33 = fmul double %32, 1.000000e+03
%34 = fdiv double %31, %33
%35 = fadd double %34, 5.000000e-01
%36 = fptoui double %35 to i32
store i32 %36, i32* %1
%37 = icmp ugt i32 %36, 1023
br i1 %37, label %38, label %50
38: ; preds = %26
%39 = load i32, i32* %2
%40 = add i32 %39, 1
store i32 %40, i32* %2
%41 = sub i32 19, %39
%42 = zext i32 %41 to i64
%43 = shl i64 %29, %42
%44 = uitofp i64 %43 to double
%45 = fdiv double %44, %33
%46 = fadd double %45, 5.000000e-01
%47 = fptoui double %46 to i32
br label %48
48: ; preds = %6, %9, %38
%49 = phi i32 [ %47, %38 ], [ 1023, %9 ], [ 0, %6 ]
store i32 %49, i32* %1
br label %50
50: ; preds = %48, %26
ret void
}