void RGB32toRGB444_ROW_SHRINK(unsigned char *dest_ptr, int dest_dx,
                              unsigned char *src_ptr, int src_dx) {
  register unsigned char *d = dest_ptr;
  register unsigned char *s = src_ptr;
  register int count = dest_dx;
  register int limit = src_dx >> 1;
  register int step = dest_dx;
  if (count) {
    do {
      register unsigned int da_rgb;
      register unsigned int sa_rgb;
      sa_rgb = *(unsigned int *)(s);
      da_rgb =
          ((8 + 4 < 8)
               ? (((((16 + 8 < 8) ? ((sa_rgb << ((8 - (16 + 8)) & 0x1F)) &
                                     (0x100 - (1U << (8 - 8))))
                                  : ((sa_rgb >> (((16 + 8) - 8) & 0x1F)) &
                                     (0x100 - (1U << (8 - 8)))))) &
                   (0x100 - (1U << (8 - 4)))) >>
                  ((8 - (8 + 4)) & 0x1F))
               : (((((16 + 8 < 8) ? ((sa_rgb << ((8 - (16 + 8)) & 0x1F)) &
                                     (0x100 - (1U << (8 - 8))))
                                  : ((sa_rgb >> (((16 + 8) - 8) & 0x1F)) &
                                     (0x100 - (1U << (8 - 8)))))) &
                   (0x100 - (1U << (8 - 4))))
                  << (((8 + 4) - 8) & 0x1F))) |
          ((4 + 4 < 8) ? (((((8 + 8 < 8) ? ((sa_rgb << ((8 - (8 + 8)) & 0x1F)) &
                                            (0x100 - (1U << (8 - 8))))
                                         : ((sa_rgb >> (((8 + 8) - 8) & 0x1F)) &
                                            (0x100 - (1U << (8 - 8)))))) &
                           (0x100 - (1U << (8 - 4)))) >>
                          ((8 - (4 + 4)) & 0x1F))
                       : (((((8 + 8 < 8) ? ((sa_rgb << ((8 - (8 + 8)) & 0x1F)) &
                                            (0x100 - (1U << (8 - 8))))
                                         : ((sa_rgb >> (((8 + 8) - 8) & 0x1F)) &
                                            (0x100 - (1U << (8 - 8)))))) &
                           (0x100 - (1U << (8 - 4))))
                          << (((4 + 4) - 8) & 0x1F))) |
          ((0 + 4 < 8) ? (((((0 + 8 < 8) ? ((sa_rgb << ((8 - (0 + 8)) & 0x1F)) &
                                            (0x100 - (1U << (8 - 8))))
                                         : ((sa_rgb >> (((0 + 8) - 8) & 0x1F)) &
                                            (0x100 - (1U << (8 - 8)))))) &
                           (0x100 - (1U << (8 - 4)))) >>
                          ((8 - (0 + 4)) & 0x1F))
                       : (((((0 + 8 < 8) ? ((sa_rgb << ((8 - (0 + 8)) & 0x1F)) &
                                            (0x100 - (1U << (8 - 8))))
                                         : ((sa_rgb >> (((0 + 8) - 8) & 0x1F)) &
                                            (0x100 - (1U << (8 - 8)))))) &
                           (0x100 - (1U << (8 - 4))))
                          << (((0 + 4) - 8) & 0x1F)));
      *(unsigned short *)(d) = da_rgb;
      d += 2;
      do {
        s += 4;
      } while ((limit -= step) >= 0);
      limit += src_dx;
    } while (--count);
  }
}


x86 assembly (clang, -O0):
<RGB32toRGB444_ROW_SHRINK>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     11ec <RGB32toRGB444_ROW_SHRINK+0xec>
jmp    1146 <RGB32toRGB444_ROW_SHRINK+0x46>
mov    -0x30(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
and    $0xf0,%eax
shl    $0x4,%eax
mov    -0x44(%rbp),%ecx
shr    $0x8,%ecx
and    $0xff,%ecx
and    $0xf0,%ecx
shl    $0x0,%ecx
or     %ecx,%eax
mov    -0x44(%rbp),%ecx
shr    $0x0,%ecx
and    $0xff,%ecx
and    $0xf0,%ecx
shr    $0x4,%ecx
or     %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    %ax,%cx
mov    -0x28(%rbp),%rax
mov    %cx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x30(%rbp)
mov    -0x3c(%rbp),%ecx
mov    -0x38(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x38(%rbp)
cmp    $0x0,%eax
jge    11ac <RGB32toRGB444_ROW_SHRINK+0xac>
mov    -0x1c(%rbp),%eax
add    -0x38(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jne    1146 <RGB32toRGB444_ROW_SHRINK+0x46>
jmp    11ec <RGB32toRGB444_ROW_SHRINK+0xec>
pop    %rbp
ret

x86 assembly (clang, -O2):
<RGB32toRGB444_ROW_SHRINK>:
test   %esi,%esi
je     1164 <RGB32toRGB444_ROW_SHRINK+0x64>
mov    %ecx,%eax
sar    %eax
mov    %esi,%r8d
nopl   0x0(%rax,%rax,1)
mov    (%rdx),%r9d
mov    %r9d,%r10d
shr    $0xc,%r10d
and    $0xf00,%r10d
mov    %r9d,%r11d
shr    $0x8,%r11d
and    $0xf0,%r11d
or     %r10d,%r11d
shr    $0x4,%r9d
and    $0xf,%r9d
or     %r11d,%r9d
mov    %r9w,(%rdi)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x4,%rdx
sub    %esi,%eax
jns    1150 <RGB32toRGB444_ROW_SHRINK+0x50>
add    $0x2,%rdi
add    %ecx,%eax
add    $0xffffffff,%r8d
jne    1110 <RGB32toRGB444_ROW_SHRINK+0x10>
ret

LLVM IR (-O0):
define void @RGB32toRGB444_ROW_SHRINK(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%16 = load i8*, i8** %5
store i8* %16, i8** %9
%17 = load i8*, i8** %7
store i8* %17, i8** %10
%18 = load i32, i32* %6
store i32 %18, i32* %11
%19 = load i32, i32* %8
%20 = ashr i32 %19, 1
store i32 %20, i32* %12
%21 = load i32, i32* %6
store i32 %21, i32* %13
%22 = load i32, i32* %11
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %69
24: ; preds = %4
br label %25
25: ; preds = %64, %24
%26 = load i8*, i8** %10
%27 = bitcast i8* %26 to i32*
%28 = load i32, i32* %27
store i32 %28, i32* %15
%29 = load i32, i32* %15
%30 = lshr i32 %29, 16
%31 = and i32 %30, 255
%32 = and i32 %31, 240
%33 = shl i32 %32, 4
%34 = load i32, i32* %15
%35 = lshr i32 %34, 8
%36 = and i32 %35, 255
%37 = and i32 %36, 240
%38 = shl i32 %37, 0
%39 = or i32 %33, %38
%40 = load i32, i32* %15
%41 = lshr i32 %40, 0
%42 = and i32 %41, 255
%43 = and i32 %42, 240
%44 = lshr i32 %43, 4
%45 = or i32 %39, %44
store i32 %45, i32* %14
%46 = load i32, i32* %14
%47 = trunc i32 %46 to i16
%48 = load i8*, i8** %9
%49 = bitcast i8* %48 to i16*
store i16 %47, i16* %49
%50 = load i8*, i8** %9
%51 = getelementptr inbounds i8, i8* %50, i64 2
store i8* %51, i8** %9
br label %52
52: ; preds = %55, %25
%53 = load i8*, i8** %10
%54 = getelementptr inbounds i8, i8* %53, i64 4
store i8* %54, i8** %10
br label %55
55: ; preds = %52
%56 = load i32, i32* %13
%57 = load i32, i32* %12
%58 = sub nsw i32 %57, %56
store i32 %58, i32* %12
%59 = icmp sge i32 %58, 0
br i1 %59, label %52, label %60
60: ; preds = %55
%61 = load i32, i32* %8
%62 = load i32, i32* %12
%63 = add nsw i32 %62, %61
store i32 %63, i32* %12
br label %64
64: ; preds = %60
%65 = load i32, i32* %11
%66 = add nsw i32 %65, -1
store i32 %66, i32* %11
%67 = icmp ne i32 %66, 0
br i1 %67, label %25, label %68
68: ; preds = %64
br label %69
69: ; preds = %68, %4
ret void
}

LLVM IR (-O2):
define void @RGB32toRGB444_ROW_SHRINK(i8* nocapture writeonly %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = icmp eq i32 %1, 0
br i1 %5, label %36, label %6
6: ; preds = %4
%7 = ashr i32 %3, 1
br label %8
8: ; preds = %6, %31
%9 = phi i32 [ %33, %31 ], [ %7, %6 ]
%10 = phi i32 [ %34, %31 ], [ %1, %6 ]
%11 = phi i8* [ %28, %31 ], [ %2, %6 ]
%12 = phi i8* [ %32, %31 ], [ %0, %6 ]
%13 = bitcast i8* %11 to i32*
%14 = load i32, i32* %13
%15 = lshr i32 %14, 12
%16 = and i32 %15, 3840
%17 = lshr i32 %14, 8
%18 = and i32 %17, 240
%19 = or i32 %16, %18
%20 = lshr i32 %14, 4
%21 = and i32 %20, 15
%22 = or i32 %19, %21
%23 = trunc i32 %22 to i16
%24 = bitcast i8* %12 to i16*
store i16 %23, i16* %24
br label %25
25: ; preds = %25, %8
%26 = phi i32 [ %9, %8 ], [ %29, %25 ]
%27 = phi i8* [ %11, %8 ], [ %28, %25 ]
%28 = getelementptr inbounds i8, i8* %27, i64 4
%29 = sub nsw i32 %26, %1
%30 = icmp sgt i32 %29, -1
br i1 %30, label %25, label %31
31: ; preds = %25
%32 = getelementptr inbounds i8, i8* %12, i64 2
%33 = add nsw i32 %29, %3
%34 = add nsw i32 %10, -1
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %8
36: ; preds = %31, %4
ret void
}