// File: /workspace/github_c_makefile_star2_O1/markdryan[P]subtilis/frontend/parser_assignment.c
// Function: subtilis_parser_swap
void subtilis_parser_swap(subtilis_parser_t *p, subtilis_token_t *t,
			  subtilis_error_t *err)
{
	const char *tbuf;
	bool lreg;
	bool rreg;
	subtilis_ir_operand_t lop;
	subtilis_ir_operand_t rop;
	subtilis_type_t ltype;
	subtilis_type_t rtype;

	ltype.type = SUBTILIS_TYPE_VOID;
	rtype.type = SUBTILIS_TYPE_VOID;

	lreg = subtilis_exp_get_lvalue(p, t, &lop, &ltype, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	tbuf = subtilis_token_get_text(t);
	if (t->type != SUBTILIS_TOKEN_OPERATOR || strcmp(tbuf, ",")) {
		subtilis_error_set_expected(err, ",", tbuf, p->l->stream->name,
					    p->l->line);
		goto cleanup;
	}

	rreg = subtilis_exp_get_lvalue(p, t, &rop, &rtype, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	subtilis_type_compare_diag_custom(p, &ltype, &rtype, NULL,
					  prv_swap_mismatch, err);
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

	if (lreg) {
		if (rreg)
			subtilis_type_if_swap_reg_reg(p, &ltype, lop.reg,
						      rop.reg, err);
		else
			subtilis_type_if_swap_reg_mem(p, &ltype, lop.reg,
						      rop.reg, err);
	} else if (rreg) {
		subtilis_type_if_swap_reg_mem(p, &ltype, rop.reg, lop.reg, err);
	} else {
		subtilis_type_if_swap_mem_mem(p, &ltype, lop.reg, rop.reg, err);
	}
	if (err->type != SUBTILIS_ERROR_OK)
		goto cleanup;

cleanup:

	subtilis_type_free(&rtype);
	subtilis_type_free(&ltype);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movl $0x8, %eax
leaq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movl %eax, 0x158(%rsp)
leaq 0x8(%rsp), %rdx
movq %rbx, %r8
callq 0x1e724
cmpl $0x0, (%rbx)
jne 0x19661
movl %eax, %ebp
movq %r15, %rdi
callq 0x12ad0
movq %rax, %r12
cmpl $0x2, (%r15)
jne 0x1962e
leaq 0x59f76(%rip), %rsi     # 0x73598
movq %r12, %rdi
callq 0x12160
testl %eax, %eax
je 0x19688
movq (%r14), %rax
movq 0x30(%rax), %r8
movl 0x38(%rax), %r9d
leaq 0x59f6c(%rip), %rax     # 0x735ac
leaq 0x59f51(%rip), %rdx     # 0x73598
movq %rbx, %rdi
movl $0x1d, %esi
movq %r12, %rcx
pushq $0x4ee                  # imm = 0x4EE
pushq %rax
callq 0x1442a
addq $0x10, %rsp
leaq 0x158(%rsp), %rdi
callq 0x2f843
leaq 0x10(%rsp), %rdi
callq 0x2f843
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rdx
leaq 0x158(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %r8
callq 0x1e724
cmpl $0x0, (%rbx)
jne 0x19661
movl %eax, %r15d
leaq 0x88(%rip), %r8         # 0x19738
leaq 0x10(%rsp), %rsi
leaq 0x158(%rsp), %rdx
movq %r14, %rdi
xorl %ecx, %ecx
movq %rbx, %r9
callq 0x37d40
cmpl $0x0, (%rbx)
jne 0x19661
testb %bpl, %bpl
je 0x196f7
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
testb %r15b, %r15b
je 0x19705
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %r8
callq 0x37a6e
jmp 0x19661
testb %r15b, %r15b
je 0x1971a
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %r8
callq 0x37aa2
jmp 0x19661
movq 0x8(%rsp), %rdx
movq (%rsp), %rcx
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %r8
callq 0x37ad6
jmp 0x19661