// File: /workspace/github_c_makefile_star2_O1/TurkeyMcMac[P]ts3d/src/ent.c
// Function: load_ent_type
struct ent_type *load_ent_type(struct loader *ldr, const char *name)
{
	struct logger *log = loader_logger(ldr);
	FILE *file;
	struct ent_type *ent, **entp;
	entp = loader_ent(ldr, name, &file);
	if (!entp) return NULL;
	ent = *entp;
	if (ent) return ent;
	ent = xmalloc(sizeof(*ent));
	struct json_node jtree;
	ent->name = str_dup(name);
	ent->frames = NULL;
	ent->n_frames = 0;
	ent->turn_chance = CHANCE_NEVER;
	ent->shoot_chance = CHANCE_NEVER;
	ent->death_spawn = NULL;
	ent->bullet = NULL;
	ent->lifetime = -1;
	ent->wall_block = true;
	ent->wall_die = false;
	ent->team_override = TEAM_INVALID;
	ent->health = 1.0;
	ent->damage = 0;
	if (parse_json_tree(name, file, log, &jtree)) return NULL;
	if (jtree.kind != JN_MAP) {
		if (jtree.kind != JN_ERROR)
			logger_printf(log, LOGGER_WARNING,
				"Entity type \"%s\" is not a JSON dictionary\n",
				name);
		*entp = ent;
		goto end;
	}
	union json_node_data *got;
	if ((got = json_map_get(&jtree, "name", TAKE_NODE | JN_STRING))) {
		free(ent->name);
		ent->name = got->str;
	}
	ent->width = 1.0;
	if ((got = json_map_get(&jtree, "width", JN_NUMBER)))
		ent->width = got->num;
	ent->height = 1.0;
	if ((got = json_map_get(&jtree, "height", JN_NUMBER)))
		ent->height = got->num;
	ent->speed = 0.0;
	if ((got = json_map_get(&jtree, "speed", JN_NUMBER)))
		ent->speed = got->num;
	if ((got = json_map_get(&jtree, "turn_chance", JN_NUMBER)))
		ent->turn_chance = chance_from_percent(got->num);
	if ((got = json_map_get(&jtree, "shoot_chance", JN_NUMBER)))
		ent->shoot_chance = chance_from_percent(got->num);
	ent->random_start_frame =
		(got = json_map_get(&jtree, "random_start_frame", JN_BOOLEAN))
		&& got->boolean;
	if ((got = json_map_get(&jtree, "frames", JN_LIST))) {
		ent->n_frames = got->list.n_vals;
		ent->frames = xmalloc(ent->n_frames * sizeof(*ent->frames));
		for (size_t i = 0; i < ent->n_frames; ++i) {
			parse_frame(&got->list.vals[i], &ent->frames[i], ldr);
		}
	}
	// To prevent infinite recursion with infinite cycles.
	*entp = ent;
	if ((got = json_map_get(&jtree, "death_spawn", JN_STRING)))
		ent->death_spawn = load_ent_type(ldr, got->str);
	if ((got = json_map_get(&jtree, "bullet", JN_STRING)))
		ent->bullet = load_ent_type(ldr, got->str);
	if ((got = json_map_get(&jtree, "lifetime", JN_NUMBER)))
		ent->lifetime = got->num;
	if ((got = json_map_get(&jtree, "wall_block", JN_BOOLEAN))
	 && !got->boolean)
		ent->wall_block = false;
	if ((got = json_map_get(&jtree, "wall_die", JN_BOOLEAN))
	 && got->boolean)
		ent->wall_die = true;
	if ((got = json_map_get(&jtree, "team_override", JN_STRING))
	 && (ent->team_override = team_from_str(got->str)) == TEAM_INVALID)
		logger_printf(log, LOGGER_WARNING,
			"Invalid team override: \"%s\"\n", got->str);
	if ((got = json_map_get(&jtree, "health", JN_NUMBER)))
		ent->health = got->num;
	if ((got = json_map_get(&jtree, "damage", JN_NUMBER)))
		ent->damage = got->num;
end:
	if (ent->n_frames == 0) {
		ent->frames = xrealloc(ent->frames, sizeof(*ent->frames));
		ent->frames[0].txtr = loader_empty_texture(ldr);
		ent->frames[0].duration = 0;
	}
	free_json_tree(&jtree);
	return ent;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r13
movq %rdi, %r15
callq 0x6c5a
movq %rax, %rbx
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x6a04
testq %rax, %rax
je 0x43ed
movq %rax, %r12
movq (%rax), %rbp
testq %rbp, %rbp
jne 0x43ef
movl $0x70, %edi
callq 0xb1ac
movq %rax, %r14
movq %r13, %rdi
callq 0xaec0
movq %rax, (%r14)
xorl %ebp, %ebp
movq %rbp, 0x44(%r14)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x18(%r14)
movupd %xmm0, 0x28(%r14)
movq $-0x1, 0x38(%r14)
movb $0x1, 0x58(%r14)
movb $0x0, 0x59(%r14)
movl $0xffffffff, 0x5c(%r14) # imm = 0xFFFFFFFF
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x60(%r14)
movq %rbp, 0x68(%r14)
movq 0x40(%rsp), %rsi
movq %rsp, %rcx
movq %r13, %rdi
movq %rbx, %rdx
callq 0x4cd9
testl %eax, %eax
jne 0x43ef
movabsq $0x3ff0000000000000, %rbp # imm = 0x3FF0000000000000
movq %rbx, 0x28(%rsp)
movq %r14, %rax
addq $0x18, %rax
movq %rax, 0x38(%rsp)
movl (%rsp), %eax
cmpl $0x2, %eax
je 0x4401
cmpl $0x7, %eax
je 0x43e4
leaq 0x7ef0(%rip), %rdx      # 0xc2c0
movq 0x28(%rsp), %rdi
movl $0x2, %esi
movq %r13, %rcx
xorl %eax, %eax
callq 0x6e97
movq %r14, (%r12)
jmp 0x478a
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7ee3(%rip), %rsi      # 0xc2eb
movq %rsp, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x4c98
testq %rax, %rax
je 0x442c
movq %rax, %r13
movq (%r14), %rdi
callq 0x2570
movq (%r13), %rax
movq %rax, (%r14)
movq %rbp, 0x8(%r14)
leaq 0x7eb9(%rip), %rsi      # 0xc2f0
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4c98
testq %rax, %rax
je 0x4453
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%r14)
movq %rbp, 0x10(%r14)
leaq 0x7e98(%rip), %rsi      # 0xc2f6
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4c98
testq %rax, %rax
je 0x447a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%r14)
movq $0x0, 0x50(%r14)
leaq 0x7e74(%rip), %rsi      # 0xc2fd
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4c98
testq %rax, %rax
je 0x44a5
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%r14)
leaq 0x7e57(%rip), %rsi      # 0xc303
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4c98
testq %rax, %rax
je 0x44db
movsd (%rax), %xmm0
divsd 0x7de6(%rip), %xmm0     # 0xc2b0
mulsd 0x7de6(%rip), %xmm0     # 0xc2b8
cvttsd2si %xmm0, %rax
movl %eax, 0x44(%r14)
leaq 0x7e2d(%rip), %rsi      # 0xc30f
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4c98
testq %rax, %rax
je 0x4511
movsd (%rax), %xmm0
divsd 0x7db0(%rip), %xmm0     # 0xc2b0
mulsd 0x7db0(%rip), %xmm0     # 0xc2b8
cvttsd2si %xmm0, %rax
movl %eax, 0x48(%r14)
leaq 0x7e04(%rip), %rsi      # 0xc31c
movq %rsp, %rdi
movl $0x6, %edx
callq 0x4c98
testq %rax, %rax
movq %r15, 0x20(%rsp)
je 0x4533
movb (%rax), %al
jmp 0x4535
xorl %eax, %eax
movb %al, 0x40(%r14)
leaq 0x7def(%rip), %rsi      # 0xc32f
movq %rsp, %rdi
movl $0x3, %edx
callq 0x4c98
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x463a
movq 0x30(%rsp), %rax
movq (%rax), %rdi
movq %rdi, 0x18(%r14)
shlq $0x4, %rdi
callq 0xb1ac
movq %rax, 0x20(%r14)
cmpq $0x0, 0x18(%r14)
je 0x463a
movl $0x8, %r15d
xorl %r13d, %r13d
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%r14), %rbx
movq $0x1, (%rbx,%r15)
movl -0x10(%rax,%r15,2), %ecx
cmpl $0x3, %ecx
je 0x45b9
cmpl $0x4, %ecx
jne 0x45f0
movq -0x8(%rax,%r15,2), %rbp
movb $0x1, -0xc(%rax,%r15,2)
jmp 0x45f2
cmpq $0x0, -0x8(%rax,%r15,2)
je 0x45f0
movq (%rax,%r15,2), %rcx
cmpl $0x4, (%rcx)
jne 0x45f0
movq 0x8(%rcx), %rbp
movb $0x1, 0x4(%rcx)
cmpq $0x2, -0x8(%rax,%r15,2)
jb 0x45f2
movq (%rax,%r15,2), %rax
cmpl $0x5, 0x20(%rax)
jne 0x45f2
cvttsd2si 0x28(%rax), %rax
movq %rax, (%rbx,%r15)
jmp 0x45f2
xorl %ebp, %ebp
testq %rbp, %rbp
je 0x460e
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x66c4
movq %rax, -0x8(%rbx,%r15)
testq %rax, %rax
jne 0x461d
movq 0x20(%rsp), %rdi
callq 0x6baf
movq %rax, -0x8(%rbx,%r15)
movq %rbp, %rdi
callq 0x2570
incq %r13
addq $0x10, %r15
movq 0x38(%rsp), %rax
cmpq (%rax), %r13
jb 0x4588
movq %r14, (%r12)
leaq 0x7cf1(%rip), %rsi      # 0xc336
movq %rsp, %rdi
movl $0x4, %edx
callq 0x4c98
testq %rax, %rax
movq 0x20(%rsp), %r15
je 0x466b
movq (%rax), %rsi
movq %r15, %rdi
callq 0x42ec
movq %rax, 0x28(%r14)
leaq 0x7cd0(%rip), %rsi      # 0xc342
movq %rsp, %rdi
movl $0x4, %edx
callq 0x4c98
testq %rax, %rax
je 0x4693
movq (%rax), %rsi
movq %r15, %rdi
callq 0x42ec
movq %rax, 0x30(%r14)
leaq 0x7caf(%rip), %rsi      # 0xc349
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4c98
testq %rax, %rax
je 0x46b5
cvttsd2si (%rax), %rax
movq %rax, 0x38(%r14)
leaq 0x7c96(%rip), %rsi      # 0xc352
movq %rsp, %rdi
movl $0x6, %edx
callq 0x4c98
testq %rax, %rax
je 0x46d8
cmpb $0x0, (%rax)
jne 0x46d8
movb $0x0, 0x58(%r14)
leaq 0x7c7e(%rip), %rsi      # 0xc35d
movq %rsp, %rdi
movl $0x6, %edx
callq 0x4c98
testq %rax, %rax
je 0x46fb
cmpb $0x1, (%rax)
jne 0x46fb
movb $0x1, 0x59(%r14)
leaq 0x7c64(%rip), %rsi      # 0xc366
movq %rsp, %rdi
movl $0x4, %edx
callq 0x4c98
testq %rax, %rax
je 0x4744
movq %rax, %r12
movq (%rax), %rdi
callq 0xa920
movl %eax, 0x5c(%r14)
cmpl $-0x1, %eax
jne 0x4744
movq (%r12), %rcx
leaq 0x7c41(%rip), %rdx      # 0xc374
movq 0x28(%rsp), %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x6e97
leaq 0x7c46(%rip), %rsi      # 0xc391
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4c98
testq %rax, %rax
je 0x4767
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%r14)
leaq 0x7c2a(%rip), %rsi      # 0xc398
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4c98
testq %rax, %rax
je 0x478a
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%r14)
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x47be
movq 0x20(%r14), %rdi
movl $0x10, %esi
callq 0xb2d4
movq %rax, 0x20(%r14)
movq %r15, %rdi
callq 0x6baf
movq 0x20(%r14), %rcx
movq %rax, (%rcx)
movq $0x0, 0x8(%rcx)
movq %rsp, %rdi
callq 0x5222
movq %r14, %rbp
jmp 0x43ef