#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 */
struct timeval {
  int member_0;
  int /*<<< orphan*/ member_1;
};
struct stat {
  int dummy;
};
typedef int /*<<< orphan*/ fd_set;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ FD_ISSET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char getchar();
int /*<<< orphan*/ gethostname(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ system(char *);
int main(void) {
  FILE *ptr_file, *ptr_version, *ptr_state, *ptr_ref;
  char ver[15];
  char ref[15];
  char state[15];
  char buf[1000];
  struct stat sbuf;
  char HOSTNAME[4096];
  int delay = 1;
  int detail = 0;
  gethostname(HOSTNAME, 4096);
  if (stat("/sys/module/drbd/version", &sbuf) > -1) {
    ptr_version = fopen("/sys/module/drbd/version", "r");
  } else {
    fprintf(stderr, "Unable to open DRBD version file.  Is DRBD running?\n");
    exit(0);
  }
  while (fgets(ver, 16, ptr_version) != NULL) {
    printf("%s", ver);
  }
  fclose(ptr_version);
  ver[strlen(ver) - 1] = '\0';
  while (1) {
    if (stat("/sys/module/drbd/initstate", &sbuf) > -1) {
      ptr_state = fopen("/sys/module/drbd/initstate", "r");
      while (fgets(state, 16, ptr_state) != NULL) {
        printf("%s", state);
      }
      fclose(ptr_state);
      state[strlen(state) - 1] = '\0';
    } else {
      strncpy(state, "unknown", 7);
      fprintf(stderr,
              "Unable to open DRBD initstate file.  Is DRBD running?\n");
      exit(0);
    }
    ptr_ref = fopen("/sys/module/drbd/refcnt", "r");
    while (fgets(ref, 16, ptr_ref) != NULL) {
      printf("%s", ref);
    }
    fclose(ptr_ref);
    ref[strlen(ref) - 1] = '\0';
    if (delay < 1) {
      delay = 1;
    }
    if (!(ptr_file = fopen("/proc/drbd", "r"))) {
      fprintf(stderr, "Unable to open DRBD process file.  Is DRBD running?\n");
      exit(0);
    }
    system("clear");
    fprintf(stderr, "DRBD %s status on %s, updated every %d second[s]\n", ver,
            HOSTNAME, delay);
    fprintf(stderr, "Init state: %s, Ref count: %s\n\n", state, ref);
    while (fgets(buf, 1000, ptr_file) != NULL) {
      printf("%s", buf);
    }
    fclose(ptr_file);
    fprintf(
        stderr,
        "\nPress [f] to speed up, [s] to slow down, [d] to toggle details, [q] "
        "or Ctrl-C to quit.\nHold any other key for near real-time update.\n");
    system("stty raw");
    fd_set files;
    FD_ZERO(&files);
    FD_SET(0, &files);
    struct timeval timeout = {delay, 0};
    int n = select(1, &files, NULL, NULL, &timeout);
    if (n > 0 && FD_ISSET(0, &files)) {
      char ch = getchar();
      if (ch == 'd') {
        if (detail == 0) {
          detail = 1;
          system("echo 1 > /sys/module/drbd/parameters/proc_details");
        } else {
          detail = 0;
          system("echo 0 > /sys/module/drbd/parameters/proc_details");
        }
      } else if (ch == 'f') {
        delay = delay - 1;
      } else if (ch == 's') {
        delay = delay + 1;
      } else if (ch == 'q' || ch == 0x03) {
        system("stty cooked");
        exit(0);
      }
      fflush(stdout);
    }
    system("stty cooked");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1470,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x1454(%rbp)
movl   $0x0,-0x1458(%rbp)
lea    -0x1450(%rbp),%rdi
mov    $0x1000,%esi
call   1110 <gethostname@plt>
lea    0xdb2(%rip),%rdi
lea    -0x448(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
jle    127f <main+0x6f>
lea    0xd96(%rip),%rdi
lea    0xe96(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    129d <main+0x8d>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
jmp    12a2 <main+0x92>
lea    -0x37(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x10,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     12d3 <main+0xc3>
lea    -0x37(%rbp),%rsi
lea    0xd85(%rip),%rdi
call   1080 <printf@plt>
jmp    12a2 <main+0x92>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x37(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x37(%rbp,%rax,1)
lea    0xd5b(%rip),%rdi
lea    -0x448(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
jle    1374 <main+0x164>
lea    0xd3f(%rip),%rdi
lea    0xdee(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    -0x55(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x10,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1353 <main+0x143>
lea    -0x55(%rbp),%rsi
lea    0xd05(%rip),%rdi
call   1080 <printf@plt>
jmp    1322 <main+0x112>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x55(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x55(%rbp,%rax,1)
jmp    13a7 <main+0x197>
lea    -0x55(%rbp),%rdi
lea    0xced(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    0x2c50(%rip),%rax
mov    (%rax),%edi
lea    0xcdb(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
lea    0xcfd(%rip),%rdi
lea    0xd52(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    -0x46(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x10,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13ef <main+0x1df>
lea    -0x46(%rbp),%rsi
lea    0xc69(%rip),%rdi
call   1080 <printf@plt>
jmp    13be <main+0x1ae>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x46(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x46(%rbp,%rax,1)
cmpl   $0x1,-0x1454(%rbp)
jge    1422 <main+0x212>
movl   $0x1,-0x1454(%rbp)
lea    0xc9a(%rip),%rdi
lea    0xcd7(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1461 <main+0x251>
mov    0x2b96(%rip),%rax
mov    (%rax),%edi
lea    0xc7b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
lea    0xc9b(%rip),%rdi
call   1070 <system@plt>
mov    0x2b6c(%rip),%rax
mov    (%rax),%edi
lea    -0x37(%rbp),%rdx
lea    -0x1450(%rbp),%rcx
mov    -0x1454(%rbp),%r8d
lea    0xc7a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
lea    -0x55(%rbp),%rdx
lea    -0x46(%rbp),%rcx
lea    0xc8d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     14ec <main+0x2dc>
lea    -0x440(%rbp),%rsi
lea    0xb6c(%rip),%rdi
call   1080 <printf@plt>
jmp    14b5 <main+0x2a5>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    0x2ae4(%rip),%rax
mov    (%rax),%edi
lea    0xc56(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    0xccf(%rip),%rdi
call   1070 <system@plt>
lea    -0x145c(%rbp),%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x145c(%rbp),%rsi
call   1130 <FD_SET@plt>
mov    -0x1454(%rbp),%eax
mov    %eax,-0x1468(%rbp)
movl   $0x0,-0x1464(%rbp)
mov    $0x1,%edi
lea    -0x145c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x1468(%rbp),%r8
mov    %rcx,%rdx
call   10e0 <select@plt>
mov    %eax,-0x146c(%rbp)
cmpl   $0x0,-0x146c(%rbp)
jle    168a <main+0x47a>
xor    %edi,%edi
lea    -0x145c(%rbp),%rsi
call   1040 <FD_ISSET@plt>
cmp    $0x0,%rax
je     168a <main+0x47a>
mov    $0x0,%al
call   10a0 <getchar@plt>
mov    %al,-0x146d(%rbp)
movsbl -0x146d(%rbp),%eax
cmp    $0x64,%eax
jne    15f2 <main+0x3e2>
cmpl   $0x0,-0x1458(%rbp)
jne    15d7 <main+0x3c7>
movl   $0x1,-0x1458(%rbp)
lea    0xc1e(%rip),%rdi
call   1070 <system@plt>
jmp    15ed <main+0x3dd>
movl   $0x0,-0x1458(%rbp)
lea    0xc35(%rip),%rdi
call   1070 <system@plt>
jmp    167c <main+0x46c>
movsbl -0x146d(%rbp),%eax
cmp    $0x66,%eax
jne    1616 <main+0x406>
mov    -0x1454(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1454(%rbp)
jmp    1677 <main+0x467>
movsbl -0x146d(%rbp),%eax
cmp    $0x73,%eax
jne    163a <main+0x42a>
mov    -0x1454(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1454(%rbp)
jmp    1672 <main+0x462>
movsbl -0x146d(%rbp),%eax
cmp    $0x71,%eax
je     165a <main+0x44a>
movsbl -0x146d(%rbp),%eax
cmp    $0x3,%eax
jne    166d <main+0x45d>
lea    0xbee(%rip),%rdi
call   1070 <system@plt>
xor    %edi,%edi
call   1120 <exit@plt>
jmp    1672 <main+0x462>
jmp    1677 <main+0x467>
jmp    167c <main+0x46c>
mov    0x2955(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
lea    0xbbe(%rip),%rdi
call   1070 <system@plt>
jmp    12ef <main+0xdf>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1448,%rsp
lea    0x440(%rsp),%rdi
mov    $0x1000,%esi
call   1110 <gethostname@plt>
lea    0xe06(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10c0 <stat@plt>
test   %eax,%eax
js     15e3 <main+0x3d3>
lea    0xded(%rip),%rdi
lea    0xeed(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,%rbp
lea    0x23(%rsp),%r14
mov    %r14,%rdi
mov    $0x10,%esi
mov    %rax,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     12b0 <main+0xa0>
lea    0xe0b(%rip),%r15
lea    0x23(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    1290 <main+0x80>
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
lea    0xdc2(%rip),%rdi
lea    0x8(%rsp),%rsi
call   10c0 <stat@plt>
test   %eax,%eax
js     15f5 <main+0x3e5>
lea    0xda9(%rip),%rbp
lea    0xe58(%rip),%r12
lea    0x32(%rsp),%r13
lea    0x41(%rsp),%rbx
lea    0x50(%rsp),%r15
lea    0xd89(%rip),%r14
movl   $0x1,(%rsp)
movl   $0x0,0x4(%rsp)
jmp    134f <main+0x13f>
cs nopw 0x0(%rax,%rax,1)
lea    0xd6a(%rip),%rbp
lea    0xe19(%rip),%r12
lea    0xf5a(%rip),%rdi
call   1070 <system@plt>
mov    %rbp,%rdi
lea    0x8(%rsp),%rsi
call   10c0 <stat@plt>
test   %eax,%eax
js     15f5 <main+0x3e5>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1100 <fopen@plt>
mov    %rax,%rbp
mov    %r13,%rdi
mov    $0x10,%esi
mov    %rax,%rdx
nopl   0x0(%rax,%rax,1)
call   1090 <fgets@plt>
test   %rax,%rax
je     13a0 <main+0x190>
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <printf@plt>
mov    %r13,%rdi
mov    $0x10,%esi
mov    %rbp,%rdx
jmp    1370 <main+0x160>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %r13,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r13,1)
lea    0xd2c(%rip),%rdi
mov    %r12,%rsi
call   1100 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %rax,%rdx
cs nopw 0x0(%rax,%rax,1)
nop
call   1090 <fgets@plt>
test   %rax,%rax
je     1410 <main+0x200>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1080 <printf@plt>
mov    %rbx,%rdi
mov    $0x10,%esi
mov    %rbp,%rdx
jmp    13e0 <main+0x1d0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    (%rsp),%ebp
test   %ebp,%ebp
mov    $0x1,%eax
cmovle %eax,%ebp
lea    0xcc8(%rip),%rdi
mov    %r12,%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     161d <main+0x40d>
mov    %rax,%r12
lea    0xced(%rip),%rdi
call   1070 <system@plt>
mov    0x2b7e(%rip),%rax
mov    %ebp,%r8d
mov    %rax,%rbp
mov    (%rax),%edi
lea    0xcd8(%rip),%rsi
lea    0x23(%rsp),%rdx
lea    0x440(%rsp),%rcx
mov    %r8d,(%rsp)
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x0(%rbp),%edi
lea    0xce8(%rip),%rsi
mov    %r13,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r15,%rdi
mov    $0x3e8,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     14d0 <main+0x2c0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <printf@plt>
jmp    14a0 <main+0x290>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    0x2b01(%rip),%rax
mov    (%rax),%edi
lea    0xcb3(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0xd2c(%rip),%rdi
call   1070 <system@plt>
lea    0x1c(%rsp),%rbp
mov    %rbp,%rdi
call   10d0 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbp,%rsi
call   1130 <FD_SET@plt>
mov    (%rsp),%eax
mov    %eax,0x10(%rsp)
movl   $0x0,0x14(%rsp)
mov    $0x1,%edi
mov    %rbp,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
lea    0x10(%rsp),%r8
call   10e0 <select@plt>
test   %eax,%eax
jle    1320 <main+0x110>
xor    %edi,%edi
mov    %rbp,%rsi
call   1040 <FD_ISSET@plt>
test   %rax,%rax
lea    0xb3e(%rip),%rbp
lea    0xbed(%rip),%r12
je     132e <main+0x11e>
xor    %eax,%eax
call   10a0 <getchar@plt>
lea    -0x64(%rax),%ecx
cmp    $0xf,%cl
ja     15ab <main+0x39b>
movzbl %cl,%eax
lea    0xa87(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x0,0x4(%rsp)
jne    15b4 <main+0x3a4>
lea    0xc9b(%rip),%rdi
call   1070 <system@plt>
movl   $0x1,0x4(%rsp)
jmp    15d0 <main+0x3c0>
addl   $0xffffffff,(%rsp)
jmp    15d0 <main+0x3c0>
addl   $0x1,(%rsp)
jmp    15d0 <main+0x3c0>
cmp    $0x3,%al
jne    15d0 <main+0x3c0>
jmp    163b <main+0x42b>
lea    0xca2(%rip),%rdi
call   1070 <system@plt>
movl   $0x0,0x4(%rsp)
nopl   0x0(%rax,%rax,1)
mov    0x2a01(%rip),%rax
mov    (%rax),%edi
call   10f0 <fflush@plt>
jmp    132e <main+0x11e>
mov    0x29f6(%rip),%rax
mov    (%rax),%edi
lea    0xa66(%rip),%rsi
jmp    162d <main+0x41d>
lea    0xab0(%rip),%rsi
lea    0x32(%rsp),%rdi
mov    $0x7,%edx
call   1030 <strncpy@plt>
mov    0x29ce(%rip),%rax
mov    (%rax),%edi
lea    0xa99(%rip),%rsi
jmp    162d <main+0x41d>
mov    0x29bc(%rip),%rax
mov    (%rax),%edi
lea    0xae1(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
xor    %edi,%edi
call   1120 <exit@plt>
lea    0xc4d(%rip),%rdi
call   1070 <system@plt>
xor    %edi,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [25 x i8] c"/sys/module/drbd/version\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [53 x i8] c"Unable to open DRBD version file. Is DRBD running?\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [27 x i8] c"/sys/module/drbd/initstate\00"
@.str.5 = [8 x i8] c"unknown\00"
@.str.6 = [55 x i8] c"Unable to open DRBD initstate file. Is DRBD running?\0A\00"
@.str.7 = [24 x i8] c"/sys/module/drbd/refcnt\00"
@.str.8 = [11 x i8] c"/proc/drbd\00"
@.str.9 = [53 x i8] c"Unable to open DRBD process file. Is DRBD running?\0A\00"
@.str.10 = [6 x i8] c"clear\00"
@.str.11 = [50 x i8] c"DRBD %s status on %s, updated every %d second[s]\0A\00"
@.str.12 = [32 x i8] c"Init state: %s, Ref count: %s\0A\0A\00"
@.str.13 = [135 x i8] c"\0APress [f] to speed up, [s] to slow down, [d] to toggle details, [q] or Ctrl-C to quit.\0AHold any other key for near real-time update.\0A\00"
@.str.14 = [9 x i8] c"stty raw\00"
@.str.15 = [50 x i8] c"echo 1 > /sys/module/drbd/parameters/proc_details\00"
@.str.16 = [50 x i8] c"echo 0 > /sys/module/drbd/parameters/proc_details\00"
@.str.17 = [12 x i8] c"stty cooked\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [15 x i8]
%7 = alloca [15 x i8]
%8 = alloca [15 x i8]
%9 = alloca [1000 x i8]
%10 = alloca %struct.stat
%11 = alloca [4096 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.timeval
%16 = alloca i32
%17 = alloca i8
store i32 0, i32* %1
store i32 1, i32* %12
store i32 0, i32* %13
%18 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%19 = call i32 @gethostname(i8* %18, i32 4096)
%20 = call i32 @stat(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %struct.stat* %10)
%21 = icmp sgt i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %0
%23 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %23, i32** %3
br label %28
24: ; preds = %0
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %22
br label %29
29: ; preds = %34, %28
%30 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%31 = load i32*, i32** %3
%32 = call i32* @fgets(i8* %30, i32 16, i32* %31)
%33 = icmp ne i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%36 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %35)
br label %29
37: ; preds = %29
%38 = load i32*, i32** %3
%39 = call i32 @fclose(i32* %38)
%40 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %37, %180
%46 = call i32 @stat(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %10)
%47 = icmp sgt i32 %46, -1
br i1 %47, label %48, label %66
48: ; preds = %45
%49 = call i32* @fopen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %49, i32** %4
br label %50
50: ; preds = %55, %48
%51 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%52 = load i32*, i32** %4
%53 = call i32* @fgets(i8* %51, i32 16, i32* %52)
%54 = icmp ne i32* %53, null
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%57 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %56)
br label %50
58: ; preds = %50
%59 = load i32*, i32** %4
%60 = call i32 @fclose(i32* %59)
%61 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%62 = call i32 @strlen(i8* %61)
%63 = sub nsw i32 %62, 1
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 %64
store i8 0, i8* %65
br label %72
66: ; preds = %45
%67 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%68 = call i32 @strncpy(i8* %67, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 7)
%69 = load i32, i32* @stderr
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0))
%71 = call i32 @exit(i32 0)
unreachable
72: ; preds = %58
%73 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %73, i32** %5
br label %74
74: ; preds = %79, %72
%75 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%76 = load i32*, i32** %5
%77 = call i32* @fgets(i8* %75, i32 16, i32* %76)
%78 = icmp ne i32* %77, null
br i1 %78, label %79, label %82
79: ; preds = %74
%80 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%81 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %80)
br label %74
82: ; preds = %74
%83 = load i32*, i32** %5
%84 = call i32 @fclose(i32* %83)
%85 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%86 = call i32 @strlen(i8* %85)
%87 = sub nsw i32 %86, 1
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 %88
store i8 0, i8* %89
%90 = load i32, i32* %12
%91 = icmp slt i32 %90, 1
br i1 %91, label %92, label %93
92: ; preds = %82
store i32 1, i32* %12
br label %93
93: ; preds = %92, %82
%94 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %94, i32** %2
%95 = icmp ne i32* %94, null
br i1 %95, label %100, label %96
96: ; preds = %93
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
%99 = call i32 @exit(i32 0)
unreachable
100: ; preds = %93
%101 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%102 = load i32, i32* @stderr
%103 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%104 = getelementptr inbounds [4096 x i8], [4096 x i8]* %11, i64 0, i64 0
%105 = load i32, i32* %12
%106 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.11, i64 0, i64 0), i8* %103, i8* %104, i32 %105)
%107 = load i32, i32* @stderr
%108 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%109 = getelementptr inbounds [15 x i8], [15 x i8]* %7, i64 0, i64 0
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %108, i8* %109)
br label %111
111: ; preds = %116, %100
%112 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%113 = load i32*, i32** %2
%114 = call i32* @fgets(i8* %112, i32 1000, i32* %113)
%115 = icmp ne i32* %114, null
br i1 %115, label %116, label %119
116: ; preds = %111
%117 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%118 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %117)
br label %111
119: ; preds = %111
%120 = load i32*, i32** %2
%121 = call i32 @fclose(i32* %120)
%122 = load i32, i32* @stderr
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.13, i64 0, i64 0))
%124 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
%125 = call i32 @FD_ZERO(i32* %14)
%126 = call i32 @FD_SET(i32 0, i32* %14)
%127 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%128 = load i32, i32* %12
store i32 %128, i32* %127
%129 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
store i32 0, i32* %129
%130 = call i32 @select(i32 1, i32* %14, i32* null, i32* null, %struct.timeval* %15)
store i32 %130, i32* %16
%131 = load i32, i32* %16
%132 = icmp sgt i32 %131, 0
br i1 %132, label %133, label %180
133: ; preds = %119
%134 = call i64 @FD_ISSET(i32 0, i32* %14)
%135 = icmp ne i64 %134, 0
br i1 %135, label %136, label %180
136: ; preds = %133
%137 = call signext i8 (...) @getchar()
store i8 %137, i8* %17
%138 = load i8, i8* %17
%139 = sext i8 %138 to i32
%140 = icmp eq i32 %139, 100
br i1 %140, label %141, label %149
141: ; preds = %136
%142 = load i32, i32* %13
%143 = icmp eq i32 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %141
store i32 1, i32* %13
%145 = call i32 @system(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.15, i64 0, i64 0))
br label %148
146: ; preds = %141
store i32 0, i32* %13
%147 = call i32 @system(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.16, i64 0, i64 0))
br label %148
148: ; preds = %146, %144
br label %177
149: ; preds = %136
%150 = load i8, i8* %17
%151 = sext i8 %150 to i32
%152 = icmp eq i32 %151, 102
br i1 %152, label %153, label %156
153: ; preds = %149
%154 = load i32, i32* %12
%155 = sub nsw i32 %154, 1
store i32 %155, i32* %12
br label %176
156: ; preds = %149
%157 = load i8, i8* %17
%158 = sext i8 %157 to i32
%159 = icmp eq i32 %158, 115
br i1 %159, label %160, label %163
160: ; preds = %156
%161 = load i32, i32* %12
%162 = add nsw i32 %161, 1
store i32 %162, i32* %12
br label %175
163: ; preds = %156
%164 = load i8, i8* %17
%165 = sext i8 %164 to i32
%166 = icmp eq i32 %165, 113
br i1 %166, label %171, label %167
167: ; preds = %163
%168 = load i8, i8* %17
%169 = sext i8 %168 to i32
%170 = icmp eq i32 %169, 3
br i1 %170, label %171, label %174
171: ; preds = %167, %163
%172 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0))
%173 = call i32 @exit(i32 0)
unreachable
174: ; preds = %167
br label %175
175: ; preds = %174, %160
br label %176
176: ; preds = %175, %153
br label %177
177: ; preds = %176, %148
%178 = load i32, i32* @stdout
%179 = call i32 @fflush(i32 %178)
br label %180
180: ; preds = %177, %133, %119
%181 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0))
br label %45
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [25 x i8] c"/sys/module/drbd/version\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [53 x i8] c"Unable to open DRBD version file. Is DRBD running?\0A\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [27 x i8] c"/sys/module/drbd/initstate\00"
@.str.5 = [8 x i8] c"unknown\00"
@.str.6 = [55 x i8] c"Unable to open DRBD initstate file. Is DRBD running?\0A\00"
@.str.7 = [24 x i8] c"/sys/module/drbd/refcnt\00"
@.str.8 = [11 x i8] c"/proc/drbd\00"
@.str.9 = [53 x i8] c"Unable to open DRBD process file. Is DRBD running?\0A\00"
@.str.10 = [6 x i8] c"clear\00"
@.str.11 = [50 x i8] c"DRBD %s status on %s, updated every %d second[s]\0A\00"
@.str.12 = [32 x i8] c"Init state: %s, Ref count: %s\0A\0A\00"
@.str.13 = [135 x i8] c"\0APress [f] to speed up, [s] to slow down, [d] to toggle details, [q] or Ctrl-C to quit.\0AHold any other key for near real-time update.\0A\00"
@.str.14 = [9 x i8] c"stty raw\00"
@.str.15 = [50 x i8] c"echo 1 > /sys/module/drbd/parameters/proc_details\00"
@.str.16 = [50 x i8] c"echo 0 > /sys/module/drbd/parameters/proc_details\00"
@.str.17 = [12 x i8] c"stty cooked\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca [15 x i8]
%2 = alloca [15 x i8]
%3 = alloca [15 x i8]
%4 = alloca [1000 x i8]
%5 = alloca %struct.stat
%6 = alloca [4096 x i8]
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 0
%10 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%13 = bitcast %struct.stat* %5 to i8*
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%15 = call i32 @gethostname(i8* %14, i32 4096)
%16 = call i32 @stat(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %struct.stat* %5)
%17 = icmp sgt i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %0
%19 = call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32* @fgets(i8* %9, i32 16, i32* %19)
%21 = icmp eq i32* %20, null
br i1 %21, label %30, label %26
22: ; preds = %0
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %18, %26
%27 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%28 = call i32* @fgets(i8* %9, i32 16, i32* %19)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %26
30: ; preds = %26, %18
%31 = call i32 @fclose(i32* %19)
%32 = call i32 @strlen(i8* %9)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [15 x i8], [15 x i8]* %1, i64 0, i64 %34
store i8 0, i8* %35
%36 = call i32 @stat(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %5)
%37 = icmp sgt i32 %36, -1
br i1 %37, label %38, label %62
38: ; preds = %30
%39 = bitcast i32* %7 to i8*
%40 = bitcast %struct.timeval* %8 to i8*
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 1
br label %43
43: ; preds = %38, %129
%44 = phi i32 [ 1, %38 ], [ %131, %129 ]
%45 = phi i32 [ 0, %38 ], [ %130, %129 ]
%46 = call i32* @fopen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32* @fgets(i8* %11, i32 16, i32* %46)
%48 = icmp eq i32* %47, null
br i1 %48, label %53, label %49
49: ; preds = %43, %49
%50 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %11)
%51 = call i32* @fgets(i8* %11, i32 16, i32* %46)
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %49
53: ; preds = %49, %43
%54 = call i32 @fclose(i32* %46)
%55 = call i32 @strlen(i8* %11)
%56 = add nsw i32 %55, -1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 %57
store i8 0, i8* %58
%59 = call i32* @fopen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%60 = call i32* @fgets(i8* %10, i32 16, i32* %59)
%61 = icmp eq i32* %60, null
br i1 %61, label %71, label %67
62: ; preds = %129, %30
%63 = call i32 @strncpy(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 7)
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.6, i64 0, i64 0))
%66 = call i32 @exit(i32 0)
unreachable
67: ; preds = %53, %67
%68 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%69 = call i32* @fgets(i8* %10, i32 16, i32* %59)
%70 = icmp eq i32* %69, null
br i1 %70, label %71, label %67
71: ; preds = %67, %53
%72 = call i32 @fclose(i32* %59)
%73 = call i32 @strlen(i8* %10)
%74 = add nsw i32 %73, -1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [15 x i8], [15 x i8]* %2, i64 0, i64 %75
store i8 0, i8* %76
%77 = icmp sgt i32 %44, 1
%78 = select i1 %77, i32 %44, i32 1
%79 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%80 = icmp eq i32* %79, null
br i1 %80, label %81, label %85
81: ; preds = %71
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.9, i64 0, i64 0))
%84 = call i32 @exit(i32 0)
unreachable
85: ; preds = %71
%86 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.11, i64 0, i64 0), i8* %9, i8* %14, i32 %78)
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %11, i8* %10)
%91 = call i32* @fgets(i8* %12, i32 1000, i32* %79)
%92 = icmp eq i32* %91, null
br i1 %92, label %97, label %93
93: ; preds = %85, %93
%94 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%95 = call i32* @fgets(i8* %12, i32 1000, i32* %79)
%96 = icmp eq i32* %95, null
br i1 %96, label %97, label %93
97: ; preds = %93, %85
%98 = call i32 @fclose(i32* %79)
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([135 x i8], [135 x i8]* @.str.13, i64 0, i64 0))
%101 = call i32 @system(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.14, i64 0, i64 0))
%102 = call i32 @FD_ZERO(i32* %7)
%103 = call i32 @FD_SET(i32 0, i32* %7)
store i32 %78, i32* %41
store i32 0, i32* %42
%104 = call i32 @select(i32 1, i32* %7, i32* null, i32* null, %struct.timeval* %8)
%105 = icmp sgt i32 %104, 0
br i1 %105, label %106, label %129
106: ; preds = %97
%107 = call i64 @FD_ISSET(i32 0, i32* %7)
%108 = icmp eq i64 %107, 0
br i1 %108, label %129, label %109
109: ; preds = %106
%110 = call signext i8 (...) @getchar()
switch i8 %110, label %124 [
i8 100, label %111
i8 102, label %117
i8 115, label %119
i8 113, label %121
i8 3, label %121
]
111: ; preds = %109
%112 = icmp eq i32 %45, 0
br i1 %112, label %113, label %115
113: ; preds = %111
%114 = call i32 @system(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.15, i64 0, i64 0))
br label %124
115: ; preds = %111
%116 = call i32 @system(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.16, i64 0, i64 0))
br label %124
117: ; preds = %109
%118 = add nsw i32 %78, -1
br label %124
119: ; preds = %109
%120 = add nuw nsw i32 %78, 1
br label %124
121: ; preds = %109, %109
%122 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0))
%123 = call i32 @exit(i32 0)
unreachable
124: ; preds = %109, %117, %119, %113, %115
%125 = phi i32 [ 1, %113 ], [ 0, %115 ], [ %45, %117 ], [ %45, %119 ], [ %45, %109 ]
%126 = phi i32 [ %78, %113 ], [ %78, %115 ], [ %118, %117 ], [ %120, %119 ], [ %78, %109 ]
%127 = load i32, i32* @stdout
%128 = call i32 @fflush(i32 %127)
br label %129
129: ; preds = %124, %106, %97
%130 = phi i32 [ %125, %124 ], [ %45, %106 ], [ %45, %97 ]
%131 = phi i32 [ %126, %124 ], [ %78, %106 ], [ %78, %97 ]
%132 = call i32 @system(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.17, i64 0, i64 0))
%133 = call i32 @stat(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %5)
%134 = icmp sgt i32 %133, -1
br i1 %134, label %43, label %62
}