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

/* Variables and functions */
scalar_t__ EINVAL;
char EOF;
int MS_NODEV;
int MS_NOEXEC;
int MS_NOSUID;
int /*<<< orphan*/ die2(char *, char const *);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *, int *, int *, int *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
scalar_t__ mkdir(char *, int);
scalar_t__ mount(char *, char *, char *, int, char *);
void init_cgroups() {
  const char *fpath = "/proc/cgroups";
  FILE *f = fopen(fpath, "r");
  if (f == NULL) {
    die2("fopen", fpath);
  }
  for (;;) {
    char c = fgetc(f);
    if (c == EOF || c == '\n') {
      break;
    }
  }
  for (;;) {
    static const char base_path[] = "/sys/fs/cgroup/";
    char path[sizeof(base_path) - 1 + 64];
    char *name = path + sizeof(base_path) - 1;
    int hier, groups, enabled;
    int r = fscanf(f, "%64s %d %d %d\n", name, &hier, &groups, &enabled);
    if (r == EOF) {
      break;
    }
    if (r != 4) {
      errno = errno ?: EINVAL;
      die2("fscanf", fpath);
    }
    if (enabled) {
      memcpy(path, base_path, sizeof(base_path) - 1);
      if (mkdir(path, 0755) < 0) {
        die2("mkdir", path);
      }
      if (mount(name, path, "cgroup", MS_NODEV | MS_NOSUID | MS_NOEXEC, name) <
          0) {
        die2("mount", path);
      }
    }
  }
  fclose(f);
}


x86 assembly (clang, -O0):
<init_cgroups>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
lea    0xe6e(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11c5 <init_cgroups+0x45>
mov    -0x8(%rbp),%rsi
lea    0xe4e(%rip),%rdi
call   1070 <die2@plt>
jmp    11ca <init_cgroups+0x4a>
mov    -0x10(%rbp),%rdi
call   1080 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
mov    0x2df7(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     11f9 <init_cgroups+0x79>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    11fe <init_cgroups+0x7e>
jmp    1203 <init_cgroups+0x83>
jmp    11ca <init_cgroups+0x4a>
jmp    1208 <init_cgroups+0x88>
lea    -0x60(%rbp),%rax
add    $0x10,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x68(%rbp),%rdx
lea    0xded(%rip),%rsi
lea    -0x6c(%rbp),%rcx
lea    -0x70(%rbp),%r8
lea    -0x74(%rbp),%r9
call   1060 <fscanf@plt>
mov    %eax,-0x78(%rbp)
mov    -0x78(%rbp),%eax
mov    0x2d93(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1255 <init_cgroups+0xd5>
jmp    1357 <init_cgroups+0x1d7>
cmpl   $0x4,-0x78(%rbp)
je     12b9 <init_cgroups+0x139>
mov    0x2d62(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
cmp    $0x0,%rax
je     1287 <init_cgroups+0x107>
mov    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
jmp    1298 <init_cgroups+0x118>
mov    0x2d32(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rcx
mov    0x2d22(%rip),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rsi
lea    0xd6f(%rip),%rdi
call   1070 <die2@plt>
cmpl   $0x0,-0x74(%rbp)
je     1352 <init_cgroups+0x1d2>
lea    -0x60(%rbp),%rdi
lea    0xd72(%rip),%rsi
mov    $0xf,%edx
call   1090 <memcpy@plt>
lea    -0x60(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
jge    1300 <init_cgroups+0x180>
lea    -0x60(%rbp),%rsi
lea    0xd2f(%rip),%rdi
call   1070 <die2@plt>
mov    -0x68(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    0x2ce1(%rip),%rax
mov    (%rax),%ecx
mov    0x2cc8(%rip),%rax
or     (%rax),%ecx
mov    0x2c8f(%rip),%rax
or     (%rax),%ecx
mov    -0x68(%rbp),%r8
lea    0xd02(%rip),%rdx
call   1050 <mount@plt>
cmp    $0x0,%rax
jge    134d <init_cgroups+0x1cd>
lea    -0x60(%rbp),%rsi
lea    0xcef(%rip),%rdi
call   1070 <die2@plt>
jmp    1352 <init_cgroups+0x1d2>
jmp    1208 <init_cgroups+0x88>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_cgroups>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
lea    0xe6b(%rip),%rdi
lea    0xe92(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11bc <init_cgroups+0x3c>
lea    0xe5e(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1070 <die2@plt>
mov    0x2e15(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1080 <fgetc@plt>
cmp    $0xa,%al
je     11e2 <init_cgroups+0x62>
cmp    (%r12),%al
jne    11d0 <init_cgroups+0x50>
lea    0x1f(%rsp),%r14
lea    0xe26(%rip),%rsi
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %rbx,%rdi
mov    %r14,%rdx
call   1060 <fscanf@plt>
movsbl (%r12),%ecx
cmp    %ecx,%eax
jne    1228 <init_cgroups+0xa8>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x4(%rsp),%rbp
lea    0x10(%rsp),%r15
mov    0x2d8f(%rip),%r13
jmp    1268 <init_cgroups+0xe8>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
lea    0xdca(%rip),%rsi
mov    %r14,%rdx
lea    0xc(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rbp,%r9
call   1060 <fscanf@plt>
movsbl (%r12),%ecx
cmp    %ecx,%eax
je     1211 <init_cgroups+0x91>
cmp    $0x4,%eax
je     1297 <init_cgroups+0x117>
mov    0x0(%r13),%rax
test   %rax,%rax
jne    1280 <init_cgroups+0x100>
mov    0x2d43(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x0(%r13)
lea    0xd98(%rip),%rdi
lea    0xd6e(%rip),%rsi
call   1070 <die2@plt>
cmpl   $0x0,0x4(%rsp)
je     1240 <init_cgroups+0xc0>
mov    %r15,%rdi
lea    0xd98(%rip),%rsi
mov    $0xf,%edx
call   1090 <memcpy@plt>
mov    %r15,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %rax,%rax
jns    12d3 <init_cgroups+0x153>
lea    0xd5f(%rip),%rdi
mov    %r15,%rsi
call   1070 <die2@plt>
mov    0x2d06(%rip),%rax
mov    (%rax),%ecx
mov    0x2d0d(%rip),%rax
or     (%rax),%ecx
mov    0x2cc4(%rip),%rax
or     (%rax),%ecx
mov    %r14,%rdi
mov    %r15,%rsi
lea    0xd35(%rip),%rdx
mov    %r14,%r8
call   1050 <mount@plt>
test   %rax,%rax
jns    1240 <init_cgroups+0xc0>
lea    0xd24(%rip),%rdi
mov    %r15,%rsi
call   1070 <die2@plt>
jmp    1240 <init_cgroups+0xc0>

LLVM IR (-O0):
@.str = [14 x i8] c"/proc/cgroups\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@EOF = global i8 0
@init_cgroups.base_path = internal constant [16 x i8] c"/sys/fs/cgroup/\00"
@.str.3 = [15 x i8] c"%64s %d %d %d\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.4 = [7 x i8] c"fscanf\00"
@.str.5 = [6 x i8] c"mkdir\00"
@.str.6 = [7 x i8] c"cgroup\00"
@MS_NODEV = global i32 0
@MS_NOSUID = global i32 0
@MS_NOEXEC = global i32 0
@.str.7 = [6 x i8] c"mount\00"
define void @init_cgroups() {
%1 = alloca i8*
%2 = alloca i32*
%3 = alloca i8
%4 = alloca [79 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %1
%10 = load i8*, i8** %1
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i8*, i8** %1
%16 = call i32 @die2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %17
17: ; preds = %14, %0
br label %18
18: ; preds = %31, %17
%19 = load i32*, i32** %2
%20 = call signext i8 @fgetc(i32* %19)
store i8 %20, i8* %3
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %30, label %26
26: ; preds = %18
%27 = load i8, i8* %3
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 10
br i1 %29, label %30, label %31
30: ; preds = %26, %18
br label %32
31: ; preds = %26
br label %18
32: ; preds = %30
br label %33
33: ; preds = %85, %32
%34 = getelementptr inbounds [79 x i8], [79 x i8]* %4, i64 0, i64 0
%35 = getelementptr inbounds i8, i8* %34, i64 16
%36 = getelementptr inbounds i8, i8* %35, i64 -1
store i8* %36, i8** %5
%37 = load i32*, i32** %2
%38 = load i8*, i8** %5
%39 = call i32 @fscanf(i32* %37, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %38, i32* %6, i32* %7, i32* %8)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = load i8, i8* @EOF
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %40, %42
br i1 %43, label %44, label %45
44: ; preds = %33
br label %86
45: ; preds = %33
%46 = load i32, i32* %9
%47 = icmp ne i32 %46, 4
br i1 %47, label %48, label %58
48: ; preds = %45
%49 = load i64, i64* @errno
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %48
br label %54
52: ; preds = %48
%53 = load i64, i64* @EINVAL
br label %54
54: ; preds = %52, %51
%55 = phi i64 [ %49, %51 ], [ %53, %52 ]
store i64 %55, i64* @errno
%56 = load i8*, i8** %1
%57 = call i32 @die2(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* %56)
br label %58
58: ; preds = %54, %45
%59 = load i32, i32* %8
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %85
61: ; preds = %58
%62 = getelementptr inbounds [79 x i8], [79 x i8]* %4, i64 0, i64 0
%63 = call i32 @memcpy(i8* %62, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @init_cgroups.base_path, i64 0, i64 0), i32 15)
%64 = getelementptr inbounds [79 x i8], [79 x i8]* %4, i64 0, i64 0
%65 = call i64 @mkdir(i8* %64, i32 493)
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %61
%68 = getelementptr inbounds [79 x i8], [79 x i8]* %4, i64 0, i64 0
%69 = call i32 @die2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %68)
br label %70
70: ; preds = %67, %61
%71 = load i8*, i8** %5
%72 = getelementptr inbounds [79 x i8], [79 x i8]* %4, i64 0, i64 0
%73 = load i32, i32* @MS_NODEV
%74 = load i32, i32* @MS_NOSUID
%75 = or i32 %73, %74
%76 = load i32, i32* @MS_NOEXEC
%77 = or i32 %75, %76
%78 = load i8*, i8** %5
%79 = call i64 @mount(i8* %71, i8* %72, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %77, i8* %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %70
%82 = getelementptr inbounds [79 x i8], [79 x i8]* %4, i64 0, i64 0
%83 = call i32 @die2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %82)
br label %84
84: ; preds = %81, %70
br label %85
85: ; preds = %84, %58
br label %33
86: ; preds = %44
%87 = load i32*, i32** %2
%88 = call i32 @fclose(i32* %87)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"/proc/cgroups\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@EOF = global i8 0
@init_cgroups.base_path = internal constant [16 x i8] c"/sys/fs/cgroup/\00"
@.str.3 = [15 x i8] c"%64s %d %d %d\0A\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.4 = [7 x i8] c"fscanf\00"
@.str.5 = [6 x i8] c"mkdir\00"
@.str.6 = [7 x i8] c"cgroup\00"
@MS_NODEV = global i32 0
@MS_NOSUID = global i32 0
@MS_NOEXEC = global i32 0
@.str.7 = [6 x i8] c"mount\00"
define void @init_cgroups() {
%1 = alloca [79 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @die2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
br label %10
10: ; preds = %9, %10
%11 = tail call signext i8 @fgetc(i32* %5)
%12 = load i8, i8* @EOF
%13 = icmp eq i8 %11, %12
%14 = icmp eq i8 %11, 10
%15 = or i1 %14, %13
br i1 %15, label %16, label %10
16: ; preds = %10
%17 = getelementptr inbounds [79 x i8], [79 x i8]* %1, i64 0, i64 0
%18 = getelementptr inbounds [79 x i8], [79 x i8]* %1, i64 0, i64 15
%19 = bitcast i32* %2 to i8*
%20 = bitcast i32* %3 to i8*
%21 = bitcast i32* %4 to i8*
%22 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %18, i32* %2, i32* %3, i32* %4)
%23 = load i8, i8* @EOF
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %59, label %26
26: ; preds = %16, %54
%27 = phi i32 [ %55, %54 ], [ %22, %16 ]
%28 = icmp eq i32 %27, 4
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = load i64, i64* @errno
%31 = icmp eq i64 %30, 0
%32 = load i64, i64* @EINVAL
%33 = select i1 %31, i64 %32, i64 %30
store i64 %33, i64* @errno
%34 = call i32 @die2(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %29, %26
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 0
br i1 %37, label %54, label %38
38: ; preds = %35
%39 = call i32 @memcpy(i8* %17, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @init_cgroups.base_path, i64 0, i64 0), i32 15)
%40 = call i64 @mkdir(i8* %17, i32 493)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @die2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %17)
br label %44
44: ; preds = %42, %38
%45 = load i32, i32* @MS_NODEV
%46 = load i32, i32* @MS_NOSUID
%47 = or i32 %46, %45
%48 = load i32, i32* @MS_NOEXEC
%49 = or i32 %47, %48
%50 = call i64 @mount(i8* %18, i8* %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 %49, i8* %18)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %44
%53 = call i32 @die2(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* %17)
br label %54
54: ; preds = %35, %52, %44
%55 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %18, i32* %2, i32* %3, i32* %4)
%56 = load i8, i8* @EOF
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %55, %57
br i1 %58, label %59, label %26
59: ; preds = %54, %16
%60 = call i32 @fclose(i32* %5)
ret void
}