// File: /workspace/github_c_makefile_star2_O3/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
movl 0x32fd9(%rip), %eax     # 0x3f2b8
movl $0xfffe795f, %ecx       # imm = 0xFFFE795F
leal (%rax,%rcx), %edx
cmpl %ecx, %edx
jbe 0xc628
decl %eax
movl %eax, 0x32fc1(%rip)     # 0x3f2b8
leaq 0x3c2c2(%rip), %rcx     # 0x485c0
movq (%rcx,%rax,8), %rbx
cmpb $0x7, 0x10(%rbx)
jne 0xc342
movq (%rbx), %rax
cmpl $0x2, (%rax)
jne 0xc634
movl 0x4(%rax), %r15d
cmpl 0x8(%rax), %r15d
jne 0xc634
cmpq $0x3, %r15
je 0xc3af
cmpl $0x2, %r15d
je 0xc358
cmpl $0x1, %r15d
jne 0xc512
movq 0x68(%rax), %rdi
jmp 0xc345
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8ba5
movq 0x68(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbfb4
movq 0x68(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x88(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0xa8(%rax), %rdi
callq 0x8ba5
movl $0x3, %edi
callq 0xacef
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x90(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x98(%rax), %rdi
callq 0x8ba5
movl $0x3, %edi
callq 0xacef
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0xa0(%rax), %rdi
callq 0x8ba5
movl $0x3, %edi
callq 0xacef
movq 0x109fa1(%rip), %rdi    # 0x1163f0
callq 0x8ba5
movq (%rbx), %rax
movq 0x78(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x88(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x98(%rax), %rdi
callq 0x8ba5
movl $0x4, %edi
callq 0xacef
movq 0x109f61(%rip), %rdi    # 0x1163f0
callq 0x8ba5
movq (%rbx), %rax
movq 0x70(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x80(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0xa8(%rax), %rdi
callq 0x8ba5
movl $0x4, %edi
callq 0xacef
movq 0x109f21(%rip), %rdi    # 0x1163f0
callq 0x8ba5
movq (%rbx), %rax
movq 0x68(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0x90(%rax), %rdi
callq 0x8ba5
movq (%rbx), %rax
movq 0xa0(%rax), %rdi
callq 0x8ba5
movl $0x4, %edi
callq 0xacef
movl $0x6, %edi
jmp 0xc615
leal -0x1(%r15), %r12d
movl %r12d, %edi
imull %r12d, %edi
callq 0x7893
movq %rax, %r14
movq (%rax), %rax
movl $0x2, (%rax)
movq (%r14), %rax
movl %r12d, 0x4(%rax)
movq (%r14), %rax
movl %r12d, 0x8(%rax)
testl %r15d, %r15d
jle 0xc609
movl 0x32d6d(%rip), %eax     # 0x3f2b8
movl %eax, -0x2c(%rbp)
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 0xb477
testl %eax, %eax
jne 0xc5f2
xorl %eax, %eax
movl $0x1, %ecx
movq -0x38(%rbp), %rdx
xorl %esi, %esi
cmpq %rsi, %r12
je 0xc59f
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 0xc583
incq %rcx
addq %r13, %rdx
cmpq %r15, %rcx
jne 0xc581
movq %r14, %rdi
callq 0x8ba5
callq 0xc2c8
movq (%rbx), %rax
movq 0x68(%rax,%r12,8), %rdi
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
testb $0x1, %r12b
je 0xc5f2
movq 0x109e0d(%rip), %rdi    # 0x1163f0
callq 0x8ba5
movl $0x2, %edi
callq 0xacef
incq %r12
cmpq %r15, %r12
jne 0xc565
movl 0x32cb4(%rip), %edi     # 0x3f2b8
subl -0x2c(%rbp), %edi
jne 0xc615
movq 0x36b30(%rip), %rdi     # 0x43140
jmp 0xc345
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xadb3
leaq 0x22912(%rip), %rdi     # 0x2ef41
callq 0x780b
leaq 0x1dcce(%rip), %rdi     # 0x2a309
callq 0x780b