// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/int32_type.c
// Function: prv_optimise_mod
static bool prv_optimise_mod(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 shifted;
	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;
	shifted.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, shifted, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return false;

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

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

	*result = tmp.reg;

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %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 0x51d4a
movl -0x18(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x51d52
xorl %eax, %eax
subl -0x18(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%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 0x51d81
jmp 0x51d76
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x51d5f
movl -0x38(%rbp), %eax
movl -0x34(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
cmpl %ecx, %eax
je 0x51d9d
movb $0x0, -0x1(%rbp)
jmp 0x51ebf
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, -0x50(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51dd8
movb $0x0, -0x1(%rbp)
jmp 0x51ebf
movl $0x20, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x4e, %esi
callq 0x38230
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51e17
movb $0x0, -0x1(%rbp)
jmp 0x51ebf
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, -0x50(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51e45
movb $0x0, -0x1(%rbp)
jmp 0x51ebf
movl -0x38(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl $0x25, %esi
callq 0x38230
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51e7f
movb $0x0, -0x1(%rbp)
jmp 0x51ebf
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x30(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rcx
movl $0x2, %esi
callq 0x38230
movq %rax, -0x50(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x0, (%rax)
je 0x51eb0
movb $0x0, -0x1(%rbp)
jmp 0x51ebf
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)