#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*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
size_t strlen(char const *);
char *path_hash(const char *path) {
  static char hash[16];
  size_t n = strlen(path);
  if (n <= 16) {
    memcpy(hash, path, n);
    memset(hash + n, 0, 16 - n);
  } else {
    memcpy(hash, path + (n - 16), 16);
  }
  return hash;
}


x86 assembly (clang, -O0):
<path_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x10,-0x10(%rbp)
ja     118c <path_hash+0x5c>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0x2eeb(%rip),%rdi
call   1050 <memcpy@plt>
lea    0x2edf(%rip),%rdi
add    -0x10(%rbp),%rdi
mov    $0x10,%eax
sub    -0x10(%rbp),%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
jmp    11ac <path_hash+0x7c>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
sub    $0x10,%rax
add    %rax,%rsi
lea    0x2eae(%rip),%rdi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x2e9d(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<path_hash>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
mov    %rax,%rbx
cmp    $0x10,%rax
ja     1170 <path_hash+0x40>
lea    0x2f03(%rip),%r15
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
add    %rbx,%r15
mov    $0x10,%edx
sub    %ebx,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
jmp    1189 <path_hash+0x59>
lea    (%rbx,%r14,1),%rsi
add    $0xfffffffffffffff0,%rsi
lea    0x2ed1(%rip),%rdi
mov    $0x10,%edx
call   1050 <memcpy@plt>
lea    0x2ec0(%rip),%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@path_hash.hash = internal global [16 x i8] zeroinitializer
define i8* @path_hash(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp ule i64 %6, 16
br i1 %7, label %8, label %19
8: ; preds = %1
%9 = load i8*, i8** %2
%10 = load i64, i64* %3
%11 = trunc i64 %10 to i32
%12 = call i32 @memcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @path_hash.hash, i64 0, i64 0), i8* %9, i32 %11)
%13 = load i64, i64* %3
%14 = getelementptr inbounds i8, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @path_hash.hash, i64 0, i64 0), i64 %13
%15 = load i64, i64* %3
%16 = sub i64 16, %15
%17 = trunc i64 %16 to i32
%18 = call i32 @memset(i8* %14, i32 0, i32 %17)
br label %25
19: ; preds = %1
%20 = load i8*, i8** %2
%21 = load i64, i64* %3
%22 = sub i64 %21, 16
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = call i32 @memcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @path_hash.hash, i64 0, i64 0), i8* %23, i32 16)
br label %25
25: ; preds = %19, %8
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @path_hash.hash, i64 0, i64 0)
}

LLVM IR (-O2):
@path_hash.hash = internal global [16 x i8] zeroinitializer
define i8* @path_hash(i8* %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = icmp ult i64 %2, 17
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = trunc i64 %2 to i32
%6 = tail call i32 @memcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @path_hash.hash, i64 0, i64 0), i8* %0, i32 %5)
%7 = getelementptr inbounds [16 x i8], [16 x i8]* @path_hash.hash, i64 0, i64 %2
%8 = sub nuw nsw i32 16, %5
%9 = tail call i32 @memset(i8* %7, i32 0, i32 %8)
br label %14
10: ; preds = %1
%11 = add i64 %2, -16
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = tail call i32 @memcpy(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @path_hash.hash, i64 0, i64 0), i8* %12, i32 16)
br label %14
14: ; preds = %10, %4
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @path_hash.hash, i64 0, i64 0)
}