// File: /workspace/github_c_makefile_star2_O3/Ihsoh[P]ilang/compiler/frontend/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 FE_NODE_TYPE_CHAR: {
			return 1;
		}
		case FE_NODE_TYPE_INT8: {
			return 1;
		}
		case FE_NODE_TYPE_INT16: {
			return 2;
		}
		case FE_NODE_TYPE_INT32: {
			return 4;
		}
		case FE_NODE_TYPE_INT64: {
			return 8;
		}
		case FE_NODE_TYPE_UINT8: {
			return 1;
		}
		case FE_NODE_TYPE_UINT16: {
			return 2;
		}
		case FE_NODE_TYPE_UINT32: {
			return 4;
		}
		case FE_NODE_TYPE_UINT64: {
			return 8;
		}
		case FE_NODE_TYPE_FLOAT: {
			return 4;
		}
		case FE_NODE_TYPE_DOUBLE: {
			return 8;
		}
		case FE_NODE_TYPE_VA_LIST: {
			return 0;
		}
		case FE_NODE_TYPE_STRUCT: {
			return _calc_struct_type_size(ctx, node, node_type);
		}
		case FE_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 == FE_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 *= fe_parser_get_uint_val(ctx, node_array_dim);
			}

			return size;
		}
		case FE_NODE_TYPE_FUNC: {
			return 0;
		}
		case FE_NODE_TYPE_POINTER: {
			if (ctx->arch == FE_ARCH_32) {
				return 4;
			} else if (ctx->arch == FE_ARCH_64) {
				return 8;
			} else {
				assert(0);
				return 0;
			}
		}
		case FE_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 0x30b90
movl (%rdx), %eax
movl $0x1, %r14d
cmpl $0x42f, %eax            # imm = 0x42F
jg 0x30820
addl $0xfffffc00, %eax       # imm = 0xFFFFFC00
cmpl $0x20, %eax
ja 0x3083d
leaq 0x19a28(%rip), %rcx     # 0x4a234
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x4, %r14d
jmp 0x30ac4
cmpl $0x430, %eax            # imm = 0x430
je 0x30867
cmpl $0x440, %eax            # imm = 0x440
je 0x30a7c
cmpl $0x4ff, %eax            # imm = 0x4FF
je 0x30ac4
leaq 0xeb1c(%rip), %rdi      # 0x3f360
leaq 0x1a0af(%rip), %rsi     # 0x4a8fa
leaq 0x1b261(%rip), %rcx     # 0x4bab3
movl $0x823, %edx            # imm = 0x823
callq 0x30a0
movl $0x2, %r14d
jmp 0x30ac4
xorl %r14d, %r14d
jmp 0x30ac4
cmpl $0x2, 0x44(%rdx)
jne 0x30baf
movq 0x48(%rdx), %rax
movq (%rax), %rbx
testq %rbx, %rbx
je 0x30bed
cmpl $0x421, (%rbx)          # imm = 0x421
jne 0x30c2b
movq 0x8(%rax), %rdx
testq %rdx, %rdx
je 0x30c69
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x307ca
movq %rax, %r14
cmpl $0x0, 0x44(%rbx)
jle 0x30ac4
xorl %r15d, %r15d
movq 0x48(%rbx), %rax
movq (%rax,%r15,8), %rsi
testq %rsi, %rsi
je 0x30b33
movq -0x30(%rbp), %rdi
callq 0x24ade
imulq %rax, %r14
incq %r15
movslq 0x44(%rbx), %rax
cmpq %rax, %r15
jl 0x308bf
jmp 0x30ac4
cmpl $0x1, 0x44(%rdx)
jne 0x30bce
movq 0x48(%rdx), %rax
movq (%rax), %r14
testq %r14, %r14
je 0x30c0c
cmpl $0x200, (%r14)          # imm = 0x200
jne 0x30c4a
movq 0x10(%r14), %rcx
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x2, %edx
callq 0x6c89
movq %rax, %rbx
testq %rax, %rax
jne 0x30945
movq 0x10(%r14), %rsi
leaq 0x1a355(%rip), %rdx     # 0x4ac93
movq -0x30(%rbp), %rdi
callq *0x50(%rdi)
movq 0x30(%rbx), %rcx
testq %rcx, %rcx
je 0x30c88
cmpl $0xd00, (%rcx)          # imm = 0xD00
jne 0x30ca7
movq 0x38(%rbx), %rdx
testq %rdx, %rdx
je 0x30cc6
cmpl $0xd01, (%rdx)          # imm = 0xD01
jne 0x30ce5
movl 0x44(%rdx), %eax
testl %eax, %eax
jle 0x30a9f
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 0x30b52
cmpl $0xc00, (%r14)          # imm = 0xC00
jne 0x30b71
cmpl $0x0, 0x44(%r14)
jle 0x30a6b
movq %rsi, -0x50(%rbp)
xorl %r15d, %r15d
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rax
testq %rax, %rax
je 0x30af5
cmpl $0xc01, (%rax)          # imm = 0xC01
jne 0x30b14
cmpl $0x1, 0x44(%rax)
jle 0x30ad6
movq 0x48(%rax), %rax
movq 0x8(%rax), %r13
movl $0x1, %ebx
movq -0x58(%rbp), %rax
cmpb $0x0, 0x68(%rax)
jne 0x30a19
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq %r13, %rdx
callq 0x2b281
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 0x307ca
addq %rbx, %r12
addq %rax, %r12
incq %r15
movslq 0x44(%r14), %rax
cmpq %rax, %r15
jl 0x309c8
movq -0x48(%rbp), %rdx
movl 0x44(%rdx), %eax
movq -0x50(%rbp), %rsi
incq %rsi
movslq %eax, %rcx
cmpq %rcx, %rsi
jl 0x30998
jmp 0x30aab
movq -0x30(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x4, %r14d
cmpl $0x1, %eax
je 0x30ac4
cmpl $0x2, %eax
jne 0x30d04
movl $0x8, %r14d
jmp 0x30ac4
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 0x1a3ca(%rip), %rdi     # 0x4aea7
leaq 0x19e16(%rip), %rsi     # 0x4a8fa
leaq 0x1b031(%rip), %rcx     # 0x4bb1c
movl $0x7b0, %edx            # imm = 0x7B0
callq 0x30a0
leaq 0x1a375(%rip), %rdi     # 0x4ae71
leaq 0x19df7(%rip), %rsi     # 0x4a8fa
leaq 0x1b012(%rip), %rcx     # 0x4bb1c
movl $0x7ae, %edx            # imm = 0x7AE
callq 0x30a0
leaq 0x1a364(%rip), %rdi     # 0x4ae7f
leaq 0x19dd8(%rip), %rsi     # 0x4a8fa
leaq 0x1aff3(%rip), %rcx     # 0x4bb1c
movl $0x7af, %edx            # imm = 0x7AF
callq 0x30a0
leaq 0x1afd3(%rip), %rdi     # 0x4bb0d
leaq 0x19db9(%rip), %rsi     # 0x4a8fa
leaq 0x1af6b(%rip), %rcx     # 0x4bab3
movl $0x80b, %edx            # imm = 0x80B
callq 0x30a0
leaq 0x1a2d3(%rip), %rdi     # 0x4ae2c
leaq 0x19d9a(%rip), %rsi     # 0x4a8fa
leaq 0x1afb5(%rip), %rcx     # 0x4bb1c
movl $0x7aa, %edx            # imm = 0x7AA
callq 0x30a0
leaq 0x1a2cc(%rip), %rdi     # 0x4ae44
leaq 0x19d7b(%rip), %rsi     # 0x4a8fa
leaq 0x1af96(%rip), %rcx     # 0x4bb1c
movl $0x7ab, %edx            # imm = 0x7AB
callq 0x30a0
leaq 0x10b6c(%rip), %rdi     # 0x41703
leaq 0x19d5c(%rip), %rsi     # 0x4a8fa
leaq 0x1af0e(%rip), %rcx     # 0x4bab3
movl $0x7d4, %edx            # imm = 0x7D4
callq 0x30a0
leaq 0x10c62(%rip), %rdi     # 0x41818
leaq 0x19d3d(%rip), %rsi     # 0x4a8fa
leaq 0x1aeef(%rip), %rcx     # 0x4bab3
movl $0x7ff, %edx            # imm = 0x7FF
callq 0x30a0
leaq 0x10b6f(%rip), %rdi     # 0x41744
leaq 0x19d1e(%rip), %rsi     # 0x4a8fa
leaq 0x1af39(%rip), %rcx     # 0x4bb1c
movl $0x792, %edx            # imm = 0x792
callq 0x30a0
leaq 0x1af09(%rip), %rdi     # 0x4bafd
leaq 0x19cff(%rip), %rsi     # 0x4a8fa
leaq 0x1aeb1(%rip), %rcx     # 0x4bab3
movl $0x802, %edx            # imm = 0x802
callq 0x30a0
leaq 0x1a1a2(%rip), %rdi     # 0x4adb5
leaq 0x19ce0(%rip), %rsi     # 0x4a8fa
leaq 0x1aefb(%rip), %rcx     # 0x4bb1c
movl $0x795, %edx            # imm = 0x795
callq 0x30a0
leaq 0x10b4e(%rip), %rdi     # 0x41780
leaq 0x19cc1(%rip), %rsi     # 0x4a8fa
leaq 0x1ae73(%rip), %rcx     # 0x4bab3
movl $0x803, %edx            # imm = 0x803
callq 0x30a0
leaq 0x10b0b(%rip), %rdi     # 0x4175c
leaq 0x19ca2(%rip), %rsi     # 0x4a8fa
leaq 0x1aebd(%rip), %rcx     # 0x4bb1c
movl $0x796, %edx            # imm = 0x796
callq 0x30a0
leaq 0x1a0e3(%rip), %rdi     # 0x4ad53
leaq 0x19c83(%rip), %rsi     # 0x4a8fa
leaq 0x1ae35(%rip), %rcx     # 0x4bab3
movl $0x806, %edx            # imm = 0x806
callq 0x30a0
leaq 0x1a12e(%rip), %rdi     # 0x4adbd
leaq 0x19c64(%rip), %rsi     # 0x4a8fa
leaq 0x1ae7f(%rip), %rcx     # 0x4bb1c
movl $0x79e, %edx            # imm = 0x79E
callq 0x30a0
leaq 0x1a11b(%rip), %rdi     # 0x4adc9
leaq 0x19c45(%rip), %rsi     # 0x4a8fa
leaq 0x1ae60(%rip), %rcx     # 0x4bb1c
movl $0x79f, %edx            # imm = 0x79F
callq 0x30a0
leaq 0x1a120(%rip), %rdi     # 0x4aded
leaq 0x19c26(%rip), %rsi     # 0x4a8fa
leaq 0x1ae41(%rip), %rcx     # 0x4bb1c
movl $0x7a2, %edx            # imm = 0x7A2
callq 0x30a0
leaq 0x1a112(%rip), %rdi     # 0x4adfe
leaq 0x19c07(%rip), %rsi     # 0x4a8fa
leaq 0x1ae22(%rip), %rcx     # 0x4bb1c
movl $0x7a3, %edx            # imm = 0x7A3
callq 0x30a0
leaq 0xe655(%rip), %rdi      # 0x3f360
leaq 0x19be8(%rip), %rsi     # 0x4a8fa
leaq 0x1ad9a(%rip), %rcx     # 0x4bab3
movl $0x81b, %edx            # imm = 0x81B
callq 0x30a0