#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 */
typedef int /*<<< orphan*/ v;
typedef int int32_t;

/* Variables and functions */
int Color_distance2(int, int);
int Color_distance3(int, int);
int32_t a_Color_vc(int32_t candidate, int32_t C_txt, int32_t C_lnk,
                   int32_t C_bg) {
  static int32_t v[] = {0x000000, 0x800080, 0x008b8b, 0x8b008b,
                        0x808000, 0x8b0000, 0xff7f50, 0x000000};
  int v_size = sizeof(v) / sizeof(v[0]);
  int i, max_i, score, max_score, d_bg, d_txt, d_lnk;
  v[0] = candidate;
  max_i = max_score = 0;
  for (i = 0; i < v_size; ++i) {

    ;
    d_txt = Color_distance2(C_txt, v[i]);
    d_lnk = Color_distance2(C_lnk, v[i]);
    d_bg = Color_distance2(C_bg, v[i]);
    score = (d_bg >= 2 ? 4 : 2 * d_bg) +
            (d_txt + d_lnk >= 2 ? 2 : d_txt + d_lnk) +
            (Color_distance3(C_lnk, v[i]) >= 1 ? 1 : 0);
    if (score >= 7) {
      max_i = i;
      break;
    } else if (score > max_score) {
      max_score = score;
      max_i = i;
    }
  }
  return v[max_i];
}


x86 assembly (clang, -O0):
<a_Color_vc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
movl   $0x8,-0x14(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,0x2efc(%rip)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1278 <a_Color_vc+0x158>
mov    -0x8(%rbp),%edi
movslq -0x18(%rbp),%rcx
lea    0x2ecd(%rip),%rax
mov    (%rax,%rcx,4),%esi
call   1040 <Color_distance2@plt>
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%edi
movslq -0x18(%rbp),%rcx
lea    0x2eb4(%rip),%rax
mov    (%rax,%rcx,4),%esi
call   1040 <Color_distance2@plt>
mov    %eax,-0x30(%rbp)
mov    -0x10(%rbp),%edi
movslq -0x18(%rbp),%rcx
lea    0x2e9b(%rip),%rax
mov    (%rax,%rcx,4),%esi
call   1040 <Color_distance2@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
jl     11c7 <a_Color_vc+0xa7>
mov    $0x4,%eax
mov    %eax,-0x34(%rbp)
jmp    11d0 <a_Color_vc+0xb0>
mov    -0x28(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
cmp    $0x2,%eax
jl     11f2 <a_Color_vc+0xd2>
mov    $0x2,%eax
mov    %eax,-0x3c(%rbp)
jmp    11fb <a_Color_vc+0xdb>
mov    -0x2c(%rbp),%eax
add    -0x30(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x3c(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x40(%rbp)
mov    -0xc(%rbp),%edi
movslq -0x18(%rbp),%rcx
lea    0x2e2c(%rip),%rax
mov    (%rax,%rcx,4),%esi
call   1030 <Color_distance3@plt>
mov    %eax,%esi
mov    -0x40(%rbp),%eax
xor    %ecx,%ecx
mov    $0x1,%edx
cmp    $0x1,%esi
cmovge %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x7,-0x20(%rbp)
jl     1248 <a_Color_vc+0x128>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1278 <a_Color_vc+0x158>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jle    1260 <a_Color_vc+0x140>
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    1265 <a_Color_vc+0x145>
jmp    126a <a_Color_vc+0x14a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1159 <a_Color_vc+0x39>
movslq -0x1c(%rbp),%rcx
lea    0x2dbd(%rip),%rax
mov    (%rax,%rcx,4),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<a_Color_vc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,0x14(%rsp)
mov    %edx,0x10(%rsp)
mov    %esi,0xc(%rsp)
mov    %edi,%esi
mov    %edi,0x2efe(%rip)
xor    %r14d,%r14d
lea    0x2ef4(%rip),%rbp
xor    %r15d,%r15d
movl   $0x0,0x8(%rsp)
mov    0x10(%rsp),%r13d
nopl   0x0(%rax)
mov    0xc(%rsp),%edi
call   1040 <Color_distance2@plt>
mov    %eax,%r12d
mov    0x0(%rbp,%r14,4),%esi
mov    %r13d,%edi
call   1040 <Color_distance2@plt>
mov    %eax,%ebx
mov    0x0(%rbp,%r14,4),%esi
mov    0x14(%rsp),%edi
call   1040 <Color_distance2@plt>
lea    (%rax,%rax,1),%ecx
cmp    $0x2,%eax
mov    $0x4,%eax
cmovge %eax,%ecx
add    %r12d,%ebx
cmp    $0x2,%ebx
mov    $0x2,%eax
cmovge %eax,%ebx
add    %ecx,%ebx
mov    %rbp,%r12
mov    0x0(%rbp,%r14,4),%esi
mov    %r13d,%edi
call   1030 <Color_distance3@plt>
xor    %ecx,%ecx
test   %eax,%eax
setg   %cl
add    %ebx,%ecx
cmp    $0x6,%ecx
jg     11ef <a_Color_vc+0xcf>
mov    0x8(%rsp),%eax
cmp    %eax,%ecx
cmovg  %r14d,%r15d
cmp    $0x7,%r14
je     11f2 <a_Color_vc+0xd2>
cmp    %eax,%ecx
cmovg  %ecx,%eax
mov    %eax,0x8(%rsp)
mov    %r12,%rbp
mov    0x4(%r12,%r14,4),%esi
add    $0x1,%r14
jmp    1160 <a_Color_vc+0x40>
mov    %r14d,%r15d
movslq %r15d,%rax
mov    (%r12,%rax,4),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@a_Color_vc.v = internal global [8 x i32] [i32 0, i32 8388736, i32 35723, i32 9109643, i32 8421376, i32 9109504, i32 16744272, i32 0]
define i32 @a_Color_vc(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i32 8, i32* %9
%17 = load i32, i32* %5
store i32 %17, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 0)
store i32 0, i32* %13
store i32 0, i32* %11
store i32 0, i32* %10
br label %18
18: ; preds = %84, %4
%19 = load i32, i32* %10
%20 = load i32, i32* %9
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %87
22: ; preds = %18
%23 = load i32, i32* %6
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = call i32 @Color_distance2(i32 %23, i32 %27)
store i32 %28, i32* %15
%29 = load i32, i32* %7
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @Color_distance2(i32 %29, i32 %33)
store i32 %34, i32* %16
%35 = load i32, i32* %8
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 %37
%39 = load i32, i32* %38
%40 = call i32 @Color_distance2(i32 %35, i32 %39)
store i32 %40, i32* %14
%41 = load i32, i32* %14
%42 = icmp sge i32 %41, 2
br i1 %42, label %43, label %44
43: ; preds = %22
br label %47
44: ; preds = %22
%45 = load i32, i32* %14
%46 = mul nsw i32 2, %45
br label %47
47: ; preds = %44, %43
%48 = phi i32 [ 4, %43 ], [ %46, %44 ]
%49 = load i32, i32* %15
%50 = load i32, i32* %16
%51 = add nsw i32 %49, %50
%52 = icmp sge i32 %51, 2
br i1 %52, label %53, label %54
53: ; preds = %47
br label %58
54: ; preds = %47
%55 = load i32, i32* %15
%56 = load i32, i32* %16
%57 = add nsw i32 %55, %56
br label %58
58: ; preds = %54, %53
%59 = phi i32 [ 2, %53 ], [ %57, %54 ]
%60 = add nsw i32 %48, %59
%61 = load i32, i32* %7
%62 = load i32, i32* %10
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 %63
%65 = load i32, i32* %64
%66 = call i32 @Color_distance3(i32 %61, i32 %65)
%67 = icmp sge i32 %66, 1
%68 = zext i1 %67 to i64
%69 = select i1 %67, i32 1, i32 0
%70 = add nsw i32 %60, %69
store i32 %70, i32* %12
%71 = load i32, i32* %12
%72 = icmp sge i32 %71, 7
br i1 %72, label %73, label %75
73: ; preds = %58
%74 = load i32, i32* %10
store i32 %74, i32* %11
br label %87
75: ; preds = %58
%76 = load i32, i32* %12
%77 = load i32, i32* %13
%78 = icmp sgt i32 %76, %77
br i1 %78, label %79, label %82
79: ; preds = %75
%80 = load i32, i32* %12
store i32 %80, i32* %13
%81 = load i32, i32* %10
store i32 %81, i32* %11
br label %82
82: ; preds = %79, %75
br label %83
83: ; preds = %82
br label %84
84: ; preds = %83
%85 = load i32, i32* %10
%86 = add nsw i32 %85, 1
store i32 %86, i32* %10
br label %18
87: ; preds = %73, %18
%88 = load i32, i32* %11
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 %89
%91 = load i32, i32* %90
ret i32 %91
}

LLVM IR (-O2):
@a_Color_vc.v = internal unnamed_addr global [8 x i32] [i32 0, i32 8388736, i32 35723, i32 9109643, i32 8421376, i32 9109504, i32 16744272, i32 0]
define i32 @a_Color_vc(i32 %0, i32 %1, i32 %2, i32 %3) {
store i32 %0, i32* getelementptr inbounds ([8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 0)
br label %5
5: ; preds = %35, %4
%6 = phi i32 [ %0, %4 ], [ %38, %35 ]
%7 = phi i64 [ 0, %4 ], [ %33, %35 ]
%8 = phi i32 [ 0, %4 ], [ %32, %35 ]
%9 = phi i32 [ 0, %4 ], [ %36, %35 ]
%10 = getelementptr inbounds [8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 %7
%11 = tail call i32 @Color_distance2(i32 %1, i32 %6)
%12 = load i32, i32* %10
%13 = tail call i32 @Color_distance2(i32 %2, i32 %12)
%14 = load i32, i32* %10
%15 = tail call i32 @Color_distance2(i32 %3, i32 %14)
%16 = icmp sgt i32 %15, 1
%17 = shl nsw i32 %15, 1
%18 = select i1 %16, i32 4, i32 %17
%19 = add nsw i32 %13, %11
%20 = icmp slt i32 %19, 2
%21 = select i1 %20, i32 %19, i32 2
%22 = add nsw i32 %18, %21
%23 = load i32, i32* %10
%24 = tail call i32 @Color_distance3(i32 %2, i32 %23)
%25 = icmp sgt i32 %24, 0
%26 = zext i1 %25 to i32
%27 = add nsw i32 %22, %26
%28 = icmp sgt i32 %27, 6
%29 = trunc i64 %7 to i32
br i1 %28, label %39, label %30
30: ; preds = %5
%31 = icmp sgt i32 %27, %9
%32 = select i1 %31, i32 %29, i32 %8
%33 = add nuw nsw i64 %7, 1
%34 = icmp eq i64 %33, 8
br i1 %34, label %41, label %35
35: ; preds = %30
%36 = select i1 %31, i32 %27, i32 %9
%37 = getelementptr inbounds [8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 %33
%38 = load i32, i32* %37
br label %5
39: ; preds = %5
%40 = trunc i64 %7 to i32
br label %41
41: ; preds = %30, %39
%42 = phi i32 [ %40, %39 ], [ %32, %30 ]
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [8 x i32], [8 x i32]* @a_Color_vc.v, i64 0, i64 %43
%45 = load i32, i32* %44
ret i32 %45
}