#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 strlen(char *);
int hash_t(char *s, int t) {
  unsigned int i, j = 0;
  for (i = 0; i < strlen(s); i++)
    j = (j * 256 + s[i]) % t;
  return j;
}


x86 assembly (clang, -O0):
<hash_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jae    1172 <hash_t+0x62>
mov    -0x14(%rbp),%eax
shl    $0x8,%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%edx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <hash_t+0x1d>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hash_t>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
je     1156 <hash_t+0x46>
xor    %ebx,%ebx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
shl    $0x8,%ebp
movsbl (%r15,%rbx,1),%eax
add    %ebp,%eax
xor    %edx,%edx
div    %r14d
add    $0x1,%rbx
mov    %edx,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%rbx
jb     1130 <hash_t+0x20>
jmp    1158 <hash_t+0x48>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hash_t(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %24, %2
%8 = load i32, i32* %5
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = icmp ult i32 %8, %10
br i1 %11, label %12, label %27
12: ; preds = %7
%13 = load i32, i32* %6
%14 = mul i32 %13, 256
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = add i32 %14, %20
%22 = load i32, i32* %4
%23 = urem i32 %21, %22
store i32 %23, i32* %6
br label %24
24: ; preds = %12
%25 = load i32, i32* %5
%26 = add i32 %25, 1
store i32 %26, i32* %5
br label %7
27: ; preds = %7
%28 = load i32, i32* %6
ret i32 %28
}

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