// File: aadityanaik[P]LongNums/src/longnums.cpp
// Function: LongNumber::operator+(LongNumber)
LongNumber LongNumber::operator+(LongNumber X) {                             //Addition
	LongNumber answer;
	answer.digits.pop_back();
	int carryover = 0;
	//std::vector<int> big, small;
	if (this->negative == X.negative) {
		//one must add
		if (this->negative) {
			answer.negative = true;
			//the ans will be negative
		}

		long int temp = 0;

		for (int i = 0, j = 0;; i++, j++) {  //following algorithm is the traditional digit-by-digit method of addition
			temp = carryover;
			if(i < digits.size() && j < X.digits.size()) {
				temp += digits[i] + X.digits[j];
			} else if(i < digits.size()) {
				temp += digits[i];
			} else if(j < X.digits.size()) {
				temp += X.digits[j];
			} else {
				break;
			}

			carryover = temp / BASE;
			temp %= BASE;

			answer.digits.push_back(temp);
		}

		if (carryover > 0) {                                 //if the carryover is 1
			answer.digits.push_back(carryover);
		}
	}

	else {
		//one must subtract the numbers
		LongNumber temp;
		if (negative) {                 //for cases like -1 + 2 == 2 + (-1) == 2 - 1
			temp = this->absolute();
			answer = (X - temp);
		}

		else if (X.negative) {                    //for cases like 1 + (-2) == 1 - 2
			temp = X.absolute();
			answer = ((*this) - temp);
		}
	}

	return answer;
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdx, 0x48(%rsp)
movq %rdi, 0x38(%rsp)
movq %rdi, %rax
movq %rax, 0x30(%rsp)
movq %rdi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
movq %rdx, 0x160(%rsp)
movq 0x168(%rsp), %rax
movq %rax, 0x40(%rsp)
movb $0x0, 0x15f(%rsp)
callq 0x2a10
movq 0x38(%rsp), %rdi
callq 0x81d0
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rdx
movl $0x0, 0x158(%rsp)
movb 0x18(%rax), %al
andb $0x1, %al
movzbl %al, %eax
movb 0x18(%rdx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x3b7a
movq 0x40(%rsp), %rax
testb $0x1, 0x18(%rax)
je 0x3957
movq 0x38(%rsp), %rax
movb $0x1, 0x18(%rax)
movq $0x0, 0x150(%rsp)
movl $0x0, 0x14c(%rsp)
movl $0x0, 0x148(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x158(%rsp), %rax
movq %rax, 0x150(%rsp)
movslq 0x14c(%rsp), %rax
movq %rax, 0x28(%rsp)
callq 0x7fb0
movq %rax, %rcx
movq 0x28(%rsp), %rax
cmpq %rcx, %rax
jae 0x3a1b
movq 0x48(%rsp), %rdi
movslq 0x148(%rsp), %rax
movq %rax, 0x20(%rsp)
callq 0x7fb0
movq %rax, %rcx
movq 0x20(%rsp), %rax
cmpq %rcx, %rax
jae 0x3a1b
movq 0x40(%rsp), %rdi
movslq 0x14c(%rsp), %rsi
callq 0x8120
movq 0x48(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x1c(%rsp)
movslq 0x148(%rsp), %rsi
callq 0x8120
movq %rax, %rcx
movl 0x1c(%rsp), %eax
addl (%rcx), %eax
cltq
addq 0x150(%rsp), %rax
movq %rax, 0x150(%rsp)
jmp 0x3aba
movq 0x40(%rsp), %rdi
movslq 0x14c(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0x7fb0
movq %rax, %rcx
movq 0x10(%rsp), %rax
cmpq %rcx, %rax
jae 0x3a66
movq 0x40(%rsp), %rdi
movslq 0x14c(%rsp), %rsi
callq 0x8120
movslq (%rax), %rax
addq 0x150(%rsp), %rax
movq %rax, 0x150(%rsp)
jmp 0x3ab8
movq 0x48(%rsp), %rdi
movslq 0x148(%rsp), %rax
movq %rax, 0x8(%rsp)
callq 0x7fb0
movq %rax, %rcx
movq 0x8(%rsp), %rax
cmpq %rcx, %rax
jae 0x3ab1
movq 0x48(%rsp), %rdi
movslq 0x148(%rsp), %rsi
callq 0x8120
movslq (%rax), %rax
addq 0x150(%rsp), %rax
movq %rax, 0x150(%rsp)
jmp 0x3ab6
jmp 0x3b55
jmp 0x3ab8
jmp 0x3aba
movq 0x38(%rsp), %rdi
movq 0x150(%rsp), %rax
movslq 0xb6aa(%rip), %rcx      # 0xf178
cqto
idivq %rcx
movl %eax, 0x158(%rsp)
movslq 0xb697(%rip), %rcx      # 0xf178
movq 0x150(%rsp), %rax
cqto
idivq %rcx
movq %rdx, 0x150(%rsp)
movl 0x150(%rsp), %eax
movl %eax, 0x144(%rsp)
leaq 0x144(%rsp), %rsi
callq 0x76f0
jmp 0x3b13
jmp 0x3b15
movl 0x14c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14c(%rsp)
movl 0x148(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x148(%rsp)
jmp 0x3979
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0x3e02
cmpl $0x0, 0x158(%rsp)
jle 0x3b75
movq 0x38(%rsp), %rdi
leaq 0x158(%rsp), %rsi
callq 0x7d60
jmp 0x3b73
jmp 0x3b75
jmp 0x3dd9
leaq 0x110(%rsp), %rdi
callq 0x2a10
jmp 0x3b89
movq 0x40(%rsp), %rax
testb $0x1, 0x18(%rax)
je 0x3cbe
movq 0x40(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
callq 0x3240
jmp 0x3bac
leaq 0x110(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x81f0
jmp 0x3bc3
leaq 0xf0(%rsp), %rdi
callq 0x2a80
leaq 0xb0(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x2a90
jmp 0x3be7
movq 0x48(%rsp), %rsi
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0x3e20
jmp 0x3c03
movq 0x38(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x81f0
jmp 0x3c17
leaq 0xd0(%rsp), %rdi
callq 0x2a80
leaq 0xb0(%rsp), %rdi
callq 0x2a80
jmp 0x3dbb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0x3dca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x2a80
jmp 0x3dca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0x3cac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x2a80
leaq 0xb0(%rsp), %rdi
callq 0x2a80
jmp 0x3dca
movq 0x48(%rsp), %rax
testb $0x1, 0x18(%rax)
je 0x3db9
movq 0x48(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x3240
jmp 0x3ce1
leaq 0x110(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x81f0
jmp 0x3cf8
leaq 0x90(%rsp), %rdi
callq 0x2a80
leaq 0x50(%rsp), %rdi
leaq 0x110(%rsp), %rsi
callq 0x2a90
jmp 0x3d19
movq 0x40(%rsp), %rsi
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x3e20
jmp 0x3d2f
movq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x81f0
jmp 0x3d40
leaq 0x70(%rsp), %rdi
callq 0x2a80
leaq 0x50(%rsp), %rdi
callq 0x2a80
jmp 0x3db9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x2a80
jmp 0x3dca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
jmp 0x3dad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x138(%rsp)
movl %eax, 0x134(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x2a80
leaq 0x50(%rsp), %rdi
callq 0x2a80
jmp 0x3dca
jmp 0x3dbb
leaq 0x110(%rsp), %rdi
callq 0x2a80
jmp 0x3dd9
leaq 0x110(%rsp), %rdi
callq 0x2a80
jmp 0x3e02
movb $0x1, 0x15f(%rsp)
testb $0x1, 0x15f(%rsp)
jne 0x3df5
movq 0x38(%rsp), %rdi
callq 0x2a80
movq 0x30(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
retq
movq 0x38(%rsp), %rdi
callq 0x2a80
movq 0x138(%rsp), %rdi
callq 0x2260
nopl (%rax)