#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 pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
double BatteryRawToEnergyRemaining(double);
double BatteryRawToVoltage(double);
int /*<<< orphan*/ DarkenDisplay();
int /*<<< orphan*/ DimDisplay();
char GetBrightnessIndex();
int GetInput(int);
double GetRawBatteryReadings(int, double *);
int IdleTime();
int /*<<< orphan*/ InitBattery();
int /*<<< orphan*/ InitBrightness(int);
int /*<<< orphan*/ InitGPIO();
int /*<<< orphan*/ MaxBrightness();
int /*<<< orphan*/ NextBrightness();
int /*<<< orphan*/ NudgeBrightness();
int /*<<< orphan*/ RestoreDisplay();
int /*<<< orphan*/ RotateLogs();
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ WriteToLog(char *);
int /*<<< orphan*/ WriteToLogArgF(char *, double);
int /*<<< orphan*/ WriteToLogArgI(char *, int);
int /*<<< orphan*/ chmod(char *, int);
scalar_t__ daemon(int /*<<< orphan*/, int /*<<< orphan*/);
double fabs(double);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int fscanf(int /*<<< orphan*/ *, char *, int *, ...);
int getopt(int, char **, char *);
int getpid();
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int optind;
int /*<<< orphan*/ perror(char *);
double round(double);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ unlink(char *);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  bool optLogBattery = false, optKillOnly = false, optDaemonize = true;
  int c;
  while ((c = getopt(argc, argv, "bkn")) != -1) {
    switch (c) {
    case 'b':
      optLogBattery = true;
      break;
    case 'k':
      optKillOnly = true;
      break;
    case 'n':
      optDaemonize = false;
      break;
    default:
      usage();
    }
  }
  if (optind < argc)
    usage();
  FILE *fp = fopen("/var/run/pitabd.pid", "r");
  if (fp != NULL) {
    pid_t pid;
    if (fscanf(fp, "%d", &pid) == 1)
      kill(pid, SIGINT);
    fclose(fp);
    unlink("/var/run/pitabd.pid");
    WriteToLogArgI("killed %d", pid);
  }
  if (optKillOnly)
    return (0);
  if (!InitGPIO()) {
    fprintf(stderr, "pitabd: failed to initialize GPIO\n");
    return (1);
  }
  InitBattery();
  if (optDaemonize && daemon(0, 0) != 0) {
    perror("pitabd: failed to become a daemon");
    return (1);
  }
  if ((fp = fopen("/var/run/pitabd.pid", "w")) == NULL) {
    fprintf(stderr, "pitabd: unable to record process ID\n");
    return (1);
  }
  fprintf(fp, "%d\n", getpid());
  fclose(fp);
  RotateLogs();
  WriteToLogArgI("starting with pid=%d", getpid());
  int brightnessIndex = -1;
  if ((fp = fopen("/ram/pitabd.cmd", "r")) != NULL)
    fclose(fp);
  else if ((fp = fopen("/var/tmp/pitabd.cmd", "r")) != NULL) {
    FILE *fp2 = fopen("/ram/pitabd.cmd", "w");
    if (fp2 != NULL) {
      while ((c = fgetc(fp)) != -1) {
        if ('A' <= c && c <= 'I') {
          brightnessIndex = c - 'A';
          break;
        }
        fputc(c, fp2);
      }
      fclose(fp2);
    }
    fclose(fp);
    chmod("/ram/pitabd.cmd", 0666);
  }
  InitBrightness(brightnessIndex + !brightnessIndex);
  int cyclesSinceLBO = 0;
  bool charging = false, completed = false;
  double lastVoltage = -1, lastEnergy = -1;
  enum { ACTIVE = 0, DIM, DARK } displayState = ACTIVE;
  int nextIdleCheck = 120000;
  int button1LongPress = 0, button2LongPress = 0, button3LongPress = 0;
  bool usbOn = true, wifiOn = true, allowDim = true;
  for (int cycle = 0;; ++cycle) {
    if (GetInput(0) == -1) {
      WriteToLog("shutdown initiated");
      break;
    }
    bool endIdle = false;
    c = GetInput(1);
    if (c == 1) {
      button1LongPress = cycle + 500;
      endIdle = true;
    } else if (c == -1) {
      system("wmctrl -r :ACTIVE: -b remove,fullscreen");
      if (cycle > button1LongPress)
        system("wmctrl -a \"%\"");
      else
        system("wmctrl -a \"xvkbd\"");
    }
    c = GetInput(2);
    if (c == 1) {
      button2LongPress = cycle + 500;
      endIdle = true;
    } else if (c == -1) {
      if (cycle > button2LongPress)
        MaxBrightness();
      else
        NextBrightness();
    }
    c = GetInput(3);
    if (c == 1) {
      button3LongPress = cycle + 500;
      endIdle = true;
    } else if (c == -1) {
      if (cycle > button3LongPress)
        system("wmctrl -r :ACTIVE: -b toggle,fullscreen");
      else {
        system("wmctrl -r :ACTIVE: -b remove,fullscreen");
        system("wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz");
      }
    }
    if (endIdle) {
      if (displayState != ACTIVE) {
        RestoreDisplay();
        displayState = ACTIVE;
      }
      nextIdleCheck = cycle + 120000;
    }
    if (cycle % 5000 == 0 && (fp = fopen("/ram/pitabd.cmd", "r")) != NULL) {
      int wantDim = 1, wantUSB = 1, wantWifi = 1;
      int nScanned = fscanf(fp, "%d %d %d", &wantDim, &wantUSB, &wantWifi);
      fclose(fp);
      if (nScanned == 3) {
        allowDim = wantDim;
        if (usbOn && !wantUSB) {
          if ((fp = fopen("/sys/devices/platform/soc/3f980000.usb/buspower",
                          "w")) != NULL) {
            fprintf(fp, "0\n");
            fclose(fp);
            system("/usr/bin/lxpanelctl restart");
            WriteToLog("disabled USB and Bluetooth");
            usbOn = false;
          }
        } else if (!usbOn && wantUSB) {
          if ((fp = fopen("/sys/devices/platform/soc/3f980000.usb/buspower",
                          "w")) != NULL) {
            fprintf(fp, "1\n");
            fclose(fp);
            WriteToLog("enabled USB and Bluetooth");
            usbOn = true;
          }
        }
        if (wifiOn && !wantWifi) {
          system("/sbin/iwconfig wlan0 txpower off");
          WriteToLog("disabled wifi");
          wifiOn = false;
        } else if (!wifiOn && wantWifi) {
          system("/sbin/iwconfig wlan0 txpower auto");
          system("/sbin/iwconfig wlan0 txpower auto");
          WriteToLog("enabled wifi");
          wifiOn = true;
        }
      }
    }
    bool pluggedIn = charging || completed;
    bool changed = false;
    c = GetInput(5);
    if (c == 1) {
      charging = true;
      changed = true;
    } else if (c == -1) {
      charging = false;
      changed = true;
    }
    c = GetInput(6);
    if (c == 1) {
      WriteToLog("charging completed");
      completed = true;
      changed = true;
    } else if (c == -1) {
      completed = false;
      changed = true;
    }
    if (pluggedIn && !(charging || completed)) {
      WriteToLog("charger disconnected");
      nextIdleCheck = cycle + 120000;
      pluggedIn = false;
    } else if (!pluggedIn && (charging || completed)) {
      WriteToLog("charger connected");
      pluggedIn = true;
    }
    double rAdj, rAct = GetRawBatteryReadings(charging, &rAdj);
    double v = round(BatteryRawToVoltage(rAct) * 100.0) / 100.0;
    double e = round(BatteryRawToEnergyRemaining(rAdj));
    if (cycle >= 16384) {
      if (charging && v > lastVoltage || !charging && v < lastVoltage ||
          fabs(v - lastVoltage) > 0.0101) {
        if (optLogBattery)
          WriteToLogArgF("battery voltage %1.2fV", v);
        lastVoltage = v;
        changed = true;
      }
      if (charging && e > lastEnergy || !charging && e < lastEnergy ||
          fabs(e - lastEnergy) > 1.01) {
        if (optLogBattery)
          WriteToLogArgF("energy remaining %1.0f%%", e);
        lastEnergy = e;
        changed = true;
      }
      if (optLogBattery && cycle % 60000 == 16384)
        WriteToLogArgF("raw battery %1.3f", rAct);
    }
    if (cycle > nextIdleCheck && (displayState != ACTIVE || !pluggedIn)) {
      int i = IdleTime();
      switch (displayState) {
      case ACTIVE:
        if (i > 120000 && allowDim) {
          DimDisplay();
          displayState = DIM;
          nextIdleCheck = cycle + 500;
        } else
          nextIdleCheck = cycle + 120000 - i;
        break;
      case DIM:
        if (i < 120000 || !allowDim || pluggedIn) {
          RestoreDisplay();
          displayState = ACTIVE;
          nextIdleCheck = cycle + 120000 - i;
        } else if (i > 120000 + 180000 && allowDim) {
          DarkenDisplay();
          system("wmctrl -r :ACTIVE: -b remove,fullscreen");
          system("wmctrl -a \"%\"");
          displayState = DARK;
          nextIdleCheck = cycle + 500;
        } else
          nextIdleCheck = cycle + 500;
        break;
      case DARK:
        if (i < 120000 || !allowDim || pluggedIn) {
          RestoreDisplay();
          displayState = ACTIVE;
          nextIdleCheck = cycle + 120000 - i;
        } else
          nextIdleCheck = cycle + 500;
        break;
      }
      if (!allowDim)
        nextIdleCheck = cycle + 120000;
    }
    int lbo = GetInput(4);
    if (lbo == 1)
      cyclesSinceLBO = 1;
    else if (lbo == -1)
      cyclesSinceLBO = 0;
    else if (cyclesSinceLBO > 0 && ++cyclesSinceLBO >= 60000) {
      WriteToLogArgF("low battery at %1.2fV", v);
      break;
    }
    if (cycle % 16 == 0)
      NudgeBrightness();
    if (changed && (fp = fopen("/ram/pitabd.dat", "w")) != NULL) {
      fprintf(fp, "%4.2f %2.0f %1d %1d\n", v, e, charging, completed);
      fclose(fp);
    }
    usleep(927);
  }
  if ((fp = fopen("/ram/pitabd.cmd", "r")) != NULL) {
    FILE *fp2 = fopen("/var/tmp/pitabd.cmd", "w");
    if (fp2 != NULL) {
      while ((c = fgetc(fp)) != -1)
        fputc(c, fp2);
      fprintf(fp2, "%c\n", 'A' + GetBrightnessIndex());
      fprintf(fp2, "Do not edit this file!\n");
      fclose(fp2);
    }
    fclose(fp);
  }
  unlink("/var/run/pitabd.pid");
  system("/sbin/shutdown now");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0x1cb4(%rip),%rdx
call   1200 <getopt@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     13fc <main+0xbc>
mov    -0x20(%rbp),%eax
mov    %eax,-0xcc(%rbp)
sub    $0x62,%eax
je     13cc <main+0x8c>
jmp    13a4 <main+0x64>
mov    -0xcc(%rbp),%eax
sub    $0x6b,%eax
je     13d8 <main+0x98>
jmp    13b8 <main+0x78>
mov    -0xcc(%rbp),%eax
sub    $0x6e,%eax
je     13e4 <main+0xa4>
jmp    13f0 <main+0xb0>
movl   $0x1,-0x14(%rbp)
jmp    13f7 <main+0xb7>
movl   $0x1,-0x18(%rbp)
jmp    13f7 <main+0xb7>
movl   $0x0,-0x1c(%rbp)
jmp    13f7 <main+0xb7>
mov    $0x0,%al
call   11b0 <usage@plt>
jmp    136e <main+0x2e>
mov    0x3bdd(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jge    1415 <main+0xd5>
mov    $0x0,%al
call   11b0 <usage@plt>
lea    0x1c18(%rip),%rdi
lea    0x1dcb(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     148b <main+0x14b>
mov    -0x28(%rbp),%rdi
lea    0x1d7b(%rip),%rsi
lea    -0x2c(%rbp),%rdx
mov    $0x0,%al
call   10f0 <fscanf@plt>
cmp    $0x1,%eax
jne    1467 <main+0x127>
mov    -0x2c(%rbp),%edi
mov    0x3b88(%rip),%rax
mov    (%rax),%esi
call   1150 <kill@plt>
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
lea    0x1bbd(%rip),%rdi
call   1030 <unlink@plt>
mov    -0x2c(%rbp),%esi
lea    0x1bc2(%rip),%rdi
call   1170 <WriteToLogArgI@plt>
cmpl   $0x0,-0x18(%rbp)
je     14a1 <main+0x161>
movl   $0x0,-0x4(%rbp)
jmp    21ff <main+0xebf>
mov    $0x0,%al
call   1220 <InitGPIO@plt>
cmp    $0x0,%eax
jne    14d5 <main+0x195>
mov    0x3b18(%rip),%rax
mov    (%rax),%rdi
lea    0x1b90(%rip),%rsi
mov    $0x0,%al
call   1130 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    21ff <main+0xebf>
mov    $0x0,%al
call   10d0 <InitBattery@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1511 <main+0x1d1>
xor    %esi,%esi
mov    %esi,%edi
call   1190 <daemon@plt>
cmp    $0x0,%rax
je     1511 <main+0x1d1>
lea    0x1b75(%rip),%rdi
call   11f0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    21ff <main+0xebf>
lea    0x1b1c(%rip),%rdi
lea    0x1e6a(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1556 <main+0x216>
mov    0x3a97(%rip),%rax
mov    (%rax),%rdi
lea    0x1b54(%rip),%rsi
mov    $0x0,%al
call   1130 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    21ff <main+0xebf>
mov    -0x28(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0xd8(%rbp),%rdi
mov    %eax,%edx
lea    0x1b44(%rip),%rsi
mov    $0x0,%al
call   1130 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
mov    $0x0,%al
call   1160 <RotateLogs@plt>
mov    $0x0,%al
call   1080 <getpid@plt>
mov    %eax,%esi
lea    0x1b21(%rip),%rdi
call   1170 <WriteToLogArgI@plt>
movl   $0xffffffff,-0x30(%rbp)
lea    0x1b23(%rip),%rdi
lea    0x1c35(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     15da <main+0x29a>
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
jmp    1696 <main+0x356>
lea    0x1b04(%rip),%rdi
lea    0x1c06(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1691 <main+0x351>
lea    0x1ad3(%rip),%rdi
lea    0x1d80(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1677 <main+0x337>
jmp    1622 <main+0x2e2>
mov    -0x28(%rbp),%rdi
call   1100 <fgetc@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     166e <main+0x32e>
mov    $0x41,%eax
cmp    -0x20(%rbp),%eax
jg     165d <main+0x31d>
cmpl   $0x49,-0x20(%rbp)
jg     165d <main+0x31d>
mov    -0x20(%rbp),%eax
sub    $0x41,%eax
mov    %eax,-0x30(%rbp)
jmp    166e <main+0x32e>
mov    -0x20(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1120 <fputc@plt>
jmp    1622 <main+0x2e2>
mov    -0x38(%rbp),%rdi
call   1090 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
lea    0x1a4e(%rip),%rdi
mov    $0x1b6,%esi
call   11c0 <chmod@plt>
jmp    1696 <main+0x356>
mov    -0x30(%rbp),%edi
cmpl   $0x0,-0x30(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
add    %eax,%edi
call   1140 <InitBrightness@plt>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movsd  0x1935(%rip),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0x1928(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
movl   $0x1d4c0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x6c(%rbp)
movl   $0x1,-0x70(%rbp)
movl   $0x1,-0x74(%rbp)
movl   $0x1,-0x78(%rbp)
movl   $0x0,-0x7c(%rbp)
xor    %edi,%edi
call   1060 <GetInput@plt>
cmp    $0xffffffff,%eax
jne    173d <main+0x3fd>
lea    0x19c6(%rip),%rdi
call   10c0 <WriteToLog@plt>
jmp    210f <main+0xdcf>
movl   $0x0,-0x80(%rbp)
mov    $0x1,%edi
call   1060 <GetInput@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1772 <main+0x432>
mov    -0x7c(%rbp),%eax
add    $0x1f4,%eax
mov    %eax,-0x64(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    17bb <main+0x47b>
cmpl   $0xffffffff,-0x20(%rbp)
jne    17b6 <main+0x476>
lea    0x1989(%rip),%rdi
call   10a0 <system@plt>
mov    -0x7c(%rbp),%eax
cmp    -0x64(%rbp),%eax
jle    17a5 <main+0x465>
lea    0x1999(%rip),%rdi
call   10a0 <system@plt>
jmp    17b1 <main+0x471>
lea    0x1996(%rip),%rdi
call   10a0 <system@plt>
jmp    17b6 <main+0x476>
jmp    17bb <main+0x47b>
mov    $0x2,%edi
call   1060 <GetInput@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    17e9 <main+0x4a9>
mov    -0x7c(%rbp),%eax
add    $0x1f4,%eax
mov    %eax,-0x68(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    181c <main+0x4dc>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1817 <main+0x4d7>
mov    -0x7c(%rbp),%eax
cmp    -0x68(%rbp),%eax
jle    180b <main+0x4cb>
mov    $0x0,%al
call   11d0 <MaxBrightness@plt>
jmp    1812 <main+0x4d2>
mov    $0x0,%al
call   10e0 <NextBrightness@plt>
jmp    1817 <main+0x4d7>
jmp    181c <main+0x4dc>
mov    $0x3,%edi
call   1060 <GetInput@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    184a <main+0x50a>
mov    -0x7c(%rbp),%eax
add    $0x1f4,%eax
mov    %eax,-0x6c(%rbp)
movl   $0x1,-0x80(%rbp)
jmp    1893 <main+0x553>
cmpl   $0xffffffff,-0x20(%rbp)
jne    188e <main+0x54e>
mov    -0x7c(%rbp),%eax
cmp    -0x6c(%rbp),%eax
jle    1871 <main+0x531>
lea    0x18ed(%rip),%rdi
call   10a0 <system@plt>
jmp    1889 <main+0x549>
lea    0x1894(%rip),%rdi
call   10a0 <system@plt>
lea    0x18f8(%rip),%rdi
call   10a0 <system@plt>
jmp    188e <main+0x54e>
jmp    1893 <main+0x553>
cmpl   $0x0,-0x80(%rbp)
je     18c0 <main+0x580>
cmpl   $0x0,-0x5c(%rbp)
je     18b5 <main+0x575>
mov    $0x0,%al
call   1180 <RestoreDisplay@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1d4c0,%eax
mov    %eax,-0x60(%rbp)
mov    -0x7c(%rbp),%eax
mov    $0x1388,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1ad2 <main+0x792>
lea    0x17fa(%rip),%rdi
lea    0x190c(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1ad2 <main+0x792>
movl   $0x1,-0x84(%rbp)
movl   $0x1,-0x88(%rbp)
movl   $0x1,-0x8c(%rbp)
mov    -0x28(%rbp),%rdi
lea    0x1899(%rip),%rsi
lea    -0x84(%rbp),%rdx
lea    -0x88(%rbp),%rcx
lea    -0x8c(%rbp),%r8
mov    $0x0,%al
call   10f0 <fscanf@plt>
mov    %eax,-0x90(%rbp)
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
cmpl   $0x3,-0x90(%rbp)
jne    1acd <main+0x78d>
mov    -0x84(%rbp),%eax
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x70(%rbp)
je     19d6 <main+0x696>
cmpl   $0x0,-0x88(%rbp)
jne    19d6 <main+0x696>
lea    0x1843(%rip),%rdi
lea    0x1a05(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     19d1 <main+0x691>
mov    -0x28(%rbp),%rdi
lea    0x184e(%rip),%rsi
mov    $0x0,%al
call   1130 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
lea    0x183a(%rip),%rdi
call   10a0 <system@plt>
lea    0x184a(%rip),%rdi
call   10c0 <WriteToLog@plt>
movl   $0x0,-0x70(%rbp)
jmp    1a46 <main+0x706>
cmpl   $0x0,-0x70(%rbp)
jne    1a41 <main+0x701>
cmpl   $0x0,-0x88(%rbp)
je     1a41 <main+0x701>
lea    0x17cc(%rip),%rdi
lea    0x198e(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1a3c <main+0x6fc>
mov    -0x28(%rbp),%rdi
lea    0x1811(%rip),%rsi
mov    $0x0,%al
call   1130 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
lea    0x17fd(%rip),%rdi
call   10c0 <WriteToLog@plt>
movl   $0x1,-0x70(%rbp)
jmp    1a41 <main+0x701>
jmp    1a46 <main+0x706>
cmpl   $0x0,-0x74(%rbp)
je     1a81 <main+0x741>
cmpl   $0x0,-0x8c(%rbp)
jne    1a81 <main+0x741>
lea    0x17e3(%rip),%rdi
call   10a0 <system@plt>
lea    0x17f8(%rip),%rdi
call   10c0 <WriteToLog@plt>
movl   $0x0,-0x74(%rbp)
jmp    1ac8 <main+0x788>
cmpl   $0x0,-0x74(%rbp)
jne    1ac3 <main+0x783>
cmpl   $0x0,-0x8c(%rbp)
je     1ac3 <main+0x783>
lea    0x17d7(%rip),%rdi
call   10a0 <system@plt>
lea    0x17cb(%rip),%rdi
call   10a0 <system@plt>
lea    0x17e1(%rip),%rdi
call   10c0 <WriteToLog@plt>
movl   $0x1,-0x74(%rbp)
jmp    1ac8 <main+0x788>
jmp    1acd <main+0x78d>
jmp    1ad2 <main+0x792>
mov    $0x1,%al
cmpl   $0x0,-0x40(%rbp)
mov    %al,-0xd9(%rbp)
jne    1af1 <main+0x7b1>
cmpl   $0x0,-0x44(%rbp)
setne  %al
mov    %al,-0xd9(%rbp)
mov    -0xd9(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
mov    $0x5,%edi
call   1060 <GetInput@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1b39 <main+0x7f9>
movl   $0x1,-0x40(%rbp)
movl   $0x1,-0x98(%rbp)
jmp    1b59 <main+0x819>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1b54 <main+0x814>
movl   $0x0,-0x40(%rbp)
movl   $0x1,-0x98(%rbp)
jmp    1b59 <main+0x819>
mov    $0x6,%edi
call   1060 <GetInput@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jne    1b92 <main+0x852>
lea    0x172e(%rip),%rdi
call   10c0 <WriteToLog@plt>
movl   $0x1,-0x44(%rbp)
movl   $0x1,-0x98(%rbp)
jmp    1bb2 <main+0x872>
cmpl   $0xffffffff,-0x20(%rbp)
jne    1bad <main+0x86d>
movl   $0x0,-0x44(%rbp)
movl   $0x1,-0x98(%rbp)
jmp    1bb2 <main+0x872>
cmpl   $0x0,-0x94(%rbp)
je     1bf9 <main+0x8b9>
cmpl   $0x0,-0x40(%rbp)
jne    1bf9 <main+0x8b9>
cmpl   $0x0,-0x44(%rbp)
jne    1bf9 <main+0x8b9>
lea    0x16de(%rip),%rdi
call   10c0 <WriteToLog@plt>
mov    -0x7c(%rbp),%eax
add    $0x1d4c0,%eax
mov    %eax,-0x60(%rbp)
movl   $0x0,-0x94(%rbp)
jmp    1c35 <main+0x8f5>
cmpl   $0x0,-0x94(%rbp)
jne    1c30 <main+0x8f0>
cmpl   $0x0,-0x40(%rbp)
jne    1c1a <main+0x8da>
cmpl   $0x0,-0x44(%rbp)
je     1c30 <main+0x8f0>
lea    0x16ac(%rip),%rdi
call   10c0 <WriteToLog@plt>
movl   $0x1,-0x94(%rbp)
jmp    1c35 <main+0x8f5>
mov    -0x40(%rbp),%edi
lea    -0xa0(%rbp),%rsi
call   1040 <GetRawBatteryReadings@plt>
movsd  %xmm0,-0xa8(%rbp)
ff
movsd  -0xa8(%rbp),%xmm0
ff
call   1230 <BatteryRawToVoltage@plt>
movsd  0x13a7(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1210 <round@plt>
movsd  0x1396(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
movsd  -0xa0(%rbp),%xmm0
ff
call   1110 <BatteryRawToEnergyRemaining@plt>
call   1210 <round@plt>
movsd  %xmm0,-0xb8(%rbp)
ff
cmpl   $0x4000,-0x7c(%rbp)
jl     1e19 <main+0xad9>
cmpl   $0x0,-0x40(%rbp)
je     1cc2 <main+0x982>
movsd  -0xb0(%rbp),%xmm0
ff
ucomisd -0x50(%rbp),%xmm0
ja     1d0d <main+0x9cd>
cmpl   $0x0,-0x40(%rbp)
jne    1ce3 <main+0x9a3>
movsd  -0xb0(%rbp),%xmm1
ff
movsd  -0x50(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1d0d <main+0x9cd>
movsd  -0xb0(%rbp),%xmm0
ff
subsd  -0x50(%rbp),%xmm0
movaps 0x1329(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0x130d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1d42 <main+0xa02>
cmpl   $0x0,-0x14(%rbp)
je     1d2b <main+0x9eb>
movsd  -0xb0(%rbp),%xmm0
ff
lea    0x15b9(%rip),%rdi
call   1050 <WriteToLogArgF@plt>
movsd  -0xb0(%rbp),%xmm0
ff
movsd  %xmm0,-0x50(%rbp)
movl   $0x1,-0x98(%rbp)
cmpl   $0x0,-0x40(%rbp)
je     1d5f <main+0xa1f>
movsd  -0xb8(%rbp),%xmm0
ff
ucomisd -0x58(%rbp),%xmm0
ja     1daa <main+0xa6a>
cmpl   $0x0,-0x40(%rbp)
jne    1d80 <main+0xa40>
movsd  -0xb8(%rbp),%xmm1
ff
movsd  -0x58(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1daa <main+0xa6a>
movsd  -0xb8(%rbp),%xmm0
ff
subsd  -0x58(%rbp),%xmm0
movaps 0x128c(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0x1278(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1ddf <main+0xa9f>
cmpl   $0x0,-0x14(%rbp)
je     1dc8 <main+0xa88>
movsd  -0xb8(%rbp),%xmm0
ff
lea    0x1533(%rip),%rdi
call   1050 <WriteToLogArgF@plt>
movsd  -0xb8(%rbp),%xmm0
ff
movsd  %xmm0,-0x58(%rbp)
movl   $0x1,-0x98(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1e14 <main+0xad4>
mov    -0x7c(%rbp),%eax
mov    $0xea60,%ecx
cltd
idiv   %ecx
cmp    $0x4000,%edx
jne    1e14 <main+0xad4>
movsd  -0xa8(%rbp),%xmm0
ff
lea    0x1500(%rip),%rdi
call   1050 <WriteToLogArgF@plt>
jmp    1e19 <main+0xad9>
mov    -0x7c(%rbp),%eax
cmp    -0x60(%rbp),%eax
jle    1ffa <main+0xcba>
cmpl   $0x0,-0x5c(%rbp)
jne    1e3c <main+0xafc>
cmpl   $0x0,-0x94(%rbp)
jne    1ffa <main+0xcba>
xor    %eax,%eax
call   11a0 <IdleTime@plt>
mov    %eax,-0xbc(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0xe0(%rbp)
test   %eax,%eax
je     1e87 <main+0xb47>
jmp    1e5f <main+0xb1f>
mov    -0xe0(%rbp),%eax
sub    $0x1,%eax
je     1ed5 <main+0xb95>
jmp    1e73 <main+0xb33>
mov    -0xe0(%rbp),%eax
sub    $0x2,%eax
je     1f85 <main+0xc45>
jmp    1fe0 <main+0xca0>
cmpl   $0x1d4c0,-0xbc(%rbp)
jle    1ebf <main+0xb7f>
cmpl   $0x0,-0x78(%rbp)
je     1ebf <main+0xb7f>
mov    $0x0,%al
call   1250 <DimDisplay@plt>
movl   $0x1,-0x5c(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1f4,%eax
mov    %eax,-0x60(%rbp)
jmp    1ed0 <main+0xb90>
mov    -0x7c(%rbp),%eax
add    $0x1d4c0,%eax
sub    -0xbc(%rbp),%eax
mov    %eax,-0x60(%rbp)
jmp    1fe0 <main+0xca0>
cmpl   $0x1d4c0,-0xbc(%rbp)
jl     1efc <main+0xbbc>
cmpl   $0x0,-0x78(%rbp)
je     1efc <main+0xbbc>
cmpl   $0x0,-0x94(%rbp)
je     1f20 <main+0xbe0>
mov    $0x0,%al
call   1180 <RestoreDisplay@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1d4c0,%eax
sub    -0xbc(%rbp),%eax
mov    %eax,-0x60(%rbp)
jmp    1f80 <main+0xc40>
cmpl   $0x493e0,-0xbc(%rbp)
jle    1f70 <main+0xc30>
cmpl   $0x0,-0x78(%rbp)
je     1f70 <main+0xc30>
mov    $0x0,%al
call   10b0 <DarkenDisplay@plt>
lea    0x11c4(%rip),%rdi
call   10a0 <system@plt>
lea    0x11e0(%rip),%rdi
call   10a0 <system@plt>
movl   $0x2,-0x5c(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1f4,%eax
mov    %eax,-0x60(%rbp)
jmp    1f7b <main+0xc3b>
mov    -0x7c(%rbp),%eax
add    $0x1f4,%eax
mov    %eax,-0x60(%rbp)
jmp    1f80 <main+0xc40>
jmp    1fe0 <main+0xca0>
cmpl   $0x1d4c0,-0xbc(%rbp)
jl     1fac <main+0xc6c>
cmpl   $0x0,-0x78(%rbp)
je     1fac <main+0xc6c>
cmpl   $0x0,-0x94(%rbp)
je     1fd0 <main+0xc90>
mov    $0x0,%al
call   1180 <RestoreDisplay@plt>
movl   $0x0,-0x5c(%rbp)
mov    -0x7c(%rbp),%eax
add    $0x1d4c0,%eax
sub    -0xbc(%rbp),%eax
mov    %eax,-0x60(%rbp)
jmp    1fdb <main+0xc9b>
mov    -0x7c(%rbp),%eax
add    $0x1f4,%eax
mov    %eax,-0x60(%rbp)
jmp    1fe0 <main+0xca0>
cmpl   $0x0,-0x78(%rbp)
jne    1ff5 <main+0xcb5>
mov    -0x7c(%rbp),%eax
add    $0x1d4c0,%eax
mov    %eax,-0x60(%rbp)
jmp    1ffa <main+0xcba>
mov    $0x4,%edi
call   1060 <GetInput@plt>
mov    %eax,-0xc0(%rbp)
cmpl   $0x1,-0xc0(%rbp)
jne    2023 <main+0xce3>
movl   $0x1,-0x3c(%rbp)
jmp    207d <main+0xd3d>
cmpl   $0xffffffff,-0xc0(%rbp)
jne    203c <main+0xcfc>
movl   $0x0,-0x3c(%rbp)
jmp    2078 <main+0xd38>
cmpl   $0x0,-0x3c(%rbp)
jle    2073 <main+0xd33>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
cmp    $0xea60,%eax
jl     2073 <main+0xd33>
movsd  -0xb0(%rbp),%xmm0
ff
lea    0x12b8(%rip),%rdi
call   1050 <WriteToLogArgF@plt>
jmp    210f <main+0xdcf>
jmp    2078 <main+0xd38>
jmp    207d <main+0xd3d>
mov    -0x7c(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    2098 <main+0xd58>
mov    $0x0,%al
call   1240 <NudgeBrightness@plt>
cmpl   $0x0,-0x98(%rbp)
je     20f7 <main+0xdb7>
lea    0x128b(%rip),%rdi
lea    0x12d6(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     20f7 <main+0xdb7>
mov    -0x28(%rbp),%rdi
movsd  -0xb0(%rbp),%xmm0
ff
movsd  -0xb8(%rbp),%xmm1
ff
mov    -0x40(%rbp),%edx
mov    -0x44(%rbp),%ecx
lea    0x1260(%rip),%rsi
mov    $0x2,%al
call   1130 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
mov    $0x39f,%edi
call   1260 <usleep@plt>
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    171c <main+0x3dc>
lea    0xfbf(%rip),%rdi
lea    0x10d1(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     21e0 <main+0xea0>
lea    0xfae(%rip),%rdi
lea    0x124b(%rip),%rsi
call   11e0 <fopen@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
je     21d7 <main+0xe97>
jmp    215d <main+0xe1d>
mov    -0x28(%rbp),%rdi
call   1100 <fgetc@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
je     2186 <main+0xe46>
mov    -0x20(%rbp),%edi
mov    -0xc8(%rbp),%rsi
call   1120 <fputc@plt>
jmp    215d <main+0xe1d>
mov    -0xc8(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    $0x0,%al
call   1070 <GetBrightnessIndex@plt>
mov    -0xe8(%rbp),%rdi
movsbl %al,%edx
add    $0x41,%edx
lea    0x11ad(%rip),%rsi
mov    $0x0,%al
call   1130 <fprintf@plt>
mov    -0xc8(%rbp),%rdi
lea    0x119c(%rip),%rsi
mov    $0x0,%al
call   1130 <fprintf@plt>
mov    -0xc8(%rbp),%rdi
call   1090 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1090 <fclose@plt>
lea    0xe4d(%rip),%rdi
call   1030 <unlink@plt>
lea    0x1185(%rip),%rdi
call   10a0 <system@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
lea    0xcc3(%rip),%r14
xor    %r12d,%r12d
xor    %r15d,%r15d
xor    %r13d,%r13d
jmp    1387 <main+0x37>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   11b0 <usage@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1200 <getopt@plt>
cmp    $0x6a,%eax
jg     13b0 <main+0x60>
cmp    $0xffffffff,%eax
je     13c7 <main+0x77>
cmp    $0x62,%eax
jne    1380 <main+0x30>
mov    $0x1,%r13d
jmp    1387 <main+0x37>
nopl   0x0(%rax,%rax,1)
cmp    $0x6b,%eax
je     13bf <main+0x6f>
cmp    $0x6e,%eax
jne    1380 <main+0x30>
mov    $0x1,%r15b
jmp    1387 <main+0x37>
mov    $0x1,%r12d
jmp    1387 <main+0x37>
mov    0x2c12(%rip),%rax
cmp    %ebx,(%rax)
jge    13d9 <main+0x89>
xor    %eax,%eax
call   11b0 <usage@plt>
lea    0xc54(%rip),%rdi
lea    0xe07(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     1445 <main+0xf5>
mov    %rax,%rbx
lea    0xdc2(%rip),%rsi
lea    0x20(%rsp),%rdx
mov    %rax,%rdi
xor    %eax,%eax
call   10f0 <fscanf@plt>
cmp    $0x1,%eax
jne    1421 <main+0xd1>
mov    0x20(%rsp),%edi
mov    0x2bce(%rip),%rax
mov    (%rax),%esi
call   1150 <kill@plt>
mov    %rbx,%rdi
call   1090 <fclose@plt>
lea    0xc04(%rip),%rdi
call   1030 <unlink@plt>
mov    0x20(%rsp),%esi
lea    0xc08(%rip),%rdi
call   1170 <WriteToLogArgI@plt>
xor    %eax,%eax
test   %r12d,%r12d
jne    1f5a <main+0xc0a>
xor    %eax,%eax
call   1220 <InitGPIO@plt>
test   %eax,%eax
je     1505 <main+0x1b5>
xor    %eax,%eax
call   10d0 <InitBattery@plt>
test   $0x1,%r15b
jne    147e <main+0x12e>
xor    %edi,%edi
xor    %esi,%esi
call   1190 <daemon@plt>
test   %rax,%rax
jne    1f7d <main+0xc2d>
lea    0xbaf(%rip),%rdi
lea    0xefd(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     151d <main+0x1cd>
mov    %rax,%rbx
xor    %eax,%eax
call   1080 <getpid@plt>
lea    0xc11(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1130 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <fclose@plt>
xor    %eax,%eax
call   1160 <RotateLogs@plt>
xor    %eax,%eax
call   1080 <getpid@plt>
lea    0xbec(%rip),%rdi
mov    %eax,%esi
call   1170 <WriteToLogArgI@plt>
lea    0xbf3(%rip),%rdi
lea    0xd05(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     1547 <main+0x1f7>
mov    %rax,%rdi
call   1090 <fclose@plt>
mov    $0xffffffff,%ebx
jmp    15d5 <main+0x285>
mov    0x2ac4(%rip),%rax
mov    (%rax),%rcx
lea    0xb3c(%rip),%rdi
mov    $0x22,%esi
jmp    1533 <main+0x1e3>
mov    0x2aac(%rip),%rax
mov    (%rax),%rcx
lea    0xb69(%rip),%rdi
mov    $0x24,%esi
mov    $0x1,%edx
call   1230 <fwrite@plt>
mov    $0x1,%eax
jmp    1f5a <main+0xc0a>
lea    0xb97(%rip),%rdi
lea    0xc99(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     15a1 <main+0x251>
mov    %rax,%r14
lea    0xb6c(%rip),%rdi
lea    0xe19(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     15b7 <main+0x267>
mov    %rax,%rbp
nopl   (%rax)
mov    %r14,%rdi
call   1100 <fgetc@plt>
cmp    $0xffffffff,%eax
je     15a8 <main+0x258>
lea    -0x41(%rax),%ebx
cmp    $0x9,%ebx
jb     15ad <main+0x25d>
mov    %eax,%edi
mov    %rbp,%rsi
call   1120 <fputc@plt>
jmp    1580 <main+0x230>
mov    $0xffffffff,%ebx
jmp    15d5 <main+0x285>
mov    $0xffffffff,%ebx
mov    %rbp,%rdi
call   1090 <fclose@plt>
jmp    15bc <main+0x26c>
mov    $0xffffffff,%ebx
mov    %r14,%rdi
call   1090 <fclose@plt>
lea    0xb0a(%rip),%rdi
mov    $0x1b6,%esi
call   11c0 <chmod@plt>
cmp    $0x1,%ebx
adc    $0x0,%ebx
mov    %ebx,%edi
call   1140 <InitBrightness@plt>
xor    %edi,%edi
call   1060 <GetInput@plt>
cmp    $0xffffffff,%eax
je     1e91 <main+0xb41>
movsd  0xa06(%rip),%xmm0
movsd  %xmm0,0x30(%rsp)
movapd %xmm0,0x70(%rsp)
mov    $0x0,%r15d
movl   $0x1,0x10(%rsp)
movl   $0x1,0x3c(%rsp)
movl   $0x1,0x40(%rsp)
movl   $0x0,0x4c(%rsp)
movl   $0x0,0x48(%rsp)
movl   $0x0,0x44(%rsp)
xor    %ebx,%ebx
movl   $0x0,0x4(%rsp)
xor    %r14d,%r14d
mov    %r13d,0x28(%rsp)
mov    $0x1d4c0,%r13d
movl   $0x0,0x8(%rsp)
jmp    167e <main+0x32e>
xchg   %ax,%ax
mov    $0x39f,%edi
call   1270 <usleep@plt>
add    $0x1,%r15d
xor    %edi,%edi
call   1060 <GetInput@plt>
cmp    $0xffffffff,%eax
je     1e91 <main+0xb41>
mov    %ebx,%r12d
mov    %r15d,%ebp
mov    %rbp,0x80(%rsp)
mov    $0xd1b71759,%eax
imul   %rax,%rbp
mov    $0x1,%edi
call   1060 <GetInput@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
je     16c0 <main+0x370>
cmp    $0x1,%eax
jne    16e8 <main+0x398>
lea    0x1f4(%r15),%eax
mov    %eax,0x44(%rsp)
mov    $0x1,%ebx
jmp    16e8 <main+0x398>
nopl   (%rax)
lea    0xa45(%rip),%rdi
call   10a0 <system@plt>
cmp    0x44(%rsp),%r15d
jle    16dc <main+0x38c>
lea    0xa5a(%rip),%rdi
jmp    16e3 <main+0x393>
lea    0xa5f(%rip),%rdi
call   10a0 <system@plt>
shr    $0x2c,%rbp
mov    $0x2,%edi
call   1060 <GetInput@plt>
cmp    $0xffffffff,%eax
je     1720 <main+0x3d0>
cmp    $0x1,%eax
jne    1740 <main+0x3f0>
lea    0x1f4(%r15),%eax
mov    %eax,0x48(%rsp)
mov    $0x1,%ebx
jmp    1740 <main+0x3f0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    0x48(%rsp),%r15d
jle    1730 <main+0x3e0>
xor    %eax,%eax
call   11d0 <MaxBrightness@plt>
jmp    1740 <main+0x3f0>
xor    %eax,%eax
call   10e0 <NextBrightness@plt>
nopw   0x0(%rax,%rax,1)
imul   $0x1388,%ebp,%ebp
mov    $0x3,%edi
call   1060 <GetInput@plt>
cmp    $0xffffffff,%eax
je     1770 <main+0x420>
cmp    $0x1,%eax
jne    1796 <main+0x446>
lea    0x1f4(%r15),%eax
mov    %eax,0x4c(%rsp)
jmp    179a <main+0x44a>
nopw   0x0(%rax,%rax,1)
lea    0x9dd(%rip),%rdi
cmp    0x4c(%rsp),%r15d
jg     1791 <main+0x441>
lea    0x987(%rip),%rdi
call   10a0 <system@plt>
lea    0x9eb(%rip),%rdi
call   10a0 <system@plt>
test   %ebx,%ebx
je     17b0 <main+0x460>
test   %r12d,%r12d
je     17a6 <main+0x456>
xor    %eax,%eax
call   1180 <RestoreDisplay@plt>
lea    0x1d4c0(%r15),%r13d
xor    %r12d,%r12d
cmp    %r15d,%ebp
mov    %r13d,0x2c(%rsp)
mov    %r12d,0x14(%rsp)
jne    1960 <main+0x610>
lea    0x90b(%rip),%rdi
lea    0xa1d(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     1960 <main+0x610>
mov    %rax,%rbp
movl   $0x1,0x20(%rsp)
movl   $0x1,0x54(%rsp)
movl   $0x1,0x50(%rsp)
mov    %rax,%rdi
lea    0x9b3(%rip),%rsi
lea    0x20(%rsp),%rdx
lea    0x54(%rsp),%rcx
lea    0x50(%rsp),%r8
xor    %eax,%eax
call   10f0 <fscanf@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1090 <fclose@plt>
cmp    $0x3,%ebx
jne    1960 <main+0x610>
mov    0x20(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    0x54(%rsp),%eax
mov    0x40(%rsp),%ebx
test   %ebx,%ebx
mov    0x3c(%rsp),%r12d
je     18a1 <main+0x551>
test   %eax,%eax
jne    18a1 <main+0x551>
lea    0x96f(%rip),%rdi
lea    0xb31(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     18f8 <main+0x5a8>
mov    %rax,%rbp
mov    $0x2,%esi
mov    $0x1,%edx
lea    0x976(%rip),%rdi
mov    %rax,%rcx
call   1230 <fwrite@plt>
mov    %rbp,%rdi
call   1090 <fclose@plt>
lea    0x962(%rip),%rdi
call   10a0 <system@plt>
xor    %ebx,%ebx
lea    0x970(%rip),%rdi
jmp    18f1 <main+0x5a1>
test   %ebx,%ebx
jne    1901 <main+0x5b1>
test   %eax,%eax
je     1901 <main+0x5b1>
lea    0x910(%rip),%rdi
lea    0xad2(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     18ff <main+0x5af>
mov    %rax,%rbp
mov    $0x2,%esi
mov    $0x1,%edx
lea    0x955(%rip),%rdi
mov    %rax,%rcx
call   1230 <fwrite@plt>
mov    %rbp,%rdi
call   1090 <fclose@plt>
mov    $0x1,%ebx
lea    0x93c(%rip),%rdi
call   10c0 <WriteToLog@plt>
jmp    1901 <main+0x5b1>
mov    $0x1,%ebx
jmp    1901 <main+0x5b1>
xor    %ebx,%ebx
mov    %ebx,0x40(%rsp)
mov    0x50(%rsp),%eax
test   %r12d,%r12d
je     1922 <main+0x5d2>
xor    %ebx,%ebx
lea    0x930(%rip),%rdi
lea    0x94a(%rip),%rbp
test   %eax,%eax
je     1949 <main+0x5f9>
test   %r12d,%r12d
jne    1960 <main+0x610>
test   %eax,%eax
je     1960 <main+0x610>
lea    0x944(%rip),%rbp
mov    %rbp,%rdi
call   10a0 <system@plt>
mov    $0x1,%ebx
mov    %rbp,%rdi
lea    0x94f(%rip),%rbp
call   10a0 <system@plt>
mov    %rbp,%rdi
call   10c0 <WriteToLog@plt>
mov    %ebx,0x3c(%rsp)
nopw   0x0(%rax,%rax,1)
mov    0x4(%rsp),%ebp
mov    0x8(%rsp),%eax
mov    %eax,%r13d
or     %ebp,%eax
setne  %bl
mov    $0x5,%edi
call   1060 <GetInput@plt>
mov    %eax,%r12d
cmp    $0x1,%eax
je     19a0 <main+0x650>
cmp    $0xffffffff,%r12d
jne    19b0 <main+0x660>
mov    $0x1,%r12d
xor    %r13d,%r13d
jmp    19b3 <main+0x663>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12d,%r13d
jmp    19b3 <main+0x663>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %r12d,%r12d
mov    $0x6,%edi
call   1060 <GetInput@plt>
cmp    $0xffffffff,%eax
mov    %r14d,0xc(%rsp)
je     1a00 <main+0x6b0>
cmp    $0x1,%eax
jne    1a08 <main+0x6b8>
lea    0x8d2(%rip),%rdi
call   10c0 <WriteToLog@plt>
test   %r13d,%r13d
setne  %bpl
mov    $0x1,%r12d
mov    $0x1,%al
movl   $0x1,0x4(%rsp)
jmp    1a60 <main+0x710>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%r12d
xor    %ebp,%ebp
test   %r13d,%r13d
mov    %ebp,%eax
setne  %bpl
mov    %eax,0x4(%rsp)
test   %eax,%eax
setne  %al
test   %bl,%bl
je     1a60 <main+0x710>
mov    %r13d,%ecx
test   %r13d,%r13d
jne    1a60 <main+0x710>
cmpl   $0x0,0x4(%rsp)
jne    1a60 <main+0x710>
lea    0x884(%rip),%rdi
call   10c0 <WriteToLog@plt>
lea    0x1d4c0(%r15),%eax
mov    %eax,0x2c(%rsp)
xor    %ebp,%ebp
movl   $0x0,0x4(%rsp)
xor    %r14d,%r14d
mov    0x28(%rsp),%ebx
jmp    1a90 <main+0x740>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%r14b
test   %bl,%bl
je     1a70 <main+0x720>
mov    0x28(%rsp),%ebx
jmp    1a90 <main+0x740>
nopl   (%rax)
or     %bpl,%al
cmp    $0x1,%al
mov    0x28(%rsp),%ebx
jne    1a89 <main+0x739>
lea    0x84b(%rip),%rdi
call   10c0 <WriteToLog@plt>
jmp    1a90 <main+0x740>
xor    %ebp,%ebp
xor    %r14d,%r14d
xchg   %ax,%ax
mov    %r13d,%edi
lea    0x20(%rsp),%rsi
call   1040 <GetRawBatteryReadings@plt>
movsd  %xmm0,0x58(%rsp)
call   1240 <BatteryRawToVoltage@plt>
movsd  0x558(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1210 <round@plt>
divsd  0x547(%rip),%xmm0
movapd %xmm0,0x60(%rsp)
movsd  0x20(%rsp),%xmm0
call   1110 <BatteryRawToEnergyRemaining@plt>
call   1210 <round@plt>
movapd 0x60(%rsp),%xmm1
movsd  %xmm0,0x18(%rsp)
cmp    $0x4000,%r15d
mov    %r13d,0x8(%rsp)
jb     1b20 <main+0x7d0>
movapd 0x70(%rsp),%xmm0
ucomisd %xmm0,%xmm1
seta   %al
test   %al,%bpl
jne    1b10 <main+0x7c0>
test   %bpl,%bpl
jne    1b3c <main+0x7ec>
ucomisd 0x60(%rsp),%xmm0
jbe    1b3c <main+0x7ec>
test   %ebx,%ebx
movsd  0x58(%rsp),%xmm1
jne    1b8c <main+0x83c>
jmp    1ba4 <main+0x854>
nop
mov    0x2c(%rsp),%r13d
mov    0x14(%rsp),%ebx
cmp    %r13d,%r15d
jg     1c99 <main+0x949>
mov    0xc(%rsp),%r14d
jmp    1dd0 <main+0xa80>
movapd 0x60(%rsp),%xmm2
movapd %xmm2,%xmm0
subsd  0x70(%rsp),%xmm0
andpd  0x4cc(%rip),%xmm0
movsd  0x4b4(%rip),%xmm1
ucomisd %xmm1,%xmm0
cmpnltsd %xmm0,%xmm1
movapd 0x70(%rsp),%xmm0
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm1,%xmm0
mov    $0x1,%eax
cmova  %eax,%r12d
movsd  0x58(%rsp),%xmm1
jbe    1bb0 <main+0x860>
test   %ebx,%ebx
je     1bb0 <main+0x860>
lea    0x74c(%rip),%rdi
movapd 0x60(%rsp),%xmm0
call   1050 <WriteToLogArgF@plt>
movsd  0x58(%rsp),%xmm1
mov    $0x1,%r12d
movapd 0x60(%rsp),%xmm0
movapd %xmm0,0x70(%rsp)
movsd  0x18(%rsp),%xmm0
ucomisd 0x30(%rsp),%xmm0
seta   %al
test   %al,%bpl
mov    0x2c(%rsp),%r13d
jne    1c00 <main+0x8b0>
test   %bpl,%bpl
jne    1be2 <main+0x892>
movsd  0x30(%rsp),%xmm0
ucomisd 0x18(%rsp),%xmm0
ja     1c00 <main+0x8b0>
movsd  0x18(%rsp),%xmm0
subsd  0x30(%rsp),%xmm0
andpd  0x42a(%rip),%xmm0
ucomisd 0x41a(%rip),%xmm0
jbe    1c2e <main+0x8de>
test   %ebx,%ebx
je     1c74 <main+0x924>
lea    0x6eb(%rip),%rdi
movsd  0x18(%rsp),%xmm0
call   1050 <WriteToLogArgF@plt>
movsd  0x58(%rsp),%xmm1
mov    $0x1,%r12d
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
test   %ebx,%ebx
je     1b25 <main+0x7d5>
imul   $0x45e7b273,0x80(%rsp),%rax
shr    $0x2e,%rax
imul   $0xea60,%eax,%eax
add    $0x4000,%eax
cmp    %r15d,%eax
mov    0x14(%rsp),%ebx
jne    1c90 <main+0x940>
lea    0x6ae(%rip),%rdi
movapd %xmm1,%xmm0
call   1050 <WriteToLogArgF@plt>
cmp    %r13d,%r15d
jg     1c99 <main+0x949>
jmp    1b32 <main+0x7e2>
mov    $0x1,%r12d
movsd  0x18(%rsp),%xmm0
movsd  %xmm0,0x30(%rsp)
mov    0x14(%rsp),%ebx
nopw   0x0(%rax,%rax,1)
cmp    %r13d,%r15d
jle    1b32 <main+0x7e2>
test   %ebx,%ebx
sete   %al
test   %r14b,%al
je     1cb0 <main+0x960>
xor    %ebx,%ebx
mov    0xc(%rsp),%r14d
jmp    1dd0 <main+0xa80>
nop
xor    %eax,%eax
call   11a0 <IdleTime@plt>
mov    %eax,%ebp
cmp    $0x2,%ebx
je     1cfb <main+0x9ab>
cmp    $0x1,%ebx
je     1d25 <main+0x9d5>
test   %ebx,%ebx
mov    0xc(%rsp),%r14d
jne    1dc0 <main+0xa70>
cmp    $0x1d4c1,%ebp
jl     1d5e <main+0xa0e>
cmpl   $0x0,0x10(%rsp)
je     1d5e <main+0xa0e>
xor    %eax,%eax
call   1260 <DimDisplay@plt>
lea    0x1f4(%r15),%r13d
mov    $0x1,%ebx
jmp    1dc0 <main+0xa70>
cmp    $0x1d4c0,%ebp
setl   %al
cmpl   $0x0,0x10(%rsp)
sete   %cl
or     %al,%cl
or     %cl,%r14b
cmp    $0x1,%r14b
je     1d41 <main+0x9f1>
lea    0x1f4(%r15),%r13d
mov    $0x2,%ebx
jmp    1d57 <main+0xa07>
cmp    $0x1d4c0,%ebp
setl   %al
cmpl   $0x0,0x10(%rsp)
sete   %cl
or     %al,%cl
or     %cl,%r14b
cmp    $0x1,%r14b
jne    1d6f <main+0xa1f>
xor    %ebx,%ebx
xor    %eax,%eax
call   1180 <RestoreDisplay@plt>
mov    %r15d,%r13d
sub    %ebp,%r13d
add    $0x1d4c0,%r13d
mov    0xc(%rsp),%r14d
jmp    1dc0 <main+0xa70>
mov    %r15d,%r13d
sub    %ebp,%r13d
add    $0x1d4c0,%r13d
xor    %ebx,%ebx
jmp    1dc0 <main+0xa70>
cmp    $0x493e1,%ebp
mov    0xc(%rsp),%r14d
jl     1cea <main+0x99a>
cmpl   $0x0,0x10(%rsp)
je     1cea <main+0x99a>
xor    %eax,%eax
call   10b0 <DarkenDisplay@plt>
lea    0x373(%rip),%rdi
call   10a0 <system@plt>
lea    0x38f(%rip),%rdi
call   10a0 <system@plt>
lea    0x1f4(%r15),%r13d
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
lea    0x1d4c0(%r15),%eax
cmpl   $0x0,0x10(%rsp)
cmove  %eax,%r13d
mov    $0x4,%edi
call   1060 <GetInput@plt>
cmp    $0x1,%eax
je     1df0 <main+0xaa0>
cmp    $0xffffffff,%eax
movapd 0x60(%rsp),%xmm0
jne    1e00 <main+0xab0>
xor    %r14d,%r14d
jmp    1e16 <main+0xac6>
nop
mov    %eax,%r14d
jmp    1e16 <main+0xac6>
cs nopw 0x0(%rax,%rax,1)
nop
test   %r14d,%r14d
jle    1e16 <main+0xac6>
cmp    $0xea5e,%r14d
ja     1f6c <main+0xc1c>
add    $0x1,%r14d
test   $0xf,%r15b
je     1e30 <main+0xae0>
test   %r12d,%r12d
jne    1e40 <main+0xaf0>
jmp    1660 <main+0x310>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1250 <NudgeBrightness@plt>
test   %r12d,%r12d
je     1660 <main+0x310>
lea    0x4f0(%rip),%rdi
lea    0x53b(%rip),%rsi
call   11e0 <fopen@plt>
movapd 0x60(%rsp),%xmm0
test   %rax,%rax
je     1660 <main+0x310>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0x4d8(%rip),%rsi
movsd  0x18(%rsp),%xmm1
mov    0x8(%rsp),%edx
mov    0x4(%rsp),%ecx
mov    $0x2,%al
call   1130 <fprintf@plt>
mov    %rbp,%rdi
call   1090 <fclose@plt>
jmp    1660 <main+0x310>
lea    0x261(%rip),%rdi
call   10c0 <WriteToLog@plt>
lea    0x231(%rip),%rdi
lea    0x343(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     1f40 <main+0xbf0>
mov    %rax,%rbx
lea    0x222(%rip),%rdi
lea    0x4bf(%rip),%rsi
call   11e0 <fopen@plt>
test   %rax,%rax
je     1f38 <main+0xbe8>
mov    %rax,%rbp
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1100 <fgetc@plt>
cmp    $0xffffffff,%eax
je     1ef9 <main+0xba9>
mov    %eax,%edi
mov    %rbp,%rsi
call   1120 <fputc@plt>
jmp    1ee0 <main+0xb90>
xor    %eax,%eax
call   1070 <GetBrightnessIndex@plt>
movsbl %al,%edx
add    $0x41,%edx
lea    0x44f(%rip),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1130 <fprintf@plt>
lea    0x442(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1230 <fwrite@plt>
mov    %rbp,%rdi
call   1090 <fclose@plt>
mov    %rbx,%rdi
call   1090 <fclose@plt>
lea    0xed(%rip),%rdi
call   1030 <unlink@plt>
lea    0x425(%rip),%rdi
call   10a0 <system@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x3ae(%rip),%rdi
call   1050 <WriteToLogArgF@plt>
jmp    1e9d <main+0xb4d>
lea    0xf1(%rip),%rdi
call   11f0 <perror@plt>
mov    $0x1,%eax
jmp    1f5a <main+0xc0a>

LLVM IR (-O0):
@.str = [4 x i8] c"bkn\00"
@optind = global i32 0
@.str.1 = [20 x i8] c"/var/run/pitabd.pid\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
@SIGINT = global i32 0
@.str.4 = [10 x i8] c"killed %d\00"
@stderr = global i32* null
@.str.5 = [35 x i8] c"pitabd: failed to initialize GPIO\0A\00"
@.str.6 = [34 x i8] c"pitabd: failed to become a daemon\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [37 x i8] c"pitabd: unable to record process ID\0A\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@.str.10 = [21 x i8] c"starting with pid=%d\00"
@.str.11 = [16 x i8] c"/ram/pitabd.cmd\00"
@.str.12 = [20 x i8] c"/var/tmp/pitabd.cmd\00"
@.str.13 = [19 x i8] c"shutdown initiated\00"
@.str.14 = [40 x i8] c"wmctrl -r :ACTIVE: -b remove,fullscreen\00"
@.str.15 = [14 x i8] c"wmctrl -a \22%\22\00"
@.str.16 = [18 x i8] c"wmctrl -a \22xvkbd\22\00"
@.str.17 = [40 x i8] c"wmctrl -r :ACTIVE: -b toggle,fullscreen\00"
@.str.18 = [59 x i8] c"wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz\00"
@.str.19 = [9 x i8] c"%d %d %d\00"
@.str.20 = [48 x i8] c"/sys/devices/platform/soc/3f980000.usb/buspower\00"
@.str.21 = [3 x i8] c"0\0A\00"
@.str.22 = [28 x i8] c"/usr/bin/lxpanelctl restart\00"
@.str.23 = [27 x i8] c"disabled USB and Bluetooth\00"
@.str.24 = [3 x i8] c"1\0A\00"
@.str.25 = [26 x i8] c"enabled USB and Bluetooth\00"
@.str.26 = [33 x i8] c"/sbin/iwconfig wlan0 txpower off\00"
@.str.27 = [14 x i8] c"disabled wifi\00"
@.str.28 = [34 x i8] c"/sbin/iwconfig wlan0 txpower auto\00"
@.str.29 = [13 x i8] c"enabled wifi\00"
@.str.30 = [19 x i8] c"charging completed\00"
@.str.31 = [21 x i8] c"charger disconnected\00"
@.str.32 = [18 x i8] c"charger connected\00"
@.str.33 = [23 x i8] c"battery voltage %1.2fV\00"
@.str.34 = [25 x i8] c"energy remaining %1.0f%%\00"
@.str.35 = [18 x i8] c"raw battery %1.3f\00"
@.str.36 = [22 x i8] c"low battery at %1.2fV\00"
@.str.37 = [16 x i8] c"/ram/pitabd.dat\00"
@.str.38 = [21 x i8] c"%4.2f %2.0f %1d %1d\0A\00"
@.str.39 = [4 x i8] c"%c\0A\00"
@.str.40 = [24 x i8] c"Do not edit this file!\0A\00"
@.str.41 = [19 x i8] c"/sbin/shutdown now\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca double
%18 = alloca double
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
%31 = alloca i32
%32 = alloca i32
%33 = alloca i32
%34 = alloca i32
%35 = alloca double
%36 = alloca double
%37 = alloca double
%38 = alloca double
%39 = alloca i32
%40 = alloca i32
%41 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
br label %42
42: ; preds = %54, %2
%43 = load i32, i32* %4
%44 = load i8**, i8*** %5
%45 = call i32 @getopt(i32 %43, i8** %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %45, i32* %9
%46 = icmp ne i32 %45, -1
br i1 %46, label %47, label %55
47: ; preds = %42
%48 = load i32, i32* %9
switch i32 %48, label %52 [
i32 98, label %49
i32 107, label %50
i32 110, label %51
]
49: ; preds = %47
store i32 1, i32* %6
br label %54
50: ; preds = %47
store i32 1, i32* %7
br label %54
51: ; preds = %47
store i32 0, i32* %8
br label %54
52: ; preds = %47
%53 = call i32 (...) @usage()
br label %54
54: ; preds = %52, %51, %50, %49
br label %42
55: ; preds = %42
%56 = load i32, i32* @optind
%57 = load i32, i32* %4
%58 = icmp slt i32 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = call i32 (...) @usage()
br label %61
61: ; preds = %59, %55
%62 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %62, i32** %10
%63 = load i32*, i32** %10
%64 = icmp ne i32* %63, null
br i1 %64, label %65, label %79
65: ; preds = %61
%66 = load i32*, i32** %10
%67 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %11)
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %73
69: ; preds = %65
%70 = load i32, i32* %11
%71 = load i32, i32* @SIGINT
%72 = call i32 @kill(i32 %70, i32 %71)
br label %73
73: ; preds = %69, %65
%74 = load i32*, i32** %10
%75 = call i32 @fclose(i32* %74)
%76 = call i32 @unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%77 = load i32, i32* %11
%78 = call i32 @WriteToLogArgI(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %77)
br label %79
79: ; preds = %73, %61
%80 = load i32, i32* %7
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %83
82: ; preds = %79
store i32 0, i32* %3
br label %608
83: ; preds = %79
%84 = call i32 (...) @InitGPIO()
%85 = icmp ne i32 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %83
%87 = load i32*, i32** @stderr
%88 = call i32 (i32*, i8*, ...) @fprintf(i32* %87, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %608
89: ; preds = %83
%90 = call i32 (...) @InitBattery()
%91 = load i32, i32* %8
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %98
93: ; preds = %89
%94 = call i64 @daemon(i32 0, i32 0)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %93
%97 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %608
98: ; preds = %93, %89
%99 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %99, i32** %10
%100 = icmp eq i32* %99, null
br i1 %100, label %101, label %104
101: ; preds = %98
%102 = load i32*, i32** @stderr
%103 = call i32 (i32*, i8*, ...) @fprintf(i32* %102, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %608
104: ; preds = %98
%105 = load i32*, i32** %10
%106 = call i32 (...) @getpid()
%107 = call i32 (i32*, i8*, ...) @fprintf(i32* %105, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %106)
%108 = load i32*, i32** %10
%109 = call i32 @fclose(i32* %108)
%110 = call i32 (...) @RotateLogs()
%111 = call i32 (...) @getpid()
%112 = call i32 @WriteToLogArgI(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i32 %111)
store i32 -1, i32* %12
%113 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %113, i32** %10
%114 = icmp ne i32* %113, null
br i1 %114, label %115, label %118
115: ; preds = %104
%116 = load i32*, i32** %10
%117 = call i32 @fclose(i32* %116)
br label %151
118: ; preds = %104
%119 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %119, i32** %10
%120 = icmp ne i32* %119, null
br i1 %120, label %121, label %150
121: ; preds = %118
%122 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %122, i32** %13
%123 = load i32*, i32** %13
%124 = icmp ne i32* %123, null
br i1 %124, label %125, label %146
125: ; preds = %121
br label %126
126: ; preds = %139, %125
%127 = load i32*, i32** %10
%128 = call i32 @fgetc(i32* %127)
store i32 %128, i32* %9
%129 = icmp ne i32 %128, -1
br i1 %129, label %130, label %143
130: ; preds = %126
%131 = load i32, i32* %9
%132 = icmp sle i32 65, %131
br i1 %132, label %133, label %139
133: ; preds = %130
%134 = load i32, i32* %9
%135 = icmp sle i32 %134, 73
br i1 %135, label %136, label %139
136: ; preds = %133
%137 = load i32, i32* %9
%138 = sub nsw i32 %137, 65
store i32 %138, i32* %12
br label %143
139: ; preds = %133, %130
%140 = load i32, i32* %9
%141 = load i32*, i32** %13
%142 = call i32 @fputc(i32 %140, i32* %141)
br label %126
143: ; preds = %136, %126
%144 = load i32*, i32** %13
%145 = call i32 @fclose(i32* %144)
br label %146
146: ; preds = %143, %121
%147 = load i32*, i32** %10
%148 = call i32 @fclose(i32* %147)
%149 = call i32 @chmod(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i32 438)
br label %150
150: ; preds = %146, %118
br label %151
151: ; preds = %150, %115
%152 = load i32, i32* %12
%153 = load i32, i32* %12
%154 = icmp ne i32 %153, 0
%155 = xor i1 %154, true
%156 = zext i1 %155 to i32
%157 = add nsw i32 %152, %156
%158 = call i32 @InitBrightness(i32 %157)
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
store double -1.000000e+00, double* %17
store double -1.000000e+00, double* %18
store i32 0, i32* %19
store i32 120000, i32* %20
store i32 0, i32* %21
store i32 0, i32* %22
store i32 0, i32* %23
store i32 1, i32* %24
store i32 1, i32* %25
store i32 1, i32* %26
store i32 0, i32* %27
br label %159
159: ; preds = %573, %151
%160 = call i32 @GetInput(i32 0)
%161 = icmp eq i32 %160, -1
br i1 %161, label %162, label %164
162: ; preds = %159
%163 = call i32 @WriteToLog(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
br label %576
164: ; preds = %159
store i32 0, i32* %28
%165 = call i32 @GetInput(i32 1)
store i32 %165, i32* %9
%166 = load i32, i32* %9
%167 = icmp eq i32 %166, 1
br i1 %167, label %168, label %171
168: ; preds = %164
%169 = load i32, i32* %27
%170 = add nsw i32 %169, 500
store i32 %170, i32* %21
store i32 1, i32* %28
br label %185
171: ; preds = %164
%172 = load i32, i32* %9
%173 = icmp eq i32 %172, -1
br i1 %173, label %174, label %184
174: ; preds = %171
%175 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0))
%176 = load i32, i32* %27
%177 = load i32, i32* %21
%178 = icmp sgt i32 %176, %177
br i1 %178, label %179, label %181
179: ; preds = %174
%180 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0))
br label %183
181: ; preds = %174
%182 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0))
br label %183
183: ; preds = %181, %179
br label %184
184: ; preds = %183, %171
br label %185
185: ; preds = %184, %168
%186 = call i32 @GetInput(i32 2)
store i32 %186, i32* %9
%187 = load i32, i32* %9
%188 = icmp eq i32 %187, 1
br i1 %188, label %189, label %192
189: ; preds = %185
%190 = load i32, i32* %27
%191 = add nsw i32 %190, 500
store i32 %191, i32* %22
store i32 1, i32* %28
br label %205
192: ; preds = %185
%193 = load i32, i32* %9
%194 = icmp eq i32 %193, -1
br i1 %194, label %195, label %204
195: ; preds = %192
%196 = load i32, i32* %27
%197 = load i32, i32* %22
%198 = icmp sgt i32 %196, %197
br i1 %198, label %199, label %201
199: ; preds = %195
%200 = call i32 (...) @MaxBrightness()
br label %203
201: ; preds = %195
%202 = call i32 (...) @NextBrightness()
br label %203
203: ; preds = %201, %199
br label %204
204: ; preds = %203, %192
br label %205
205: ; preds = %204, %189
%206 = call i32 @GetInput(i32 3)
store i32 %206, i32* %9
%207 = load i32, i32* %9
%208 = icmp eq i32 %207, 1
br i1 %208, label %209, label %212
209: ; preds = %205
%210 = load i32, i32* %27
%211 = add nsw i32 %210, 500
store i32 %211, i32* %23
store i32 1, i32* %28
br label %226
212: ; preds = %205
%213 = load i32, i32* %9
%214 = icmp eq i32 %213, -1
br i1 %214, label %215, label %225
215: ; preds = %212
%216 = load i32, i32* %27
%217 = load i32, i32* %23
%218 = icmp sgt i32 %216, %217
br i1 %218, label %219, label %221
219: ; preds = %215
%220 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.17, i64 0, i64 0))
br label %224
221: ; preds = %215
%222 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0))
%223 = call i32 @system(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.18, i64 0, i64 0))
br label %224
224: ; preds = %221, %219
br label %225
225: ; preds = %224, %212
br label %226
226: ; preds = %225, %209
%227 = load i32, i32* %28
%228 = icmp ne i32 %227, 0
br i1 %228, label %229, label %237
229: ; preds = %226
%230 = load i32, i32* %19
%231 = icmp ne i32 %230, 0
br i1 %231, label %232, label %234
232: ; preds = %229
%233 = call i32 (...) @RestoreDisplay()
store i32 0, i32* %19
br label %234
234: ; preds = %232, %229
%235 = load i32, i32* %27
%236 = add nsw i32 %235, 120000
store i32 %236, i32* %20
br label %237
237: ; preds = %234, %226
%238 = load i32, i32* %27
%239 = srem i32 %238, 5000
%240 = icmp eq i32 %239, 0
br i1 %240, label %241, label %308
241: ; preds = %237
%242 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %242, i32** %10
%243 = icmp ne i32* %242, null
br i1 %243, label %244, label %308
244: ; preds = %241
store i32 1, i32* %29
store i32 1, i32* %30
store i32 1, i32* %31
%245 = load i32*, i32** %10
%246 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %245, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0), i32* %29, i32* %30, i32* %31)
store i32 %246, i32* %32
%247 = load i32*, i32** %10
%248 = call i32 @fclose(i32* %247)
%249 = load i32, i32* %32
%250 = icmp eq i32 %249, 3
br i1 %250, label %251, label %307
251: ; preds = %244
%252 = load i32, i32* %29
store i32 %252, i32* %26
%253 = load i32, i32* %24
%254 = icmp ne i32 %253, 0
br i1 %254, label %255, label %269
255: ; preds = %251
%256 = load i32, i32* %30
%257 = icmp ne i32 %256, 0
br i1 %257, label %269, label %258
258: ; preds = %255
%259 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %259, i32** %10
%260 = icmp ne i32* %259, null
br i1 %260, label %261, label %268
261: ; preds = %258
%262 = load i32*, i32** %10
%263 = call i32 (i32*, i8*, ...) @fprintf(i32* %262, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0))
%264 = load i32*, i32** %10
%265 = call i32 @fclose(i32* %264)
%266 = call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.22, i64 0, i64 0))
%267 = call i32 @WriteToLog(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.23, i64 0, i64 0))
store i32 0, i32* %24
br label %268
268: ; preds = %261, %258
br label %286
269: ; preds = %255, %251
%270 = load i32, i32* %24
%271 = icmp ne i32 %270, 0
br i1 %271, label %285, label %272
272: ; preds = %269
%273 = load i32, i32* %30
%274 = icmp ne i32 %273, 0
br i1 %274, label %275, label %285
275: ; preds = %272
%276 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %276, i32** %10
%277 = icmp ne i32* %276, null
br i1 %277, label %278, label %284
278: ; preds = %275
%279 = load i32*, i32** %10
%280 = call i32 (i32*, i8*, ...) @fprintf(i32* %279, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.24, i64 0, i64 0))
%281 = load i32*, i32** %10
%282 = call i32 @fclose(i32* %281)
%283 = call i32 @WriteToLog(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.25, i64 0, i64 0))
store i32 1, i32* %24
br label %284
284: ; preds = %278, %275
br label %285
285: ; preds = %284, %272, %269
br label %286
286: ; preds = %285, %268
%287 = load i32, i32* %25
%288 = icmp ne i32 %287, 0
br i1 %288, label %289, label %295
289: ; preds = %286
%290 = load i32, i32* %31
%291 = icmp ne i32 %290, 0
br i1 %291, label %295, label %292
292: ; preds = %289
%293 = call i32 @system(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.26, i64 0, i64 0))
%294 = call i32 @WriteToLog(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.27, i64 0, i64 0))
store i32 0, i32* %25
br label %306
295: ; preds = %289, %286
%296 = load i32, i32* %25
%297 = icmp ne i32 %296, 0
br i1 %297, label %305, label %298
298: ; preds = %295
%299 = load i32, i32* %31
%300 = icmp ne i32 %299, 0
br i1 %300, label %301, label %305
301: ; preds = %298
%302 = call i32 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.28, i64 0, i64 0))
%303 = call i32 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.28, i64 0, i64 0))
%304 = call i32 @WriteToLog(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.29, i64 0, i64 0))
store i32 1, i32* %25
br label %305
305: ; preds = %301, %298, %295
br label %306
306: ; preds = %305, %292
br label %307
307: ; preds = %306, %244
br label %308
308: ; preds = %307, %241, %237
%309 = load i32, i32* %15
%310 = icmp ne i32 %309, 0
br i1 %310, label %314, label %311
311: ; preds = %308
%312 = load i32, i32* %16
%313 = icmp ne i32 %312, 0
br label %314
314: ; preds = %311, %308
%315 = phi i1 [ true, %308 ], [ %313, %311 ]
%316 = zext i1 %315 to i32
store i32 %316, i32* %33
store i32 0, i32* %34
%317 = call i32 @GetInput(i32 5)
store i32 %317, i32* %9
%318 = load i32, i32* %9
%319 = icmp eq i32 %318, 1
br i1 %319, label %320, label %321
320: ; preds = %314
store i32 1, i32* %15
store i32 1, i32* %34
br label %326
321: ; preds = %314
%322 = load i32, i32* %9
%323 = icmp eq i32 %322, -1
br i1 %323, label %324, label %325
324: ; preds = %321
store i32 0, i32* %15
store i32 1, i32* %34
br label %325
325: ; preds = %324, %321
br label %326
326: ; preds = %325, %320
%327 = call i32 @GetInput(i32 6)
store i32 %327, i32* %9
%328 = load i32, i32* %9
%329 = icmp eq i32 %328, 1
br i1 %329, label %330, label %332
330: ; preds = %326
%331 = call i32 @WriteToLog(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.30, i64 0, i64 0))
store i32 1, i32* %16
store i32 1, i32* %34
br label %337
332: ; preds = %326
%333 = load i32, i32* %9
%334 = icmp eq i32 %333, -1
br i1 %334, label %335, label %336
335: ; preds = %332
store i32 0, i32* %16
store i32 1, i32* %34
br label %336
336: ; preds = %335, %332
br label %337
337: ; preds = %336, %330
%338 = load i32, i32* %33
%339 = icmp ne i32 %338, 0
br i1 %339, label %340, label %350
340: ; preds = %337
%341 = load i32, i32* %15
%342 = icmp ne i32 %341, 0
br i1 %342, label %350, label %343
343: ; preds = %340
%344 = load i32, i32* %16
%345 = icmp ne i32 %344, 0
br i1 %345, label %350, label %346
346: ; preds = %343
%347 = call i32 @WriteToLog(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.31, i64 0, i64 0))
%348 = load i32, i32* %27
%349 = add nsw i32 %348, 120000
store i32 %349, i32* %20
store i32 0, i32* %33
br label %362
350: ; preds = %343, %340, %337
%351 = load i32, i32* %33
%352 = icmp ne i32 %351, 0
br i1 %352, label %361, label %353
353: ; preds = %350
%354 = load i32, i32* %15
%355 = icmp ne i32 %354, 0
br i1 %355, label %359, label %356
356: ; preds = %353
%357 = load i32, i32* %16
%358 = icmp ne i32 %357, 0
br i1 %358, label %359, label %361
359: ; preds = %356, %353
%360 = call i32 @WriteToLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.32, i64 0, i64 0))
store i32 1, i32* %33
br label %361
361: ; preds = %359, %356, %350
br label %362
362: ; preds = %361, %346
%363 = load i32, i32* %15
%364 = call double @GetRawBatteryReadings(i32 %363, double* %35)
store double %364, double* %36
%365 = load double, double* %36
%366 = call double @BatteryRawToVoltage(double %365)
%367 = fmul double %366, 1.000000e+02
%368 = call double @llvm.round.f64(double %367)
%369 = fdiv double %368, 1.000000e+02
store double %369, double* %37
%370 = load double, double* %35
%371 = call double @BatteryRawToEnergyRemaining(double %370)
%372 = call double @llvm.round.f64(double %371)
store double %372, double* %38
%373 = load i32, i32* %27
%374 = icmp sge i32 %373, 16384
br i1 %374, label %375, label %442
375: ; preds = %362
%376 = load i32, i32* %15
%377 = icmp ne i32 %376, 0
br i1 %377, label %378, label %382
378: ; preds = %375
%379 = load double, double* %37
%380 = load double, double* %17
%381 = fcmp ogt double %379, %380
br i1 %381, label %395, label %382
382: ; preds = %378, %375
%383 = load i32, i32* %15
%384 = icmp ne i32 %383, 0
br i1 %384, label %389, label %385
385: ; preds = %382
%386 = load double, double* %37
%387 = load double, double* %17
%388 = fcmp olt double %386, %387
br i1 %388, label %395, label %389
389: ; preds = %385, %382
%390 = load double, double* %37
%391 = load double, double* %17
%392 = fsub double %390, %391
%393 = call double @llvm.fabs.f64(double %392)
%394 = fcmp ogt double %393, 1.010000e-02
br i1 %394, label %395, label %403
395: ; preds = %389, %385, %378
%396 = load i32, i32* %6
%397 = icmp ne i32 %396, 0
br i1 %397, label %398, label %401
398: ; preds = %395
%399 = load double, double* %37
%400 = call i32 @WriteToLogArgF(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.33, i64 0, i64 0), double %399)
br label %401
401: ; preds = %398, %395
%402 = load double, double* %37
store double %402, double* %17
store i32 1, i32* %34
br label %403
403: ; preds = %401, %389
%404 = load i32, i32* %15
%405 = icmp ne i32 %404, 0
br i1 %405, label %406, label %410
406: ; preds = %403
%407 = load double, double* %38
%408 = load double, double* %18
%409 = fcmp ogt double %407, %408
br i1 %409, label %423, label %410
410: ; preds = %406, %403
%411 = load i32, i32* %15
%412 = icmp ne i32 %411, 0
br i1 %412, label %417, label %413
413: ; preds = %410
%414 = load double, double* %38
%415 = load double, double* %18
%416 = fcmp olt double %414, %415
br i1 %416, label %423, label %417
417: ; preds = %413, %410
%418 = load double, double* %38
%419 = load double, double* %18
%420 = fsub double %418, %419
%421 = call double @llvm.fabs.f64(double %420)
%422 = fcmp ogt double %421, 1.010000e+00
br i1 %422, label %423, label %431
423: ; preds = %417, %413, %406
%424 = load i32, i32* %6
%425 = icmp ne i32 %424, 0
br i1 %425, label %426, label %429
426: ; preds = %423
%427 = load double, double* %38
%428 = call i32 @WriteToLogArgF(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.34, i64 0, i64 0), double %427)
br label %429
429: ; preds = %426, %423
%430 = load double, double* %38
store double %430, double* %18
store i32 1, i32* %34
br label %431
431: ; preds = %429, %417
%432 = load i32, i32* %6
%433 = icmp ne i32 %432, 0
br i1 %433, label %434, label %441
434: ; preds = %431
%435 = load i32, i32* %27
%436 = srem i32 %435, 60000
%437 = icmp eq i32 %436, 16384
br i1 %437, label %438, label %441
438: ; preds = %434
%439 = load double, double* %36
%440 = call i32 @WriteToLogArgF(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.35, i64 0, i64 0), double %439)
br label %441
441: ; preds = %438, %434, %431
br label %442
442: ; preds = %441, %362
%443 = load i32, i32* %27
%444 = load i32, i32* %20
%445 = icmp sgt i32 %443, %444
br i1 %445, label %446, label %529
446: ; preds = %442
%447 = load i32, i32* %19
%448 = icmp ne i32 %447, 0
br i1 %448, label %452, label %449
449: ; preds = %446
%450 = load i32, i32* %33
%451 = icmp ne i32 %450, 0
br i1 %451, label %529, label %452
452: ; preds = %449, %446
%453 = call i32 (...) @IdleTime()
store i32 %453, i32* %39
%454 = load i32, i32* %19
switch i32 %454, label %522 [
i32 0, label %455
i32 1, label %471
i32 2, label %503
]
455: ; preds = %452
%456 = load i32, i32* %39
%457 = icmp sgt i32 %456, 120000
br i1 %457, label %458, label %465
458: ; preds = %455
%459 = load i32, i32* %26
%460 = icmp ne i32 %459, 0
br i1 %460, label %461, label %465
461: ; preds = %458
%462 = call i32 (...) @DimDisplay()
store i32 1, i32* %19
%463 = load i32, i32* %27
%464 = add nsw i32 %463, 500
store i32 %464, i32* %20
br label %470
465: ; preds = %458, %455
%466 = load i32, i32* %27
%467 = add nsw i32 %466, 120000
%468 = load i32, i32* %39
%469 = sub nsw i32 %467, %468
store i32 %469, i32* %20
br label %470
470: ; preds = %465, %461
br label %522
471: ; preds = %452
%472 = load i32, i32* %39
%473 = icmp slt i32 %472, 120000
br i1 %473, label %480, label %474
474: ; preds = %471
%475 = load i32, i32* %26
%476 = icmp ne i32 %475, 0
br i1 %476, label %477, label %480
477: ; preds = %474
%478 = load i32, i32* %33
%479 = icmp ne i32 %478, 0
br i1 %479, label %480, label %486
480: ; preds = %477, %474, %471
%481 = call i32 (...) @RestoreDisplay()
store i32 0, i32* %19
%482 = load i32, i32* %27
%483 = add nsw i32 %482, 120000
%484 = load i32, i32* %39
%485 = sub nsw i32 %483, %484
store i32 %485, i32* %20
br label %502
486: ; preds = %477
%487 = load i32, i32* %39
%488 = icmp sgt i32 %487, 300000
br i1 %488, label %489, label %498
489: ; preds = %486
%490 = load i32, i32* %26
%491 = icmp ne i32 %490, 0
br i1 %491, label %492, label %498
492: ; preds = %489
%493 = call i32 (...) @DarkenDisplay()
%494 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0))
%495 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0))
store i32 2, i32* %19
%496 = load i32, i32* %27
%497 = add nsw i32 %496, 500
store i32 %497, i32* %20
br label %501
498: ; preds = %489, %486
%499 = load i32, i32* %27
%500 = add nsw i32 %499, 500
store i32 %500, i32* %20
br label %501
501: ; preds = %498, %492
br label %502
502: ; preds = %501, %480
br label %522
503: ; preds = %452
%504 = load i32, i32* %39
%505 = icmp slt i32 %504, 120000
br i1 %505, label %512, label %506
506: ; preds = %503
%507 = load i32, i32* %26
%508 = icmp ne i32 %507, 0
br i1 %508, label %509, label %512
509: ; preds = %506
%510 = load i32, i32* %33
%511 = icmp ne i32 %510, 0
br i1 %511, label %512, label %518
512: ; preds = %509, %506, %503
%513 = call i32 (...) @RestoreDisplay()
store i32 0, i32* %19
%514 = load i32, i32* %27
%515 = add nsw i32 %514, 120000
%516 = load i32, i32* %39
%517 = sub nsw i32 %515, %516
store i32 %517, i32* %20
br label %521
518: ; preds = %509
%519 = load i32, i32* %27
%520 = add nsw i32 %519, 500
store i32 %520, i32* %20
br label %521
521: ; preds = %518, %512
br label %522
522: ; preds = %452, %521, %502, %470
%523 = load i32, i32* %26
%524 = icmp ne i32 %523, 0
br i1 %524, label %528, label %525
525: ; preds = %522
%526 = load i32, i32* %27
%527 = add nsw i32 %526, 120000
store i32 %527, i32* %20
br label %528
528: ; preds = %525, %522
br label %529
529: ; preds = %528, %449, %442
%530 = call i32 @GetInput(i32 4)
store i32 %530, i32* %40
%531 = load i32, i32* %40
%532 = icmp eq i32 %531, 1
br i1 %532, label %533, label %534
533: ; preds = %529
store i32 1, i32* %14
br label %550
534: ; preds = %529
%535 = load i32, i32* %40
%536 = icmp eq i32 %535, -1
br i1 %536, label %537, label %538
537: ; preds = %534
store i32 0, i32* %14
br label %549
538: ; preds = %534
%539 = load i32, i32* %14
%540 = icmp sgt i32 %539, 0
br i1 %540, label %541, label %548
541: ; preds = %538
%542 = load i32, i32* %14
%543 = add nsw i32 %542, 1
store i32 %543, i32* %14
%544 = icmp sge i32 %543, 60000
br i1 %544, label %545, label %548
545: ; preds = %541
%546 = load double, double* %37
%547 = call i32 @WriteToLogArgF(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.36, i64 0, i64 0), double %546)
br label %576
548: ; preds = %541, %538
br label %549
549: ; preds = %548, %537
br label %550
550: ; preds = %549, %533
%551 = load i32, i32* %27
%552 = srem i32 %551, 16
%553 = icmp eq i32 %552, 0
br i1 %553, label %554, label %556
554: ; preds = %550
%555 = call i32 (...) @NudgeBrightness()
br label %556
556: ; preds = %554, %550
%557 = load i32, i32* %34
%558 = icmp ne i32 %557, 0
br i1 %558, label %559, label %571
559: ; preds = %556
%560 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.37, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %560, i32** %10
%561 = icmp ne i32* %560, null
br i1 %561, label %562, label %571
562: ; preds = %559
%563 = load i32*, i32** %10
%564 = load double, double* %37
%565 = load double, double* %38
%566 = load i32, i32* %15
%567 = load i32, i32* %16
%568 = call i32 (i32*, i8*, ...) @fprintf(i32* %563, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.38, i64 0, i64 0), double %564, double %565, i32 %566, i32 %567)
%569 = load i32*, i32** %10
%570 = call i32 @fclose(i32* %569)
br label %571
571: ; preds = %562, %559, %556
%572 = call i32 @usleep(i32 927)
br label %573
573: ; preds = %571
%574 = load i32, i32* %27
%575 = add nsw i32 %574, 1
store i32 %575, i32* %27
br label %159
576: ; preds = %545, %162
%577 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %577, i32** %10
%578 = icmp ne i32* %577, null
br i1 %578, label %579, label %605
579: ; preds = %576
%580 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %580, i32** %41
%581 = load i32*, i32** %41
%582 = icmp ne i32* %581, null
br i1 %582, label %583, label %602
583: ; preds = %579
br label %584
584: ; preds = %588, %583
%585 = load i32*, i32** %10
%586 = call i32 @fgetc(i32* %585)
store i32 %586, i32* %9
%587 = icmp ne i32 %586, -1
br i1 %587, label %588, label %592
588: ; preds = %584
%589 = load i32, i32* %9
%590 = load i32*, i32** %41
%591 = call i32 @fputc(i32 %589, i32* %590)
br label %584
592: ; preds = %584
%593 = load i32*, i32** %41
%594 = call signext i8 (...) @GetBrightnessIndex()
%595 = sext i8 %594 to i32
%596 = add nsw i32 65, %595
%597 = call i32 (i32*, i8*, ...) @fprintf(i32* %593, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.39, i64 0, i64 0), i32 %596)
%598 = load i32*, i32** %41
%599 = call i32 (i32*, i8*, ...) @fprintf(i32* %598, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.40, i64 0, i64 0))
%600 = load i32*, i32** %41
%601 = call i32 @fclose(i32* %600)
br label %602
602: ; preds = %592, %579
%603 = load i32*, i32** %10
%604 = call i32 @fclose(i32* %603)
br label %605
605: ; preds = %602, %576
%606 = call i32 @unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%607 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.41, i64 0, i64 0))
store i32 0, i32* %3
br label %608
608: ; preds = %605, %101, %96, %86, %82
%609 = load i32, i32* %3
ret i32 %609
}

LLVM IR (-O2):
@.str = [4 x i8] c"bkn\00"
@optind = global i32 0
@.str.1 = [20 x i8] c"/var/run/pitabd.pid\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [3 x i8] c"%d\00"
@SIGINT = global i32 0
@.str.4 = [10 x i8] c"killed %d\00"
@stderr = global i32* null
@.str.5 = [35 x i8] c"pitabd: failed to initialize GPIO\0A\00"
@.str.6 = [34 x i8] c"pitabd: failed to become a daemon\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [37 x i8] c"pitabd: unable to record process ID\0A\00"
@.str.9 = [4 x i8] c"%d\0A\00"
@.str.10 = [21 x i8] c"starting with pid=%d\00"
@.str.11 = [16 x i8] c"/ram/pitabd.cmd\00"
@.str.12 = [20 x i8] c"/var/tmp/pitabd.cmd\00"
@.str.13 = [19 x i8] c"shutdown initiated\00"
@.str.14 = [40 x i8] c"wmctrl -r :ACTIVE: -b remove,fullscreen\00"
@.str.15 = [14 x i8] c"wmctrl -a \22%\22\00"
@.str.16 = [18 x i8] c"wmctrl -a \22xvkbd\22\00"
@.str.17 = [40 x i8] c"wmctrl -r :ACTIVE: -b toggle,fullscreen\00"
@.str.18 = [59 x i8] c"wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz\00"
@.str.19 = [9 x i8] c"%d %d %d\00"
@.str.20 = [48 x i8] c"/sys/devices/platform/soc/3f980000.usb/buspower\00"
@.str.21 = [3 x i8] c"0\0A\00"
@.str.22 = [28 x i8] c"/usr/bin/lxpanelctl restart\00"
@.str.23 = [27 x i8] c"disabled USB and Bluetooth\00"
@.str.24 = [3 x i8] c"1\0A\00"
@.str.25 = [26 x i8] c"enabled USB and Bluetooth\00"
@.str.26 = [33 x i8] c"/sbin/iwconfig wlan0 txpower off\00"
@.str.27 = [14 x i8] c"disabled wifi\00"
@.str.28 = [34 x i8] c"/sbin/iwconfig wlan0 txpower auto\00"
@.str.29 = [13 x i8] c"enabled wifi\00"
@.str.30 = [19 x i8] c"charging completed\00"
@.str.31 = [21 x i8] c"charger disconnected\00"
@.str.32 = [18 x i8] c"charger connected\00"
@.str.33 = [23 x i8] c"battery voltage %1.2fV\00"
@.str.34 = [25 x i8] c"energy remaining %1.0f%%\00"
@.str.35 = [18 x i8] c"raw battery %1.3f\00"
@.str.36 = [22 x i8] c"low battery at %1.2fV\00"
@.str.37 = [16 x i8] c"/ram/pitabd.dat\00"
@.str.38 = [21 x i8] c"%4.2f %2.0f %1d %1d\0A\00"
@.str.39 = [4 x i8] c"%c\0A\00"
@.str.40 = [24 x i8] c"Do not edit this file!\0A\00"
@.str.41 = [19 x i8] c"/sbin/shutdown now\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
br label %8
8: ; preds = %17, %2
%9 = phi i1 [ false, %2 ], [ true, %17 ]
%10 = phi i32 [ 0, %2 ], [ %13, %17 ]
%11 = phi i32 [ 0, %2 ], [ %16, %17 ]
br label %12
12: ; preds = %17, %8
%13 = phi i32 [ %10, %8 ], [ 1, %17 ]
%14 = phi i32 [ %11, %8 ], [ %16, %17 ]
br label %15
15: ; preds = %17, %12
%16 = phi i32 [ %14, %12 ], [ 1, %17 ]
br label %17
17: ; preds = %15, %19
%18 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %18, label %19 [
i32 -1, label %21
i32 98, label %15
i32 107, label %12
i32 110, label %8
]
19: ; preds = %17
%20 = tail call i32 (...) @usage()
br label %17
21: ; preds = %17
%22 = load i32, i32* @optind
%23 = icmp slt i32 %22, %0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 (...) @usage()
br label %26
26: ; preds = %24, %21
%27 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %42, label %29
29: ; preds = %26
%30 = bitcast i32* %3 to i8*
%31 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%32 = icmp eq i32 %31, 1
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = load i32, i32* %3
%35 = load i32, i32* @SIGINT
%36 = call i32 @kill(i32 %34, i32 %35)
br label %37
37: ; preds = %33, %29
%38 = call i32 @fclose(i32* %27)
%39 = call i32 @unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32, i32* %3
%41 = call i32 @WriteToLogArgI(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %37, %26
%43 = icmp eq i32 %13, 0
br i1 %43, label %44, label %440
44: ; preds = %42
%45 = call i32 (...) @InitGPIO()
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32*, i32** @stderr
%49 = call i64 @fwrite(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i64 34, i64 1, i32* %48)
br label %440
50: ; preds = %44
%51 = call i32 (...) @InitBattery()
br i1 %9, label %57, label %52
52: ; preds = %50
%53 = call i64 @daemon(i32 0, i32 0)
%54 = icmp eq i64 %53, 0
br i1 %54, label %57, label %55
55: ; preds = %52
%56 = call i32 @perror(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0))
br label %440
57: ; preds = %52, %50
%58 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%59 = icmp eq i32* %58, null
br i1 %59, label %60, label %63
60: ; preds = %57
%61 = load i32*, i32** @stderr
%62 = call i64 @fwrite(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0), i64 36, i64 1, i32* %61)
br label %440
63: ; preds = %57
%64 = call i32 (...) @getpid()
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %58, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i32 %64)
%66 = call i32 @fclose(i32* %58)
%67 = call i32 (...) @RotateLogs()
%68 = call i32 (...) @getpid()
%69 = call i32 @WriteToLogArgI(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.10, i64 0, i64 0), i32 %68)
%70 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%71 = icmp eq i32* %70, null
br i1 %71, label %74, label %72
72: ; preds = %63
%73 = call i32 @fclose(i32* %70)
br label %98
74: ; preds = %63
%75 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%76 = icmp eq i32* %75, null
br i1 %76, label %98, label %77
77: ; preds = %74
%78 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%79 = icmp eq i32* %78, null
br i1 %79, label %94, label %80
80: ; preds = %77
%81 = call i32 @fgetc(i32* %75)
%82 = icmp eq i32 %81, -1
br i1 %82, label %91, label %83
83: ; preds = %80, %87
%84 = phi i32 [ %89, %87 ], [ %81, %80 ]
%85 = add i32 %84, -65
%86 = icmp ult i32 %85, 9
br i1 %86, label %91, label %87
87: ; preds = %83
%88 = call i32 @fputc(i32 %84, i32* %78)
%89 = call i32 @fgetc(i32* %75)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %83
91: ; preds = %87, %83, %80
%92 = phi i32 [ -1, %80 ], [ %85, %83 ], [ -1, %87 ]
%93 = call i32 @fclose(i32* %78)
br label %94
94: ; preds = %91, %77
%95 = phi i32 [ %92, %91 ], [ -1, %77 ]
%96 = call i32 @fclose(i32* %75)
%97 = call i32 @chmod(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i32 438)
br label %98
98: ; preds = %74, %94, %72
%99 = phi i32 [ -1, %72 ], [ %95, %94 ], [ -1, %74 ]
%100 = icmp eq i32 %99, 0
%101 = zext i1 %100 to i32
%102 = add nsw i32 %99, %101
%103 = call i32 @InitBrightness(i32 %102)
%104 = call i32 @GetInput(i32 0)
%105 = icmp eq i32 %104, -1
br i1 %105, label %113, label %106
106: ; preds = %98
%107 = bitcast i32* %4 to i8*
%108 = bitcast i32* %5 to i8*
%109 = bitcast i32* %6 to i8*
%110 = bitcast double* %7 to i8*
%111 = icmp eq i32 %16, 0
%112 = icmp ne i32 %16, 0
br label %115
113: ; preds = %409, %98
%114 = call i32 @WriteToLog(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
br label %414
115: ; preds = %106, %409
%116 = phi i32 [ 0, %106 ], [ %411, %409 ]
%117 = phi i32 [ 1, %106 ], [ %235, %409 ]
%118 = phi i32 [ 1, %106 ], [ %234, %409 ]
%119 = phi i32 [ 1, %106 ], [ %233, %409 ]
%120 = phi i32 [ 0, %106 ], [ %175, %409 ]
%121 = phi i32 [ 0, %106 ], [ %153, %409 ]
%122 = phi i32 [ 0, %106 ], [ %141, %409 ]
%123 = phi i32 [ 120000, %106 ], [ %385, %409 ]
%124 = phi i32 [ 0, %106 ], [ %384, %409 ]
%125 = phi double [ -1.000000e+00, %106 ], [ %328, %409 ]
%126 = phi double [ -1.000000e+00, %106 ], [ %327, %409 ]
%127 = phi i32 [ 0, %106 ], [ %273, %409 ]
%128 = phi i32 [ 0, %106 ], [ %243, %409 ]
%129 = phi i32 [ 0, %106 ], [ %394, %409 ]
%130 = call i32 @GetInput(i32 1)
switch i32 %130, label %140 [
i32 1, label %131
i32 -1, label %133
]
131: ; preds = %115
%132 = add nuw nsw i32 %116, 500
br label %140
133: ; preds = %115
%134 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0))
%135 = icmp sgt i32 %116, %122
br i1 %135, label %136, label %138
136: ; preds = %133
%137 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0))
br label %140
138: ; preds = %133
%139 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0))
br label %140
140: ; preds = %115, %138, %136, %131
%141 = phi i32 [ %132, %131 ], [ %122, %136 ], [ %122, %138 ], [ %122, %115 ]
%142 = phi i32 [ 1, %131 ], [ 0, %136 ], [ 0, %138 ], [ 0, %115 ]
%143 = call i32 @GetInput(i32 2)
switch i32 %143, label %152 [
i32 1, label %144
i32 -1, label %146
]
144: ; preds = %140
%145 = add nuw nsw i32 %116, 500
br label %152
146: ; preds = %140
%147 = icmp sgt i32 %116, %121
br i1 %147, label %148, label %150
148: ; preds = %146
%149 = call i32 (...) @MaxBrightness()
br label %152
150: ; preds = %146
%151 = call i32 (...) @NextBrightness()
br label %152
152: ; preds = %140, %150, %148, %144
%153 = phi i32 [ %145, %144 ], [ %121, %148 ], [ %121, %150 ], [ %121, %140 ]
%154 = phi i32 [ 1, %144 ], [ %142, %148 ], [ %142, %150 ], [ %142, %140 ]
%155 = call i32 @GetInput(i32 3)
switch i32 %155, label %165 [
i32 1, label %156
i32 -1, label %158
]
156: ; preds = %152
%157 = add nuw nsw i32 %116, 500
br label %167
158: ; preds = %152
%159 = icmp sgt i32 %116, %120
br i1 %159, label %162, label %160
160: ; preds = %158
%161 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0))
br label %162
162: ; preds = %158, %160
%163 = phi i8* [ getelementptr inbounds ([59 x i8], [59 x i8]* @.str.18, i64 0, i64 0), %160 ], [ getelementptr inbounds ([40 x i8], [40 x i8]* @.str.17, i64 0, i64 0), %158 ]
%164 = call i32 @system(i8* %163)
br label %165
165: ; preds = %162, %152
%166 = icmp eq i32 %154, 0
br i1 %166, label %174, label %167
167: ; preds = %156, %165
%168 = phi i32 [ %157, %156 ], [ %120, %165 ]
%169 = icmp eq i32 %124, 0
br i1 %169, label %172, label %170
170: ; preds = %167
%171 = call i32 (...) @RestoreDisplay()
br label %172
172: ; preds = %170, %167
%173 = add nuw nsw i32 %116, 120000
br label %174
174: ; preds = %172, %165
%175 = phi i32 [ %168, %172 ], [ %120, %165 ]
%176 = phi i32 [ 0, %172 ], [ %124, %165 ]
%177 = phi i32 [ %173, %172 ], [ %123, %165 ]
%178 = urem i32 %116, 5000
%179 = icmp eq i32 %178, 0
br i1 %179, label %180, label %232
180: ; preds = %174
%181 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%182 = icmp eq i32* %181, null
br i1 %182, label %232, label %183
183: ; preds = %180
store i32 1, i32* %4
store i32 1, i32* %5
store i32 1, i32* %6
%184 = call i32 (i32*, i8*, i32*, ...) @fscanf(i32* %181, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.19, i64 0, i64 0), i32* %4, i32* %5, i32* %6)
%185 = call i32 @fclose(i32* %181)
%186 = icmp eq i32 %184, 3
br i1 %186, label %187, label %228
187: ; preds = %183
%188 = load i32, i32* %4
%189 = icmp eq i32 %119, 0
%190 = load i32, i32* %5
%191 = icmp ne i32 %190, 0
%192 = select i1 %189, i1 true, i1 %191
br i1 %192, label %200, label %193
193: ; preds = %187
%194 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%195 = icmp eq i32* %194, null
br i1 %195, label %212, label %196
196: ; preds = %193
%197 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.21, i64 0, i64 0), i64 2, i64 1, i32* %194)
%198 = call i32 @fclose(i32* %194)
%199 = call i32 @system(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.22, i64 0, i64 0))
br label %208
200: ; preds = %187
%201 = select i1 %189, i1 %191, i1 false
br i1 %201, label %202, label %212
202: ; preds = %200
%203 = call i32* @fopen(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.20, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%204 = icmp eq i32* %203, null
br i1 %204, label %212, label %205
205: ; preds = %202
%206 = call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.24, i64 0, i64 0), i64 2, i64 1, i32* %203)
%207 = call i32 @fclose(i32* %203)
br label %208
208: ; preds = %196, %205
%209 = phi i8* [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.25, i64 0, i64 0), %205 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.23, i64 0, i64 0), %196 ]
%210 = phi i32 [ 1, %205 ], [ 0, %196 ]
%211 = call i32 @WriteToLog(i8* %209)
br label %212
212: ; preds = %208, %200, %202, %193
%213 = phi i32 [ 0, %202 ], [ %119, %200 ], [ 1, %193 ], [ %210, %208 ]
%214 = icmp eq i32 %118, 0
%215 = load i32, i32* %6
%216 = icmp ne i32 %215, 0
%217 = select i1 %214, i1 true, i1 %216
br i1 %217, label %218, label %222
218: ; preds = %212
%219 = select i1 %214, i1 %216, i1 false
br i1 %219, label %220, label %228
220: ; preds = %218
%221 = call i32 @system(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.28, i64 0, i64 0))
br label %222
222: ; preds = %212, %220
%223 = phi i8* [ getelementptr inbounds ([34 x i8], [34 x i8]* @.str.28, i64 0, i64 0), %220 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.26, i64 0, i64 0), %212 ]
%224 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.29, i64 0, i64 0), %220 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.27, i64 0, i64 0), %212 ]
%225 = phi i32 [ 1, %220 ], [ 0, %212 ]
%226 = call i32 @system(i8* %223)
%227 = call i32 @WriteToLog(i8* %224)
br label %228
228: ; preds = %222, %218, %183
%229 = phi i32 [ %213, %218 ], [ %119, %183 ], [ %213, %222 ]
%230 = phi i32 [ %118, %218 ], [ %118, %183 ], [ %225, %222 ]
%231 = phi i32 [ %188, %218 ], [ %117, %183 ], [ %188, %222 ]
br label %232
232: ; preds = %228, %180, %174
%233 = phi i32 [ %229, %228 ], [ %119, %180 ], [ %119, %174 ]
%234 = phi i32 [ %230, %228 ], [ %118, %180 ], [ %118, %174 ]
%235 = phi i32 [ %231, %228 ], [ %117, %180 ], [ %117, %174 ]
%236 = icmp ne i32 %128, 0
%237 = icmp ne i32 %127, 0
%238 = select i1 %236, i1 true, i1 %237
%239 = call i32 @GetInput(i32 5)
switch i32 %239, label %241 [
i32 1, label %242
i32 -1, label %240
]
240: ; preds = %232
br label %242
241: ; preds = %232
br label %242
242: ; preds = %232, %241, %240
%243 = phi i32 [ 0, %240 ], [ %239, %232 ], [ %128, %241 ]
%244 = phi i32 [ 1, %240 ], [ %239, %232 ], [ 0, %241 ]
%245 = call i32 @GetInput(i32 6)
switch i32 %245, label %250 [
i32 1, label %246
i32 -1, label %249
]
246: ; preds = %242
%247 = call i32 @WriteToLog(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.30, i64 0, i64 0))
%248 = icmp ne i32 %243, 0
br label %261
249: ; preds = %242
br label %250
250: ; preds = %242, %249
%251 = phi i32 [ 0, %249 ], [ %127, %242 ]
%252 = phi i32 [ 1, %249 ], [ %244, %242 ]
%253 = xor i1 %238, true
%254 = icmp ne i32 %243, 0
%255 = select i1 %253, i1 true, i1 %254
%256 = icmp ne i32 %251, 0
%257 = select i1 %255, i1 true, i1 %256
br i1 %257, label %261, label %258
258: ; preds = %250
%259 = call i32 @WriteToLog(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.31, i64 0, i64 0))
%260 = add nuw nsw i32 %116, 120000
br label %270
261: ; preds = %246, %250
%262 = phi i1 [ true, %246 ], [ %256, %250 ]
%263 = phi i1 [ %248, %246 ], [ %254, %250 ]
%264 = phi i32 [ 1, %246 ], [ %252, %250 ]
%265 = phi i32 [ 1, %246 ], [ %251, %250 ]
br i1 %238, label %270, label %266
266: ; preds = %261
%267 = select i1 %263, i1 true, i1 %262
br i1 %267, label %268, label %270
268: ; preds = %266
%269 = call i32 @WriteToLog(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.32, i64 0, i64 0))
br label %270
270: ; preds = %261, %268, %266, %258
%271 = phi i1 [ %263, %261 ], [ %263, %268 ], [ false, %266 ], [ false, %258 ]
%272 = phi i32 [ %264, %261 ], [ %264, %268 ], [ %264, %266 ], [ %252, %258 ]
%273 = phi i32 [ %265, %261 ], [ %265, %268 ], [ %265, %266 ], [ 0, %258 ]
%274 = phi i32 [ %177, %261 ], [ %177, %268 ], [ %177, %266 ], [ %260, %258 ]
%275 = phi i1 [ true, %261 ], [ true, %268 ], [ false, %266 ], [ false, %258 ]
%276 = call double @GetRawBatteryReadings(i32 %243, double* %7)
%277 = call double @BatteryRawToVoltage(double %276)
%278 = fmul double %277, 1.000000e+02
%279 = call double @llvm.round.f64(double %278)
%280 = fdiv double %279, 1.000000e+02
%281 = load double, double* %7
%282 = call double @BatteryRawToEnergyRemaining(double %281)
%283 = call double @llvm.round.f64(double %282)
%284 = icmp ugt i32 %116, 16383
br i1 %284, label %285, label %326
285: ; preds = %270
%286 = fcmp ogt double %280, %126
%287 = select i1 %271, i1 %286, i1 false
br i1 %287, label %299, label %288
288: ; preds = %285
%289 = xor i1 %271, true
%290 = fcmp olt double %280, %126
%291 = select i1 %289, i1 %290, i1 false
br i1 %291, label %299, label %292
292: ; preds = %288
%293 = fsub double %280, %126
%294 = call double @llvm.fabs.f64(double %293)
%295 = fcmp ule double %294, 1.010000e-02
%296 = select i1 %295, i1 true, i1 %111
%297 = select i1 %295, double %126, double %280
%298 = select i1 %295, i32 %272, i32 1
br i1 %296, label %302, label %300
299: ; preds = %288, %285
br i1 %111, label %302, label %300
300: ; preds = %292, %299
%301 = call i32 @WriteToLogArgF(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.33, i64 0, i64 0), double %280)
br label %302
302: ; preds = %292, %299, %300
%303 = phi double [ %297, %292 ], [ %280, %300 ], [ %280, %299 ]
%304 = phi i32 [ %298, %292 ], [ 1, %300 ], [ 1, %299 ]
%305 = fcmp ogt double %283, %125
%306 = select i1 %271, i1 %305, i1 false
br i1 %306, label %315, label %307
307: ; preds = %302
%308 = xor i1 %271, true
%309 = fcmp olt double %283, %125
%310 = select i1 %308, i1 %309, i1 false
br i1 %310, label %315, label %311
311: ; preds = %307
%312 = fsub double %283, %125
%313 = call double @llvm.fabs.f64(double %312)
%314 = fcmp ogt double %313, 1.010000e+00
br i1 %314, label %315, label %318
315: ; preds = %307, %302, %311
br i1 %111, label %326, label %316
316: ; preds = %315
%317 = call i32 @WriteToLogArgF(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.34, i64 0, i64 0), double %283)
br label %318
318: ; preds = %316, %311
%319 = phi double [ %125, %311 ], [ %283, %316 ]
%320 = phi i32 [ %304, %311 ], [ 1, %316 ]
%321 = urem i32 %116, 60000
%322 = icmp eq i32 %321, 16384
%323 = select i1 %112, i1 %322, i1 false
br i1 %323, label %324, label %326
324: ; preds = %318
%325 = call i32 @WriteToLogArgF(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.35, i64 0, i64 0), double %276)
br label %326
326: ; preds = %315, %318, %324, %270
%327 = phi double [ %303, %324 ], [ %303, %318 ], [ %126, %270 ], [ %303, %315 ]
%328 = phi double [ %319, %324 ], [ %319, %318 ], [ %125, %270 ], [ %283, %315 ]
%329 = phi i32 [ %320, %324 ], [ %320, %318 ], [ %272, %270 ], [ 1, %315 ]
%330 = icmp sgt i32 %116, %274
br i1 %330, label %331, label %383
331: ; preds = %326
%332 = icmp eq i32 %176, 0
%333 = and i1 %332, %275
br i1 %333, label %383, label %334
334: ; preds = %331
%335 = call i32 (...) @IdleTime()
switch i32 %176, label %377 [
i32 0, label %336
i32 1, label %346
i32 2, label %366
]
336: ; preds = %334
%337 = icmp sgt i32 %335, 120000
%338 = icmp ne i32 %235, 0
%339 = select i1 %337, i1 %338, i1 false
br i1 %339, label %340, label %343
340: ; preds = %336
%341 = call i32 (...) @DimDisplay()
%342 = add nuw nsw i32 %116, 500
br label %377
343: ; preds = %336
%344 = add nuw nsw i32 %116, 120000
%345 = sub i32 %344, %335
br label %377
346: ; preds = %334
%347 = icmp sgt i32 %335, 119999
%348 = icmp ne i32 %235, 0
%349 = select i1 %347, i1 %348, i1 false
%350 = xor i1 %349, true
%351 = or i1 %275, %350
br i1 %351, label %352, label %356
352: ; preds = %346
%353 = call i32 (...) @RestoreDisplay()
%354 = add nuw nsw i32 %116, 120000
%355 = sub i32 %354, %335
br label %377
356: ; preds = %346
%357 = icmp sgt i32 %335, 300000
%358 = select i1 %357, i1 %348, i1 false
br i1 %358, label %359, label %364
359: ; preds = %356
%360 = call i32 (...) @DarkenDisplay()
%361 = call i32 @system(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0))
%362 = call i32 @system(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.15, i64 0, i64 0))
%363 = add nuw nsw i32 %116, 500
br label %377
364: ; preds = %356
%365 = add nuw nsw i32 %116, 500
br label %377
366: ; preds = %334
%367 = icmp slt i32 %335, 120000
%368 = icmp eq i32 %235, 0
%369 = select i1 %367, i1 true, i1 %368
%370 = or i1 %275, %369
br i1 %370, label %371, label %375
371: ; preds = %366
%372 = call i32 (...) @RestoreDisplay()
%373 = add nuw nsw i32 %116, 120000
%374 = sub i32 %373, %335
br label %377
375: ; preds = %366
%376 = add nuw nsw i32 %116, 500
br label %377
377: ; preds = %371, %375, %352, %364, %359, %340, %343, %334
%378 = phi i32 [ %176, %334 ], [ 0, %371 ], [ 2, %375 ], [ 0, %352 ], [ 2, %359 ], [ 1, %364 ], [ 1, %340 ], [ 0, %343 ]
%379 = phi i32 [ %274, %334 ], [ %374, %371 ], [ %376, %375 ], [ %355, %352 ], [ %363, %359 ], [ %365, %364 ], [ %342, %340 ], [ %345, %343 ]
%380 = icmp eq i32 %235, 0
%381 = add nuw nsw i32 %116, 120000
%382 = select i1 %380, i32 %381, i32 %379
br label %383
383: ; preds = %331, %377, %326
%384 = phi i32 [ 0, %331 ], [ %378, %377 ], [ %176, %326 ]
%385 = phi i32 [ %274, %331 ], [ %382, %377 ], [ %274, %326 ]
%386 = call i32 @GetInput(i32 4)
switch i32 %386, label %388 [
i32 1, label %393
i32 -1, label %387
]
387: ; preds = %383
br label %393
388: ; preds = %383
%389 = icmp sgt i32 %129, 0
br i1 %389, label %390, label %393
390: ; preds = %388
%391 = add nuw nsw i32 %129, 1
%392 = icmp ugt i32 %129, 59998
br i1 %392, label %407, label %393
393: ; preds = %383, %387, %390, %388
%394 = phi i32 [ 0, %387 ], [ %391, %390 ], [ %129, %388 ], [ %386, %383 ]
%395 = and i32 %116, 15
%396 = icmp eq i32 %395, 0
br i1 %396, label %397, label %399
397: ; preds = %393
%398 = call i32 (...) @NudgeBrightness()
br label %399
399: ; preds = %397, %393
%400 = icmp eq i32 %329, 0
br i1 %400, label %409, label %401
401: ; preds = %399
%402 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.37, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%403 = icmp eq i32* %402, null
br i1 %403, label %409, label %404
404: ; preds = %401
%405 = call i32 (i32*, i8*, ...) @fprintf(i32* %402, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.38, i64 0, i64 0), double %280, double %283, i32 %243, i32 %273)
%406 = call i32 @fclose(i32* %402)
br label %409
407: ; preds = %390
%408 = call i32 @WriteToLogArgF(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.36, i64 0, i64 0), double %280)
br label %414
409: ; preds = %399, %401, %404
%410 = call i32 @usleep(i32 927)
%411 = add nuw nsw i32 %116, 1
%412 = call i32 @GetInput(i32 0)
%413 = icmp eq i32 %412, -1
br i1 %413, label %113, label %115
414: ; preds = %407, %113
%415 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%416 = icmp eq i32* %415, null
br i1 %416, label %437, label %417
417: ; preds = %414
%418 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%419 = icmp eq i32* %418, null
br i1 %419, label %435, label %420
420: ; preds = %417
%421 = call i32 @fgetc(i32* %415)
%422 = icmp eq i32 %421, -1
br i1 %422, label %428, label %423
423: ; preds = %420, %423
%424 = phi i32 [ %426, %423 ], [ %421, %420 ]
%425 = call i32 @fputc(i32 %424, i32* %418)
%426 = call i32 @fgetc(i32* %415)
%427 = icmp eq i32 %426, -1
br i1 %427, label %428, label %423
428: ; preds = %423, %420
%429 = call signext i8 (...) @GetBrightnessIndex()
%430 = sext i8 %429 to i32
%431 = add nsw i32 %430, 65
%432 = call i32 (i32*, i8*, ...) @fprintf(i32* %418, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.39, i64 0, i64 0), i32 %431)
%433 = call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.40, i64 0, i64 0), i64 23, i64 1, i32* %418)
%434 = call i32 @fclose(i32* %418)
br label %435
435: ; preds = %428, %417
%436 = call i32 @fclose(i32* %415)
br label %437
437: ; preds = %435, %414
%438 = call i32 @unlink(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%439 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.41, i64 0, i64 0))
br label %440
440: ; preds = %42, %437, %60, %55, %47
%441 = phi i32 [ 1, %55 ], [ 1, %60 ], [ 0, %437 ], [ 1, %47 ], [ 0, %42 ]
ret i32 %441
}