#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*/ WINDOW;

/* Variables and functions */
int /*<<< orphan*/ A_BLINK;
int /*<<< orphan*/ A_BOLD;
int /*<<< orphan*/ A_NORMAL;
int /*<<< orphan*/ COLOR_PAIR(int);
int /*<<< orphan*/ wattron(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ wattrset(int /*<<< orphan*/ *, int /*<<< orphan*/);
void curutil_attrset(WINDOW *win, unsigned char attr) {
  int fg = (attr & 0x70) >> 4;
  int bg = attr & 0x07;
  int cp = bg * 8 + 7 - fg;
  if (cp)
    wattrset(win, COLOR_PAIR(cp));
  else
    wattrset(win, A_NORMAL);
  if (attr & 0x80)
    wattron(win, A_BOLD);
  if (attr & 0x08)
    wattron(win, A_BLINK);
}


x86 assembly (clang, -O0):
<curutil_attrset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x70,%eax
sar    $0x4,%eax
mov    %eax,-0x10(%rbp)
movzbl -0x9(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
add    $0x7,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1192 <curutil_attrset+0x62>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <COLOR_PAIR@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
call   1030 <wattrset@plt>
jmp    11a4 <curutil_attrset+0x74>
mov    -0x8(%rbp),%rdi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
call   1030 <wattrset@plt>
movzbl -0x9(%rbp),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     11c8 <curutil_attrset+0x98>
mov    -0x8(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
call   1050 <wattron@plt>
movzbl -0x9(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11ea <curutil_attrset+0xba>
mov    -0x8(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
call   1050 <wattron@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<curutil_attrset>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%eax
shr    $0x4,%eax
and    $0x7,%eax
mov    %esi,%ecx
and    $0x7,%ecx
lea    0x7(,%rcx,8),%edi
sub    %eax,%edi
je     1159 <curutil_attrset+0x29>
call   1040 <COLOR_PAIR@plt>
mov    %eax,%esi
jmp    1162 <curutil_attrset+0x32>
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <wattrset@plt>
test   $0x80,%bpl
je     1181 <curutil_attrset+0x51>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <wattron@plt>
test   $0x8,%bpl
jne    118e <curutil_attrset+0x5e>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <wattron@plt>

LLVM IR (-O0):
@A_NORMAL = global i32 0
@A_BOLD = global i32 0
@A_BLINK = global i32 0
define void @curutil_attrset(i32* %0, i8 zeroext %1) {
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i8 %1, i8* %4
%8 = load i8, i8* %4
%9 = zext i8 %8 to i32
%10 = and i32 %9, 112
%11 = ashr i32 %10, 4
store i32 %11, i32* %5
%12 = load i8, i8* %4
%13 = zext i8 %12 to i32
%14 = and i32 %13, 7
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = mul nsw i32 %15, 8
%17 = add nsw i32 %16, 7
%18 = load i32, i32* %5
%19 = sub nsw i32 %17, %18
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i32*, i32** %3
%24 = load i32, i32* %7
%25 = call i32 @COLOR_PAIR(i32 %24)
%26 = call i32 @wattrset(i32* %23, i32 %25)
br label %31
27: ; preds = %2
%28 = load i32*, i32** %3
%29 = load i32, i32* @A_NORMAL
%30 = call i32 @wattrset(i32* %28, i32 %29)
br label %31
31: ; preds = %27, %22
%32 = load i8, i8* %4
%33 = zext i8 %32 to i32
%34 = and i32 %33, 128
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32*, i32** %3
%38 = load i32, i32* @A_BOLD
%39 = call i32 @wattron(i32* %37, i32 %38)
br label %40
40: ; preds = %36, %31
%41 = load i8, i8* %4
%42 = zext i8 %41 to i32
%43 = and i32 %42, 8
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %40
%46 = load i32*, i32** %3
%47 = load i32, i32* @A_BLINK
%48 = call i32 @wattron(i32* %46, i32 %47)
br label %49
49: ; preds = %45, %40
ret void
}

LLVM IR (-O2):
@A_NORMAL = global i32 0
@A_BOLD = global i32 0
@A_BLINK = global i32 0
define void @curutil_attrset(i32* %0, i8 zeroext %1) {
%3 = zext i8 %1 to i32
%4 = lshr i32 %3, 4
%5 = and i32 %4, 7
%6 = shl nuw nsw i32 %3, 3
%7 = and i32 %6, 56
%8 = or i32 %7, 7
%9 = sub nuw nsw i32 %8, %5
%10 = icmp eq i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @COLOR_PAIR(i32 %9)
br label %15
13: ; preds = %2
%14 = load i32, i32* @A_NORMAL
br label %15
15: ; preds = %13, %11
%16 = phi i32 [ %14, %13 ], [ %12, %11 ]
%17 = tail call i32 @wattrset(i32* %0, i32 %16)
%18 = and i32 %3, 128
%19 = icmp eq i32 %18, 0
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i32, i32* @A_BOLD
%22 = tail call i32 @wattron(i32* %0, i32 %21)
br label %23
23: ; preds = %20, %15
%24 = and i32 %3, 8
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* @A_BLINK
%28 = tail call i32 @wattron(i32* %0, i32 %27)
br label %29
29: ; preds = %26, %23
ret void
}