#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*/ diskbuf;
typedef int /*<<< orphan*/ cpubuf1;
typedef int /*<<< orphan*/ count2;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ exit(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, char *, ...);
displayExtendedStats() {
  char ctxt[12];
  char ctxt1[12];
  char numcpu[3];
  char numcpu1[3];
  char cpubuf1[100];
  char diskbuf[100];
  char cpu[12];
  char cpu1[12];
  char cpu2[12];
  char cpu3[12];
  char cpu4[12];
  char cpu5[12];
  char disk[12];
  char disk1[12];
  char disk2[12];
  char disk3[12];
  char disk4[12];
  char disk5[12];
  int s;
  int u;
  int n;
  int cpus;
  int fd_cpu;
  int fd_disk;
  int fd;
  int count1;
  int count2;
  int i;
  int context, context2;
  if ((fd_cpu = open("/proc/stat", O_RDONLY)) < 0) {
    perror("Bad open of /proc/stat");
    exit(-1);
  }
  while ((count1 = read(fd_cpu, &cpubuf1[0], sizeof(cpubuf1))) > 0) {
    for (i = 0; i < (count1 - 1); i++) {
      sscanf(&cpubuf1[i], "ctxt %s ", &ctxt[0]);
      sscanf(&cpubuf1[i], "cpu  %s %s %s %s %s ", &cpu[0], &cpu1[0], &cpu2[0],
             &cpu3[0], &cpu4[0]);
      sscanf(&cpubuf1[i], "ctxt %s ", &ctxt[0]);
      sscanf(&cpubuf1[i], "processes %s %s ", &numcpu[0]);
    }
  }
  if (count1 < 0) {
    perror("Bad read");
    exit(-1);
  }
  i = 2;
  i = atoi(&cpu4[0]);
  s = atoi(&cpu3[0]);
  u = atoi(&cpu1[0]);
  n = atoi(&cpu2[0]);
  u = u + n;
  context = atoi(&ctxt[0]);
  printf("cpu usage:\n\tIdle:[%d]\n\tUser mode:[%d]\n\tKernel mode[%d]\n", i, u,
         s);
  printf("Number of processes:  [%d]\n", atoi(&numcpu[0]));
  printf("Number of contextual Switches: %d \n", context);
  if ((fd_disk = open("/proc/diskstats", O_RDONLY)) < 0) {
    perror("Bad open");
    exit(-1);
  }
  while ((count2 = read(fd_disk, &diskbuf[0], sizeof(diskbuf))) > 0) {
    for (i = 0; i < sizeof(count2); i++) {
      sscanf(&diskbuf[i], "%s %s sda %s %s %s %s", &disk[0], &disk1[0],
             &disk2[0], &disk3[0], &disk4[0], &disk5[0]);
    }
  }
  if (count2 < 0) {
    perror("Bad read");
    exit(-1);
  }
  printf("Disk stats:\n\tNumber of disk reads:%d\n", atoi(&disk2[0]));
}


x86 assembly (clang, -O0):
<displayExtendedStats>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1a4(%rbp)
cmp    $0x0,%eax
jge    11b5 <displayExtendedStats+0x45>
lea    0xe5a(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    11ba <displayExtendedStats+0x4a>
mov    -0x1a4(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x64,%edx
call   1040 <read@plt>
mov    %eax,-0x1b0(%rbp)
cmp    $0x0,%eax
jle    12c9 <displayExtendedStats+0x159>
movl   $0x0,-0x1b8(%rbp)
mov    -0x1b8(%rbp),%eax
mov    -0x1b0(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12c4 <displayExtendedStats+0x154>
movslq -0x1b8(%rbp),%rax
lea    -0x90(%rbp),%rdi
add    %rax,%rdi
lea    -0x10(%rbp),%rdx
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
movslq -0x1b8(%rbp),%rax
lea    -0x90(%rbp),%rdi
add    %rax,%rdi
lea    -0x10c(%rbp),%rdx
lea    -0x118(%rbp),%rcx
lea    -0x124(%rbp),%r8
lea    -0x130(%rbp),%r9
lea    -0x13c(%rbp),%rax
lea    0xdc1(%rip),%rsi
mov    %rax,(%rsp)
mov    $0x0,%al
call   1050 <sscanf@plt>
movslq -0x1b8(%rbp),%rax
lea    -0x90(%rbp),%rdi
add    %rax,%rdi
lea    -0x10(%rbp),%rdx
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
movslq -0x1b8(%rbp),%rax
lea    -0x90(%rbp),%rdi
add    %rax,%rdi
lea    -0x1f(%rbp),%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    11ea <displayExtendedStats+0x7a>
jmp    11ba <displayExtendedStats+0x4a>
cmpl   $0x0,-0x1b0(%rbp)
jge    12ec <displayExtendedStats+0x17c>
lea    0xd69(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movl   $0x2,-0x1b8(%rbp)
lea    -0x13c(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1b8(%rbp)
lea    -0x130(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x194(%rbp)
lea    -0x118(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x198(%rbp)
lea    -0x124(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x19c(%rbp)
mov    -0x198(%rbp),%eax
add    -0x19c(%rbp),%eax
mov    %eax,-0x198(%rbp)
lea    -0x10(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1bc(%rbp)
mov    -0x1b8(%rbp),%esi
mov    -0x198(%rbp),%edx
mov    -0x194(%rbp),%ecx
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1f(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
lea    0xcf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1bc(%rbp),%esi
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2c35(%rip),%rax
mov    (%rax),%esi
lea    0xd0b(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1a8(%rbp)
cmp    $0x0,%eax
jge    13e6 <displayExtendedStats+0x276>
lea    0xd00(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    13eb <displayExtendedStats+0x27b>
mov    -0x1a8(%rbp),%edi
lea    -0x100(%rbp),%rsi
mov    $0x64,%edx
call   1040 <read@plt>
mov    %eax,-0x1b4(%rbp)
cmp    $0x0,%eax
jle    1497 <displayExtendedStats+0x327>
movl   $0x0,-0x1b8(%rbp)
movslq -0x1b8(%rbp),%rax
cmp    $0x4,%rax
jae    1492 <displayExtendedStats+0x322>
movslq -0x1b8(%rbp),%rax
lea    -0x100(%rbp),%rdi
add    %rax,%rdi
lea    -0x154(%rbp),%rdx
lea    -0x160(%rbp),%rcx
lea    -0x16c(%rbp),%r8
lea    -0x178(%rbp),%r9
lea    -0x184(%rbp),%r10
lea    -0x190(%rbp),%rax
lea    0xc72(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1050 <sscanf@plt>
mov    -0x1b8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
jmp    141b <displayExtendedStats+0x2ab>
jmp    13eb <displayExtendedStats+0x27b>
cmpl   $0x0,-0x1b4(%rbp)
jge    14ba <displayExtendedStats+0x34a>
lea    0xb9b(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
lea    -0x16c(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%esi
lea    0xc27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<displayExtendedStats>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x178,%rsp
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     149b <displayExtendedStats+0x32b>
mov    %eax,%r14d
lea    0x110(%rsp),%rsi
mov    %eax,%edi
mov    $0x64,%edx
call   1040 <read@plt>
mov    %eax,%r12d
test   %eax,%eax
jle    12a1 <displayExtendedStats+0x131>
lea    0xe50(%rip),%rbp
lea    0x7c(%rsp),%rbx
mov    %r14d,0x8(%rsp)
jmp    1201 <displayExtendedStats+0x91>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x8(%rsp),%edi
lea    0x110(%rsp),%rsi
mov    $0x64,%edx
call   1040 <read@plt>
mov    %eax,%r12d
test   %eax,%eax
jle    12a1 <displayExtendedStats+0x131>
cmp    $0x2,%r12d
lea    0xe29(%rip),%r15
lea    0xd(%rsp),%r13
jb     11e0 <displayExtendedStats+0x70>
add    $0xffffffff,%r12d
lea    0x110(%rsp),%r14
nop
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
sub    $0x8,%rsp
mov    %r14,%rdi
lea    0xde2(%rip),%rsi
lea    0x9c(%rsp),%rdx
lea    0x78(%rsp),%rcx
lea    0x6c(%rsp),%r8
lea    0x60(%rsp),%r9
xor    %eax,%eax
mov    %rbx,%r10
mov    %rbp,%rbx
lea    0x54(%rsp),%rbp
push   %rbp
mov    %rbx,%rbp
mov    %r10,%rbx
call   1050 <sscanf@plt>
add    $0x10,%rsp
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <sscanf@plt>
add    $0x1,%r14
add    $0xffffffffffffffff,%r12
jne    1220 <displayExtendedStats+0xb0>
jmp    11e0 <displayExtendedStats+0x70>
test   %r12d,%r12d
js     1492 <displayExtendedStats+0x322>
lea    0x4c(%rsp),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
lea    0x58(%rsp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
lea    0x70(%rsp),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebx
lea    0x64(%rsp),%rdi
call   1080 <atoi@plt>
add    %eax,%ebx
lea    0x7c(%rsp),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
lea    0xd60(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xd(%rsp),%rdi
call   1080 <atoi@plt>
lea    0xd79(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xd85(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2cb9(%rip),%rax
mov    (%rax),%esi
lea    0xd8f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     14a4 <displayExtendedStats+0x334>
mov    %eax,%ebx
lea    0xa0(%rsp),%rsi
mov    %eax,%edi
mov    $0x64,%edx
call   1040 <read@plt>
test   %eax,%eax
jle    1462 <displayExtendedStats+0x2f2>
mov    %ebx,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
lea    0xa0(%rsp),%rdi
lea    0xd61(%rip),%r14
mov    %r14,%rsi
lea    0x40(%rsp),%rdx
lea    0x34(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0x28(%rsp),%r9
xor    %eax,%eax
lea    0x1c(%rsp),%rbx
push   %rbx
lea    0x90(%rsp),%r15
push   %r15
call   1050 <sscanf@plt>
add    $0x10,%rsp
lea    0xa1(%rsp),%rdi
mov    %r14,%rsi
lea    0x40(%rsp),%r12
mov    %r12,%rdx
lea    0x34(%rsp),%r13
mov    %r13,%rcx
lea    0x10(%rsp),%rbp
mov    %rbp,%r8
lea    0x28(%rsp),%rbx
mov    %rbx,%r9
xor    %eax,%eax
lea    0x1c(%rsp),%r14
push   %r14
push   %r15
call   1050 <sscanf@plt>
add    $0x10,%rsp
lea    0xa2(%rsp),%rdi
lea    0xce1(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
mov    %rbx,%r9
xor    %eax,%eax
push   %r14
push   %r15
call   1050 <sscanf@plt>
add    $0x10,%rsp
lea    0xa3(%rsp),%rdi
lea    0xcb7(%rip),%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
mov    %rbx,%r9
xor    %eax,%eax
push   %r14
push   %r15
call   1050 <sscanf@plt>
add    $0x10,%rsp
mov    0x8(%rsp),%edi
lea    0xa0(%rsp),%rsi
mov    $0x64,%edx
call   1040 <read@plt>
test   %eax,%eax
jg     1370 <displayExtendedStats+0x200>
test   %eax,%eax
js     1492 <displayExtendedStats+0x322>
lea    0x10(%rsp),%rdi
call   1080 <atoi@plt>
lea    0xc7f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x178,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xbad(%rip),%rdi
jmp    14ab <displayExtendedStats+0x33b>
lea    0xb5e(%rip),%rdi
jmp    14ab <displayExtendedStats+0x33b>
lea    0xc2c(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"/proc/stat\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Bad open of /proc/stat\00"
@.str.2 = [9 x i8] c"ctxt %s \00"
@.str.3 = [21 x i8] c"cpu %s %s %s %s %s \00"
@.str.4 = [17 x i8] c"processes %s %s \00"
@.str.5 = [9 x i8] c"Bad read\00"
@.str.6 = [56 x i8] c"cpu usage:\0A\09Idle:[%d]\0A\09User mode:[%d]\0A\09Kernel mode[%d]\0A\00"
@.str.7 = [28 x i8] c"Number of processes: [%d]\0A\00"
@.str.8 = [36 x i8] c"Number of contextual Switches: %d \0A\00"
@.str.9 = [16 x i8] c"/proc/diskstats\00"
@.str.10 = [9 x i8] c"Bad open\00"
@.str.11 = [22 x i8] c"%s %s sda %s %s %s %s\00"
@.str.12 = [38 x i8] c"Disk stats:\0A\09Number of disk reads:%d\0A\00"
define i32 @displayExtendedStats() {
%1 = alloca i32
%2 = alloca [12 x i8]
%3 = alloca [12 x i8]
%4 = alloca [3 x i8]
%5 = alloca [3 x i8]
%6 = alloca [100 x i8]
%7 = alloca [100 x i8]
%8 = alloca [12 x i8]
%9 = alloca [12 x i8]
%10 = alloca [12 x i8]
%11 = alloca [12 x i8]
%12 = alloca [12 x i8]
%13 = alloca [12 x i8]
%14 = alloca [12 x i8]
%15 = alloca [12 x i8]
%16 = alloca [12 x i8]
%17 = alloca [12 x i8]
%18 = alloca [12 x i8]
%19 = alloca [12 x i8]
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca i32
%31 = alloca i32
%32 = load i32, i32* @O_RDONLY
%33 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %32)
store i32 %33, i32* %24
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %0
%36 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %0
br label %39
39: ; preds = %78, %38
%40 = load i32, i32* %24
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 100)
store i32 %42, i32* %27
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %79
44: ; preds = %39
store i32 0, i32* %29
br label %45
45: ; preds = %75, %44
%46 = load i32, i32* %29
%47 = load i32, i32* %27
%48 = sub nsw i32 %47, 1
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %78
50: ; preds = %45
%51 = load i32, i32* %29
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %52
%54 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%55 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %53, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %54)
%56 = load i32, i32* %29
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %57
%59 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%60 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%61 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%62 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 0
%63 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%64 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %58, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %59, i8* %60, i8* %61, i8* %62, i8* %63)
%65 = load i32, i32* %29
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %66
%68 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%69 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %67, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %68)
%70 = load i32, i32* %29
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %71
%73 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%74 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %72, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %73)
br label %75
75: ; preds = %50
%76 = load i32, i32* %29
%77 = add nsw i32 %76, 1
store i32 %77, i32* %29
br label %45
78: ; preds = %45
br label %39
79: ; preds = %39
%80 = load i32, i32* %27
%81 = icmp slt i32 %80, 0
br i1 %81, label %82, label %85
82: ; preds = %79
%83 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%84 = call i32 @exit(i32 -1)
unreachable
85: ; preds = %79
store i32 2, i32* %29
%86 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%87 = call i32 @atoi(i8* %86)
store i32 %87, i32* %29
%88 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 0
%89 = call i32 @atoi(i8* %88)
store i32 %89, i32* %20
%90 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%91 = call i32 @atoi(i8* %90)
store i32 %91, i32* %21
%92 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%93 = call i32 @atoi(i8* %92)
store i32 %93, i32* %22
%94 = load i32, i32* %21
%95 = load i32, i32* %22
%96 = add nsw i32 %94, %95
store i32 %96, i32* %21
%97 = getelementptr inbounds [12 x i8], [12 x i8]* %2, i64 0, i64 0
%98 = call i32 @atoi(i8* %97)
store i32 %98, i32* %30
%99 = load i32, i32* %29
%100 = load i32, i32* %21
%101 = load i32, i32* %20
%102 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i32 %99, i32 %100, i32 %101)
%103 = getelementptr inbounds [3 x i8], [3 x i8]* %4, i64 0, i64 0
%104 = call i32 @atoi(i8* %103)
%105 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %104)
%106 = load i32, i32* %30
%107 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i32 %106)
%108 = load i32, i32* @O_RDONLY
%109 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %108)
store i32 %109, i32* %25
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %85
%112 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%113 = call i32 @exit(i32 -1)
unreachable
114: ; preds = %85
br label %115
115: ; preds = %139, %114
%116 = load i32, i32* %25
%117 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%118 = call i32 @read(i32 %116, i8* %117, i32 100)
store i32 %118, i32* %28
%119 = icmp sgt i32 %118, 0
br i1 %119, label %120, label %140
120: ; preds = %115
store i32 0, i32* %29
br label %121
121: ; preds = %136, %120
%122 = load i32, i32* %29
%123 = sext i32 %122 to i64
%124 = icmp ult i64 %123, 4
br i1 %124, label %125, label %139
125: ; preds = %121
%126 = load i32, i32* %29
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %127
%129 = getelementptr inbounds [12 x i8], [12 x i8]* %14, i64 0, i64 0
%130 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 0
%131 = getelementptr inbounds [12 x i8], [12 x i8]* %16, i64 0, i64 0
%132 = getelementptr inbounds [12 x i8], [12 x i8]* %17, i64 0, i64 0
%133 = getelementptr inbounds [12 x i8], [12 x i8]* %18, i64 0, i64 0
%134 = getelementptr inbounds [12 x i8], [12 x i8]* %19, i64 0, i64 0
%135 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %128, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %129, i8* %130, i8* %131, i8* %132, i8* %133, i8* %134)
br label %136
136: ; preds = %125
%137 = load i32, i32* %29
%138 = add nsw i32 %137, 1
store i32 %138, i32* %29
br label %121
139: ; preds = %121
br label %115
140: ; preds = %115
%141 = load i32, i32* %28
%142 = icmp slt i32 %141, 0
br i1 %142, label %143, label %146
143: ; preds = %140
%144 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%145 = call i32 @exit(i32 -1)
unreachable
146: ; preds = %140
%147 = getelementptr inbounds [12 x i8], [12 x i8]* %16, i64 0, i64 0
%148 = call i32 @atoi(i8* %147)
%149 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i32 %148)
%150 = load i32, i32* %1
ret i32 %150
}

LLVM IR (-O2):
@.str = [11 x i8] c"/proc/stat\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Bad open of /proc/stat\00"
@.str.2 = [9 x i8] c"ctxt %s \00"
@.str.3 = [21 x i8] c"cpu %s %s %s %s %s \00"
@.str.4 = [17 x i8] c"processes %s %s \00"
@.str.5 = [9 x i8] c"Bad read\00"
@.str.6 = [56 x i8] c"cpu usage:\0A\09Idle:[%d]\0A\09User mode:[%d]\0A\09Kernel mode[%d]\0A\00"
@.str.7 = [28 x i8] c"Number of processes: [%d]\0A\00"
@.str.8 = [36 x i8] c"Number of contextual Switches: %d \0A\00"
@.str.9 = [16 x i8] c"/proc/diskstats\00"
@.str.10 = [9 x i8] c"Bad open\00"
@.str.11 = [22 x i8] c"%s %s sda %s %s %s %s\00"
@.str.12 = [38 x i8] c"Disk stats:\0A\09Number of disk reads:%d\0A\00"
define i32 @displayExtendedStats() {
%1 = alloca [12 x i8]
%2 = alloca [3 x i8]
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca [12 x i8]
%6 = alloca [12 x i8]
%7 = alloca [12 x i8]
%8 = alloca [12 x i8]
%9 = alloca [12 x i8]
%10 = alloca [12 x i8]
%11 = alloca [12 x i8]
%12 = alloca [12 x i8]
%13 = alloca [12 x i8]
%14 = alloca [12 x i8]
%15 = alloca [12 x i8]
%16 = getelementptr inbounds [12 x i8], [12 x i8]* %1, i64 0, i64 0
%17 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [12 x i8], [12 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [12 x i8], [12 x i8]* %6, i64 0, i64 0
%22 = getelementptr inbounds [12 x i8], [12 x i8]* %7, i64 0, i64 0
%23 = getelementptr inbounds [12 x i8], [12 x i8]* %8, i64 0, i64 0
%24 = getelementptr inbounds [12 x i8], [12 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds [12 x i8], [12 x i8]* %10, i64 0, i64 0
%26 = getelementptr inbounds [12 x i8], [12 x i8]* %11, i64 0, i64 0
%27 = getelementptr inbounds [12 x i8], [12 x i8]* %12, i64 0, i64 0
%28 = getelementptr inbounds [12 x i8], [12 x i8]* %13, i64 0, i64 0
%29 = getelementptr inbounds [12 x i8], [12 x i8]* %14, i64 0, i64 0
%30 = getelementptr inbounds [12 x i8], [12 x i8]* %15, i64 0, i64 0
%31 = load i32, i32* @O_RDONLY
%32 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %0
%35 = call i32 @read(i32 %32, i8* %18, i32 100)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %43, label %58
37: ; preds = %0
%38 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%39 = tail call i32 @exit(i32 -1)
unreachable
40: ; preds = %49, %43
%41 = call i32 @read(i32 %32, i8* %18, i32 100)
%42 = icmp sgt i32 %41, 0
br i1 %42, label %43, label %58
43: ; preds = %34, %40
%44 = phi i32 [ %41, %40 ], [ %35, %34 ]
%45 = icmp ugt i32 %44, 1
br i1 %45, label %46, label %40
46: ; preds = %43
%47 = add nsw i32 %44, -1
%48 = zext i32 %47 to i64
br label %49
49: ; preds = %46, %49
%50 = phi i64 [ 0, %46 ], [ %56, %49 ]
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %50
%52 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %51, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%53 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %51, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %20, i8* %21, i8* %22, i8* %23, i8* %24)
%54 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %51, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %16)
%55 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %51, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i8* %17)
%56 = add nuw nsw i64 %50, 1
%57 = icmp eq i64 %56, %48
br i1 %57, label %40, label %49
58: ; preds = %40, %34
%59 = phi i32 [ %35, %34 ], [ %41, %40 ]
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %58
%65 = call i32 @atoi(i8* %24)
%66 = call i32 @atoi(i8* %23)
%67 = call i32 @atoi(i8* %21)
%68 = call i32 @atoi(i8* %22)
%69 = add nsw i32 %68, %67
%70 = call i32 @atoi(i8* %16)
%71 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.6, i64 0, i64 0), i32 %65, i32 %69, i32 %66)
%72 = call i32 @atoi(i8* %17)
%73 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i32 %72)
%74 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i32 %70)
%75 = load i32, i32* @O_RDONLY
%76 = call i32 @open(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0), i32 %75)
%77 = icmp slt i32 %76, 0
br i1 %77, label %85, label %78
78: ; preds = %64
%79 = call i32 @read(i32 %76, i8* %19, i32 100)
%80 = icmp sgt i32 %79, 0
br i1 %80, label %81, label %95
81: ; preds = %78
%82 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 1
%83 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 2
%84 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 3
br label %88
85: ; preds = %64
%86 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0))
%87 = call i32 @exit(i32 -1)
unreachable
88: ; preds = %81, %88
%89 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %25, i8* %26, i8* %27, i8* %28, i8* %29, i8* %30)
%90 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %82, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %25, i8* %26, i8* %27, i8* %28, i8* %29, i8* %30)
%91 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %83, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %25, i8* %26, i8* %27, i8* %28, i8* %29, i8* %30)
%92 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %84, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %25, i8* %26, i8* %27, i8* %28, i8* %29, i8* %30)
%93 = call i32 @read(i32 %76, i8* %19, i32 100)
%94 = icmp sgt i32 %93, 0
br i1 %94, label %88, label %95
95: ; preds = %88, %78
%96 = phi i32 [ %79, %78 ], [ %93, %88 ]
%97 = icmp slt i32 %96, 0
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%100 = call i32 @exit(i32 -1)
unreachable
101: ; preds = %95
%102 = call i32 @atoi(i8* %27)
%103 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.12, i64 0, i64 0), i32 %102)
ret i32 undef
}