// File: /workspace/github_c_makefile_star2_O1/Ihsoh[P]ilang/compiler/frontend/irgen_llvmir.c
// Function: ir_expr_logic
static bool _ir_expr_logic(
	IRGeneratorLlvmirContext *ctx,
	ResizableString *rstr,
	_ExprResult *expr_result,
	ParserASTNode *node
) {
	assert(ctx);
	assert(rstr);
	assert(expr_result);
	assert(node);

	switch (node->type) {
		case FE_NODE_EXPR_AND:
		case FE_NODE_EXPR_OR: {
			assert(node->nchilds == 2);

			ParserASTNode *node_type = FE_EXPR_AST_NODE_GET_TYPE_NODE(node);
			
			ResizableString rstr_type;
			rstr_init(&rstr_type);
			_ir_type(ctx, &rstr_type, node_type);

			_TMP_LABEL_DEF(ctx, lhs)
			_TMP_LABEL_DEF(ctx, rhs)
			_TMP_LABEL_DEF(ctx, rhs1)
			_TMP_LABEL_DEF(ctx, end)
			_TMP_LABEL_DEF(ctx, result)
			_TMP_LABEL_DEF(ctx, result_casted)

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

			_ExprResult result_lhs;
			_expr_result_init(&result_lhs);

			_ExprResult result_rhs;
			_expr_result_init(&result_rhs);

			_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));

			ResizableString rstr_lhs_cond;
			rstr_init(&rstr_lhs_cond);
			_ir_cond_expr_with_rstr(ctx, rstr, &rstr_lhs_cond, &result_lhs, node_lhs);

			// 左表达式的Basic Block的标号。
			rstr_appendf(
				rstr,
				"br label %s\n%s:\n",
				_TMP_LABEL_CSTR(lhs),
				_TMP_LABEL_NAME_CSTR(lhs)
			);

			if (node->type == FE_NODE_EXPR_AND) {
				rstr_appendf(
					rstr,
					"br i1 %s, label %s, label %s\n",
					RSTR_CSTR(&rstr_lhs_cond),
					_TMP_LABEL_CSTR(rhs),
					_TMP_LABEL_CSTR(end)
				);
			} else if (node->type == FE_NODE_EXPR_OR) {
				rstr_appendf(
					rstr,
					"br i1 %s, label %s, label %s\n",
					RSTR_CSTR(&rstr_lhs_cond),
					_TMP_LABEL_CSTR(end),
					_TMP_LABEL_CSTR(rhs)
				);
			} else {
				assert(0);
			}

			// 右表达式的Basic Block的标号。
			rstr_appendf(
				rstr,
				"br label %s\n%s:\n",
				_TMP_LABEL_CSTR(rhs),
				_TMP_LABEL_NAME_CSTR(rhs)
			);

			_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));

			ResizableString rstr_rhs_cond;
			rstr_init(&rstr_rhs_cond);
			_ir_cond_expr_with_rstr(ctx, rstr, &rstr_rhs_cond, &result_rhs, node_rhs);

			rstr_appendf(
				rstr,
				"br label %s\n%s:\n",
				_TMP_LABEL_CSTR(rhs1),
				_TMP_LABEL_NAME_CSTR(rhs1)
			);

			// 结束的Basic Block的标号。
			rstr_appendf(
				rstr,
				"br label %s\n%s:\n",
				_TMP_LABEL_CSTR(end),
				_TMP_LABEL_NAME_CSTR(end)
			);

			if (node->type == FE_NODE_EXPR_AND) {
				rstr_appendf(
					&(expr_result->rstr_for_result),
					"%s = phi i1 [ false, %s ], [ %s, %s ]\n",
					_TMP_LABEL_CSTR(result),
					_TMP_LABEL_CSTR(lhs),
					RSTR_CSTR(&rstr_rhs_cond),
					_TMP_LABEL_CSTR(rhs1)
				);
			} else if (node->type == FE_NODE_EXPR_OR) {
				rstr_appendf(
					&(expr_result->rstr_for_result),
					"%s = phi i1 [ true, %s ], [ %s, %s ]\n",
					_TMP_LABEL_CSTR(result),
					_TMP_LABEL_CSTR(lhs),
					RSTR_CSTR(&rstr_rhs_cond),
					_TMP_LABEL_CSTR(rhs1)
				);
			} else {
				assert(0);
			}

			rstr_appendf(
				&(expr_result->rstr_for_result),
				"%s = zext i1 %s to %s\n",
				_TMP_LABEL_CSTR(result_casted),
				_TMP_LABEL_CSTR(result),
				RSTR_CSTR(&rstr_type)
			);
			_expr_result_set_result(
				expr_result,
				RSTR_CSTR(&rstr_type),
				_TMP_LABEL_CSTR(result_casted)
			);

			rstr_free(&rstr_type);

			_TMP_LABEL_FREE(lhs)
			_TMP_LABEL_FREE(rhs)
			_TMP_LABEL_FREE(rhs1)
			_TMP_LABEL_FREE(end)
			_TMP_LABEL_FREE(result)
			_TMP_LABEL_FREE(result_casted)

			_expr_result_free(&result_lhs);
			_expr_result_free(&result_rhs);

			rstr_free(&rstr_lhs_cond);

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl (%rcx), %eax
orl $0x10, %eax
cmpl $0xe30, %eax            # imm = 0xE30
jne 0x1d528
movq %rdx, -0x60(%rbp)
cmpl $0x2, 0x44(%rcx)
jne 0x1d771
movq %rsi, %r15
movq %rdi, %r12
movq 0x68(%rcx), %rbx
leaq -0xd0(%rbp), %r13
movq %r13, %rdi
movq %rcx, %r14
movq %rcx, -0x30(%rbp)
callq 0x7548
movq %r13, %rdi
movq %rbx, %rsi
callq 0x198ea
leaq -0x80(%rbp), %rbx
movq %rbx, %rdi
callq 0x7548
movq 0x40(%r12), %rdi
movq %rbx, %rsi
callq 0x1e318
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x7548
movq 0x40(%r12), %rdi
movq %rbx, %rsi
callq 0x1e318
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x7548
movq 0x40(%r12), %rdi
movq %rbx, %rsi
callq 0x1e318
leaq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x7548
movq 0x40(%r12), %rdi
movq %rbx, %rsi
callq 0x1e318
leaq -0xc0(%rbp), %rbx
movq %rbx, %rdi
callq 0x7548
movq 0x40(%r12), %rdi
movq %rbx, %rsi
callq 0x1e318
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
callq 0x7548
movq 0x40(%r12), %rdi
movq %rbx, %rsi
callq 0x1e318
movq 0x48(%r14), %rax
movq (%rax), %rbx
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
leaq -0x1d0(%rbp), %r13
movq %r13, %rdi
callq 0x19eca
leaq -0x150(%rbp), %rdi
callq 0x19eca
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1ad56
leaq -0x1c0(%rbp), %rsi
movq %r15, %rdi
callq 0x788c
movq %r15, %rdi
movq %r13, %rsi
callq 0x788c
leaq -0x90(%rbp), %r14
movq %r14, %rdi
callq 0x7548
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
movq %rbx, %r8
callq 0x20138
leaq -0x80(%rbp), %rax
movq 0x8(%rax), %rdx
testq %rdx, %rdx
leaq 0x269e8(%rip), %rbx     # 0x43eba
cmoveq %rbx, %rdx
leaq 0x1(%rdx), %rcx
leaq 0x297e2(%rip), %rsi     # 0x46cc3
movq %r15, %rdi
xorl %eax, %eax
callq 0x7b31
movq -0x30(%rbp), %rax
movl (%rax), %ecx
cmpl $0xe30, %ecx            # imm = 0xE30
je 0x1d52f
leaq -0x38(%rbp), %rax
cmpl $0xe20, %ecx            # imm = 0xE20
leaq -0x48(%rbp), %rsi
je 0x1d537
leaq 0x22e74(%rip), %rdi     # 0x40384
leaq 0x2835d(%rip), %rsi     # 0x45874
leaq 0x29741(%rip), %rcx     # 0x46c5f
movl $0x10b1, %edx           # imm = 0x10B1
callq 0x30a0
xorl %eax, %eax
jmp 0x1d75f
leaq -0x48(%rbp), %rax
leaq -0x38(%rbp), %rsi
movq -0x88(%rbp), %rdx
testq %rdx, %rdx
cmoveq %rbx, %rdx
movq (%rax), %rcx
testq %rcx, %rcx
cmoveq %rbx, %rcx
movq (%rsi), %r8
testq %r8, %r8
cmoveq %rbx, %r8
leaq 0x29774(%rip), %rsi     # 0x46cd4
movq %r15, %rdi
xorl %eax, %eax
callq 0x7b31
movq -0x48(%rbp), %rdx
testq %rdx, %rdx
cmoveq %rbx, %rdx
leaq 0x1(%rdx), %rcx
leaq 0x29743(%rip), %rsi     # 0x46cc3
movq %r15, %rdi
xorl %eax, %eax
callq 0x7b31
leaq -0x150(%rbp), %r14
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq -0x58(%rbp), %rbx
movq %rbx, %rcx
callq 0x1ad56
leaq -0x140(%rbp), %rsi
movq %r15, %rdi
callq 0x788c
movq %r15, %rdi
movq %r14, %rsi
callq 0x788c
leaq -0xa0(%rbp), %r13
movq %r13, %rdi
callq 0x7548
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbx, %r8
leaq 0x268d5(%rip), %rbx     # 0x43eba
callq 0x20138
movq -0x68(%rbp), %rdx
testq %rdx, %rdx
cmoveq %rbx, %rdx
leaq 0x1(%rdx), %rcx
movq %r15, %rdi
leaq 0x296c0(%rip), %r14     # 0x46cc3
movq %r14, %rsi
xorl %eax, %eax
callq 0x7b31
movq -0x38(%rbp), %rdx
testq %rdx, %rdx
cmoveq %rbx, %rdx
leaq 0x1(%rdx), %rcx
movq %r15, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x7b31
movq -0x30(%rbp), %rax
movl (%rax), %eax
cmpl $0xe30, %eax            # imm = 0xE30
je 0x1d64a
cmpl $0xe20, %eax            # imm = 0xE20
jne 0x1d790
leaq 0x296d1(%rip), %rsi     # 0x46d19
jmp 0x1d651
leaq 0x296a1(%rip), %rsi     # 0x46cf2
leaq -0xc0(%rbp), %r14
movq 0x8(%r14), %rdx
testq %rdx, %rdx
cmoveq %rbx, %rdx
leaq -0x80(%rbp), %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
cmoveq %rbx, %rcx
movq -0x98(%rbp), %r8
testq %r8, %r8
cmoveq %rbx, %r8
leaq -0x70(%rbp), %rax
movq 0x8(%rax), %r9
testq %r9, %r9
cmoveq %rbx, %r9
movq -0x60(%rbp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x7b31
leaq -0xb0(%rbp), %r12
movq 0x8(%r12), %rdx
testq %rdx, %rdx
cmoveq %rbx, %rdx
movq 0x8(%r14), %rcx
testq %rcx, %rcx
cmoveq %rbx, %rcx
leaq -0xd0(%rbp), %r13
movq 0x8(%r13), %r8
testq %r8, %r8
cmoveq %rbx, %r8
leaq 0x28bff(%rip), %rsi     # 0x462d3
movq %r15, %rdi
xorl %eax, %eax
callq 0x7b31
movq 0x8(%r13), %rsi
testq %rsi, %rsi
cmoveq %rbx, %rsi
movq 0x8(%r12), %rdx
testq %rdx, %rdx
cmoveq %rbx, %rdx
movq %r15, %rdi
callq 0x1e280
movq %r13, %rdi
callq 0x7a38
leaq -0x80(%rbp), %rdi
callq 0x7a38
leaq -0x50(%rbp), %rdi
callq 0x7a38
leaq -0x70(%rbp), %rdi
callq 0x7a38
leaq -0x40(%rbp), %rdi
callq 0x7a38
movq %r14, %rdi
callq 0x7a38
movq %r12, %rdi
callq 0x7a38
leaq -0x1d0(%rbp), %rdi
callq 0x1a7ab
leaq -0x150(%rbp), %rdi
callq 0x1a7ab
leaq -0x90(%rbp), %rdi
callq 0x7a38
movb $0x1, %al
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2e4dd(%rip), %rdi     # 0x4bc55
leaq 0x280f5(%rip), %rsi     # 0x45874
leaq 0x294d9(%rip), %rcx     # 0x46c5f
movl $0x1078, %edx           # imm = 0x1078
callq 0x30a0
leaq 0x22bed(%rip), %rdi     # 0x40384
leaq 0x280d6(%rip), %rsi     # 0x45874
leaq 0x294ba(%rip), %rcx     # 0x46c5f
movl $0x10e6, %edx           # imm = 0x10E6
callq 0x30a0