// File: /workspace/github_c_makefile_star2_O2/zuocheng-liu[P]ae-memcached/src/assoc.c
// Function: hash
ub4 hash( k, length, initval)
     register ub1 *k;        /* the key */
     register ub4  length;   /* the length of the key */
     register ub4  initval;  /* the previous hash, or an arbitrary value */
{
    register ub4 a,b,c,len;

    /* Set up the internal state */
    len = length;
    a = b = 0x9e3779b9;  /* the golden ratio; an arbitrary value */
    c = initval;         /* the previous hash value */

    /*---------------------------------------- handle most of the key */
    while (len >= 12)
        {
            a += (k[0] +((ub4)k[1]<<8) +((ub4)k[2]<<16) +((ub4)k[3]<<24));
            b += (k[4] +((ub4)k[5]<<8) +((ub4)k[6]<<16) +((ub4)k[7]<<24));
            c += (k[8] +((ub4)k[9]<<8) +((ub4)k[10]<<16)+((ub4)k[11]<<24));
            mix(a,b,c);
            k += 12; len -= 12;
        }

    /*------------------------------------- handle the last 11 bytes */
    c += length;
    switch(len)              /* all the case statements fall through */
        {
        case 11: c+=((ub4)k[10]<<24);
        case 10: c+=((ub4)k[9]<<16);
        case 9 : c+=((ub4)k[8]<<8);
            /* the first byte of c is reserved for the length */
        case 8 : b+=((ub4)k[7]<<24);
        case 7 : b+=((ub4)k[6]<<16);
        case 6 : b+=((ub4)k[5]<<8);
        case 5 : b+=k[4];
        case 4 : a+=((ub4)k[3]<<24);
        case 3 : a+=((ub4)k[2]<<16);
        case 2 : a+=((ub4)k[1]<<8);
        case 1 : a+=k[0];
            /* case 0: nothing left to add */
        }
    mix(a,b,c);
    /*-------------------------------------------- report the result */
    return c;
}

// Assembly:
movl $0x9e3779b9, %ecx       # imm = 0x9E3779B9
addq $0xa, %rdi
movl $0x9e3779b9, %eax       # imm = 0x9E3779B9
movq %rsi, %r8
cmpq $0xc, %r8
jb 0x2ed5
movl -0xa(%rdi), %r9d
movl -0x6(%rdi), %r10d
addq %r10, %rax
movl -0x2(%rdi), %r10d
addq %r10, %rdx
addq %r9, %rcx
subq %rax, %rcx
subq %rdx, %rcx
movq %rdx, %r9
shrq $0xd, %r9
xorq %rcx, %r9
subq %rdx, %rax
subq %r9, %rax
movq %r9, %rcx
shlq $0x8, %rcx
xorq %rax, %rcx
subq %r9, %rdx
subq %rcx, %rdx
movq %rcx, %rax
shrq $0xd, %rax
xorq %rdx, %rax
subq %rcx, %r9
subq %rax, %r9
movq %rax, %rdx
shrq $0xc, %rdx
xorq %r9, %rdx
subq %rax, %rcx
subq %rdx, %rcx
movq %rdx, %r9
shlq $0x10, %r9
xorq %rcx, %r9
subq %rdx, %rax
subq %r9, %rax
movq %r9, %r10
shrq $0x5, %r10
xorq %rax, %r10
subq %r9, %rdx
subq %r10, %rdx
movq %r10, %rcx
shrq $0x3, %rcx
xorq %rdx, %rcx
subq %r10, %r9
subq %rcx, %r9
movq %rcx, %rax
shlq $0xa, %rax
xorq %r9, %rax
subq %rcx, %r10
subq %rax, %r10
movq %rax, %rdx
shrq $0xf, %rdx
xorq %r10, %rdx
addq $-0xc, %r8
addq $0xc, %rdi
jmp 0x2e19
addq %rsi, %rdx
decq %r8
cmpq $0xa, %r8
ja 0x2f59
leaq 0x5124(%rip), %rsi      # 0x800c
movslq (%rsi,%r8,4), %r8
addq %rsi, %r8
jmpq *%r8
movzbl (%rdi), %esi
shll $0x18, %esi
addq %rsi, %rdx
movzbl -0x1(%rdi), %esi
shll $0x10, %esi
addq %rsi, %rdx
movzbl -0x2(%rdi), %esi
shll $0x8, %esi
addq %rsi, %rdx
movzbl -0x3(%rdi), %esi
shll $0x18, %esi
addq %rsi, %rax
movzbl -0x4(%rdi), %esi
shll $0x10, %esi
addq %rsi, %rax
movzbl -0x5(%rdi), %esi
shll $0x8, %esi
addq %rsi, %rax
movzbl -0x6(%rdi), %esi
addq %rsi, %rax
movzbl -0x7(%rdi), %esi
shll $0x18, %esi
addq %rsi, %rcx
movzbl -0x8(%rdi), %esi
shll $0x10, %esi
addq %rsi, %rcx
movzbl -0x9(%rdi), %esi
shll $0x8, %esi
addq %rsi, %rcx
movzbl -0xa(%rdi), %esi
addq %rsi, %rcx
subq %rax, %rcx
subq %rdx, %rcx
movq %rdx, %rsi
shrq $0xd, %rsi
xorq %rcx, %rsi
subq %rdx, %rax
subq %rsi, %rax
movq %rsi, %rcx
shlq $0x8, %rcx
xorq %rax, %rcx
subq %rsi, %rdx
subq %rcx, %rdx
movq %rcx, %rax
shrq $0xd, %rax
xorq %rdx, %rax
subq %rcx, %rsi
subq %rax, %rsi
movq %rax, %rdx
shrq $0xc, %rdx
xorq %rsi, %rdx
subq %rax, %rcx
subq %rdx, %rcx
movq %rdx, %rsi
shlq $0x10, %rsi
xorq %rcx, %rsi
subq %rdx, %rax
subq %rsi, %rax
movq %rsi, %rcx
shrq $0x5, %rcx
xorq %rax, %rcx
subq %rsi, %rdx
subq %rcx, %rdx
movq %rcx, %rdi
shrq $0x3, %rdi
xorq %rdx, %rdi
subq %rcx, %rsi
subq %rdi, %rsi
movq %rdi, %rax
shlq $0xa, %rax
xorq %rsi, %rax
addq %rax, %rdi
subq %rdi, %rcx
shrq $0xf, %rax
xorq %rcx, %rax
retq