int countint(const struct ltable_key *key, int *nums) {
  int k = arrayindex(key);
  if (k < 0 || k > (1 << 30))
    return 0;
  if (k == 0)
    nums[0]++;
  else
    nums[_floorlog2(k) + 1]++;
  return 1;
}


x86 assembly (clang, -O0):
<countint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <arrayindex@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     1155 <countint+0x35>
cmpl   $0x40000000,-0x1c(%rbp)
jle    1161 <countint+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <countint+0x89>
cmpl   $0x0,-0x1c(%rbp)
jne    117b <countint+0x5b>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    11a2 <countint+0x82>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x0,%al
call   1040 <_floorlog2@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
mov    %edx,(%rax,%rcx,4)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countint>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <arrayindex@plt>
cmp    $0x40000000,%eax
ja     1155 <countint+0x35>
test   %eax,%eax
je     114d <countint+0x2d>
mov    %eax,%edi
xor    %eax,%eax
call   1040 <_floorlog2@plt>
cltq
lea    (%rbx,%rax,4),%rbx
add    $0x4,%rbx
addl   $0x1,(%rbx)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ltable_key = type opaque
define i32 @countint(%struct.ltable_key* %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.ltable_key*
%5 = alloca i32*
%6 = alloca i32
store %struct.ltable_key* %0, %struct.ltable_key** %4
store i32* %1, i32** %5
%7 = load %struct.ltable_key*, %struct.ltable_key** %4
%8 = call i32 (%struct.ltable_key*, ...) bitcast (i32 (...)* @arrayindex to i32 (%struct.ltable_key*, ...)*)(%struct.ltable_key* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %6
%13 = icmp sgt i32 %12, 1073741824
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i32 0, i32* %3
br label %33
15: ; preds = %11
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32*, i32** %5
%20 = getelementptr inbounds i32, i32* %19, i64 0
%21 = load i32, i32* %20
%22 = add nsw i32 %21, 1
store i32 %22, i32* %20
br label %32
23: ; preds = %15
%24 = load i32*, i32** %5
%25 = load i32, i32* %6
%26 = call i32 (i32, ...) bitcast (i32 (...)* @_floorlog2 to i32 (i32, ...)*)(i32 %25)
%27 = add nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %24, i64 %28
%30 = load i32, i32* %29
%31 = add nsw i32 %30, 1
store i32 %31, i32* %29
br label %32
32: ; preds = %23, %18
store i32 1, i32* %3
br label %33
33: ; preds = %32, %14
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
%struct.ltable_key = type opaque
define i32 @countint(%struct.ltable_key* %0, i32* nocapture %1) {
%3 = tail call i32 (%struct.ltable_key*, ...) bitcast (i32 (...)* @arrayindex to i32 (%struct.ltable_key*, ...)*)(%struct.ltable_key* %0)
%4 = icmp ugt i32 %3, 1073741824
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = icmp eq i32 %3, 0
br i1 %6, label %12, label %7
7: ; preds = %5
%8 = tail call i32 (i32, ...) bitcast (i32 (...)* @_floorlog2 to i32 (i32, ...)*)(i32 %3)
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %1, i64 %10
br label %12
12: ; preds = %5, %7
%13 = phi i32* [ %11, %7 ], [ %1, %5 ]
%14 = load i32, i32* %13
%15 = add nsw i32 %14, 1
store i32 %15, i32* %13
br label %16
16: ; preds = %12, %2
%17 = phi i32 [ 0, %2 ], [ 1, %12 ]
ret i32 %17
}