#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int __u64;
typedef int __u32;

/* Variables and functions */
__u32 CalcHeads(const __u64 uiSize) {
  __u64 size = uiSize;
  if (!({
        __u32 __rem = size % 16;
        size /= 16;
        __rem;
      }))
    return 16;
  if (!(uiSize % 8))
    return 8;
  if (!(uiSize % 4))
    return 4;
  if (!(uiSize % 2))
    return 2;
  return ~0;
}


x86 assembly (clang, -O0):
<CalcHeads>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1145 <CalcHeads+0x45>
movl   $0x10,-0x4(%rbp)
jmp    11ac <CalcHeads+0xac>
mov    -0x8(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1165 <CalcHeads+0x65>
movl   $0x8,-0x4(%rbp)
jmp    11ac <CalcHeads+0xac>
mov    -0x8(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1185 <CalcHeads+0x85>
movl   $0x4,-0x4(%rbp)
jmp    11ac <CalcHeads+0xac>
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a5 <CalcHeads+0xa5>
movl   $0x2,-0x4(%rbp)
jmp    11ac <CalcHeads+0xac>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalcHeads>:
test   $0xf,%dil
je     111d <CalcHeads+0x1d>
test   $0x7,%dil
je     1123 <CalcHeads+0x23>
test   $0x3,%dil
je     1129 <CalcHeads+0x29>
and    $0x1,%edi
neg    %edi
sbb    %eax,%eax
or     $0x2,%eax
ret
mov    $0x10,%eax
ret
mov    $0x8,%eax
ret
mov    $0x4,%eax
ret

LLVM IR (-O0):
define i32 @CalcHeads(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* %3
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = srem i32 %8, 16
store i32 %9, i32* %5
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 16
store i32 %11, i32* %4
%12 = load i32, i32* %5
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %1
store i32 16, i32* %2
br label %32
16: ; preds = %1
%17 = load i32, i32* %3
%18 = srem i32 %17, 8
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %16
store i32 8, i32* %2
br label %32
21: ; preds = %16
%22 = load i32, i32* %3
%23 = srem i32 %22, 4
%24 = icmp ne i32 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %21
store i32 4, i32* %2
br label %32
26: ; preds = %21
%27 = load i32, i32* %3
%28 = srem i32 %27, 2
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %26
store i32 2, i32* %2
br label %32
31: ; preds = %26
store i32 -1, i32* %2
br label %32
32: ; preds = %31, %30, %25, %20, %15
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @CalcHeads(i32 %0) {
%2 = and i32 %0, 15
%3 = icmp eq i32 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = and i32 %0, 7
%6 = icmp eq i32 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %4
%8 = and i32 %0, 3
%9 = icmp eq i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %7
%11 = and i32 %0, 1
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i32 2, i32 -1
br label %14
14: ; preds = %10, %7, %4, %1
%15 = phi i32 [ 16, %1 ], [ 8, %4 ], [ 4, %7 ], [ %13, %10 ]
ret i32 %15
}