#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 */
struct stat {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CGROUP_SUPER_MAGIC;
int /*<<< orphan*/ TMPFS_MAGIC;
int /*<<< orphan*/ close(int);
int mkdir(char *, int);
int mount(char *, char *, char *, int /*<<< orphan*/, char *);
int mounted(char *, int /*<<< orphan*/);
int open_cpuset(char *, char *);
int stat(char *, struct stat *);
int write(int, char *, int);
int mount_cpuset(void) {
  struct stat st;
  int ret;
  int fd;
  ret = mounted("/sys/fs/cgroup", TMPFS_MAGIC);
  if (ret < 0)
    return ret;
  if (!ret) {
    ret = mount("cgroup_root", "/sys/fs/cgroup", "tmpfs", 0, NULL);
    if (ret < 0)
      return ret;
  }
  ret = stat("/sys/fs/cgroup"
             "/cpuset",
             &st);
  if (ret < 0) {
    ret = mkdir("/sys/fs/cgroup"
                "/cpuset",
                0755);
    if (ret < 0)
      return ret;
  }
  ret = mounted("/sys/fs/cgroup"
                "/cpuset",
                CGROUP_SUPER_MAGIC);
  if (ret < 0)
    return ret;
  if (!ret) {
    ret = mount("cpuset",
                "/sys/fs/cgroup"
                "/cpuset",
                "cgroup", 0, "cpuset");
    if (ret < 0)
      return ret;
  }
  fd = open_cpuset("/sys/fs/cgroup"
                   "/cpuset",
                   "cpuset.cpu_exclusive");
  if (fd < 0)
    return fd;
  ret = write(fd, "1", 2);
  close(fd);
  fd = open_cpuset("/sys/fs/cgroup"
                   "/cpuset",
                   "cpuset.sched_load_balance");
  if (fd < 0)
    return fd;
  ret = write(fd, "0", 2);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<mount_cpuset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe78(%rip),%rdi
call   1040 <mounted@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11a5 <mount_cpuset+0x35>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1346 <mount_cpuset+0x1d6>
cmpl   $0x0,-0xc(%rbp)
jne    11ed <mount_cpuset+0x7d>
lea    0xe59(%rip),%rdi
lea    0xe43(%rip),%rsi
lea    0xe57(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <mount@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11e8 <mount_cpuset+0x78>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1346 <mount_cpuset+0x1d6>
jmp    11ed <mount_cpuset+0x7d>
lea    0xe2d(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1080 <stat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1238 <mount_cpuset+0xc8>
lea    0xe10(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1233 <mount_cpuset+0xc3>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1346 <mount_cpuset+0x1d6>
jmp    1238 <mount_cpuset+0xc8>
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
lea    0xdd9(%rip),%rdi
call   1040 <mounted@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1265 <mount_cpuset+0xf5>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1346 <mount_cpuset+0x1d6>
cmpl   $0x0,-0xc(%rbp)
jne    12ab <mount_cpuset+0x13b>
lea    0xdba(%rip),%r8
lea    0xda4(%rip),%rsi
lea    0xd84(%rip),%rdx
xor    %ecx,%ecx
mov    %r8,%rdi
call   1060 <mount@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    12a6 <mount_cpuset+0x136>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1346 <mount_cpuset+0x1d6>
jmp    12ab <mount_cpuset+0x13b>
lea    0xd6f(%rip),%rdi
lea    0xd7e(%rip),%rsi
call   1090 <open_cpuset@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    12d6 <mount_cpuset+0x166>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1346 <mount_cpuset+0x1d6>
mov    -0x10(%rbp),%edi
lea    0xd6c(%rip),%rsi
mov    $0x2,%edx
call   1050 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
lea    0xd25(%rip),%rdi
lea    0xd4b(%rip),%rsi
call   1090 <open_cpuset@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1320 <mount_cpuset+0x1b0>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1346 <mount_cpuset+0x1d6>
mov    -0x10(%rbp),%edi
lea    0xd3e(%rip),%rsi
mov    $0x2,%edx
call   1050 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mount_cpuset>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    0xe7b(%rip),%rdi
call   1040 <mounted@plt>
test   %eax,%eax
js     1295 <mount_cpuset+0x125>
jne    11bb <mount_cpuset+0x4b>
lea    0xe74(%rip),%rdi
lea    0xe5e(%rip),%rsi
lea    0xe72(%rip),%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1060 <mount@plt>
test   %eax,%eax
js     1295 <mount_cpuset+0x125>
lea    0xe5f(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
test   %eax,%eax
jns    11e9 <mount_cpuset+0x79>
lea    0xe4a(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
test   %eax,%eax
js     1295 <mount_cpuset+0x125>
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
lea    0xe28(%rip),%rdi
call   1040 <mounted@plt>
test   %eax,%eax
js     1295 <mount_cpuset+0x125>
jne    122b <mount_cpuset+0xbb>
lea    0xe12(%rip),%rsi
lea    0xdf2(%rip),%rdx
lea    0xe13(%rip),%rdi
xor    %ecx,%ecx
mov    %rdi,%r8
call   1060 <mount@plt>
test   %eax,%eax
js     1295 <mount_cpuset+0x125>
lea    0xdef(%rip),%rdi
lea    0xdfe(%rip),%rsi
call   1090 <open_cpuset@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1297 <mount_cpuset+0x127>
lea    0xe01(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1050 <write@plt>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xdbc(%rip),%rdi
lea    0xde2(%rip),%rsi
call   1090 <open_cpuset@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1297 <mount_cpuset+0x127>
lea    0xdea(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1050 <write@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %ebx,%ebx
jmp    1297 <mount_cpuset+0x127>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [15 x i8] c"/sys/fs/cgroup\00"
@TMPFS_MAGIC = global i32 0
@.str.1 = [12 x i8] c"cgroup_root\00"
@.str.2 = [6 x i8] c"tmpfs\00"
@.str.3 = [22 x i8] c"/sys/fs/cgroup/cpuset\00"
@CGROUP_SUPER_MAGIC = global i32 0
@.str.4 = [7 x i8] c"cpuset\00"
@.str.5 = [7 x i8] c"cgroup\00"
@.str.6 = [21 x i8] c"cpuset.cpu_exclusive\00"
@.str.7 = [2 x i8] c"1\00"
@.str.8 = [26 x i8] c"cpuset.sched_load_balance\00"
@.str.9 = [2 x i8] c"0\00"
define i32 @mount_cpuset() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i32
%4 = alloca i32
%5 = load i32, i32* @TMPFS_MAGIC
%6 = call i32 @mounted(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = load i32, i32* %3
store i32 %10, i32* %1
br label %70
11: ; preds = %0
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %11
%15 = call i32 @mount(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* null)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i32, i32* %3
store i32 %19, i32* %1
br label %70
20: ; preds = %14
br label %21
21: ; preds = %20, %11
%22 = call i32 @stat(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %2)
store i32 %22, i32* %3
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = call i32 @mkdir(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 493)
store i32 %26, i32* %3
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i32, i32* %3
store i32 %30, i32* %1
br label %70
31: ; preds = %25
br label %32
32: ; preds = %31, %21
%33 = load i32, i32* @CGROUP_SUPER_MAGIC
%34 = call i32 @mounted(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %33)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = load i32, i32* %3
store i32 %38, i32* %1
br label %70
39: ; preds = %32
%40 = load i32, i32* %3
%41 = icmp ne i32 %40, 0
br i1 %41, label %49, label %42
42: ; preds = %39
%43 = call i32 @mount(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 %43, i32* %3
%44 = load i32, i32* %3
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = load i32, i32* %3
store i32 %47, i32* %1
br label %70
48: ; preds = %42
br label %49
49: ; preds = %48, %39
%50 = call i32 @open_cpuset(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
store i32 %50, i32* %4
%51 = load i32, i32* %4
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %49
%54 = load i32, i32* %4
store i32 %54, i32* %1
br label %70
55: ; preds = %49
%56 = load i32, i32* %4
%57 = call i32 @write(i32 %56, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 2)
store i32 %57, i32* %3
%58 = load i32, i32* %4
%59 = call i32 @close(i32 %58)
%60 = call i32 @open_cpuset(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
store i32 %60, i32* %4
%61 = load i32, i32* %4
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %55
%64 = load i32, i32* %4
store i32 %64, i32* %1
br label %70
65: ; preds = %55
%66 = load i32, i32* %4
%67 = call i32 @write(i32 %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 2)
store i32 %67, i32* %3
%68 = load i32, i32* %4
%69 = call i32 @close(i32 %68)
store i32 0, i32* %1
br label %70
70: ; preds = %65, %63, %53, %46, %37, %29, %18, %9
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"/sys/fs/cgroup\00"
@TMPFS_MAGIC = global i32 0
@.str.1 = [12 x i8] c"cgroup_root\00"
@.str.2 = [6 x i8] c"tmpfs\00"
@.str.3 = [22 x i8] c"/sys/fs/cgroup/cpuset\00"
@CGROUP_SUPER_MAGIC = global i32 0
@.str.4 = [7 x i8] c"cpuset\00"
@.str.5 = [7 x i8] c"cgroup\00"
@.str.6 = [21 x i8] c"cpuset.cpu_exclusive\00"
@.str.7 = [2 x i8] c"1\00"
@.str.8 = [26 x i8] c"cpuset.sched_load_balance\00"
@.str.9 = [2 x i8] c"0\00"
define i32 @mount_cpuset() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i32, i32* @TMPFS_MAGIC
%4 = tail call i32 @mounted(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %37, label %6
6: ; preds = %0
%7 = icmp eq i32 %4, 0
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = tail call i32 @mount(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 0, i8* null)
%10 = icmp slt i32 %9, 0
br i1 %10, label %37, label %11
11: ; preds = %8, %6
%12 = call i32 @stat(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %1)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = tail call i32 @mkdir(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 493)
%16 = icmp slt i32 %15, 0
br i1 %16, label %37, label %17
17: ; preds = %14, %11
%18 = load i32, i32* @CGROUP_SUPER_MAGIC
%19 = tail call i32 @mounted(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %37, label %21
21: ; preds = %17
%22 = icmp eq i32 %19, 0
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = tail call i32 @mount(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp slt i32 %24, 0
br i1 %25, label %37, label %26
26: ; preds = %23, %21
%27 = tail call i32 @open_cpuset(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%28 = icmp slt i32 %27, 0
br i1 %28, label %37, label %29
29: ; preds = %26
%30 = tail call i32 @write(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i32 2)
%31 = tail call i32 @close(i32 %27)
%32 = tail call i32 @open_cpuset(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
%33 = icmp slt i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = tail call i32 @write(i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i32 2)
%36 = tail call i32 @close(i32 %32)
br label %37
37: ; preds = %29, %26, %23, %17, %14, %8, %0, %34
%38 = phi i32 [ 0, %34 ], [ %4, %0 ], [ %9, %8 ], [ %15, %14 ], [ %19, %17 ], [ %24, %23 ], [ %27, %26 ], [ %32, %29 ]
ret i32 %38
}