// File: /workspace/github_c_makefile_star2_O1/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
movl %ecx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
testq %r14, %r14
je 0x2ccb9
movl (%r14), %eax
cmpl $0x43f, %eax            # imm = 0x43F
jg 0x2c96e
cmpl $0x430, %eax            # imm = 0x430
jne 0x2c999
movl 0x44(%r14), %eax
decl %eax
cmpl $0x2, %eax
jae 0x2ccd8
testq %rdx, %rdx
je 0x2c900
movb $0xf, (%rdx)
movq 0x48(%r14), %rax
movq (%rax), %r15
cmpl $0x0, 0x44(%r15)
jle 0x2c959
xorl %r12d, %r12d
movq 0x48(%r15), %rax
movq (%rax,%r12,8), %rax
movl (%rax), %ecx
cmpl $0xa03, %ecx            # imm = 0xA03
je 0x2c94d
cmpl $0xa02, %ecx            # imm = 0xA02
jne 0x2cc9a
cmpl $0x2, 0x44(%rax)
jne 0x2cc7b
movq 0x48(%rax), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2c8aa
incq %r12
movslq 0x44(%r15), %rax
cmpq %rax, %r12
jl 0x2c911
cmpl $0x2, 0x44(%r14)
jne 0x2cc45
movq 0x48(%r14), %rax
movq 0x8(%rax), %r14
jmp 0x2c98f
cmpl $0x440, %eax            # imm = 0x440
jne 0x2c9d3
cmpl $0x1, 0x44(%r14)
jne 0x2ccf7
testq %rdx, %rdx
je 0x2c988
movb $0x10, (%rdx)
movq 0x48(%r14), %rax
movq (%rax), %r14
xorl %edx, %edx
xorl %r15d, %r15d
jmp 0x2c8c7
addl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x20, %eax
ja 0x2cd16
leaq 0x1e4e6(%rip), %rcx     # 0x4ae94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x44(%r14)
jne 0x2cd54
testq %rdx, %rdx
je 0x2cc45
movb $0x1, (%rdx)
jmp 0x2cc45
cmpl $0x4ff, %eax            # imm = 0x4FF
jne 0x2cd16
cmpl $0x0, 0x44(%r14)
jne 0x2cf06
testq %rdx, %rdx
je 0x2cc45
movb $-0x1, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2cd73
testq %rdx, %rdx
je 0x2cc45
movb $0xc, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2cd92
testq %rdx, %rdx
je 0x2cc45
movb $0x9, (%rdx)
jmp 0x2cc45
cmpl $0x1, 0x44(%r14)
jne 0x2cdb1
testq %rdx, %rdx
je 0x2ca45
movb $0xd, (%rdx)
movq 0x48(%r14), %rax
movq (%rax), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x2cf25
movq 0x10(%rax), %r12
movq %rbx, %rdi
movq %r14, %rsi
movl $0x2, %edx
movq %r12, %rcx
callq 0x6db9
testq %rax, %rax
je 0x2cc57
testb $0x1, %r15b
je 0x2cc45
cmpb $0x1, 0x40(%rax)
jne 0x2cc45
movq 0x50(%rbx), %rax
leaq 0x1f16e(%rip), %rdx     # 0x4bc05
jmp 0x2cc62
cmpl $0x0, 0x44(%r14)
jne 0x2cdd0
testq %rdx, %rdx
je 0x2cc45
movb $0x4, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2cdef
testq %rdx, %rdx
je 0x2cc45
movb $0x2, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2ce0e
testq %rdx, %rdx
je 0x2cc45
movb $0xa, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2ce2d
testq %rdx, %rdx
je 0x2cc45
movb $0x8, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2ce4c
testq %rdx, %rdx
je 0x2cc45
movb $0x3, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2ce6b
testq %rdx, %rdx
je 0x2cc45
movb $0x5, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2ce8a
testq %rdx, %rdx
je 0x2cc45
movb $0x6, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2cea9
testq %rdx, %rdx
je 0x2cc45
movb $0x7, (%rdx)
jmp 0x2cc45
cmpl $0x0, 0x44(%r14)
jne 0x2cec8
testq %rdx, %rdx
je 0x2cc45
movb $0xb, (%rdx)
jmp 0x2cc45
cmpl $0x2, 0x44(%r14)
jne 0x2cee7
testq %rdx, %rdx
je 0x2cbab
movb $0xe, (%rdx)
movq 0x48(%r14), %rax
movq (%rax), %r13
cmpl $0x421, (%r13)          # imm = 0x421
jne 0x2cf44
cmpl $0x0, 0x44(%r13)
jle 0x2cc31
xorl %r15d, %r15d
movq 0x48(%r13), %rax
movq (%rax,%r15,8), %r12
cmpl $0x300, (%r12)          # imm = 0x300
jne 0x2cd35
movq %rbx, %rdi
movq %r12, %rsi
callq 0x24ee8
testq %rax, %rax
jne 0x2cc25
movups 0x1f036(%rip), %xmm0    # 0x4bc2d
movaps %xmm0, -0x420(%rbp)
movups 0x1f018(%rip), %xmm0    # 0x4bc1d
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 0x2cbca
movq 0x48(%r14), %rax
movq 0x8(%rax), %rsi
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2c8aa
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rbx), %rax
leaq 0x1ef91(%rip), %rdx     # 0x4bbf3
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 0x15c62(%rip), %rdi     # 0x428e4
leaq 0x1ebd1(%rip), %rsi     # 0x4b85a
leaq 0x1ef10(%rip), %rcx     # 0x4bba0
movl $0x3cf, %edx            # imm = 0x3CF
callq 0x30a0
leaq 0x136e3(%rip), %rdi     # 0x40384
leaq 0x1ebb2(%rip), %rsi     # 0x4b85a
leaq 0x1eef1(%rip), %rcx     # 0x4bba0
movl $0x3d9, %edx            # imm = 0x3D9
callq 0x30a0
leaq 0x170d6(%rip), %rdi     # 0x43d96
leaq 0x1eb93(%rip), %rsi     # 0x4b85a
leaq 0x1eed2(%rip), %rcx     # 0x4bba0
movl $0x34e, %edx            # imm = 0x34E
callq 0x30a0
leaq 0x1ef60(%rip), %rdi     # 0x4bc3f
leaq 0x1eb74(%rip), %rsi     # 0x4b85a
leaq 0x1eeb3(%rip), %rcx     # 0x4bba0
movl $0x3bf, %edx            # imm = 0x3BF
callq 0x30a0
leaq 0x1f9f2(%rip), %rdi     # 0x4c6f0
leaq 0x1eb55(%rip), %rsi     # 0x4b85a
leaq 0x1ee94(%rip), %rcx     # 0x4bba0
movl $0x3e6, %edx            # imm = 0x3E6
callq 0x30a0
leaq 0x13667(%rip), %rdi     # 0x40384
leaq 0x1eb36(%rip), %rsi     # 0x4b85a
leaq 0x1ee75(%rip), %rcx     # 0x4bba0
movl $0x3f5, %edx            # imm = 0x3F5
callq 0x30a0
leaq 0x15a46(%rip), %rdi     # 0x42782
leaq 0x1eb17(%rip), %rsi     # 0x4b85a
leaq 0x1ee56(%rip), %rcx     # 0x4bba0
movl $0x3ad, %edx            # imm = 0x3AD
callq 0x30a0
leaq 0x1ee85(%rip), %rdi     # 0x4bbe0
leaq 0x1eaf8(%rip), %rsi     # 0x4b85a
leaq 0x1ee37(%rip), %rcx     # 0x4bba0
movl $0x354, %edx            # imm = 0x354
callq 0x30a0
leaq 0x1ee66(%rip), %rdi     # 0x4bbe0
leaq 0x1ead9(%rip), %rsi     # 0x4b85a
leaq 0x1ee18(%rip), %rcx     # 0x4bba0
movl $0x38b, %edx            # imm = 0x38B
callq 0x30a0
leaq 0x1ee47(%rip), %rdi     # 0x4bbe0
leaq 0x1eaba(%rip), %rsi     # 0x4b85a
leaq 0x1edf9(%rip), %rcx     # 0x4bba0
movl $0x37c, %edx            # imm = 0x37C
callq 0x30a0
leaq 0x1f938(%rip), %rdi     # 0x4c6f0
leaq 0x1ea9b(%rip), %rsi     # 0x4b85a
leaq 0x1edda(%rip), %rcx     # 0x4bba0
movl $0x390, %edx            # imm = 0x390
callq 0x30a0
leaq 0x1ee09(%rip), %rdi     # 0x4bbe0
leaq 0x1ea7c(%rip), %rsi     # 0x4b85a
leaq 0x1edbb(%rip), %rcx     # 0x4bba0
movl $0x36d, %edx            # imm = 0x36D
callq 0x30a0
leaq 0x1edea(%rip), %rdi     # 0x4bbe0
leaq 0x1ea5d(%rip), %rsi     # 0x4b85a
leaq 0x1ed9c(%rip), %rcx     # 0x4bba0
movl $0x359, %edx            # imm = 0x359
callq 0x30a0
leaq 0x1edcb(%rip), %rdi     # 0x4bbe0
leaq 0x1ea3e(%rip), %rsi     # 0x4b85a
leaq 0x1ed7d(%rip), %rcx     # 0x4bba0
movl $0x381, %edx            # imm = 0x381
callq 0x30a0
leaq 0x1edac(%rip), %rdi     # 0x4bbe0
leaq 0x1ea1f(%rip), %rsi     # 0x4b85a
leaq 0x1ed5e(%rip), %rcx     # 0x4bba0
movl $0x372, %edx            # imm = 0x372
callq 0x30a0
leaq 0x1ed8d(%rip), %rdi     # 0x4bbe0
leaq 0x1ea00(%rip), %rsi     # 0x4b85a
leaq 0x1ed3f(%rip), %rcx     # 0x4bba0
movl $0x363, %edx            # imm = 0x363
callq 0x30a0
leaq 0x1ed6e(%rip), %rdi     # 0x4bbe0
leaq 0x1e9e1(%rip), %rsi     # 0x4b85a
leaq 0x1ed20(%rip), %rcx     # 0x4bba0
movl $0x377, %edx            # imm = 0x377
callq 0x30a0
leaq 0x1ed4f(%rip), %rdi     # 0x4bbe0
leaq 0x1e9c2(%rip), %rsi     # 0x4b85a
leaq 0x1ed01(%rip), %rcx     # 0x4bba0
movl $0x35e, %edx            # imm = 0x35E
callq 0x30a0
leaq 0x1ed30(%rip), %rdi     # 0x4bbe0
leaq 0x1e9a3(%rip), %rsi     # 0x4b85a
leaq 0x1ece2(%rip), %rcx     # 0x4bba0
movl $0x368, %edx            # imm = 0x368
callq 0x30a0
leaq 0x1ed11(%rip), %rdi     # 0x4bbe0
leaq 0x1e984(%rip), %rsi     # 0x4b85a
leaq 0x1ecc3(%rip), %rcx     # 0x4bba0
movl $0x386, %edx            # imm = 0x386
callq 0x30a0
leaq 0x1ed67(%rip), %rdi     # 0x4bc55
leaq 0x1e965(%rip), %rsi     # 0x4b85a
leaq 0x1eca4(%rip), %rcx     # 0x4bba0
movl $0x3a5, %edx            # imm = 0x3A5
callq 0x30a0
leaq 0x1ecd3(%rip), %rdi     # 0x4bbe0
leaq 0x1e946(%rip), %rsi     # 0x4b85a
leaq 0x1ec85(%rip), %rcx     # 0x4bba0
movl $0x3f0, %edx            # imm = 0x3F0
callq 0x30a0
leaq 0x157e4(%rip), %rdi     # 0x42710
leaq 0x1e927(%rip), %rsi     # 0x4b85a
leaq 0x1ec66(%rip), %rcx     # 0x4bba0
movl $0x395, %edx            # imm = 0x395
callq 0x30a0
leaq 0x157e9(%rip), %rdi     # 0x42734
leaq 0x1e908(%rip), %rsi     # 0x4b85a
leaq 0x1ec47(%rip), %rcx     # 0x4bba0
movl $0x3aa, %edx            # imm = 0x3AA
callq 0x30a0