// File: /workspace/github_cpp_makefile_star2_O2/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 $0x248, %rsp            # imm = 0x248
movq %r9, %r15
movl %r8d, %ebp
movl %ecx, %r12d
movl %edx, %r13d
movl %esi, %ebx
movq %rdi, %r14
andq $0x0, 0x10(%rdi)
addq $0x18, %rdi
movq %rdi, 0x20(%rsp)
movq %r9, %rsi
callq 0x525e0
movb 0x280(%rsp), %al
movb %al, 0x38(%r14)
movl %ebx, 0x3c(%r14)
movl %r13d, 0x40(%r14)
movl %r12d, 0x44(%r14)
movl %ebp, 0x48(%r14)
leaq 0x1dcd1(%rip), %rdx     # 0x9026f
movq %rsp, %rdi
movq %r15, %rsi
callq 0x72e8d
leaq 0x48(%rsp), %rdi
movq %rsp, %rsi
pushq $0x10
popq %rdx
callq 0x52840
movq %rsp, %rdi
callq 0x52888
leaq 0xb8(%rsp), %rdi
callq 0x520e0
testb %al, %al
je 0x7269c
leaq 0x48(%rsp), %rdi
callq 0x52630
leaq 0x1dcb4(%rip), %rsi     # 0x9029b
leaq 0x28(%rsp), %rdi
movq %r15, %rdx
callq 0x59955
leaq 0x1dca7(%rip), %rdx     # 0x902a2
movq %rsp, %rdi
leaq 0x28(%rsp), %rsi
callq 0x5a4df
leaq 0x28(%rsp), %rdi
callq 0x52888
movq (%rsp), %rdi
callq 0x523d0
testl %eax, %eax
je 0x7263a
movq 0x3f9ba(%rip), %rdi     # 0xb1fe0
leaq 0x1dc7f(%rip), %rsi     # 0x902ac
callq 0x52450
movq %rax, %rdi
callq 0x52210
pushq $0x10
popq %rdi
callq 0x52470
movq %rax, %r15
movl 0x3c(%r14), %esi
movl 0x40(%r14), %edx
movq %rax, %rdi
callq 0x7312e
movq %r15, (%r14)
cmpb $0x0, 0x38(%r14)
jne 0x72678
movl 0x44(%r14), %edi
shlq $0x3, %rdi
callq 0x52040
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rcx
movq %r15, (%rax,%rcx,8)
movq %rsp, %rdi
callq 0x52888
leaq 0x48(%rsp), %rdi
callq 0x52650
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3f93d(%rip), %rdi     # 0xb1fe0
leaq 0x1dbcf(%rip), %rsi     # 0x90279
callq 0x52450
movq %rax, %r14
callq 0x52060
movl (%rax), %esi
movq %rsp, %rdi
callq 0x88570
movq %rsp, %rsi
movq %r14, %rdi
callq 0x52400
movq %rax, %rdi
callq 0x52210
movq %rsp, %rdi
callq 0x52888
pushq $-0x1
popq %rdi
callq 0x52550
jmp 0x7271b
jmp 0x72716
movq %rax, %r14
pushq $0x10
popq %rsi
movq %r15, %rdi
callq 0x52480
jmp 0x7271e
movq %rax, %r14
leaq 0x28(%rsp), %rdi
jmp 0x72721
jmp 0x72716
movq %rax, %r14
movq %rsp, %rdi
callq 0x52888
jmp 0x72730
movq %rax, %r14
jmp 0x72730
movq %rax, %r14
jmp 0x72726
movq %rax, %r14
movq %rsp, %rdi
callq 0x52888
leaq 0x48(%rsp), %rdi
callq 0x52650
movq 0x20(%rsp), %rdi
callq 0x52888
movq %r14, %rdi
callq 0x527a0