#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*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, char *, char *, char *, char *,
           char *, char *, char *, char *, char *, char *, int *);
int /*<<< orphan*/ perror(char *);
int get_page_fault_num() {
  FILE *f = fopen("/proc/self/stat", "r");
  char s[11][256];
  int pg;
  int ret = fscanf(f, "%s %s %s %s %s %s %s %s %s %s %s %d", s[0], s[1], s[2],
                   s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], &pg);
  if (ret != 12) {
    perror("get_page_fault_num");
    pg = -1;
  }
  return pg;
}


x86 assembly (clang, -O0):
<get_page_fault_num>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb58,%rsp
lea    0xeb5(%rip),%rdi
lea    0xebe(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0xb30(%rbp),%rdx
lea    -0xb30(%rbp),%rcx
add    $0x100,%rcx
lea    -0xb30(%rbp),%r8
add    $0x200,%r8
lea    -0xb30(%rbp),%r9
add    $0x300,%r9
lea    -0xb30(%rbp),%r13
add    $0x400,%r13
lea    -0xb30(%rbp),%r12
add    $0x500,%r12
lea    -0xb30(%rbp),%r15
add    $0x600,%r15
lea    -0xb30(%rbp),%r14
add    $0x700,%r14
lea    -0xb30(%rbp),%rbx
add    $0x800,%rbx
lea    -0xb30(%rbp),%r11
add    $0x900,%r11
lea    -0xb30(%rbp),%r10
add    $0xa00,%r10
lea    0xe19(%rip),%rsi
lea    -0xb34(%rbp),%rax
mov    %r13,(%rsp)
mov    %r12,0x8(%rsp)
mov    %r15,0x10(%rsp)
mov    %r14,0x18(%rsp)
mov    %rbx,0x20(%rsp)
mov    %r11,0x28(%rsp)
mov    %r10,0x30(%rsp)
mov    %rax,0x38(%rsp)
call   1030 <fscanf@plt>
mov    %eax,-0xb38(%rbp)
cmpl   $0xc,-0xb38(%rbp)
je     1255 <get_page_fault_num+0x125>
lea    0xdf0(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0xb34(%rbp)
ff ff ff
mov    -0xb34(%rbp),%eax
add    $0xb58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_page_fault_num>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xb18,%rsp
lea    0xeb8(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1040 <fopen@plt>
lea    0x110(%rsp),%rcx
lea    0x210(%rsp),%r8
lea    0x310(%rsp),%r9
lea    0x410(%rsp),%r10
lea    0x510(%rsp),%r11
lea    0x610(%rsp),%r14
lea    0x710(%rsp),%r15
lea    0x810(%rsp),%r12
lea    0x910(%rsp),%r13
lea    0xa10(%rsp),%rbx
lea    0xc(%rsp),%rbp
lea    0xe62(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
push   %rbp
push   %rbx
push   %r13
push   %r12
push   %r15
push   %r14
push   %r11
push   %r10
call   1030 <fscanf@plt>
add    $0x40,%rsp
cmp    $0xc,%eax
jne    11ea <get_page_fault_num+0xba>
mov    0xc(%rsp),%eax
add    $0xb18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe45(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%eax
jmp    11d8 <get_page_fault_num+0xa8>

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/self/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"%s %s %s %s %s %s %s %s %s %s %s %d\00"
@.str.3 = [19 x i8] c"get_page_fault_num\00"
define i32 @get_page_fault_num() {
%1 = alloca i32*
%2 = alloca [11 x [256 x i8]]
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %1
%6 = load i32*, i32** %1
%7 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%9 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 1
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%11 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 2
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%13 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 3
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%15 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 4
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %15, i64 0, i64 0
%17 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 5
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %17, i64 0, i64 0
%19 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 6
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 0
%21 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 7
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %21, i64 0, i64 0
%23 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 8
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %23, i64 0, i64 0
%25 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 9
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %25, i64 0, i64 0
%27 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %2, i64 0, i64 10
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %27, i64 0, i64 0
%29 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %8, i8* %10, i8* %12, i8* %14, i8* %16, i8* %18, i8* %20, i8* %22, i8* %24, i8* %26, i8* %28, i32* %3)
store i32 %29, i32* %4
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 12
br i1 %31, label %32, label %34
32: ; preds = %0
%33 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %34
34: ; preds = %32, %0
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/self/stat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [36 x i8] c"%s %s %s %s %s %s %s %s %s %s %s %d\00"
@.str.3 = [19 x i8] c"get_page_fault_num\00"
define i32 @get_page_fault_num() {
%1 = alloca [11 x [256 x i8]]
%2 = alloca i32
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 1, i64 0
%7 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 2, i64 0
%8 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 3, i64 0
%9 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 4, i64 0
%10 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 5, i64 0
%11 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 6, i64 0
%12 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 7, i64 0
%13 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 8, i64 0
%14 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 9, i64 0
%15 = getelementptr inbounds [11 x [256 x i8]], [11 x [256 x i8]]* %1, i64 0, i64 10, i64 0
%16 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %4, i8* %6, i8* %7, i8* %8, i8* %9, i8* %10, i8* %11, i8* %12, i8* %13, i8* %14, i8* %15, i32* %2)
%17 = icmp eq i32 %16, 12
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = load i32, i32* %2
br label %22
20: ; preds = %0
%21 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %22
22: ; preds = %18, %20
%23 = phi i32 [ %19, %18 ], [ -1, %20 ]
ret i32 %23
}