// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
callq 0x27ac
addq $-0x4, 0x8(%rbx)
movl $0x0, 0x4(%rsp)
movb 0x18(%r15), %al
cmpb 0x18(%r14), %al
jne 0x3116
testb %al, %al
je 0x3088
movb $0x1, 0x18(%rbx)
xorl %r12d, %r12d
leaq 0x28(%rsp), %r13
xorl %ebp, %ebp
movq (%r15), %rcx
movq 0x8(%r15), %rsi
subq %rcx, %rsi
sarq $0x2, %rsi
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %rbp, %rsi
jbe 0x30c0
movl (%rcx,%rbp,4), %ecx
cmpq %rbp, %rdx
jbe 0x30cc
addl (%rax,%rbp,4), %ecx
jmp 0x30cc
cmpq %rbp, %rdx
jbe 0x31ac
movl (%rax,%rbp,4), %ecx
movslq %r12d, %rdx
movslq %ecx, %rax
addq %rdx, %rax
movslq 0x600c(%rip), %rcx      # 0x90e8
cqto
idivq %rcx
movq %rax, %r12
movl %r12d, 0x4(%rsp)
movl %edx, 0x28(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3103
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x310e
movq %rbx, %rdi
movq %r13, %rdx
callq 0x56c6
incq %rbp
jmp 0x3092
leaq 0x28(%rsp), %rdi
callq 0x27ac
cmpb $0x1, 0x18(%r15)
jne 0x31d3
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x2c0c
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x5412
movb 0x20(%rsp), %al
movb %al, 0x40(%rsp)
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x315e
callq 0x20b0
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2806
leaq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %rdx
movq %r14, %rsi
callq 0x3320
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5412
movb 0x20(%rsp), %al
movb %al, 0x18(%rbx)
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x31a2
callq 0x20b0
movq 0x68(%rsp), %rdi
jmp 0x325a
testl %r12d, %r12d
jle 0x3282
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3275
movl %r12d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3282
cmpb $0x1, 0x18(%r14)
jne 0x3264
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x2c0c
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x5412
movb 0x20(%rsp), %al
movb %al, 0x40(%rsp)
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x3211
callq 0x20b0
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2806
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movq %r15, %rsi
callq 0x3320
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5412
movb 0x20(%rsp), %al
movb %al, 0x18(%rbx)
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x3255
callq 0x20b0
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3264
callq 0x20b0
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3282
callq 0x20b0
jmp 0x3282
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
callq 0x57fa
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3307
movq %rax, %r14
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x32b0
callq 0x20b0
jmp 0x32b0
movq %rax, %r14
movq 0x48(%rsp), %rdi
jmp 0x32e5
jmp 0x32f1
jmp 0x32dd
jmp 0x32f1
movq %rax, %r14
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x32d4
callq 0x20b0
jmp 0x32d4
movq %rax, %r14
movq 0x68(%rsp), %rdi
jmp 0x32e5
jmp 0x32f1
movq %rax, %r14
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x32f4
callq 0x20b0
jmp 0x32f4
movq %rax, %r14
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x330a
callq 0x20b0
jmp 0x330a
jmp 0x3307
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x3317
callq 0x20b0
movq %r14, %rdi
callq 0x2180
nop