// File: /workspace/github_c_makefile_star2_O3/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 0x3d0a8(%rip), %r15     # 0x485c0
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 0xb57b
cmpb $0x4, %al
jne 0xb6af
movq %rbx, %rdi
callq 0xb79b
movl 0x33d68(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0xb78f
decl %eax
movl %eax, 0x33d50(%rip)     # 0x3f2b8
movq (%r15,%rax,8), %r14
movq %r14, (%r15,%r13,8)
movl $0x1, %r14d
jmp 0xb6af
cmpb $0x4, %al
je 0xb6af
movq 0x10054e(%rip), %rcx    # 0x10bad8
cmpb $0x1, %r8b
leaq 0x3a46b(%rip), %rax     # 0x45a00
movq %rax, %r9
cmoveq %rbx, %r9
movq 0x3cd05(%rip), %rdi     # 0x482a8
movb $0x1, %r12b
cmpq %rdi, (%r9)
jne 0xb625
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, -0x30(%rbp)
movb 0x10(%r9), %r9b
andb $-0x2, %r9b
cmpb $0x4, %r9b
jne 0xb622
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 0x3a3fb(%rip), %rbx     # 0x45a00
cmpq %rbx, (%r9)
sete %r9b
setne %r11b
cmovneq %r8, %rbx
orb %r10b, %r11b
je 0xb750
movl %r9d, %r12d
jmp 0xb629
xorl %r12d, %r12d
movq %rcx, -0x30(%rbp)
movl %r12d, -0x34(%rbp)
cmpb $0x1, %dl
movq %rax, %r8
cmoveq %rsi, %r8
cmpq %rdi, (%r8)
jne 0xb6a0
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 0xb6a0
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 0x3a373(%rip), %rsi     # 0x45a00
cmpq %rsi, (%rdx)
setne %dl
cmovneq %rcx, %rsi
orb %al, %dl
jne 0xb6a3
movq (%rcx), %rsi
jmp 0xb6a3
movq %rcx, %r12
movq %rbx, %rdi
callq 0x8d48
testl %eax, %eax
je 0xb6c1
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0xb79b
movl 0x33be5(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0xb78f
decl %eax
movl %eax, 0x33bcd(%rip)     # 0x3f2b8
movq (%r15,%rax,8), %r14
movq %r14, %rdi
callq 0xb477
testl %eax, %eax
movl -0x34(%rbp), %r12d
jne 0xb56c
movq %r14, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xd1c4
testl %eax, %eax
je 0xb720
cmpb $0x5, 0x10(%r14)
jne 0xb75f
movq 0x3cb81(%rip), %rdi     # 0x482a8
callq 0x8ba5
movq %r14, %rdi
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
testb %r12b, %r12b
je 0xb758
movl $0x3, %edi
callq 0x8b7d
jmp 0xb54a
movq (%r8), %rbx
jmp 0xb629
callq 0x8be6
jmp 0xb785
testb %r12b, %r12b
je 0xb771
movq %rbx, %rdi
callq 0x8ba5
jmp 0xb54a
movq 0x3cb30(%rip), %rdi     # 0x482a8
callq 0x8ba5
movq %rbx, %rdi
callq 0x8ba5
callq 0x8be6
jmp 0xb54a
leaq 0x237ab(%rip), %rdi     # 0x2ef41
callq 0x780b