#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 */
short COLOR_WHITE;
short CSLP_GetCurrentPair();
int CSLP_GetBackgroundColor() {
  short pair = CSLP_GetCurrentPair();
  if (pair == 0) {
    return 0;
  }
  pair--;
  if (pair == COLOR_WHITE) {
    return COLOR_WHITE;
  }
  return (pair & (0x07 << 3)) >> 3;
}


x86 assembly (clang, -O0):
<CSLP_GetBackgroundColor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <CSLP_GetCurrentPair@plt>
mov    %ax,-0x6(%rbp)
movswl -0x6(%rbp),%eax
cmp    $0x0,%eax
jne    113c <CSLP_GetBackgroundColor+0x2c>
movl   $0x0,-0x4(%rbp)
jmp    117d <CSLP_GetBackgroundColor+0x6d>
mov    -0x6(%rbp),%ax
add    $0xffff,%ax
mov    %ax,-0x6(%rbp)
movswl -0x6(%rbp),%eax
mov    0x2e8d(%rip),%rcx
movswl (%rcx),%ecx
cmp    %ecx,%eax
jne    1170 <CSLP_GetBackgroundColor+0x60>
mov    0x2e7b(%rip),%rax
movswl (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    117d <CSLP_GetBackgroundColor+0x6d>
movswl -0x6(%rbp),%eax
and    $0x38,%eax
sar    $0x3,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CSLP_GetBackgroundColor>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <CSLP_GetCurrentPair@plt>
test   %ax,%ax
je     113b <CSLP_GetBackgroundColor+0x2b>
add    $0xffffffff,%eax
mov    0x2eb7(%rip),%rcx
cmp    (%rcx),%ax
jne    1133 <CSLP_GetBackgroundColor+0x23>
movswl %ax,%ebx
jmp    113b <CSLP_GetBackgroundColor+0x2b>
shr    $0x3,%eax
and    $0x7,%eax
mov    %eax,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@COLOR_WHITE = global i16 0
define i32 @CSLP_GetBackgroundColor() {
%1 = alloca i32
%2 = alloca i16
%3 = call signext i16 (...) @CSLP_GetCurrentPair()
store i16 %3, i16* %2
%4 = load i16, i16* %2
%5 = sext i16 %4 to i32
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 0, i32* %1
br label %24
8: ; preds = %0
%9 = load i16, i16* %2
%10 = add i16 %9, -1
store i16 %10, i16* %2
%11 = load i16, i16* %2
%12 = sext i16 %11 to i32
%13 = load i16, i16* @COLOR_WHITE
%14 = sext i16 %13 to i32
%15 = icmp eq i32 %12, %14
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = load i16, i16* @COLOR_WHITE
%18 = sext i16 %17 to i32
store i32 %18, i32* %1
br label %24
19: ; preds = %8
%20 = load i16, i16* %2
%21 = sext i16 %20 to i32
%22 = and i32 %21, 56
%23 = ashr i32 %22, 3
store i32 %23, i32* %1
br label %24
24: ; preds = %19, %16, %7
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@COLOR_WHITE = global i16 0
define i32 @CSLP_GetBackgroundColor() {
%1 = tail call signext i16 (...) @CSLP_GetCurrentPair()
%2 = icmp eq i16 %1, 0
br i1 %2, label %13, label %3
3: ; preds = %0
%4 = add i16 %1, -1
%5 = load i16, i16* @COLOR_WHITE
%6 = icmp eq i16 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = sext i16 %4 to i32
br label %13
9: ; preds = %3
%10 = lshr i16 %4, 3
%11 = and i16 %10, 7
%12 = zext i16 %11 to i32
br label %13
13: ; preds = %0, %9, %7
%14 = phi i32 [ %8, %7 ], [ %12, %9 ], [ 0, %0 ]
ret i32 %14
}