#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 ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
char *memalign(int, size_t);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ sscanf(char *, char *, long *, long *, char *, long *,
                          long *, size_t *, long *, long *, long *, size_t *,
                          long *, long *, size_t *);
int /*<<< orphan*/ stderr;
void getProcDiskstats(const unsigned int major, const unsigned int minor,
                      size_t *sread, size_t *swritten, size_t *stimeIO) {
  FILE *fp = fopen("/proc/diskstats", "rt");
  if (!fp) {
    fprintf(stderr, "can't open diskstats!\n");
    return;
  }
  char *line = NULL;
  size_t len = 0;
  ssize_t read = 0;
  char *str;
  {
    str = memalign(4096, (((size_t)((1000) * (1))) / 4096 + 1) * 4096);
    if (str)
      memset(str, 0, (((size_t)((1000) * (1))) / 4096 + 1) * 4096);
    if (!(str)) {
      fprintf(stderr, "ooom!!\n");
      abort();
    }
  };
  while ((read = getline(&line, &len, fp)) != -1) {
    long mj, mn, s;
    size_t read1, write1, timespentIO;
    sscanf(line, "%ld %ld %s %ld %ld %zu %ld %ld %ld %zu %ld %ld %zu", &mj, &mn,
           str, &s, &s, &read1, &s, &s, &s, &write1, &s, &s, &timespentIO);
    if (mj == major && mn == minor) {
      *sread = read1;
      *swritten = write1;
      *stimeIO = timespentIO;
      break;
    }
  }
  free(str);
  free(line);
  fclose(fp);
}


x86 assembly (clang, -O0):
<getProcDiskstats>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0xc8,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    0xe4b(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11ea <getProcDiskstats+0x5a>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1339 <getProcDiskstats+0x1a9>
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    $0x1000,%edi
mov    $0x1000,%esi
call   1080 <memalign@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     122f <getProcDiskstats+0x9f>
mov    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1060 <memset@plt>
cmpq   $0x0,-0x50(%rbp)
jne    1256 <getProcDiskstats+0xc6>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1040 <abort@plt>
jmp    125b <getProcDiskstats+0xcb>
mov    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10b0 <getline@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
je     131e <getProcDiskstats+0x18e>
mov    -0x38(%rbp),%rdi
mov    -0x50(%rbp),%r8
lea    0xdab(%rip),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x60(%rbp),%rcx
lea    -0x68(%rbp),%r10
lea    -0x70(%rbp),%rbx
lea    -0x78(%rbp),%r11
lea    -0x80(%rbp),%rax
mov    %r10,%r9
mov    %r10,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %r10,0x18(%rsp)
mov    %r10,0x20(%rsp)
mov    %r11,0x28(%rsp)
mov    %r10,0x30(%rsp)
mov    %r10,0x38(%rsp)
mov    %rax,0x40(%rsp)
call   1090 <sscanf@plt>
mov    -0x58(%rbp),%rax
mov    -0xc(%rbp),%ecx
cmp    %rcx,%rax
jne    1319 <getProcDiskstats+0x189>
mov    -0x60(%rbp),%rax
mov    -0x10(%rbp),%ecx
cmp    %rcx,%rax
jne    1319 <getProcDiskstats+0x189>
mov    -0x70(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x78(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x80(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    131e <getProcDiskstats+0x18e>
jmp    125b <getProcDiskstats+0xcb>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
add    $0xc8,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<getProcDiskstats>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r8,%r12
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %edi,%r15d
lea    0xe4c(%rip),%rdi
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     130a <getProcDiskstats+0x17a>
mov    %rax,%r13
mov    %rbx,0x18(%rsp)
mov    %rbp,0x20(%rsp)
mov    %r12,0x28(%rsp)
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    $0x1000,%esi
mov    $0x1000,%edi
call   1080 <memalign@plt>
test   %rax,%rax
je     132d <getProcDiskstats+0x19d>
mov    %rax,%rbx
mov    $0x1000,%edx
mov    %rax,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r13,%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     12e1 <getProcDiskstats+0x151>
mov    %r15d,%r15d
mov    %r14d,%eax
mov    %rax,0x30(%rsp)
lea    0x60(%rsp),%rbp
lea    0x50(%rsp),%r12
lea    0x10(%rsp),%r14
jmp    1265 <getProcDiskstats+0xd5>
xchg   %ax,%ax
lea    0x8(%rsp),%rdi
mov    %r14,%rsi
mov    %r13,%rdx
call   10b0 <getline@plt>
cmp    $0xffffffff,%eax
je     12e1 <getProcDiskstats+0x151>
mov    0x8(%rsp),%rdi
sub    $0x8,%rsp
lea    0xdbd(%rip),%rsi
lea    0x60(%rsp),%rdx
mov    %r12,%rcx
mov    %rbx,%r8
mov    %rbp,%r9
lea    0x40(%rsp),%rax
push   %rax
push   %rbp
push   %rbp
lea    0x60(%rsp),%rax
push   %rax
push   %rbp
push   %rbp
push   %rbp
lea    0x88(%rsp),%rax
push   %rax
push   %rbp
call   1090 <sscanf@plt>
add    $0x50,%rsp
cmp    %r15,0x58(%rsp)
jne    1250 <getProcDiskstats+0xc0>
mov    0x30(%rsp),%rax
cmp    %rax,0x50(%rsp)
jne    1250 <getProcDiskstats+0xc0>
mov    0x48(%rsp),%rax
mov    0x18(%rsp),%rcx
mov    %rax,(%rcx)
mov    0x40(%rsp),%rax
mov    0x20(%rsp),%rcx
mov    %rax,(%rcx)
mov    0x38(%rsp),%rax
mov    0x28(%rsp),%rcx
mov    %rax,(%rcx)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1050 <fclose@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
lea    0xcf9(%rip),%rsi
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fprintf@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
lea    0xced(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1040 <abort@plt>

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/diskstats\00"
@.str.1 = [3 x i8] c"rt\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"can't open diskstats!\0A\00"
@.str.3 = [8 x i8] c"ooom!!\0A\00"
@.str.4 = [51 x i8] c"%ld %ld %s %ld %ld %zu %ld %ld %ld %zu %ld %ld %zu\00"
define void @getProcDiskstats(i32 %0, i32 %1, i64* %2, i64* %3, i64* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64*
%9 = alloca i64*
%10 = alloca i64*
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i64
%18 = alloca i64
%19 = alloca i64
%20 = alloca i64
%21 = alloca i64
store i32 %0, i32* %6
store i32 %1, i32* %7
store i64* %2, i64** %8
store i64* %3, i64** %9
store i64* %4, i64** %10
%22 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %11
%23 = load i32*, i32** %11
%24 = icmp ne i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %5
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %75
28: ; preds = %5
store i8* null, i8** %12
store i64 0, i64* %13
store i32 0, i32* %14
%29 = call i8* @memalign(i32 4096, i64 4096)
store i8* %29, i8** %15
%30 = load i8*, i8** %15
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i8*, i8** %15
%34 = call i32 @memset(i8* %33, i32 0, i64 4096)
br label %35
35: ; preds = %32, %28
%36 = load i8*, i8** %15
%37 = icmp ne i8* %36, null
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%41 = call i32 (...) @abort()
unreachable
42: ; preds = %35
br label %43
43: ; preds = %67, %42
%44 = load i32*, i32** %11
%45 = call i32 @getline(i8** %12, i64* %13, i32* %44)
store i32 %45, i32* %14
%46 = icmp ne i32 %45, -1
br i1 %46, label %47, label %68
47: ; preds = %43
%48 = load i8*, i8** %12
%49 = load i8*, i8** %15
%50 = call i32 @sscanf(i8* %48, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i64* %16, i64* %17, i8* %49, i64* %18, i64* %18, i64* %19, i64* %18, i64* %18, i64* %18, i64* %20, i64* %18, i64* %18, i64* %21)
%51 = load i64, i64* %16
%52 = load i32, i32* %6
%53 = zext i32 %52 to i64
%54 = icmp eq i64 %51, %53
br i1 %54, label %55, label %67
55: ; preds = %47
%56 = load i64, i64* %17
%57 = load i32, i32* %7
%58 = zext i32 %57 to i64
%59 = icmp eq i64 %56, %58
br i1 %59, label %60, label %67
60: ; preds = %55
%61 = load i64, i64* %19
%62 = load i64*, i64** %8
store i64 %61, i64* %62
%63 = load i64, i64* %20
%64 = load i64*, i64** %9
store i64 %63, i64* %64
%65 = load i64, i64* %21
%66 = load i64*, i64** %10
store i64 %65, i64* %66
br label %68
67: ; preds = %55, %47
br label %43
68: ; preds = %60, %43
%69 = load i8*, i8** %15
%70 = call i32 @free(i8* %69)
%71 = load i8*, i8** %12
%72 = call i32 @free(i8* %71)
%73 = load i32*, i32** %11
%74 = call i32 @fclose(i32* %73)
br label %75
75: ; preds = %68, %25
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/diskstats\00"
@.str.1 = [3 x i8] c"rt\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"can't open diskstats!\0A\00"
@.str.3 = [8 x i8] c"ooom!!\0A\00"
@.str.4 = [51 x i8] c"%ld %ld %s %ld %ld %zu %ld %ld %ld %zu %ld %ld %zu\00"
define void @getProcDiskstats(i32 %0, i32 %1, i64* nocapture writeonly %2, i64* nocapture writeonly %3, i64* nocapture writeonly %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i64
%14 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %5
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %61
19: ; preds = %5
%20 = bitcast i8** %6 to i8*
store i8* null, i8** %6
%21 = bitcast i64* %7 to i8*
store i64 0, i64* %7
%22 = tail call align 4096 dereferenceable_or_null(4096) i8* @memalign(i32 4096, i64 4096)
%23 = icmp eq i8* %22, null
br i1 %23, label %37, label %24
24: ; preds = %19
%25 = tail call i32 @memset(i8* %22, i32 0, i64 4096)
%26 = call i32 @getline(i8** %6, i64* %7, i32* %14)
%27 = icmp eq i32 %26, -1
br i1 %27, label %56, label %28
28: ; preds = %24
%29 = bitcast i64* %8 to i8*
%30 = bitcast i64* %9 to i8*
%31 = bitcast i64* %10 to i8*
%32 = bitcast i64* %11 to i8*
%33 = bitcast i64* %12 to i8*
%34 = bitcast i64* %13 to i8*
%35 = zext i32 %0 to i64
%36 = zext i32 %1 to i64
br label %41
37: ; preds = %19
%38 = load i32, i32* @stderr
%39 = tail call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%40 = tail call i32 (...) @abort()
unreachable
41: ; preds = %28, %53
%42 = load i8*, i8** %6
%43 = call i32 @sscanf(i8* %42, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i64* %8, i64* %9, i8* %22, i64* %10, i64* %10, i64* %11, i64* %10, i64* %10, i64* %10, i64* %12, i64* %10, i64* %10, i64* %13)
%44 = load i64, i64* %8
%45 = icmp eq i64 %44, %35
%46 = load i64, i64* %9
%47 = icmp eq i64 %46, %36
%48 = select i1 %45, i1 %47, i1 false
br i1 %48, label %49, label %53
49: ; preds = %41
%50 = load i64, i64* %11
store i64 %50, i64* %2
%51 = load i64, i64* %12
store i64 %51, i64* %3
%52 = load i64, i64* %13
store i64 %52, i64* %4
br label %56
53: ; preds = %41
%54 = call i32 @getline(i8** %6, i64* %7, i32* %14)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %41
56: ; preds = %53, %24, %49
%57 = call i32 @free(i8* %22)
%58 = load i8*, i8** %6
%59 = call i32 @free(i8* %58)
%60 = call i32 @fclose(i32* %14)
br label %61
61: ; preds = %56, %16
ret void
}