// File: /workspace/github_cpp_makefile_star2_O3/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 0x258d(%rip), %rdi      # 0xc3ef
leaq -0x440(%rbp), %rsi
callq 0x3240
testl %eax, %eax
je 0xa285
movq 0x5153(%rip), %rdi      # 0xefd0
leaq 0x275b(%rip), %rsi      # 0xc5df
movl $0x2a, %edx
callq 0x32f0
leaq -0x68(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
movq 0x5137(%rip), %rdi      # 0xefe0
leaq -0x78(%rbp), %rsi
callq 0x3340
leaq -0x2a0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3460
leaq 0x267f(%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 0x2474(%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 0x2494(%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 0x2649(%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 0x2434(%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 0x2405(%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 0x23c1(%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 0x23ad(%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 0x237c(%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 0x2340(%rip), %rsi      # 0xc3e1
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
movq %r14, %rsi
callq 0x3310
movq %r14, %rdi
callq 0x3140
leaq 0x22fd(%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 0x22be(%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 0x22c0(%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 0x2284(%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 0x2226(%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 0xa220
callq 0x3260
leaq -0x2a0(%rbp), %rdi
callq 0x33a0
movq 0x4d95(%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 0x7e6a
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0xa3d4
callq 0x3260
jmp 0xa3d4
leaq 0x2163(%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 0xa386
movq 0x4cfc(%rip), %r14      # 0xefd0
leaq 0x22e8(%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 0x4cca(%rip), %rdi      # 0xefd0
callq 0x3030
movq %rax, %rdi
callq 0x31a0
movq %rax, %r14
leaq 0x21c4(%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 0xa386
callq 0x3260
leaq -0x2b8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa39b
callq 0x3260
leaq -0x300(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa3b0
callq 0x3260
leaq -0x360(%rbp), %rdi
callq 0xa800
leaq -0x3b0(%rbp), %rdi
callq 0xa9a0
leaq -0x2a0(%rbp), %rdi
callq 0x3080
leaq 0x216d(%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 0xa41a
callq 0x3260
leaq 0x1f57(%rip), %rsi      # 0xc378
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x20(%rcx)
leaq 0x1f8c(%rip), %rsi      # 0xc3cc
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x24(%rcx)
leaq 0x2156(%rip), %rsi      # 0xc5b5
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x28(%rcx)
leaq 0x1f56(%rip), %rsi      # 0xc3d4
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x2c(%rcx)
leaq 0x1f3c(%rip), %rsi      # 0xc3d9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x30(%rcx)
leaq 0x1f0d(%rip), %rsi      # 0xc3c9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x34(%rcx)
leaq 0x1f0b(%rip), %rsi      # 0xc3e6
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x3c(%rcx)
leaq 0x1eef(%rip), %rsi      # 0xc3e9
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x38(%rcx)
leaq 0x1ec8(%rip), %rsi      # 0xc3e1
leaq -0x58(%rbp), %rdi
callq 0x30e0
movq %rax, %rdi
callq 0x33f0
movq -0x30(%rbp), %rcx
movl %eax, 0x40(%rcx)
leaq 0x1e89(%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 0xa5c8
movq %r15, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x33f0
movq %r13, %rdi
movl %eax, %esi
callq 0x96ee
movq %r14, %rdi
movq %r13, %rsi
callq 0xa9fa
movq -0x2a0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa5be
callq 0x3260
movq %r15, %rdi
callq 0x3070
jmp 0xa579
leaq 0x1e33(%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 0xa65f
movq %r15, %rdi
callq 0x3360
movq %rax, %rdi
callq 0x33f0
movq %r13, %rdi
movl %eax, %esi
callq 0x93ff
movq %r14, %rdi
movq %r13, %rsi
callq 0xac96
movq -0x2a0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa655
callq 0x3260
movq %r15, %rdi
callq 0x3070
jmp 0xa610
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 0xa744
callq 0x3260
jmp 0xa744
jmp 0xa741
movq %rax, %r14
jmp 0xa750
jmp 0xa792
jmp 0xa6ca
movq %rax, %r14
leaq -0x88(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xa6cd
callq 0x3260
jmp 0xa6cd
movq %rax, %r14
leaq -0x2a0(%rbp), %rdi
callq 0x33d0
jmp 0xa6de
movq %rax, %r14
leaq -0x3b0(%rbp), %rdi
callq 0x7e6a
jmp 0xa763
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
jmp 0xa722
jmp 0xa760
movq %rax, %r14
leaq -0x2a0(%rbp), %rdi
callq 0x3140
jmp 0xa763
jmp 0xa760
jmp 0xa792
jmp 0xa792
jmp 0xa792
jmp 0xa792
jmp 0xa792
jmp 0xa792
movq %rax, %r14
leaq -0x3b0(%rbp), %rdi
callq 0xa7b0
leaq -0x2a0(%rbp), %rdi
callq 0x3080
jmp 0xa795
jmp 0xa792
movq %rax, %r14
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
jne 0xa783
jmp 0xa795
jmp 0xa792
jmp 0xa774
jmp 0xa792
movq %rax, %r14
movq -0x2a0(%rbp), %rdi
cmpq %rbx, %rdi
je 0xa795
callq 0x3260
jmp 0xa795
jmp 0xa792
jmp 0xa792
jmp 0xa792
jmp 0xa792
movq %rax, %r14
movq -0x30(%rbp), %rdi
callq 0x7d3a
leaq -0x58(%rbp), %rdi
callq 0x3140
movq %r14, %rdi
callq 0x34d0
nop