// File: /workspace/github_cpp_makefile_star2_O3/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 %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movq %rsp, %r14
movl $0x9, %ecx
movq %r14, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movq %r14, %rdi
callq 0x32d02
movl 0x30(%r14), %esi
movl 0x30(%rbx), %ecx
movl 0x54(%rbx), %eax
movl 0x58(%rbx), %ebp
cmpl $0x40, %eax
movl $0x40, %r15d
cmovll %eax, %r15d
testl %ebp, %ebp
jle 0x31f72
testl %eax, %eax
jle 0x31f87
testl %ecx, %ecx
jg 0x31f7f
movl %ebp, %eax
xorl %edx, %edx
divl %r15d
cmpl %ebp, %r15d
movl $0x1, %ecx
cmovbel %eax, %ecx
jmp 0x31fa6
cmpl $0x2, %r15d
movl $0x1, %eax
cmovll %eax, %r15d
imull %r15d, %esi
movl %esi, %ebp
jmp 0x31fa6
movl %ebp, %eax
cltd
idivl %esi
testl %eax, %eax
cmovel %ebp, %eax
movl $0x1, %edx
cmovel %edx, %ecx
cmpl $0x40, %eax
movl $0x40, %r15d
cmovll %eax, %r15d
movl %ecx, 0x30(%rbx)
movq 0x38(%rbx), %r14
movq 0x48(%rbx), %rax
leaq 0x1(%rax), %rcx
cmpq $0x2, %rcx
jae 0x31ffc
movq %rbx, %rdi
callq 0x32d02
movq %r14, 0x38(%rbx)
movl 0x30(%rbx), %ecx
movq 0x48(%rbx), %rsi
cmpq $-0x1, %rsi
je 0x31fec
testq %rsi, %rsi
jne 0x32013
cmpl $0x1, %r15d
jg 0x32013
movq $-0x1, 0x48(%rbx)
jmp 0x320a4
movl $0x1, %eax
movl $0x1, %r15d
jmp 0x320a9
cmpq %r14, %rax
setae %cl
cmpq $-0x1, %r14
setne %dl
testb %cl, %dl
jne 0x31fbb
movq %rax, 0x38(%rbx)
jmp 0x31fbb
testq %rsi, %rsi
jne 0x3205e
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 0x320a4
movq %r14, %rax
xorl %edx, %edx
divq %rsi
imulq %rax, %rsi
xorl %edx, %edx
cmpq %r14, %rsi
setne %dl
addq %rax, %rdx
movl %r15d, %esi
movl $0x1, %eax
cmovnel %edx, %eax
imull %eax, %ecx
cmpq %rsi, %rdx
cmovael %ebp, %ecx
cmovael %r15d, %eax
jmp 0x320a9
movl %ebp, %ecx
movl %r15d, %eax
movl %r15d, 0x54(%rbx)
movl %eax, 0x50(%rbx)
movl %ecx, 0x58(%rbx)
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq