#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 stat {
  int st_mtime;
};
typedef int /*<<< orphan*/ WINDOW;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int KEY_DOWN;
int KEY_NPAGE;
int KEY_PPAGE;
int KEY_UP;
int /*<<< orphan*/ TRUE;
int /*<<< orphan*/ curs_set(int /*<<< orphan*/);
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgetc(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int getch();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ *initscr();
int /*<<< orphan*/ keypad(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ mvaddch(int, int, char);
int /*<<< orphan*/ noecho();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ refresh();
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ timeout(int);
int main(int argc, char *argv[]) {
  FILE *file;
  if (argc != 2 && argc != 3 || !strcmp(argv[1], "-h") ||
      !strcmp(argv[1], "--help")) {
    printf("IRC viewer.\n");
    exit(0);
  } else if (argc == 2) {
    file = fopen(argv[1], "r");
  } else if (argc == 3) {
    printf("In-files not yet implemented.\n");
    exit(0);
  }
  WINDOW *screen = initscr();
  curs_set(0);
  timeout(10);
  keypad(screen, TRUE);
  noecho();
  int rows, cols;
  getmaxyx(screen, rows, cols);
  int y, x, l, key, start = 0;
  char line[1024], end = 0;
  struct stat s;
  stat(argv[1], &s);
  int mtime = s.st_mtime;
  while (1) {
    stat(argv[1], &s);
    fseek(file, start, 0);
    for (y = 0; y < rows; y++) {
      if (fgets(line, 1024, file))
        l = strlen(line);
      else {
        l = 0;
        end = 1;
      }
      if (l && y == rows - 1)
        end = 0;
      for (x = 0; x < cols; x++)
        if (x < l)
          mvaddch(y, x, line[x]);
        else
          mvaddch(y, x, ' ');
    }
    refresh();
    key = getch();
    if (!key)
      continue;
    else if (key == 'q')
      break;
    else if (key == KEY_UP || key == KEY_PPAGE) {
      l = 1;
      for (x = start - 2;; x--) {
        if (x <= 0) {
          start = 0;
          break;
        }
        fseek(file, x, 0);
        y = (char)fgetc(file);
        if (y == '\n') {
          if (key == KEY_UP || l == rows) {
            start = x + 1;
            break;
          }
          l++;
        }
      }
    } else if (key == KEY_DOWN && !end) {
      fseek(file, start, 0);
      fgets(line, 1024, file);
      start = ftell(file);
    } else if (key == KEY_NPAGE && !end) {
      l = start;
      for (x = 0; x < rows; x++) {
        fseek(file, l, 0);
        for (y = 0; y < rows; y++) {
          if (y == 1)
            l = ftell(file);
          if (!fgets(line, 1024, file)) {
            y = 0;
            break;
          }
        }
        if (!y)
          break;
        start = l;
      }
    } else if (mtime != s.st_mtime) {
      mtime = s.st_mtime;
      l = start;
      for (x = 0;; x++) {
        fseek(file, l, 0);
        for (y = 0; y < rows; y++) {
          if (y == 1)
            l = ftell(file);
          if (!fgets(line, 1024, file)) {
            y = 0;
            break;
          }
        }
        if (!y)
          break;
        start = l;
      }
    }
  }
  endwin();
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     126d <main+0x2d>
cmpl   $0x3,-0x8(%rbp)
jne    12a7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd84(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
je     12a7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd6a(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%eax
jne    12ba <main+0x7a>
lea    0xd5c(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    12e1 <main+0xa1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd44(%rip),%rsi
call   1120 <fopen@plt>
mov    %rax,-0x18(%rbp)
jmp    1303 <main+0xc3>
cmpl   $0x3,-0x8(%rbp)
jne    12fe <main+0xbe>
lea    0xd27(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
jmp    1303 <main+0xc3>
jmp    1308 <main+0xc8>
mov    $0x0,%al
call   1060 <initscr@plt>
mov    %rax,-0x20(%rbp)
xor    %edi,%edi
call   1160 <curs_set@plt>
mov    $0xa,%edi
call   1070 <timeout@plt>
mov    -0x20(%rbp),%rdi
mov    0x2ca1(%rip),%rax
mov    (%rax),%esi
call   1050 <keypad@plt>
mov    $0x0,%al
call   1130 <noecho@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   10a0 <getmaxyx@plt>
movl   $0x0,-0x3c(%rbp)
movb   $0x0,-0x441(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x448(%rbp),%rsi
call   10d0 <stat@plt>
mov    -0x448(%rbp),%eax
mov    %eax,-0x44c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x448(%rbp),%rsi
call   10d0 <stat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x3c(%rbp),%esi
xor    %edx,%edx
call   10e0 <fseek@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1483 <main+0x243>
lea    -0x440(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     13e2 <main+0x1a2>
lea    -0x440(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
jmp    13f0 <main+0x1b0>
movl   $0x0,-0x34(%rbp)
movb   $0x1,-0x441(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     1412 <main+0x1d2>
mov    -0x2c(%rbp),%eax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1412 <main+0x1d2>
movb   $0x0,-0x441(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1470 <main+0x230>
mov    -0x30(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    144d <main+0x20d>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
movslq -0x30(%rbp),%rax
movsbl -0x440(%rbp,%rax,1),%edx
ff
call   1140 <mvaddch@plt>
jmp    145d <main+0x21d>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
mov    $0x20,%edx
call   1140 <mvaddch@plt>
jmp    1462 <main+0x222>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1419 <main+0x1d9>
jmp    1475 <main+0x235>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    13a3 <main+0x163>
mov    $0x0,%al
call   10f0 <refresh@plt>
mov    $0x0,%al
call   1100 <getch@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jne    14a3 <main+0x263>
jmp    137a <main+0x13a>
cmpl   $0x71,-0x38(%rbp)
jne    14b2 <main+0x272>
jmp    177e <main+0x53e>
mov    -0x38(%rbp),%eax
mov    0x2b1c(%rip),%rcx
cmp    (%rcx),%eax
je     14d6 <main+0x296>
mov    -0x38(%rbp),%eax
mov    0x2b2a(%rip),%rcx
cmp    (%rcx),%eax
jne    1570 <main+0x330>
movl   $0x1,-0x34(%rbp)
mov    -0x3c(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jg     14fc <main+0x2bc>
movl   $0x0,-0x3c(%rbp)
jmp    156b <main+0x32b>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%esi
xor    %edx,%edx
call   10e0 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1080 <fgetc@plt>
movsbl %al,%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jne    1558 <main+0x318>
mov    -0x38(%rbp),%eax
mov    0x2aab(%rip),%rcx
cmp    (%rcx),%eax
je     1541 <main+0x301>
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    154f <main+0x30f>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    156b <main+0x32b>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    155d <main+0x31d>
mov    -0x30(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x30(%rbp)
jmp    14e6 <main+0x2a6>
jmp    176f <main+0x52f>
mov    -0x38(%rbp),%eax
mov    0x2a66(%rip),%rcx
cmp    (%rcx),%eax
jne    15c3 <main+0x383>
cmpb   $0x0,-0x441(%rbp)
jne    15c3 <main+0x383>
mov    -0x18(%rbp),%rdi
mov    -0x3c(%rbp),%esi
xor    %edx,%edx
call   10e0 <fseek@plt>
lea    -0x440(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %eax,-0x3c(%rbp)
jmp    176a <main+0x52a>
mov    -0x38(%rbp),%eax
mov    0x29fb(%rip),%rcx
cmp    (%rcx),%eax
jne    1698 <main+0x458>
cmpb   $0x0,-0x441(%rbp)
jne    1698 <main+0x458>
mov    -0x3c(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1693 <main+0x453>
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%esi
xor    %edx,%edx
call   10e0 <fseek@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1670 <main+0x430>
cmpl   $0x1,-0x2c(%rbp)
jne    1632 <main+0x3f2>
mov    -0x18(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %eax,-0x34(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
jne    165d <main+0x41d>
movl   $0x0,-0x2c(%rbp)
jmp    1670 <main+0x430>
jmp    1662 <main+0x422>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1610 <main+0x3d0>
cmpl   $0x0,-0x2c(%rbp)
jne    167f <main+0x43f>
jmp    1693 <main+0x453>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    15ef <main+0x3af>
jmp    1765 <main+0x525>
mov    -0x44c(%rbp),%eax
cmp    -0x448(%rbp),%eax
je     1760 <main+0x520>
mov    -0x448(%rbp),%eax
mov    %eax,-0x44c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x34(%rbp),%esi
xor    %edx,%edx
call   10e0 <fseek@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1738 <main+0x4f8>
cmpl   $0x1,-0x2c(%rbp)
jne    16fa <main+0x4ba>
mov    -0x18(%rbp),%rdi
call   10c0 <ftell@plt>
mov    %eax,-0x34(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
jne    1725 <main+0x4e5>
movl   $0x0,-0x2c(%rbp)
jmp    1738 <main+0x4f8>
jmp    172a <main+0x4ea>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    16d8 <main+0x498>
cmpl   $0x0,-0x2c(%rbp)
jne    1747 <main+0x507>
jmp    175b <main+0x51b>
mov    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    16c3 <main+0x483>
jmp    1760 <main+0x520>
jmp    1765 <main+0x525>
jmp    176a <main+0x52a>
jmp    176f <main+0x52f>
jmp    1774 <main+0x534>
jmp    1779 <main+0x539>
jmp    137a <main+0x13a>
mov    $0x0,%al
call   1110 <endwin@plt>
xor    %edi,%edi
call   1150 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edi,%eax
and    $0xfffffffe,%eax
cmp    $0x2,%eax
jne    126a <main+0x4a>
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x8(%rsi),%rbp
lea    0xdb5(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     126a <main+0x4a>
lea    0xda5(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcmp@plt>
test   %eax,%eax
jne    127d <main+0x5d>
lea    0xd9b(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1130 <exit@plt>
cmp    $0x3,%ebx
je     1437 <main+0x217>
cmp    $0x2,%ebx
jne    129d <main+0x7d>
lea    0xd78(%rip),%rsi
mov    %rbp,%rdi
call   1110 <fopen@plt>
mov    %rax,%r13
xor    %eax,%eax
call   1050 <initscr@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1140 <curs_set@plt>
mov    $0xa,%edi
call   1060 <timeout@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1040 <keypad@plt>
xor    %eax,%eax
call   1120 <noecho@plt>
mov    %rbx,%rdi
call   1090 <getmaxyx@plt>
mov    0x8(%r14),%rdi
lea    0x8(%rsp),%r15
mov    %r15,%rsi
call   10c0 <stat@plt>
mov    0x8(%rsp),%eax
mov    %eax,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %r12d,%r12d
jmp    1339 <main+0x119>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   10d0 <fseek@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %r13,%rdx
call   1080 <fgets@plt>
mov    %r13,%rdi
call   10b0 <ftell@plt>
mov    %eax,%r12d
mov    %r12d,%ebp
mov    0x2c95(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%r14),%rdi
mov    %r15,%rsi
call   10c0 <stat@plt>
mov    %r13,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   10d0 <fseek@plt>
xor    %eax,%eax
call   10e0 <refresh@plt>
xor    %eax,%eax
call   10f0 <getch@plt>
test   %eax,%eax
je     1350 <main+0x130>
mov    %eax,%ebx
cmp    $0x71,%eax
je     1429 <main+0x209>
cmp    (%r12),%ebx
je     13d0 <main+0x1b0>
mov    0x2c66(%rip),%rax
cmp    (%rax),%ebx
je     13d0 <main+0x1b0>
mov    0x2c43(%rip),%rax
cmp    (%rax),%ebx
je     1310 <main+0xf0>
mov    0x2c1c(%rip),%rax
cmp    (%rax),%ebx
je     1350 <main+0x130>
mov    0x8(%rsp),%ebx
cmp    %ebx,0xc(%rsp)
je     1350 <main+0x130>
mov    %r13,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   10d0 <fseek@plt>
mov    %ebx,0xc(%rsp)
jmp    1350 <main+0x130>
nopl   0x0(%rax)
mov    $0x0,%r12d
cmp    $0x3,%ebp
jl     1339 <main+0x119>
add    $0xffffffff,%ebp
mov    %ebp,%r12d
jmp    13fc <main+0x1dc>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%r12d
cmp    $0x2,%ebp
jl     1300 <main+0xe0>
lea    -0x1(%r12),%ebp
mov    %r13,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   10d0 <fseek@plt>
mov    %r13,%rdi
call   1070 <fgetc@plt>
cmp    $0xa,%al
jne    13f0 <main+0x1d0>
mov    0x2bb8(%rip),%rax
cmp    (%rax),%ebx
jne    13f0 <main+0x1d0>
jmp    1339 <main+0x119>
xor    %eax,%eax
call   1100 <endwin@plt>
xor    %edi,%edi
call   1130 <exit@plt>
lea    0xbda(%rip),%rdi
jmp    1271 <main+0x51>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [13 x i8] c"IRC viewer.\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [31 x i8] c"In-files not yet implemented.\0A\00"
@TRUE = global i32 0
@KEY_UP = global i32 0
@KEY_PPAGE = global i32 0
@KEY_DOWN = global i32 0
@KEY_NPAGE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [1024 x i8]
%16 = alloca i8
%17 = alloca %struct.stat
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 2
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 3
br i1 %23, label %36, label %24
24: ; preds = %21, %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @strcmp(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %24
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strcmp(i8* %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %30, %24, %21
%37 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @exit(i32 0)
unreachable
39: ; preds = %30
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 2
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %46, i32** %6
br label %54
47: ; preds = %39
%48 = load i32, i32* %4
%49 = icmp eq i32 %48, 3
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @exit(i32 0)
unreachable
53: ; preds = %47
br label %54
54: ; preds = %53, %42
br label %55
55: ; preds = %54
%56 = call i32* (...) @initscr()
store i32* %56, i32** %7
%57 = call i32 @curs_set(i32 0)
%58 = call i32 @timeout(i32 10)
%59 = load i32*, i32** %7
%60 = load i32, i32* @TRUE
%61 = call i32 @keypad(i32* %59, i32 %60)
%62 = call i32 (...) @noecho()
%63 = load i32*, i32** %7
%64 = load i32, i32* %8
%65 = load i32, i32* %9
%66 = call i32 @getmaxyx(i32* %63, i32 %64, i32 %65)
store i32 0, i32* %14
store i8 0, i8* %16
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = call i32 @stat(i8* %69, %struct.stat* %17)
%71 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 0
%72 = load i32, i32* %71
store i32 %72, i32* %18
br label %73
73: ; preds = %55, %137, %297
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = call i32 @stat(i8* %76, %struct.stat* %17)
%78 = load i32*, i32** %6
%79 = load i32, i32* %14
%80 = call i32 @fseek(i32* %78, i32 %79, i32 0)
store i32 0, i32* %10
br label %81
81: ; preds = %129, %73
%82 = load i32, i32* %10
%83 = load i32, i32* %8
%84 = icmp slt i32 %82, %83
br i1 %84, label %85, label %132
85: ; preds = %81
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%87 = load i32*, i32** %6
%88 = call i64 @fgets(i8* %86, i32 1024, i32* %87)
%89 = icmp ne i64 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %85
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%92 = call i32 @strlen(i8* %91)
store i32 %92, i32* %12
br label %94
93: ; preds = %85
store i32 0, i32* %12
store i8 1, i8* %16
br label %94
94: ; preds = %93, %90
%95 = load i32, i32* %12
%96 = icmp ne i32 %95, 0
br i1 %96, label %97, label %103
97: ; preds = %94
%98 = load i32, i32* %10
%99 = load i32, i32* %8
%100 = sub nsw i32 %99, 1
%101 = icmp eq i32 %98, %100
br i1 %101, label %102, label %103
102: ; preds = %97
store i8 0, i8* %16
br label %103
103: ; preds = %102, %97, %94
store i32 0, i32* %11
br label %104
104: ; preds = %125, %103
%105 = load i32, i32* %11
%106 = load i32, i32* %9
%107 = icmp slt i32 %105, %106
br i1 %107, label %108, label %128
108: ; preds = %104
%109 = load i32, i32* %11
%110 = load i32, i32* %12
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %120
112: ; preds = %108
%113 = load i32, i32* %10
%114 = load i32, i32* %11
%115 = load i32, i32* %11
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 %116
%118 = load i8, i8* %117
%119 = call i32 @mvaddch(i32 %113, i32 %114, i8 signext %118)
br label %124
120: ; preds = %108
%121 = load i32, i32* %10
%122 = load i32, i32* %11
%123 = call i32 @mvaddch(i32 %121, i32 %122, i8 signext 32)
br label %124
124: ; preds = %120, %112
br label %125
125: ; preds = %124
%126 = load i32, i32* %11
%127 = add nsw i32 %126, 1
store i32 %127, i32* %11
br label %104
128: ; preds = %104
br label %129
129: ; preds = %128
%130 = load i32, i32* %10
%131 = add nsw i32 %130, 1
store i32 %131, i32* %10
br label %81
132: ; preds = %81
%133 = call i32 (...) @refresh()
%134 = call i32 (...) @getch()
store i32 %134, i32* %13
%135 = load i32, i32* %13
%136 = icmp ne i32 %135, 0
br i1 %136, label %138, label %137
137: ; preds = %132
br label %73
138: ; preds = %132
%139 = load i32, i32* %13
%140 = icmp eq i32 %139, 113
br i1 %140, label %141, label %142
141: ; preds = %138
br label %298
142: ; preds = %138
%143 = load i32, i32* %13
%144 = load i32, i32* @KEY_UP
%145 = icmp eq i32 %143, %144
br i1 %145, label %150, label %146
146: ; preds = %142
%147 = load i32, i32* %13
%148 = load i32, i32* @KEY_PPAGE
%149 = icmp eq i32 %147, %148
br i1 %149, label %150, label %186
150: ; preds = %146, %142
store i32 1, i32* %12
%151 = load i32, i32* %14
%152 = sub nsw i32 %151, 2
store i32 %152, i32* %11
br label %153
153: ; preds = %182, %150
%154 = load i32, i32* %11
%155 = icmp sle i32 %154, 0
br i1 %155, label %156, label %157
156: ; preds = %153
store i32 0, i32* %14
br label %185
157: ; preds = %153
%158 = load i32*, i32** %6
%159 = load i32, i32* %11
%160 = call i32 @fseek(i32* %158, i32 %159, i32 0)
%161 = load i32*, i32** %6
%162 = call i64 @fgetc(i32* %161)
%163 = trunc i64 %162 to i8
%164 = sext i8 %163 to i32
store i32 %164, i32* %10
%165 = load i32, i32* %10
%166 = icmp eq i32 %165, 10
br i1 %166, label %167, label %181
167: ; preds = %157
%168 = load i32, i32* %13
%169 = load i32, i32* @KEY_UP
%170 = icmp eq i32 %168, %169
br i1 %170, label %175, label %171
171: ; preds = %167
%172 = load i32, i32* %12
%173 = load i32, i32* %8
%174 = icmp eq i32 %172, %173
br i1 %174, label %175, label %178
175: ; preds = %171, %167
%176 = load i32, i32* %11
%177 = add nsw i32 %176, 1
store i32 %177, i32* %14
br label %185
178: ; preds = %171
%179 = load i32, i32* %12
%180 = add nsw i32 %179, 1
store i32 %180, i32* %12
br label %181
181: ; preds = %178, %157
br label %182
182: ; preds = %181
%183 = load i32, i32* %11
%184 = add nsw i32 %183, -1
store i32 %184, i32* %11
br label %153
185: ; preds = %175, %156
br label %295
186: ; preds = %146
%187 = load i32, i32* %13
%188 = load i32, i32* @KEY_DOWN
%189 = icmp eq i32 %187, %188
br i1 %189, label %190, label %202
190: ; preds = %186
%191 = load i8, i8* %16
%192 = icmp ne i8 %191, 0
br i1 %192, label %202, label %193
193: ; preds = %190
%194 = load i32*, i32** %6
%195 = load i32, i32* %14
%196 = call i32 @fseek(i32* %194, i32 %195, i32 0)
%197 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%198 = load i32*, i32** %6
%199 = call i64 @fgets(i8* %197, i32 1024, i32* %198)
%200 = load i32*, i32** %6
%201 = call i32 @ftell(i32* %200)
store i32 %201, i32* %14
br label %294
202: ; preds = %190, %186
%203 = load i32, i32* %13
%204 = load i32, i32* @KEY_NPAGE
%205 = icmp eq i32 %203, %204
br i1 %205, label %206, label %249
206: ; preds = %202
%207 = load i8, i8* %16
%208 = icmp ne i8 %207, 0
br i1 %208, label %249, label %209
209: ; preds = %206
%210 = load i32, i32* %14
store i32 %210, i32* %12
store i32 0, i32* %11
br label %211
211: ; preds = %245, %209
%212 = load i32, i32* %11
%213 = load i32, i32* %8
%214 = icmp slt i32 %212, %213
br i1 %214, label %215, label %248
215: ; preds = %211
%216 = load i32*, i32** %6
%217 = load i32, i32* %12
%218 = call i32 @fseek(i32* %216, i32 %217, i32 0)
store i32 0, i32* %10
br label %219
219: ; preds = %236, %215
%220 = load i32, i32* %10
%221 = load i32, i32* %8
%222 = icmp slt i32 %220, %221
br i1 %222, label %223, label %239
223: ; preds = %219
%224 = load i32, i32* %10
%225 = icmp eq i32 %224, 1
br i1 %225, label %226, label %229
226: ; preds = %223
%227 = load i32*, i32** %6
%228 = call i32 @ftell(i32* %227)
store i32 %228, i32* %12
br label %229
229: ; preds = %226, %223
%230 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%231 = load i32*, i32** %6
%232 = call i64 @fgets(i8* %230, i32 1024, i32* %231)
%233 = icmp ne i64 %232, 0
br i1 %233, label %235, label %234
234: ; preds = %229
store i32 0, i32* %10
br label %239
235: ; preds = %229
br label %236
236: ; preds = %235
%237 = load i32, i32* %10
%238 = add nsw i32 %237, 1
store i32 %238, i32* %10
br label %219
239: ; preds = %234, %219
%240 = load i32, i32* %10
%241 = icmp ne i32 %240, 0
br i1 %241, label %243, label %242
242: ; preds = %239
br label %248
243: ; preds = %239
%244 = load i32, i32* %12
store i32 %244, i32* %14
br label %245
245: ; preds = %243
%246 = load i32, i32* %11
%247 = add nsw i32 %246, 1
store i32 %247, i32* %11
br label %211
248: ; preds = %242, %211
br label %293
249: ; preds = %206, %202
%250 = load i32, i32* %18
%251 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 0
%252 = load i32, i32* %251
%253 = icmp ne i32 %250, %252
br i1 %253, label %254, label %292
254: ; preds = %249
%255 = getelementptr inbounds %struct.stat, %struct.stat* %17, i32 0, i32 0
%256 = load i32, i32* %255
store i32 %256, i32* %18
%257 = load i32, i32* %14
store i32 %257, i32* %12
store i32 0, i32* %11
br label %258
258: ; preds = %288, %254
%259 = load i32*, i32** %6
%260 = load i32, i32* %12
%261 = call i32 @fseek(i32* %259, i32 %260, i32 0)
store i32 0, i32* %10
br label %262
262: ; preds = %279, %258
%263 = load i32, i32* %10
%264 = load i32, i32* %8
%265 = icmp slt i32 %263, %264
br i1 %265, label %266, label %282
266: ; preds = %262
%267 = load i32, i32* %10
%268 = icmp eq i32 %267, 1
br i1 %268, label %269, label %272
269: ; preds = %266
%270 = load i32*, i32** %6
%271 = call i32 @ftell(i32* %270)
store i32 %271, i32* %12
br label %272
272: ; preds = %269, %266
%273 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%274 = load i32*, i32** %6
%275 = call i64 @fgets(i8* %273, i32 1024, i32* %274)
%276 = icmp ne i64 %275, 0
br i1 %276, label %278, label %277
277: ; preds = %272
store i32 0, i32* %10
br label %282
278: ; preds = %272
br label %279
279: ; preds = %278
%280 = load i32, i32* %10
%281 = add nsw i32 %280, 1
store i32 %281, i32* %10
br label %262
282: ; preds = %277, %262
%283 = load i32, i32* %10
%284 = icmp ne i32 %283, 0
br i1 %284, label %286, label %285
285: ; preds = %282
br label %291
286: ; preds = %282
%287 = load i32, i32* %12
store i32 %287, i32* %14
br label %288
288: ; preds = %286
%289 = load i32, i32* %11
%290 = add nsw i32 %289, 1
store i32 %290, i32* %11
br label %258
291: ; preds = %285
br label %292
292: ; preds = %291, %249
br label %293
293: ; preds = %292, %248
br label %294
294: ; preds = %293, %193
br label %295
295: ; preds = %294, %185
br label %296
296: ; preds = %295
br label %297
297: ; preds = %296
br label %73
298: ; preds = %141
%299 = call i32 (...) @endwin()
%300 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [3 x i8] c"-h\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.3 = [2 x i8] c"r\00"
@TRUE = global i32 0
@KEY_UP = global i32 0
@KEY_PPAGE = global i32 0
@KEY_DOWN = global i32 0
@KEY_NPAGE = global i32 0
@str = [12 x i8] c"IRC viewer.\00"
@str.5 = [30 x i8] c"In-files not yet implemented.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.stat
%5 = and i32 %0, -2
%6 = icmp eq i32 %5, 2
br i1 %6, label %7, label %15
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %7
%13 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2, %12, %7
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %12
switch i32 %0, label %24 [
i32 2, label %19
i32 3, label %21
]
19: ; preds = %18
%20 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %24
21: ; preds = %18
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.5, i64 0, i64 0))
%23 = tail call i32 @exit(i32 0)
unreachable
24: ; preds = %18, %19
%25 = phi i32* [ %20, %19 ], [ undef, %18 ]
%26 = tail call i32* (...) @initscr()
%27 = tail call i32 @curs_set(i32 0)
%28 = tail call i32 @timeout(i32 10)
%29 = load i32, i32* @TRUE
%30 = tail call i32 @keypad(i32* %26, i32 %29)
%31 = tail call i32 (...) @noecho()
%32 = tail call i32 @getmaxyx(i32* %26, i32 undef, i32 undef)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%34 = bitcast %struct.stat* %4 to i8*
%35 = load i8*, i8** %8
%36 = call i32 @stat(i8* %35, %struct.stat* %4)
%37 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%38 = load i32, i32* %37
br label %39
39: ; preds = %72, %24
%40 = phi i32 [ 0, %24 ], [ %73, %72 ]
%41 = phi i32 [ %38, %24 ], [ %43, %72 ]
br label %42
42: ; preds = %39, %91
%43 = phi i32 [ %41, %39 ], [ %89, %91 ]
br label %44
44: ; preds = %87, %42
br label %45
45: ; preds = %44, %45
%46 = load i8*, i8** %8
%47 = call i32 @stat(i8* %46, %struct.stat* %4)
%48 = call i32 @fseek(i32* %25, i32 %40, i32 0)
%49 = call i32 (...) @refresh()
%50 = call i32 (...) @getch()
switch i32 %50, label %51 [
i32 0, label %45
i32 113, label %93
]
51: ; preds = %45
%52 = load i32, i32* @KEY_UP
%53 = icmp eq i32 %50, %52
%54 = load i32, i32* @KEY_PPAGE
%55 = icmp eq i32 %50, %54
%56 = select i1 %53, i1 true, i1 %55
br i1 %56, label %57, label %77
57: ; preds = %51
%58 = icmp slt i32 %40, 3
br i1 %58, label %72, label %59
59: ; preds = %57
%60 = add nsw i32 %40, -2
br label %61
61: ; preds = %59, %74
%62 = phi i32 [ %75, %74 ], [ %60, %59 ]
%63 = call i32 @fseek(i32* %25, i32 %62, i32 0)
%64 = call i64 @fgetc(i32* %25)
%65 = and i64 %64, 255
%66 = icmp eq i64 %65, 10
%67 = load i32, i32* @KEY_UP
%68 = icmp eq i32 %50, %67
%69 = select i1 %66, i1 %68, i1 false
br i1 %69, label %70, label %74
70: ; preds = %61
%71 = add nuw nsw i32 %62, 1
br label %72
72: ; preds = %74, %70, %80, %57
%73 = phi i32 [ 0, %57 ], [ %83, %80 ], [ %71, %70 ], [ 0, %74 ]
br label %39
74: ; preds = %61
%75 = add nsw i32 %62, -1
%76 = icmp slt i32 %62, 2
br i1 %76, label %72, label %61
77: ; preds = %51
%78 = load i32, i32* @KEY_DOWN
%79 = icmp eq i32 %50, %78
br i1 %79, label %80, label %84
80: ; preds = %77
%81 = call i32 @fseek(i32* %25, i32 %40, i32 0)
%82 = call i64 @fgets(i8* %33, i32 1024, i32* %25)
%83 = call i32 @ftell(i32* %25)
br label %72
84: ; preds = %77
%85 = load i32, i32* @KEY_NPAGE
%86 = icmp eq i32 %50, %85
br i1 %86, label %87, label %88
87: ; preds = %84, %88
br label %44
88: ; preds = %84
%89 = load i32, i32* %37
%90 = icmp eq i32 %43, %89
br i1 %90, label %87, label %91
91: ; preds = %88
%92 = call i32 @fseek(i32* %25, i32 %40, i32 0)
br label %42
93: ; preds = %45
%94 = call i32 (...) @endwin()
%95 = call i32 @exit(i32 0)
unreachable
}