// File: /workspace/github_c_makefile_star2_O2/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 0x6705
movq %rax, %rbx
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x64c4
testq %rax, %rax
je 0x417c
movq %rax, %r12
movq %rbx, 0x28(%rsp)
movq (%rax), %rbx
testq %rbx, %rbx
jne 0x417e
pushq $0x70
popq %rdi
callq 0xa7d0
movq %rax, %rbx
movq %r13, %rdi
callq 0xa554
movq %rax, (%rbx)
andq $0x0, 0x44(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
movups %xmm0, 0x28(%rbx)
orq $-0x1, 0x38(%rbx)
movw $0x1, 0x58(%rbx)
orl $-0x1, 0x5c(%rbx)
movsd 0x6f92(%rip), %xmm0     # 0xb0f0
movupd %xmm0, 0x60(%rbx)
movq 0x40(%rsp), %rsi
movq %rsp, %rcx
movq %r13, %rdi
movq 0x28(%rsp), %rdx
callq 0x4a25
testl %eax, %eax
je 0x4190
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rax
addq $0x18, %rax
movq %rax, 0x38(%rsp)
movl (%rsp), %eax
cmpl $0x2, %eax
je 0x41cb
cmpl $0x7, %eax
je 0x41c2
leaq 0x7150(%rip), %rdx      # 0xb300
pushq $0x2
popq %rsi
movq 0x28(%rsp), %rdi
movq %r13, %rcx
xorl %eax, %eax
callq 0x691c
movq %rbx, (%r12)
jmp 0x4528
leaq 0x7159(%rip), %rsi      # 0xb32b
movq %rsp, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x49e4
testq %rax, %rax
je 0x41f6
movq %rax, %r13
movq (%rbx), %rdi
callq 0x2580
movq (%r13), %rax
movq %rax, (%rbx)
movabsq $0x3ff0000000000000, %r14 # imm = 0x3FF0000000000000
movq %r14, 0x8(%rbx)
leaq 0x7125(%rip), %rsi      # 0xb330
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x4224
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rbx)
movq %r14, 0x10(%rbx)
leaq 0x7107(%rip), %rsi      # 0xb336
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x4248
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rbx)
andq $0x0, 0x50(%rbx)
leaq 0x70e9(%rip), %rsi      # 0xb33d
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x426d
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rbx)
leaq 0x70cf(%rip), %rsi      # 0xb343
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x42a0
movsd (%rax), %xmm0
divsd 0x7060(%rip), %xmm0     # 0xb2f0
mulsd 0x7060(%rip), %xmm0     # 0xb2f8
cvttsd2si %xmm0, %rax
movl %eax, 0x44(%rbx)
leaq 0x70a8(%rip), %rsi      # 0xb34f
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x42d3
movsd (%rax), %xmm0
divsd 0x702d(%rip), %xmm0     # 0xb2f0
mulsd 0x702d(%rip), %xmm0     # 0xb2f8
cvttsd2si %xmm0, %rax
movl %eax, 0x48(%rbx)
movq %r15, 0x20(%rsp)
leaq 0x707d(%rip), %rsi      # 0xb35c
movq %rsp, %rdi
pushq $0x6
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x42f3
movb (%rax), %al
jmp 0x42f5
xorl %eax, %eax
movb %al, 0x40(%rbx)
leaq 0x7070(%rip), %rsi      # 0xb36f
movq %rsp, %rdi
pushq $0x3
popq %rdx
callq 0x49e4
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x43ef
movq 0x30(%rsp), %rax
movq (%rax), %rdi
movq %rdi, 0x18(%rbx)
shlq $0x4, %rdi
callq 0xa7d0
movq %rax, 0x20(%rbx)
pushq $0x8
popq %r15
xorl %r13d, %r13d
movq 0x38(%rsp), %rax
cmpq (%rax), %r13
jae 0x43ef
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rbx), %r14
movq $0x1, (%r14,%r15)
movl -0x10(%rax,%r15,2), %ecx
cmpl $0x3, %ecx
je 0x4393
cmpl $0x4, %ecx
jne 0x43ca
movq -0x8(%rax,%r15,2), %rbp
movb $0x1, -0xc(%rax,%r15,2)
testq %rbp, %rbp
je 0x43ca
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x61b4
movq %rax, -0x8(%r14,%r15)
testq %rax, %rax
jne 0x43db
jmp 0x43cc
cmpq $0x0, -0x8(%rax,%r15,2)
je 0x43ca
movq (%rax,%r15,2), %rcx
cmpl $0x4, (%rcx)
jne 0x43ca
movq 0x8(%rcx), %rbp
movb $0x1, 0x4(%rcx)
cmpq $0x2, -0x8(%rax,%r15,2)
jb 0x4375
movq (%rax,%r15,2), %rax
cmpl $0x5, 0x20(%rax)
jne 0x4375
cvttsd2si 0x28(%rax), %rax
movq %rax, (%r14,%r15)
jmp 0x4375
xorl %ebp, %ebp
movq 0x20(%rsp), %rdi
callq 0x6660
movq %rax, -0x8(%r14,%r15)
movq %rbp, %rdi
callq 0x2580
incq %r13
addq $0x10, %r15
jmp 0x4338
movq %rbx, (%r12)
leaq 0x6f7c(%rip), %rsi      # 0xb376
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x49e4
testq %rax, %rax
movq 0x20(%rsp), %r15
je 0x441e
movq (%rax), %rsi
movq %r15, %rdi
callq 0x40e0
movq %rax, 0x28(%rbx)
leaq 0x6f5d(%rip), %rsi      # 0xb382
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x4444
movq (%rax), %rsi
movq %r15, %rdi
callq 0x40e0
movq %rax, 0x30(%rbx)
leaq 0x6f3e(%rip), %rsi      # 0xb389
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x4464
cvttsd2si (%rax), %rax
movq %rax, 0x38(%rbx)
leaq 0x6f27(%rip), %rsi      # 0xb392
movq %rsp, %rdi
pushq $0x6
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x4484
cmpb $0x0, (%rax)
jne 0x4484
movb $0x0, 0x58(%rbx)
leaq 0x6f12(%rip), %rsi      # 0xb39d
movq %rsp, %rdi
pushq $0x6
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x44a4
cmpb $0x1, (%rax)
jne 0x44a4
movb $0x1, 0x59(%rbx)
leaq 0x6efb(%rip), %rsi      # 0xb3a6
movq %rsp, %rdi
pushq $0x4
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x44e8
movq %rax, %r12
movq (%rax), %rdi
callq 0xa000
movl %eax, 0x5c(%rbx)
cmpl $-0x1, %eax
jne 0x44e8
movq (%r12), %rcx
leaq 0x6edb(%rip), %rdx      # 0xb3b4
pushq $0x2
popq %rsi
movq 0x28(%rsp), %rdi
xorl %eax, %eax
callq 0x691c
leaq 0x6ee2(%rip), %rsi      # 0xb3d1
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x4508
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rbx)
leaq 0x6ec9(%rip), %rsi      # 0xb3d8
movq %rsp, %rdi
pushq $0x5
popq %rdx
callq 0x49e4
testq %rax, %rax
je 0x4528
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rbx)
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x4557
movq 0x20(%rbx), %rdi
pushq $0x10
popq %rsi
callq 0xa8f4
movq %rax, 0x20(%rbx)
movq %r15, %rdi
callq 0x6660
movq 0x20(%rbx), %rcx
movq %rax, (%rcx)
andq $0x0, 0x8(%rcx)
movq %rsp, %rdi
callq 0x4eaf
jmp 0x417e