// File: /workspace/github_c_makefile_star2_O0/bluecmd[P]fst-example/gtkwave/fstapi.c
// Function: fstWriterCreateEnumTable
fstEnumHandle fstWriterCreateEnumTable(void *ctx, const char *name, uint32_t elem_count, unsigned int min_valbits, const char **literal_arr, const char **val_arr)
{
fstEnumHandle handle = 0;
unsigned int *literal_lens = NULL;
unsigned int *val_lens = NULL;
int lit_len_tot = 0;
int val_len_tot = 0;
int name_len;
char elem_count_buf[16];
int elem_count_len;
int total_len;
int pos = 0;
char *attr_str = NULL;

if(ctx && name && literal_arr && val_arr && (elem_count != 0))
	{
	struct fstWriterContext *xc = (struct fstWriterContext *)ctx;

	uint32_t i;

	name_len = strlen(name);
	elem_count_len = sprintf(elem_count_buf, "%" PRIu32, elem_count);

	literal_lens = (unsigned int *)calloc(elem_count, sizeof(unsigned int));
	val_lens = (unsigned int *)calloc(elem_count, sizeof(unsigned int));

	for(i=0;i<elem_count;i++)
		{
		literal_lens[i] = strlen(literal_arr[i]);
		lit_len_tot += fstUtilityBinToEscConvertedLen((unsigned char*)literal_arr[i], literal_lens[i]);

		val_lens[i] =  strlen(val_arr[i]);
		val_len_tot += fstUtilityBinToEscConvertedLen((unsigned char*)val_arr[i], val_lens[i]);

		if(min_valbits > 0)
			{
			if(val_lens[i] < min_valbits)
				{
				val_len_tot += (min_valbits - val_lens[i]); /* additional converted len is same for '0' character */
				}
			}
		}

	total_len = name_len + 1 + elem_count_len + 1 + lit_len_tot + elem_count + val_len_tot + elem_count;

	attr_str = (char*)malloc(total_len);
	pos = 0;

	memcpy(attr_str+pos, name, name_len);
	pos += name_len;
	attr_str[pos++] = ' ';

	memcpy(attr_str+pos, elem_count_buf, elem_count_len);
	pos += elem_count_len;
	attr_str[pos++] = ' ';

	for(i=0;i<elem_count;i++)
		{
		pos += fstUtilityBinToEsc((unsigned char*)attr_str+pos, (unsigned char*)literal_arr[i], literal_lens[i]);
		attr_str[pos++] = ' ';
		}

	for(i=0;i<elem_count;i++)
		{
		if(min_valbits > 0)
			{
			if(val_lens[i] < min_valbits)
				{
				memset(attr_str+pos, '0', min_valbits - val_lens[i]);
				pos += (min_valbits - val_lens[i]);
				}
			}

		pos += fstUtilityBinToEsc((unsigned char*)attr_str+pos, (unsigned char*)val_arr[i], val_lens[i]);
		attr_str[pos++] = ' ';
		}

	attr_str[pos-1] = 0;

#ifdef FST_DEBUG
	fprintf(stderr, FST_APIMESS "fstWriterCreateEnumTable() total_len: %d, pos: %d\n", total_len, pos);
	fprintf(stderr, FST_APIMESS "*%s*\n", attr_str);
#endif

	fstWriterSetAttrBegin(xc, FST_AT_MISC, FST_MT_ENUMTABLE, attr_str, handle = ++xc->max_enumhandle);

	free(attr_str);
	free(val_lens);
	free(literal_lens);
	}

return(handle);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl $0x0, -0x6c(%rbp)
movq $0x0, -0x78(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x90ce
cmpq $0x0, -0x10(%rbp)
je 0x90ce
cmpq $0x0, -0x20(%rbp)
je 0x90ce
cmpq $0x0, -0x28(%rbp)
je 0x90ce
cmpl $0x0, -0x14(%rbp)
je 0x90ce
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2130
movl %eax, -0x4c(%rbp)
leaq -0x60(%rbp), %rdi
movl -0x14(%rbp), %edx
leaq 0x2223f(%rip), %rsi     # 0x2afbc
movb $0x0, %al
callq 0x2370
movl %eax, -0x64(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x21f0
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %edi
movl $0x4, %esi
callq 0x21f0
movq %rax, -0x40(%rbp)
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x8e9c
movq -0x20(%rbp), %rax
movl -0x84(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2130
movl %eax, %edx
movq -0x38(%rbp), %rax
movl -0x84(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x20(%rbp), %rax
movl -0x84(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movq -0x38(%rbp), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,4), %esi
callq 0x90e0
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rax
movl -0x84(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
callq 0x2130
movl %eax, %edx
movq -0x40(%rbp), %rax
movl -0x84(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl -0x84(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movq -0x40(%rbp), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,4), %esi
callq 0x90e0
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x18(%rbp)
jbe 0x8e86
movq -0x40(%rbp), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x18(%rbp), %eax
jae 0x8e84
movl -0x18(%rbp), %eax
movq -0x40(%rbp), %rcx
movl -0x84(%rbp), %edx
subl (%rcx,%rdx,4), %eax
addl -0x48(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x8e86
jmp 0x8e88
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x8db7
movl -0x4c(%rbp), %eax
addl $0x1, %eax
addl -0x64(%rbp), %eax
addl $0x1, %eax
addl -0x44(%rbp), %eax
addl -0x14(%rbp), %eax
addl -0x48(%rbp), %eax
addl -0x14(%rbp), %eax
movl %eax, -0x68(%rbp)
movslq -0x68(%rbp), %rdi
callq 0x2280
movq %rax, -0x78(%rbp)
movl $0x0, -0x6c(%rbp)
movq -0x78(%rbp), %rdi
movslq -0x6c(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movslq -0x4c(%rbp), %rdx
callq 0x2250
movl -0x4c(%rbp), %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x78(%rbp), %rax
movl -0x6c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x6c(%rbp)
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
movq -0x78(%rbp), %rdi
movslq -0x6c(%rbp), %rax
addq %rax, %rdi
leaq -0x60(%rbp), %rsi
movslq -0x64(%rbp), %rdx
callq 0x2250
movl -0x64(%rbp), %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x78(%rbp), %rax
movl -0x6c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x6c(%rbp)
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x8fa6
movq -0x78(%rbp), %rdi
movslq -0x6c(%rbp), %rax
addq %rax, %rdi
movq -0x20(%rbp), %rax
movl -0x84(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
movq -0x38(%rbp), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,4), %edx
callq 0x91a0
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x78(%rbp), %rax
movl -0x6c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x6c(%rbp)
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x8f43
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x9073
cmpl $0x0, -0x18(%rbp)
jbe 0x9018
movq -0x40(%rbp), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x18(%rbp), %eax
jae 0x9016
movq -0x78(%rbp), %rdi
movslq -0x6c(%rbp), %rax
addq %rax, %rdi
movl -0x18(%rbp), %eax
movq -0x40(%rbp), %rcx
movl -0x84(%rbp), %edx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movl %eax, %edx
movl $0x30, %esi
callq 0x2190
movl -0x18(%rbp), %eax
movq -0x40(%rbp), %rcx
movl -0x84(%rbp), %edx
subl (%rcx,%rdx,4), %eax
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x9018
movq -0x78(%rbp), %rdi
movslq -0x6c(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rax
movl -0x84(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
movq -0x40(%rbp), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,4), %edx
callq 0x91a0
addl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x78(%rbp), %rax
movl -0x6c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x6c(%rbp)
movslq %ecx, %rcx
movb $0x20, (%rax,%rcx)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x8fb0
movq -0x78(%rbp), %rax
movl -0x6c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %rdx
movl 0x150(%rdx), %eax
addl $0x1, %eax
movl %eax, 0x150(%rdx)
movl %eax, -0x2c(%rbp)
movl %eax, %eax
movl %eax, %r8d
xorl %esi, %esi
movl $0x7, %edx
callq 0x8b10
movq -0x78(%rbp), %rdi
callq 0x2040
movq -0x40(%rbp), %rdi
callq 0x2040
movq -0x38(%rbp), %rdi
callq 0x2040
movl -0x2c(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw (%rax,%rax)