// File: /workspace/github_c_makefile_star2_O3/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 0x87e5
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3b3e(%rip), %rsi      # 0xc26d
movq %rdx, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x4cbc
testq %rax, %rax
je 0x87ee
movq %r14, (%rsp)
movq (%rax), %rax
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
leaq 0x4817(%rip), %rsi      # 0xcf75
movq %r13, %rdi
movl $0x3, %edx
callq 0x4cbc
testq %rax, %rax
je 0x880e
movq %rax, %r12
movl $0x1, 0x10(%rbx)
imulq $0x38, (%rax), %rdi
callq 0xb080
movq %rax, 0x20(%rbx)
movq $0x0, 0x28(%rbx)
cmpq $0x0, (%r12)
je 0x88a3
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x20(%rbx), %rdi
addq %r13, %rdi
movq 0x8(%r12), %rdx
addq %rbp, %rdx
movq %rbx, %rsi
movq %r15, %rcx
callq 0x8708
movq 0x28(%rbx), %rcx
testl %eax, %eax
jne 0x8844
incq %rcx
movq %rcx, 0x28(%rbx)
incq %r14
addq $0x20, %rbp
addq $0x38, %r13
cmpq (%r12), %r14
jb 0x87a6
jmp 0x88a3
leaq 0x473b(%rip), %rdx      # 0xcf27
jmp 0x87f5
leaq 0x4751(%rip), %rdx      # 0xcf46
movq %r15, %rdi
movl $0x4, %esi
xorl %eax, %eax
callq 0x6e50
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x88b4
leaq 0x4766(%rip), %rsi      # 0xcf7b
movq %r13, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x4cbc
testq %rax, %rax
je 0x8873
movl $0x2, 0x10(%rbx)
movq (%rax), %rdi
movq %rdi, 0x18(%rbx)
callq 0xb004
movq $0x0, 0x28(%rbx)
jmp 0x88a3
testq %rcx, %rcx
je 0x8868
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x20(%rbx), %rdi
addq %r14, %rdi
callq 0x8ddd
incq %r15
addq $0x38, %r14
cmpq 0x28(%rbx), %r15
jb 0x884f
movq 0x8(%rbx), %rdi
callq 0x2570
jmp 0x8804
leaq 0x4706(%rip), %rsi      # 0xcf80
movq %r13, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x4cbc
testq %rax, %rax
je 0x889c
movl $0x3, 0x10(%rbx)
movq (%rax), %rax
movq %rax, 0x18(%rbx)
jmp 0x88a3
movl $0x0, 0x10(%rbx)
movq $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