// File: /workspace/github_c_makefile_star2_O3/Ihsoh[P]ilang/compiler/frontend/semantics.c
// Function: _type
static void __type(
	ParserContext *ctx,
	ParserASTNode *node,
	uint8_t *type,
	bool first_type
) {
	assert(ctx);
	assert(node);
	
	#define _SET_TYPE(t) { if (type != NULL) { *type = (t); } }

	switch (node->type) {
		case FE_NODE_TYPE_CHAR: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_CHAR)
			break;
		}
		case FE_NODE_TYPE_INT8: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_INT8)
			break;
		}
		case FE_NODE_TYPE_UINT8: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_UINT8)
			break;
		}
		case FE_NODE_TYPE_INT16: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_INT16)
			break;
		}
		case FE_NODE_TYPE_UINT16: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_UINT16)
			break;
		}
		case FE_NODE_TYPE_INT32: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_INT32)
			break;
		}
		case FE_NODE_TYPE_UINT32: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_UINT32)
			break;
		}
		case FE_NODE_TYPE_INT64: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_INT64)
			break;
		}
		case FE_NODE_TYPE_UINT64: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_UINT64)
			break;
		}
		case FE_NODE_TYPE_FLOAT: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_FLOAT)
			break;
		}
		case FE_NODE_TYPE_DOUBLE: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_DOUBLE)
			break;
		}
		case FE_NODE_TYPE_VA_LIST: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_VA_LIST)
			break;
		}
		case FE_NODE_TYPE_STRUCT: {
			assert(node->nchilds == 1);

			_SET_TYPE(FE_TYPE_STRUCT)

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

			LexerToken *token = node_id->token;
			ParserSymbol *symbol_struct = parser_get_symbol_from_node(ctx, node, FE_SYM_STRUCT, token);
			if (symbol_struct == NULL) {
				_SYNERR_TOKEN(ctx, token, "undefined struct.");
			} else {
				if (first_type
						&& FE_STRUCT_SYMBOL_GET_DUMMY(symbol_struct)) {
					_SYNERR_TOKEN(ctx, token, "struct not implemented.");
				}
			}

			break;
		}
		case FE_NODE_TYPE_ARRAY: {
			assert(node->nchilds == 2);

			_SET_TYPE(FE_TYPE_ARRAY)

			ParserASTNode *node_array_dims = node->childs[0];
			assert(node_array_dims->type == FE_NODE_TYPE_ARRAY_DIMS);
			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);

				uint64_t dim = fe_parser_get_uint_val(ctx, node_array_dim);
				if (dim == 0) {
					_SYNERR_NODE(
						ctx,
						node_array_dim,
						"array dimension size cannot be 0."
					);
				}
			}
			
			ParserASTNode *node_type = node->childs[1];
			__type(ctx, node_type, NULL, false);

			break;
		}
		case FE_NODE_TYPE_FUNC: {
			assert(node->nchilds == 1 || node->nchilds == 2);

			_SET_TYPE(FE_TYPE_FUNC)

			ParserASTNode *node_params = NULL;
			ParserASTNode *node_type = NULL;

			node_params = node->childs[0];
			for (int i = 0; i < node_params->nchilds; i++) {
				ParserASTNode *node_param = node_params->childs[i];
				switch (node_param->type) {
					case FE_NODE_FUNC_PARAMS_ELLIPSIS_ITEM: {

						break;
					}
					case FE_NODE_FUNC_PARAMS_ITEM: {
						assert(node_param->nchilds == 2);
						
						ParserASTNode *node_param_id = node_param->childs[0];

						ParserASTNode *node_param_type = node_param->childs[1];
						__type(ctx, node_param_type, NULL, false);

						break;
					}
					default: {
						assert(0);
					}
				}
			}
			
			if (node->nchilds == 2) {
				node_type = node->childs[1];
				__type(ctx, node_type, NULL, false);
			}

			break;
		}
		case FE_NODE_TYPE_POINTER: {
			assert(node->nchilds == 1);

			_SET_TYPE(FE_TYPE_POINTER)

			ParserASTNode *node_type = node->childs[0];
			__type(ctx, node_type, NULL, false);

			break;
		}
		case FE_NODE_TYPE_VOID: {
			assert(node->nchilds == 0);
			_SET_TYPE(FE_TYPE_VOID)
			break;
		}
		default: {
			assert(0);
		}
	}

	#undef	_SET_TYPE
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x408, %rsp            # imm = 0x408
testq %rsi, %rsi
je 0x2bfcd
movl %ecx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movl (%r14), %eax
cmpl $0x43f, %eax            # imm = 0x43F
jg 0x2bf97
cmpl $0x430, %eax            # imm = 0x430
jne 0x2bfec
movl 0x44(%r14), %eax
decl %eax
cmpl $0x2, %eax
jae 0x2c30c
testq %rdx, %rdx
je 0x2bf25
movb $0xf, (%rdx)
movq 0x48(%r14), %rax
movq (%rax), %r15
movl 0x44(%r15), %eax
testl %eax, %eax
jle 0x2bf82
xorl %r12d, %r12d
movq 0x48(%r15), %rcx
movq (%rcx,%r12,8), %rcx
movl (%rcx), %edx
cmpl $0xa03, %edx            # imm = 0xA03
je 0x2bf77
cmpl $0xa02, %edx            # imm = 0xA02
jne 0x2c2ed
cmpl $0x2, 0x44(%rcx)
jne 0x2c2ce
movq 0x48(%rcx), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2becf
movl 0x44(%r15), %eax
incq %r12
movslq %eax, %rcx
cmpq %rcx, %r12
jl 0x2bf37
cmpl $0x2, 0x44(%r14)
jne 0x2c298
movq 0x48(%r14), %rax
addq $0x8, %rax
jmp 0x2bfb9
cmpl $0x440, %eax            # imm = 0x440
jne 0x2c026
cmpl $0x1, 0x44(%r14)
jne 0x2c32b
testq %rdx, %rdx
je 0x2bfb5
movb $0x10, (%rdx)
movq 0x48(%r14), %rax
movq (%rax), %r14
xorl %r15d, %r15d
movl $0x0, %edx
testq %r14, %r14
jne 0x2bef5
leaq 0x16e0e(%rip), %rdi     # 0x42de2
leaq 0x1e91f(%rip), %rsi     # 0x4a8fa
leaq 0x1ec5e(%rip), %rcx     # 0x4ac40
movl $0x34e, %edx            # imm = 0x34E
callq 0x30a0
addl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x20, %eax
ja 0x2c34a
leaq 0x1df63(%rip), %rcx     # 0x49f64
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x44(%r14)
jne 0x2c388
testq %rdx, %rdx
je 0x2c298
movb $0x1, (%rdx)
jmp 0x2c298
cmpl $0x4ff, %eax            # imm = 0x4FF
jne 0x2c34a
cmpl $0x0, 0x44(%r14)
jne 0x2c53a
testq %rdx, %rdx
je 0x2c298
movb $-0x1, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c3a7
testq %rdx, %rdx
je 0x2c298
movb $0xc, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c3c6
testq %rdx, %rdx
je 0x2c298
movb $0x9, (%rdx)
jmp 0x2c298
cmpl $0x1, 0x44(%r14)
jne 0x2c3e5
testq %rdx, %rdx
je 0x2c098
movb $0xd, (%rdx)
movq 0x48(%r14), %rax
movq (%rax), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x2c559
movq 0x10(%rax), %r12
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
movq %r12, %rcx
callq 0x6c89
testq %rax, %rax
je 0x2c2aa
testb $0x1, %r15b
je 0x2c298
cmpb $0x1, 0x40(%rax)
jne 0x2c298
movq 0x50(%rbx), %rax
leaq 0x1ebbb(%rip), %rdx     # 0x4aca5
jmp 0x2c2b5
cmpl $0x0, 0x44(%r14)
jne 0x2c404
testq %rdx, %rdx
je 0x2c298
movb $0x4, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c423
testq %rdx, %rdx
je 0x2c298
movb $0x2, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c442
testq %rdx, %rdx
je 0x2c298
movb $0xa, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c461
testq %rdx, %rdx
je 0x2c298
movb $0x8, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c480
testq %rdx, %rdx
je 0x2c298
movb $0x3, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c49f
testq %rdx, %rdx
je 0x2c298
movb $0x5, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c4be
testq %rdx, %rdx
je 0x2c298
movb $0x6, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c4dd
testq %rdx, %rdx
je 0x2c298
movb $0x7, (%rdx)
jmp 0x2c298
cmpl $0x0, 0x44(%r14)
jne 0x2c4fc
testq %rdx, %rdx
je 0x2c298
movb $0xb, (%rdx)
jmp 0x2c298
cmpl $0x2, 0x44(%r14)
jne 0x2c51b
testq %rdx, %rdx
je 0x2c1fe
movb $0xe, (%rdx)
movq 0x48(%r14), %rax
movq (%rax), %r13
cmpl $0x421, (%r13)          # imm = 0x421
jne 0x2c578
cmpl $0x0, 0x44(%r13)
jle 0x2c288
xorl %r15d, %r15d
movq 0x48(%r13), %rax
movq (%rax,%r15,8), %r12
cmpl $0x300, (%r12)          # imm = 0x300
jne 0x2c369
movq %rbx, %rdi
movq %r12, %rsi
callq 0x24ade
testq %rax, %rax
jne 0x2c278
movups 0x1ea83(%rip), %xmm0    # 0x4accd
movaps %xmm0, -0x420(%rbp)
movups 0x1ea65(%rip), %xmm0    # 0x4acbd
movaps %xmm0, -0x430(%rbp)
movw $0x2e, -0x410(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
leaq -0x430(%rbp), %rdx
callq *0x58(%rbx)
incq %r15
movslq 0x44(%r13), %rax
cmpq %rax, %r15
jl 0x2c21d
movq 0x48(%r14), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2becf
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rbx), %rax
leaq 0x1e9de(%rip), %rdx     # 0x4ac93
movq %rbx, %rdi
movq %r12, %rsi
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
leaq 0x1565b(%rip), %rdi     # 0x41930
leaq 0x1e61e(%rip), %rsi     # 0x4a8fa
leaq 0x1e95d(%rip), %rcx     # 0x4ac40
movl $0x3cf, %edx            # imm = 0x3CF
callq 0x30a0
leaq 0x1306c(%rip), %rdi     # 0x3f360
leaq 0x1e5ff(%rip), %rsi     # 0x4a8fa
leaq 0x1e93e(%rip), %rcx     # 0x4ac40
movl $0x3d9, %edx            # imm = 0x3D9
callq 0x30a0
leaq 0x1e9cc(%rip), %rdi     # 0x4acdf
leaq 0x1e5e0(%rip), %rsi     # 0x4a8fa
leaq 0x1e91f(%rip), %rcx     # 0x4ac40
movl $0x3bf, %edx            # imm = 0x3BF
callq 0x30a0
leaq 0x1f45e(%rip), %rdi     # 0x4b790
leaq 0x1e5c1(%rip), %rsi     # 0x4a8fa
leaq 0x1e900(%rip), %rcx     # 0x4ac40
movl $0x3e6, %edx            # imm = 0x3E6
callq 0x30a0
leaq 0x1300f(%rip), %rdi     # 0x3f360
leaq 0x1e5a2(%rip), %rsi     # 0x4a8fa
leaq 0x1e8e1(%rip), %rcx     # 0x4ac40
movl $0x3f5, %edx            # imm = 0x3F5
callq 0x30a0
leaq 0x1545e(%rip), %rdi     # 0x417ce
leaq 0x1e583(%rip), %rsi     # 0x4a8fa
leaq 0x1e8c2(%rip), %rcx     # 0x4ac40
movl $0x3ad, %edx            # imm = 0x3AD
callq 0x30a0
leaq 0x1e8f1(%rip), %rdi     # 0x4ac80
leaq 0x1e564(%rip), %rsi     # 0x4a8fa
leaq 0x1e8a3(%rip), %rcx     # 0x4ac40
movl $0x354, %edx            # imm = 0x354
callq 0x30a0
leaq 0x1e8d2(%rip), %rdi     # 0x4ac80
leaq 0x1e545(%rip), %rsi     # 0x4a8fa
leaq 0x1e884(%rip), %rcx     # 0x4ac40
movl $0x38b, %edx            # imm = 0x38B
callq 0x30a0
leaq 0x1e8b3(%rip), %rdi     # 0x4ac80
leaq 0x1e526(%rip), %rsi     # 0x4a8fa
leaq 0x1e865(%rip), %rcx     # 0x4ac40
movl $0x37c, %edx            # imm = 0x37C
callq 0x30a0
leaq 0x1f3a4(%rip), %rdi     # 0x4b790
leaq 0x1e507(%rip), %rsi     # 0x4a8fa
leaq 0x1e846(%rip), %rcx     # 0x4ac40
movl $0x390, %edx            # imm = 0x390
callq 0x30a0
leaq 0x1e875(%rip), %rdi     # 0x4ac80
leaq 0x1e4e8(%rip), %rsi     # 0x4a8fa
leaq 0x1e827(%rip), %rcx     # 0x4ac40
movl $0x36d, %edx            # imm = 0x36D
callq 0x30a0
leaq 0x1e856(%rip), %rdi     # 0x4ac80
leaq 0x1e4c9(%rip), %rsi     # 0x4a8fa
leaq 0x1e808(%rip), %rcx     # 0x4ac40
movl $0x359, %edx            # imm = 0x359
callq 0x30a0
leaq 0x1e837(%rip), %rdi     # 0x4ac80
leaq 0x1e4aa(%rip), %rsi     # 0x4a8fa
leaq 0x1e7e9(%rip), %rcx     # 0x4ac40
movl $0x381, %edx            # imm = 0x381
callq 0x30a0
leaq 0x1e818(%rip), %rdi     # 0x4ac80
leaq 0x1e48b(%rip), %rsi     # 0x4a8fa
leaq 0x1e7ca(%rip), %rcx     # 0x4ac40
movl $0x372, %edx            # imm = 0x372
callq 0x30a0
leaq 0x1e7f9(%rip), %rdi     # 0x4ac80
leaq 0x1e46c(%rip), %rsi     # 0x4a8fa
leaq 0x1e7ab(%rip), %rcx     # 0x4ac40
movl $0x363, %edx            # imm = 0x363
callq 0x30a0
leaq 0x1e7da(%rip), %rdi     # 0x4ac80
leaq 0x1e44d(%rip), %rsi     # 0x4a8fa
leaq 0x1e78c(%rip), %rcx     # 0x4ac40
movl $0x377, %edx            # imm = 0x377
callq 0x30a0
leaq 0x1e7bb(%rip), %rdi     # 0x4ac80
leaq 0x1e42e(%rip), %rsi     # 0x4a8fa
leaq 0x1e76d(%rip), %rcx     # 0x4ac40
movl $0x35e, %edx            # imm = 0x35E
callq 0x30a0
leaq 0x1e79c(%rip), %rdi     # 0x4ac80
leaq 0x1e40f(%rip), %rsi     # 0x4a8fa
leaq 0x1e74e(%rip), %rcx     # 0x4ac40
movl $0x368, %edx            # imm = 0x368
callq 0x30a0
leaq 0x1e77d(%rip), %rdi     # 0x4ac80
leaq 0x1e3f0(%rip), %rsi     # 0x4a8fa
leaq 0x1e72f(%rip), %rcx     # 0x4ac40
movl $0x386, %edx            # imm = 0x386
callq 0x30a0
leaq 0x1e7d3(%rip), %rdi     # 0x4acf5
leaq 0x1e3d1(%rip), %rsi     # 0x4a8fa
leaq 0x1e710(%rip), %rcx     # 0x4ac40
movl $0x3a5, %edx            # imm = 0x3A5
callq 0x30a0
leaq 0x1e73f(%rip), %rdi     # 0x4ac80
leaq 0x1e3b2(%rip), %rsi     # 0x4a8fa
leaq 0x1e6f1(%rip), %rcx     # 0x4ac40
movl $0x3f0, %edx            # imm = 0x3F0
callq 0x30a0
leaq 0x151fc(%rip), %rdi     # 0x4175c
leaq 0x1e393(%rip), %rsi     # 0x4a8fa
leaq 0x1e6d2(%rip), %rcx     # 0x4ac40
movl $0x395, %edx            # imm = 0x395
callq 0x30a0
leaq 0x15201(%rip), %rdi     # 0x41780
leaq 0x1e374(%rip), %rsi     # 0x4a8fa
leaq 0x1e6b3(%rip), %rcx     # 0x4ac40
movl $0x3aa, %edx            # imm = 0x3AA
callq 0x30a0