#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 const *);
unsigned int __str2id(int hash_sz, const char *name) {
  static unsigned int short hi2 = 0;
  unsigned short low2 = 0;
  int i = 0;
  unsigned int gid = 0;
  for (i = 0; i < strlen(name); i++) {
    low2 += (unsigned short)name[i];
  }
  hi2 %= hash_sz;
  gid = ((hi2 + 1) << 16 | low2);
  return gid;
}


x86 assembly (clang, -O0):
<__str2id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movw   $0x0,-0x12(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    117d <__str2id+0x6d>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movzwl %ax,%ecx
movzwl -0x12(%rbp),%eax
add    %ecx,%eax
mov    %ax,-0x12(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <__str2id+0x2a>
mov    -0x4(%rbp),%ecx
movzwl 0x2ea3(%rip),%eax
cltd
idiv   %ecx
mov    %dx,%ax
mov    %ax,0x2e96(%rip)
movzwl 0x2e8f(%rip),%eax
add    $0x1,%eax
shl    $0x10,%eax
movzwl -0x12(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__str2id>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1155 <__str2id+0x45>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl (%r14,%rbx,1),%eax
add    %ebp,%eax
add    $0x1,%rbx
movzwl %ax,%ebp
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1130 <__str2id+0x20>
or     $0x10000,%ebp
jmp    115a <__str2id+0x4a>
mov    $0x10000,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__str2id.hi2 = internal global i16 0
define i32 @__str2id(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
store i16 0, i16* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %6
br label %8
8: ; preds = %25, %2
%9 = load i32, i32* %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %28
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i16
%20 = zext i16 %19 to i32
%21 = load i16, i16* %5
%22 = zext i16 %21 to i32
%23 = add nsw i32 %22, %20
%24 = trunc i32 %23 to i16
store i16 %24, i16* %5
br label %25
25: ; preds = %13
%26 = load i32, i32* %6
%27 = add nsw i32 %26, 1
store i32 %27, i32* %6
br label %8
28: ; preds = %8
%29 = load i32, i32* %3
%30 = load i16, i16* @__str2id.hi2
%31 = zext i16 %30 to i32
%32 = srem i32 %31, %29
%33 = trunc i32 %32 to i16
store i16 %33, i16* @__str2id.hi2
%34 = load i16, i16* @__str2id.hi2
%35 = zext i16 %34 to i32
%36 = add nsw i32 %35, 1
%37 = shl i32 %36, 16
%38 = load i16, i16* %5
%39 = zext i16 %38 to i32
%40 = or i32 %37, %39
store i32 %40, i32* %7
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
define i32 @__str2id(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %2, %5
%6 = phi i64 [ %12, %5 ], [ 0, %2 ]
%7 = phi i32 [ %13, %5 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %1, i64 %6
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = add nsw i32 %7, %10
%12 = add nuw nsw i64 %6, 1
%13 = and i32 %11, 65535
%14 = tail call i32 @strlen(i8* %1)
%15 = sext i32 %14 to i64
%16 = icmp slt i64 %12, %15
br i1 %16, label %5, label %17
17: ; preds = %5
%18 = or i32 %13, 65536
br label %19
19: ; preds = %17, %2
%20 = phi i32 [ 65536, %2 ], [ %18, %17 ]
ret i32 %20
}