// File: /workspace/github_cpp_makefile_star2_O3/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 0x3ca5
movq 0x8(%r14), %rsi
leaq -0x340(%rbp), %rdi
movl $0x8, %edx
callq 0x1090
jmp 0x3cbd
leaq 0x13d0(%rip), %rsi      # 0x507c
leaq -0x340(%rbp), %rdi
movl $0x8, %edx
callq 0x1090
leaq -0x80(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
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 0x3e98
xorl %r15d, %r15d
leaq -0x4c0(%rbp), %rbx
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
xorl %r14d, %r14d
movl %r15d, %r13d
movq -0x340(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x340(%rbp), %r15
addq %r15, %rdi
movl $0xa, %esi
callq 0x10e0
leaq -0x90(%rbp), %r12
movsbl %al, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x1180
movq %rbx, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x1150
movq %rbx, %rdi
leaq -0x38(%rbp), %rsi
callq 0x1080
movl %r13d, %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), %r8d
movl -0x34(%rbp), %edi
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl %r8d, (%rax)
movl %edi, 0x4(%rax)
movl %edx, 0x8(%rax)
movl %ecx, 0xc(%rax)
movb $0x0, 0x10(%rax)
movq %rax, -0xf0(%rbp)
movq -0x68(%rbp), %rsi
cmpq -0x60(%rbp), %rsi
je 0x3e27
movq %rax, (%rsi)
addq $0x8, -0x68(%rbp)
jmp 0x3e44
leaq -0x70(%rbp), %rdi
leaq -0xf0(%rbp), %rdx
callq 0x21bc
movl -0x38(%rbp), %r8d
movl -0x34(%rbp), %edi
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl -0x40(%rbp), %eax
cmpl %eax, %r8d
cmovll %r8d, %eax
movl %eax, -0x40(%rbp)
movl -0x44(%rbp), %eax
cmpl %eax, %edi
cmovgl %edi, %eax
movl %eax, -0x44(%rbp)
cmpl %r15d, %edx
cmovll %edx, %r15d
movl -0x3c(%rbp), %eax
cmpl %eax, %ecx
cmovgl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq %rbx, %rdi
movq 0x4158(%rip), %rsi      # 0x7fd0
callq 0x1120
leaq -0x448(%rbp), %rdi
callq 0x1050
incl %r14d
cmpl -0x4c(%rbp), %r14d
jl 0x3d6b
jmp 0x3eb0
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 0x3f65
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 0x3f21
movq -0xc8(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
movq %r13, %rcx
cmpq -0xc0(%rbp), %rsi
je 0x3f42
movq %rax, (%rsi)
addq $0x8, (%rcx)
jmp 0x3f4a
movl (%rax), %ecx
cmpl 0x4(%rax), %ecx
jne 0x3f4a
movq -0xa8(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
movq %r12, %rcx
cmpq -0xa0(%rbp), %rsi
jne 0x3f18
addq %rbx, %rdx
callq 0x21bc
incq %r14
movq -0x70(%rbp), %rdx
movq -0x68(%rbp), %rax
subq %rdx, %rax
sarq $0x3, %rax
addq $0x8, %rbx
cmpq %r14, %rax
ja 0x3ef2
movl $0x8, %edi
callq 0x10f0
movq %rax, %rbx
movq $0x0, (%rax)
leaq -0x138(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x1f1e
leaq -0x138(%rbp), %rdx
movq %rbx, %rdi
movq %rbx, %rsi
callq 0x3a96
movq %rax, -0xe8(%rbp)
movq -0x138(%rbp), %rdi
testq %rdi, %rdi
je 0x3fb3
callq 0x10d0
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
movq -0xc8(%rbp), %rax
cmpq -0xd0(%rbp), %rax
je 0x400a
leaq -0x120(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x1f1e
leaq -0xe0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x16e6
movq -0x120(%rbp), %rdi
testq %rdi, %rdi
je 0x400a
callq 0x10d0
movq -0xa8(%rbp), %rax
cmpq -0xb0(%rbp), %rax
je 0x4051
leaq -0x108(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x1f1e
leaq -0xd8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x1a54
movq -0x108(%rbp), %rdi
testq %rdi, %rdi
je 0x4051
callq 0x10d0
cmpl $0x0, -0x48(%rbp)
jle 0x4292
xorl %r14d, %r14d
leaq -0x4c0(%rbp), %r12
movq -0x70(%rbp), %rax
movq -0x68(%rbp), %rcx
subq %rax, %rcx
je 0x4090
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 0x4080
movq -0x340(%rbp), %rax
movq -0x18(%rax), %rdi
leaq -0x340(%rbp), %rbx
addq %rbx, %rdi
movl $0xa, %esi
callq 0x10e0
leaq -0x90(%rbp), %r13
movsbl %al, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1180
movq %r12, %rdi
movq %r13, %rsi
movl $0x8, %edx
callq 0x1150
movq %r12, %rdi
leaq -0x38(%rbp), %rsi
callq 0x1080
movq %r12, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1080
movq %r12, %rdi
leaq -0x34(%rbp), %rsi
callq 0x1080
movq %r12, %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1080
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
je 0x426a
movl -0x2c(%rbp), %eax
cmpl %eax, -0x30(%rbp)
je 0x426a
movl $0x15, %edx
movq 0x3eb0(%rip), %rdi      # 0x7fd8
leaq 0xf57(%rip), %rsi       # 0x5086
callq 0x1110
movl -0x38(%rbp), %esi
movq 0x3e9a(%rip), %rdi      # 0x7fd8
callq 0x1160
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0xeb9(%rip), %rsi       # 0x500e
callq 0x1110
movl -0x30(%rbp), %esi
movq %rbx, %rdi
callq 0x1160
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0xf25(%rip), %rsi       # 0x509c
callq 0x1110
movl -0x34(%rbp), %esi
movq %rbx, %rdi
callq 0x1160
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0xe75(%rip), %rsi       # 0x500e
callq 0x1110
movl -0x2c(%rbp), %esi
movq %rbx, %rdi
callq 0x1160
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0xee5(%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 0x380a
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %r9d
leaq -0xe0(%rbp), %rdi
movl -0x44(%rbp), %esi
movl -0x40(%rbp), %edx
movl %ecx, %r8d
callq 0x1dc2
movl -0x38(%rbp), %ecx
movl -0x34(%rbp), %r9d
leaq -0xd8(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl %r15d, %edx
movl %ecx, %r8d
callq 0x1e70
movq 0x3d99(%rip), %rcx      # 0x7fd8
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x10e0
movsbl %al, %esi
movq 0x3d7b(%rip), %rdi      # 0x7fd8
callq 0x1030
movq %rax, %rdi
callq 0x10a0
movq %r12, %rdi
movq 0x3d5c(%rip), %rsi      # 0x7fd0
callq 0x1120
leaq -0x448(%rbp), %rdi
callq 0x1050
incl %r14d
cmpl -0x48(%rbp), %r14d
jl 0x4065
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x42a3
callq 0x10d0
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
leaq -0x80(%rbp), %rbx
je 0x42b8
callq 0x10d0
movq 0x3d11(%rip), %rsi      # 0x7fd0
leaq -0x640(%rbp), %rdi
callq 0x1120
leaq -0x5c8(%rbp), %rdi
callq 0x1050
movq -0x90(%rbp), %rdi
cmpq %rbx, %rdi
je 0x42e8
callq 0x10d0
leaq -0x340(%rbp), %rdi
callq 0x1040
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x4302
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, %r14
movq -0x108(%rbp), %rdi
jmp 0x4338
movq %rax, %r14
movq -0x120(%rbp), %rdi
jmp 0x4338
movq %rax, %r14
movq -0x138(%rbp), %rdi
testq %rdi, %rdi
je 0x43bc
callq 0x10d0
jmp 0x43bc
jmp 0x435a
movq %rax, %r14
jmp 0x4412
jmp 0x4368
jmp 0x4368
movq %rax, %r14
jmp 0x43e2
movq %rax, %r14
jmp 0x4401
jmp 0x4368
jmp 0x4368
jmp 0x436d
movq %rax, %r14
jmp 0x43bc
movq %rax, %r14
jmp 0x4394
movq %rax, %r14
movq 0x3c54(%rip), %rsi      # 0x7fd0
leaq -0x4c0(%rbp), %rdi
callq 0x1120
leaq -0x448(%rbp), %rdi
callq 0x1050
leaq -0x80(%rbp), %r15
jmp 0x43e2
movq %rax, %r14
movq 0x3c2c(%rip), %rsi      # 0x7fd0
leaq -0x4c0(%rbp), %rdi
callq 0x1120
leaq -0x448(%rbp), %rdi
callq 0x1050
leaq -0x80(%rbp), %r15
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x43d1
callq 0x10d0
movq -0xd0(%rbp), %rdi
testq %rdi, %rdi
je 0x43e2
callq 0x10d0
movq 0x3be7(%rip), %rsi      # 0x7fd0
leaq -0x640(%rbp), %rdi
callq 0x1120
leaq -0x5c8(%rbp), %rdi
callq 0x1050
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x4412
callq 0x10d0
leaq -0x340(%rbp), %rdi
callq 0x1040
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x442c
callq 0x10d0
movq %r14, %rdi
callq 0x1170