// File: msotoodeh[P]asymmetric-passwords/demo/demo.cpp
// Function: demoChangeUserPassword(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void demoChangeUserPassword(
    const std::string& userid,
    const std::string& old_password,
    const std::string& new_password,
    const std::string& domain)
{
    printf("\n-- CLIENT ---- CHANGE PASSWORD ------------------------------\n");
    APUser new_user(userid, new_password, domain);
    APUser old_user(userid, old_password, domain);
    printf(" user id ........... : %s\n", userid.c_str());
    printf(" old password ...... : %s\n", old_password.c_str());
    printf(" new password ...... : %s\n", new_password.c_str());
    printf(" domain ............ : %s\n", domain.c_str());
    printf(" new public key .... : %s\n", new_user.getPublicKey().c_str());
    std::string new_key_token = old_user.changePassword(new_user);
    printf(" token layout ...... : cp.timestamp.new_public_key.signature\n");
    printf(" token: %s\n", new_key_token.c_str());

    printf("\n~~ SERVER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");

    // Locate user's public key
    user_info_record& ui = user_info_records[userid];
    APVerifier verifier = APVerifier();
    if (verifier.setKey(ui.publicKey) == APVerifier::AP_SUCCESS &&
        verifier.parseChangePasswordToken(new_key_token))
    {
        // SUCCESS: Update user record
        user_info_records[userid].publicKey = verifier.getPublicKey();
        user_info_records[userid].last_access_time = verifier.getTimestamp();
    }
    else
    {
        // ERROR
    }

    print_verifier_state(verifier);
    printf(" new public key .... : %s\n", verifier.getPublicKey().c_str());
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq 0x17c606(%rip), %rdi    # 0x581528
xorl %eax, %eax
callq 0x4d79b0
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0x60(%rbp), %rdi
callq 0x407bc0
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
callq 0x407bc0
jmp 0x404f58
movq -0x8(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c3ca(%rip), %rdi    # 0x581335
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404f74
movq -0x10(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c5e1(%rip), %rdi    # 0x581568
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404f90
movq -0x18(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c5e0(%rip), %rdi    # 0x581583
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404fac
movq -0x20(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c3ac(%rip), %rdi    # 0x58136b
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404fc8
leaq -0xd0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x407df0
jmp 0x404fda
leaq -0xd0(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c5ae(%rip), %rdi    # 0x58159e
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404ff9
leaq -0xd0(%rbp), %rdi
callq 0x47ebf0
leaq -0xf0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x4082a0
jmp 0x40501e
leaq 0x17c594(%rip), %rdi    # 0x5815b9
xorl %eax, %eax
callq 0x4d79b0
jmp 0x40502e
leaq -0xf0(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c3b7(%rip), %rdi    # 0x5813fb
xorl %eax, %eax
callq 0x4d79b0
jmp 0x40504d
leaq 0x17c3b3(%rip), %rdi    # 0x581407
xorl %eax, %eax
callq 0x4d79b0
jmp 0x40505d
movq -0x8(%rbp), %rsi
leaq 0x1f0708(%rip), %rdi    # 0x5f5770
callq 0x405a50
movq %rax, -0x190(%rbp)
jmp 0x405076
movq -0x190(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x4088d0
jmp 0x405092
movq -0xf8(%rbp), %rsi
addq $0x28, %rsi
leaq -0x148(%rbp), %rdi
callq 0x408980
movl %eax, -0x194(%rbp)
jmp 0x4050b1
movl -0x194(%rbp), %eax
cmpl $0x0, %eax
jne 0x405223
leaq -0x148(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x4091a0
movb %al, -0x195(%rbp)
jmp 0x4050db
movb -0x195(%rbp), %al
testb $0x1, %al
jne 0x4050ea
jmp 0x405223
leaq -0x168(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x4089f0
jmp 0x4050ff
movq -0x8(%rbp), %rsi
leaq 0x1f0666(%rip), %rdi    # 0x5f5770
callq 0x405a50
movq %rax, -0x1a0(%rbp)
jmp 0x405118
movq -0x1a0(%rbp), %rdi
addq $0x28, %rdi
leaq -0x168(%rbp), %rsi
callq 0x47ec20
jmp 0x405131
leaq -0x168(%rbp), %rdi
callq 0x47ebf0
leaq -0x148(%rbp), %rdi
callq 0x405950
movq %rax, -0x1a8(%rbp)
jmp 0x405152
movq -0x8(%rbp), %rsi
leaq 0x1f0613(%rip), %rdi    # 0x5f5770
callq 0x405a50
movq %rax, -0x1b0(%rbp)
jmp 0x40516b
movq -0x1b0(%rbp), %rax
movq -0x1a8(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x405225
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x4052eb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x4052df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x47ebf0
jmp 0x4052df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x4052d3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
jmp 0x4052c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x47ebf0
jmp 0x4052c7
jmp 0x405225
leaq -0x148(%rbp), %rdi
callq 0x404680
jmp 0x405233
leaq -0x188(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x4089f0
jmp 0x405248
leaq -0x188(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c340(%rip), %rdi    # 0x58159e
xorl %eax, %eax
callq 0x4d79b0
jmp 0x405267
leaq -0x188(%rbp), %rdi
callq 0x47ebf0
leaq -0x148(%rbp), %rdi
callq 0x408940
leaq -0xf0(%rbp), %rdi
callq 0x47ebf0
leaq -0xa0(%rbp), %rdi
callq 0x407c00
leaq -0x60(%rbp), %rdi
callq 0x407c00
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa8(%rbp)
movl %eax, -0xac(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x47ebf0
leaq -0x148(%rbp), %rdi
callq 0x408940
leaq -0xf0(%rbp), %rdi
callq 0x47ebf0
leaq -0xa0(%rbp), %rdi
callq 0x407c00
leaq -0x60(%rbp), %rdi
callq 0x407c00
movq -0xa8(%rbp), %rdi
callq 0x4b0e70