#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 */
unsigned int strhash(char const *);
unsigned int hash(unsigned int method, unsigned int i, const char *key) {
  unsigned int hash = 0;
  switch (method & 3) {
  case 0:
    hash = strhash(key);
    break;
  case 1:
    hash = i;
    break;
  case 2:
    hash = i / 10;
    break;
  case 3:
    hash = 0;
    break;
  }
  if (method & 4)
    hash = 2 * hash;
  return hash;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0x3,%eax
mov    %rax,-0x20(%rbp)
sub    $0x3,%eax
ja     1187 <hash+0x77>
mov    -0x20(%rbp),%rax
lea    0xeb9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
call   1030 <strhash@plt>
mov    %eax,-0x14(%rbp)
jmp    1187 <hash+0x77>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1187 <hash+0x77>
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x14(%rbp)
jmp    1187 <hash+0x77>
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     119f <hash+0x8f>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbx
mov    %esi,%eax
mov    %edi,%ebx
mov    %edi,%ecx
and    $0x3,%ecx
lea    0xedf(%rip),%rsi
movslq (%rsi,%rcx,4),%rcx
add    %rsi,%rcx
jmp    *%rcx
mov    %rdx,%rdi
call   1030 <strhash@plt>
jmp    1147 <hash+0x37>
mov    %eax,%ecx
mov    $0xcccccccd,%eax
imul   %rcx,%rax
shr    $0x23,%rax
jmp    1147 <hash+0x37>
xor    %eax,%eax
shr    $0x2,%bl
and    $0x1,%bl
mov    %ebx,%ecx
shl    %cl,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @hash(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i8* %2, i8** %6
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = and i32 %8, 3
switch i32 %9, label %19 [
i32 0, label %10
i32 1, label %13
i32 2, label %15
i32 3, label %18
]
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = call i32 @strhash(i8* %11)
store i32 %12, i32* %7
br label %19
13: ; preds = %3
%14 = load i32, i32* %5
store i32 %14, i32* %7
br label %19
15: ; preds = %3
%16 = load i32, i32* %5
%17 = udiv i32 %16, 10
store i32 %17, i32* %7
br label %19
18: ; preds = %3
store i32 0, i32* %7
br label %19
19: ; preds = %3, %18, %15, %13, %10
%20 = load i32, i32* %4
%21 = and i32 %20, 4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %7
%25 = mul i32 2, %24
store i32 %25, i32* %7
br label %26
26: ; preds = %23, %19
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
define i32 @hash(i32 %0, i32 %1, i8* %2) {
%4 = and i32 %0, 3
switch i32 %4, label %10 [
i32 0, label %5
i32 1, label %11
i32 2, label %7
i32 3, label %9
]
5: ; preds = %3
%6 = tail call i32 @strhash(i8* %2)
br label %11
7: ; preds = %3
%8 = udiv i32 %1, 10
br label %11
9: ; preds = %3
br label %11
10: ; preds = %3
unreachable
11: ; preds = %3, %9, %7, %5
%12 = phi i32 [ 0, %9 ], [ %8, %7 ], [ %6, %5 ], [ %1, %3 ]
%13 = lshr i32 %0, 2
%14 = and i32 %13, 1
%15 = shl i32 %12, %14
ret i32 %15
}