// File: ambersun1234[P]AVL_Tree/./src/avl.h
// Function: AVLTree<int>::doRotation(node<int>*&)
void AVLTree< itemType >::doRotation( node< itemType > *&root ) {
	int direction[ 2 ] = { 0 };
	node< itemType > *up = root , *middle , *down;
	// check for nullptr
	if ( up->getLeftChildHeight() > up->getRightChildHeight() ) {
		middle = up->getLeftChild();
		direction[ 0 ] = -1;
	}
	else {
		middle = up->getRightChild();
		direction[ 0 ] = 1;
	}

	if ( middle->getLeftChildHeight() > middle->getRightChildHeight() ) {
		down = middle->getLeftChild();
		direction[ 1 ] = -1;
	}
	else {
		down = middle->getRightChild();
		direction[ 1 ] = 1;
	}
	if ( direction[ 1 ] == 1 && direction[ 0 ] == 1 ) { // LL rotation
		root = this->leftRotation( up , middle );
	}
	else if ( direction[ 1 ] == -1 && direction[ 0 ] == -1 ) { // RR rotation
		root = this->rightRotation( up , middle );
	}
	else if ( direction[ 1 ] == 1 && direction[ 0 ] == -1 ) { // RL rotation
		middle = this->leftRotation( middle , down );
		up->setLeftChild( middle );

		root = this->rightRotation( up , middle );
	}
	else { // LR rotation
		middle = this->rightRotation( middle , down );
		up->setRightChild( middle );

		root = this->leftRotation( up , middle );
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x9330
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
callq 0x134a0
movl %eax, -0x34(%rbp)
movq -0x20(%rbp), %rdi
callq 0x134f0
movl %eax, %ecx
movl -0x34(%rbp), %eax
cmpl %ecx, %eax
jle 0x13767
movq -0x20(%rbp), %rdi
callq 0xf5e0
movq %rax, -0x28(%rbp)
movl $0xffffffff, -0x18(%rbp) # imm = 0xFFFFFFFF
jmp 0x1377b
movq -0x20(%rbp), %rdi
callq 0xf620
movq %rax, -0x28(%rbp)
movl $0x1, -0x18(%rbp)
movq -0x28(%rbp), %rdi
callq 0x134a0
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rdi
callq 0x134f0
movl %eax, %ecx
movl -0x44(%rbp), %eax
cmpl %ecx, %eax
jle 0x137af
movq -0x28(%rbp), %rdi
callq 0xf5e0
movq %rax, -0x30(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x137c3
movq -0x28(%rbp), %rdi
callq 0xf620
movq %rax, -0x30(%rbp)
movl $0x1, -0x14(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0x137ef
cmpl $0x1, -0x18(%rbp)
jne 0x137ef
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x138d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x138a7
cmpl $-0x1, -0x14(%rbp)
jne 0x1381b
cmpl $-0x1, -0x18(%rbp)
jne 0x1381b
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x13950
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x138a5
cmpl $0x1, -0x14(%rbp)
jne 0x13866
cmpl $-0x1, -0x18(%rbp)
jne 0x13866
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x138d0
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xf600
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x13950
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x138a3
movq -0x40(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x13950
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xf640
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
callq 0x138d0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
jmp 0x138a5
jmp 0x138a7
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)