void setPixel(unsigned char *vmem, unsigned short x, unsigned short y,
              unsigned char r, unsigned char g, unsigned char b) {
  unsigned char *pixel = vmem + ((1024 * 4) * y + x * 4);
  pixel[1] = r >> 2;
  pixel[2] = g >> 2;
  pixel[3] = b >> 2;
}


x86 assembly (clang, -O0):
<setPixel>:
push   %rbp
mov    %rsp,%rbp
mov    %r8d,-0x28(%rbp)
mov    %ecx,%eax
mov    -0x28(%rbp),%ecx
mov    %eax,-0x24(%rbp)
mov    %edx,%eax
mov    -0x24(%rbp),%edx
mov    %eax,-0x20(%rbp)
mov    %esi,%eax
mov    -0x20(%rbp),%esi
mov    %eax,-0x1c(%rbp)
mov    %rdi,%r8
mov    -0x1c(%rbp),%edi
mov    %r9b,%al
mov    %r8,-0x8(%rbp)
mov    %di,-0xa(%rbp)
mov    %si,-0xc(%rbp)
mov    %dl,-0xd(%rbp)
mov    %cl,-0xe(%rbp)
mov    %al,-0xf(%rbp)
mov    -0x8(%rbp),%rax
movzwl -0xc(%rbp),%ecx
shl    $0xc,%ecx
movzwl -0xa(%rbp),%edx
shl    $0x2,%edx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
movzbl -0xd(%rbp),%eax
sar    $0x2,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
movzbl -0xe(%rbp),%eax
sar    $0x2,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
movzbl -0xf(%rbp),%eax
sar    $0x2,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<setPixel>:
mov    %edx,%eax
shl    $0xc,%rax
mov    %esi,%edx
lea    (%rax,%rdx,4),%rax
shr    $0x2,%cl
mov    %cl,0x1(%rdi,%rax,1)
shr    $0x2,%r8b
mov    %r8b,0x2(%rdi,%rax,1)
shr    $0x2,%r9b
mov    %r9b,0x3(%rdi,%rax,1)
ret

LLVM IR (-O0):
define void @setPixel(i8* %0, i16 zeroext %1, i16 zeroext %2, i8 zeroext %3, i8 zeroext %4, i8 zeroext %5) {
%7 = alloca i8*
%8 = alloca i16
%9 = alloca i16
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8*
store i8* %0, i8** %7
store i16 %1, i16* %8
store i16 %2, i16* %9
store i8 %3, i8* %10
store i8 %4, i8* %11
store i8 %5, i8* %12
%14 = load i8*, i8** %7
%15 = load i16, i16* %9
%16 = zext i16 %15 to i32
%17 = mul nsw i32 4096, %16
%18 = load i16, i16* %8
%19 = zext i16 %18 to i32
%20 = mul nsw i32 %19, 4
%21 = add nsw i32 %17, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %14, i64 %22
store i8* %23, i8** %13
%24 = load i8, i8* %10
%25 = zext i8 %24 to i32
%26 = ashr i32 %25, 2
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %13
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 %27, i8* %29
%30 = load i8, i8* %11
%31 = zext i8 %30 to i32
%32 = ashr i32 %31, 2
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %13
%35 = getelementptr inbounds i8, i8* %34, i64 2
store i8 %33, i8* %35
%36 = load i8, i8* %12
%37 = zext i8 %36 to i32
%38 = ashr i32 %37, 2
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %13
%41 = getelementptr inbounds i8, i8* %40, i64 3
store i8 %39, i8* %41
ret void
}

LLVM IR (-O2):
define void @setPixel(i8* nocapture writeonly %0, i16 zeroext %1, i16 zeroext %2, i8 zeroext %3, i8 zeroext %4, i8 zeroext %5) {
%7 = zext i16 %2 to i64
%8 = shl nuw nsw i64 %7, 12
%9 = zext i16 %1 to i64
%10 = shl nuw nsw i64 %9, 2
%11 = add nuw nsw i64 %8, %10
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = lshr i8 %3, 2
%14 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %13, i8* %14
%15 = lshr i8 %4, 2
%16 = getelementptr inbounds i8, i8* %12, i64 2
store i8 %15, i8* %16
%17 = lshr i8 %5, 2
%18 = getelementptr inbounds i8, i8* %12, i64 3
store i8 %17, i8* %18
ret void
}