// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x8, -0x180(%rbp)
movl $0x8, -0x2c8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %r8
leaq -0x30(%rbp), %rdx
leaq -0x180(%rbp), %rcx
callq 0x24350
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1caca
jmp 0x1cc36
movq -0x10(%rbp), %rdi
callq 0x12d70
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x1caf5
movq -0x20(%rbp), %rdi
leaq 0x8dabe(%rip), %rsi     # 0xaa5a9
callq 0x12140
cmpl $0x0, %eax
je 0x1cb3c
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x30(%rax), %r8
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl 0x38(%rax), %r9d
movl $0x1d, %esi
leaq 0x8da8a(%rip), %rdx     # 0xaa5a9
leaq 0x8da96(%rip), %rax     # 0xaa5bc
movq %rax, (%rsp)
movl $0x4ee, 0x8(%rsp)       # imm = 0x4EE
callq 0x156d0
jmp 0x1cc36
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %r8
leaq -0x38(%rbp), %rdx
leaq -0x2c8(%rbp), %rcx
callq 0x24350
andb $0x1, %al
movb %al, -0x22(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1cb6b
jmp 0x1cc36
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %r9
leaq -0x180(%rbp), %rsi
leaq -0x2c8(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
leaq 0xd4(%rip), %r8         # 0x1cc60
callq 0x4a900
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1cb9f
jmp 0x1cc36
testb $0x1, -0x21(%rbp)
je 0x1cbe7
testb $0x1, -0x22(%rbp)
je 0x1cbc9
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq -0x180(%rbp), %rsi
callq 0x4a3d0
jmp 0x1cbe5
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq -0x180(%rbp), %rsi
callq 0x4a450
jmp 0x1cc29
testb $0x1, -0x22(%rbp)
je 0x1cc0b
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq -0x180(%rbp), %rsi
callq 0x4a450
jmp 0x1cc27
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x38(%rbp), %rcx
movq -0x18(%rbp), %r8
leaq -0x180(%rbp), %rsi
callq 0x4a4d0
jmp 0x1cc29
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1cc34
jmp 0x1cc36
jmp 0x1cc36
leaq -0x2c8(%rbp), %rdi
callq 0x3e100
leaq -0x180(%rbp), %rdi
callq 0x3e100
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
nopw (%rax,%rax)