// File: /workspace/github_c_makefile_star2_O2/georgeweigt[P]eigenmath/eigenmath.c
// Function: decomp_sum
void
decomp_sum(struct atom *F, struct atom *X)
{
	int h, i, j, k, n;
	struct atom *p1, *p2;

	h = tos;

	// partition terms

	p1 = cdr(F);

	while (iscons(p1)) {
		p2 = car(p1);
		if (dependent(p2, X)) {
			if (car(p2) == symbol(MULTIPLY)) {
				push(p2);
				push(X);
				partition_term();	// push const part then push var part
			} else {
				push_integer(1);	// const part
				push(p2);		// var part
			}
		}
		p1 = cdr(p1);
	}

	// combine const parts of matching var parts

	n = tos - h;

	for (i = 0; i < n - 2; i += 2)
		for (j = i + 2; j < n; j += 2) {
			if (!equal(stack[h + i + 1], stack[h + j + 1]))
				continue;
			push(stack[h + i]); // add const parts
			push(stack[h + j]);
			add();
			stack[h + i] = pop();
			for (k = j; k < n - 2; k++)
				stack[h + k] = stack[h + k + 2];
			j -= 2; // use same j again
			n -= 2;
			tos -= 2; // pop
		}

	// push const parts, decomp var parts

	list(tos - h);
	p1 = pop();

	while (iscons(p1)) {
		push(car(p1)); // const part
		push(cadr(p1)); // var part
		push(X);
		decomp();
		p1 = cddr(p1);
	}

	// add together all constant terms

	h = tos;
	p1 = cdr(F);
	while (iscons(p1)) {
		if (!dependent(car(p1), X))
			push(car(p1));
		p1 = cdr(p1);
	}

	n = tos - h;

	if (n > 1) {
		list(n);
		push_symbol(ADD);
		swap();
		cons(); // makes ADD head of list
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movslq 0x236a2(%rip), %rax     # 0x382a8
movq %rax, -0x30(%rbp)
leaq 0x8(%rdi), %rcx
movq %rdi, -0x40(%rbp)
cmpb $0x1, 0x10(%rdi)
leaq 0x29dd3(%rip), %r15     # 0x3e9f0
movq %r15, %rax
movq %rcx, -0x48(%rbp)
cmoveq %rcx, %rax
pushq $0x1
popq %r13
movq (%rax), %rbx
cmpb $0x1, 0x10(%rbx)
jne 0x14c95
movq (%rbx), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x14b61
testl %eax, %eax
je 0x14c87
cmpb $0x1, 0x10(%r12)
movq %r15, %rax
cmoveq %r12, %rax
movq (%rax), %rax
cmpq 0x2c63a(%rip), %rax     # 0x41298
je 0x14c72
movl %r13d, %edi
callq 0xa426
movq %r12, %rdi
callq 0x861b
jmp 0x14c87
movq %r12, %rdi
callq 0x861b
movq %r14, %rdi
callq 0x861b
callq 0x14284
leaq 0x8(%rbx), %rax
cmpb $0x1, 0x10(%rbx)
cmovneq %r15, %rax
jmp 0x14c2c
movq %r14, -0x50(%rbp)
movl 0x23609(%rip), %ecx     # 0x382a8
movq -0x30(%rbp), %rax
subl %eax, %ecx
movq %rcx, -0x38(%rbp)
leaq 0x2c900(%rip), %r14     # 0x415b0
leaq (%r14,%rax,8), %r13
addq $0x10, %r13
xorl %r12d, %r12d
movq -0x38(%rbp), %rax
addl $-0x2, %eax
cltq
cmpq %rax, %r12
jge 0x14d5c
leaq 0x2(%r12), %r15
addq -0x30(%rbp), %r12
movq %r15, -0x58(%rbp)
cmpl -0x38(%rbp), %r15d
jge 0x14d53
movq 0x8(%r14,%r12,8), %rdi
movq -0x30(%rbp), %rax
addl %r15d, %eax
movslq %eax, %rbx
movq 0x8(%r14,%rbx,8), %rsi
callq 0x8760
testl %eax, %eax
jne 0x14d4d
movq (%r14,%r12,8), %rdi
callq 0x861b
movq (%r14,%rbx,8), %rdi
callq 0x861b
callq 0xa1f6
callq 0x868d
movq %rax, (%r14,%r12,8)
movq -0x38(%rbp), %rcx
addl $-0x2, %ecx
movslq %r15d, %rax
movq %rcx, -0x38(%rbp)
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x14d42
movq (%r13,%rax,8), %rdx
movq %rdx, -0x10(%r13,%rax,8)
incq %rax
jmp 0x14d2e
addl $-0x2, %r15d
addl $-0x2, 0x2355b(%rip)    # 0x382a8
addl $0x2, %r15d
jmp 0x14cda
movq -0x58(%rbp), %r12
jmp 0x14cbb
movl 0x23546(%rip), %edi     # 0x382a8
subl -0x30(%rbp), %edi
callq 0x85eb
callq 0x868d
movq %rax, %r15
movq -0x50(%rbp), %r12
leaq 0x29c73(%rip), %r13     # 0x3e9f0
cmpb $0x1, 0x10(%r15)
jne 0x14dd9
movq (%r15), %rdi
callq 0x861b
cmpb $0x1, 0x10(%r15)
leaq 0x8(%r15), %rbx
movq %r13, %rax
cmoveq %rbx, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %r13, %rax
movq (%rax), %rdi
callq 0x861b
movq %r12, %rdi
callq 0x861b
callq 0x14878
cmpb $0x1, 0x10(%r15)
cmovneq %r13, %rbx
movq (%rbx), %rax
cmpb $0x1, 0x10(%rax)
leaq 0x8(%rax), %rax
cmovneq %r13, %rax
movq (%rax), %r15
jmp 0x14d7d
movl 0x234c9(%rip), %ebx     # 0x382a8
movq -0x40(%rbp), %rax
cmpb $0x1, 0x10(%rax)
movq -0x48(%rbp), %rax
cmovneq %r13, %rax
movq (%rax), %r14
cmpb $0x1, 0x10(%r14)
jne 0x14e27
movq (%r14), %rdi
movq %r12, %rsi
callq 0x14b61
testl %eax, %eax
jne 0x14e1c
cmpb $0x1, 0x10(%r14)
movq %r13, %rax
cmoveq %r14, %rax
movq (%rax), %rdi
callq 0x861b
leaq 0x8(%r14), %rax
cmpb $0x1, 0x10(%r14)
jmp 0x14deb
movl 0x2347b(%rip), %edi     # 0x382a8
subl %ebx, %edi
cmpl $0x2, %edi
jl 0x14e5d
callq 0x85eb
movq 0x2c450(%rip), %rdi     # 0x41290
callq 0x861b
callq 0xa49b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x865c
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq