// File: /workspace/github_cpp_makefile_star2_O2/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 -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x30e0
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbx)
movups %xmm0, 0x58(%rbx)
movups %xmm0, 0x68(%rbx)
leaq 0x15c2(%rip), %rdi      # 0x93ef
leaq -0x438(%rbp), %rsi
callq 0x31e0
testl %eax, %eax
je 0x81ec
movq 0x5188(%rip), %rdi      # 0xcfd0
leaq 0x1766(%rip), %rsi      # 0x95b5
callq 0x3220
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x5175(%rip), %rdi      # 0xcfe0
leaq -0x70(%rbp), %rsi
callq 0x32d0
leaq -0x298(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3420
leaq 0x1693(%rip), %rsi      # 0x951e
leaq -0x50(%rbp), %rdi
callq 0x30b0
leaq -0x298(%rbp), %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x3150
leaq 0x14b4(%rip), %rsi      # 0x9378
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x3150
leaq 0x14d6(%rip), %rsi      # 0x93cc
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x3150
leaq 0x1663(%rip), %rsi      # 0x958b
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
pushq $0x5
popq %rsi
callq 0x3150
leaq 0x147a(%rip), %rsi      # 0x93d4
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
pushq $0x5
popq %rsi
callq 0x3150
leaq 0x144d(%rip), %rsi      # 0x93d9
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
pushq $0xa
popq %rsi
callq 0x3150
leaq 0x140b(%rip), %rsi      # 0x93c9
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
xorl %esi, %esi
callq 0x3150
leaq 0x13f7(%rip), %rsi      # 0x93e6
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x3150
leaq 0x13c8(%rip), %rsi      # 0x93e9
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq -0x298(%rbp), %rdi
pushq $0xa
popq %rsi
callq 0x3150
leaq 0x138e(%rip), %rsi      # 0x93e1
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
movq %r14, %rsi
callq 0x32a0
movq %r14, %rdi
callq 0x3120
leaq 0x134b(%rip), %rsi      # 0x93c1
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %r14
leaq -0x298(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x3150
leaq -0x298(%rbp), %rsi
movq %r14, %rdi
callq 0x3320
leaq -0x298(%rbp), %rdi
callq 0x3120
leaq 0x130e(%rip), %rsi      # 0x93c1
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %r14
leaq -0x298(%rbp), %rdi
pushq $0x2
popq %rsi
callq 0x3150
leaq -0x298(%rbp), %rsi
movq %r14, %rdi
callq 0x3320
leaq -0x298(%rbp), %rdi
callq 0x3120
leaq 0x1312(%rip), %rsi      # 0x9402
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %r14
leaq -0x298(%rbp), %rdi
xorl %esi, %esi
callq 0x3150
leaq -0x298(%rbp), %rsi
movq %r14, %rdi
callq 0x3320
leaq -0x298(%rbp), %rdi
callq 0x3120
leaq 0x12d6(%rip), %rsi      # 0x9402
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %r14
leaq -0x298(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x3150
leaq -0x298(%rbp), %rsi
movq %r14, %rdi
callq 0x3320
leaq -0x298(%rbp), %rdi
callq 0x3120
leaq -0x3a8(%rbp), %rdi
callq 0x3050
leaq 0x127a(%rip), %rsi      # 0x93ef
leaq -0x298(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x3250
leaq -0x90(%rbp), %rdi
leaq -0x3a8(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x32f0
leaq -0x298(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x31d0
leaq -0x90(%rbp), %rdi
callq 0x3100
leaq -0x298(%rbp), %rdi
callq 0x3350
leaq -0x298(%rbp), %rdi
callq 0x3380
leaq -0x3a8(%rbp), %rdi
callq 0x639e
leaq -0x70(%rbp), %rdi
callq 0x3100
jmp 0x829e
leaq 0x11fc(%rip), %rsi      # 0x93ef
leaq -0x298(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x34a0
leaq -0x3a8(%rbp), %rdi
callq 0x3240
leaq -0x3a8(%rbp), %rdi
leaq -0x298(%rbp), %rsi
leaq -0x50(%rbp), %rdx
pushq $0x1
popq %rcx
callq 0x34c0
testb %al, %al
jne 0x8286
movq 0x4d9d(%rip), %rdi      # 0xcfd0
leaq 0x135f(%rip), %rsi      # 0x9599
callq 0x3220
movq %rax, %rdi
callq 0x3110
leaq 0x1269(%rip), %rsi      # 0x94b7
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3110
movq %rax, %r14
leaq -0x70(%rbp), %rdi
leaq -0x3a8(%rbp), %rsi
callq 0x33d0
leaq -0x70(%rbp), %rsi
movq %r14, %rdi
callq 0x31d0
leaq -0x70(%rbp), %rdi
callq 0x3100
leaq -0x3a8(%rbp), %rdi
callq 0x860c
leaq -0x298(%rbp), %rdi
callq 0x3070
leaq 0x1279(%rip), %rsi      # 0x951e
leaq -0x50(%rbp), %rdi
callq 0x30b0
leaq -0x298(%rbp), %rdi
movq %rax, %rsi
callq 0x34b0
leaq -0x298(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32c0
movq %r14, %rdi
callq 0x3100
leaq 0x109a(%rip), %rsi      # 0x9378
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x20(%rbx)
leaq 0x10d3(%rip), %rsi      # 0x93cc
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x24(%rbx)
leaq 0x1277(%rip), %rsi      # 0x958b
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x28(%rbx)
leaq 0x10a5(%rip), %rsi      # 0x93d4
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x2c(%rbx)
leaq 0x108f(%rip), %rsi      # 0x93d9
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x30(%rbx)
leaq 0x1064(%rip), %rsi      # 0x93c9
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x34(%rbx)
leaq 0x1066(%rip), %rsi      # 0x93e6
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x3c(%rbx)
leaq 0x104e(%rip), %rsi      # 0x93e9
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x38(%rbx)
leaq 0x102b(%rip), %rsi      # 0x93e1
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x40(%rbx)
leaq 0xff0(%rip), %rsi       # 0x93c1
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %r14
leaq -0x3a8(%rbp), %rdi
movq %rax, %rsi
callq 0x3270
leaq -0x70(%rbp), %rdi
movq %r14, %rsi
callq 0x3370
leaq 0x48(%rbx), %r14
leaq -0x3a8(%rbp), %r15
leaq -0x70(%rbp), %r12
leaq -0x298(%rbp), %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x8644
testb %al, %al
je 0x8454
movq %r15, %rdi
callq 0x3300
movq %rax, %rdi
callq 0x33a0
movq %r13, %rdi
movl %eax, %esi
callq 0x77cb
movq %r14, %rdi
movq %r13, %rsi
callq 0x884e
movq %r13, %rdi
callq 0x3100
movq %r15, %rdi
callq 0x3060
jmp 0x840e
leaq 0xfa7(%rip), %rsi       # 0x9402
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %r14
leaq -0x3a8(%rbp), %rdi
movq %rax, %rsi
callq 0x3270
leaq -0x70(%rbp), %rdi
movq %r14, %rsi
callq 0x3370
leaq 0x60(%rbx), %r14
leaq -0x3a8(%rbp), %r15
leaq -0x70(%rbp), %r12
leaq -0x298(%rbp), %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x8644
testb %al, %al
je 0x84de
movq %r15, %rdi
callq 0x3300
movq %rax, %rdi
callq 0x33a0
movq %r13, %rdi
movl %eax, %esi
callq 0x7547
movq %r14, %rdi
movq %r13, %rsi
callq 0x8a0c
movq %r13, %rdi
callq 0x3100
movq %r15, %rdi
callq 0x3060
jmp 0x8498
leaq -0x50(%rbp), %rdi
callq 0x3120
movq %rbx, %rax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x70(%rbp), %rdi
callq 0x3100
jmp 0x85ac
jmp 0x85a9
movq %rax, %r14
jmp 0x85b8
jmp 0x85f0
jmp 0x8532
movq %rax, %r14
leaq -0x90(%rbp), %rdi
callq 0x3100
jmp 0x8535
movq %rax, %r14
leaq -0x298(%rbp), %rdi
callq 0x3380
jmp 0x8546
movq %rax, %r14
leaq -0x3a8(%rbp), %rdi
callq 0x639e
jmp 0x85cb
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
jmp 0x858a
jmp 0x85c8
movq %rax, %r14
leaq -0x298(%rbp), %rdi
callq 0x3120
jmp 0x85cb
jmp 0x85c8
jmp 0x85f0
jmp 0x85f0
jmp 0x85f0
jmp 0x85f0
jmp 0x85f0
jmp 0x85f0
movq %rax, %r14
leaq -0x3a8(%rbp), %rdi
callq 0x860c
leaq -0x298(%rbp), %rdi
callq 0x3070
jmp 0x85f3
jmp 0x85f0
movq %rax, %r14
leaq -0x70(%rbp), %rdi
jmp 0x85e1
jmp 0x85f0
jmp 0x85d7
jmp 0x85f0
movq %rax, %r14
leaq -0x298(%rbp), %rdi
callq 0x3100
jmp 0x85f3
jmp 0x85f0
jmp 0x85f0
jmp 0x85f0
jmp 0x85f0
movq %rax, %r14
movq %rbx, %rdi
callq 0x6090
leaq -0x50(%rbp), %rdi
callq 0x3120
movq %r14, %rdi
callq 0x3490