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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, int *, int *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int cgroup_check_cpu_controller(void) {
  int dummy[2], enabled, ret = 0;
  FILE *cgroups;
  char buf[512];
  cgroups = fopen("/proc/cgroups", "re");
  if (!cgroups) {
    perror("fopen");
    goto err;
  }
  if (!fgets(buf, sizeof(buf), cgroups)) {
    perror("fgets");
    goto err;
  }
  while (!feof(cgroups)) {
    if (fscanf(cgroups, "%s %d %d %d", buf, &dummy[0], &dummy[1], &enabled) <
        4) {
      perror("fscanf");
      goto err;
    }
    if (!strcmp(buf, "cpu") && enabled == 1)
      goto done;
  }
err:
  ret = -1;
done:
  if (cgroups)
    fclose(cgroups);
  return ret;
}


x86 assembly (clang, -O0):
<cgroup_check_cpu_controller>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x10(%rbp)
lea    0xe77(%rip),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b5 <cgroup_check_cpu_controller+0x45>
lea    0xe66(%rip),%rdi
call   1090 <perror@plt>
jmp    127d <cgroup_check_cpu_controller+0x10d>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%eax
jne    11e4 <cgroup_check_cpu_controller+0x74>
lea    0xe3d(%rip),%rdi
call   1090 <perror@plt>
jmp    127d <cgroup_check_cpu_controller+0x10d>
jmp    11e9 <cgroup_check_cpu_controller+0x79>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1207 <cgroup_check_cpu_controller+0x97>
jmp    1278 <cgroup_check_cpu_controller+0x108>
mov    -0x18(%rbp),%rdi
lea    -0x220(%rbp),%rdx
lea    -0x8(%rbp),%rcx
lea    -0x8(%rbp),%r8
add    $0x4,%r8
lea    0xdf8(%rip),%rsi
lea    -0xc(%rbp),%r9
call   1040 <fscanf@plt>
cmp    $0x4,%eax
jge    1248 <cgroup_check_cpu_controller+0xd8>
lea    0xdeb(%rip),%rdi
call   1090 <perror@plt>
jmp    127d <cgroup_check_cpu_controller+0x10d>
lea    -0x220(%rbp),%rdi
lea    0xdda(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1273 <cgroup_check_cpu_controller+0x103>
cmpl   $0x1,-0xc(%rbp)
jne    1273 <cgroup_check_cpu_controller+0x103>
jmp    1284 <cgroup_check_cpu_controller+0x114>
jmp    11e9 <cgroup_check_cpu_controller+0x79>
jmp    127d <cgroup_check_cpu_controller+0x10d>
movl   $0xffffffff,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1298 <cgroup_check_cpu_controller+0x128>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgroup_check_cpu_controller>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
lea    0xe88(%rip),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11fd <cgroup_check_cpu_controller+0x9d>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x200,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %eax,%eax
je     1210 <cgroup_check_cpu_controller+0xb0>
lea    0xc(%rsp),%r15
lea    0xe6f(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rbp
lea    0x4(%rsp),%r14
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1225 <cgroup_check_cpu_controller+0xc5>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
mov    %r15,%r8
mov    %r14,%r9
call   1040 <fscanf@plt>
cmp    $0x4,%eax
jl     1219 <cgroup_check_cpu_controller+0xb9>
cmpl   $0x757063,0x10(%rsp)
jne    11c0 <cgroup_check_cpu_controller+0x60>
cmpl   $0x1,0x4(%rsp)
jne    11c0 <cgroup_check_cpu_controller+0x60>
xor    %ebp,%ebp
jmp    122a <cgroup_check_cpu_controller+0xca>
lea    0xe0d(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1232 <cgroup_check_cpu_controller+0xd2>
lea    0xe00(%rip),%rdi
jmp    1220 <cgroup_check_cpu_controller+0xc0>
lea    0xe09(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cgroups\00"
@.str.1 = [3 x i8] c"re\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [6 x i8] c"fgets\00"
@.str.4 = [12 x i8] c"%s %d %d %d\00"
@.str.5 = [7 x i8] c"fscanf\00"
@.str.6 = [4 x i8] c"cpu\00"
define i32 @cgroup_check_cpu_controller() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca [512 x i8]
store i32 0, i32* %3
%6 = 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* %6, i32** %4
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %43
11: ; preds = %0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32 @fgets(i8* %12, i32 512, i32* %13)
%15 = icmp ne i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %43
18: ; preds = %11
br label %19
19: ; preds = %41, %18
%20 = load i32*, i32** %4
%21 = call i32 @feof(i32* %20)
%22 = icmp ne i32 %21, 0
%23 = xor i1 %22, true
br i1 %23, label %24, label %42
24: ; preds = %19
%25 = load i32*, i32** %4
%26 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%29 = call i32 @fscanf(i32* %25, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %26, i32* %27, i32* %28, i32* %2)
%30 = icmp slt i32 %29, 4
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %43
33: ; preds = %24
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%35 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %33
%38 = load i32, i32* %2
%39 = icmp eq i32 %38, 1
br i1 %39, label %40, label %41
40: ; preds = %37
br label %44
41: ; preds = %37, %33
br label %19
42: ; preds = %19
br label %43
43: ; preds = %42, %31, %16, %9
store i32 -1, i32* %3
br label %44
44: ; preds = %43, %40
%45 = load i32*, i32** %4
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i32*, i32** %4
%49 = call i32 @fclose(i32* %48)
br label %50
50: ; preds = %47, %44
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cgroups\00"
@.str.1 = [3 x i8] c"re\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [6 x i8] c"fgets\00"
@.str.4 = [12 x i8] c"%s %d %d %d\00"
@.str.5 = [7 x i8] c"fscanf\00"
define i32 @cgroup_check_cpu_controller() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = alloca [512 x i8]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%7 = 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))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %36
11: ; preds = %0
%12 = call i32 @fgets(i8* %6, i32 512, i32* %7)
%13 = icmp eq i32 %12, 0
br i1 %13, label %30, label %14
14: ; preds = %11
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%17 = bitcast [512 x i8]* %3 to i32*
br label %18
18: ; preds = %14, %24
%19 = call i32 @feof(i32* %7)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %33
21: ; preds = %18
%22 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %6, i32* %15, i32* %16, i32* %2)
%23 = icmp slt i32 %22, 4
br i1 %23, label %30, label %24
24: ; preds = %21
%25 = load i32, i32* %17
%26 = icmp eq i32 %25, 7696483
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 1
%29 = select i1 %26, i1 %28, i1 false
br i1 %29, label %33, label %18
30: ; preds = %21, %11
%31 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %21 ]
%32 = call i32 @perror(i8* %31)
br label %33
33: ; preds = %24, %18, %30
%34 = phi i32 [ -1, %30 ], [ -1, %18 ], [ 0, %24 ]
%35 = call i32 @fclose(i32* %7)
br label %36
36: ; preds = %9, %33
%37 = phi i32 [ -1, %9 ], [ %34, %33 ]
ret i32 %37
}