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

	AtomRecord A;

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

	/* fields missing from PQR files */
	A.segId[0] = '\0';
	A.element[0] = '\0';
	A.charge[0] = '\0';

	/* save atom charge and radius in Temperature factor
	 * and Occupancy respectively */
	str[80] = '\0';
	sscanf(str + 54, "%lf %lf", &(A.q), &(A.r));
	A.temp = A.q;
	A.occup = A.r;

	/* 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);

	A.charge[0] = A.element[0] = '\0';

	return A;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, %rcx
movq %rcx, -0x20(%rbp)
movq %rcx, %rdi
movq %rdi, -0x18(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movb $0x0, 0x40(%rcx)
movb $0x0, 0x45(%rcx)
movb $0x0, 0x48(%rcx)
movq -0x10(%rbp), %rax
movb $0x0, 0x50(%rax)
movq -0x10(%rbp), %rdi
addq $0x36, %rdi
movq %rcx, %rdx
addq $0x50, %rdx
addq $0x58, %rcx
leaq 0x1b871(%rip), %rsi     # 0x34bcd
movb $0x0, %al
callq 0x3280
movq -0x20(%rbp), %rdi
movsd 0x50(%rdi), %xmm0
movsd %xmm0, 0x38(%rdi)
movsd 0x58(%rdi), %xmm0
movsd %xmm0, 0x30(%rdi)
movq -0x10(%rbp), %rax
movb $0x0, 0x36(%rax)
movq -0x10(%rbp), %rdi
addq $0x2e, %rdi
callq 0x3370
movq -0x20(%rbp), %rdi
movsd %xmm0, 0x28(%rdi)
movq -0x10(%rbp), %rax
movb $0x0, 0x2e(%rax)
movq -0x10(%rbp), %rdi
addq $0x26, %rdi
callq 0x3370
movq -0x20(%rbp), %rdi
movsd %xmm0, 0x20(%rdi)
movq -0x10(%rbp), %rax
movb $0x0, 0x26(%rax)
movq -0x10(%rbp), %rdi
addq $0x1e, %rdi
callq 0x3370
movq -0x20(%rbp), %rdi
movsd %xmm0, 0x18(%rdi)
movq -0x10(%rbp), %rax
movb 0x1a(%rax), %al
movb %al, 0x14(%rdi)
movq -0x10(%rbp), %rax
movb $0x0, 0x1a(%rax)
movq -0x10(%rbp), %rdi
addq $0x16, %rdi
callq 0x33f0
movq -0x20(%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 0x1dad3(%rip), %rsi     # 0x36ef3
movb $0x0, %al
callq 0x3280
movq -0x20(%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 0x1daa3(%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 -0x20(%rbp), %rdi
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rdi)
movb $0x0, 0x45(%rdi)
movb $0x0, 0x48(%rdi)
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)