// File: /workspace/github_c_makefile_star2_O0/markdryan[P]subtilis/frontend/builtins_ir.c
// Function: subtilis_builtins_ir_rnd_pos
subtilis_exp_t *subtilis_builtins_ir_rnd_pos(subtilis_parser_t *p, int32_t val,
					     subtilis_error_t *err)
{
	subtilis_exp_t *e;
	subtilis_exp_t *m;
	subtilis_exp_t *e_dup = NULL;
	subtilis_exp_t *top_bit = NULL;

	e = subtilis_builtins_ir_basic_rnd(p, err);
	if (err->type != SUBTILIS_ERROR_OK)
		return NULL;

	e_dup = subtilis_type_if_dup(e, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_var_assign_hidden(p, subtilis_rnd_hidden_var,
				   &subtilis_type_integer, e_dup, err);
	e_dup = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	top_bit = subtilis_exp_new_int32((int32_t)0x7fffffff, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	e = subtilis_type_if_and(p, e, top_bit, err);
	top_bit = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	m = subtilis_exp_new_int32(val, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	e = subtilis_type_if_mod(p, e, m, err);
	m = NULL;
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	m = subtilis_exp_new_int32(1, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	return subtilis_exp_add(p, e, m, err);

cleanup:

	subtilis_exp_delete(top_bit);
	subtilis_exp_delete(e_dup);
	subtilis_exp_delete(e);

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x40390
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x407aa
movq $0x0, -0x8(%rbp)
jmp 0x408ef
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x47d20
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x407c9
jmp 0x408cc
movq -0x10(%rbp), %rdi
leaq 0x9405c(%rip), %rax     # 0xd4830
movq (%rax), %rsi
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq 0x6b0ea(%rip), %rdx     # 0xab8d0
callq 0x47150
movq $0x0, -0x38(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40801
jmp 0x408cc
movq -0x20(%rbp), %rsi
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
callq 0x37800
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40821
jmp 0x408cc
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x49090
movq %rax, -0x28(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x4084d
jmp 0x408cc
movl -0x14(%rbp), %edi
movq -0x20(%rbp), %rsi
callq 0x37800
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40868
jmp 0x408cc
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x493f0
movq %rax, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x40894
jmp 0x408cc
movq -0x20(%rbp), %rsi
movl $0x1, %edi
callq 0x37800
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x408b1
jmp 0x408cc
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0x37bd0
movq %rax, -0x8(%rbp)
jmp 0x408ef
movq -0x40(%rbp), %rdi
callq 0x36ee0
movq -0x38(%rbp), %rdi
callq 0x36ee0
movq -0x28(%rbp), %rdi
callq 0x36ee0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)