// File: /workspace/github_c_makefile_star2_O1/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 0x2b1a6
movl (%rdx), %eax
movl $0x1, %r14d
cmpl $0x42f, %eax            # imm = 0x42F
jg 0x2ae0a
addl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x20, %eax
ja 0x2ae2b
leaq 0x227c2(%rip), %rcx     # 0x4d5b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x8, %r14d
jmp 0x2b0da
cmpl $0x430, %eax            # imm = 0x430
je 0x2b0b0
cmpl $0x440, %eax            # imm = 0x440
je 0x2b076
cmpl $0x4ff, %eax            # imm = 0x4FF
je 0x2b0da
leaq 0x1555b(%rip), %rdi     # 0x4038d
leaq 0x23337(%rip), %rsi     # 0x4e170
leaq 0x26118(%rip), %rcx     # 0x50f58
movl $0x538, %edx            # imm = 0x538
callq 0x30a0
movl $0x4, %r14d
jmp 0x2b0da
movl $0x2, %r14d
jmp 0x2b0da
cmpl $0x2, 0x44(%rdx)
jne 0x2b1c5
movq 0x48(%rdx), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x2b203
cmpl $0x421, (%rbx)          # imm = 0x421
jne 0x2b241
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x2b27f
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x2adb4
movq %rax, %r14
cmpl $0x0, 0x44(%rbx)
jle 0x2b0da
xorl %r15d, %r15d
movq 0x48(%rbx), %rax
movq (%rax,%r15,8), %rsi
testq %rsi, %rsi
je 0x2b149
movq -0x30(%rbp), %rdi
callq 0x2312b
imulq %rax, %r14
incq %r15
movslq 0x44(%rbx), %rax
cmpq %rax, %r15
jl 0x2aeb0
jmp 0x2b0da
cmpl $0x1, 0x44(%rdx)
jne 0x2b1e4
movq 0x48(%rdx), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x2b222
cmpl $0x200, (%r14)          # imm = 0x200
jne 0x2b260
movq 0x10(%r14), %rcx
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x2, %edx
callq 0x6d79
movq %rax, %rbx
testq %rax, %rax
jne 0x2af36
movq 0x10(%r14), %rsi
leaq 0x23616(%rip), %rdx     # 0x4e545
movq -0x30(%rbp), %rdi
callq *0x50(%rdi)
movq 0x30(%rbx), %rax
testq %rax, %rax
je 0x2b29e
cmpl $0xd00, (%rax)          # imm = 0xD00
jne 0x2b2bd
movq 0x38(%rbx), %rcx
testq %rcx, %rcx
je 0x2b2dc
cmpl $0xd01, (%rcx)          # imm = 0xD01
jne 0x2b2fb
cmpl $0x0, 0x44(%rcx)
jle 0x2b0b5
movq %rax, -0x58(%rbp)
movl $0x1, %eax
movq %rax, -0x40(%rbp)
xorl %edx, %edx
xorl %r12d, %r12d
movq %rcx, -0x48(%rbp)
movq 0x48(%rcx), %rax
movq (%rax,%rdx,8), %r14
testq %r14, %r14
je 0x2b168
cmpl $0xc00, (%r14)          # imm = 0xC00
jne 0x2b187
movq %rdx, -0x50(%rbp)
cmpl $0x0, 0x44(%r14)
jle 0x2b056
xorl %r15d, %r15d
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rax
testq %rax, %rax
je 0x2b10b
cmpl $0xc01, (%rax)          # imm = 0xC01
jne 0x2b12a
cmpl $0x1, 0x44(%rax)
jle 0x2b0ec
movq 0x48(%rax), %rax
movq 0x8(%rax), %rbx
movl $0x1, %r13d
movq -0x58(%rbp), %rax
cmpb $0x0, 0x68(%rax)
jne 0x2b00a
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq 0x2dcf8
movq %rax, %r13
movq -0x40(%rbp), %rax
cmpq %rax, %r13
cmovaq %r13, %rax
movq %rax, -0x40(%rbp)
movq %r12, %rax
xorl %edx, %edx
divq %r13
subq %rdx, %r13
testq %rdx, %rdx
cmoveq %rdx, %r13
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq 0x2adb4
addq %r12, %r13
addq %rax, %r13
incq %r15
movslq 0x44(%r14), %rax
movq %r13, %r12
cmpq %rax, %r15
jl 0x2afb8
jmp 0x2b059
movq %r12, %r13
movq -0x50(%rbp), %rdx
incq %rdx
movq -0x48(%rbp), %rcx
movslq 0x44(%rcx), %rax
movq %r13, %r12
cmpq %rax, %rdx
jl 0x2af88
jmp 0x2b0c1
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x4, %r14d
cmpl $0x1, %eax
je 0x2b0da
cmpl $0x2, %eax
je 0x2adff
leaq 0x152f5(%rip), %rdi     # 0x4038d
leaq 0x230d1(%rip), %rsi     # 0x4e170
leaq 0x25eb2(%rip), %rcx     # 0x50f58
movl $0x530, %edx            # imm = 0x530
callq 0x30a0
xorl %r14d, %r14d
jmp 0x2b0da
movl $0x1, %eax
movq %rax, -0x40(%rbp)
xorl %r13d, %r13d
movq %r13, %rax
xorl %edx, %edx
movq -0x40(%rbp), %r14
divq %r14
subq %rdx, %r14
testq %rdx, %rdx
cmoveq %rdx, %r14
addq %r13, %r14
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23705(%rip), %rdi     # 0x4e7f8
leaq 0x23076(%rip), %rsi     # 0x4e170
leaq 0x25ec0(%rip), %rcx     # 0x50fc1
movl $0x4c5, %edx            # imm = 0x4C5
callq 0x30a0
leaq 0x236b0(%rip), %rdi     # 0x4e7c2
leaq 0x23057(%rip), %rsi     # 0x4e170
leaq 0x25ea1(%rip), %rcx     # 0x50fc1
movl $0x4c3, %edx            # imm = 0x4C3
callq 0x30a0
leaq 0x2369f(%rip), %rdi     # 0x4e7d0
leaq 0x23038(%rip), %rsi     # 0x4e170
leaq 0x25e82(%rip), %rcx     # 0x50fc1
movl $0x4c4, %edx            # imm = 0x4C4
callq 0x30a0
leaq 0x25e62(%rip), %rdi     # 0x50fb2
leaq 0x23019(%rip), %rsi     # 0x4e170
leaq 0x25dfa(%rip), %rcx     # 0x50f58
movl $0x520, %edx            # imm = 0x520
callq 0x30a0
leaq 0x2360e(%rip), %rdi     # 0x4e77d
leaq 0x22ffa(%rip), %rsi     # 0x4e170
leaq 0x25e44(%rip), %rcx     # 0x50fc1
movl $0x4bf, %edx            # imm = 0x4BF
callq 0x30a0
leaq 0x23607(%rip), %rdi     # 0x4e795
leaq 0x22fdb(%rip), %rsi     # 0x4e170
leaq 0x25e25(%rip), %rcx     # 0x50fc1
movl $0x4c0, %edx            # imm = 0x4C0
callq 0x30a0
leaq 0x25693(%rip), %rdi     # 0x50840
leaq 0x22fbc(%rip), %rsi     # 0x4e170
leaq 0x25d9d(%rip), %rcx     # 0x50f58
movl $0x4e9, %edx            # imm = 0x4E9
callq 0x30a0
leaq 0x234b0(%rip), %rdi     # 0x4e67c
leaq 0x22f9d(%rip), %rsi     # 0x4e170
leaq 0x25d7e(%rip), %rcx     # 0x50f58
movl $0x514, %edx            # imm = 0x514
callq 0x30a0
leaq 0x2350b(%rip), %rdi     # 0x4e6f6
leaq 0x22f7e(%rip), %rsi     # 0x4e170
leaq 0x25dc8(%rip), %rcx     # 0x50fc1
movl $0x4a7, %edx            # imm = 0x4A7
callq 0x30a0
leaq 0x25d98(%rip), %rdi     # 0x50fa2
leaq 0x22f5f(%rip), %rsi     # 0x4e170
leaq 0x25d40(%rip), %rcx     # 0x50f58
movl $0x517, %edx            # imm = 0x517
callq 0x30a0
leaq 0x1862d(%rip), %rdi     # 0x43856
leaq 0x22f40(%rip), %rsi     # 0x4e170
leaq 0x25d8a(%rip), %rcx     # 0x50fc1
movl $0x4aa, %edx            # imm = 0x4AA
callq 0x30a0
leaq 0x23327(%rip), %rdi     # 0x4e56f
leaq 0x22f21(%rip), %rsi     # 0x4e170
leaq 0x25d02(%rip), %rcx     # 0x50f58
movl $0x518, %edx            # imm = 0x518
callq 0x30a0
leaq 0x1856d(%rip), %rdi     # 0x437d4
leaq 0x22f02(%rip), %rsi     # 0x4e170
leaq 0x25d4c(%rip), %rcx     # 0x50fc1
movl $0x4ab, %edx            # imm = 0x4AB
callq 0x30a0
leaq 0x2340e(%rip), %rdi     # 0x4e694
leaq 0x22ee3(%rip), %rsi     # 0x4e170
leaq 0x25cc4(%rip), %rcx     # 0x50f58
movl $0x51b, %edx            # imm = 0x51B
callq 0x30a0
leaq 0x23469(%rip), %rdi     # 0x4e70e
leaq 0x22ec4(%rip), %rsi     # 0x4e170
leaq 0x25d0e(%rip), %rcx     # 0x50fc1
movl $0x4b3, %edx            # imm = 0x4B3
callq 0x30a0
leaq 0x23456(%rip), %rdi     # 0x4e71a
leaq 0x22ea5(%rip), %rsi     # 0x4e170
leaq 0x25cef(%rip), %rcx     # 0x50fc1
movl $0x4b4, %edx            # imm = 0x4B4
callq 0x30a0
leaq 0x2345b(%rip), %rdi     # 0x4e73e
leaq 0x22e86(%rip), %rsi     # 0x4e170
leaq 0x25cd0(%rip), %rcx     # 0x50fc1
movl $0x4b7, %edx            # imm = 0x4B7
callq 0x30a0
leaq 0x2344d(%rip), %rdi     # 0x4e74f
leaq 0x22e67(%rip), %rsi     # 0x4e170
leaq 0x25cb1(%rip), %rcx     # 0x50fc1
movl $0x4b8, %edx            # imm = 0x4B8
callq 0x30a0