#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;

/* Variables and functions */
scalar_t__ cg_create(char *);
int /*<<< orphan*/ cg_destroy(char *);
char *cg_name(char const *, char *);
scalar_t__ cg_read(char *, char *, char *, int);
scalar_t__ cg_read_strstr(char *, char *, char *);
scalar_t__ cg_write(char *, char *, char *);
int /*<<< orphan*/ free(char *);
int test_memcg_subtree_control(const char *root) {
  char *parent, *child, *parent2, *child2;
  int ret = 1;
  char buf[4096];
  parent = cg_name(root, "memcg_test_0");
  child = cg_name(root, "memcg_test_0/memcg_test_1");
  if (!parent || !child)
    goto cleanup;
  if (cg_create(parent))
    goto cleanup;
  if (cg_write(parent, "cgroup.subtree_control", "+memory"))
    goto cleanup;
  if (cg_create(child))
    goto cleanup;
  if (cg_read_strstr(child, "cgroup.controllers", "memory"))
    goto cleanup;
  parent2 = cg_name(root, "memcg_test_1");
  child2 = cg_name(root, "memcg_test_1/memcg_test_1");
  if (!parent2 || !child2)
    goto cleanup;
  if (cg_create(parent2))
    goto cleanup;
  if (cg_create(child2))
    goto cleanup;
  if (cg_read(child2, "cgroup.controllers", buf, sizeof(buf)))
    goto cleanup;
  if (!cg_read_strstr(child2, "cgroup.controllers", "memory"))
    goto cleanup;
  ret = 0;
cleanup:
  cg_destroy(child);
  cg_destroy(parent);
  free(parent);
  free(child);
  cg_destroy(child2);
  cg_destroy(parent2);
  free(parent2);
  free(child2);
  return ret;
}


x86 assembly (clang, -O0):
<test_memcg_subtree_control>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <cg_name@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1060 <cg_name@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c4 <test_memcg_subtree_control+0x54>
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <test_memcg_subtree_control+0x59>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x10(%rbp),%rdi
call   1070 <cg_create@plt>
cmp    $0x0,%rax
je     11e1 <test_memcg_subtree_control+0x71>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x10(%rbp),%rdi
lea    0xe3b(%rip),%rsi
lea    0xe4b(%rip),%rdx
call   1080 <cg_write@plt>
cmp    $0x0,%rax
je     1207 <test_memcg_subtree_control+0x97>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x18(%rbp),%rdi
call   1070 <cg_create@plt>
cmp    $0x0,%rax
je     121f <test_memcg_subtree_control+0xaf>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x18(%rbp),%rdi
lea    0xe1c(%rip),%rsi
lea    0xe0e(%rip),%rdx
call   1090 <cg_read_strstr@plt>
cmp    $0x0,%rax
je     1245 <test_memcg_subtree_control+0xd5>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x8(%rbp),%rdi
lea    0xdca(%rip),%rsi
call   1060 <cg_name@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1060 <cg_name@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1283 <test_memcg_subtree_control+0x113>
cmpq   $0x0,-0x28(%rbp)
jne    1288 <test_memcg_subtree_control+0x118>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x20(%rbp),%rdi
call   1070 <cg_create@plt>
cmp    $0x0,%rax
je     12a0 <test_memcg_subtree_control+0x130>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x28(%rbp),%rdi
call   1070 <cg_create@plt>
cmp    $0x0,%rax
je     12b8 <test_memcg_subtree_control+0x148>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x28(%rbp),%rdi
lea    -0x1030(%rbp),%rdx
lea    0xd7c(%rip),%rsi
mov    $0x1000,%ecx
call   1050 <cg_read@plt>
cmp    $0x0,%rax
je     12e3 <test_memcg_subtree_control+0x173>
jmp    1310 <test_memcg_subtree_control+0x1a0>
mov    -0x28(%rbp),%rdi
lea    0xd58(%rip),%rsi
lea    0xd4a(%rip),%rdx
call   1090 <cg_read_strstr@plt>
cmp    $0x0,%rax
jne    1309 <test_memcg_subtree_control+0x199>
jmp    1310 <test_memcg_subtree_control+0x1a0>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_memcg_subtree_control>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rdi,%rbp
lea    0xe75(%rip),%rsi
call   1060 <cg_name@plt>
mov    %rax,%rbx
lea    0xe73(%rip),%rsi
mov    %rbp,%rdi
call   1060 <cg_name@plt>
mov    %rax,%r13
mov    $0x1,%r14d
test   %rbx,%rbx
je     1205 <test_memcg_subtree_control+0x95>
test   %r13,%r13
je     1205 <test_memcg_subtree_control+0x95>
mov    %rbx,%rdi
call   1070 <cg_create@plt>
test   %rax,%rax
jne    1205 <test_memcg_subtree_control+0x95>
lea    0xe5e(%rip),%rsi
lea    0xe6e(%rip),%rdx
mov    %rbx,%rdi
call   1080 <cg_write@plt>
test   %rax,%rax
jne    1205 <test_memcg_subtree_control+0x95>
mov    %r13,%rdi
call   1070 <cg_create@plt>
test   %rax,%rax
jne    1205 <test_memcg_subtree_control+0x95>
lea    0xe55(%rip),%rsi
lea    0xe47(%rip),%rdx
mov    %r13,%rdi
call   1090 <cg_read_strstr@plt>
test   %rax,%rax
je     125a <test_memcg_subtree_control+0xea>
mov    %r13,%rdi
call   1030 <cg_destroy@plt>
mov    %rbx,%rdi
call   1030 <cg_destroy@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1030 <cg_destroy@plt>
mov    %r15,%rdi
call   1030 <cg_destroy@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %r14d,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb9(%rip),%rsi
mov    %rbp,%rdi
call   1060 <cg_name@plt>
mov    %rax,%r15
lea    0xde6(%rip),%rsi
mov    %rbp,%rdi
call   1060 <cg_name@plt>
mov    %rax,%r12
test   %r15,%r15
je     1205 <test_memcg_subtree_control+0x95>
test   %r12,%r12
je     1205 <test_memcg_subtree_control+0x95>
mov    %r15,%rdi
call   1070 <cg_create@plt>
test   %rax,%rax
jne    1205 <test_memcg_subtree_control+0x95>
mov    %r12,%rdi
call   1070 <cg_create@plt>
test   %rax,%rax
jne    1205 <test_memcg_subtree_control+0x95>
lea    0xd91(%rip),%rsi
mov    %rsp,%rdx
mov    %r12,%rdi
mov    $0x1000,%ecx
call   1050 <cg_read@plt>
test   %rax,%rax
jne    1205 <test_memcg_subtree_control+0x95>
lea    0xd71(%rip),%rsi
lea    0xd63(%rip),%rdx
mov    %r12,%rdi
call   1090 <cg_read_strstr@plt>
xor    %r14d,%r14d
test   %rax,%rax
sete   %r14b
jmp    1205 <test_memcg_subtree_control+0x95>

LLVM IR (-O0):
@.str = [13 x i8] c"memcg_test_0\00"
@.str.1 = [26 x i8] c"memcg_test_0/memcg_test_1\00"
@.str.2 = [23 x i8] c"cgroup.subtree_control\00"
@.str.3 = [8 x i8] c"+memory\00"
@.str.4 = [19 x i8] c"cgroup.controllers\00"
@.str.5 = [7 x i8] c"memory\00"
@.str.6 = [13 x i8] c"memcg_test_1\00"
@.str.7 = [26 x i8] c"memcg_test_1/memcg_test_1\00"
define i32 @test_memcg_subtree_control(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [4096 x i8]
store i8* %0, i8** %2
store i32 1, i32* %7
%9 = load i8*, i8** %2
%10 = call i8* @cg_name(i8* %9, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = call i8* @cg_name(i8* %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i8* %12, i8** %4
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %1
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15, %1
br label %72
19: ; preds = %15
%20 = load i8*, i8** %3
%21 = call i64 @cg_create(i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
br label %72
24: ; preds = %19
%25 = load i8*, i8** %3
%26 = call i64 @cg_write(i8* %25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %24
br label %72
29: ; preds = %24
%30 = load i8*, i8** %4
%31 = call i64 @cg_create(i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %29
br label %72
34: ; preds = %29
%35 = load i8*, i8** %4
%36 = call i64 @cg_read_strstr(i8* %35, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %72
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = call i8* @cg_name(i8* %40, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
store i8* %41, i8** %5
%42 = load i8*, i8** %2
%43 = call i8* @cg_name(i8* %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
store i8* %43, i8** %6
%44 = load i8*, i8** %5
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = load i8*, i8** %6
%48 = icmp ne i8* %47, null
br i1 %48, label %50, label %49
49: ; preds = %46, %39
br label %72
50: ; preds = %46
%51 = load i8*, i8** %5
%52 = call i64 @cg_create(i8* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %50
br label %72
55: ; preds = %50
%56 = load i8*, i8** %6
%57 = call i64 @cg_create(i8* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %55
br label %72
60: ; preds = %55
%61 = load i8*, i8** %6
%62 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%63 = call i64 @cg_read(i8* %61, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %62, i32 4096)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %60
br label %72
66: ; preds = %60
%67 = load i8*, i8** %6
%68 = call i64 @cg_read_strstr(i8* %67, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%69 = icmp ne i64 %68, 0
br i1 %69, label %71, label %70
70: ; preds = %66
br label %72
71: ; preds = %66
store i32 0, i32* %7
br label %72
72: ; preds = %71, %70, %65, %59, %54, %49, %38, %33, %28, %23, %18
%73 = load i8*, i8** %4
%74 = call i32 @cg_destroy(i8* %73)
%75 = load i8*, i8** %3
%76 = call i32 @cg_destroy(i8* %75)
%77 = load i8*, i8** %3
%78 = call i32 @free(i8* %77)
%79 = load i8*, i8** %4
%80 = call i32 @free(i8* %79)
%81 = load i8*, i8** %6
%82 = call i32 @cg_destroy(i8* %81)
%83 = load i8*, i8** %5
%84 = call i32 @cg_destroy(i8* %83)
%85 = load i8*, i8** %5
%86 = call i32 @free(i8* %85)
%87 = load i8*, i8** %6
%88 = call i32 @free(i8* %87)
%89 = load i32, i32* %7
ret i32 %89
}

LLVM IR (-O2):
@.str = [13 x i8] c"memcg_test_0\00"
@.str.1 = [26 x i8] c"memcg_test_0/memcg_test_1\00"
@.str.2 = [23 x i8] c"cgroup.subtree_control\00"
@.str.3 = [8 x i8] c"+memory\00"
@.str.4 = [19 x i8] c"cgroup.controllers\00"
@.str.5 = [7 x i8] c"memory\00"
@.str.6 = [13 x i8] c"memcg_test_1\00"
@.str.7 = [26 x i8] c"memcg_test_1/memcg_test_1\00"
define i32 @test_memcg_subtree_control(i8* %0) {
%2 = alloca [4096 x i8]
%3 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%5 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp ne i8* %4, null
%7 = icmp ne i8* %5, null
%8 = select i1 %6, i1 %7, i1 false
br i1 %8, label %9, label %40
9: ; preds = %1
%10 = tail call i64 @cg_create(i8* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %40
12: ; preds = %9
%13 = tail call i64 @cg_write(i8* %4, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %40
15: ; preds = %12
%16 = tail call i64 @cg_create(i8* %5)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %40
18: ; preds = %15
%19 = tail call i64 @cg_read_strstr(i8* %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %40
21: ; preds = %18
%22 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%23 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0))
%24 = icmp ne i8* %22, null
%25 = icmp ne i8* %23, null
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %40
27: ; preds = %21
%28 = tail call i64 @cg_create(i8* %22)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = tail call i64 @cg_create(i8* %23)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = call i64 @cg_read(i8* %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* %3, i32 4096)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = call i64 @cg_read_strstr(i8* %23, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i32
br label %40
40: ; preds = %36, %33, %30, %27, %21, %18, %15, %12, %9, %1
%41 = phi i8* [ undef, %9 ], [ undef, %12 ], [ undef, %15 ], [ undef, %18 ], [ %22, %27 ], [ %22, %30 ], [ %22, %33 ], [ %22, %21 ], [ undef, %1 ], [ %22, %36 ]
%42 = phi i8* [ undef, %9 ], [ undef, %12 ], [ undef, %15 ], [ undef, %18 ], [ %23, %27 ], [ %23, %30 ], [ %23, %33 ], [ %23, %21 ], [ undef, %1 ], [ %23, %36 ]
%43 = phi i32 [ 1, %9 ], [ 1, %12 ], [ 1, %15 ], [ 1, %18 ], [ 1, %27 ], [ 1, %30 ], [ 1, %33 ], [ 1, %21 ], [ 1, %1 ], [ %39, %36 ]
%44 = call i32 @cg_destroy(i8* %5)
%45 = call i32 @cg_destroy(i8* %4)
%46 = call i32 @free(i8* %4)
%47 = call i32 @free(i8* %5)
%48 = call i32 @cg_destroy(i8* %42)
%49 = call i32 @cg_destroy(i8* %41)
%50 = call i32 @free(i8* %41)
%51 = call i32 @free(i8* %42)
ret i32 %43
}