// File: /workspace/github_c_makefile_star2_O3/Ihsoh[P]ilang/compiler/backend/semantics.c
// Function: calc_type_size
static size_t _calc_type_size(
	ParserContext *ctx,
	ParserASTNode *node,
	ParserASTNode *node_type
) {
	assert(ctx);
	assert(node);
	assert(node_type);

	switch (node_type->type) {
		case BE_NODE_TYPE_CHAR: {
			return 1;
		}
		case BE_NODE_TYPE_INT8: {
			return 1;
		}
		case BE_NODE_TYPE_INT16: {
			return 2;
		}
		case BE_NODE_TYPE_INT32: {
			return 4;
		}
		case BE_NODE_TYPE_INT64: {
			return 8;
		}
		case BE_NODE_TYPE_UINT8: {
			return 1;
		}
		case BE_NODE_TYPE_UINT16: {
			return 2;
		}
		case BE_NODE_TYPE_UINT32: {
			return 4;
		}
		case BE_NODE_TYPE_UINT64: {
			return 8;
		}
		case BE_NODE_TYPE_FLOAT: {
			return 4;
		}
		case BE_NODE_TYPE_DOUBLE: {
			return 8;
		}
		case BE_NODE_TYPE_VA_LIST: {
			return 8;
		}
		case BE_NODE_TYPE_STRUCT: {
			return _calc_struct_type_size(ctx, node, node_type);
		}
		case BE_NODE_TYPE_ARRAY: {
			assert(node_type->nchilds == 2);

			ParserASTNode *node_array_dims = node_type->childs[0];
			assert(node_array_dims);
			assert(node_array_dims->type == BE_NODE_TYPE_ARRAY_DIMS);

			ParserASTNode *node_array_type = node_type->childs[1];
			assert(node_array_type);

			size_t size = _calc_type_size(ctx, node, node_array_type);
			for (int i = 0; i < node_array_dims->nchilds; i++) {
				ParserASTNode *node_array_dim = node_array_dims->childs[i];
				assert(node_array_dim);

				size *= be_parser_get_uint_val(ctx, node_array_dim);
			}

			return size;
		}
		case BE_NODE_TYPE_FUNC: {
			return 0;
		}
		case BE_NODE_TYPE_POINTER: {
			if (ctx->arch == BE_ARCH_32) {
				return 4;
			} else if (ctx->arch == BE_ARCH_64) {
				return 8;
			} else {
				assert(0);
				return 0;
			}
		}
		case BE_NODE_TYPE_VOID: {
			return 1;
		}
		default: {
			assert(0);
			return 0;
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, -0x38(%rbp)
movq %rdi, -0x30(%rbp)
testq %rdx, %rdx
je 0x2a7c3
movl (%rdx), %eax
movl $0x1, %r14d
cmpl $0x42f, %eax            # imm = 0x42F
jg 0x2a430
addl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x20, %eax
ja 0x2a451
leaq 0x2116c(%rip), %rcx     # 0x4b588
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x8, %r14d
jmp 0x2a6f7
cmpl $0x430, %eax            # imm = 0x430
je 0x2a6cd
cmpl $0x440, %eax            # imm = 0x440
je 0x2a693
cmpl $0x4ff, %eax            # imm = 0x4FF
je 0x2a6f7
leaq 0x13f11(%rip), %rdi     # 0x3e369
leaq 0x21ce1(%rip), %rsi     # 0x4c140
leaq 0x24a4c(%rip), %rcx     # 0x4eeb2
movl $0x538, %edx            # imm = 0x538
callq 0x30a0
movl $0x4, %r14d
jmp 0x2a6f7
movl $0x2, %r14d
jmp 0x2a6f7
cmpl $0x2, 0x44(%rdx)
jne 0x2a7e2
movq 0x48(%rdx), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x2a820
cmpl $0x421, (%rbx)          # imm = 0x421
jne 0x2a85e
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x2a89c
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2a3da
movq %rax, %r14
cmpl $0x0, 0x44(%rbx)
jle 0x2a6f7
xorl %r15d, %r15d
movq 0x48(%rbx), %rax
movq (%rax,%r15,8), %rsi
testq %rsi, %rsi
je 0x2a766
movq -0x30(%rbp), %rdi
callq 0x22d3f
imulq %rax, %r14
incq %r15
movslq 0x44(%rbx), %rax
cmpq %rax, %r15
jl 0x2a4d6
jmp 0x2a6f7
cmpl $0x1, 0x44(%rdx)
jne 0x2a801
movq 0x48(%rdx), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x2a83f
cmpl $0x200, (%r14)          # imm = 0x200
jne 0x2a87d
movq 0x10(%r14), %rcx
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x2, %edx
callq 0x6c49
movq %rax, %rbx
testq %rax, %rax
jne 0x2a55c
movq 0x10(%r14), %rsi
leaq 0x21fc0(%rip), %rdx     # 0x4c515
movq -0x30(%rbp), %rdi
callq *0x50(%rdi)
movq 0x30(%rbx), %rcx
testq %rcx, %rcx
je 0x2a8bb
cmpl $0xd00, (%rcx)          # imm = 0xD00
jne 0x2a8da
movq 0x38(%rbx), %rdx
testq %rdx, %rdx
je 0x2a8f9
cmpl $0xd01, (%rdx)          # imm = 0xD01
jne 0x2a918
movl 0x44(%rdx), %eax
testl %eax, %eax
jle 0x2a6d2
movq %rcx, -0x58(%rbp)
movl $0x1, %ecx
movq %rcx, -0x40(%rbp)
xorl %esi, %esi
xorl %r12d, %r12d
movq %rdx, -0x48(%rbp)
movq 0x48(%rdx), %rcx
movq (%rcx,%rsi,8), %r14
testq %r14, %r14
je 0x2a785
cmpl $0xc00, (%r14)          # imm = 0xC00
jne 0x2a7a4
cmpl $0x0, 0x44(%r14)
jle 0x2a682
movq %rsi, -0x50(%rbp)
xorl %r15d, %r15d
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rax
testq %rax, %rax
je 0x2a728
cmpl $0xc01, (%rax)          # imm = 0xC01
jne 0x2a747
cmpl $0x1, 0x44(%rax)
jle 0x2a709
movq 0x48(%rax), %rax
movq 0x8(%rax), %r13
movl $0x1, %ebx
movq -0x58(%rbp), %rax
cmpb $0x0, 0x68(%rax)
jne 0x2a630
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x2d2ca
movq %rax, %rbx
movq -0x40(%rbp), %rax
cmpq %rax, %rbx
cmovaq %rbx, %rax
movq %rax, -0x40(%rbp)
movq %r12, %rax
xorl %edx, %edx
divq %rbx
subq %rdx, %rbx
testq %rdx, %rdx
cmoveq %rdx, %rbx
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x2a3da
addq %rbx, %r12
addq %rax, %r12
incq %r15
movslq 0x44(%r14), %rax
cmpq %rax, %r15
jl 0x2a5df
movq -0x48(%rbp), %rdx
movl 0x44(%rdx), %eax
movq -0x50(%rbp), %rsi
incq %rsi
movslq %eax, %rcx
cmpq %rcx, %rsi
jl 0x2a5af
jmp 0x2a6de
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x4, %r14d
cmpl $0x1, %eax
je 0x2a6f7
cmpl $0x2, %eax
je 0x2a425
leaq 0x13cb4(%rip), %rdi     # 0x3e369
leaq 0x21a84(%rip), %rsi     # 0x4c140
leaq 0x247ef(%rip), %rcx     # 0x4eeb2
movl $0x530, %edx            # imm = 0x530
callq 0x30a0
xorl %r14d, %r14d
jmp 0x2a6f7
movl $0x1, %eax
movq %rax, -0x40(%rbp)
xorl %r12d, %r12d
movq %r12, %rax
xorl %edx, %edx
movq -0x40(%rbp), %r14
divq %r14
subq %rdx, %r14
testq %rdx, %rdx
cmoveq %rdx, %r14
addq %r12, %r14
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x220b8(%rip), %rdi     # 0x4c7c8
leaq 0x21a29(%rip), %rsi     # 0x4c140
leaq 0x247fd(%rip), %rcx     # 0x4ef1b
movl $0x4c5, %edx            # imm = 0x4C5
callq 0x30a0
leaq 0x22063(%rip), %rdi     # 0x4c792
leaq 0x21a0a(%rip), %rsi     # 0x4c140
leaq 0x247de(%rip), %rcx     # 0x4ef1b
movl $0x4c3, %edx            # imm = 0x4C3
callq 0x30a0
leaq 0x22052(%rip), %rdi     # 0x4c7a0
leaq 0x219eb(%rip), %rsi     # 0x4c140
leaq 0x247bf(%rip), %rcx     # 0x4ef1b
movl $0x4c4, %edx            # imm = 0x4C4
callq 0x30a0
leaq 0x2479f(%rip), %rdi     # 0x4ef0c
leaq 0x219cc(%rip), %rsi     # 0x4c140
leaq 0x24737(%rip), %rcx     # 0x4eeb2
movl $0x520, %edx            # imm = 0x520
callq 0x30a0
leaq 0x21fc1(%rip), %rdi     # 0x4c74d
leaq 0x219ad(%rip), %rsi     # 0x4c140
leaq 0x24781(%rip), %rcx     # 0x4ef1b
movl $0x4bf, %edx            # imm = 0x4BF
callq 0x30a0
leaq 0x21fba(%rip), %rdi     # 0x4c765
leaq 0x2198e(%rip), %rsi     # 0x4c140
leaq 0x24762(%rip), %rcx     # 0x4ef1b
movl $0x4c0, %edx            # imm = 0x4C0
callq 0x30a0
leaq 0x23fef(%rip), %rdi     # 0x4e7b9
leaq 0x2196f(%rip), %rsi     # 0x4c140
leaq 0x246da(%rip), %rcx     # 0x4eeb2
movl $0x4e9, %edx            # imm = 0x4E9
callq 0x30a0
leaq 0x21e63(%rip), %rdi     # 0x4c64c
leaq 0x21950(%rip), %rsi     # 0x4c140
leaq 0x246bb(%rip), %rcx     # 0x4eeb2
movl $0x514, %edx            # imm = 0x514
callq 0x30a0
leaq 0x21ebe(%rip), %rdi     # 0x4c6c6
leaq 0x21931(%rip), %rsi     # 0x4c140
leaq 0x24705(%rip), %rcx     # 0x4ef1b
movl $0x4a7, %edx            # imm = 0x4A7
callq 0x30a0
leaq 0x246d5(%rip), %rdi     # 0x4eefc
leaq 0x21912(%rip), %rsi     # 0x4c140
leaq 0x2467d(%rip), %rcx     # 0x4eeb2
movl $0x517, %edx            # imm = 0x517
callq 0x30a0
leaq 0x16fd0(%rip), %rdi     # 0x41816
leaq 0x218f3(%rip), %rsi     # 0x4c140
leaq 0x246c7(%rip), %rcx     # 0x4ef1b
movl $0x4aa, %edx            # imm = 0x4AA
callq 0x30a0
leaq 0x21cda(%rip), %rdi     # 0x4c53f
leaq 0x218d4(%rip), %rsi     # 0x4c140
leaq 0x2463f(%rip), %rcx     # 0x4eeb2
movl $0x518, %edx            # imm = 0x518
callq 0x30a0
leaq 0x16f10(%rip), %rdi     # 0x41794
leaq 0x218b5(%rip), %rsi     # 0x4c140
leaq 0x24689(%rip), %rcx     # 0x4ef1b
movl $0x4ab, %edx            # imm = 0x4AB
callq 0x30a0
leaq 0x21dc1(%rip), %rdi     # 0x4c664
leaq 0x21896(%rip), %rsi     # 0x4c140
leaq 0x24601(%rip), %rcx     # 0x4eeb2
movl $0x51b, %edx            # imm = 0x51B
callq 0x30a0
leaq 0x21e1c(%rip), %rdi     # 0x4c6de
leaq 0x21877(%rip), %rsi     # 0x4c140
leaq 0x2464b(%rip), %rcx     # 0x4ef1b
movl $0x4b3, %edx            # imm = 0x4B3
callq 0x30a0
leaq 0x21e09(%rip), %rdi     # 0x4c6ea
leaq 0x21858(%rip), %rsi     # 0x4c140
leaq 0x2462c(%rip), %rcx     # 0x4ef1b
movl $0x4b4, %edx            # imm = 0x4B4
callq 0x30a0
leaq 0x21e0e(%rip), %rdi     # 0x4c70e
leaq 0x21839(%rip), %rsi     # 0x4c140
leaq 0x2460d(%rip), %rcx     # 0x4ef1b
movl $0x4b7, %edx            # imm = 0x4B7
callq 0x30a0
leaq 0x21e00(%rip), %rdi     # 0x4c71f
leaq 0x2181a(%rip), %rsi     # 0x4c140
leaq 0x245ee(%rip), %rcx     # 0x4ef1b
movl $0x4b8, %edx            # imm = 0x4B8
callq 0x30a0