// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/frontend/irgen_llvmir.c
// Function: ir_stat_if
static void _ir_stat_if(
	IRGeneratorLlvmirContext *ctx,
	ParserASTNode *node_if
) {
	assert(ctx);
	assert(node_if);
	assert(node_if->type == FE_NODE_STAT_IF);

	_TMP_LABEL_DEF(ctx, if_end)

	_TMP_LABEL_DEF(ctx, if_true)
	_TMP_LABEL_DEF(ctx, if_false)

	ParserASTNode *node_if_expr = node_if->childs[0];
	ParserASTNode *node_if_body = node_if->childs[1];

	_ExprResult result_if_expr;
	_expr_result_init(&result_if_expr);

	_ir_expr_wrapper_val(ctx, ctx->body, &result_if_expr, node_if_expr);

	ResizableString rstr_label_if_cond_expr;
	rstr_init(&rstr_label_if_cond_expr);
	_ir_cond_expr(ctx, &rstr_label_if_cond_expr, &result_if_expr, node_if_expr);
	rstr_appendf(
		ctx->body,
		"br i1 %s, label %s, label %s\n",
		RSTR_CSTR(&rstr_label_if_cond_expr),
		_TMP_LABEL_CSTR(if_true),
		_TMP_LABEL_CSTR(if_false)
	);

	rstr_appendf(
		ctx->body,
		"br label %s\n%s:\n",
		_TMP_LABEL_CSTR(if_true),
		_TMP_LABEL_NAME_CSTR(if_true)
	);
	_ir_stats_block(ctx, node_if_body);
	rstr_appendf(
		ctx->body,
		"br label %s\n",
		_TMP_LABEL_CSTR(if_end)
	);
	rstr_appendf(
		ctx->body,
		"br label %s\n%s:\n",
		_TMP_LABEL_CSTR(if_false),
		_TMP_LABEL_NAME_CSTR(if_false)
	);

	for (int i = 2; i < node_if->nchilds; i++) {
		ParserASTNode *node = node_if->childs[i];
		if (node->type == FE_NODE_STAT_ELIF) {
			ParserASTNode *node_elif_expr = node->childs[0];
			ParserASTNode *node_elif_body = node->childs[1];

			_TMP_LABEL_DEF(ctx, elif_true)
			_TMP_LABEL_DEF(ctx, elif_false)

			_ExprResult result_elif_expr;
			_expr_result_init(&result_elif_expr);

			_ir_expr_wrapper_val(ctx, ctx->body, &result_elif_expr, node_elif_expr);

			ResizableString rstr_label_elif_cond_expr;
			rstr_init(&rstr_label_elif_cond_expr);
			_ir_cond_expr(ctx, &rstr_label_elif_cond_expr, &result_elif_expr, node_elif_expr);
			rstr_appendf(
				ctx->body,
				"br i1 %s, label %s, label %s\n",
				RSTR_CSTR(&rstr_label_elif_cond_expr),
				_TMP_LABEL_CSTR(elif_true),
				_TMP_LABEL_CSTR(elif_false)
			);

			rstr_appendf(
				ctx->body,
				"br label %s\n%s:\n",
				_TMP_LABEL_CSTR(elif_true),
				_TMP_LABEL_NAME_CSTR(elif_true)
			);
			_ir_stats_block(ctx, node_elif_body);
			rstr_appendf(
				ctx->body,
				"br label %s\n",
				_TMP_LABEL_CSTR(if_end)
			);
			rstr_appendf(
				ctx->body,
				"br label %s\n%s:\n",
				_TMP_LABEL_CSTR(elif_false),
				_TMP_LABEL_NAME_CSTR(elif_false)
			);

			_TMP_LABEL_FREE(elif_true)
			_TMP_LABEL_FREE(elif_false)
		} else if (node->type == FE_NODE_STAT_ELSE) {
			ParserASTNode *node_else_body = node->childs[0];
			_ir_stats_block(ctx, node_else_body);
		} else {
			assert(0);
		}
	}

	rstr_appendf(
		ctx->body,
		"br label %s\n%s:\n",
		_TMP_LABEL_CSTR(if_end),
		_TMP_LABEL_NAME_CSTR(if_end)
	);

	_TMP_LABEL_FREE(if_end)

	_TMP_LABEL_FREE(if_true)
	_TMP_LABEL_FREE(if_false)
	
	_expr_result_free(&result_if_expr);

	rstr_free(&rstr_label_if_cond_expr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2e0, %rsp            # imm = 0x2E0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x39d6c
jmp 0x39d8b
leaq 0x427e3(%rip), %rdi     # 0x7c556
leaq 0x3e356(%rip), %rsi     # 0x780d0
movl $0x553, %edx            # imm = 0x553
leaq 0x3fe3d(%rip), %rcx     # 0x79bc3
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x39d94
jmp 0x39db3
leaq 0x3c5b0(%rip), %rdi     # 0x7634b
leaq 0x3e32e(%rip), %rsi     # 0x780d0
movl $0x554, %edx            # imm = 0x554
leaq 0x3fe15(%rip), %rcx     # 0x79bc3
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0xb10, (%rax)          # imm = 0xB10
jne 0x39dc1
jmp 0x39de0
leaq 0x3c58b(%rip), %rdi     # 0x76353
leaq 0x3e301(%rip), %rsi     # 0x780d0
movl $0x555, %edx            # imm = 0x555
leaq 0x3fde8(%rip), %rcx     # 0x79bc3
callq 0x30a0
leaq -0x20(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq -0x20(%rbp), %rdx
callq 0x35980
leaq -0x30(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq -0x30(%rbp), %rdx
callq 0x35980
leaq -0x40(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq -0x40(%rbp), %rdx
callq 0x35980
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x2a260
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x48(%rbp), %rcx
leaq -0xd0(%rbp), %rdx
callq 0x2a300
leaq -0xe0(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rcx
leaq -0xe0(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
callq 0x3c6f0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x1c0(%rbp)
cmpq $0x0, -0xd8(%rbp)
jne 0x39ed1
leaq 0x3d9ed(%rip), %rax     # 0x778b5
movq %rax, -0x1c8(%rbp)
jmp 0x39edf
movq -0xd8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq -0x1c8(%rbp), %rax
movq %rax, -0x1d0(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x39f04
leaq 0x3d9ba(%rip), %rax     # 0x778b5
movq %rax, -0x1d8(%rbp)
jmp 0x39f0f
movq -0x28(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rax
movq %rax, -0x1e0(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x39f34
leaq 0x3d98a(%rip), %rax     # 0x778b5
movq %rax, -0x1e8(%rbp)
jmp 0x39f3f
movq -0x38(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movq -0x1e0(%rbp), %rcx
movq -0x1d0(%rbp), %rdx
movq -0x1c0(%rbp), %rdi
movq -0x1e8(%rbp), %r8
leaq 0x3f6ff(%rip), %rsi     # 0x79661
movb $0x0, %al
callq 0x94d0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x1f0(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x39f8f
leaq 0x3d92f(%rip), %rax     # 0x778b5
movq %rax, -0x1f8(%rbp)
jmp 0x39f9a
movq -0x28(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq -0x1f8(%rbp), %rax
movq %rax, -0x200(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x39fbf
leaq 0x3d8ff(%rip), %rax     # 0x778b5
movq %rax, -0x208(%rbp)
jmp 0x39fca
movq -0x28(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x200(%rbp), %rdx
movq -0x1f0(%rbp), %rdi
movq -0x208(%rbp), %rcx
addq $0x1, %rcx
leaq 0x3f666(%rip), %rsi     # 0x79650
movb $0x0, %al
callq 0x94d0
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x39800
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x210(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3a024
leaq 0x3d89a(%rip), %rax     # 0x778b5
movq %rax, -0x218(%rbp)
jmp 0x3a02f
movq -0x18(%rbp), %rax
movq %rax, -0x218(%rbp)
movq -0x210(%rbp), %rdi
movq -0x218(%rbp), %rdx
leaq 0x3f795(%rip), %rsi     # 0x797d9
movb $0x0, %al
callq 0x94d0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x220(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x3a071
leaq 0x3d84d(%rip), %rax     # 0x778b5
movq %rax, -0x228(%rbp)
jmp 0x3a07c
movq -0x38(%rbp), %rax
movq %rax, -0x228(%rbp)
movq -0x228(%rbp), %rax
movq %rax, -0x230(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x3a0a1
leaq 0x3d81d(%rip), %rax     # 0x778b5
movq %rax, -0x238(%rbp)
jmp 0x3a0ac
movq -0x38(%rbp), %rax
movq %rax, -0x238(%rbp)
movq -0x230(%rbp), %rdx
movq -0x220(%rbp), %rdi
movq -0x238(%rbp), %rcx
addq $0x1, %rcx
leaq 0x3f584(%rip), %rsi     # 0x79650
movb $0x0, %al
callq 0x94d0
movl $0x2, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x3a4be
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0xe4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
cmpl $0xb11, (%rax)          # imm = 0xB11
jne 0x3a451
movq -0xf0(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0xf8(%rbp)
movq -0xf0(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x100(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq -0x110(%rbp), %rdx
callq 0x35980
leaq -0x120(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rsi
leaq -0x120(%rbp), %rdx
callq 0x35980
leaq -0x1a0(%rbp), %rdi
callq 0x2a260
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0xf8(%rbp), %rcx
leaq -0x1a0(%rbp), %rdx
callq 0x2a300
leaq -0x1b0(%rbp), %rdi
callq 0x8c90
movq -0x8(%rbp), %rdi
movq -0xf8(%rbp), %rcx
leaq -0x1b0(%rbp), %rsi
leaq -0x1a0(%rbp), %rdx
callq 0x3c6f0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x240(%rbp)
cmpq $0x0, -0x1a8(%rbp)
jne 0x3a20e
leaq 0x3d6b0(%rip), %rax     # 0x778b5
movq %rax, -0x248(%rbp)
jmp 0x3a21c
movq -0x1a8(%rbp), %rax
movq %rax, -0x248(%rbp)
movq -0x248(%rbp), %rax
movq %rax, -0x250(%rbp)
cmpq $0x0, -0x108(%rbp)
jne 0x3a244
leaq 0x3d67a(%rip), %rax     # 0x778b5
movq %rax, -0x258(%rbp)
jmp 0x3a252
movq -0x108(%rbp), %rax
movq %rax, -0x258(%rbp)
movq -0x258(%rbp), %rax
movq %rax, -0x260(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0x3a27a
leaq 0x3d644(%rip), %rax     # 0x778b5
movq %rax, -0x268(%rbp)
jmp 0x3a288
movq -0x118(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x260(%rbp), %rcx
movq -0x250(%rbp), %rdx
movq -0x240(%rbp), %rdi
movq -0x268(%rbp), %r8
leaq 0x3f3b6(%rip), %rsi     # 0x79661
movb $0x0, %al
callq 0x94d0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x270(%rbp)
cmpq $0x0, -0x108(%rbp)
jne 0x3a2db
leaq 0x3d5e3(%rip), %rax     # 0x778b5
movq %rax, -0x278(%rbp)
jmp 0x3a2e9
movq -0x108(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x278(%rbp), %rax
movq %rax, -0x280(%rbp)
cmpq $0x0, -0x108(%rbp)
jne 0x3a311
leaq 0x3d5ad(%rip), %rax     # 0x778b5
movq %rax, -0x288(%rbp)
jmp 0x3a31f
movq -0x108(%rbp), %rax
movq %rax, -0x288(%rbp)
movq -0x280(%rbp), %rdx
movq -0x270(%rbp), %rdi
movq -0x288(%rbp), %rcx
addq $0x1, %rcx
leaq 0x3f311(%rip), %rsi     # 0x79650
movb $0x0, %al
callq 0x94d0
movq -0x8(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x39800
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x290(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3a37c
leaq 0x3d542(%rip), %rax     # 0x778b5
movq %rax, -0x298(%rbp)
jmp 0x3a387
movq -0x18(%rbp), %rax
movq %rax, -0x298(%rbp)
movq -0x290(%rbp), %rdi
movq -0x298(%rbp), %rdx
leaq 0x3f43d(%rip), %rsi     # 0x797d9
movb $0x0, %al
callq 0x94d0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x2a0(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0x3a3cc
leaq 0x3d4f2(%rip), %rax     # 0x778b5
movq %rax, -0x2a8(%rbp)
jmp 0x3a3da
movq -0x118(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movq -0x2a8(%rbp), %rax
movq %rax, -0x2b0(%rbp)
cmpq $0x0, -0x118(%rbp)
jne 0x3a402
leaq 0x3d4bc(%rip), %rax     # 0x778b5
movq %rax, -0x2b8(%rbp)
jmp 0x3a410
movq -0x118(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movq -0x2b0(%rbp), %rdx
movq -0x2a0(%rbp), %rdi
movq -0x2b8(%rbp), %rcx
addq $0x1, %rcx
leaq 0x3f220(%rip), %rsi     # 0x79650
movb $0x0, %al
callq 0x94d0
leaq -0x110(%rbp), %rdi
callq 0x9310
leaq -0x120(%rbp), %rdi
callq 0x9310
jmp 0x3a4a8
movq -0xf0(%rbp), %rax
cmpl $0xb12, (%rax)          # imm = 0xB12
jne 0x3a487
movq -0xf0(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x1b8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x1b8(%rbp), %rsi
callq 0x39800
jmp 0x3a4a6
leaq 0x37fcd(%rip), %rdi     # 0x7245b
leaq 0x3dc3b(%rip), %rsi     # 0x780d0
movl $0x5b4, %edx            # imm = 0x5B4
leaq 0x3f722(%rip), %rcx     # 0x79bc3
callq 0x30a0
jmp 0x3a4a8
jmp 0x3a4aa
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x3a0dd
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x2c0(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3a4e4
leaq 0x3d3da(%rip), %rax     # 0x778b5
movq %rax, -0x2c8(%rbp)
jmp 0x3a4ef
movq -0x18(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movq -0x2c8(%rbp), %rax
movq %rax, -0x2d0(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x3a514
leaq 0x3d3aa(%rip), %rax     # 0x778b5
movq %rax, -0x2d8(%rbp)
jmp 0x3a51f
movq -0x18(%rbp), %rax
movq %rax, -0x2d8(%rbp)
movq -0x2d0(%rbp), %rdx
movq -0x2c0(%rbp), %rdi
movq -0x2d8(%rbp), %rcx
addq $0x1, %rcx
leaq 0x3f111(%rip), %rsi     # 0x79650
movb $0x0, %al
callq 0x94d0
leaq -0x20(%rbp), %rdi
callq 0x9310
leaq -0x30(%rbp), %rdi
callq 0x9310
leaq -0x40(%rbp), %rdi
callq 0x9310
leaq -0xd0(%rbp), %rdi
callq 0x2c6a0
leaq -0xe0(%rbp), %rdi
callq 0x9310
addq $0x2e0, %rsp            # imm = 0x2E0
popq %rbp
retq
nopw %cs:(%rax,%rax)