#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 *);
scalar_t__ cg_enter_current(char const *);
char *cg_name(char const *, char *);
scalar_t__ cg_read_strstr(char const *, char *, char *);
scalar_t__ cg_write(char *, char *, char *);
int /*<<< orphan*/ free(char *);
int test_cgcore_no_internal_process_constraint_on_threads(const char *root) {
  int ret = 1;
  char *parent = NULL, *child = NULL;
  if (cg_read_strstr(root, "cgroup.controllers", "cpu") ||
      cg_read_strstr(root, "cgroup.subtree_control", "cpu")) {
    ret = 4;
    goto cleanup;
  }
  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.type", "threaded"))
    goto cleanup;
  if (cg_write(child, "cgroup.type", "threaded"))
    goto cleanup;
  if (cg_write(parent, "cgroup.subtree_control", "+cpu"))
    goto cleanup;
  if (cg_enter_current(parent))
    goto cleanup;
  ret = 0;
cleanup:
  cg_enter_current(root);
  cg_enter_current(root);
  if (child)
    cg_destroy(child);
  if (parent)
    cg_destroy(parent);
  free(child);
  free(parent);
  return ret;
}


x86 assembly (clang, -O0):
<test_cgcore_no_internal_process_constraint_on_threads>:
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
lea    0xec7(%rip),%rdx
call   1090 <cg_read_strstr@plt>
cmp    $0x0,%rax
jne    11d5 <test_cgcore_no_internal_process_constraint_on_threads+0x65>
mov    -0x8(%rbp),%rdi
lea    0xe54(%rip),%rsi
lea    0xea6(%rip),%rdx
call   1090 <cg_read_strstr@plt>
cmp    $0x0,%rax
je     11e1 <test_cgcore_no_internal_process_constraint_on_threads+0x71>
movl   $0x4,-0xc(%rbp)
jmp    12e5 <test_cgcore_no_internal_process_constraint_on_threads+0x175>
mov    -0x8(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     121f <test_cgcore_no_internal_process_constraint_on_threads+0xaf>
cmpq   $0x0,-0x20(%rbp)
jne    1224 <test_cgcore_no_internal_process_constraint_on_threads+0xb4>
jmp    12e5 <test_cgcore_no_internal_process_constraint_on_threads+0x175>
mov    -0x18(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     123c <test_cgcore_no_internal_process_constraint_on_threads+0xcc>
jmp    12e5 <test_cgcore_no_internal_process_constraint_on_threads+0x175>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     1254 <test_cgcore_no_internal_process_constraint_on_threads+0xe4>
jmp    12e5 <test_cgcore_no_internal_process_constraint_on_threads+0x175>
mov    -0x18(%rbp),%rdi
lea    0xdf7(%rip),%rsi
lea    0xdfc(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     127a <test_cgcore_no_internal_process_constraint_on_threads+0x10a>
jmp    12e5 <test_cgcore_no_internal_process_constraint_on_threads+0x175>
mov    -0x20(%rbp),%rdi
lea    0xdd1(%rip),%rsi
lea    0xdd6(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     12a0 <test_cgcore_no_internal_process_constraint_on_threads+0x130>
jmp    12e5 <test_cgcore_no_internal_process_constraint_on_threads+0x175>
mov    -0x18(%rbp),%rdi
lea    0xd68(%rip),%rsi
lea    0xdb9(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     12c6 <test_cgcore_no_internal_process_constraint_on_threads+0x156>
jmp    12e5 <test_cgcore_no_internal_process_constraint_on_threads+0x175>
mov    -0x18(%rbp),%rdi
call   1080 <cg_enter_current@plt>
cmp    $0x0,%rax
je     12de <test_cgcore_no_internal_process_constraint_on_threads+0x16e>
jmp    12e5 <test_cgcore_no_internal_process_constraint_on_threads+0x175>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <cg_enter_current@plt>
mov    -0x8(%rbp),%rdi
call   1080 <cg_enter_current@plt>
cmpq   $0x0,-0x20(%rbp)
je     130b <test_cgcore_no_internal_process_constraint_on_threads+0x19b>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x18(%rbp)
je     131f <test_cgcore_no_internal_process_constraint_on_threads+0x1af>
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_no_internal_process_constraint_on_threads>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe7f(%rip),%rsi
lea    0xee4(%rip),%rdx
call   1090 <cg_read_strstr@plt>
mov    $0x4,%r14d
test   %rax,%rax
jne    11b3 <test_cgcore_no_internal_process_constraint_on_threads+0x43>
lea    0xe74(%rip),%rsi
lea    0xec6(%rip),%rdx
mov    %rbx,%rdi
call   1090 <cg_read_strstr@plt>
test   %rax,%rax
je     1200 <test_cgcore_no_internal_process_constraint_on_threads+0x90>
xor    %r15d,%r15d
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1080 <cg_enter_current@plt>
mov    %rbx,%rdi
call   1080 <cg_enter_current@plt>
test   %rbp,%rbp
je     11d5 <test_cgcore_no_internal_process_constraint_on_threads+0x65>
mov    %rbp,%rdi
call   1030 <cg_destroy@plt>
test   %r15,%r15
je     11e2 <test_cgcore_no_internal_process_constraint_on_threads+0x72>
mov    %r15,%rdi
call   1030 <cg_destroy@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe23(%rip),%rsi
mov    %rbx,%rdi
call   1050 <cg_name@plt>
mov    %rax,%r15
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
call   1050 <cg_name@plt>
mov    %rax,%rbp
mov    $0x1,%r14d
test   %r15,%r15
je     11b8 <test_cgcore_no_internal_process_constraint_on_threads+0x48>
test   %rbp,%rbp
je     11b8 <test_cgcore_no_internal_process_constraint_on_threads+0x48>
mov    %r15,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11b8 <test_cgcore_no_internal_process_constraint_on_threads+0x48>
mov    %rbp,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    11b8 <test_cgcore_no_internal_process_constraint_on_threads+0x48>
lea    0xdf9(%rip),%rsi
lea    0xdfe(%rip),%rdx
mov    %r15,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    11b8 <test_cgcore_no_internal_process_constraint_on_threads+0x48>
lea    0xdda(%rip),%rsi
lea    0xddf(%rip),%rdx
mov    %rbp,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    11b8 <test_cgcore_no_internal_process_constraint_on_threads+0x48>
lea    0xd78(%rip),%rsi
lea    0xdc9(%rip),%rdx
mov    %r15,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    11b8 <test_cgcore_no_internal_process_constraint_on_threads+0x48>
mov    %r15,%rdi
call   1080 <cg_enter_current@plt>
xor    %r14d,%r14d
test   %rax,%rax
setne  %r14b
jmp    11b8 <test_cgcore_no_internal_process_constraint_on_threads+0x48>

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

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