// File: /workspace/github_c_makefile_star2_O2/Ihsoh[P]ilang/compiler/frontend/irgen_llvmir.c
// Function: ir_expr_add
static void _ir_expr_add(
	IRGeneratorLlvmirContext *ctx,
	ResizableString *rstr,
	ResizableString *rstr_result_lhs_ptr,
	_ExprResult *expr_result,
	ParserASTNode *node
) {
	assert(ctx);
	assert(rstr);
	assert(expr_result);
	assert(node);
	assert(node->type == FE_NODE_EXPR_ADD
			|| node->type == FE_NODE_EXPR_ADD_ASSIGN);

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

	uint8_t type1 = FE_EXPR_AST_NODE_GET_TYPE(node->childs[0]);
	uint8_t type2 = FE_EXPR_AST_NODE_GET_TYPE(node->childs[1]);

	if ((fe_sem_is_pointer_type(type1) && fe_sem_is_integer_type(type2))) {
		ParserASTNode *node_lhs = NULL;
		ParserASTNode *node_rhs = NULL;

		if (fe_sem_is_pointer_type(type1) && fe_sem_is_integer_type(type2)) {
			node_lhs = node->childs[0];
			node_rhs = node->childs[1];
		} else if (fe_sem_is_integer_type(type1) && fe_sem_is_pointer_type(type2)) {
			node_lhs = node->childs[1];
			node_rhs = node->childs[0];
		} else {
			assert(0);
		}

		_ExprResult result_lhs;
		_ExprResult result_rhs;

		_expr_result_init(&result_lhs);
		_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));

		if (rstr_result_lhs_ptr != NULL) {
			rstr_append_with_rstr(
				rstr_result_lhs_ptr,
				&(result_lhs.rstr_result_ptr)
			);
		}

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

		ParserASTNode *node_lhs_ptr_type = FE_EXPR_AST_NODE_GET_TYPE_NODE(node_lhs);
		assert(node_lhs_ptr_type->type == FE_NODE_TYPE_POINTER);
		ParserASTNode *node_lhs_type = node_lhs_ptr_type->childs[0];

		ResizableString rstr_lhs_type;
		rstr_init(&rstr_lhs_type);
		_ir_type(ctx, &rstr_lhs_type, node_lhs_type);

		ResizableString rstr_tmp_label_val;
		rstr_init(&rstr_tmp_label_val);
		_generate_func_tmp(ctx, func_symbol, &rstr_tmp_label_val);

		rstr_appendf(
			&(expr_result->rstr_for_result),
			"%s = getelementptr inbounds %s, %s, %s\n",
			RSTR_CSTR(&rstr_tmp_label_val),
			RSTR_CSTR(&rstr_lhs_type),
			RSTR_CSTR(&(result_lhs.rstr_result)),
			RSTR_CSTR(&(result_rhs.rstr_result))
		);
		_expr_result_set_result(
			expr_result,
			RSTR_CSTR(&(result_lhs.rstr_result_type)),
			RSTR_CSTR(&rstr_tmp_label_val)
		);

		_expr_result_free(&result_lhs);
		_expr_result_free(&result_rhs);
		rstr_free(&rstr_lhs_type);
		rstr_free(&rstr_tmp_label_val);
	} else if (fe_sem_is_number_type(type1) && fe_sem_is_number_type(type2)) {
		ParserASTNode *node_type = FE_EXPR_AST_NODE_GET_TYPE_NODE(node);
		uint8_t type = FE_EXPR_AST_NODE_GET_TYPE(node);

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

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

		if (rstr_result_lhs_ptr != NULL) {
			rstr_append_with_rstr(
				rstr_result_lhs_ptr,
				&(result_lhs.rstr_result_ptr)
			);
		}

		_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_type,
			&result_lhs,
			FE_EXPR_AST_NODE_GET_TYPE_NODE(node_lhs)
		);
		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_type,
			&result_rhs,
			FE_EXPR_AST_NODE_GET_TYPE_NODE(node_rhs)
		);
		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(ctx, func_symbol, &rstr_tmp_label_val);

		if (fe_sem_is_signed_type(type)) {
			rstr_appendf(
				&(expr_result->rstr_for_result),
				"%s = add nsw %s, %s\n",
				RSTR_CSTR(&rstr_tmp_label_val),
				RSTR_CSTR(&(result_lhs_casted.rstr_result)),
				RSTR_CSTR(&(result_rhs_casted.rstr_result_val))
			);
		} else if (fe_sem_is_unsigned_type(type)) {
			rstr_appendf(
				&(expr_result->rstr_for_result),
				"%s = add %s, %s\n",
				RSTR_CSTR(&rstr_tmp_label_val),
				RSTR_CSTR(&(result_lhs_casted.rstr_result)),
				RSTR_CSTR(&(result_rhs_casted.rstr_result_val))
			);
		} else if (fe_sem_is_float_type(type)) {
			rstr_appendf(
				&(expr_result->rstr_for_result),
				"%s = fadd %s, %s\n",
				RSTR_CSTR(&rstr_tmp_label_val),
				RSTR_CSTR(&(result_lhs_casted.rstr_result)),
				RSTR_CSTR(&(result_rhs_casted.rstr_result_val))
			);
		} else {
			assert(0);
		}
		_expr_result_set_result(
			expr_result,
			RSTR_CSTR(&(result_lhs_casted.rstr_result_type)),
			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);
	} else {
		assert(0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
testq %rcx, %rcx
je 0x1db27
movq %r8, %rbx
movq %rsi, %r15
movq %rdi, %r12
movl (%r8), %eax
cmpl $0xe11, %eax            # imm = 0xE11
je 0x1d68d
cmpl $0xea0, %eax            # imm = 0xEA0
jne 0x1db65
movq %rdx, -0x48(%rbp)
movq %rcx, -0x38(%rbp)
movq 0x40(%r12), %rax
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x1db46
movq 0x48(%rbx), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movb 0x60(%rax), %r14b
movzbl 0x60(%rcx), %r13d
movl %r13d, %edi
callq 0x2832b
movzbl %r14b, %r14d
testb %al, %al
je 0x1d704
movl %r14d, %edi
callq 0x282fa
testb %al, %al
je 0x1d704
movl %r13d, %edi
callq 0x2832b
testb %al, %al
je 0x1d8ab
movl %r14d, %edi
callq 0x282fa
testb %al, %al
je 0x1d8ab
movq 0x48(%rbx), %rcx
leaq 0x8(%rcx), %rax
jmp 0x1d8d3
movl %r13d, %edi
callq 0x28337
testb %al, %al
je 0x1db08
movl %r14d, %edi
callq 0x28337
testb %al, %al
je 0x1db08
movq 0x68(%rbx), %rax
movq %rax, -0x50(%rbp)
movb 0x60(%rbx), %al
movb %al, -0x29(%rbp)
movq 0x48(%rbx), %rax
movq (%rax), %r13
movq 0x8(%rax), %rbx
leaq -0x160(%rbp), %r14
movq %r14, %rdi
callq 0x188c9
leaq -0xe0(%rbp), %rdi
callq 0x188c9
leaq -0x260(%rbp), %rdi
callq 0x188c9
leaq -0x1e0(%rbp), %rdi
callq 0x188c9
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %r13, %rcx
callq 0x19792
leaq -0x150(%rbp), %rsi
movq %r15, %rdi
callq 0x712e
movq %r15, %rdi
movq %r14, %rsi
callq 0x712e
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1d7b0
leaq -0x110(%rbp), %rsi
callq 0x712e
leaq -0xe0(%rbp), %rdx
movq %r12, %r14
movq %r12, %rdi
movq %r15, %rsi
movq %rdx, %r12
movq %rbx, %rcx
callq 0x19792
leaq -0xd0(%rbp), %rsi
movq %r15, %rdi
callq 0x712e
movq %r15, %rdi
movq %r12, %rsi
callq 0x712e
movq 0x68(%r13), %r8
leaq -0x260(%rbp), %r13
leaq -0x160(%rbp), %rcx
movq %r14, %rdi
movq %r13, %rsi
movq -0x50(%rbp), %r12
movq %r12, %rdx
callq 0x1896e
leaq -0x250(%rbp), %rsi
movq %r15, %rdi
callq 0x712e
movq %r15, %rdi
movq %r13, %rsi
callq 0x712e
movq 0x68(%rbx), %r8
leaq -0x1e0(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
leaq -0xe0(%rbp), %rcx
callq 0x1896e
leaq -0x1d0(%rbp), %rsi
movq %r15, %rdi
callq 0x712e
movq %r15, %rdi
movq %rbx, %rsi
callq 0x712e
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x6e1c
movq -0x40(%rbp), %rdi
movq %rbx, %rsi
callq 0x1cc34
movzbl -0x29(%rbp), %ebx
movl %ebx, %edi
callq 0x282d9
testb %al, %al
je 0x1d890
leaq 0x24f6c(%rip), %rsi     # 0x427f7
jmp 0x1da60
movl %ebx, %edi
callq 0x282e9
testb %al, %al
je 0x1da4a
leaq 0x24f66(%rip), %rsi     # 0x4280c
jmp 0x1da60
movl %r13d, %edi
callq 0x282fa
testb %al, %al
je 0x1db84
movl %r14d, %edi
callq 0x2832b
testb %al, %al
je 0x1db84
movq 0x48(%rbx), %rax
leaq 0x8(%rax), %rcx
movq (%rcx), %rbx
movq (%rax), %r14
leaq -0x160(%rbp), %r13
movq %r13, %rdi
callq 0x188c9
leaq -0xe0(%rbp), %rdi
callq 0x188c9
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x19792
leaq -0x150(%rbp), %rsi
movq %r15, %rdi
callq 0x712e
movq %r15, %rdi
movq %r13, %rsi
callq 0x712e
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1d934
leaq -0x110(%rbp), %rsi
callq 0x712e
leaq -0xe0(%rbp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0x19792
leaq -0xd0(%rbp), %rsi
movq %r15, %rdi
callq 0x712e
movq %r15, %rdi
movq %r13, %rsi
callq 0x712e
movq 0x68(%rbx), %rax
cmpl $0x440, (%rax)          # imm = 0x440
jne 0x1dba3
movq 0x48(%rax), %rax
movq (%rax), %r14
leaq -0x260(%rbp), %rbx
movq %rbx, %rdi
callq 0x6e1c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x18312
leaq -0x1e0(%rbp), %r14
movq %r14, %rdi
callq 0x6e1c
movq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x1cc34
movq 0x8(%r14), %rdx
testq %rdx, %rdx
leaq 0x22556(%rip), %r13     # 0x3ff16
cmoveq %r13, %rdx
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
cmoveq %r13, %rcx
leaq -0x160(%rbp), %r15
movq 0x28(%r15), %r8
testq %r8, %r8
cmoveq %r13, %r8
leaq -0xe0(%rbp), %rax
movq 0x28(%rax), %r9
testq %r9, %r9
cmoveq %r13, %r9
leaq 0x24937(%rip), %rsi     # 0x42331
movq -0x38(%rbp), %r12
movq %r12, %rdi
xorl %eax, %eax
callq 0x739a
movq 0x38(%r15), %rsi
testq %rsi, %rsi
cmoveq %r13, %rsi
movq 0x8(%r14), %rdx
testq %rdx, %rdx
cmoveq %r13, %rdx
movq %r12, %rdi
callq 0x1cba4
movq %r15, %rdi
callq 0x191df
leaq -0xe0(%rbp), %rdi
callq 0x191df
movq %rbx, %rdi
callq 0x72b9
movq %r14, %rdi
jmp 0x1daf1
movl %ebx, %edi
callq 0x2830a
testb %al, %al
je 0x1dbc2
leaq 0x24dbd(%rip), %rsi     # 0x4281d
leaq -0x60(%rbp), %rbx
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
leaq 0x224a4(%rip), %r12     # 0x3ff16
cmoveq %r12, %rdx
leaq -0x260(%rbp), %r14
movq 0x28(%r14), %rcx
testq %rcx, %rcx
cmoveq %r12, %rcx
leaq -0x1e0(%rbp), %r15
movq 0x48(%r15), %r8
testq %r8, %r8
cmoveq %r12, %r8
movq -0x38(%rbp), %r13
movq %r13, %rdi
xorl %eax, %eax
callq 0x739a
movq 0x38(%r14), %rsi
testq %rsi, %rsi
cmoveq %r12, %rsi
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
cmoveq %r12, %rdx
movq %r13, %rdi
callq 0x1cba4
leaq -0x160(%rbp), %rdi
callq 0x191df
leaq -0xe0(%rbp), %rdi
callq 0x191df
movq %r14, %rdi
callq 0x191df
movq %r15, %rdi
callq 0x191df
movq %rbx, %rdi
callq 0x72b9
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1e851(%rip), %rdi     # 0x3c360
leaq 0x23e72(%rip), %rsi     # 0x41988
leaq 0x24c36(%rip), %rcx     # 0x42753
movl $0xd4d, %edx            # imm = 0xD4D
callq 0x30a0
leaq 0x210b6(%rip), %rdi     # 0x3ebe4
leaq 0x23e53(%rip), %rsi     # 0x41988
leaq 0x24c17(%rip), %rcx     # 0x42753
movl $0xca2, %edx            # imm = 0xCA2
callq 0x30a0
leaq 0x2242a(%rip), %rdi     # 0x3ff77
leaq 0x23e34(%rip), %rsi     # 0x41988
leaq 0x24bf8(%rip), %rcx     # 0x42753
movl $0xca8, %edx            # imm = 0xCA8
callq 0x30a0
leaq 0x219c6(%rip), %rdi     # 0x3f532
leaq 0x23e15(%rip), %rsi     # 0x41988
leaq 0x24bd9(%rip), %rcx     # 0x42753
movl $0xca5, %edx            # imm = 0xCA5
callq 0x30a0
leaq 0x1e7d5(%rip), %rdi     # 0x3c360
leaq 0x23df6(%rip), %rsi     # 0x41988
leaq 0x24bba(%rip), %rcx     # 0x42753
movl $0xcb8, %edx            # imm = 0xCB8
callq 0x30a0
leaq 0x24c1d(%rip), %rdi     # 0x427c7
leaq 0x23dd7(%rip), %rsi     # 0x41988
leaq 0x24b9b(%rip), %rcx     # 0x42753
movl $0xcd1, %edx            # imm = 0xCD1
callq 0x30a0
leaq 0x1e797(%rip), %rdi     # 0x3c360
leaq 0x23db8(%rip), %rsi     # 0x41988
leaq 0x24b7c(%rip), %rcx     # 0x42753
movl $0xd3f, %edx            # imm = 0xD3F
callq 0x30a0