// File: gjoni[P]iPot/src/Chain.cpp
// Function: Chain::ReadAtomRecord(char*)
AtomRecord Chain::ReadAtomRecord(char* str) {

	AtomRecord A;

	/* complete string to 80 characters */
	char *pch = strpbrk(str, "\n");
	if (pch != NULL && pch - str < 80) {
		while (pch != str + 80) {
			*pch++ = ' ';
		}
		*pch = '\0';
	}

	/*
	 * reading PDB ATOM string in the reverse direction
	 */

	/* Charge on the atom */
	str[80] = '\0';
	strncpy(A.charge, str + 78, 3);

	/* Element symbol, right-justified */
	str[78] = '\0';
	strncpy(A.element, str + 76, 3);

	/* Segment identifier, left-justified */
	str[76] = '\0';
	strncpy(A.segId, str + 72, 5);

	/* Temperature factor */
	str[67] = '\0';
	A.temp = atof(str + 60);

	/* Occupancy */
	str[60] = '\0';
	A.occup = atof(str + 54);

	/* Z coordinate */
	str[54] = '\0';
	A.z = atof(str + 46);

	/* Y coordinate */
	str[46] = '\0';
	A.y = atof(str + 38);

	/* X coordinate */
	str[38] = '\0';
	A.x = atof(str + 30);

	/* Code for insertion of residues */
	A.insCode = str[26];

	/* Residue sequence number */
	str[26] = '\0';
	A.resNum = atoi(str + 22);

	/* Chain identifier */
	A.chainId = str[21];

	/* Residue name */
	str[20] = '\0';
	//strncpy(A.resName, str + 17, 4);
	sscanf(str + 17, "%s", A.resName); /* no spaces in residue name */

	/* Alternate location indicator */
	A.altLoc = str[16];

	/* Atom name */
	str[16] = '\0';
	//strncpy(A.atomName, str + 12, 5);
	sscanf(str + 12, "%s", A.atomName);

	/* Atom serial number */
	str[11] = '\0';
	A.atomNum = atoi(str + 6);

	return A;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x28(%rbp)
movq %rdi, -0x20(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x19bb9(%rip), %rsi     # 0x3306c
callq 0x3450
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x19502
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
cmpq $0x50, %rax
jge 0x19502
jmp 0x194d6
movq -0x18(%rbp), %rax
movq -0x10(%rbp), %rcx
addq $0x50, %rcx
cmpq %rcx, %rax
je 0x194fb
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb $0x20, (%rax)
jmp 0x194d6
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movb $0x0, 0x50(%rax)
addq $0x48, %rdi
movq -0x10(%rbp), %rsi
addq $0x4e, %rsi
movl $0x3, %edx
callq 0x3150
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movb $0x0, 0x4e(%rax)
addq $0x45, %rdi
movq -0x10(%rbp), %rsi
addq $0x4c, %rsi
movl $0x3, %edx
callq 0x3150
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rax
movb $0x0, 0x4c(%rax)
addq $0x40, %rdi
movq -0x10(%rbp), %rsi
addq $0x48, %rsi
movl $0x5, %edx
callq 0x3150
movq -0x10(%rbp), %rax
movb $0x0, 0x43(%rax)
movq -0x10(%rbp), %rdi
addq $0x3c, %rdi
callq 0x3370
movq -0x28(%rbp), %rax
movsd %xmm0, 0x38(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x3c(%rax)
movq -0x10(%rbp), %rdi
addq $0x36, %rdi
callq 0x3370
movq -0x28(%rbp), %rax
movsd %xmm0, 0x30(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x36(%rax)
movq -0x10(%rbp), %rdi
addq $0x2e, %rdi
callq 0x3370
movq -0x28(%rbp), %rax
movsd %xmm0, 0x28(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x2e(%rax)
movq -0x10(%rbp), %rdi
addq $0x26, %rdi
callq 0x3370
movq -0x28(%rbp), %rax
movsd %xmm0, 0x20(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x26(%rax)
movq -0x10(%rbp), %rdi
addq $0x1e, %rdi
callq 0x3370
movq -0x28(%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq -0x10(%rbp), %rcx
movb 0x1a(%rcx), %cl
movb %cl, 0x14(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x1a(%rax)
movq -0x10(%rbp), %rdi
addq $0x16, %rdi
callq 0x33f0
movq -0x28(%rbp), %rdx
movl %eax, 0x10(%rdx)
movq -0x10(%rbp), %rax
movb 0x15(%rax), %al
movb %al, 0xe(%rdx)
movq -0x10(%rbp), %rax
movb $0x0, 0x14(%rax)
movq -0x10(%rbp), %rdi
addq $0x11, %rdi
addq $0xa, %rdx
leaq 0x1d8aa(%rip), %rsi     # 0x36ef3
movb $0x0, %al
callq 0x3280
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rax
movb 0x10(%rax), %al
movb %al, 0x9(%rdx)
movq -0x10(%rbp), %rax
movb $0x0, 0x10(%rax)
movq -0x10(%rbp), %rdi
addq $0xc, %rdi
addq $0x4, %rdx
leaq 0x1d87a(%rip), %rsi     # 0x36ef3
movb $0x0, %al
callq 0x3280
movq -0x10(%rbp), %rax
movb $0x0, 0xb(%rax)
movq -0x10(%rbp), %rdi
addq $0x6, %rdi
callq 0x33f0
movq -0x28(%rbp), %rcx
movl %eax, %edx
movq -0x20(%rbp), %rax
movl %edx, (%rcx)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)