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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ read(int, unsigned long *, int);
int test_kmem_proc_kpagecgroup(const char *root) {
  unsigned long buf[128];
  int ret = 1;
  ssize_t len;
  int fd;
  fd = open("/proc/kpagecgroup", O_RDONLY);
  if (fd < 0)
    return ret;
  do {
    len = read(fd, buf, sizeof(buf));
  } while (len > 0);
  if (len == 0)
    ret = 0;
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<test_kmem_proc_kpagecgroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x414(%rbp)
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jge    117f <test_kmem_proc_kpagecgroup+0x4f>
mov    -0x414(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11dc <test_kmem_proc_kpagecgroup+0xac>
jmp    1184 <test_kmem_proc_kpagecgroup+0x54>
mov    -0x424(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %rax,-0x420(%rbp)
cmpq   $0x0,-0x420(%rbp)
jg     1184 <test_kmem_proc_kpagecgroup+0x54>
cmpq   $0x0,-0x420(%rbp)
jne    11c8 <test_kmem_proc_kpagecgroup+0x98>
movl   $0x0,-0x414(%rbp)
mov    -0x424(%rbp),%edi
call   1030 <close@plt>
mov    -0x414(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_kmem_proc_kpagecgroup>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    0x2ea6(%rip),%rax
mov    (%rax),%esi
lea    0xeb5(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1183 <test_kmem_proc_kpagecgroup+0x53>
mov    %eax,%ebx
mov    %rsp,%r14
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   1040 <read@plt>
test   %rax,%rax
jg     1160 <test_kmem_proc_kpagecgroup+0x30>
setne  %al
movzbl %al,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
jmp    1188 <test_kmem_proc_kpagecgroup+0x58>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"/proc/kpagecgroup\00"
@O_RDONLY = global i32 0
define i32 @test_kmem_proc_kpagecgroup(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [128 x i64]
%5 = alloca i32
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %3
store i32 1, i32* %5
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i32, i32* %5
store i32 %13, i32* %2
br label %30
14: ; preds = %1
br label %15
15: ; preds = %19, %14
%16 = load i32, i32* %7
%17 = getelementptr inbounds [128 x i64], [128 x i64]* %4, i64 0, i64 0
%18 = call i64 @read(i32 %16, i64* %17, i32 1024)
store i64 %18, i64* %6
br label %19
19: ; preds = %15
%20 = load i64, i64* %6
%21 = icmp sgt i64 %20, 0
br i1 %21, label %15, label %22
22: ; preds = %19
%23 = load i64, i64* %6
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %5
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %7
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %5
store i32 %29, i32* %2
br label %30
30: ; preds = %26, %12
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@.str = [18 x i8] c"/proc/kpagecgroup\00"
@O_RDONLY = global i32 0
define i32 @test_kmem_proc_kpagecgroup(i8* nocapture readnone %0) {
%2 = alloca [128 x i64]
%3 = bitcast [128 x i64]* %2 to i8*
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %1
%8 = getelementptr inbounds [128 x i64], [128 x i64]* %2, i64 0, i64 0
br label %9
9: ; preds = %7, %9
%10 = call i64 @read(i32 %5, i64* %8, i32 1024)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %9, label %12
12: ; preds = %9
%13 = icmp ne i64 %10, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @close(i32 %5)
br label %16
16: ; preds = %1, %12
%17 = phi i32 [ %14, %12 ], [ 1, %1 ]
ret i32 %17
}