// File: /workspace/github_c_makefile_star2_O1/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 0x6e06
movq (%rbx), %rsi
leaq -0xc0(%rbp), %rdi
leaq -0x39(%rbp), %rdx
callq 0x69c6
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
xorl %edx, %edx
callq 0x6e54
leaq -0xb0(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa211
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2230
movl $0x1, %r15d
leaq -0xa0(%rbp), %r13
leaq 0x8e91(%rip), %rbx      # 0x130b6
leaq 0x8e94(%rip), %r14      # 0x130c0
movq %r13, %rdi
callq 0x715e
leal -0x1(%r15), %esi
cmpl %eax, %esi
jge 0xa363
movq %r13, %rdi
callq 0x7190
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x20d0
testl %eax, %eax
je 0xa2cf
movq %r12, %rdi
movq %r14, %rsi
callq 0x20d0
testl %eax, %eax
je 0xa2e0
movq %r12, %rdi
leaq 0x8e58(%rip), %rsi      # 0x130cb
callq 0x20d0
testl %eax, %eax
je 0xa303
movq %r12, %rdi
leaq 0x8e51(%rip), %rsi      # 0x130db
callq 0x20d0
testl %eax, %eax
jne 0xa2fa
movq %r13, %rdi
movl %r15d, %esi
callq 0x7190
movq (%rax), %rdi
leaq 0x8e30(%rip), %rsi      # 0x130d8
leaq -0x2c(%rbp), %rdx
xorl %eax, %eax
callq 0x2200
movss -0x2c(%rbp), %xmm0
addss 0x8948(%rip), %xmm0     # 0x12c08
mulss 0x8944(%rip), %xmm0     # 0x12c0c
movss %xmm0, -0x2c(%rbp)
jmp 0xa2fa
movq %r13, %rdi
movl %r15d, %esi
callq 0x7190
leaq -0x68(%rbp), %rdi
jmp 0xa2f2
movq %r13, %rdi
movl %r15d, %esi
callq 0x7190
leaq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x2140
addl $0x2, %r15d
jmp 0xa22c
movq %r13, %rdi
movl %r15d, %esi
callq 0x7190
movq (%rax), %rdi
leaq 0x8dba(%rip), %rsi      # 0x130d2
leaq -0x38(%rbp), %rdx
leaq -0x34(%rbp), %rcx
leaq -0x30(%rbp), %r8
xorl %eax, %eax
callq 0x2200
movss -0x38(%rbp), %xmm0
movss 0x88c8(%rip), %xmm2     # 0x12c00
mulss %xmm2, %xmm0
movss %xmm0, -0x38(%rbp)
movss -0x34(%rbp), %xmm0
movss -0x30(%rbp), %xmm1
mulss %xmm2, %xmm1
movss %xmm1, -0x34(%rbp)
mulss 0x88a8(%rip), %xmm0     # 0x12c04
movss %xmm0, -0x30(%rbp)
jmp 0xa2fa
leaq 0x8d77(%rip), %rsi      # 0x130e1
leaq -0x68(%rbp), %rdi
callq 0x20d0
testl %eax, %eax
jne 0xa3bb
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 0x8d4f(%rip), %rsi      # 0x130f1
movq -0x48(%rbp), %rdi
movl $0x22, %ecx
movq %rdx, %r8
movl $0x22, %r9d
movb $0x4, %al
callq 0x2300
leaq 0x8d9a(%rip), %rsi      # 0x1315c
leaq -0x68(%rbp), %rdi
callq 0x20d0
testl %eax, %eax
jne 0xa410
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 0x8cfe(%rip), %rsi      # 0x130f8
movq -0x48(%rbp), %rdi
movl $0x22, %edx
movl $0x22, %r8d
movb $0x4, %al
callq 0x2300
leaq -0xa0(%rbp), %rdi
callq 0x70de
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xa438
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xa451
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 0xa493
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2230
jmp 0xa493
jmp 0xa490
movq %rax, %rbx
jmp 0xa49f
jmp 0xa490
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x70de
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0xa4bb
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2230
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0xa4d4
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2230
movq %rbx, %rdi
callq 0x23c0