void data_fill(unsigned char *data, unsigned pattern, unsigned alt) {
  int i;
  for (i = 0; i < 1024; ++i) {
    if (alt == ~0)
      data[i] = pattern++;
    else
      data[i] = (i & 1) ? alt : pattern;
  }
}


x86 assembly (clang, -O0):
<data_fill>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x400,-0x14(%rbp)
jge    118c <data_fill+0x8c>
cmpl   $0xffffffff,-0x10(%rbp)
jne    1149 <data_fill+0x49>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1179 <data_fill+0x79>
mov    -0x14(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1163 <data_fill+0x63>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1169 <data_fill+0x69>
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    117e <data_fill+0x7e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1115 <data_fill+0x15>
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_fill>:
sub    $0x68,%rsp
xor    %eax,%eax
cmp    $0xffffffff,%edx
sete   %al
movd   %esi,%xmm0
pshufd $0x0,%xmm0,%xmm1
movd   %eax,%xmm0
pshufd $0x0,%xmm0,%xmm0
movdqa 0xeda(%rip),%xmm4
pmaddwd %xmm0,%xmm4
movdqa 0xedd(%rip),%xmm13
pmaddwd %xmm0,%xmm13
movdqa 0xee0(%rip),%xmm2
pmaddwd %xmm0,%xmm2
movdqa 0xee4(%rip),%xmm3
pmaddwd %xmm0,%xmm3
paddd  %xmm1,%xmm3
movdqa %xmm3,-0x40(%rsp)
paddd  %xmm1,%xmm2
movdqa %xmm2,-0x30(%rsp)
paddd  %xmm1,%xmm13
paddd  %xmm1,%xmm4
movdqa %xmm4,-0x50(%rsp)
pslld  $0x4,%xmm0
movdqa %xmm0,-0x20(%rsp)
movd   %edx,%xmm1
pshufd $0x0,%xmm1,%xmm0
movdqa %xmm0,-0x10(%rsp)
movaps 0xeac(%rip),%xmm0
movaps %xmm0,-0x60(%rsp)
movdqa 0xeaf(%rip),%xmm0
movdqa %xmm0,-0x70(%rsp)
movdqa 0xeb0(%rip),%xmm10
movdqa 0xeb7(%rip),%xmm12
movdqa 0xebe(%rip),%xmm8
movdqa 0xec5(%rip),%xmm11
movdqa 0xecd(%rip),%xmm4
movdqa 0xed5(%rip),%xmm3
xor    %eax,%eax
jmp    1440 <data_fill+0x340>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movaps %xmm14,%xmm7
punpcklbw %xmm7,%xmm7
movdqa %xmm4,0x10(%rsp)
movdqa %xmm3,(%rsp)
movdqa %xmm7,%xmm15
punpcklwd %xmm15,%xmm15
pslld  $0x1f,%xmm15
psrad  $0x1f,%xmm15
movdqa -0x50(%rsp),%xmm3
movdqa %xmm3,%xmm1
pand   %xmm15,%xmm1
movdqa %xmm11,0x20(%rsp)
movdqa %xmm15,%xmm11
movdqa -0x10(%rsp),%xmm0
pandn  %xmm0,%xmm11
por    %xmm11,%xmm1
punpckhwd %xmm7,%xmm7
pslld  $0x1f,%xmm7
psrad  $0x1f,%xmm7
movdqa %xmm13,%xmm2
pand   %xmm7,%xmm2
punpckhbw %xmm14,%xmm14
movdqa %xmm10,0x50(%rsp)
movdqa %xmm12,0x40(%rsp)
movdqa %xmm8,0x30(%rsp)
movdqa %xmm13,-0x80(%rsp)
movdqa %xmm3,%xmm13
movdqa %xmm14,%xmm8
punpcklwd %xmm8,%xmm8
pslld  $0x1f,%xmm8
psrad  $0x1f,%xmm8
movdqa -0x30(%rsp),%xmm9
movdqa %xmm9,%xmm3
pand   %xmm8,%xmm3
movdqa %xmm8,%xmm12
pandn  %xmm0,%xmm12
por    %xmm12,%xmm3
punpckhwd %xmm14,%xmm14
pslld  $0x1f,%xmm14
psrad  $0x1f,%xmm14
movdqa -0x40(%rsp),%xmm6
movdqa %xmm6,%xmm4
pand   %xmm14,%xmm4
movdqa %xmm14,%xmm5
pandn  %xmm0,%xmm5
por    %xmm5,%xmm4
movdqa 0xe03(%rip),%xmm10
pand   %xmm10,%xmm4
pand   %xmm10,%xmm3
packuswb %xmm4,%xmm3
movdqa %xmm7,%xmm4
pandn  %xmm0,%xmm4
por    %xmm4,%xmm2
pand   %xmm10,%xmm2
pand   %xmm10,%xmm1
packuswb %xmm2,%xmm1
packuswb %xmm3,%xmm1
movdqu %xmm1,(%rdi,%rax,1)
movdqa -0x20(%rsp),%xmm0
paddd  %xmm0,%xmm13
pand   %xmm13,%xmm15
por    %xmm11,%xmm15
movdqa 0x20(%rsp),%xmm11
movdqa -0x80(%rsp),%xmm1
paddd  %xmm0,%xmm1
movdqa %xmm1,-0x80(%rsp)
pand   -0x80(%rsp),%xmm7
por    %xmm4,%xmm7
paddd  %xmm0,%xmm9
pand   %xmm9,%xmm8
por    %xmm12,%xmm8
paddd  %xmm0,%xmm6
pand   %xmm6,%xmm14
por    %xmm5,%xmm14
pand   %xmm10,%xmm14
pand   %xmm10,%xmm8
packuswb %xmm14,%xmm8
pand   %xmm10,%xmm7
pand   %xmm10,%xmm15
packuswb %xmm7,%xmm15
packuswb %xmm8,%xmm15
movdqa %xmm13,%xmm2
movdqa -0x80(%rsp),%xmm13
movdqa 0x30(%rsp),%xmm8
movdqa 0x40(%rsp),%xmm12
movdqa 0x50(%rsp),%xmm10
movdqu %xmm15,0x10(%rdi,%rax,1)
movdqa (%rsp),%xmm3
movdqa 0x10(%rsp),%xmm4
add    $0x20,%rax
movdqa 0xd2d(%rip),%xmm5
paddq  %xmm5,%xmm3
paddq  %xmm5,%xmm4
paddq  %xmm5,%xmm11
paddq  %xmm5,%xmm8
paddq  %xmm5,%xmm12
paddq  %xmm5,%xmm10
movdqa -0x70(%rsp),%xmm1
paddq  %xmm5,%xmm1
movdqa %xmm1,-0x70(%rsp)
movdqa -0x60(%rsp),%xmm1
paddq  %xmm5,%xmm1
movdqa %xmm1,-0x60(%rsp)
paddd  %xmm0,%xmm2
movdqa %xmm2,-0x50(%rsp)
paddd  %xmm0,%xmm13
paddd  %xmm0,%xmm9
movdqa %xmm9,-0x30(%rsp)
paddd  %xmm0,%xmm6
movdqa %xmm6,-0x40(%rsp)
cmp    $0x400,%rax
je     1578 <data_fill+0x478>
movaps 0xc98(%rip),%xmm14
cmp    $0xffffffff,%edx
je     11f0 <data_fill+0xf0>
movdqa -0x60(%rsp),%xmm7
movdqa 0xc60(%rip),%xmm9
pand   %xmm9,%xmm7
movdqa %xmm8,%xmm1
pand   %xmm9,%xmm1
movdqa %xmm4,%xmm2
pand   %xmm9,%xmm2
movdqa %xmm3,%xmm14
pand   %xmm9,%xmm14
pxor   %xmm6,%xmm6
pcmpeqd %xmm6,%xmm14
pshufd $0xb1,%xmm14,%xmm5
movdqa 0xc37(%rip),%xmm0
pand   %xmm0,%xmm14
pand   %xmm5,%xmm14
pcmpeqd %xmm6,%xmm2
pshufd $0xb1,%xmm2,%xmm5
pand   %xmm0,%xmm2
pand   %xmm5,%xmm2
movdqa %xmm11,%xmm5
pand   %xmm9,%xmm5
packuswb %xmm2,%xmm14
pcmpeqd %xmm6,%xmm5
pshufd $0xb1,%xmm5,%xmm2
pand   %xmm0,%xmm5
pand   %xmm2,%xmm5
pcmpeqd %xmm6,%xmm1
pshufd $0xb1,%xmm1,%xmm2
pand   %xmm0,%xmm1
pand   %xmm2,%xmm1
movdqa %xmm10,%xmm2
pand   %xmm9,%xmm2
packuswb %xmm1,%xmm5
movdqa %xmm12,%xmm1
pand   %xmm9,%xmm1
packuswb %xmm14,%xmm14
packuswb %xmm5,%xmm5
packuswb %xmm5,%xmm14
pcmpeqd %xmm6,%xmm1
pshufd $0xb1,%xmm1,%xmm5
pand   %xmm0,%xmm1
pand   %xmm5,%xmm1
pcmpeqd %xmm6,%xmm2
pshufd $0xb1,%xmm2,%xmm5
pand   %xmm0,%xmm2
pand   %xmm5,%xmm2
movdqa -0x70(%rsp),%xmm5
pand   %xmm9,%xmm5
packuswb %xmm2,%xmm1
pcmpeqd %xmm6,%xmm5
pshufd $0xb1,%xmm5,%xmm2
pand   %xmm0,%xmm5
pand   %xmm2,%xmm5
pcmpeqd %xmm6,%xmm7
pshufd $0xb1,%xmm7,%xmm2
pand   %xmm0,%xmm7
pand   %xmm2,%xmm7
packuswb %xmm7,%xmm5
packuswb %xmm1,%xmm1
packuswb %xmm5,%xmm2
packuswb %xmm2,%xmm1
shufps $0xcc,%xmm1,%xmm14
jmp    11f0 <data_fill+0xf0>
add    $0x68,%rsp
ret

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

LLVM IR (-O2):
define void @data_fill(i8* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, -1
%5 = zext i1 %4 to i32
%6 = insertelement <16 x i32> poison, i32 %1, i64 0
%7 = shufflevector <16 x i32> %6, <16 x i32> poison, <16 x i32> zeroinitializer
%8 = insertelement <16 x i32> poison, i32 %5, i64 0
%9 = shufflevector <16 x i32> %8, <16 x i32> poison, <16 x i32> zeroinitializer
%10 = mul nuw nsw <16 x i32> %9, <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
%11 = add <16 x i32> %7, %10
%12 = select i1 %4, i32 16, i32 0
%13 = insertelement <16 x i32> poison, i32 %12, i64 0
%14 = shufflevector <16 x i32> %13, <16 x i32> poison, <16 x i32> zeroinitializer
%15 = insertelement <16 x i32> poison, i32 %2, i64 0
%16 = shufflevector <16 x i32> %15, <16 x i32> poison, <16 x i32> zeroinitializer
br label %17
17: ; preds = %17, %3
%18 = phi i64 [ 0, %3 ], [ %37, %17 ]
%19 = phi <16 x i64> [ <i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9, i64 10, i64 11, i64 12, i64 13, i64 14, i64 15>, %3 ], [ %38, %17 ]
%20 = phi <16 x i32> [ %11, %3 ], [ %39, %17 ]
%21 = and <16 x i64> %19, <i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1>
%22 = icmp eq <16 x i64> %21, zeroinitializer
%23 = select i1 %4, <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <16 x i1> %22
%24 = select <16 x i1> %23, <16 x i32> %20, <16 x i32> %16
%25 = trunc <16 x i32> %24 to <16 x i8>
%26 = getelementptr inbounds i8, i8* %0, i64 %18
%27 = bitcast i8* %26 to <16 x i8>*
store <16 x i8> %25, <16 x i8>* %27
%28 = or i64 %18, 16
%29 = add <16 x i32> %20, %14
%30 = and <16 x i64> %19, <i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1, i64 1>
%31 = icmp eq <16 x i64> %30, zeroinitializer
%32 = select i1 %4, <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <16 x i1> %31
%33 = select <16 x i1> %32, <16 x i32> %29, <16 x i32> %16
%34 = trunc <16 x i32> %33 to <16 x i8>
%35 = getelementptr inbounds i8, i8* %0, i64 %28
%36 = bitcast i8* %35 to <16 x i8>*
store <16 x i8> %34, <16 x i8>* %36
%37 = add nuw nsw i64 %18, 32
%38 = add <16 x i64> %19, <i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32, i64 32>
%39 = add <16 x i32> %29, %14
%40 = icmp eq i64 %37, 1024
br i1 %40, label %41, label %17
41: ; preds = %17
ret void
}