// File: /workspace/github_c_makefile_star2_O3/Ihsoh[P]ilang/compiler/frontend/irgen_llvmir.c
// Function: ir_expr_sub
static void _ir_expr_sub(
	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_SUB
			|| node->type == FE_NODE_EXPR_SUB_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));

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

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

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

		_expr_result_free(&result_lhs);
		_expr_result_free(&result_rhs);
		rstr_free(&rstr_lhs_type);
		rstr_free(&rstr_tmp_label_val);
		rstr_free(&rstr_tmp_label_val1);
	} 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 = sub 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 = sub %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 = fsub %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 $0x248, %rsp            # imm = 0x248
testq %rcx, %rcx
je 0x1f4b9
movq %r8, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl (%r8), %eax
cmpl $0xe12, %eax            # imm = 0xE12
je 0x1efce
cmpl $0xea1, %eax            # imm = 0xEA1
jne 0x1f4f7
movq %rdx, -0x48(%rbp)
movq %rcx, -0x38(%rbp)
movq 0x40(%r15), %rax
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x1f4d8
movq 0x48(%rbx), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movb 0x60(%rax), %r12b
movzbl 0x60(%rcx), %r13d
movl %r13d, %edi
callq 0x2a496
movzbl %r12b, %r12d
testb %al, %al
je 0x1f22f
movl %r12d, %edi
callq 0x2a465
testb %al, %al
je 0x1f22f
movq 0x48(%rbx), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r12
leaq -0x160(%rbp), %r13
movq %r13, %rdi
callq 0x19b1c
leaq -0xe0(%rbp), %rdi
callq 0x19b1c
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1a9a8
leaq -0x150(%rbp), %rsi
movq %r14, %rdi
callq 0x769e
movq %r14, %rdi
movq %r13, %rsi
callq 0x769e
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1f085
leaq -0x110(%rbp), %rsi
callq 0x769e
leaq -0xe0(%rbp), %r13
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x1a9a8
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x769e
movq %r14, %rdi
movq %r13, %rsi
callq 0x769e
movq 0x68(%rbx), %rax
cmpl $0x440, (%rax)          # imm = 0x440
jne 0x1f516
movq 0x48(%rax), %rax
movq (%rax), %rbx
leaq -0x260(%rbp), %r14
movq %r14, %rdi
callq 0x7354
movq %r14, %rdi
movq %r14, %r13
movq %rbx, %rsi
callq 0x19540
leaq -0x1e0(%rbp), %r15
movq %r15, %rdi
callq 0x7354
movq -0x40(%rbp), %r14
movl 0x54(%r14), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x54(%r14)
leaq 0x2605a(%rip), %rbx     # 0x4516a
movq %r15, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x7945
leaq -0x60(%rbp), %r12
movq %r12, %rdi
callq 0x7354
movl 0x54(%r14), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x54(%r14)
movq %r12, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x7945
movq 0x8(%r15), %rdx
testq %rdx, %rdx
leaq 0x23db7(%rip), %r14     # 0x42f06
cmoveq %r14, %rdx
leaq -0xe0(%rbp), %rbx
movq 0x38(%rbx), %rcx
testq %rcx, %rcx
cmoveq %r14, %rcx
movq 0x48(%rbx), %r8
testq %r8, %r8
cmoveq %r14, %r8
leaq 0x2625a(%rip), %rsi     # 0x453d1
movq -0x38(%rbp), %r15
movq %r15, %rdi
xorl %eax, %eax
callq 0x7945
movq 0x8(%r12), %rdx
testq %rdx, %rdx
cmoveq %r14, %rdx
movq 0x8(%r13), %rcx
testq %rcx, %rcx
cmoveq %r14, %rcx
leaq -0x160(%rbp), %r13
movq 0x28(%r13), %r8
testq %r8, %r8
cmoveq %r14, %r8
movq 0x38(%rbx), %r9
testq %r9, %r9
cmoveq %r14, %r9
leaq -0x1e0(%rbp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
cmoveq %r14, %rax
movq %rax, (%rsp)
leaq 0x26689(%rip), %rsi     # 0x4585f
movq %r15, %rdi
xorl %eax, %eax
callq 0x7945
movq 0x38(%r13), %rsi
testq %rsi, %rsi
cmoveq %r14, %rsi
movq 0x8(%r12), %rdx
testq %rdx, %rdx
cmoveq %r14, %rdx
movq %r15, %rdi
callq 0x1def5
movq %r13, %rdi
callq 0x1a3fd
movq %rbx, %rdi
callq 0x1a3fd
leaq -0x260(%rbp), %rdi
callq 0x7852
leaq -0x1e0(%rbp), %rdi
callq 0x7852
movq %r12, %rdi
jmp 0x1f483
movl %r13d, %edi
callq 0x2a4a2
testb %al, %al
je 0x1f49a
movl %r12d, %edi
callq 0x2a4a2
testb %al, %al
je 0x1f49a
movq 0x68(%rbx), %rax
movq %rax, -0x50(%rbp)
movb 0x60(%rbx), %al
movb %al, -0x29(%rbp)
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq 0x8(%rax), %rbx
leaq -0x160(%rbp), %r13
movq %r13, %rdi
callq 0x19b1c
leaq -0xe0(%rbp), %rdi
callq 0x19b1c
leaq -0x260(%rbp), %rdi
callq 0x19b1c
leaq -0x1e0(%rbp), %rdi
callq 0x19b1c
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %r12, %rcx
callq 0x1a9a8
leaq -0x150(%rbp), %rsi
movq %r14, %rdi
callq 0x769e
movq %r14, %rdi
movq %r13, %rsi
callq 0x769e
movq -0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x1f2db
leaq -0x110(%rbp), %rsi
callq 0x769e
leaq -0xe0(%rbp), %r13
movq %r15, %rdi
movq %r14, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x1a9a8
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x769e
movq %r14, %rdi
movq %r13, %rsi
callq 0x769e
movq 0x68(%r12), %r8
leaq -0x260(%rbp), %r12
leaq -0x160(%rbp), %rcx
movq %r15, %rdi
movq %r12, %rsi
movq -0x50(%rbp), %r13
movq %r13, %rdx
callq 0x19bc3
leaq -0x250(%rbp), %rsi
movq %r14, %rdi
callq 0x769e
movq %r14, %rdi
movq %r12, %rsi
callq 0x769e
movq 0x68(%rbx), %r8
leaq -0x1e0(%rbp), %rbx
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
leaq -0xe0(%rbp), %rcx
callq 0x19bc3
leaq -0x1d0(%rbp), %rsi
movq %r14, %rdi
callq 0x769e
movq %r14, %rdi
movq %rbx, %rsi
callq 0x769e
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x7354
movq -0x40(%rbp), %rcx
movl 0x54(%rcx), %edx
leal 0x1(%rdx), %eax
movl %eax, 0x54(%rcx)
leaq 0x25dc4(%rip), %rsi     # 0x4516a
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7945
movzbl -0x29(%rbp), %ebx
movl %ebx, %edi
callq 0x2a444
testb %al, %al
je 0x1f3c8
leaq 0x264c4(%rip), %rsi     # 0x4588a
jmp 0x1f3f2
movl %ebx, %edi
callq 0x2a454
testb %al, %al
je 0x1f3dc
leaq 0x264c5(%rip), %rsi     # 0x4589f
jmp 0x1f3f2
movl %ebx, %edi
callq 0x2a475
testb %al, %al
je 0x1f535
leaq 0x264be(%rip), %rsi     # 0x458b0
leaq -0x60(%rbp), %rbx
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
leaq 0x23b02(%rip), %r12     # 0x42f06
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 0x7945
movq 0x38(%r14), %rsi
testq %rsi, %rsi
cmoveq %r12, %rsi
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
cmoveq %r12, %rdx
movq %r13, %rdi
callq 0x1def5
leaq -0x160(%rbp), %rdi
callq 0x1a3fd
leaq -0xe0(%rbp), %rdi
callq 0x1a3fd
movq %r14, %rdi
callq 0x1a3fd
movq %r15, %rdi
callq 0x1a3fd
movq %rbx, %rdi
callq 0x7852
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1febf(%rip), %rdi     # 0x3f360
leaq 0x2549c(%rip), %rsi     # 0x44944
leaq 0x2633c(%rip), %rcx     # 0x457eb
movl $0xe08, %edx            # imm = 0xE08
callq 0x30a0
leaq 0x22714(%rip), %rdi     # 0x41bd4
leaq 0x2547d(%rip), %rsi     # 0x44944
leaq 0x2631d(%rip), %rcx     # 0x457eb
movl $0xd5a, %edx            # imm = 0xD5A
callq 0x30a0
leaq 0x23a88(%rip), %rdi     # 0x42f67
leaq 0x2545e(%rip), %rsi     # 0x44944
leaq 0x262fe(%rip), %rcx     # 0x457eb
movl $0xd60, %edx            # imm = 0xD60
callq 0x30a0
leaq 0x230da(%rip), %rdi     # 0x425d8
leaq 0x2543f(%rip), %rsi     # 0x44944
leaq 0x262df(%rip), %rcx     # 0x457eb
movl $0xd5d, %edx            # imm = 0xD5D
callq 0x30a0
leaq 0x26266(%rip), %rdi     # 0x45783
leaq 0x25420(%rip), %rsi     # 0x44944
leaq 0x262c0(%rip), %rcx     # 0x457eb
movl $0xd7f, %edx            # imm = 0xD7F
callq 0x30a0
leaq 0x1fe24(%rip), %rdi     # 0x3f360
leaq 0x25401(%rip), %rsi     # 0x44944
leaq 0x262a1(%rip), %rcx     # 0x457eb
movl $0xdfa, %edx            # imm = 0xDFA
callq 0x30a0