// File: /workspace/github_c_makefile_star2_O2/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 0x27e83
movl (%rdx), %eax
pushq $0x1
popq %r15
leal -0x400(%rax), %ecx
cmpl $0x20, %ecx
ja 0x27b15
leaq 0x20ab3(%rip), %rax     # 0x485b8
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
pushq $0x8
jmp 0x27d9a
cmpl $0x430, %eax            # imm = 0x430
je 0x27d5f
cmpl $0x440, %eax            # imm = 0x440
je 0x27d64
cmpl $0x4ff, %eax            # imm = 0x4FF
je 0x27d9c
leaq 0x1382c(%rip), %rdi     # 0x3b369
leaq 0x2162c(%rip), %rsi     # 0x49170
leaq 0x24397(%rip), %rcx     # 0x4bee2
movl $0x538, %edx            # imm = 0x538
callq 0x30a0
pushq $0x2
jmp 0x27d9a
cmpl $0x2, 0x44(%rdx)
jne 0x27ea2
movq 0x48(%rdx), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x27ee0
cmpl $0x421, (%rbx)          # imm = 0x421
jne 0x27f1e
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x27f5c
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x27acb
movq %rax, %r15
xorl %r14d, %r14d
movslq 0x44(%rbx), %rax
cmpq %rax, %r14
jge 0x27d9c
movq 0x48(%rbx), %rax
movq (%rax,%r14,8), %rsi
testq %rsi, %rsi
je 0x27e26
movq -0x30(%rbp), %rdi
callq 0x20c3e
imulq %rax, %r15
incq %r14
jmp 0x27ba2
cmpl $0x1, 0x44(%rdx)
jne 0x27ec1
movq 0x48(%rdx), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x27eff
cmpl $0x200, (%r14)          # imm = 0x200
jne 0x27f3d
movq 0x10(%r14), %rcx
pushq $0x2
popq %rdx
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x6779
movq %rax, %rbx
testq %rax, %rax
jne 0x27c27
movq 0x10(%r14), %rsi
leaq 0x21925(%rip), %rdx     # 0x49545
movq -0x30(%rbp), %rdi
callq *0x50(%rdi)
movq 0x30(%rbx), %rcx
testq %rcx, %rcx
je 0x27f7b
cmpl $0xd00, (%rcx)          # imm = 0xD00
jne 0x27f9a
movq 0x38(%rbx), %rdx
testq %rdx, %rdx
je 0x27fb9
cmpl $0xd01, (%rdx)          # imm = 0xD01
jne 0x27fd8
pushq $0x1
popq %rax
xorl %esi, %esi
xorl %edi, %edi
movq %rax, -0x40(%rbp)
movq %rdx, -0x48(%rbp)
movslq 0x44(%rdx), %rax
cmpq %rax, %rsi
jge 0x27dae
movq 0x48(%rdx), %rax
movq (%rax,%rsi,8), %r12
testq %r12, %r12
je 0x27e45
movq %rsi, -0x50(%rbp)
cmpl $0xc00, (%r12)          # imm = 0xC00
jne 0x27e64
xorl %r14d, %r14d
movq %r12, -0x58(%rbp)
movslq 0x44(%r12), %rax
cmpq %rax, %r14
jge 0x27d4f
movq 0x48(%r12), %rax
movq (%rax,%r14,8), %rax
testq %rax, %rax
je 0x27de8
cmpl $0xc01, (%rax)          # imm = 0xC01
jne 0x27e07
cmpl $0x1, 0x44(%rax)
jle 0x27dc9
movq 0x48(%rax), %rax
movq 0x8(%rax), %rbx
movq %rcx, %r12
cmpb $0x0, 0x68(%rcx)
pushq $0x1
popq %r13
jne 0x27d03
movq %rdi, %r13
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq 0x2a91b
movq %r13, %rdi
movq %rax, %r13
movq -0x40(%rbp), %rax
cmpq %rax, %r13
cmovaq %r13, %rax
movq %rax, -0x40(%rbp)
movq %rdi, %rax
xorl %edx, %edx
divq %r13
subq %rdx, %r13
testq %rdx, %rdx
cmoveq %rdx, %r13
movq %rdi, %r15
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %rbx, %rdx
callq 0x27acb
addq %r15, %r13
addq %rax, %r13
incq %r14
movq %r13, %rdi
movq %r12, %rcx
movq -0x58(%rbp), %r12
jmp 0x27c9f
movq -0x50(%rbp), %rsi
incq %rsi
movq -0x48(%rbp), %rdx
jmp 0x27c68
xorl %r15d, %r15d
jmp 0x27d9c
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
cmpl $0x1, %eax
je 0x27d98
cmpl $0x2, %eax
je 0x27b0e
leaq 0x135e9(%rip), %rdi     # 0x3b369
leaq 0x213e9(%rip), %rsi     # 0x49170
leaq 0x24154(%rip), %rcx     # 0x4bee2
movl $0x530, %edx            # imm = 0x530
callq 0x30a0
pushq $0x4
popq %r15
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rax
xorl %edx, %edx
movq -0x40(%rbp), %r15
divq %r15
subq %rdx, %r15
testq %rdx, %rdx
cmoveq %rdx, %r15
addq %rdi, %r15
jmp 0x27d9c
leaq 0x21a28(%rip), %rdi     # 0x497f8
leaq 0x21399(%rip), %rsi     # 0x49170
leaq 0x2416d(%rip), %rcx     # 0x4bf4b
movl $0x4c5, %edx            # imm = 0x4C5
callq 0x30a0
leaq 0x219d3(%rip), %rdi     # 0x497c2
leaq 0x2137a(%rip), %rsi     # 0x49170
leaq 0x2414e(%rip), %rcx     # 0x4bf4b
movl $0x4c3, %edx            # imm = 0x4C3
callq 0x30a0
leaq 0x219c2(%rip), %rdi     # 0x497d0
leaq 0x2135b(%rip), %rsi     # 0x49170
leaq 0x2412f(%rip), %rcx     # 0x4bf4b
movl $0x4c4, %edx            # imm = 0x4C4
callq 0x30a0
leaq 0x2410f(%rip), %rdi     # 0x4bf3c
leaq 0x2133c(%rip), %rsi     # 0x49170
leaq 0x240a7(%rip), %rcx     # 0x4bee2
movl $0x520, %edx            # imm = 0x520
callq 0x30a0
leaq 0x21931(%rip), %rdi     # 0x4977d
leaq 0x2131d(%rip), %rsi     # 0x49170
leaq 0x240f1(%rip), %rcx     # 0x4bf4b
movl $0x4bf, %edx            # imm = 0x4BF
callq 0x30a0
leaq 0x2192a(%rip), %rdi     # 0x49795
leaq 0x212fe(%rip), %rsi     # 0x49170
leaq 0x240d2(%rip), %rcx     # 0x4bf4b
movl $0x4c0, %edx            # imm = 0x4C0
callq 0x30a0
leaq 0x2395f(%rip), %rdi     # 0x4b7e9
leaq 0x212df(%rip), %rsi     # 0x49170
leaq 0x2404a(%rip), %rcx     # 0x4bee2
movl $0x4e9, %edx            # imm = 0x4E9
callq 0x30a0
leaq 0x217d3(%rip), %rdi     # 0x4967c
leaq 0x212c0(%rip), %rsi     # 0x49170
leaq 0x2402b(%rip), %rcx     # 0x4bee2
movl $0x514, %edx            # imm = 0x514
callq 0x30a0
leaq 0x2182e(%rip), %rdi     # 0x496f6
leaq 0x212a1(%rip), %rsi     # 0x49170
leaq 0x24075(%rip), %rcx     # 0x4bf4b
movl $0x4a7, %edx            # imm = 0x4A7
callq 0x30a0
leaq 0x24045(%rip), %rdi     # 0x4bf2c
leaq 0x21282(%rip), %rsi     # 0x49170
leaq 0x23fed(%rip), %rcx     # 0x4bee2
movl $0x517, %edx            # imm = 0x517
callq 0x30a0
leaq 0x16942(%rip), %rdi     # 0x3e848
leaq 0x21263(%rip), %rsi     # 0x49170
leaq 0x24037(%rip), %rcx     # 0x4bf4b
movl $0x4aa, %edx            # imm = 0x4AA
callq 0x30a0
leaq 0x2164a(%rip), %rdi     # 0x4956f
leaq 0x21244(%rip), %rsi     # 0x49170
leaq 0x23faf(%rip), %rcx     # 0x4bee2
movl $0x518, %edx            # imm = 0x518
callq 0x30a0
leaq 0x16882(%rip), %rdi     # 0x3e7c6
leaq 0x21225(%rip), %rsi     # 0x49170
leaq 0x23ff9(%rip), %rcx     # 0x4bf4b
movl $0x4ab, %edx            # imm = 0x4AB
callq 0x30a0
leaq 0x21731(%rip), %rdi     # 0x49694
leaq 0x21206(%rip), %rsi     # 0x49170
leaq 0x23f71(%rip), %rcx     # 0x4bee2
movl $0x51b, %edx            # imm = 0x51B
callq 0x30a0
leaq 0x2178c(%rip), %rdi     # 0x4970e
leaq 0x211e7(%rip), %rsi     # 0x49170
leaq 0x23fbb(%rip), %rcx     # 0x4bf4b
movl $0x4b3, %edx            # imm = 0x4B3
callq 0x30a0
leaq 0x21779(%rip), %rdi     # 0x4971a
leaq 0x211c8(%rip), %rsi     # 0x49170
leaq 0x23f9c(%rip), %rcx     # 0x4bf4b
movl $0x4b4, %edx            # imm = 0x4B4
callq 0x30a0
leaq 0x2177e(%rip), %rdi     # 0x4973e
leaq 0x211a9(%rip), %rsi     # 0x49170
leaq 0x23f7d(%rip), %rcx     # 0x4bf4b
movl $0x4b7, %edx            # imm = 0x4B7
callq 0x30a0
leaq 0x21770(%rip), %rdi     # 0x4974f
leaq 0x2118a(%rip), %rsi     # 0x49170
leaq 0x23f5e(%rip), %rcx     # 0x4bf4b
movl $0x4b8, %edx            # imm = 0x4B8
callq 0x30a0