void PaintPicDot(unsigned char *p, unsigned char c) {
  if (c == 0) {
    *p++ = 0x00;
    *p++ = 0x00;
    *p = 0x00;
    return;
  }
  if (c == 1) {
    *p++ = 0xff;
    *p++ = 0xff;
    *p = 0xff;
    return;
  }
  if (c == 2) {
    *p++ = 0x00;
    *p++ = 0x00;
    *p = 0xff;
    return;
  }
}


x86 assembly (clang, -O0):
<PaintPicDot>:
push   %rbp
mov    %rsp,%rbp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    114b <PaintPicDot+0x4b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11c0 <PaintPicDot+0xc0>
movzbl -0x9(%rbp),%eax
cmp    $0x1,%eax
jne    1188 <PaintPicDot+0x88>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xff,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0xff,(%rax)
mov    -0x8(%rbp),%rax
movb   $0xff,(%rax)
jmp    11c0 <PaintPicDot+0xc0>
movzbl -0x9(%rbp),%eax
cmp    $0x2,%eax
jne    11c0 <PaintPicDot+0xc0>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movb   $0xff,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<PaintPicDot>:
cmp    $0x2,%sil
ja     1123 <PaintPicDot+0x23>
movzbl %sil,%ecx
shl    $0x3,%ecx
mov    $0xff00,%eax
shr    %cl,%eax
mov    $0xffff00,%edx
shr    %cl,%edx
mov    %al,(%rdi)
mov    %al,0x1(%rdi)
mov    %dl,0x2(%rdi)
ret

LLVM IR (-O0):
define void @PaintPicDot(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
store i8* %0, i8** %3
store i8 %1, i8* %4
%5 = load i8, i8* %4
%6 = zext i8 %5 to i32
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %3
store i8 0, i8* %9
%11 = load i8*, i8** %3
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %3
store i8 0, i8* %11
%13 = load i8*, i8** %3
store i8 0, i8* %13
br label %34
14: ; preds = %2
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %3
store i8 -1, i8* %19
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
store i8 -1, i8* %21
%23 = load i8*, i8** %3
store i8 -1, i8* %23
br label %34
24: ; preds = %14
%25 = load i8, i8* %4
%26 = zext i8 %25 to i32
%27 = icmp eq i32 %26, 2
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
store i8 0, i8* %29
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %3
store i8 0, i8* %31
%33 = load i8*, i8** %3
store i8 -1, i8* %33
br label %34
34: ; preds = %8, %18, %28, %24
ret void
}

LLVM IR (-O2):
define void @PaintPicDot(i8* nocapture writeonly %0, i8 zeroext %1) {
%3 = icmp ult i8 %1, 3
br i1 %3, label %4, label %15
4: ; preds = %2
%5 = zext i8 %1 to i24
%6 = shl nuw nsw i24 %5, 3
%7 = lshr i24 65280, %6
%8 = trunc i24 %7 to i8
%9 = zext i8 %1 to i24
%10 = shl nuw nsw i24 %9, 3
%11 = lshr i24 -256, %10
%12 = trunc i24 %11 to i8
%13 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %8, i8* %0
%14 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %8, i8* %13
store i8 %12, i8* %14
br label %15
15: ; preds = %2, %4
ret void
}