#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 */
int fnv1a(char, int);
int strlen(char *);
int hashing4(char str[]) {
  int hash = 571, i, len = strlen(str);
  for (i = 0; i < len; i++) {
    hash = fnv1a(str[i], hash);
    if (hash < 0)
      hash = -hash;
  }
  return hash % 3000;
}


x86 assembly (clang, -O0):
<hashing4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x23b,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1190 <hashing4+0x70>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0xc(%rbp),%esi
movsbl %al,%edi
call   1040 <fnv1a@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    117d <hashing4+0x5d>
xor    %eax,%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1182 <hashing4+0x62>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <hashing4+0x26>
mov    -0xc(%rbp),%eax
mov    $0xbb8,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashing4>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1171 <hashing4+0x51>
mov    %eax,%r15d
mov    $0x23b,%esi
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%edi
call   1040 <fnv1a@plt>
mov    %eax,%esi
neg    %esi
cmovs  %eax,%esi
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <hashing4+0x20>
mov    %esi,%eax
imul   $0x57619f1,%rax,%rax
shr    $0x26,%rax
imul   $0xbb8,%eax,%eax
sub    %eax,%esi
jmp    1176 <hashing4+0x56>
mov    $0x23b,%esi
mov    %esi,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @hashing4(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 571, i32* %3
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
store i32 0, i32* %4
br label %8
8: ; preds = %26, %1
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = load i32, i32* %3
%19 = call i32 @fnv1a(i8 signext %17, i32 %18)
store i32 %19, i32* %3
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %12
%23 = load i32, i32* %3
%24 = sub nsw i32 0, %23
store i32 %24, i32* %3
br label %25
25: ; preds = %22, %12
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %8
29: ; preds = %8
%30 = load i32, i32* %3
%31 = srem i32 %30, 3000
ret i32 %31
}

LLVM IR (-O2):
define i32 @hashing4(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %13, %6 ]
%8 = phi i32 [ 571, %4 ], [ %12, %6 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i32 @fnv1a(i8 signext %10, i32 %8)
%12 = tail call i32 @llvm.abs.i32(i32 %11, i1 true)
%13 = add nuw nsw i64 %7, 1
%14 = icmp eq i64 %13, %5
br i1 %14, label %15, label %6
15: ; preds = %6
%16 = urem i32 %12, 3000
br label %17
17: ; preds = %15, %1
%18 = phi i32 [ 571, %1 ], [ %16, %15 ]
ret i32 %18
}