// File: /workspace/github_cpp_makefile_star2_O1/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 $0x158, %rsp            # imm = 0x158
movq %rsi, %rbx
movl %edi, %eax
movq %rax, 0xd8(%rsp)
movl $0x1, 0x18(%rsp)
leaq 0xe0(%rsp), %r12
movabsq $-0x71c71c71c71c71c7, %r13 # imm = 0x8E38E38E38E38E39
leaq 0x130(%rsp), %r14
leaq 0x77eb(%rip), %rbp      # 0xa1b0
movl 0x788d(%rip), %eax      # 0xa258
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
leaq 0x77b2(%rip), %rax      # 0xa18c
movl (%rax), %eax
decl %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
divss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
mulss 0x362c(%rip), %xmm1     # 0x6024
movss %xmm1, 0x14(%rsp)
xorl %eax, %eax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq %rax, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq (%rbx), %rsi
movq (%rsi), %rax
movq %r12, %rdi
callq *(%rax)
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0xe0(%rsp), %rax
movq %rax, 0x20(%rsp)
movups 0xe8(%rsp), %xmm0
movups %xmm0, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xe0(%rsp)
movq $0x0, 0xf0(%rsp)
testq %rdi, %rdi
je 0x2a6a
subq %rdi, %rsi
callq 0x21c0
movq 0xe0(%rsp), %rdi
testq %rdi, %rdi
je 0x2a87
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x120(%rsp)
movaps %xmm0, 0x110(%rsp)
movaps %xmm0, 0x100(%rsp)
movaps %xmm0, 0xf0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movq %r12, %rdi
xorl %esi, %esi
callq 0x40c8
movl $0x0, 0x1c(%rsp)
movb $0x0, 0x7(%rsp)
movl 0x7789(%rip), %eax      # 0xa258
leaq 0x76b6(%rip), %rcx      # 0xa18c
cmpl (%rcx), %eax
jae 0x2dae
movss 0x353a(%rip), %xmm0     # 0x6020
subss 0x8(%rsp), %xmm0
addss 0x14(%rsp), %xmm0
movss %xmm0, 0x38(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x14(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x7687(%rip), %rsi      # 0xa1a0
movq (%rsi), %rax
leaq 0x90(%rsp), %r15
movq %r15, %rdi
leaq 0x20(%rsp), %rdx
callq *0x8(%rax)
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x4b52
movss 0xa8(%rsp), %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x2b68
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq (%rbx), %rax
movq %rax, 0x80(%rsp)
movq 0x8(%rbx), %rax
movq %rax, 0x88(%rsp)
testq %rax, %rax
je 0x2b99
movq 0x7445(%rip), %rcx      # 0x9fd0
cmpb $0x0, (%rcx)
je 0x2b95
incl 0x8(%rax)
jmp 0x2b99
lock
incl 0x8(%rax)
leaq 0x80(%rsp), %rdi
movss 0x38(%rsp), %xmm0
leaq 0x60(%rsp), %rsi
callq 0x25fc
movq %rax, %r15
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2bc6
callq 0x3c8a
movq %r15, 0x58(%rsp)
movq (%rbx), %rsi
movq (%rsi), %rax
leaq 0x90(%rsp), %rdi
leaq 0x58(%rsp), %rdx
callq *0x8(%rax)
leaq 0x40(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x4b52
movss 0x94(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movb 0x90(%rsp), %al
movb %al, 0x7(%rsp)
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2c2a
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movss 0x14(%rsp), %xmm0
addss 0x1c(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
leaq 0x90(%rsp), %r15
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0x7(%rsp), %r9
callq 0x426c
movq %r12, %rdi
movq %r15, %rsi
callq 0x36d2
movq 0x128(%rsp), %rax
movq %rax, %rcx
subq 0x108(%rsp), %rcx
sarq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
leaq (,%rcx,8), %rdx
subq %rcx, %rdx
movq 0x110(%rsp), %rax
movq %rax, %rsi
subq 0x118(%rsp), %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
movq 0xf0(%rsp), %rcx
movq 0x100(%rsp), %rdi
subq %rcx, %rdi
sarq $0x3, %rdi
imulq %r13, %rdi
addq %rsi, %rdi
addq %rdx, %rdi
cmpq $0x7, %rdi
ja 0x2ce8
cmpq %rcx, %rax
je 0x2d2a
cmpb $0x0, 0x7(%rsp)
je 0x2d2a
movq %r14, %rdi
movq %r12, %rsi
movss 0x8(%rsp), %xmm0
callq 0x26ad
movq %rbp, %rdi
movq %r14, %rsi
callq 0x36fc
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x2c70
movq 0x150(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
jmp 0x2c70
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x3760
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x2d56
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2d73
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x2d8a
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movb 0x7(%rsp), %r15b
testb %r15b, %r15b
jne 0x2db6
movl 0x74be(%rip), %eax      # 0xa258
leaq 0x73eb(%rip), %rcx      # 0xa18c
cmpl (%rcx), %eax
jb 0x2b01
jmp 0x2f4e
xorl %r15d, %r15d
jmp 0x2f4e
imull $0xcccccccd, 0x18(%rsp), %eax # imm = 0xCCCCCCCD
rorl %eax
cmpl $0x19999999, %eax       # imm = 0x19999999
ja 0x2f4e
movl $0x1, %edx
movq 0x7201(%rip), %rdi      # 0x9fd8
leaq 0x32e9(%rip), %rsi      # 0x60c7
callq 0x21d0
movq 0x71ee(%rip), %rcx      # 0x9fd8
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
cmpb $0x0, 0xe1(%rcx,%rax)
jne 0x2e20
movq %rdi, 0x8(%rsp)
movl $0x20, %esi
callq 0x21a0
movq 0x8(%rsp), %rdi
movb %al, 0xe0(%rdi)
movb $0x1, 0xe1(%rdi)
movb $0x30, 0xe0(%rdi)
movq 0x71aa(%rip), %rdi      # 0x9fd8
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rdi,%rax)
movq 0xd8(%rsp), %rsi
callq 0x20f0
movl $0x2, %edx
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x3268(%rip), %rsi      # 0x60c9
callq 0x21d0
movl $0x4, %edx
movq 0x8(%rsp), %rdi
leaq 0x3255(%rip), %rsi      # 0x60cc
callq 0x21d0
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq -0x18(%rax), %rax
movq %rcx, %rdx
addq %rax, %rdx
cmpb $0x0, 0xe1(%rcx,%rax)
jne 0x2ebc
movq %rdx, 0x38(%rsp)
movq %rdx, %rdi
movl $0x20, %esi
callq 0x21a0
movq 0x38(%rsp), %rdx
movb %al, 0xe0(%rdx)
movb $0x1, 0xe1(%rdx)
movb $0x30, 0xe0(%rdx)
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0x5, 0x10(%rdi,%rax)
movl 0x18(%rsp), %esi
callq 0x20f0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x31df(%rip), %rsi      # 0x60cf
movq %rax, 0x8(%rsp)
callq 0x21d0
movq 0x8(%rsp), %rdi
movl $0x8, %edx
leaq 0x31c6(%rip), %rsi      # 0x60d1
callq 0x21d0
movq 0x8(%rsp), %rdi
cvtss2sd 0x14(%rsp), %xmm0
callq 0x2250
movq (%rax), %rcx
movq -0x18(%rcx), %rdi
addq %rax, %rdi
movl $0xa, %esi
movq %rax, 0x8(%rsp)
callq 0x21a0
movq 0x8(%rsp), %rdi
movsbl %al, %esi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq %r12, %rdi
callq 0x3836
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x2f6d
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2f84
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
incl 0x18(%rsp)
testb %r15b, %r15b
jne 0x29c5
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2fa5
movq %rax, %rbx
jmp 0x305a
movq %rax, %rbx
jmp 0x304d
jmp 0x2fb9
jmp 0x2fb9
movq %rax, %rbx
jmp 0x3036
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x3036
callq 0x3c8a
jmp 0x3036
jmp 0x2ff9
movq %rax, %rbx
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x2ffc
movq 0x150(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
jmp 0x2ffc
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x3019
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x3036
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x304d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
leaq 0xe0(%rsp), %rdi
callq 0x3836
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3071
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x3088
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x22b0