#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 scalar_t__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ validate_fit(size_t, unsigned int);
size_t to_index(const uint8_t *buf, unsigned int m_cost) {
  size_t index = 0;
  size_t i;
  assert(validate_fit((((size_t)64) * ((size_t)4)), m_cost) == 0);
  for (i = 0; i < ((size_t)16); i++) {
    index <<= 8;
    index += buf[i];
  }
  index &= ~(~((size_t)0) << m_cost);
  index *= (((size_t)64) * ((size_t)4));
  return index;
}


x86 assembly (clang, -O0):
<to_index>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x100,%edi
call   1040 <validate_fit@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movq   $0x0,-0x20(%rbp)
cmpq   $0x10,-0x20(%rbp)
jae    1199 <to_index+0x79>
mov    -0x18(%rbp),%rax
shl    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115d <to_index+0x3d>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0xffffffffffffffff,%rax
shl    %cl,%rax
xor    $0xffffffffffffffff,%rax
and    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_index>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x100,%edi
call   1040 <validate_fit@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1030 <assert@plt>
mov    0x48(%rbx),%rdx
shl    $0x8,%rdx
add    0x50(%rbx),%rdx
shl    $0x8,%rdx
add    0x58(%rbx),%rdx
shl    $0x8,%rdx
add    0x60(%rbx),%rdx
shl    $0x8,%rdx
add    0x68(%rbx),%rdx
shl    $0x8,%rdx
add    0x70(%rbx),%rdx
shl    $0x8,%rdx
add    0x78(%rbx),%rdx
mov    $0xffffffffffffffff,%rax
mov    %ebp,%ecx
shl    %cl,%rax
not    %rax
and    %rdx,%rax
shl    $0x8,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i64 @to_index(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i64* %0, i64** %3
store i32 %1, i32* %4
store i64 0, i64* %5
%7 = load i32, i32* %4
%8 = call i64 @validate_fit(i64 256, i32 %7)
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
store i64 0, i64* %6
br label %12
12: ; preds = %24, %2
%13 = load i64, i64* %6
%14 = icmp ult i64 %13, 16
br i1 %14, label %15, label %27
15: ; preds = %12
%16 = load i64, i64* %5
%17 = shl i64 %16, 8
store i64 %17, i64* %5
%18 = load i64*, i64** %3
%19 = load i64, i64* %6
%20 = getelementptr inbounds i64, i64* %18, i64 %19
%21 = load i64, i64* %20
%22 = load i64, i64* %5
%23 = add i64 %22, %21
store i64 %23, i64* %5
br label %24
24: ; preds = %15
%25 = load i64, i64* %6
%26 = add i64 %25, 1
store i64 %26, i64* %6
br label %12
27: ; preds = %12
%28 = load i32, i32* %4
%29 = zext i32 %28 to i64
%30 = shl i64 -1, %29
%31 = xor i64 %30, -1
%32 = load i64, i64* %5
%33 = and i64 %32, %31
store i64 %33, i64* %5
%34 = load i64, i64* %5
%35 = mul i64 %34, 256
store i64 %35, i64* %5
%36 = load i64, i64* %5
ret i64 %36
}

LLVM IR (-O2):
define i64 @to_index(i64* nocapture %0, i32 %1) {
%3 = tail call i64 @validate_fit(i64 256, i32 %1)
%4 = icmp eq i64 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = getelementptr inbounds i64, i64* %0, i64 9
%8 = load i64, i64* %7
%9 = shl i64 %8, 8
%10 = getelementptr inbounds i64, i64* %0, i64 10
%11 = load i64, i64* %10
%12 = add i64 %11, %9
%13 = shl i64 %12, 8
%14 = getelementptr inbounds i64, i64* %0, i64 11
%15 = load i64, i64* %14
%16 = add i64 %15, %13
%17 = shl i64 %16, 8
%18 = getelementptr inbounds i64, i64* %0, i64 12
%19 = load i64, i64* %18
%20 = add i64 %19, %17
%21 = shl i64 %20, 8
%22 = getelementptr inbounds i64, i64* %0, i64 13
%23 = load i64, i64* %22
%24 = add i64 %23, %21
%25 = shl i64 %24, 8
%26 = getelementptr inbounds i64, i64* %0, i64 14
%27 = load i64, i64* %26
%28 = add i64 %27, %25
%29 = shl i64 %28, 8
%30 = getelementptr inbounds i64, i64* %0, i64 15
%31 = load i64, i64* %30
%32 = add i64 %31, %29
%33 = zext i32 %1 to i64
%34 = shl nsw i64 -1, %33
%35 = xor i64 %34, -1
%36 = and i64 %32, %35
%37 = shl i64 %36, 8
ret i64 %37
}