// File: /workspace/github_cpp_makefile_star2_O1/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 0x33112
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 0x3233e
testl %eax, %eax
jle 0x32353
testl %ecx, %ecx
jg 0x3234b
movl %ebp, %eax
xorl %edx, %edx
divl %r15d
cmpl %ebp, %r15d
movl $0x1, %ecx
cmovbel %eax, %ecx
jmp 0x32372
cmpl $0x2, %r15d
movl $0x1, %eax
cmovll %eax, %r15d
imull %r15d, %esi
movl %esi, %ebp
jmp 0x32372
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 0x323c8
movq %rbx, %rdi
callq 0x33112
movq %r14, 0x38(%rbx)
movl 0x30(%rbx), %ecx
movq 0x48(%rbx), %rax
cmpq $-0x1, %rax
je 0x323b8
testq %rax, %rax
jne 0x323df
cmpl $0x1, %r15d
jg 0x323df
movq $-0x1, 0x48(%rbx)
jmp 0x32474
movl $0x1, %eax
movl $0x1, %r15d
jmp 0x32479
cmpq %r14, %rax
setae %cl
cmpq $-0x1, %r14
setne %dl
testb %cl, %dl
jne 0x32387
movq %rax, 0x38(%rbx)
jmp 0x32387
testq %rax, %rax
jne 0x3242a
movl 0x4(%rbx), %eax
leaq (,%rax,4), %rdx
cmpq $0x100001, %rdx         # imm = 0x100001
movl $0x100000, %esi         # imm = 0x100000
cmovaeq %rdx, %rsi
movl $0x10000000, %edx       # imm = 0x10000000
cmpq %rdx, %rsi
cmovaeq %rdx, %rsi
cmpq %rax, %rsi
cmovbeq %rax, %rsi
addq $0xfffff, %rsi          # imm = 0xFFFFF
movabsq $0x1fff00000, %rax      # imm = 0x1FFF00000
andq %rsi, %rax
movq %rax, 0x48(%rbx)
cmpl $0x2, %r15d
setge %al
cmpq $-0x1, %r14
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x32474
movq 0x48(%rbx), %rsi
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 0x32479
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