// File: /workspace/github_c_makefile_star2_O2/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 $0x88, %rsp
movq %r9, %r15
movl %ecx, %r9d
movq %rdx, -0x58(%rbp)
movl %esi, %eax
movq %rsp, %rbx
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
leal (%rsi,%rsi), %ecx
movq %rsp, %r10
movq %rcx, -0x40(%rbp)
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %r10
movq %r10, %rsp
movq %rsp, %r12
subq %rcx, %r12
movq %r12, %rsp
movq %rsp, %rdx
subq %rcx, %rdx
movq %rdx, -0xa8(%rbp)
movq %rdx, %rsp
movq %rsp, %r11
subq %rcx, %r11
movq %r11, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x68(%rbp)
movq %rcx, %rsp
pushq $0x2
popq %rcx
movq %rsi, -0x50(%rbp)
movl %esi, %eax
cltd
idivl %ecx
movq %rax, -0x48(%rbp)
leaq 0xf(,%rax,8), %rax
andq $-0x10, %rax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, %rsp
movq %rdi, -0x30(%rbp)
cmpl $0x1, %edi
jne 0x3d0a
movl (%r15), %esi
andl $0x1, %esi
movl %r9d, %ecx
andb $0x7, %cl
shll %cl, %esi
pushq $0x8
popq %rcx
movl %r9d, %eax
cltd
idivl %ecx
cltq
orb %sil, (%r8,%rax)
jmp 0x3d10
movq %r8, -0x78(%rbp)
jg 0x3d1f
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
movq -0x50(%rbp), %rdx
testl %edx, %edx
movl $0x0, %esi
cmovgl %edx, %esi
cmpq %rax, %rsi
je 0x3d3c
movl %eax, (%rbx,%rax,4)
incq %rax
jmp 0x3d2f
movq %r11, -0x98(%rbp)
movq %rcx, -0x90(%rbp)
movl %r9d, -0x34(%rbp)
movq %rsi, -0x70(%rbp)
movq -0x50(%rbp), %r14
movl %r14d, %edi
movq %rbx, %rsi
movq %rbx, %rdx
movq %r15, %rcx
movq %r10, -0x60(%rbp)
callq 0x414b
movq -0x60(%rbp), %r9
pushq $0x1
popq %rax
movq -0x30(%rbp), %rcx
shll %cl, %eax
movslq %r14d, %rcx
movq -0x70(%rbp), %rdi
movq %rcx, -0x88(%rbp)
leaq (%r9,%rcx,4), %rcx
xorl %edx, %edx
cmpq %rdx, %rdi
je 0x3da6
movl (%rbx,%rdx,4), %esi
orl %eax, %esi
movl %esi, (%r9,%rdx,4)
movl (%r15,%rdx,4), %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
jmp 0x3d8c
addl $-0x2, %eax
xorl %edx, %edx
movq -0x40(%rbp), %rcx
testl %ecx, %ecx
movl $0x0, %ebx
cmovgl %ecx, %ebx
cmpq %rdx, %rbx
je 0x3de2
movl %edx, %esi
movq -0x30(%rbp), %rcx
shrl %cl, %esi
movl %eax, %edi
andl %edx, %edi
movl %edx, %r8d
andl $0x1, %r8d
shll %cl, %r8d
addl %esi, %edi
addl %edi, %r8d
movl %r8d, (%r12,%rdx,4)
incq %rdx
jmp 0x3db9
xorl %r13d, %r13d
movq %r12, -0x80(%rbp)
movq %r15, -0xa0(%rbp)
cmpl -0x30(%rbp), %r13d
je 0x3eca
movq -0x40(%rbp), %rdi
movq -0xa8(%rbp), %r14
movq %r14, %rsi
movq %r12, %rdx
movq %r9, %rcx
callq 0x414b
movq %r12, %r15
movq %rbx, %r12
subq $0x1, %r12
jb 0x3e3b
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %r13d, %ecx
callq 0x41bb
addq $0x4, %r14
addq $0x4, %r15
jmp 0x3e19
xorl %eax, %eax
movq -0x80(%rbp), %r15
movq -0x60(%rbp), %rdx
movq -0x98(%rbp), %r14
cmpq %rax, %rbx
je 0x3e64
movq %rax, %rcx
xorq $0x1, %rcx
movl (%rdx,%rcx,4), %ecx
movl %ecx, (%r14,%rax,4)
incq %rax
jmp 0x3e4c
movq -0x40(%rbp), %rdi
movq %rdx, %rsi
movq %r14, %rcx
callq 0x414b
xorl %eax, %eax
cmpq %rax, %rbx
je 0x3e8e
movq %rax, %rcx
xorq $0x1, %rcx
movl (%r15,%rcx,4), %ecx
movl %ecx, (%r14,%rax,4)
incq %rax
jmp 0x3e75
movq %rbx, %r12
subq $0x1, %r12
jb 0x3eb3
movq -0x30(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
pushq $0x1
popq %rcx
callq 0x41bb
addq $0x4, %r14
addq $0x4, %r15
jmp 0x3e91
incl %r13d
movq -0x80(%rbp), %r12
movq -0xa0(%rbp), %r15
movq -0x60(%rbp), %r9
jmp 0x3df0
xorl %eax, %eax
movq -0x78(%rbp), %r10
movq -0x58(%rbp), %r11
movq -0x68(%rbp), %rbx
movq -0x50(%rbp), %r14
cmpq %rax, -0x70(%rbp)
je 0x3eee
movl (%r15,%rax,4), %ecx
movl %ecx, (%rbx,%rax,4)
incq %rax
jmp 0x3edc
xorl %r8d, %r8d
movq -0x48(%rbp), %rax
testl %eax, %eax
movl $0x0, %r15d
cmovgl %eax, %r15d
pushq $0x8
popq %rdi
movl -0x34(%rbp), %esi
cmpq %r8, %r15
je 0x3f39
movl (%r12,%r8,8), %eax
xorl %r9d, %r9d
movq -0x30(%rbp), %rcx
btl %ecx, %eax
setb %r9b
movl %esi, %ecx
andb $0x7, %cl
shll %cl, %r9d
movl %esi, %eax
cltd
idivl %edi
cltq
orb %r9b, (%r10,%rax)
incq %r8
addl %r11d, %esi
jmp 0x3f07
movq -0x30(%rbp), %rax
leal -0x1(%rax), %ecx
movq -0x88(%rbp), %rax
leaq (%r12,%rax,4), %r12
imull %r11d, %r14d
movl %ecx, -0x40(%rbp)
imull %ecx, %r14d
addl -0x34(%rbp), %r14d
xorl %esi, %esi
cmpq %rsi, %r15
je 0x3f90
movl (%r12,%rsi,8), %eax
xorl %r8d, %r8d
movq -0x30(%rbp), %rcx
btl %ecx, %eax
setb %r8b
movl %r14d, %ecx
andb $0x7, %cl
shll %cl, %r8d
movl %r14d, %eax
cltd
idivl %edi
cltq
orb %r8b, (%r10,%rax)
incq %rsi
addl %r11d, %r14d
jmp 0x3f5c
xorl %r13d, %r13d
cmpq %r13, %r15
je 0x3fbd
leaq 0x4(%rbx), %rsi
movl (%r12,%r13,8), %eax
xorl %edx, %edx
movq -0x30(%rbp), %rcx
btl %ecx, %eax
setb %dl
movq %rbx, %rdi
callq 0x41f1
incq %r13
addq $0x8, %rbx
jmp 0x3f93
movq -0x48(%rbp), %rax
leaq (,%rax,4), %r12
xorl %eax, %eax
movq -0x90(%rbp), %r14
movq %r14, %rdi
movl -0x34(%rbp), %ecx
movq -0x58(%rbp), %r8
movq -0x68(%rbp), %r10
cmpq $0x2, %rax
je 0x4007
xorl %edx, %edx
cmpq %rdx, %r15
je 0x3ffb
movl (%r10,%rdx,8), %esi
shrl %esi
movl %esi, (%rdi,%rdx,4)
incq %rdx
jmp 0x3fe8
incq %rax
addq %r12, %rdi
addq $0x4, %r10
jmp 0x3fe0
leal (%r8,%r8), %ebx
movq -0x48(%rbp), %rax
imull %r8d, %eax
addl %eax, %ecx
pushq $0x2
popq %r15
subq $0x1, %r15
jb 0x3d10
movl -0x40(%rbp), %edi
movq -0x48(%rbp), %rsi
movl %ebx, %edx
movq -0x78(%rbp), %r8
movq %r14, %r9
movl %ecx, %r13d
callq 0x3c3d
movl %r13d, %ecx
addl -0x58(%rbp), %ecx
addq %r12, %r14
jmp 0x4019