#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
size_t tree_depth(size_t count) {
  size_t i;
  size_t depth = 0;
  assert(count > 0);
  for (i = sizeof(size_t) << 2; i > 0; i >>= 1) {
    if (count >> i > 0) {
      count >>= i;
      depth += i;
    }
  }
  return depth;
}


x86 assembly (clang, -O0):
<tree_depth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0x20,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jbe    118f <tree_depth+0x7f>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
shr    %cl,%rax
cmp    $0x0,%rax
jbe    1179 <tree_depth+0x69>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
shr    %cl,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    117e <tree_depth+0x6e>
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    113e <tree_depth+0x2e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tree_depth>:
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
xor    %eax,%eax
mov    %rbx,%rcx
shr    $0x20,%rcx
setne  %al
cmove  %rbx,%rcx
shl    $0x5,%rax
mov    %rcx,%rdx
shr    $0x10,%rdx
xor    %esi,%esi
cmp    $0x10000,%rcx
cmovb  %rcx,%rdx
setae  %sil
shl    $0x4,%rsi
or     %rax,%rsi
mov    %rdx,%rax
shr    $0x8,%rax
xor    %ecx,%ecx
cmp    $0x100,%rdx
cmovb  %rdx,%rax
setae  %cl
mov    %rax,%rdx
shr    $0x4,%rdx
xor    %edi,%edi
cmp    $0x10,%rax
setae  %dil
lea    (%rsi,%rcx,8),%rcx
cmovb  %rax,%rdx
mov    %rdx,%rsi
shr    $0x2,%rsi
xor    %eax,%eax
cmp    $0x4,%rdx
setae  %al
lea    (%rcx,%rdi,4),%rcx
cmovb  %rdx,%rsi
lea    (%rcx,%rax,2),%rcx
xor    %eax,%eax
cmp    $0x2,%rsi
setae  %al
or     %rcx,%rax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @tree_depth(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %4
%5 = load i64, i64* %2
%6 = icmp ugt i64 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
store i64 32, i64* %3
br label %9
9: ; preds = %25, %1
%10 = load i64, i64* %3
%11 = icmp ugt i64 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %9
%13 = load i64, i64* %2
%14 = load i64, i64* %3
%15 = lshr i64 %13, %14
%16 = icmp ugt i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = load i64, i64* %3
%19 = load i64, i64* %2
%20 = lshr i64 %19, %18
store i64 %20, i64* %2
%21 = load i64, i64* %3
%22 = load i64, i64* %4
%23 = add i64 %22, %21
store i64 %23, i64* %4
br label %24
24: ; preds = %17, %12
br label %25
25: ; preds = %24
%26 = load i64, i64* %3
%27 = lshr i64 %26, 1
store i64 %27, i64* %3
br label %9
28: ; preds = %9
%29 = load i64, i64* %4
ret i64 %29
}

LLVM IR (-O2):
define i64 @tree_depth(i64 %0) {
%2 = icmp ne i64 %0, 0
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = lshr i64 %0, 32
%6 = icmp ult i64 %0, 4294967296
%7 = select i1 %6, i64 %0, i64 %5
%8 = select i1 %6, i64 0, i64 32
%9 = lshr i64 %7, 16
%10 = icmp ult i64 %7, 65536
%11 = select i1 %10, i64 %7, i64 %9
%12 = select i1 %10, i64 0, i64 16
%13 = or i64 %12, %8
%14 = lshr i64 %11, 8
%15 = icmp ult i64 %11, 256
%16 = select i1 %15, i64 %11, i64 %14
%17 = select i1 %15, i64 0, i64 8
%18 = or i64 %17, %13
%19 = lshr i64 %16, 4
%20 = icmp ult i64 %16, 16
%21 = select i1 %20, i64 %16, i64 %19
%22 = select i1 %20, i64 0, i64 4
%23 = or i64 %22, %18
%24 = lshr i64 %21, 2
%25 = icmp ult i64 %21, 4
%26 = select i1 %25, i64 %21, i64 %24
%27 = select i1 %25, i64 0, i64 2
%28 = or i64 %27, %23
%29 = icmp ugt i64 %26, 1
%30 = zext i1 %29 to i64
%31 = or i64 %28, %30
ret i64 %31
}