#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 */

/* Variables and functions */
char *getLineFromFile(char *, char *, char *, int, int *);
int /*<<< orphan*/ printf(char *, ...);
int printDiskRW() {
  printf("\n\n-- Number of disk read and writes:\n\t\t");
  int lineLength = 0;
  char *lineFromFile =
      getLineFromFile("/proc/diskstats", "rb", " ", 1, &lineLength);
  int flag = 0;
  int k = 0;
  int wordNumber = 1;
  while (k < lineLength) {
    if (lineFromFile[k] == ' ') {
      wordNumber++;
      k++;
    }
    if (wordNumber == 9) {
      if (flag == 0) {
        printf("Disk Reads:  ");
        flag = 1;
      }
      printf("%c", lineFromFile[k]);
    }
    if (wordNumber == 13) {
      if (flag == 1) {
        printf("\n\t\tDisk Writes: ");
        flag = 2;
      }
      printf("%c", lineFromFile[k]);
    }
    k++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<printDiskRW>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
lea    0xee4(%rip),%rdi
lea    0xeed(%rip),%rsi
lea    0xef5(%rip),%rdx
mov    $0x1,%ecx
lea    -0x4(%rbp),%r8
call   1040 <getLineFromFile@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1240 <printDiskRW+0x120>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    11ac <printDiskRW+0x8c>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x9,-0x1c(%rbp)
jne    11ef <printDiskRW+0xcf>
cmpl   $0x0,-0x14(%rbp)
jne    11d5 <printDiskRW+0xb5>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xd,-0x1c(%rbp)
jne    1232 <printDiskRW+0x112>
cmpl   $0x1,-0x14(%rbp)
jne    1218 <printDiskRW+0xf8>
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x2,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1179 <printDiskRW+0x59>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printDiskRW>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
movl   $0x0,0x4(%rsp)
lea    0xed0(%rip),%rdi
lea    0xed9(%rip),%rsi
lea    0xee1(%rip),%rdx
mov    $0x1,%ebp
lea    0x4(%rsp),%r8
mov    $0x1,%ecx
call   1050 <getLineFromFile@plt>
cmpl   $0x0,0x4(%rsp)
jle    1201 <printDiskRW+0xd1>
mov    %rax,%r12
lea    0xeba(%rip),%r14
xor    %ebx,%ebx
xor    %r15d,%r15d
jmp    11c3 <printDiskRW+0x93>
mov    $0x1,%r13d
lea    0xe98(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13d,%r15d
movslq %ebx,%rax
movsbl (%r12,%rax,1),%edi
call   1030 <putchar@plt>
add    $0x1,%ebx
cmp    0x4(%rsp),%ebx
jge    1201 <printDiskRW+0xd1>
movslq %ebx,%rbx
xor    %eax,%eax
cmpb   $0x20,(%r12,%rbx,1)
sete   %al
add    %eax,%ebx
add    %eax,%ebp
cmp    $0xd,%ebp
je     11f0 <printDiskRW+0xc0>
cmp    $0x9,%ebp
jne    11ba <printDiskRW+0x8a>
test   %r15d,%r15d
jne    11ad <printDiskRW+0x7d>
jmp    1196 <printDiskRW+0x66>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2,%r13d
mov    %r14,%rdi
cmp    $0x1,%r15d
je     11a3 <printDiskRW+0x73>
jmp    11ad <printDiskRW+0x7d>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [40 x i8] c"\0A\0A-- Number of disk read and writes:\0A\09\09\00"
@.str.1 = [16 x i8] c"/proc/diskstats\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [14 x i8] c"Disk Reads: \00"
@.str.5 = [3 x i8] c"%c\00"
@.str.6 = [17 x i8] c"\0A\09\09Disk Writes: \00"
define i32 @printDiskRW() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
%7 = call i8* @getLineFromFile(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32* %1)
store i8* %7, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 1, i32* %5
br label %8
8: ; preds = %57, %0
%9 = load i32, i32* %4
%10 = load i32, i32* %1
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %60
12: ; preds = %8
%13 = load i8*, i8** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 32
br i1 %19, label %20, label %25
20: ; preds = %12
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %25
25: ; preds = %20, %12
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 9
br i1 %27, label %28, label %41
28: ; preds = %25
%29 = load i32, i32* %3
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %33
33: ; preds = %31, %28
%34 = load i8*, i8** %2
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = sext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %33, %25
%42 = load i32, i32* %5
%43 = icmp eq i32 %42, 13
br i1 %43, label %44, label %57
44: ; preds = %41
%45 = load i32, i32* %3
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %49
47: ; preds = %44
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %3
br label %49
49: ; preds = %47, %44
%50 = load i8*, i8** %2
%51 = load i32, i32* %4
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %55)
br label %57
57: ; preds = %49, %41
%58 = load i32, i32* %4
%59 = add nsw i32 %58, 1
store i32 %59, i32* %4
br label %8
60: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@.str = [40 x i8] c"\0A\0A-- Number of disk read and writes:\0A\09\09\00"
@.str.1 = [16 x i8] c"/proc/diskstats\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [14 x i8] c"Disk Reads: \00"
@.str.6 = [17 x i8] c"\0A\09\09Disk Writes: \00"
define i32 @printDiskRW() {
%1 = alloca i32
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = call i8* @getLineFromFile(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 1, i32* %1)
%5 = load i32, i32* %1
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %38
7: ; preds = %0, %33
%8 = phi i32 [ %17, %33 ], [ 1, %0 ]
%9 = phi i32 [ %35, %33 ], [ 0, %0 ]
%10 = phi i32 [ %34, %33 ], [ 0, %0 ]
%11 = sext i32 %9 to i64
%12 = getelementptr inbounds i8, i8* %4, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 32
%15 = zext i1 %14 to i32
%16 = add nsw i32 %9, %15
%17 = add nuw nsw i32 %8, %15
switch i32 %17, label %33 [
i32 9, label %18
i32 13, label %20
]
18: ; preds = %7
%19 = icmp eq i32 %10, 0
br i1 %19, label %22, label %26
20: ; preds = %7
%21 = icmp eq i32 %10, 1
br i1 %21, label %22, label %26
22: ; preds = %20, %18
%23 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %18 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), %20 ]
%24 = phi i32 [ 1, %18 ], [ 2, %20 ]
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %23)
br label %26
26: ; preds = %22, %20, %18
%27 = phi i32 [ %10, %18 ], [ %10, %20 ], [ %24, %22 ]
%28 = sext i32 %16 to i64
%29 = getelementptr inbounds i8, i8* %4, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = call i32 @putchar(i32 %31)
br label %33
33: ; preds = %26, %7
%34 = phi i32 [ %10, %7 ], [ %27, %26 ]
%35 = add nsw i32 %16, 1
%36 = load i32, i32* %1
%37 = icmp slt i32 %35, %36
br i1 %37, label %7, label %38
38: ; preds = %33, %0
ret i32 0
}