// File: /workspace/github_cpp_makefile_star2_O1/Agusyc[P]CTRPG/src/jsonparser.cpp
// Function: parsePlayer()
Player parsePlayer() {
    Json::Value jPlayer; // The root element

    Player player; // The "Player" struct

    struct stat buffer;
    if(stat("./json/player.json", &buffer) == 0) {
        // File exists

        ifstream ifs("./json/player.json");

        Json::Reader reader; // The reader... that reads.

        bool parsingSuccessful = reader.parse(ifs, jPlayer);
        if (!parsingSuccessful) {
            // Print error
            cout << "Failed to parse the player." << endl << "Error:" << endl << reader.getFormattedErrorMessages();
        }

    } else {
        // The player doesn't exist.
        cout << "Welcome to CTRPG! Please enter your name: ";
        string name;

        cin >> name;

        // We create a new player.

        jPlayer["name"] = name;
        jPlayer["attack"] = 1;
        jPlayer["defense"] = 1;
        jPlayer["shieldDefense"] = 1;
        jPlayer["mana"] = 5;
        jPlayer["stamina"] = 5;
        jPlayer["hp"] = 10;
        jPlayer["xp"] = 0;
        jPlayer["level"] = 1;
        jPlayer["goal"] = 10;
        jPlayer["attacks"].append(1);
        jPlayer["attacks"].append(2);
        jPlayer["items"].append(0);
        jPlayer["items"].append(1);

        // We write the new data to a file.

        Json::StyledWriter writer;

        ofstream ofs("./json/player.json");

        ofs << writer.write(jPlayer);
        ofs.close();
    }

    player.name = jPlayer["name"].asString();
    player.attack = jPlayer["attack"].asInt();
    player.defense = jPlayer["defense"].asInt();
    player.shieldDefense = jPlayer["shieldDefense"].asInt();
    player.mana = jPlayer["mana"].asInt();
    player.stamina = jPlayer["stamina"].asInt();
    player.hp = jPlayer["hp"].asInt();
    player.xp = jPlayer["xp"].asInt();
    player.level =jPlayer["level"].asInt();
    player.goal = jPlayer["goal"].asInt();

    // Iterates trough the array "attacks", which contains all the indexes of the attacks of the player
    for (const Json::Value& attack : jPlayer["attacks"]) { // "attack" is the current index
        player.attacks.push_back(parseAttack(attack.asInt())); // Pushes the attack to the vector
    }

    // Itereates trough the array "items", which contains all the indexes of the items of the player
    for (const Json::Value& item : jPlayer["items"]) { // "item" is the current index
        player.items.push_back(parseItem(item.asInt())); // Pushes the item to the vector
    }

    return player;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdi, %rbx
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x3100
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbx)
movups %xmm0, 0x58(%rbx)
movq %rbx, -0x30(%rbp)
movups %xmm0, 0x68(%rbx)
leaq 0x253d(%rip), %rdi      # 0xc3ef
leaq -0x440(%rbp), %rsi
callq 0x3240
testl %eax, %eax
je 0xa2d5
movq 0x5103(%rip), %rdi      # 0xefd0
leaq 0x270b(%rip), %rsi      # 0xc5df
movl $0x2a, %edx
callq 0x32f0
leaq -0x68(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movq 0x50e7(%rip), %rdi      # 0xefe0
leaq -0x78(%rbp), %rsi
callq 0x3340
leaq -0x2a0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3460
leaq 0x262f(%rip), %rsi      # 0xc548
leaq -0x58(%rbp), %rdi
callq 0x30e0
leaq -0x2a0(%rbp), %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x3170
leaq 0x2424(%rip), %rsi      # 0xc378
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x3170
leaq 0x2444(%rip), %rsi      # 0xc3cc
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x3170
leaq 0x25f9(%rip), %rsi      # 0xc5b5
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
movl $0x5, %esi
callq 0x3170
leaq 0x23e4(%rip), %rsi      # 0xc3d4
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
movl $0x5, %esi
callq 0x3170
leaq 0x23b5(%rip), %rsi      # 0xc3d9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
movl $0xa, %esi
callq 0x3170
leaq 0x2371(%rip), %rsi      # 0xc3c9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
xorl %esi, %esi
callq 0x3170
leaq 0x235d(%rip), %rsi      # 0xc3e6
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x3170
leaq 0x232c(%rip), %rsi      # 0xc3e9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq -0x2a0(%rbp), %rdi
movl $0xa, %esi
callq 0x3170
leaq 0x22f0(%rip), %rsi      # 0xc3e1
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq 0x22ad(%rip), %rsi      # 0xc3c1
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %r14
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x3170
leaq -0x2a0(%rbp), %rsi
movq %r14, %rdi
callq 0x3370
leaq -0x2a0(%rbp), %rdi
callq 0x3140
leaq 0x226e(%rip), %rsi      # 0xc3c1
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %r14
leaq -0x2a0(%rbp), %rdi
movl $0x2, %esi
callq 0x3170
leaq -0x2a0(%rbp), %rsi
movq %r14, %rdi
callq 0x3370
leaq -0x2a0(%rbp), %rdi
callq 0x3140
leaq 0x2270(%rip), %rsi      # 0xc402
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %r14
leaq -0x2a0(%rbp), %rdi
xorl %esi, %esi
callq 0x3170
leaq -0x2a0(%rbp), %rsi
movq %r14, %rdi
callq 0x3370
leaq -0x2a0(%rbp), %rdi
callq 0x3140
leaq 0x2234(%rip), %rsi      # 0xc402
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %r14
leaq -0x2a0(%rbp), %rdi
movl $0x1, %esi
callq 0x3170
leaq -0x2a0(%rbp), %rsi
movq %r14, %rdi
callq 0x3370
leaq -0x2a0(%rbp), %rdi
callq 0x3140
leaq -0x3b0(%rbp), %rdi
callq 0x3060
leaq 0x21d6(%rip), %rsi      # 0xc3ef
leaq -0x2a0(%rbp), %rdi
movl $0x10, %edx
callq 0x32b0
leaq -0x98(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x3350
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
leaq -0x2a0(%rbp), %rdi
callq 0x32f0
leaq -0x88(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa270
callq 0x3260
leaq -0x2a0(%rbp), %rdi
callq 0x33a0
movq 0x4d45(%rip), %rax      # 0xefc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x298(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x2a0(%rbp,%rcx)
callq 0x3200
leaq -0x1a8(%rbp), %rdi
callq 0x30c0
leaq -0x3b0(%rbp), %rdi
callq 0x7ef6
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0xa424
callq 0x3260
jmp 0xa424
leaq 0x2113(%rip), %rsi      # 0xc3ef
leaq -0x2a0(%rbp), %rdi
movl $0x8, %edx
callq 0x34f0
leaq -0x3b0(%rbp), %rdi
callq 0x32a0
leaq -0x3b0(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
leaq -0x58(%rbp), %rdx
movl $0x1, %ecx
callq 0x3510
testb %al, %al
jne 0xa3d6
movq 0x4cac(%rip), %r14      # 0xefd0
leaq 0x2298(%rip), %rsi      # 0xc5c3
movl $0x1b, %edx
movq %r14, %rdi
callq 0x32f0
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0x4c7a(%rip), %rdi      # 0xefd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq %rax, %r14
leaq 0x2174(%rip), %rsi      # 0xc4e1
movl $0x6, %edx
movq %rax, %rdi
callq 0x32f0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq %rax, %r14
leaq -0x78(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x3420
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq %r14, %rdi
callq 0x32f0
leaq -0x68(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa3d6
callq 0x3260
leaq -0x2b8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa3eb
callq 0x3260
leaq -0x300(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa400
callq 0x3260
leaq -0x360(%rbp), %rdi
callq 0xa850
leaq -0x3b0(%rbp), %rdi
callq 0xa9de
leaq -0x2a0(%rbp), %rdi
callq 0x3080
leaq 0x211d(%rip), %rsi      # 0xc548
leaq -0x58(%rbp), %rdi
callq 0x30e0
leaq -0x2a0(%rbp), %rdi
movq %rax, %rsi
callq 0x3500
leaq -0x2a0(%rbp), %r14
movq -0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x3330
movq (%r14), %rdi
leaq -0x290(%rbp), %rbx
cmpq %rbx, %rdi
je 0xa46a
callq 0x3260
leaq 0x1f07(%rip), %rsi      # 0xc378
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x20(%rcx)
leaq 0x1f3c(%rip), %rsi      # 0xc3cc
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x24(%rcx)
leaq 0x2106(%rip), %rsi      # 0xc5b5
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x28(%rcx)
leaq 0x1f06(%rip), %rsi      # 0xc3d4
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x2c(%rcx)
leaq 0x1eec(%rip), %rsi      # 0xc3d9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x30(%rcx)
leaq 0x1ebd(%rip), %rsi      # 0xc3c9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x34(%rcx)
leaq 0x1ebb(%rip), %rsi      # 0xc3e6
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x3c(%rcx)
leaq 0x1e9f(%rip), %rsi      # 0xc3e9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x38(%rcx)
leaq 0x1e78(%rip), %rsi      # 0xc3e1
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x40(%rcx)
leaq 0x1e39(%rip), %rsi      # 0xc3c1
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %r14
leaq -0x3b0(%rbp), %rdi
movq %rax, %rsi
callq 0x32d0
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x33c0
movq -0x30(%rbp), %rax
leaq 0x48(%rax), %r14
leaq -0x3b0(%rbp), %r15
leaq -0x78(%rbp), %r12
leaq -0x2a0(%rbp), %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x3040
testb %al, %al
jne 0xa618
movq %r15, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x33f0
movq %r13, %rdi
movl %eax, %esi
callq 0x973e
movq %r14, %rdi
movq %r13, %rsi
callq 0xaa2c
movq -0x2a0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa60e
callq 0x3260
movq %r15, %rdi
callq 0x3070
jmp 0xa5c9
leaq 0x1de3(%rip), %rsi      # 0xc402
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %r14
leaq -0x3b0(%rbp), %rdi
movq %rax, %rsi
callq 0x32d0
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x33c0
movq -0x30(%rbp), %rax
leaq 0x60(%rax), %r14
leaq -0x3b0(%rbp), %r15
leaq -0x78(%rbp), %r12
leaq -0x2a0(%rbp), %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x3040
testb %al, %al
jne 0xa6af
movq %r15, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x33f0
movq %r13, %rdi
movl %eax, %esi
callq 0x944f
movq %r14, %rdi
movq %r13, %rsi
callq 0xacc8
movq -0x2a0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa6a5
callq 0x3260
movq %r15, %rdi
callq 0x3070
jmp 0xa660
leaq -0x58(%rbp), %rdi
callq 0x3140
movq -0x30(%rbp), %rax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x68(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa794
callq 0x3260
jmp 0xa794
jmp 0xa791
movq %rax, %r14
jmp 0xa7a0
jmp 0xa7e2
jmp 0xa71a
movq %rax, %r14
leaq -0x88(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa71d
callq 0x3260
jmp 0xa71d
movq %rax, %r14
leaq -0x2a0(%rbp), %rdi
callq 0x33d0
jmp 0xa72e
movq %rax, %r14
leaq -0x3b0(%rbp), %rdi
callq 0x7ef6
jmp 0xa7b3
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
jmp 0xa772
jmp 0xa7b0
movq %rax, %r14
leaq -0x2a0(%rbp), %rdi
callq 0x3140
jmp 0xa7b3
jmp 0xa7b0
jmp 0xa7e2
jmp 0xa7e2
jmp 0xa7e2
jmp 0xa7e2
jmp 0xa7e2
jmp 0xa7e2
movq %rax, %r14
leaq -0x3b0(%rbp), %rdi
callq 0xa800
leaq -0x2a0(%rbp), %rdi
callq 0x3080
jmp 0xa7e5
jmp 0xa7e2
movq %rax, %r14
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
jne 0xa7d3
jmp 0xa7e5
jmp 0xa7e2
jmp 0xa7c4
jmp 0xa7e2
movq %rax, %r14
movq -0x2a0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa7e5
callq 0x3260
jmp 0xa7e5
jmp 0xa7e2
jmp 0xa7e2
jmp 0xa7e2
jmp 0xa7e2
movq %rax, %r14
movq -0x30(%rbp), %rdi
callq 0x7dc6
leaq -0x58(%rbp), %rdi
callq 0x3140
movq %r14, %rdi
callq 0x34d0
nop