int store_int(unsigned int l, int nbytes, unsigned char *c) {
  int i;
  for (i = 0; i < nbytes; i++)
    c[i] = (unsigned char)(l >> (8 * (nbytes - i - 1))) & 0xff;
  return nbytes;
}


x86 assembly (clang, -O0):
<store_int>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1155 <store_int+0x55>
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    -0x14(%rbp),%ecx
sub    $0x1,%ecx
shl    $0x3,%ecx
shr    %cl,%eax
movzbl %al,%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1115 <store_int+0x15>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<store_int>:
mov    %esi,%eax
test   %esi,%esi
jle    1714 <store_int+0x614>
mov    %eax,%r8d
cmp    $0x10,%eax
jae    111a <store_int+0x1a>
xor    %r11d,%r11d
jmp    16e8 <store_int+0x5e8>
mov    %r8d,%r11d
and    $0xfffffff0,%r11d
movd   %eax,%xmm0
pshufd $0x0,%xmm0,%xmm12
movd   %edi,%xmm0
pshufd $0x0,%xmm0,%xmm9
lea    -0x10(%r11),%rcx
mov    %rcx,%r9
shr    $0x4,%r9
add    $0x1,%r9
test   %rcx,%rcx
je     1715 <store_int+0x615>
mov    %r9,%rcx
and    $0xfffffffffffffffe,%rcx
movdqa 0xee4(%rip),%xmm3
movdqa 0xeec(%rip),%xmm2
movdqa 0xef3(%rip),%xmm8
movdqa 0xefa(%rip),%xmm10
xor    %r10d,%r10d
nopl   0x0(%rax)
movdqa %xmm2,-0x18(%rsp)
movdqa %xmm3,-0x58(%rsp)
movdqa %xmm2,%xmm13
movdqa %xmm8,%xmm14
movdqa %xmm8,-0x28(%rsp)
movdqa %xmm10,%xmm15
movdqa %xmm10,%xmm7
pcmpeqd %xmm0,%xmm0
pxor   %xmm0,%xmm7
pxor   %xmm0,%xmm14
movdqa %xmm2,%xmm6
pxor   %xmm0,%xmm6
movdqa %xmm3,%xmm1
pxor   %xmm0,%xmm1
paddd  %xmm12,%xmm1
paddd  %xmm12,%xmm6
paddd  %xmm12,%xmm14
paddd  %xmm12,%xmm7
pslld  $0x3,%xmm7
pslld  $0x3,%xmm14
pslld  $0x3,%xmm1
pshuflw $0xfe,%xmm1,%xmm0
movdqa %xmm9,%xmm2
psrld  %xmm0,%xmm2
pslld  $0x3,%xmm6
pshuflw $0x54,%xmm1,%xmm11
movdqa %xmm9,%xmm0
psrld  %xmm11,%xmm0
movdqa %xmm3,%xmm11
pshufd $0xee,%xmm1,%xmm1
pshuflw $0xfe,%xmm1,%xmm3
movdqa %xmm9,%xmm5
psrld  %xmm3,%xmm5
punpcklqdq %xmm2,%xmm0
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm9,%xmm2
psrld  %xmm1,%xmm2
punpckhqdq %xmm5,%xmm2
pshuflw $0xfe,%xmm6,%xmm1
movdqa %xmm9,%xmm3
psrld  %xmm1,%xmm3
shufps $0xcc,%xmm2,%xmm0
pshuflw $0x54,%xmm6,%xmm2
movdqa %xmm9,%xmm1
psrld  %xmm2,%xmm1
pshufd $0xee,%xmm6,%xmm2
pshuflw $0xfe,%xmm2,%xmm5
movdqa %xmm9,%xmm6
psrld  %xmm5,%xmm6
punpcklqdq %xmm3,%xmm1
pshuflw $0x54,%xmm2,%xmm2
movdqa %xmm9,%xmm3
psrld  %xmm2,%xmm3
punpckhqdq %xmm6,%xmm3
pshuflw $0xfe,%xmm14,%xmm2
movdqa %xmm9,%xmm5
psrld  %xmm2,%xmm5
shufps $0xcc,%xmm3,%xmm1
pshuflw $0x54,%xmm14,%xmm3
movdqa %xmm9,%xmm2
psrld  %xmm3,%xmm2
pshufd $0xee,%xmm14,%xmm3
pshuflw $0xfe,%xmm3,%xmm6
movdqa %xmm9,%xmm4
psrld  %xmm6,%xmm4
punpcklqdq %xmm5,%xmm2
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm9,%xmm5
psrld  %xmm3,%xmm5
punpckhqdq %xmm4,%xmm5
pshuflw $0xfe,%xmm7,%xmm3
movdqa %xmm9,%xmm4
psrld  %xmm3,%xmm4
shufps $0xcc,%xmm5,%xmm2
pshuflw $0x54,%xmm7,%xmm3
movdqa %xmm9,%xmm5
psrld  %xmm3,%xmm5
pshufd $0xee,%xmm7,%xmm3
pshuflw $0xfe,%xmm3,%xmm6
movdqa %xmm9,%xmm7
psrld  %xmm6,%xmm7
punpcklqdq %xmm4,%xmm5
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm9,%xmm4
psrld  %xmm3,%xmm4
punpckhqdq %xmm7,%xmm4
shufps $0xcc,%xmm4,%xmm5
movaps 0xd6d(%rip),%xmm14
andps  %xmm14,%xmm5
andps  %xmm14,%xmm2
packuswb %xmm2,%xmm5
andps  %xmm14,%xmm1
andps  %xmm14,%xmm0
packuswb %xmm0,%xmm1
packuswb %xmm1,%xmm5
movdqu %xmm5,(%rdx,%r10,1)
movdqa %xmm12,%xmm1
movdqa %xmm11,-0x38(%rsp)
psubd  %xmm11,%xmm1
pslld  $0x3,%xmm1
movdqa %xmm12,%xmm2
movdqa %xmm13,-0x48(%rsp)
psubd  %xmm13,%xmm2
movdqa -0x28(%rsp),%xmm13
pslld  $0x3,%xmm2
movdqa %xmm12,%xmm6
psubd  %xmm13,%xmm6
pslld  $0x3,%xmm6
movdqa %xmm12,%xmm7
movdqa %xmm10,%xmm11
psubd  %xmm10,%xmm7
pslld  $0x3,%xmm7
movdqa 0xcdd(%rip),%xmm4
paddd  %xmm4,%xmm7
paddd  %xmm4,%xmm6
paddd  %xmm4,%xmm1
pshuflw $0xfe,%xmm1,%xmm0
movdqa %xmm9,%xmm3
psrld  %xmm0,%xmm3
paddd  %xmm4,%xmm2
pshuflw $0x54,%xmm1,%xmm4
movdqa %xmm9,%xmm0
psrld  %xmm4,%xmm0
pshufd $0xee,%xmm1,%xmm1
pshuflw $0xfe,%xmm1,%xmm4
movdqa %xmm9,%xmm5
psrld  %xmm4,%xmm5
punpcklqdq %xmm3,%xmm0
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm9,%xmm3
psrld  %xmm1,%xmm3
punpckhqdq %xmm5,%xmm3
pshuflw $0xfe,%xmm2,%xmm1
movdqa %xmm9,%xmm4
psrld  %xmm1,%xmm4
shufps $0xcc,%xmm3,%xmm0
pshuflw $0x54,%xmm2,%xmm3
movdqa %xmm9,%xmm1
psrld  %xmm3,%xmm1
pshufd $0xee,%xmm2,%xmm2
pshuflw $0xfe,%xmm2,%xmm3
movdqa %xmm9,%xmm5
psrld  %xmm3,%xmm5
punpcklqdq %xmm4,%xmm1
pshuflw $0x54,%xmm2,%xmm2
movdqa %xmm9,%xmm3
psrld  %xmm2,%xmm3
punpckhqdq %xmm5,%xmm3
pshuflw $0xfe,%xmm6,%xmm2
movdqa %xmm9,%xmm4
psrld  %xmm2,%xmm4
shufps $0xcc,%xmm3,%xmm1
pshuflw $0x54,%xmm6,%xmm3
movdqa %xmm9,%xmm2
psrld  %xmm3,%xmm2
pshufd $0xee,%xmm6,%xmm3
pshuflw $0xfe,%xmm3,%xmm5
movdqa %xmm9,%xmm6
psrld  %xmm5,%xmm6
punpcklqdq %xmm4,%xmm2
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm9,%xmm4
psrld  %xmm3,%xmm4
punpckhqdq %xmm6,%xmm4
pshuflw $0xfe,%xmm7,%xmm3
movdqa %xmm9,%xmm5
psrld  %xmm3,%xmm5
shufps $0xcc,%xmm4,%xmm2
pshuflw $0x54,%xmm7,%xmm3
movdqa %xmm9,%xmm4
psrld  %xmm3,%xmm4
pshufd $0xee,%xmm7,%xmm3
pshuflw $0xfe,%xmm3,%xmm6
movdqa %xmm9,%xmm7
psrld  %xmm6,%xmm7
punpcklqdq %xmm5,%xmm4
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm9,%xmm5
psrld  %xmm3,%xmm5
punpckhqdq %xmm7,%xmm5
shufps $0xcc,%xmm5,%xmm4
andps  %xmm14,%xmm4
andps  %xmm14,%xmm2
packuswb %xmm2,%xmm4
movdqa -0x18(%rsp),%xmm2
andps  %xmm14,%xmm1
andps  %xmm14,%xmm0
packuswb %xmm0,%xmm1
packuswb %xmm1,%xmm4
movdqu %xmm4,0x10(%rdx,%r10,1)
add    $0x20,%r10
movdqa 0xb94(%rip),%xmm0
paddd  %xmm0,%xmm10
paddd  %xmm0,%xmm8
paddd  %xmm0,%xmm2
movdqa -0x58(%rsp),%xmm1
paddd  %xmm0,%xmm1
movdqa %xmm1,-0x58(%rsp)
movdqa -0x58(%rsp),%xmm3
add    $0xfffffffffffffffe,%rcx
jne    1180 <store_int+0x80>
movdqa 0xb6e(%rip),%xmm1
movdqa %xmm1,%xmm2
psubd  %xmm11,%xmm2
movdqa %xmm1,%xmm3
psubd  %xmm13,%xmm3
movdqa %xmm1,%xmm5
psubd  -0x48(%rsp),%xmm5
psubd  -0x38(%rsp),%xmm1
test   $0x1,%r9b
je     16e3 <store_int+0x5e3>
paddd  %xmm12,%xmm1
paddd  %xmm12,%xmm5
paddd  %xmm12,%xmm3
paddd  %xmm12,%xmm2
pslld  $0x3,%xmm2
pslld  $0x3,%xmm1
pshuflw $0xfe,%xmm1,%xmm0
movdqa %xmm9,%xmm4
psrld  %xmm0,%xmm4
pslld  $0x3,%xmm3
pshuflw $0x54,%xmm1,%xmm6
movdqa %xmm9,%xmm0
psrld  %xmm6,%xmm0
pshufd $0xee,%xmm1,%xmm1
pshuflw $0xfe,%xmm1,%xmm6
movdqa %xmm9,%xmm7
psrld  %xmm6,%xmm7
pslld  $0x3,%xmm5
pshuflw $0x54,%xmm1,%xmm1
movdqa %xmm9,%xmm6
psrld  %xmm1,%xmm6
punpcklqdq %xmm4,%xmm0
pshuflw $0xfe,%xmm5,%xmm1
movdqa %xmm9,%xmm4
psrld  %xmm1,%xmm4
punpckhqdq %xmm7,%xmm6
pshuflw $0x54,%xmm5,%xmm7
movdqa %xmm9,%xmm1
psrld  %xmm7,%xmm1
pshufd $0xee,%xmm5,%xmm5
pshuflw $0xfe,%xmm5,%xmm8
movdqa %xmm9,%xmm7
psrld  %xmm8,%xmm7
shufps $0xcc,%xmm6,%xmm0
pshuflw $0x54,%xmm5,%xmm5
movdqa %xmm9,%xmm6
psrld  %xmm5,%xmm6
punpcklqdq %xmm4,%xmm1
pshuflw $0xfe,%xmm3,%xmm5
movdqa %xmm9,%xmm4
psrld  %xmm5,%xmm4
punpckhqdq %xmm7,%xmm6
pshuflw $0x54,%xmm3,%xmm7
movdqa %xmm9,%xmm5
psrld  %xmm7,%xmm5
pshufd $0xee,%xmm3,%xmm3
pshuflw $0xfe,%xmm3,%xmm8
movdqa %xmm9,%xmm7
psrld  %xmm8,%xmm7
shufps $0xcc,%xmm6,%xmm1
pshuflw $0x54,%xmm3,%xmm3
movdqa %xmm9,%xmm6
psrld  %xmm3,%xmm6
punpcklqdq %xmm4,%xmm5
pshuflw $0xfe,%xmm2,%xmm3
movdqa %xmm9,%xmm4
psrld  %xmm3,%xmm4
punpckhqdq %xmm7,%xmm6
pshuflw $0x54,%xmm2,%xmm3
movdqa %xmm9,%xmm7
psrld  %xmm3,%xmm7
pshufd $0xee,%xmm2,%xmm2
pshuflw $0xfe,%xmm2,%xmm8
movdqa %xmm9,%xmm3
psrld  %xmm8,%xmm3
shufps $0xcc,%xmm6,%xmm5
pshuflw $0x54,%xmm2,%xmm2
psrld  %xmm2,%xmm9
punpcklqdq %xmm4,%xmm7
punpckhqdq %xmm3,%xmm9
shufps $0xcc,%xmm9,%xmm7
movaps 0x9cb(%rip),%xmm2
andps  %xmm2,%xmm7
andps  %xmm2,%xmm5
packuswb %xmm5,%xmm7
andps  %xmm2,%xmm1
andps  %xmm2,%xmm0
packuswb %xmm0,%xmm1
packuswb %xmm1,%xmm7
movdqu %xmm7,(%rdx,%r10,1)
cmp    %r8,%r11
je     1714 <store_int+0x614>
mov    %eax,%ecx
sub    %r11d,%ecx
lea    -0x8(,%rcx,8),%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %edi,%esi
shr    %cl,%esi
mov    %sil,(%rdx,%r11,1)
add    $0x1,%r11
add    $0xfffffff8,%ecx
cmp    %r11,%r8
jne    1700 <store_int+0x600>
ret
movdqa 0x8e3(%rip),%xmm1
movdqa 0x8eb(%rip),%xmm5
movdqa 0x8f3(%rip),%xmm3
movdqa 0x8fb(%rip),%xmm2
xor    %r10d,%r10d
test   $0x1,%r9b
jne    156e <store_int+0x46e>
jmp    16e3 <store_int+0x5e3>

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

LLVM IR (-O2):
define i32 @store_int(i32 %0, i32 returned %1, i8* nocapture writeonly %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %72
5: ; preds = %3
%6 = zext i32 %1 to i64
%7 = icmp ult i32 %1, 16
br i1 %7, label %59, label %8
8: ; preds = %5
%9 = and i64 %6, 4294967280
%10 = insertelement <16 x i32> poison, i32 %1, i64 0
%11 = shufflevector <16 x i32> %10, <16 x i32> poison, <16 x i32> zeroinitializer
%12 = insertelement <16 x i32> poison, i32 %0, i64 0
%13 = shufflevector <16 x i32> %12, <16 x i32> poison, <16 x i32> zeroinitializer
%14 = add nsw i64 %9, -16
%15 = lshr exact i64 %14, 4
%16 = add nuw nsw i64 %15, 1
%17 = and i64 %16, 1
%18 = icmp eq i64 %14, 0
br i1 %18, label %46, label %19
19: ; preds = %8
%20 = and i64 %16, 2305843009213693950
br label %21
21: ; preds = %21, %19
%22 = phi i64 [ 0, %19 ], [ %40, %21 ]
%23 = 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>, %19 ], [ %41, %21 ]
%24 = phi i64 [ 0, %19 ], [ %42, %21 ]
%25 = xor <16 x i32> %23, <i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1, i32 -1>
%26 = add <16 x i32> %11, %25
%27 = shl nsw <16 x i32> %26, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%28 = lshr <16 x i32> %13, %27
%29 = trunc <16 x i32> %28 to <16 x i8>
%30 = getelementptr inbounds i8, i8* %2, i64 %22
%31 = bitcast i8* %30 to <16 x i8>*
store <16 x i8> %29, <16 x i8>* %31
%32 = or i64 %22, 16
%33 = sub <16 x i32> <i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17, i32 -17>, %23
%34 = add <16 x i32> %11, %33
%35 = shl nsw <16 x i32> %34, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%36 = lshr <16 x i32> %13, %35
%37 = trunc <16 x i32> %36 to <16 x i8>
%38 = getelementptr inbounds i8, i8* %2, i64 %32
%39 = bitcast i8* %38 to <16 x i8>*
store <16 x i8> %37, <16 x i8>* %39
%40 = add nuw i64 %22, 32
%41 = add <16 x i32> %23, <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>
%42 = add i64 %24, 2
%43 = icmp eq i64 %42, %20
br i1 %43, label %44, label %21
44: ; preds = %21
%45 = sub <16 x i32> <i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33, i32 -33>, %23
br label %46
46: ; preds = %44, %8
%47 = phi i64 [ 0, %8 ], [ %40, %44 ]
%48 = phi <16 x i32> [ <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, i32 -16>, %8 ], [ %45, %44 ]
%49 = icmp eq i64 %17, 0
br i1 %49, label %57, label %50
50: ; preds = %46
%51 = add <16 x i32> %11, %48
%52 = shl nsw <16 x i32> %51, <i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3, i32 3>
%53 = lshr <16 x i32> %13, %52
%54 = trunc <16 x i32> %53 to <16 x i8>
%55 = getelementptr inbounds i8, i8* %2, i64 %47
%56 = bitcast i8* %55 to <16 x i8>*
store <16 x i8> %54, <16 x i8>* %56
br label %57
57: ; preds = %46, %50
%58 = icmp eq i64 %9, %6
br i1 %58, label %72, label %59
59: ; preds = %5, %57
%60 = phi i64 [ 0, %5 ], [ %9, %57 ]
br label %61
61: ; preds = %59, %61
%62 = phi i64 [ %70, %61 ], [ %60, %59 ]
%63 = trunc i64 %62 to i32
%64 = xor i32 %63, -1
%65 = add i32 %64, %1
%66 = shl nsw i32 %65, 3
%67 = lshr i32 %0, %66
%68 = trunc i32 %67 to i8
%69 = getelementptr inbounds i8, i8* %2, i64 %62
store i8 %68, i8* %69
%70 = add nuw nsw i64 %62, 1
%71 = icmp eq i64 %70, %6
br i1 %71, label %72, label %61
72: ; preds = %61, %57, %3
ret i32 %1
}