#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 int uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ state;

/* Variables and functions */
int hx4_check_params(int, void const *, size_t, void const *, size_t, void *,
                     size_t);
int /*<<< orphan*/ hx4_xor_cookie_128(int *, void const *);
int /*<<< orphan*/ memcpy(void *, int *, int);
int hx4_x4djbx33a_128_ref(const void *buffer, size_t buffer_size,
                          const void *cookie, size_t cookie_sz, void *out_hash,
                          size_t out_hash_size) {
  const uint8_t *p;
  const uint8_t *const buffer_end = (uint8_t *)buffer + buffer_size;
  uint32_t state[] = {5381, 5381, 5381, 5381};
  int state_i = 0;
  int rc;
  rc = hx4_check_params(sizeof(state), buffer, buffer_size, cookie, cookie_sz,
                        out_hash, out_hash_size);
  if (rc != (0)) {
    return rc;
  }
  p = buffer;
  while (p < buffer_end) {
    state[state_i] = state[state_i] * 33 + *p;
    p++;
    state_i = (state_i + 1) % 4;
  }
  hx4_xor_cookie_128(state, cookie);
  memcpy(out_hash, state, sizeof(state));
  return (0);
}


x86 assembly (clang, -O0):
<hx4_x4djbx33a_128_ref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    0xe96(%rip),%rax
mov    %rax,-0x60(%rbp)
mov    0xe93(%rip),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
mov    -0x38(%rbp),%rax
mov    $0x10,%edi
mov    %rax,(%rsp)
call   1050 <hx4_check_params@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
je     11be <hx4_x4djbx33a_128_ref+0x8e>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1233 <hx4_x4djbx33a_128_ref+0x103>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    120d <hx4_x4djbx33a_128_ref+0xdd>
movslq -0x64(%rbp),%rax
imul   $0x21,-0x60(%rbp,%rax,4),%ecx
mov    -0x40(%rbp),%rax
add    (%rax),%ecx
movslq -0x64(%rbp),%rax
mov    %ecx,-0x60(%rbp,%rax,4)
mov    -0x40(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x40(%rbp)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %edx,-0x64(%rbp)
jmp    11c6 <hx4_x4djbx33a_128_ref+0x96>
lea    -0x60(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <hx4_xor_cookie_128@plt>
mov    -0x30(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hx4_x4djbx33a_128_ref>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r14
mov    %rcx,%r8
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
movaps 0xeaf(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %r9,(%rsp)
mov    $0x10,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r9
call   1050 <hx4_check_params@plt>
test   %eax,%eax
jne    11f4 <hx4_x4djbx33a_128_ref+0xc4>
lea    (%rbx,%r12,4),%rax
cmp    %rbx,%rax
jbe    11d2 <hx4_x4djbx33a_128_ref+0xa2>
mov    $0x2b5a5,%ecx
add    (%rbx),%ecx
mov    %ecx,0x10(%rsp)
add    $0x4,%rbx
cmp    %rbx,%rax
jbe    11d2 <hx4_x4djbx33a_128_ref+0xa2>
mov    $0x1,%ecx
nopw   0x0(%rax,%rax,1)
movslq %ecx,%rcx
mov    0x10(%rsp,%rcx,4),%edx
mov    %edx,%esi
shl    $0x5,%esi
add    %edx,%esi
add    (%rbx),%esi
mov    %esi,0x10(%rsp,%rcx,4)
add    $0x4,%rbx
lea    0x1(%rcx),%edx
lea    0x4(%rcx),%esi
test   %edx,%edx
cmovns %edx,%esi
and    $0xfffffffc,%esi
neg    %esi
add    %esi,%ecx
add    $0x1,%ecx
cmp    %rax,%rbx
jb     11a0 <hx4_x4djbx33a_128_ref+0x70>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <hx4_xor_cookie_128@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.hx4_x4djbx33a_128_ref.state = [4 x i32] [i32 5381, i32 5381, i32 5381, i32 5381]
define i32 @hx4_x4djbx33a_128_ref(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5) {
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca [4 x i32]
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %8
store i64 %1, i64* %9
store i8* %2, i8** %10
store i64 %3, i64* %11
store i8* %4, i8** %12
store i64 %5, i64* %13
%19 = load i8*, i8** %8
%20 = bitcast i8* %19 to i32*
%21 = load i64, i64* %9
%22 = getelementptr inbounds i32, i32* %20, i64 %21
store i32* %22, i32** %15
%23 = bitcast [4 x i32]* %16 to i8*
store i32 0, i32* %17
%24 = load i8*, i8** %8
%25 = load i64, i64* %9
%26 = load i8*, i8** %10
%27 = load i64, i64* %11
%28 = load i8*, i8** %12
%29 = load i64, i64* %13
%30 = call i32 @hx4_check_params(i32 16, i8* %24, i64 %25, i8* %26, i64 %27, i8* %28, i64 %29)
store i32 %30, i32* %18
%31 = load i32, i32* %18
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %6
%34 = load i32, i32* %18
store i32 %34, i32* %7
br label %66
35: ; preds = %6
%36 = load i8*, i8** %8
%37 = bitcast i8* %36 to i32*
store i32* %37, i32** %14
br label %38
38: ; preds = %42, %35
%39 = load i32*, i32** %14
%40 = load i32*, i32** %15
%41 = icmp ult i32* %39, %40
br i1 %41, label %42, label %59
42: ; preds = %38
%43 = load i32, i32* %17
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = mul nsw i32 %46, 33
%48 = load i32*, i32** %14
%49 = load i32, i32* %48
%50 = add nsw i32 %47, %49
%51 = load i32, i32* %17
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 %52
store i32 %50, i32* %53
%54 = load i32*, i32** %14
%55 = getelementptr inbounds i32, i32* %54, i32 1
store i32* %55, i32** %14
%56 = load i32, i32* %17
%57 = add nsw i32 %56, 1
%58 = srem i32 %57, 4
store i32 %58, i32* %17
br label %38
59: ; preds = %38
%60 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
%61 = load i8*, i8** %10
%62 = call i32 @hx4_xor_cookie_128(i32* %60, i8* %61)
%63 = load i8*, i8** %12
%64 = getelementptr inbounds [4 x i32], [4 x i32]* %16, i64 0, i64 0
%65 = call i32 @memcpy(i8* %63, i32* %64, i32 16)
store i32 0, i32* %7
br label %66
66: ; preds = %59, %33
%67 = load i32, i32* %7
ret i32 %67
}

LLVM IR (-O2):
@__const.hx4_x4djbx33a_128_ref.state = [4 x i32] [i32 5381, i32 5381, i32 5381, i32 5381]
define i32 @hx4_x4djbx33a_128_ref(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5) {
%7 = alloca [4 x i32]
%8 = bitcast i8* %0 to i32*
%9 = getelementptr inbounds i32, i32* %8, i64 %1
%10 = bitcast [4 x i32]* %7 to i8*
%11 = tail call i32 @hx4_check_params(i32 16, i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %41
13: ; preds = %6
%14 = icmp ugt i32* %9, %8
br i1 %14, label %15, label %37
15: ; preds = %13
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
%17 = load i32, i32* %8
%18 = add nsw i32 %17, 177573
store i32 %18, i32* %16
%19 = getelementptr inbounds i8, i8* %0, i64 4
%20 = bitcast i8* %19 to i32*
%21 = icmp ugt i32* %9, %20
br i1 %21, label %22, label %37
22: ; preds = %15, %22
%23 = phi i32 [ %35, %22 ], [ 1, %15 ]
%24 = phi i32* [ %33, %22 ], [ %20, %15 ]
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = sext i32 %23 to i64
%29 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 %28
%30 = mul nsw i32 %27, 33
%31 = load i32, i32* %24
%32 = add nsw i32 %30, %31
store i32 %32, i32* %29
%33 = getelementptr inbounds i32, i32* %24, i64 1
%34 = add nsw i32 %23, 1
%35 = srem i32 %34, 4
%36 = icmp ult i32* %33, %9
br i1 %36, label %22, label %37
37: ; preds = %22, %15, %13
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %7, i64 0, i64 0
%39 = call i32 @hx4_xor_cookie_128(i32* %38, i8* %2)
%40 = call i32 @memcpy(i8* %4, i32* %38, i32 16)
br label %41
41: ; preds = %6, %37
%42 = phi i32 [ 0, %37 ], [ %11, %6 ]
ret i32 %42
}