// File: /workspace/github_c_makefile_star2_O1/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 0x8b78
movq %rax, %rbx
cmpb $0x7, 0x10(%rax)
jne 0xbd61
movq (%rbx), %rax
cmpl $0x2, (%rax)
jne 0xc051
movl 0x4(%rax), %ecx
cmpl 0x8(%rax), %ecx
jne 0xc051
movq (%rbx), %rax
movl 0x4(%rax), %r15d
cmpq $0x3, %r15
je 0xbdce
cmpl $0x2, %r15d
je 0xbd77
cmpl $0x1, %r15d
jne 0xbf31
movq 0x68(%rax), %rdi
jmp 0xbd64
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8b01
movq 0x68(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xba6d
movq 0x68(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x88(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0xa8(%rax), %rdi
callq 0x8b01
movl $0x3, %edi
callq 0xa8bb
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x90(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x98(%rax), %rdi
callq 0x8b01
movl $0x3, %edi
callq 0xa8bb
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0xa0(%rax), %rdi
callq 0x8b01
movl $0x3, %edi
callq 0xa8bb
movq 0x105582(%rip), %rdi    # 0x1113f0
callq 0x8b01
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x88(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x98(%rax), %rdi
callq 0x8b01
movl $0x4, %edi
callq 0xa8bb
movq 0x105542(%rip), %rdi    # 0x1113f0
callq 0x8b01
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0xa8(%rax), %rdi
callq 0x8b01
movl $0x4, %edi
callq 0xa8bb
movq 0x105502(%rip), %rdi    # 0x1113f0
callq 0x8b01
movq (%rbx), %rax
movq 0x68(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0x90(%rax), %rdi
callq 0x8b01
movq (%rbx), %rax
movq 0xa0(%rax), %rdi
callq 0x8b01
movl $0x4, %edi
callq 0xa8bb
movl $0x6, %edi
jmp 0xc03e
leal -0x1(%r15), %r12d
movl %r12d, %edi
imull %r12d, %edi
callq 0x7850
movq %rax, %r14
movq (%rax), %rax
movl $0x2, (%rax)
movq (%r14), %rax
movl %r12d, 0x4(%rax)
movq (%r14), %rax
movl %r12d, 0x8(%rax)
movl 0x2e357(%rip), %eax     # 0x3a2b8
movl %eax, -0x2c(%rbp)
testl %r15d, %r15d
jle 0xc027
leaq (,%r15,8), %r13
leaq 0x68(,%r15,8), %rax
movq %rax, -0x38(%rbp)
xorl %r12d, %r12d
movq (%rbx), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0xaece
testl %eax, %eax
jne 0xc01b
cmpl $0x1, %r15d
je 0xbfdb
xorl %eax, %eax
movl $0x1, %ecx
movq -0x38(%rbp), %rdx
xorl %esi, %esi
cmpq %rsi, %r12
je 0xbfc8
movq (%rbx), %rdi
addq %rdx, %rdi
movq (%rdi,%rsi,8), %rdi
movq (%r14), %r8
movslq %eax, %r9
incl %eax
movq %rdi, 0x68(%r8,%r9,8)
incq %rsi
cmpq %rsi, %r15
jne 0xbfac
incq %rcx
addq %r13, %rdx
cmpq %r15, %rcx
jne 0xbfaa
movq %r14, %rdi
callq 0x8b01
callq 0xbd03
movq (%rbx), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
testb $0x1, %r12b
je 0xc01b
movq 0x1053e4(%rip), %rdi    # 0x1113f0
callq 0x8b01
movl $0x2, %edi
callq 0xa8bb
incq %r12
cmpq %r15, %r12
jne 0xbf84
movl 0x2e28b(%rip), %edi     # 0x3a2b8
subl -0x2c(%rbp), %edi
jne 0xc03e
movq 0x32107(%rip), %rdi     # 0x3e140
jmp 0xbd64
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa975
leaq 0x1a291(%rip), %rdi     # 0x262e9
callq 0x77c8