// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/frontend/irgen.c
// Function: ir_expr_add
static void _ir_expr_add(
	IRGeneratorContext *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 = node->childs[0];
		ParserASTNode *node_rhs = node->childs[1];

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

		ResizableString rstr_tmp_label_val;
		rstr_init(&rstr_tmp_label_val);
		_generate_func_tmp_var(
			ctx,
			func_symbol,
			&rstr_tmp_label_val,
			FE_EXPR_AST_NODE_GET_TYPE_NODE(node)
		);

		rstr_appendf(
			&(expr_result->rstr_for_result),
			"add %s, %s, %s;\n",
			RSTR_CSTR(&rstr_tmp_label_val),
			RSTR_CSTR(&(result_lhs.rstr_result)),
			RSTR_CSTR(&(result_rhs.rstr_result))
		);

		_expr_result_set_result(
			expr_result,
			RSTR_CSTR(&rstr_tmp_label_val)
		);

		_expr_result_free(&result_lhs);
		_expr_result_free(&result_rhs);
		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);

		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_var(
			ctx,
			func_symbol,
			&rstr_tmp_label_val,
			node_type
		);

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

		_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);
	} else {
		assert(0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x280, %rsp            # imm = 0x280
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x1ba28
jmp 0x1ba47
leaq 0x60b27(%rip), %rdi     # 0x7c556
leaq 0x5895e(%rip), %rsi     # 0x74394
movl $0x848, %edx            # imm = 0x848
leaq 0x59c63(%rip), %rcx     # 0x756a5
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x1ba50
jmp 0x1ba6f
leaq 0x570b7(%rip), %rdi     # 0x72b0e
leaq 0x58936(%rip), %rsi     # 0x74394
movl $0x849, %edx            # imm = 0x849
leaq 0x59c3b(%rip), %rcx     # 0x756a5
callq 0x30a0
cmpq $0x0, -0x20(%rbp)
je 0x1ba78
jmp 0x1ba97
leaq 0x59194(%rip), %rdi     # 0x74c13
leaq 0x5890e(%rip), %rsi     # 0x74394
movl $0x84a, %edx            # imm = 0x84A
leaq 0x59c13(%rip), %rcx     # 0x756a5
callq 0x30a0
cmpq $0x0, -0x28(%rbp)
je 0x1baa0
jmp 0x1babf
leaq 0x5a52c(%rip), %rdi     # 0x75fd3
leaq 0x588e6(%rip), %rsi     # 0x74394
movl $0x84b, %edx            # imm = 0x84B
leaq 0x59beb(%rip), %rcx     # 0x756a5
callq 0x30a0
movq -0x28(%rbp), %rax
cmpl $0xea0, (%rax)          # imm = 0xEA0
je 0x1bad7
movq -0x28(%rbp), %rax
cmpl $0xe11, (%rax)          # imm = 0xE11
jne 0x1bad9
jmp 0x1baf8
leaq 0x59c33(%rip), %rdi     # 0x75713
leaq 0x588ad(%rip), %rsi     # 0x74394
movl $0x84d, %edx            # imm = 0x84D
leaq 0x59bb2(%rip), %rcx     # 0x756a5
callq 0x30a0
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1bb0d
jmp 0x1bb2c
leaq 0x5a65f(%rip), %rdi     # 0x76173
leaq 0x58879(%rip), %rsi     # 0x74394
movl $0x850, %edx            # imm = 0x850
leaq 0x59b7e(%rip), %rcx     # 0x756a5
callq 0x30a0
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movb 0x60(%rax), %al
movb %al, -0x31(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movb 0x60(%rax), %al
movb %al, -0x32(%rbp)
movzbl -0x31(%rbp), %edi
callq 0x4d4a0
testb $0x1, %al
jne 0x1bb61
jmp 0x1bd97
movzbl -0x32(%rbp), %edi
callq 0x4d3b0
testb $0x1, %al
jne 0x1bb73
jmp 0x1bd97
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x113b0
leaq -0xc8(%rbp), %rdi
callq 0x113b0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rcx
leaq -0x88(%rbp), %rdx
callq 0x13d10
movq -0x10(%rbp), %rdi
leaq -0x88(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x9100
cmpq $0x0, -0x18(%rbp)
je 0x1bc01
movq -0x18(%rbp), %rdi
leaq -0x88(%rbp), %rsi
addq $0x30, %rsi
callq 0x9100
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rcx
leaq -0xc8(%rbp), %rdx
callq 0x13d10
movq -0x10(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x9100
leaq -0xd8(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rcx
leaq -0xd8(%rbp), %rdx
callq 0x1ab00
movq -0x20(%rbp), %rax
movq %rax, -0x208(%rbp)
cmpq $0x0, -0xd0(%rbp)
jne 0x1bc8a
leaq 0x5bc34(%rip), %rax     # 0x778b5
movq %rax, -0x210(%rbp)
jmp 0x1bc98
movq -0xd0(%rbp), %rax
movq %rax, -0x210(%rbp)
movq -0x210(%rbp), %rax
movq %rax, -0x218(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x1bcbd
leaq 0x5bc01(%rip), %rax     # 0x778b5
movq %rax, -0x220(%rbp)
jmp 0x1bcc8
movq -0x60(%rbp), %rax
movq %rax, -0x220(%rbp)
movq -0x220(%rbp), %rax
movq %rax, -0x228(%rbp)
cmpq $0x0, -0xa0(%rbp)
jne 0x1bcf0
leaq 0x5bbce(%rip), %rax     # 0x778b5
movq %rax, -0x230(%rbp)
jmp 0x1bcfe
movq -0xa0(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x228(%rbp), %rcx
movq -0x218(%rbp), %rdx
movq -0x208(%rbp), %rdi
movq -0x230(%rbp), %r8
leaq 0x59421(%rip), %rsi     # 0x75142
movb $0x0, %al
callq 0x94d0
movq -0x20(%rbp), %rax
movq %rax, -0x238(%rbp)
cmpq $0x0, -0xd0(%rbp)
jne 0x1bd4d
leaq 0x5bb71(%rip), %rax     # 0x778b5
movq %rax, -0x240(%rbp)
jmp 0x1bd5b
movq -0xd0(%rbp), %rax
movq %rax, -0x240(%rbp)
movq -0x238(%rbp), %rdi
movq -0x240(%rbp), %rsi
callq 0x1a6c0
leaq -0x88(%rbp), %rdi
callq 0x130a0
leaq -0xc8(%rbp), %rdi
callq 0x130a0
leaq -0xd8(%rbp), %rdi
callq 0x9310
jmp 0x1c0e7
movzbl -0x31(%rbp), %edi
callq 0x4d4e0
testb $0x1, %al
jne 0x1bda9
jmp 0x1c0c6
movzbl -0x32(%rbp), %edi
callq 0x4d4e0
testb $0x1, %al
jne 0x1bdbb
jmp 0x1c0c6
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0xe8(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf0(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x113b0
leaq -0x170(%rbp), %rdi
callq 0x113b0
leaq -0x1b0(%rbp), %rdi
callq 0x113b0
leaq -0x1f0(%rbp), %rdi
callq 0x113b0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0xe8(%rbp), %rcx
leaq -0x130(%rbp), %rdx
callq 0x13d10
movq -0x10(%rbp), %rdi
leaq -0x130(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x9100
cmpq $0x0, -0x18(%rbp)
je 0x1be79
movq -0x18(%rbp), %rdi
leaq -0x130(%rbp), %rsi
addq $0x30, %rsi
callq 0x9100
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0xf0(%rbp), %rcx
leaq -0x170(%rbp), %rdx
callq 0x13d10
movq -0x10(%rbp), %rdi
leaq -0x170(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x9100
movq -0x8(%rbp), %rdi
movq -0xe0(%rbp), %rdx
movq -0xe8(%rbp), %rax
movq 0x68(%rax), %r8
leaq -0x1b0(%rbp), %rsi
leaq -0x130(%rbp), %rcx
callq 0x11460
movq -0x10(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x9100
movq -0x8(%rbp), %rdi
movq -0xe0(%rbp), %rdx
movq -0xf0(%rbp), %rax
movq 0x68(%rax), %r8
leaq -0x1f0(%rbp), %rsi
leaq -0x170(%rbp), %rcx
callq 0x11460
movq -0x10(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x9100
leaq -0x200(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0xe0(%rbp), %rcx
leaq -0x200(%rbp), %rdx
callq 0x1ab00
movq -0x20(%rbp), %rax
movq %rax, -0x248(%rbp)
cmpq $0x0, -0x1f8(%rbp)
jne 0x1bf9e
leaq 0x5b920(%rip), %rax     # 0x778b5
movq %rax, -0x250(%rbp)
jmp 0x1bfac
movq -0x1f8(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x250(%rbp), %rax
movq %rax, -0x258(%rbp)
cmpq $0x0, -0x188(%rbp)
jne 0x1bfd4
leaq 0x5b8ea(%rip), %rax     # 0x778b5
movq %rax, -0x260(%rbp)
jmp 0x1bfe2
movq -0x188(%rbp), %rax
movq %rax, -0x260(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x268(%rbp)
cmpq $0x0, -0x1c8(%rbp)
jne 0x1c00a
leaq 0x5b8b4(%rip), %rax     # 0x778b5
movq %rax, -0x270(%rbp)
jmp 0x1c018
movq -0x1c8(%rbp), %rax
movq %rax, -0x270(%rbp)
movq -0x268(%rbp), %rcx
movq -0x258(%rbp), %rdx
movq -0x248(%rbp), %rdi
movq -0x270(%rbp), %r8
leaq 0x59107(%rip), %rsi     # 0x75142
movb $0x0, %al
callq 0x94d0
movq -0x20(%rbp), %rax
movq %rax, -0x278(%rbp)
cmpq $0x0, -0x1f8(%rbp)
jne 0x1c067
leaq 0x5b857(%rip), %rax     # 0x778b5
movq %rax, -0x280(%rbp)
jmp 0x1c075
movq -0x1f8(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x278(%rbp), %rdi
movq -0x280(%rbp), %rsi
callq 0x1a6c0
leaq -0x130(%rbp), %rdi
callq 0x130a0
leaq -0x170(%rbp), %rdi
callq 0x130a0
leaq -0x1b0(%rbp), %rdi
callq 0x130a0
leaq -0x1f0(%rbp), %rdi
callq 0x130a0
leaq -0x200(%rbp), %rdi
callq 0x9310
jmp 0x1c0e5
leaq 0x5638e(%rip), %rdi     # 0x7245b
leaq 0x582c0(%rip), %rsi     # 0x74394
movl $0x8d6, %edx            # imm = 0x8D6
leaq 0x595c5(%rip), %rcx     # 0x756a5
callq 0x30a0
jmp 0x1c0e7
addq $0x280, %rsp            # imm = 0x280
popq %rbp
retq