#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 strlen(char *);
unsigned int BKDRHash(char *str) {
  unsigned int seed = 131;
  unsigned int hash = 0;
  int i = 0;
  while (i < strlen(str)) {
    hash = hash * seed + *str++;
  }
  return (hash % 9973);
}


x86 assembly (clang, -O0):
<BKDRHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x83,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    1170 <BKDRHash+0x60>
mov    -0x10(%rbp),%eax
imul   -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
movsbl (%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
jmp    1131 <BKDRHash+0x21>
mov    -0x10(%rbp),%eax
mov    $0x26f5,%ecx
xor    %edx,%edx
div    %ecx
mov    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<BKDRHash>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    1166 <BKDRHash+0x56>
add    $0x1,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
imul   $0x83,%ebx,%eax
movsbl -0x1(%r14),%ebx
add    %eax,%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
add    $0x1,%r14
test   %eax,%eax
jg     1130 <BKDRHash+0x20>
mov    %ebx,%eax
mov    $0xd2487055,%ecx
imul   %rax,%rcx
shr    $0x2d,%rcx
imul   $0x26f5,%ecx,%eax
sub    %eax,%ebx
jmp    1168 <BKDRHash+0x58>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @BKDRHash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 131, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %11, %1
%7 = load i32, i32* %5
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
%10 = icmp slt i32 %7, %9
br i1 %10, label %11, label %20
11: ; preds = %6
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = mul i32 %12, %13
%15 = load i8*, i8** %2
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %2
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
%19 = add i32 %14, %18
store i32 %19, i32* %4
br label %6
20: ; preds = %6
%21 = load i32, i32* %4
%22 = urem i32 %21, 9973
ret i32 %22
}

LLVM IR (-O2):
define i32 @BKDRHash(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %16
4: ; preds = %1, %4
%5 = phi i8* [ %8, %4 ], [ %0, %1 ]
%6 = phi i32 [ %11, %4 ], [ 0, %1 ]
%7 = mul i32 %6, 131
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = load i8, i8* %5
%10 = sext i8 %9 to i32
%11 = add i32 %7, %10
%12 = tail call i32 @strlen(i8* %8)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %4, label %14
14: ; preds = %4
%15 = urem i32 %11, 9973
br label %16
16: ; preds = %14, %1
%17 = phi i32 [ 0, %1 ], [ %15, %14 ]
ret i32 %17
}