// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/jfbuild/src/cache1d.c
// Function: klistaddentry
static int klistaddentry(CACHE1D_FIND_REC **rec, char *name, int type, int source)
{
	CACHE1D_FIND_REC *r = NULL, *attach = NULL;

	if (*rec) {
		int insensitive, v;
		CACHE1D_FIND_REC *last = NULL;
		
		for (attach = *rec; attach; last = attach, attach = attach->next) {
			if (type == CACHE1D_FIND_DRIVE) continue;	// we just want to get to the end for drives
#ifdef _WIN32
			insensitive = 1;
#else
			if (source == CACHE1D_SOURCE_GRP || attach->source == CACHE1D_SOURCE_GRP)
				insensitive = 1;
			else if (source == CACHE1D_SOURCE_ZIP || attach->source == CACHE1D_SOURCE_ZIP)
				insensitive = 1;
			else
				insensitive = 0;
#endif
			if (insensitive) v = Bstrcasecmp(name, attach->name);
			else v = Bstrcmp(name, attach->name);
			
			// sorted list
			if (v > 0) continue;	// item to add is bigger than the current one
									// so look for something bigger than us
			if (v < 0) {			// item to add is smaller than the current one
				attach = NULL;		// so wedge it between the current item and the one before
				break;
			}
			
			// matched
			if (source >= attach->source) return 1;	// item to add is of lower priority
			r = attach;
			break;
		}

		// wasn't found in the list, so attach to the end
		if (!attach) attach = last;
	}

	if (r) {
		r->type = type;
		r->source = source;
		return 0;
	}

	r = (CACHE1D_FIND_REC *)malloc(sizeof(CACHE1D_FIND_REC)+strlen(name)+1);
	if (!r) return -1;
	r->name = (char*)r + sizeof(CACHE1D_FIND_REC); strcpy(r->name, name);
	r->type = type;
	r->source = source;
	r->usera = r->userb = NULL;

	if (!attach) {	// we are the first item
		r->prev = NULL;
		r->next = *rec;
		if (*rec) (*rec)->prev = r;
		*rec = r;
	} else {
		r->prev = attach;
		r->next = attach->next;
		if (attach->next) attach->next->prev = r;
		attach->next = r;
	}

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, (%rsp)
movq (%rdi), %r13
xorl %ebx, %ebx
testq %r13, %r13
je 0x1e85c
movq %r13, %rax
testq %rax, %rax
je 0x1e85c
movq %rax, %r12
cmpl $0x4, %r14d
je 0x1e836
cmpl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
jne 0x1e813
movq (%r12), %rsi
movq %r15, %rdi
callq 0x6880
jmp 0x1e832
cmpl $0x7ffffffe, %ebp       # imm = 0x7FFFFFFE
je 0x1e805
cmpl $0x7ffffffd, 0xc(%r12)  # imm = 0x7FFFFFFD
jg 0x1e805
movq (%r12), %rsi
movq %r15, %rdi
callq 0x68d0
testl %eax, %eax
jle 0x1e840
movq 0x10(%r12), %rax
movq %r12, %rbx
jmp 0x1e7ef
js 0x1e85c
cmpl %ebp, 0xc(%r12)
jle 0x1e8ed
movl %r14d, 0x8(%r12)
movl %ebp, 0xc(%r12)
jmp 0x1e8dc
movq %r15, %rdi
callq 0x6420
leaq 0x31(%rax), %rdi
callq 0x69a0
testq %rax, %rax
je 0x1e8bc
movq %rax, %r12
movq %rax, %rdi
addq $0x30, %rdi
movq %rdi, (%rax)
movq %r15, %rsi
callq 0x6430
movl %r14d, 0x8(%r12)
movl %ebp, 0xc(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%r12)
testq %rbx, %rbx
je 0x1e8c1
movq %rbx, 0x18(%r12)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r12)
testq %rax, %rax
je 0x1e8b6
movq %r12, 0x18(%rax)
movq %r12, 0x10(%rbx)
jmp 0x1e8dc
pushq $-0x1
popq %rax
jmp 0x1e8de
andq $0x0, 0x18(%r12)
movq %r13, 0x10(%r12)
testq %r13, %r13
je 0x1e8d5
movq %r12, 0x18(%r13)
movq (%rsp), %rax
movq %r12, (%rax)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
jmp 0x1e8be