// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/frontend/irgen_llvmir.c
// Function: ir_expr_div
static void _ir_expr_div(
	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_DIV
			|| node->type == FE_NODE_EXPR_DIV_ASSIGN);

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

	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 = sdiv %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 = udiv %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 = fdiv %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);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
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 0x36378
jmp 0x36397
leaq 0x461d7(%rip), %rdi     # 0x7c556
leaq 0x41d4a(%rip), %rsi     # 0x780d0
movl $0xba1, %edx            # imm = 0xBA1
leaq 0x42a92(%rip), %rcx     # 0x78e24
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x363a0
jmp 0x363bf
leaq 0x3c767(%rip), %rdi     # 0x72b0e
leaq 0x41d22(%rip), %rsi     # 0x780d0
movl $0xba2, %edx            # imm = 0xBA2
leaq 0x42a6a(%rip), %rcx     # 0x78e24
callq 0x30a0
cmpq $0x0, -0x20(%rbp)
je 0x363c8
jmp 0x363e7
leaq 0x3e844(%rip), %rdi     # 0x74c13
leaq 0x41cfa(%rip), %rsi     # 0x780d0
movl $0xba3, %edx            # imm = 0xBA3
leaq 0x42a42(%rip), %rcx     # 0x78e24
callq 0x30a0
cmpq $0x0, -0x28(%rbp)
je 0x363f0
jmp 0x3640f
leaq 0x3fbdc(%rip), %rdi     # 0x75fd3
leaq 0x41cd2(%rip), %rsi     # 0x780d0
movl $0xba4, %edx            # imm = 0xBA4
leaq 0x42a1a(%rip), %rcx     # 0x78e24
callq 0x30a0
movq -0x28(%rbp), %rax
cmpl $0xeb1, (%rax)          # imm = 0xEB1
je 0x36427
movq -0x28(%rbp), %rax
cmpl $0xe14, (%rax)          # imm = 0xE14
jne 0x36429
jmp 0x36448
leaq 0x3f0f5(%rip), %rdi     # 0x75525
leaq 0x41c99(%rip), %rsi     # 0x780d0
movl $0xba6, %edx            # imm = 0xBA6
leaq 0x429e1(%rip), %rcx     # 0x78e24
callq 0x30a0
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x3645d
jmp 0x3647c
leaq 0x3fd0f(%rip), %rdi     # 0x76173
leaq 0x41c65(%rip), %rsi     # 0x780d0
movl $0xba9, %edx            # imm = 0xBA9
leaq 0x429ad(%rip), %rcx     # 0x78e24
callq 0x30a0
movq -0x28(%rbp), %rax
movq 0x68(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movb 0x60(%rax), %al
movb %al, -0x39(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x2a260
leaq -0x150(%rbp), %rdi
callq 0x2a260
leaq -0x1d0(%rbp), %rdi
callq 0x2a260
leaq -0x250(%rbp), %rdi
callq 0x2a260
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x48(%rbp), %rcx
leaq -0xd0(%rbp), %rdx
callq 0x2d590
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x9100
cmpq $0x0, -0x18(%rbp)
je 0x36538
movq -0x18(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
addq $0x50, %rsi
callq 0x9100
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x50(%rbp), %rcx
leaq -0x150(%rbp), %rdx
callq 0x2d590
movq -0x10(%rbp), %rdi
leaq -0x150(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x9100
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x48(%rbp), %rax
movq 0x68(%rax), %r8
leaq -0x1d0(%rbp), %rsi
leaq -0xd0(%rbp), %rcx
callq 0x2a360
movq -0x10(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x9100
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rdx
movq -0x50(%rbp), %rax
movq 0x68(%rax), %r8
leaq -0x250(%rbp), %rsi
leaq -0x150(%rbp), %rcx
callq 0x2a360
movq -0x10(%rbp), %rdi
leaq -0x250(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x10(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x9100
leaq -0x260(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x260(%rbp), %rdx
callq 0x35980
movzbl -0x39(%rbp), %edi
callq 0x4d310
testb $0x1, %al
jne 0x36634
jmp 0x36702
movq -0x20(%rbp), %rax
movq %rax, -0x268(%rbp)
cmpq $0x0, -0x258(%rbp)
jne 0x36659
leaq 0x41265(%rip), %rax     # 0x778b5
movq %rax, -0x270(%rbp)
jmp 0x36667
movq -0x258(%rbp), %rax
movq %rax, -0x270(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0x278(%rbp)
cmpq $0x0, -0x1a8(%rbp)
jne 0x3668f
leaq 0x4122f(%rip), %rax     # 0x778b5
movq %rax, -0x280(%rbp)
jmp 0x3669d
movq -0x1a8(%rbp), %rax
movq %rax, -0x280(%rbp)
movq -0x280(%rbp), %rax
movq %rax, -0x288(%rbp)
cmpq $0x0, -0x208(%rbp)
jne 0x366c5
leaq 0x411f9(%rip), %rax     # 0x778b5
movq %rax, -0x290(%rbp)
jmp 0x366d3
movq -0x208(%rbp), %rax
movq %rax, -0x290(%rbp)
movq -0x288(%rbp), %rcx
movq -0x278(%rbp), %rdx
movq -0x268(%rbp), %rdi
movq -0x290(%rbp), %r8
leaq 0x427a2(%rip), %rsi     # 0x78e98
movb $0x0, %al
callq 0x94d0
jmp 0x368e2
movzbl -0x39(%rbp), %edi
callq 0x4d360
testb $0x1, %al
jne 0x36714
jmp 0x367e2
movq -0x20(%rbp), %rax
movq %rax, -0x298(%rbp)
cmpq $0x0, -0x258(%rbp)
jne 0x36739
leaq 0x41185(%rip), %rax     # 0x778b5
movq %rax, -0x2a0(%rbp)
jmp 0x36747
movq -0x258(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0x2a0(%rbp), %rax
movq %rax, -0x2a8(%rbp)
cmpq $0x0, -0x1a8(%rbp)
jne 0x3676f
leaq 0x4114f(%rip), %rax     # 0x778b5
movq %rax, -0x2b0(%rbp)
jmp 0x3677d
movq -0x1a8(%rbp), %rax
movq %rax, -0x2b0(%rbp)
movq -0x2b0(%rbp), %rax
movq %rax, -0x2b8(%rbp)
cmpq $0x0, -0x208(%rbp)
jne 0x367a5
leaq 0x41119(%rip), %rax     # 0x778b5
movq %rax, -0x2c0(%rbp)
jmp 0x367b3
movq -0x208(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movq -0x2b8(%rbp), %rcx
movq -0x2a8(%rbp), %rdx
movq -0x298(%rbp), %rdi
movq -0x2c0(%rbp), %r8
leaq 0x426d4(%rip), %rsi     # 0x78eaa
movb $0x0, %al
callq 0x94d0
jmp 0x368e0
movzbl -0x39(%rbp), %edi
callq 0x4d400
testb $0x1, %al
jne 0x367f4
jmp 0x368bf
movq -0x20(%rbp), %rax
movq %rax, -0x2c8(%rbp)
cmpq $0x0, -0x258(%rbp)
jne 0x36819
leaq 0x410a5(%rip), %rax     # 0x778b5
movq %rax, -0x2d0(%rbp)
jmp 0x36827
movq -0x258(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x2d0(%rbp), %rax
movq %rax, -0x2d8(%rbp)
cmpq $0x0, -0x1a8(%rbp)
jne 0x3684f
leaq 0x4106f(%rip), %rax     # 0x778b5
movq %rax, -0x2e0(%rbp)
jmp 0x3685d
movq -0x1a8(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movq -0x2e0(%rbp), %rax
movq %rax, -0x2e8(%rbp)
cmpq $0x0, -0x208(%rbp)
jne 0x36885
leaq 0x41039(%rip), %rax     # 0x778b5
movq %rax, -0x2f0(%rbp)
jmp 0x36893
movq -0x208(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movq -0x2e8(%rbp), %rcx
movq -0x2d8(%rbp), %rdx
movq -0x2c8(%rbp), %rdi
movq -0x2f0(%rbp), %r8
leaq 0x42606(%rip), %rsi     # 0x78ebc
movb $0x0, %al
callq 0x94d0
jmp 0x368de
leaq 0x3bb95(%rip), %rdi     # 0x7245b
leaq 0x41803(%rip), %rsi     # 0x780d0
movl $0xbfb, %edx            # imm = 0xBFB
leaq 0x4254b(%rip), %rcx     # 0x78e24
callq 0x30a0
jmp 0x368e0
jmp 0x368e2
movq -0x20(%rbp), %rax
movq %rax, -0x2f8(%rbp)
cmpq $0x0, -0x198(%rbp)
jne 0x36907
leaq 0x40fb7(%rip), %rax     # 0x778b5
movq %rax, -0x300(%rbp)
jmp 0x36915
movq -0x198(%rbp), %rax
movq %rax, -0x300(%rbp)
movq -0x300(%rbp), %rax
movq %rax, -0x308(%rbp)
cmpq $0x0, -0x258(%rbp)
jne 0x3693d
leaq 0x40f81(%rip), %rax     # 0x778b5
movq %rax, -0x310(%rbp)
jmp 0x3694b
movq -0x258(%rbp), %rax
movq %rax, -0x310(%rbp)
movq -0x308(%rbp), %rsi
movq -0x2f8(%rbp), %rdi
movq -0x310(%rbp), %rdx
callq 0x358a0
leaq -0xd0(%rbp), %rdi
callq 0x2c6a0
leaq -0x150(%rbp), %rdi
callq 0x2c6a0
leaq -0x1d0(%rbp), %rdi
callq 0x2c6a0
leaq -0x250(%rbp), %rdi
callq 0x2c6a0
leaq -0x260(%rbp), %rdi
callq 0x9310
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
nopw (%rax,%rax)