// File: msotoodeh[P]asymmetric-passwords/demo/demo.cpp
// Function: demoUserLogin(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 demoUserLogin(
    const std::string& userid,
    const std::string& password,
    const std::string& domain)
{
    printf("\n-- CLIENT ---- LOGIN ----------------------------------------\n");
    APUser user(userid, password, domain);
    printf(" user id ........... : %s\n", userid.c_str());
    printf(" password .......... : %s\n", password.c_str());
    printf(" domain ............ : %s\n", domain.c_str());
    printf(" public key ........ : %s\n", user.getPublicKey().c_str());

    std::string login_token = user.login(600);
    printf(" token layout ...... : li.timestamp.duration.signature\n");
    printf(" token: %s\n", login_token.c_str());

    printf("\n~~ SERVER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
    // Locate user's public key
    user_info_record& ui = user_info_records[userid];
    if (ui.publicKey.empty())
    {
        printf(" USER ID '%s' NOT FOUND.\n", userid.c_str());
        return;
    }

    APVerifier verifier = APVerifier();
    if (verifier.setKey(ui.publicKey) == APVerifier::AP_SUCCESS &&
        verifier.parseUserLoginToken(login_token))
    {
        if (verifier.getTimestamp() < ui.last_access_time)
        {
            // Token re-use
            printf(" TOKEN-REUSE ....... : %llu\n", ui.last_access_time);
        }

        // SUCCESS
        printf(" user id ........... : %s\n", userid.c_str());
        printf(" public key ........ : %s\n", verifier.getPublicKey().c_str());
        print_time_value(" expiration time ... :", verifier.getExpirationTime());
        user_info_records[userid].last_access_time = verifier.getTimestamp();
    }
    print_verifier_state(verifier);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x17c924(%rip), %rdi    # 0x581462
xorl %eax, %eax
movb %al, -0x129(%rbp)
callq 0x4d79b0
movq -0x8(%rbp), %rsi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rcx
leaq -0x58(%rbp), %rdi
callq 0x407bc0
movq -0x8(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
movb -0x129(%rbp), %al
leaq 0x17c7bc(%rip), %rdi    # 0x581335
callq 0x4d79b0
jmp 0x404b80
movq -0x10(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c7bd(%rip), %rdi    # 0x581350
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404b9c
movq -0x18(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c7bc(%rip), %rdi    # 0x58136b
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404bb8
leaq -0x88(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x407df0
jmp 0x404bca
leaq -0x88(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c7a6(%rip), %rdi    # 0x581386
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404be9
leaq -0x88(%rbp), %rdi
callq 0x47ebf0
leaq -0xa8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x258, %edx            # imm = 0x258
callq 0x4083f0
jmp 0x404c0c
leaq 0x17c88f(%rip), %rdi    # 0x5814a2
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404c1c
leaq -0xa8(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c7c9(%rip), %rdi    # 0x5813fb
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404c3b
leaq 0x17c7c5(%rip), %rdi    # 0x581407
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404c4b
movq -0x8(%rbp), %rsi
leaq 0x1f0b1a(%rip), %rdi    # 0x5f5770
callq 0x405a50
movq %rax, -0x138(%rbp)
jmp 0x404c64
movq -0x138(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
addq $0x28, %rdi
callq 0x47f110
testb $0x1, %al
jne 0x404c88
jmp 0x404cf2
movq -0x8(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c83f(%rip), %rdi    # 0x5814da
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404ca4
movl $0x1, -0xb4(%rbp)
jmp 0x404eb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x404ee8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x47ebf0
jmp 0x404ee8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x404edc
leaq -0x108(%rbp), %rdi
callq 0x4088d0
jmp 0x404d00
movq -0xb0(%rbp), %rsi
addq $0x28, %rsi
leaq -0x108(%rbp), %rdi
callq 0x408980
movl %eax, -0x13c(%rbp)
jmp 0x404d1f
movl -0x13c(%rbp), %eax
cmpl $0x0, %eax
jne 0x404e8e
leaq -0x108(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x4090d0
movb %al, -0x13d(%rbp)
jmp 0x404d49
movb -0x13d(%rbp), %al
testb $0x1, %al
jne 0x404d58
jmp 0x404e8e
leaq -0x108(%rbp), %rdi
callq 0x405950
movq %rax, -0x148(%rbp)
jmp 0x404d6d
movq -0x148(%rbp), %rax
movq -0xb0(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x404dad
movq -0xb0(%rbp), %rax
movq (%rax), %rsi
leaq 0x17c763(%rip), %rdi    # 0x5814f4
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404d9a
jmp 0x404dad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x404ed0
movq -0x8(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c575(%rip), %rdi    # 0x581335
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404dc9
leaq -0x128(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x4089f0
jmp 0x404dde
leaq -0x128(%rbp), %rdi
callq 0x480630
movq %rax, %rsi
leaq 0x17c592(%rip), %rdi    # 0x581386
xorl %eax, %eax
callq 0x4d79b0
jmp 0x404dfd
leaq -0x128(%rbp), %rdi
callq 0x47ebf0
leaq -0x108(%rbp), %rdi
callq 0x405bc0
movq %rax, -0x150(%rbp)
jmp 0x404e1e
movq -0x150(%rbp), %rsi
leaq 0x17c6e5(%rip), %rdi    # 0x581511
callq 0x404560
jmp 0x404e33
leaq -0x108(%rbp), %rdi
callq 0x405950
movq %rax, -0x158(%rbp)
jmp 0x404e48
movq -0x8(%rbp), %rsi
leaq 0x1f091d(%rip), %rdi    # 0x5f5770
callq 0x405a50
movq %rax, -0x160(%rbp)
jmp 0x404e61
movq -0x160(%rbp), %rax
movq -0x158(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x404e8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x47ebf0
jmp 0x404ed0
leaq -0x108(%rbp), %rdi
callq 0x404680
jmp 0x404e9c
leaq -0x108(%rbp), %rdi
callq 0x408940
movl $0x0, -0xb4(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x47ebf0
leaq -0x58(%rbp), %rdi
callq 0x407c00
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x108(%rbp), %rdi
callq 0x408940
leaq -0xa8(%rbp), %rdi
callq 0x47ebf0
leaq -0x58(%rbp), %rdi
callq 0x407c00
movq -0x60(%rbp), %rdi
callq 0x4b0e70
nopw (%rax,%rax)