// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/array_type.c
// Function: prv_check_constant_dims
static int64_t prv_check_constant_dims(subtilis_parser_t *p, subtilis_exp_t **e,
				       size_t index_count, const char *var_name,
				       const subtilis_type_t *type,
				       int *dyn_start, int32_t *block_size,
				       subtilis_error_t *err)
{
	int i;
	int j;
	int32_t dim_size;
	int64_t prod;
	int32_t bsize = 1;
	int dstart = index_count - 1;
	int64_t array_size = 0;

	for (i = index_count - 1; i >= 0; i--) {
		if (e[i]->type.type != SUBTILIS_TYPE_CONST_INTEGER)
			break;
		dim_size = type->params.array.dims[i];
		if (dim_size == SUBTILIS_DYNAMIC_DIMENSION)
			break;

		if ((e[i]->exp.ir_op.integer < 0) ||
		    (e[i]->exp.ir_op.integer > dim_size)) {
			subtilis_error_bad_index(
			    err, var_name, p->l->stream->name, p->l->line);
			return 0;
		}
		dstart--;
	}

	*dyn_start = dstart;

	/*
	 * i now stores the last dimension (working backwards) where the
	 * index and the dimension are both known at compile time.
	 */

	i++;
	for (j = i; j < index_count; j++) {
		dim_size = type->params.array.dims[j] + 1;
		bsize *= dim_size;
	}

	*block_size = bsize;

	for (; i < index_count - 1; i++) {
		prod = e[i]->exp.ir_op.integer;
		for (j = i + 1; j < index_count; j++) {
			dim_size = type->params.array.dims[j] + 1;
			prod *= dim_size;
		}

		array_size += prod;
	}

	return array_size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movl $0x1, -0x54(%rbp)
movq -0x20(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x20(%rbp), %rax
subq $0x1, %rax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x5f4c9
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x1, (%rax)
je 0x5f41d
jmp 0x5f4c9
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %eax
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x5f437
jmp 0x5f4c9
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpl $0x0, 0x148(%rax)
jl 0x5f463
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x148(%rax), %eax
cmpl -0x44(%rbp), %eax
jle 0x5f4b2
movq 0x18(%rbp), %rdi
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x39, %esi
leaq 0x4bde9(%rip), %rcx     # 0xab276
leaq 0x4d4e9(%rip), %rax     # 0xac97d
movq %rax, (%rsp)
movl $0x729, 0x8(%rsp)       # imm = 0x729
callq 0x156d0
movq $0x0, -0x8(%rbp)
jmp 0x5f59f
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5f3fd
movl -0x58(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movslq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x5f512
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
imull -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x5f4e1
movl -0x54(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movslq -0x3c(%rbp), %rax
movq -0x20(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x5f597
movq -0x18(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x148(%rax), %rax
movq %rax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movslq -0x40(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x5f580
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movl 0xc(%rax,%rcx,4), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movslq -0x44(%rbp), %rax
imulq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x5f54c
movq -0x50(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5f51b
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)