// File: NKUSec[P]Rethinking-Honeywords/calc.cpp
// Function: calc_honeywords_pr(char*, char*)
void calc_honeywords_pr(char* honeywords_file, char* pr_file)
{
	char line[LINE_LEN];
	FILE* fhoney = fopen(honeywords_file, "r");
	FILE* fout = fopen(pr_file, "w");
	while (fgets(line, LINE_LEN, fhoney))
	{
		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;

		while (ptr <= l-1)
		{
			char tmpstr[LINE_LEN];
			int head = ptr, tail;
			while (line[ptr] != '\t' && line[ptr] != '\0') ptr++;
			tail = ptr; ptr++;
			for (int i = head; i < tail; i++) tmpstr[i-head] = line[i];
			tmpstr[tail-head] = '\0';

			int freq = 0;
			map<string, int>::iterator it;
			it = train_dic.find(tmpstr);
			if (it != train_dic.end())
				freq = it->second;

			// smooth
			fprintf(fout, "%g\t", (double)(freq+1.0)/ dic_size);

			honey_cnt++;
		}

		account_size++;
		fprintf(fout, "\n");
		if (account_size % 100000 == 0) printf("account: %d\n", account_size);
	}
	fclose(fhoney);
	fclose(fout);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4ed0, %rsp           # imm = 0x4ED0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x19a2(%rip), %rsi      # 0x4010
callq 0x21b0
movq %rax, -0x2728(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x198d(%rip), %rsi      # 0x4012
callq 0x21b0
movq %rax, -0x2730(%rbp)
leaq -0x2720(%rbp), %rdi
movq -0x2728(%rbp), %rdx
movl $0x2710, %esi           # imm = 0x2710
callq 0x21f0
cmpq $0x0, %rax
je 0x29f9
leaq -0x2720(%rbp), %rdi
callq 0x20a0
movl %eax, -0x2734(%rbp)
movl -0x2734(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x2720(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x26ff
movl -0x2734(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x2720(%rbp,%rax)
movl -0x2734(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2734(%rbp)
movl -0x2734(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x2720(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x2739
movl -0x2734(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x2720(%rbp,%rax)
movl -0x2734(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2734(%rbp)
movl $0x0, -0x2738(%rbp)
movl $0x0, -0x273c(%rbp)
movl -0x2738(%rbp), %eax
movl -0x2734(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x29a9
movl -0x2738(%rbp), %eax
movl %eax, -0x4e54(%rbp)
movslq -0x2738(%rbp), %rax
movsbl -0x2720(%rbp,%rax), %ecx
xorl %eax, %eax
cmpl $0x9, %ecx
movb %al, -0x4eb1(%rbp)
je 0x27a7
movslq -0x2738(%rbp), %rax
movsbl -0x2720(%rbp,%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x4eb1(%rbp)
movb -0x4eb1(%rbp), %al
testb $0x1, %al
jne 0x27b3
jmp 0x27c4
movl -0x2738(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2738(%rbp)
jmp 0x2770
movl -0x2738(%rbp), %eax
movl %eax, -0x4e58(%rbp)
movl -0x2738(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2738(%rbp)
movl -0x4e54(%rbp), %eax
movl %eax, -0x4e5c(%rbp)
movl -0x4e5c(%rbp), %eax
cmpl -0x4e58(%rbp), %eax
jge 0x282d
movslq -0x4e5c(%rbp), %rax
movb -0x2720(%rbp,%rax), %cl
movl -0x4e5c(%rbp), %eax
subl -0x4e54(%rbp), %eax
cltq
movb %cl, -0x4e50(%rbp,%rax)
movl -0x4e5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4e5c(%rbp)
jmp 0x27eb
movl -0x4e58(%rbp), %eax
movl -0x4e54(%rbp), %ecx
subl %ecx, %eax
cltq
movb $0x0, -0x4e50(%rbp,%rax)
movl $0x0, -0x4e60(%rbp)
leaq -0x4e68(%rbp), %rdi
callq 0x2b90
leaq -0x4e91(%rbp), %rdi
movq %rdi, -0x4ec0(%rbp)
callq 0x2220
movq -0x4ec0(%rbp), %rdx
leaq -0x4e90(%rbp), %rdi
leaq -0x4e50(%rbp), %rsi
callq 0x2be0
jmp 0x288a
leaq 0x48c7(%rip), %rdi      # 0x7158
leaq -0x4e90(%rbp), %rsi
callq 0x2bb0
movq %rax, -0x4ec8(%rbp)
jmp 0x28a6
movq -0x4ec8(%rbp), %rax
movq %rax, -0x4e70(%rbp)
movq -0x4e70(%rbp), %rax
movq %rax, -0x4e68(%rbp)
leaq -0x4e90(%rbp), %rdi
callq 0x20b0
leaq -0x4e91(%rbp), %rdi
callq 0x2180
leaq 0x4877(%rip), %rdi      # 0x7158
callq 0x2cc0
movq %rax, -0x4eb0(%rbp)
leaq -0x4e68(%rbp), %rdi
leaq -0x4eb0(%rbp), %rsi
callq 0x2d90
testb $0x1, %al
jne 0x2906
jmp 0x2960
leaq -0x4e68(%rbp), %rdi
callq 0x2d70
movl 0x20(%rax), %eax
movl %eax, -0x4e60(%rbp)
jmp 0x2960
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x4ea0(%rbp)
movl %eax, -0x4ea4(%rbp)
jmp 0x294f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x4ea0(%rbp)
movl %eax, -0x4ea4(%rbp)
leaq -0x4e90(%rbp), %rdi
callq 0x20b0
leaq -0x4e91(%rbp), %rdi
callq 0x2180
jmp 0x2a1a
movq -0x2730(%rbp), %rdi
cvtsi2sdl -0x4e60(%rbp), %xmm0
movsd 0x1691(%rip), %xmm1     # 0x4008
addsd %xmm1, %xmm0
cvtsi2sdl 0x47d1(%rip), %xmm1 # 0x7154
divsd %xmm1, %xmm0
leaq 0x1686(%rip), %rsi      # 0x4014
movb $0x1, %al
callq 0x21d0
movl -0x273c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x273c(%rbp)
jmp 0x274d
movl 0x47a1(%rip), %eax      # 0x7150
addl $0x1, %eax
movl %eax, 0x4798(%rip)      # 0x7150
movq -0x2730(%rbp), %rdi
leaq 0x1675(%rip), %rsi      # 0x403b
movb $0x0, %al
callq 0x21d0
movl 0x477d(%rip), %eax      # 0x7150
movl $0x186a0, %ecx          # imm = 0x186A0
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x29f4
movl 0x476a(%rip), %esi      # 0x7150
leaq 0x162b(%rip), %rdi      # 0x4018
movb $0x0, %al
callq 0x2040
jmp 0x2691
movq -0x2728(%rbp), %rdi
callq 0x2130
movq -0x2730(%rbp), %rdi
callq 0x2130
addq $0x4ed0, %rsp           # imm = 0x4ED0
popq %rbp
retq
movq -0x4ea0(%rbp), %rdi
callq 0x2210
nopw %cs:(%rax,%rax)