// File: gjoni[P]iPot/src/AACE.cpp
// Function: AACE::AACE(std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>> const&, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
AACE::AACE(const GROUPS_TYPE &GROUPS, double dmax_, 
		const std::string &name_) : 
		h(NULL), J(NULL), dmax(dmax_), name(name_) {

	int dim = ReadGroups(GROUPS);
	Allocate(dim);

	FILE *F = fopen(name.c_str(), "r");
	if (F == NULL) {
		printf("Error: cannot open table file %s\n", name.c_str());
		exit(1);
	}

	const int STRMAX = 10000;
	char buf[STRMAX];

	int N = 0;
	
	while (fgets(buf, STRMAX, F)) {
		N++;
	}
	rewind(F);
	
	assert(N == dim);

	for (int i = 0; i < N; i++) {
		fgets(buf, STRMAX, F);
		char * pch;
		pch = strtok(buf, " "); /* label */
		pch = strtok(NULL, " "); /* local field */
		h[i] = atof(pch);
		for (int j = 0; j < N; j++) {
			pch = strtok(NULL, " ");
			J[i][j] = atof(pch);
		}
	}
	fclose(F);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x27a0, %rsp           # imm = 0x27A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x2778(%rbp)
movq %rdi, %rax
movq %rax, -0x2788(%rbp)
callq 0x23320
movq -0x2778(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x2780(%rbp)
callq 0x23320
movq -0x2778(%rbp), %rdi
movq $0x0, 0x60(%rdi)
movq $0x0, 0x68(%rdi)
movsd -0x18(%rbp), %xmm0
movsd %xmm0, 0x70(%rdi)
addq $0x78, %rdi
movq %rdi, -0x2770(%rbp)
movq -0x20(%rbp), %rsi
callq 0x3120
jmp 0x21014
movq -0x2788(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x20d10
movl %eax, -0x278c(%rbp)
jmp 0x2102c
movq -0x2788(%rbp), %rdi
movl -0x278c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %esi
callq 0x20f00
jmp 0x21046
movq -0x2788(%rbp), %rdi
addq $0x78, %rdi
callq 0x3110
movq %rax, %rdi
leaq 0x13aed(%rip), %rsi     # 0x34b4d
callq 0x3310
movq %rax, -0x2798(%rbp)
jmp 0x2106e
movq -0x2798(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x210db
movq -0x2788(%rbp), %rdi
addq $0x78, %rdi
callq 0x3110
movq %rax, %rsi
leaq 0x15c18(%rip), %rdi     # 0x36cb2
xorl %eax, %eax
callq 0x3070
jmp 0x210a3
movl $0x1, %edi
callq 0x3330
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x2127e
movq -0x2770(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
callq 0x3190
jmp 0x2127e
movl $0x2710, -0x3c(%rbp)    # imm = 0x2710
movl $0x0, -0x2754(%rbp)
movq -0x38(%rbp), %rdx
leaq -0x2750(%rbp), %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x3410
movq %rax, -0x27a0(%rbp)
jmp 0x2110a
movq -0x27a0(%rbp), %rax
cmpq $0x0, %rax
je 0x21128
movl -0x2754(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2754(%rbp)
jmp 0x210ec
movq -0x38(%rbp), %rdi
callq 0x3080
jmp 0x21133
movl -0x2754(%rbp), %eax
cmpl -0x30(%rbp), %eax
jne 0x21140
jmp 0x2115f
leaq 0x15b8d(%rip), %rdi     # 0x36cd4
leaq 0x15aa4(%rip), %rsi     # 0x36bf2
movl $0x3b, %edx
leaq 0x15b83(%rip), %rcx     # 0x36cdd
callq 0x31b0
movl $0x0, -0x2758(%rbp)
movl -0x2758(%rbp), %eax
cmpl -0x2754(%rbp), %eax
jge 0x2126a
movq -0x38(%rbp), %rdx
leaq -0x2750(%rbp), %rdi
movl $0x2710, %esi           # imm = 0x2710
callq 0x3410
jmp 0x21192
leaq -0x2750(%rbp), %rdi
leaq 0x15b7a(%rip), %rsi     # 0x36d1a
callq 0x3400
movq %rax, -0x2760(%rbp)
xorl %eax, %eax
movl %eax, %edi
leaq 0x15b63(%rip), %rsi     # 0x36d1a
callq 0x3400
movq %rax, -0x2760(%rbp)
movq -0x2760(%rbp), %rdi
callq 0x3370
movq -0x2788(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x2758(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x2764(%rbp)
movl -0x2764(%rbp), %eax
cmpl -0x2754(%rbp), %eax
jge 0x21254
xorl %eax, %eax
movl %eax, %edi
leaq 0x15b11(%rip), %rsi     # 0x36d1a
callq 0x3400
movq %rax, -0x2760(%rbp)
movq -0x2760(%rbp), %rdi
callq 0x3370
movq -0x2788(%rbp), %rax
movq 0x68(%rax), %rax
movslq -0x2758(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x2764(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x2764(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2764(%rbp)
jmp 0x211f0
jmp 0x21256
movl -0x2758(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2758(%rbp)
jmp 0x21169
movq -0x38(%rbp), %rdi
callq 0x3290
jmp 0x21275
addq $0x27a0, %rsp           # imm = 0x27A0
popq %rbp
retq
movq -0x2780(%rbp), %rdi
callq 0x233b0
movq -0x2778(%rbp), %rdi
callq 0x233b0
movq -0x28(%rbp), %rdi
callq 0x3460
nop