// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/frontend/irgen.c
// Function: ir_stat_return
static void _ir_stat_return(
	IRGeneratorContext *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, "return;\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,
			"return %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 $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x1f5cc
jmp 0x1f5eb
leaq 0x5cf83(%rip), %rdi     # 0x7c556
leaq 0x54dba(%rip), %rsi     # 0x74394
movl $0x1133, %edx           # imm = 0x1133
leaq 0x57200(%rip), %rcx     # 0x767e6
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x1f5f4
jmp 0x1f613
leaq 0x57227(%rip), %rdi     # 0x76822
leaq 0x54d92(%rip), %rsi     # 0x74394
movl $0x1134, %edx           # imm = 0x1134
leaq 0x571d8(%rip), %rcx     # 0x767e6
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0xb70, (%rax)          # imm = 0xB70
jne 0x1f621
jmp 0x1f640
leaq 0x5720b(%rip), %rdi     # 0x76833
leaq 0x54d65(%rip), %rsi     # 0x74394
movl $0x1135, %edx           # imm = 0x1135
leaq 0x571ab(%rip), %rcx     # 0x767e6
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x44(%rax)
je 0x1f654
movq -0x10(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jne 0x1f656
jmp 0x1f675
leaq 0x57204(%rip), %rdi     # 0x76861
leaq 0x54d30(%rip), %rsi     # 0x74394
movl $0x1136, %edx           # imm = 0x1136
leaq 0x57176(%rip), %rcx     # 0x767e6
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jne 0x1f698
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
leaq 0x57214(%rip), %rsi     # 0x768a2
callq 0x8d70
jmp 0x1f81c
movq -0x10(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jne 0x1f7fb
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x1f6bb
jmp 0x1f6da
leaq 0x56ab1(%rip), %rdi     # 0x76173
leaq 0x54ccb(%rip), %rsi     # 0x74394
movl $0x113c, %edx           # imm = 0x113C
leaq 0x57111(%rip), %rcx     # 0x767e6
callq 0x30a0
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x1f6ef
jmp 0x1f70e
leaq 0x571b5(%rip), %rdi     # 0x768ab
leaq 0x54c97(%rip), %rsi     # 0x74394
movl $0x113e, %edx           # imm = 0x113E
leaq 0x570dd(%rip), %rcx     # 0x767e6
callq 0x30a0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x113b0
leaq -0xa8(%rbp), %rdi
callq 0x113b0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x28(%rbp), %rcx
leaq -0x68(%rbp), %rdx
callq 0x11420
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rax
movq 0x68(%rax), %r8
leaq -0xa8(%rbp), %rsi
leaq -0x68(%rbp), %rcx
callq 0x11460
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0xa8(%rbp), %rsi
addq $0x10, %rsi
callq 0x9100
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x9100
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x1f7bd
leaq 0x58101(%rip), %rax     # 0x778b5
movq %rax, -0xb8(%rbp)
jmp 0x1f7c8
movq -0x80(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdi
movq -0xb8(%rbp), %rdx
leaq 0x570e4(%rip), %rsi     # 0x768c1
movb $0x0, %al
callq 0x94d0
leaq -0x68(%rbp), %rdi
callq 0x130a0
leaq -0xa8(%rbp), %rdi
callq 0x130a0
jmp 0x1f81a
leaq 0x52c59(%rip), %rdi     # 0x7245b
leaq 0x54b8b(%rip), %rsi     # 0x74394
movl $0x115d, %edx           # imm = 0x115D
leaq 0x56fd1(%rip), %rcx     # 0x767e6
callq 0x30a0
jmp 0x1f81c
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)