#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_32(int *, void const *);
int /*<<< orphan*/ memcpy(void *, int *, int);
int hx4_djbx33a_32_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;
  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 * 33 + *p;
    p++;
  }
  hx4_xor_cookie_32(&state, cookie);
  memcpy(out_hash, &state, sizeof(state));
  return (0);
}


x86 assembly (clang, -O0):
<hx4_djbx33a_32_ref>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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)
movl   $0x1505,-0x4c(%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    $0x4,%edi
mov    %rax,(%rsp)
call   1050 <hx4_check_params@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
je     11a8 <hx4_djbx33a_32_ref+0x78>
mov    -0x50(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1202 <hx4_djbx33a_32_ref+0xd2>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    11dc <hx4_djbx33a_32_ref+0xac>
imul   $0x21,-0x4c(%rbp),%eax
mov    -0x40(%rbp),%rcx
add    (%rcx),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x40(%rbp)
jmp    11b0 <hx4_djbx33a_32_ref+0x80>
mov    -0x20(%rbp),%rsi
lea    -0x4c(%rbp),%rdi
call   1030 <hx4_xor_cookie_32@plt>
mov    -0x30(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hx4_djbx33a_32_ref>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%r8
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
mov    %r9,(%rsp)
mov    $0x4,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %r14,%r9
call   1050 <hx4_check_params@plt>
test   %eax,%eax
jne    11b8 <hx4_djbx33a_32_ref+0x88>
lea    (%rbx,%r12,4),%rax
mov    $0x1505,%ecx
cmp    %rbx,%rax
jbe    1192 <hx4_djbx33a_32_ref+0x62>
mov    $0x1505,%edx
mov    %edx,%ecx
nopl   (%rax)
shl    $0x5,%ecx
add    %edx,%ecx
add    (%rbx),%ecx
add    $0x4,%rbx
mov    %ecx,%edx
cmp    %rax,%rbx
jb     1180 <hx4_djbx33a_32_ref+0x50>
mov    %ecx,0x14(%rsp)
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <hx4_xor_cookie_32@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @hx4_djbx33a_32_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 i32
%17 = 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
%18 = load i8*, i8** %8
%19 = bitcast i8* %18 to i32*
%20 = load i64, i64* %9
%21 = getelementptr inbounds i32, i32* %19, i64 %20
store i32* %21, i32** %15
store i32 5381, i32* %16
%22 = load i8*, i8** %8
%23 = load i64, i64* %9
%24 = load i8*, i8** %10
%25 = load i64, i64* %11
%26 = load i8*, i8** %12
%27 = load i64, i64* %13
%28 = call i32 @hx4_check_params(i32 4, i8* %22, i64 %23, i8* %24, i64 %25, i8* %26, i64 %27)
store i32 %28, i32* %17
%29 = load i32, i32* %17
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %6
%32 = load i32, i32* %17
store i32 %32, i32* %7
br label %53
33: ; preds = %6
%34 = load i8*, i8** %8
%35 = bitcast i8* %34 to i32*
store i32* %35, i32** %14
br label %36
36: ; preds = %40, %33
%37 = load i32*, i32** %14
%38 = load i32*, i32** %15
%39 = icmp ult i32* %37, %38
br i1 %39, label %40, label %48
40: ; preds = %36
%41 = load i32, i32* %16
%42 = mul nsw i32 %41, 33
%43 = load i32*, i32** %14
%44 = load i32, i32* %43
%45 = add nsw i32 %42, %44
store i32 %45, i32* %16
%46 = load i32*, i32** %14
%47 = getelementptr inbounds i32, i32* %46, i32 1
store i32* %47, i32** %14
br label %36
48: ; preds = %36
%49 = load i8*, i8** %10
%50 = call i32 @hx4_xor_cookie_32(i32* %16, i8* %49)
%51 = load i8*, i8** %12
%52 = call i32 @memcpy(i8* %51, i32* %16, i32 4)
store i32 0, i32* %7
br label %53
53: ; preds = %48, %31
%54 = load i32, i32* %7
ret i32 %54
}

LLVM IR (-O2):
define i32 @hx4_djbx33a_32_ref(i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5) {
%7 = alloca i32
%8 = bitcast i8* %0 to i32*
%9 = getelementptr inbounds i32, i32* %8, i64 %1
%10 = bitcast i32* %7 to i8*
%11 = tail call i32 @hx4_check_params(i32 4, i8* %0, i64 %1, i8* %2, i64 %3, i8* %4, i64 %5)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %6
%14 = icmp ugt i32* %9, %8
br i1 %14, label %15, label %23
15: ; preds = %13, %15
%16 = phi i32* [ %21, %15 ], [ %8, %13 ]
%17 = phi i32 [ %20, %15 ], [ 5381, %13 ]
%18 = mul nsw i32 %17, 33
%19 = load i32, i32* %16
%20 = add nsw i32 %18, %19
%21 = getelementptr inbounds i32, i32* %16, i64 1
%22 = icmp ult i32* %21, %9
br i1 %22, label %15, label %23
23: ; preds = %15, %13
%24 = phi i32 [ 5381, %13 ], [ %20, %15 ]
store i32 %24, i32* %7
%25 = call i32 @hx4_xor_cookie_32(i32* %7, i8* %2)
%26 = call i32 @memcpy(i8* %4, i32* %7, i32 4)
br label %27
27: ; preds = %6, %23
%28 = phi i32 [ 0, %23 ], [ %11, %6 ]
ret i32 %28
}