#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 */
typedef int u_short;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int saphash(u_short ServType, char *ServName) {
  int hsh, i;
  char name[48];
  bzero(name, 48);
  strncpy(name, ServName, 48);
  ServName = name;
  hsh = 0;
  hsh = hsh * 33 + (ServType & 0xff);
  hsh = hsh * 33 + (ServType >> 8);
  for (i = 0; i < 14; i++) {
    hsh = hsh * 33 + *ServName++;
    ServName++;
  }
  return hsh;
}


x86 assembly (clang, -O0):
<saphash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x30,%esi
call   1040 <bzero@plt>
lea    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x30,%edx
call   1030 <strncpy@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
imul   $0x21,-0x14(%rbp),%eax
mov    -0x4(%rbp),%ecx
and    $0xff,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
imul   $0x21,-0x14(%rbp),%eax
mov    -0x4(%rbp),%ecx
sar    $0x8,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0xe,-0x18(%rbp)
jge    11c5 <saphash+0xa5>
imul   $0x21,-0x14(%rbp),%eax
mov    -0x10(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
movsbl (%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1186 <saphash+0x66>
mov    -0x14(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saphash>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x30,%esi
call   1040 <bzero@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x30,%edx
call   1030 <strncpy@plt>
movzbl %bpl,%eax
mov    %eax,%ecx
shl    $0x5,%ecx
add    %eax,%ecx
sar    $0x8,%ebp
add    %ecx,%ebp
mov    %ebp,%eax
shl    $0x5,%eax
add    %ebp,%eax
movsbl (%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x2(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x4(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x6(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x8(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0xa(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0xc(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0xe(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x10(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x12(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x14(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x16(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%eax
shl    $0x5,%eax
add    %ecx,%eax
movsbl 0x18(%rsp),%ecx
add    %eax,%ecx
mov    %ecx,%edx
shl    $0x5,%edx
add    %ecx,%edx
movsbl 0x1a(%rsp),%eax
add    %edx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @saphash(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [48 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = getelementptr inbounds [48 x i8], [48 x i8]* %7, i64 0, i64 0
%9 = call i32 @bzero(i8* %8, i32 48)
%10 = getelementptr inbounds [48 x i8], [48 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 48)
%13 = getelementptr inbounds [48 x i8], [48 x i8]* %7, i64 0, i64 0
store i8* %13, i8** %4
store i32 0, i32* %5
%14 = load i32, i32* %5
%15 = mul nsw i32 %14, 33
%16 = load i32, i32* %3
%17 = and i32 %16, 255
%18 = add nsw i32 %15, %17
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = mul nsw i32 %19, 33
%21 = load i32, i32* %3
%22 = ashr i32 %21, 8
%23 = add nsw i32 %20, %22
store i32 %23, i32* %5
store i32 0, i32* %6
br label %24
24: ; preds = %37, %2
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 14
br i1 %26, label %27, label %40
27: ; preds = %24
%28 = load i32, i32* %5
%29 = mul nsw i32 %28, 33
%30 = load i8*, i8** %4
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %4
%32 = load i8, i8* %30
%33 = sext i8 %32 to i32
%34 = add nsw i32 %29, %33
store i32 %34, i32* %5
%35 = load i8*, i8** %4
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %4
br label %37
37: ; preds = %27
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %24
40: ; preds = %24
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
define i32 @saphash(i32 %0, i8* %1) {
%3 = alloca [48 x i8]
%4 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 0
%5 = call i32 @bzero(i8* %4, i32 48)
%6 = call i32 @strncpy(i8* %4, i8* %1, i32 48)
%7 = and i32 %0, 255
%8 = mul nuw nsw i32 %7, 33
%9 = ashr i32 %0, 8
%10 = add nsw i32 %8, %9
%11 = mul nsw i32 %10, 33
%12 = load i8, i8* %4
%13 = sext i8 %12 to i32
%14 = add nsw i32 %11, %13
%15 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 2
%16 = mul nsw i32 %14, 33
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
%19 = add nsw i32 %16, %18
%20 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 4
%21 = mul nsw i32 %19, 33
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
%24 = add nsw i32 %21, %23
%25 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 6
%26 = mul nsw i32 %24, 33
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
%29 = add nsw i32 %26, %28
%30 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 8
%31 = mul nsw i32 %29, 33
%32 = load i8, i8* %30
%33 = sext i8 %32 to i32
%34 = add nsw i32 %31, %33
%35 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 10
%36 = mul nsw i32 %34, 33
%37 = load i8, i8* %35
%38 = sext i8 %37 to i32
%39 = add nsw i32 %36, %38
%40 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 12
%41 = mul nsw i32 %39, 33
%42 = load i8, i8* %40
%43 = sext i8 %42 to i32
%44 = add nsw i32 %41, %43
%45 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 14
%46 = mul nsw i32 %44, 33
%47 = load i8, i8* %45
%48 = sext i8 %47 to i32
%49 = add nsw i32 %46, %48
%50 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 16
%51 = mul nsw i32 %49, 33
%52 = load i8, i8* %50
%53 = sext i8 %52 to i32
%54 = add nsw i32 %51, %53
%55 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 18
%56 = mul nsw i32 %54, 33
%57 = load i8, i8* %55
%58 = sext i8 %57 to i32
%59 = add nsw i32 %56, %58
%60 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 20
%61 = mul nsw i32 %59, 33
%62 = load i8, i8* %60
%63 = sext i8 %62 to i32
%64 = add nsw i32 %61, %63
%65 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 22
%66 = mul nsw i32 %64, 33
%67 = load i8, i8* %65
%68 = sext i8 %67 to i32
%69 = add nsw i32 %66, %68
%70 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 24
%71 = mul nsw i32 %69, 33
%72 = load i8, i8* %70
%73 = sext i8 %72 to i32
%74 = add nsw i32 %71, %73
%75 = getelementptr inbounds [48 x i8], [48 x i8]* %3, i64 0, i64 26
%76 = mul nsw i32 %74, 33
%77 = load i8, i8* %75
%78 = sext i8 %77 to i32
%79 = add nsw i32 %76, %78
ret i32 %79
}