// File: /workspace/github_c_makefile_star2_O0/MikeGray-APH[P]LibLouisAPH/source/pattern.c
// Function: pattern_reverse_expression
static void pattern_reverse_expression(unichar *expr_data, const int expr_start)
{
	unichar expr_end, expr_crs, expr_prv;

	expr_end = EXPR_NXT(expr_start);

	/*   empty expression   */
	if(EXPR_TYPE(expr_end) == PTN_END)
		return;

	/*   find end expression   */
	while(EXPR_TYPE(expr_end) != PTN_END)
		expr_end = EXPR_NXT(expr_end);

	expr_crs = EXPR_PRV(expr_end);
	expr_prv = EXPR_PRV(expr_crs);

	/*   relink expression before end expression   */
	EXPR_NXT(expr_start) = expr_crs;
	EXPR_PRV(expr_crs)   = expr_start;
	EXPR_NXT(expr_crs)   = expr_prv;

	/*   reverse any branching expressions   */
	pattern_reverse_branch(expr_data, expr_crs);

	while(expr_prv != expr_start)
	{
		/*   shift current expression   */
		expr_crs = expr_prv;
		expr_prv = EXPR_PRV(expr_prv);

		/*   reverse any branching expressions   */
		pattern_reverse_branch(expr_data, expr_crs);

		if(expr_prv == expr_start)
			break;

		/*   relink current expression   */
		EXPR_PRV(expr_crs) = EXPR_NXT(expr_crs);
		EXPR_NXT(expr_crs) = expr_prv;
	}

	/*   relink expression after start expression   */
	EXPR_PRV(expr_crs) = EXPR_NXT(expr_crs);
	EXPR_NXT(expr_crs) = expr_end;
	EXPR_PRV(expr_end) = expr_crs;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0xe(%rbp)
movq -0x8(%rbp), %rax
movzwl -0xe(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jne 0xca92
jmp 0xcc0c
jmp 0xca94
movq -0x8(%rbp), %rax
movzwl -0xe(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
je 0xcac5
movq -0x8(%rbp), %rax
movzwl -0xe(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0xe(%rbp)
jmp 0xca94
movq -0x8(%rbp), %rax
movzwl -0xe(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0x12(%rbp)
movw -0x10(%rbp), %dx
movq -0x8(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0xc(%rbp), %eax
movw %ax, %dx
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movw -0x12(%rbp), %dx
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movq -0x8(%rbp), %rdi
movzwl -0x10(%rbp), %esi
callq 0xdce0
movzwl -0x12(%rbp), %eax
cmpl -0xc(%rbp), %eax
je 0xcbbc
movw -0x12(%rbp), %ax
movw %ax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movzwl -0x12(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0x12(%rbp)
movq -0x8(%rbp), %rdi
movzwl -0x10(%rbp), %esi
callq 0xdce0
movzwl -0x12(%rbp), %eax
cmpl -0xc(%rbp), %eax
jne 0xcb80
jmp 0xcbbc
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %dx
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movw -0x12(%rbp), %dx
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
jmp 0xcb41
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %dx
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movw -0xe(%rbp), %dx
movq -0x8(%rbp), %rax
movzwl -0x10(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movw -0x10(%rbp), %dx
movq -0x8(%rbp), %rax
movzwl -0xe(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)