// File: /workspace/github_c_makefile_star2_O3/markdryan[P]subtilis/frontend/int32_type.c
// Function: prv_div_mod_vars
static size_t prv_div_mod_vars(subtilis_parser_t *p, subtilis_ir_operand_t a,
			       subtilis_ir_operand_t b,
			       subtilis_op_instr_type_t type,
			       subtilis_error_t *err)
{
	subtilis_exp_t *e;
	subtilis_ir_arg_t *args;
	size_t res;
	size_t div_flag;
	size_t eflag_reg;
	size_t err_reg;
	subtilis_ir_operand_t div_mod;
	subtilis_ir_operand_t eflag_offset;
	subtilis_ir_operand_t err_offset;
	static const char idiv[] = "_idiv";
	char *name = NULL;

	if (p->backend.caps & SUBTILIS_BACKEND_HAVE_DIV) {
		res =
		    subtilis_ir_section_add_instr(p->current, type, a, b, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return 0;
		subtilis_exp_handle_errors(p, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return 0;
		return res;
	}

	name = malloc(sizeof(idiv));
	if (!name) {
		subtilis_error_set_oom(err);
		return 0;
	}
	strcpy(name, idiv);

	args = malloc(sizeof(*args) * 5);
	if (!args) {
		free(name);
		subtilis_error_set_oom(err);
		return 0;
	}

	div_mod.integer = type == SUBTILIS_OP_INSTR_DIV_I32 ? 0 : 1;
	div_flag = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOVI_I32, div_mod, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return 0;

	eflag_offset.integer = p->eflag_offset;
	eflag_reg = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOVI_I32, eflag_offset, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return 0;

	err_offset.integer = p->error_offset;
	err_reg = subtilis_ir_section_add_instr2(
	    p->current, SUBTILIS_OP_INSTR_MOVI_I32, err_offset, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return 0;

	args[0].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[0].reg = a.reg;
	args[1].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[1].reg = b.reg;
	args[2].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[2].reg = div_flag;
	args[3].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[3].reg = eflag_reg;
	args[4].type = SUBTILIS_IR_REG_TYPE_INTEGER;
	args[4].reg = err_reg;
	e = subtilis_exp_add_call(p, name, SUBTILIS_BUILTINS_IDIV, NULL, args,
				  &subtilis_type_integer, 5, true, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return 0;
	res = e->exp.ir_op.reg;
	subtilis_exp_delete(e);

	return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, %r14
testb $0x1, 0x8(%rdi)
jne 0x3b975
movl $0x6, %edi
callq 0x121d0
testq %rax, %rax
je 0x3b9a7
movq %rax, %r12
movw $0x76, 0x4(%rax)
movl $0x6964695f, (%rax)     # imm = 0x6964695F
movl $0x78, %edi
callq 0x121d0
testq %rax, %rax
je 0x3b9bd
movq %rax, 0x10(%rsp)
xorl %edx, %edx
cmpl $0x6, %ebp
setne %dl
movq 0x48(%r14), %rdi
movl $0x1b, %esi
movq %rbx, %rcx
callq 0x2be09
cmpl $0x0, (%rbx)
jne 0x3b9de
movq %rax, %rbp
movl 0xb0(%r14), %edx
movq 0x48(%r14), %rdi
movl $0x1b, %esi
movq %rbx, %rcx
callq 0x2be09
cmpl $0x0, (%rbx)
jne 0x3b9de
movq %rax, (%rsp)
movq %rbp, 0x8(%rsp)
movl 0xb4(%r14), %edx
movq 0x48(%r14), %rdi
movl $0x1b, %esi
movq %rbx, %rcx
callq 0x2be09
xorl %ebp, %ebp
cmpl $0x0, (%rbx)
jne 0x3b9e0
movq 0x10(%rsp), %r8
movl %ebp, (%r8)
movq %r13, 0x8(%r8)
movl %ebp, 0x18(%r8)
movq %r15, 0x20(%r8)
movl %ebp, 0x30(%r8)
movq 0x8(%rsp), %rcx
movq %rcx, 0x38(%r8)
movl %ebp, 0x48(%r8)
movq (%rsp), %rcx
movq %rcx, 0x50(%r8)
movl %ebp, 0x60(%r8)
movq %rax, 0x68(%r8)
subq $0x8, %rsp
leaq 0x38fd0(%rip), %r9      # 0x74918
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
pushq %rbx
pushq $0x1
pushq $0x5
callq 0x2b1aa
addq $0x20, %rsp
cmpl %ebp, (%rbx)
jne 0x3b9e0
movq 0x148(%rax), %rbp
movq %rax, %rdi
callq 0x2b166
jmp 0x3b9e0
movq 0x48(%r14), %rdi
movl %ebp, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x2bc8f
cmpl $0x0, (%rbx)
jne 0x3b9de
movq %rax, %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2b01f
xorl %ebp, %ebp
cmpl $0x0, (%rbx)
cmoveq %r15, %rbp
jmp 0x3b9e0
leaq 0x39b55(%rip), %rdx     # 0x75503
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1bb, %ecx            # imm = 0x1BB
jmp 0x3b9d9
movq %r12, %rdi
callq 0x122c0
leaq 0x39b37(%rip), %rdx     # 0x75503
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1c3, %ecx            # imm = 0x1C3
callq 0x145a4
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq