// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x2, (%rax)
je 0xc95d
movq -0x28(%rbp), %rdi
movl $0x4, %esi
leaq 0x5716(%rip), %rdx      # 0x12067
movb $0x0, %al
callq 0xa260
jmp 0xcb9d
movq -0x20(%rbp), %rdi
leaq 0x486d(%rip), %rsi      # 0x111d5
movl $0x1004, %edx           # imm = 0x1004
callq 0x6820
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xc98d
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0xc9a9
movq -0x28(%rbp), %rdi
movl $0x4, %esi
leaq 0x56e9(%rip), %rdx      # 0x12086
movb $0x0, %al
callq 0xa260
jmp 0xcb9b
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x20(%rbp), %rdi
leaq 0x56e9(%rip), %rsi      # 0x120b5
movl $0x3, %edx
callq 0x6820
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xca8d
movq -0x10(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
imulq $0x38, (%rax), %rdi
callq 0x10b80
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xca88
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
imulq $0x38, -0x40(%rbp), %rax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x40(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
callq 0xc920
cmpl $0x0, %eax
je 0xca6a
jmp 0xcb55
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x28(%rax)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0xca23
jmp 0xcb2b
movq -0x20(%rbp), %rdi
leaq 0x5623(%rip), %rsi      # 0x120bb
movl $0x1004, %edx           # imm = 0x1004
callq 0x6820
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xcae1
movq -0x10(%rbp), %rax
movl $0x2, 0x10(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x10a60
movq -0x10(%rbp), %rax
movq $0x0, 0x28(%rax)
jmp 0xcb29
movq -0x20(%rbp), %rdi
leaq 0x55d4(%rip), %rsi      # 0x120c0
movl $0x1004, %edx           # imm = 0x1004
callq 0x6820
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0xcb1c
movq -0x10(%rbp), %rax
movl $0x3, 0x10(%rax)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0xcb27
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
jmp 0xcb29
jmp 0xcb2b
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x34(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0xcba4
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jae 0xcb8e
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
imulq $0x38, -0x48(%rbp), %rax
addq %rax, %rdi
callq 0xd4d0
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0xcb5d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2580
jmp 0xcb9d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)