// File: /workspace/github_cpp_makefile_star2_O3/integeruser[P]GA3C-cpp/src/ga3c.cc
// Function: agent(unsigned int, std::shared_ptr<Environment>)
void agent(uint32_t id, std::shared_ptr<Environment> env)
{
    for (uint32_t episode = 1; true; ++episode) {
        const float t = (float)num_training_experiences / (MAX_NUM_TRAINING_EXPERIENCES-1);
        const float epsilon = (1-t)*EPSILON_START + t*EPSILON_END;

        // reset the environment starting a new episode
        observation_t curr_state, next_state;
        curr_state = env->reset();

        memory_t memory;
        float reward = 0.0f;
        float episode_reward = 0.0f;

        bool done = false;
        while (not done) {
            // stop training after reaching a fixed number of training experiences
            if (num_training_experiences >= MAX_NUM_TRAINING_EXPERIENCES) { return; }

            // predict policy and value
            std::vector<float> policy;
            float value;
            std::tie(policy, value) = shared_model->predict_policy_and_value(curr_state);

            // select and perform an action
            const auto action = select_action(env, epsilon, policy);
            std::tie(next_state, reward, done) = env->step(action);
            episode_reward += reward;

            experience_t experience = experience_t{curr_state, action, reward, next_state, done};
            memory.push_back(experience);

            // add experiences to the training queue when:
            // - enough of them are accumulated in memory and the n-step return can be computed
            // - the episode is over and the memory is not empty
            while ((memory.size() >= N_STEP_RETURN) or (done and not memory.empty())) {
                const auto training_experience = extract_accumulated_experience(memory, value);
                training_experiences_queue.push(training_experience);
            }

            curr_state = next_state;
        }

        if (episode % 10 == 0) {
            std::cout << "[" << std::setfill('0') << std::setw(2) << id << "] "
                      << "Ep. " << std::setfill('0') << std::setw(5) << episode << " "
                      << "reward: " << episode_reward << std::endl;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, 0x58(%rsp)
movl %edi, %eax
movq %rax, 0xe8(%rsp)
movl $0x1, 0x10(%rsp)
xorps %xmm1, %xmm1
leaq 0xf0(%rsp), %r15
movabsq $-0x71c71c71c71c71c7, %r12 # imm = 0x8E38E38E38E38E39
leaq 0x140(%rsp), %rbp
leaq 0x77c2(%rip), %r14      # 0xa1b0
movl 0x7864(%rip), %eax      # 0xa258
xorps %xmm2, %xmm2
cvtsi2ss %rax, %xmm2
leaq 0x7789(%rip), %rax      # 0xa18c
movl (%rax), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
divss %xmm0, %xmm2
movss %xmm2, 0x18(%rsp)
mulss 0x3603(%rip), %xmm2     # 0x6024
movss %xmm2, 0x8(%rsp)
xorl %eax, %eax
movq %rax, 0x30(%rsp)
movaps %xmm1, 0x20(%rsp)
movq %rax, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movq 0x58(%rsp), %rax
movq (%rax), %rsi
movq (%rsi), %rax
movq %r15, %rdi
callq *(%rax)
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rsi
movaps 0xf0(%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
movq 0x100(%rsp), %rax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xf0(%rsp)
movq $0x0, 0x100(%rsp)
testq %rdi, %rdi
je 0x2ab2
subq %rdi, %rsi
callq 0x21c0
movq 0xf0(%rsp), %rdi
testq %rdi, %rdi
je 0x2ab2
movq 0x100(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x130(%rsp)
movaps %xmm0, 0x120(%rsp)
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movq %r15, %rdi
xorl %esi, %esi
callq 0x412e
movss 0x3531(%rip), %xmm0     # 0x6020
subss 0x18(%rsp), %xmm0
addss 0x8(%rsp), %xmm0
movss %xmm0, 0x60(%rsp)
movl $0x0, 0xc(%rsp)
movb $0x0, 0x7(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x14(%rsp)
movl 0x773b(%rip), %ecx      # 0xa258
leaq 0x7668(%rip), %rax      # 0xa18c
movl (%rax), %ebx
movl %ecx, 0x64(%rsp)
cmpl %ebx, %ecx
jae 0x2f73
movq 0x7667(%rip), %rsi      # 0xa1a0
movq (%rsi), %rax
leaq 0x70(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq *0x8(%rax)
movaps 0x70(%rsp), %xmm0
movaps %xmm0, 0xd0(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0xe0(%rsp)
movss 0x88(%rsp), %xmm0
movss %xmm0, 0x18(%rsp)
movq 0x58(%rsp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
movq %rcx, 0xc0(%rsp)
movq %rax, 0xc8(%rsp)
testq %rax, %rax
je 0x2bab
movq 0x7433(%rip), %rcx      # 0x9fd0
cmpb $0x0, (%rcx)
je 0x2ba7
incl 0x8(%rax)
jmp 0x2bab
lock
incl 0x8(%rax)
leaq 0xc0(%rsp), %rdi
movss 0x60(%rsp), %xmm0
leaq 0xd0(%rsp), %rsi
callq 0x261c
movq %rax, %r13
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x2bdb
callq 0x3cdc
movq %r13, 0x68(%rsp)
movq 0x58(%rsp), %rax
movq (%rax), %rsi
movq (%rsi), %rax
leaq 0x70(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq *0x8(%rax)
movq 0x40(%rsp), %rdi
movq 0x50(%rsp), %rsi
movups 0x78(%rsp), %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x78(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
testq %rdi, %rdi
je 0x2c7b
subq %rdi, %rsi
callq 0x21c0
movq 0x78(%rsp), %rdi
movss 0x74(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movss %xmm0, 0xc(%rsp)
movb 0x70(%rsp), %al
movb %al, 0x7(%rsp)
testq %rdi, %rdi
je 0x2c95
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
jmp 0x2c95
movss 0x74(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movss %xmm0, 0xc(%rsp)
movb 0x70(%rsp), %al
movb %al, 0x7(%rsp)
leaq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x68(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x7(%rsp), %r9
callq 0x42d2
movq %r15, %rdi
movq %r13, %rsi
callq 0x3740
movss 0x14(%rsp), %xmm0
addss 0x8(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movq 0x138(%rsp), %rax
movq %rax, %rcx
subq 0x118(%rsp), %rcx
sarq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
leaq (,%rcx,8), %rdx
subq %rcx, %rdx
movq 0x120(%rsp), %rax
movq %rax, %rsi
subq 0x128(%rsp), %rsi
sarq $0x3, %rsi
imulq %r12, %rsi
movq 0x100(%rsp), %rcx
movq 0x110(%rsp), %rdi
subq %rcx, %rdi
sarq $0x3, %rdi
imulq %r12, %rdi
addq %rsi, %rdi
addq %rdx, %rdi
cmpq $0x7, %rdi
ja 0x2d50
cmpq %rcx, %rax
je 0x2d92
cmpb $0x0, 0x7(%rsp)
je 0x2d92
movq %rbp, %rdi
movq %r15, %rsi
movss 0x18(%rsp), %xmm0
callq 0x26cd
movq %r14, %rdi
movq %rbp, %rsi
callq 0x376a
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x2cd8
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
jmp 0x2cd8
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x37ce
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x2dbe
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x2dd8
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x2df5
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
cmpb $0x0, 0x7(%rsp)
je 0x2b17
imull $0xcccccccd, 0x10(%rsp), %eax # imm = 0xCCCCCCCD
rorl %eax
cmpl $0x19999999, %eax       # imm = 0x19999999
ja 0x2f73
movl $0x1, %edx
movq 0x71b7(%rip), %rdi      # 0x9fd8
leaq 0x329f(%rip), %rsi      # 0x60c7
callq 0x21d0
movq 0x71a4(%rip), %rdi      # 0x9fd8
movq (%rdi), %rax
movq -0x18(%rax), %rcx
leaq (%rdi,%rcx), %r13
cmpb $0x0, 0xe1(%rdi,%rcx)
jne 0x2e68
movq %r13, %rdi
movl $0x20, %esi
callq 0x21a0
movb $0x1, 0xe1(%r13)
movq 0x7173(%rip), %rdi      # 0x9fd8
movq (%rdi), %rax
movb $0x30, 0xe0(%r13)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rdi,%rax)
movq 0xe8(%rsp), %rsi
callq 0x20f0
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
leaq 0x322d(%rip), %rsi      # 0x60c9
callq 0x21d0
movl $0x4, %edx
movq %r13, %rdi
leaq 0x321c(%rip), %rsi      # 0x60cc
callq 0x21d0
movq (%r13), %rax
movq -0x18(%rax), %rcx
movq %r13, %rdx
addq %rcx, %rdx
cmpb $0x0, 0xe1(%r13,%rcx)
jne 0x2ef0
movq %rdx, 0x18(%rsp)
movq %rdx, %rdi
movl $0x20, %esi
callq 0x21a0
movq 0x18(%rsp), %rdx
movb $0x1, 0xe1(%rdx)
movq (%r13), %rax
movb $0x30, 0xe0(%rdx)
movq -0x18(%rax), %rax
movq $0x5, 0x10(%r13,%rax)
movl 0x10(%rsp), %esi
movq %r13, %rdi
callq 0x20f0
movq %rax, %r13
movl $0x1, %edx
movq %rax, %rdi
leaq 0x31ad(%rip), %rsi      # 0x60cf
callq 0x21d0
movl $0x8, %edx
movq %r13, %rdi
leaq 0x319b(%rip), %rsi      # 0x60d1
callq 0x21d0
cvtss2sd 0x14(%rsp), %xmm0
movq %r13, %rdi
callq 0x2250
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq %r15, %rdi
callq 0x38b2
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2f92
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2fa9
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
incl 0x10(%rsp)
cmpl %ebx, 0x64(%rsp)
xorps %xmm1, %xmm1
jb 0x29ee
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2fce
movq %rax, %rbx
jmp 0x3086
jmp 0x2fd8
movq %rax, %rbx
jmp 0x3079
jmp 0x2ff9
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x305c
callq 0x3cdc
jmp 0x305c
movq %rax, %rbx
jmp 0x305c
jmp 0x3022
movq %rax, %rbx
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x3025
movq 0x160(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
jmp 0x3025
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x3042
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x305c
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x3079
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
leaq 0xf0(%rsp), %rdi
callq 0x38b2
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x309d
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x30b4
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x22b0