// File: flastest[P]HW2_Systems_flaster_strand/test_cache_lib.cc
// Function: testEvictorWithFullCache(bool)
bool testEvictorWithFullCache(bool DEBUG_PRINT_MESSAGES)
{
    if (DEBUG_PRINT_MESSAGES) std::cout<<"testing evicting from a full array and putting something new in"<<std::endl;
    auto my_cache = makeCache(13);
    // i like bridge
    char spades[]{ "AK10xxx" };
    my_cache->set("spades", spades, 8);

    char diamonds[]{ "KJxx" };
    my_cache->set("diamonds", diamonds, 5);

    if(DEBUG_PRINT_MESSAGES) std::cout<<"array is full"<<std::endl;

    //at this point, the cache should be full with spades and diamonds
    //spades should be evicted so that hearts can be inserted.
    char hearts[]{ "QJx" };
    my_cache->set("hearts", hearts, 4);    

    if(DEBUG_PRINT_MESSAGES) std::cout<<"attempted to add hearts"<<std::endl;

    Cache::size_type size_hearts;
    Cache::size_type size_diamonds;
    Cache::size_type size_spades;
    auto hearts_gotten = (my_cache->get("hearts", size_hearts));
    auto diamonds_gotten = (my_cache->get("diamonds", size_diamonds));
    auto spades_gotten = (my_cache->get("spades", size_spades));
    
    if(DEBUG_PRINT_MESSAGES) std::cout<<"hearts should've been added, hearts_gotten is "<< hearts_gotten <<"."<<std::endl;
    if(DEBUG_PRINT_MESSAGES) std::cout<<"compare hearts_gotten to hearts, which is "<<hearts<<"."<<std::endl;

    //convert get results to strings
    std::string hearts_holding_from_cache(hearts_gotten);
    std::string diamonds_holding_from_cache(diamonds_gotten);

    //test that spades are removed
    //check that diamonds are still there
    bool hearts_in_cache = (hearts_holding_from_cache == "QJx");
    bool diamonds_in_cache = (diamonds_holding_from_cache == "KJxx");
    bool spades_not_in_cache = (spades_gotten == nullptr);

    return (hearts_in_cache && diamonds_in_cache && spades_not_in_cache);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movb %dil, %al
andb $0x1, %al
movb %al, -0x1(%rbp)
testb $0x1, -0x1(%rbp)
je 0x708b
movq 0x9f68(%rip), %rdi      # 0x10fd8
leaq 0x423b(%rip), %rsi      # 0xb2b2
callq 0x21b0
movq %rax, %rdi
movq 0x9f3a(%rip), %rsi      # 0x10fc0
callq 0x21e0
movl $0xd, %edi
callq 0x6430
movq %rax, -0x10(%rbp)
movabsq $0x78787830314b41, %rax # imm = 0x78787830314B41
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x198(%rbp)
callq 0x22e0
movq -0x198(%rbp), %rdx
leaq 0x422a(%rip), %rsi      # 0xb2fa
leaq -0x38(%rbp), %rdi
callq 0x80f0
jmp 0x70db
movq -0x1a0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x18(%rbp), %rdx
movl $0x8, %ecx
callq 0x25c0
jmp 0x70f6
leaq -0x38(%rbp), %rdi
callq 0x2100
leaq -0x39(%rbp), %rdi
callq 0x2200
movb $0x0, -0x50(%rbp)
movl $0x78784a4b, -0x54(%rbp) # imm = 0x78784A4B
movq -0x10(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x22e0
movq -0x1a8(%rbp), %rdx
leaq 0x41ca(%rip), %rsi      # 0xb306
leaq -0x78(%rbp), %rdi
callq 0x80f0
jmp 0x7147
movq -0x1b0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x54(%rbp), %rdx
movl $0x5, %ecx
callq 0x25c0
jmp 0x7162
leaq -0x78(%rbp), %rdi
callq 0x2100
leaq -0x79(%rbp), %rdi
callq 0x2200
testb $0x1, -0x1(%rbp)
je 0x7204
movq 0x9e53(%rip), %rdi      # 0x10fd8
leaq 0x4183(%rip), %rsi      # 0xb30f
callq 0x21b0
movq %rax, %rdi
movq 0x9e25(%rip), %rsi      # 0x10fc0
callq 0x21e0
jmp 0x7204
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x71c5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x2100
leaq -0x39(%rbp), %rdi
callq 0x2200
jmp 0x774e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x71f6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x2100
leaq -0x79(%rbp), %rdi
callq 0x2200
jmp 0x774e
movl $0x784a51, -0x80(%rbp)  # imm = 0x784A51
movq -0x10(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x22e0
movq -0x1b8(%rbp), %rdx
leaq 0x40fb(%rip), %rsi      # 0xb332
leaq -0xa0(%rbp), %rdi
callq 0x80f0
jmp 0x7245
movq -0x1c0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl $0x4, %ecx
callq 0x25c0
jmp 0x7263
leaq -0xa0(%rbp), %rdi
callq 0x2100
leaq -0xa1(%rbp), %rdi
callq 0x2200
testb $0x1, -0x1(%rbp)
je 0x72dc
movq 0x9d50(%rip), %rdi      # 0x10fd8
leaq 0x4092(%rip), %rsi      # 0xb321
callq 0x21b0
movq %rax, %rdi
movq 0x9d22(%rip), %rsi      # 0x10fc0
callq 0x21e0
jmp 0x72dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x72cb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x2100
leaq -0xa1(%rbp), %rdi
callq 0x2200
jmp 0x774e
movq -0x10(%rbp), %rax
movq %rax, -0x1d0(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x22e0
movq -0x1c8(%rbp), %rdx
leaq 0x402a(%rip), %rsi      # 0xb332
leaq -0xd8(%rbp), %rdi
callq 0x80f0
jmp 0x7316
movq -0x1d0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0x2640
movq %rax, -0x1d8(%rbp)
jmp 0x7339
leaq -0xd8(%rbp), %rdi
callq 0x2100
leaq -0xd9(%rbp), %rdi
callq 0x2200
movq -0x1d8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x22e0
movq -0x1e0(%rbp), %rdx
leaq 0x3f7b(%rip), %rsi      # 0xb306
leaq -0x108(%rbp), %rdi
callq 0x80f0
jmp 0x7399
movq -0x1e8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0xac(%rbp), %rdx
callq 0x2640
movq %rax, -0x1f0(%rbp)
jmp 0x73bc
leaq -0x108(%rbp), %rdi
callq 0x2100
leaq -0x109(%rbp), %rdi
callq 0x2200
movq -0x1f0(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq -0x139(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x22e0
movq -0x1f8(%rbp), %rdx
leaq 0x3eec(%rip), %rsi      # 0xb2fa
leaq -0x138(%rbp), %rdi
callq 0x80f0
jmp 0x741c
movq -0x200(%rbp), %rdi
leaq -0x138(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x2640
movq %rax, -0x208(%rbp)
jmp 0x743f
leaq -0x138(%rbp), %rdi
callq 0x2100
leaq -0x139(%rbp), %rdi
callq 0x2200
movq -0x208(%rbp), %rax
movq %rax, -0x118(%rbp)
testb $0x1, -0x1(%rbp)
je 0x7559
movq 0x9b62(%rip), %rdi      # 0x10fd8
leaq 0x3ebc(%rip), %rsi      # 0xb339
callq 0x21b0
movq %rax, %rdi
movq -0xb8(%rbp), %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x3f5a(%rip), %rsi      # 0xb3f5
callq 0x21b0
movq %rax, %rdi
movq 0x9b16(%rip), %rsi      # 0x10fc0
callq 0x21e0
jmp 0x7559
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x74da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x2100
leaq -0xd9(%rbp), %rdi
callq 0x2200
jmp 0x774e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x7511
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x2100
leaq -0x109(%rbp), %rdi
callq 0x2200
jmp 0x774e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x7548
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x2100
leaq -0x139(%rbp), %rdi
callq 0x2200
jmp 0x774e
testb $0x1, -0x1(%rbp)
je 0x759c
movq 0x9a72(%rip), %rdi      # 0x10fd8
leaq 0x3dfb(%rip), %rsi      # 0xb368
callq 0x21b0
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x3e6d(%rip), %rsi      # 0xb3f5
callq 0x21b0
movq %rax, %rdi
movq 0x9a29(%rip), %rsi      # 0x10fc0
callq 0x21e0
movq -0xb8(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0x161(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x22e0
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
leaq -0x160(%rbp), %rdi
callq 0x80f0
jmp 0x75d9
leaq -0x161(%rbp), %rdi
callq 0x2200
movq -0xe8(%rbp), %rax
movq %rax, -0x228(%rbp)
leaq -0x189(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x22e0
movq -0x228(%rbp), %rsi
movq -0x220(%rbp), %rdx
leaq -0x188(%rbp), %rdi
callq 0x80f0
jmp 0x7622
leaq -0x189(%rbp), %rdi
callq 0x2200
leaq 0x3ce8(%rip), %rsi      # 0xb31d
leaq -0x160(%rbp), %rdi
callq 0x81a0
movb %al, -0x229(%rbp)
jmp 0x7649
movb -0x229(%rbp), %al
andb $0x1, %al
movb %al, -0x18a(%rbp)
leaq 0x3ca3(%rip), %rsi      # 0xb301
leaq -0x188(%rbp), %rdi
callq 0x81a0
movb %al, -0x22a(%rbp)
jmp 0x7672
movb -0x22a(%rbp), %al
andb $0x1, %al
movb %al, -0x18b(%rbp)
cmpq $0x0, -0x118(%rbp)
sete %al
andb $0x1, %al
movb %al, -0x18c(%rbp)
xorl %eax, %eax
testb $0x1, -0x18a(%rbp)
movb %al, -0x22b(%rbp)
je 0x76c1
xorl %eax, %eax
testb $0x1, -0x18b(%rbp)
movb %al, -0x22b(%rbp)
je 0x76c1
movb -0x18c(%rbp), %al
movb %al, -0x22b(%rbp)
movb -0x22b(%rbp), %al
movb %al, -0x22c(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x2100
leaq -0x160(%rbp), %rdi
callq 0x2100
movb -0x22c(%rbp), %al
andb $0x1, %al
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x161(%rbp), %rdi
callq 0x2200
jmp 0x774e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x189(%rbp), %rdi
callq 0x2200
jmp 0x7742
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x2100
leaq -0x160(%rbp), %rdi
callq 0x2100
movq -0x48(%rbp), %rdi
callq 0x22d0
nopw (%rax,%rax)