// File: /workspace/github_c_makefile_star2_O1/Ihsoh[P]ilang/compiler/frontend/irgen.c
// Function: ir_expr_comparison
static bool _ir_expr_comparison(
	IRGeneratorContext *ctx,
	ResizableString *rstr,
	_ExprResult *expr_result,
	ParserASTNode *node
) {
	assert(ctx);
	assert(rstr);
	assert(expr_result);
	assert(node);

	switch (node->type) {
		case FE_NODE_EXPR_LT:
		case FE_NODE_EXPR_LE:
		case FE_NODE_EXPR_GT:
		case FE_NODE_EXPR_GE:
		case FE_NODE_EXPR_EQ:
		case FE_NODE_EXPR_NEQ: {
			assert(node->nchilds == 2);

			ParserSymbol *func_symbol = ctx->func_symbol;
			assert(func_symbol);

			ParserASTNode *node_lhs = node->childs[0];
			ParserASTNode *node_rhs = node->childs[1];

			ParserASTNode *node_type = FE_EXPR_AST_NODE_GET_TYPE_NODE(node);

			ParserASTNode *node_lhs_type = FE_EXPR_AST_NODE_GET_TYPE_NODE(node_lhs);
			ParserASTNode *node_rhs_type = FE_EXPR_AST_NODE_GET_TYPE_NODE(node_rhs);
			
			uint8_t lhs_type = FE_EXPR_AST_NODE_GET_TYPE(node_lhs);
			uint8_t rhs_type = FE_EXPR_AST_NODE_GET_TYPE(node_rhs);
			
			ParserASTNode *node_target_type = NULL;
			uint8_t target_type;
			if (lhs_type == FE_TYPE_POINTER) {
				node_target_type = node_lhs_type;
				target_type = lhs_type;
			} else if (rhs_type == FE_TYPE_POINTER) {
				node_target_type = node_rhs_type;
				target_type = rhs_type;
			} else {
				int32_t lhs_type_weight = fe_sem_get_primitive_type_weight(lhs_type);
				int32_t rhs_type_weight = fe_sem_get_primitive_type_weight(rhs_type); 
				if (lhs_type_weight > rhs_type_weight) {
					node_target_type = node_lhs_type;
				} else {
					node_target_type = node_rhs_type;
				}
				target_type = fe_sem_get_type_by_type_node(ctx->psrctx, node_target_type);
			}

			_ExprResult result_lhs;
			_ExprResult result_rhs;
			_ExprResult result_lhs_casted;
			_ExprResult result_rhs_casted;

			_expr_result_init(&result_lhs);
			_expr_result_init(&result_rhs);
			_expr_result_init(&result_lhs_casted);
			_expr_result_init(&result_rhs_casted);

			_ir_expr(ctx, rstr, &result_lhs, node_lhs);
			rstr_append_with_rstr(rstr, &(result_lhs.rstr_for_result_ptr));
			rstr_append_with_rstr(rstr, &(result_lhs.rstr_for_result));

			_ir_expr(ctx, rstr, &result_rhs, node_rhs);
			rstr_append_with_rstr(rstr, &(result_rhs.rstr_for_result_ptr));
			rstr_append_with_rstr(rstr, &(result_rhs.rstr_for_result));

			_expr_result_cast(
				ctx,
				&result_lhs_casted,
				node_target_type,
				&result_lhs,
				node_lhs_type
			);
			rstr_append_with_rstr(rstr, &(result_lhs_casted.rstr_for_result_ptr));
			rstr_append_with_rstr(rstr, &(result_lhs_casted.rstr_for_result));

			_expr_result_cast(
				ctx,
				&result_rhs_casted,
				node_target_type,
				&result_rhs,
				node_rhs_type
			);
			rstr_append_with_rstr(rstr, &(result_rhs_casted.rstr_for_result_ptr));
			rstr_append_with_rstr(rstr, &(result_rhs_casted.rstr_for_result));

			ResizableString rstr_tmp_label_val;
			rstr_init(&rstr_tmp_label_val);
			_generate_func_tmp_var(
				ctx,
				func_symbol,
				&rstr_tmp_label_val,
				node_type
			);

			#define	_A(cmd)	\
				rstr_appendf(	\
					&(expr_result->rstr_for_result),	\
					cmd" %s, %s, %s;\n",	\
					RSTR_CSTR(&rstr_tmp_label_val),	\
					RSTR_CSTR(&(result_lhs_casted.rstr_result)),	\
					RSTR_CSTR(&(result_rhs_casted.rstr_result))	\
				);

			switch (node->type) {
				case FE_NODE_EXPR_LT: {
					_A("lt")
					break;
				}
				case FE_NODE_EXPR_LE: {
					_A("le")
					break;
				}
				case FE_NODE_EXPR_GT: {
					_A("gt")
					break;
				}
				case FE_NODE_EXPR_GE: {
					_A("ge")
					break;
				}
				case FE_NODE_EXPR_EQ: {
					_A("eq")
					break;
				}
				case FE_NODE_EXPR_NEQ: {
					_A("neq")
					break;
				}
				default: {
					assert(0);
					break;
				}
			}

			#undef	_A

			_expr_result_set_result(
				expr_result,
				RSTR_CSTR(&rstr_tmp_label_val)
			);

			_expr_result_free(&result_lhs);
			_expr_result_free(&result_rhs);
			_expr_result_free(&result_lhs_casted);
			_expr_result_free(&result_rhs_casted);
			rstr_free(&rstr_tmp_label_val);

			return true;
		}
		default: {
			return false;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %r15
xorl %eax, %eax
movl $0xfffff190, %edi       # imm = 0xFFFFF190
addl (%rcx), %edi
cmpl $0x13, %edi
ja 0xfb70
movq %rsi, %r12
movl $0xf0003, %esi          # imm = 0xF0003
btl %edi, %esi
jae 0xfb70
cmpl $0x2, 0x44(%rcx)
jne 0xfb82
movq %rdx, -0x60(%rbp)
movq 0x40(%r15), %rax
testq %rax, %rax
je 0xfba1
movq %rax, -0x50(%rbp)
movq 0x48(%rcx), %rax
movq %rcx, -0x58(%rbp)
movq 0x68(%rcx), %rcx
movq %rcx, -0x48(%rbp)
movq (%rax), %r14
movq 0x8(%rax), %r13
movq 0x68(%r14), %rbx
movq 0x68(%r13), %rax
movq %rax, -0x38(%rbp)
movb 0x60(%r14), %al
movq %rbx, -0x40(%rbp)
cmpb $0x10, %al
je 0xf958
movb 0x60(%r13), %cl
movq -0x38(%rbp), %rbx
cmpb $0x10, %cl
je 0xf958
movzbl %al, %edi
movl %ecx, %ebx
callq 0x2acb1
movl %eax, -0x30(%rbp)
movzbl %bl, %edi
callq 0x2acb1
cmpl %eax, -0x30(%rbp)
movq -0x38(%rbp), %rbx
cmovgq -0x40(%rbp), %rbx
movq (%r15), %rdi
movq %rbx, %rsi
callq 0x2b043
leaq -0x170(%rbp), %rdi
movq %r13, -0x30(%rbp)
movq %rdi, %r13
callq 0xd03d
leaq -0xb0(%rbp), %rdi
callq 0xd03d
leaq -0x130(%rbp), %rdi
callq 0xd03d
leaq -0xf0(%rbp), %rdi
callq 0xd03d
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0xde8a
leaq -0x160(%rbp), %rsi
movq %r12, %rdi
callq 0x788c
movq %r12, %rdi
movq %r13, %rsi
callq 0x788c
movq %r15, %rdi
movq %r12, %rsi
leaq -0xb0(%rbp), %r14
movq %r14, %rdx
movq -0x30(%rbp), %rcx
callq 0xde8a
leaq -0xa0(%rbp), %rsi
movq %r12, %rdi
callq 0x788c
movq %r12, %rdi
movq %r14, %rsi
callq 0x788c
movq %r15, %rdi
leaq -0x130(%rbp), %r14
movq %r14, %rsi
movq %rbx, %rdx
movq %r13, %rcx
movq -0x40(%rbp), %r8
callq 0xd093
leaq -0x120(%rbp), %rsi
movq %r12, %rdi
callq 0x788c
movq %r12, %rdi
movq %r14, %rsi
callq 0x788c
movq %r15, %rdi
leaq -0xf0(%rbp), %r14
movq %r14, %rsi
movq %rbx, %rdx
leaq -0xb0(%rbp), %rcx
movq -0x38(%rbp), %r8
callq 0xd093
leaq -0xe0(%rbp), %rsi
movq %r12, %rdi
callq 0x788c
movq %r12, %rdi
movq %r14, %rsi
callq 0x788c
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x7548
movq %r15, %rdi
movq -0x50(%rbp), %rsi
movq %rbx, %rdx
movq -0x48(%rbp), %rcx
callq 0x10e9c
movq -0x58(%rbp), %rax
movl (%rax), %eax
leal -0xe80(%rax), %ecx
cmpl $0x3, %ecx
ja 0xfaa6
leaq 0x32848(%rip), %rax     # 0x422dc
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0x33dbd(%rip), %rsi     # 0x43861
jmp 0xfae3
cmpl $0xe70, %eax            # imm = 0xE70
je 0xfaca
cmpl $0xe71, %eax            # imm = 0xE71
jne 0xfbc0
leaq 0x33de2(%rip), %rsi     # 0x438a1
jmp 0xfae3
leaq 0x33db9(%rip), %rsi     # 0x43881
jmp 0xfae3
leaq 0x33dd1(%rip), %rsi     # 0x438a2
jmp 0xfae3
leaq 0x33db7(%rip), %rsi     # 0x43891
jmp 0xfae3
leaq 0x33d8e(%rip), %rsi     # 0x43871
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
leaq 0x343c9(%rip), %r12     # 0x43eba
cmoveq %r12, %rdx
leaq -0x130(%rbp), %r14
movq 0x28(%r14), %rcx
testq %rcx, %rcx
cmoveq %r12, %rcx
leaq -0xf0(%rbp), %r15
movq 0x28(%r15), %r8
testq %r8, %r8
cmoveq %r12, %r8
movq -0x60(%rbp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x7b31
movq 0x8(%rbx), %rsi
testq %rsi, %rsi
cmoveq %r12, %rsi
addq $0x20, %r13
movq %r13, %rdi
callq 0x75cf
leaq -0x170(%rbp), %rdi
callq 0xd787
leaq -0xb0(%rbp), %rdi
callq 0xd787
movq %r14, %rdi
callq 0xd787
movq %r15, %rdi
callq 0xd787
movq %rbx, %rdi
callq 0x7a38
movb $0x1, %al
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3c0cc(%rip), %rdi     # 0x4bc55
leaq 0x32788(%rip), %rsi     # 0x42318
leaq 0x33c67(%rip), %rcx     # 0x437fe
movl $0xa6d, %edx            # imm = 0xA6D
callq 0x30a0
leaq 0x34373(%rip), %rdi     # 0x43f1b
leaq 0x32769(%rip), %rsi     # 0x42318
leaq 0x33c48(%rip), %rcx     # 0x437fe
movl $0xa70, %edx            # imm = 0xA70
callq 0x30a0
leaq 0x307bd(%rip), %rdi     # 0x40384
leaq 0x3274a(%rip), %rsi     # 0x42318
leaq 0x33c29(%rip), %rcx     # 0x437fe
movl $0xae2, %edx            # imm = 0xAE2
callq 0x30a0