#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 */
size_t __ind_shift();
scalar_t__ __libc_getpagesize();
size_t get_index(size_t _size) {
  register size_t idx = 0;
  register size_t size =
      ((_size - 1) & (((size_t)__libc_getpagesize()) - 1)) >> __ind_shift();
  while (size) {
    size >>= 1;
    ++idx;
  }
  return idx;
}


x86 assembly (clang, -O0):
<get_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1040 <__libc_getpagesize@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
sub    $0x1,%rcx
and    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <__ind_shift@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
shr    %cl,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1196 <get_index+0x76>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    116e <get_index+0x4e>
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_index>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
add    $0xffffffffffffffff,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <__libc_getpagesize@plt>
mov    %rax,%r14
add    $0xffffffffffffffff,%r14
and    %r15,%r14
xor    %eax,%eax
call   1030 <__ind_shift@plt>
mov    %eax,%ecx
shr    %cl,%r14
test   %r14,%r14
je     1170 <get_index+0x50>
xor    %ebx,%ebx
mov    %r14,%rax
cs nopw 0x0(%rax,%rax,1)
nop
shr    %rax
add    $0x1,%rbx
cmp    $0x1,%r14
mov    %rax,%r14
ja     1160 <get_index+0x40>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @get_index(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %3
%5 = load i64, i64* %2
%6 = sub i64 %5, 1
%7 = call i64 (...) @__libc_getpagesize()
%8 = sub i64 %7, 1
%9 = and i64 %6, %8
%10 = call i64 (...) @__ind_shift()
%11 = lshr i64 %9, %10
store i64 %11, i64* %4
br label %12
12: ; preds = %15, %1
%13 = load i64, i64* %4
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = load i64, i64* %4
%17 = lshr i64 %16, 1
store i64 %17, i64* %4
%18 = load i64, i64* %3
%19 = add i64 %18, 1
store i64 %19, i64* %3
br label %12
20: ; preds = %12
%21 = load i64, i64* %3
ret i64 %21
}

LLVM IR (-O2):
define i64 @get_index(i64 %0) {
%2 = add i64 %0, -1
%3 = tail call i64 (...) @__libc_getpagesize()
%4 = add i64 %3, -1
%5 = and i64 %4, %2
%6 = tail call i64 (...) @__ind_shift()
%7 = lshr i64 %5, %6
%8 = icmp eq i64 %7, 0
br i1 %8, label %15, label %9
9: ; preds = %1, %9
%10 = phi i64 [ %12, %9 ], [ %7, %1 ]
%11 = phi i64 [ %13, %9 ], [ 0, %1 ]
%12 = lshr i64 %10, 1
%13 = add nuw nsw i64 %11, 1
%14 = icmp ult i64 %10, 2
br i1 %14, label %15, label %9
15: ; preds = %9, %1
%16 = phi i64 [ 0, %1 ], [ %13, %9 ]
ret i64 %16
}