#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 uint8_t;

/* Variables and functions */
int CharProp2Color(int);
int ReverseColor(int);
uint8_t GetColorFromProp(uint8_t prop) {
  uint8_t fore0, back0, fore1, back1;
  fore0 = prop & 0x0f;
  back0 = ((prop & 0x70) >> 4);
  fore1 = CharProp2Color(fore0);
  back1 = CharProp2Color(back0);
  if (fore0 != back0 && fore1 == back1) {
    fore1 = ReverseColor(fore1);
  }
  return (fore1 * 8 + back1);
}


x86 assembly (clang, -O0):
<GetColorFromProp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x70,%eax
sar    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <CharProp2Color@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <CharProp2Color@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     1179 <GetColorFromProp+0x59>
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1179 <GetColorFromProp+0x59>
mov    -0x10(%rbp),%edi
call   1040 <ReverseColor@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x3,%eax
add    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetColorFromProp>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    %edi,%ebx
and    $0xf,%ebx
shr    $0x4,%ebp
and    $0x7,%ebp
mov    %ebx,%edi
call   1030 <CharProp2Color@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1030 <CharProp2Color@plt>
mov    %eax,%r14d
cmp    %ebp,%ebx
je     115c <GetColorFromProp+0x3c>
cmp    %r14d,%r15d
jne    115c <GetColorFromProp+0x3c>
mov    %r15d,%edi
call   1040 <ReverseColor@plt>
mov    %eax,%r15d
lea    (%r14,%r15,8),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @GetColorFromProp(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = and i32 %7, 15
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = and i32 %9, 112
%11 = ashr i32 %10, 4
store i32 %11, i32* %4
%12 = load i32, i32* %3
%13 = call i32 @CharProp2Color(i32 %12)
store i32 %13, i32* %5
%14 = load i32, i32* %4
%15 = call i32 @CharProp2Color(i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %26
19: ; preds = %1
%20 = load i32, i32* %5
%21 = load i32, i32* %6
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = load i32, i32* %5
%25 = call i32 @ReverseColor(i32 %24)
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %19, %1
%27 = load i32, i32* %5
%28 = mul nsw i32 %27, 8
%29 = load i32, i32* %6
%30 = add nsw i32 %28, %29
ret i32 %30
}

LLVM IR (-O2):
define i32 @GetColorFromProp(i32 %0) {
%2 = and i32 %0, 15
%3 = lshr i32 %0, 4
%4 = and i32 %3, 7
%5 = tail call i32 @CharProp2Color(i32 %2)
%6 = tail call i32 @CharProp2Color(i32 %4)
%7 = icmp ne i32 %2, %4
%8 = icmp eq i32 %5, %6
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @ReverseColor(i32 %5)
br label %12
12: ; preds = %10, %1
%13 = phi i32 [ %11, %10 ], [ %5, %1 ]
%14 = shl nsw i32 %13, 3
%15 = add nsw i32 %14, %6
ret i32 %15
}