// File: /workspace/github_cpp_makefile_star2_O1/integeruser[P]GA3C-cpp/src/ga3c.cc
// Function: extract_accumulated_experience(std::deque<std::tuple<std::vector<float, std::allocator<float>>, long, float, std::vector<float, std::allocator<float>>, bool>, std::allocator<std::tuple<std::vector<float, std::allocator<float>>, long, float, std::vector<float, std::allocator<float>>, bool>>>&, float)
training_experience_t extract_accumulated_experience(memory_t& memory, float next_state_value)
{
    assert(not memory.empty());
    const auto n = std::min<uint32_t>(N_STEP_RETURN, memory.size());

    // pick experience at time step t
    uint32_t t = 0;
    const auto curr_state = std::get<0>(memory[t]);
    const auto action = std::get<1>(memory[t]);

    // and calculate its n-step return (until time step t+n)
    float n_step_return = 0.0f;
    for (; t < n; ++t) {
        const auto reward = std::get<2>(memory[t]);
        n_step_return += std::pow(GAMMA, t)*reward;
    }
    const auto done = std::get<4>(memory[n-1]);
    if (not done) { n_step_return += std::pow(GAMMA, n)*next_state_value; }

    memory.pop_front();
    return training_experience_t{curr_state, action, n_step_return};
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq 0x10(%rsi), %rsi
movq 0x30(%r14), %rax
cmpq %rsi, %rax
je 0x293d
movq %rdi, %r15
movq 0x48(%r14), %rcx
movq %rcx, %rdx
subq 0x28(%r14), %rdx
shrq $0x3, %rdx
cmpq $0x1, %rcx
adcl $-0x1, %edx
movq 0x20(%r14), %rcx
leal (,%rdx,8), %edi
subq 0x38(%r14), %rax
subl %edx, %edi
shrq $0x3, %rax
imull $0x38e38e39, %eax, %eax # imm = 0x38E38E39
subq %rsi, %rcx
shrq $0x3, %rcx
imull $0x38e38e39, %ecx, %ebp # imm = 0x38E38E39
addl %eax, %ebp
addl %edi, %ebp
cmpl $0x8, %ebp
movl $0x8, %r13d
cmovbl %ebp, %r13d
movq %rsi, %rdi
subq 0x18(%r14), %rdi
movq %rdi, %rcx
sarq $0x3, %rcx
movabsq $-0x71c71c71c71c71c7, %rbx # imm = 0x8E38E38E38E38E39
imulq %rbx, %rcx
cmpq $0x7, %rcx
jb 0x279c
movq 0x28(%r14), %r8
testq %rdi, %rdi
jle 0x276b
movabsq $0x2492492492492493, %rdx # imm = 0x2492492492492493
movq %rcx, %rax
mulq %rdx
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x2, %rcx
jmp 0x278e
notq %rcx
movabsq $0x2492492492492493, %rdx # imm = 0x2492492492492493
movq %rcx, %rax
mulq %rdx
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x2, %rcx
notq %rcx
imulq $-0x1f8, %rcx, %rsi     # imm = 0xFE08
addq (%r8,%rcx,8), %rsi
addq %rdi, %rsi
movss %xmm0, 0xc(%rsp)
addq $0x30, %rsi
leaq 0x20(%rsp), %rdi
callq 0x3624
movq 0x10(%r14), %rax
movq %rax, %rsi
subq 0x18(%r14), %rsi
movq %rsi, %rcx
sarq $0x3, %rcx
imulq %rbx, %rcx
cmpq $0x7, %rcx
jb 0x2825
movq 0x28(%r14), %rdi
testq %rsi, %rsi
jle 0x27f4
movabsq $0x2492492492492493, %rdx # imm = 0x2492492492492493
movq %rcx, %rax
mulq %rdx
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x2, %rcx
jmp 0x2817
notq %rcx
movabsq $0x2492492492492493, %rdx # imm = 0x2492492492492493
movq %rcx, %rax
mulq %rdx
subq %rdx, %rcx
shrq %rcx
addq %rdx, %rcx
shrq $0x2, %rcx
notq %rcx
imulq $-0x1f8, %rcx, %rax     # imm = 0xFE08
addq (%rdi,%rcx,8), %rax
addq %rsi, %rax
movq %r15, 0x10(%rsp)
leaq 0x10(%r14), %r15
movq 0x28(%rax), %rbx
testl %ebp, %ebp
je 0x2897
movl %r13d, %ebp
xorps %xmm0, %xmm0
xorl %r12d, %r12d
movss %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x4a34
movl %r12d, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %rcx, %xmm1
xorps %xmm0, %xmm0
cvtss2sd 0x20(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x3797(%rip), %xmm0     # 0x6008
callq 0x22a0
xorps %xmm1, %xmm1
cvtss2sd 0x8(%rsp), %xmm1
mulsd 0x18(%rsp), %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
incq %r12
cmpq %rbp, %r12
jb 0x283f
jmp 0x289a
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
leal -0x1(%r13), %esi
movq %r15, %rdi
callq 0x4a34
cmpb $0x0, (%rax)
jne 0x28ea
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd 0x3747(%rip), %xmm0     # 0x6008
callq 0x22a0
xorps %xmm1, %xmm1
cvtss2sd 0xc(%rsp), %xmm1
cvtss2sd 0x8(%rsp), %xmm2
mulsd %xmm0, %xmm1
addsd %xmm2, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x10(%rsp), %r15
movq %r14, %rdi
callq 0x36a4
movss 0x8(%rsp), %xmm0
movss %xmm0, (%r15)
movq %rbx, 0x8(%r15)
leaq 0x10(%r15), %rdi
leaq 0x20(%rsp), %rsi
callq 0x3624
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x292b
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x371c(%rip), %rdi      # 0x6060
leaq 0x3728(%rip), %rsi      # 0x6073
leaq 0x372d(%rip), %rcx      # 0x607f
movl $0x3d, %edx
callq 0x20d0
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2976
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x22b0