void qc_imag_writergb(void *addr, int bpp, unsigned char r, unsigned char g,
                      unsigned char b) {
  if (0) {
    if (bpp == 4) {
      unsigned char *addr2 = (unsigned char *)addr;
      addr2[0] = b;
      addr2[1] = g;
      addr2[2] = r;
      addr2[3] = 0;
    } else {
      unsigned char *addr2 = (unsigned char *)addr;
      addr2[0] = b;
      addr2[1] = g;
      addr2[2] = r;
    }
  } else {
    if (bpp == 4) {
      unsigned char *addr2 = (unsigned char *)addr;
      addr2[0] = r;
      addr2[1] = g;
      addr2[2] = b;
      addr2[3] = 0;
    } else {
      unsigned char *addr2 = (unsigned char *)addr;
      addr2[0] = r;
      addr2[1] = g;
      addr2[2] = b;
    }
  }
}


x86 assembly (clang, -O0):
<qc_imag_writergb>:
push   %rbp
mov    %rsp,%rbp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %dl,-0xd(%rbp)
mov    %cl,-0xe(%rbp)
mov    %al,-0xf(%rbp)
cmpl   $0x4,-0xc(%rbp)
jne    1153 <qc_imag_writergb+0x53>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xd(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0xe(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0xf(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0x3(%rax)
jmp    1178 <qc_imag_writergb+0x78>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xd(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0xe(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0xf(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x2(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<qc_imag_writergb>:
mov    %dl,(%rdi)
cmp    $0x4,%esi
jne    110b <qc_imag_writergb+0xb>
movb   $0x0,0x3(%rdi)
mov    %cl,0x1(%rdi)
mov    %r8b,0x2(%rdi)
ret

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

LLVM IR (-O2):
define void @qc_imag_writergb(i8* nocapture writeonly %0, i32 %1, i8 zeroext %2, i8 zeroext %3, i8 zeroext %4) {
%6 = icmp eq i32 %1, 4
store i8 %2, i8* %0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %0, i64 3
store i8 0, i8* %8
br label %9
9: ; preds = %5, %7
%10 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %3, i8* %10
%11 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %4, i8* %11
ret void
}