#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 /*<<< orphan*/ scanf(char *, char *);
int strlen(char *);
long hash(char *word) {
  int start = 42;
  int l;
  int counter;
  scanf("%s", word);
  l = strlen(word);
  for (counter = 0; counter <= l; counter++) {
    l = strlen(word);
    start = start + (word[counter] * (counter + 1));
  }
  return start;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x2a,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec2(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     1199 <hash+0x79>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x14(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
mov    -0x14(%rbp),%edx
add    $0x1,%edx
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <hash+0x36>
movslq -0xc(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xed2(%rip),%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
js     1176 <hash+0x56>
mov    $0x2a,%ebp
mov    $0xffffffffffffffff,%rbx
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <strlen@plt>
movsbl 0x1(%r14,%rbx,1),%ecx
lea    0x2(%rbx),%edx
imul   %ecx,%edx
add    %edx,%ebp
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1150 <hash+0x30>
movslq %ebp,%rax
jmp    117b <hash+0x5b>
mov    $0x2a,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i64 @hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
store i32 42, i32* %3
%6 = load i8*, i8** %2
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %4
store i32 0, i32* %5
br label %10
10: ; preds = %28, %1
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp sle i32 %11, %12
br i1 %13, label %14, label %31
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %4
%17 = load i32, i32* %3
%18 = load i8*, i8** %2
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
%26 = mul nsw i32 %23, %25
%27 = add nsw i32 %17, %26
store i32 %27, i32* %3
br label %28
28: ; preds = %14
%29 = load i32, i32* %5
%30 = add nsw i32 %29, 1
store i32 %30, i32* %5
br label %10
31: ; preds = %10
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
ret i64 %33
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define i64 @hash(i8* %0) {
%2 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %20, label %5
5: ; preds = %1, %5
%6 = phi i64 [ %12, %5 ], [ 0, %1 ]
%7 = phi i32 [ %15, %5 ], [ 42, %1 ]
%8 = tail call i32 @strlen(i8* %0)
%9 = getelementptr inbounds i8, i8* %0, i64 %6
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = add nuw nsw i64 %6, 1
%13 = trunc i64 %12 to i32
%14 = mul nsw i32 %13, %11
%15 = add nsw i32 %14, %7
%16 = sext i32 %8 to i64
%17 = icmp slt i64 %6, %16
br i1 %17, label %5, label %18
18: ; preds = %5
%19 = sext i32 %15 to i64
br label %20
20: ; preds = %18, %1
%21 = phi i64 [ 42, %1 ], [ %19, %18 ]
ret i64 %21
}