#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ endwin();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *, int *, int *);
int /*<<< orphan*/ getch();
int /*<<< orphan*/ getmaxyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ getyx(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ initscr();
int /*<<< orphan*/ move(int, int);
int /*<<< orphan*/ mvprintw(int, int, char *, ...);
int /*<<< orphan*/ noecho();
scalar_t__ realloc(int *, int);
int /*<<< orphan*/ rectangle(int, int, int, int);
int /*<<< orphan*/ scanw(char *, char *);
int /*<<< orphan*/ sort(int *, int *, int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stdscr;
int main() {
  int unit, *o = NULL, *bt = NULL, *p = NULL, i = 0, TT, T, j, n, maxx, maxy, x,
            y;
  float TAT, WT;
  char file[32];
  FILE *fp;
  initscr();
  getmaxyx(stdscr, maxy, maxx);
  rectangle(0, 0, maxy - 1, maxx - 1);
  mvprintw(maxy / 4, (maxx - 32) / 2, "Enter the filename to  be read: ");
  scanw("%s", file);
  fp = fopen(file, "r");
  if (fp == NULL) {
    mvprintw(maxy / 2, (maxx - 22) / 2, "Error opening file!!!");
    noecho();
    getch();
    endwin();
    return -1;
  }
  TT = 0;
  while (!feof(fp)) {
    i++;
    bt = (int *)realloc(bt, sizeof(int) * i);
    p = (int *)realloc(p, sizeof(int) * i);
    o = (int *)realloc(o, sizeof(int) * i);
    o[i - 1] = i;
    fscanf(fp, "%d%d%d", &j, &bt[i - 1], &p[i - 1]);
    TT += bt[i - 1];
  }
  TT -= bt[i - 1];
  fclose(fp);
  n = i - 1;
  sort(bt, p, o, 0, n);
  getyx(stdscr, y, x);
  y += 4;
  x = (maxx - 8) / 2;
  WT = T = 0;
  mvprintw(y, x, "G-Chart:");
  y += 2;
  unit = (maxx - 4) / TT;
  x = (maxx - (TT * unit)) / 2;
  move(x, y);
  mvprintw(y + 4, x, "%d", T);
  for (i = 0; i < n; i++) {
    rectangle(y, x, y + 2, x + (bt[i] * unit));
    mvprintw(y + 1, x + (bt[i] * unit / 2), "P%d", o[i]);
    T += bt[i];
    WT += T;
    mvprintw(y + 4, x + (bt[i] * unit), "%d", T);
    x += (bt[i] * unit);
  }
  mvprintw(y + 4, x, "%d", T);
  WT = (WT - T) / n;
  TAT = (float)TT / n;
  y += 8;
  mvprintw(y, (maxx - 30) / 2, "Average turn-around time: %.2f", TAT + WT);
  y += 2;
  mvprintw(y, (maxx - 30) / 2, "Average waiting time: %.2f", WT);
  noecho();
  getch();
  endwin();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1060 <initscr@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x3c(%rbp),%esi
mov    -0x38(%rbp),%edx
call   1090 <getmaxyx@plt>
mov    -0x3c(%rbp),%edx
sub    $0x1,%edx
mov    -0x38(%rbp),%ecx
sub    $0x1,%ecx
xor    %esi,%esi
mov    %esi,%edi
call   1030 <rectangle@plt>
mov    -0x3c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x38(%rbp),%eax
sub    $0x20,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xd7b(%rip),%rdx
mov    $0x0,%al
call   1110 <mvprintw@plt>
lea    -0x70(%rbp),%rsi
lea    0xd8a(%rip),%rdi
call   1100 <scanw@plt>
lea    -0x70(%rbp),%rdi
lea    0xd7d(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x78(%rbp)
cmpq   $0x0,-0x78(%rbp)
jne    1307 <main+0x107>
mov    -0x3c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
mov    -0x38(%rbp),%eax
sub    $0x16,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xd47(%rip),%rdx
mov    $0x0,%al
call   1110 <mvprintw@plt>
mov    $0x0,%al
call   10f0 <noecho@plt>
mov    $0x0,%al
call   10c0 <getch@plt>
mov    $0x0,%al
call   10d0 <endwin@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1678 <main+0x478>
movl   $0x0,-0x28(%rbp)
mov    -0x78(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    132c <main+0x12c>
jmp    13e2 <main+0x1e2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   10b0 <realloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   10b0 <realloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%esi
call   10b0 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x78(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%rcx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
shl    $0x2,%rax
add    %rax,%r8
lea    0xc7e(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1080 <fscanf@plt>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%eax
add    -0x28(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    130e <main+0x10e>
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x28(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x28(%rbp)
mov    -0x78(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x34(%rbp),%r8d
xor    %ecx,%ecx
call   1070 <sort@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%esi
mov    -0x40(%rbp),%edx
call   1050 <getyx@plt>
mov    -0x44(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%eax
sub    $0x8,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x40(%rbp)
movl   $0x0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%esi
lea    0xbd6(%rip),%rdx
mov    $0x0,%al
call   1110 <mvprintw@plt>
mov    -0x44(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%eax
sub    $0x4,%eax
cltd
idivl  -0x28(%rbp)
mov    %eax,-0x8(%rbp)
mov    -0x38(%rbp),%eax
mov    -0x28(%rbp),%ecx
imul   -0x8(%rbp),%ecx
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x44(%rbp),%esi
call   1120 <move@plt>
mov    -0x44(%rbp),%edi
add    $0x4,%edi
mov    -0x40(%rbp),%esi
mov    -0x2c(%rbp),%ecx
lea    0xb8e(%rip),%rdx
mov    $0x0,%al
call   1110 <mvprintw@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    15a8 <main+0x3a8>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%esi
mov    -0x44(%rbp),%edx
add    $0x2,%edx
mov    -0x40(%rbp),%ecx
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%r8
mov    (%rax,%r8,4),%eax
imul   -0x8(%rbp),%eax
add    %eax,%ecx
call   1030 <rectangle@plt>
mov    -0x44(%rbp),%edi
add    $0x1,%edi
mov    -0x40(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
imul   -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    %eax,%esi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
lea    0xb19(%rip),%rdx
mov    $0x0,%al
call   1110 <mvprintw@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cvtsi2ssl -0x2c(%rbp),%xmm0
addss  -0x4c(%rbp),%xmm0
movss  %xmm0,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
add    $0x4,%edi
mov    -0x40(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
imul   -0x8(%rbp),%eax
add    %eax,%esi
mov    -0x2c(%rbp),%ecx
lea    0xacf(%rip),%rdx
mov    $0x0,%al
call   1110 <mvprintw@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
imul   -0x8(%rbp),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    14cd <main+0x2cd>
mov    -0x44(%rbp),%edi
add    $0x4,%edi
mov    -0x40(%rbp),%esi
mov    -0x2c(%rbp),%ecx
lea    0xa92(%rip),%rdx
mov    $0x0,%al
call   1110 <mvprintw@plt>
movss  -0x4c(%rbp),%xmm0
cvtsi2ssl -0x2c(%rbp),%xmm1
subss  %xmm1,%xmm0
cvtsi2ssl -0x34(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x4c(%rbp)
cvtsi2ssl -0x28(%rbp),%xmm0
cvtsi2ssl -0x34(%rbp),%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x48(%rbp)
mov    -0x44(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%eax
sub    $0x1e,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
movss  -0x48(%rbp),%xmm0
addss  -0x4c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xa2e(%rip),%rdx
mov    $0x1,%al
call   1110 <mvprintw@plt>
mov    -0x44(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%edi
mov    -0x38(%rbp),%eax
sub    $0x1e,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
movss  -0x4c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xa1a(%rip),%rdx
mov    $0x1,%al
call   1110 <mvprintw@plt>
mov    $0x0,%al
call   10f0 <noecho@plt>
mov    $0x0,%al
call   10c0 <getch@plt>
mov    $0x0,%al
call   10d0 <endwin@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
xor    %eax,%eax
call   1060 <initscr@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1090 <getmaxyx@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1030 <rectangle@plt>
lea    0xdcd(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1110 <mvprintw@plt>
lea    0xddc(%rip),%rdi
lea    0x40(%rsp),%rbx
mov    %rbx,%rsi
call   1100 <scanw@plt>
lea    0xdcb(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     141d <main+0x21d>
mov    (%rsp),%rdi
call   10a0 <feof@plt>
mov    $0x1,%eax
mov    %rax,0x28(%rsp)
mov    $0x1,%r13d
xor    %r12d,%r12d
xor    %eax,%eax
mov    %rax,0x20(%rsp)
xor    %edi,%edi
xor    %r15d,%r15d
xor    %eax,%eax
mov    %rax,0x10(%rsp)
nopl   (%rax)
lea    0x4(%r12),%r14
mov    %r14d,%esi
call   10b0 <realloc@plt>
mov    %rax,%rbp
mov    %r15,%rdi
mov    %r14d,%esi
call   10b0 <realloc@plt>
mov    %rax,%rbx
mov    0x20(%rsp),%rdi
mov    %r14d,%esi
call   10b0 <realloc@plt>
mov    %rax,0x20(%rsp)
mov    %r13d,(%rax,%r12,1)
lea    (%r12,%rbp,1),%rcx
lea    (%rbx,%r12,1),%r8
mov    (%rsp),%r15
mov    %r15,%rdi
lea    0xd52(%rip),%rsi
lea    0x3c(%rsp),%rdx
call   1080 <fscanf@plt>
mov    0x10(%rsp),%rax
add    0x0(%rbp,%r12,1),%eax
mov    %rax,0x10(%rsp)
mov    %r15,%rdi
mov    %rbx,%r15
call   10a0 <feof@plt>
mov    %rbp,%rdi
addq   $0xffffffffffffffff,0x28(%rsp)
add    $0x1,%r13d
mov    %r14,%r12
test   %eax,%eax
je     12a0 <main+0xa0>
mov    0x28(%rsp),%r13
mov    %r13,%rbp
neg    %rbp
mov    %ebp,%eax
mov    0x10(%rsp),%rcx
sub    (%rdi,%rax,4),%ecx
mov    %rcx,0x10(%rsp)
mov    %rdi,%rbx
mov    (%rsp),%rdi
call   1040 <fclose@plt>
mov    %rbx,%r14
mov    %rbx,%rdi
mov    %r15,%rsi
mov    0x20(%rsp),%r15
mov    %r15,%rdx
xor    %ecx,%ecx
mov    %rbp,0x30(%rsp)
mov    %ebp,%r8d
call   1070 <sort@plt>
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
call   1050 <getyx@plt>
lea    0xcc2(%rip),%rdx
xor    %esi,%esi
xor    %eax,%eax
call   1110 <mvprintw@plt>
xor    %edi,%edi
call   1120 <move@plt>
lea    0xcb5(%rip),%rdx
xor    %esi,%esi
xor    %ecx,%ecx
xor    %eax,%eax
call   1110 <mvprintw@plt>
test   %r13d,%r13d
je     1439 <main+0x239>
neg    %r13d
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0xc90(%rip),%r12
xor    %ebx,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %esi,%esi
xor    %ecx,%ecx
call   1030 <rectangle@plt>
mov    (%r15,%rbx,4),%ecx
xor    %esi,%esi
lea    0xc66(%rip),%rdx
xor    %eax,%eax
call   1110 <mvprintw@plt>
add    (%r14,%rbx,4),%ebp
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
movaps (%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,(%rsp)
xor    %esi,%esi
mov    %r12,%rdx
mov    %ebp,%ecx
xor    %eax,%eax
call   1110 <mvprintw@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    13d0 <main+0x1d0>
jmp    1442 <main+0x242>
lea    0xc02(%rip),%rdx
xor    %edi,%edi
xor    %esi,%esi
xor    %eax,%eax
call   1110 <mvprintw@plt>
mov    $0xffffffff,%ebx
jmp    14be <main+0x2be>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
xor    %ebp,%ebp
lea    0xc04(%rip),%rdx
xor    %esi,%esi
mov    %ebp,%ecx
xor    %eax,%eax
call   1110 <mvprintw@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %ebp,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssl 0x30(%rsp),%xmm1
cvtsi2ssl 0x10(%rsp),%xmm2
movaps (%rsp),%xmm3
subss  %xmm0,%xmm3
unpcklps %xmm3,%xmm2
shufps $0x0,%xmm1,%xmm1
divps  %xmm1,%xmm2
movaps %xmm2,%xmm0
shufps $0x55,%xmm2,%xmm0
movaps %xmm0,0x10(%rsp)
addss  %xmm0,%xmm2
xorps  %xmm0,%xmm0
cvtss2sd %xmm2,%xmm0
lea    0xbb6(%rip),%rdx
xor    %esi,%esi
mov    $0x1,%al
call   1110 <mvprintw@plt>
movaps 0x10(%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xbbc(%rip),%rdx
xor    %esi,%esi
mov    $0x1,%al
call   1110 <mvprintw@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   10f0 <noecho@plt>
xor    %eax,%eax
call   10c0 <getch@plt>
xor    %eax,%eax
call   10d0 <endwin@plt>
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdscr = global i32 0
@.str = [33 x i8] c"Enter the filename to be read: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [22 x i8] c"Error opening file!!!\00"
@.str.4 = [7 x i8] c"%d%d%d\00"
@.str.5 = [9 x i8] c"G-Chart:\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [4 x i8] c"P%d\00"
@.str.8 = [31 x i8] c"Average turn-around time: %.2f\00"
@.str.9 = [27 x i8] c"Average waiting time: %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32*
%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 float
%16 = alloca float
%17 = alloca [32 x i8]
%18 = alloca i32*
store i32 0, i32* %1
store i32* null, i32** %3
store i32* null, i32** %4
store i32* null, i32** %5
store i32 0, i32* %6
%19 = call i32 (...) @initscr()
%20 = load i32, i32* @stdscr
%21 = load i32, i32* %12
%22 = load i32, i32* %11
%23 = call i32 @getmaxyx(i32 %20, i32 %21, i32 %22)
%24 = load i32, i32* %12
%25 = sub nsw i32 %24, 1
%26 = load i32, i32* %11
%27 = sub nsw i32 %26, 1
%28 = call i32 @rectangle(i32 0, i32 0, i32 %25, i32 %27)
%29 = load i32, i32* %12
%30 = sdiv i32 %29, 4
%31 = load i32, i32* %11
%32 = sub nsw i32 %31, 32
%33 = sdiv i32 %32, 2
%34 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %30, i32 %33, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%35 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%36 = call i32 @scanw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %35)
%37 = getelementptr inbounds [32 x i8], [32 x i8]* %17, i64 0, i64 0
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %38, i32** %18
%39 = load i32*, i32** %18
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %51
41: ; preds = %0
%42 = load i32, i32* %12
%43 = sdiv i32 %42, 2
%44 = load i32, i32* %11
%45 = sub nsw i32 %44, 22
%46 = sdiv i32 %45, 2
%47 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %43, i32 %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%48 = call i32 (...) @noecho()
%49 = call i32 (...) @getch()
%50 = call i32 (...) @endwin()
store i32 -1, i32* %1
br label %271
51: ; preds = %0
store i32 0, i32* %7
br label %52
52: ; preds = %57, %51
%53 = load i32*, i32** %18
%54 = call i32 @feof(i32* %53)
%55 = icmp ne i32 %54, 0
%56 = xor i1 %55, true
br i1 %56, label %57, label %107
57: ; preds = %52
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
store i32 %59, i32* %6
%60 = load i32*, i32** %4
%61 = load i32, i32* %6
%62 = sext i32 %61 to i64
%63 = mul i64 4, %62
%64 = trunc i64 %63 to i32
%65 = call i64 @realloc(i32* %60, i32 %64)
%66 = inttoptr i64 %65 to i32*
store i32* %66, i32** %4
%67 = load i32*, i32** %5
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = mul i64 4, %69
%71 = trunc i64 %70 to i32
%72 = call i64 @realloc(i32* %67, i32 %71)
%73 = inttoptr i64 %72 to i32*
store i32* %73, i32** %5
%74 = load i32*, i32** %3
%75 = load i32, i32* %6
%76 = sext i32 %75 to i64
%77 = mul i64 4, %76
%78 = trunc i64 %77 to i32
%79 = call i64 @realloc(i32* %74, i32 %78)
%80 = inttoptr i64 %79 to i32*
store i32* %80, i32** %3
%81 = load i32, i32* %6
%82 = load i32*, i32** %3
%83 = load i32, i32* %6
%84 = sub nsw i32 %83, 1
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds i32, i32* %82, i64 %85
store i32 %81, i32* %86
%87 = load i32*, i32** %18
%88 = load i32*, i32** %4
%89 = load i32, i32* %6
%90 = sub nsw i32 %89, 1
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i32, i32* %88, i64 %91
%93 = load i32*, i32** %5
%94 = load i32, i32* %6
%95 = sub nsw i32 %94, 1
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i32, i32* %93, i64 %96
%98 = call i32 @fscanf(i32* %87, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %9, i32* %92, i32* %97)
%99 = load i32*, i32** %4
%100 = load i32, i32* %6
%101 = sub nsw i32 %100, 1
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds i32, i32* %99, i64 %102
%104 = load i32, i32* %103
%105 = load i32, i32* %7
%106 = add nsw i32 %105, %104
store i32 %106, i32* %7
br label %52
107: ; preds = %52
%108 = load i32*, i32** %4
%109 = load i32, i32* %6
%110 = sub nsw i32 %109, 1
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds i32, i32* %108, i64 %111
%113 = load i32, i32* %112
%114 = load i32, i32* %7
%115 = sub nsw i32 %114, %113
store i32 %115, i32* %7
%116 = load i32*, i32** %18
%117 = call i32 @fclose(i32* %116)
%118 = load i32, i32* %6
%119 = sub nsw i32 %118, 1
store i32 %119, i32* %10
%120 = load i32*, i32** %4
%121 = load i32*, i32** %5
%122 = load i32*, i32** %3
%123 = load i32, i32* %10
%124 = call i32 @sort(i32* %120, i32* %121, i32* %122, i32 0, i32 %123)
%125 = load i32, i32* @stdscr
%126 = load i32, i32* %14
%127 = load i32, i32* %13
%128 = call i32 @getyx(i32 %125, i32 %126, i32 %127)
%129 = load i32, i32* %14
%130 = add nsw i32 %129, 4
store i32 %130, i32* %14
%131 = load i32, i32* %11
%132 = sub nsw i32 %131, 8
%133 = sdiv i32 %132, 2
store i32 %133, i32* %13
store i32 0, i32* %8
store float 0.000000e+00, float* %16
%134 = load i32, i32* %14
%135 = load i32, i32* %13
%136 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %134, i32 %135, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%137 = load i32, i32* %14
%138 = add nsw i32 %137, 2
store i32 %138, i32* %14
%139 = load i32, i32* %11
%140 = sub nsw i32 %139, 4
%141 = load i32, i32* %7
%142 = sdiv i32 %140, %141
store i32 %142, i32* %2
%143 = load i32, i32* %11
%144 = load i32, i32* %7
%145 = load i32, i32* %2
%146 = mul nsw i32 %144, %145
%147 = sub nsw i32 %143, %146
%148 = sdiv i32 %147, 2
store i32 %148, i32* %13
%149 = load i32, i32* %13
%150 = load i32, i32* %14
%151 = call i32 @move(i32 %149, i32 %150)
%152 = load i32, i32* %14
%153 = add nsw i32 %152, 4
%154 = load i32, i32* %13
%155 = load i32, i32* %8
%156 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %153, i32 %154, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %155)
store i32 0, i32* %6
br label %157
157: ; preds = %227, %107
%158 = load i32, i32* %6
%159 = load i32, i32* %10
%160 = icmp slt i32 %158, %159
br i1 %160, label %161, label %230
161: ; preds = %157
%162 = load i32, i32* %14
%163 = load i32, i32* %13
%164 = load i32, i32* %14
%165 = add nsw i32 %164, 2
%166 = load i32, i32* %13
%167 = load i32*, i32** %4
%168 = load i32, i32* %6
%169 = sext i32 %168 to i64
%170 = getelementptr inbounds i32, i32* %167, i64 %169
%171 = load i32, i32* %170
%172 = load i32, i32* %2
%173 = mul nsw i32 %171, %172
%174 = add nsw i32 %166, %173
%175 = call i32 @rectangle(i32 %162, i32 %163, i32 %165, i32 %174)
%176 = load i32, i32* %14
%177 = add nsw i32 %176, 1
%178 = load i32, i32* %13
%179 = load i32*, i32** %4
%180 = load i32, i32* %6
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds i32, i32* %179, i64 %181
%183 = load i32, i32* %182
%184 = load i32, i32* %2
%185 = mul nsw i32 %183, %184
%186 = sdiv i32 %185, 2
%187 = add nsw i32 %178, %186
%188 = load i32*, i32** %3
%189 = load i32, i32* %6
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds i32, i32* %188, i64 %190
%192 = load i32, i32* %191
%193 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %177, i32 %187, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %192)
%194 = load i32*, i32** %4
%195 = load i32, i32* %6
%196 = sext i32 %195 to i64
%197 = getelementptr inbounds i32, i32* %194, i64 %196
%198 = load i32, i32* %197
%199 = load i32, i32* %8
%200 = add nsw i32 %199, %198
store i32 %200, i32* %8
%201 = load i32, i32* %8
%202 = sitofp i32 %201 to float
%203 = load float, float* %16
%204 = fadd float %203, %202
store float %204, float* %16
%205 = load i32, i32* %14
%206 = add nsw i32 %205, 4
%207 = load i32, i32* %13
%208 = load i32*, i32** %4
%209 = load i32, i32* %6
%210 = sext i32 %209 to i64
%211 = getelementptr inbounds i32, i32* %208, i64 %210
%212 = load i32, i32* %211
%213 = load i32, i32* %2
%214 = mul nsw i32 %212, %213
%215 = add nsw i32 %207, %214
%216 = load i32, i32* %8
%217 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %206, i32 %215, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %216)
%218 = load i32*, i32** %4
%219 = load i32, i32* %6
%220 = sext i32 %219 to i64
%221 = getelementptr inbounds i32, i32* %218, i64 %220
%222 = load i32, i32* %221
%223 = load i32, i32* %2
%224 = mul nsw i32 %222, %223
%225 = load i32, i32* %13
%226 = add nsw i32 %225, %224
store i32 %226, i32* %13
br label %227
227: ; preds = %161
%228 = load i32, i32* %6
%229 = add nsw i32 %228, 1
store i32 %229, i32* %6
br label %157
230: ; preds = %157
%231 = load i32, i32* %14
%232 = add nsw i32 %231, 4
%233 = load i32, i32* %13
%234 = load i32, i32* %8
%235 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %232, i32 %233, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %234)
%236 = load float, float* %16
%237 = load i32, i32* %8
%238 = sitofp i32 %237 to float
%239 = fsub float %236, %238
%240 = load i32, i32* %10
%241 = sitofp i32 %240 to float
%242 = fdiv float %239, %241
store float %242, float* %16
%243 = load i32, i32* %7
%244 = sitofp i32 %243 to float
%245 = load i32, i32* %10
%246 = sitofp i32 %245 to float
%247 = fdiv float %244, %246
store float %247, float* %15
%248 = load i32, i32* %14
%249 = add nsw i32 %248, 8
store i32 %249, i32* %14
%250 = load i32, i32* %14
%251 = load i32, i32* %11
%252 = sub nsw i32 %251, 30
%253 = sdiv i32 %252, 2
%254 = load float, float* %15
%255 = load float, float* %16
%256 = fadd float %254, %255
%257 = fpext float %256 to double
%258 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %250, i32 %253, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), double %257)
%259 = load i32, i32* %14
%260 = add nsw i32 %259, 2
store i32 %260, i32* %14
%261 = load i32, i32* %14
%262 = load i32, i32* %11
%263 = sub nsw i32 %262, 30
%264 = sdiv i32 %263, 2
%265 = load float, float* %16
%266 = fpext float %265 to double
%267 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 %261, i32 %264, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), double %266)
%268 = call i32 (...) @noecho()
%269 = call i32 (...) @getch()
%270 = call i32 (...) @endwin()
store i32 0, i32* %1
br label %271
271: ; preds = %230, %41
%272 = load i32, i32* %1
ret i32 %272
}

LLVM IR (-O2):
@stdscr = global i32 0
@.str = [33 x i8] c"Enter the filename to be read: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [22 x i8] c"Error opening file!!!\00"
@.str.4 = [7 x i8] c"%d%d%d\00"
@.str.5 = [9 x i8] c"G-Chart:\00"
@.str.6 = [3 x i8] c"%d\00"
@.str.7 = [4 x i8] c"P%d\00"
@.str.8 = [31 x i8] c"Average turn-around time: %.2f\00"
@.str.9 = [27 x i8] c"Average waiting time: %.2f\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [32 x i8]
%3 = bitcast i32* %1 to i8*
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @initscr()
%6 = load i32, i32* @stdscr
%7 = tail call i32 @getmaxyx(i32 %6, i32 undef, i32 undef)
%8 = tail call i32 @rectangle(i32 0, i32 0, i32 undef, i32 undef)
%9 = tail call i32 (i32, i32, i8*, ...) @mvprintw(i32 0, i32 0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @scanw(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%11 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %0
%14 = call i32 @feof(i32* %11)
%15 = icmp eq i32 %14, 0
br label %18
16: ; preds = %0
%17 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 0, i32 0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %94
18: ; preds = %13, %18
%19 = phi i64 [ 0, %13 ], [ %24, %18 ]
%20 = phi i32* [ null, %13 ], [ %32, %18 ]
%21 = phi i32* [ null, %13 ], [ %28, %18 ]
%22 = phi i32 [ 0, %13 ], [ %38, %18 ]
%23 = phi i32* [ null, %13 ], [ %30, %18 ]
%24 = add nuw i64 %19, 1
%25 = trunc i64 %24 to i32
%26 = shl i32 %25, 2
%27 = call i64 @realloc(i32* %21, i32 %26)
%28 = inttoptr i64 %27 to i32*
%29 = call i64 @realloc(i32* %23, i32 %26)
%30 = inttoptr i64 %29 to i32*
%31 = call i64 @realloc(i32* %20, i32 %26)
%32 = inttoptr i64 %31 to i32*
%33 = getelementptr inbounds i32, i32* %32, i64 %19
store i32 %25, i32* %33
%34 = getelementptr inbounds i32, i32* %28, i64 %19
%35 = getelementptr inbounds i32, i32* %30, i64 %19
%36 = call i32 @fscanf(i32* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32* %1, i32* %34, i32* %35)
%37 = load i32, i32* %34
%38 = add nsw i32 %37, %22
%39 = call i32 @feof(i32* %11)
%40 = icmp eq i32 %39, 0
br i1 %40, label %18, label %41
41: ; preds = %18
%42 = inttoptr i64 %27 to i32*
%43 = inttoptr i64 %29 to i32*
%44 = inttoptr i64 %31 to i32*
%45 = trunc i64 %19 to i32
%46 = and i64 %19, 4294967295
%47 = getelementptr inbounds i32, i32* %42, i64 %46
%48 = load i32, i32* %47
%49 = sub nsw i32 %38, %48
%50 = call i32 @fclose(i32* %11)
%51 = call i32 @sort(i32* %42, i32* %43, i32* %44, i32 0, i32 %45)
%52 = load i32, i32* @stdscr
%53 = call i32 @getyx(i32 %52, i32 undef, i32 undef)
%54 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 undef, i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%55 = call i32 @move(i32 0, i32 undef)
%56 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 undef, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 0)
%57 = icmp eq i32 %45, 0
br i1 %57, label %74, label %58
58: ; preds = %41, %58
%59 = phi i64 [ %72, %58 ], [ 0, %41 ]
%60 = phi float [ %70, %58 ], [ 0.000000e+00, %41 ]
%61 = phi i32 [ %68, %58 ], [ 0, %41 ]
%62 = getelementptr inbounds i32, i32* %42, i64 %59
%63 = call i32 @rectangle(i32 undef, i32 0, i32 undef, i32 0)
%64 = getelementptr inbounds i32, i32* %44, i64 %59
%65 = load i32, i32* %64
%66 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 undef, i32 0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i32 %65)
%67 = load i32, i32* %62
%68 = add nsw i32 %67, %61
%69 = sitofp i32 %68 to float
%70 = fadd float %60, %69
%71 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 undef, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %68)
%72 = add nuw nsw i64 %59, 1
%73 = icmp eq i64 %72, %46
br i1 %73, label %74, label %58
74: ; preds = %58, %41
%75 = phi i32 [ 0, %41 ], [ %68, %58 ]
%76 = phi float [ 0.000000e+00, %41 ], [ %70, %58 ]
%77 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 undef, i32 0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %75)
%78 = sitofp i32 %75 to float
%79 = fsub float %76, %78
%80 = sitofp i32 %45 to float
%81 = sitofp i32 %49 to float
%82 = insertelement <2 x float> poison, float %81, i64 0
%83 = insertelement <2 x float> %82, float %79, i64 1
%84 = insertelement <2 x float> poison, float %80, i64 0
%85 = shufflevector <2 x float> %84, <2 x float> poison, <2 x i32> zeroinitializer
%86 = fdiv <2 x float> %83, %85
%87 = extractelement <2 x float> %86, i64 0
%88 = extractelement <2 x float> %86, i64 1
%89 = fadd float %87, %88
%90 = fpext float %89 to double
%91 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 undef, i32 0, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), double %90)
%92 = fpext float %88 to double
%93 = call i32 (i32, i32, i8*, ...) @mvprintw(i32 undef, i32 0, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), double %92)
br label %94
94: ; preds = %74, %16
%95 = phi i32 [ -1, %16 ], [ 0, %74 ]
%96 = call i32 (...) @noecho()
%97 = call i32 (...) @getch()
%98 = call i32 (...) @endwin()
ret i32 %95
}