#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 *);
int /*<<< orphan*/ cg_enter_current(char *);
char *cg_name(char const *, char *);
scalar_t__ cg_write(char *, char *, char *);
int /*<<< orphan*/ free(char *);
int test_cgcore_internal_process_constraint(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_enter_current(parent))
    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_internal_process_constraint>:
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    0xe72(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c1 <test_cgcore_internal_process_constraint+0x61>
cmpq   $0x0,-0x20(%rbp)
jne    11c6 <test_cgcore_internal_process_constraint+0x66>
jmp    123a <test_cgcore_internal_process_constraint+0xda>
mov    -0x18(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11de <test_cgcore_internal_process_constraint+0x7e>
jmp    123a <test_cgcore_internal_process_constraint+0xda>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11f6 <test_cgcore_internal_process_constraint+0x96>
jmp    123a <test_cgcore_internal_process_constraint+0xda>
mov    -0x18(%rbp),%rdi
lea    0xe2b(%rip),%rsi
lea    0xe3b(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     121c <test_cgcore_internal_process_constraint+0xbc>
jmp    123a <test_cgcore_internal_process_constraint+0xda>
mov    -0x18(%rbp),%rdi
call   1080 <cg_enter_current@plt>
cmp    $0x0,%eax
jne    1233 <test_cgcore_internal_process_constraint+0xd3>
jmp    123a <test_cgcore_internal_process_constraint+0xda>
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     124e <test_cgcore_internal_process_constraint+0xee>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x18(%rbp)
je     1262 <test_cgcore_internal_process_constraint+0x102>
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_internal_process_constraint>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
lea    0xe92(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,%rbx
lea    0xe92(%rip),%rsi
mov    %rbp,%rdi
call   1050 <cg_name@plt>
mov    %rax,%r14
mov    $0x1,%ebp
test   %rbx,%rbx
je     11dc <test_cgcore_internal_process_constraint+0x7c>
test   %r14,%r14
je     11dc <test_cgcore_internal_process_constraint+0x7c>
mov    %rbx,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11dc <test_cgcore_internal_process_constraint+0x7c>
mov    %r14,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11dc <test_cgcore_internal_process_constraint+0x7c>
lea    0xe74(%rip),%rsi
lea    0xe84(%rip),%rdx
mov    %rbx,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    11dc <test_cgcore_internal_process_constraint+0x7c>
mov    %rbx,%rdi
call   1080 <cg_enter_current@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
test   %r14,%r14
je     11e9 <test_cgcore_internal_process_constraint+0x89>
mov    %r14,%rdi
call   1030 <cg_destroy@plt>
test   %rbx,%rbx
je     11f6 <test_cgcore_internal_process_constraint+0x96>
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"
define i32 @test_cgcore_internal_process_constraint(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 %37
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 %37
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 %37
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 %37
31: ; preds = %26
%32 = load i8*, i8** %4
%33 = call i32 @cg_enter_current(i8* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %31
br label %37
36: ; preds = %31
store i32 0, i32* %3
br label %37
37: ; preds = %36, %35, %30, %25, %20, %15
%38 = load i8*, i8** %5
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = call i32 @cg_destroy(i8* %41)
br label %43
43: ; preds = %40, %37
%44 = load i8*, i8** %4
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = load i8*, i8** %4
%48 = call i32 @cg_destroy(i8* %47)
br label %49
49: ; preds = %46, %43
%50 = load i8*, i8** %5
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %4
%53 = call i32 @free(i8* %52)
%54 = load i32, i32* %3
ret i32 %54
}

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