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

/* Variables and functions */
int /*<<< orphan*/ LED_CAP;
int /*<<< orphan*/ LED_SCR;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ daemonize();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int get_pid();
scalar_t__ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ toggleled(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  FILE *procnet = NULL;
  char ttyname[20] = "/dev/";
  int ttyfd;
  char line[255];
  char name[16];
  char recieved[16];
  char oldrecieved[16];
  char transmit[16];
  char oldtransmit[16];
  int waitdelay = 100;
  int i;
  int daemonized;
  if (daemonized == 0) {
    fprintf(stderr, "\n NetLED Version 3.0 ");
    fprintf(stderr, "(see COPYING for lisence information)\n\n");
  }
  if (argc < 2) {
    fprintf(stderr,
            "  netled useage: netled <console> <interface> <refresh> [-k]\n");
    fprintf(stderr, "    console    Select a console to flash the leds on.\n");
    fprintf(stderr, "    interface  Select a running interface to monitor.\n");
    fprintf(stderr,
            "    -d         Run as daemon, write pid to /var/run/netled.pid\n");
    fprintf(stderr, "    -k         Kill the running deamon.\n\n");
    exit(1);
  }
  if (strlen(argv[1]) >= 10) {
    fprintf(stderr, " Invalid argument: Argument too long!");
    exit(1);
  }
  strcat(ttyname, argv[1]);
  if ((ttyfd = open(ttyname, O_RDWR)) < 0) {
    fprintf(stderr, " Error opening keyboard %s\n ", ttyname);
    exit(1);
  }
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "-k") == 0) {
      i = get_pid();
      if (i > 0) {
        if (kill(i, SIGTERM) != 0) {
          fprintf(stderr, "Could not kill process %i\n", i);
        }
      } else {
        fprintf(stderr, "No netled process running..\n");
      }
      exit(0);
    }
    if (strcmp(argv[i], "-d") == 0) {
      daemonized = 1;
    }
  }
  if (daemonized != 0)
    daemonize();
  while (1) {
    procnet = fopen("/proc/net/dev", "r");
    if (procnet == NULL) {
      perror("Error opening /proc/net/dev");
      exit(1);
    }
    fgets(line, 255, procnet);
    fgets(line, 255, procnet);
    while (fgets(line, 255, procnet)) {
      memset(name, 0, sizeof(name));
      strncpy(name, line, 6);
      if (strstr(name, argv[2])) {
        memset(recieved, 0, sizeof(recieved));
        strncpy(recieved, line + 15, 8);
        memset(transmit, 0, sizeof(transmit));
        strncpy(transmit, line + 74, 8);
        if (strcmp(recieved, oldrecieved)) {
          toggleled(ttyfd, LED_CAP, 1);
        } else {
          toggleled(ttyfd, LED_CAP, 0);
        }
        if (strcmp(transmit, oldtransmit)) {
          toggleled(ttyfd, LED_SCR, 1);
        } else {
          toggleled(ttyfd, LED_SCR, 0);
        }
        strcpy(oldrecieved, recieved);
        strcpy(oldtransmit, transmit);
      }
    }
    fclose(procnet);
    usleep(waitdelay * 100);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0xda8(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xda5(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xda3(%rip),%eax
mov    %eax,-0x20(%rbp)
movl   $0x64,-0x194(%rbp)
cmpl   $0x0,-0x19c(%rbp)
jne    12b5 <main+0x85>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    133c <main+0x10c>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2cd4(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
lea    0xe13(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <strlen@plt>
cmp    $0xa,%eax
jl     1373 <main+0x143>
mov    0x2c6f(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1110 <strcat@plt>
lea    -0x30(%rbp),%rdi
mov    0x2c59(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    13c7 <main+0x197>
mov    0x2c1f(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rdx
lea    0xdd8(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movl   $0x1,-0x198(%rbp)
mov    -0x198(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    14c5 <main+0x295>
mov    -0x10(%rbp),%rax
movslq -0x198(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdb5(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    147d <main+0x24d>
mov    $0x0,%al
call   1140 <get_pid@plt>
mov    %eax,-0x198(%rbp)
cmpl   $0x0,-0x198(%rbp)
jle    145f <main+0x22f>
mov    -0x198(%rbp),%edi
mov    0x2bb4(%rip),%rax
mov    (%rax),%esi
call   10d0 <kill@plt>
cmp    $0x0,%rax
je     145a <main+0x22a>
mov    0x2b84(%rip),%rax
mov    (%rax),%edi
mov    -0x198(%rbp),%edx
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
jmp    1476 <main+0x246>
mov    0x2b62(%rip),%rax
mov    (%rax),%edi
lea    0xd5a(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
movslq -0x198(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd53(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jne    14ac <main+0x27c>
movl   $0x1,-0x19c(%rbp)
jmp    14b1 <main+0x281>
mov    -0x198(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x198(%rbp)
jmp    13d1 <main+0x1a1>
cmpl   $0x0,-0x19c(%rbp)
je     14d9 <main+0x2a9>
mov    $0x0,%al
call   1060 <daemonize@plt>
jmp    14de <main+0x2ae>
lea    0xd14(%rip),%rdi
lea    0xcfd(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1516 <main+0x2e6>
lea    0xce4(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x140(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   10a0 <fgets@plt>
lea    -0x140(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   10a0 <fgets@plt>
lea    -0x140(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0xff,%esi
call   10a0 <fgets@plt>
cmp    $0x0,%rax
je     16c7 <main+0x497>
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x150(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    -0x150(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1130 <strstr@plt>
cmp    $0x0,%rax
je     16c2 <main+0x492>
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x160(%rbp),%rdi
lea    -0x140(%rbp),%rsi
add    $0xf,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    -0x180(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x180(%rbp),%rdi
lea    -0x140(%rbp),%rsi
add    $0x4a,%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    -0x160(%rbp),%rdi
lea    -0x170(%rbp),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
je     163e <main+0x40e>
mov    -0x34(%rbp),%edi
mov    0x29a3(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1090 <toggleled@plt>
jmp    1651 <main+0x421>
mov    -0x34(%rbp),%edi
mov    0x2988(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <toggleled@plt>
lea    -0x180(%rbp),%rdi
lea    -0x190(%rbp),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
je     1689 <main+0x459>
mov    -0x34(%rbp),%edi
mov    0x2948(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1090 <toggleled@plt>
jmp    169c <main+0x46c>
mov    -0x34(%rbp),%edi
mov    0x292d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <toggleled@plt>
lea    -0x170(%rbp),%rdi
lea    -0x160(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x190(%rbp),%rdi
lea    -0x180(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1540 <main+0x310>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
imul   $0x64,-0x194(%rbp),%edi
call   1150 <usleep@plt>
jmp    14de <main+0x2ae>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x188,%rsp
movaps 0xdb8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
cmp    $0x1,%edi
jg     12ac <main+0x7c>
mov    0x2d67(%rip),%rbx
mov    (%rbx),%edi
lea    0xdaa(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdd8(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdff(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe26(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe56(%rip),%rsi
jmp    12cf <main+0x9f>
mov    %rsi,%r13
mov    %edi,%ebx
mov    0x8(%rsi),%rdi
call   1070 <strlen@plt>
cmp    $0xa,%eax
jl     12e0 <main+0xb0>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xe5b(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x8(%r13),%rsi
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1110 <strcat@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   10e0 <open@plt>
test   %eax,%eax
jns    132c <main+0xfc>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xe3a(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %eax,0x4(%rsp)
mov    %ebx,%r12d
mov    $0x1,%ebx
lea    0xe2e(%rip),%r14
lea    0xe62(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13,%rbx,8),%rdi
mov    %r14,%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
je     13b2 <main+0x182>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r15,%rsi
call   10b0 <strcmp@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1350 <main+0x120>
mov    %r13,0x8(%rsp)
xor    %eax,%eax
call   1060 <daemonize@plt>
lea    0xe30(%rip),%rdi
lea    0xe19(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
jne    13fc <main+0x1cc>
lea    0xe0a(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
xor    %eax,%eax
call   1140 <get_pid@plt>
test   %eax,%eax
jle    1585 <main+0x355>
mov    %eax,%ebx
mov    0x2c16(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   10d0 <kill@plt>
test   %rax,%rax
je     159c <main+0x36c>
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
mov    %rax,%r14
lea    0x80(%rsp),%rbx
jmp    1441 <main+0x211>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    $0x2710,%edi
call   1150 <usleep@plt>
lea    0xd92(%rip),%rdi
lea    0xd7b(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
je     139c <main+0x16c>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1410 <main+0x1e0>
lea    0x70(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
mov    0x8(%rsp),%rax
mov    0x10(%rax),%rsi
mov    %rbp,%rdi
call   1130 <strstr@plt>
test   %rax,%rax
je     1470 <main+0x240>
lea    0x60(%rsp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    %r12,%rdi
lea    0x8f(%rsp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    0x50(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    %r13,%rdi
lea    0xca(%rsp),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
mov    %r12,%rdi
lea    0x30(%rsp),%rsi
call   10b0 <strcmp@plt>
xor    %edx,%edx
test   %rax,%rax
setne  %dl
mov    0x2aa3(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%r15
mov    0x4(%rsp),%ebx
mov    %ebx,%edi
call   1090 <toggleled@plt>
mov    %r13,%rdi
lea    0x40(%rsp),%rbp
mov    %rbp,%rsi
call   10b0 <strcmp@plt>
xor    %edx,%edx
test   %rax,%rax
setne  %dl
mov    0x2a64(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r15,%rbx
call   1090 <toggleled@plt>
lea    0x30(%rsp),%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
jmp    1470 <main+0x240>
mov    0x2a3c(%rip),%rax
mov    (%rax),%edi
lea    0xbf6(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
@__const.main.ttyname = [20 x i8] c"/dev/\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str = [22 x i8] c"\0A NetLED Version 3.0 \00"
@.str.1 = [40 x i8] c"(see COPYING for lisence information)\0A\0A\00"
@.str.2 = [62 x i8] c" netled useage: netled <console> <interface> <refresh> [-k]\0A\00"
@.str.3 = [55 x i8] c" console Select a console to flash the leds on.\0A\00"
@.str.4 = [55 x i8] c" interface Select a running interface to monitor.\0A\00"
@.str.5 = [64 x i8] c" -d Run as daemon, write pid to /var/run/netled.pid\0A\00"
@.str.6 = [42 x i8] c" -k Kill the running deamon.\0A\0A\00"
@.str.7 = [38 x i8] c" Invalid argument: Argument too long!\00"
@O_RDWR = global i32 0
@.str.8 = [29 x i8] c" Error opening keyboard %s\0A \00"
@.str.9 = [3 x i8] c"-k\00"
@SIGTERM = global i32 0
@.str.10 = [27 x i8] c"Could not kill process %i\0A\00"
@.str.11 = [29 x i8] c"No netled process running..\0A\00"
@.str.12 = [3 x i8] c"-d\00"
@.str.13 = [14 x i8] c"/proc/net/dev\00"
@.str.14 = [2 x i8] c"r\00"
@.str.15 = [28 x i8] c"Error opening /proc/net/dev\00"
@LED_CAP = global i32 0
@LED_SCR = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca [20 x i8]
%8 = alloca i32
%9 = alloca [255 x i8]
%10 = alloca [16 x i8]
%11 = alloca [16 x i8]
%12 = alloca [16 x i8]
%13 = alloca [16 x i8]
%14 = alloca [16 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%18 = bitcast [20 x i8]* %7 to i8*
store i32 100, i32* %15
%19 = load i32, i32* %17
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %21, %2
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 2
br i1 %28, label %29, label %41
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0))
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %26
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = call i32 @strlen(i8* %44)
%46 = icmp sge i32 %45, 10
br i1 %46, label %47, label %51
47: ; preds = %41
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %41
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @strcat(i8* %52, i8* %55)
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%58 = load i32, i32* @O_RDWR
%59 = call i32 @open(i8* %57, i32 %58)
store i32 %59, i32* %8
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %66
61: ; preds = %51
%62 = load i32, i32* @stderr
%63 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %51
store i32 1, i32* %16
br label %67
67: ; preds = %108, %66
%68 = load i32, i32* %16
%69 = load i32, i32* %4
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %111
71: ; preds = %67
%72 = load i8**, i8*** %5
%73 = load i32, i32* %16
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
%77 = call i64 @strcmp(i8* %76, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %98
79: ; preds = %71
%80 = call i32 (...) @get_pid()
store i32 %80, i32* %16
%81 = load i32, i32* %16
%82 = icmp sgt i32 %81, 0
br i1 %82, label %83, label %93
83: ; preds = %79
%84 = load i32, i32* %16
%85 = load i32, i32* @SIGTERM
%86 = call i64 @kill(i32 %84, i32 %85)
%87 = icmp ne i64 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %83
%89 = load i32, i32* @stderr
%90 = load i32, i32* %16
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %88, %83
br label %96
93: ; preds = %79
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
br label %96
96: ; preds = %93, %92
%97 = call i32 @exit(i32 0)
unreachable
98: ; preds = %71
%99 = load i8**, i8*** %5
%100 = load i32, i32* %16
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds i8*, i8** %99, i64 %101
%103 = load i8*, i8** %102
%104 = call i64 @strcmp(i8* %103, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
br i1 %105, label %106, label %107
106: ; preds = %98
store i32 1, i32* %17
br label %107
107: ; preds = %106, %98
br label %108
108: ; preds = %107
%109 = load i32, i32* %16
%110 = add nsw i32 %109, 1
store i32 %110, i32* %16
br label %67
111: ; preds = %67
%112 = load i32, i32* %17
%113 = icmp ne i32 %112, 0
br i1 %113, label %114, label %116
114: ; preds = %111
%115 = call i32 (...) @daemonize()
br label %116
116: ; preds = %114, %111
br label %117
117: ; preds = %116, %194
%118 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
store i32* %118, i32** %6
%119 = load i32*, i32** %6
%120 = icmp eq i32* %119, null
br i1 %120, label %121, label %124
121: ; preds = %117
%122 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0))
%123 = call i32 @exit(i32 1)
unreachable
124: ; preds = %117
%125 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%126 = load i32*, i32** %6
%127 = call i64 @fgets(i8* %125, i32 255, i32* %126)
%128 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%129 = load i32*, i32** %6
%130 = call i64 @fgets(i8* %128, i32 255, i32* %129)
br label %131
131: ; preds = %193, %124
%132 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%133 = load i32*, i32** %6
%134 = call i64 @fgets(i8* %132, i32 255, i32* %133)
%135 = icmp ne i64 %134, 0
br i1 %135, label %136, label %194
136: ; preds = %131
%137 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%138 = call i32 @memset(i8* %137, i32 0, i32 16)
%139 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%140 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%141 = call i32 @strncpy(i8* %139, i8* %140, i32 6)
%142 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%143 = load i8**, i8*** %5
%144 = getelementptr inbounds i8*, i8** %143, i64 2
%145 = load i8*, i8** %144
%146 = call i64 @strstr(i8* %142, i8* %145)
%147 = icmp ne i64 %146, 0
br i1 %147, label %148, label %193
148: ; preds = %136
%149 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%150 = call i32 @memset(i8* %149, i32 0, i32 16)
%151 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%152 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%153 = getelementptr inbounds i8, i8* %152, i64 15
%154 = call i32 @strncpy(i8* %151, i8* %153, i32 8)
%155 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%156 = call i32 @memset(i8* %155, i32 0, i32 16)
%157 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%158 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%159 = getelementptr inbounds i8, i8* %158, i64 74
%160 = call i32 @strncpy(i8* %157, i8* %159, i32 8)
%161 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%162 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%163 = call i64 @strcmp(i8* %161, i8* %162)
%164 = icmp ne i64 %163, 0
br i1 %164, label %165, label %169
165: ; preds = %148
%166 = load i32, i32* %8
%167 = load i32, i32* @LED_CAP
%168 = call i32 @toggleled(i32 %166, i32 %167, i32 1)
br label %173
169: ; preds = %148
%170 = load i32, i32* %8
%171 = load i32, i32* @LED_CAP
%172 = call i32 @toggleled(i32 %170, i32 %171, i32 0)
br label %173
173: ; preds = %169, %165
%174 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%175 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%176 = call i64 @strcmp(i8* %174, i8* %175)
%177 = icmp ne i64 %176, 0
br i1 %177, label %178, label %182
178: ; preds = %173
%179 = load i32, i32* %8
%180 = load i32, i32* @LED_SCR
%181 = call i32 @toggleled(i32 %179, i32 %180, i32 1)
br label %186
182: ; preds = %173
%183 = load i32, i32* %8
%184 = load i32, i32* @LED_SCR
%185 = call i32 @toggleled(i32 %183, i32 %184, i32 0)
br label %186
186: ; preds = %182, %178
%187 = getelementptr inbounds [16 x i8], [16 x i8]* %12, i64 0, i64 0
%188 = getelementptr inbounds [16 x i8], [16 x i8]* %11, i64 0, i64 0
%189 = call i32 @strcpy(i8* %187, i8* %188)
%190 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%191 = getelementptr inbounds [16 x i8], [16 x i8]* %13, i64 0, i64 0
%192 = call i32 @strcpy(i8* %190, i8* %191)
br label %193
193: ; preds = %186, %136
br label %131
194: ; preds = %131
%195 = load i32*, i32** %6
%196 = call i32 @fclose(i32* %195)
%197 = load i32, i32* %15
%198 = mul nsw i32 %197, 100
%199 = call i32 @usleep(i32 %198)
br label %117
}

LLVM IR (-O2):
@__const.main.ttyname = [20 x i8] c"/dev/\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@stderr = global i32 0
@.str.2 = [62 x i8] c" netled useage: netled <console> <interface> <refresh> [-k]\0A\00"
@.str.3 = [55 x i8] c" console Select a console to flash the leds on.\0A\00"
@.str.4 = [55 x i8] c" interface Select a running interface to monitor.\0A\00"
@.str.5 = [64 x i8] c" -d Run as daemon, write pid to /var/run/netled.pid\0A\00"
@.str.6 = [42 x i8] c" -k Kill the running deamon.\0A\0A\00"
@.str.7 = [38 x i8] c" Invalid argument: Argument too long!\00"
@O_RDWR = global i32 0
@.str.8 = [29 x i8] c" Error opening keyboard %s\0A \00"
@.str.9 = [3 x i8] c"-k\00"
@SIGTERM = global i32 0
@.str.10 = [27 x i8] c"Could not kill process %i\0A\00"
@.str.11 = [29 x i8] c"No netled process running..\0A\00"
@.str.12 = [3 x i8] c"-d\00"
@.str.13 = [14 x i8] c"/proc/net/dev\00"
@.str.14 = [2 x i8] c"r\00"
@.str.15 = [28 x i8] c"Error opening /proc/net/dev\00"
@LED_CAP = global i32 0
@LED_SCR = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca [255 x i8]
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = alloca [16 x i8]
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%14 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%17 = icmp slt i32 %0, 2
br i1 %17, label %18, label %30
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.5, i64 0, i64 0))
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.6, i64 0, i64 0))
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %2
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call i32 @strlen(i8* %32)
%34 = icmp sgt i32 %33, 9
br i1 %34, label %35, label %39
35: ; preds = %30
%36 = load i32, i32* @stderr
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %30
%40 = load i8*, i8** %31
%41 = call i32 @strcat(i8* %10, i8* %40)
%42 = load i32, i32* @O_RDWR
%43 = call i32 @open(i8* %10, i32 %42)
%44 = icmp slt i32 %43, 0
br i1 %44, label %47, label %45
45: ; preds = %39
%46 = zext i32 %0 to i64
br label %51
47: ; preds = %39
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i8* %10)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %45, %72
%52 = phi i64 [ 1, %45 ], [ %75, %72 ]
%53 = getelementptr inbounds i8*, i8** %1, i64 %52
%54 = load i8*, i8** %53
%55 = call i64 @strcmp(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %72
57: ; preds = %51
%58 = call i32 (...) @get_pid()
%59 = icmp sgt i32 %58, 0
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = load i32, i32* @SIGTERM
%62 = call i64 @kill(i32 %58, i32 %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %70, label %64
64: ; preds = %60
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.10, i64 0, i64 0), i32 %58)
br label %70
67: ; preds = %57
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0))
br label %70
70: ; preds = %60, %64, %67
%71 = call i32 @exit(i32 0)
unreachable
72: ; preds = %51
%73 = load i8*, i8** %53
%74 = call i64 @strcmp(i8* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%75 = add nuw nsw i64 %52, 1
%76 = icmp eq i64 %75, %46
br i1 %76, label %77, label %51
77: ; preds = %72
%78 = call i32 (...) @daemonize()
%79 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
%80 = icmp eq i32* %79, null
br i1 %80, label %85, label %81
81: ; preds = %77
%82 = getelementptr inbounds i8*, i8** %1, i64 2
%83 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 15
%84 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 74
br label %88
85: ; preds = %120, %77
%86 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.15, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %81, %120
%89 = phi i32* [ %79, %81 ], [ %123, %120 ]
%90 = call i64 @fgets(i8* %11, i32 255, i32* %89)
%91 = call i64 @fgets(i8* %11, i32 255, i32* %89)
%92 = call i64 @fgets(i8* %11, i32 255, i32* %89)
%93 = icmp eq i64 %92, 0
br i1 %93, label %120, label %94
94: ; preds = %88, %117
%95 = call i32 @memset(i8* %12, i32 0, i32 16)
%96 = call i32 @strncpy(i8* %12, i8* %11, i32 6)
%97 = load i8*, i8** %82
%98 = call i64 @strstr(i8* %12, i8* %97)
%99 = icmp eq i64 %98, 0
br i1 %99, label %117, label %100
100: ; preds = %94
%101 = call i32 @memset(i8* %13, i32 0, i32 16)
%102 = call i32 @strncpy(i8* %13, i8* %83, i32 8)
%103 = call i32 @memset(i8* %15, i32 0, i32 16)
%104 = call i32 @strncpy(i8* %15, i8* %84, i32 8)
%105 = call i64 @strcmp(i8* %13, i8* %14)
%106 = icmp ne i64 %105, 0
%107 = load i32, i32* @LED_CAP
%108 = zext i1 %106 to i32
%109 = call i32 @toggleled(i32 %43, i32 %107, i32 %108)
%110 = call i64 @strcmp(i8* %15, i8* %16)
%111 = icmp ne i64 %110, 0
%112 = zext i1 %111 to i32
%113 = load i32, i32* @LED_SCR
%114 = call i32 @toggleled(i32 %43, i32 %113, i32 %112)
%115 = call i32 @strcpy(i8* %14, i8* %13)
%116 = call i32 @strcpy(i8* %16, i8* %15)
br label %117
117: ; preds = %100, %94
%118 = call i64 @fgets(i8* %11, i32 255, i32* %89)
%119 = icmp eq i64 %118, 0
br i1 %119, label %120, label %94
120: ; preds = %117, %88
%121 = call i32 @fclose(i32* %89)
%122 = call i32 @usleep(i32 10000)
%123 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
%124 = icmp eq i32* %123, null
br i1 %124, label %85, label %88
}