#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 unsigned int uint32_t;
typedef unsigned int int32_t;

/* Variables and functions */
int /*<<< orphan*/ assert(char *);
unsigned int strings_length(char *);
int32_t strings_hash(char *string) {
  assert(string);
  int32_t ret = 0;
  unsigned int length = strings_length(string);
  for (unsigned int k = 0; k < length; k++) {
    ret ^= ((uint32_t)string[k]) << (k % 24);
  }
  return ret;
}


x86 assembly (clang, -O0):
<strings_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strings_length@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    1190 <strings_hash+0x70>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x18,%ecx
xor    %edx,%edx
div    %ecx
mov    -0x18(%rbp),%eax
mov    %edx,%ecx
shl    %cl,%eax
xor    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <strings_hash+0x2f>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strings_hash>:
push   %rbx
mov    %rdi,%rbx
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <strings_length@plt>
test   %eax,%eax
je     1146 <strings_hash+0x26>
mov    %eax,%r8d
cmp    $0x8,%eax
jae    114a <strings_hash+0x2a>
xor    %esi,%esi
xor    %eax,%eax
jmp    12e7 <strings_hash+0x1c7>
xor    %eax,%eax
pop    %rbx
ret
mov    %r8d,%esi
and    $0xfffffff8,%esi
movdqa 0xea8(%rip),%xmm3
pxor   %xmm13,%xmm13
xor    %eax,%eax
movdqa 0xea8(%rip),%xmm8
movdqa 0xeaf(%rip),%xmm11
movdqa 0xeb6(%rip),%xmm12
movdqa 0xebd(%rip),%xmm10
movdqa 0xec4(%rip),%xmm9
pxor   %xmm4,%xmm4
movdqa %xmm3,%xmm1
paddd  %xmm8,%xmm1
movd   (%rbx,%rax,1),%xmm6
punpcklbw %xmm6,%xmm6
punpcklwd %xmm6,%xmm6
movd   0x4(%rbx,%rax,1),%xmm7
punpcklbw %xmm7,%xmm7
punpcklwd %xmm7,%xmm7
psrad  $0x18,%xmm6
psrad  $0x18,%xmm7
movdqa %xmm3,%xmm2
pmuludq %xmm11,%xmm2
pshufd $0xed,%xmm2,%xmm2
pshufd $0xf5,%xmm3,%xmm5
pmuludq %xmm11,%xmm5
pshufd $0xed,%xmm5,%xmm5
punpckldq %xmm5,%xmm2
psrld  $0x4,%xmm2
pshufd $0xf5,%xmm2,%xmm5
pmuludq %xmm12,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm12,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm5,%xmm2
movdqa %xmm3,%xmm5
psubd  %xmm2,%xmm5
movdqa %xmm1,%xmm2
pmuludq %xmm11,%xmm2
pshufd $0xed,%xmm2,%xmm2
pshufd $0xf5,%xmm1,%xmm0
pmuludq %xmm11,%xmm0
pshufd $0xed,%xmm0,%xmm0
punpckldq %xmm0,%xmm2
psrld  $0x4,%xmm2
pshufd $0xf5,%xmm2,%xmm0
pmuludq %xmm12,%xmm2
pshufd $0xe8,%xmm2,%xmm2
pmuludq %xmm12,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm2
psubd  %xmm2,%xmm1
pslld  $0x17,%xmm5
paddd  %xmm10,%xmm5
cvttps2dq %xmm5,%xmm0
pshufd $0xf5,%xmm6,%xmm2
pmuludq %xmm0,%xmm6
pshufd $0xe8,%xmm6,%xmm5
pshufd $0xf5,%xmm0,%xmm0
pmuludq %xmm2,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm5
pxor   %xmm5,%xmm13
pslld  $0x17,%xmm1
paddd  %xmm10,%xmm1
cvttps2dq %xmm1,%xmm0
pshufd $0xf5,%xmm7,%xmm1
pmuludq %xmm0,%xmm7
pshufd $0xe8,%xmm7,%xmm2
pshufd $0xf5,%xmm0,%xmm0
pmuludq %xmm1,%xmm0
pshufd $0xe8,%xmm0,%xmm0
punpckldq %xmm0,%xmm2
pxor   %xmm2,%xmm4
add    $0x8,%rax
paddd  %xmm9,%xmm3
cmp    %rax,%rsi
jne    1190 <strings_hash+0x70>
pxor   %xmm13,%xmm4
pshufd $0xee,%xmm4,%xmm0
pxor   %xmm4,%xmm0
pshufd $0x55,%xmm0,%xmm1
pxor   %xmm0,%xmm1
movd   %xmm1,%eax
cmp    %r8,%rsi
je     1315 <strings_hash+0x1f5>
mov    $0xaaaaaaab,%edi
nopl   0x0(%rax)
mov    %esi,%ecx
imul   %rdi,%rcx
shr    $0x24,%rcx
shl    $0x3,%ecx
lea    (%rcx,%rcx,2),%edx
mov    %esi,%ecx
sub    %edx,%ecx
movsbl (%rbx,%rsi,1),%edx
shl    %cl,%edx
xor    %edx,%eax
add    $0x1,%rsi
cmp    %rsi,%r8
jne    12f0 <strings_hash+0x1d0>
pop    %rbx
ret

LLVM IR (-O0):
define i32 @strings_hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @assert(i8* %6)
store i32 0, i32* %3
%8 = load i8*, i8** %2
%9 = call i32 @strings_length(i8* %8)
store i32 %9, i32* %4
store i32 0, i32* %5
br label %10
10: ; preds = %26, %1
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp ult i32 %11, %12
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* %5
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = load i32, i32* %5
%22 = urem i32 %21, 24
%23 = shl i32 %20, %22
%24 = load i32, i32* %3
%25 = xor i32 %24, %23
store i32 %25, i32* %3
br label %26
26: ; preds = %14
%27 = load i32, i32* %5
%28 = add i32 %27, 1
store i32 %28, i32* %5
br label %10
29: ; preds = %10
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @strings_hash(i8* %0) {
%2 = tail call i32 @assert(i8* %0)
%3 = tail call i32 @strings_length(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %40, label %5
5: ; preds = %1
%6 = zext i32 %3 to i64
%7 = icmp ult i32 %3, 8
br i1 %7, label %37, label %8
8: ; preds = %5
%9 = and i64 %6, 4294967288
br label %10
10: ; preds = %10, %8
%11 = phi i64 [ 0, %8 ], [ %30, %10 ]
%12 = phi <4 x i32> [ zeroinitializer, %8 ], [ %28, %10 ]
%13 = phi <4 x i32> [ zeroinitializer, %8 ], [ %29, %10 ]
%14 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %8 ], [ %31, %10 ]
%15 = add <4 x i32> %14, <i32 4, i32 4, i32 4, i32 4>
%16 = getelementptr inbounds i8, i8* %0, i64 %11
%17 = bitcast i8* %16 to <4 x i8>*
%18 = load <4 x i8>, <4 x i8>* %17
%19 = getelementptr inbounds i8, i8* %16, i64 4
%20 = bitcast i8* %19 to <4 x i8>*
%21 = load <4 x i8>, <4 x i8>* %20
%22 = sext <4 x i8> %18 to <4 x i32>
%23 = sext <4 x i8> %21 to <4 x i32>
%24 = urem <4 x i32> %14, <i32 24, i32 24, i32 24, i32 24>
%25 = urem <4 x i32> %15, <i32 24, i32 24, i32 24, i32 24>
%26 = shl nsw <4 x i32> %22, %24
%27 = shl nsw <4 x i32> %23, %25
%28 = xor <4 x i32> %26, %12
%29 = xor <4 x i32> %27, %13
%30 = add nuw i64 %11, 8
%31 = add <4 x i32> %14, <i32 8, i32 8, i32 8, i32 8>
%32 = icmp eq i64 %30, %9
br i1 %32, label %33, label %10
33: ; preds = %10
%34 = xor <4 x i32> %29, %28
%35 = call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %34)
%36 = icmp eq i64 %9, %6
br i1 %36, label %40, label %37
37: ; preds = %5, %33
%38 = phi i64 [ 0, %5 ], [ %9, %33 ]
%39 = phi i32 [ 0, %5 ], [ %35, %33 ]
br label %42
40: ; preds = %42, %33, %1
%41 = phi i32 [ 0, %1 ], [ %35, %33 ], [ %51, %42 ]
ret i32 %41
42: ; preds = %37, %42
%43 = phi i64 [ %52, %42 ], [ %38, %37 ]
%44 = phi i32 [ %51, %42 ], [ %39, %37 ]
%45 = getelementptr inbounds i8, i8* %0, i64 %43
%46 = load i8, i8* %45
%47 = sext i8 %46 to i32
%48 = trunc i64 %43 to i32
%49 = urem i32 %48, 24
%50 = shl nsw i32 %47, %49
%51 = xor i32 %50, %44
%52 = add nuw nsw i64 %43, 1
%53 = icmp eq i64 %52, %6
br i1 %53, label %40, label %42
}