// File: meghanamreddy[P]Range-trees-and-Interval-Trees/binaryRangeTree.cpp
// Function: BinaryRangeTree::insert(int, int, BinaryRangeNode*, Line*)
BinaryRangeNode* BinaryRangeTree::insert(int x, int y, BinaryRangeNode *t, Line *line)
{	
     if (t == NULL) 
         t = new BinaryRangeNode(x,y, line);
     else if (x < t->data)
     {
         t->left = insert(x, y, t->left, line);
         if (height(t->left) - height(t->right) == 2)
             if (x < t->left->data)
                 t = rotateWithLeftChild(t);
             else
                 t = doubleWithLeftChild(t);
     }
     else if (x > t->data)
     {
         t->right = insert(x, y, t->right, line);
         if (height(t->right) - height(t->left) == 2)
             if (x > t->right->data)
                 t = rotateWithRightChild(t);
             else
                 t = doubleWithRightChild(t);
     }
	else if (x == t->data) {
		t->data2.push_back(y);
		t->lines.push_back(line);			
	}
     t->height = max(height(t->left), height(t->right)) + 1;
     return t;
 }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x6bf5
movl $0x50, %edi
callq 0x2110
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x40(%rbp)
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x20(%rbp), %rcx
callq 0x8800
jmp 0x6bce
movq -0x40(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x6d6a
movq -0x40(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x20f0
jmp 0x6db2
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x6c97
movq -0x38(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x20(%rbp), %r8
callq 0x6b80
movq -0x38(%rbp), %rdi
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x6dc0
movq -0x38(%rbp), %rdi
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x6dc0
movl %eax, %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
cmpl $0x2, %eax
jne 0x6c92
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpl 0x4(%rcx), %eax
jge 0x6c7f
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6e20
movq %rax, -0x18(%rbp)
jmp 0x6c90
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6ee0
movq %rax, -0x18(%rbp)
jmp 0x6c92
jmp 0x6d68
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jle 0x6d36
movq -0x38(%rbp), %rdi
movl -0xc(%rbp), %esi
movl -0x10(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x20(%rbp), %r8
callq 0x6b80
movq -0x38(%rbp), %rdi
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x6dc0
movq -0x38(%rbp), %rdi
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x6dc0
movl %eax, %ecx
movl -0x48(%rbp), %eax
subl %ecx, %eax
cmpl $0x2, %eax
jne 0x6d34
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x28(%rcx), %rcx
cmpl 0x4(%rcx), %eax
jle 0x6d21
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6f30
movq %rax, -0x18(%rbp)
jmp 0x6d32
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x6ff0
movq %rax, -0x18(%rbp)
jmp 0x6d34
jmp 0x6d66
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x6d64
movq -0x18(%rbp), %rdi
addq $0x8, %rdi
leaq -0x10(%rbp), %rsi
callq 0x3460
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
leaq -0x20(%rbp), %rsi
callq 0x3800
jmp 0x6d66
jmp 0x6d68
jmp 0x6d6a
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0x6dc0
movq -0x38(%rbp), %rdi
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x6dc0
movq -0x38(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl %eax, %edx
callq 0x6df0
movl %eax, %ecx
addl $0x1, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x21b0
nopl (%rax,%rax)