#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ lerp_rgb(unsigned char *, unsigned char *, unsigned char *,
                            int);
int /*<<< orphan*/ unpack_rgb565(unsigned char *, unsigned short);
void eval_colors(unsigned char color[4][3], unsigned short c0,
                 unsigned short c1) {
  unpack_rgb565(color[0], c0);
  unpack_rgb565(color[1], c1);
  if (c0 > c1) {
    lerp_rgb(color[2], color[0], color[1], 0x55);
    lerp_rgb(color[3], color[0], color[1], 0xaa);
  } else {
    color[2][0] = (color[0][0] + color[1][0]) >> 1;
    color[2][1] = (color[0][1] + color[1][1]) >> 1;
    color[2][2] = (color[0][2] + color[1][2]) >> 1;
    color[3][0] = color[3][1] = color[3][2] = 0;
  }
}


x86 assembly (clang, -O0):
<eval_colors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dx,%ax
mov    %si,%cx
mov    %rdi,-0x8(%rbp)
mov    %cx,-0xa(%rbp)
mov    %ax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
movzwl -0xa(%rbp),%esi
call   1040 <unpack_rgb565@plt>
mov    -0x8(%rbp),%rdi
add    $0x3,%rdi
movzwl -0xc(%rbp),%esi
call   1040 <unpack_rgb565@plt>
movzwl -0xa(%rbp),%eax
movzwl -0xc(%rbp),%ecx
cmp    %ecx,%eax
jle    11a9 <eval_colors+0x89>
mov    -0x8(%rbp),%rdi
add    $0x6,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
add    $0x3,%rdx
mov    $0x55,%ecx
call   1030 <lerp_rgb@plt>
mov    -0x8(%rbp),%rdi
add    $0x9,%rdi
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
add    $0x3,%rdx
mov    $0xaa,%ecx
call   1030 <lerp_rgb@plt>
jmp    121a <eval_colors+0xfa>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    -0x8(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
add    %ecx,%eax
sar    $0x1,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%eax
mov    -0x8(%rbp),%rcx
movzbl 0x4(%rcx),%ecx
add    %ecx,%eax
sar    $0x1,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x8(%rbp),%rax
movzbl 0x2(%rax),%eax
mov    -0x8(%rbp),%rcx
movzbl 0x5(%rcx),%ecx
add    %ecx,%eax
sar    $0x1,%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0xb(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0xa(%rax)
mov    -0x8(%rbp),%rax
movb   $0x0,0x9(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_colors>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
call   1040 <unpack_rgb565@plt>
lea    0x3(%rbx),%r14
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <unpack_rgb565@plt>
cmp    %r15w,%bp
jbe    117b <eval_colors+0x5b>
lea    0x6(%rbx),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    $0x55,%ecx
call   1030 <lerp_rgb@plt>
lea    0x9(%rbx),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    $0xaa,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <lerp_rgb@plt>
movzbl (%rbx),%eax
movzbl 0x3(%rbx),%ecx
add    %eax,%ecx
shr    %ecx
mov    %cl,0x6(%rbx)
movzbl 0x1(%rbx),%eax
movzbl 0x4(%rbx),%ecx
add    %eax,%ecx
shr    %ecx
mov    %cl,0x7(%rbx)
movzbl 0x2(%rbx),%eax
movzbl 0x5(%rbx),%ecx
add    %eax,%ecx
shr    %ecx
mov    %cl,0x8(%rbx)
movb   $0x0,0xb(%rbx)
movw   $0x0,0x9(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @eval_colors([3 x i8]* %0, i16 zeroext %1, i16 zeroext %2) {
%4 = alloca [3 x i8]*
%5 = alloca i16
%6 = alloca i16
store [3 x i8]* %0, [3 x i8]** %4
store i16 %1, i16* %5
store i16 %2, i16* %6
%7 = load [3 x i8]*, [3 x i8]** %4
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %7, i64 0
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%10 = load i16, i16* %5
%11 = call i32 @unpack_rgb565(i8* %9, i16 zeroext %10)
%12 = load [3 x i8]*, [3 x i8]** %4
%13 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 1
%14 = getelementptr inbounds [3 x i8], [3 x i8]* %13, i64 0, i64 0
%15 = load i16, i16* %6
%16 = call i32 @unpack_rgb565(i8* %14, i16 zeroext %15)
%17 = load i16, i16* %5
%18 = zext i16 %17 to i32
%19 = load i16, i16* %6
%20 = zext i16 %19 to i32
%21 = icmp sgt i32 %18, %20
br i1 %21, label %22, label %43
22: ; preds = %3
%23 = load [3 x i8]*, [3 x i8]** %4
%24 = getelementptr inbounds [3 x i8], [3 x i8]* %23, i64 2
%25 = getelementptr inbounds [3 x i8], [3 x i8]* %24, i64 0, i64 0
%26 = load [3 x i8]*, [3 x i8]** %4
%27 = getelementptr inbounds [3 x i8], [3 x i8]* %26, i64 0
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %27, i64 0, i64 0
%29 = load [3 x i8]*, [3 x i8]** %4
%30 = getelementptr inbounds [3 x i8], [3 x i8]* %29, i64 1
%31 = getelementptr inbounds [3 x i8], [3 x i8]* %30, i64 0, i64 0
%32 = call i32 @lerp_rgb(i8* %25, i8* %28, i8* %31, i32 85)
%33 = load [3 x i8]*, [3 x i8]** %4
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %33, i64 3
%35 = getelementptr inbounds [3 x i8], [3 x i8]* %34, i64 0, i64 0
%36 = load [3 x i8]*, [3 x i8]** %4
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %36, i64 0
%38 = getelementptr inbounds [3 x i8], [3 x i8]* %37, i64 0, i64 0
%39 = load [3 x i8]*, [3 x i8]** %4
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %39, i64 1
%41 = getelementptr inbounds [3 x i8], [3 x i8]* %40, i64 0, i64 0
%42 = call i32 @lerp_rgb(i8* %35, i8* %38, i8* %41, i32 170)
br label %101
43: ; preds = %3
%44 = load [3 x i8]*, [3 x i8]** %4
%45 = getelementptr inbounds [3 x i8], [3 x i8]* %44, i64 0
%46 = getelementptr inbounds [3 x i8], [3 x i8]* %45, i64 0, i64 0
%47 = load i8, i8* %46
%48 = zext i8 %47 to i32
%49 = load [3 x i8]*, [3 x i8]** %4
%50 = getelementptr inbounds [3 x i8], [3 x i8]* %49, i64 1
%51 = getelementptr inbounds [3 x i8], [3 x i8]* %50, i64 0, i64 0
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = add nsw i32 %48, %53
%55 = ashr i32 %54, 1
%56 = trunc i32 %55 to i8
%57 = load [3 x i8]*, [3 x i8]** %4
%58 = getelementptr inbounds [3 x i8], [3 x i8]* %57, i64 2
%59 = getelementptr inbounds [3 x i8], [3 x i8]* %58, i64 0, i64 0
store i8 %56, i8* %59
%60 = load [3 x i8]*, [3 x i8]** %4
%61 = getelementptr inbounds [3 x i8], [3 x i8]* %60, i64 0
%62 = getelementptr inbounds [3 x i8], [3 x i8]* %61, i64 0, i64 1
%63 = load i8, i8* %62
%64 = zext i8 %63 to i32
%65 = load [3 x i8]*, [3 x i8]** %4
%66 = getelementptr inbounds [3 x i8], [3 x i8]* %65, i64 1
%67 = getelementptr inbounds [3 x i8], [3 x i8]* %66, i64 0, i64 1
%68 = load i8, i8* %67
%69 = zext i8 %68 to i32
%70 = add nsw i32 %64, %69
%71 = ashr i32 %70, 1
%72 = trunc i32 %71 to i8
%73 = load [3 x i8]*, [3 x i8]** %4
%74 = getelementptr inbounds [3 x i8], [3 x i8]* %73, i64 2
%75 = getelementptr inbounds [3 x i8], [3 x i8]* %74, i64 0, i64 1
store i8 %72, i8* %75
%76 = load [3 x i8]*, [3 x i8]** %4
%77 = getelementptr inbounds [3 x i8], [3 x i8]* %76, i64 0
%78 = getelementptr inbounds [3 x i8], [3 x i8]* %77, i64 0, i64 2
%79 = load i8, i8* %78
%80 = zext i8 %79 to i32
%81 = load [3 x i8]*, [3 x i8]** %4
%82 = getelementptr inbounds [3 x i8], [3 x i8]* %81, i64 1
%83 = getelementptr inbounds [3 x i8], [3 x i8]* %82, i64 0, i64 2
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = add nsw i32 %80, %85
%87 = ashr i32 %86, 1
%88 = trunc i32 %87 to i8
%89 = load [3 x i8]*, [3 x i8]** %4
%90 = getelementptr inbounds [3 x i8], [3 x i8]* %89, i64 2
%91 = getelementptr inbounds [3 x i8], [3 x i8]* %90, i64 0, i64 2
store i8 %88, i8* %91
%92 = load [3 x i8]*, [3 x i8]** %4
%93 = getelementptr inbounds [3 x i8], [3 x i8]* %92, i64 3
%94 = getelementptr inbounds [3 x i8], [3 x i8]* %93, i64 0, i64 2
store i8 0, i8* %94
%95 = load [3 x i8]*, [3 x i8]** %4
%96 = getelementptr inbounds [3 x i8], [3 x i8]* %95, i64 3
%97 = getelementptr inbounds [3 x i8], [3 x i8]* %96, i64 0, i64 1
store i8 0, i8* %97
%98 = load [3 x i8]*, [3 x i8]** %4
%99 = getelementptr inbounds [3 x i8], [3 x i8]* %98, i64 3
%100 = getelementptr inbounds [3 x i8], [3 x i8]* %99, i64 0, i64 0
store i8 0, i8* %100
br label %101
101: ; preds = %43, %22
ret void
}

LLVM IR (-O2):
define void @eval_colors([3 x i8]* %0, i16 zeroext %1, i16 zeroext %2) {
%4 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 0, i64 0
%5 = tail call i32 @unpack_rgb565(i8* %4, i16 zeroext %1)
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 1, i64 0
%7 = tail call i32 @unpack_rgb565(i8* %6, i16 zeroext %2)
%8 = icmp ugt i16 %1, %2
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 2, i64 0
%11 = tail call i32 @lerp_rgb(i8* %10, i8* %4, i8* %6, i32 85)
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 3, i64 0
%13 = tail call i32 @lerp_rgb(i8* %12, i8* %4, i8* %6, i32 170)
br label %46
14: ; preds = %3
%15 = load i8, i8* %4
%16 = zext i8 %15 to i16
%17 = load i8, i8* %6
%18 = zext i8 %17 to i16
%19 = add nuw nsw i16 %18, %16
%20 = lshr i16 %19, 1
%21 = trunc i16 %20 to i8
%22 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 2, i64 0
store i8 %21, i8* %22
%23 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 0, i64 1
%24 = load i8, i8* %23
%25 = zext i8 %24 to i16
%26 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 1, i64 1
%27 = load i8, i8* %26
%28 = zext i8 %27 to i16
%29 = add nuw nsw i16 %28, %25
%30 = lshr i16 %29, 1
%31 = trunc i16 %30 to i8
%32 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 2, i64 1
store i8 %31, i8* %32
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 0, i64 2
%34 = load i8, i8* %33
%35 = zext i8 %34 to i16
%36 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 1, i64 2
%37 = load i8, i8* %36
%38 = zext i8 %37 to i16
%39 = add nuw nsw i16 %38, %35
%40 = lshr i16 %39, 1
%41 = trunc i16 %40 to i8
%42 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 2, i64 2
store i8 %41, i8* %42
%43 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 3, i64 2
store i8 0, i8* %43
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 3, i64 1
store i8 0, i8* %44
%45 = getelementptr inbounds [3 x i8], [3 x i8]* %0, i64 3, i64 0
store i8 0, i8* %45
br label %46
46: ; preds = %14, %9
ret void
}