#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 *);
char pow(unsigned int const, unsigned int);
unsigned int hashstring(void *key) {
  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);
}


x86 assembly (clang, -O0):
<hashstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x80,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1197 <hashstring+0x77>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%esi
mov    $0x80,%edi
call   1040 <pow@plt>
mov    %al,%cl
mov    -0x20(%rbp),%eax
movsbl %cl,%ecx
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1149 <hashstring+0x29>
lea    -0x14(%rbp),%rdi
call   1030 <hashnat@plt>
add    $0x20,%rsp
pop    %rbp
ret

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

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

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