// File: /workspace/github_c_makefile_star2_O3/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, %r14
callq 0x6c2a
movq %rax, %r15
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x69d4
testq %rax, %rax
je 0x43dc
movq %rax, %r12
movq (%rax), %rbx
testq %rbx, %rbx
jne 0x43de
movl $0x70, %edi
callq 0xb080
movq %rax, %rbx
movq %r13, %rdi
callq 0xada8
movq %rax, (%rbx)
movq $0x0, 0x44(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rbx)
movups %xmm0, 0x28(%rbx)
movq $-0x1, 0x38(%rbx)
movw $0x1, 0x58(%rbx)
movl $0xffffffff, 0x5c(%rbx) # imm = 0xFFFFFFFF
movsd 0x7d48(%rip), %xmm0     # 0xc108
movupd %xmm0, 0x60(%rbx)
movq 0x40(%rsp), %rsi
movq %rsp, %rcx
movq %r13, %rdi
movq %r15, %rdx
callq 0x4cfd
testl %eax, %eax
je 0x43f0
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, 0x30(%rsp)
movl (%rsp), %eax
cmpl $0x2, %eax
je 0x442b
cmpl $0x7, %eax
je 0x4422
leaq 0x7f20(%rip), %rdx      # 0xc330
movq %r15, %rdi
movl $0x2, %esi
movq %r13, %rcx
xorl %eax, %eax
callq 0x6e50
movq %rbx, (%r12)
jmp 0x47bb
movq %r14, 0x20(%rsp)
leaq 0x7f24(%rip), %rsi      # 0xc35b
movq %rsp, %rdi
movl $0x1004, %edx           # imm = 0x1004
callq 0x4cbc
testq %rax, %rax
je 0x445b
movq %rax, %r13
movq (%rbx), %rdi
callq 0x2570
movq (%r13), %rax
movq %rax, (%rbx)
movabsq $0x3ff0000000000000, %r14 # imm = 0x3FF0000000000000
movq %r14, 0x8(%rbx)
leaq 0x7ef0(%rip), %rsi      # 0xc360
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4cbc
testq %rax, %rax
je 0x448b
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rbx)
movq %r14, 0x10(%rbx)
leaq 0x7ed0(%rip), %rsi      # 0xc366
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4cbc
testq %rax, %rax
je 0x44b1
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rbx)
movq $0x0, 0x50(%rbx)
leaq 0x7ead(%rip), %rsi      # 0xc36d
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4cbc
testq %rax, %rax
je 0x44db
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rbx)
leaq 0x7e91(%rip), %rsi      # 0xc373
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4cbc
testq %rax, %rax
je 0x4510
movsd (%rax), %xmm0
divsd 0x7e20(%rip), %xmm0     # 0xc320
mulsd 0x7e20(%rip), %xmm0     # 0xc328
cvttsd2si %xmm0, %rax
movl %eax, 0x44(%rbx)
leaq 0x7e68(%rip), %rsi      # 0xc37f
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4cbc
testq %rax, %rax
je 0x4545
movsd (%rax), %xmm0
divsd 0x7deb(%rip), %xmm0     # 0xc320
mulsd 0x7deb(%rip), %xmm0     # 0xc328
cvttsd2si %xmm0, %rax
movl %eax, 0x48(%rbx)
movq %r15, 0x38(%rsp)
leaq 0x7e3b(%rip), %rsi      # 0xc38c
movq %rsp, %rdi
movl $0x6, %edx
callq 0x4cbc
testq %rax, %rax
je 0x4567
movb (%rax), %al
jmp 0x4569
xorl %eax, %eax
movb %al, 0x40(%rbx)
leaq 0x7e2c(%rip), %rsi      # 0xc39f
movq %rsp, %rdi
movl $0x3, %edx
callq 0x4cbc
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x466d
movq 0x28(%rsp), %rax
movq (%rax), %rdi
movq %rdi, 0x18(%rbx)
shlq $0x4, %rdi
callq 0xb080
movq %rax, 0x20(%rbx)
cmpq $0x0, 0x18(%rbx)
je 0x466d
movl $0x8, %r15d
xorl %r13d, %r13d
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rbx), %r14
movq $0x1, (%r14,%r15)
movl -0x10(%rax,%r15,2), %ecx
cmpl $0x3, %ecx
je 0x4608
cmpl $0x4, %ecx
jne 0x463f
movq -0x8(%rax,%r15,2), %rbp
movb $0x1, -0xc(%rax,%r15,2)
testq %rbp, %rbp
je 0x463f
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x6690
movq %rax, -0x8(%r14,%r15)
testq %rax, %rax
jne 0x4650
jmp 0x4641
cmpq $0x0, -0x8(%rax,%r15,2)
je 0x463f
movq (%rax,%r15,2), %rcx
cmpl $0x4, (%rcx)
jne 0x463f
movq 0x8(%rcx), %rbp
movb $0x1, 0x4(%rcx)
cmpq $0x2, -0x8(%rax,%r15,2)
jb 0x45ea
movq (%rax,%r15,2), %rax
cmpl $0x5, 0x20(%rax)
jne 0x45ea
cvttsd2si 0x28(%rax), %rax
movq %rax, (%r14,%r15)
jmp 0x45ea
xorl %ebp, %ebp
movq 0x20(%rsp), %rdi
callq 0x6b7f
movq %rax, -0x8(%r14,%r15)
movq %rbp, %rdi
callq 0x2570
incq %r13
addq $0x10, %r15
movq 0x30(%rsp), %rax
cmpq (%rax), %r13
jb 0x45bb
movq %rbx, (%r12)
leaq 0x7d2e(%rip), %rsi      # 0xc3a6
movq %rsp, %rdi
movl $0x4, %edx
callq 0x4cbc
testq %rax, %rax
movq 0x20(%rsp), %r14
je 0x469e
movq (%rax), %rsi
movq %r14, %rdi
callq 0x433c
movq %rax, 0x28(%rbx)
leaq 0x7d0d(%rip), %rsi      # 0xc3b2
movq %rsp, %rdi
movl $0x4, %edx
callq 0x4cbc
testq %rax, %rax
movq 0x38(%rsp), %r15
je 0x46cb
movq (%rax), %rsi
movq %r14, %rdi
callq 0x433c
movq %rax, 0x30(%rbx)
leaq 0x7ce7(%rip), %rsi      # 0xc3b9
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4cbc
testq %rax, %rax
je 0x46ed
cvttsd2si (%rax), %rax
movq %rax, 0x38(%rbx)
leaq 0x7cce(%rip), %rsi      # 0xc3c2
movq %rsp, %rdi
movl $0x6, %edx
callq 0x4cbc
testq %rax, %rax
je 0x470f
cmpb $0x0, (%rax)
jne 0x470f
movb $0x0, 0x58(%rbx)
leaq 0x7cb7(%rip), %rsi      # 0xc3cd
movq %rsp, %rdi
movl $0x6, %edx
callq 0x4cbc
testq %rax, %rax
je 0x4731
cmpb $0x1, (%rax)
jne 0x4731
movb $0x1, 0x59(%rbx)
leaq 0x7c9e(%rip), %rsi      # 0xc3d6
movq %rsp, %rdi
movl $0x4, %edx
callq 0x4cbc
testq %rax, %rax
je 0x4777
movq %rax, %r12
movq (%rax), %rdi
callq 0xa808
movl %eax, 0x5c(%rbx)
cmpl $-0x1, %eax
jne 0x4777
movq (%r12), %rcx
leaq 0x7c7c(%rip), %rdx      # 0xc3e4
movq %r15, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x6e50
leaq 0x7c83(%rip), %rsi      # 0xc401
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4cbc
testq %rax, %rax
je 0x4799
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rbx)
leaq 0x7c68(%rip), %rsi      # 0xc408
movq %rsp, %rdi
movl $0x5, %edx
callq 0x4cbc
testq %rax, %rax
je 0x47bb
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rbx)
movq 0x30(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x47ef
movq 0x20(%rbx), %rdi
movl $0x10, %esi
callq 0xb1a8
movq %rax, 0x20(%rbx)
movq %r14, %rdi
callq 0x6b7f
movq 0x20(%rbx), %rcx
movq %rax, (%rcx)
movq $0x0, 0x8(%rcx)
movq %rsp, %rdi
callq 0x5215
jmp 0x43de