// File: /workspace/github_c_makefile_star2_O2/QwazyWabbitWOS[P]lmctf60/g_misc.c
// Function: func_explosive_explode
void func_explosive_explode (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
{
	vec3_t	origin;
	vec3_t	chunkorigin;
	vec3_t	size;
	int		count;
	int		mass;


	//surt, why was this commented out?????
	// bmodel origins are (0 0 0), we need to adjust that here
	VectorScale (self->size, 0.5, size);
	VectorAdd (self->absmin, size, origin);
//	VectorCopy (origin, self->s.origin);
	//surt, don't copy into the ent's origin!  the ent needs to reappear
	//this information is only calculated for the throwdebris!
	

//	VectorCopy(self->s.origin, origin); //surt FIXME put something in origin

	self->takedamage = DAMAGE_NO;

	if (self->dmg)
		T_RadiusDamage (self, attacker, self->dmg, NULL, self->dmg+40, MOD_EXPLOSIVE);
	
	//surt this is commented out because we don't want to screw with
	//self while generating the debris
//	VectorSubtract (self->s.origin, inflictor->s.origin, self->velocity);
//	VectorNormalize (self->velocity);
//	VectorScale (self->velocity, 150, self->velocity);
	
	// start chunks towards the center
	VectorScale (size, 0.5, size);

	mass = self->mass;
	if (!mass)
		mass = 75;

	// big chunks
	if (mass >= 100)
	{
		count = mass / 100;
		if (count > 8)
			count = 8;
		while(count--)
		{
			chunkorigin[0] = origin[0] + crandom() * size[0];
			chunkorigin[1] = origin[1] + crandom() * size[1];
			chunkorigin[2] = origin[2] + crandom() * size[2];
			ThrowDebris (self, "models/objects/debris1/tris.md2", 1, chunkorigin);
		}
	}

	// small chunks
	count = mass / 25;
	if (count > 16)
		count = 16;
	while(count--)
	{
		chunkorigin[0] = origin[0] + crandom() * size[0];
		chunkorigin[1] = origin[1] + crandom() * size[1];
		chunkorigin[2] = origin[2] + crandom() * size[2];
		ThrowDebris (self, "models/objects/debris2/tris.md2", 2, chunkorigin);
	}

	G_UseTargets (self, attacker);

	// LM_JORM -- Support respawning explosive walls
	if (!deathmatch->value)
	{
		if (self->dmg)
			BecomeExplosion1 (self);
		else
			G_FreeEdict (self);
	}
	else
	{
		self->svflags |= SVF_NOCLIENT;
		self->solid = SOLID_NOT;
		self->think = func_explosive_respawn;
		self->nextthink = level.time + self->speed;
	}
	// END LM_JORM

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r13
movq %rdi, %rbx
addq $0xfc, %rdi
movss 0x1eb67(%rip), %xmm0    # 0x50400
leaq 0x10(%rsp), %r15
movq %r15, %rsi
callq 0x18a70
movsd 0xe4(%rbx), %xmm0
movss 0xec(%rbx), %xmm1
addss 0x8(%r15), %xmm1
movss %xmm1, 0x8(%rsp)
movsd (%r15), %xmm1
andl $0x0, 0x27c(%rbx)
movl 0x280(%rbx), %eax
testl %eax, %eax
je 0x31907
movaps %xmm0, 0x20(%rsp)
cvtsi2ss %eax, %xmm0
addl $0x28, %eax
movaps %xmm1, 0x40(%rsp)
cvtsi2ss %eax, %xmm1
pushq $0x19
popq %rcx
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x180c0
movaps 0x40(%rsp), %xmm1
movaps 0x20(%rsp), %xmm0
addps %xmm1, %xmm0
movaps %xmm0, 0x20(%rsp)
pushq $0x19
popq %r14
movss 0x1eae5(%rip), %xmm0    # 0x50400
leaq 0x10(%rsp), %rdi
movq %rdi, %rsi
callq 0x18a70
movl 0x1d8(%rbx), %eax
testl %eax, %eax
pushq $0x4b
popq %rbp
cmovnel %eax, %ebp
cmpl $0x63, %ebp
jle 0x31a4a
movq %r13, 0x50(%rsp)
pushq $0x64
popq %rcx
movl %ebp, %eax
xorl %edx, %edx
divl %ecx
cmpl $0x8, %eax
pushq $0x8
popq %r14
cmovbl %eax, %r14d
cvtps2pd 0x20(%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
cvtss2sd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x21ca3(%rip), %r15     # 0x53618
leaq 0x30(%rsp), %r12
subl $0x1, %r14d
jb 0x31a62
callq 0x19bf0
movl %eax, %r13d
movss 0x10(%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
callq 0x19bf0
movd %r13d, %xmm0
movd %eax, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
pand 0x219bf(%rip), %xmm0    # 0x53370
cvtdq2ps %xmm0, %xmm0
divps 0x219c5(%rip), %xmm0    # 0x53380
cvtps2pd %xmm0, %xmm0
addpd 0x219ca(%rip), %xmm0    # 0x53390
addpd %xmm0, %xmm0
movss 0x14(%rsp), %xmm1
movaps 0x20(%rsp), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
cvtps2pd %xmm2, %xmm1
mulpd %xmm0, %xmm1
addpd 0x40(%rsp), %xmm1
cvtpd2ps %xmm1, %xmm0
movlpd %xmm0, 0x30(%rsp)
callq 0x19bf0
andl $0x7fff, %eax           # imm = 0x7FFF
cvtsi2ss %eax, %xmm0
divss 0x1d883(%rip), %xmm0    # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x201e7(%rip), %xmm0    # 0x51bf8
addsd %xmm0, %xmm0
cvtss2sd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movss 0x1d4eb(%rip), %xmm0    # 0x4ef28
movq %r12, %rdx
callq 0x186e0
jmp 0x3197a
cvtps2pd 0x20(%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
cvtss2sd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
jmp 0x31a6b
movq 0x50(%rsp), %r13
pushq $0x19
popq %r14
movl %ebp, %eax
cltd
idivl %r14d
cmpl $0x10, %eax
pushq $0x10
popq %r14
cmovll %eax, %r14d
leaq 0x20d1e(%rip), %r15     # 0x527a1
leaq 0x30(%rsp), %r12
subl $0x1, %r14d
jb 0x31b56
callq 0x19bf0
movl %eax, %ebp
movss 0x10(%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
callq 0x19bf0
movd %ebp, %xmm0
movd %eax, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
pand 0x218b3(%rip), %xmm0    # 0x53370
cvtdq2ps %xmm0, %xmm0
divps 0x218b9(%rip), %xmm0    # 0x53380
cvtps2pd %xmm0, %xmm0
addpd 0x218be(%rip), %xmm0    # 0x53390
addpd %xmm0, %xmm0
movss 0x14(%rsp), %xmm1
movaps 0x20(%rsp), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
cvtps2pd %xmm2, %xmm1
mulpd %xmm0, %xmm1
addpd 0x40(%rsp), %xmm1
cvtpd2ps %xmm1, %xmm0
movlpd %xmm0, 0x30(%rsp)
callq 0x19bf0
andl $0x7fff, %eax           # imm = 0x7FFF
cvtsi2ss %eax, %xmm0
divss 0x1d777(%rip), %xmm0    # 0x4f288
cvtss2sd %xmm0, %xmm0
addsd 0x200db(%rip), %xmm0    # 0x51bf8
addsd %xmm0, %xmm0
cvtss2sd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x8(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x38(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movss 0x1d923(%rip), %xmm0    # 0x4f46c
movq %r12, %rdx
callq 0x186e0
jmp 0x31a88
movq %rbx, %rdi
movq %r13, %rsi
callq 0x19ac0
movq 0x35358(%rip), %rax     # 0x66ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x31b7a
jnp 0x31bb4
orb $0x1, 0xc8(%rbx)
andl $0x0, 0x108(%rbx)
movq 0x350f1(%rip), %rax     # 0x66c80
movq %rax, 0x210(%rbx)
movq 0x35203(%rip), %rax     # 0x66da0
movss 0x4(%rax), %xmm0
addss 0x190(%rbx), %xmm0
movss %xmm0, 0x200(%rbx)
jmp 0x31bcf
cmpl $0x0, 0x280(%rbx)
je 0x31bc7
movq %rbx, %rdi
callq 0x19780
jmp 0x31bcf
movq %rbx, %rdi
callq 0x19c50
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq