// File: /workspace/github_c_makefile_star2_O0/Ihsoh[P]ilang/compiler/backend/semantics.c
// Function: calc_struct_type_align
static size_t _calc_struct_type_align(
	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);
	if (BE_STRUCT_AST_NODE_GET_PACKED(struct_node)) {
		return 1;
	}

	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;

	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 = _calc_type_align(ctx, node, node_var_type);
			if (align > max_align) {
				max_align = align;
			}
		}
	}

	return max_align;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x50160
jmp 0x5017f
leaq 0x2fffa(%rip), %rdi     # 0x80161
leaq 0x32712(%rip), %rsi     # 0x82880
movl $0x417, %edx            # imm = 0x417
leaq 0x32c69(%rip), %rcx     # 0x82de3
callq 0x30a0
cmpq $0x0, -0x18(%rbp)
je 0x50188
jmp 0x501a7
leaq 0x263cd(%rip), %rdi     # 0x7655c
leaq 0x326ea(%rip), %rsi     # 0x82880
movl $0x418, %edx            # imm = 0x418
leaq 0x32c41(%rip), %rcx     # 0x82de3
callq 0x30a0
cmpq $0x0, -0x20(%rbp)
je 0x501b0
jmp 0x501cf
leaq 0x35087(%rip), %rdi     # 0x8523e
leaq 0x326c2(%rip), %rsi     # 0x82880
movl $0x419, %edx            # imm = 0x419
leaq 0x32c19(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x20(%rbp), %rax
cmpl $0x410, (%rax)          # imm = 0x410
jne 0x501dd
jmp 0x501fc
leaq 0x32c51(%rip), %rdi     # 0x82e35
leaq 0x32695(%rip), %rsi     # 0x82880
movl $0x41a, %edx            # imm = 0x41A
leaq 0x32bec(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x20(%rbp), %rax
cmpl $0x1, 0x44(%rax)
jne 0x50208
jmp 0x50227
leaq 0x32c4d(%rip), %rdi     # 0x82e5c
leaq 0x3266a(%rip), %rsi     # 0x82880
movl $0x41b, %edx            # imm = 0x41B
leaq 0x32bc1(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x5023f
jmp 0x5025e
leaq 0x26dde(%rip), %rdi     # 0x77024
leaq 0x32633(%rip), %rsi     # 0x82880
movl $0x41e, %edx            # imm = 0x41E
leaq 0x32b8a(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x28(%rbp), %rax
cmpl $0x200, (%rax)          # imm = 0x200
jne 0x5026c
jmp 0x5028b
leaq 0x26d2f(%rip), %rdi     # 0x76fa2
leaq 0x32606(%rip), %rsi     # 0x82880
movl $0x41f, %edx            # imm = 0x41F
leaq 0x32b5d(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movl $0x2, %edx
callq 0x82f0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x502cd
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rsi
leaq 0x329b9(%rip), %rdx     # 0x82c84
callq *%rax
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x502e2
jmp 0x50301
leaq 0x32b8b(%rip), %rdi     # 0x82e74
leaq 0x32590(%rip), %rsi     # 0x82880
movl $0x427, %edx            # imm = 0x427
leaq 0x32ae7(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x38(%rbp), %rax
cmpl $0xd00, (%rax)          # imm = 0xD00
jne 0x5030f
jmp 0x5032e
leaq 0x32b6a(%rip), %rdi     # 0x82e80
leaq 0x32563(%rip), %rsi     # 0x82880
movl $0x428, %edx            # imm = 0x428
leaq 0x32aba(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x38(%rbp), %rax
testb $0x1, 0x68(%rax)
je 0x50345
movq $0x1, -0x8(%rbp)
jmp 0x50538
movq -0x30(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x5035a
jmp 0x50379
leaq 0x32b43(%rip), %rdi     # 0x82ea4
leaq 0x32518(%rip), %rsi     # 0x82880
movl $0x42e, %edx            # imm = 0x42E
leaq 0x32a6f(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x40(%rbp), %rax
cmpl $0xd01, (%rax)          # imm = 0xD01
jne 0x50387
jmp 0x503a6
leaq 0x32b27(%rip), %rdi     # 0x82eb5
leaq 0x324eb(%rip), %rsi     # 0x82880
movl $0x42f, %edx            # imm = 0x42F
leaq 0x32a42(%rip), %rcx     # 0x82de3
callq 0x30a0
movq $0x1, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x50530
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x503e2
jmp 0x50401
leaq 0x32afa(%rip), %rdi     # 0x82ee3
leaq 0x32490(%rip), %rsi     # 0x82880
movl $0x435, %edx            # imm = 0x435
leaq 0x329e7(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x58(%rbp), %rax
cmpl $0xc00, (%rax)          # imm = 0xC00
jne 0x5040f
jmp 0x5042e
leaq 0x32ae5(%rip), %rdi     # 0x82efb
leaq 0x32463(%rip), %rsi     # 0x82880
movl $0x436, %edx            # imm = 0x436
leaq 0x329ba(%rip), %rcx     # 0x82de3
callq 0x30a0
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x44(%rcx), %eax
jge 0x50520
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 0x50462
jmp 0x50481
leaq 0x32abf(%rip), %rdi     # 0x82f28
leaq 0x32410(%rip), %rsi     # 0x82880
movl $0x439, %edx            # imm = 0x439
leaq 0x32967(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x68(%rbp), %rax
cmpl $0xc01, (%rax)          # imm = 0xC01
jne 0x5048f
jmp 0x504ae
leaq 0x32aa0(%rip), %rdi     # 0x82f36
leaq 0x323e3(%rip), %rsi     # 0x82880
movl $0x43a, %edx            # imm = 0x43A
leaq 0x3293a(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x68(%rbp), %rax
cmpl $0x2, 0x44(%rax)
jl 0x504ba
jmp 0x504d9
leaq 0x32a9d(%rip), %rdi     # 0x82f5e
leaq 0x323b8(%rip), %rsi     # 0x82880
movl $0x43b, %edx            # imm = 0x43B
leaq 0x3290f(%rip), %rcx     # 0x82de3
callq 0x30a0
movq -0x68(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x4f0a0
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x48(%rbp), %rax
jbe 0x50510
movq -0x78(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x50512
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x50435
jmp 0x50522
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x503b5
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)