// File: /workspace/github_c_makefile_star2_O0/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
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x17434
jmp 0x17453
leaq 0x6511b(%rip), %rdi     # 0x7c556
leaq 0x5cf52(%rip), %rsi     # 0x74394
movl $0xa61, %edx            # imm = 0xA61
leaq 0x5e5ed(%rip), %rcx     # 0x75a3b
callq 0x30a0
cmpq $0x0, -0x18(%rbp)
je 0x1745c
jmp 0x1747b
leaq 0x5b6ab(%rip), %rdi     # 0x72b0e
leaq 0x5cf2a(%rip), %rsi     # 0x74394
movl $0xa62, %edx            # imm = 0xA62
leaq 0x5e5c5(%rip), %rcx     # 0x75a3b
callq 0x30a0
cmpq $0x0, -0x20(%rbp)
je 0x17484
jmp 0x174a3
leaq 0x5d788(%rip), %rdi     # 0x74c13
leaq 0x5cf02(%rip), %rsi     # 0x74394
movl $0xa63, %edx            # imm = 0xA63
leaq 0x5e59d(%rip), %rcx     # 0x75a3b
callq 0x30a0
cmpq $0x0, -0x28(%rbp)
je 0x174ac
jmp 0x174cb
leaq 0x5eb20(%rip), %rdi     # 0x75fd3
leaq 0x5ceda(%rip), %rsi     # 0x74394
movl $0xa64, %edx            # imm = 0xA64
leaq 0x5e575(%rip), %rcx     # 0x75a3b
callq 0x30a0
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18c(%rbp)
addl $0xfffff190, %eax       # imm = 0xFFFFF190
subl $0x2, %eax
jb 0x174f9
jmp 0x174e3
movl -0x18c(%rbp), %eax
addl $0xfffff180, %eax       # imm = 0xFFFFF180
subl $0x3, %eax
ja 0x17d41
jmp 0x174f9
movq -0x28(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x17505
jmp 0x17524
leaq 0x67168(%rip), %rdi     # 0x7e674
leaq 0x5ce81(%rip), %rsi     # 0x74394
movl $0xa6d, %edx            # imm = 0xA6D
leaq 0x5e51c(%rip), %rcx     # 0x75a3b
callq 0x30a0
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x17539
jmp 0x17558
leaq 0x5ec33(%rip), %rdi     # 0x76173
leaq 0x5ce4d(%rip), %rsi     # 0x74394
movl $0xa70, %edx            # imm = 0xA70
leaq 0x5e4e8(%rip), %rcx     # 0x75a3b
callq 0x30a0
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movb 0x60(%rax), %al
movb %al, -0x59(%rbp)
movq -0x40(%rbp), %rax
movb 0x60(%rax), %al
movb %al, -0x5a(%rbp)
movq $0x0, -0x68(%rbp)
movzbl -0x59(%rbp), %eax
cmpl $0x10, %eax
jne 0x175d0
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
movb -0x59(%rbp), %al
movb %al, -0x69(%rbp)
jmp 0x17630
movzbl -0x5a(%rbp), %eax
cmpl $0x10, %eax
jne 0x175e9
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movb -0x5a(%rbp), %al
movb %al, -0x69(%rbp)
jmp 0x1762e
movzbl -0x59(%rbp), %edi
callq 0x4d130
movl %eax, -0x70(%rbp)
movzbl -0x5a(%rbp), %edi
callq 0x4d130
movl %eax, -0x74(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x74(%rbp), %eax
jle 0x17613
movq -0x50(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x1761b
movq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x68(%rbp), %rsi
callq 0x4d720
movb %al, -0x69(%rbp)
jmp 0x17630
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x113b0
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x113b0
leaq -0x138(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x113b0
leaq -0x178(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x113b0
movq -0x1c0(%rbp), %rdx
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rcx
callq 0x13d10
movq -0x18(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x9100
movq -0x1c0(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x9100
movq -0x1b0(%rbp), %rdx
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x40(%rbp), %rcx
callq 0x13d10
movq -0x18(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x9100
movq -0x1b0(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x9100
movq -0x1c0(%rbp), %rcx
movq -0x1b8(%rbp), %rsi
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x50(%rbp), %r8
callq 0x11460
movq -0x18(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x9100
movq -0x1b8(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x9100
movq -0x1b0(%rbp), %rcx
movq -0x1a8(%rbp), %rsi
movq -0x10(%rbp), %rdi
movq -0x68(%rbp), %rdx
movq -0x58(%rbp), %r8
callq 0x11460
movq -0x18(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x9100
movq -0x1a8(%rbp), %rsi
movq -0x18(%rbp), %rdi
callq 0x9100
leaq -0x188(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
callq 0x8c90
movq -0x1a0(%rbp), %rdx
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rcx
callq 0x1ab00
movq -0x28(%rbp), %rax
movl (%rax), %eax
addl $0xfffff190, %eax       # imm = 0xFFFFF190
movl %eax, %ecx
movq %rcx, -0x198(%rbp)
subl $0x13, %eax
ja 0x17c9a
movq -0x198(%rbp), %rax
leaq 0x5cb58(%rip), %rcx     # 0x74318
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rax
movq %rax, -0x1c8(%rbp)
cmpq $0x0, -0x180(%rbp)
jne 0x177ee
leaq 0x600d0(%rip), %rax     # 0x778b5
movq %rax, -0x1d0(%rbp)
jmp 0x177fc
movq -0x180(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rax
movq %rax, -0x1d8(%rbp)
cmpq $0x0, -0x110(%rbp)
jne 0x17824
leaq 0x6009a(%rip), %rax     # 0x778b5
movq %rax, -0x1e0(%rbp)
jmp 0x17832
movq -0x110(%rbp), %rax
movq %rax, -0x1e0(%rbp)
movq -0x1e0(%rbp), %rax
movq %rax, -0x1e8(%rbp)
cmpq $0x0, -0x150(%rbp)
jne 0x1785a
leaq 0x60064(%rip), %rax     # 0x778b5
movq %rax, -0x1f0(%rbp)
jmp 0x17868
movq -0x150(%rbp), %rax
movq %rax, -0x1f0(%rbp)
movq -0x1e8(%rbp), %rcx
movq -0x1d8(%rbp), %rdx
movq -0x1c8(%rbp), %rdi
movq -0x1f0(%rbp), %r8
leaq 0x5e213(%rip), %rsi     # 0x75a9e
movb $0x0, %al
callq 0x94d0
jmp 0x17cb9
movq -0x20(%rbp), %rax
movq %rax, -0x1f8(%rbp)
cmpq $0x0, -0x180(%rbp)
jne 0x178bc
leaq 0x60002(%rip), %rax     # 0x778b5
movq %rax, -0x200(%rbp)
jmp 0x178ca
movq -0x180(%rbp), %rax
movq %rax, -0x200(%rbp)
movq -0x200(%rbp), %rax
movq %rax, -0x208(%rbp)
cmpq $0x0, -0x110(%rbp)
jne 0x178f2
leaq 0x5ffcc(%rip), %rax     # 0x778b5
movq %rax, -0x210(%rbp)
jmp 0x17900
movq -0x110(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rax
movq %rax, -0x218(%rbp)
cmpq $0x0, -0x150(%rbp)
jne 0x17928
leaq 0x5ff96(%rip), %rax     # 0x778b5
movq %rax, -0x220(%rbp)
jmp 0x17936
movq -0x150(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x218(%rbp), %rcx
movq -0x208(%rbp), %rdx
movq -0x1f8(%rbp), %rdi
movq -0x220(%rbp), %r8
leaq 0x5e155(%rip), %rsi     # 0x75aae
movb $0x0, %al
callq 0x94d0
jmp 0x17cb9
movq -0x20(%rbp), %rax
movq %rax, -0x228(%rbp)
cmpq $0x0, -0x180(%rbp)
jne 0x1798a
leaq 0x5ff34(%rip), %rax     # 0x778b5
movq %rax, -0x230(%rbp)
jmp 0x17998
movq -0x180(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x230(%rbp), %rax
movq %rax, -0x238(%rbp)
cmpq $0x0, -0x110(%rbp)
jne 0x179c0
leaq 0x5fefe(%rip), %rax     # 0x778b5
movq %rax, -0x240(%rbp)
jmp 0x179ce
movq -0x110(%rbp), %rax
movq %rax, -0x240(%rbp)
movq -0x240(%rbp), %rax
movq %rax, -0x248(%rbp)
cmpq $0x0, -0x150(%rbp)
jne 0x179f6
leaq 0x5fec8(%rip), %rax     # 0x778b5
movq %rax, -0x250(%rbp)
jmp 0x17a04
movq -0x150(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x248(%rbp), %rcx
movq -0x238(%rbp), %rdx
movq -0x228(%rbp), %rdi
movq -0x250(%rbp), %r8
leaq 0x5e097(%rip), %rsi     # 0x75abe
movb $0x0, %al
callq 0x94d0
jmp 0x17cb9
movq -0x20(%rbp), %rax
movq %rax, -0x258(%rbp)
cmpq $0x0, -0x180(%rbp)
jne 0x17a58
leaq 0x5fe66(%rip), %rax     # 0x778b5
movq %rax, -0x260(%rbp)
jmp 0x17a66
movq -0x180(%rbp), %rax
movq %rax, -0x260(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x268(%rbp)
cmpq $0x0, -0x110(%rbp)
jne 0x17a8e
leaq 0x5fe30(%rip), %rax     # 0x778b5
movq %rax, -0x270(%rbp)
jmp 0x17a9c
movq -0x110(%rbp), %rax
movq %rax, -0x270(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x278(%rbp)
cmpq $0x0, -0x150(%rbp)
jne 0x17ac4
leaq 0x5fdfa(%rip), %rax     # 0x778b5
movq %rax, -0x280(%rbp)
jmp 0x17ad2
movq -0x150(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x278(%rbp), %rcx
movq -0x268(%rbp), %rdx
movq -0x258(%rbp), %rdi
movq -0x280(%rbp), %r8
leaq 0x5dfd9(%rip), %rsi     # 0x75ace
movb $0x0, %al
callq 0x94d0
jmp 0x17cb9
movq -0x20(%rbp), %rax
movq %rax, -0x288(%rbp)
cmpq $0x0, -0x180(%rbp)
jne 0x17b26
leaq 0x5fd98(%rip), %rax     # 0x778b5
movq %rax, -0x290(%rbp)
jmp 0x17b34
movq -0x180(%rbp), %rax
movq %rax, -0x290(%rbp)
movq -0x290(%rbp), %rax
movq %rax, -0x298(%rbp)
cmpq $0x0, -0x110(%rbp)
jne 0x17b5c
leaq 0x5fd62(%rip), %rax     # 0x778b5
movq %rax, -0x2a0(%rbp)
jmp 0x17b6a
movq -0x110(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
movq %rax, -0x2a8(%rbp)
cmpq $0x0, -0x150(%rbp)
jne 0x17b92
leaq 0x5fd2c(%rip), %rax     # 0x778b5
movq %rax, -0x2b0(%rbp)
jmp 0x17ba0
movq -0x150(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movq -0x2a8(%rbp), %rcx
movq -0x298(%rbp), %rdx
movq -0x288(%rbp), %rdi
movq -0x2b0(%rbp), %r8
leaq 0x5df1c(%rip), %rsi     # 0x75adf
movb $0x0, %al
callq 0x94d0
jmp 0x17cb9
movq -0x20(%rbp), %rax
movq %rax, -0x2b8(%rbp)
cmpq $0x0, -0x180(%rbp)
jne 0x17bf4
leaq 0x5fcca(%rip), %rax     # 0x778b5
movq %rax, -0x2c0(%rbp)
jmp 0x17c02
movq -0x180(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movq -0x2c0(%rbp), %rax
movq %rax, -0x2c8(%rbp)
cmpq $0x0, -0x110(%rbp)
jne 0x17c2a
leaq 0x5fc94(%rip), %rax     # 0x778b5
movq %rax, -0x2d0(%rbp)
jmp 0x17c38
movq -0x110(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x2d0(%rbp), %rax
movq %rax, -0x2d8(%rbp)
cmpq $0x0, -0x150(%rbp)
jne 0x17c60
leaq 0x5fc5e(%rip), %rax     # 0x778b5
movq %rax, -0x2e0(%rbp)
jmp 0x17c6e
movq -0x150(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movq -0x2d8(%rbp), %rcx
movq -0x2c8(%rbp), %rdx
movq -0x2b8(%rbp), %rdi
movq -0x2e0(%rbp), %r8
leaq 0x5de4d(%rip), %rsi     # 0x75ade
movb $0x0, %al
callq 0x94d0
jmp 0x17cb9
leaq 0x5a7ba(%rip), %rdi     # 0x7245b
leaq 0x5c6ec(%rip), %rsi     # 0x74394
movl $0xae2, %edx            # imm = 0xAE2
leaq 0x5dd87(%rip), %rcx     # 0x75a3b
callq 0x30a0
movq -0x20(%rbp), %rax
movq %rax, -0x2e8(%rbp)
cmpq $0x0, -0x180(%rbp)
jne 0x17cde
leaq 0x5fbe0(%rip), %rax     # 0x778b5
movq %rax, -0x2f0(%rbp)
jmp 0x17cec
movq -0x180(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movq -0x2e8(%rbp), %rdi
movq -0x2f0(%rbp), %rsi
callq 0x1a6c0
leaq -0xb8(%rbp), %rdi
callq 0x130a0
leaq -0xf8(%rbp), %rdi
callq 0x130a0
leaq -0x138(%rbp), %rdi
callq 0x130a0
leaq -0x178(%rbp), %rdi
callq 0x130a0
leaq -0x188(%rbp), %rdi
callq 0x9310
movb $0x1, -0x1(%rbp)
jmp 0x17d45
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
nopw %cs:(%rax,%rax)