#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 */
scalar_t__ generic_crc(int, unsigned long, char const *, size_t);
char *malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int, size_t,
                           unsigned int, unsigned int);
size_t strlen(char const *);
char *hashed_name(int retry, const char *tag, const char *refname) {
  char *retname;
  size_t len = strlen(tag);
  static unsigned long p16[] = {0x1021, 0x8408, 0x8005, 0xA001};
  static unsigned long p24[] = {0x5d6dcb, 0x864cfb};
  if ((retname = malloc(19 + len)) != NULL) {
    retry &= 7;
    len = strlen(refname);
    sprintf(retname, "%s-%u-%03u-%04x-%06x", tag, retry, len,
            (unsigned)(generic_crc(16, p16[retry >> 1], refname, len)),
            (unsigned)(generic_crc(24, p24[retry & 1], refname, len)));
  }
  return retname;
}


x86 assembly (clang, -O0):
<hashed_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x13,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1222 <hashed_name+0xe2>
mov    -0x4(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x4(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x4(%rbp),%eax
sar    $0x1,%eax
movslq %eax,%rcx
lea    0x2e8f(%rip),%rax
mov    (%rax,%rcx,8),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x10,%edi
call   1060 <generic_crc@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
movslq %eax,%rcx
lea    0x2e86(%rip),%rax
mov    (%rax,%rcx,8),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x18,%edi
call   1060 <generic_crc@plt>
mov    -0x50(%rbp),%rdi
mov    -0x48(%rbp),%rdx
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x2c(%rbp),%r9d
lea    0xde6(%rip),%rsi
mov    %eax,(%rsp)
call   1050 <sprintf@plt>
mov    -0x20(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hashed_name>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %edi,%ebx
mov    %rsi,%rdi
call   1030 <strlen@plt>
lea    0x13(%rax),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     11df <hashed_name+0x9f>
mov    %ebx,%ebp
and    $0x7,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r13
mov    %ebp,%eax
shr    %eax
lea    0xe77(%rip),%rcx
mov    (%rcx,%rax,8),%rsi
mov    $0x10,%edi
mov    %r15,%rdx
mov    %r13,%rcx
call   1060 <generic_crc@plt>
mov    %rax,0x10(%rsp)
and    $0x1,%ebx
lea    0xe74(%rip),%rax
mov    (%rax,%rbx,8),%rsi
mov    $0x18,%edi
mov    %r15,%rdx
mov    %r13,%rcx
call   1060 <generic_crc@plt>
mov    %eax,(%rsp)
lea    0xe66(%rip),%rsi
mov    %r12,%rdi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %r13,%r8
mov    0x10(%rsp),%r9
call   1050 <sprintf@plt>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@hashed_name.p16 = internal global [4 x i64] [i64 4129, i64 33800, i64 32773, i64 40961]
@hashed_name.p24 = internal global [2 x i64] [i64 6122955, i64 8801531]
@.str = [21 x i8] c"%s-%u-%03u-%04x-%06x\00"
define i8* @hashed_name(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %5
%10 = call i64 @strlen(i8* %9)
store i64 %10, i64* %8
%11 = load i64, i64* %8
%12 = add i64 19, %11
%13 = trunc i64 %12 to i32
%14 = call i8* @malloc(i32 %13)
store i8* %14, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %44
16: ; preds = %3
%17 = load i32, i32* %4
%18 = and i32 %17, 7
store i32 %18, i32* %4
%19 = load i8*, i8** %6
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %8
%21 = load i8*, i8** %7
%22 = load i8*, i8** %5
%23 = load i32, i32* %4
%24 = load i64, i64* %8
%25 = load i32, i32* %4
%26 = ashr i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [4 x i64], [4 x i64]* @hashed_name.p16, i64 0, i64 %27
%29 = load i64, i64* %28
%30 = load i8*, i8** %6
%31 = load i64, i64* %8
%32 = call i64 @generic_crc(i32 16, i64 %29, i8* %30, i64 %31)
%33 = trunc i64 %32 to i32
%34 = load i32, i32* %4
%35 = and i32 %34, 1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [2 x i64], [2 x i64]* @hashed_name.p24, i64 0, i64 %36
%38 = load i64, i64* %37
%39 = load i8*, i8** %6
%40 = load i64, i64* %8
%41 = call i64 @generic_crc(i32 24, i64 %38, i8* %39, i64 %40)
%42 = trunc i64 %41 to i32
%43 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23, i64 %24, i32 %33, i32 %42)
br label %44
44: ; preds = %16, %3
%45 = load i8*, i8** %7
ret i8* %45
}

LLVM IR (-O2):
@hashed_name.p16 = internal unnamed_addr constant [4 x i64] [i64 4129, i64 33800, i64 32773, i64 40961]
@hashed_name.p24 = internal unnamed_addr constant [2 x i64] [i64 6122955, i64 8801531]
@.str = [21 x i8] c"%s-%u-%03u-%04x-%06x\00"
define noalias i8* @hashed_name(i32 %0, i8* %1, i8* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%5 = trunc i64 %4 to i32
%6 = add i32 %5, 19
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %25, label %9
9: ; preds = %3
%10 = and i32 %0, 7
%11 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%12 = lshr i32 %10, 1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [4 x i64], [4 x i64]* @hashed_name.p16, i64 0, i64 %13
%15 = load i64, i64* %14
%16 = tail call i64 @generic_crc(i32 16, i64 %15, i8* %2, i64 %11)
%17 = trunc i64 %16 to i32
%18 = and i32 %0, 1
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds [2 x i64], [2 x i64]* @hashed_name.p24, i64 0, i64 %19
%21 = load i64, i64* %20
%22 = tail call i64 @generic_crc(i32 24, i64 %21, i8* %2, i64 %11)
%23 = trunc i64 %22 to i32
%24 = tail call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %10, i64 %11, i32 %17, i32 %23)
br label %25
25: ; preds = %9, %3
ret i8* %7
}