// File: NKUSec[P]Rethinking-Honeywords/gen.cpp
// Function: honeywords_gen_model_syntax(char*, char*, char*)
void honeywords_gen_model_syntax(char* pwd_file, char* honeywords_file, char* checker_file)
{
	char line[LINE_LEN];
	FILE* fpwd = fopen(pwd_file, "r");
	FILE* fhny = fopen(honeywords_file, "w");
	FILE* fchk = fopen(checker_file, "w");
	read_dic(pwd_file);
	while (fgets(line, LINE_LEN, fpwd))
	{
		int l = strlen(line);
		if (line[l-1] == '\n') {line[l-1] = '\0'; l--;}
		if (line[l-1] == '\r') {line[l-1] = '\0'; l--;}
		if (l >= WORD_LEN) continue;

		char *pwdset[THRESHOLD_K];
		for (int j = 0; j < THRESHOLD_K; j++)
			pwdset[j] = new char[WORD_LEN];

		gen_model_syntax(line, THRESHOLD_K, pwdset);
		
		int idx[THRESHOLD_K];
		for (int i = 0; i < THRESHOLD_K; i++) idx[i] = i;
		int pw_pos = shuffle(idx);

		for (int i = 0; i < THRESHOLD_K; i++)
		{
			fprintf(fhny, "%s\t", pwdset[idx[i]]);
		}
		fprintf(fhny, "\n");
		fprintf(fchk, "%d\n", pw_pos);
		
		for (int j = 0; j < THRESHOLD_K; j++)
			delete pwdset[j];
	}
	fclose(fpwd);
	fclose(fhny);
	fclose(fchk);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x18800, %rsp          # imm = 0x18800
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x1cfe(%rip), %rsi      # 0x4010
callq 0x10f0
movq %rax, -0x186c8(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x1d08(%rip), %rsi      # 0x4031
callq 0x10f0
movq %rax, -0x186d0(%rbp)
movq -0x18(%rbp), %rdi
leaq 0x1cf1(%rip), %rsi      # 0x4031
callq 0x10f0
movq %rax, -0x186d8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1700
leaq -0x186c0(%rbp), %rdi
movq -0x186c8(%rbp), %rdx
movl $0x186a0, %esi          # imm = 0x186A0
callq 0x1110
cmpq $0x0, %rax
je 0x2585
leaq -0x186c0(%rbp), %rdi
callq 0x1060
movl %eax, -0x186dc(%rbp)
movl -0x186dc(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x186c0(%rbp,%rax), %eax
cmpl $0xa, %eax
jne 0x23c3
movl -0x186dc(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x186c0(%rbp,%rax)
movl -0x186dc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x186dc(%rbp)
movl -0x186dc(%rbp), %eax
subl $0x1, %eax
cltq
movsbl -0x186c0(%rbp,%rax), %eax
cmpl $0xd, %eax
jne 0x23fd
movl -0x186dc(%rbp), %eax
subl $0x1, %eax
cltq
movb $0x0, -0x186c0(%rbp,%rax)
movl -0x186dc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x186dc(%rbp)
cmpl $0x1e, -0x186dc(%rbp)
jl 0x240b
jmp 0x2355
movl $0x0, -0x18784(%rbp)
cmpl $0x14, -0x18784(%rbp)
jge 0x244b
movl $0x1e, %edi
callq 0x1030
movq %rax, %rcx
movslq -0x18784(%rbp), %rax
movq %rcx, -0x18780(%rbp,%rax,8)
movl -0x18784(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18784(%rbp)
jmp 0x2415
leaq -0x186c0(%rbp), %rdi
leaq -0x18780(%rbp), %rdx
movl $0x14, %esi
callq 0x21d0
movl $0x0, -0x187e4(%rbp)
cmpl $0x14, -0x187e4(%rbp)
jge 0x249b
movl -0x187e4(%rbp), %ecx
movslq -0x187e4(%rbp), %rax
movl %ecx, -0x187e0(%rbp,%rax,4)
movl -0x187e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x187e4(%rbp)
jmp 0x246d
leaq -0x187e0(%rbp), %rdi
callq 0x2240
movl %eax, -0x187e8(%rbp)
movl $0x0, -0x187ec(%rbp)
cmpl $0x14, -0x187ec(%rbp)
jge 0x24fd
movq -0x186d0(%rbp), %rdi
movslq -0x187ec(%rbp), %rax
movslq -0x187e0(%rbp,%rax,4), %rax
movq -0x18780(%rbp,%rax,8), %rdx
leaq 0x1b4e(%rip), %rsi      # 0x4033
movb $0x0, %al
callq 0x1100
movl -0x187ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x187ec(%rbp)
jmp 0x24b7
movq -0x186d0(%rbp), %rdi
leaq 0x1b41(%rip), %rsi      # 0x404c
movb $0x0, %al
callq 0x1100
movq -0x186d8(%rbp), %rdi
movl -0x187e8(%rbp), %edx
leaq 0x1aec(%rip), %rsi      # 0x4012
movb $0x0, %al
callq 0x1100
movl $0x0, -0x187f0(%rbp)
cmpl $0x14, -0x187f0(%rbp)
jge 0x2580
movslq -0x187f0(%rbp), %rax
movq -0x18780(%rbp,%rax,8), %rax
movq %rax, -0x187f8(%rbp)
cmpq $0x0, %rax
je 0x256d
movq -0x187f8(%rbp), %rdi
movl $0x1, %esi
callq 0x10e0
jmp 0x256f
movl -0x187f0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x187f0(%rbp)
jmp 0x2537
jmp 0x2355
movq -0x186c8(%rbp), %rdi
callq 0x10c0
movq -0x186d0(%rbp), %rdi
callq 0x10c0
movq -0x186d8(%rbp), %rdi
callq 0x10c0
addq $0x18800, %rsp          # imm = 0x18800
popq %rbp
retq
nopw %cs:(%rax,%rax)