unsigned int fc8180_set_filter(void *handle, unsigned int ref_clock,
                               unsigned int filter_bw) {
  unsigned int div_cal = 0;
  unsigned char div = 0;
  div_cal = (378000 / filter_bw) * ref_clock / 10000;
  if ((div_cal % 10) >= 5)
    div = (unsigned char)(div_cal / 10) + 1;
  else
    div = (unsigned char)div_cal / 10;
  return div;
}


x86 assembly (clang, -O0):
<fc8180_set_filter>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    $0x5c490,%eax
xor    %edx,%edx
divl   -0x10(%rbp)
imul   -0xc(%rbp),%eax
mov    $0x2710,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
cmp    $0x5,%edx
jb     1162 <fc8180_set_filter+0x62>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
movzbl %al,%eax
add    $0x1,%eax
mov    %al,-0x15(%rbp)
jmp    1173 <fc8180_set_filter+0x73>
mov    -0x14(%rbp),%eax
movzbl %al,%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc8180_set_filter>:
mov    %edx,%ecx
mov    $0x5c490,%eax
xor    %edx,%edx
div    %ecx
imul   %esi,%eax
mov    $0xd1b71759,%ecx
imul   %rax,%rcx
shr    $0x2d,%rcx
mov    $0xcccccccd,%edx
imul   %rcx,%rdx
shr    $0x23,%rdx
add    %edx,%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
cmp    $0x5,%esi
jb     114e <fc8180_set_filter+0x4e>
shr    $0x5,%eax
imul   $0xa7c5ac5,%rax,%rax
shr    $0x27,%rax
movzbl %al,%eax
add    $0x1,%eax
movzbl %al,%eax
ret
movzbl %cl,%eax
imul   $0xcd,%eax,%eax
shr    $0xb,%eax
movzbl %al,%eax
ret

LLVM IR (-O0):
define i32 @fc8180_set_filter(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i8 0, i8* %8
%9 = load i32, i32* %6
%10 = udiv i32 378000, %9
%11 = load i32, i32* %5
%12 = mul i32 %10, %11
%13 = udiv i32 %12, 10000
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = urem i32 %14, 10
%16 = icmp uge i32 %15, 5
br i1 %16, label %17, label %24
17: ; preds = %3
%18 = load i32, i32* %7
%19 = udiv i32 %18, 10
%20 = trunc i32 %19 to i8
%21 = zext i8 %20 to i32
%22 = add nsw i32 %21, 1
%23 = trunc i32 %22 to i8
store i8 %23, i8* %8
br label %30
24: ; preds = %3
%25 = load i32, i32* %7
%26 = trunc i32 %25 to i8
%27 = zext i8 %26 to i32
%28 = sdiv i32 %27, 10
%29 = trunc i32 %28 to i8
store i8 %29, i8* %8
br label %30
30: ; preds = %24, %17
%31 = load i8, i8* %8
%32 = zext i8 %31 to i32
ret i32 %32
}

LLVM IR (-O2):
define i32 @fc8180_set_filter(i8* nocapture readnone %0, i32 %1, i32 %2) {
%4 = udiv i32 378000, %2
%5 = mul i32 %4, %1
%6 = udiv i32 %5, 10000
%7 = urem i32 %6, 10
%8 = icmp ugt i32 %7, 4
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = udiv i32 %5, 100000
%11 = and i32 %10, 255
%12 = add nuw nsw i32 %11, 1
br label %17
13: ; preds = %3
%14 = trunc i32 %6 to i8
%15 = udiv i8 %14, 10
%16 = zext i8 %15 to i32
br label %17
17: ; preds = %13, %9
%18 = phi i32 [ %12, %9 ], [ %16, %13 ]
%19 = and i32 %18, 255
ret i32 %19
}