// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/backend/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 == BE_NODE_TYPE_STRUCT);
	assert(node_type->nchilds == 1);

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

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

	ParserASTNode *struct_node = BE_STRUCT_SYMBOL_GET_STRUCT_NODE(struct_symbol);
	assert(struct_node);
	assert(struct_node->type == BE_NODE_STRUCT);

	ParserASTNode *struct_body_node = BE_STRUCT_SYMBOL_GET_BODY_NODE(struct_symbol);
	assert(struct_body_node);
	assert(struct_body_node->type == BE_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 == BE_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 == BE_NODE_VAR_ITEM);
			assert(var_item_node->nchilds >= 2);

			ParserASTNode *node_var_type = var_item_node->childs[1];
			size_t align = 1;
			if (BE_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 0x60de0
jmp 0x60dff
leaq 0x1f37a(%rip), %rdi     # 0x80161
leaq 0x21a92(%rip), %rsi     # 0x82880
movl $0x4a3, %edx            # imm = 0x4A3
leaq 0x24c60(%rip), %rcx     # 0x85a5a
callq 0x30a0
cmpq $0x0, -0x10(%rbp)
je 0x60e08
jmp 0x60e27
leaq 0x1574d(%rip), %rdi     # 0x7655c
leaq 0x21a6a(%rip), %rsi     # 0x82880
movl $0x4a4, %edx            # imm = 0x4A4
leaq 0x24c38(%rip), %rcx     # 0x85a5a
callq 0x30a0
cmpq $0x0, -0x18(%rbp)
je 0x60e30
jmp 0x60e4f
leaq 0x24407(%rip), %rdi     # 0x8523e
leaq 0x21a42(%rip), %rsi     # 0x82880
movl $0x4a5, %edx            # imm = 0x4A5
leaq 0x24c10(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x18(%rbp), %rax
cmpl $0x410, (%rax)          # imm = 0x410
jne 0x60e5d
jmp 0x60e7c
leaq 0x21fd1(%rip), %rdi     # 0x82e35
leaq 0x21a15(%rip), %rsi     # 0x82880
movl $0x4a6, %edx            # imm = 0x4A6
leaq 0x24be3(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x18(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jne 0x60e88
jmp 0x60ea7
leaq 0x21fcd(%rip), %rdi     # 0x82e5c
leaq 0x219ea(%rip), %rsi     # 0x82880
movl $0x4a7, %edx            # imm = 0x4A7
leaq 0x24bb8(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x60ebf
jmp 0x60ede
leaq 0x1615e(%rip), %rdi     # 0x77024
leaq 0x219b3(%rip), %rsi     # 0x82880
movl $0x4aa, %edx            # imm = 0x4AA
leaq 0x24b81(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x20(%rbp), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x60eec
jmp 0x60f0b
leaq 0x160af(%rip), %rdi     # 0x76fa2
leaq 0x21986(%rip), %rsi     # 0x82880
movl $0x4ab, %edx            # imm = 0x4AB
leaq 0x24b54(%rip), %rcx     # 0x85a5a
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 0x60f4d
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rcx
movq 0x10(%rcx), %rsi
leaq 0x21d39(%rip), %rdx     # 0x82c84
callq *%rax
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x60f62
jmp 0x60f81
leaq 0x21f0b(%rip), %rdi     # 0x82e74
leaq 0x21910(%rip), %rsi     # 0x82880
movl $0x4b3, %edx            # imm = 0x4B3
leaq 0x24ade(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x30(%rbp), %rax
cmpl $0xd00, (%rax)          # imm = 0xD00
jne 0x60f8f
jmp 0x60fae
leaq 0x21eea(%rip), %rdi     # 0x82e80
leaq 0x218e3(%rip), %rsi     # 0x82880
movl $0x4b4, %edx            # imm = 0x4B4
leaq 0x24ab1(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x60fc3
jmp 0x60fe2
leaq 0x21eda(%rip), %rdi     # 0x82ea4
leaq 0x218af(%rip), %rsi     # 0x82880
movl $0x4b7, %edx            # imm = 0x4B7
leaq 0x24a7d(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x38(%rbp), %rax
cmpl $0xd01, (%rax)          # imm = 0xD01
jne 0x60ff0
jmp 0x6100f
leaq 0x21ebe(%rip), %rdi     # 0x82eb5
leaq 0x21882(%rip), %rsi     # 0x82880
movl $0x4b8, %edx            # imm = 0x4B8
leaq 0x24a50(%rip), %rcx     # 0x85a5a
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 0x61209
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 0x61053
jmp 0x61072
leaq 0x21e89(%rip), %rdi     # 0x82ee3
leaq 0x2181f(%rip), %rsi     # 0x82880
movl $0x4bf, %edx            # imm = 0x4BF
leaq 0x249ed(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x58(%rbp), %rax
cmpl $0xc00, (%rax)          # imm = 0xC00
jne 0x61080
jmp 0x6109f
leaq 0x21e74(%rip), %rdi     # 0x82efb
leaq 0x217f2(%rip), %rsi     # 0x82880
movl $0x4c0, %edx            # imm = 0x4C0
leaq 0x249c0(%rip), %rcx     # 0x85a5a
callq 0x30a0
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x611f9
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 0x610d3
jmp 0x610f2
leaq 0x21e4e(%rip), %rdi     # 0x82f28
leaq 0x2179f(%rip), %rsi     # 0x82880
movl $0x4c3, %edx            # imm = 0x4C3
leaq 0x2496d(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x68(%rbp), %rax
cmpl $0xc01, (%rax)          # imm = 0xC01
jne 0x61100
jmp 0x6111f
leaq 0x21e2f(%rip), %rdi     # 0x82f36
leaq 0x21772(%rip), %rsi     # 0x82880
movl $0x4c4, %edx            # imm = 0x4C4
leaq 0x24940(%rip), %rcx     # 0x85a5a
callq 0x30a0
movq -0x68(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jl 0x6112b
jmp 0x6114a
leaq 0x21e2c(%rip), %rdi     # 0x82f5e
leaq 0x21747(%rip), %rsi     # 0x82880
movl $0x4c5, %edx            # imm = 0x4C5
leaq 0x24915(%rip), %rcx     # 0x85a5a
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 0x61176
movq $0x1, -0x78(%rbp)
jmp 0x6118b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x4f0a0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0x6119d
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 0x611d2
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 0x4d5a0
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x610a6
jmp 0x611fb
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x61026
movq -0x48(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x40(%rbp)
cmpq $0x0, %rdx
jbe 0x61244
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)