#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
void scatter(unsigned char chunk[(255 * 4096)],
             const unsigned char encoded[255], unsigned idx) {
  assert(idx < 4096);
  for (unsigned i = 0; i < 255; ++i) {
    chunk[4096 * i + idx] = encoded[i];
  }
}


x86 assembly (clang, -O0):
<scatter>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1000,-0x14(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xff,-0x18(%rbp)
jae    1175 <scatter+0x65>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0xc,%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <scatter+0x2e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scatter>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
cmp    $0x1000,%edx
setb   %dil
call   1030 <assert@plt>
xor    %eax,%eax
movzbl (%r14,%rax,1),%ecx
mov    %ebx,%edx
mov    %cl,(%r15,%rdx,1)
movzbl 0x1(%r14,%rax,1),%ecx
lea    0x1000(%rbx),%edx
mov    %cl,(%r15,%rdx,1)
movzbl 0x2(%r14,%rax,1),%ecx
lea    0x2000(%rbx),%edx
mov    %cl,(%r15,%rdx,1)
add    $0x3,%rax
add    $0x3000,%ebx
cmp    $0xff,%rax
jne    1130 <scatter+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @scatter(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp ult i32 %8, 4096
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
store i32 0, i32* %7
br label %12
12: ; preds = %28, %3
%13 = load i32, i32* %7
%14 = icmp ult i32 %13, 255
br i1 %14, label %15, label %31
15: ; preds = %12
%16 = load i8*, i8** %5
%17 = load i32, i32* %7
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = mul i32 4096, %22
%24 = load i32, i32* %6
%25 = add i32 %23, %24
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %21, i64 %26
store i8 %20, i8* %27
br label %28
28: ; preds = %15
%29 = load i32, i32* %7
%30 = add i32 %29, 1
store i32 %30, i32* %7
br label %12
31: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @scatter(i8* nocapture writeonly %0, i8* nocapture %1, i32 %2) {
%4 = icmp ult i32 %2, 4096
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
br label %8
7: ; preds = %8
ret void
8: ; preds = %8, %3
%9 = phi i64 [ 0, %3 ], [ %33, %8 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %9
%11 = load i8, i8* %10
%12 = trunc i64 %9 to i32
%13 = shl i32 %12, 12
%14 = add i32 %13, %2
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 %11, i8* %16
%17 = add nuw nsw i64 %9, 1
%18 = getelementptr inbounds i8, i8* %1, i64 %17
%19 = load i8, i8* %18
%20 = trunc i64 %17 to i32
%21 = shl i32 %20, 12
%22 = add i32 %21, %2
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 %19, i8* %24
%25 = add nuw nsw i64 %9, 2
%26 = getelementptr inbounds i8, i8* %1, i64 %25
%27 = load i8, i8* %26
%28 = trunc i64 %25 to i32
%29 = shl i32 %28, 12
%30 = add i32 %29, %2
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
store i8 %27, i8* %32
%33 = add nuw nsw i64 %9, 3
%34 = icmp eq i64 %33, 255
br i1 %34, label %7, label %8
}