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

	p1 = pop();

	if (!istensor(p1)) {
		push(p1);
		return;
	}

	if (!issquarematrix(p1))
		stopf("det: square matrix expected");

	n = p1->u.tensor->dim[0];

	switch (n) {
	case 1:
		push(p1->u.tensor->elem[0]);
		return;
	case 2:
		push(p1->u.tensor->elem[0]);
		push(p1->u.tensor->elem[3]);
		multiply();
		push(p1->u.tensor->elem[1]);
		push(p1->u.tensor->elem[2]);
		multiply();
		subtract();
		return;
	case 3:
		push(p1->u.tensor->elem[0]);
		push(p1->u.tensor->elem[4]);
		push(p1->u.tensor->elem[8]);
		multiply_factors(3);
		push(p1->u.tensor->elem[1]);
		push(p1->u.tensor->elem[5]);
		push(p1->u.tensor->elem[6]);
		multiply_factors(3);
		push(p1->u.tensor->elem[2]);
		push(p1->u.tensor->elem[3]);
		push(p1->u.tensor->elem[7]);
		multiply_factors(3);
		push_integer(-1);
		push(p1->u.tensor->elem[2]);
		push(p1->u.tensor->elem[4]);
		push(p1->u.tensor->elem[6]);
		multiply_factors(4);
		push_integer(-1);
		push(p1->u.tensor->elem[1]);
		push(p1->u.tensor->elem[3]);
		push(p1->u.tensor->elem[8]);
		multiply_factors(4);
		push_integer(-1);
		push(p1->u.tensor->elem[0]);
		push(p1->u.tensor->elem[5]);
		push(p1->u.tensor->elem[7]);
		multiply_factors(4);
		add_terms(6);
		return;
	default:
		break;
	}

	p2 = alloc_matrix(n - 1, n - 1);

	h = tos;

	for (m = 0; m < n; m++) {
		if (iszero(p1->u.tensor->elem[m]))
			continue;
		k = 0;
		for (i = 1; i < n; i++)
			for (j = 0; j < n; j++)
				if (j != m)
					p2->u.tensor->elem[k++] = p1->u.tensor->elem[n * i + j];
		push(p2);
		det();
		push(p1->u.tensor->elem[m]);
		multiply();
		if (m % 2)
			negate();
	}

	n = tos - h;

	if (n == 0)
		push_integer(0);
	else
		add_terms(n);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
callq 0x868d
movq %rax, %rbx
cmpb $0x7, 0x10(%rax)
jne 0xb304
movq %rbx, %rdi
callq 0xb291
testl %eax, %eax
je 0xb5b8
movq (%rbx), %rax
movslq 0x4(%rax), %r15
cmpq $0x3, %r15
je 0xb367
cmpl $0x2, %r15d
je 0xb31a
cmpl $0x1, %r15d
jne 0xb4bc
movq 0x68(%rax), %rdi
jmp 0xb307
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x861b
movq 0x68(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x861b
callq 0x9fae
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x861b
callq 0x9fae
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb07f
movq 0x68(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x88(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0xa8(%rax), %rdi
callq 0x861b
pushq $0x3
popq %r14
movl %r14d, %edi
callq 0xa04c
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x90(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x98(%rax), %rdi
callq 0x861b
movl %r14d, %edi
callq 0xa04c
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0xa0(%rax), %rdi
callq 0x861b
movl %r14d, %edi
callq 0xa04c
pushq $-0x1
popq %r14
movl %r14d, %edi
callq 0xa426
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x88(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x98(%rax), %rdi
callq 0x861b
pushq $0x4
popq %r15
movl %r15d, %edi
callq 0xa04c
movl %r14d, %edi
callq 0xa426
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0xa8(%rax), %rdi
callq 0x861b
movl %r15d, %edi
callq 0xa04c
movl %r14d, %edi
callq 0xa426
movq (%rbx), %rax
movq 0x68(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0x90(%rax), %rdi
callq 0x861b
movq (%rbx), %rax
movq 0xa0(%rax), %rdi
callq 0x861b
movl %r15d, %edi
callq 0xa04c
pushq $0x6
popq %rdi
jmp 0xb5a5
movl %r15d, %r12d
leal -0x1(%r12), %edi
movl %edi, %esi
callq 0x782d
movq %rax, %r14
xorl %r13d, %r13d
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
movq %rax, -0x40(%rbp)
movl 0x2cdc1(%rip), %eax     # 0x382a8
movl %eax, -0x2c(%rbp)
leaq 0x68(,%r15,8), %rax
movq %rax, -0x38(%rbp)
shlq $0x3, %r15
cmpq -0x40(%rbp), %r13
je 0xb585
movq (%rbx), %rax
movq 0x68(%rax,%r13,8), %rdi
callq 0xa641
testl %eax, %eax
jne 0xb57d
xorl %eax, %eax
movq -0x38(%rbp), %rcx
pushq $0x1
popq %rdx
cmpq %r12, %rdx
je 0xb553
xorl %esi, %esi
cmpq %rsi, %r12
je 0xb54b
cmpq %rsi, %r13
je 0xb546
movq (%rbx), %rdi
addq %rcx, %rdi
movq (%rdi,%rsi,8), %rdi
movq (%r14), %r8
movslq %eax, %r9
incl %eax
movq %rdi, 0x68(%r8,%r9,8)
incq %rsi
jmp 0xb525
incq %rdx
addq %r15, %rcx
jmp 0xb51e
movq %r14, %rdi
callq 0x861b
callq 0xb2b2
movq (%rbx), %rax
movq 0x68(%rax,%r13,8), %rdi
callq 0x861b
callq 0x9fae
testb $0x1, %r13b
je 0xb57d
callq 0x975f
incq %r13
jmp 0xb4fa
movl 0x2cd1d(%rip), %edi     # 0x382a8
subl -0x2c(%rbp), %edi
jne 0xb5a5
xorl %edi, %edi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa426
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa0fd
leaq 0x17d82(%rip), %rdi     # 0x23341
callq 0x7756