// File: cloudinary[P]fuif/transform/squeeze.h
// Function: default_squeeze_parameters(std::vector<int, std::allocator<int>>&, Image const&)
void default_squeeze_parameters(std::vector<int> &parameters, const Image &image) {
    int nb_channels = image.nb_channels;
    // maybe other transforms have been applied before, but let's assume the first nb_channels channels
    // still contain the 'main' data

    parameters.clear();
    int w = image.channel[image.nb_meta_channels].w;
    int h = image.channel[image.nb_meta_channels].h;
    v_printf(7,"\nDefault squeeze parameters for %ix%i image: ",w,h);

    bool wide = (w>h);  // do horizontal first on wide images; vertical first on tall images
    if (nb_channels>2 && image.channel[image.nb_meta_channels+1].w == w && image.channel[image.nb_meta_channels+1].h == h) {
        // assume channels 1 and 2 are chroma, and can be squeezed first for 4:2:0 previews
        v_printf(7,"(4:2:0 chroma), ",w,h);
//        if (!wide) {
//        parameters.push_back(0+2); // vertical chroma squeeze
//        parameters.push_back(image.nb_meta_channels+1);
//        parameters.push_back(image.nb_meta_channels+2);
//        }
        parameters.push_back(1+2); // horizontal chroma squeeze
        parameters.push_back(image.nb_meta_channels+1);
        parameters.push_back(image.nb_meta_channels+2);
//        if (wide) {
        parameters.push_back(0+2); // vertical chroma squeeze
        parameters.push_back(image.nb_meta_channels+1);
        parameters.push_back(image.nb_meta_channels+2);
//        }
    }

    if (!wide) {
            if (h > MAX_FIRST_PREVIEW_SIZE) {
                parameters.push_back(0); // vertical squeeze
                parameters.push_back(image.nb_meta_channels);
                parameters.push_back(image.nb_meta_channels+nb_channels-1);
                h = (h+1)/2;
                v_printf(7,"Vertical (%ix%i), ",w,h);
            }
    }
    while ( w > MAX_FIRST_PREVIEW_SIZE || h > MAX_FIRST_PREVIEW_SIZE ) {
            if (w > MAX_FIRST_PREVIEW_SIZE) {
                parameters.push_back(1); // horizontal squeeze
                parameters.push_back(image.nb_meta_channels);
                parameters.push_back(image.nb_meta_channels+nb_channels-1);
                w = (w+1)/2;
                v_printf(7,"Horizontal (%ix%i), ",w,h);
            }
            if (h > MAX_FIRST_PREVIEW_SIZE) {
                parameters.push_back(0); // vertical squeeze
                parameters.push_back(image.nb_meta_channels);
                parameters.push_back(image.nb_meta_channels+nb_channels-1);
                h = (h+1)/2;
                v_printf(7,"Vertical (%ix%i), ",w,h);
            }
    }
    v_printf(7,"that's it\n");
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x48(%rsp), %rax
movl 0x64(%rax), %eax
movl %eax, 0x44(%rsp)
movq 0x50(%rsp), %rdi
callq 0x121e0
movq 0x48(%rsp), %rdi
movq 0x48(%rsp), %rax
movslq 0x6c(%rax), %rsi
callq 0x13390
movl 0x18(%rax), %eax
movl %eax, 0x40(%rsp)
movq 0x48(%rsp), %rdi
movq 0x48(%rsp), %rax
movslq 0x6c(%rax), %rsi
callq 0x13390
movl 0x1c(%rax), %eax
movl %eax, 0x3c(%rsp)
movl 0x40(%rsp), %edx
movl 0x3c(%rsp), %ecx
movl $0x7, %edi
leaq 0x3996d(%rip), %rsi     # 0x46c49
movb $0x0, %al
callq 0x3a770
movl 0x40(%rsp), %eax
cmpl 0x3c(%rsp), %eax
setg %al
andb $0x1, %al
movb %al, 0x3b(%rsp)
cmpl $0x2, 0x44(%rsp)
jle 0xd40a
movq 0x48(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x13390
movl 0x18(%rax), %eax
cmpl 0x40(%rsp), %eax
jne 0xd40a
movq 0x48(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x13390
movl 0x1c(%rax), %eax
cmpl 0x3c(%rsp), %eax
jne 0xd40a
movl 0x40(%rsp), %edx
movl 0x3c(%rsp), %ecx
movl $0x7, %edi
leaq 0x3991a(%rip), %rsi     # 0x46c77
movb $0x0, %al
callq 0x3a770
movq 0x50(%rsp), %rdi
movl $0x3, 0x34(%rsp)
leaq 0x34(%rsp), %rsi
callq 0x121b0
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
leaq 0x30(%rsp), %rsi
callq 0x121b0
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl $0x2, %eax
movl %eax, 0x2c(%rsp)
leaq 0x2c(%rsp), %rsi
callq 0x121b0
movq 0x50(%rsp), %rdi
movl $0x2, 0x28(%rsp)
leaq 0x28(%rsp), %rsi
callq 0x121b0
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
leaq 0x24(%rsp), %rsi
callq 0x121b0
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl $0x2, %eax
movl %eax, 0x20(%rsp)
leaq 0x20(%rsp), %rsi
callq 0x121b0
testb $0x1, 0x3b(%rsp)
jne 0xd498
cmpl $0x8, 0x3c(%rsp)
jle 0xd496
movq 0x50(%rsp), %rdi
movl $0x0, 0x1c(%rsp)
leaq 0x1c(%rsp), %rsi
callq 0x121b0
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq $0x6c, %rsi
callq 0x12560
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl 0x44(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x18(%rsp)
leaq 0x18(%rsp), %rsi
callq 0x121b0
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x3c(%rsp)
movl 0x40(%rsp), %edx
movl 0x3c(%rsp), %ecx
movl $0x7, %edi
leaq 0x397f9(%rip), %rsi     # 0x46c88
movb $0x0, %al
callq 0x3a770
jmp 0xd498
jmp 0xd49a
movb $0x1, %al
cmpl $0x8, 0x40(%rsp)
movb %al, 0x7(%rsp)
jg 0xd4b3
cmpl $0x8, 0x3c(%rsp)
setg %al
movb %al, 0x7(%rsp)
movb 0x7(%rsp), %al
testb $0x1, %al
jne 0xd4c0
jmp 0xd5c7
cmpl $0x8, 0x40(%rsp)
jle 0xd541
movq 0x50(%rsp), %rdi
movl $0x1, 0x14(%rsp)
leaq 0x14(%rsp), %rsi
callq 0x121b0
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq $0x6c, %rsi
callq 0x12560
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl 0x44(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x10(%rsp)
leaq 0x10(%rsp), %rsi
callq 0x121b0
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x40(%rsp)
movl 0x40(%rsp), %edx
movl 0x3c(%rsp), %ecx
movl $0x7, %edi
leaq 0x39761(%rip), %rsi     # 0x46c9b
movb $0x0, %al
callq 0x3a770
cmpl $0x8, 0x3c(%rsp)
jle 0xd5c2
movq 0x50(%rsp), %rdi
movl $0x0, 0xc(%rsp)
leaq 0xc(%rsp), %rsi
callq 0x121b0
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
addq $0x6c, %rsi
callq 0x12560
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movl 0x6c(%rax), %eax
addl 0x44(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x8(%rsp)
leaq 0x8(%rsp), %rsi
callq 0x121b0
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, 0x3c(%rsp)
movl 0x40(%rsp), %edx
movl 0x3c(%rsp), %ecx
movl $0x7, %edi
leaq 0x396cd(%rip), %rsi     # 0x46c88
movb $0x0, %al
callq 0x3a770
jmp 0xd49a
movl $0x7, %edi
leaq 0x396dd(%rip), %rsi     # 0x46cb0
movb $0x0, %al
callq 0x3a770
addq $0x58, %rsp
retq
nop