#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 gather(const unsigned char chunk[(255 * 4096)], unsigned char encoded[255],
            unsigned idx) {
  assert(idx < 4096);
  for (unsigned i = 0; i < 255; ++i) {
    encoded[i] = chunk[4096 * i + idx];
  }
}


x86 assembly (clang, -O0):
<gather>:
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 <gather+0x65>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
shl    $0xc,%ecx
add    -0x14(%rbp),%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113e <gather+0x2e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gather>:
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
mov    %ebx,%ecx
movzbl (%r15,%rcx,1),%ecx
mov    %cl,(%r14,%rax,1)
lea    0x1000(%rbx),%ecx
movzbl (%r15,%rcx,1),%ecx
mov    %cl,0x1(%r14,%rax,1)
lea    0x2000(%rbx),%ecx
movzbl (%r15,%rcx,1),%ecx
mov    %cl,0x2(%r14,%rax,1)
add    $0x3,%rax
add    $0x3000,%ebx
cmp    $0xff,%rax
jne    1130 <gather+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @gather(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** %4
%17 = load i32, i32* %7
%18 = mul i32 4096, %17
%19 = load i32, i32* %6
%20 = add i32 %18, %19
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %16, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %5
%25 = load i32, i32* %7
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 %23, 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 @gather(i8* nocapture %0, i8* nocapture writeonly %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 = trunc i64 %9 to i32
%11 = shl i32 %10, 12
%12 = add i32 %11, %2
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %15, i8* %16
%17 = add nuw nsw i64 %9, 1
%18 = trunc i64 %17 to i32
%19 = shl i32 %18, 12
%20 = add i32 %19, %2
%21 = zext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %0, i64 %21
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %1, i64 %17
store i8 %23, i8* %24
%25 = add nuw nsw i64 %9, 2
%26 = trunc i64 %25 to i32
%27 = shl i32 %26, 12
%28 = add i32 %27, %2
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
%31 = load i8, i8* %30
%32 = getelementptr inbounds i8, i8* %1, i64 %25
store i8 %31, i8* %32
%33 = add nuw nsw i64 %9, 3
%34 = icmp eq i64 %33, 255
br i1 %34, label %7, label %8
}