#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 uint8_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
void _interleave(uint8_t d[(2048 / 8)]) {
  uint8_t tmp[(2048 / 8) - 4];
  int x, y;
  memset(tmp, 0, (2048 / 8) - 4);
  d += 4;
  for (x = y = 0; x < 2048 - 32; x++) {
    if ((d[y >> 3] >> (7 - (y & 7))) & 1)
      tmp[x >> 3] |= 1 << (7 - (x & 7));
    if ((y += 63) >= 2016)
      y -= 2015;
  }
  memcpy(d, tmp, (2048 / 8) - 4);
}


x86 assembly (clang, -O0):
<_interleave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x400(%rbp),%rdi
xor    %esi,%esi
mov    $0xfc,%edx
call   1030 <memset@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0x408(%rbp)
movl   $0x0,-0x404(%rbp)
cmpl   $0x7e0,-0x404(%rbp)
jge    1219 <_interleave+0xf9>
mov    -0x8(%rbp),%rax
mov    -0x408(%rbp),%ecx
sar    $0x3,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x408(%rbp),%edx
and    $0x7,%edx
mov    $0x7,%ecx
sub    %edx,%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11d5 <_interleave+0xb5>
mov    -0x404(%rbp),%eax
and    $0x7,%eax
mov    $0x7,%ecx
sub    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x404(%rbp),%eax
sar    $0x3,%eax
cltq
or     -0x400(%rbp,%rax,4),%ecx
mov    %ecx,-0x400(%rbp,%rax,4)
mov    -0x408(%rbp),%eax
add    $0x3f,%eax
mov    %eax,-0x408(%rbp)
cmp    $0x7e0,%eax
jl     1200 <_interleave+0xe0>
mov    -0x408(%rbp),%eax
sub    $0x7df,%eax
mov    %eax,-0x408(%rbp)
jmp    1205 <_interleave+0xe5>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    1162 <_interleave+0x42>
mov    -0x8(%rbp),%rdi
lea    -0x400(%rbp),%rsi
mov    $0xfc,%edx
call   1040 <memcpy@plt>
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_interleave>:
push   %r14
push   %rbx
sub    $0x3f8,%rsp
mov    %rdi,%r14
mov    %rsp,%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xfc,%edx
call   1030 <memset@plt>
add    $0x10,%r14
xor    %eax,%eax
jmp    116e <_interleave+0x4e>
cs nopw 0x0(%rax,%rax,1)
lea    0x3f(%rbx),%ecx
cmp    $0x7a1,%ebx
lea    -0x7a0(%rbx),%edx
cmovl  %ecx,%edx
add    $0x1,%eax
mov    %edx,%ebx
cmp    $0x7e0,%eax
je     11a1 <_interleave+0x81>
mov    %ebx,%ecx
sar    $0x3,%ecx
movslq %ecx,%rcx
mov    (%r14,%rcx,4),%ecx
mov    %ebx,%edx
not    %dl
and    $0x7,%dl
movzbl %dl,%edx
bt     %edx,%ecx
jae    1150 <_interleave+0x30>
mov    %eax,%ecx
not    %cl
and    $0x7,%cl
mov    $0x1,%edx
shl    %cl,%edx
mov    %eax,%ecx
shr    $0x3,%ecx
or     %edx,(%rsp,%rcx,4)
jmp    1150 <_interleave+0x30>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0xfc,%edx
call   1040 <memcpy@plt>
add    $0x3f8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @_interleave(i32* %0) {
%2 = alloca i32*
%3 = alloca [252 x i32]
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %2
%6 = getelementptr inbounds [252 x i32], [252 x i32]* %3, i64 0, i64 0
%7 = call i32 @memset(i32* %6, i32 0, i32 252)
%8 = load i32*, i32** %2
%9 = getelementptr inbounds i32, i32* %8, i64 4
store i32* %9, i32** %2
store i32 0, i32* %5
store i32 0, i32* %4
br label %10
10: ; preds = %45, %1
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2016
br i1 %12, label %13, label %48
13: ; preds = %10
%14 = load i32*, i32** %2
%15 = load i32, i32* %5
%16 = ashr i32 %15, 3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i32, i32* %14, i64 %17
%19 = load i32, i32* %18
%20 = load i32, i32* %5
%21 = and i32 %20, 7
%22 = sub nsw i32 7, %21
%23 = ashr i32 %19, %22
%24 = and i32 %23, 1
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %37
26: ; preds = %13
%27 = load i32, i32* %4
%28 = and i32 %27, 7
%29 = sub nsw i32 7, %28
%30 = shl i32 1, %29
%31 = load i32, i32* %4
%32 = ashr i32 %31, 3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [252 x i32], [252 x i32]* %3, i64 0, i64 %33
%35 = load i32, i32* %34
%36 = or i32 %35, %30
store i32 %36, i32* %34
br label %37
37: ; preds = %26, %13
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 63
store i32 %39, i32* %5
%40 = icmp sge i32 %39, 2016
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %5
%43 = sub nsw i32 %42, 2015
store i32 %43, i32* %5
br label %44
44: ; preds = %41, %37
br label %45
45: ; preds = %44
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %10
48: ; preds = %10
%49 = load i32*, i32** %2
%50 = getelementptr inbounds [252 x i32], [252 x i32]* %3, i64 0, i64 0
%51 = call i32 @memcpy(i32* %49, i32* %50, i32 252)
ret void
}

LLVM IR (-O2):
define void @_interleave(i32* %0) {
%2 = alloca [252 x i32]
%3 = bitcast [252 x i32]* %2 to i8*
%4 = getelementptr inbounds [252 x i32], [252 x i32]* %2, i64 0, i64 0
%5 = call i32 @memset(i32* %4, i32 0, i32 252)
%6 = getelementptr inbounds i32, i32* %0, i64 4
br label %7
7: ; preds = %1, %28
%8 = phi i32 [ 0, %1 ], [ %31, %28 ]
%9 = phi i32 [ 0, %1 ], [ %32, %28 ]
%10 = ashr i32 %8, 3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %6, i64 %11
%13 = load i32, i32* %12
%14 = and i32 %8, 7
%15 = xor i32 %14, 7
%16 = shl nuw i32 1, %15
%17 = and i32 %13, %16
%18 = icmp eq i32 %17, 0
br i1 %18, label %28, label %19
19: ; preds = %7
%20 = and i32 %9, 7
%21 = xor i32 %20, 7
%22 = shl nuw i32 1, %21
%23 = lshr i32 %9, 3
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [252 x i32], [252 x i32]* %2, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = or i32 %26, %22
store i32 %27, i32* %25
br label %28
28: ; preds = %19, %7
%29 = icmp sgt i32 %8, 1952
%30 = select i1 %29, i32 -1952, i32 63
%31 = add nsw i32 %30, %8
%32 = add nuw nsw i32 %9, 1
%33 = icmp eq i32 %32, 2016
br i1 %33, label %34, label %7
34: ; preds = %28
%35 = call i32 @memcpy(i32* %6, i32* %4, i32 252)
ret void
}