// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/int32_type.c
// Function: prv_optimise_div
static bool prv_optimise_div(subtilis_parser_t *p, subtilis_ir_operand_t a,
			     subtilis_ir_operand_t b, size_t *result,
			     subtilis_error_t *err)
{
	int32_t s;
	uint32_t abs_b = (uint32_t)(b.integer > 0) ? b.integer : -b.integer;
	subtilis_ir_operand_t c;
	subtilis_ir_operand_t tmp;

	for (s = 0; abs_b / 2 >= (1u << s); s++)
		;

	if (abs_b != 1u << s)
		return false;

	c.integer = 31;
	tmp.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ASRI_I32, a, c, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return false;

	c.integer = 32 - s;
	tmp.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_LSRI_I32, tmp, c, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return false;

	tmp.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ADD_I32, a, tmp, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return false;

	c.integer = s;
	tmp.reg = subtilis_ir_section_add_instr(
	    p->current, SUBTILIS_OP_INSTR_ASRI_I32, tmp, c, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return false;

	if (b.integer < 0) {
		c.integer = 0;
		tmp.reg = subtilis_ir_section_add_instr(
		    p->current, SUBTILIS_OP_INSTR_RSUBI_I32, tmp, c, err);
		if (err->type != SUBTILIS_ERROR_OK)
			return false;
	}

	*result = tmp.reg;

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rdi, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpl $0x0, -0x18(%rbp)
jle 0x51a8a
movl -0x18(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x51a92
xorl %eax, %eax
subl -0x18(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x38(%rbp), %eax
shrl %eax
movl -0x34(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
jb 0x51ac1
jmp 0x51ab6
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x51a9f
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
je 0x51add
movb $0x0, -0x1(%rbp)
jmp 0x51c0e
movl $0x1f, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r8
movq -0x10(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x50, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51b18
movb $0x0, -0x1(%rbp)
jmp 0x51c0e
movl $0x20, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r8
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x4e, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51b57
movb $0x0, -0x1(%rbp)
jmp 0x51c0e
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r8
movq -0x10(%rbp), %rdx
movq -0x48(%rbp), %rcx
xorl %esi, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51b88
movb $0x0, -0x1(%rbp)
jmp 0x51c0e
movl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r8
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x50, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51bbf
movb $0x0, -0x1(%rbp)
jmp 0x51c0e
cmpl $0x0, -0x18(%rbp)
jge 0x51bff
movl $0x0, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r8
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x21, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51bfd
movb $0x0, -0x1(%rbp)
jmp 0x51c0e
jmp 0x51bff
movq -0x48(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)