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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int fscanf(int /*<<< orphan*/ *, char *, unsigned short *, unsigned short *,
           unsigned short *, unsigned short *, unsigned short *,
           unsigned short *, unsigned short *, unsigned short *,
           unsigned short *, unsigned short *, unsigned short *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ *stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ usleep(int);
int main(int argc, char *argv[]) {
  char debug = 0;
  int prev_bl = -1;
  char *file;
  FILE *in, *out;
  if (argv[1] != NULL && strcmp(argv[1], "-d") == 0) {
    fprintf(stderr, "debug mode\n");
    debug = 1;
  } else if (argv[1]) {
    fprintf(stderr, "usage: blanviewd [-d]\n");
    return 1;
  }
  file =
      "/sys/devices/platform/pwm-backlight/backlight/pwm-backlight/brightness";
  out = fopen(file, "w");
  if (!out) {
    fprintf(stderr, "%s: %s\n", file, strerror(errno));
    return 1;
  }
  while (1) {
    int i, n;
    unsigned short x, y, pressure_raw, pressure, pendown;
    unsigned short temperature, temp0, temp1;
    unsigned short z1, z2;
    unsigned short aux;
    unsigned short ambient_light;
    unsigned short bl;
    file = "/sys/bus/i2c/drivers/tsc2007/2-0048/values";
    in = fopen(file, "r");
    if (!in) {
      fprintf(stderr, "%s: %s\n", file, strerror(errno));
      return 1;
    }
    n = fscanf(in, "%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu", &x, &y,
               &pressure_raw, &pendown, &temperature, &z1, &z2, &temp0, &temp1,
               &aux, &pressure);
    fclose(in);
    if (n == 11) {
      if (debug)
        fprintf(stderr, "aux=%d", aux);
      if (aux <= 4096 && aux > 2048)
        ambient_light = 1;
      else if (aux <= 2048 && aux > 1024)
        ambient_light = 2;
      else if (aux <= 1024 && aux > 512)
        ambient_light = 3;
      else if (aux <= 512 && aux > 256)
        ambient_light = 4;
      else if (aux <= 256 && aux > 0)
        ambient_light = 5;
      else
        ambient_light = 5;
      bl = ambient_light * 20;
      if (debug)
        fprintf(stderr, " ->");
      while (prev_bl != bl) {
        if (prev_bl < 0)
          prev_bl = bl;
        else if (prev_bl < bl)
          prev_bl += 1;
        else
          prev_bl -= 1;
        fprintf(out, "%d\n", prev_bl);
        fflush(out);
        if (debug)
          fprintf(stderr, " %d", prev_bl);
        usleep(10000);
      }
      prev_bl = bl;
      if (debug)
        fprintf(stderr, "\n");
    } else if (debug)
      fprintf(stderr, "n=%d\n", n);
    sleep(5);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xb0,%rsp
movl   $0x0,-0x24(%rbp)
mov    %edi,-0x28(%rbp)
mov    %rsi,-0x30(%rbp)
movb   $0x0,-0x31(%rbp)
movl   $0xffffffff,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1209 <main+0x79>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe27(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1209 <main+0x79>
mov    0x2df1(%rip),%rax
mov    (%rax),%rdi
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movb   $0x1,-0x31(%rbp)
jmp    1241 <main+0xb1>
mov    -0x30(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     123c <main+0xac>
mov    0x2dc1(%rip),%rax
mov    (%rax),%rdi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    15f8 <main+0x468>
jmp    1241 <main+0xb1>
lea    0xdde(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12ba <main+0x12a>
mov    0x2d6e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rdx
mov    %rax,%rcx
lea    0xdc8(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    15f8 <main+0x468>
jmp    12bf <main+0x12f>
lea    0xdb1(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    0xdcd(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    133e <main+0x1ae>
mov    0x2cf0(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x98(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x98(%rbp),%rdi
mov    -0x90(%rbp),%rdx
mov    %rax,%rcx
lea    0xd44(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    15f8 <main+0x468>
mov    -0x48(%rbp),%rdi
lea    0xd5b(%rip),%rsi
lea    -0x5a(%rbp),%rdx
lea    -0x5c(%rbp),%rcx
lea    -0x5e(%rbp),%r8
lea    -0x62(%rbp),%r9
lea    -0x64(%rbp),%r12
lea    -0x6a(%rbp),%r15
lea    -0x6c(%rbp),%r14
lea    -0x66(%rbp),%rbx
lea    -0x68(%rbp),%r11
lea    -0x6e(%rbp),%r10
lea    -0x60(%rbp),%rax
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rbx,0x18(%rsp)
mov    %r11,0x20(%rsp)
mov    %r10,0x28(%rsp)
mov    %rax,0x30(%rsp)
call   1040 <fscanf@plt>
mov    %eax,-0x58(%rbp)
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0xb,-0x58(%rbp)
jne    15bf <main+0x42f>
cmpb   $0x0,-0x31(%rbp)
je     13d8 <main+0x248>
mov    0x2c1d(%rip),%rax
mov    (%rax),%rdi
movzwl -0x6e(%rbp),%edx
lea    0xcff(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movzwl -0x6e(%rbp),%eax
cmp    $0x1000,%eax
jg     1401 <main+0x271>
movzwl -0x6e(%rbp),%eax
cmp    $0x800,%eax
jle    1401 <main+0x271>
movw   $0x1,-0x70(%rbp)
jmp    14bd <main+0x32d>
movzwl -0x6e(%rbp),%eax
cmp    $0x800,%eax
jg     142a <main+0x29a>
movzwl -0x6e(%rbp),%eax
cmp    $0x400,%eax
jle    142a <main+0x29a>
movw   $0x2,-0x70(%rbp)
jmp    14b8 <main+0x328>
movzwl -0x6e(%rbp),%eax
cmp    $0x400,%eax
jg     1453 <main+0x2c3>
movzwl -0x6e(%rbp),%eax
cmp    $0x200,%eax
jle    1453 <main+0x2c3>
movw   $0x3,-0x70(%rbp)
jmp    14b3 <main+0x323>
movzwl -0x6e(%rbp),%eax
cmp    $0x200,%eax
jg     147c <main+0x2ec>
movzwl -0x6e(%rbp),%eax
cmp    $0x100,%eax
jle    147c <main+0x2ec>
movw   $0x4,-0x70(%rbp)
jmp    14ae <main+0x31e>
movzwl -0x6e(%rbp),%eax
cmp    $0x100,%eax
jg     14a3 <main+0x313>
movzwl -0x6e(%rbp),%eax
cmp    $0x0,%eax
jle    14a3 <main+0x313>
movw   $0x5,-0x70(%rbp)
jmp    14a9 <main+0x319>
movw   $0x5,-0x70(%rbp)
jmp    14ae <main+0x31e>
jmp    14b3 <main+0x323>
jmp    14b8 <main+0x328>
jmp    14bd <main+0x32d>
movzwl -0x70(%rbp),%eax
imul   $0x14,%eax,%eax
mov    %ax,-0x72(%rbp)
cmpb   $0x0,-0x31(%rbp)
je     14ea <main+0x35a>
mov    0x2b07(%rip),%rax
mov    (%rax),%rdi
lea    0xbf4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    14ef <main+0x35f>
mov    -0x38(%rbp),%eax
movzwl -0x72(%rbp),%ecx
cmp    %ecx,%eax
je     1591 <main+0x401>
cmpl   $0x0,-0x38(%rbp)
jge    1514 <main+0x384>
movzwl -0x72(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    153f <main+0x3af>
mov    -0x38(%rbp),%eax
movzwl -0x72(%rbp),%ecx
cmp    %ecx,%eax
jge    1531 <main+0x3a1>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    153a <main+0x3aa>
mov    -0x38(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    153f <main+0x3af>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xb94(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x50(%rbp),%rdi
call   1070 <fflush@plt>
cmpb   $0x0,-0x31(%rbp)
je     1582 <main+0x3f2>
mov    0x2a72(%rip),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%edx
lea    0xb60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2710,%edi
call   10b0 <usleep@plt>
jmp    14ef <main+0x35f>
movzwl -0x72(%rbp),%eax
mov    %eax,-0x38(%rbp)
cmpb   $0x0,-0x31(%rbp)
je     15ba <main+0x42a>
mov    0x2a37(%rip),%rax
mov    (%rax),%rdi
lea    0xa71(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    15e9 <main+0x459>
cmpb   $0x0,-0x31(%rbp)
je     15e4 <main+0x454>
mov    0x2a10(%rip),%rax
mov    (%rax),%rdi
mov    -0x58(%rbp),%edx
lea    0xb02(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    15e9 <main+0x459>
mov    $0x5,%edi
call   10a0 <sleep@plt>
jmp    12bf <main+0x12f>
mov    -0x24(%rbp),%eax
add    $0xb0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rdi
mov    $0x1,%r13b
test   %rdi,%rdi
je     122d <main+0x7d>
mov    %rsi,%rbx
lea    0xe2c(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120a <main+0x5a>
cmpq   $0x0,0x8(%rbx)
je     122d <main+0x7d>
mov    0x2df4(%rip),%rax
mov    (%rax),%rcx
lea    0xe19(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
jmp    14d4 <main+0x324>
mov    0x2dcf(%rip),%rax
mov    (%rax),%rcx
lea    0xde8(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
xor    %r13d,%r13d
lea    0xdf2(%rip),%rdi
lea    0xe32(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     14a1 <main+0x2f1>
mov    %rax,%r14
lea    0xe24(%rip),%rdi
lea    0xe48(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1479 <main+0x2c9>
mov    %rax,%rbp
mov    $0xffffffff,%r15d
jmp    12af <main+0xff>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%ebx
mov    $0x5,%edi
call   10c0 <sleep@plt>
lea    0xde3(%rip),%rdi
lea    0xe07(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbp
mov    %ebx,%r15d
test   %rax,%rax
je     1479 <main+0x2c9>
sub    $0x8,%rsp
mov    %rbp,%rdi
lea    0xde7(%rip),%rsi
lea    0x1e(%rsp),%rdx
lea    0x1c(%rsp),%rcx
lea    0x1a(%rsp),%r8
lea    0x16(%rsp),%r9
lea    0x18(%rsp),%rax
push   %rax
lea    0x12(%rsp),%rax
push   %rax
lea    0x20(%rsp),%rax
push   %rax
lea    0x2a(%rsp),%rax
push   %rax
lea    0x2c(%rsp),%rax
push   %rax
lea    0x36(%rsp),%rax
push   %rax
lea    0x44(%rsp),%rax
push   %rax
call   1040 <fscanf@plt>
add    $0x40,%rsp
mov    %eax,%r12d
mov    %rbp,%rdi
call   1030 <fclose@plt>
cmp    $0xb,%r12d
jne    1450 <main+0x2a0>
test   %r13b,%r13b
mov    0x2cbd(%rip),%r12
jne    133c <main+0x18c>
mov    (%r12),%rdi
movzwl 0x2(%rsp),%edx
lea    0xd9b(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
movzwl 0x2(%rsp),%eax
lea    -0x801(%rax),%ecx
movzwl %cx,%ecx
mov    $0x14,%ebx
cmp    $0x800,%ecx
jb     13a0 <main+0x1f0>
lea    -0x401(%rax),%ecx
movzwl %cx,%ecx
mov    $0x28,%ebx
cmp    $0x400,%ecx
jb     13a0 <main+0x1f0>
lea    -0x201(%rax),%ecx
movzwl %cx,%ecx
mov    $0x3c,%ebx
cmp    $0x200,%ecx
jb     13a0 <main+0x1f0>
add    $0xfffffeff,%eax
movzwl %ax,%eax
cmp    $0x100,%eax
mov    $0x64,%ebx
mov    $0x50,%eax
cmovb  %eax,%ebx
nopl   (%rax)
test   %r13b,%r13b
jne    13bf <main+0x20f>
mov    (%r12),%rcx
mov    $0x3,%esi
mov    $0x1,%edx
lea    0xd1d(%rip),%rdi
call   10a0 <fwrite@plt>
cmp    %ebx,%r15d
jne    13f1 <main+0x241>
test   %r13b,%r13b
jne    1283 <main+0xd3>
mov    (%r12),%rsi
mov    $0xa,%edi
call   1050 <fputc@plt>
jmp    1283 <main+0xd3>
mov    $0x2710,%edi
call   10d0 <usleep@plt>
mov    %ebp,%r15d
cmp    %ebx,%ebp
je     13c4 <main+0x214>
mov    %ebx,%ebp
test   %r15d,%r15d
js     1417 <main+0x267>
cmp    %ebx,%r15d
jge    1410 <main+0x260>
add    $0x1,%r15d
jmp    1414 <main+0x264>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%r15d
mov    %r15d,%ebp
mov    %r14,%rdi
lea    0xcc0(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1080 <fflush@plt>
test   %r13b,%r13b
jne    13e0 <main+0x230>
mov    (%r12),%rdi
lea    0xc99(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13e0 <main+0x230>
nopl   (%rax)
test   %r13b,%r13b
jne    1280 <main+0xd0>
mov    0x2b80(%rip),%rax
mov    (%rax),%rdi
lea    0xc75(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1280 <main+0xd0>
mov    0x2b60(%rip),%rax
mov    (%rax),%rbx
mov    0x2b4e(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xbd7(%rip),%rsi
lea    0xbd8(%rip),%rdx
jmp    14c7 <main+0x317>
mov    0x2b38(%rip),%rax
mov    (%rax),%rbx
mov    0x2b26(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xbaf(%rip),%rsi
lea    0xb5f(%rip),%rdx
mov    %rbx,%rdi
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-d\00"
@stderr = global i32* null
@.str.1 = [12 x i8] c"debug mode\0A\00"
@.str.2 = [23 x i8] c"usage: blanviewd [-d]\0A\00"
@.str.3 = [71 x i8] c"/sys/devices/platform/pwm-backlight/backlight/pwm-backlight/brightness\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@.str.6 = [43 x i8] c"/sys/bus/i2c/drivers/tsc2007/2-0048/values\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [44 x i8] c"%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu\00"
@.str.9 = [7 x i8] c"aux=%d\00"
@.str.10 = [4 x i8] c" ->\00"
@.str.11 = [4 x i8] c"%d\0A\00"
@.str.12 = [4 x i8] c" %d\00"
@.str.13 = [2 x i8] c"\0A\00"
@.str.14 = [6 x i8] c"n=%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i16
%14 = alloca i16
%15 = alloca i16
%16 = alloca i16
%17 = alloca i16
%18 = alloca i16
%19 = alloca i16
%20 = alloca i16
%21 = alloca i16
%22 = alloca i16
%23 = alloca i16
%24 = alloca i16
%25 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 0, i8* %6
store i32 -1, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %39
30: ; preds = %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %30
%37 = load i32*, i32** @stderr
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i8 1, i8* %6
br label %48
39: ; preds = %30, %2
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %39
%45 = load i32*, i32** @stderr
%46 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %203
47: ; preds = %39
br label %48
48: ; preds = %47, %36
store i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i8** %8
%49 = load i8*, i8** %8
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %50, i32** %10
%51 = load i32*, i32** %10
%52 = icmp ne i32* %51, null
br i1 %52, label %59, label %53
53: ; preds = %48
%54 = load i32*, i32** @stderr
%55 = load i8*, i8** %8
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %55, i8* %57)
store i32 1, i32* %3
br label %203
59: ; preds = %48
br label %60
60: ; preds = %59, %201
store i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i8** %8
%61 = load i8*, i8** %8
%62 = call i32* @fopen(i8* %61, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %62, i32** %9
%63 = load i32*, i32** %9
%64 = icmp ne i32* %63, null
br i1 %64, label %71, label %65
65: ; preds = %60
%66 = load i32*, i32** @stderr
%67 = load i8*, i8** %8
%68 = load i32, i32* @errno
%69 = call i8* @strerror(i32 %68)
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %67, i8* %69)
store i32 1, i32* %3
br label %203
71: ; preds = %60
%72 = load i32*, i32** %9
%73 = call i32 @fscanf(i32* %72, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i16* %13, i16* %14, i16* %15, i16* %17, i16* %18, i16* %21, i16* %22, i16* %19, i16* %20, i16* %23, i16* %16)
store i32 %73, i32* %12
%74 = load i32*, i32** %9
%75 = call i32 @fclose(i32* %74)
%76 = load i32, i32* %12
%77 = icmp eq i32 %76, 11
br i1 %77, label %78, label %193
78: ; preds = %71
%79 = load i8, i8* %6
%80 = icmp ne i8 %79, 0
br i1 %80, label %81, label %86
81: ; preds = %78
%82 = load i32*, i32** @stderr
%83 = load i16, i16* %23
%84 = zext i16 %83 to i32
%85 = call i32 (i32*, i8*, ...) @fprintf(i32* %82, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %84)
br label %86
86: ; preds = %81, %78
%87 = load i16, i16* %23
%88 = zext i16 %87 to i32
%89 = icmp sle i32 %88, 4096
br i1 %89, label %90, label %95
90: ; preds = %86
%91 = load i16, i16* %23
%92 = zext i16 %91 to i32
%93 = icmp sgt i32 %92, 2048
br i1 %93, label %94, label %95
94: ; preds = %90
store i16 1, i16* %24
br label %136
95: ; preds = %90, %86
%96 = load i16, i16* %23
%97 = zext i16 %96 to i32
%98 = icmp sle i32 %97, 2048
br i1 %98, label %99, label %104
99: ; preds = %95
%100 = load i16, i16* %23
%101 = zext i16 %100 to i32
%102 = icmp sgt i32 %101, 1024
br i1 %102, label %103, label %104
103: ; preds = %99
store i16 2, i16* %24
br label %135
104: ; preds = %99, %95
%105 = load i16, i16* %23
%106 = zext i16 %105 to i32
%107 = icmp sle i32 %106, 1024
br i1 %107, label %108, label %113
108: ; preds = %104
%109 = load i16, i16* %23
%110 = zext i16 %109 to i32
%111 = icmp sgt i32 %110, 512
br i1 %111, label %112, label %113
112: ; preds = %108
store i16 3, i16* %24
br label %134
113: ; preds = %108, %104
%114 = load i16, i16* %23
%115 = zext i16 %114 to i32
%116 = icmp sle i32 %115, 512
br i1 %116, label %117, label %122
117: ; preds = %113
%118 = load i16, i16* %23
%119 = zext i16 %118 to i32
%120 = icmp sgt i32 %119, 256
br i1 %120, label %121, label %122
121: ; preds = %117
store i16 4, i16* %24
br label %133
122: ; preds = %117, %113
%123 = load i16, i16* %23
%124 = zext i16 %123 to i32
%125 = icmp sle i32 %124, 256
br i1 %125, label %126, label %131
126: ; preds = %122
%127 = load i16, i16* %23
%128 = zext i16 %127 to i32
%129 = icmp sgt i32 %128, 0
br i1 %129, label %130, label %131
130: ; preds = %126
store i16 5, i16* %24
br label %132
131: ; preds = %126, %122
store i16 5, i16* %24
br label %132
132: ; preds = %131, %130
br label %133
133: ; preds = %132, %121
br label %134
134: ; preds = %133, %112
br label %135
135: ; preds = %134, %103
br label %136
136: ; preds = %135, %94
%137 = load i16, i16* %24
%138 = zext i16 %137 to i32
%139 = mul nsw i32 %138, 20
%140 = trunc i32 %139 to i16
store i16 %140, i16* %25
%141 = load i8, i8* %6
%142 = icmp ne i8 %141, 0
br i1 %142, label %143, label %146
143: ; preds = %136
%144 = load i32*, i32** @stderr
%145 = call i32 (i32*, i8*, ...) @fprintf(i32* %144, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
br label %146
146: ; preds = %143, %136
br label %147
147: ; preds = %182, %146
%148 = load i32, i32* %7
%149 = load i16, i16* %25
%150 = zext i16 %149 to i32
%151 = icmp ne i32 %148, %150
br i1 %151, label %152, label %184
152: ; preds = %147
%153 = load i32, i32* %7
%154 = icmp slt i32 %153, 0
br i1 %154, label %155, label %158
155: ; preds = %152
%156 = load i16, i16* %25
%157 = zext i16 %156 to i32
store i32 %157, i32* %7
br label %170
158: ; preds = %152
%159 = load i32, i32* %7
%160 = load i16, i16* %25
%161 = zext i16 %160 to i32
%162 = icmp slt i32 %159, %161
br i1 %162, label %163, label %166
163: ; preds = %158
%164 = load i32, i32* %7
%165 = add nsw i32 %164, 1
store i32 %165, i32* %7
br label %169
166: ; preds = %158
%167 = load i32, i32* %7
%168 = sub nsw i32 %167, 1
store i32 %168, i32* %7
br label %169
169: ; preds = %166, %163
br label %170
170: ; preds = %169, %155
%171 = load i32*, i32** %10
%172 = load i32, i32* %7
%173 = call i32 (i32*, i8*, ...) @fprintf(i32* %171, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32 %172)
%174 = load i32*, i32** %10
%175 = call i32 @fflush(i32* %174)
%176 = load i8, i8* %6
%177 = icmp ne i8 %176, 0
br i1 %177, label %178, label %182
178: ; preds = %170
%179 = load i32*, i32** @stderr
%180 = load i32, i32* %7
%181 = call i32 (i32*, i8*, ...) @fprintf(i32* %179, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i32 %180)
br label %182
182: ; preds = %178, %170
%183 = call i32 @usleep(i32 10000)
br label %147
184: ; preds = %147
%185 = load i16, i16* %25
%186 = zext i16 %185 to i32
store i32 %186, i32* %7
%187 = load i8, i8* %6
%188 = icmp ne i8 %187, 0
br i1 %188, label %189, label %192
189: ; preds = %184
%190 = load i32*, i32** @stderr
%191 = call i32 (i32*, i8*, ...) @fprintf(i32* %190, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
br label %192
192: ; preds = %189, %184
br label %201
193: ; preds = %71
%194 = load i8, i8* %6
%195 = icmp ne i8 %194, 0
br i1 %195, label %196, label %200
196: ; preds = %193
%197 = load i32*, i32** @stderr
%198 = load i32, i32* %12
%199 = call i32 (i32*, i8*, ...) @fprintf(i32* %197, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0), i32 %198)
br label %200
200: ; preds = %196, %193
br label %201
201: ; preds = %200, %192
%202 = call i32 @sleep(i32 5)
br label %60
203: ; preds = %65, %53, %44
%204 = load i32, i32* %3
ret i32 %204
}

LLVM IR (-O2):
@.str = [3 x i8] c"-d\00"
@stderr = global i32* null
@.str.1 = [12 x i8] c"debug mode\0A\00"
@.str.2 = [23 x i8] c"usage: blanviewd [-d]\0A\00"
@.str.3 = [71 x i8] c"/sys/devices/platform/pwm-backlight/backlight/pwm-backlight/brightness\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@.str.6 = [43 x i8] c"/sys/bus/i2c/drivers/tsc2007/2-0048/values\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [44 x i8] c"%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu\00"
@.str.9 = [7 x i8] c"aux=%d\00"
@.str.10 = [4 x i8] c" ->\00"
@.str.11 = [4 x i8] c"%d\0A\00"
@.str.12 = [4 x i8] c" %d\00"
@.str.14 = [6 x i8] c"n=%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = alloca i16
%5 = alloca i16
%6 = alloca i16
%7 = alloca i16
%8 = alloca i16
%9 = alloca i16
%10 = alloca i16
%11 = alloca i16
%12 = alloca i16
%13 = alloca i16
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %29, label %17
17: ; preds = %2
%18 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32*, i32** @stderr
%22 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 11, i64 1, i32* %21)
br label %29
23: ; preds = %17
%24 = load i8*, i8** %14
%25 = icmp eq i8* %24, null
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32*, i32** @stderr
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i64 22, i64 1, i32* %27)
br label %122
29: ; preds = %2, %23, %20
%30 = phi i1 [ true, %23 ], [ false, %20 ], [ true, %2 ]
%31 = tail call i32* @fopen(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i32* %31, null
br i1 %32, label %47, label %33
33: ; preds = %29
%34 = bitcast i16* %3 to i8*
%35 = bitcast i16* %4 to i8*
%36 = bitcast i16* %5 to i8*
%37 = bitcast i16* %6 to i8*
%38 = bitcast i16* %7 to i8*
%39 = bitcast i16* %8 to i8*
%40 = bitcast i16* %9 to i8*
%41 = bitcast i16* %10 to i8*
%42 = bitcast i16* %11 to i8*
%43 = bitcast i16* %12 to i8*
%44 = bitcast i16* %13 to i8*
%45 = call i32* @fopen(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%46 = icmp eq i32* %45, null
br i1 %46, label %52, label %57
47: ; preds = %29
%48 = load i32*, i32** @stderr
%49 = load i32, i32* @errno
%50 = tail call i8* @strerror(i32 %49)
%51 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.3, i64 0, i64 0), i8* %50)
br label %122
52: ; preds = %117, %33
%53 = load i32*, i32** @stderr
%54 = load i32, i32* @errno
%55 = call i8* @strerror(i32 %54)
%56 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i8* %55)
br label %122
57: ; preds = %33, %117
%58 = phi i32* [ %120, %117 ], [ %45, %33 ]
%59 = phi i32 [ %118, %117 ], [ -1, %33 ]
%60 = call i32 @fscanf(i32* %58, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.8, i64 0, i64 0), i16* %3, i16* %4, i16* %5, i16* %7, i16* %8, i16* %11, i16* %12, i16* %9, i16* %10, i16* %13, i16* %6)
%61 = call i32 @fclose(i32* %58)
%62 = icmp eq i32 %60, 11
br i1 %62, label %63, label %113
63: ; preds = %57
br i1 %30, label %69, label %64
64: ; preds = %63
%65 = load i32*, i32** @stderr
%66 = load i16, i16* %13
%67 = zext i16 %66 to i32
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %65, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %67)
br label %69
69: ; preds = %64, %63
%70 = load i16, i16* %13
%71 = add i16 %70, -2049
%72 = icmp ult i16 %71, 2048
br i1 %72, label %83, label %73
73: ; preds = %69
%74 = add i16 %70, -1025
%75 = icmp ult i16 %74, 1024
br i1 %75, label %83, label %76
76: ; preds = %73
%77 = add i16 %70, -513
%78 = icmp ult i16 %77, 512
br i1 %78, label %83, label %79
79: ; preds = %76
%80 = add i16 %70, -257
%81 = icmp ult i16 %80, 256
%82 = select i1 %81, i32 80, i32 100
br label %83
83: ; preds = %79, %76, %73, %69
%84 = phi i32 [ 20, %69 ], [ 40, %73 ], [ 60, %76 ], [ %82, %79 ]
br i1 %30, label %88, label %85
85: ; preds = %83
%86 = load i32*, i32** @stderr
%87 = call i64 @fwrite(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i64 3, i64 1, i32* %86)
br label %88
88: ; preds = %85, %83
%89 = icmp eq i32 %59, %84
br i1 %89, label %109, label %90
90: ; preds = %88, %106
%91 = phi i32 [ %100, %106 ], [ %59, %88 ]
%92 = icmp slt i32 %91, 0
br i1 %92, label %99, label %93
93: ; preds = %90
%94 = icmp slt i32 %91, %84
br i1 %94, label %95, label %97
95: ; preds = %93
%96 = add nuw nsw i32 %91, 1
br label %99
97: ; preds = %93
%98 = add nsw i32 %91, -1
br label %99
99: ; preds = %90, %95, %97
%100 = phi i32 [ %96, %95 ], [ %98, %97 ], [ %84, %90 ]
%101 = call i32 (i32*, i8*, ...) @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i32 %100)
%102 = call i32 @fflush(i32* %31)
br i1 %30, label %106, label %103
103: ; preds = %99
%104 = load i32*, i32** @stderr
%105 = call i32 (i32*, i8*, ...) @fprintf(i32* %104, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i32 %100)
br label %106
106: ; preds = %103, %99
%107 = call i32 @usleep(i32 10000)
%108 = icmp eq i32 %100, %84
br i1 %108, label %109, label %90
109: ; preds = %106, %88
br i1 %30, label %117, label %110
110: ; preds = %109
%111 = load i32*, i32** @stderr
%112 = call i32 @fputc(i32 10, i32* %111)
br label %117
113: ; preds = %57
br i1 %30, label %117, label %114
114: ; preds = %113
%115 = load i32*, i32** @stderr
%116 = call i32 (i32*, i8*, ...) @fprintf(i32* %115, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.14, i64 0, i64 0), i32 %60)
br label %117
117: ; preds = %110, %109, %114, %113
%118 = phi i32 [ %84, %110 ], [ %84, %109 ], [ %59, %114 ], [ %59, %113 ]
%119 = call i32 @sleep(i32 5)
%120 = call i32* @fopen(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%121 = icmp eq i32* %120, null
br i1 %121, label %52, label %57
122: ; preds = %52, %47, %26
ret i32 1
}