#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 */
unsigned int hashnat(int *, unsigned int);
char pow(unsigned int const, unsigned int);
unsigned int hashstring(void *key, unsigned int buckets) {
  char *c = key;
  int key_n = 0;
  unsigned const int base = 128;
  unsigned int i;
  for (i = 0; c[i] != '\0'; i++) {
    key_n += c[i] * pow(base, i);
  }
  return hashnat(&key_n, buckets);
}


x86 assembly (clang, -O0):
<hashstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x80,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     119a <hashstring+0x7a>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%esi
mov    $0x80,%edi
call   1040 <pow@plt>
mov    %al,%cl
mov    -0x28(%rbp),%eax
movsbl %cl,%ecx
imul   %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    114c <hashstring+0x2c>
mov    -0xc(%rbp),%esi
lea    -0x1c(%rbp),%rdi
call   1030 <hashnat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashstring>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    (%rdi),%al
test   %al,%al
je     1167 <hashstring+0x47>
mov    %rdi,%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl %al,%r12d
mov    $0x80,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
movsbl %al,%eax
imul   %r12d,%eax
add    %eax,%ebx
add    $0x1,%ebp
movzbl (%r15,%rbp,1),%eax
test   %al,%al
jne    1140 <hashstring+0x20>
jmp    1169 <hashstring+0x49>
xor    %ebx,%ebx
mov    %ebx,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    %r14d,%esi
call   1030 <hashnat@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hashstring(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
store i32 0, i32* %6
store i32 128, i32* %7
store i32 0, i32* %8
br label %10
10: ; preds = %31, %2
%11 = load i8*, i8** %5
%12 = load i32, i32* %8
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %10
%19 = load i8*, i8** %5
%20 = load i32, i32* %8
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i32, i32* %8
%26 = call signext i8 @pow(i32 128, i32 %25)
%27 = sext i8 %26 to i32
%28 = mul nsw i32 %24, %27
%29 = load i32, i32* %6
%30 = add nsw i32 %29, %28
store i32 %30, i32* %6
br label %31
31: ; preds = %18
%32 = load i32, i32* %8
%33 = add i32 %32, 1
store i32 %33, i32* %8
br label %10
34: ; preds = %10
%35 = load i32, i32* %4
%36 = call i32 @hashnat(i32* %6, i32 %35)
ret i32 %36
}

LLVM IR (-O2):
define i32 @hashstring(i8* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %2, %7
%8 = phi i8 [ %19, %7 ], [ %5, %2 ]
%9 = phi i32 [ %16, %7 ], [ 0, %2 ]
%10 = phi i32 [ %15, %7 ], [ 0, %2 ]
%11 = sext i8 %8 to i32
%12 = tail call signext i8 @pow(i32 128, i32 %9)
%13 = sext i8 %12 to i32
%14 = mul nsw i32 %13, %11
%15 = add nsw i32 %14, %10
%16 = add i32 %9, 1
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %7
21: ; preds = %7, %2
%22 = phi i32 [ 0, %2 ], [ %15, %7 ]
store i32 %22, i32* %3
%23 = call i32 @hashnat(i32* %3, i32 %1)
ret i32 %23
}