// File: /workspace/github_c_makefile_star2_O0/inflex[P]ripMIME/boundary-stack.c
// Function: BS_cmp
int BS_cmp( char *boundary, int len )
{

	char testspace[128]; // was 1024
	int testspacelen=127; // was 1023
	int spin=1;
	int nhl=0;
	struct BS_node *node=glb.boundarystack;
	struct BS_node *nodetmp=NULL, *nodedel=NULL;

	if ((!boundary)||(glb.count == 0)) return 0;
	//if ((glb.smallest_length > 0)&&(len < glb.smallest_length)) return 0;
	if (BS_is_long_enough(len) == 0) return 0;

	nhl = BS_non_hyphen_length(boundary);

	DBS LOGGER_log("%s:%d:BS_cmp:DEBUG: possible-boundary='%s', len=%d, smallest=%d, count=%d, NHL=%d"
			, FL
			, boundary
			, len
			, glb.smallest_length
			, glb.count
			, nhl
			);


	// Crop the incoming string to fit in our testspace length
	if (len > testspacelen) len = testspacelen;

	// Copy the potential boundary into our testspace
	snprintf(testspace, testspacelen, "%s", boundary);

	// First, search through the stack looking for a boundary that matches
	// our search criterion
	//
	// When we do find one, we will jump out of this WHILE loop by setting
	// 'spin' to 0.

	while((node)&&(spin))
	{
//		if (node->boundary_length <= len)
		if (node->boundary_nhl == nhl)
		{	
			DBS LOGGER_log("%s:%d:BS_cmp:DEBUG: Comparing '%s' to '%s'", FL, boundary, node->boundary);
			// * 20040903-08H57:PLD: Set boundary length comparison from > 0 to >= 0
			if ((node->boundary != NULL)&&(node->boundary_length >= 0))
			{
				if ((BS_boundary_detect(testspace, node->boundary, node->boundary_length))==0)
				{
					DBS LOGGER_log("%s:%d:BS_cmp:DEBUG: Boundary HIT",FL);
					spin = 0;
				}
			}
		}

		if (spin != 0) node = node->next;
	}

	// If we have a hit on the matching, then, according
	// to nested MIME rules, we must "remove" any previous
	// boundaries
	//
	// We know that we had a HIT in matching if spin == 0, because
	// in our previous code block that's what we set spin to if
	if(spin==0)
	{

		DBS LOGGER_log("%s:%d:BS_cmp:DEBUG: Boundary hit on '%s' == '%s'",FL, boundary,node->boundary);

		// If our "HIT" node is /NOT/ the one on the top of the
		// stack, then we need to pop off and deallocate the nodes
		// PRIOR/Above the hit node.
		//
		// ie, if "NODE" is not the top, then pop off until we
		// do get to the node

		if (node != glb.boundarystack)
		{
			nodetmp = glb.boundarystack;
			while ((nodetmp)&&(nodetmp != node))
			{
				// - Set the node to delete (nodedel) to the current temp
				// node (notetmp)
				// - Increment the nodetmp to the next node in the stack
				// - Free the node to delete (nodedel)

				nodedel = nodetmp;
				nodetmp = nodetmp->next;
				free(nodedel->boundary);
				free(nodedel);
			}
			glb.boundarystack = node;
		}
		return 1;

	}
	else
	{
		return 0;
	}

	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl $0x7f, -0xa4(%rbp)
movl $0x1, -0xa8(%rbp)
movl $0x0, -0xac(%rbp)
movq 0x22bb1(%rip), %rax     # 0x35968
movq %rax, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movq $0x0, -0xc8(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x12de4
cmpl $0x0, 0x22b6e(%rip)     # 0x35950
jne 0x12df0
movl $0x0, -0x4(%rbp)
jmp 0x1308b
movl -0x14(%rbp), %edi
callq 0x12bb0
cmpl $0x0, %eax
jne 0x12e09
movl $0x0, -0x4(%rbp)
jmp 0x1308b
movq -0x10(%rbp), %rdi
callq 0x128a0
movl %eax, -0xac(%rbp)
cmpl $0x0, 0x22b21(%rip)     # 0x35940
je 0x12e5f
movq -0x10(%rbp), %rcx
movl -0x14(%rbp), %r8d
movl 0x22b2c(%rip), %r9d     # 0x3595c
movl 0x22b19(%rip), %r10d    # 0x35950
movl -0xac(%rbp), %eax
leaq 0xc392(%rip), %rdi      # 0x1f1d6
leaq 0xc187(%rip), %rsi      # 0x1efd2
movl $0x1e2, %edx            # imm = 0x1E2
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x117c0
movl -0x14(%rbp), %eax
cmpl -0xa4(%rbp), %eax
jle 0x12e73
movl -0xa4(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0xa0(%rbp), %rdi
movslq -0xa4(%rbp), %rsi
movq -0x10(%rbp), %rcx
leaq 0xc11e(%rip), %rdx      # 0x1efaa
movb $0x0, %al
callq 0x2130
xorl %eax, %eax
cmpq $0x0, -0xb8(%rbp)
movb %al, -0xc9(%rbp)
je 0x12eb5
cmpl $0x0, -0xa8(%rbp)
setne %al
movb %al, -0xc9(%rbp)
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x12ec4
jmp 0x12f9b
movq -0xb8(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0xac(%rbp), %eax
jne 0x12f7b
cmpl $0x0, 0x22a5f(%rip)     # 0x35940
je 0x12f0b
movq -0x10(%rbp), %rcx
movq -0xb8(%rbp), %rax
movq (%rax), %r8
leaq 0xc330(%rip), %rdi      # 0x1f228
leaq 0xc0d3(%rip), %rsi      # 0x1efd2
movl $0x1fc, %edx            # imm = 0x1FC
movb $0x0, %al
callq 0x117c0
movq -0xb8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x12f79
movq -0xb8(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jl 0x12f79
leaq -0xa0(%rbp), %rdi
movq -0xb8(%rbp), %rax
movq (%rax), %rsi
movq -0xb8(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x12bf0
cmpl $0x0, %eax
jne 0x12f77
cmpl $0x0, 0x229ef(%rip)     # 0x35940
je 0x12f6d
leaq 0xc2f9(%rip), %rdi      # 0x1f253
leaq 0xc071(%rip), %rsi      # 0x1efd2
movl $0x202, %edx            # imm = 0x202
movb $0x0, %al
callq 0x117c0
movl $0x0, -0xa8(%rbp)
jmp 0x12f79
jmp 0x12f7b
cmpl $0x0, -0xa8(%rbp)
je 0x12f96
movq -0xb8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xb8(%rbp)
jmp 0x12e93
cmpl $0x0, -0xa8(%rbp)
jne 0x13084
cmpl $0x0, 0x22991(%rip)     # 0x35940
je 0x12fd9
movq -0x10(%rbp), %rcx
movq -0xb8(%rbp), %rax
movq (%rax), %r8
leaq 0xc2ae(%rip), %rdi      # 0x1f274
leaq 0xc005(%rip), %rsi      # 0x1efd2
movl $0x214, %edx            # imm = 0x214
movb $0x0, %al
callq 0x117c0
movq -0xb8(%rbp), %rax
cmpq 0x22981(%rip), %rax     # 0x35968
je 0x1307b
movq 0x22974(%rip), %rax     # 0x35968
movq %rax, -0xc0(%rbp)
xorl %eax, %eax
cmpq $0x0, -0xc0(%rbp)
movb %al, -0xca(%rbp)
je 0x13024
movq -0xc0(%rbp), %rax
cmpq -0xb8(%rbp), %rax
setne %al
movb %al, -0xca(%rbp)
movb -0xca(%rbp), %al
testb $0x1, %al
jne 0x13030
jmp 0x1306d
movq -0xc0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0xc8(%rbp), %rax
movq (%rax), %rdi
callq 0x2030
movq -0xc8(%rbp), %rdi
callq 0x2030
jmp 0x12ffb
movq -0xb8(%rbp), %rax
movq %rax, 0x228ed(%rip)     # 0x35968
movl $0x1, -0x4(%rbp)
jmp 0x1308b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw (%rax,%rax)