// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/frontend/semantics.c
// Function: calc_struct_type_size
static size_t _calc_struct_type_size(
	ParserContext *ctx,
	ParserASTNode *node,
	ParserASTNode *node_type
) {
	assert(ctx);
	assert(node);
	assert(node_type);
	assert(node_type->type == FE_NODE_TYPE_STRUCT);
	assert(node_type->nchilds == 1);

	ParserASTNode *node_id = node_type->childs[0];
	assert(node_id);
	assert(node_id->type == FE_NODE_IDENTIFIER);

	ParserSymbol *struct_symbol = parser_get_symbol_from_node(ctx, node, FE_SYM_STRUCT, node_id->token);
	if (struct_symbol == NULL) {
		_SYNERR_TOKEN(ctx, node_id->token, "undefined struct.");
	}

	ParserASTNode *struct_node = FE_STRUCT_SYMBOL_GET_STRUCT_NODE(struct_symbol);
	assert(struct_node);
	assert(struct_node->type == FE_NODE_STRUCT);

	ParserASTNode *struct_body_node = FE_STRUCT_SYMBOL_GET_BODY_NODE(struct_symbol);
	assert(struct_body_node);
	assert(struct_body_node->type == FE_NODE_STRUCT_BODY);

	size_t max_align = 1;
	size_t size = 0;

	for (int i = 0; i < struct_body_node->nchilds; i++) {
		ParserASTNode *struct_body_member_node = struct_body_node->childs[i];
		assert(struct_body_member_node);
		assert(struct_body_member_node->type == FE_NODE_VAR);
		for (int j = 0; j < struct_body_member_node->nchilds; j++) {
			ParserASTNode *var_item_node = struct_body_member_node->childs[j];
			assert(var_item_node);
			assert(var_item_node->type == FE_NODE_VAR_ITEM);
			assert(var_item_node->nchilds >= 2);

			ParserASTNode *node_var_type = var_item_node->childs[1];
			size_t align = 1;
			if (FE_STRUCT_AST_NODE_GET_PACKED(struct_node)) {
				align = 1;
			} else {
				align = _calc_type_align(ctx, node, node_var_type);
			}

			if (align > max_align) {
				max_align = align;
			}

			if (size % align > 0) {
				size += align - size % align;
			}

			size += _calc_type_size(ctx, node, node_var_type);
		}
	}

	if (size % max_align > 0) {
		size += max_align - size % max_align;
	}

	return size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x5af20
jmp 0x5af3f
leaq 0x2162f(%rip), %rdi     # 0x7c556
leaq 0x2331c(%rip), %rsi     # 0x7e24a
movl $0x78e, %edx            # imm = 0x78E
leaq 0x24562(%rip), %rcx     # 0x7f49c
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x5af48
jmp 0x5af67
leaq 0x1b084(%rip), %rdi     # 0x75fd3
leaq 0x232f4(%rip), %rsi     # 0x7e24a
movl $0x78f, %edx            # imm = 0x78F
leaq 0x2453a(%rip), %rcx     # 0x7f49c
callq 0x30a0
cmpq $0x0, -0x18(%rbp)
je 0x5af70
jmp 0x5af8f
leaq 0x197bc(%rip), %rdi     # 0x74733
leaq 0x232cc(%rip), %rsi     # 0x7e24a
movl $0x790, %edx            # imm = 0x790
leaq 0x24512(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x18(%rbp), %rax
cmpl $0x410, (%rax)          # imm = 0x410
jne 0x5af9d
jmp 0x5afbc
leaq 0x1a07d(%rip), %rdi     # 0x75021
leaq 0x2329f(%rip), %rsi     # 0x7e24a
movl $0x791, %edx            # imm = 0x791
leaq 0x244e5(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x18(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jne 0x5afc8
jmp 0x5afe7
leaq 0x197a5(%rip), %rdi     # 0x74774
leaq 0x23274(%rip), %rsi     # 0x7e24a
movl $0x792, %edx            # imm = 0x792
leaq 0x244ba(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x5afff
jmp 0x5b01e
leaq 0x2372e(%rip), %rdi     # 0x7e734
leaq 0x2323d(%rip), %rsi     # 0x7e24a
movl $0x795, %edx            # imm = 0x795
leaq 0x24483(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x20(%rbp), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x5b02c
jmp 0x5b04b
leaq 0x19759(%rip), %rdi     # 0x7478c
leaq 0x23210(%rip), %rsi     # 0x7e24a
movl $0x796, %edx            # imm = 0x796
leaq 0x24456(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rcx
movl $0x2, %edx
callq 0x82f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x5b08d
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rsi
leaq 0x23587(%rip), %rdx     # 0x7e612
callq *%rax
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x5b0a2
jmp 0x5b0c1
leaq 0x23693(%rip), %rdi     # 0x7e73c
leaq 0x2319a(%rip), %rsi     # 0x7e24a
movl $0x79e, %edx            # imm = 0x79E
leaq 0x243e0(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x30(%rbp), %rax
cmpl $0xd00, (%rax)          # imm = 0xD00
jne 0x5b0cf
jmp 0x5b0ee
leaq 0x23672(%rip), %rdi     # 0x7e748
leaq 0x2316d(%rip), %rsi     # 0x7e24a
movl $0x79f, %edx            # imm = 0x79F
leaq 0x243b3(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5b103
jmp 0x5b122
leaq 0x23662(%rip), %rdi     # 0x7e76c
leaq 0x23139(%rip), %rsi     # 0x7e24a
movl $0x7a2, %edx            # imm = 0x7A2
leaq 0x2437f(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x38(%rbp), %rax
cmpl $0xd01, (%rax)          # imm = 0xD01
jne 0x5b130
jmp 0x5b14f
leaq 0x23646(%rip), %rdi     # 0x7e77d
leaq 0x2310c(%rip), %rsi     # 0x7e24a
movl $0x7a3, %edx            # imm = 0x7A3
leaq 0x24352(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq $0x1, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x5b349
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x5b193
jmp 0x5b1b2
leaq 0x23611(%rip), %rdi     # 0x7e7ab
leaq 0x230a9(%rip), %rsi     # 0x7e24a
movl $0x7aa, %edx            # imm = 0x7AA
leaq 0x242ef(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x58(%rbp), %rax
cmpl $0xc00, (%rax)          # imm = 0xC00
jne 0x5b1c0
jmp 0x5b1df
leaq 0x235fc(%rip), %rdi     # 0x7e7c3
leaq 0x2307c(%rip), %rsi     # 0x7e24a
movl $0x7ab, %edx            # imm = 0x7AB
leaq 0x242c2(%rip), %rcx     # 0x7f49c
callq 0x30a0
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x5b339
movq -0x58(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x5b213
jmp 0x5b232
leaq 0x235d6(%rip), %rdi     # 0x7e7f0
leaq 0x23029(%rip), %rsi     # 0x7e24a
movl $0x7ae, %edx            # imm = 0x7AE
leaq 0x2426f(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x68(%rbp), %rax
cmpl $0xc01, (%rax)          # imm = 0xC01
jne 0x5b240
jmp 0x5b25f
leaq 0x235b7(%rip), %rdi     # 0x7e7fe
leaq 0x22ffc(%rip), %rsi     # 0x7e24a
movl $0x7af, %edx            # imm = 0x7AF
leaq 0x24242(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x68(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jl 0x5b26b
jmp 0x5b28a
leaq 0x235b4(%rip), %rdi     # 0x7e826
leaq 0x22fd1(%rip), %rsi     # 0x7e24a
movl $0x7b0, %edx            # imm = 0x7B0
leaq 0x24217(%rip), %rcx     # 0x7f49c
callq 0x30a0
movq -0x68(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq $0x1, -0x78(%rbp)
movq -0x30(%rbp), %rax
testb $0x1, 0x68(%rax)
je 0x5b2b6
movq $0x1, -0x78(%rbp)
jmp 0x5b2cb
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x4f150
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0x5b2dd
movq -0x78(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x78(%rbp)
cmpq $0x0, %rdx
jbe 0x5b312
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x78(%rbp)
movq -0x80(%rbp), %rax
subq %rdx, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x57dd0
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x5b1e6
jmp 0x5b33b
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x5b166
movq -0x48(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x40(%rbp)
cmpq $0x0, %rdx
jbe 0x5b384
movq -0x40(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x40(%rbp)
movq -0x88(%rbp), %rax
subq %rdx, %rax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)