// File: NKUSec[P]Rethinking-Honeywords/atk.cpp
// Function: read_honeywords_pr_file(char*, char*, char*, int)
void read_honeywords_pr_file(char* pr_file, char* honeywords_file, char* checker_file, int THRESHOLD_X)
{
	char line[LINE_LEN];
	FILE* fpr = fopen(pr_file, "r");
	FILE* fhny = fopen(honeywords_file, "r");
	FILE* fchk = fopen(checker_file, "r");
	while (fgets(line, LINE_LEN, fpr))
	{
		int l = strlen(line);
		if (line[l-1] == '\n') {line[l-1] = '\0'; l--;}
		if (line[l-1] == '\r') {line[l-1] = '\0'; l--;}

		int ptr = 0;
		int honey_cnt = 0;
		double tmpp[THRESHOLD_K];
		while (ptr <= l-1)
		{
			sscanf(line+ptr, "%lf", &tmpp[honey_cnt]);
			acnt[account_size].sum += tmpp[honey_cnt];
			while (line[ptr] != '\t' && line[ptr] != '\0') ptr++;
			ptr++;
			honey_cnt++;
			if (honey_cnt >= THRESHOLD_K) break;
		}

		fgets(line, LINE_LEN, fchk);
		l = strlen(line);
		if (line[l-1] == '\n') {line[l-1] = '\0'; l--;}
		if (line[l-1] == '\r') {line[l-1] = '\0'; l--;}
		int real_pos = atoi(line);

		fgets(line, LINE_LEN, fhny);
		l = strlen(line);
		if (line[l-1] == '\n') {line[l-1] = '\0'; l--;}
		if (line[l-1] == '\r') {line[l-1] = '\0'; l--;}
		char tmpstr[THRESHOLD_K][WORD_LEN];
		ptr = 0;
		honey_cnt = 0;
		while (ptr <= l-1)
		{
			int head = ptr, tail;
			while (line[ptr] != '\t' && line[ptr] != '\0') ptr++;
			tail = ptr; ptr++;
			for (int i = head; i < tail; i++) tmpstr[honey_cnt][i-head] = line[i];
			tmpstr[honey_cnt][tail-head] = '\0';
			honey_cnt++;
		}

		if (acnt[account_size].sum == 0)
		{
			for (int i = 0; i < THRESHOLD_K; i++) tmpp[i]+=1;
			acnt[account_size].sum += THRESHOLD_K;
		}

		bool vis[THRESHOLD_K] = {false};
		for (int i = 0; i < THRESHOLD_X; i++)
		{
			int same[THRESHOLD_K];
			double max = 0;
			int cnt = 0;
			int pos = 0;
			for (int j = 0; j < THRESHOLD_K; j++)
			{
				if (tmpp[j]>max && !vis[j])
				{
					pos = j;
					max = tmpp[j];
					same[0] = j;
					cnt = 1;
				}
				else if (tmpp[j] == max && !vis[j])
				{
					same[cnt] = j;
					cnt++;
				}
			}
			if (tmpp[pos] == max && cnt > 1)
			{
				int rrr = rand()%cnt;
				pos = same[rrr];
			}

			acnt[account_size].p[i] = 0;
			for (int j = 0; j < THRESHOLD_K; j++)
				if (j != pos && !vis[j]) acnt[account_size].p[i] += tmpp[j];

			acnt[account_size].p[i] /= acnt[account_size].sum;

			acnt[account_size].pos[i] = pos;
			if (strcmp(tmpstr[pos], tmpstr[real_pos])==0)
				acnt[account_size].hit[i] = true;
			else
				acnt[account_size].hit[i] = false;
			vis[pos] = true;
		}
		acnt[account_size].line = account_size;
		if (acnt[account_size].sum != 0) heap.push(acnt[account_size]);
		account_size++;
		if (account_size % 100000 == 0) printf("%d\n", account_size);
	}
	fclose(fpr);
	fclose(fhny);
	fclose(fchk);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b10, %rsp           # imm = 0x2B10
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x2c93(%rip), %rsi      # 0x4018
callq 0x1160
movq %rax, -0x2738(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x2c7c(%rip), %rsi      # 0x4018
callq 0x1160
movq %rax, -0x2740(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x2c65(%rip), %rsi      # 0x4018
callq 0x1160
movq %rax, -0x2748(%rbp)
leaq -0x2730(%rbp), %rdi
movq -0x2738(%rbp), %rdx
movl $0x2710, %esi           # imm = 0x2710
callq 0x11a0
cmpq $0x0, %rax
je 0x1ca1
leaq -0x2730(%rbp), %rdi
callq 0x1090
movl %eax, -0x274c(%rbp)
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x2730(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x142d
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x2730(%rbp,%rax)
movl -0x274c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x274c(%rbp)
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x2730(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x1467
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x2730(%rbp,%rax)
movl -0x274c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x274c(%rbp)
movl $0x0, -0x2750(%rbp)
movl $0x0, -0x2754(%rbp)
movl -0x2750(%rbp), %eax
movl -0x274c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x1580
leaq -0x2730(%rbp), %rdi
movslq -0x2750(%rbp), %rax
addq %rax, %rdi
movslq -0x2754(%rbp), %rax
leaq -0x2800(%rbp), %rdx
shlq $0x3, %rax
addq %rax, %rdx
leaq 0x2b5b(%rip), %rsi      # 0x401a
movb $0x0, %al
callq 0x1120
movslq -0x2754(%rbp), %rax
movsd -0x2800(%rbp,%rax,8), %xmm0
movq 0x5c53(%rip), %rax      # 0x7130
movslq 0x5c58(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
addsd 0x108(%rax), %xmm0
movsd %xmm0, 0x108(%rax)
movslq -0x2750(%rbp), %rax
movsbl -0x2730(%rbp,%rax), %ecx
xorl %eax, %eax
cmpl $0x9, %ecx
movb %al, -0x2b0d(%rbp)
je 0x1535
movslq -0x2750(%rbp), %rax
movsbl -0x2730(%rbp,%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x2b0d(%rbp)
movb -0x2b0d(%rbp), %al
testb $0x1, %al
jne 0x1541
jmp 0x1552
movl -0x2750(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2750(%rbp)
jmp 0x14fe
movl -0x2750(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2750(%rbp)
movl -0x2754(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2754(%rbp)
cmpl $0x14, -0x2754(%rbp)
jl 0x157b
jmp 0x1580
jmp 0x147b
leaq -0x2730(%rbp), %rdi
movq -0x2748(%rbp), %rdx
movl $0x2710, %esi           # imm = 0x2710
callq 0x11a0
leaq -0x2730(%rbp), %rdi
callq 0x1090
movl %eax, -0x274c(%rbp)
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x2730(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x15e4
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x2730(%rbp,%rax)
movl -0x274c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x274c(%rbp)
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x2730(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x161e
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x2730(%rbp,%rax)
movl -0x274c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x274c(%rbp)
leaq -0x2730(%rbp), %rdi
callq 0x1190
movl %eax, -0x2804(%rbp)
leaq -0x2730(%rbp), %rdi
movq -0x2740(%rbp), %rdx
movl $0x2710, %esi           # imm = 0x2710
callq 0x11a0
leaq -0x2730(%rbp), %rdi
callq 0x1090
movl %eax, -0x274c(%rbp)
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x2730(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x1694
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x2730(%rbp,%rax)
movl -0x274c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x274c(%rbp)
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x2730(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x16ce
movl -0x274c(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x2730(%rbp,%rax)
movl -0x274c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x274c(%rbp)
movl $0x0, -0x2750(%rbp)
movl $0x0, -0x2754(%rbp)
movl -0x2750(%rbp), %eax
movl -0x274c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x1810
movl -0x2750(%rbp), %eax
movl %eax, -0x2a64(%rbp)
movslq -0x2750(%rbp), %rax
movsbl -0x2730(%rbp,%rax), %ecx
xorl %eax, %eax
cmpl $0x9, %ecx
movb %al, -0x2b0e(%rbp)
je 0x173c
movslq -0x2750(%rbp), %rax
movsbl -0x2730(%rbp,%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x2b0e(%rbp)
movb -0x2b0e(%rbp), %al
testb $0x1, %al
jne 0x1748
jmp 0x1759
movl -0x2750(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2750(%rbp)
jmp 0x1705
movl -0x2750(%rbp), %eax
movl %eax, -0x2a68(%rbp)
movl -0x2750(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2750(%rbp)
movl -0x2a64(%rbp), %eax
movl %eax, -0x2a6c(%rbp)
movl -0x2a6c(%rbp), %eax
cmpl -0x2a68(%rbp), %eax
jge 0x17d4
movslq -0x2a6c(%rbp), %rax
movb -0x2730(%rbp,%rax), %dl
movslq -0x2754(%rbp), %rcx
leaq -0x2a60(%rbp), %rax
imulq $0x1e, %rcx, %rcx
addq %rcx, %rax
movl -0x2a6c(%rbp), %ecx
subl -0x2a64(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x2a6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a6c(%rbp)
jmp 0x1780
movslq -0x2754(%rbp), %rcx
leaq -0x2a60(%rbp), %rax
imulq $0x1e, %rcx, %rcx
addq %rcx, %rax
movl -0x2a68(%rbp), %ecx
subl -0x2a64(%rbp), %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl -0x2754(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2754(%rbp)
jmp 0x16e2
movq 0x5919(%rip), %rax      # 0x7130
movslq 0x591e(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movsd 0x108(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x18b0
jp 0x18b0
movl $0x0, -0x2a70(%rbp)
cmpl $0x14, -0x2a70(%rbp)
jge 0x1880
movslq -0x2a70(%rbp), %rax
movsd 0x27b3(%rip), %xmm0     # 0x4010
addsd -0x2800(%rbp,%rax,8), %xmm0
movsd %xmm0, -0x2800(%rbp,%rax,8)
movl -0x2a70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a70(%rbp)
jmp 0x1845
movq 0x58a9(%rip), %rax      # 0x7130
movslq 0x58ae(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movsd 0x2768(%rip), %xmm0     # 0x4008
addsd 0x108(%rax), %xmm0
movsd %xmm0, 0x108(%rax)
leaq -0x2a90(%rbp), %rdi
xorl %esi, %esi
movl $0x14, %edx
callq 0x10b0
movl $0x0, -0x2a94(%rbp)
movl -0x2a94(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x1bf1
xorps %xmm0, %xmm0
movsd %xmm0, -0x2af8(%rbp)
movl $0x0, -0x2afc(%rbp)
movl $0x0, -0x2b00(%rbp)
movl $0x0, -0x2b04(%rbp)
cmpl $0x14, -0x2b04(%rbp)
jge 0x19e1
movslq -0x2b04(%rbp), %rax
movsd -0x2800(%rbp,%rax,8), %xmm0
ucomisd -0x2af8(%rbp), %xmm0
jbe 0x1979
movslq -0x2b04(%rbp), %rax
testb $0x1, -0x2a90(%rbp,%rax)
jne 0x1979
movl -0x2b04(%rbp), %eax
movl %eax, -0x2b00(%rbp)
movslq -0x2b04(%rbp), %rax
movsd -0x2800(%rbp,%rax,8), %xmm0
movsd %xmm0, -0x2af8(%rbp)
movl -0x2b04(%rbp), %eax
movl %eax, -0x2af0(%rbp)
movl $0x1, -0x2afc(%rbp)
jmp 0x19cb
movslq -0x2b04(%rbp), %rax
movsd -0x2800(%rbp,%rax,8), %xmm0
ucomisd -0x2af8(%rbp), %xmm0
jne 0x19c9
jp 0x19c9
movslq -0x2b04(%rbp), %rax
testb $0x1, -0x2a90(%rbp,%rax)
jne 0x19c9
movl -0x2b04(%rbp), %ecx
movslq -0x2afc(%rbp), %rax
movl %ecx, -0x2af0(%rbp,%rax,4)
movl -0x2afc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2afc(%rbp)
jmp 0x19cb
jmp 0x19cd
movl -0x2b04(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b04(%rbp)
jmp 0x1905
movslq -0x2b00(%rbp), %rax
movsd -0x2800(%rbp,%rax,8), %xmm0
ucomisd -0x2af8(%rbp), %xmm0
jne 0x1a2c
jp 0x1a2c
cmpl $0x1, -0x2afc(%rbp)
jle 0x1a2c
callq 0x1050
cltd
idivl -0x2afc(%rbp)
movl %edx, -0x2b08(%rbp)
movslq -0x2b08(%rbp), %rax
movl -0x2af0(%rbp,%rax,4), %eax
movl %eax, -0x2b00(%rbp)
movq 0x56fd(%rip), %rax      # 0x7130
movslq 0x5702(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movslq -0x2a94(%rbp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x2b0c(%rbp)
cmpl $0x14, -0x2b0c(%rbp)
jge 0x1ad1
movl -0x2b0c(%rbp), %eax
cmpl -0x2b00(%rbp), %eax
je 0x1abe
movslq -0x2b0c(%rbp), %rax
testb $0x1, -0x2a90(%rbp,%rax)
jne 0x1abe
movslq -0x2b0c(%rbp), %rax
movsd -0x2800(%rbp,%rax,8), %xmm0
movq 0x5694(%rip), %rax      # 0x7130
movslq 0x5699(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movslq -0x2a94(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x1ac0
movl -0x2b0c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2b0c(%rbp)
jmp 0x1a5d
movq 0x5658(%rip), %rax      # 0x7130
movslq 0x565d(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movsd 0x108(%rax), %xmm1
movq 0x5638(%rip), %rax      # 0x7130
movslq 0x563d(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movslq -0x2a94(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x2b00(%rbp), %edx
movq 0x5605(%rip), %rax      # 0x7130
movslq 0x560a(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movslq -0x2a94(%rbp), %rcx
movl %edx, 0xa0(%rax,%rcx,4)
movslq -0x2b00(%rbp), %rax
leaq -0x2a60(%rbp), %rdi
imulq $0x1e, %rax, %rax
addq %rax, %rdi
movslq -0x2804(%rbp), %rax
leaq -0x2a60(%rbp), %rsi
imulq $0x1e, %rax, %rax
addq %rax, %rsi
callq 0x1170
cmpl $0x0, %eax
jne 0x1ba7
movq 0x55ab(%rip), %rax      # 0x7130
movslq 0x55b0(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movslq -0x2a94(%rbp), %rcx
movb $0x1, 0xf0(%rax,%rcx)
jmp 0x1bce
movq 0x5582(%rip), %rax      # 0x7130
movslq 0x5587(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movslq -0x2a94(%rbp), %rcx
movb $0x0, 0xf0(%rax,%rcx)
movslq -0x2b00(%rbp), %rax
movb $0x1, -0x2a90(%rbp,%rax)
movl -0x2a94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2a94(%rbp)
jmp 0x18cd
movl 0x5545(%rip), %ecx      # 0x713c
movq 0x5532(%rip), %rax      # 0x7130
movslq 0x5537(%rip), %rdx      # 0x713c
imulq $0x118, %rdx, %rdx      # imm = 0x118
addq %rdx, %rax
movl %ecx, 0x114(%rax)
movq 0x5514(%rip), %rax      # 0x7130
movslq 0x5519(%rip), %rcx      # 0x713c
imulq $0x118, %rcx, %rcx      # imm = 0x118
addq %rcx, %rax
movsd 0x108(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1c42
jp 0x1c42
jmp 0x1c66
movq 0x54e7(%rip), %rsi      # 0x7130
movslq 0x54ec(%rip), %rax      # 0x713c
imulq $0x118, %rax, %rax      # imm = 0x118
addq %rax, %rsi
leaq 0x54af(%rip), %rdi      # 0x7110
callq 0x24e0
movl 0x54d0(%rip), %eax      # 0x713c
addl $0x1, %eax
movl %eax, 0x54c7(%rip)      # 0x713c
movl 0x54c1(%rip), %eax      # 0x713c
movl $0x186a0, %ecx          # imm = 0x186A0
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x1c9c
movl 0x54ae(%rip), %esi      # 0x713c
leaq 0x23a8(%rip), %rdi      # 0x403d
movb $0x0, %al
callq 0x1040
jmp 0x13bf
movq -0x2738(%rbp), %rdi
callq 0x1130
movq -0x2740(%rbp), %rdi
callq 0x1130
movq -0x2748(%rbp), %rdi
callq 0x1130
addq $0x2b10, %rsp           # imm = 0x2B10
popq %rbp
retq
nop