#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 ___hash(unsigned char *);
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(size_t);
int /*<<< orphan*/ memcpy(unsigned char *, void const *, size_t);
unsigned long ulong_hash(const void *data, size_t size) {
  unsigned char *strbuf = malloc(size + sizeof(unsigned char));
  memcpy(strbuf, data, size);
  strbuf[size % sizeof(unsigned char)] = 0;
  for (size_t cter = 0; cter < size % sizeof(unsigned char); ++cter) {
    if (!strbuf[cter])
      strbuf[cter] = 73;
  }
  auto ret = ___hash(strbuf);
  free(strbuf);
  return ret;
}


x86 assembly (clang, -O0):
<ulong_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
and    $0x0,%rcx
movb   $0x0,(%rax,%rcx,1)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
and    $0x0,%rcx
cmp    %rcx,%rax
jae    11d3 <ulong_hash+0x93>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11bd <ulong_hash+0x7d>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x49,(%rax,%rcx,1)
jmp    11c2 <ulong_hash+0x82>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    118a <ulong_hash+0x4a>
mov    -0x18(%rbp),%rdi
call   1040 <___hash@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movslq -0x24(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ulong_hash>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0x1(%rsi),%rdi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
call   1040 <___hash@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
movslq %ebp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @ulong_hash(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = add i64 %8, 1
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = load i8*, i8** %3
%13 = load i64, i64* %4
%14 = call i32 @memcpy(i8* %11, i8* %12, i64 %13)
%15 = load i8*, i8** %5
%16 = load i64, i64* %4
%17 = urem i64 %16, 1
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 0, i8* %18
store i64 0, i64* %6
br label %19
19: ; preds = %35, %2
%20 = load i64, i64* %6
%21 = load i64, i64* %4
%22 = urem i64 %21, 1
%23 = icmp ult i64 %20, %22
br i1 %23, label %24, label %38
24: ; preds = %19
%25 = load i8*, i8** %5
%26 = load i64, i64* %6
%27 = getelementptr inbounds i8, i8* %25, i64 %26
%28 = load i8, i8* %27
%29 = icmp ne i8 %28, 0
br i1 %29, label %34, label %30
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = load i64, i64* %6
%33 = getelementptr inbounds i8, i8* %31, i64 %32
store i8 73, i8* %33
br label %34
34: ; preds = %30, %24
br label %35
35: ; preds = %34
%36 = load i64, i64* %6
%37 = add i64 %36, 1
store i64 %37, i64* %6
br label %19
38: ; preds = %19
%39 = load i8*, i8** %5
%40 = call i32 @___hash(i8* %39)
store i32 %40, i32* %7
%41 = load i8*, i8** %5
%42 = call i32 @free(i8* %41)
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
ret i64 %44
}

LLVM IR (-O2):
define i64 @ulong_hash(i8* %0, i64 %1) {
%3 = add i64 %1, 1
%4 = tail call i8* @malloc(i64 %3)
%5 = tail call i32 @memcpy(i8* %4, i8* %0, i64 %1)
store i8 0, i8* %4
%6 = tail call i32 @___hash(i8* %4)
%7 = tail call i32 @free(i8* %4)
%8 = sext i32 %6 to i64
ret i64 %8
}