// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rcx, %r15
cmpl $0x2, (%rdx)
jne 0x88e1
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x3a33(%rip), %rsi      # 0xc1fd
movq %rdx, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x4c98
testq %rax, %rax
je 0x88ea
movq %r14, 0x10(%rsp)
movq (%rax), %rax
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
leaq 0x470b(%rip), %rsi      # 0xcf05
movq %r13, %rdi
movl $0x3, %edx
callq 0x4c98
testq %rax, %rax
je 0x8907
movq %rax, %r12
movq %r15, 0x8(%rsp)
movl $0x1, 0x10(%rbx)
imulq $0x38, (%rax), %rdi
callq 0xb1ac
movq %rax, 0x20(%rbx)
movq $0x0, 0x28(%rbx)
cmpq $0x0, (%r12)
setne %bpl
je 0x896d
movq 0x20(%rbx), %rdi
movq 0x8(%r12), %rdx
movq %rbx, %rsi
movq 0x8(%rsp), %rcx
callq 0x87a0
testl %eax, %eax
jne 0x88a7
movl $0x38, %edi
movl $0x20, %edx
xorl %r13d, %r13d
incq 0x28(%rbx)
incq %r13
cmpq (%r12), %r13
setb %bpl
jae 0x896d
leaq 0x38(%rdi), %r14
leaq 0x20(%rdx), %r15
addq 0x20(%rbx), %rdi
addq 0x8(%r12), %rdx
movq %rbx, %rsi
movq 0x8(%rsp), %rcx
callq 0x87a0
movq %r15, %rdx
movq %r14, %rdi
testl %eax, %eax
je 0x886a
testb %bpl, %bpl
je 0x896d
cmpq $0x0, 0x28(%rbx)
je 0x88d6
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x20(%rbx), %rdi
addq %r14, %rdi
callq 0x8ea1
incq %r15
addq $0x38, %r14
cmpq 0x28(%rbx), %r15
jb 0x88bd
movq 0x8(%rbx), %rdi
callq 0x2570
jmp 0x8900
leaq 0x45cf(%rip), %rdx      # 0xceb7
jmp 0x88f1
leaq 0x45e5(%rip), %rdx      # 0xced6
movq %r15, %rdi
movl $0x4, %esi
xorl %eax, %eax
callq 0x6e97
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x897f
leaq 0x45fd(%rip), %rsi      # 0xcf0b
movq %r13, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x4c98
testq %rax, %rax
je 0x893d
movl $0x2, 0x10(%rbx)
movq (%rax), %rdi
movq %rdi, 0x18(%rbx)
callq 0xb129
movq $0x0, 0x28(%rbx)
jmp 0x896d
leaq 0x45cc(%rip), %rsi      # 0xcf10
movq %r13, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x4c98
testq %rax, %rax
je 0x8966
movl $0x3, 0x10(%rbx)
movq (%rax), %rax
movq %rax, 0x18(%rbx)
jmp 0x896d
movl $0x0, 0x10(%rbx)
movq $0x0, 0x30(%rbx)
movq 0x10(%rsp), %rax
movq %rax, (%rbx)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq