// File: /workspace/github_c_makefile_star2_O1/Ihsoh[P]ilang/compiler/backend/semantics.c
// Function: expr_unary
static void _expr_unary(
	ParserContext *ctx,
	ParserASTNode *node
) {
	assert(ctx);
	assert(node);

	uint32_t node_type = node->type;

	switch (node_type) {
		case BE_NODE_EXPR_NOT:
		case BE_NODE_EXPR_BNOT: {
			assert(node->nchilds == 1);

			ParserASTNode *node_oprd = node->childs[0];
			_expr_parenthesis(ctx, node_oprd);

			if (!_is_integer_type_node(ctx, node_oprd)) {
				switch (node_type) {
					case BE_NODE_EXPR_NOT: {
						_SYNERR_NODE(ctx, node, "unary operator '!' need integer operand.");
						break;
					}
					case BE_NODE_EXPR_BNOT: {
						_SYNERR_NODE(ctx, node, "unary operator '~' need integer operand.");
						break;
					}
					default: {
						assert(0);
					}
				}
			}

			BE_EXPR_AST_NODE_COPY(node, node_oprd);

			if (BE_EXPR_AST_NODE_GET_CONSTANT(node_oprd)) {
				_calc_unary_constexpr(ctx, node_type, node, node_oprd);
			}
			break;
		}
		case BE_NODE_EXPR_POSITIVE:
		case BE_NODE_EXPR_NEGATIVE: {
			assert(node->nchilds == 1);

			ParserASTNode *node_oprd = node->childs[0];
			_expr_parenthesis(ctx, node_oprd);

			if (!_is_number_type_node(ctx, node_oprd)) {
				switch (node_type) {
					case BE_NODE_EXPR_POSITIVE: {
						_SYNERR_NODE(ctx, node, "unary operator '+' need number operand.");
						break;
					}
					case BE_NODE_EXPR_NEGATIVE: {
						_SYNERR_NODE(ctx, node, "unary operator '-' need number operand.");
						break;
					}
					default: {
						assert(0);
					}
				}
			}

			BE_EXPR_AST_NODE_COPY(node, node_oprd);

			if (BE_EXPR_AST_NODE_GET_CONSTANT(node_oprd)) {
				BE_EXPR_AST_NODE_COPY_CONSTANT(node, node_oprd);
				_calc_unary_constexpr(ctx, node_type, node, node_oprd);
			}
			break;
		}
		case BE_NODE_EXPR_SIZEOF: {
			assert(node->nchilds == 1);

			ParserASTNode *node_oprd = node->childs[0];
			ParserASTNode *type_node = NULL;
			switch (_get_node_catagory(node_oprd->type)) {
				case BE_SEM_NODE_CATEGORY_TYPE: {
					_type(ctx, node_oprd, NULL);
					type_node = node_oprd;
					break;
				}
				case BE_SEM_NODE_CATAGORY_EXPR: {
					_expr(ctx, node_oprd);
					type_node = BE_EXPR_AST_NODE_GET_TYPE_NODE(node_oprd);
					break;
				}
				default: {
					assert(0);
					break;
				}
			}

			if (ctx->arch == BE_ARCH_32) {
				BE_EXPR_AST_NODE_SET_TYPE(node, BE_TYPE_UINT32);
				BE_EXPR_AST_NODE_SET_TYPE_NODE(node, _NODE_TYPE_UINT32);

				BE_EXPR_AST_NODE_SET_CONSTEXPR_RESULT_UINT32_VAL(
					node, (uint32_t) _calc_type_size(ctx, node, type_node)
				);
			} else if (ctx->arch == BE_ARCH_64) {
				BE_EXPR_AST_NODE_SET_TYPE(node, BE_TYPE_UINT64);
				BE_EXPR_AST_NODE_SET_TYPE_NODE(node, _NODE_TYPE_UINT64);
			
				BE_EXPR_AST_NODE_SET_CONSTEXPR_RESULT_UINT64_VAL(
					node, (uint64_t) _calc_type_size(ctx, node, type_node)
				);
			} else {
				assert(0);
			}

			BE_EXPR_AST_NODE_SET_CONSTANT(node, true);

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

			ParserASTNode *node_oprd = node->childs[0];
			ParserASTNode *type_node = NULL;
			switch (_get_node_catagory(node_oprd->type)) {
				case BE_SEM_NODE_CATEGORY_TYPE: {
					_type(ctx, node_oprd, NULL);
					type_node = node_oprd;
					break;
				}
				case BE_SEM_NODE_CATAGORY_EXPR: {
					_expr(ctx, node_oprd);
					type_node = BE_EXPR_AST_NODE_GET_TYPE_NODE(node_oprd);
					break;
				}
				default: {
					assert(0);
					break;
				}
			}

			size_t align = 0;
			if (node_oprd->type == BE_NODE_EXPR_ATOM
					&& node_oprd->childs[0]->type == BE_NODE_IDENTIFIER) {
				ParserSymbol *symbol = parser_get_symbol_from_node(
					ctx, node, BE_SYM_VAR, node_oprd->childs[0]->token
				);
				if (symbol != NULL) {
					align = BE_VAR_SYMBOL_GET_ALIGN(symbol);
				} else {
					align = _calc_type_align(ctx, node, type_node);
				}
			} else {
				align = _calc_type_align(ctx, node, type_node);
			}

			if (ctx->arch == BE_ARCH_32) {
				BE_EXPR_AST_NODE_SET_TYPE(node, BE_TYPE_UINT32);
				BE_EXPR_AST_NODE_SET_TYPE_NODE(node, _NODE_TYPE_UINT32);

				BE_EXPR_AST_NODE_SET_CONSTEXPR_RESULT_UINT32_VAL(
					node, (uint32_t) align
				);
			} else if (ctx->arch == BE_ARCH_64) {
				BE_EXPR_AST_NODE_SET_TYPE(node, BE_TYPE_UINT64);
				BE_EXPR_AST_NODE_SET_TYPE_NODE(node, _NODE_TYPE_UINT64);
			
				BE_EXPR_AST_NODE_SET_CONSTEXPR_RESULT_UINT64_VAL(
					node, (uint64_t) align
				);
			} else {
				assert(0);
			}

			BE_EXPR_AST_NODE_SET_CONSTANT(node, true);
			break;
		}
		case BE_NODE_EXPR_CAST: {
			assert(node->nchilds == 2);

			ParserASTNode *node_type = node->childs[0];
			ParserASTNode *node_expr = node->childs[1];

			_type(ctx, node_type, NULL);
			_expr(ctx, node_expr);

			BE_EXPR_AST_NODE_COPY(node, node_expr);

			uint8_t node_type_type = _get_type_by_type_node(ctx, node_type);
			if (node_type_type == BE_TYPE_STRUCT
					|| node_type_type == BE_TYPE_ARRAY
					|| node_type_type == BE_TYPE_FUNC) {
				_SYNERR_NODE(
					ctx, node, "operator cast cannot cast operand to struct type or array type or function type."
				);
			}

			ParserASTNode *node_expr_type = BE_EXPR_AST_NODE_GET_TYPE_NODE(node_expr);
			uint8_t node_expr_type_type = _get_type_by_type_node(ctx, node_expr_type);
			if (node_expr_type_type == BE_TYPE_STRUCT
					|| node_expr_type_type == BE_TYPE_ARRAY
					|| node_expr_type_type == BE_TYPE_FUNC) {
				_SYNERR_NODE(
					ctx, node, "operator cast cannot cast struct type or array type or function type operand."
				);
			}

			BE_EXPR_AST_NODE_SET_TYPE(node, _get_type_by_type_node(ctx, node_type));
			BE_EXPR_AST_NODE_SET_TYPE_NODE(node, node_type);

			if (BE_EXPR_AST_NODE_GET_CONSTANT(node_expr)) {
				BE_EXPR_AST_NODE_SET_CONSTANT(node, true);
				_calc_cast_constexpr(ctx, node_type_type, node, node_expr);
			}
			break;
		}
		default: {
			_expr_parenthesis(ctx, node);
			break;
		}
	}
}

// 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 0x32061
movq %rsi, %rbx
movq %rdi, %r14
movl (%rsi), %r15d
leal -0xec0(%r15), %eax
cmpl $0x8, %eax
ja 0x31caa
leaq 0x1be16(%rip), %rcx     # 0x4d9c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, 0x44(%rbx)
jne 0x3209f
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x32213
movq %r12, %rdi
callq 0x2ef23
testb %al, %al
jne 0x31f25
cmpl $0xec3, %r15d           # imm = 0xEC3
je 0x31ef4
cmpl $0xec0, %r15d           # imm = 0xEC0
jne 0x32178
movups 0x1d022(%rip), %xmm0    # 0x4ec2a
leaq -0x430(%rbp), %rdx
movups %xmm0, 0x19(%rdx)
movups 0x1d007(%rip), %xmm0    # 0x4ec21
movaps %xmm0, 0x10(%rdx)
movups 0x1cfec(%rip), %xmm0    # 0x4ec11
jmp 0x31f18
cmpl $0x1, 0x44(%rbx)
jne 0x32080
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x32213
testq %r12, %r12
je 0x320be
movzbl 0x1(%r12), %eax
shll $0x8, %eax
cmpl $0xe00, %eax            # imm = 0xE00
jne 0x320dd
movb 0x60(%r12), %al
decb %al
cmpb $0xb, %al
jb 0x32016
cmpl $0xec2, %r15d           # imm = 0xEC2
je 0x31fe2
cmpl $0xec1, %r15d           # imm = 0xEC1
jne 0x321f4
movups 0x1cfe0(%rip), %xmm0    # 0x4ec73
leaq -0x430(%rbp), %rdx
movaps %xmm0, 0x10(%rdx)
movups 0x1cfbe(%rip), %xmm0    # 0x4ec63
jmp 0x31ffb
movq %r14, %rdi
movq %rbx, %rsi
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32213
cmpl $0x1, 0x44(%rbx)
jne 0x320fc
movq 0x48(%rbx), %rax
movq (%rax), %r15
movzbl 0x1(%r15), %eax
shll $0x8, %eax
xorl %ecx, %ecx
cmpl $0xe00, %eax            # imm = 0xE00
sete %cl
addl %ecx, %ecx
cmpl $0x400, %eax            # imm = 0x400
movl $0x1, %eax
cmovnel %ecx, %eax
cmpl $0x2, %eax
je 0x31e76
cmpl $0x1, %eax
jne 0x32159
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x2e6cf
movq %r15, %r12
jmp 0x31e85
cmpl $0x2, 0x44(%rbx)
jne 0x3211b
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq 0x8(%rax), %r15
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2dcc6
movq %r14, %rdi
movq %r15, %rsi
callq 0x2e11b
movups 0x60(%r15), %xmm0
movups 0x70(%r15), %xmm1
movups 0x80(%r15), %xmm2
movups %xmm2, 0x80(%rbx)
movups %xmm1, 0x70(%rbx)
movups %xmm0, 0x60(%rbx)
movq %r12, %rdi
callq 0x32b74
movl %eax, %r13d
leal -0xd(%r13), %eax
cmpb $0x2, %al
ja 0x31dae
leaq 0x1cf27(%rip), %rsi     # 0x4ecb3
leaq -0x430(%rbp), %rdi
movl $0x51, %edx
callq 0x3100
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x430(%rbp), %rdx
callq *0x58(%r14)
movq 0x68(%r15), %rdi
callq 0x32b74
addb $-0xd, %al
cmpb $0x2, %al
ja 0x31de6
leaq 0x1cf40(%rip), %rsi     # 0x4ed04
leaq -0x430(%rbp), %rdi
movl $0x4e, %edx
callq 0x3100
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x430(%rbp), %rdx
callq *0x58(%r14)
movq %r12, %rdi
callq 0x32b74
movb %al, 0x60(%rbx)
movq %r12, 0x68(%rbx)
cmpb $0x1, 0x70(%r15)
jne 0x3204f
movb $0x1, 0x70(%rbx)
movzbl %r13b, %esi
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x32c3f
jmp 0x3204f
cmpl $0x1, 0x44(%rbx)
jne 0x3213a
movq 0x48(%rbx), %rax
movq (%rax), %r15
movzbl 0x1(%r15), %eax
shll $0x8, %eax
xorl %ecx, %ecx
cmpl $0xe00, %eax            # imm = 0xE00
sete %cl
addl %ecx, %ecx
cmpl $0x400, %eax            # imm = 0x400
movl $0x1, %eax
cmovnel %ecx, %eax
cmpl $0x2, %eax
je 0x31f5a
cmpl $0x1, %eax
jne 0x32197
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x2e6cf
jmp 0x31f69
movq %r14, %rdi
movq %r15, %rsi
callq 0x2e11b
movq 0x68(%r15), %r12
cmpl $0xee0, (%r15)          # imm = 0xEE0
jne 0x31ebc
movq 0x48(%r15), %rax
movq (%rax), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x31ebc
movq 0x10(%rax), %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x6d79
testq %rax, %rax
je 0x31ebc
movslq 0x60(%rax), %rax
jmp 0x31eca
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2dcf8
movl 0x30(%r14), %ecx
cmpl $0x2, %ecx
je 0x31fa2
cmpl $0x1, %ecx
jne 0x321b6
movb $0x8, 0x60(%rbx)
leaq 0x2a5ed(%rip), %rcx     # 0x5c4d8
movq %rcx, 0x68(%rbx)
jmp 0x31f98
movups 0x1cd58(%rip), %xmm0    # 0x4ec53
leaq -0x430(%rbp), %rdx
movups %xmm0, 0x19(%rdx)
movups 0x1cd3d(%rip), %xmm0    # 0x4ec4a
movaps %xmm0, 0x10(%rdx)
movups 0x1cd22(%rip), %xmm0    # 0x4ec3a
movaps %xmm0, (%rdx)
movq %r14, %rdi
movq %rbx, %rsi
callq *0x58(%r14)
movups 0x60(%r12), %xmm0
movups 0x70(%r12), %xmm1
movups 0x80(%r12), %xmm2
movups %xmm2, 0x80(%rbx)
movups %xmm1, 0x70(%rbx)
movups %xmm0, 0x60(%rbx)
cmpb $0x1, 0x70(%r12)
je 0x32041
jmp 0x3204f
movq %r14, %rdi
movq %r15, %rsi
callq 0x2e11b
movq 0x68(%r15), %r15
movl 0x30(%r14), %eax
cmpl $0x2, %eax
je 0x31fb3
cmpl $0x1, %eax
jne 0x321d5
movb $0x8, 0x60(%rbx)
leaq 0x2a552(%rip), %rax     # 0x5c4d8
movq %rax, 0x68(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2adb4
movl %eax, 0x88(%rbx)
movb $0x8, %al
jmp 0x31fd9
movb $0x9, 0x60(%rbx)
leaq 0x2a58b(%rip), %rcx     # 0x5c538
movq %rcx, 0x68(%rbx)
jmp 0x31fd0
movb $0x9, 0x60(%rbx)
leaq 0x2a57a(%rip), %rax     # 0x5c538
movq %rax, 0x68(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2adb4
movq %rax, 0x88(%rbx)
movb $0x9, %al
movb %al, 0x71(%rbx)
movb $0x1, 0x70(%rbx)
jmp 0x3204f
movups 0x1ccb2(%rip), %xmm0    # 0x4ec9b
leaq -0x430(%rbp), %rdx
movaps %xmm0, 0x10(%rdx)
movups 0x1cc90(%rip), %xmm0    # 0x4ec8b
movaps %xmm0, (%rdx)
movabsq $0x2e646e61726570, %rax # imm = 0x2E646E61726570
movq %rax, 0x20(%rdx)
movq %r14, %rdi
movq %rbx, %rsi
callq *0x58(%r14)
leaq 0x60(%r12), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x80(%rbx)
movups %xmm1, 0x70(%rbx)
movups %xmm0, 0x60(%rbx)
cmpb $0x1, 0x70(%r12)
jne 0x3204f
movb $0x1, 0x70(%rbx)
movl %r15d, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x327db
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10ee3(%rip), %rdi     # 0x42f4b
leaq 0x1c101(%rip), %rsi     # 0x4e170
leaq 0x1cb68(%rip), %rcx     # 0x4ebde
movl $0xa08, %edx            # imm = 0xA08
callq 0x30a0
leaq 0x11b5a(%rip), %rdi     # 0x43be1
leaq 0x1c0e2(%rip), %rsi     # 0x4e170
leaq 0x1cb49(%rip), %rcx     # 0x4ebde
movl $0xa2d, %edx            # imm = 0xA2D
callq 0x30a0
leaq 0x11b3b(%rip), %rdi     # 0x43be1
leaq 0x1c0c3(%rip), %rsi     # 0x4e170
leaq 0x1cb2a(%rip), %rcx     # 0x4ebde
movl $0xa0f, %edx            # imm = 0xA0F
callq 0x30a0
leaq 0x10e86(%rip), %rdi     # 0x42f4b
leaq 0x1c0a4(%rip), %rsi     # 0x4e170
leaq 0x1cd86(%rip), %rcx     # 0x4ee59
movl $0x1f7, %edx            # imm = 0x1F7
callq 0x30a0
leaq 0x1cdb2(%rip), %rdi     # 0x4ee96
leaq 0x1c085(%rip), %rsi     # 0x4e170
leaq 0x1cd67(%rip), %rcx     # 0x4ee59
movl $0x1f8, %edx            # imm = 0x1F8
callq 0x30a0
leaq 0x11ade(%rip), %rdi     # 0x43be1
leaq 0x1c066(%rip), %rsi     # 0x4e170
leaq 0x1cacd(%rip), %rcx     # 0x4ebde
movl $0xa77, %edx            # imm = 0xA77
callq 0x30a0
leaq 0x1c4e3(%rip), %rdi     # 0x4e605
leaq 0x1c047(%rip), %rsi     # 0x4e170
leaq 0x1caae(%rip), %rcx     # 0x4ebde
movl $0xab1, %edx            # imm = 0xAB1
callq 0x30a0
leaq 0x11aa0(%rip), %rdi     # 0x43be1
leaq 0x1c028(%rip), %rsi     # 0x4e170
leaq 0x1ca8f(%rip), %rcx     # 0x4ebde
movl $0xa4b, %edx            # imm = 0xA4B
callq 0x30a0
leaq 0xe22d(%rip), %rdi      # 0x4038d
leaq 0x1c009(%rip), %rsi     # 0x4e170
leaq 0x1ca70(%rip), %rcx     # 0x4ebde
movl $0xa87, %edx            # imm = 0xA87
callq 0x30a0
leaq 0xe20e(%rip), %rdi      # 0x4038d
leaq 0x1bfea(%rip), %rsi     # 0x4e170
leaq 0x1ca51(%rip), %rcx     # 0x4ebde
movl $0xa1f, %edx            # imm = 0xA1F
callq 0x30a0
leaq 0xe1ef(%rip), %rdi      # 0x4038d
leaq 0x1bfcb(%rip), %rsi     # 0x4e170
leaq 0x1ca32(%rip), %rcx     # 0x4ebde
movl $0xa5b, %edx            # imm = 0xA5B
callq 0x30a0
leaq 0xe1d0(%rip), %rdi      # 0x4038d
leaq 0x1bfac(%rip), %rsi     # 0x4e170
leaq 0x1ca13(%rip), %rcx     # 0x4ebde
movl $0xaaa, %edx            # imm = 0xAAA
callq 0x30a0
leaq 0xe1b1(%rip), %rdi      # 0x4038d
leaq 0x1bf8d(%rip), %rsi     # 0x4e170
leaq 0x1c9f4(%rip), %rcx     # 0x4ebde
movl $0xa6f, %edx            # imm = 0xA6F
callq 0x30a0
leaq 0xe192(%rip), %rdi      # 0x4038d
leaq 0x1bf6e(%rip), %rsi     # 0x4e170
leaq 0x1c9d5(%rip), %rcx     # 0x4ebde
movl $0xa3d, %edx            # imm = 0xA3D
callq 0x30a0