// File: jeffchan[P]blockchain-parser/Base58.cpp
// Function: BigNumberEqualsAdditionByBigInt(BigNumber*, BigNumber*)
bool BigNumberEqualsAdditionByBigInt(BigNumber * a, BigNumber * b)
{
	if (a->length < b->length) 
	{
		// Make certain expansion of data is empty
		memset(a->data + a->length, 0, b->length - a->length);
		a->length = b->length;
	}
	// a->length >= b->length
	bool overflow = 0;
	uint8_t x = 0;
	for (; x < b->length; x++) 
	{
		a->data[x] += b->data[x] + overflow;
		// a->data[x] now equals the result of the addition.
		// The overflow will never go beyond 1. Imagine a->data[x] == 0xff, b->data[x] == 0xff and the overflow is 1, the new overflow is still 1 and a->data[x] is 0xff. Therefore it does work.
		overflow = (a->data[x] < (b->data[x] + overflow))? 1 : 0;
	}
	// Propagate overflow up the whole length of a if necessary
	while (overflow && x < a->length)
		overflow = ! ++a->data[x++]; // Index at x, increment x, increment data, test new value for overflow.
	if (overflow) 
	{ // Add extra byte
		a->length++;
		assert( a->length < MAX_BIG_NUMBER );
		a->data[a->length - 1] = 1;
	}
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x100(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x100(%rcx), %eax
jae 0x252a
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x100(%rax), %eax
addq %rax, %rdi
movq -0x10(%rbp), %rax
movl 0x100(%rax), %eax
movq -0x8(%rbp), %rcx
subl 0x100(%rcx), %eax
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x20b0
movq -0x10(%rbp), %rax
movl 0x100(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x100(%rax)
movb $0x0, -0x11(%rbp)
movb $0x0, -0x12(%rbp)
movzbl -0x12(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x100(%rcx), %eax
jae 0x25ac
movq -0x10(%rbp), %rax
movzbl -0x12(%rbp), %ecx
movzbl (%rax,%rcx), %esi
movb -0x11(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %esi
movq -0x8(%rbp), %rax
movzbl -0x12(%rbp), %ecx
movzbl (%rax,%rcx), %edx
addl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x8(%rbp), %rax
movzbl -0x12(%rbp), %ecx
movzbl (%rax,%rcx), %edx
movq -0x10(%rbp), %rax
movzbl -0x12(%rbp), %ecx
movzbl (%rax,%rcx), %esi
movb -0x11(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %esi
xorl %eax, %eax
movl $0x1, %ecx
cmpl %esi, %edx
cmovll %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x11(%rbp)
movb -0x12(%rbp), %al
addb $0x1, %al
movb %al, -0x12(%rbp)
jmp 0x2532
jmp 0x25ae
xorl %eax, %eax
testb $0x1, -0x11(%rbp)
movb %al, -0x13(%rbp)
je 0x25cd
movzbl -0x12(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x100(%rcx), %eax
setb %al
movb %al, -0x13(%rbp)
movb -0x13(%rbp), %al
testb $0x1, %al
jne 0x25d6
jmp 0x2600
movq -0x8(%rbp), %rcx
movb -0x12(%rbp), %al
movb %al, %dl
addb $0x1, %dl
movb %dl, -0x12(%rbp)
movzbl %al, %eax
movl %eax, %edx
movb (%rcx,%rdx), %al
addb $0x1, %al
movb %al, (%rcx,%rdx)
cmpb $0x0, %al
setne %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x11(%rbp)
jmp 0x25ae
testb $0x1, -0x11(%rbp)
je 0x2661
movq -0x8(%rbp), %rax
movl 0x100(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x100(%rax)
movq -0x8(%rbp), %rax
cmpl $0x100, 0x100(%rax)     # imm = 0x100
jae 0x262b
jmp 0x264a
leaq 0x2d9d2(%rip), %rdi     # 0x30004
leaq 0x2d9e6(%rip), %rsi     # 0x3001f
movl $0xb5, %edx
leaq 0x2d9e5(%rip), %rcx     # 0x3002a
callq 0x20c0
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x100(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movb $0x1, %al
andb $0x1, %al
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)