#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 */
char *gen_cname_native(char const *);
int /*<<< orphan*/ gen_str_alphanumeric(char *, char const *, size_t);
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
void gen_cname_type(char *dst, const char *src, size_t n) {
  const char *native = gen_cname_native(src);
  if (native != NULL) {
    strncpy(dst, native, n);
    dst[n - 1] = '\0';
  } else {
    if (n > 4) {
      const char *colon = strchr(src, ':');
      if (colon != NULL) {
        src = colon + 1;
      }
      strcpy(dst, "dae_");
      gen_str_alphanumeric(dst + 4, src, n - 4);
    } else if (n > 0) {
      *dst = '\0';
    }
  }
}


x86 assembly (clang, -O0):
<gen_cname_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <gen_cname_native@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a2 <gen_cname_type+0x52>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1220 <gen_cname_type+0xd0>
cmpq   $0x4,-0x18(%rbp)
jbe    1204 <gen_cname_type+0xb4>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d6 <gen_cname_type+0x86>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x4,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x4,%rdx
call   1070 <gen_str_alphanumeric@plt>
jmp    121b <gen_cname_type+0xcb>
cmpq   $0x0,-0x18(%rbp)
jbe    1216 <gen_cname_type+0xc6>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    121b <gen_cname_type+0xcb>
jmp    1220 <gen_cname_type+0xd0>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_cname_type>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1060 <gen_cname_native@plt>
test   %rax,%rax
je     118e <gen_cname_type+0x3e>
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r15,%rdx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r15,%r14,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
cmp    $0x5,%r15
jb     11dc <gen_cname_type+0x8c>
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%r12
test   %rax,%rax
cmove  %rbx,%r12
lea    0xe4d(%rip),%rsi
mov    %r14,%rdi
call   1040 <strcpy@plt>
add    $0x4,%r14
add    $0xfffffffffffffffc,%r15
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1070 <gen_str_alphanumeric@plt>
test   %r15,%r15
je     1182 <gen_cname_type+0x32>
movb   $0x0,(%r14)
jmp    1182 <gen_cname_type+0x32>

LLVM IR (-O0):
@.str = [5 x i8] c"dae_\00"
define void @gen_cname_type(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = load i8*, i8** %5
%10 = call i8* @gen_cname_native(i8* %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %22
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = load i8*, i8** %7
%16 = load i64, i64* %6
%17 = call i32 @strncpy(i8* %14, i8* %15, i64 %16)
%18 = load i8*, i8** %4
%19 = load i64, i64* %6
%20 = sub i64 %19, 1
%21 = getelementptr inbounds i8, i8* %18, i64 %20
store i8 0, i8* %21
br label %49
22: ; preds = %3
%23 = load i64, i64* %6
%24 = icmp ugt i64 %23, 4
br i1 %24, label %25, label %42
25: ; preds = %22
%26 = load i8*, i8** %5
%27 = call i8* @strchr(i8* %26, i8 signext 58)
store i8* %27, i8** %8
%28 = load i8*, i8** %8
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i64 1
store i8* %32, i8** %5
br label %33
33: ; preds = %30, %25
%34 = load i8*, i8** %4
%35 = call i32 @strcpy(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 4
%38 = load i8*, i8** %5
%39 = load i64, i64* %6
%40 = sub i64 %39, 4
%41 = call i32 @gen_str_alphanumeric(i8* %37, i8* %38, i64 %40)
br label %48
42: ; preds = %22
%43 = load i64, i64* %6
%44 = icmp ugt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = load i8*, i8** %4
store i8 0, i8* %46
br label %47
47: ; preds = %45, %42
br label %48
48: ; preds = %47, %33
br label %49
49: ; preds = %48, %13
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"dae_\00"
define void @gen_cname_type(i8* %0, i8* %1, i64 %2) {
%4 = tail call i8* @gen_cname_native(i8* %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = tail call i32 @strncpy(i8* %0, i8* %4, i64 %2)
%8 = add i64 %2, -1
%9 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 0, i8* %9
br label %24
10: ; preds = %3
%11 = icmp ugt i64 %2, 4
br i1 %11, label %12, label %21
12: ; preds = %10
%13 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 58)
%14 = icmp eq i8* %13, null
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = select i1 %14, i8* %1, i8* %15
%17 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds i8, i8* %0, i64 4
%19 = add i64 %2, -4
%20 = tail call i32 @gen_str_alphanumeric(i8* %18, i8* %16, i64 %19)
br label %24
21: ; preds = %10
%22 = icmp eq i64 %2, 0
br i1 %22, label %24, label %23
23: ; preds = %21
store i8 0, i8* %0
br label %24
24: ; preds = %12, %23, %21, %6
ret void
}