void init_gray_array(unsigned char *gray_begin) {
  int i;
  gray_begin[0] = 0;
  for (i = 1; i < 256; i++) {
    gray_begin[i] = gray_begin[i - 1] + 1;
  }
  return;
}


x86 assembly (clang, -O0):
<init_gray_array>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0xc(%rbp)
cmpl   $0x100,-0xc(%rbp)
jge    1152 <init_gray_array+0x52>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
add    $0x1,%eax
mov    %al,%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    1116 <init_gray_array+0x16>
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_gray_array>:
movb   $0x0,(%rdi)
movaps 0xef6(%rip),%xmm0
movups %xmm0,0x1(%rdi)
movaps 0xefb(%rip),%xmm0
movups %xmm0,0x11(%rdi)
movaps 0xf00(%rip),%xmm0
movups %xmm0,0x21(%rdi)
movaps 0xf05(%rip),%xmm0
movups %xmm0,0x31(%rdi)
movaps 0xf0a(%rip),%xmm0
movups %xmm0,0x41(%rdi)
movaps 0xf0f(%rip),%xmm0
movups %xmm0,0x51(%rdi)
movaps 0xf14(%rip),%xmm0
movups %xmm0,0x61(%rdi)
movaps 0xf19(%rip),%xmm0
movups %xmm0,0x71(%rdi)
movaps 0xf1e(%rip),%xmm0
movups %xmm0,0x81(%rdi)
movaps 0xf20(%rip),%xmm0
movups %xmm0,0x91(%rdi)
movaps 0xf22(%rip),%xmm0
movups %xmm0,0xa1(%rdi)
movaps 0xf24(%rip),%xmm0
movups %xmm0,0xb1(%rdi)
movaps 0xf26(%rip),%xmm0
movups %xmm0,0xc1(%rdi)
movaps 0xf28(%rip),%xmm0
movups %xmm0,0xd1(%rdi)
movaps 0xf2a(%rip),%xmm0
movups %xmm0,0xe1(%rdi)
movabs $0xf8f7f6f5f4f3f2f1,%rax
f6 f7 f8
mov    %rax,0xf1(%rdi)
movl   $0xfcfbfaf9,0xf9(%rdi)
fa fb fc
movw   $0xfefd,0xfd(%rdi)
fd fe
movb   $0xff,0xff(%rdi)
ret

LLVM IR (-O0):
define void @init_gray_array(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
store i8 0, i8* %5
store i32 1, i32* %3
br label %6
6: ; preds = %23, %1
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 256
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load i8*, i8** %2
%11 = load i32, i32* %3
%12 = sub nsw i32 %11, 1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %10, i64 %13
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = add nsw i32 %16, 1
%18 = trunc i32 %17 to i8
%19 = load i8*, i8** %2
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
store i8 %18, i8* %22
br label %23
23: ; preds = %9
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %6
26: ; preds = %6
ret void
}

LLVM IR (-O2):
define void @init_gray_array(i8* nocapture %0) {
store i8 0, i8* %0
%2 = getelementptr inbounds i8, i8* %0, i64 1
%3 = bitcast i8* %2 to <16 x i8>*
store <16 x i8> <i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15, i8 16>, <16 x i8>* %3
%4 = getelementptr inbounds i8, i8* %0, i64 17
%5 = bitcast i8* %4 to <16 x i8>*
store <16 x i8> <i8 17, i8 18, i8 19, i8 20, i8 21, i8 22, i8 23, i8 24, i8 25, i8 26, i8 27, i8 28, i8 29, i8 30, i8 31, i8 32>, <16 x i8>* %5
%6 = getelementptr inbounds i8, i8* %0, i64 33
%7 = bitcast i8* %6 to <16 x i8>*
store <16 x i8> <i8 33, i8 34, i8 35, i8 36, i8 37, i8 38, i8 39, i8 40, i8 41, i8 42, i8 43, i8 44, i8 45, i8 46, i8 47, i8 48>, <16 x i8>* %7
%8 = getelementptr inbounds i8, i8* %0, i64 49
%9 = bitcast i8* %8 to <16 x i8>*
store <16 x i8> <i8 49, i8 50, i8 51, i8 52, i8 53, i8 54, i8 55, i8 56, i8 57, i8 58, i8 59, i8 60, i8 61, i8 62, i8 63, i8 64>, <16 x i8>* %9
%10 = getelementptr inbounds i8, i8* %0, i64 65
%11 = bitcast i8* %10 to <16 x i8>*
store <16 x i8> <i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79, i8 80>, <16 x i8>* %11
%12 = getelementptr inbounds i8, i8* %0, i64 81
%13 = bitcast i8* %12 to <16 x i8>*
store <16 x i8> <i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 91, i8 92, i8 93, i8 94, i8 95, i8 96>, <16 x i8>* %13
%14 = getelementptr inbounds i8, i8* %0, i64 97
%15 = bitcast i8* %14 to <16 x i8>*
store <16 x i8> <i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111, i8 112>, <16 x i8>* %15
%16 = getelementptr inbounds i8, i8* %0, i64 113
%17 = bitcast i8* %16 to <16 x i8>*
store <16 x i8> <i8 113, i8 114, i8 115, i8 116, i8 117, i8 118, i8 119, i8 120, i8 121, i8 122, i8 123, i8 124, i8 125, i8 126, i8 127, i8 -128>, <16 x i8>* %17
%18 = getelementptr inbounds i8, i8* %0, i64 129
%19 = bitcast i8* %18 to <16 x i8>*
store <16 x i8> <i8 -127, i8 -126, i8 -125, i8 -124, i8 -123, i8 -122, i8 -121, i8 -120, i8 -119, i8 -118, i8 -117, i8 -116, i8 -115, i8 -114, i8 -113, i8 -112>, <16 x i8>* %19
%20 = getelementptr inbounds i8, i8* %0, i64 145
%21 = bitcast i8* %20 to <16 x i8>*
store <16 x i8> <i8 -111, i8 -110, i8 -109, i8 -108, i8 -107, i8 -106, i8 -105, i8 -104, i8 -103, i8 -102, i8 -101, i8 -100, i8 -99, i8 -98, i8 -97, i8 -96>, <16 x i8>* %21
%22 = getelementptr inbounds i8, i8* %0, i64 161
%23 = bitcast i8* %22 to <16 x i8>*
store <16 x i8> <i8 -95, i8 -94, i8 -93, i8 -92, i8 -91, i8 -90, i8 -89, i8 -88, i8 -87, i8 -86, i8 -85, i8 -84, i8 -83, i8 -82, i8 -81, i8 -80>, <16 x i8>* %23
%24 = getelementptr inbounds i8, i8* %0, i64 177
%25 = bitcast i8* %24 to <16 x i8>*
store <16 x i8> <i8 -79, i8 -78, i8 -77, i8 -76, i8 -75, i8 -74, i8 -73, i8 -72, i8 -71, i8 -70, i8 -69, i8 -68, i8 -67, i8 -66, i8 -65, i8 -64>, <16 x i8>* %25
%26 = getelementptr inbounds i8, i8* %0, i64 193
%27 = bitcast i8* %26 to <16 x i8>*
store <16 x i8> <i8 -63, i8 -62, i8 -61, i8 -60, i8 -59, i8 -58, i8 -57, i8 -56, i8 -55, i8 -54, i8 -53, i8 -52, i8 -51, i8 -50, i8 -49, i8 -48>, <16 x i8>* %27
%28 = getelementptr inbounds i8, i8* %0, i64 209
%29 = bitcast i8* %28 to <16 x i8>*
store <16 x i8> <i8 -47, i8 -46, i8 -45, i8 -44, i8 -43, i8 -42, i8 -41, i8 -40, i8 -39, i8 -38, i8 -37, i8 -36, i8 -35, i8 -34, i8 -33, i8 -32>, <16 x i8>* %29
%30 = getelementptr inbounds i8, i8* %0, i64 225
store i8 -31, i8* %30
%31 = getelementptr inbounds i8, i8* %0, i64 226
store i8 -30, i8* %31
%32 = getelementptr inbounds i8, i8* %0, i64 227
store i8 -29, i8* %32
%33 = getelementptr inbounds i8, i8* %0, i64 228
store i8 -28, i8* %33
%34 = getelementptr inbounds i8, i8* %0, i64 229
store i8 -27, i8* %34
%35 = getelementptr inbounds i8, i8* %0, i64 230
store i8 -26, i8* %35
%36 = getelementptr inbounds i8, i8* %0, i64 231
store i8 -25, i8* %36
%37 = getelementptr inbounds i8, i8* %0, i64 232
store i8 -24, i8* %37
%38 = getelementptr inbounds i8, i8* %0, i64 233
store i8 -23, i8* %38
%39 = getelementptr inbounds i8, i8* %0, i64 234
store i8 -22, i8* %39
%40 = getelementptr inbounds i8, i8* %0, i64 235
store i8 -21, i8* %40
%41 = getelementptr inbounds i8, i8* %0, i64 236
store i8 -20, i8* %41
%42 = getelementptr inbounds i8, i8* %0, i64 237
store i8 -19, i8* %42
%43 = getelementptr inbounds i8, i8* %0, i64 238
store i8 -18, i8* %43
%44 = getelementptr inbounds i8, i8* %0, i64 239
store i8 -17, i8* %44
%45 = getelementptr inbounds i8, i8* %0, i64 240
store i8 -16, i8* %45
%46 = getelementptr inbounds i8, i8* %0, i64 241
store i8 -15, i8* %46
%47 = getelementptr inbounds i8, i8* %0, i64 242
store i8 -14, i8* %47
%48 = getelementptr inbounds i8, i8* %0, i64 243
store i8 -13, i8* %48
%49 = getelementptr inbounds i8, i8* %0, i64 244
store i8 -12, i8* %49
%50 = getelementptr inbounds i8, i8* %0, i64 245
store i8 -11, i8* %50
%51 = getelementptr inbounds i8, i8* %0, i64 246
store i8 -10, i8* %51
%52 = getelementptr inbounds i8, i8* %0, i64 247
store i8 -9, i8* %52
%53 = getelementptr inbounds i8, i8* %0, i64 248
store i8 -8, i8* %53
%54 = getelementptr inbounds i8, i8* %0, i64 249
store i8 -7, i8* %54
%55 = getelementptr inbounds i8, i8* %0, i64 250
store i8 -6, i8* %55
%56 = getelementptr inbounds i8, i8* %0, i64 251
store i8 -5, i8* %56
%57 = getelementptr inbounds i8, i8* %0, i64 252
store i8 -4, i8* %57
%58 = getelementptr inbounds i8, i8* %0, i64 253
store i8 -3, i8* %58
%59 = getelementptr inbounds i8, i8* %0, i64 254
store i8 -2, i8* %59
%60 = getelementptr inbounds i8, i8* %0, i64 255
store i8 -1, i8* %60
ret void
}