// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rdi, %rbx
pushq $0xa
popq %rsi
movq %rdx, %rdi
callq 0x20d0
testq %rax, %rax
sete %cl
movq %rax, %rdx
subq %r14, %rdx
cmpq $0x50, %rdx
setge %dl
orb %cl, %dl
jne 0xe1db
leaq 0x50(%r14), %rcx
cmpq %rcx, %rax
je 0xe1d8
movb $0x20, (%rax)
incq %rax
jmp 0xe1cb
movb $0x0, (%rax)
xorl %ebp, %ebp
movb %bpl, 0x50(%r14)
leaq 0x48(%rbx), %rdi
leaq 0x4e(%r14), %rsi
pushq $0x3
popq %r15
movq %r15, %rdx
callq 0x2120
movb %bpl, 0x4e(%r14)
leaq 0x45(%rbx), %rdi
leaq 0x4c(%r14), %rsi
movq %r15, %rdx
callq 0x2120
movb %bpl, 0x4c(%r14)
leaq 0x40(%rbx), %rdi
leaq 0x48(%r14), %rsi
pushq $0x5
popq %rdx
callq 0x2120
movb %bpl, 0x43(%r14)
leaq 0x3c(%r14), %rdi
callq 0x22a0
movsd %xmm0, 0x38(%rbx)
movb %bpl, 0x3c(%r14)
leaq 0x36(%r14), %rdi
callq 0x22a0
movsd %xmm0, 0x30(%rbx)
movb %bpl, 0x36(%r14)
leaq 0x2e(%r14), %rdi
callq 0x22a0
movsd %xmm0, 0x28(%rbx)
movb %bpl, 0x2e(%r14)
leaq 0x26(%r14), %rdi
callq 0x22a0
movsd %xmm0, 0x20(%rbx)
movb %bpl, 0x26(%r14)
leaq 0x1e(%r14), %rdi
callq 0x22a0
movsd %xmm0, 0x18(%rbx)
movb 0x1a(%r14), %al
movb %al, 0x14(%rbx)
movb %bpl, 0x1a(%r14)
leaq 0x16(%r14), %rdi
callq 0x2340
movl %eax, 0x10(%rbx)
movb 0x15(%r14), %al
movb %al, 0xe(%rbx)
movb %bpl, 0x14(%r14)
leaq 0x11(%r14), %rdi
leaq 0xa(%rbx), %rdx
leaq 0xcc1f(%rip), %r15      # 0x1aec7
movq %r15, %rsi
xorl %eax, %eax
callq 0x21f0
movb 0x10(%r14), %al
movb %al, 0x9(%rbx)
movb %bpl, 0x10(%r14)
leaq 0xc(%r14), %rdi
leaq 0x4(%rbx), %rdx
movq %r15, %rsi
xorl %eax, %eax
callq 0x21f0
movb %bpl, 0xb(%r14)
addq $0x6, %r14
movq %r14, %rdi
callq 0x2340
movl %eax, (%rbx)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop