#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*/ gen_str_alphanumeric(char *, char const *, size_t);
int /*<<< orphan*/ gen_str_upper(char *, char *, size_t);
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char *);
void gen_cname_id(char *dst, const char *src, size_t n) {
  if (n > 7) {
    const char *colon = strchr(src, ':');
    if (colon != NULL) {
      src = colon + 1;
    }
    strcpy(dst, "dae_ID_");
    gen_str_alphanumeric(dst + 7, src, n - 7);
    gen_str_upper(dst + 7, dst + 7, n - 7);
  } else if (n > 0) {
    *dst = '\0';
  }
}


x86 assembly (clang, -O0):
<gen_cname_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x7,-0x18(%rbp)
jbe    11d3 <gen_cname_id+0x93>
mov    -0x10(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1188 <gen_cname_id+0x48>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rdi
add    $0x7,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x7,%rdx
call   1050 <gen_str_alphanumeric@plt>
mov    -0x8(%rbp),%rdi
add    $0x7,%rdi
mov    -0x8(%rbp),%rsi
add    $0x7,%rsi
mov    -0x18(%rbp),%rdx
sub    $0x7,%rdx
call   1060 <gen_str_upper@plt>
jmp    11ea <gen_cname_id+0xaa>
cmpq   $0x0,-0x18(%rbp)
jbe    11e5 <gen_cname_id+0xa5>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11ea <gen_cname_id+0xaa>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_cname_id>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
cmp    $0x8,%rdx
jb     11ad <gen_cname_id+0x6d>
mov    %rsi,%r15
mov    %rsi,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
lea    0x1(%rax),%r12
test   %rax,%rax
cmove  %r15,%r12
lea    0xe8a(%rip),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
add    $0x7,%r14
add    $0xfffffffffffffff9,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <gen_str_alphanumeric@plt>
mov    %r14,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <gen_str_upper@plt>
test   %rbx,%rbx
je     11b6 <gen_cname_id+0x76>
movb   $0x0,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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