// File: /workspace/github_c_makefile_star2_O2/TurkeyMcMac[P]ts3d/src/menu.c
// Function: construct
static int construct(struct menu_item *item, struct menu_item *parent,
	struct json_node *json, struct logger *log)
{
	if (json->kind != JN_MAP) {
		logger_printf(log, LOGGER_ERROR,
			"Menu item is not a dictionary\n");
		goto error_kind;
	}
	union json_node_data *got;
	if ((got = json_map_get(json, "title", TAKE_NODE | JN_STRING))) {
		item->title = got->str;
	} else {
		logger_printf(log, LOGGER_ERROR,
			"Menu item has no or invalid \"title\" attribute\n");
		goto error_title;
	}
	item->tag = NULL;
	item->items = NULL;
	if ((got = json_map_get(json, "items", JN_LIST))) {
		item->kind = ITEM_LINKS;
		struct json_node_data_list *list = &got->list;
		item->items = xmalloc(list->n_vals * sizeof(*item->items));
		item->n_items = 0;
		for (size_t i = 0; i < list->n_vals; ++i) {
			if (construct(&item->items[i], item, &list->vals[i], log))
				goto error_item;
			++item->n_items;
		}
	} else if ((got = json_map_get(json, "text", TAKE_NODE | JN_STRING))) {
		item->kind = ITEM_TEXT;
		item->tag = got->str;
		subst_native_dir_sep(item->tag);
		item->n_items = 0;
	} else if ((got = json_map_get(json, "tag", TAKE_NODE | JN_STRING))) {
		item->kind = ITEM_TAG;
		item->tag = got->str;
	} else {
		item->kind = ITEM_INERT;
	}
	item->place = 0;
	item->frame = 0;
	item->parent = parent;
	return 0;

error_item:
	for (size_t i = 0; i < item->n_items; ++i) {
		destroy_item(&item->items[i]);
	}
	free(item->title);
error_title:
error_kind:
	return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
cmpl $0x2, (%rdx)
jne 0x81c1
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x311c(%rip), %rsi      # 0xb23d
movq %rdx, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x49e4
testq %rax, %rax
je 0x81ca
movq (%rax), %rax
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
leaq 0x3df9(%rip), %rsi      # 0xbf45
pushq $0x3
popq %rdx
movq %r13, %rdi
callq 0x49e4
testq %rax, %rax
movq %r14, (%rsp)
je 0x81e6
movq %rax, %r12
movl $0x1, 0x10(%rbx)
imulq $0x38, (%rax), %rdi
callq 0xa7d0
movq %rax, 0x20(%rbx)
andq $0x0, 0x28(%rbx)
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpq (%r12), %r14
jae 0x8272
movq 0x20(%rbx), %rdi
addq %rbp, %rdi
movq 0x8(%r12), %rdx
addq %r13, %rdx
movq %rbx, %rsi
movq %r15, %rcx
callq 0x80fa
testl %eax, %eax
jne 0x8219
incq 0x28(%rbx)
incq %r14
addq $0x38, %rbp
addq $0x20, %r13
jmp 0x8188
leaq 0x3d2f(%rip), %rdx      # 0xbef7
jmp 0x81d1
leaq 0x3d45(%rip), %rdx      # 0xbf16
pushq $0x4
popq %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x691c
pushq $-0x1
popq %rax
jmp 0x8280
leaq 0x3d5e(%rip), %rsi      # 0xbf4b
movq %r13, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x49e4
testq %rax, %rax
je 0x8245
movl $0x2, 0x10(%rbx)
movq (%rax), %rdi
movq %rdi, 0x18(%rbx)
callq 0xa760
andq $0x0, 0x28(%rbx)
jmp 0x8272
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpq 0x28(%rbx), %r15
jae 0x823a
movq 0x20(%rbx), %rdi
addq %r14, %rdi
callq 0x8762
incq %r15
addq $0x38, %r14
jmp 0x821f
movq 0x8(%rbx), %rdi
callq 0x2580
jmp 0x81de
leaq 0x3d04(%rip), %rsi      # 0xbf50
movq %r13, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x49e4
testq %rax, %rax
je 0x826e
movl $0x3, 0x10(%rbx)
movq (%rax), %rax
movq %rax, 0x18(%rbx)
jmp 0x8272
andl $0x0, 0x10(%rbx)
andq $0x0, 0x30(%rbx)
movq (%rsp), %rax
movq %rax, (%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq