#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ c;

/* Variables and functions */
int /*<<< orphan*/ controlbitsfrompermutation(int, int, int, int /*<<< orphan*/,
                                              unsigned char *,
                                              int /*<<< orphan*/ *);
int /*<<< orphan*/ perm_gen(int /*<<< orphan*/ *);
void controlbits(unsigned char *out) {
  int i;
  uint32_t pi[(1 << 13)];
  unsigned char c[(2 * 13 - 1) * (1 << 13) / 16];
  perm_gen(pi);
  for (i = 0; i < sizeof(c); i++)
    c[i] = 0;
  controlbitsfrompermutation(13, (1 << 13), 1, 0, c, pi);
  for (i = 0; i < sizeof(c); i++)
    out[i] = c[i];
}


x86 assembly (clang, -O0):
<controlbits>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb210,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x8010(%rbp),%rdi
call   1030 <perm_gen@plt>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x3200,%rax
jae    116c <controlbits+0x4c>
movslq -0xc(%rbp),%rax
movb   $0x0,-0xb210(%rbp,%rax,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1142 <controlbits+0x22>
lea    -0xb210(%rbp),%r8
lea    -0x8010(%rbp),%r9
mov    $0xd,%edi
mov    $0x2000,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <controlbitsfrompermutation@plt>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x3200,%rax
jae    11cb <controlbits+0xab>
movslq -0xc(%rbp),%rax
mov    -0xb210(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1197 <controlbits+0x77>
add    $0xb210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<controlbits>:
push   %r15
push   %r14
push   %rbx
sub    $0xb200,%rsp
mov    %rdi,%r15
lea    0x3200(%rsp),%r14
mov    %r14,%rdi
call   1040 <perm_gen@plt>
mov    %rsp,%rbx
mov    $0x3200,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
mov    $0xd,%edi
mov    $0x2000,%esi
mov    $0x1,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
mov    %r14,%r9
call   1060 <controlbitsfrompermutation@plt>
mov    $0x3200,%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <memcpy@plt>
add    $0xb200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @controlbits(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [8192 x i32]
%5 = alloca [12800 x i8]
store i8* %0, i8** %2
%6 = getelementptr inbounds [8192 x i32], [8192 x i32]* %4, i64 0, i64 0
%7 = call i32 @perm_gen(i32* %6)
store i32 0, i32* %3
br label %8
8: ; preds = %16, %1
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = icmp ult i64 %10, 12800
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [12800 x i8], [12800 x i8]* %5, i64 0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %8
19: ; preds = %8
%20 = getelementptr inbounds [12800 x i8], [12800 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [8192 x i32], [8192 x i32]* %4, i64 0, i64 0
%22 = call i32 @controlbitsfrompermutation(i32 13, i32 8192, i32 1, i32 0, i8* %20, i32* %21)
store i32 0, i32* %3
br label %23
23: ; preds = %36, %19
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = icmp ult i64 %25, 12800
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i32, i32* %3
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [12800 x i8], [12800 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = load i8*, i8** %2
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
store i8 %31, i8* %35
br label %36
36: ; preds = %27
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %23
39: ; preds = %23
ret void
}

LLVM IR (-O2):
define void @controlbits(i8* nocapture writeonly %0) {
%2 = alloca [8192 x i32]
%3 = alloca [12800 x i8]
%4 = getelementptr inbounds [12800 x i8], [12800 x i8]* %3, i64 0, i64 0
%5 = bitcast [8192 x i32]* %2 to i8*
%6 = getelementptr inbounds [12800 x i8], [12800 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [8192 x i32], [8192 x i32]* %2, i64 0, i64 0
%8 = call i32 @perm_gen(i32* %7)
%9 = call i32 @controlbitsfrompermutation(i32 13, i32 8192, i32 1, i32 0, i8* %6, i32* %7)
ret void
}