#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 /*<<< orphan*/ buf;

/* Variables and functions */
int LOCK_EX;
int LOCK_NB;
int LOCK_UN;
int O_RDONLY;
int O_RDWR;
int O_SYNC;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
scalar_t__ flock(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int /*<<< orphan*/,
                           int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/, int, int, int,
                           int /*<<< orphan*/, int /*<<< orphan*/, int, int);
int sscanf(char *, char *, int *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int /*<<< orphan*/ usleep(int);
scalar_t__ write(int, char *, scalar_t__);
int main(int argc, char **argv) {
  int major, minor, fd_v;
  int i, tries, fd_s, fd_l;
  char buf[80];
  int ret = 1;
  fd_v = open("/sys/devices/virtual/chromeos/cros_ec/lightbar"
              "/version",
              O_RDONLY);
  if (fd_v < 0) {
    perror("can't open version file");
    goto out;
  }
  ret = read(fd_v, buf, sizeof(buf) - 1);
  if (ret <= 0) {
    perror("can't read version");
    close(fd_v);
    goto out;
  }
  buf[ret] = '\0';
  close(fd_v);
  errno = 0;
  if (2 != sscanf(buf, "%d %d", &major, &minor)) {
    if (errno)
      perror("can't parse version string");
    else
      fprintf(stderr, "can't parse version string\n");
    goto out;
  }
  if (major != 0) {
    fprintf(stderr, "Don't know how to handle version %d.%d\n", major, minor);
    goto out;
  }
  fd_s = open("/sys/devices/virtual/chromeos/cros_ec/lightbar"
              "/sequence",
              O_RDWR | O_SYNC);
  if (fd_s < 0) {
    perror("can't open sequence control");
    goto out;
  }
  if (flock(fd_s, LOCK_EX | LOCK_NB) < 0) {
    perror("can't lock sequence control");
    goto out_close;
  }
  tries = 3;
  while (1) {
    lseek(fd_s, 0, SEEK_SET);
    if (read(fd_s, buf, sizeof(buf)) <= 0) {
      perror("can't read sequence control");
      goto out_unlock;
    }
    if (!strncasecmp(buf, "stop", 4))
      break;
    if (!tries--) {
      fprintf(stderr, "couldn't get EC to stop\n");
      goto out_unlock;
    }
    lseek(fd_s, 0, SEEK_SET);
    strcpy(buf, "stop");
    if (write(fd_s, buf, strlen(buf) + 1) <= 0) {
      perror("can't write sequence control");
      goto out_unlock;
    }
  }
  fd_l = open("/sys/devices/virtual/chromeos/cros_ec/lightbar"
              "/brightness",
              O_WRONLY | O_SYNC);
  if (fd_l < 0) {
    perror("can't open brightness control");
    goto out_run;
  }
  strcpy(buf, "255");
  if (write(fd_l, buf, strlen(buf) + 1) < 0) {
    perror("can't write brightness control");
    goto out_led;
  }
  close(fd_l);
  fd_l = open("/sys/devices/virtual/chromeos/cros_ec/lightbar"
              "/led_rgb",
              O_WRONLY | O_SYNC);
  if (fd_l < 0) {
    perror("can't open led control");
    goto out_run;
  }
  for (i = 0; i < 256; i += 4) {
    sprintf(buf, "0 %d %d %d 1 %d %d %d 2 %d %d %d 3 %d %d %d", i, 0, 0, 0, 0,
            i, 255 - i, 255, 0, 0, 255, 255 - i);
    lseek(fd_l, 0, SEEK_SET);
    if (write(fd_l, buf, strlen(buf) + 1) < 0)
      perror("write to led control");
    usleep(100000);
  }
  strcpy(buf, "4 255 255 255");
  lseek(fd_l, 0, SEEK_SET);
  if (write(fd_l, buf, strlen(buf) + 1) < 0)
    perror("write to led control");
  usleep(400000);
  ret = 0;
out_led:
  close(fd_l);
out_run:
  strcpy(buf, "run");
  lseek(fd_s, 0, SEEK_SET);
  if (write(fd_s, buf, strlen(buf) + 1) < 0)
    perror("write to sequence control");
out_unlock:
  flock(fd_s, LOCK_UN);
out_close:
  close(fd_s);
out:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x84(%rbp)
mov    0x2dc6(%rip),%rax
mov    (%rax),%esi
lea    0xded(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1236 <main+0x56>
lea    0xe0b(%rip),%rdi
call   10d0 <perror@plt>
jmp    1793 <main+0x5b3>
mov    -0x1c(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x4f,%edx
call   1080 <read@plt>
mov    %eax,-0x84(%rbp)
cmpl   $0x0,-0x84(%rbp)
jg     1273 <main+0x93>
lea    0xdee(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
jmp    1793 <main+0x5b3>
movslq -0x84(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2d2a(%rip),%rax
movq   $0x0,(%rax)
lea    -0x80(%rbp),%rdi
lea    0xfd3(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   10b0 <sscanf@plt>
mov    %eax,%ecx
mov    $0x2,%eax
cmp    %ecx,%eax
je     12fa <main+0x11a>
mov    0x2cf5(%rip),%rax
cmpq   $0x0,(%rax)
je     12de <main+0xfe>
lea    0xd8e(%rip),%rdi
call   10d0 <perror@plt>
jmp    12f5 <main+0x115>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1793 <main+0x5b3>
cmpl   $0x0,-0x14(%rbp)
je     1326 <main+0x146>
mov    0x2cb5(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xd7f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    1793 <main+0x5b3>
mov    0x2cbb(%rip),%rax
mov    (%rax),%esi
mov    0x2caa(%rip),%rax
or     (%rax),%esi
lea    0xd82(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1362 <main+0x182>
lea    0xda1(%rip),%rdi
call   10d0 <perror@plt>
jmp    1793 <main+0x5b3>
mov    -0x28(%rbp),%edi
mov    0x2c6c(%rip),%rax
mov    (%rax),%esi
mov    0x2c1b(%rip),%rax
or     (%rax),%esi
call   10e0 <flock@plt>
cmp    $0x0,%rax
jge    1397 <main+0x1b7>
lea    0xd88(%rip),%rdi
call   10d0 <perror@plt>
jmp    178b <main+0x5ab>
movl   $0x3,-0x24(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2c08(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x28(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x50,%edx
call   1080 <read@plt>
cmp    $0x0,%eax
jg     13dc <main+0x1fc>
lea    0xd5f(%rip),%rdi
call   10d0 <perror@plt>
jmp    177a <main+0x59a>
lea    -0x80(%rbp),%rdi
lea    0xd66(%rip),%rsi
mov    $0x4,%edx
call   10a0 <strncasecmp@plt>
cmp    $0x0,%eax
jne    13ff <main+0x21f>
jmp    14a8 <main+0x2c8>
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x24(%rbp)
cmp    $0x0,%eax
jne    142f <main+0x24f>
mov    0x2ba6(%rip),%rax
mov    (%rax),%edi
lea    0xd2f(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    177a <main+0x59a>
mov    -0x28(%rbp),%edi
mov    0x2b77(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
lea    -0x80(%rbp),%rdi
lea    0xd00(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x94(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x90(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x94(%rbp),%edi
mov    -0x90(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
cmp    $0x0,%rax
jg     14a3 <main+0x2c3>
lea    0xcd2(%rip),%rdi
call   10d0 <perror@plt>
jmp    177a <main+0x59a>
jmp    139e <main+0x1be>
mov    0x2ae9(%rip),%rax
mov    (%rax),%esi
mov    0x2b28(%rip),%rax
or     (%rax),%esi
lea    0xcc7(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    14e4 <main+0x304>
lea    0xce8(%rip),%rdi
call   10d0 <perror@plt>
jmp    1706 <main+0x526>
lea    -0x80(%rbp),%rdi
lea    0xda9(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0xa4(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1545 <main+0x365>
lea    0xca5(%rip),%rdi
call   10d0 <perror@plt>
jmp    16fe <main+0x51e>
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
mov    0x2a44(%rip),%rax
mov    (%rax),%esi
mov    0x2a83(%rip),%rax
or     (%rax),%esi
lea    0xc99(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1589 <main+0x3a9>
lea    0xcb7(%rip),%rdi
call   10d0 <perror@plt>
jmp    1706 <main+0x526>
movl   $0x0,-0x20(%rbp)
cmpl   $0x100,-0x20(%rbp)
jge    167b <main+0x49b>
lea    -0x80(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    -0x20(%rbp),%r11d
mov    $0xff,%r10d
sub    -0x20(%rbp),%r10d
mov    $0xff,%eax
sub    -0x20(%rbp),%eax
lea    0xc8c(%rip),%rsi
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x0,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
movl   $0xff,0x18(%rsp)
movl   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
movl   $0xff,0x30(%rsp)
mov    %eax,0x38(%rsp)
call   10f0 <sprintf@plt>
mov    -0x2c(%rbp),%edi
mov    0x29a2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0xb4(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xb0(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xb4(%rbp),%edi
mov    -0xb0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1663 <main+0x483>
lea    0xc1b(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x186a0,%edi
call   1100 <usleep@plt>
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
jmp    1590 <main+0x3b0>
lea    -0x80(%rbp),%rdi
lea    0xc08(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x2c(%rbp),%edi
mov    0x291b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0xc4(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xc0(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xc4(%rbp),%edi
mov    -0xc0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    16ea <main+0x50a>
lea    0xb94(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x61a80,%edi
call   1100 <usleep@plt>
movl   $0x0,-0x84(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <close@plt>
lea    -0x80(%rbp),%rdi
lea    0xb8b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x28(%rbp),%edi
mov    0x2890(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0xd4(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0xd0(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xd4(%rbp),%edi
mov    -0xd0(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
cmp    $0x0,%rax
jge    1775 <main+0x595>
lea    0xb30(%rip),%rdi
call   10d0 <perror@plt>
jmp    177a <main+0x59a>
mov    -0x28(%rbp),%edi
mov    0x2824(%rip),%rax
mov    (%rax),%esi
call   10e0 <flock@plt>
mov    -0x28(%rbp),%edi
call   1070 <close@plt>
mov    -0x84(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    0xe02(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     16ae <main+0x4ce>
mov    %eax,%ebp
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x4f,%edx
call   1080 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    16c1 <main+0x4e1>
mov    %ebx,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %ebp,%edi
call   1070 <close@plt>
mov    0x2d7b(%rip),%rbp
movq   $0x0,0x0(%rbp)
lea    0x1027(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   10b0 <sscanf@plt>
cmp    $0x2,%eax
jne    128d <main+0xad>
mov    0xc(%rsp),%edx
test   %edx,%edx
je     12b4 <main+0xd4>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%ecx
lea    0xe18(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1725 <main+0x545>
cmpq   $0x0,0x0(%rbp)
jne    16cf <main+0x4ef>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    0xdd5(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    1725 <main+0x545>
mov    0x2d2d(%rip),%rax
mov    0x2d1e(%rip),%r15
mov    (%r15),%esi
or     (%rax),%esi
lea    0xdf3(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     16e6 <main+0x506>
mov    %eax,%ebp
mov    0x2cf4(%rip),%rax
mov    0x2ca5(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %ebp,%edi
call   10e0 <flock@plt>
test   %rax,%rax
js     16f4 <main+0x514>
mov    0x2caa(%rip),%r13
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x50,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    16dd <main+0x4fd>
lea    0xe1a(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x4,%edx
call   10a0 <strncasecmp@plt>
test   %eax,%eax
je     14ee <main+0x30e>
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0xdef(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <write@plt>
test   %rax,%rax
jle    1702 <main+0x522>
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x50,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    16dd <main+0x4fd>
lea    0xd96(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x4,%edx
call   10a0 <strncasecmp@plt>
test   %eax,%eax
je     14ee <main+0x30e>
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0xd6b(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <write@plt>
test   %rax,%rax
jle    1702 <main+0x522>
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x50,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    16dd <main+0x4fd>
lea    0xd12(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x4,%edx
call   10a0 <strncasecmp@plt>
test   %eax,%eax
je     14ee <main+0x30e>
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0xce7(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <write@plt>
test   %rax,%rax
jle    1702 <main+0x522>
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x50,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    16dd <main+0x4fd>
lea    0xc8e(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    $0x4,%edx
call   10a0 <strncasecmp@plt>
test   %eax,%eax
je     14ee <main+0x30e>
mov    0x2ae7(%rip),%rax
mov    (%rax),%edi
lea    0xc70(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    170e <main+0x52e>
mov    %ebp,0x4(%rsp)
mov    0x2a9f(%rip),%r14
mov    (%r15),%esi
or     (%r14),%esi
lea    0xc82(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     1736 <main+0x556>
mov    %eax,%r12d
lea    0xd7b(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12d,%edi
mov    %rbp,%rsi
call   1040 <write@plt>
test   %rax,%rax
js     173f <main+0x55f>
mov    %r12d,%edi
call   1070 <close@plt>
mov    (%r15),%esi
or     (%r14),%esi
lea    0xca0(%rip),%rdi
call   10c0 <open@plt>
test   %eax,%eax
js     1750 <main+0x570>
mov    %eax,%r12d
mov    $0xfffffffc,%ebx
mov    $0xff,%r14d
lea    0xccc(%rip),%r15
lea    0x10(%rsp),%rbp
jmp    15a6 <main+0x3c6>
nopl   0x0(%rax,%rax,1)
mov    $0x186a0,%edi
call   1100 <usleep@plt>
add    $0xfffffffc,%r14d
cmp    $0xfc,%ebx
jae    160f <main+0x42f>
add    $0x4,%ebx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
push   %r14
push   $0xff
push   $0x0
push   $0x0
push   $0xff
push   %r14
push   %rbx
push   $0x0
call   10f0 <sprintf@plt>
add    $0x40,%rsp
mov    0x0(%r13),%edx
mov    %r12d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12d,%edi
mov    %rbp,%rsi
call   1040 <write@plt>
test   %rax,%rax
jns    1590 <main+0x3b0>
lea    0xc71(%rip),%rdi
call   10d0 <perror@plt>
jmp    1590 <main+0x3b0>
lea    0xc78(%rip),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
mov    0x0(%r13),%edx
xor    %ebx,%ebx
mov    %r12d,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r12d,%edi
mov    %rbp,%rsi
call   1040 <write@plt>
test   %rax,%rax
js     1765 <main+0x585>
mov    $0x61a80,%edi
call   1100 <usleep@plt>
mov    0x4(%rsp),%ebp
mov    %r12d,%edi
call   1070 <close@plt>
lea    0xc2c(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
call   1040 <write@plt>
test   %rax,%rax
jns    170e <main+0x52e>
lea    0xbf4(%rip),%rdi
jmp    1709 <main+0x529>
lea    0x982(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%ebx
jmp    1725 <main+0x545>
lea    0x987(%rip),%rdi
call   10d0 <perror@plt>
jmp    171e <main+0x53e>
lea    0x98c(%rip),%rdi
call   10d0 <perror@plt>
jmp    1725 <main+0x545>
lea    0xa4d(%rip),%rdi
jmp    1709 <main+0x529>
lea    0xa0c(%rip),%rdi
call   10d0 <perror@plt>
jmp    1725 <main+0x545>
lea    0xa1a(%rip),%rdi
call   10d0 <perror@plt>
jmp    171e <main+0x53e>
lea    0xa62(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2893(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   10e0 <flock@plt>
mov    %ebp,%edi
call   1070 <close@plt>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xa85(%rip),%rdi
jmp    1757 <main+0x577>
lea    0xa9a(%rip),%rdi
call   10d0 <perror@plt>
jmp    165d <main+0x47d>
lea    0xadf(%rip),%rdi
call   10d0 <perror@plt>
mov    0x4(%rsp),%ebp
jmp    1669 <main+0x489>
lea    0xb0d(%rip),%rdi
call   10d0 <perror@plt>
jmp    1653 <main+0x473>

LLVM IR (-O0):
@.str = [55 x i8] c"/sys/devices/virtual/chromeos/cros_ec/lightbar/version\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"can't open version file\00"
@.str.2 = [19 x i8] c"can't read version\00"
@errno = global i64 0
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [27 x i8] c"can't parse version string\00"
@stderr = global i32 0
@.str.5 = [28 x i8] c"can't parse version string\0A\00"
@.str.6 = [40 x i8] c"Don't know how to handle version %d.%d\0A\00"
@.str.7 = [56 x i8] c"/sys/devices/virtual/chromeos/cros_ec/lightbar/sequence\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.8 = [28 x i8] c"can't open sequence control\00"
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
@.str.9 = [28 x i8] c"can't lock sequence control\00"
@SEEK_SET = global i32 0
@.str.10 = [28 x i8] c"can't read sequence control\00"
@.str.11 = [5 x i8] c"stop\00"
@.str.12 = [25 x i8] c"couldn't get EC to stop\0A\00"
@.str.13 = [29 x i8] c"can't write sequence control\00"
@.str.14 = [58 x i8] c"/sys/devices/virtual/chromeos/cros_ec/lightbar/brightness\00"
@O_WRONLY = global i32 0
@.str.15 = [30 x i8] c"can't open brightness control\00"
@.str.16 = [4 x i8] c"255\00"
@.str.17 = [31 x i8] c"can't write brightness control\00"
@.str.18 = [55 x i8] c"/sys/devices/virtual/chromeos/cros_ec/lightbar/led_rgb\00"
@.str.19 = [23 x i8] c"can't open led control\00"
@.str.20 = [44 x i8] c"0 %d %d %d 1 %d %d %d 2 %d %d %d 3 %d %d %d\00"
@.str.21 = [21 x i8] c"write to led control\00"
@.str.22 = [14 x i8] c"4 255 255 255\00"
@.str.23 = [4 x i8] c"run\00"
@.str.24 = [26 x i8] c"write to sequence control\00"
@LOCK_UN = global i32 0
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 [80 x i8]
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %14
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %219
21: ; preds = %2
%22 = load i32, i32* %8
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%24 = call i32 @read(i32 %22, i8* %23, i32 79)
store i32 %24, i32* %14
%25 = load i32, i32* %14
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* %8
%30 = call i32 @close(i32 %29)
br label %219
31: ; preds = %21
%32 = load i32, i32* %14
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* %8
%36 = call i32 @close(i32 %35)
store i64 0, i64* @errno
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%38 = call i32 @sscanf(i8* %37, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %6, i32* %7)
%39 = icmp ne i32 2, %38
br i1 %39, label %40, label %49
40: ; preds = %31
%41 = load i64, i64* @errno
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %48
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %45, %43
br label %219
49: ; preds = %31
%50 = load i32, i32* %6
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %54, i32 %55)
br label %219
57: ; preds = %49
%58 = load i32, i32* @O_RDWR
%59 = load i32, i32* @O_SYNC
%60 = or i32 %58, %59
%61 = call i32 @open(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0), i32 %60)
store i32 %61, i32* %11
%62 = load i32, i32* %11
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %57
%65 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %219
66: ; preds = %57
%67 = load i32, i32* %11
%68 = load i32, i32* @LOCK_EX
%69 = load i32, i32* @LOCK_NB
%70 = or i32 %68, %69
%71 = call i64 @flock(i32 %67, i32 %70)
%72 = icmp slt i64 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %66
%74 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
br label %216
75: ; preds = %66
store i32 3, i32* %10
br label %76
76: ; preds = %75, %113
%77 = load i32, i32* %11
%78 = load i32, i32* @SEEK_SET
%79 = call i32 @lseek(i32 %77, i32 0, i32 %78)
%80 = load i32, i32* %11
%81 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%82 = call i32 @read(i32 %80, i8* %81, i32 80)
%83 = icmp sle i32 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %76
%85 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %212
86: ; preds = %76
%87 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%88 = call i32 @strncasecmp(i8* %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%89 = icmp ne i32 %88, 0
br i1 %89, label %91, label %90
90: ; preds = %86
br label %114
91: ; preds = %86
%92 = load i32, i32* %10
%93 = add nsw i32 %92, -1
store i32 %93, i32* %10
%94 = icmp ne i32 %92, 0
br i1 %94, label %98, label %95
95: ; preds = %91
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
br label %212
98: ; preds = %91
%99 = load i32, i32* %11
%100 = load i32, i32* @SEEK_SET
%101 = call i32 @lseek(i32 %99, i32 0, i32 %100)
%102 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%103 = call i32 @strcpy(i8* %102, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%104 = load i32, i32* %11
%105 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%106 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%107 = call i64 @strlen(i8* %106)
%108 = add nsw i64 %107, 1
%109 = call i64 @write(i32 %104, i8* %105, i64 %108)
%110 = icmp sle i64 %109, 0
br i1 %110, label %111, label %113
111: ; preds = %98
%112 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
br label %212
113: ; preds = %98
br label %76
114: ; preds = %90
%115 = load i32, i32* @O_WRONLY
%116 = load i32, i32* @O_SYNC
%117 = or i32 %115, %116
%118 = call i32 @open(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.14, i64 0, i64 0), i32 %117)
store i32 %118, i32* %12
%119 = load i32, i32* %12
%120 = icmp slt i32 %119, 0
br i1 %120, label %121, label %123
121: ; preds = %114
%122 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.15, i64 0, i64 0))
br label %196
123: ; preds = %114
%124 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%125 = call i32 @strcpy(i8* %124, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0))
%126 = load i32, i32* %12
%127 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%128 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%129 = call i64 @strlen(i8* %128)
%130 = add nsw i64 %129, 1
%131 = call i64 @write(i32 %126, i8* %127, i64 %130)
%132 = icmp slt i64 %131, 0
br i1 %132, label %133, label %135
133: ; preds = %123
%134 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.17, i64 0, i64 0))
br label %193
135: ; preds = %123
%136 = load i32, i32* %12
%137 = call i32 @close(i32 %136)
%138 = load i32, i32* @O_WRONLY
%139 = load i32, i32* @O_SYNC
%140 = or i32 %138, %139
%141 = call i32 @open(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.18, i64 0, i64 0), i32 %140)
store i32 %141, i32* %12
%142 = load i32, i32* %12
%143 = icmp slt i32 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %135
%145 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0))
br label %196
146: ; preds = %135
store i32 0, i32* %9
br label %147
147: ; preds = %173, %146
%148 = load i32, i32* %9
%149 = icmp slt i32 %148, 256
br i1 %149, label %150, label %176
150: ; preds = %147
%151 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%152 = load i32, i32* %9
%153 = load i32, i32* %9
%154 = load i32, i32* %9
%155 = sub nsw i32 255, %154
%156 = load i32, i32* %9
%157 = sub nsw i32 255, %156
%158 = call i32 @sprintf(i8* %151, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.20, i64 0, i64 0), i32 %152, i32 0, i32 0, i32 0, i32 0, i32 %153, i32 %155, i32 255, i32 0, i32 0, i32 255, i32 %157)
%159 = load i32, i32* %12
%160 = load i32, i32* @SEEK_SET
%161 = call i32 @lseek(i32 %159, i32 0, i32 %160)
%162 = load i32, i32* %12
%163 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%164 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%165 = call i64 @strlen(i8* %164)
%166 = add nsw i64 %165, 1
%167 = call i64 @write(i32 %162, i8* %163, i64 %166)
%168 = icmp slt i64 %167, 0
br i1 %168, label %169, label %171
169: ; preds = %150
%170 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.21, i64 0, i64 0))
br label %171
171: ; preds = %169, %150
%172 = call i32 @usleep(i32 100000)
br label %173
173: ; preds = %171
%174 = load i32, i32* %9
%175 = add nsw i32 %174, 4
store i32 %175, i32* %9
br label %147
176: ; preds = %147
%177 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%178 = call i32 @strcpy(i8* %177, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.22, i64 0, i64 0))
%179 = load i32, i32* %12
%180 = load i32, i32* @SEEK_SET
%181 = call i32 @lseek(i32 %179, i32 0, i32 %180)
%182 = load i32, i32* %12
%183 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%184 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%185 = call i64 @strlen(i8* %184)
%186 = add nsw i64 %185, 1
%187 = call i64 @write(i32 %182, i8* %183, i64 %186)
%188 = icmp slt i64 %187, 0
br i1 %188, label %189, label %191
189: ; preds = %176
%190 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.21, i64 0, i64 0))
br label %191
191: ; preds = %189, %176
%192 = call i32 @usleep(i32 400000)
store i32 0, i32* %14
br label %193
193: ; preds = %191, %133
%194 = load i32, i32* %12
%195 = call i32 @close(i32 %194)
br label %196
196: ; preds = %193, %144, %121
%197 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%198 = call i32 @strcpy(i8* %197, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.23, i64 0, i64 0))
%199 = load i32, i32* %11
%200 = load i32, i32* @SEEK_SET
%201 = call i32 @lseek(i32 %199, i32 0, i32 %200)
%202 = load i32, i32* %11
%203 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%204 = getelementptr inbounds [80 x i8], [80 x i8]* %13, i64 0, i64 0
%205 = call i64 @strlen(i8* %204)
%206 = add nsw i64 %205, 1
%207 = call i64 @write(i32 %202, i8* %203, i64 %206)
%208 = icmp slt i64 %207, 0
br i1 %208, label %209, label %211
209: ; preds = %196
%210 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.24, i64 0, i64 0))
br label %211
211: ; preds = %209, %196
br label %212
212: ; preds = %211, %111, %95, %84
%213 = load i32, i32* %11
%214 = load i32, i32* @LOCK_UN
%215 = call i64 @flock(i32 %213, i32 %214)
br label %216
216: ; preds = %212, %73
%217 = load i32, i32* %11
%218 = call i32 @close(i32 %217)
br label %219
219: ; preds = %216, %64, %52, %48, %27, %19
%220 = load i32, i32* %14
ret i32 %220
}

LLVM IR (-O2):
@.str = [55 x i8] c"/sys/devices/virtual/chromeos/cros_ec/lightbar/version\00"
@O_RDONLY = global i32 0
@.str.1 = [24 x i8] c"can't open version file\00"
@.str.2 = [19 x i8] c"can't read version\00"
@errno = global i64 0
@.str.3 = [6 x i8] c"%d %d\00"
@.str.4 = [27 x i8] c"can't parse version string\00"
@stderr = global i32 0
@.str.5 = [28 x i8] c"can't parse version string\0A\00"
@.str.6 = [40 x i8] c"Don't know how to handle version %d.%d\0A\00"
@.str.7 = [56 x i8] c"/sys/devices/virtual/chromeos/cros_ec/lightbar/sequence\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.8 = [28 x i8] c"can't open sequence control\00"
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
@.str.9 = [28 x i8] c"can't lock sequence control\00"
@SEEK_SET = global i32 0
@.str.10 = [28 x i8] c"can't read sequence control\00"
@.str.11 = [5 x i8] c"stop\00"
@.str.12 = [25 x i8] c"couldn't get EC to stop\0A\00"
@.str.13 = [29 x i8] c"can't write sequence control\00"
@.str.14 = [58 x i8] c"/sys/devices/virtual/chromeos/cros_ec/lightbar/brightness\00"
@O_WRONLY = global i32 0
@.str.15 = [30 x i8] c"can't open brightness control\00"
@.str.16 = [4 x i8] c"255\00"
@.str.17 = [31 x i8] c"can't write brightness control\00"
@.str.18 = [55 x i8] c"/sys/devices/virtual/chromeos/cros_ec/lightbar/led_rgb\00"
@.str.19 = [23 x i8] c"can't open led control\00"
@.str.20 = [44 x i8] c"0 %d %d %d 1 %d %d %d 2 %d %d %d 3 %d %d %d\00"
@.str.21 = [21 x i8] c"write to led control\00"
@.str.22 = [14 x i8] c"4 255 255 255\00"
@.str.23 = [4 x i8] c"run\00"
@.str.24 = [26 x i8] c"write to sequence control\00"
@LOCK_UN = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
br label %195
14: ; preds = %2
%15 = call i32 @read(i32 %10, i8* %8, i32 79)
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%19 = tail call i32 @close(i32 %10)
br label %195
20: ; preds = %14
%21 = zext i32 %15 to i64
%22 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %21
store i8 0, i8* %22
%23 = tail call i32 @close(i32 %10)
store i64 0, i64* @errno
%24 = call i32 @sscanf(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32* %3, i32* %4)
%25 = icmp eq i32 %24, 2
br i1 %25, label %34, label %26
26: ; preds = %20
%27 = load i64, i64* @errno
%28 = icmp eq i64 %27, 0
br i1 %28, label %31, label %29
29: ; preds = %26
%30 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %195
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %195
34: ; preds = %20
%35 = load i32, i32* %3
%36 = icmp eq i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %34
%38 = load i32, i32* @stderr
%39 = load i32, i32* %4
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0), i32 %35, i32 %39)
br label %195
41: ; preds = %34
%42 = load i32, i32* @O_RDWR
%43 = load i32, i32* @O_SYNC
%44 = or i32 %43, %42
%45 = call i32 @open(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.7, i64 0, i64 0), i32 %44)
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %49
47: ; preds = %41
%48 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %195
49: ; preds = %41
%50 = load i32, i32* @LOCK_EX
%51 = load i32, i32* @LOCK_NB
%52 = or i32 %51, %50
%53 = call i64 @flock(i32 %45, i32 %52)
%54 = icmp slt i64 %53, 0
br i1 %54, label %60, label %55
55: ; preds = %49
%56 = load i32, i32* @SEEK_SET
%57 = call i32 @lseek(i32 %45, i32 0, i32 %56)
%58 = call i32 @read(i32 %45, i8* %8, i32 80)
%59 = icmp slt i32 %58, 1
br i1 %59, label %62, label %64
60: ; preds = %49
%61 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.9, i64 0, i64 0))
br label %192
62: ; preds = %110, %94, %78, %55
%63 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.10, i64 0, i64 0))
br label %188
64: ; preds = %55
%65 = call i32 @strncasecmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%66 = icmp eq i32 %65, 0
br i1 %66, label %120, label %67
67: ; preds = %64
%68 = load i32, i32* @SEEK_SET
%69 = call i32 @lseek(i32 %45, i32 0, i32 %68)
%70 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%71 = call i64 @strlen(i8* %8)
%72 = add nsw i64 %71, 1
%73 = call i64 @write(i32 %45, i8* %8, i64 %72)
%74 = icmp slt i64 %73, 1
br i1 %74, label %118, label %78
75: ; preds = %115
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
br label %188
78: ; preds = %67
%79 = load i32, i32* @SEEK_SET
%80 = call i32 @lseek(i32 %45, i32 0, i32 %79)
%81 = call i32 @read(i32 %45, i8* %8, i32 80)
%82 = icmp slt i32 %81, 1
br i1 %82, label %62, label %83
83: ; preds = %78
%84 = call i32 @strncasecmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%85 = icmp eq i32 %84, 0
br i1 %85, label %120, label %86
86: ; preds = %83
%87 = load i32, i32* @SEEK_SET
%88 = call i32 @lseek(i32 %45, i32 0, i32 %87)
%89 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%90 = call i64 @strlen(i8* %8)
%91 = add nsw i64 %90, 1
%92 = call i64 @write(i32 %45, i8* %8, i64 %91)
%93 = icmp slt i64 %92, 1
br i1 %93, label %118, label %94
94: ; preds = %86
%95 = load i32, i32* @SEEK_SET
%96 = call i32 @lseek(i32 %45, i32 0, i32 %95)
%97 = call i32 @read(i32 %45, i8* %8, i32 80)
%98 = icmp slt i32 %97, 1
br i1 %98, label %62, label %99
99: ; preds = %94
%100 = call i32 @strncasecmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%101 = icmp eq i32 %100, 0
br i1 %101, label %120, label %102
102: ; preds = %99
%103 = load i32, i32* @SEEK_SET
%104 = call i32 @lseek(i32 %45, i32 0, i32 %103)
%105 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%106 = call i64 @strlen(i8* %8)
%107 = add nsw i64 %106, 1
%108 = call i64 @write(i32 %45, i8* %8, i64 %107)
%109 = icmp slt i64 %108, 1
br i1 %109, label %118, label %110
110: ; preds = %102
%111 = load i32, i32* @SEEK_SET
%112 = call i32 @lseek(i32 %45, i32 0, i32 %111)
%113 = call i32 @read(i32 %45, i8* %8, i32 80)
%114 = icmp slt i32 %113, 1
br i1 %114, label %62, label %115
115: ; preds = %110
%116 = call i32 @strncasecmp(i8* %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), i32 4)
%117 = icmp eq i32 %116, 0
br i1 %117, label %120, label %75
118: ; preds = %102, %86, %67
%119 = call i32 @perror(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.13, i64 0, i64 0))
br label %188
120: ; preds = %115, %99, %83, %64
%121 = load i32, i32* @O_WRONLY
%122 = load i32, i32* @O_SYNC
%123 = or i32 %122, %121
%124 = call i32 @open(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.14, i64 0, i64 0), i32 %123)
%125 = icmp slt i32 %124, 0
br i1 %125, label %126, label %128
126: ; preds = %120
%127 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.15, i64 0, i64 0))
br label %177
128: ; preds = %120
%129 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.16, i64 0, i64 0))
%130 = call i64 @strlen(i8* %8)
%131 = add nsw i64 %130, 1
%132 = call i64 @write(i32 %124, i8* %8, i64 %131)
%133 = icmp slt i64 %132, 0
br i1 %133, label %134, label %136
134: ; preds = %128
%135 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.17, i64 0, i64 0))
br label %173
136: ; preds = %128
%137 = call i32 @close(i32 %124)
%138 = load i32, i32* @O_WRONLY
%139 = load i32, i32* @O_SYNC
%140 = or i32 %139, %138
%141 = call i32 @open(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.18, i64 0, i64 0), i32 %140)
%142 = icmp slt i32 %141, 0
br i1 %142, label %143, label %145
143: ; preds = %136
%144 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0))
br label %177
145: ; preds = %136, %157
%146 = phi i32 [ %159, %157 ], [ 0, %136 ]
%147 = sub nuw nsw i32 255, %146
%148 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.20, i64 0, i64 0), i32 %146, i32 0, i32 0, i32 0, i32 0, i32 %146, i32 %147, i32 255, i32 0, i32 0, i32 255, i32 %147)
%149 = load i32, i32* @SEEK_SET
%150 = call i32 @lseek(i32 %141, i32 0, i32 %149)
%151 = call i64 @strlen(i8* %8)
%152 = add nsw i64 %151, 1
%153 = call i64 @write(i32 %141, i8* %8, i64 %152)
%154 = icmp slt i64 %153, 0
br i1 %154, label %155, label %157
155: ; preds = %145
%156 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.21, i64 0, i64 0))
br label %157
157: ; preds = %155, %145
%158 = call i32 @usleep(i32 100000)
%159 = add nuw nsw i32 %146, 4
%160 = icmp ult i32 %146, 252
br i1 %160, label %145, label %161
161: ; preds = %157
%162 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.22, i64 0, i64 0))
%163 = load i32, i32* @SEEK_SET
%164 = call i32 @lseek(i32 %141, i32 0, i32 %163)
%165 = call i64 @strlen(i8* %8)
%166 = add nsw i64 %165, 1
%167 = call i64 @write(i32 %141, i8* %8, i64 %166)
%168 = icmp slt i64 %167, 0
br i1 %168, label %169, label %171
169: ; preds = %161
%170 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.21, i64 0, i64 0))
br label %171
171: ; preds = %169, %161
%172 = call i32 @usleep(i32 400000)
br label %173
173: ; preds = %171, %134
%174 = phi i32 [ %124, %134 ], [ %141, %171 ]
%175 = phi i32 [ %15, %134 ], [ 0, %171 ]
%176 = call i32 @close(i32 %174)
br label %177
177: ; preds = %173, %143, %126
%178 = phi i32 [ %15, %126 ], [ %175, %173 ], [ %15, %143 ]
%179 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.23, i64 0, i64 0))
%180 = load i32, i32* @SEEK_SET
%181 = call i32 @lseek(i32 %45, i32 0, i32 %180)
%182 = call i64 @strlen(i8* %8)
%183 = add nsw i64 %182, 1
%184 = call i64 @write(i32 %45, i8* %8, i64 %183)
%185 = icmp slt i64 %184, 0
br i1 %185, label %186, label %188
186: ; preds = %177
%187 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.24, i64 0, i64 0))
br label %188
188: ; preds = %177, %186, %118, %75, %62
%189 = phi i32 [ %15, %62 ], [ %15, %118 ], [ %15, %75 ], [ %178, %186 ], [ %178, %177 ]
%190 = load i32, i32* @LOCK_UN
%191 = call i64 @flock(i32 %45, i32 %190)
br label %192
192: ; preds = %188, %60
%193 = phi i32 [ %15, %60 ], [ %189, %188 ]
%194 = call i32 @close(i32 %45)
br label %195
195: ; preds = %29, %31, %192, %47, %37, %17, %12
%196 = phi i32 [ 1, %12 ], [ %15, %17 ], [ %15, %29 ], [ %15, %31 ], [ %15, %37 ], [ %15, %47 ], [ %193, %192 ]
ret i32 %196
}