// File: /workspace/github_cpp_makefile_star2_O1/meghanamreddy[P]Range-trees-and-Interval-Trees/main.cpp
// Function: main
int main(int argc, char* argv[]) {
	// Read in line segment data //
	vector<Line*> line_segments;

	// read the input of line segments
	ifstream infile;
	if (argc > 1)
		infile.open(argv[1]);
	else
		infile.open("input.txt");

	string line;
	int num = 0, i, numquery=0, j;
	getline(infile, line);
    	istringstream iss(line);
	iss >> num; iss >> numquery;
	int x1, x2, y1, y2;
	int maxX=0, minX=0, maxY=0, minY=0;
	Line *temp;


	for (i=0; i<num; i++) {
		getline(infile, line);
    		istringstream iss(line);
		iss >> x1; iss >> y1;
		iss >> x2; iss >> y2;
		temp = new Line(x1, x2, y1, y2);
		line_segments.push_back(temp);

		if (x1 < minX) minX = x1;
		if (x2 > maxX) maxX = x2;
		if (y1 < minY) minY = y1;
		if (y2 > maxY) maxY = y2;
	}

	vector<Line*> lines_x;
	vector<Line*> lines_y;
	for (i=0; i<line_segments.size(); i++) {
		if (line_segments[i]->y1 == line_segments[i]->y2)
			lines_x.push_back(line_segments[i]);
		else if (line_segments[i]->x1 == line_segments[i]->x2)
			lines_y.push_back(line_segments[i]);
	}		

	BinaryRangeTree* rangeTreeEndPoints = new BinaryRangeTree();
	rangeTreeEndPoints = rangeTreeEndPoints->buildRangeTreeEndPoints(rangeTreeEndPoints, line_segments);
	IntervalTree treeX;
	IntervalTree treeY;
	if (lines_x.size() > 0)
		treeX.constructX(lines_x);
	if (lines_y.size() > 0)
		treeY.constructY(lines_y);


	//Read queries //

	for (i=0; i<numquery; i++) {
		// set the flags of all lines back to 0
		for (j=0; j<line_segments.size(); j++)
			line_segments[j]->reported = 0;

		getline(infile, line);
    		istringstream iss(line);
		iss >> x1; iss >> y1;
		iss >> x2; iss >> y2;
		if ((x1 != x2) & (y1 != y2)) {
		cout << " Query rectangle :: (" <<  x1 << " " << y1 << ") (" << x2 << " " << y2 << ") " << endl;
		rangeTreeEndPoints->twodquery(x1, x2, y1, y2);
		treeX.queryX(maxX,minX, y1, y1, y2);
		treeY.queryY(maxY, minY, x1, x1, x2);
		cout << endl;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x618, %rsp            # imm = 0x618
movq %rsi, %r14
movl %edi, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movq $0x0, -0x60(%rbp)
leaq -0x340(%rbp), %rbx
movq %rbx, %rdi
callq 0x1100
cmpl $0x2, %r15d
jl 0x3c9d
movq 0x8(%r14), %rsi
leaq -0x340(%rbp), %rdi
movl $0x8, %edx
callq 0x1090
jmp 0x3cb5
leaq 0x13d8(%rip), %rsi      # 0x507c
leaq -0x340(%rbp), %rdi
movl $0x8, %edx
callq 0x1090
leaq -0x80(%rbp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
xorl %eax, %eax
movl %eax, -0x4c(%rbp)
movl %eax, -0x48(%rbp)
movq -0x340(%rbp), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %edx
leaq -0x340(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x1180
leaq -0x640(%rbp), %rdi
leaq -0x90(%rbp), %rsi
movl $0x8, %edx
callq 0x1150
leaq -0x640(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x1080
leaq -0x640(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1080
cmpl $0x0, -0x4c(%rbp)
jle 0x3e8b
xorl %r15d, %r15d
leaq -0x4c0(%rbp), %rbx
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
xorl %r14d, %r14d
movl %r15d, %r12d
movq -0x340(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x340(%rbp), %r15
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
leaq -0x90(%rbp), %r13
movsbl %al, %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x1180
movq %rbx, %rdi
movq %r13, %rsi
movl $0x8, %edx
callq 0x1150
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
callq 0x1080
movl %r12d, %r15d
movq %rbx, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1080
movq %rbx, %rdi
leaq -0x34(%rbp), %rsi
callq 0x1080
movq %rbx, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1080
movl $0x14, %edi
callq 0x10f0
movl -0x38(%rbp), %ecx
movl -0x34(%rbp), %edx
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edi
movl %ecx, (%rax)
movl %edx, 0x4(%rax)
movl %esi, 0x8(%rax)
movl %edi, 0xc(%rax)
movb $0x0, 0x10(%rax)
movq %rax, -0xf0(%rbp)
movq -0x68(%rbp), %rsi
cmpq -0x60(%rbp), %rsi
je 0x3e1d
movq %rax, (%rsi)
addq $0x8, -0x68(%rbp)
jmp 0x3e2d
leaq -0x70(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
callq 0x218e
movl -0x38(%rbp), %eax
movl -0x40(%rbp), %ecx
cmpl %ecx, %eax
cmovll %eax, %ecx
movl %ecx, -0x40(%rbp)
movl -0x34(%rbp), %eax
movl -0x44(%rbp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, -0x44(%rbp)
movl -0x30(%rbp), %eax
cmpl %r15d, %eax
cmovll %eax, %r15d
movl -0x2c(%rbp), %eax
movl -0x3c(%rbp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl %ecx, -0x3c(%rbp)
movq %rbx, %rdi
movq 0x4165(%rip), %rsi      # 0x7fd0
callq 0x1120
leaq -0x448(%rbp), %rdi
callq 0x1050
incl %r14d
cmpl -0x4c(%rbp), %r14d
jl 0x3d63
jmp 0x3ea3
movl $0x0, -0x44(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
xorl %r15d, %r15d
xorps %xmm0, %xmm0
movaps %xmm0, -0xd0(%rbp)
xorl %eax, %eax
movq %rax, -0xc0(%rbp)
movq %rax, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
movq -0x70(%rbp), %rdx
cmpq %rdx, -0x68(%rbp)
je 0x3f58
leaq -0xa8(%rbp), %r12
leaq -0xc8(%rbp), %r13
xorl %ebx, %ebx
xorl %r14d, %r14d
movq (%rdx,%rbx), %rax
movl 0x8(%rax), %ecx
cmpl 0xc(%rax), %ecx
jne 0x3f14
movq -0xc8(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
movq %r13, %rcx
cmpq -0xc0(%rbp), %rsi
je 0x3f35
movq %rax, (%rsi)
addq $0x8, (%rcx)
jmp 0x3f3d
movl (%rax), %ecx
cmpl 0x4(%rax), %ecx
jne 0x3f3d
movq -0xa8(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
movq %r12, %rcx
cmpq -0xa0(%rbp), %rsi
jne 0x3f0b
addq %rbx, %rdx
callq 0x218e
incq %r14
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rax
subq %rdx, %rax
sarq $0x3, %rax
addq $0x8, %rbx
cmpq %r14, %rax
ja 0x3ee5
movl $0x8, %edi
callq 0x10f0
movq %rax, %rbx
movq $0x0, (%rax)
leaq -0x138(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x1efe
leaq -0x138(%rbp), %rdx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x3a8a
movq %rax, -0xe8(%rbp)
movq -0x138(%rbp), %rdi
testq %rdi, %rdi
je 0x3fa6
callq 0x10d0
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
movq -0xc8(%rbp), %rax
cmpq -0xd0(%rbp), %rax
je 0x3ffd
leaq -0x120(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1efe
leaq -0xe0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x16ce
movq -0x120(%rbp), %rdi
testq %rdi, %rdi
je 0x3ffd
callq 0x10d0
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
je 0x4044
leaq -0x108(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1efe
leaq -0xd8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x1a38
movq -0x108(%rbp), %rdi
testq %rdi, %rdi
je 0x4044
callq 0x10d0
cmpl $0x0, -0x48(%rbp)
jle 0x4285
xorl %r14d, %r14d
leaq -0x4c0(%rbp), %r13
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
subq %rax, %rcx
je 0x4083
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
movq (%rax,%rdx,8), %rsi
movb $0x0, 0x10(%rsi)
incq %rdx
cmpq %rdx, %rcx
jne 0x4073
movq -0x340(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x340(%rbp), %rbx
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
leaq -0x90(%rbp), %r12
movsbl %al, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1180
movq %r13, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x1150
movq %r13, %rdi
leaq -0x38(%rbp), %rsi
callq 0x1080
movq %r13, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1080
movq %r13, %rdi
leaq -0x34(%rbp), %rsi
callq 0x1080
movq %r13, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1080
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x425d
movl -0x2c(%rbp), %eax
cmpl %eax, -0x30(%rbp)
je 0x425d
movl $0x15, %edx
movq 0x3ebd(%rip), %rdi      # 0x7fd8
leaq 0xf64(%rip), %rsi       # 0x5086
callq 0x1110
movl -0x38(%rbp), %esi
movq 0x3ea7(%rip), %rdi      # 0x7fd8
callq 0x1160
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0xec6(%rip), %rsi       # 0x500e
callq 0x1110
movl -0x30(%rbp), %esi
movq %rbx, %rdi
callq 0x1160
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0xf32(%rip), %rsi       # 0x509c
callq 0x1110
movl -0x34(%rbp), %esi
movq %rbx, %rdi
callq 0x1160
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0xe82(%rip), %rsi       # 0x500e
callq 0x1110
movl -0x2c(%rbp), %esi
movq %rbx, %rdi
callq 0x1160
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xef2(%rip), %rsi       # 0x50a0
callq 0x1110
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movl -0x38(%rbp), %esi
movl -0x34(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %r8d
movq -0xe8(%rbp), %rdi
callq 0x37d2
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %r9d
leaq -0xe0(%rbp), %rdi
movl -0x44(%rbp), %esi
movl -0x40(%rbp), %edx
movl %ecx, %r8d
callq 0x1da2
movl -0x38(%rbp), %ecx
movl -0x34(%rbp), %r9d
leaq -0xd8(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl %r15d, %edx
movl %ecx, %r8d
callq 0x1e50
movq 0x3da6(%rip), %rcx      # 0x7fd8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq 0x3d88(%rip), %rdi      # 0x7fd8
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq %r13, %rdi
movq 0x3d69(%rip), %rsi      # 0x7fd0
callq 0x1120
leaq -0x448(%rbp), %rdi
callq 0x1050
incl %r14d
cmpl -0x48(%rbp), %r14d
jl 0x4058
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x4296
callq 0x10d0
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
leaq -0x80(%rbp), %rbx
je 0x42ab
callq 0x10d0
movq 0x3d1e(%rip), %rsi      # 0x7fd0
leaq -0x640(%rbp), %rdi
callq 0x1120
leaq -0x5c8(%rbp), %rdi
callq 0x1050
movq -0x90(%rbp), %rdi
cmpq %rbx, %rdi
je 0x42db
callq 0x10d0
leaq -0x340(%rbp), %rdi
callq 0x1040
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x42f5
callq 0x10d0
xorl %eax, %eax
addq $0x618, %rsp            # imm = 0x618
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x108(%rbp), %rdi
jmp 0x432b
movq %rax, %rbx
movq -0x120(%rbp), %rdi
jmp 0x432b
movq %rax, %rbx
movq -0x138(%rbp), %rdi
testq %rdi, %rdi
je 0x43be
callq 0x10d0
jmp 0x43be
jmp 0x435c
movq %rax, %rbx
jmp 0x4414
movq %rax, %rbx
jmp 0x4420
jmp 0x436a
jmp 0x436a
movq %rax, %rbx
jmp 0x43e4
movq %rax, %rbx
jmp 0x4403
jmp 0x436a
jmp 0x436a
jmp 0x436f
movq %rax, %rbx
jmp 0x43be
movq %rax, %rbx
jmp 0x4396
movq %rax, %rbx
movq 0x3c52(%rip), %rsi      # 0x7fd0
leaq -0x4c0(%rbp), %rdi
callq 0x1120
leaq -0x448(%rbp), %rdi
callq 0x1050
leaq -0x80(%rbp), %r14
jmp 0x43e4
movq %rax, %rbx
movq 0x3c2a(%rip), %rsi      # 0x7fd0
leaq -0x4c0(%rbp), %rdi
callq 0x1120
leaq -0x448(%rbp), %rdi
callq 0x1050
leaq -0x80(%rbp), %r14
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x43d3
callq 0x10d0
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x43e4
callq 0x10d0
movq 0x3be5(%rip), %rsi      # 0x7fd0
leaq -0x640(%rbp), %rdi
callq 0x1120
leaq -0x5c8(%rbp), %rdi
callq 0x1050
movq -0x90(%rbp), %rdi
cmpq %r14, %rdi
je 0x4414
callq 0x10d0
leaq -0x340(%rbp), %rdi
callq 0x1040
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x442e
callq 0x10d0
movq %rbx, %rdi
callq 0x1170