// File: /workspace/github_c_makefile_star2_O2/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 0xc120
movq %rsi, %r15
movq %rdi, %rbx
testq %r15, %r15
je 0xc047
movl (%r15), %eax
leal -0x400(%rax), %ecx
cmpl $0x20, %ecx
jbe 0xbdf5
cmpl $0x430, %eax            # imm = 0x430
je 0xbe95
cmpl $0x440, %eax            # imm = 0x440
jne 0xbf1b
cmpl $0x1, 0x44(%r15)
jne 0xc0a4
movq 0x48(%r15), %rax
movq (%rax), %r15
movb $0x2a, %al
jmp 0xbf0b
leaq 0x32390(%rip), %rdx     # 0x3e18c
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpl $0x2, 0x44(%r15)
jne 0xc0c3
movq 0x48(%r15), %rcx
movq (%rcx), %r12
cmpl $0x421, (%r12)          # imm = 0x421
jne 0xc0e2
movl 0x44(%r12), %eax
testl %eax, %eax
jle 0xc101
movq 0x8(%rcx), %r15
xorl %r13d, %r13d
cltq
cmpq %rax, %r13
jge 0xbdaf
movq 0x48(%r12), %rax
movq (%rax,%r13,8), %r14
cmpl $0x300, (%r14)          # imm = 0x300
jne 0xc028
movq %rbx, %rdi
leaq 0x329a7(%rip), %rsi     # 0x3e80b
callq 0x6e99
movq 0x10(%r14), %rax
movq 0x8(%rax), %rsi
movl 0x4(%rax), %edx
movq %rbx, %rdi
callq 0x700f
movq %rbx, %rdi
leaq 0x3c977(%rip), %rsi     # 0x487fd
callq 0x6e99
incq %r13
movl 0x44(%r12), %eax
jmp 0xbe39
movl 0x44(%r15), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0xc085
movq 0x48(%r15), %rcx
movq (%rcx), %r12
cmpl $0xa01, (%r12)          # imm = 0xA01
jne 0xc066
cmpl $0x2, %eax
jne 0xbec5
movq 0x8(%rcx), %r15
jmp 0xbec8
xorl %r15d, %r15d
movq %rbx, %rdi
leaq 0x32997(%rip), %rsi     # 0x3e869
callq 0x6e99
movq %rbx, %rdi
leaq 0x35590(%rip), %rsi     # 0x41471
callq 0x6e99
movq %rbx, %rdi
movq %r12, %rsi
callq 0xc938
movq %rbx, %rdi
leaq 0x34b37(%rip), %rsi     # 0x40a32
callq 0x6e99
movb $0x3a, %al
testq %r15, %r15
je 0xbf99
movzbl %al, %esi
movq %rbx, %rdi
callq 0x6f81
jmp 0xbdaf
cmpl $0x4ff, %eax            # imm = 0x4FF
je 0xbf99
leaq 0x30437(%rip), %rdi     # 0x3c360
leaq 0x32444(%rip), %rsi     # 0x3e374
leaq 0x32794(%rip), %rcx     # 0x3e6cb
movl $0x15c, %edx            # imm = 0x15C
callq 0x30a0
cmpl $0x1, 0x44(%r15)
jne 0xc13f
movq 0x48(%r15), %rax
movq (%rax), %r14
cmpl $0x200, (%r14)          # imm = 0x200
jne 0xc15e
leaq 0x33f9f(%rip), %rsi     # 0x3ff06
movq %rbx, %rdi
callq 0x6e99
leaq -0x38(%rbp), %r15
movq %r15, %rdi
callq 0x6e1c
movq %r15, %rdi
movq %r14, %rsi
callq 0xbd23
movq %rbx, %rdi
movq %r15, %rsi
callq 0x712e
movq %r15, %rdi
callq 0x72b9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x32773(%rip), %rsi     # 0x3e722
jmp 0xc012
leaq 0x32777(%rip), %rsi     # 0x3e72f
jmp 0xc012
leaq 0x3277c(%rip), %rsi     # 0x3e73d
jmp 0xc012
leaq 0x32766(%rip), %rsi     # 0x3e730
jmp 0xc012
leaq 0x32756(%rip), %rsi     # 0x3e729
jmp 0xc012
leaq 0x3275b(%rip), %rsi     # 0x3e737
jmp 0xc012
leaq 0x3273e(%rip), %rsi     # 0x3e723
jmp 0xc012
leaq 0x3275c(%rip), %rsi     # 0x3e74a
jmp 0xc012
leaq 0x32726(%rip), %rsi     # 0x3e71d
jmp 0xc012
leaq 0x32728(%rip), %rsi     # 0x3e728
jmp 0xc012
leaq 0x3273a(%rip), %rsi     # 0x3e743
jmp 0xc012
leaq 0x32724(%rip), %rsi     # 0x3e736
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6e99
leaq 0x327af(%rip), %rdi     # 0x3e7de
leaq 0x3233e(%rip), %rsi     # 0x3e374
leaq 0x3268e(%rip), %rcx     # 0x3e6cb
movl $0x12a, %edx            # imm = 0x12A
callq 0x30a0
leaq 0x326c5(%rip), %rdi     # 0x3e713
leaq 0x3231f(%rip), %rsi     # 0x3e374
leaq 0x3266f(%rip), %rcx     # 0x3e6cb
movl $0xdd, %edx
callq 0x30a0
leaq 0x327d3(%rip), %rdi     # 0x3e840
leaq 0x32300(%rip), %rsi     # 0x3e374
leaq 0x32650(%rip), %rcx     # 0x3e6cb
movl $0x13b, %edx            # imm = 0x13B
callq 0x30a0
leaq 0x32781(%rip), %rdi     # 0x3e80d
leaq 0x322e1(%rip), %rsi     # 0x3e374
leaq 0x32631(%rip), %rcx     # 0x3e6cb
movl $0x136, %edx            # imm = 0x136
callq 0x30a0
leaq 0x326a9(%rip), %rdi     # 0x3e754
leaq 0x322c2(%rip), %rsi     # 0x3e374
leaq 0x32612(%rip), %rcx     # 0x3e6cb
movl $0x14f, %edx            # imm = 0x14F
callq 0x30a0
leaq 0x3275e(%rip), %rdi     # 0x3e828
leaq 0x322a3(%rip), %rsi     # 0x3e374
leaq 0x325f3(%rip), %rcx     # 0x3e6cb
movl $0x120, %edx            # imm = 0x120
callq 0x30a0
leaq 0x326a7(%rip), %rdi     # 0x3e790
leaq 0x32284(%rip), %rsi     # 0x3e374
leaq 0x325d4(%rip), %rcx     # 0x3e6cb
movl $0x123, %edx            # imm = 0x123
callq 0x30a0
leaq 0x326b9(%rip), %rdi     # 0x3e7c1
leaq 0x32265(%rip), %rsi     # 0x3e374
leaq 0x325b5(%rip), %rcx     # 0x3e6cb
movl $0x124, %edx            # imm = 0x124
callq 0x30a0
leaq 0x30909(%rip), %rdi     # 0x3ca30
leaq 0x32246(%rip), %rsi     # 0x3e374
leaq 0x32596(%rip), %rcx     # 0x3e6cb
movl $0xdc, %edx
callq 0x30a0
leaq 0x3260e(%rip), %rdi     # 0x3e754
leaq 0x32227(%rip), %rsi     # 0x3e374
leaq 0x32577(%rip), %rcx     # 0x3e6cb
movl $0x111, %edx            # imm = 0x111
callq 0x30a0
leaq 0x32607(%rip), %rdi     # 0x3e76c
leaq 0x32208(%rip), %rsi     # 0x3e374
leaq 0x32558(%rip), %rcx     # 0x3e6cb
movl $0x114, %edx            # imm = 0x114
callq 0x30a0