#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*/ assert(int /*<<< orphan*/);
char pow(int, int);
int strlen(char *);
int hash(char *str) {
  int tmp = 0;
  assert(str && strlen(str) >= 2);
  for (int i = 0; i < 2; i++)
    tmp += pow(26, i) * (str[i] - 97);
  return tmp;
}


x86 assembly (clang, -O0):
<hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x11(%rbp)
je     1165 <hash+0x35>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
setge  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x2,-0x10(%rbp)
jge    11b9 <hash+0x89>
mov    -0x10(%rbp),%esi
mov    $0x1a,%edi
call   1050 <pow@plt>
movsbl %al,%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x61,%ecx
imul   %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1179 <hash+0x49>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %rdi,%rdi
je     114e <hash+0x1e>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %edi,%edi
cmp    $0x2,%eax
setge  %dil
jmp    1150 <hash+0x20>
xor    %edi,%edi
call   1040 <assert@plt>
mov    $0x1a,%edi
xor    %esi,%esi
call   1050 <pow@plt>
movsbl %al,%eax
movsbl (%rbx),%ebp
add    $0xffffff9f,%ebp
imul   %eax,%ebp
mov    $0x1a,%edi
mov    $0x1,%esi
call   1050 <pow@plt>
movsbl %al,%ecx
movsbl 0x1(%rbx),%eax
add    $0xffffff9f,%eax
imul   %ecx,%eax
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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