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

/* Variables and functions */
int /*<<< orphan*/ log_error(char *, int);
int /*<<< orphan*/ panel_if_set_rgb(int, int);
void panel_set_bl_led(int led, int state) {
  int32_t color = 0;
  if (led < 0 || led > 1) {
    log_error("psbl - led invalid: %d", led);
    return;
  }
  if (state & 0x01) {
    color |= 0x0000ff;
  }
  if (state & 0x02) {
    color |= 0x00ff00;
  }
  if (state & 0x04) {
    color |= 0xff0000;
  }
  panel_if_set_rgb(led, color);
}


x86 assembly (clang, -O0):
<panel_set_bl_led>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1149 <panel_set_bl_led+0x29>
cmpl   $0x1,-0x4(%rbp)
jle    115d <panel_set_bl_led+0x3d>
mov    -0x4(%rbp),%esi
lea    0xead(%rip),%rdi
call   1030 <log_error@plt>
jmp    11b6 <panel_set_bl_led+0x96>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1177 <panel_set_bl_led+0x57>
mov    -0xc(%rbp),%eax
or     $0xff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1191 <panel_set_bl_led+0x71>
mov    -0xc(%rbp),%eax
or     $0xff00,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     11ab <panel_set_bl_led+0x8b>
mov    -0xc(%rbp),%eax
or     $0xff0000,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1040 <panel_if_set_rgb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<panel_set_bl_led>:
mov    %edi,%eax
cmp    $0x2,%edi
jb     1135 <panel_set_bl_led+0x15>
lea    0xed2(%rip),%rdi
mov    %eax,%esi
jmp    1030 <log_error@plt>
mov    %esi,%ecx
and    $0x1,%ecx
neg    %ecx
movzbl %cl,%ecx
lea    0xff00(%rcx),%edx
test   $0x2,%sil
cmove  %ecx,%edx
lea    0xff0000(%rdx),%ecx
test   $0x4,%sil
cmove  %edx,%ecx
mov    %eax,%edi
mov    %ecx,%esi
jmp    1040 <panel_if_set_rgb@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"psbl - led invalid: %d\00"
define void @panel_set_bl_led(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32, i32* %3
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %8, %2
%12 = load i32, i32* %3
%13 = call i32 @log_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %39
14: ; preds = %8
%15 = load i32, i32* %4
%16 = and i32 %15, 1
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %14
%19 = load i32, i32* %5
%20 = or i32 %19, 255
store i32 %20, i32* %5
br label %21
21: ; preds = %18, %14
%22 = load i32, i32* %4
%23 = and i32 %22, 2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i32, i32* %5
%27 = or i32 %26, 65280
store i32 %27, i32* %5
br label %28
28: ; preds = %25, %21
%29 = load i32, i32* %4
%30 = and i32 %29, 4
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i32, i32* %5
%34 = or i32 %33, 16711680
store i32 %34, i32* %5
br label %35
35: ; preds = %32, %28
%36 = load i32, i32* %3
%37 = load i32, i32* %5
%38 = call i32 @panel_if_set_rgb(i32 %36, i32 %37)
br label %39
39: ; preds = %35, %11
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"psbl - led invalid: %d\00"
define void @panel_set_bl_led(i32 %0, i32 %1) {
%3 = icmp ugt i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @log_error(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %19
6: ; preds = %2
%7 = and i32 %1, 1
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i32 0, i32 255
%10 = and i32 %1, 2
%11 = icmp eq i32 %10, 0
%12 = or i32 %9, 65280
%13 = select i1 %11, i32 %9, i32 %12
%14 = and i32 %1, 4
%15 = icmp eq i32 %14, 0
%16 = or i32 %13, 16711680
%17 = select i1 %15, i32 %13, i32 %16
%18 = tail call i32 @panel_if_set_rgb(i32 %0, i32 %17)
br label %19
19: ; preds = %6, %4
ret void
}