// File: /workspace/github_c_makefile_star2_O2/aquaxis[P]synverll/src/parser_ir.c
// Function: search_reg_llvm
INST_STAGE search_reg_llvm(PARSER_TREE_IR *now_parser_tree_ir, char *name, char *left_name, char *right_name)
{
    now_parser_tree_ir = now_parser_tree_ir->prev_ptr;
	INST_STAGE inst_stage;

	int left_stage = 0;
	int left_parallel = 0;
	int right_stage = 0;
	int right_parallel = 0;

	inst_stage.parallel = 0;
	inst_stage.stage = 0;

	while(now_parser_tree_ir != parser_tree_ir_top){

		switch(now_parser_tree_ir->flag){
			case PARSER_IR_FLAG_MODULE:
				if(!search_module_llvm(left_name, now_parser_tree_ir->module.argument)){
					left_parallel = now_parser_tree_ir->parallel;
					left_stage = now_parser_tree_ir->stage;
					break;
				}
			case PARSER_IR_FLAG_REGISTER:
			case PARSER_IR_FLAG_LOAD:
			case PARSER_IR_FLAG_FLOAT:
			case PARSER_IR_FLAG_WIRE:
			case PARSER_IR_FLAG_CALL:
			case PARSER_IR_FLAG_ALLOCA:
			case PARSER_IR_FLAG_COMPARE:
			case PARSER_IR_FLAG_POINTER:
			case PARSER_IR_FLAG_SELECT:
			case PARSER_IR_FLAG_TYPE:
			case PARSER_IR_FLAG_REGISTER_LOOP:
				if(!strcmp(now_parser_tree_ir->label, left_name) && (strlen(left_name) > 0) && (left_name[0] == '%')){
					left_parallel = now_parser_tree_ir->parallel;
					left_stage = now_parser_tree_ir->stage;
					break;
				}
				if(!strcmp(now_parser_tree_ir->label, right_name) && (strlen(right_name) > 0) && (right_name[0] == '%')){
					right_parallel = now_parser_tree_ir->parallel;
					right_stage = now_parser_tree_ir->stage;
					break;
				}
			default:
				break;
		}
        now_parser_tree_ir = now_parser_tree_ir->prev_ptr;
	}

	if(left_stage > right_stage){
		inst_stage.parallel = left_parallel;
		inst_stage.stage = left_stage;
	}else if(right_stage > left_stage){
		inst_stage.parallel = right_parallel;
		inst_stage.stage = right_stage;
	}else{
		inst_stage.parallel = left_parallel;
		inst_stage.stage = left_stage;
	}

	return inst_stage;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, %r12
movq $0x0, 0x10(%rsp)
movq 0xe9af(%rip), %rbx      # 0x13130
movl $0x12f9e, %ebp          # imm = 0x12F9E
movl $0x0, 0x4(%rsp)
movl $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
movq (%r12), %r12
cmpq %rbx, %r12
je 0x4835
movl 0x10(%r12), %eax
cmpl $0x10, %eax
ja 0x479e
btl %eax, %ebp
jb 0x47da
cmpl $0xf, %eax
jne 0x479e
leaq 0x1430(%r12), %rsi
movq %r15, %rdi
callq 0x46ef
movq 0xe95a(%rip), %rbx      # 0x13130
testl %eax, %eax
je 0x481d
leaq 0x30(%r12), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x1100
testl %eax, %eax
jne 0x47f4
cmpb $0x25, (%r15)
je 0x481d
movq %r13, %rdi
movq %r14, %rsi
callq 0x1100
testl %eax, %eax
jne 0x479e
cmpb $0x25, (%r14)
jne 0x479e
movl 0x18(%r12), %eax
movq %rax, 0x8(%rsp)
movl 0x1c(%r12), %eax
movl %eax, (%rsp)
jmp 0x479e
movl 0x18(%r12), %eax
movl %eax, 0x4(%rsp)
movl 0x1c(%r12), %eax
movq %rax, 0x10(%rsp)
jmp 0x479e
movq 0x10(%rsp), %rcx
movl (%rsp), %esi
cmpl %ecx, %esi
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %edx
cmovlel %edx, %eax
cmovgl %esi, %ecx
cmovll %edx, %eax
shlq $0x20, %rcx
orq %rcx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq