// File: /workspace/github_cpp_makefile_star2_O1/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 0x48976
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 0x48976
leaq 0x269a1(%rip), %rsi     # 0x890ef
leaq 0x8(%rsp), %rdi
callq 0x3a800
leaq 0x58(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl $0x10, %edx
callq 0x3a820
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x62783
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a470
leaq 0xc8(%rsp), %rdi
callq 0x3a0e0
testb %al, %al
je 0x62912
leaq 0x58(%rsp), %rdi
callq 0x3a610
leaq 0x26972(%rip), %rsi     # 0x8911b
leaq 0x38(%rsp), %rdi
movq %r15, %rdx
callq 0x4459c
leaq 0x26965(%rip), %rsi     # 0x89122
leaq 0x38(%rsp), %rdi
callq 0x3a800
movq %rbx, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x627ea
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x627f0
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x62823
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x8(%rsp), %rdi
callq 0x3a3c0
testl %eax, %eax
je 0x62877
movq 0x427a8(%rip), %r15     # 0xa4fe0
leaq 0x268ed(%rip), %rsi     # 0x8912c
movl $0x44, %edx
movq %r15, %rdi
callq 0x3a4f0
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x3a430
movsbl %al, %esi
movq 0x42776(%rip), %rdi     # 0xa4fe0
callq 0x3a050
movq %rax, %rdi
callq 0x3a300
movl $0x10, %edi
callq 0x3a460
movq %rax, %r15
movl 0x3c(%r14), %esi
movl 0x40(%r14), %edx
movq %rax, %rdi
callq 0x63e38
movq %r15, (%r14)
cmpb $0x0, 0x38(%r14)
jne 0x628b7
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 0x628ce
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a470
movq 0x42683(%rip), %rax     # 0xa4f58
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 0x3a3b0
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 0x426c7(%rip), %rdi     # 0xa4fe0
leaq 0x267d9(%rip), %rsi     # 0x890f9
movl $0x21, %edx
callq 0x3a4f0
callq 0x3a070
movl (%rax), %esi
leaq 0x8(%rsp), %rdi
callq 0x81138
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x42694(%rip), %rdi     # 0xa4fe0
callq 0x3a4f0
movq %rax, %rdi
callq 0x3a200
leaq 0x8(%rsp), %rdi
callq 0x3a858
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3a550
jmp 0x629c5
jmp 0x629c0
movq %rax, %r14
movl $0x10, %esi
movq %r15, %rdi
callq 0x3a470
jmp 0x629c8
movq %rax, %r14
leaq 0x48(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x629df
movq 0x48(%rsp), %rsi
jmp 0x629d7
jmp 0x629c0
jmp 0x6299f
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x629e9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a470
jmp 0x629e9
movq %rax, %r14
jmp 0x629e9
movq %rax, %r14
jmp 0x629df
movq %rax, %r14
movq 0x8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x629df
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3a470
leaq 0x58(%rsp), %rdi
callq 0x3a640
movq 0x30(%rsp), %rax
movq (%rax), %rdi
cmpq 0x28(%rsp), %rdi
je 0x62a08
movq 0x28(%rsp), %rax
movq (%rax), %rsi
incq %rsi
callq 0x3a470
movq %r14, %rdi
callq 0x3a780