// File: CodyNault[P]Image-Filter-Dataflow/src/filters.cpp
// Function: Crop::Execute()
void Crop::Execute(void)
{
    OneInputCheck();
    if (Istart < 0 || Istop < 0 || Jstart < 0 || Jstop < 0)
    {
        char msg[1024];
        sprintf(msg, "%s: uninitialized region", FilterName());
        DataFlowException e(FilterName(), msg);
        throw e;
    }
    if (Istart >= inputImg1->GetWidth() || Istop >= inputImg1->GetWidth())
    {
        char msg[1024];
        sprintf(msg, "%s: region outside image width", FilterName());
        DataFlowException e(FilterName(), msg);
        throw e;
    }
    if (Jstart >= inputImg1->GetHeight() || Jstop >= inputImg1->GetHeight())
    {
        char msg[1024];
        sprintf(msg, "%s: region outside image height", FilterName());
        DataFlowException e(FilterName(), msg);
        throw e;
    }
    if (Istop < Istart || Jstop < Jstart)
    {
        char msg[1024];
        sprintf(msg, "%s: invalid region", FilterName());
        DataFlowException e(FilterName(), msg);
        throw e;
    }

    int height = Jstop-Jstart+1;
    int width  = Istop-Istart+1;
    int inputWidth = inputImg1->GetWidth();
    Pixel *outBuffer = new Pixel[width * height];
    Pixel *inBuffer1 = inputImg1->GetBuffer();
    for (int i = Istart ; i <= Istop ; i++)
        for (int j = Jstart ; j <= Jstop ; j++)
        {
            int idx1 = j*inputWidth+i;
            int idx  = (j-Jstart)*width+(i-Istart);
            outBuffer[idx].red   = inBuffer1[idx1].red;
            outBuffer[idx].green = inBuffer1[idx1].green;
            outBuffer[idx].blue = inBuffer1[idx1].blue;
        }
    outputImg.ResetSize(width, height);
    outputImg.SetBuffer(outBuffer);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2100, %rsp           # imm = 0x2100
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x2090(%rbp)
addq $0x28, %rdi
callq 0x3fa0
movq -0x2090(%rbp), %rax
cmpl $0x0, 0x40(%rax)
jl 0x6dfb
movq -0x2090(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jl 0x6dfb
movq -0x2090(%rbp), %rax
cmpl $0x0, 0x48(%rax)
jl 0x6dfb
movq -0x2090(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
jge 0x6eb9
movq -0x2090(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq %rax, %rdx
leaq 0x240c(%rip), %rsi      # 0x9221
xorl %eax, %eax
leaq -0x410(%rbp), %rdi
movq %rdi, -0x20a8(%rbp)
callq 0x3050
movq -0x2090(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq -0x20a8(%rbp), %rdx
movq %rax, %rsi
leaq -0x818(%rbp), %rdi
movq %rdi, -0x20a0(%rbp)
callq 0x8420
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq -0x20a0(%rbp), %rsi
movq %rax, %rdi
movq %rdi, -0x2098(%rbp)
callq 0x4240
movq -0x2098(%rbp), %rdi
leaq 0x5a03(%rip), %rsi      # 0xc888
leaq -0x2bfc(%rip), %rdx     # 0x4290
callq 0x31c0
jmp 0x73c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x820(%rbp)
movl %eax, -0x824(%rbp)
leaq -0x818(%rbp), %rdi
callq 0x4290
jmp 0x73ba
movq -0x2090(%rbp), %rax
movl 0x40(%rax), %ecx
movl %ecx, -0x20ac(%rbp)
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movl -0x20ac(%rbp), %eax
cmpl %ecx, %eax
jge 0x6f07
movq -0x2090(%rbp), %rax
movl 0x44(%rax), %ecx
movl %ecx, -0x20b0(%rbp)
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, %ecx
movl -0x20b0(%rbp), %eax
cmpl %ecx, %eax
jl 0x6fc5
movq -0x2090(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq %rax, %rdx
leaq 0x2319(%rip), %rsi      # 0x923a
xorl %eax, %eax
leaq -0xc30(%rbp), %rdi
movq %rdi, -0x20c8(%rbp)
callq 0x3050
movq -0x2090(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq -0x20c8(%rbp), %rdx
movq %rax, %rsi
leaq -0x1038(%rbp), %rdi
movq %rdi, -0x20c0(%rbp)
callq 0x8420
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq -0x20c0(%rbp), %rsi
movq %rax, %rdi
movq %rdi, -0x20b8(%rbp)
callq 0x4240
movq -0x20b8(%rbp), %rdi
leaq 0x58f7(%rip), %rsi      # 0xc888
leaq -0x2d08(%rip), %rdx     # 0x4290
callq 0x31c0
jmp 0x73c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x820(%rbp)
movl %eax, -0x824(%rbp)
leaq -0x1038(%rbp), %rdi
callq 0x4290
jmp 0x73ba
movq -0x2090(%rbp), %rax
movl 0x48(%rax), %ecx
movl %ecx, -0x20cc(%rbp)
movq 0x30(%rax), %rdi
callq 0x3dd0
movl %eax, %ecx
movl -0x20cc(%rbp), %eax
cmpl %ecx, %eax
jge 0x7013
movq -0x2090(%rbp), %rax
movl 0x4c(%rax), %ecx
movl %ecx, -0x20d0(%rbp)
movq 0x30(%rax), %rdi
callq 0x3dd0
movl %eax, %ecx
movl -0x20d0(%rbp), %eax
cmpl %ecx, %eax
jl 0x70d1
movq -0x2090(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq %rax, %rdx
leaq 0x222c(%rip), %rsi      # 0x9259
xorl %eax, %eax
leaq -0x1440(%rbp), %rdi
movq %rdi, -0x20e8(%rbp)
callq 0x3050
movq -0x2090(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq -0x20e8(%rbp), %rdx
movq %rax, %rsi
leaq -0x1848(%rbp), %rdi
movq %rdi, -0x20e0(%rbp)
callq 0x8420
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq -0x20e0(%rbp), %rsi
movq %rax, %rdi
movq %rdi, -0x20d8(%rbp)
callq 0x4240
movq -0x20d8(%rbp), %rdi
leaq 0x57eb(%rip), %rsi      # 0xc888
leaq -0x2e14(%rip), %rdx     # 0x4290
callq 0x31c0
jmp 0x73c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x820(%rbp)
movl %eax, -0x824(%rbp)
leaq -0x1848(%rbp), %rdi
callq 0x4290
jmp 0x73ba
movq -0x2090(%rbp), %rcx
movl 0x44(%rcx), %eax
cmpl 0x40(%rcx), %eax
jl 0x70f3
movq -0x2090(%rbp), %rcx
movl 0x4c(%rcx), %eax
cmpl 0x48(%rcx), %eax
jge 0x71b1
movq -0x2090(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq %rax, %rdx
leaq 0x216c(%rip), %rsi      # 0x9279
xorl %eax, %eax
leaq -0x1c50(%rbp), %rdi
movq %rdi, -0x2100(%rbp)
callq 0x3050
movq -0x2090(%rbp), %rdi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq -0x2100(%rbp), %rdx
movq %rax, %rsi
leaq -0x2058(%rbp), %rdi
movq %rdi, -0x20f8(%rbp)
callq 0x8420
movl $0x408, %edi            # imm = 0x408
callq 0x30a0
movq -0x20f8(%rbp), %rsi
movq %rax, %rdi
movq %rdi, -0x20f0(%rbp)
callq 0x4240
movq -0x20f0(%rbp), %rdi
leaq 0x570b(%rip), %rsi      # 0xc888
leaq -0x2ef4(%rip), %rdx     # 0x4290
callq 0x31c0
jmp 0x73c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x820(%rbp)
movl %eax, -0x824(%rbp)
leaq -0x2058(%rbp), %rdi
callq 0x4290
jmp 0x73ba
movq -0x2090(%rbp), %rax
movl 0x4c(%rax), %ecx
subl 0x48(%rax), %ecx
addl $0x1, %ecx
movl %ecx, -0x205c(%rbp)
movl 0x44(%rax), %ecx
subl 0x40(%rax), %ecx
addl $0x1, %ecx
movl %ecx, -0x2060(%rbp)
movq 0x30(%rax), %rdi
callq 0x3db0
movl %eax, -0x2064(%rbp)
movl -0x2060(%rbp), %eax
imull -0x205c(%rbp), %eax
cltq
movl $0x3, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rcx
movq -0x2090(%rbp), %rax
movq %rcx, -0x2070(%rbp)
movq 0x30(%rax), %rdi
callq 0x3df0
movq %rax, %rcx
movq -0x2090(%rbp), %rax
movq %rcx, -0x2078(%rbp)
movl 0x40(%rax), %eax
movl %eax, -0x207c(%rbp)
movq -0x2090(%rbp), %rcx
movl -0x207c(%rbp), %eax
cmpl 0x44(%rcx), %eax
jg 0x737e
movq -0x2090(%rbp), %rax
movl 0x48(%rax), %eax
movl %eax, -0x2080(%rbp)
movq -0x2090(%rbp), %rcx
movl -0x2080(%rbp), %eax
cmpl 0x4c(%rcx), %eax
jg 0x7368
movq -0x2090(%rbp), %rdx
movl -0x2080(%rbp), %eax
imull -0x2064(%rbp), %eax
addl -0x207c(%rbp), %eax
movl %eax, -0x2084(%rbp)
movl -0x2080(%rbp), %eax
subl 0x48(%rdx), %eax
imull -0x2060(%rbp), %eax
movl -0x207c(%rbp), %ecx
subl 0x40(%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x2088(%rbp)
movq -0x2078(%rbp), %rax
movslq -0x2084(%rbp), %rcx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movb (%rax), %cl
movq -0x2070(%rbp), %rax
movslq -0x2088(%rbp), %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rax
movb %cl, (%rax)
movq -0x2078(%rbp), %rax
movslq -0x2084(%rbp), %rcx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movb 0x1(%rax), %cl
movq -0x2070(%rbp), %rax
movslq -0x2088(%rbp), %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x1(%rax)
movq -0x2078(%rbp), %rax
movslq -0x2084(%rbp), %rcx
imulq $0x3, %rcx, %rcx
addq %rcx, %rax
movb 0x2(%rax), %cl
movq -0x2070(%rbp), %rax
movslq -0x2088(%rbp), %rdx
imulq $0x3, %rdx, %rdx
addq %rdx, %rax
movb %cl, 0x2(%rax)
movl -0x2080(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2080(%rbp)
jmp 0x726f
jmp 0x736a
movl -0x207c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x207c(%rbp)
jmp 0x7249
movq -0x2090(%rbp), %rdi
addq $0x8, %rdi
movl -0x2060(%rbp), %esi
movl -0x205c(%rbp), %edx
callq 0x3e90
movq -0x2090(%rbp), %rdi
addq $0x8, %rdi
movq -0x2070(%rbp), %rsi
callq 0x3eb0
addq $0x2100, %rsp           # imm = 0x2100
popq %rbp
retq
movq -0x820(%rbp), %rdi
callq 0x31d0
nopw %cs:(%rax,%rax)