#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 /*<<< orphan*/ dir;

/* Variables and functions */
unsigned int DJBHash(char *, int);
int PATH_MAX;
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char *, char);
unsigned int gen_dir_hash(const char *path) {
  char dir[PATH_MAX], *base;
  int len;
  strncpy(dir, path, sizeof(dir));
  dir[sizeof(dir) - 1] = '\0';
  base = strrchr(dir, '/');
  if (!base)
    base = strrchr(dir, '\\');
  if (base) {
    *base = '\0';
    len = base - dir;
  } else
    return 0;
  return DJBHash(dir, len);
}


x86 assembly (clang, -O0):
<gen_dir_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x38(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,(%rdi,%rax,1)
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b2 <gen_dir_hash+0x82>
mov    -0x40(%rbp),%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d7 <gen_dir_hash+0xa7>
mov    -0x40(%rbp),%rcx
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x2c(%rbp)
jmp    11ea <gen_dir_hash+0xba>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
jmp    1200 <gen_dir_hash+0xd0>
mov    -0x40(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <DJBHash@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_dir_hash>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    %rdi,%rsi
mov    0x2eaf(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r14,%rbx,1)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
jne    118a <gen_dir_hash+0x5a>
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     11a2 <gen_dir_hash+0x72>
movb   $0x0,(%rax)
sub    %ebx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <DJBHash@plt>
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
xor    %eax,%eax
jmp    1199 <gen_dir_hash+0x69>

LLVM IR (-O0):
@PATH_MAX = global i32 0
define i32 @gen_dir_hash(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %4
%12 = alloca i8, i64 %10
store i64 %10, i64* %5
%13 = load i8*, i8** %3
%14 = trunc i64 %10 to i32
%15 = call i32 @strncpy(i8* %12, i8* %13, i32 %14)
%16 = sub i64 %10, 1
%17 = getelementptr inbounds i8, i8* %12, i64 %16
store i8 0, i8* %17
%18 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %18, i8** %6
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %1
%22 = call i8* @strrchr(i8* %12, i8 signext 92)
store i8* %22, i8** %6
br label %23
23: ; preds = %21, %1
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i8*, i8** %6
store i8 0, i8* %27
%28 = load i8*, i8** %6
%29 = ptrtoint i8* %28 to i64
%30 = ptrtoint i8* %12 to i64
%31 = sub i64 %29, %30
%32 = trunc i64 %31 to i32
store i32 %32, i32* %7
br label %34
33: ; preds = %23
store i32 0, i32* %2
store i32 1, i32* %8
br label %37
34: ; preds = %26
%35 = load i32, i32* %7
%36 = call i32 @DJBHash(i8* %12, i32 %35)
store i32 %36, i32* %2
store i32 1, i32* %8
br label %37
37: ; preds = %34, %33
%38 = load i8*, i8** %4
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
define i32 @gen_dir_hash(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @strncpy(i8* %4, i8* %0, i32 %2)
%6 = add nsw i64 %3, -1
%7 = getelementptr inbounds i8, i8* %4, i64 %6
store i8 0, i8* %7
%8 = call i8* @strrchr(i8* %4, i8 signext 47)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i8* @strrchr(i8* %4, i8 signext 92)
%12 = icmp eq i8* %11, null
br i1 %12, label %20, label %13
13: ; preds = %1, %10
%14 = phi i8* [ %11, %10 ], [ %8, %1 ]
store i8 0, i8* %14
%15 = ptrtoint i8* %14 to i64
%16 = ptrtoint i8* %4 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = call i32 @DJBHash(i8* %4, i32 %18)
br label %20
20: ; preds = %10, %13
%21 = phi i32 [ %19, %13 ], [ 0, %10 ]
ret i32 %21
}