// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/frontend/irgen.c
// Function: ir_stat_asm
static void _ir_stat_asm(
	IRGeneratorContext *ctx,
	ParserASTNode *node_stat_asm
) {
	assert(ctx);
	assert(node_stat_asm);
	assert(node_stat_asm->type == FE_NODE_STAT_ASM);
	assert(node_stat_asm->nchilds >= 1);

	ParserASTNode *node_asm_code = node_stat_asm->childs[0];
	assert(node_asm_code->type == FE_NODE_LITERAL_STRING);

	ResizableString rstr_set_reg;
	rstr_init(&rstr_set_reg);

	ResizableString rstr_get_reg;
	rstr_init(&rstr_get_reg);

	for (int i = 1; i < node_stat_asm->nchilds; i++) {
		ParserASTNode *node_asm_option = node_stat_asm->childs[i];
		assert(node_asm_option->type == FE_NODE_STAT_ASM_OPTION);
		assert(node_asm_option->nchilds == 2);

		ParserASTNode *node_expr = node_asm_option->childs[1];
		assert(node_expr->type == FE_NODE_EXPR);
		_ExprResult expr_result;
		_expr_result_init(&expr_result);
		_ir_expr_wrapper_val(ctx, ctx->body, &expr_result, node_expr);

		ParserASTNode *node_specifier = node_asm_option->childs[0];
		assert(node_specifier->type == FE_NODE_LITERAL_STRING);
		LexerToken *tk_specifier = node_specifier->token;
		if (tk_specifier->len >= 4) {
			if (strncmp("set#", tk_specifier->content + 1, 4) == 0) {
				ResizableString rstr_reg;
				rstr_init_with_raw(
					&rstr_reg,
					tk_specifier->content + 5,
					tk_specifier->len - 6
				);
				rstr_appendf(
					&rstr_set_reg,
					"asm_set_reg \"%s\", %s;\n",
					RSTR_CSTR(&rstr_reg),
					RSTR_CSTR(&(expr_result.rstr_result))
				);
				rstr_free(&rstr_reg);
			} else if (strncmp("get#", tk_specifier->content + 1, 4) == 0) {
				ResizableString rstr_reg;
				rstr_init_with_raw(
					&rstr_reg,
					tk_specifier->content + 5,
					tk_specifier->len - 6
				);
				rstr_appendf(
					&rstr_get_reg,
					"asm_get_reg %s, \"%s\";\n",
					RSTR_CSTR(&(expr_result.rstr_result)),
					RSTR_CSTR(&rstr_reg)
				);
				rstr_free(&rstr_reg);
			} else {
				assert(0);
			}
		} else {
			assert(0);
		}

		_expr_result_free(&expr_result);
	}

	rstr_append_with_rstr(
		ctx->body,
		&rstr_set_reg
	);

	ResizableString rstr_asm_code;
	rstr_init_with_raw(
		&rstr_asm_code,
		node_asm_code->token->content,
		node_asm_code->token->len
	);
	rstr_appendf(
		ctx->body,
		"asm %s;\n",
		RSTR_CSTR(&rstr_asm_code)
	);
	rstr_free(&rstr_asm_code);

	rstr_append_with_rstr(
		ctx->body,
		&rstr_get_reg
	);

	rstr_free(&rstr_set_reg);
	rstr_free(&rstr_get_reg);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x1facc
jmp 0x1faeb
leaq 0x5ca83(%rip), %rdi     # 0x7c556
leaq 0x548ba(%rip), %rsi     # 0x74394
movl $0x1193, %edx           # imm = 0x1193
leaq 0x56f0c(%rip), %rcx     # 0x769f2
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x1faf4
jmp 0x1fb13
leaq 0x56f30(%rip), %rdi     # 0x76a2b
leaq 0x54892(%rip), %rsi     # 0x74394
movl $0x1194, %edx           # imm = 0x1194
leaq 0x56ee4(%rip), %rcx     # 0x769f2
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0xba0, (%rax)          # imm = 0xBA0
jne 0x1fb21
jmp 0x1fb40
leaq 0x56f11(%rip), %rdi     # 0x76a39
leaq 0x54865(%rip), %rsi     # 0x74394
movl $0x1195, %edx           # imm = 0x1195
leaq 0x56eb7(%rip), %rcx     # 0x769f2
callq 0x30a0
movq -0x10(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jl 0x1fb4c
jmp 0x1fb6b
leaq 0x56f0e(%rip), %rdi     # 0x76a61
leaq 0x5483a(%rip), %rsi     # 0x74394
movl $0x1196, %edx           # imm = 0x1196
leaq 0x56e8c(%rip), %rcx     # 0x769f2
callq 0x30a0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x303, (%rax)          # imm = 0x303
jne 0x1fb88
jmp 0x1fba7
leaq 0x56eee(%rip), %rdi     # 0x76a7d
leaq 0x547fe(%rip), %rsi     # 0x74394
movl $0x1199, %edx           # imm = 0x1199
leaq 0x56e50(%rip), %rcx     # 0x769f2
callq 0x30a0
leaq -0x28(%rbp), %rdi
callq 0x8c90
leaq -0x38(%rbp), %rdi
callq 0x8c90
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x1ff13
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpl $0xba1, (%rax)          # imm = 0xBA1
jne 0x1fbf2
jmp 0x1fc11
leaq 0x56eb2(%rip), %rdi     # 0x76aab
leaq 0x54794(%rip), %rsi     # 0x74394
movl $0x11a3, %edx           # imm = 0x11A3
leaq 0x56de6(%rip), %rcx     # 0x769f2
callq 0x30a0
movq -0x48(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jne 0x1fc1d
jmp 0x1fc3c
leaq 0x56eb8(%rip), %rdi     # 0x76adc
leaq 0x54769(%rip), %rsi     # 0x74394
movl $0x11a4, %edx           # imm = 0x11A4
leaq 0x56dbb(%rip), %rcx     # 0x769f2
callq 0x30a0
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpl $0xe00, (%rax)          # imm = 0xE00
jne 0x1fc5a
jmp 0x1fc79
leaq 0x56a22(%rip), %rdi     # 0x76683
leaq 0x5472c(%rip), %rsi     # 0x74394
movl $0x11a7, %edx           # imm = 0x11A7
leaq 0x56d7e(%rip), %rcx     # 0x769f2
callq 0x30a0
leaq -0x90(%rbp), %rdi
callq 0x113b0
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x50(%rbp), %rcx
leaq -0x90(%rbp), %rdx
callq 0x11420
movq -0x48(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpl $0x303, (%rax)          # imm = 0x303
jne 0x1fcc4
jmp 0x1fce3
leaq 0x56e2f(%rip), %rdi     # 0x76afa
leaq 0x546c2(%rip), %rsi     # 0x74394
movl $0x11ad, %edx           # imm = 0x11AD
leaq 0x56d14(%rip), %rcx     # 0x769f2
callq 0x30a0
movq -0x98(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpl $0x4, 0x4(%rax)
jl 0x1feda
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x1, %rsi
leaq 0x56e0d(%rip), %rdi     # 0x76b29
movl $0x4, %edx
callq 0x3030
cmpl $0x0, %eax
jne 0x1fde0
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x5, %rsi
movq -0xa0(%rbp), %rax
movl 0x4(%rax), %edx
subl $0x6, %edx
leaq -0xb0(%rbp), %rdi
callq 0x8ee0
cmpq $0x0, -0xa8(%rbp)
jne 0x1fd71
leaq 0x57b4d(%rip), %rax     # 0x778b5
movq %rax, -0xd8(%rbp)
jmp 0x1fd7f
movq -0xa8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xe0(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x1fda4
leaq 0x57b1a(%rip), %rax     # 0x778b5
movq %rax, -0xe8(%rbp)
jmp 0x1fdaf
movq -0x68(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0xe0(%rbp), %rdx
movq -0xe8(%rbp), %rcx
leaq -0x28(%rbp), %rdi
leaq 0x56d66(%rip), %rsi     # 0x76b2e
movb $0x0, %al
callq 0x94d0
leaq -0xb0(%rbp), %rdi
callq 0x9310
jmp 0x1fed8
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x1, %rsi
leaq 0x56d4f(%rip), %rdi     # 0x76b45
movl $0x4, %edx
callq 0x3030
cmpl $0x0, %eax
jne 0x1feb7
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rsi
addq $0x5, %rsi
movq -0xa0(%rbp), %rax
movl 0x4(%rax), %edx
subl $0x6, %edx
leaq -0xc0(%rbp), %rdi
callq 0x8ee0
cmpq $0x0, -0x68(%rbp)
jne 0x1fe48
leaq 0x57a76(%rip), %rax     # 0x778b5
movq %rax, -0xf0(%rbp)
jmp 0x1fe53
movq -0x68(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0xf8(%rbp)
cmpq $0x0, -0xb8(%rbp)
jne 0x1fe7b
leaq 0x57a43(%rip), %rax     # 0x778b5
movq %rax, -0x100(%rbp)
jmp 0x1fe89
movq -0xb8(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xf8(%rbp), %rdx
movq -0x100(%rbp), %rcx
leaq -0x38(%rbp), %rdi
leaq 0x56ca8(%rip), %rsi     # 0x76b4a
movb $0x0, %al
callq 0x94d0
leaq -0xc0(%rbp), %rdi
callq 0x9310
jmp 0x1fed6
leaq 0x5259d(%rip), %rdi     # 0x7245b
leaq 0x544cf(%rip), %rsi     # 0x74394
movl $0x11cd, %edx           # imm = 0x11CD
leaq 0x56b21(%rip), %rcx     # 0x769f2
callq 0x30a0
jmp 0x1fed8
jmp 0x1fef9
leaq 0x5257a(%rip), %rdi     # 0x7245b
leaq 0x544ac(%rip), %rsi     # 0x74394
movl $0x11d0, %edx           # imm = 0x11D0
leaq 0x56afe(%rip), %rcx     # 0x769f2
callq 0x30a0
leaq -0x90(%rbp), %rdi
callq 0x130a0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x1fbc0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0x9100
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movl 0x4(%rax), %edx
leaq -0xd0(%rbp), %rdi
callq 0x8ee0
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x108(%rbp)
cmpq $0x0, -0xc8(%rbp)
jne 0x1ff70
leaq 0x5794e(%rip), %rax     # 0x778b5
movq %rax, -0x110(%rbp)
jmp 0x1ff7e
movq -0xc8(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x108(%rbp), %rdi
movq -0x110(%rbp), %rdx
leaq 0x56bce(%rip), %rsi     # 0x76b61
movb $0x0, %al
callq 0x94d0
leaq -0xd0(%rbp), %rdi
callq 0x9310
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
leaq -0x38(%rbp), %rsi
callq 0x9100
leaq -0x28(%rbp), %rdi
callq 0x9310
leaq -0x38(%rbp), %rdi
callq 0x9310
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)