// File: /workspace/github_cpp_makefile_star2_O3/Lut99[P]RayTracer/src/lib/Frames.cpp
// Function: RayTracer::Frames::Frames(unsigned int, unsigned int, unsigned int, unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
Frames::Frames(unsigned int width, unsigned int height, unsigned int num_of_frames, unsigned int framerate, std::string temp_dir, bool dynamic_write)
    : frame_index(0),
    temp_dir(temp_dir),
    dynamic_writing(dynamic_write),
    width(width),
    height(height),
    n_frames(num_of_frames),
    fps(framerate)
{
    // Touch a file in the temp dir to make sure that the director exists
    ofstream temp_check(temp_dir + "/out1.png");
    if (!temp_check.is_open()) {
        cerr << "temp_dir existance check failed: " << string_error(errno) << endl;
        exit(-1);
    }
    temp_check.close();

    // Delete all .png files starting with out and ending in .png in the folder
    string command = "rm -r "+ temp_dir + "/out*.png";
    int res = system(command.c_str());
    if (res != 0) {
        cerr << "WARNING: Could not remove .png files in the temporary output folder." << endl;
    }

    // Initialize the first frame
    this->current_frame = new Image(this->width, this->height);

    // If everything should be kept in memory, allocate and sync the frames list as well
    if (!this->dynamic_writing) {
        this->frames = new Image*[this->n_frames];
        this->frames[this->frame_index] = this->current_frame;
    } 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %r9, %r15
movl %r8d, %ebp
movl %ecx, %r12d
movl %edx, %r13d
movl %esi, %ebx
movq %rdi, %r14
movq $0x0, 0x10(%rdi)
addq $0x18, %rdi
leaq 0x28(%r14), %rax
movq %rax, 0x28(%rsp)
movq %rax, 0x18(%r14)
movq (%r9), %rsi
movq 0x8(%r9), %rdx
addq %rsi, %rdx
movq %rdi, 0x30(%rsp)
callq 0x48588
movb 0x290(%rsp), %al
movb %al, 0x38(%r14)
movl %ebx, 0x3c(%r14)
movl %r13d, 0x40(%r14)
movl %r12d, 0x44(%r14)
movl %ebp, 0x48(%r14)
leaq 0x18(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rdi
callq 0x48588
leaq 0x25eed(%rip), %rsi     # 0x880ef
leaq 0x8(%rsp), %rdi
callq 0x3a810
leaq 0x58(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x10, %edx
callq 0x3a830
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x62237
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a480
leaq 0xc8(%rsp), %rdi
callq 0x3a0e0
testb %al, %al
je 0x623cc
leaq 0x58(%rsp), %rdi
callq 0x3a620
leaq 0x25ebe(%rip), %rsi     # 0x8811b
leaq 0x38(%rsp), %rdi
movq %r15, %rdx
callq 0x44204
leaq 0x25eb1(%rip), %rsi     # 0x88122
leaq 0x38(%rsp), %rdi
callq 0x3a810
movq %rbx, 0x8(%rsp)
movq (%rax), %rdi
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdi
je 0x6229e
movq %rdi, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x622a7
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq %rbx, %rdi
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x48(%rsp), %rcx
movq -0x10(%rcx), %rax
cmpq %rcx, %rax
je 0x622e2
movq 0x48(%rsp), %rsi
incq %rsi
movq %rax, %rdi
callq 0x3a480
movq 0x8(%rsp), %rdi
callq 0x3a3d0
testl %eax, %eax
je 0x62331
movq 0x41ce6(%rip), %r15     # 0xa3fd8
leaq 0x25e33(%rip), %rsi     # 0x8812c
movl $0x44, %edx
movq %r15, %rdi
callq 0x3a500
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3a440
movsbl %al, %esi
movq 0x41cb4(%rip), %rdi     # 0xa3fd8
callq 0x3a050
movq %rax, %rdi
callq 0x3a310
movl $0x10, %edi
callq 0x3a470
movq %rax, %r15
movl 0x3c(%r14), %esi
movl 0x40(%r14), %edx
movq %rax, %rdi
callq 0x63920
movq %r15, (%r14)
cmpb $0x0, 0x38(%r14)
jne 0x62371
movl 0x44(%r14), %edi
shlq $0x3, %rdi
callq 0x3a040
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rcx
movq %r15, (%rax,%rcx,8)
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x62388
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a480
movq 0x41bc1(%rip), %rax     # 0xa3f50
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x60(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x58(%rsp,%rcx)
callq 0x3a3c0
leaq 0x150(%rsp), %rdi
callq 0x3a150
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x41c05(%rip), %rdi     # 0xa3fd8
leaq 0x25d1f(%rip), %rsi     # 0x880f9
movl $0x21, %edx
callq 0x3a500
callq 0x3a070
movl (%rax), %esi
leaq 0x8(%rsp), %rdi
callq 0x809b4
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x41bd2(%rip), %rdi     # 0xa3fd8
callq 0x3a500
movq %rax, %rdi
callq 0x3a200
leaq 0x8(%rsp), %rdi
callq 0x3a868
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3a560
jmp 0x6247f
jmp 0x6247a
movq %rax, %r14
movl $0x10, %esi
movq %r15, %rdi
callq 0x3a480
jmp 0x62482
movq %rax, %r14
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x62499
movq 0x48(%rsp), %rsi
jmp 0x62491
jmp 0x6247a
jmp 0x62459
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x624a3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a480
jmp 0x624a3
movq %rax, %r14
jmp 0x624a3
movq %rax, %r14
jmp 0x62499
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x62499
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a480
leaq 0x58(%rsp), %rdi
callq 0x3a650
movq 0x30(%rsp), %rax
movq (%rax), %rdi
cmpq 0x28(%rsp), %rdi
je 0x624c2
movq 0x28(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x3a480
movq %r14, %rdi
callq 0x3a790