#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 char wchar_t;

/* Variables and functions */
int is_prime(long double);
long int calculate_double_hash_key(wchar_t *str, long int hash_table_length) {
  long int i, R, second_hash_key, str_sum;
  wchar_t c;
  R = 1;
  for (i = hash_table_length - 1; i > 0; i--) {
    if (is_prime((long double)i) == 1) {
      R = i;
      break;
    }
  }
  i = 0;
  c = str[i];
  str_sum = 0;
  while (c != '\0') {
    str_sum += (long int)c;
    i++;
    c = str[i];
  }
  second_hash_key = R - (str_sum % R);
  return second_hash_key;
}


x86 assembly (clang, -O0):
<calculate_double_hash_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    1180 <calculate_double_hash_key+0x70>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
fildll -0x40(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
call   1030 <is_prime@plt>
cmp    $0x1,%eax
jne    116a <calculate_double_hash_key+0x5a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
jmp    1180 <calculate_double_hash_key+0x70>
jmp    116f <calculate_double_hash_key+0x5f>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1134 <calculate_double_hash_key+0x24>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
movq   $0x0,-0x30(%rbp)
movsbl -0x31(%rbp),%eax
cmp    $0x0,%eax
je     11d7 <calculate_double_hash_key+0xc7>
movsbq -0x31(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
jmp    119e <calculate_double_hash_key+0x8e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
cqto
idivq  -0x20(%rbp)
mov    -0x48(%rbp),%rax
sub    %rdx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calculate_double_hash_key>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
nopl   (%rax)
cmp    $0x2,%r14
jl     1142 <calculate_double_hash_key+0x32>
add    $0xffffffffffffffff,%r14
mov    %r14,0x10(%rsp)
fildll 0x10(%rsp)
fstpt  (%rsp)
call   1030 <is_prime@plt>
cmp    $0x1,%eax
jne    1120 <calculate_double_hash_key+0x10>
jmp    1148 <calculate_double_hash_key+0x38>
mov    $0x1,%r14d
mov    (%rbx),%cl
test   %cl,%cl
je     1174 <calculate_double_hash_key+0x64>
add    $0x1,%rbx
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbq %cl,%rcx
add    %rcx,%rax
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1160 <calculate_double_hash_key+0x50>
jmp    1176 <calculate_double_hash_key+0x66>
xor    %eax,%eax
mov    %rax,%rcx
or     %r14,%rcx
shr    $0x20,%rcx
je     1189 <calculate_double_hash_key+0x79>
cqto
idiv   %r14
jmp    118e <calculate_double_hash_key+0x7e>
xor    %edx,%edx
div    %r14d
sub    %rdx,%r14
mov    %r14,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @calculate_double_hash_key(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8
store i8* %0, i8** %3
store i64 %1, i64* %4
store i64 1, i64* %6
%10 = load i64, i64* %4
%11 = sub nsw i64 %10, 1
store i64 %11, i64* %5
br label %12
12: ; preds = %23, %2
%13 = load i64, i64* %5
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %26
15: ; preds = %12
%16 = load i64, i64* %5
%17 = sitofp i64 %16 to x86_fp80
%18 = call i32 @is_prime(x86_fp80 %17)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i64, i64* %5
store i64 %21, i64* %6
br label %26
22: ; preds = %15
br label %23
23: ; preds = %22
%24 = load i64, i64* %5
%25 = add nsw i64 %24, -1
store i64 %25, i64* %5
br label %12
26: ; preds = %20, %12
store i64 0, i64* %5
%27 = load i8*, i8** %3
%28 = load i64, i64* %5
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %9
store i64 0, i64* %8
br label %31
31: ; preds = %35, %26
%32 = load i8, i8* %9
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %46
35: ; preds = %31
%36 = load i8, i8* %9
%37 = sext i8 %36 to i64
%38 = load i64, i64* %8
%39 = add nsw i64 %38, %37
store i64 %39, i64* %8
%40 = load i64, i64* %5
%41 = add nsw i64 %40, 1
store i64 %41, i64* %5
%42 = load i8*, i8** %3
%43 = load i64, i64* %5
%44 = getelementptr inbounds i8, i8* %42, i64 %43
%45 = load i8, i8* %44
store i8 %45, i8* %9
br label %31
46: ; preds = %31
%47 = load i64, i64* %6
%48 = load i64, i64* %8
%49 = load i64, i64* %6
%50 = srem i64 %48, %49
%51 = sub nsw i64 %47, %50
store i64 %51, i64* %7
%52 = load i64, i64* %7
ret i64 %52
}

LLVM IR (-O2):
define i64 @calculate_double_hash_key(i8* nocapture %0, i64 %1) {
br label %3
3: ; preds = %7, %2
%4 = phi i64 [ %1, %2 ], [ %5, %7 ]
%5 = add nsw i64 %4, -1
%6 = icmp sgt i64 %4, 1
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = sitofp i64 %5 to x86_fp80
%9 = tail call i32 @is_prime(x86_fp80 %8)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %3
11: ; preds = %7, %3
%12 = phi i64 [ 1, %3 ], [ %5, %7 ]
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 0
br i1 %14, label %25, label %15
15: ; preds = %11, %15
%16 = phi i8 [ %23, %15 ], [ %13, %11 ]
%17 = phi i64 [ %20, %15 ], [ 0, %11 ]
%18 = phi i64 [ %21, %15 ], [ 0, %11 ]
%19 = sext i8 %16 to i64
%20 = add nsw i64 %17, %19
%21 = add nuw nsw i64 %18, 1
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %15
25: ; preds = %15, %11
%26 = phi i64 [ 0, %11 ], [ %20, %15 ]
%27 = srem i64 %26, %12
%28 = sub nsw i64 %12, %27
ret i64 %28
}