// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rdi, %r14
testb $0x1, 0x8(%rdi)
jne 0x397aa
pushq $0x6
popq %rdi
callq 0x121d0
testq %rax, %rax
je 0x397dc
movq %rax, %r13
movw $0x76, 0x4(%rax)
movl $0x6964695f, (%rax)     # imm = 0x6964695F
pushq $0x78
popq %rdi
callq 0x121d0
testq %rax, %rax
je 0x397f0
movq %rax, 0x10(%rsp)
xorl %edx, %edx
cmpl $0x6, %ebp
setne %dl
movq 0x48(%r14), %rdi
pushq $0x1b
popq %rsi
movq %rbx, %rcx
callq 0x2a981
cmpl $0x0, (%rbx)
jne 0x3980f
movq %rax, %rbp
movl 0xb0(%r14), %edx
movq 0x48(%r14), %rdi
pushq $0x1b
popq %rsi
movq %rbx, %rcx
callq 0x2a981
cmpl $0x0, (%rbx)
jne 0x3980f
movq %rax, (%rsp)
movq %rbp, 0x8(%rsp)
movl 0xb4(%r14), %edx
movq 0x48(%r14), %rdi
pushq $0x1b
popq %rsi
movq %rbx, %rcx
callq 0x2a981
xorl %ebp, %ebp
cmpl $0x0, (%rbx)
jne 0x39811
movq 0x10(%rsp), %r8
andl $0x0, (%r8)
movq %r12, 0x8(%r8)
andl $0x0, 0x18(%r8)
movq %r15, 0x20(%r8)
andl $0x0, 0x30(%r8)
movq 0x8(%rsp), %rcx
movq %rcx, 0x38(%r8)
andl $0x0, 0x48(%r8)
movq (%rsp), %rcx
movq %rcx, 0x50(%r8)
andl $0x0, 0x60(%r8)
movq %rax, 0x68(%r8)
subq $0x8, %rsp
leaq 0x3514b(%rip), %r9      # 0x6e8c8
movq %r14, %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
pushq %rbx
pushq $0x1
pushq $0x5
callq 0x29dcc
addq $0x20, %rsp
cmpl %ebp, (%rbx)
jne 0x39811
movq 0x148(%rax), %rbp
movq %rax, %rdi
callq 0x29d88
jmp 0x39811
movq 0x48(%r14), %rdi
movl %ebp, %esi
movq %r12, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x2a819
cmpl $0x0, (%rbx)
jne 0x3980f
movq %rax, %r15
movq %r14, %rdi
movq %rbx, %rsi
callq 0x29c49
xorl %ebp, %ebp
cmpl $0x0, (%rbx)
cmoveq %r15, %rbp
jmp 0x39811
leaq 0x35cac(%rip), %rdx     # 0x6f48f
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0x1bb, %ecx            # imm = 0x1BB
jmp 0x3980a
movq %r13, %rdi
callq 0x122c0
leaq 0x35c90(%rip), %rdx     # 0x6f48f
pushq $0x1
popq %rsi
movq %rbx, %rdi
movl $0x1c3, %ecx            # imm = 0x1C3
callq 0x1429e
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq