// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/frontend/irgen_llvmir.c
// Function: ir_stat_return
static void _ir_stat_return(
	IRGeneratorLlvmirContext *ctx,
	ParserASTNode *node_stat_return
) {
	assert(ctx);
	assert(node_stat_return);
	assert(node_stat_return->type == FE_NODE_STAT_RETURN);
	assert(node_stat_return->nchilds == 0 || node_stat_return->nchilds == 1);

	if (node_stat_return->nchilds == 0) {
		rstr_append_with_cstr(ctx->body, "ret void\n");
	} else if (node_stat_return->nchilds == 1) {
		ParserSymbol *func_symbol = ctx->func_symbol;
		assert(func_symbol);
		ParserASTNode *node_func_return_type = FE_FUNC_SYMBOL_GET_RETURN_TYPE_NODE(func_symbol);
		assert(node_func_return_type);

		ParserASTNode *node_expr = node_stat_return->childs[0];

		_ExprResult expr_result;
		_expr_result_init(&expr_result);

		_ExprResult casted_result;
		_expr_result_init(&casted_result);

		_ir_expr_wrapper_val(ctx, ctx->body, &expr_result, node_expr);

		_expr_result_cast(
			ctx,
			&casted_result,
			node_func_return_type,
			&expr_result,
			FE_EXPR_AST_NODE_GET_TYPE_NODE(node_expr)
		);
		rstr_append_with_rstr(ctx->body, &(casted_result.rstr_for_result_ptr));
		rstr_append_with_rstr(ctx->body, &(casted_result.rstr_for_result));


		rstr_appendf(
			ctx->body,
			"ret %s\n",
			RSTR_CSTR(&(casted_result.rstr_result))
		);

		_expr_result_free(&expr_result);
		_expr_result_free(&casted_result);
	} else {
		assert(0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x3b92c
jmp 0x3b94b
leaq 0x40c23(%rip), %rdi     # 0x7c556
leaq 0x3c796(%rip), %rsi     # 0x780d0
movl $0x71c, %edx            # imm = 0x71C
leaq 0x3e3fe(%rip), %rcx     # 0x79d44
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x3b954
jmp 0x3b973
leaq 0x3aec7(%rip), %rdi     # 0x76822
leaq 0x3c76e(%rip), %rsi     # 0x780d0
movl $0x71d, %edx            # imm = 0x71D
leaq 0x3e3d6(%rip), %rcx     # 0x79d44
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0xb70, (%rax)          # imm = 0xB70
jne 0x3b981
jmp 0x3b9a0
leaq 0x3aeab(%rip), %rdi     # 0x76833
leaq 0x3c741(%rip), %rsi     # 0x780d0
movl $0x71e, %edx            # imm = 0x71E
leaq 0x3e3a9(%rip), %rcx     # 0x79d44
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x44(%rax)
je 0x3b9b4
movq -0x10(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jne 0x3b9b6
jmp 0x3b9d5
leaq 0x3aea4(%rip), %rdi     # 0x76861
leaq 0x3c70c(%rip), %rsi     # 0x780d0
movl $0x71f, %edx            # imm = 0x71F
leaq 0x3e374(%rip), %rcx     # 0x79d44
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jne 0x3b9f8
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x3e398(%rip), %rsi     # 0x79d86
callq 0x8d70
jmp 0x3bb8e
movq -0x10(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jne 0x3bb6d
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x3ba1b
jmp 0x3ba3a
leaq 0x3a751(%rip), %rdi     # 0x76173
leaq 0x3c6a7(%rip), %rsi     # 0x780d0
movl $0x725, %edx            # imm = 0x725
leaq 0x3e30f(%rip), %rcx     # 0x79d44
callq 0x30a0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3ba4f
jmp 0x3ba6e
leaq 0x3ae55(%rip), %rdi     # 0x768ab
leaq 0x3c673(%rip), %rsi     # 0x780d0
movl $0x727, %edx            # imm = 0x727
leaq 0x3e2db(%rip), %rcx     # 0x79d44
callq 0x30a0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x2a260
leaq -0x128(%rbp), %rdi
callq 0x2a260
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x28(%rbp), %rcx
leaq -0xa8(%rbp), %rdx
callq 0x2a300
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x68(%rax), %r8
leaq -0x128(%rbp), %rsi
leaq -0xa8(%rbp), %rcx
callq 0x2a360
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x128(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x128(%rbp), %rsi
callq 0x9100
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x130(%rbp)
cmpq $0x0, -0x100(%rbp)
jne 0x3bb29
leaq 0x3bd95(%rip), %rax     # 0x778b5
movq %rax, -0x138(%rbp)
jmp 0x3bb37
movq -0x100(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rdx
leaq 0x3e244(%rip), %rsi     # 0x79d90
movb $0x0, %al
callq 0x94d0
leaq -0xa8(%rbp), %rdi
callq 0x2c6a0
leaq -0x128(%rbp), %rdi
callq 0x2c6a0
jmp 0x3bb8c
leaq 0x368e7(%rip), %rdi     # 0x7245b
leaq 0x3c555(%rip), %rsi     # 0x780d0
movl $0x747, %edx            # imm = 0x747
leaq 0x3e1bd(%rip), %rcx     # 0x79d44
callq 0x30a0
jmp 0x3bb8e
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw (%rax,%rax)