// File: /workspace/github_cpp_makefile_star2_O2/Agusyc[P]CTRPG/src/jsonparser.cpp
// Function: parseEnemy(int)
Enemy parseEnemy(int index) {
    Json::Value root; // The root element
    Json::Reader reader; // The reader... that reads

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

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

    Json::Value jEnemy = root[index];

    Enemy enemy;

    enemy.name = jEnemy["name"].asString();
    enemy.attack = jEnemy["attack"].asInt();
    enemy.defense = jEnemy["defense"].asInt();
    enemy.shieldDefense = jEnemy["shieldDefense"].asInt();
    enemy.mana = jEnemy["mana"].asInt();
    enemy.stamina = jEnemy["stamina"].asInt();
    enemy.hp = jEnemy["hp"].asInt();
    enemy.xp = jEnemy["xp"].asInt();
    enemy.id = index;
    enemy.minLevel = jEnemy["minLevel"].asInt();
    enemy.maxLevel = jEnemy["maxLevel"].asInt();

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

    return enemy;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3c8, %rsp            # imm = 0x3C8
movl %esi, %r14d
movq %rdi, %rbx
leaq -0xd8(%rbp), %rdi
xorl %esi, %esi
callq 0x30e0
leaq -0x1e8(%rbp), %rdi
callq 0x3240
leaq 0x1a34(%rip), %rsi      # 0x94be
leaq -0x3f0(%rbp), %rdi
pushq $0x8
popq %rdx
callq 0x34a0
leaq -0x1e8(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
pushq $0x1
popq %rcx
callq 0x34c0
testb %al, %al
je 0x7cf7
leaq -0xd8(%rbp), %rdi
movl %r14d, %esi
callq 0x3260
leaq -0x50(%rbp), %rdi
movq %rax, %rsi
callq 0x3410
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x48(%rbx)
andq $0x0, 0x58(%rbx)
leaq 0x1a22(%rip), %rsi      # 0x951e
leaq -0x50(%rbp), %rdi
callq 0x30b0
leaq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x34b0
leaq -0x90(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x32c0
movq %r15, %rdi
callq 0x3100
leaq 0x1843(%rip), %rsi      # 0x9378
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x20(%rbx)
leaq 0x187c(%rip), %rsi      # 0x93cc
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x24(%rbx)
leaq 0x1a20(%rip), %rsi      # 0x958b
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x28(%rbx)
leaq 0x184e(%rip), %rsi      # 0x93d4
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x2c(%rbx)
leaq 0x1838(%rip), %rsi      # 0x93d9
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x30(%rbx)
leaq 0x180d(%rip), %rsi      # 0x93c9
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x34(%rbx)
leaq 0x180f(%rip), %rsi      # 0x93e6
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x38(%rbx)
movl %r14d, 0x3c(%rbx)
leaq 0x196b(%rip), %rsi      # 0x9561
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x40(%rbx)
leaq 0x1959(%rip), %rsi      # 0x956a
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %rdi
callq 0x33a0
movl %eax, 0x44(%rbx)
leaq 0x1795(%rip), %rsi      # 0x93c1
leaq -0x50(%rbp), %rdi
callq 0x30b0
movq %rax, %r14
leaq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x3270
leaq -0xa0(%rbp), %rdi
movq %r14, %rsi
callq 0x3370
leaq 0x48(%rbx), %r14
leaq -0xb0(%rbp), %r15
leaq -0xa0(%rbp), %r12
leaq -0x90(%rbp), %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x8644
testb %al, %al
je 0x7cb5
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 0x7c6f
leaq -0x50(%rbp), %rdi
callq 0x3120
leaq -0x3f0(%rbp), %rdi
callq 0x3070
leaq -0x1e8(%rbp), %rdi
callq 0x860c
leaq -0xd8(%rbp), %rdi
callq 0x3120
movq %rbx, %rax
addq $0x3c8, %rsp            # imm = 0x3C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x52d2(%rip), %rdi      # 0xcfd0
leaq 0x17cd(%rip), %rsi      # 0x94d2
callq 0x3220
movq %rax, %rdi
callq 0x3110
leaq 0x179e(%rip), %rsi      # 0x94b7
movq %rax, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x3110
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x33d0
leaq -0x90(%rbp), %rsi
movq %rbx, %rdi
callq 0x31d0
leaq -0x90(%rbp), %rdi
callq 0x3100
pushq $0x1
popq %rdi
callq 0x32b0
movq %rax, %r14
leaq -0x90(%rbp), %rdi
callq 0x3100
jmp 0x7db9
jmp 0x7d89
jmp 0x7da5
jmp 0x7da5
jmp 0x7da5
movq %rax, %r14
jmp 0x7dc5
movq %rax, %r14
jmp 0x7dd1
jmp 0x7d89
jmp 0x7da5
movq %rax, %r14
jmp 0x7db9
jmp 0x7da5
movq %rax, %r14
leaq -0x90(%rbp), %rdi
callq 0x3100
jmp 0x7da8
jmp 0x7da5
jmp 0x7da5
movq %rax, %r14
movq %rbx, %rdi
callq 0x6070
leaq -0x50(%rbp), %rdi
callq 0x3120
leaq -0x3f0(%rbp), %rdi
callq 0x3070
leaq -0x1e8(%rbp), %rdi
callq 0x860c
leaq -0xd8(%rbp), %rdi
callq 0x3120
movq %r14, %rdi
callq 0x3490