// File: /workspace/github_c_makefile_star2_O1/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, %r12
leaq 0x8(%rdi), %rcx
movq %rdi, -0x40(%rbp)
cmpb $0x1, 0x10(%rdi)
leaq 0x29d8b(%rip), %rax     # 0x40a00
movq %rcx, -0x48(%rbp)
cmoveq %rcx, %rax
movslq 0x23634(%rip), %rcx     # 0x3a2b8
movq %rcx, -0x30(%rbp)
movq (%rax), %rbx
cmpb $0x1, 0x10(%rbx)
jne 0x16d0e
leaq 0x10(%rbx), %r14
movq (%rbx), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x16ba1
testl %eax, %eax
je 0x16cee
cmpb $0x1, 0x10(%r15)
leaq 0x29d4d(%rip), %rax     # 0x40a00
cmoveq %r15, %rax
movq (%rax), %rax
cmpq 0x2c5e7(%rip), %rax     # 0x432a8
je 0x16cd9
movq 0xefe0e(%rip), %rdi     # 0x106ad8
callq 0x8b01
movq %r15, %rdi
callq 0x8b01
jmp 0x16cee
movq %r15, %rdi
callq 0x8b01
movq %r12, %rdi
callq 0x8b01
callq 0x16162
addq $0x8, %rbx
cmpb $0x1, (%r14)
leaq 0x29d03(%rip), %rax     # 0x40a00
cmovneq %rax, %rbx
movq (%rbx), %rbx
leaq 0x10(%rbx), %r14
cmpb $0x1, 0x10(%rbx)
je 0x16c95
movq %r12, -0x50(%rbp)
movl 0x235a0(%rip), %edi     # 0x3a2b8
subl -0x30(%rbp), %edi
cmpl $0x3, %edi
jl 0x16dec
leaq 0x2c895(%rip), %r15     # 0x435c0
movq -0x30(%rbp), %rax
leaq (%r15,%rax,8), %rbx
addq $0x10, %rbx
xorl %r12d, %r12d
leaq 0x2(%r12), %r14
movslq %edi, %rax
cmpq %rax, %r14
movq %r14, -0x58(%rbp)
jge 0x16dda
addq -0x30(%rbp), %r12
movq %rdi, -0x38(%rbp)
movq 0x8(%r15,%r12,8), %rdi
movq -0x30(%rbp), %rax
addl %r14d, %eax
movslq %eax, %r13
movq 0x8(%r15,%r13,8), %rsi
callq 0x8c79
testl %eax, %eax
je 0x16d7a
movq -0x38(%rbp), %rdi
jmp 0x16dcd
movq (%r15,%r12,8), %rdi
callq 0x8b01
movq (%r15,%r13,8), %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa975
callq 0x8b78
movq %rax, (%r15,%r12,8)
movq -0x38(%rbp), %rdi
addl $-0x2, %edi
cmpl %edi, %r14d
jge 0x16dc2
movslq %r14d, %rax
movslq %edi, %rcx
movq (%rbx,%rax,8), %rdx
movq %rdx, -0x10(%rbx,%rax,8)
incq %rax
cmpq %rax, %rcx
jne 0x16db1
addl $-0x2, %r14d
addl $-0x2, 0x234eb(%rip)    # 0x3a2b8
addl $0x2, %r14d
cmpl %edi, %r14d
jl 0x16d53
leal -0x2(%rdi), %eax
cltq
movq -0x58(%rbp), %r12
cmpq %rax, %r12
jl 0x16d3a
movl 0x234c6(%rip), %edi     # 0x3a2b8
subl -0x30(%rbp), %edi
callq 0x8ad9
callq 0x8b78
cmpb $0x1, 0x10(%rax)
movq -0x50(%rbp), %r12
leaq 0x29bf2(%rip), %r14     # 0x40a00
jne 0x16e6d
movq %rax, %r15
movq (%r15), %rdi
callq 0x8b01
cmpb $0x1, 0x10(%r15)
leaq 0x8(%r15), %rbx
movq %r14, %rax
cmoveq %rbx, %rax
movq (%rax), %rax
cmpb $0x1, 0x10(%rax)
cmovneq %r14, %rax
movq (%rax), %rdi
callq 0x8b01
movq %r12, %rdi
callq 0x8b01
callq 0x167e8
cmpb $0x1, 0x10(%r15)
cmovneq %r14, %rbx
movq (%rbx), %rax
leaq 0x8(%rax), %rcx
cmpb $0x1, 0x10(%rax)
cmovneq %r14, %rcx
movq (%rcx), %r15
cmpb $0x1, 0x10(%r15)
je 0x16e13
movq -0x40(%rbp), %rax
cmpb $0x1, 0x10(%rax)
movq -0x48(%rbp), %rax
cmovneq %r14, %rax
movl 0x23435(%rip), %ebx     # 0x3a2b8
movq (%rax), %r14
cmpb $0x1, 0x10(%r14)
jne 0x16ed8
leaq 0x10(%r14), %r15
movq (%r14), %rdi
movq %r12, %rsi
callq 0x16ba1
testl %eax, %eax
jne 0x16eb7
cmpb $0x1, (%r15)
leaq 0x29b55(%rip), %rax     # 0x40a00
cmoveq %r14, %rax
movq (%rax), %rdi
callq 0x8b01
addq $0x8, %r14
cmpb $0x1, (%r15)
leaq 0x29b3a(%rip), %rax     # 0x40a00
cmovneq %rax, %r14
movq (%r14), %r14
leaq 0x10(%r14), %r15
cmpb $0x1, 0x10(%r14)
je 0x16e91
movl 0x233da(%rip), %edi     # 0x3a2b8
subl %ebx, %edi
cmpl $0x2, %edi
jl 0x16f0e
callq 0x8ad9
movq 0x2c3af(%rip), %rdi     # 0x432a0
callq 0x8b01
callq 0xad38
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b47
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq