// File: /workspace/github_c_makefile_star2_O3/Ihsoh[P]ilang/compiler/frontend/irgen.c
// Function: ir_type
static void _ir_type(
	IRGeneratorContext *ctx,
	ResizableString *rstr,
	ParserASTNode *node_type
) {
	assert(ctx);
	assert(rstr);
	assert(node_type);

	switch (node_type->type) {
		case FE_NODE_TYPE_CHAR: {
			rstr_append_with_cstr(rstr, "char");
			break;
		}
		case FE_NODE_TYPE_INT8: {
			rstr_append_with_cstr(rstr, "int8");
			break;
		}
		case FE_NODE_TYPE_UINT8: {
			rstr_append_with_cstr(rstr, "uint8");
			break;
		}
		case FE_NODE_TYPE_INT16: {
			rstr_append_with_cstr(rstr, "int16");
			break;
		}
		case FE_NODE_TYPE_UINT16: {
			rstr_append_with_cstr(rstr, "uint16");
			break;
		}
		case FE_NODE_TYPE_INT32: {
			rstr_append_with_cstr(rstr, "int32");
			break;
		}
		case FE_NODE_TYPE_UINT32: {
			rstr_append_with_cstr(rstr, "uint32");
			break;
		}
		case FE_NODE_TYPE_INT64: {
			rstr_append_with_cstr(rstr, "int64");
			break;
		}
		case FE_NODE_TYPE_UINT64: {
			rstr_append_with_cstr(rstr, "uint64");
			break;
		}
		case FE_NODE_TYPE_FLOAT: {
			rstr_append_with_cstr(rstr, "float");
			break;
		}
		case FE_NODE_TYPE_DOUBLE: {
			rstr_append_with_cstr(rstr, "double");
			break;
		}
		case FE_NODE_TYPE_VA_LIST: {
			rstr_append_with_cstr(rstr, "__va_list");
			break;
		}
		case FE_NODE_TYPE_STRUCT: {
			assert(node_type->nchilds == 1);

			ParserASTNode *node_id = node_type->childs[0];
			assert(node_id->type == FE_NODE_IDENTIFIER);

			rstr_append_with_cstr(rstr, "struct ");

			ResizableString rstr_id;
			rstr_init(&rstr_id);
			_ir_identifier_name(ctx, &rstr_id, node_id);
			rstr_append_with_rstr(rstr, &rstr_id);
			rstr_free(&rstr_id);
			break;
		}
		case FE_NODE_TYPE_ARRAY: {
			assert(node_type->nchilds == 2);

			ParserASTNode *node_array_dims = node_type->childs[0];
			assert(node_array_dims->type == FE_NODE_TYPE_ARRAY_DIMS);
			assert(node_array_dims->nchilds > 0);

			ParserASTNode *node_t = node_type->childs[1];

			for (int i = 0; i < node_array_dims->nchilds; i++) {
				ParserASTNode *node_array_dim = node_array_dims->childs[i];
				assert(node_array_dim->type == FE_NODE_LITERAL_UINT);

				rstr_append_with_cstr(rstr, "[");
				rstr_append_with_raw(rstr, node_array_dim->token->content, node_array_dim->token->len);
				rstr_append_with_cstr(rstr, "]");
			}

			_ir_type(ctx, rstr, node_t);

			break;
		}
		case FE_NODE_TYPE_FUNC: {
			assert(node_type->nchilds == 1 || node_type->nchilds == 2);
			ParserASTNode *node_params = NULL;
			ParserASTNode *node_t = NULL;

			node_params = node_type->childs[0];
			assert(node_params->type == FE_NODE_FUNC_PARAMS);

			if (node_type->nchilds == 2) {
				node_t = node_type->childs[1];
			}

			rstr_append_with_cstr(rstr, "function");

			rstr_append_with_cstr(rstr, "(");
			_ir_func_type_params(ctx, rstr, node_params);
			rstr_append_with_cstr(rstr, ")");

			if (node_t != NULL) {
				rstr_append_with_char(rstr, ':');
				_ir_type(ctx, rstr, node_t);
			}
			
			break;
		}
		case FE_NODE_TYPE_POINTER: {
			assert(node_type->nchilds == 1);
			ParserASTNode *node_t = node_type->childs[0];

			rstr_append_with_char(rstr, '*');

			_ir_type(ctx, rstr, node_t);
			break;
		}
		case FE_NODE_TYPE_VOID: {
			// 什么都不做。
			break;
		}
		default: {
			assert(0);
			break;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0xcd61
movq %rsi, %r13
testq %rsi, %rsi
je 0xcb28
movq %rdi, %rbx
movl (%r13), %eax
cmpl $0x42f, %eax            # imm = 0x42F
jle 0xc9f4
cmpl $0x430, %eax            # imm = 0x430
je 0xca9e
cmpl $0x440, %eax            # imm = 0x440
jne 0xcb47
cmpl $0x1, 0x44(%r13)
jne 0xcca7
movq 0x48(%r13), %rax
movq (%rax), %r13
movb $0x2a, %al
jmp 0xcb14
addl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x20, %eax
ja 0xcb52
leaq 0x34773(%rip), %rcx     # 0x4117c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x2, 0x44(%r13)
jne 0xcd04
movq 0x48(%r13), %rax
movq (%rax), %r12
cmpl $0x421, (%r12)          # imm = 0x421
jne 0xcd23
cmpl $0x0, 0x44(%r12)
jle 0xcd42
movq 0x8(%rax), %r13
xorl %r14d, %r14d
movq 0x48(%r12), %rax
movq (%rax,%r14,8), %r15
cmpl $0x300, (%r15)          # imm = 0x300
jne 0xcc88
movq %rbx, %rdi
leaq 0x34d96(%rip), %rsi     # 0x417fb
callq 0x73db
movq 0x10(%r15), %rax
movq 0x8(%rax), %rsi
movl 0x4(%rax), %edx
movq %rbx, %rdi
callq 0x7577
movq %rbx, %rdi
leaq 0x3ed36(%rip), %rsi     # 0x4b7bd
callq 0x73db
incq %r14
movslq 0x44(%r12), %rax
cmpq %rax, %r14
jl 0xca45
jmp 0xcb1f
movl 0x44(%r13), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0xccc6
movq 0x48(%r13), %rcx
movq (%rcx), %r12
cmpl $0xa01, (%r12)          # imm = 0xA01
jne 0xcce5
cmpl $0x2, %eax
jne 0xcace
movq 0x8(%rcx), %r13
jmp 0xcad1
xorl %r13d, %r13d
movq %rbx, %rdi
leaq 0x34d7e(%rip), %rsi     # 0x41859
callq 0x73db
movq %rbx, %rdi
leaq 0x3795c(%rip), %rsi     # 0x44446
callq 0x73db
movq %rbx, %rdi
movq %r12, %rsi
callq 0xd55e
movq %rbx, %rdi
leaq 0x36f06(%rip), %rsi     # 0x43a0a
callq 0x73db
movb $0x3a, %al
testq %r13, %r13
je 0xcc4a
movzbl %al, %esi
movq %rbx, %rdi
callq 0x74da
testq %r13, %r13
jne 0xc9ba
leaq 0x34bd4(%rip), %rdi     # 0x41703
leaq 0x3482e(%rip), %rsi     # 0x41364
leaq 0x34b7e(%rip), %rcx     # 0x416bb
movl $0xdd, %edx
callq 0x30a0
cmpl $0x4ff, %eax            # imm = 0x4FF
je 0xcc4a
leaq 0x32807(%rip), %rdi     # 0x3f360
leaq 0x34804(%rip), %rsi     # 0x41364
leaq 0x34b54(%rip), %rcx     # 0x416bb
movl $0x15c, %edx            # imm = 0x15C
callq 0x30a0
leaq 0x34ba7(%rip), %rsi     # 0x4171f
jmp 0xcc72
leaq 0x34baf(%rip), %rsi     # 0x41733
jmp 0xcc72
leaq 0x34b82(%rip), %rsi     # 0x41712
jmp 0xcc72
leaq 0x34b84(%rip), %rsi     # 0x41720
jmp 0xcc72
leaq 0x34b6b(%rip), %rsi     # 0x41713
jmp 0xcc72
leaq 0x34b73(%rip), %rsi     # 0x41727
jmp 0xcc72
leaq 0x34b4d(%rip), %rsi     # 0x4170d
jmp 0xcc72
leaq 0x34b4d(%rip), %rsi     # 0x41719
jmp 0xcc72
leaq 0x34b4e(%rip), %rsi     # 0x41726
jmp 0xcc72
cmpl $0x1, 0x44(%r13)
jne 0xcd80
movq 0x48(%r13), %rax
movq (%rax), %r15
cmpl $0x200, (%r15)          # imm = 0x200
jne 0xcd9f
leaq 0x362f3(%rip), %rsi     # 0x42ef6
movq %rbx, %rdi
callq 0x73db
leaq -0x38(%rbp), %r14
movq %r14, %rdi
callq 0x7354
movq %r14, %rdi
movl $0x5f, %esi
callq 0x74da
movq 0x10(%r15), %rax
movq 0x8(%rax), %rsi
movl 0x4(%rax), %edx
movq %r14, %rdi
callq 0x7577
movq %rbx, %rdi
movq %r14, %rsi
callq 0x769e
movq %r14, %rdi
callq 0x7852
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x34ab8(%rip), %rsi     # 0x41718
jmp 0xcc72
leaq 0x34ac4(%rip), %rsi     # 0x4172d
jmp 0xcc72
leaq 0x34ac8(%rip), %rsi     # 0x4173a
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x73db
leaq 0x34b3f(%rip), %rdi     # 0x417ce
leaq 0x346ce(%rip), %rsi     # 0x41364
leaq 0x34a1e(%rip), %rcx     # 0x416bb
movl $0x12a, %edx            # imm = 0x12A
callq 0x30a0
leaq 0x34a96(%rip), %rdi     # 0x41744
leaq 0x346af(%rip), %rsi     # 0x41364
leaq 0x349ff(%rip), %rcx     # 0x416bb
movl $0x14f, %edx            # imm = 0x14F
callq 0x30a0
leaq 0x34b30(%rip), %rdi     # 0x417fd
leaq 0x34690(%rip), %rsi     # 0x41364
leaq 0x349e0(%rip), %rcx     # 0x416bb
movl $0x136, %edx            # imm = 0x136
callq 0x30a0
leaq 0x34b44(%rip), %rdi     # 0x41830
leaq 0x34671(%rip), %rsi     # 0x41364
leaq 0x349c1(%rip), %rcx     # 0x416bb
movl $0x13b, %edx            # imm = 0x13B
callq 0x30a0
leaq 0x34b0d(%rip), %rdi     # 0x41818
leaq 0x34652(%rip), %rsi     # 0x41364
leaq 0x349a2(%rip), %rcx     # 0x416bb
movl $0x120, %edx            # imm = 0x120
callq 0x30a0
leaq 0x34a56(%rip), %rdi     # 0x41780
leaq 0x34633(%rip), %rsi     # 0x41364
leaq 0x34983(%rip), %rcx     # 0x416bb
movl $0x123, %edx            # imm = 0x123
callq 0x30a0
leaq 0x34a68(%rip), %rdi     # 0x417b1
leaq 0x34614(%rip), %rsi     # 0x41364
leaq 0x34964(%rip), %rcx     # 0x416bb
movl $0x124, %edx            # imm = 0x124
callq 0x30a0
leaq 0x32cc8(%rip), %rdi     # 0x3fa30
leaq 0x345f5(%rip), %rsi     # 0x41364
leaq 0x34945(%rip), %rcx     # 0x416bb
movl $0xdc, %edx
callq 0x30a0
leaq 0x349bd(%rip), %rdi     # 0x41744
leaq 0x345d6(%rip), %rsi     # 0x41364
leaq 0x34926(%rip), %rcx     # 0x416bb
movl $0x111, %edx            # imm = 0x111
callq 0x30a0
leaq 0x349b6(%rip), %rdi     # 0x4175c
leaq 0x345b7(%rip), %rsi     # 0x41364
leaq 0x34907(%rip), %rcx     # 0x416bb
movl $0x114, %edx            # imm = 0x114
callq 0x30a0