void write_mem(char *addr, unsigned long size) {
  int i = 0;
  for (i = 0; i < size; i++) {
    *(addr + i) = (char)('a' + (i % 26));
  }
}


x86 assembly (clang, -O0):
<write_mem>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    114f <write_mem+0x4f>
mov    -0x14(%rbp),%eax
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    111a <write_mem+0x1a>
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_mem>:
test   %rsi,%rsi
je     15dd <write_mem+0x4dd>
cmp    $0x10,%rsi
jae    1117 <write_mem+0x17>
xor    %r9d,%r9d
jmp    159e <write_mem+0x49e>
mov    %rsi,%r9
and    $0xfffffffffffffff0,%r9
lea    -0x10(%r9),%rcx
mov    %rcx,%r8
shr    $0x4,%r8
add    $0x1,%r8
test   %rcx,%rcx
je     15de <write_mem+0x4de>
mov    %r8,%rcx
and    $0xfffffffffffffffe,%rcx
movdqa 0xecb(%rip),%xmm4
movdqa 0xed2(%rip),%xmm14
movdqa 0xeda(%rip),%xmm6
movdqa 0xee1(%rip),%xmm13
xor    %edx,%edx
movdqa 0xee6(%rip),%xmm12
movdqa 0xeed(%rip),%xmm11
movdqa 0xef4(%rip),%xmm8
movdqa 0xefb(%rip),%xmm9
movdqa 0xf02(%rip),%xmm10
xchg   %ax,%ax
movdqa %xmm14,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm14,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm2
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm0
punpckldq %xmm0,%xmm2
movdqa %xmm14,%xmm0
psubd  %xmm2,%xmm0
movdqa %xmm4,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm4,%xmm2
pmuludq %xmm12,%xmm2
pshufd $0xed,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm2
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
movdqa %xmm4,%xmm2
psubd  %xmm1,%xmm2
packuswb %xmm2,%xmm0
movdqa %xmm13,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm13,%xmm2
pmuludq %xmm12,%xmm2
pshufd $0xed,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm2
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm2
pshufd $0xe8,%xmm2,%xmm2
punpckldq %xmm2,%xmm1
movdqa %xmm13,%xmm2
psubd  %xmm1,%xmm2
movdqa %xmm6,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm6,%xmm5
pmuludq %xmm12,%xmm5
pshufd $0xed,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm5
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
movdqa %xmm6,%xmm5
psubd  %xmm1,%xmm5
packuswb %xmm5,%xmm2
packuswb %xmm0,%xmm2
paddb  %xmm8,%xmm2
movdqu %xmm2,(%rdi,%rdx,1)
movdqa %xmm6,%xmm2
paddd  %xmm9,%xmm2
movdqa %xmm13,%xmm0
paddd  %xmm9,%xmm0
movdqa %xmm4,%xmm5
paddd  %xmm9,%xmm5
movdqa %xmm14,%xmm3
paddd  %xmm9,%xmm3
movdqa %xmm3,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm3,%xmm7
pmuludq %xmm12,%xmm7
pshufd $0xed,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm7
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psubd  %xmm1,%xmm3
movdqa %xmm5,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm5,%xmm7
pmuludq %xmm12,%xmm7
pshufd $0xed,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm7
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm7
pshufd $0xe8,%xmm7,%xmm7
punpckldq %xmm7,%xmm1
psubd  %xmm1,%xmm5
packuswb %xmm5,%xmm3
movdqa %xmm0,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm0,%xmm5
pmuludq %xmm12,%xmm5
pshufd $0xed,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm5
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psubd  %xmm1,%xmm0
movdqa %xmm2,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
pshufd $0xf5,%xmm2,%xmm5
pmuludq %xmm12,%xmm5
pshufd $0xed,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psrld  $0x3,%xmm1
pshufd $0xf5,%xmm1,%xmm5
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
pmuludq %xmm11,%xmm5
pshufd $0xe8,%xmm5,%xmm5
punpckldq %xmm5,%xmm1
psubd  %xmm1,%xmm2
packuswb %xmm2,%xmm0
packuswb %xmm3,%xmm0
paddb  %xmm8,%xmm0
movdqu %xmm0,0x10(%rdi,%rdx,1)
add    $0x20,%rdx
paddd  %xmm10,%xmm13
paddd  %xmm10,%xmm6
paddd  %xmm10,%xmm14
paddd  %xmm10,%xmm4
add    $0xfffffffffffffffe,%rcx
jne    1190 <write_mem+0x90>
movdqa %xmm14,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm14,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psubd  %xmm0,%xmm14
movdqa %xmm4,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm4,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psubd  %xmm0,%xmm4
packuswb %xmm4,%xmm14
movdqa %xmm13,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm13,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psubd  %xmm0,%xmm13
movdqa %xmm6,%xmm0
pmuludq %xmm12,%xmm0
pshufd $0xed,%xmm0,%xmm0
pshufd $0xf5,%xmm6,%xmm1
pmuludq %xmm12,%xmm1
pshufd $0xed,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psrld  $0x3,%xmm0
pshufd $0xf5,%xmm0,%xmm1
pmuludq %xmm11,%xmm0
pshufd $0xe8,%xmm0,%xmm0
pmuludq %xmm11,%xmm1
pshufd $0xe8,%xmm1,%xmm1
punpckldq %xmm1,%xmm0
psubd  %xmm0,%xmm6
packuswb %xmm6,%xmm13
packuswb %xmm14,%xmm13
paddb  0xae3(%rip),%xmm13
test   $0x1,%r8b
je     1599 <write_mem+0x499>
movdqu %xmm13,(%rdi,%rdx,1)
cmp    %rsi,%r9
je     15dd <write_mem+0x4dd>
add    %r9,%rdi
lea    0x61(%r9),%ecx
sub    %r9,%rsi
nopl   0x0(%rax,%rax,1)
mov    %r9d,%edx
imul   $0x4ec4ec4f,%rdx,%rdx
shr    $0x23,%rdx
lea    (%rdx,%rdx,4),%eax
lea    (%rax,%rax,4),%eax
add    %edx,%eax
mov    %ecx,%edx
sub    %al,%dl
mov    %dl,(%rdi)
add    $0x1,%rdi
add    $0x1,%cl
add    $0x1,%r9d
add    $0xffffffffffffffff,%rsi
jne    15b0 <write_mem+0x4b0>
ret
movdqa 0xa19(%rip),%xmm13
xor    %edx,%edx
test   $0x1,%r8b
jne    1593 <write_mem+0x493>
jmp    1599 <write_mem+0x499>

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

LLVM IR (-O2):
define void @write_mem(i8* nocapture writeonly %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %59, label %4
4: ; preds = %2
%5 = icmp ult i64 %1, 16
br i1 %5, label %48, label %6
6: ; preds = %4
%7 = and i64 %1, -16
%8 = add i64 %7, -16
%9 = lshr exact i64 %8, 4
%10 = add nuw nsw i64 %9, 1
%11 = and i64 %10, 1
%12 = icmp eq i64 %8, 0
br i1 %12, label %39, label %13
13: ; preds = %6
%14 = and i64 %10, 2305843009213693950
br label %15
15: ; preds = %15, %13
%16 = phi i64 [ 0, %13 ], [ %31, %15 ]
%17 = phi <16 x i32> [ <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>, %13 ], [ %32, %15 ]
%18 = phi i64 [ 0, %13 ], [ %33, %15 ]
%19 = urem <16 x i32> %17, <i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26>
%20 = trunc <16 x i32> %19 to <16 x i8>
%21 = add nuw nsw <16 x i8> %20, <i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97>
%22 = getelementptr inbounds i8, i8* %0, i64 %16
%23 = bitcast i8* %22 to <16 x i8>*
store <16 x i8> %21, <16 x i8>* %23
%24 = or i64 %16, 16
%25 = add <16 x i32> %17, <i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16, i32 16>
%26 = urem <16 x i32> %25, <i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26>
%27 = trunc <16 x i32> %26 to <16 x i8>
%28 = add nuw nsw <16 x i8> %27, <i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97>
%29 = getelementptr inbounds i8, i8* %0, i64 %24
%30 = bitcast i8* %29 to <16 x i8>*
store <16 x i8> %28, <16 x i8>* %30
%31 = add nuw i64 %16, 32
%32 = add <16 x i32> %17, <i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32>
%33 = add i64 %18, 2
%34 = icmp eq i64 %33, %14
br i1 %34, label %35, label %15
35: ; preds = %15
%36 = urem <16 x i32> %32, <i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26, i32 26>
%37 = trunc <16 x i32> %36 to <16 x i8>
%38 = add nuw <16 x i8> %37, <i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97, i8 97>
br label %39
39: ; preds = %35, %6
%40 = phi i64 [ 0, %6 ], [ %31, %35 ]
%41 = phi <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>, %6 ], [ %38, %35 ]
%42 = icmp eq i64 %11, 0
br i1 %42, label %46, label %43
43: ; preds = %39
%44 = getelementptr inbounds i8, i8* %0, i64 %40
%45 = bitcast i8* %44 to <16 x i8>*
store <16 x i8> %41, <16 x i8>* %45
br label %46
46: ; preds = %39, %43
%47 = icmp eq i64 %7, %1
br i1 %47, label %59, label %48
48: ; preds = %4, %46
%49 = phi i64 [ 0, %4 ], [ %7, %46 ]
br label %50
50: ; preds = %48, %50
%51 = phi i64 [ %57, %50 ], [ %49, %48 ]
%52 = trunc i64 %51 to i32
%53 = urem i32 %52, 26
%54 = trunc i32 %53 to i8
%55 = add nuw nsw i8 %54, 97
%56 = getelementptr inbounds i8, i8* %0, i64 %51
store i8 %55, i8* %56
%57 = add nuw nsw i64 %51, 1
%58 = icmp eq i64 %57, %1
br i1 %58, label %59, label %50
59: ; preds = %50, %46, %2
ret void
}