// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %r8, -0x60(%rbp)
movl %ecx, %r12d
movl %esi, %r8d
movl %esi, %r13d
movq %rsp, %rcx
leaq 0xf(,%r13,4), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
leal (%r8,%r8), %ecx
movq %rsp, %r11
movq %rcx, -0x30(%rbp)
leaq 0xf(,%rcx,4), %rcx
andq $-0x10, %rcx
subq %rcx, %r11
movq %r11, %rsp
movq %rsp, %r15
subq %rcx, %r15
movq %r15, %rsp
movq %rsp, %rsi
subq %rcx, %rsi
movq %rsi, -0x80(%rbp)
movq %rsi, %rsp
movq %rsp, %rbx
subq %rcx, %rbx
movq %rbx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x98(%rbp)
movq %rcx, %rsp
movl %r8d, %esi
shrl $0x1f, %esi
addl %r8d, %esi
sarl %esi
leaq 0xf(,%rsi,8), %rax
andq $-0x10, %rax
movq %rsp, %r10
subq %rax, %r10
movq %r10, %rsp
cmpl $0x1, %edi
jne 0x3d83
movl (%r9), %eax
andl $0x1, %eax
movl %r12d, %ecx
andb $0x7, %cl
shll %cl, %eax
leal 0x7(%r12), %ecx
testl %r12d, %r12d
cmovnsl %r12d, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
movq -0x60(%rbp), %r14
orb %al, (%r14,%rcx)
cmpl $0x2, %edi
jl 0x412e
movq %r11, -0x68(%rbp)
movq %r10, -0x88(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdi, -0x70(%rbp)
movq %rdx, -0x58(%rbp)
testl %r8d, %r8d
movq -0x38(%rbp), %rdx
jle 0x3db9
xorl %eax, %eax
movl %eax, (%rdx,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x3dae
movl %r8d, %edi
movq %rdx, %rsi
movq %r9, %rcx
movq %r8, -0x40(%rbp)
movq %r9, -0x78(%rbp)
callq 0x4247
movq -0x38(%rbp), %r14
movq -0x78(%rbp), %r9
movq -0x40(%rbp), %r8
testl %r8d, %r8d
movq -0x70(%rbp), %rcx
movq -0x68(%rbp), %r11
jle 0x3e0e
movl $0x1, %eax
shll %cl, %eax
leaq (%r11,%r13,4), %rdi
xorl %edx, %edx
movl (%r14,%rdx,4), %esi
orl %eax, %esi
movl %esi, (%r11,%rdx,4)
movl (%r9,%rdx,4), %esi
movl %esi, (%rdi,%rdx,4)
incq %rdx
cmpq %rdx, %r13
jne 0x3df5
movq %r13, -0x48(%rbp)
movq %r12, -0x90(%rbp)
testl %r8d, %r8d
jle 0x3e5c
movl $0x1, %eax
movl $0x1, %edx
shll %cl, %edx
addl $-0x2, %edx
movq -0x30(%rbp), %rsi
cmpl $0x2, %esi
cmovgel %esi, %eax
xorl %esi, %esi
movl %esi, %edi
shrl %cl, %edi
movl %edx, %r8d
andl %esi, %r8d
addl %edi, %r8d
movl %esi, %edi
andl $0x1, %edi
shll %cl, %edi
addl %r8d, %edi
movl %edi, (%r15,%rsi,4)
incq %rsi
cmpq %rsi, %rax
jne 0x3e39
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
shll %cl, %r14d
notl %r14d
movq -0x30(%rbp), %rax
cmpl $0x2, %eax
movl $0x1, %edx
movl $0x1, %r13d
cmovgel %eax, %r13d
cmpl $0x2, %ecx
cmovgel %ecx, %edx
movl %edx, -0x38(%rbp)
xorl %r12d, %r12d
movq -0x30(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq %r15, %rdx
movq %r11, %rcx
callq 0x4247
movq -0x80(%rbp), %r11
movq -0x70(%rbp), %rcx
movq -0x40(%rbp), %r10
testl %r10d, %r10d
jle 0x3eeb
xorl %eax, %eax
testl %r12d, %r12d
setne %r9b
movl (%r11,%rax,4), %edx
movl %edx, %esi
andl %r14d, %esi
movl (%r15,%rax,4), %edi
movl %edi, %r8d
andl %r14d, %r8d
cmpl %r8d, %esi
setb %sil
cmovbl %edx, %edi
andb %r9b, %sil
movzbl %sil, %edx
shll %cl, %edx
xorl %edi, %edx
movl %edx, (%r15,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x3eb0
testl %r10d, %r10d
movq -0x68(%rbp), %rdx
jle 0x3f0b
xorl %eax, %eax
movq %rax, %rcx
xorq $0x1, %rcx
movl (%rdx,%rcx,4), %ecx
movl %ecx, (%rbx,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x3ef6
movq -0x30(%rbp), %rdi
movq %rdx, %rsi
movq %rbx, %rcx
callq 0x4247
movq -0x40(%rbp), %rdx
testl %edx, %edx
jle 0x3f3a
xorl %eax, %eax
movq %rax, %rcx
xorq $0x1, %rcx
movl (%r15,%rcx,4), %ecx
movl %ecx, (%rbx,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x3f24
testl %edx, %edx
movq -0x70(%rbp), %r10
jle 0x3f76
xorl %eax, %eax
movl (%rbx,%rax,4), %ecx
movl %ecx, %edx
andl %r14d, %edx
movl (%r15,%rax,4), %esi
movl %esi, %edi
andl %r14d, %edi
xorl %r8d, %r8d
cmpl %edi, %edx
setb %r8b
cmovbl %ecx, %esi
movl %r10d, %ecx
shll %cl, %r8d
xorl %esi, %r8d
movl %r8d, (%r15,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x3f44
incl %r12d
cmpl -0x38(%rbp), %r12d
movq -0x68(%rbp), %r11
jne 0x3e8a
movq -0x40(%rbp), %r11
testl %r11d, %r11d
movq -0x58(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x98(%rbp), %r12
movq -0x48(%rbp), %rsi
movq -0x78(%rbp), %rdi
jle 0x3fb8
xorl %eax, %eax
movl (%rdi,%rax,4), %ecx
movl %ecx, (%r12,%rax,4)
incq %rax
cmpq %rax, %rsi
jne 0x3fa9
movl %edx, %r14d
cmpl $0x2, %r11d
movq -0x60(%rbp), %r9
movq -0x90(%rbp), %r13
jl 0x4003
xorl %eax, %eax
movl %r13d, %edx
movl (%r15,%rax,8), %ecx
xorl %esi, %esi
btl %r10d, %ecx
setb %sil
movl %edx, %ecx
andb $0x7, %cl
shll %cl, %esi
leal 0x7(%rdx), %ecx
testl %edx, %edx
cmovnsl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
orb %sil, (%r9,%rcx)
incq %rax
addl %r8d, %edx
cmpq %rax, %r14
jne 0x3fd1
cmpl $0x2, %r11d
jl 0x4055
leal -0x1(%r10), %ecx
movq -0x48(%rbp), %rax
leaq (%r15,%rax,4), %rax
movl %r8d, %edx
imull %r11d, %edx
imull %ecx, %edx
addl %r13d, %edx
xorl %esi, %esi
movl (%rax,%rsi,8), %ecx
xorl %edi, %edi
btl %r10d, %ecx
setb %dil
movl %edx, %ecx
andb $0x7, %cl
shll %cl, %edi
leal 0x7(%rdx), %ecx
testl %edx, %edx
cmovnsl %edx, %ecx
sarl $0x3, %ecx
movslq %ecx, %rcx
orb %dil, (%r9,%rcx)
incq %rsi
addl %r8d, %edx
cmpq %rsi, %r14
jne 0x4024
cmpl $0x2, %r11d
jl 0x40a0
movl $0x1, %eax
movl %r10d, %ecx
shll %cl, %eax
movq -0x48(%rbp), %rcx
leaq (%r15,%rcx,4), %rcx
xorl %edx, %edx
movl (%r12,%rdx,8), %esi
movl 0x4(%r12,%rdx,8), %edi
movl %edi, %r8d
xorl %esi, %r8d
movl (%rcx,%rdx,8), %r9d
andl %eax, %r9d
cmovnel %r8d, %r9d
xorl %r9d, %esi
movl %esi, (%r12,%rdx,8)
xorl %edi, %r9d
movl %r9d, 0x4(%r12,%rdx,8)
incq %rdx
cmpq %rdx, %r14
jne 0x406f
leaq (,%r14,4), %rax
xorl %edx, %edx
movq -0x88(%rbp), %rbx
movq %rbx, %rcx
movq -0x58(%rbp), %r8
cmpl $0x2, %r11d
jl 0x40d1
xorl %esi, %esi
movl (%r12,%rsi,8), %edi
shrl %edi
movl %edi, (%rcx,%rsi,4)
incq %rsi
cmpq %rsi, %r14
jne 0x40c0
leaq 0x1(%rdx), %rsi
addq $0x4, %r12
addq %rax, %rcx
testq %rdx, %rdx
movq %rsi, %rdx
je 0x40b8
decl %r10d
leal (%r8,%r8), %eax
movl %eax, -0x30(%rbp)
movq -0x50(%rbp), %rax
imull %r8d, %eax
addl %eax, %r13d
shlq $0x2, %r14
movl $0x1, %r15d
movl %r10d, %edi
movq -0x50(%rbp), %rsi
movl -0x30(%rbp), %edx
movl %r13d, %ecx
movq -0x60(%rbp), %r8
movq %rbx, %r9
movq %r10, %r12
callq 0x3cb3
movq %r12, %r10
addl -0x58(%rbp), %r13d
addq %r14, %rbx
decq %r15
je 0x4103
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq