#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 */
int /*<<< orphan*/ log_error(char *, int);
int /*<<< orphan*/ panel_set_led(int, int);
void panel_update_track_led(int track, int state) {
  static int oldstate[6] = {0};
  if (track < 0 || track >= 6) {
    log_error("putl - track invalid: %d", track);
    return;
  }
  if (state != oldstate[track]) {
    if (state) {
      panel_set_led(2 + track, 2);
    } else {
      panel_set_led(2 + track, 0);
    }
    oldstate[track] = state;
  }
}


x86 assembly (clang, -O0):
<panel_update_track_led>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1142 <panel_update_track_led+0x22>
cmpl   $0x6,-0x4(%rbp)
jl     1156 <panel_update_track_led+0x36>
mov    -0x4(%rbp),%esi
lea    0xeb4(%rip),%rdi
call   1030 <log_error@plt>
jmp    11aa <panel_update_track_led+0x8a>
mov    -0x8(%rbp),%eax
movslq -0x4(%rbp),%rdx
lea    0x2edc(%rip),%rcx
cmp    (%rcx,%rdx,4),%eax
je     11aa <panel_update_track_led+0x8a>
cmpl   $0x0,-0x8(%rbp)
je     118c <panel_update_track_led+0x6c>
mov    -0x4(%rbp),%edi
add    $0x2,%edi
mov    $0x2,%esi
call   1040 <panel_set_led@plt>
jmp    1199 <panel_update_track_led+0x79>
mov    -0x4(%rbp),%edi
add    $0x2,%edi
xor    %esi,%esi
call   1040 <panel_set_led@plt>
mov    -0x8(%rbp),%edx
movslq -0x4(%rbp),%rcx
lea    0x2e99(%rip),%rax
mov    %edx,(%rax,%rcx,4)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<panel_update_track_led>:
mov    %edi,%eax
cmp    $0x6,%edi
jb     1135 <panel_update_track_led+0x15>
lea    0xed2(%rip),%rdi
mov    %eax,%esi
jmp    1030 <log_error@plt>
push   %r15
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %eax,%r14d
lea    0x2efa(%rip),%r15
cmp    %esi,(%r15,%r14,4)
je     1164 <panel_update_track_led+0x44>
xor    %esi,%esi
test   %ebx,%ebx
setne  %sil
add    $0x2,%eax
add    %esi,%esi
mov    %eax,%edi
call   1040 <panel_set_led@plt>
mov    %ebx,(%r15,%r14,4)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@panel_update_track_led.oldstate = internal global [6 x i32] zeroinitializer
@.str = [25 x i8] c"putl - track invalid: %d\00"
define void @panel_update_track_led(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* %3
%9 = icmp sge i32 %8, 6
br i1 %9, label %10, label %13
10: ; preds = %7, %2
%11 = load i32, i32* %3
%12 = call i32 @log_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %11)
br label %36
13: ; preds = %7
%14 = load i32, i32* %4
%15 = load i32, i32* %3
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [6 x i32], [6 x i32]* @panel_update_track_led.oldstate, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = icmp ne i32 %14, %18
br i1 %19, label %20, label %36
20: ; preds = %13
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i32, i32* %3
%25 = add nsw i32 2, %24
%26 = call i32 @panel_set_led(i32 %25, i32 2)
br label %31
27: ; preds = %20
%28 = load i32, i32* %3
%29 = add nsw i32 2, %28
%30 = call i32 @panel_set_led(i32 %29, i32 0)
br label %31
31: ; preds = %27, %23
%32 = load i32, i32* %4
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [6 x i32], [6 x i32]* @panel_update_track_led.oldstate, i64 0, i64 %34
store i32 %32, i32* %35
br label %36
36: ; preds = %10, %31, %13
ret void
}

LLVM IR (-O2):
@panel_update_track_led.oldstate = internal unnamed_addr global [6 x i32] zeroinitializer
@.str = [25 x i8] c"putl - track invalid: %d\00"
define void @panel_update_track_led(i32 %0, i32 %1) {
%3 = icmp ugt i32 %0, 5
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @log_error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %16
6: ; preds = %2
%7 = zext i32 %0 to i64
%8 = getelementptr inbounds [6 x i32], [6 x i32]* @panel_update_track_led.oldstate, i64 0, i64 %7
%9 = load i32, i32* %8
%10 = icmp eq i32 %9, %1
br i1 %10, label %16, label %11
11: ; preds = %6
%12 = icmp eq i32 %1, 0
%13 = add nuw nsw i32 %0, 2
%14 = select i1 %12, i32 0, i32 2
%15 = tail call i32 @panel_set_led(i32 %13, i32 %14)
store i32 %1, i32* %8
br label %16
16: ; preds = %4, %11, %6
ret void
}