#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 */

/* Variables and functions */
scalar_t__ cg_create(char *);
int /*<<< orphan*/ cg_destroy(char *);
char *cg_name(char const *, char *);
scalar_t__ cg_write(char *, char *, char *);
int /*<<< orphan*/ free(char *);
int test_cgcore_top_down_constraint_disable(const char *root) {
  int ret = 1;
  char *parent = NULL, *child = NULL;
  parent = cg_name(root, "cg_test_parent");
  child = cg_name(root, "cg_test_parent/cg_test_child");
  if (!parent || !child)
    goto cleanup;
  if (cg_create(parent))
    goto cleanup;
  if (cg_create(child))
    goto cleanup;
  if (cg_write(parent, "cgroup.subtree_control", "+memory"))
    goto cleanup;
  if (cg_write(child, "cgroup.subtree_control", "+memory"))
    goto cleanup;
  if (!cg_write(parent, "cgroup.subtree_control", "-memory"))
    goto cleanup;
  ret = 0;
cleanup:
  if (child)
    cg_destroy(child);
  if (parent)
    cg_destroy(parent);
  free(child);
  free(parent);
  return ret;
}


x86 assembly (clang, -O0):
<test_cgcore_top_down_constraint_disable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b1 <test_cgcore_top_down_constraint_disable+0x61>
cmpq   $0x0,-0x20(%rbp)
jne    11b6 <test_cgcore_top_down_constraint_disable+0x66>
jmp    125f <test_cgcore_top_down_constraint_disable+0x10f>
mov    -0x18(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11ce <test_cgcore_top_down_constraint_disable+0x7e>
jmp    125f <test_cgcore_top_down_constraint_disable+0x10f>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11e6 <test_cgcore_top_down_constraint_disable+0x96>
jmp    125f <test_cgcore_top_down_constraint_disable+0x10f>
mov    -0x18(%rbp),%rdi
lea    0xe3b(%rip),%rsi
lea    0xe4b(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     120c <test_cgcore_top_down_constraint_disable+0xbc>
jmp    125f <test_cgcore_top_down_constraint_disable+0x10f>
mov    -0x20(%rbp),%rdi
lea    0xe15(%rip),%rsi
lea    0xe25(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     1232 <test_cgcore_top_down_constraint_disable+0xe2>
jmp    125f <test_cgcore_top_down_constraint_disable+0x10f>
mov    -0x18(%rbp),%rdi
lea    0xdef(%rip),%rsi
lea    0xe07(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
jne    1258 <test_cgcore_top_down_constraint_disable+0x108>
jmp    125f <test_cgcore_top_down_constraint_disable+0x10f>
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1273 <test_cgcore_top_down_constraint_disable+0x123>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x18(%rbp)
je     1287 <test_cgcore_top_down_constraint_disable+0x137>
mov    -0x18(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cgcore_top_down_constraint_disable>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
lea    0xea2(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,%rbx
lea    0xea2(%rip),%rsi
mov    %rbp,%rdi
call   1050 <cg_name@plt>
mov    %rax,%r14
mov    $0x1,%ebp
test   %rbx,%rbx
je     11f6 <test_cgcore_top_down_constraint_disable+0xa6>
test   %r14,%r14
je     11f6 <test_cgcore_top_down_constraint_disable+0xa6>
mov    %rbx,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11f6 <test_cgcore_top_down_constraint_disable+0xa6>
mov    %r14,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11f6 <test_cgcore_top_down_constraint_disable+0xa6>
lea    0xe84(%rip),%rsi
lea    0xe94(%rip),%rdx
mov    %rbx,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    11f6 <test_cgcore_top_down_constraint_disable+0xa6>
lea    0xe69(%rip),%rsi
lea    0xe79(%rip),%rdx
mov    %r14,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    11f6 <test_cgcore_top_down_constraint_disable+0xa6>
lea    0xe4e(%rip),%rsi
lea    0xe66(%rip),%rdx
mov    %rbx,%rdi
call   1070 <cg_write@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
test   %r14,%r14
je     1203 <test_cgcore_top_down_constraint_disable+0xb3>
mov    %r14,%rdi
call   1030 <cg_destroy@plt>
test   %rbx,%rbx
je     1210 <test_cgcore_top_down_constraint_disable+0xc0>
mov    %rbx,%rdi
call   1030 <cg_destroy@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"cg_test_parent\00"
@.str.1 = [29 x i8] c"cg_test_parent/cg_test_child\00"
@.str.2 = [23 x i8] c"cgroup.subtree_control\00"
@.str.3 = [8 x i8] c"+memory\00"
@.str.4 = [8 x i8] c"-memory\00"
define i32 @test_cgcore_top_down_constraint_disable(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i32 1, i32* %3
store i8* null, i8** %4
store i8* null, i8** %5
%6 = load i8*, i8** %2
%7 = call i8* @cg_name(i8* %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %2
%9 = call i8* @cg_name(i8* %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i8* %9, i8** %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %16, label %15
15: ; preds = %12, %1
br label %42
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i64 @cg_create(i8* %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
br label %42
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = call i64 @cg_create(i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
br label %42
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = call i64 @cg_write(i8* %27, 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))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
br label %42
31: ; preds = %26
%32 = load i8*, i8** %5
%33 = call i64 @cg_write(i8* %32, 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))
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %42
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = call i64 @cg_write(i8* %37, 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.4, i64 0, i64 0))
%39 = icmp ne i64 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %36
br label %42
41: ; preds = %36
store i32 0, i32* %3
br label %42
42: ; preds = %41, %40, %35, %30, %25, %20, %15
%43 = load i8*, i8** %5
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i8*, i8** %5
%47 = call i32 @cg_destroy(i8* %46)
br label %48
48: ; preds = %45, %42
%49 = load i8*, i8** %4
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = load i8*, i8** %4
%53 = call i32 @cg_destroy(i8* %52)
br label %54
54: ; preds = %51, %48
%55 = load i8*, i8** %5
%56 = call i32 @free(i8* %55)
%57 = load i8*, i8** %4
%58 = call i32 @free(i8* %57)
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [15 x i8] c"cg_test_parent\00"
@.str.1 = [29 x i8] c"cg_test_parent/cg_test_child\00"
@.str.2 = [23 x i8] c"cgroup.subtree_control\00"
@.str.3 = [8 x i8] c"+memory\00"
@.str.4 = [8 x i8] c"-memory\00"
define i32 @test_cgcore_top_down_constraint_disable(i8* %0) {
%2 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp ne i8* %2, null
%5 = icmp ne i8* %3, null
%6 = select i1 %4, i1 %5, i1 false
br i1 %6, label %7, label %23
7: ; preds = %1
%8 = tail call i64 @cg_create(i8* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = tail call i64 @cg_create(i8* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %10
%14 = tail call i64 @cg_write(i8* %2, 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))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = tail call i64 @cg_write(i8* %3, 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))
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = tail call i64 @cg_write(i8* %2, 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.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %19, %16, %13, %10, %7, %1
%24 = phi i32 [ 1, %7 ], [ 1, %10 ], [ 1, %13 ], [ 1, %16 ], [ 1, %1 ], [ %22, %19 ]
br i1 %5, label %25, label %27
25: ; preds = %23
%26 = tail call i32 @cg_destroy(i8* %3)
br label %27
27: ; preds = %25, %23
br i1 %4, label %28, label %30
28: ; preds = %27
%29 = tail call i32 @cg_destroy(i8* %2)
br label %30
30: ; preds = %28, %27
%31 = tail call i32 @free(i8* %3)
%32 = tail call i32 @free(i8* %2)
ret i32 %24
}