#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 *);
int /*<<< orphan*/ cg_write(char *, char *, char *);
int /*<<< orphan*/ free(char *);
int test_cgcore_top_down_constraint_enable(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(child, "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_enable>:
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_enable+0x61>
cmpq   $0x0,-0x20(%rbp)
jne    11b6 <test_cgcore_top_down_constraint_enable+0x66>
jmp    1212 <test_cgcore_top_down_constraint_enable+0xc2>
mov    -0x18(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11ce <test_cgcore_top_down_constraint_enable+0x7e>
jmp    1212 <test_cgcore_top_down_constraint_enable+0xc2>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11e6 <test_cgcore_top_down_constraint_enable+0x96>
jmp    1212 <test_cgcore_top_down_constraint_enable+0xc2>
mov    -0x20(%rbp),%rdi
lea    0xe3b(%rip),%rsi
lea    0xe4b(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%eax
jne    120b <test_cgcore_top_down_constraint_enable+0xbb>
jmp    1212 <test_cgcore_top_down_constraint_enable+0xc2>
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1226 <test_cgcore_top_down_constraint_enable+0xd6>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x18(%rbp)
je     123a <test_cgcore_top_down_constraint_enable+0xea>
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_enable>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xea2(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,%r14
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
call   1050 <cg_name@plt>
mov    %rax,%rbx
mov    $0x1,%ebp
test   %r14,%r14
je     11bf <test_cgcore_top_down_constraint_enable+0x6f>
test   %rbx,%rbx
je     11bf <test_cgcore_top_down_constraint_enable+0x6f>
mov    %r14,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11bf <test_cgcore_top_down_constraint_enable+0x6f>
mov    %rbx,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11bf <test_cgcore_top_down_constraint_enable+0x6f>
lea    0xe84(%rip),%rsi
lea    0xe94(%rip),%rdx
mov    %rbx,%rdi
call   1070 <cg_write@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
test   %rbx,%rbx
je     11cc <test_cgcore_top_down_constraint_enable+0x7c>
mov    %rbx,%rdi
call   1030 <cg_destroy@plt>
test   %r14,%r14
je     11d9 <test_cgcore_top_down_constraint_enable+0x89>
mov    %r14,%rdi
call   1030 <cg_destroy@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r14,%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"
define i32 @test_cgcore_top_down_constraint_enable(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 %32
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 %32
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 %32
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = call i32 @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 i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %26
br label %32
31: ; preds = %26
store i32 0, i32* %3
br label %32
32: ; preds = %31, %30, %25, %20, %15
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %38
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = call i32 @cg_destroy(i8* %36)
br label %38
38: ; preds = %35, %32
%39 = load i8*, i8** %4
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i8*, i8** %4
%43 = call i32 @cg_destroy(i8* %42)
br label %44
44: ; preds = %41, %38
%45 = load i8*, i8** %5
%46 = call i32 @free(i8* %45)
%47 = load i8*, i8** %4
%48 = call i32 @free(i8* %47)
%49 = load i32, i32* %3
ret i32 %49
}

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"
define i32 @test_cgcore_top_down_constraint_enable(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 %17
7: ; preds = %1
%8 = tail call i64 @cg_create(i8* %2)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %7
%11 = tail call i64 @cg_create(i8* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = tail call i32 @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))
%15 = icmp eq i32 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %13, %10, %7, %1
%18 = phi i32 [ 1, %7 ], [ 1, %10 ], [ 1, %1 ], [ %16, %13 ]
br i1 %5, label %19, label %21
19: ; preds = %17
%20 = tail call i32 @cg_destroy(i8* %3)
br label %21
21: ; preds = %19, %17
br i1 %4, label %22, label %24
22: ; preds = %21
%23 = tail call i32 @cg_destroy(i8* %2)
br label %24
24: ; preds = %22, %21
%25 = tail call i32 @free(i8* %3)
%26 = tail call i32 @free(i8* %2)
ret i32 %18
}