// File: /workspace/github_c_makefile_star2_O2/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 0x2e719
movq %rsi, %rbx
movq %rdi, %r14
movl (%rsi), %r15d
leal -0xec0(%r15), %eax
cmpl $0x8, %eax
ja 0x2e36a
leaq 0x1a72d(%rip), %rcx     # 0x489c8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, 0x44(%rbx)
jne 0x2e757
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x2e86e
movq %r12, %rdi
callq 0x2ba25
testb %al, %al
jne 0x2e63e
cmpl $0xec3, %r15d           # imm = 0xEC3
je 0x2e60d
cmpl $0xec0, %r15d           # imm = 0xEC0
jne 0x2e7f2
movups 0x1b939(%rip), %xmm0    # 0x49c2a
leaq -0x430(%rbp), %rdx
movups %xmm0, 0x19(%rdx)
movups 0x1b91e(%rip), %xmm0    # 0x49c21
movaps %xmm0, 0x10(%rdx)
movups 0x1b903(%rip), %xmm0    # 0x49c11
jmp 0x2e631
cmpl $0x1, 0x44(%rbx)
jne 0x2e738
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x2e86e
movq %r12, %rdi
callq 0x2f15c
testb %al, %al
jne 0x2e558
cmpl $0xec1, %r15d           # imm = 0xEC1
jne 0x2e524
movups 0x1b920(%rip), %xmm0    # 0x49c73
leaq -0x430(%rbp), %rdx
movaps %xmm0, 0x10(%rdx)
movups 0x1b8fe(%rip), %xmm0    # 0x49c63
jmp 0x2e53d
movq %r14, %rdi
movq %rbx, %rsi
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2e86e
cmpl $0x1, 0x44(%rbx)
jne 0x2e776
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
pushq $0x1
popq %rax
cmovnel %ecx, %eax
cmpl $0x2, %eax
je 0x2e591
cmpl $0x1, %eax
jne 0x2e7d3
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2a8eb
movq %r15, %r12
jmp 0x2e5a0
cmpl $0x2, 0x44(%rbx)
jne 0x2e795
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq 0x8(%rax), %r15
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2a8eb
movq %r14, %rdi
movq %r15, %rsi
callq 0x2acf8
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 0x2f1bd
movl %eax, %r13d
leal -0xd(%r13), %eax
cmpb $0x2, %al
ja 0x2e465
leaq 0x1b86e(%rip), %rsi     # 0x49cb3
leaq -0x430(%rbp), %rdi
pushq $0x51
popq %rdx
callq 0x3100
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x430(%rbp), %rdx
callq *0x58(%r14)
movq 0x68(%r15), %rdi
callq 0x2f1bd
addb $-0xd, %al
cmpb $0x2, %al
ja 0x2e49b
leaq 0x1b889(%rip), %rsi     # 0x49d04
leaq -0x430(%rbp), %rdi
pushq $0x4e
popq %rdx
callq 0x3100
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x430(%rbp), %rdx
callq *0x58(%r14)
movq %r12, %rdi
callq 0x2f1bd
movb %al, 0x60(%rbx)
movq %r12, 0x68(%rbx)
cmpb $0x1, 0x70(%r15)
jne 0x2e707
movb $0x1, 0x70(%rbx)
movzbl %r13b, %esi
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x2f27a
jmp 0x2e707
cmpl $0x1, 0x44(%rbx)
jne 0x2e7b4
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
pushq $0x1
popq %rax
cmovnel %ecx, %eax
cmpl $0x2, %eax
je 0x2e681
cmpl $0x1, %eax
jne 0x2e811
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x2a8eb
jmp 0x2e690
movups 0x1b770(%rip), %xmm0    # 0x49c9b
leaq -0x430(%rbp), %rdx
movaps %xmm0, 0x10(%rdx)
movups 0x1b74e(%rip), %xmm0    # 0x49c8b
movaps %xmm0, (%rdx)
movabsq $0x2e646e61726570, %rax # imm = 0x2E646E61726570
movq %rax, 0x20(%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)
jne 0x2e707
movb $0x1, 0x70(%rbx)
jmp 0x2e66e
movq %r14, %rdi
movq %r15, %rsi
callq 0x2acf8
movq 0x68(%r15), %r12
cmpl $0xee0, (%r15)          # imm = 0xEE0
jne 0x2e5d5
movq 0x48(%r15), %rax
movq (%rax), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x2e5d5
movq 0x10(%rax), %rcx
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6779
testq %rax, %rax
je 0x2e5d5
movslq 0x60(%rax), %rax
jmp 0x2e5e3
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2a91b
movl 0x30(%r14), %ecx
cmpl $0x2, %ecx
je 0x2e6c9
cmpl $0x1, %ecx
jne 0x2e830
movb $0x8, 0x60(%rbx)
leaq 0x28ed4(%rip), %rcx     # 0x574d8
movq %rcx, 0x68(%rbx)
jmp 0x2e6bf
movups 0x1b63f(%rip), %xmm0    # 0x49c53
leaq -0x430(%rbp), %rdx
movups %xmm0, 0x19(%rdx)
movups 0x1b624(%rip), %xmm0    # 0x49c4a
movaps %xmm0, 0x10(%rdx)
movups 0x1b609(%rip), %xmm0    # 0x49c3a
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)
jne 0x2e707
movl %r15d, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2edc3
jmp 0x2e707
movq %r14, %rdi
movq %r15, %rsi
callq 0x2acf8
movq 0x68(%r15), %r15
movl 0x30(%r14), %eax
cmpl $0x2, %eax
je 0x2e6da
cmpl $0x1, %eax
jne 0x2e84f
movb $0x8, 0x60(%rbx)
leaq 0x28e2b(%rip), %rax     # 0x574d8
movq %rax, 0x68(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x27acb
movl %eax, 0x88(%rbx)
movb $0x8, %al
jmp 0x2e700
movb $0x9, 0x60(%rbx)
leaq 0x28e64(%rip), %rcx     # 0x57538
movq %rcx, 0x68(%rbx)
jmp 0x2e6f7
movb $0x9, 0x60(%rbx)
leaq 0x28e53(%rip), %rax     # 0x57538
movq %rax, 0x68(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x27acb
movq %rax, 0x88(%rbx)
movb $0x9, %al
movb %al, 0x71(%rbx)
movb $0x1, 0x70(%rbx)
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf7ea(%rip), %rdi      # 0x3df0a
leaq 0x1aa49(%rip), %rsi     # 0x49170
leaq 0x1b4b0(%rip), %rcx     # 0x49bde
movl $0xa08, %edx            # imm = 0xA08
callq 0x30a0
leaq 0x10494(%rip), %rdi     # 0x3ebd3
leaq 0x1aa2a(%rip), %rsi     # 0x49170
leaq 0x1b491(%rip), %rcx     # 0x49bde
movl $0xa2d, %edx            # imm = 0xA2D
callq 0x30a0
leaq 0x10475(%rip), %rdi     # 0x3ebd3
leaq 0x1aa0b(%rip), %rsi     # 0x49170
leaq 0x1b472(%rip), %rcx     # 0x49bde
movl $0xa0f, %edx            # imm = 0xA0F
callq 0x30a0
leaq 0x10456(%rip), %rdi     # 0x3ebd3
leaq 0x1a9ec(%rip), %rsi     # 0x49170
leaq 0x1b453(%rip), %rcx     # 0x49bde
movl $0xa77, %edx            # imm = 0xA77
callq 0x30a0
leaq 0x1ae69(%rip), %rdi     # 0x49605
leaq 0x1a9cd(%rip), %rsi     # 0x49170
leaq 0x1b434(%rip), %rcx     # 0x49bde
movl $0xab1, %edx            # imm = 0xAB1
callq 0x30a0
leaq 0x10418(%rip), %rdi     # 0x3ebd3
leaq 0x1a9ae(%rip), %rsi     # 0x49170
leaq 0x1b415(%rip), %rcx     # 0x49bde
movl $0xa4b, %edx            # imm = 0xA4B
callq 0x30a0
leaq 0xcb8f(%rip), %rdi      # 0x3b369
leaq 0x1a98f(%rip), %rsi     # 0x49170
leaq 0x1b3f6(%rip), %rcx     # 0x49bde
movl $0xa87, %edx            # imm = 0xA87
callq 0x30a0
leaq 0xcb70(%rip), %rdi      # 0x3b369
leaq 0x1a970(%rip), %rsi     # 0x49170
leaq 0x1b3d7(%rip), %rcx     # 0x49bde
movl $0xa1f, %edx            # imm = 0xA1F
callq 0x30a0
leaq 0xcb51(%rip), %rdi      # 0x3b369
leaq 0x1a951(%rip), %rsi     # 0x49170
leaq 0x1b3b8(%rip), %rcx     # 0x49bde
movl $0xa5b, %edx            # imm = 0xA5B
callq 0x30a0
leaq 0xcb32(%rip), %rdi      # 0x3b369
leaq 0x1a932(%rip), %rsi     # 0x49170
leaq 0x1b399(%rip), %rcx     # 0x49bde
movl $0xaaa, %edx            # imm = 0xAAA
callq 0x30a0
leaq 0xcb13(%rip), %rdi      # 0x3b369
leaq 0x1a913(%rip), %rsi     # 0x49170
leaq 0x1b37a(%rip), %rcx     # 0x49bde
movl $0xa6f, %edx            # imm = 0xA6F
callq 0x30a0