// File: /workspace/github_c_makefile_star2_O3/janmojzis[P]mcencrypt/controlbits.c
// Function: controlbitsfrompermutation
static void controlbitsfrompermutation(int w, int n, int step, int off, unsigned char *c, uint32_t pi[n])
{
  int i;
  int j;
  int k;
  int t;
  uint32_t ip[n];
  uint32_t I[2 * n];
  uint32_t P[2 * n];
  uint32_t PI[2 * n];
  uint32_t T[2 * n];
  uint32_t piflip[n];
  uint32_t subpi[2][n / 2];

  if (w == 1) c[ off/8 ] |= (pi[0] & 1) << (off%8);
  if (w <= 1) return;

  invert(n,ip,pi);

  for (i = 0;i < n;++i) 
  {
    I[i] = ip[i] | (1 << w);
    I[n + i] = pi[i];
  }

  for (i = 0;i < 2 * n;++i)
      P[i] = (i >> w) + (i & ((1<<w)-2)) + ((i & 1) << w);

  for (t = 0;t < w;++t) 
  {
    composeinv(2 * n,PI,P,I);

    for (i = 0;i < 2 * n;++i)
      flow(w,&P[i],&PI[i],t);

    for (i = 0;i < 2 * n;++i)
	T[i] = I[i ^ 1];

    composeinv(2 * n,I,I,T);

    for (i = 0;i < 2 * n;++i)
	T[i] = P[i ^ 1];

    for (i = 0;i < 2 * n;++i)
      flow(w,&P[i],&T[i],1);
  }

  for (i = 0;i < n;++i)
    for (j = 0;j < w;++j)
      piflip[i] = pi[i];

  for (i = 0;i < n / 2;++i) c[ (off + i * step)/8 ] |= ((P[i * 2] >> w) & 1) << ((off + i * step)%8);
  for (i = 0;i < n / 2;++i) c[ (off + ((w-1)*n + i) * step)/8 ] |= ((P[n + i * 2] >> w) & 1) << ((off + ((w-1)*n + i) * step)%8);

  for (i = 0;i < n / 2;++i)
    cswap(&piflip[i * 2], &piflip[i * 2 + 1], (P[n + i * 2] >> w) & 1);

  for (k = 0;k < 2;++k)
    for (i = 0;i < n / 2;++i)
        subpi[k][i] = piflip[i * 2 + k] >> 1;

  for (k = 0;k < 2;++k)
    controlbitsfrompermutation(w - 1, n / 2, step * 2, off + step * (n/2 + k), c, subpi[k]);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %r15
movl %ecx, %r9d
movl %esi, %ebx
movq %rsp, %r12
leaq 0xf(,%rbx,4), %rax
andq $-0x10, %rax
subq %rax, %r12
movq %r12, %rsp
leal (%rsi,%rsi), %ecx
movq %rsp, %r11
movq %rcx, -0x50(%rbp)
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %r11
movq %r11, %rsp
movq %rsp, %r14
subq %rcx, %r14
movq %r14, %rsp
movq %rsp, %r10
subq %rcx, %r10
movq %r10, -0x88(%rbp)
movq %r10, %rsp
movq %rsp, %r13
subq %rcx, %r13
movq %r13, %rsp
movq %rsp, %r10
subq %rax, %r10
movq %r10, %rsp
movl %esi, %eax
shrl $0x1f, %eax
addl %esi, %eax
sarl %eax
movq %rax, -0x78(%rbp)
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
cmpl $0x1, %edi
jne 0x3d9b
movl (%r15), %eax
andl $0x1, %eax
movl %r9d, %ecx
andb $0x7, %cl
shll %cl, %eax
leal 0x7(%r9), %ecx
testl %r9d, %r9d
cmovnsl %r9d, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
orb %al, (%r8,%rcx)
jmp 0x424c
jle 0x424c
testl %esi, %esi
movq %rdi, -0x38(%rbp)
movq %rsi, -0x30(%rbp)
movq %r11, -0x58(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
movq %r10, -0x60(%rbp)
jle 0x4042
leal 0x1(%rbx), %eax
andl $-0x2, %eax
leaq -0x1(%rbx), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x42ff(%rip), %xmm1     # 0x80e0
xorl %ecx, %ecx
movdqa 0x4325(%rip), %xmm7     # 0x8110
pxor %xmm7, %xmm0
pcmpeqd %xmm2, %xmm2
movdqa 0x42f5(%rip), %xmm3     # 0x80f0
movdqa %xmm1, %xmm4
pxor %xmm7, %xmm4
movdqa %xmm4, %xmm5
pcmpgtd %xmm0, %xmm5
pcmpeqd %xmm0, %xmm4
pshufd $0xf5, %xmm4, %xmm6     # xmm6 = xmm4[1,1,3,3]
pand %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm4     # xmm4 = xmm5[1,1,3,3]
por %xmm6, %xmm4
movd %xmm4, %edi
notl %edi
testb $0x1, %dil
je 0x3e31
movl %ecx, (%r12,%rcx,4)
pxor %xmm2, %xmm4
pextrw $0x4, %xmm4, %edi
testb $0x1, %dil
je 0x3e48
leal 0x1(%rcx), %edi
movl %edi, 0x4(%r12,%rcx,4)
addq $0x2, %rcx
paddq %xmm3, %xmm1
cmpq %rcx, %rax
jne 0x3dfb
movl %esi, %edi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x449f
movdqa 0x42a2(%rip), %xmm14    # 0x8110
movq -0x30(%rbp), %r8
testl %r8d, %r8d
movq -0x38(%rbp), %rcx
movq -0x58(%rbp), %r9
jle 0x4056
movl $0x1, %eax
shll %cl, %eax
leaq (%r9,%rbx,4), %rdi
xorl %edx, %edx
movl (%r12,%rdx,4), %esi
orl %eax, %esi
movl %esi, (%r9,%rdx,4)
movl (%r15,%rdx,4), %esi
movl %esi, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %rbx
jne 0x3e90
testl %r8d, %r8d
jle 0x4056
movq -0x50(%rbp), %rsi
cmpl $0x2, %esi
movl $0x1, %edx
movl $0x1, %eax
cmovgel %esi, %eax
shll %cl, %edx
addl $-0x2, %edx
leaq -0x1(%rax), %rsi
addl $0x3, %eax
movq %rsi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movd %ecx, %xmm6
movd %edx, %xmm1
pshufd $0x0, %xmm1, %xmm1      # xmm1 = xmm1[0,0,0,0]
andl $-0x4, %eax
shlq $0x2, %rax
movdqa 0x4228(%rip), %xmm2     # 0x8120
movdqa 0x41e0(%rip), %xmm3     # 0x80e0
movdqa 0x4228(%rip), %xmm4     # 0x8130
xorl %esi, %esi
pxor %xmm14, %xmm0
pxor %xmm5, %xmm5
movss %xmm6, %xmm5            # xmm5 = xmm6[0],xmm5[1,2,3]
movdqa 0x4221(%rip), %xmm6     # 0x8140
pcmpeqd %xmm7, %xmm7
movdqa 0x4224(%rip), %xmm8     # 0x8150
movdqa 0x422b(%rip), %xmm9     # 0x8160
movdqa %xmm3, %xmm10
pxor %xmm14, %xmm10
movdqa %xmm10, %xmm11
pcmpgtd %xmm0, %xmm11
pcmpeqd %xmm0, %xmm10
pshufd $0xf5, %xmm10, %xmm10   # xmm10 = xmm10[1,1,3,3]
pand %xmm11, %xmm10
pshufd $0xf5, %xmm11, %xmm11   # xmm11 = xmm11[1,1,3,3]
movdqa %xmm4, %xmm12
psrld %xmm5, %xmm12
por %xmm10, %xmm11
movdqa %xmm1, %xmm13
pand %xmm4, %xmm13
paddd %xmm12, %xmm13
movdqa %xmm4, %xmm10
pand %xmm6, %xmm10
pslld %xmm5, %xmm10
paddd %xmm13, %xmm10
movd %xmm11, %edx
notl %edx
testb $0x1, %dl
je 0x3fa3
movd %xmm10, (%r14,%rsi)
pxor %xmm7, %xmm11
pextrw $0x4, %xmm11, %edx
testb $0x1, %dl
je 0x3fc0
pshufd $0x55, %xmm10, %xmm11   # xmm11 = xmm10[1,1,1,1]
movd %xmm11, 0x4(%r14,%rsi)
movdqa %xmm2, %xmm11
pxor %xmm14, %xmm11
movdqa %xmm11, %xmm12
pcmpgtd %xmm0, %xmm12
pcmpeqd %xmm0, %xmm11
pshufd $0xf5, %xmm11, %xmm13   # xmm13 = xmm11[1,1,3,3]
pand %xmm12, %xmm13
pshufd $0xf5, %xmm12, %xmm11   # xmm11 = xmm12[1,1,3,3]
por %xmm13, %xmm11
pxor %xmm7, %xmm11
pextrw $0x0, %xmm11, %edx
testb $0x1, %dl
je 0x400c
pshufd $0xee, %xmm10, %xmm12   # xmm12 = xmm10[2,3,2,3]
movd %xmm12, 0x8(%r14,%rsi)
pextrw $0x4, %xmm11, %edx
testb $0x1, %dl
je 0x4024
pshufd $0xff, %xmm10, %xmm10   # xmm10 = xmm10[3,3,3,3]
movd %xmm10, 0xc(%r14,%rsi)
paddq %xmm8, %xmm3
paddq %xmm8, %xmm2
paddd %xmm9, %xmm4
addq $0x10, %rsi
cmpq %rsi, %rax
jne 0x3f35
jmp 0x4056
movl %esi, %edi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x449f
movq -0x38(%rbp), %rcx
movq %r15, -0x90(%rbp)
movq %rbx, -0x80(%rbp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
shll %cl, %r12d
notl %r12d
movq -0x50(%rbp), %rax
cmpl $0x2, %eax
movl $0x1, %r15d
cmovgel %eax, %r15d
xorl %ebx, %ebx
movq -0x50(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq %r14, %rdx
movq -0x58(%rbp), %rcx
callq 0x449f
movq -0x30(%rbp), %r10
testl %r10d, %r10d
jle 0x4190
xorl %eax, %eax
movq -0x38(%rbp), %rcx
movq -0x88(%rbp), %r11
testl %ebx, %ebx
setne %r9b
movl (%r11,%rax,4), %edx
movl %edx, %esi
andl %r12d, %esi
movl (%r14,%rax,4), %edi
movl %edi, %r8d
andl %r12d, %r8d
cmpl %r8d, %esi
setb %sil
cmovbl %edx, %edi
andb %r9b, %sil
movzbl %sil, %edx
shll %cl, %edx
xorl %edi, %edx
movl %edx, (%r14,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x40b1
testl %r10d, %r10d
jle 0x4190
xorl %eax, %eax
movq -0x58(%rbp), %rdx
movq %rax, %rcx
xorq $0x1, %rcx
movl (%rdx,%rcx,4), %ecx
movl %ecx, (%r13,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x40fa
movq -0x50(%rbp), %rdi
movq %rdx, %rsi
movq %r13, %rcx
callq 0x449f
cmpl $0x0, -0x30(%rbp)
movq -0x38(%rbp), %r11
jle 0x41a7
xorl %eax, %eax
movq %rax, %rcx
xorq $0x1, %rcx
movl (%r14,%rcx,4), %ecx
movl %ecx, (%r13,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x412c
cmpl $0x0, -0x30(%rbp)
jle 0x41a7
xorl %eax, %eax
movl (%r13,%rax,4), %ecx
movl %ecx, %edx
andl %r12d, %edx
movl (%r14,%rax,4), %esi
movl %esi, %edi
andl %r12d, %edi
xorl %r8d, %r8d
cmpl %edi, %edx
setb %r8b
cmovbl %ecx, %esi
movl %r11d, %ecx
shll %cl, %r8d
xorl %esi, %r8d
movl %r8d, (%r14,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x414c
incl %ebx
cmpl %r11d, %ebx
jne 0x4080
jmp 0x425b
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rdx
movq %rdx, %rsi
movq %r13, %rcx
callq 0x449f
movq -0x38(%rbp), %r11
incl %ebx
cmpl %r11d, %ebx
jne 0x4080
xorl %eax, %eax
movq -0x40(%rbp), %r8
movq -0x70(%rbp), %r14
movq -0x68(%rbp), %rbx
movq -0x78(%rbp), %r12
movq -0x48(%rbp), %r9
movq -0x60(%rbp), %r15
movb $0x1, %cl
xorl %edx, %edx
testb %al, %al
je 0x41f5
leaq (%r15,%rdx,4), %rsi
imulq %r12, %rdx
leaq (%r9,%rdx,4), %rdx
xorl %edi, %edi
movl (%rsi,%rdi,8), %r10d
shrl %r10d
movl %r10d, (%rdx,%rdi,4)
incq %rdi
cmpq %rdi, %r12
jne 0x41e2
movl $0x1, %edx
testb $0x1, %cl
movl $0x0, %ecx
jne 0x41d0
decl %r11d
movq %r11, -0x38(%rbp)
movq %rbx, %r13
addl %ebx, %ebx
movl %r12d, %ecx
imull %r13d, %ecx
addl %r14d, %ecx
movl %r11d, %edi
movl %r12d, %esi
movl %ebx, %edx
movq %r9, %r15
callq 0x3cd3
leaq (%r15,%r12,4), %r9
leal 0x1(%r12), %ecx
imull %r13d, %ecx
addl %r14d, %ecx
movq -0x38(%rbp), %rdi
movl %r12d, %esi
movl %ebx, %edx
movq -0x40(%rbp), %r8
callq 0x3cd3
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x0, -0x30(%rbp)
jle 0x41b2
xorl %eax, %eax
movq -0x40(%rbp), %r8
movq -0x70(%rbp), %r13
movq -0x68(%rbp), %rbx
movq -0x78(%rbp), %r12
movq -0x60(%rbp), %r15
movq -0x80(%rbp), %rdx
movq -0x90(%rbp), %rsi
movl (%rsi,%rax,4), %ecx
movl %ecx, (%r15,%rax,4)
incq %rax
cmpq %rax, %rdx
jne 0x4286
cmpl $0x1, -0x30(%rbp)
setne %al
je 0x4380
xorl %edx, %edx
movl %r13d, %esi
movl (%r14,%rdx,8), %ecx
xorl %edi, %edi
btl %r11d, %ecx
setb %dil
movl %esi, %ecx
andb $0x7, %cl
shll %cl, %edi
leal 0x7(%rsi), %ecx
testl %esi, %esi
cmovnsl %esi, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
orb %dil, (%r8,%rcx)
incq %rdx
addl %ebx, %esi
cmpq %rdx, %r12
jne 0x42a7
movq -0x30(%rbp), %rdi
cmpl $0x1, %edi
je 0x4380
leal -0x1(%r11), %ecx
movq -0x80(%rbp), %rdx
leaq (%r14,%rdx,4), %rdx
movl %ebx, %esi
imull %edi, %esi
imull %ecx, %esi
movq %r13, %r14
addl %r14d, %esi
xorl %edi, %edi
movl (%rdx,%rdi,8), %ecx
xorl %r9d, %r9d
btl %r11d, %ecx
setb %r9b
movl %esi, %ecx
andb $0x7, %cl
shll %cl, %r9d
leal 0x7(%rsi), %ecx
testl %esi, %esi
cmovnsl %esi, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
orb %r9b, (%r8,%rcx)
incq %rdi
addl %ebx, %esi
cmpq %rdi, %r12
jne 0x4301
cmpl $0x1, -0x30(%rbp)
movq -0x48(%rbp), %r9
je 0x438e
movl $0x1, %esi
movl %r11d, %ecx
shll %cl, %esi
xorl %ecx, %ecx
movl (%r15,%rcx,8), %edi
movl 0x4(%r15,%rcx,8), %r8d
movl %r8d, %r14d
xorl %edi, %r14d
movl (%rdx,%rcx,8), %r10d
andl %esi, %r10d
cmovnel %r14d, %r10d
xorl %r10d, %edi
movl %edi, (%r15,%rcx,8)
xorl %r8d, %r10d
movl %r10d, 0x4(%r15,%rcx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x4349
movq -0x40(%rbp), %r8
jmp 0x4386
xorl %eax, %eax
movq -0x48(%rbp), %r9
movq %r13, %r14
jmp 0x41cc
xorl %eax, %eax
jmp 0x41cc