// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x90, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
callq 0x27ac
addq $-0x4, 0x8(%rbx)
movl $0x0, 0xc(%rsp)
movb 0x18(%r15), %al
cmpb 0x18(%r14), %al
jne 0x31fb
testb %al, %al
je 0x3159
movb $0x1, 0x18(%rbx)
xorl %r13d, %r13d
leaq 0x30(%rsp), %r12
movl 0xc(%rsp), %eax
movq (%r15), %rcx
movq 0x8(%r15), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %r13, %rdx
jbe 0x319a
movq (%r14), %rsi
movq 0x8(%r14), %rdi
subq %rsi, %rdi
sarq $0x2, %rdi
cmpq %r13, %rdi
jbe 0x3195
movl (%rsi,%r13,4), %edx
addl (%rcx,%r13,4), %edx
jmp 0x31b5
cmpq %r13, %rdx
ja 0x31b1
movq (%r14), %rcx
movq 0x8(%r14), %rdx
subq %rcx, %rdx
sarq $0x2, %rdx
cmpq %r13, %rdx
jbe 0x3291
movl (%rcx,%r13,4), %edx
movslq %eax, %rcx
movslq %edx, %rax
addq %rcx, %rax
movslq 0x5f23(%rip), %rcx      # 0x90e8
cqto
idivq %rcx
movl %eax, 0xc(%rsp)
movl %edx, 0x30(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x31e8
movl %edx, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x31f3
movq %rbx, %rdi
movq %r12, %rdx
callq 0x57c4
incq %r13
jmp 0x3161
leaq 0x30(%rsp), %rdi
callq 0x27ac
cmpb $0x1, 0x18(%r15)
jne 0x32b6
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x2cde
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x551e
movb 0x28(%rsp), %al
movb %al, 0x48(%rsp)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3243
callq 0x20b0
leaq 0x70(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2822
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
movq %r14, %rsi
callq 0x3402
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x551e
movb 0x28(%rsp), %al
movb %al, 0x18(%rbx)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3287
callq 0x20b0
movq 0x70(%rsp), %rdi
jmp 0x333d
testl %eax, %eax
jle 0x3365
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x3358
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x3365
cmpb $0x1, 0x18(%r14)
jne 0x3347
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x2cde
leaq 0x30(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x551e
movb 0x28(%rsp), %al
movb %al, 0x48(%rsp)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x32f4
callq 0x20b0
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x2822
leaq 0x10(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %r15, %rsi
callq 0x3402
leaq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x551e
movb 0x28(%rsp), %al
movb %al, 0x18(%rbx)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3338
callq 0x20b0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x3347
callq 0x20b0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3365
callq 0x20b0
jmp 0x3365
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x58f8
movq %rbx, %rax
addq $0x90, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x33e9
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3392
callq 0x20b0
jmp 0x3392
movq %rax, %r14
movq 0x50(%rsp), %rdi
jmp 0x33c7
jmp 0x33d3
jmp 0x33bf
jmp 0x33d3
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x33b6
callq 0x20b0
jmp 0x33b6
movq %rax, %r14
movq 0x70(%rsp), %rdi
jmp 0x33c7
jmp 0x33d3
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x33d6
callq 0x20b0
jmp 0x33d6
movq %rax, %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x33ec
callq 0x20b0
jmp 0x33ec
jmp 0x33e9
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x33f9
callq 0x20b0
movq %r14, %rdi
callq 0x2180
nop