// File: /workspace/github_cpp_makefile_star2_O3/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 0x402697
movq %rsi, %rbx
movq 0x8(%rsi), %rdi
leaq 0xf0775(%rip), %r15     # 0x4f2b51
leaq 0x10dd0d(%rip), %rdx    # 0x5100f0
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e760
movq 0x10(%rbx), %rdi
leaq 0x10e0e8(%rip), %rdx    # 0x5104e0
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e760
cmpl $0x4, %r14d
jb 0x402440
movq 0x18(%rbx), %rdi
leaq 0xd813e(%rip), %rsi     # 0x4da551
leaq 0x10e89e(%rip), %rdx    # 0x510cb8
xorl %eax, %eax
callq 0x42e760
cmpl $0x4, %r14d
je 0x402440
movq 0x20(%rbx), %rdi
leaq 0xf071f(%rip), %rsi     # 0x4f2b51
leaq 0x10e497(%rip), %rdx    # 0x5108d0
xorl %eax, %eax
callq 0x42e760
leaq 0xd1bbd(%rip), %rdi     # 0x4d4004
leaq 0x10dca2(%rip), %rbx    # 0x5100f0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x42e5d0
leaq 0xd1cc6(%rip), %rdi     # 0x4d4125
callq 0x43d370
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 0x42e5d0
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 0x40316d
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 0x40a260
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 0x40a492
testl %eax, %eax
jne 0x4026d1
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 0xef4d4(%rip), %rdx     # 0x4f1a5d
leaq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rdx, %rsi
callq 0x40272a
leaq 0xd1b85(%rip), %rdi     # 0x4d4125
callq 0x43d370
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 0x40c850
incq %r12
cmpq $0x1fe0, %r12           # imm = 0x1FE0
jne 0x4025af
movl 0x10e6e0(%rip), %eax    # 0x510cb8
cmpl 0x18(%rsp), %eax
jg 0x4026f0
testl %eax, %eax
jle 0x402605
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
movsbl (%rax,%rbx), %edi
callq 0x43d510
incq %rbx
movslq 0x10e6b8(%rip), %rax    # 0x510cb8
cmpq %rax, %rbx
jl 0x4025e8
movl $0xa, %edi
callq 0x43d510
leaq 0xd1b0f(%rip), %rdi     # 0x4d4125
callq 0x43d370
cmpl $0x0, 0x10e696(%rip)    # 0x510cb8
jle 0x40266b
xorl %ebx, %ebx
movl $0xcccccccd, %r14d      # imm = 0xCCCCCCCD
testq %rbx, %rbx
je 0x40264e
movl %ebx, %eax
imulq %r14, %rax
shrq $0x22, %rax
leal (%rax,%rax,4), %eax
movl %ebx, %ecx
subl %eax, %ecx
jne 0x40264e
movl $0x20, %edi
callq 0x43d510
movq 0x10(%rsp), %rax
movsbl (%rax,%rbx), %edi
callq 0x43d510
incq %rbx
movslq 0x10e652(%rip), %rax    # 0x510cb8
cmpq %rax, %rbx
jl 0x40262c
movl $0xa, %edi
callq 0x43d510
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x402684
callq 0x40a6d0
xorl %eax, %eax
addq $0xc00, %rsp            # imm = 0xC00
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0xd1a91(%rip), %rdi     # 0x4d412f
callq 0x43d370
leaq 0xd1a8c(%rip), %rdi     # 0x4d4136
callq 0x43d370
leaq 0xd1a99(%rip), %rdi     # 0x4d414f
callq 0x43d370
leaq 0xd1aaa(%rip), %rdi     # 0x4d416c
callq 0x43d370
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x42daa0
leaq 0xd1953(%rip), %rdi     # 0x4d402b
leaq 0xd19db(%rip), %rsi     # 0x4d40ba
leaq 0xd19dd(%rip), %rcx     # 0x4d40c3
movl $0x46, %edx
callq 0x4273e0
leaq 0xd19e3(%rip), %rdi     # 0x4d40da
leaq 0xd19bc(%rip), %rsi     # 0x4d40ba
leaq 0xd19be(%rip), %rcx     # 0x4d40c3
movl $0x55, %edx
callq 0x4273e0
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x402721
callq 0x40a6d0
movq %rbx, %rdi
callq 0x422130
nop