#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 luminance(unsigned char const *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
unsigned short pack_rgb565(unsigned char *);
void get_min_max_colors_luminance(const unsigned char *block,
                                  unsigned short *max16,
                                  unsigned short *min16) {
  int i, lum, minlum = 0x7fffffff, maxlum = -0x7fffffff;
  unsigned char mn[3], mx[3];
  for (i = 0; i < 16; ++i) {
    lum = luminance(&block[4 * i]);
    if (lum > maxlum) {
      maxlum = lum;
      memcpy(mx, &block[4 * i], 3);
    }
    if (lum < minlum) {
      minlum = lum;
      memcpy(mn, &block[4 * i], 3);
    }
  }
  *max16 = pack_rgb565(mx);
  *min16 = pack_rgb565(mn);
}


x86 assembly (clang, -O0):
<get_min_max_colors_luminance>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x7fffffff,-0x24(%rbp)
movl   $0x80000001,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    11eb <get_min_max_colors_luminance+0xbb>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
cltq
add    %rax,%rdi
call   1040 <luminance@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jle    11a9 <get_min_max_colors_luminance+0x79>
mov    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
lea    -0x2e(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
cltq
add    %rax,%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    11d8 <get_min_max_colors_luminance+0xa8>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    -0x2b(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%eax
shl    $0x2,%eax
cltq
add    %rax,%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
jmp    11dd <get_min_max_colors_luminance+0xad>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1159 <get_min_max_colors_luminance+0x29>
lea    -0x2e(%rbp),%rdi
call   1030 <pack_rgb565@plt>
mov    %ax,%cx
mov    -0x10(%rbp),%rax
mov    %cx,(%rax)
lea    -0x2b(%rbp),%rdi
call   1030 <pack_rgb565@plt>
mov    %ax,%cx
mov    -0x18(%rbp),%rax
mov    %cx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_min_max_colors_luminance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbx
mov    $0x7fffffff,%r12d
mov    $0x80000001,%r13d
xor    %r15d,%r15d
jmp    116a <get_min_max_colors_luminance+0x3a>
nopl   0x0(%rax)
add    $0x4,%r15
cmp    $0x40,%r15
je     11af <get_min_max_colors_luminance+0x7f>
lea    (%rbx,%r15,1),%rbp
mov    %rbp,%rdi
call   1040 <luminance@plt>
mov    %eax,%r14d
cmp    %r13d,%eax
jle    1193 <get_min_max_colors_luminance+0x63>
lea    0x2(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
mov    %r14d,%r13d
cmp    %r12d,%r14d
jge    1160 <get_min_max_colors_luminance+0x30>
lea    0x5(%rsp),%rdi
mov    %rbp,%rsi
mov    $0x3,%edx
call   1050 <memcpy@plt>
mov    %r14d,%r12d
jmp    1160 <get_min_max_colors_luminance+0x30>
lea    0x2(%rsp),%rdi
call   1030 <pack_rgb565@plt>
mov    0x8(%rsp),%rcx
mov    %ax,(%rcx)
lea    0x5(%rsp),%rdi
call   1030 <pack_rgb565@plt>
mov    0x10(%rsp),%rcx
mov    %ax,(%rcx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @get_min_max_colors_luminance(i8* %0, i16* %1, i16* %2) {
%4 = alloca i8*
%5 = alloca i16*
%6 = alloca i16*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [3 x i8]
%12 = alloca [3 x i8]
store i8* %0, i8** %4
store i16* %1, i16** %5
store i16* %2, i16** %6
store i32 2147483647, i32* %9
store i32 -2147483647, i32* %10
store i32 0, i32* %7
br label %13
13: ; preds = %49, %3
%14 = load i32, i32* %7
%15 = icmp slt i32 %14, 16
br i1 %15, label %16, label %52
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = load i32, i32* %7
%19 = mul nsw i32 4, %18
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
%22 = call i32 @luminance(i8* %21)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* %10
%25 = icmp sgt i32 %23, %24
br i1 %25, label %26, label %35
26: ; preds = %16
%27 = load i32, i32* %8
store i32 %27, i32* %10
%28 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = load i32, i32* %7
%31 = mul nsw i32 4, %30
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = call i32 @memcpy(i8* %28, i8* %33, i32 3)
br label %35
35: ; preds = %26, %16
%36 = load i32, i32* %8
%37 = load i32, i32* %9
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = load i32, i32* %8
store i32 %40, i32* %9
%41 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%42 = load i8*, i8** %4
%43 = load i32, i32* %7
%44 = mul nsw i32 4, %43
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
%47 = call i32 @memcpy(i8* %41, i8* %46, i32 3)
br label %48
48: ; preds = %39, %35
br label %49
49: ; preds = %48
%50 = load i32, i32* %7
%51 = add nsw i32 %50, 1
store i32 %51, i32* %7
br label %13
52: ; preds = %13
%53 = getelementptr inbounds [3 x i8], [3 x i8]* %12, i64 0, i64 0
%54 = call zeroext i16 @pack_rgb565(i8* %53)
%55 = load i16*, i16** %5
store i16 %54, i16* %55
%56 = getelementptr inbounds [3 x i8], [3 x i8]* %11, i64 0, i64 0
%57 = call zeroext i16 @pack_rgb565(i8* %56)
%58 = load i16*, i16** %6
store i16 %57, i16* %58
ret void
}

LLVM IR (-O2):
define void @get_min_max_colors_luminance(i8* %0, i16* nocapture writeonly %1, i16* nocapture writeonly %2) {
%4 = alloca [3 x i8]
%5 = alloca [3 x i8]
%6 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
br label %8
8: ; preds = %3, %23
%9 = phi i64 [ 0, %3 ], [ %25, %23 ]
%10 = phi i32 [ -2147483647, %3 ], [ %19, %23 ]
%11 = phi i32 [ 2147483647, %3 ], [ %24, %23 ]
%12 = shl nuw nsw i64 %9, 2
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = call i32 @luminance(i8* %13)
%15 = icmp sgt i32 %14, %10
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @memcpy(i8* %7, i8* %13, i32 3)
br label %18
18: ; preds = %16, %8
%19 = phi i32 [ %14, %16 ], [ %10, %8 ]
%20 = icmp slt i32 %14, %11
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @memcpy(i8* %6, i8* %13, i32 3)
br label %23
23: ; preds = %18, %21
%24 = phi i32 [ %14, %21 ], [ %11, %18 ]
%25 = add nuw nsw i64 %9, 1
%26 = icmp eq i64 %25, 16
br i1 %26, label %27, label %8
27: ; preds = %23
%28 = call zeroext i16 @pack_rgb565(i8* %7)
store i16 %28, i16* %1
%29 = call zeroext i16 @pack_rgb565(i8* %6)
store i16 %29, i16* %2
ret void
}