#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 unsigned long long uint64_t;
typedef int int64_t;
typedef int int32_t;

/* Variables and functions */
int32_t jumphash(uint64_t key, int32_t num_buckets) {
  int64_t b = -1;
  int64_t j = 0;
  while (j < num_buckets) {
    b = j;
    key = key * 2862933555777941757ULL + 1;
    j = (b + 1) * ((double)(1LL << 31) / (double)((key >> 33) + 1));
  }
  return ((int32_t)b);
}


x86 assembly (clang, -O0):
<jumphash>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117c <jumphash+0x7c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movabs $0x27bb2ee687b0b0fd,%rcx
2e bb 27
imul   %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
shr    $0x21,%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm2
movsd  0xe98(%rip),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
jmp    1119 <jumphash+0x19>
mov    -0x10(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<jumphash>:
test   %esi,%esi
jle    115c <jumphash+0x5c>
xor    %edx,%edx
movabs $0x27bb2ee687b0b0fd,%rcx
2e bb 27
movsd  0xee8(%rip),%xmm0
nopl   0x0(%rax,%rax,1)
mov    %edx,%eax
imul   %rcx,%rdi
add    $0x1,%rdi
lea    0x1(%rax),%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
mov    %rdi,%rdx
shr    $0x21,%rdx
add    $0x1,%rdx
xorps  %xmm2,%xmm2
cvtsi2sd %rdx,%xmm2
movapd %xmm0,%xmm3
divsd  %xmm2,%xmm3
mulsd  %xmm1,%xmm3
cvttsd2si %xmm3,%edx
cmp    %esi,%edx
jl     1120 <jumphash+0x20>
ret
mov    $0xffffffff,%eax
ret

LLVM IR (-O0):
define i32 @jumphash(i64 %0, i32 %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i64 %0, i64* %3
store i32 %1, i32* %4
store i32 -1, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %11, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load i32, i32* %6
store i32 %12, i32* %5
%13 = load i64, i64* %3
%14 = mul i64 %13, 2862933555777941757
%15 = add i64 %14, 1
store i64 %15, i64* %3
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
%18 = sitofp i32 %17 to double
%19 = load i64, i64* %3
%20 = lshr i64 %19, 33
%21 = add i64 %20, 1
%22 = uitofp i64 %21 to double
%23 = fdiv double 0x41E0000000000000, %22
%24 = fmul double %18, %23
%25 = fptosi double %24 to i32
store i32 %25, i32* %6
br label %7
26: ; preds = %7
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
define i32 @jumphash(i64 %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %18
4: ; preds = %2, %4
%5 = phi i32 [ %16, %4 ], [ 0, %2 ]
%6 = phi i64 [ %8, %4 ], [ %0, %2 ]
%7 = mul i64 %6, 2862933555777941757
%8 = add i64 %7, 1
%9 = add nsw i32 %5, 1
%10 = sitofp i32 %9 to double
%11 = lshr i64 %8, 33
%12 = add nuw nsw i64 %11, 1
%13 = uitofp i64 %12 to double
%14 = fdiv double 0x41E0000000000000, %13
%15 = fmul double %14, %10
%16 = fptosi double %15 to i32
%17 = icmp slt i32 %16, %1
br i1 %17, label %4, label %18
18: ; preds = %4, %2
%19 = phi i32 [ -1, %2 ], [ %5, %4 ]
ret i32 %19
}