// File: /workspace/github_c_makefile_star2_O3/vlenhart[P]q3bsp/q3bsp.cpp
// Function: Quake3BSP::SaveEntity(EntityReference const&, _IO_FILE*, VFormatOptions&) const
void Quake3BSP::SaveEntity(const EntityReference &entity,
						   FILE *f
						   ,VFormatOptions &options
						   ) const
{
   
   std::string classname;
   std::string targetname;
   float angle = 0;
   vec3_t origin;
   // targetname	
   // model
   // dmg
   // spawnflags
   //_color
   //message
   //music
 
  ArgList args;
  
  args.Set( entity.mBody.c_str(),false); // crunch it into arguments.
  // now ready to process it as a series of arguments!

  int argi=0;
  while (argi < args.size()) 
  {
	String&  key = args[argi];
	
	argi++;

	if (key == "classname") {
		classname = args[argi];
		argi++;
	}
	else if (key == "targetname") {
		targetname = args[argi];
		argi++;
	}
	else if (key == "origin") {
		sscanf(args[argi].c_str(),"%f %f %f",&origin[0],&origin[1],&origin[2]);
		options.MapVertex(origin);
		argi++;
	}
	else if (key == "angle") {
		sscanf(args[argi].c_str(),"%f",&angle);
		angle -=90;
		angle *= (float)Q_PI/180.0f;

		argi++;
	}
	else {
		argi += 1;
	}

  }	

  //
  // info_player_intermission
  if (classname == "target_position") {
	  fprintf(f,"DEF %s Viewpoint { position %g %g %g fieldOfView 1.0 jump TRUE orientation 0 1 0 %g\n\tdescription %c%s%c }\n",targetname.c_str(),origin[0],origin[1],origin[2],angle,'"',targetname.c_str(),'"');
  }	
  if (classname == "info_player_deathmatch") {
	  fprintf(f,"Viewpoint { position %g %g %g fieldOfView 1.0 jump TRUE orientation 0 1 0 %g\n\tdescription %c%s%c }\n",origin[0],origin[1],origin[2],angle,'"',classname.c_str(),'"');
  }	
  // worldspawn	
  //misc_model .. model


}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, -0x48(%rbp)
movq %rsi, %rbx
leaq -0x58(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x78(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movl $0x0, -0x2c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x6e22
movq (%rbx), %rsi
leaq -0xc0(%rbp), %rdi
leaq -0x39(%rbp), %rdx
callq 0x69f2
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
xorl %edx, %edx
callq 0x6e70
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa12b
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2230
movl $0x1, %r15d
leaq -0xa0(%rbp), %r13
leaq 0x8f51(%rip), %rbx      # 0x13090
leaq 0x8f54(%rip), %r14      # 0x1309a
movq %r13, %rdi
callq 0x7132
leal -0x1(%r15), %esi
cmpl %eax, %esi
jge 0xa27d
movq %r13, %rdi
callq 0x7164
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x20d0
testl %eax, %eax
je 0xa1e9
movq %r12, %rdi
movq %r14, %rsi
callq 0x20d0
testl %eax, %eax
je 0xa1fa
movq %r12, %rdi
leaq 0x8f18(%rip), %rsi      # 0x130a5
callq 0x20d0
testl %eax, %eax
je 0xa21d
movq %r12, %rdi
leaq 0x8f11(%rip), %rsi      # 0x130b5
callq 0x20d0
testl %eax, %eax
jne 0xa214
movq %r13, %rdi
movl %r15d, %esi
callq 0x7164
movq (%rax), %rdi
leaq 0x8ef0(%rip), %rsi      # 0x130b2
leaq -0x2c(%rbp), %rdx
xorl %eax, %eax
callq 0x2200
movss -0x2c(%rbp), %xmm0
addss 0x8a1e(%rip), %xmm0     # 0x12bf8
mulss 0x8a1a(%rip), %xmm0     # 0x12bfc
movss %xmm0, -0x2c(%rbp)
jmp 0xa214
movq %r13, %rdi
movl %r15d, %esi
callq 0x7164
leaq -0x68(%rbp), %rdi
jmp 0xa20c
movq %r13, %rdi
movl %r15d, %esi
callq 0x7164
leaq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x2140
addl $0x2, %r15d
jmp 0xa146
movq %r13, %rdi
movl %r15d, %esi
callq 0x7164
movq (%rax), %rdi
leaq 0x8e7a(%rip), %rsi      # 0x130ac
leaq -0x38(%rbp), %rdx
leaq -0x34(%rbp), %rcx
leaq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x2200
movss -0x38(%rbp), %xmm0
movss 0x899e(%rip), %xmm2     # 0x12bf0
mulss %xmm2, %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x34(%rbp), %xmm0
movss -0x30(%rbp), %xmm1
mulss %xmm2, %xmm1
movss %xmm1, -0x34(%rbp)
mulss 0x897e(%rip), %xmm0     # 0x12bf4
movss %xmm0, -0x30(%rbp)
jmp 0xa214
leaq 0x8e37(%rip), %rsi      # 0x130bb
leaq -0x68(%rbp), %rdi
callq 0x20d0
testl %eax, %eax
jne 0xa2d5
movq -0x88(%rbp), %rdx
xorps %xmm0, %xmm0
cvtss2sd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0x34(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd -0x30(%rbp), %xmm2
cvtss2sd -0x2c(%rbp), %xmm3
leaq 0x8e0f(%rip), %rsi      # 0x130cb
movq -0x48(%rbp), %rdi
movl $0x22, %ecx
movq %rdx, %r8
movl $0x22, %r9d
movb $0x4, %al
callq 0x2300
leaq 0x8e5a(%rip), %rsi      # 0x13136
leaq -0x68(%rbp), %rdi
callq 0x20d0
testl %eax, %eax
jne 0xa32a
xorps %xmm0, %xmm0
cvtss2sd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
cvtss2sd -0x34(%rbp), %xmm1
xorps %xmm2, %xmm2
cvtss2sd -0x30(%rbp), %xmm2
xorps %xmm3, %xmm3
cvtss2sd -0x2c(%rbp), %xmm3
movq -0x68(%rbp), %rcx
leaq 0x8dbe(%rip), %rsi      # 0x130d2
movq -0x48(%rbp), %rdi
movl $0x22, %edx
movl $0x22, %r8d
movb $0x4, %al
callq 0x2300
leaq -0xa0(%rbp), %rdi
callq 0x70b2
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xa352
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xa36b
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2230
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa3ad
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2230
jmp 0xa3ad
jmp 0xa3aa
movq %rax, %rbx
jmp 0xa3b9
jmp 0xa3aa
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x70b2
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xa3d5
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xa3ee
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x23c0