// File: /workspace/github_c_makefile_star2_O1/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 0x38651(%rip), %r15     # 0x435c0
movq (%r15,%r13,8), %rbx
movq 0x8(%r15,%r13,8), %rsi
movb 0x10(%rbx), %r8b
movl %r8d, %eax
andb $-0x2, %al
cmpb $0x4, %al
jne 0xafba
movb 0x10(%rsi), %cl
andb $-0x2, %cl
cmpb $0x4, %cl
jne 0xafaf
movq %rbx, %rdi
callq 0xb1bc
callq 0x8b78
movq %rax, %r14
movq %r14, (%r15,%r13,8)
movl $0x1, %r14d
jmp 0xb0f8
xorl %r14d, %r14d
cmpb $0x4, %al
je 0xb0f8
movb 0x10(%rsi), %dl
movl %edx, %eax
andb $-0x2, %al
xorl %r14d, %r14d
cmpb $0x4, %al
je 0xb0f8
movq 0xfbb05(%rip), %rcx     # 0x106ad8
cmpb $0x1, %r8b
leaq 0x35a22(%rip), %rax     # 0x40a00
movq %rax, %r9
cmoveq %rbx, %r9
movq 0x382bc(%rip), %rdi     # 0x432a8
movb $0x1, %r12b
cmpq %rdi, (%r9)
jne 0xb06e
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 0xb06b
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 0x359b2(%rip), %rbx     # 0x40a00
cmpq %rbx, (%r9)
sete %r9b
setne %r11b
cmovneq %r8, %rbx
orb %r10b, %r11b
je 0xb17c
movl %r9d, %r12d
jmp 0xb072
xorl %r12d, %r12d
movq %rcx, -0x38(%rbp)
movl %r12d, -0x2c(%rbp)
cmpb $0x1, %dl
movq %rax, %r8
cmoveq %rsi, %r8
cmpq %rdi, (%r8)
jne 0xb0e9
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 0xb0e9
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 0x3592a(%rip), %rsi     # 0x40a00
cmpq %rsi, (%rdx)
setne %dl
cmovneq %rcx, %rsi
orb %al, %dl
jne 0xb0ec
movq (%rcx), %rsi
jmp 0xb0ec
movq %rcx, %r12
movq %rbx, %rdi
callq 0x8c79
testl %eax, %eax
je 0xb10a
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 0xb1bc
callq 0x8b78
movq %rax, %r14
movq %rax, %rdi
callq 0xaece
testl %eax, %eax
jne 0xafa0
movq %r14, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xcb82
testl %eax, %eax
je 0xb14b
cmpb $0x5, 0x10(%r14)
jne 0xb18b
movq 0x38156(%rip), %rdi     # 0x432a8
callq 0x8b01
movq %r14, %rdi
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
cmpb $0x0, -0x2c(%rbp)
je 0xb184
movl $0x3, %edi
callq 0x8ad9
jmp 0xaf98
movq (%r8), %rbx
jmp 0xb072
callq 0x8b47
jmp 0xb1b2
cmpb $0x0, -0x2c(%rbp)
je 0xb19e
movq %rbx, %rdi
callq 0x8b01
jmp 0xaf98
movq 0x38103(%rip), %rdi     # 0x432a8
callq 0x8b01
movq %rbx, %rdi
callq 0x8b01
callq 0x8b47
jmp 0xaf98