// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movl $0x48, %edx
callq 0x4320
leaq -0x70(%rbp), %rdi
callq 0x67180
movl -0x40(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, -0x24(%rbp)
cmpl $0x40, -0x1c(%rbp)
jle 0x6595b
movl $0x40, -0x1c(%rbp)
cmpl $0x0, -0x24(%rbp)
jg 0x6597a
cmpl $0x0, -0x1c(%rbp)
jg 0x6596e
movl $0x1, -0x1c(%rbp)
movl -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x659d9
cmpl $0x0, -0x1c(%rbp)
jg 0x659ac
movl -0x24(%rbp), %eax
cltd
idivl -0x18(%rbp)
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x6599d
movl $0x1, -0x14(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x40, -0x1c(%rbp)
jle 0x659aa
movl $0x40, -0x1c(%rbp)
jmp 0x659d7
cmpl $0x0, -0x14(%rbp)
jg 0x659cb
movl -0x24(%rbp), %eax
cltd
idivl -0x1c(%rbp)
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x659c9
movl $0x1, -0x14(%rbp)
jmp 0x659d5
movl -0x18(%rbp), %eax
imull -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x659d7
jmp 0x659d9
movl -0x14(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x30(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $-0x1, 0x48(%rax)
je 0x65a30
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x65a30
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rax
cmpq -0x10(%rbp), %rax
jb 0x65a20
cmpq $-0x1, -0x10(%rbp)
jne 0x65a30
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rdi
callq 0x67180
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
cmpq $-0x1, 0x48(%rax)
jne 0x65a73
movl $0x1, -0x1c(%rbp)
movl $0x1, -0x20(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x65bca
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x65a95
cmpl $0x1, -0x1c(%rbp)
jg 0x65a95
movq -0x8(%rbp), %rax
movq $-0x1, 0x48(%rax)
jmp 0x65bc8
movq -0x8(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x65b4a
movl $0x100000, -0x74(%rbp)  # imm = 0x100000
movl $0x10000000, -0x78(%rbp) # imm = 0x10000000
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
shlq $0x2, %rax
movq %rax, -0x88(%rbp)
cmpq $0x100000, -0x88(%rbp) # imm = 0x100000
jae 0x65ae2
movq $0x100000, -0x88(%rbp) # imm = 0x100000
cmpq $0x10000000, -0x88(%rbp) # imm = 0x10000000
jbe 0x65afa
movq $0x10000000, -0x88(%rbp) # imm = 0x10000000
movq -0x88(%rbp), %rax
movl -0x7c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x65b13
movl -0x7c(%rbp), %eax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
addq $0xfffff, %rax          # imm = 0xFFFFF
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
andq $-0x100000, %rax        # imm = 0xFFF00000
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
cmpl $0x1, -0x1c(%rbp)
jle 0x65bc6
cmpq $-0x1, -0x10(%rbp)
je 0x65bc6
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
xorl %edx, %edx
divq 0x48(%rcx)
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq -0x8(%rbp), %rcx
imulq 0x48(%rcx), %rax
cmpq -0x10(%rbp), %rax
je 0x65b94
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x65bc4
movq -0x90(%rbp), %rax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x65bba
movl $0x1, -0x20(%rbp)
movl -0x14(%rbp), %eax
imull -0x20(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x65bc6
jmp 0x65bc8
jmp 0x65bca
movl -0x1c(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x54(%rax)
movl -0x20(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x50(%rax)
movl -0x24(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x58(%rax)
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)