// File: /workspace/github_cpp_makefile_star2_O2/sisong[P]ApkDiffPatch/lzma/C/Lzma2Enc.c
// Function: Lzma2EncProps_Normalize
void Lzma2EncProps_Normalize(CLzma2EncProps *p)
{
  UInt64 fileSize;
  int t1, t1n, t2, t2r, t3;
  {
    CLzmaEncProps lzmaProps = p->lzmaProps;
    LzmaEncProps_Normalize(&lzmaProps);
    t1n = lzmaProps.numThreads;
  }

  t1 = p->lzmaProps.numThreads;
  t2 = p->numBlockThreads_Max;
  t3 = p->numTotalThreads;

  if (t2 > MTCODER_THREADS_MAX)
    t2 = MTCODER_THREADS_MAX;

  if (t3 <= 0)
  {
    if (t2 <= 0)
      t2 = 1;
    t3 = t1n * t2;
  }
  else if (t2 <= 0)
  {
    t2 = t3 / t1n;
    if (t2 == 0)
    {
      t1 = 1;
      t2 = t3;
    }
    if (t2 > MTCODER_THREADS_MAX)
      t2 = MTCODER_THREADS_MAX;
  }
  else if (t1 <= 0)
  {
    t1 = t3 / t2;
    if (t1 == 0)
      t1 = 1;
  }
  else
    t3 = t1n * t2;

  p->lzmaProps.numThreads = t1;

  t2r = t2;

  fileSize = p->lzmaProps.reduceSize;

  if (   p->blockSize != LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID
      && p->blockSize != LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO
      && (p->blockSize < fileSize || fileSize == (UInt64)(Int64)-1))
    p->lzmaProps.reduceSize = p->blockSize;

  LzmaEncProps_Normalize(&p->lzmaProps);

  p->lzmaProps.reduceSize = fileSize;

  t1 = p->lzmaProps.numThreads;

  if (p->blockSize == LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID)
  {
    t2r = t2 = 1;
    t3 = t1;
  }
  else if (p->blockSize == LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO && t2 <= 1)
  {
    /* if there is no block multi-threading, we use SOLID block */
    p->blockSize = LZMA2_ENC_PROPS_BLOCK_SIZE_SOLID;
  }
  else
  {
    if (p->blockSize == LZMA2_ENC_PROPS_BLOCK_SIZE_AUTO)
    {
      const UInt32 kMinSize = (UInt32)1 << 20;
      const UInt32 kMaxSize = (UInt32)1 << 28;
      const UInt32 dictSize = p->lzmaProps.dictSize;
      UInt64 blockSize = (UInt64)dictSize << 2;
      if (blockSize < kMinSize) blockSize = kMinSize;
      if (blockSize > kMaxSize) blockSize = kMaxSize;
      if (blockSize < dictSize) blockSize = dictSize;
      blockSize += (kMinSize - 1);
      blockSize &= ~(UInt64)(kMinSize - 1);
      p->blockSize = blockSize;
    }
    
    if (t2 > 1 && fileSize != (UInt64)(Int64)-1)
    {
      UInt64 numBlocks = fileSize / p->blockSize;
      if (numBlocks * p->blockSize != fileSize)
        numBlocks++;
      if (numBlocks < (unsigned)t2)
      {
        t2r = (int)numBlocks;
        if (t2r == 0)
          t2r = 1;
        t3 = t1 * t2r;
      }
    }
  }
  
  p->numBlockThreads_Max = t2;
  p->numBlockThreads_Reduced = t2r;
  p->numTotalThreads = t3;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x50, %rsp
movq %rdi, %rbx
pushq $0x9
popq %rcx
leaq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x2af63
movl 0x30(%r14), %esi
movl 0x30(%rbx), %ecx
movl 0x54(%rbx), %eax
movl 0x58(%rbx), %ebp
cmpl $0x40, %eax
pushq $0x40
popq %rdi
movl %edi, %r15d
cmovll %eax, %r15d
pushq $0x1
popq %r12
testl %ebp, %ebp
jle 0x2a279
testl %eax, %eax
jle 0x2a28c
testl %ecx, %ecx
jg 0x2a284
movl %ebp, %eax
xorl %edx, %edx
divl %r15d
movl %eax, %ecx
cmpl %ebp, %r15d
cmoval %r12d, %ecx
jmp 0x2a2a3
cmpl $0x2, %r15d
pushq $0x1
popq %rax
cmovll %eax, %r15d
imull %r15d, %esi
movl %esi, %ebp
jmp 0x2a2a3
movl %ebp, %eax
cltd
idivl %esi
testl %eax, %eax
cmovel %ebp, %eax
cmovel %r12d, %ecx
cmpl $0x40, %eax
cmovll %eax, %edi
movl %edi, %r15d
movl %ecx, 0x30(%rbx)
movq 0x38(%rbx), %r14
movq 0x48(%rbx), %rax
leaq 0x1(%rax), %rcx
cmpq $0x2, %rcx
jae 0x2a2f0
movq %rbx, %rdi
callq 0x2af63
movq %r14, 0x38(%rbx)
movl 0x30(%rbx), %ecx
movq 0x48(%rbx), %rsi
cmpq $-0x1, %rsi
je 0x2a2e6
testq %rsi, %rsi
jne 0x2a307
cmpl $0x1, %r15d
jg 0x2a307
orq $-0x1, 0x48(%rbx)
jmp 0x2a399
movl %ecx, %ebp
movl %r12d, %r15d
jmp 0x2a39c
cmpq %r14, %rax
setae %cl
cmpq $-0x1, %r14
setne %dl
testb %cl, %dl
jne 0x2a2b8
movq %rax, 0x38(%rbx)
jmp 0x2a2b8
testq %rsi, %rsi
jne 0x2a352
movl 0x4(%rbx), %eax
leaq (,%rax,4), %rdx
cmpq $0x100001, %rdx         # imm = 0x100001
movl $0x100000, %edi         # imm = 0x100000
cmovaeq %rdx, %rdi
movl $0x10000000, %edx       # imm = 0x10000000
cmpq %rdx, %rdi
cmovaeq %rdx, %rdi
cmpq %rax, %rdi
cmovbeq %rax, %rdi
addq $0xfffff, %rdi          # imm = 0xFFFFF
movabsq $0x1fff00000, %rsi      # imm = 0x1FFF00000
andq %rdi, %rsi
movq %rsi, 0x48(%rbx)
cmpl $0x2, %r15d
setge %al
cmpq $-0x1, %r14
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x2a399
movq %r14, %rax
xorl %edx, %edx
divq %rsi
imulq %rax, %rsi
xorl %edx, %edx
cmpq %r14, %rsi
setne %dl
addq %rax, %rdx
movl %r15d, %eax
pushq $0x1
popq %r12
cmovnel %edx, %r12d
imull %r12d, %ecx
cmpq %rax, %rdx
cmovbl %ecx, %ebp
cmovael %r15d, %r12d
jmp 0x2a39c
movl %r15d, %r12d
movl %r15d, 0x54(%rbx)
movl %r12d, 0x50(%rbx)
movl %ebp, 0x58(%rbx)
addq $0x50, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq