#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 battery_get_level();
int /*<<< orphan*/ disable_timer();
scalar_t__ enable_timer(int, int);
scalar_t__ has_wlan_interfaces();
int /*<<< orphan*/ led_reset();
int /*<<< orphan*/ perror(char *);
scalar_t__ power_online();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int main(int argc, char **argv) {
  int timer_enabled = 0;
  while (1) {
    int battery_level = battery_get_level();
    if (battery_level < 0) {
      perror("Unable to open battery sysfs file");
      return 1;
    }
    printf("Battery level: %i\n", battery_level);
    if (power_online()) {
      if (timer_enabled && battery_level > 10) {
        if (has_wlan_interfaces() > 0) {
          printf("Reverting to the WiFi notifier blinking mode\n");
          enable_timer(100, 1400);
        } else {
          printf("Disabling timer\n");
          disable_timer();
          led_reset();
        }
        timer_enabled = 0;
      }
    } else if (!timer_enabled && battery_level < 10) {
      printf("Enabling timer\n");
      if (enable_timer(250, 250)) {
        perror("Unable to open Power LED sysfs file");
        return 1;
      }
      timer_enabled = 1;
    }
    sleep(60);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    $0x0,%al
call   1070 <battery_get_level@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    11d9 <main+0x49>
lea    0xe38(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x145>
mov    -0x18(%rbp),%esi
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1080 <power_online@plt>
cmp    $0x0,%rax
je     126a <main+0xda>
cmpl   $0x0,-0x14(%rbp)
je     1265 <main+0xd5>
cmpl   $0xa,-0x18(%rbp)
jle    1265 <main+0xd5>
mov    $0x0,%al
call   1050 <has_wlan_interfaces@plt>
cmp    $0x0,%rax
jle    1242 <main+0xb2>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x64,%edi
mov    $0x578,%esi
call   1040 <enable_timer@plt>
jmp    125e <main+0xce>
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1030 <disable_timer@plt>
mov    $0x0,%al
call   1090 <led_reset@plt>
movl   $0x0,-0x14(%rbp)
jmp    12c6 <main+0x136>
cmpl   $0x0,-0x14(%rbp)
jne    12c1 <main+0x131>
cmpl   $0xa,-0x18(%rbp)
jge    12c1 <main+0x131>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xfa,%esi
mov    %esi,%edi
call   1040 <enable_timer@plt>
cmp    $0x0,%rax
je     12ba <main+0x12a>
lea    0xddb(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d5 <main+0x145>
movl   $0x1,-0x14(%rbp)
jmp    12c6 <main+0x136>
mov    $0x3c,%edi
call   10b0 <sleep@plt>
jmp    11ad <main+0x1d>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <battery_get_level@plt>
lea    0xe47(%rip),%rdi
test   %eax,%eax
js     12b0 <main+0x110>
mov    %eax,%ebp
lea    0xe58(%rip),%rbx
lea    0xe88(%rip),%r15
lea    0xea0(%rip),%r12
lea    0xe89(%rip),%r13
xor    %r14d,%r14d
jmp    121b <main+0x7b>
mov    %r13,%rdi
call   1040 <puts@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <disable_timer@plt>
xor    %eax,%eax
call   10a0 <led_reset@plt>
nopl   (%rax)
mov    $0x3c,%edi
call   10c0 <sleep@plt>
xor    %eax,%eax
call   1080 <battery_get_level@plt>
mov    %eax,%ebp
test   %eax,%eax
js     12a9 <main+0x109>
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1090 <power_online@plt>
test   %rax,%rax
je     1270 <main+0xd0>
test   %r14d,%r14d
je     1200 <main+0x60>
cmp    $0xb,%ebp
jb     1200 <main+0x60>
xor    %eax,%eax
call   1060 <has_wlan_interfaces@plt>
test   %rax,%rax
jle    11e4 <main+0x44>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    $0x64,%edi
mov    $0x578,%esi
call   1050 <enable_timer@plt>
xor    %r14d,%r14d
jmp    1200 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r14d,%r14d
jne    1200 <main+0x60>
cmp    $0x9,%ebp
ja     1200 <main+0x60>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    $0xfa,%edi
mov    $0xfa,%esi
call   1050 <enable_timer@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     1200 <main+0x60>
lea    0xd8e(%rip),%rdi
jmp    12b0 <main+0x110>
lea    0xd50(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Unable to open battery sysfs file\00"
@.str.1 = [19 x i8] c"Battery level: %i\0A\00"
@.str.2 = [46 x i8] c"Reverting to the WiFi notifier blinking mode\0A\00"
@.str.3 = [17 x i8] c"Disabling timer\0A\00"
@.str.4 = [16 x i8] c"Enabling timer\0A\00"
@.str.5 = [36 x i8] c"Unable to open Power LED sysfs file\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %8
8: ; preds = %2, %51
%9 = call i32 (...) @battery_get_level()
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %53
14: ; preds = %8
%15 = load i32, i32* %7
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = call i64 (...) @power_online()
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %37
19: ; preds = %14
%20 = load i32, i32* %6
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %19
%23 = load i32, i32* %7
%24 = icmp sgt i32 %23, 10
br i1 %24, label %25, label %36
25: ; preds = %22
%26 = call i64 (...) @has_wlan_interfaces()
%27 = icmp sgt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%30 = call i64 @enable_timer(i32 100, i32 1400)
br label %35
31: ; preds = %25
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 (...) @disable_timer()
%34 = call i32 (...) @led_reset()
br label %35
35: ; preds = %31, %28
store i32 0, i32* %6
br label %36
36: ; preds = %35, %22, %19
br label %51
37: ; preds = %14
%38 = load i32, i32* %6
%39 = icmp ne i32 %38, 0
br i1 %39, label %50, label %40
40: ; preds = %37
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 10
br i1 %42, label %43, label %50
43: ; preds = %40
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%45 = call i64 @enable_timer(i32 250, i32 250)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %53
49: ; preds = %43
store i32 1, i32* %6
br label %50
50: ; preds = %49, %40, %37
br label %51
51: ; preds = %50, %36
%52 = call i32 @sleep(i32 60)
br label %8
53: ; preds = %47, %12
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [34 x i8] c"Unable to open battery sysfs file\00"
@.str.1 = [19 x i8] c"Battery level: %i\0A\00"
@.str.5 = [36 x i8] c"Unable to open Power LED sysfs file\00"
@str = [15 x i8] c"Enabling timer\00"
@str.6 = [16 x i8] c"Disabling timer\00"
@str.7 = [45 x i8] c"Reverting to the WiFi notifier blinking mode\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @battery_get_level()
%4 = icmp slt i32 %3, 0
br i1 %4, label %38, label %5
5: ; preds = %2, %33
%6 = phi i32 [ %36, %33 ], [ %3, %2 ]
%7 = phi i32 [ %34, %33 ], [ 0, %2 ]
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%9 = tail call i64 (...) @power_online()
%10 = icmp eq i64 %9, 0
br i1 %10, label %25, label %11
11: ; preds = %5
%12 = icmp ne i32 %7, 0
%13 = icmp ugt i32 %6, 10
%14 = and i1 %12, %13
br i1 %14, label %15, label %33
15: ; preds = %11
%16 = tail call i64 (...) @has_wlan_interfaces()
%17 = icmp sgt i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.7, i64 0, i64 0))
%20 = tail call i64 @enable_timer(i32 100, i32 1400)
br label %33
21: ; preds = %15
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.6, i64 0, i64 0))
%23 = tail call i32 (...) @disable_timer()
%24 = tail call i32 (...) @led_reset()
br label %33
25: ; preds = %5
%26 = icmp eq i32 %7, 0
%27 = icmp ult i32 %6, 10
%28 = and i1 %26, %27
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%31 = tail call i64 @enable_timer(i32 250, i32 250)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %11, %25, %21, %18, %29
%34 = phi i32 [ %7, %11 ], [ %7, %25 ], [ 0, %21 ], [ 0, %18 ], [ 1, %29 ]
%35 = tail call i32 @sleep(i32 60)
%36 = tail call i32 (...) @battery_get_level()
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %5
38: ; preds = %29, %33, %2
%39 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), %33 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), %29 ]
%40 = tail call i32 @perror(i8* %39)
ret i32 1
}