#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int sscanf(char *, char *, char *, long *);
scalar_t__ strcmp(char *, char *);
size_t dirtyPagesBytes() {
  long ret = 0;
  FILE *fp = fopen("/proc/meminfo", "rt");
  if (fp) {
    char *line = NULL;
    long temp = 0;
    size_t len = 0;
    ssize_t read = 0;
    char s[100];
    while ((read = getline(&line, &len, fp)) != -1) {
      if (sscanf(line, "%s %ld", s, &temp) == 2) {
        if (strcmp(s, "Dirty:") == 0) {
          ret = temp * 1024;
          break;
        }
      }
    }
    fclose(fp);
  }
  return ret;
}


x86 assembly (clang, -O0):
<dirtyPagesBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xe96(%rip),%rdi
lea    0xe9d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1226 <dirtyPagesBytes+0xd6>
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     121d <dirtyPagesBytes+0xcd>
mov    -0x18(%rbp),%rdi
lea    -0x90(%rbp),%rdx
lea    0xe3e(%rip),%rsi
lea    -0x20(%rbp),%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    1218 <dirtyPagesBytes+0xc8>
lea    -0x90(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1213 <dirtyPagesBytes+0xc3>
mov    -0x20(%rbp),%rax
shl    $0xa,%rax
mov    %rax,-0x8(%rbp)
jmp    121d <dirtyPagesBytes+0xcd>
jmp    1218 <dirtyPagesBytes+0xc8>
jmp    11a4 <dirtyPagesBytes+0x54>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dirtyPagesBytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
lea    0xe98(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1226 <dirtyPagesBytes+0xd6>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     121a <dirtyPagesBytes+0xca>
lea    0xe58(%rip),%r15
lea    0x20(%rsp),%r12
lea    0x18(%rsp),%r13
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%rbp
jmp    11e3 <dirtyPagesBytes+0x93>
nop
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     121a <dirtyPagesBytes+0xca>
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
call   1050 <sscanf@plt>
cmp    $0x2,%eax
jne    11d0 <dirtyPagesBytes+0x80>
mov    %r12,%rdi
lea    0xe13(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    11d0 <dirtyPagesBytes+0x80>
mov    0x18(%rsp),%rbp
shl    $0xa,%rbp
jmp    121c <dirtyPagesBytes+0xcc>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    1228 <dirtyPagesBytes+0xd8>
xor    %ebp,%ebp
mov    %rbp,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [7 x i8] c"%s %ld\00"
@.str.3 = [7 x i8] c"Dirty:\00"
define i64 @dirtyPagesBytes() {
%1 = alloca i64
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca [100 x i8]
store i64 0, i64* %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %33
11: ; preds = %0
store i8* null, i8** %3
store i64 0, i64* %4
store i64 0, i64* %5
store i32 0, i32* %6
br label %12
12: ; preds = %29, %11
%13 = load i32*, i32** %2
%14 = call i32 @getline(i8** %3, i64* %5, i32* %13)
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %30
16: ; preds = %12
%17 = load i8*, i8** %3
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%19 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %18, i64* %4)
%20 = icmp eq i32 %19, 2
br i1 %20, label %21, label %29
21: ; preds = %16
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%23 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %21
%26 = load i64, i64* %4
%27 = mul nsw i64 %26, 1024
store i64 %27, i64* %1
br label %30
28: ; preds = %21
br label %29
29: ; preds = %28, %16
br label %12
30: ; preds = %25, %12
%31 = load i32*, i32** %2
%32 = call i32 @fclose(i32* %31)
br label %33
33: ; preds = %30, %0
%34 = load i64, i64* %1
ret i64 %34
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/meminfo\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [7 x i8] c"%s %ld\00"
@.str.3 = [7 x i8] c"Dirty:\00"
define i64 @dirtyPagesBytes() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i64
%4 = alloca [100 x i8]
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %30, label %7
7: ; preds = %0
%8 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%9 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%10 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = call i32 @getline(i8** %1, i64* %3, i32* %5)
%13 = icmp eq i32 %12, -1
br i1 %13, label %27, label %14
14: ; preds = %7, %24
%15 = load i8*, i8** %1
%16 = call i32 @sscanf(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %11, i64* %2)
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i64, i64* %2
%23 = shl nsw i64 %22, 10
br label %27
24: ; preds = %18, %14
%25 = call i32 @getline(i8** %1, i64* %3, i32* %5)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %14
27: ; preds = %24, %7, %21
%28 = phi i64 [ %23, %21 ], [ 0, %7 ], [ 0, %24 ]
%29 = call i32 @fclose(i32* %5)
br label %30
30: ; preds = %27, %0
%31 = phi i64 [ %28, %27 ], [ 0, %0 ]
ret i64 %31
}