#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*/ clone_into_cgroup_run_wait(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;
  if (!clone_into_cgroup_run_wait(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    0xe62(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d1 <test_cgcore_internal_process_constraint+0x61>
cmpq   $0x0,-0x20(%rbp)
jne    11d6 <test_cgcore_internal_process_constraint+0x66>
jmp    1261 <test_cgcore_internal_process_constraint+0xf1>
mov    -0x18(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     11ee <test_cgcore_internal_process_constraint+0x7e>
jmp    1261 <test_cgcore_internal_process_constraint+0xf1>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     1206 <test_cgcore_internal_process_constraint+0x96>
jmp    1261 <test_cgcore_internal_process_constraint+0xf1>
mov    -0x18(%rbp),%rdi
lea    0xe1b(%rip),%rsi
lea    0xe2b(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     122c <test_cgcore_internal_process_constraint+0xbc>
jmp    1261 <test_cgcore_internal_process_constraint+0xf1>
mov    -0x18(%rbp),%rdi
call   1090 <cg_enter_current@plt>
cmp    $0x0,%eax
jne    1243 <test_cgcore_internal_process_constraint+0xd3>
jmp    1261 <test_cgcore_internal_process_constraint+0xf1>
mov    -0x18(%rbp),%rdi
call   1080 <clone_into_cgroup_run_wait@plt>
cmp    $0x0,%eax
jne    125a <test_cgcore_internal_process_constraint+0xea>
jmp    1261 <test_cgcore_internal_process_constraint+0xf1>
movl   $0x0,-0xc(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1275 <test_cgcore_internal_process_constraint+0x105>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x18(%rbp)
je     1289 <test_cgcore_internal_process_constraint+0x119>
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    0xe82(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,%rbx
lea    0xe82(%rip),%rsi
mov    %rbp,%rdi
call   1050 <cg_name@plt>
mov    %rax,%r14
mov    $0x1,%ebp
test   %rbx,%rbx
je     11f8 <test_cgcore_internal_process_constraint+0x88>
test   %r14,%r14
je     11f8 <test_cgcore_internal_process_constraint+0x88>
mov    %rbx,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11f8 <test_cgcore_internal_process_constraint+0x88>
mov    %r14,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11f8 <test_cgcore_internal_process_constraint+0x88>
lea    0xe64(%rip),%rsi
lea    0xe74(%rip),%rdx
mov    %rbx,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    11f8 <test_cgcore_internal_process_constraint+0x88>
mov    %rbx,%rdi
call   1090 <cg_enter_current@plt>
test   %eax,%eax
je     11f8 <test_cgcore_internal_process_constraint+0x88>
mov    %rbx,%rdi
call   1080 <clone_into_cgroup_run_wait@plt>
xor    %ebp,%ebp
test   %eax,%eax
sete   %bpl
test   %r14,%r14
je     1205 <test_cgcore_internal_process_constraint+0x95>
mov    %r14,%rdi
call   1030 <cg_destroy@plt>
test   %rbx,%rbx
je     1212 <test_cgcore_internal_process_constraint+0xa2>
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 %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** %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 %42
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = call i32 @clone_into_cgroup_run_wait(i8* %37)
%39 = icmp ne i32 %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"
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 %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 i32 @cg_enter_current(i8* %2)
%18 = icmp eq i32 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %16
%20 = tail call i32 @clone_into_cgroup_run_wait(i8* %2)
%21 = icmp eq i32 %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
}