// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x31426
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x31415
cmpl $0x4, -0x1c(%rbp)
jne 0x3134d
jmp 0x313fc
cmpl $0x7fffffff, -0x20(%rbp) # imm = 0x7FFFFFFF
je 0x31363
movq -0x30(%rbp), %rax
cmpl $0x7fffffff, 0xc(%rax)  # imm = 0x7FFFFFFF
jne 0x3136c
movl $0x1, -0x34(%rbp)
jmp 0x31394
cmpl $0x7ffffffe, -0x20(%rbp) # imm = 0x7FFFFFFE
je 0x31382
movq -0x30(%rbp), %rax
cmpl $0x7ffffffe, 0xc(%rax)  # imm = 0x7FFFFFFE
jne 0x3138b
movl $0x1, -0x34(%rbp)
jmp 0x31392
movl $0x0, -0x34(%rbp)
jmp 0x31394
cmpl $0x0, -0x34(%rbp)
je 0x313af
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
callq 0x67c0
movl %eax, -0x38(%rbp)
jmp 0x313c2
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
callq 0x6820
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jle 0x313ca
jmp 0x313fc
cmpl $0x0, -0x38(%rbp)
jge 0x313da
movq $0x0, -0x30(%rbp)
jmp 0x31415
movl -0x20(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jl 0x313f2
movl $0x1, -0x4(%rbp)
jmp 0x3155a
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x31415
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
jmp 0x31337
cmpq $0x0, -0x30(%rbp)
jne 0x31424
movq -0x40(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x31426
cmpq $0x0, -0x28(%rbp)
je 0x3144d
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x20(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3155a
movq -0x18(%rbp), %rdi
callq 0x63d0
movq %rax, %rdi
addq $0x30, %rdi
addq $0x1, %rdi
callq 0x68f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3147d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3155a
movq -0x28(%rbp), %rcx
addq $0x30, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x63e0
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x20(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x20(%rax)
cmpq $0x0, -0x30(%rbp)
jne 0x31510
movq -0x28(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x31503
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x31553
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x31547
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)