// File: /workspace/github_c_makefile_star2_O0/QwazyWabbitWOS[P]lmctf60/g_save.c
// Function: WriteField1
void WriteField1(FILE* f, field_t* field, byte* base)
{
	void* p;
	size_t		len;
	int			index;

	if (field->flags & FFL_SPAWNTEMP)
		return;

	p = (void*)(base + field->ofs);
	switch (field->type)
	{
	case F_INT:
	case F_FLOAT:
	case F_ANGLEHACK:
	case F_VECTOR:
	case F_IGNORE:
		break;

	case F_LSTRING:
	case F_GSTRING:
		if (*(char**)p)
			len = strlen(*(char**)p) + 1;
		else
			len = 0;
		*(size_t*)p = len;
		break;
	case F_EDICT:
		if (*(edict_t**)p == NULL)
			index = -1;
		else
			index = *(edict_t**)p - g_edicts;
		*(int*)p = index;
		break;
	case F_CLIENT:
		if (*(gclient_t**)p == NULL)
			index = -1;
		else
			index = *(gclient_t**)p - game.clients;
		*(int*)p = index;
		break;
	case F_ITEM:
		if (*(edict_t**)p == NULL)
			index = -1;
		else
			index = *(gitem_t**)p - itemlist;
		*(int*)p = index;
		break;

		//relative to code segment
	case F_FUNCTION:
		if (*(byte**)p == NULL)
			index = 0;
		else
			index = *(byte**)p - ((byte*)InitGame);
		*(int*)p = index;
		break;

		//relative to data segment
	case F_MMOVE:
		if (*(byte**)p == NULL)
			index = 0;
		else
			index = *(byte**)p - (byte*)&mmove_reloc;
		*(int*)p = index;
		break;

	default:
		gi.error("WriteEdict: unknown field type");
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x494e8
jmp 0x4969c
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq %rax, -0x38(%rbp)
subq $0xb, %rax
ja 0x49689
movq -0x38(%rbp), %rax
leaq 0x2b2b5(%rip), %rcx     # 0x747d0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x4969c
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x49549
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x186e0
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x49551
movq $0x0, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
jmp 0x4969c
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x49574
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x49595
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x38fd6(%rip), %rcx     # 0x82558
movq (%rcx), %rcx
subq %rcx, %rax
movl $0x4a8, %ecx            # imm = 0x4A8
cqto
idivq %rcx
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x4969c
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x495b6
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x495db
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x3977c(%rip), %rcx     # 0x82d40
movq 0x408(%rcx), %rcx
subq %rcx, %rax
movl $0x9140, %ecx           # imm = 0x9140
cqto
idivq %rcx
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x4969c
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x495fc
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
jmp 0x4961a
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x39836(%rip), %rcx     # 0x82e40
subq %rcx, %rax
movl $0x88, %ecx
cqto
idivq %rcx
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x4969c
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x49638
movl $0x0, -0x2c(%rbp)
jmp 0x4964c
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x39042(%rip), %rcx     # 0x82688
subq %rcx, %rax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x4969c
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x4966a
movl $0x0, -0x2c(%rbp)
jmp 0x4967e
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq 0x39310(%rip), %rcx     # 0x82988
subq %rcx, %rax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x4969c
leaq 0x2b6e4(%rip), %rdi     # 0x74d74
movq 0x38f69(%rip), %rcx     # 0x82600
movb $0x0, %al
callq *0x38(%rcx)
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)