// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: combine_terms_nib
int
combine_terms_nib(int i)
{
	int denorm;
	struct atom *coeff1, *coeff2, *p1, *p2;

	p1 = stack[i];
	p2 = stack[i + 1];

	if (isnum(p1) && isnum(p2)) {
		add_numbers(p1, p2);
		stack[i] = pop();
		return 1;
	}

	if (isnum(p1) || isnum(p2))
		return 0; // cannot add number and something else

	coeff1 = one;
	coeff2 = one;

	denorm = 0;

	if (car(p1) == symbol(MULTIPLY)) {
		p1 = cdr(p1);
		denorm = 1;
		if (isnum(car(p1))) {
			coeff1 = car(p1);
			p1 = cdr(p1);
			if (cdr(p1) == symbol(NIL)) {
				p1 = car(p1);
				denorm = 0;
			}
		}
	}

	if (car(p2) == symbol(MULTIPLY)) {
		p2 = cdr(p2);
		if (isnum(car(p2))) {
			coeff2 = car(p2);
			p2 = cdr(p2);
			if (cdr(p2) == symbol(NIL))
				p2 = car(p2);
		}
	}

	if (!equal(p1, p2))
		return 0;

	add_numbers(coeff1, coeff2);

	coeff1 = pop();

	if (iszero(coeff1)) {
		stack[i] = coeff1;
		return 1;
	}

	if (isplusone(coeff1) && !isdouble(coeff1)) {
		if (denorm) {
			push_symbol(MULTIPLY);
			push(p1); // p1 is a list, not an atom
			cons(); // prepend MULTIPLY
		} else
			push(p1);
	} else {
		if (denorm) {
			push_symbol(MULTIPLY);
			push(coeff1);
			push(p1); // p1 is a list, not an atom
			cons(); // prepend coeff1
			cons(); // prepend MULTIPLY
		} else {
			push_symbol(MULTIPLY);
			push(coeff1);
			push(p1);
			list(3);
		}
	}

	stack[i] = pop();

	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movslq %edi, %r13
leaq 0x36ed8(%rip), %r15     # 0x415b0
movq (%r15,%r13,8), %rbx
movq 0x8(%r15,%r13,8), %rsi
movb 0x10(%rbx), %r8b
movl %r8d, %ecx
andb $-0x2, %cl
movb 0x10(%rsi), %dl
movl %edx, %eax
andb $-0x2, %al
xorl %r14d, %r14d
cmpb $0x4, %cl
jne 0xa71f
cmpb $0x4, %al
jne 0xa853
movq %rbx, %rdi
callq 0xa90b
callq 0x868d
movq %rax, %r14
movq %r14, (%r15,%r13,8)
pushq $0x1
popq %r14
jmp 0xa853
cmpb $0x4, %al
je 0xa853
movq 0xfa39a(%rip), %rcx     # 0x104ac8
cmpb $0x1, %r8b
leaq 0x342b7(%rip), %rax     # 0x3e9f0
movq %rax, %r9
cmoveq %rbx, %r9
movq 0x36b51(%rip), %rdi     # 0x41298
movb $0x1, %r12b
cmpq %rdi, (%r9)
jne 0xa7c9
addq $0x8, %rbx
cmpb $0x1, %r8b
cmovneq %rax, %rbx
movq (%rbx), %rbx
movb 0x10(%rbx), %r8b
cmpb $0x1, %r8b
movq %rax, %r9
cmoveq %rbx, %r9
movq (%r9), %r9
movq %r9, -0x38(%rbp)
movb 0x10(%r9), %r9b
andb $-0x2, %r9b
cmpb $0x4, %r9b
jne 0xa7c6
addq $0x8, %rbx
cmpb $0x1, %r8b
cmovneq %rax, %rbx
movq (%rbx), %r8
cmpb $0x1, 0x10(%r8)
leaq 0x8(%r8), %r9
setne %r10b
cmovneq %rax, %r9
movq 0x34247(%rip), %rbx     # 0x3e9f0
cmpq %rbx, (%r9)
sete %r9b
setne %r11b
cmovneq %r8, %rbx
orb %r10b, %r11b
je 0xa8cb
movl %r9d, %r12d
jmp 0xa7cd
xorl %r12d, %r12d
movq %rcx, -0x38(%rbp)
movl %r12d, -0x2c(%rbp)
cmpb $0x1, %dl
movq %rax, %r8
cmoveq %rsi, %r8
cmpq %rdi, (%r8)
jne 0xa844
addq $0x8, %rsi
cmpb $0x1, %dl
cmovneq %rax, %rsi
movq (%rsi), %rsi
movb 0x10(%rsi), %dl
cmpb $0x1, %dl
movq %rax, %rdi
cmoveq %rsi, %rdi
movq (%rdi), %r12
movb 0x10(%r12), %dil
andb $-0x2, %dil
cmpb $0x4, %dil
jne 0xa844
addq $0x8, %rsi
cmpb $0x1, %dl
cmovneq %rax, %rsi
movq (%rsi), %rcx
leaq 0x8(%rcx), %rdx
cmpb $0x1, 0x10(%rcx)
cmovneq %rax, %rdx
setne %al
movq 0x341bf(%rip), %rsi     # 0x3e9f0
cmpq %rsi, (%rdx)
setne %dl
cmovneq %rcx, %rsi
orb %al, %dl
jne 0xa847
movq (%rcx), %rsi
jmp 0xa847
movq %rcx, %r12
movq %rbx, %rdi
callq 0x8760
testl %eax, %eax
je 0xa865
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rdi
movq %r12, %rsi
callq 0xa90b
callq 0x868d
movq %rax, %r14
movq %rax, %rdi
callq 0xa641
testl %eax, %eax
jne 0xa712
movq %r14, %rdi
callq 0xa95a
testl %eax, %eax
je 0xa89c
cmpb $0x5, 0x10(%r14)
jne 0xa8da
movq 0x369f5(%rip), %rdi     # 0x41298
callq 0x861b
movq %r14, %rdi
callq 0x861b
movq %rbx, %rdi
callq 0x861b
cmpb $0x0, -0x2c(%rbp)
je 0xa8d3
pushq $0x3
popq %rdi
callq 0x85eb
jmp 0xa70a
movq (%r8), %rbx
jmp 0xa7cd
callq 0x865c
jmp 0xa901
cmpb $0x0, -0x2c(%rbp)
je 0xa8ed
movq %rbx, %rdi
callq 0x861b
jmp 0xa70a
movq 0x369a4(%rip), %rdi     # 0x41298
callq 0x861b
movq %rbx, %rdi
callq 0x861b
callq 0x865c
jmp 0xa70a