// File: /workspace/github_c_makefile_star2_O0/TurkeyMcMac[P]ts3d/src/save-state.c
// Function: save_state_init
int save_state_init(struct save_state *save, FILE *from, struct logger *log)
{
	struct json_node jtree;
	if (parse_json_tree("save_state", from, log, &jtree)) return -1;
	table_init(&save->complete, 5); // This empty table will be populated.
	if (jtree.kind != JN_MAP) goto end;
	union json_node_data *got;
	if ((got = json_map_get(&jtree, "complete", JN_LIST))) {
		struct json_node_data_list *complete = &got->list;
		for (size_t i = 0; i < complete->n_vals; ++i) {
			struct json_node *node = &complete->vals[i];
			if (node->kind == JN_STRING)
				save_state_mark_complete(save, node->d.str);
		}
	} else if ((got = json_map_get(&jtree, "saves", JN_MAP))) {
		// With the old format, merge all the saves' completed levels
		// into one list.
		table *saves = &got->map;
		const char *UNUSED_VAR(key);
		void **val;
		TABLE_FOR_EACH(saves, key, val) {
			if ((got = json_map_get(*val, "complete", JN_LIST))) {
				struct json_node_data_list *complete =
					&got->list;
				for (size_t i = 0; i < complete->n_vals; ++i) {
					struct json_node *node =
						&complete->vals[i];
					if (node->kind == JN_STRING)
						save_state_mark_complete(save,
							node->d.str);
				}
			}
		}
	}
end:
	free_json_tree(&jtree);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq 0x2f4a(%rip), %rdi      # 0x12250
leaq -0x40(%rbp), %rcx
callq 0x68e0
cmpl $0x0, %eax
je 0xf320
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xf51f
movq -0x10(%rbp), %rdi
movl $0x5, %esi
callq 0xf990
cmpl $0x2, -0x40(%rbp)
je 0xf339
jmp 0xf50f
leaq -0x40(%rbp), %rdi
leaq 0x2f17(%rip), %rsi      # 0x1225b
movl $0x3, %edx
callq 0x6820
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0xf3bb
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xf3b6
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpl $0x4, (%rax)
jne 0xf3a6
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xf530
jmp 0xf3a8
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xf368
jmp 0xf50d
leaq -0x40(%rbp), %rdi
leaq 0x2e9e(%rip), %rsi      # 0x12264
movl $0x2, %edx
callq 0x6820
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0xf50b
movq -0x48(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rcx
movq -0x68(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x99(%rbp)
jae 0xf440
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x80(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x80(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, -0x78(%rbp)
movb $0x1, %al
movb %al, -0x99(%rbp)
movb -0x99(%rbp), %al
testb $0x1, %al
jne 0xf44f
jmp 0xf509
movq -0x78(%rbp), %rax
movq (%rax), %rdi
leaq 0x2dfe(%rip), %rsi      # 0x1225b
movl $0x3, %edx
callq 0x6820
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0xf4f6
movq -0x48(%rbp), %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x88(%rbp), %rcx
cmpq (%rcx), %rax
jae 0xf4f4
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x90(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
cmpl $0x4, (%rax)
jne 0xf4de
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0xf530
jmp 0xf4e0
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0xf48b
jmp 0xf4f6
jmp 0xf4f8
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0xf3ee
jmp 0xf50b
jmp 0xf50d
jmp 0xf50f
leaq -0x40(%rbp), %rdi
callq 0x6e30
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)