// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/jpeg/jcparam.c
// Function: jpeg_simple_progression
GLOBAL(void)
jpeg_simple_progression (j_compress_ptr cinfo)
{
  int ncomps = cinfo->num_components;
  int nscans;
  jpeg_scan_info * scanptr;

  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  /* Figure space needed for script.  Calculation must match code below! */
  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    /* Custom script for YCbCr color images. */
    nscans = 10;
  } else {
    /* All-purpose script for other color spaces. */
    if (ncomps > MAX_COMPS_IN_SCAN)
      nscans = 6 * ncomps;	/* 2 DC + 4 AC scans per component */
    else
      nscans = 2 + 4 * ncomps;	/* 2 DC scans; 4 AC scans per component */
  }

  /* Allocate space for script.
   * We need to put it in the permanent pool in case the application performs
   * multiple compressions without changing the settings.  To avoid a memory
   * leak if jpeg_simple_progression is called repeatedly for the same JPEG
   * object, we try to re-use previously allocated space, and we allocate
   * enough space to handle YCbCr even if initially asked for grayscale.
   */
  if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
    cinfo->script_space_size = MAX(nscans, 10);
    cinfo->script_space = (jpeg_scan_info *)
      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
			cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  }
  scanptr = cinfo->script_space;
  cinfo->scan_info = scanptr;
  cinfo->num_scans = nscans;

  if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
    /* Custom script for YCbCr color images. */
    /* Initial DC scan */
    scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
    /* Initial AC scan: get some luma data out in a hurry */
    scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
    /* Chroma data is too small to be worth expending many scans on */
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
    /* Complete spectral selection for luma AC */
    scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
    /* Refine next bit of luma AC */
    scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
    /* Finish DC successive approximation */
    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
    /* Finish AC successive approximation */
    scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
    scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
    /* Luma bottom bit comes last since it's usually largest scan */
    scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  } else {
    /* All-purpose script for other color spaces. */
    /* Successive approximation first pass */
    scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
    scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
    scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
    /* Successive approximation second pass */
    scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
    /* Successive approximation final pass */
    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
    scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %r14
movl 0x24(%rdi), %eax
movl 0x4c(%rdi), %ebx
cmpl $0x64, %eax
je 0x7373b
movq (%r14), %rcx
movl $0x14, 0x28(%rcx)
movl %eax, 0x2c(%rcx)
movq (%r14), %rax
movq %r14, %rdi
callq *(%rax)
cmpl $0x3, %ebx
jne 0x7374c
movl $0xa, %ebp
cmpl $0x3, 0x50(%r14)
je 0x73760
cmpl $0x5, %ebx
jl 0x73759
leal (%rbx,%rbx), %eax
leal (%rax,%rax,2), %ebp
jmp 0x73760
leal 0x2(,%rbx,4), %ebp
cmpq $0x0, 0x1f8(%r14)
je 0x73773
cmpl %ebp, 0x200(%r14)
jge 0x7379f
cmpl $0xb, %ebp
movl $0xa, %eax
cmovgel %ebp, %eax
movl %eax, 0x200(%r14)
movq 0x8(%r14), %rcx
shlq $0x2, %rax
leaq (%rax,%rax,8), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq *(%rcx)
movq %rax, 0x1f8(%r14)
movq 0x1f8(%r14), %rdi
movq %rdi, 0xf8(%r14)
movl %ebp, 0xf0(%r14)
cmpl $0x3, %ebx
jne 0x73962
cmpl $0x3, 0x50(%r14)
jne 0x73962
movl $0x3, (%rdi)
movdqa 0x2eaaa(%rip), %xmm4    # 0xa2280
xorl %eax, %eax
movdqa 0x2eab0(%rip), %xmm0    # 0xa2290
movdqa 0x36898(%rip), %xmm1    # 0xaa080
pshufd $0xf5, %xmm1, %xmm2     # xmm2 = xmm1[1,1,3,3]
movdqa 0x2eaab(%rip), %xmm3    # 0xa22a0
movdqa %xmm4, %xmm5
pxor %xmm0, %xmm5
movdqa %xmm1, %xmm6
pcmpgtd %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
pcmpeqd %xmm2, %xmm5
pand %xmm6, %xmm5
movd %xmm5, %ecx
testb $0x1, %cl
je 0x7381f
movl %eax, 0x4(%rdi,%rax,4)
pextrw $0x4, %xmm5, %ecx
testb $0x1, %cl
je 0x73830
leal 0x1(%rax), %ecx
movl %ecx, 0x8(%rdi,%rax,4)
addq $0x2, %rax
paddq %xmm3, %xmm4
cmpq $0x4, %rax
jne 0x737f5
movaps 0x3684b(%rip), %xmm4    # 0xaa090
movups %xmm4, 0x14(%rdi)
movl $0x1, %edx
movq %rdx, 0x24(%rdi)
movaps 0x367e7(%rip), %xmm4    # 0xaa040
movups %xmm4, 0x38(%rdi)
movabsq $0x200000001, %rax      # imm = 0x200000001
movq %rax, 0x48(%rdi)
movaps 0x3682e(%rip), %xmm4    # 0xaa0a0
movups %xmm4, 0x5c(%rdi)
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x6c(%rdi)
movups %xmm4, 0x80(%rdi)
movq %rdx, 0x90(%rdi)
movaps 0x367b7(%rip), %xmm4    # 0xaa050
movups %xmm4, 0xa4(%rdi)
movq %rdx, 0xb4(%rdi)
movaps 0x367b2(%rip), %xmm4    # 0xaa060
movups %xmm4, 0xc8(%rdi)
movl $0x3, 0xd8(%rdi)
movdqa 0x2e9b9(%rip), %xmm4    # 0xa2280
xorl %edx, %edx
movdqa %xmm4, %xmm5
pxor %xmm0, %xmm5
movdqa %xmm1, %xmm6
pcmpgtd %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
pcmpeqd %xmm2, %xmm5
pand %xmm6, %xmm5
movd %xmm5, %esi
testb $0x1, %sil
je 0x738f7
movl %edx, 0xdc(%rdi,%rdx,4)
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x7390c
leal 0x1(%rdx), %esi
movl %esi, 0xe0(%rdi,%rdx,4)
addq $0x2, %rdx
paddq %xmm3, %xmm4
cmpq $0x4, %rdx
jne 0x738c9
movaps 0x2e95f(%rip), %xmm0    # 0xa2280
movups %xmm0, 0xec(%rdi)
movq %rax, 0xfc(%rdi)
movaps 0x3673a(%rip), %xmm0    # 0xaa070
movups %xmm0, 0x110(%rdi)
movq %rcx, 0x120(%rdi)
movups %xmm0, 0x134(%rdi)
movq $0x1, 0x144(%rdi)
movups %xmm0, 0x158(%rdi)
jmp 0x73a11
xorl %ebp, %ebp
movl %ebx, %esi
xorl %edx, %edx
movl $0x1, %ecx
callq 0x73a16
testl %ebx, %ebx
jle 0x73994
movaps 0x366c3(%rip), %xmm0    # 0xaa040
movl $0x1, (%rax)
movl %ebp, 0x4(%rax)
movups %xmm0, 0x14(%rax)
addq $0x24, %rax
incl %ebp
cmpl %ebp, %ebx
jne 0x7397d
testl %ebx, %ebx
jle 0x739b8
xorl %ecx, %ecx
movaps 0x366af(%rip), %xmm0    # 0xaa050
movl $0x1, (%rax)
movl %ecx, 0x4(%rax)
movups %xmm0, 0x14(%rax)
addq $0x24, %rax
incl %ecx
cmpl %ecx, %ebx
jne 0x739a1
testl %ebx, %ebx
jle 0x739dc
xorl %ecx, %ecx
movaps 0x3669b(%rip), %xmm0    # 0xaa060
movl $0x1, (%rax)
movl %ecx, 0x4(%rax)
movups %xmm0, 0x14(%rax)
addq $0x24, %rax
incl %ecx
cmpl %ecx, %ebx
jne 0x739c5
xorl %ebp, %ebp
movq %rax, %rdi
movl %ebx, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x73a16
testl %ebx, %ebx
jle 0x73a11
movaps 0x36676(%rip), %xmm0    # 0xaa070
movl $0x1, (%rax)
movl %ebp, 0x4(%rax)
movups %xmm0, 0x14(%rax)
addq $0x24, %rax
incl %ebp
cmpl %ebp, %ebx
jne 0x739fa
popq %rbx
popq %r14
popq %rbp
retq