void build_bulb(unsigned char *out, unsigned char string, unsigned char addr,
                unsigned char bright, unsigned char r, unsigned char g,
                unsigned char b, int more_bulbs) {
  ((out)[0]) = addr;
  if (more_bulbs)
    ((out)[0]) |= 0x40;
  ((out)[1]) = (b << 4) | string;
  ((out)[2]) = (g << 4) | (r & 0xF);
  ((out)[3]) = bright;
}


x86 assembly (clang, -O0):
<build_bulb>:
push   %rbp
mov    %rsp,%rbp
mov    %r8d,-0x20(%rbp)
mov    %ecx,%eax
mov    -0x20(%rbp),%ecx
mov    %eax,-0x1c(%rbp)
mov    %edx,%eax
mov    -0x1c(%rbp),%edx
mov    %eax,-0x18(%rbp)
mov    %esi,%eax
mov    -0x18(%rbp),%esi
mov    %eax,-0x14(%rbp)
mov    %rdi,%r8
mov    -0x14(%rbp),%edi
mov    %r9b,%al
mov    0x18(%rbp),%r9d
mov    0x10(%rbp),%r9b
mov    %r8,-0x8(%rbp)
mov    %dil,-0x9(%rbp)
mov    %sil,-0xa(%rbp)
mov    %dl,-0xb(%rbp)
mov    %cl,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    -0xa(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0x0,0x18(%rbp)
je     1165 <build_bulb+0x65>
mov    -0x8(%rbp),%rax
movzbl (%rax),%ecx
or     $0x40,%ecx
mov    %cl,(%rax)
movzbl 0x10(%rbp),%eax
shl    $0x4,%eax
movzbl -0x9(%rbp),%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x1(%rax)
movzbl -0xd(%rbp),%eax
shl    $0x4,%eax
movzbl -0xc(%rbp),%ecx
and    $0xf,%ecx
or     %ecx,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0xb(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x3(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_bulb>:
mov    0x8(%rsp),%r11b
mov    %edx,%r10d
or     $0x40,%r10b
cmpl   $0x0,0x10(%rsp)
movzbl %r10b,%eax
cmove  %edx,%eax
mov    %al,(%rdi)
shl    $0x4,%r11b
or     %sil,%r11b
mov    %r11b,0x1(%rdi)
shl    $0x4,%r9b
and    $0xf,%r8b
or     %r9b,%r8b
mov    %r8b,0x2(%rdi)
mov    %cl,0x3(%rdi)
ret

LLVM IR (-O0):
define void @build_bulb(i8* %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8 zeroext %4, i8 zeroext %5, i8 zeroext %6, i32 %7) {
%9 = alloca i8*
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8
%13 = alloca i8
%14 = alloca i8
%15 = alloca i8
%16 = alloca i32
store i8* %0, i8** %9
store i8 %1, i8* %10
store i8 %2, i8* %11
store i8 %3, i8* %12
store i8 %4, i8* %13
store i8 %5, i8* %14
store i8 %6, i8* %15
store i32 %7, i32* %16
%17 = load i8, i8* %11
%18 = load i8*, i8** %9
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 %17, i8* %19
%20 = load i32, i32* %16
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %8
%23 = load i8*, i8** %9
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = or i32 %26, 64
%28 = trunc i32 %27 to i8
store i8 %28, i8* %24
br label %29
29: ; preds = %22, %8
%30 = load i8, i8* %15
%31 = zext i8 %30 to i32
%32 = shl i32 %31, 4
%33 = load i8, i8* %10
%34 = zext i8 %33 to i32
%35 = or i32 %32, %34
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8 %36, i8* %38
%39 = load i8, i8* %14
%40 = zext i8 %39 to i32
%41 = shl i32 %40, 4
%42 = load i8, i8* %13
%43 = zext i8 %42 to i32
%44 = and i32 %43, 15
%45 = or i32 %41, %44
%46 = trunc i32 %45 to i8
%47 = load i8*, i8** %9
%48 = getelementptr inbounds i8, i8* %47, i64 2
store i8 %46, i8* %48
%49 = load i8, i8* %12
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i64 3
store i8 %49, i8* %51
ret void
}

LLVM IR (-O2):
define void @build_bulb(i8* nocapture writeonly %0, i8 zeroext %1, i8 zeroext %2, i8 zeroext %3, i8 zeroext %4, i8 zeroext %5, i8 zeroext %6, i32 %7) {
%9 = icmp eq i32 %7, 0
%10 = or i8 %2, 64
%11 = select i1 %9, i8 %2, i8 %10
store i8 %11, i8* %0
%12 = shl i8 %6, 4
%13 = or i8 %12, %1
%14 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %13, i8* %14
%15 = shl i8 %5, 4
%16 = and i8 %4, 15
%17 = or i8 %15, %16
%18 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %17, i8* %18
%19 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %3, i8* %19
ret void
}