// File: /workspace/github_cpp_makefile_star2_O1/wangyu-[P]pwdgen/main.cpp
// Function: main
int main(int argc, char *argv[])
{
	if(argc!=3&&argc!=4&&argc!=5)
	{
		printf("usage:\n");
		printf(" ./this_program pwd info\n");
		printf(" ./this_program pwd info len\n");
		printf(" ./this_program pwd info len custom_char_list\n");
		exit(-1);
	}

	sscanf(argv[1],"%s",user_passwd);
	sscanf(argv[2],"%s",hkdf_info);
	if(argc>=4)
		sscanf(argv[3],"%d",&output_len);
	if(argc>=5)
		sscanf(argv[4],"%s",custom_str);

	printf("pwd=[%s]\n",user_passwd);
	printf("---------\n");

	printf("info=[%s] len=[%d] str=[%s]\n",hkdf_info,output_len,custom_str);

	int user_passwd_len=strlen(user_passwd);

	unsigned char salt[1000]="";
	char salt_text[1000]="wangyu_personal_salt1";
	md5((uint8_t*)(salt_text),strlen(salt_text),salt);

	unsigned char pbkdf2_output1[1000]="";
	PKCS5_PBKDF2_HMAC_SHA256((uint8_t*)user_passwd,user_passwd_len,salt,16,it_count, 32,pbkdf2_output1);  //TODO argon2 ?

	assert( hkdf_sha256_expand( pbkdf2_output1,32, (unsigned char *)hkdf_info,strlen(hkdf_info), (unsigned char *)inner_output_buf, inner_output_len )  ==0);

	init_table();

	string output="";


	printf("---------\n");

	for(int i=0;i<inner_output_len;i++)
	{
		unsigned char c=inner_output_buf[i];
		//if(char_table[c]) printf("%c",char(c));
		if(char_table[c]) output+=char(c);
	}
	assert(int(output.length())>=output_len);

	for(int i=0;i<output_len;i++)
	{
		printf("%c",output[i]);
	}
	printf("\n");

	printf("---------\n");

	for(int i=0;i<output_len;i++)
	{
		if(i!=0&&i%5==0) printf(" ");
		printf("%c",output[i]);
	}
	printf("\n");
	return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc00, %rsp            # imm = 0xC00
movl %edi, %r14d
leal -0x6(%r14), %eax
cmpl $-0x4, %eax
jbe 0x40269c
movq %rsi, %rbx
movq 0x8(%rsi), %rdi
leaq 0xf06f5(%rip), %r15     # 0x4f2ad1
leaq 0x10dd0d(%rip), %rdx    # 0x5100f0
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e6b0
movq 0x10(%rbx), %rdi
leaq 0x10e0e8(%rip), %rdx    # 0x5104e0
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e6b0
cmpl $0x4, %r14d
jl 0x402421
movq 0x18(%rbx), %rdi
leaq 0xd80be(%rip), %rsi     # 0x4da4d1
leaq 0x10e89e(%rip), %rdx    # 0x510cb8
xorl %eax, %eax
callq 0x42e6b0
cmpl $0x5, %r14d
jl 0x402440
movq 0x20(%rbx), %rdi
leaq 0xf069f(%rip), %rsi     # 0x4f2ad1
leaq 0x10e497(%rip), %rdx    # 0x5108d0
xorl %eax, %eax
callq 0x42e6b0
leaq 0xd1bbd(%rip), %rdi     # 0x4d4004
leaq 0x10dca2(%rip), %rbx    # 0x5100f0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x42e520
leaq 0xd1cc6(%rip), %rdi     # 0x4d4125
callq 0x43d2c0
movl 0x10e84e(%rip), %edx    # 0x510cb8
leaq 0xd1b9d(%rip), %rdi     # 0x4d400e
leaq 0x10e068(%rip), %r14    # 0x5104e0
leaq 0x10e451(%rip), %rcx    # 0x5108d0
movq %r14, %rsi
xorl %eax, %eax
callq 0x42e520
movq %rbx, %rdi
callq 0x4010d8
movq %rax, %r12
leaq 0x810(%rsp), %r15
movl $0x3e8, %edx            # imm = 0x3E8
movq %r15, %rdi
xorl %esi, %esi
callq 0x401098
leaq 0xd1cee(%rip), %rsi     # 0x4d41a0
leaq 0x420(%rsp), %r13
movl $0x3e8, %edx            # imm = 0x3E8
movq %r13, %rdi
callq 0x401040
movq %r13, %rdi
callq 0x4010d8
movq %r13, %rdi
movq %rax, %rsi
movq %r15, %rdx
callq 0x403180
leaq 0x30(%rsp), %r13
movl $0x3e8, %edx            # imm = 0x3E8
movq %r13, %rdi
xorl %esi, %esi
callq 0x401098
movslq %r12d, %rsi
movq %r13, (%rsp)
movl $0x10, %ecx
movl $0x186a0, %r8d          # imm = 0x186A0
movl $0x20, %r9d
movq %rbx, %rdi
movq %r15, %rdx
callq 0x40a1af
movq %r14, %rdi
callq 0x4010d8
leaq 0x110a6d(%rip), %rbx    # 0x512f90
movl $0x20, %esi
movl $0x1fe0, %r9d           # imm = 0x1FE0
movq %r13, %rdi
movq %r14, %rdx
movq %rax, %rcx
movq %rbx, %r8
callq 0x40a3e1
testl %eax, %eax
jne 0x4026d6
leaq 0x10e382(%rip), %r14    # 0x5108d0
movq %r14, %rdi
callq 0x4010d8
testl %eax, %eax
jle 0x402579
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
leaq 0x112a78(%rip), %rdx    # 0x514fe0
movzbl (%rcx,%r14), %esi
movb $0x1, (%rsi,%rdx)
incq %rcx
cmpq %rcx, %rax
jne 0x402568
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xef454(%rip), %rdx     # 0x4f19dd
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rdx, %rsi
callq 0x40272e
leaq 0xd1b85(%rip), %rdi     # 0x4d4125
callq 0x43d2c0
xorl %r12d, %r12d
leaq 0x112a31(%rip), %r13    # 0x514fe0
movzbl (%r12,%rbx), %eax
cmpb $0x1, (%rax,%r13)
jne 0x4025c6
movsbl %al, %esi
movq %r14, %rdi
callq 0x40c7a0
incq %r12
cmpq $0x1fe0, %r12           # imm = 0x1FE0
jne 0x4025af
movl 0x10e6e0(%rip), %eax    # 0x510cb8
cmpl 0x18(%rsp), %eax
jg 0x4026f5
cmpl $0x0, 0x10e6cf(%rip)    # 0x510cb8
jle 0x40260a
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movsbl (%rax,%rbx), %edi
callq 0x43d460
incq %rbx
movslq 0x10e6b3(%rip), %rax    # 0x510cb8
cmpq %rax, %rbx
jl 0x4025ed
movl $0xa, %edi
callq 0x43d460
leaq 0xd1b0a(%rip), %rdi     # 0x4d4125
callq 0x43d2c0
cmpl $0x0, 0x10e691(%rip)    # 0x510cb8
jle 0x402670
xorl %ebx, %ebx
movl $0xcccccccd, %r14d      # imm = 0xCCCCCCCD
testq %rbx, %rbx
je 0x402653
movl %ebx, %eax
imulq %r14, %rax
shrq $0x22, %rax
leal (%rax,%rax,4), %eax
movl %ebx, %ecx
subl %eax, %ecx
jne 0x402653
movl $0x20, %edi
callq 0x43d460
movq 0x10(%rsp), %rax
movsbl (%rax,%rbx), %edi
callq 0x43d460
incq %rbx
movslq 0x10e64d(%rip), %rax    # 0x510cb8
cmpq %rax, %rbx
jl 0x402631
movl $0xa, %edi
callq 0x43d460
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x402689
callq 0x40a620
xorl %eax, %eax
addq $0xc00, %rsp            # imm = 0xC00
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xd1a8c(%rip), %rdi     # 0x4d412f
callq 0x43d2c0
leaq 0xd1a87(%rip), %rdi     # 0x4d4136
callq 0x43d2c0
leaq 0xd1a94(%rip), %rdi     # 0x4d414f
callq 0x43d2c0
leaq 0xd1aa5(%rip), %rdi     # 0x4d416c
callq 0x43d2c0
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42d9f0
leaq 0xd194e(%rip), %rdi     # 0x4d402b
leaq 0xd19d6(%rip), %rsi     # 0x4d40ba
leaq 0xd19d8(%rip), %rcx     # 0x4d40c3
movl $0x46, %edx
callq 0x427330
leaq 0xd19de(%rip), %rdi     # 0x4d40da
leaq 0xd19b7(%rip), %rsi     # 0x4d40ba
leaq 0xd19b9(%rip), %rcx     # 0x4d40c3
movl $0x55, %edx
callq 0x427330
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x402726
callq 0x40a620
movq %rbx, %rdi
callq 0x422080