// File: IsaacLaw12[P]RayTracer/./src/Image.cpp
// Function: Image::blur_pixel(int, int, int)
void Image::blur_pixel(int index_x, int index_y, int blur_size){
    // Original color matrices are not affected. Their blurred averages are
    //     written to post_* matrices
    double red_avg = 0;
    double green_avg = 0;
    double blue_avg = 0;
    int avg_num = 0;
    if (blur_size <= 0) return;

    for (int x=-blur_size; x<=blur_size; x++){
        for (int y=-blur_size; y<=blur_size; y++){
            int x_index = index_x + x;
            if (x_index < 0 || x_index >= image_width){
               continue;
            }
            int y_index = index_y + y;
            if (y_index < 0 || y_index >= image_height){
               continue;
            }
            red_avg += red_pixels(x_index, y_index);
            green_avg += green_pixels(x_index, y_index);
            blue_avg += blue_pixels(x_index, y_index);
            avg_num++;
        }
    }
    if (avg_num > 0){
        post_red_pixels(index_x, index_y) = red_avg / avg_num;
        post_green_pixels(index_x, index_y) = green_avg / avg_num;
        post_blue_pixels(index_x, index_y) = blue_avg / avg_num;
    }
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movl %esi, 0x5c(%rsp)
movl %edx, 0x58(%rsp)
movl %ecx, 0x54(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x0, 0x34(%rsp)
cmpl $0x0, 0x54(%rsp)
jg 0x5dae
jmp 0x5f83
xorl %eax, %eax
subl 0x54(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x54(%rsp), %eax
jg 0x5ecf
xorl %eax, %eax
subl 0x54(%rsp), %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x54(%rsp), %eax
jg 0x5ebd
movl 0x5c(%rsp), %eax
addl 0x30(%rsp), %eax
movl %eax, 0x28(%rsp)
cmpl $0x0, 0x28(%rsp)
jl 0x5dff
movq 0x18(%rsp), %rcx
movl 0x28(%rsp), %eax
cmpl 0x10(%rcx), %eax
jl 0x5e04
jmp 0x5ead
movl 0x58(%rsp), %eax
addl 0x2c(%rsp), %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jl 0x5e25
movq 0x18(%rsp), %rcx
movl 0x24(%rsp), %eax
cmpl 0x14(%rcx), %eax
jl 0x5e2a
jmp 0x5ead
movq 0x18(%rsp), %rdi
addq $0x18, %rdi
movslq 0x28(%rsp), %rsi
movslq 0x24(%rsp), %rdx
callq 0x61c0
movq 0x18(%rsp), %rdi
movsd (%rax), %xmm0
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
addq $0x30, %rdi
movslq 0x28(%rsp), %rsi
movslq 0x24(%rsp), %rdx
callq 0x61c0
movq 0x18(%rsp), %rdi
movsd (%rax), %xmm0
addsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
addq $0x48, %rdi
movslq 0x28(%rsp), %rsi
movslq 0x24(%rsp), %rdx
callq 0x61c0
movsd (%rax), %xmm0
addsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x5dd0
jmp 0x5ebf
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x5db8
cmpl $0x0, 0x34(%rsp)
jle 0x5f83
movq 0x18(%rsp), %rdi
movsd 0x48(%rsp), %xmm0
cvtsi2sdl 0x34(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
addq $0x60, %rdi
movslq 0x5c(%rsp), %rsi
movslq 0x58(%rsp), %rdx
callq 0x61c0
movsd (%rsp), %xmm0
movq 0x18(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x40(%rsp), %xmm0
cvtsi2sdl 0x34(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
addq $0x78, %rdi
movslq 0x5c(%rsp), %rsi
movslq 0x58(%rsp), %rdx
callq 0x61c0
movsd 0x8(%rsp), %xmm0
movq 0x18(%rsp), %rdi
movsd %xmm0, (%rax)
movsd 0x38(%rsp), %xmm0
cvtsi2sdl 0x34(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
addq $0x90, %rdi
movslq 0x5c(%rsp), %rsi
movslq 0x58(%rsp), %rdx
callq 0x61c0
movsd 0x10(%rsp), %xmm0
movsd %xmm0, (%rax)
addq $0x68, %rsp
retq
nopl (%rax,%rax)