// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
movq %rdx, %r14
movq %rdi, %rbx
addq $0xfc, %rdi
movss 0x1ff29(%rip), %xmm0    # 0x54400
leaq 0x8(%rsp), %r15
movq %r15, %rsi
callq 0x189d0
movsd 0xe4(%rbx), %xmm0
movss 0xec(%rbx), %xmm1
addss 0x8(%r15), %xmm1
movss %xmm1, 0x4(%rsp)
movsd (%r15), %xmm1
movl $0x0, 0x27c(%rbx)
movl 0x280(%rbx), %eax
testl %eax, %eax
je 0x34550
movaps %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
addl $0x28, %eax
movaps %xmm1, 0x30(%rsp)
xorps %xmm1, %xmm1
cvtsi2ss %eax, %xmm1
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movl $0x19, %ecx
callq 0x180c0
movaps 0x30(%rsp), %xmm1
movaps 0x40(%rsp), %xmm0
movq %r14, 0x60(%rsp)
addps %xmm1, %xmm0
movaps %xmm0, 0x40(%rsp)
movss 0x1fe9b(%rip), %xmm0    # 0x54400
leaq 0x8(%rsp), %rdi
movq %rdi, %rsi
callq 0x189d0
movl 0x1d8(%rbx), %eax
testl %eax, %eax
movl $0x4b, %r13d
cmovnel %eax, %r13d
cmpl $0x64, %r13d
jl 0x3469f
movl %r13d, %eax
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
shrq $0x25, %rax
cmpl $0x8, %eax
movl $0x8, %r14d
cmovbl %eax, %r14d
cvtps2pd 0x40(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x4(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x2306f(%rip), %r15     # 0x57638
leaq 0x20(%rsp), %r12
callq 0x19a10
movl %eax, %ebp
movss 0x8(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
callq 0x19a10
movd %ebp, %xmm0
movd %eax, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
pand 0x22d97(%rip), %xmm0    # 0x57390
cvtdq2ps %xmm0, %xmm0
divps 0x22d9d(%rip), %xmm0    # 0x573a0
cvtps2pd %xmm0, %xmm0
addpd 0x22da2(%rip), %xmm0    # 0x573b0
addpd %xmm0, %xmm0
movss 0xc(%rsp), %xmm1
movaps 0x30(%rsp), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
cvtps2pd %xmm2, %xmm1
mulpd %xmm0, %xmm1
addpd 0x50(%rsp), %xmm1
cvtpd2ps %xmm1, %xmm0
movlpd %xmm0, 0x20(%rsp)
callq 0x19a10
andl $0x7fff, %eax           # imm = 0x7FFF
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x1ec38(%rip), %xmm0    # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x215bc(%rip), %xmm0    # 0x55c18
addsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x18(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x28(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movss 0x1e89a(%rip), %xmm0    # 0x52f28
movq %r12, %rdx
callq 0x186a0
decl %r14d
jne 0x345ce
leal 0x18(%r13), %eax
cmpl $0x31, %eax
jb 0x347c6
movslq %r13d, %rax
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x23, %rax
addl %ecx, %eax
cmpl $0x10, %eax
movl $0x10, %r14d
cmovll %eax, %r14d
cvtps2pd 0x40(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x4(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
leaq 0x220d1(%rip), %r15     # 0x567c1
leaq 0x20(%rsp), %r12
callq 0x19a10
movl %eax, %ebp
movss 0x8(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
callq 0x19a10
movd %ebp, %xmm0
movd %eax, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
pand 0x22c70(%rip), %xmm0    # 0x57390
cvtdq2ps %xmm0, %xmm0
divps 0x22c76(%rip), %xmm0    # 0x573a0
cvtps2pd %xmm0, %xmm0
addpd 0x22c7b(%rip), %xmm0    # 0x573b0
addpd %xmm0, %xmm0
movss 0xc(%rsp), %xmm1
movaps 0x30(%rsp), %xmm2
unpcklps %xmm1, %xmm2            # xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
cvtps2pd %xmm2, %xmm1
mulpd %xmm0, %xmm1
addpd 0x50(%rsp), %xmm1
cvtpd2ps %xmm1, %xmm0
movlpd %xmm0, 0x20(%rsp)
callq 0x19a10
andl $0x7fff, %eax           # imm = 0x7FFF
xorps %xmm0, %xmm0
cvtsi2ss %eax, %xmm0
divss 0x1eb11(%rip), %xmm0    # 0x53288
cvtss2sd %xmm0, %xmm0
addsd 0x21495(%rip), %xmm0    # 0x55c18
addsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtss2sd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x18(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x28(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movss 0x1ecb7(%rip), %xmm0    # 0x5346c
movq %r12, %rdx
callq 0x186a0
decl %r14d
jne 0x346f5
movq %rbx, %rdi
movq 0x60(%rsp), %rsi
callq 0x198e0
movq 0x346e6(%rip), %rax     # 0x68ec0
movq (%rax), %rax
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x347ec
jnp 0x34829
orb $0x1, 0xc8(%rbx)
movl $0x0, 0x108(%rbx)
movq 0x3447c(%rip), %rax     # 0x68c80
movq %rax, 0x210(%rbx)
movq 0x3458e(%rip), %rax     # 0x68da0
movss 0x4(%rax), %xmm0
addss 0x190(%rbx), %xmm0
movss %xmm0, 0x200(%rbx)
jmp 0x34844
cmpl $0x0, 0x280(%rbx)
je 0x3483c
movq %rbx, %rdi
callq 0x195c0
jmp 0x34844
movq %rbx, %rdi
callq 0x19a50
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq