// File: PrarabdhJoshi[P]DatabaseImplementation/Comparison.cc
// Function: CNF::GetSortOrders(OrderMaker&, OrderMaker&)
int CNF :: GetSortOrders (OrderMaker &left, OrderMaker &right) {

	// initialize the size of the OrderMakers
	left.numAtts = 0;
	right.numAtts = 0;

	// loop through all of the disjunctions in the CNF and find those
	// that are acceptable for use in a sort ordering
	for (int i = 0; i < numAnds; i++) {
		
		// if we don't have a disjunction of length one, then it
		// can't be acceptable for use with a sort ordering
		if (orLens[i] != 1) {
			continue;
		}

		// made it this far, so first verify that it is an equality check
		if (orList[i][0].op != Equals) {
			continue;
		}

		// now verify that it operates over atts from both tables
		if (!((orList[i][0].operand1 == Left && orList[i][0].operand2 == Right) ||
		      (orList[i][0].operand2 == Left && orList[i][0].operand1 == Right))) {
			continue;		
		}

		// since we are here, we have found a join attribute!!!
		// so all we need to do is add the new comparison info into the
		// relevant structures
		if (orList[i][0].operand1 == Left) {
			left.whichAtts[left.numAtts] = orList[i][0].whichAtt1;
			left.whichTypes[left.numAtts] = orList[i][0].attType;	
		}	

		if (orList[i][0].operand1 == Right) {
                        right.whichAtts[right.numAtts] = orList[i][0].whichAtt1;
                        right.whichTypes[right.numAtts] = orList[i][0].attType;
                }

		if (orList[i][0].operand2 == Left) {
                        left.whichAtts[left.numAtts] = orList[i][0].whichAtt2;
                        left.whichTypes[left.numAtts] = orList[i][0].attType;
                }

		if (orList[i][0].operand2 == Right) {
                        right.whichAtts[right.numAtts] = orList[i][0].whichAtt2;
                        right.whichTypes[right.numAtts] = orList[i][0].attType;
                }

		// note that we have found two new attributes
		left.numAtts++;
		right.numAtts++;
	}
	
	return left.numAtts;

}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq %rdx, -0x18(%rsp)
movq -0x8(%rsp), %rax
movq %rax, -0x28(%rsp)
movq -0x10(%rsp), %rax
movl $0x0, (%rax)
movq -0x18(%rsp), %rax
movl $0x0, (%rax)
movl $0x0, -0x1c(%rsp)
movq -0x28(%rsp), %rcx
movl -0x1c(%rsp), %eax
cmpl 0x25d0(%rcx), %eax
jge 0x3ae5
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
cmpl $0x1, 0x2580(%rax,%rcx,4)
je 0x3895
jmp 0x3ad5
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x2, 0x14(%rax)
je 0x38b4
jmp 0x3ad5
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x38e7
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x1, 0x8(%rax)
je 0x391f
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jne 0x391a
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x1, (%rax)
je 0x391f
jmp 0x3ad5
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x0, (%rax)
jne 0x3986
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rdx      # imm = 0x1E0
movq %rax, %rcx
addq %rdx, %rcx
movl 0x4(%rcx), %esi
movq -0x10(%rsp), %rcx
movq -0x10(%rsp), %rdx
movslq (%rdx), %rdx
movl %esi, 0x4(%rcx,%rdx,4)
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
movl 0x10(%rax), %edx
movq -0x10(%rsp), %rax
movq -0x10(%rsp), %rcx
movslq (%rcx), %rcx
movl %edx, 0x54(%rax,%rcx,4)
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x1, (%rax)
jne 0x39ed
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rdx      # imm = 0x1E0
movq %rax, %rcx
addq %rdx, %rcx
movl 0x4(%rcx), %esi
movq -0x18(%rsp), %rcx
movq -0x18(%rsp), %rdx
movslq (%rdx), %rdx
movl %esi, 0x4(%rcx,%rdx,4)
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
movl 0x10(%rax), %edx
movq -0x18(%rsp), %rax
movq -0x18(%rsp), %rcx
movslq (%rcx), %rcx
movl %edx, 0x54(%rax,%rcx,4)
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
jne 0x3a55
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rdx      # imm = 0x1E0
movq %rax, %rcx
addq %rdx, %rcx
movl 0xc(%rcx), %esi
movq -0x10(%rsp), %rcx
movq -0x10(%rsp), %rdx
movslq (%rdx), %rdx
movl %esi, 0x4(%rcx,%rdx,4)
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
movl 0x10(%rax), %edx
movq -0x10(%rsp), %rax
movq -0x10(%rsp), %rcx
movslq (%rcx), %rcx
movl %edx, 0x54(%rax,%rcx,4)
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
cmpl $0x1, 0x8(%rax)
jne 0x3abd
movq -0x28(%rsp), %rax
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rdx      # imm = 0x1E0
movq %rax, %rcx
addq %rdx, %rcx
movl 0xc(%rcx), %esi
movq -0x18(%rsp), %rcx
movq -0x18(%rsp), %rdx
movslq (%rdx), %rdx
movl %esi, 0x4(%rcx,%rdx,4)
movslq -0x1c(%rsp), %rcx
imulq $0x1e0, %rcx, %rcx      # imm = 0x1E0
addq %rcx, %rax
movl 0x10(%rax), %edx
movq -0x18(%rsp), %rax
movq -0x18(%rsp), %rcx
movslq (%rcx), %rcx
movl %edx, 0x54(%rax,%rcx,4)
movq -0x10(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x18(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x3867
movq -0x10(%rsp), %rax
movl (%rax), %eax
retq
nopl (%rax)