// File: /workspace/github_c_makefile_star2_O3/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 0x312a6
movq %rsi, %rbx
movq %rdi, %r14
movl (%rsi), %r15d
leal -0xec0(%r15), %eax
cmpl $0x8, %eax
ja 0x30ee3
leaq 0x1ab84(%rip), %rcx     # 0x4b998
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x1, 0x44(%rbx)
jne 0x312e4
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x313fb
movq %r12, %rdi
callq 0x2e4a1
testb %al, %al
jne 0x311cb
cmpl $0xec3, %r15d           # imm = 0xEC3
je 0x3119a
cmpl $0xec0, %r15d           # imm = 0xEC0
jne 0x3137f
movups 0x1bd90(%rip), %xmm0    # 0x4cbfa
leaq -0x430(%rbp), %rdx
movups %xmm0, 0x19(%rdx)
movups 0x1bd75(%rip), %xmm0    # 0x4cbf1
movaps %xmm0, 0x10(%rdx)
movups 0x1bd5a(%rip), %xmm0    # 0x4cbe1
jmp 0x311be
cmpl $0x1, 0x44(%rbx)
jne 0x312c5
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x313fb
movq %r12, %rdi
callq 0x31cec
testb %al, %al
jne 0x310e3
cmpl $0xec1, %r15d           # imm = 0xEC1
jne 0x310af
movups 0x1bd77(%rip), %xmm0    # 0x4cc43
leaq -0x430(%rbp), %rdx
movaps %xmm0, 0x10(%rdx)
movups 0x1bd55(%rip), %xmm0    # 0x4cc33
jmp 0x310c8
movq %r14, %rdi
movq %rbx, %rsi
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x313fb
cmpl $0x1, 0x44(%rbx)
jne 0x31303
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 0x3111c
cmpl $0x1, %eax
jne 0x31360
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x2dc3e
movq %r15, %r12
jmp 0x3112b
cmpl $0x2, 0x44(%rbx)
jne 0x31322
movq 0x48(%rbx), %rax
movq (%rax), %r12
movq 0x8(%rax), %r15
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x2d298
movq %r14, %rdi
movq %r15, %rsi
callq 0x2d6f0
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 0x31d4d
movl %eax, %r13d
leal -0xd(%r13), %eax
cmpb $0x2, %al
ja 0x30fe7
leaq 0x1bcbe(%rip), %rsi     # 0x4cc83
leaq -0x430(%rbp), %rdi
movl $0x51, %edx
callq 0x3110
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x430(%rbp), %rdx
callq *0x58(%r14)
movq 0x68(%r15), %rdi
callq 0x31d4d
addb $-0xd, %al
cmpb $0x2, %al
ja 0x3101f
leaq 0x1bcd7(%rip), %rsi     # 0x4ccd4
leaq -0x430(%rbp), %rdi
movl $0x4e, %edx
callq 0x3110
movq %r14, %rdi
movq %rbx, %rsi
leaq -0x430(%rbp), %rdx
callq *0x58(%r14)
movq %r12, %rdi
callq 0x31d4d
movb %al, 0x60(%rbx)
movq %r12, 0x68(%rbx)
cmpb $0x1, 0x70(%r15)
jne 0x31294
movb $0x1, 0x70(%rbx)
movzbl %r13b, %esi
movq %r14, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x31e18
jmp 0x31294
cmpl $0x1, 0x44(%rbx)
jne 0x31341
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 0x3120e
cmpl $0x1, %eax
jne 0x3139e
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x2dc3e
jmp 0x3121d
movups 0x1bbb5(%rip), %xmm0    # 0x4cc6b
leaq -0x430(%rbp), %rdx
movaps %xmm0, 0x10(%rdx)
movups 0x1bb93(%rip), %xmm0    # 0x4cc5b
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 0x31294
movb $0x1, 0x70(%rbx)
jmp 0x311fb
movq %r14, %rdi
movq %r15, %rsi
callq 0x2d6f0
movq 0x68(%r15), %r12
cmpl $0xee0, (%r15)          # imm = 0xEE0
jne 0x31162
movq 0x48(%r15), %rax
movq (%rax), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x31162
movq 0x10(%rax), %rcx
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x6c49
testq %rax, %rax
je 0x31162
movslq 0x60(%rax), %rax
jmp 0x31170
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2d2ca
movl 0x30(%r14), %ecx
cmpl $0x2, %ecx
je 0x31256
cmpl $0x1, %ecx
jne 0x313bd
movb $0x8, 0x60(%rbx)
leaq 0x29347(%rip), %rcx     # 0x5a4d8
movq %rcx, 0x68(%rbx)
jmp 0x3124c
movups 0x1ba82(%rip), %xmm0    # 0x4cc23
leaq -0x430(%rbp), %rdx
movups %xmm0, 0x19(%rdx)
movups 0x1ba67(%rip), %xmm0    # 0x4cc1a
movaps %xmm0, 0x10(%rdx)
movups 0x1ba4c(%rip), %xmm0    # 0x4cc0a
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 0x31294
movl %r15d, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x31953
jmp 0x31294
movq %r14, %rdi
movq %r15, %rsi
callq 0x2d6f0
movq 0x68(%r15), %r15
movl 0x30(%r14), %eax
cmpl $0x2, %eax
je 0x31267
cmpl $0x1, %eax
jne 0x313dc
movb $0x8, 0x60(%rbx)
leaq 0x2929e(%rip), %rax     # 0x5a4d8
movq %rax, 0x68(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2a3da
movl %eax, 0x88(%rbx)
movb $0x8, %al
jmp 0x3128d
movb $0x9, 0x60(%rbx)
leaq 0x292d7(%rip), %rcx     # 0x5a538
movq %rcx, 0x68(%rbx)
jmp 0x31284
movb $0x9, 0x60(%rbx)
leaq 0x292c6(%rip), %rax     # 0x5a538
movq %rax, 0x68(%rbx)
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2a3da
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 0xfc5e(%rip), %rdi      # 0x40f0b
leaq 0x1ae8c(%rip), %rsi     # 0x4c140
leaq 0x1b8f3(%rip), %rcx     # 0x4cbae
movl $0xa08, %edx            # imm = 0xA08
callq 0x30a0
leaq 0x108d5(%rip), %rdi     # 0x41ba1
leaq 0x1ae6d(%rip), %rsi     # 0x4c140
leaq 0x1b8d4(%rip), %rcx     # 0x4cbae
movl $0xa2d, %edx            # imm = 0xA2D
callq 0x30a0
leaq 0x108b6(%rip), %rdi     # 0x41ba1
leaq 0x1ae4e(%rip), %rsi     # 0x4c140
leaq 0x1b8b5(%rip), %rcx     # 0x4cbae
movl $0xa0f, %edx            # imm = 0xA0F
callq 0x30a0
leaq 0x10897(%rip), %rdi     # 0x41ba1
leaq 0x1ae2f(%rip), %rsi     # 0x4c140
leaq 0x1b896(%rip), %rcx     # 0x4cbae
movl $0xa77, %edx            # imm = 0xA77
callq 0x30a0
leaq 0x1b2ac(%rip), %rdi     # 0x4c5d5
leaq 0x1ae10(%rip), %rsi     # 0x4c140
leaq 0x1b877(%rip), %rcx     # 0x4cbae
movl $0xab1, %edx            # imm = 0xAB1
callq 0x30a0
leaq 0x10859(%rip), %rdi     # 0x41ba1
leaq 0x1adf1(%rip), %rsi     # 0x4c140
leaq 0x1b858(%rip), %rcx     # 0x4cbae
movl $0xa4b, %edx            # imm = 0xA4B
callq 0x30a0
leaq 0xd002(%rip), %rdi      # 0x3e369
leaq 0x1add2(%rip), %rsi     # 0x4c140
leaq 0x1b839(%rip), %rcx     # 0x4cbae
movl $0xa87, %edx            # imm = 0xA87
callq 0x30a0
leaq 0xcfe3(%rip), %rdi      # 0x3e369
leaq 0x1adb3(%rip), %rsi     # 0x4c140
leaq 0x1b81a(%rip), %rcx     # 0x4cbae
movl $0xa1f, %edx            # imm = 0xA1F
callq 0x30a0
leaq 0xcfc4(%rip), %rdi      # 0x3e369
leaq 0x1ad94(%rip), %rsi     # 0x4c140
leaq 0x1b7fb(%rip), %rcx     # 0x4cbae
movl $0xa5b, %edx            # imm = 0xA5B
callq 0x30a0
leaq 0xcfa5(%rip), %rdi      # 0x3e369
leaq 0x1ad75(%rip), %rsi     # 0x4c140
leaq 0x1b7dc(%rip), %rcx     # 0x4cbae
movl $0xaaa, %edx            # imm = 0xAAA
callq 0x30a0
leaq 0xcf86(%rip), %rdi      # 0x3e369
leaq 0x1ad56(%rip), %rsi     # 0x4c140
leaq 0x1b7bd(%rip), %rcx     # 0x4cbae
movl $0xa6f, %edx            # imm = 0xA6F
callq 0x30a0