// File: /workspace/github_cpp_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xbf8, %rsp            # imm = 0xBF8
movl %edi, %r14d
leal -0x6(%r14), %eax
cmpl $-0x4, %eax
jbe 0x402652
movq %rsi, %rbx
movq 0x8(%rsi), %rdi
leaq 0xf0736(%rip), %r15     # 0x4f2b11
leaq 0x10dd0e(%rip), %rdx    # 0x5100f0
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e4b0
movq 0x10(%rbx), %rdi
leaq 0x10e0e9(%rip), %rdx    # 0x5104e0
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e4b0
cmpl $0x4, %r14d
jb 0x40243f
movq 0x18(%rbx), %rdi
leaq 0xd80ff(%rip), %rsi     # 0x4da511
leaq 0x10e89f(%rip), %rdx    # 0x510cb8
xorl %eax, %eax
callq 0x42e4b0
cmpl $0x4, %r14d
je 0x40243f
movq 0x20(%rbx), %rdi
leaq 0xf06e0(%rip), %rsi     # 0x4f2b11
leaq 0x10e498(%rip), %rdx    # 0x5108d0
xorl %eax, %eax
callq 0x42e4b0
leaq 0xd1bbe(%rip), %rdi     # 0x4d4004
leaq 0x10dca3(%rip), %r14    # 0x5100f0
movq %r14, %rsi
xorl %eax, %eax
callq 0x42e320
leaq 0xd1c9d(%rip), %rdi     # 0x4d40fb
callq 0x43d0c0
movl 0x10e84f(%rip), %edx    # 0x510cb8
leaq 0xd1b9e(%rip), %rdi     # 0x4d400e
leaq 0x10e069(%rip), %rbx    # 0x5104e0
leaq 0x10e452(%rip), %rcx    # 0x5108d0
movq %rbx, %rsi
xorl %eax, %eax
callq 0x42e320
movq %r14, %rdi
callq 0x4010d8
movq %rax, %r12
leaq 0x810(%rsp), %r15
movl $0x3e8, %edx            # imm = 0x3E8
movq %r15, %rdi
xorl %esi, %esi
callq 0x401098
leaq 0xd1cbf(%rip), %rsi     # 0x4d4170
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 0x403097
leaq 0x30(%rsp), %r13
movl $0x3e8, %edx            # imm = 0x3E8
movq %r13, %rdi
xorl %esi, %esi
callq 0x401098
movslq %r12d, %rsi
movq %r13, (%rsp)
pushq $0x10
popq %rcx
pushq $0x20
popq %r12
movl $0x186a0, %r8d          # imm = 0x186A0
movq %r14, %rdi
movq %r15, %rdx
movq %r12, %r9
callq 0x409f62
movq %rbx, %rdi
callq 0x4010d8
leaq 0x110a6f(%rip), %r14    # 0x512f90
movl $0x1fe0, %r9d           # imm = 0x1FE0
movq %r13, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %rax, %rcx
movq %r14, %r8
callq 0x40a14c
testl %eax, %eax
jne 0x40268a
callq 0x402378
leaq 0xef4ce(%rip), %rsi     # 0x4f1a1d
leaq 0x10(%rsp), %rbx
leaq 0xf(%rsp), %rdx
movq %rbx, %rdi
callq 0x40e360
leaq 0xd1b93(%rip), %rdi     # 0x4d40fb
callq 0x43d0c0
xorl %r15d, %r15d
leaq 0x112a69(%rip), %r12    # 0x514fe0
cmpq $0x1fe0, %r15           # imm = 0x1FE0
je 0x40259c
movzbl (%r15,%r14), %eax
cmpb $0x1, (%rax,%r12)
jne 0x402597
movsbl %al, %esi
movq %rbx, %rdi
callq 0x40bfc0
incq %r15
jmp 0x402577
movl 0x10e716(%rip), %eax    # 0x510cb8
cmpl 0x18(%rsp), %eax
jg 0x4026a3
xorl %ebx, %ebx
cltq
cmpq %rax, %rbx
jge 0x4025ce
movq 0x10(%rsp), %rax
movsbl (%rax,%rbx), %edi
callq 0x43d260
incq %rbx
movl 0x10e6ec(%rip), %eax    # 0x510cb8
jmp 0x4025ae
pushq $0xa
popq %rdi
callq 0x43d260
leaq 0xd1b1e(%rip), %rdi     # 0x4d40fb
callq 0x43d0c0
xorl %r15d, %r15d
pushq $0x5
popq %rbp
pushq $0x20
popq %rbx
xorl %r14d, %r14d
movl %r14d, %eax
xorl %edx, %edx
divl %ebp
movslq 0x10e6bc(%rip), %rcx    # 0x510cb8
cmpq %rcx, %r14
jge 0x40262c
testq %r14, %r14
je 0x402615
leal (%rax,%rax,4), %eax
addl %r15d, %eax
jne 0x402615
movl %ebx, %edi
callq 0x43d260
movq 0x10(%rsp), %rax
movsbl (%rax,%r14), %edi
callq 0x43d260
incq %r14
decl %r15d
jmp 0x4025ee
pushq $0xa
popq %rdi
callq 0x43d260
leaq 0x10(%rsp), %rdi
callq 0x40b930
xorl %eax, %eax
addq $0xbf8, %rsp            # imm = 0xBF8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd1aac(%rip), %rdi     # 0x4d4105
callq 0x43d0c0
leaq 0xd1aa7(%rip), %rdi     # 0x4d410c
callq 0x43d0c0
leaq 0xd1ab4(%rip), %rdi     # 0x4d4125
callq 0x43d0c0
leaq 0xd1ac5(%rip), %rdi     # 0x4d4142
callq 0x43d0c0
pushq $-0x1
popq %rdi
callq 0x42d7f0
leaq 0xd199a(%rip), %rdi     # 0x4d402b
leaq 0xd1a22(%rip), %rsi     # 0x4d40ba
leaq 0xd1a24(%rip), %rcx     # 0x4d40c3
pushq $0x46
jmp 0x4026ba
leaq 0xd1a30(%rip), %rdi     # 0x4d40da
leaq 0xd1a09(%rip), %rsi     # 0x4d40ba
leaq 0xd1a0b(%rip), %rcx     # 0x4d40c3
pushq $0x55
popq %rdx
callq 0x427130
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x40b930
movq %rbx, %rdi
callq 0x421e80
nopl (%rax)