// File: gjoni[P]iPot/src/Chain.cpp
// Function: Chain::Save(char const*)
void Chain::Save(const char *name) {

	FILE *F = fopen(name, "w");
	if (F == NULL) {
		fprintf(stderr, "ERROR: Cannot write to file '%s'\n", name);
		return;
	}
	Atom *A;
	for (int i = 0; i < nRes; ++i) {
		for (int j = 0; j < residue[i].nAtoms; j++) {
			A = &(residue[i].atom[j]);
			if (strlen(A->name) == 4 || A->name[0] == '1' || A->name[0] == '2'
					|| A->name[0] == '3' || A->name[0] == '4') {
				fprintf(F,
						"ATOM  %5d %-4s%c%3s %c%4d%c   %8.3f%8.3f%8.3f%6.2f%6.2f          %2s%2s\n",
						A->atomNum, A->name, A->altLoc, residue[i].name,
						residue[i].chainId, residue[i].seqNum,
						residue[i].insCode, A->x, A->y, A->z, A->occup, A->temp,
						A->element, A->charge);
			} else {
				fprintf(F,
						"ATOM  %5d  %-3s%c%3s %c%4d%c   %8.3f%8.3f%8.3f%6.2f%6.2f          %2s%2s\n",
						A->atomNum, A->name, A->altLoc, residue[i].name,
						residue[i].chainId, residue[i].seqNum,
						residue[i].insCode, A->x, A->y, A->z, A->occup, A->temp,
						A->element, A->charge);
			}
		}
	}
	fprintf(F, "TER\n");
	fclose(F);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x60, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
leaq 0x19b2f(%rip), %rsi     # 0x34bd5
callq 0x3310
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x1b0d7
movq 0x32f23(%rip), %rax     # 0x4dfe0
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x19b0c(%rip), %rsi     # 0x34bd7
movb $0x0, %al
callq 0x33d0
jmp 0x1b37f
movl $0x0, -0x34(%rbp)
movq -0x40(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x48(%rcx), %eax
jge 0x1b364
movl $0x0, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movl -0x38(%rbp), %eax
movq 0x40(%rcx), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
cmpl 0x18(%rcx), %eax
jge 0x1b354
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movq 0x10(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
addq $0x4, %rdi
callq 0x3130
cmpq $0x4, %rax
je 0x1b18b
movq -0x30(%rbp), %rax
movsbl 0x4(%rax), %eax
cmpl $0x31, %eax
je 0x1b18b
movq -0x30(%rbp), %rax
movsbl 0x4(%rax), %eax
cmpl $0x32, %eax
je 0x1b18b
movq -0x30(%rbp), %rax
movsbl 0x4(%rax), %eax
cmpl $0x33, %eax
je 0x1b18b
movq -0x30(%rbp), %rax
movsbl 0x4(%rax), %eax
cmpl $0x34, %eax
jne 0x1b26a
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rcx
movl (%rcx), %edx
movq -0x30(%rbp), %rcx
addq $0x4, %rcx
movq -0x30(%rbp), %rsi
movsbl 0x9(%rsi), %r8d
movq 0x40(%rax), %r9
movslq -0x34(%rbp), %rsi
imulq $0x188, %rsi, %rsi      # imm = 0x188
addq %rsi, %r9
addq $0x1, %r9
movq 0x40(%rax), %rsi
movslq -0x34(%rbp), %r10
imulq $0x188, %r10, %r10      # imm = 0x188
addq %r10, %rsi
movsbl 0x1c(%rsi), %r14d
movq 0x40(%rax), %rsi
movslq -0x34(%rbp), %r10
imulq $0x188, %r10, %r10      # imm = 0x188
addq %r10, %rsi
movl 0x8(%rsi), %ebx
movq 0x40(%rax), %rax
movslq -0x34(%rbp), %rsi
imulq $0x188, %rsi, %rsi      # imm = 0x188
addq %rsi, %rax
movsbl 0xc(%rax), %r11d
movq -0x30(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x30(%rbp), %rax
movsd 0x18(%rax), %xmm1
movq -0x30(%rbp), %rax
movsd 0x20(%rax), %xmm2
movq -0x30(%rbp), %rax
movsd 0x28(%rax), %xmm3
movq -0x30(%rbp), %rax
movsd 0x30(%rax), %xmm4
movq -0x30(%rbp), %r10
addq $0x38, %r10
movq -0x30(%rbp), %rax
addq $0x3b, %rax
leaq 0x199b2(%rip), %rsi     # 0x34bf9
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x5, %al
callq 0x33d0
jmp 0x1b344
movq -0x40(%rbp), %rax
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rcx
movl (%rcx), %edx
movq -0x30(%rbp), %rcx
addq $0x4, %rcx
movq -0x30(%rbp), %rsi
movsbl 0x9(%rsi), %r8d
movq 0x40(%rax), %r9
movslq -0x34(%rbp), %rsi
imulq $0x188, %rsi, %rsi      # imm = 0x188
addq %rsi, %r9
addq $0x1, %r9
movq 0x40(%rax), %rsi
movslq -0x34(%rbp), %r10
imulq $0x188, %r10, %r10      # imm = 0x188
addq %r10, %rsi
movsbl 0x1c(%rsi), %r14d
movq 0x40(%rax), %rsi
movslq -0x34(%rbp), %r10
imulq $0x188, %r10, %r10      # imm = 0x188
addq %r10, %rsi
movl 0x8(%rsi), %ebx
movq 0x40(%rax), %rax
movslq -0x34(%rbp), %rsi
imulq $0x188, %rsi, %rsi      # imm = 0x188
addq %rsi, %rax
movsbl 0xc(%rax), %r11d
movq -0x30(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x30(%rbp), %rax
movsd 0x18(%rax), %xmm1
movq -0x30(%rbp), %rax
movsd 0x20(%rax), %xmm2
movq -0x30(%rbp), %rax
movsd 0x28(%rax), %xmm3
movq -0x30(%rbp), %rax
movsd 0x30(%rax), %xmm4
movq -0x30(%rbp), %r10
addq $0x38, %r10
movq -0x30(%rbp), %rax
addq $0x3b, %rax
leaq 0x1991c(%rip), %rsi     # 0x34c42
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x5, %al
callq 0x33d0
jmp 0x1b346
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1b0f5
jmp 0x1b356
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1b0de
movq -0x28(%rbp), %rdi
leaq 0x1991d(%rip), %rsi     # 0x34c8c
movb $0x0, %al
callq 0x33d0
movq -0x28(%rbp), %rdi
callq 0x3290
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax,%rax)