#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 get_battery_lights(int *);
int /*<<< orphan*/ get_cpu_utilisation();
int /*<<< orphan*/ set_num_and_caps_lights(int);
int /*<<< orphan*/ set_wifi_light(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ update_keyboard_backlight();
int main(void) {
  int battery_lights;
  int urgent;
  set_wifi_light(0);
  set_wifi_light(1);
  get_cpu_utilisation();
  while (1) {
    battery_lights = get_battery_lights(&urgent);
    set_wifi_light(!!(battery_lights & 4));
    set_num_and_caps_lights(battery_lights & 0x3);
    update_keyboard_backlight();
    sleep(urgent ? 1 : 4);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1030 <set_wifi_light@plt>
mov    $0x1,%edi
call   1030 <set_wifi_light@plt>
mov    $0x0,%al
call   1060 <get_cpu_utilisation@plt>
lea    -0xc(%rbp),%rdi
call   1070 <get_battery_lights@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x4,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x17(%rbp)
xor    $0xff,%al
mov    %al,-0x16(%rbp)
and    $0x1,%al
mov    %al,-0x15(%rbp)
movzbl %al,%edi
call   1030 <set_wifi_light@plt>
mov    -0x8(%rbp),%edi
and    $0x3,%edi
mov    %edi,-0x14(%rbp)
call   1050 <set_num_and_caps_lights@plt>
mov    $0x0,%al
call   1040 <update_keyboard_backlight@plt>
mov    -0xc(%rbp),%ecx
mov    $0x4,%edi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edi
mov    %edi,-0x10(%rbp)
call   1080 <sleep@plt>
jmp    1187 <main+0x27>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %edi,%edi
call   1030 <set_wifi_light@plt>
mov    $0x1,%edi
call   1030 <set_wifi_light@plt>
xor    %eax,%eax
call   1060 <get_cpu_utilisation@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <get_battery_lights@plt>
mov    %eax,%ebp
mov    %eax,%edi
shr    $0x2,%edi
and    $0x1,%edi
call   1030 <set_wifi_light@plt>
and    $0x3,%ebp
mov    %ebp,%edi
call   1050 <set_num_and_caps_lights@plt>
xor    %eax,%eax
call   1040 <update_keyboard_backlight@plt>
xor    %eax,%eax
cmpl   $0x0,0x4(%rsp)
sete   %al
lea    (%rax,%rax,2),%edi
add    $0x1,%edi
call   1080 <sleep@plt>
jmp    1180 <main+0x20>

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @set_wifi_light(i32 0)
%5 = call i32 @set_wifi_light(i32 1)
%6 = call i32 (...) @get_cpu_utilisation()
br label %7
7: ; preds = %0, %7
%8 = call i32 @get_battery_lights(i32* %3)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = and i32 %9, 4
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
%13 = xor i1 %12, true
%14 = zext i1 %13 to i32
%15 = call i32 @set_wifi_light(i32 %14)
%16 = load i32, i32* %2
%17 = and i32 %16, 3
%18 = call i32 @set_num_and_caps_lights(i32 %17)
%19 = call i32 (...) @update_keyboard_backlight()
%20 = load i32, i32* %3
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 1, i32 4
%24 = call i32 @sleep(i32 %23)
br label %7
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 @set_wifi_light(i32 0)
%4 = tail call i32 @set_wifi_light(i32 1)
%5 = tail call i32 (...) @get_cpu_utilisation()
br label %6
6: ; preds = %6, %0
%7 = call i32 @get_battery_lights(i32* %1)
%8 = lshr i32 %7, 2
%9 = and i32 %8, 1
%10 = call i32 @set_wifi_light(i32 %9)
%11 = and i32 %7, 3
%12 = call i32 @set_num_and_caps_lights(i32 %11)
%13 = call i32 (...) @update_keyboard_backlight()
%14 = load i32, i32* %1
%15 = icmp eq i32 %14, 0
%16 = select i1 %15, i32 4, i32 1
%17 = call i32 @sleep(i32 %16)
br label %6
}