#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__ ENOSYS;
scalar_t__ EOPNOTSUPP;
scalar_t__ cg_create(char *);
int /*<<< orphan*/ cg_destroy(char *);
int /*<<< orphan*/ cg_enter_current(char const *);
char *cg_name(char const *, char *);
scalar_t__ cg_read_strcmp(char *, char *, char *);
scalar_t__ cg_write(char *, char *, char *);
int /*<<< orphan*/ clone_into_cgroup_run_wait(char *);
scalar_t__ errno;
int /*<<< orphan*/ free(char *);
int test_cgcore_invalid_domain(const char *root) {
  int ret = 1;
  char *grandparent = NULL, *parent = NULL, *child = NULL;
  grandparent = cg_name(root, "cg_test_grandparent");
  parent = cg_name(root, "cg_test_grandparent/cg_test_parent");
  child = cg_name(root, "cg_test_grandparent/cg_test_parent/cg_test_child");
  if (!parent || !child || !grandparent)
    goto cleanup;
  if (cg_create(grandparent))
    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_read_strcmp(child, "cgroup.type", "domain invalid\n"))
    goto cleanup;
  if (!cg_enter_current(child))
    goto cleanup;
  if (errno != EOPNOTSUPP)
    goto cleanup;
  if (!clone_into_cgroup_run_wait(child))
    goto cleanup;
  if (errno == ENOSYS)
    goto cleanup_pass;
  if (errno != EOPNOTSUPP)
    goto cleanup;
cleanup_pass:
  ret = 0;
cleanup:
  cg_enter_current(root);
  if (child)
    cg_destroy(child);
  if (parent)
    cg_destroy(parent);
  if (grandparent)
    cg_destroy(grandparent);
  free(child);
  free(parent);
  free(grandparent);
  return ret;
}


x86 assembly (clang, -O0):
<test_cgcore_invalid_domain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1208 <test_cgcore_invalid_domain+0x88>
cmpq   $0x0,-0x28(%rbp)
je     1208 <test_cgcore_invalid_domain+0x88>
cmpq   $0x0,-0x18(%rbp)
jne    120d <test_cgcore_invalid_domain+0x8d>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    -0x18(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     1225 <test_cgcore_invalid_domain+0xa5>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     123d <test_cgcore_invalid_domain+0xbd>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    -0x28(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     1255 <test_cgcore_invalid_domain+0xd5>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    -0x20(%rbp),%rdi
lea    0xe08(%rip),%rsi
lea    0xe0d(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     127b <test_cgcore_invalid_domain+0xfb>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    -0x28(%rbp),%rdi
lea    0xde2(%rip),%rsi
lea    0xdf0(%rip),%rdx
call   1080 <cg_read_strcmp@plt>
cmp    $0x0,%rax
je     12a1 <test_cgcore_invalid_domain+0x121>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    -0x28(%rbp),%rdi
call   10a0 <cg_enter_current@plt>
cmp    $0x0,%eax
jne    12b8 <test_cgcore_invalid_domain+0x138>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    0x2d11(%rip),%rax
mov    (%rax),%rax
mov    0x2d0f(%rip),%rcx
cmp    (%rcx),%rax
je     12d7 <test_cgcore_invalid_domain+0x157>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    -0x28(%rbp),%rdi
call   1090 <clone_into_cgroup_run_wait@plt>
cmp    $0x0,%eax
jne    12ee <test_cgcore_invalid_domain+0x16e>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
mov    0x2cdb(%rip),%rax
mov    (%rax),%rax
mov    0x2ce9(%rip),%rcx
cmp    (%rcx),%rax
jne    130d <test_cgcore_invalid_domain+0x18d>
jmp    1331 <test_cgcore_invalid_domain+0x1b1>
mov    0x2cbc(%rip),%rax
mov    (%rax),%rax
mov    0x2cba(%rip),%rcx
cmp    (%rcx),%rax
je     132c <test_cgcore_invalid_domain+0x1ac>
jmp    1338 <test_cgcore_invalid_domain+0x1b8>
jmp    1331 <test_cgcore_invalid_domain+0x1b1>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   10a0 <cg_enter_current@plt>
cmpq   $0x0,-0x28(%rbp)
je     1355 <test_cgcore_invalid_domain+0x1d5>
mov    -0x28(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x20(%rbp)
je     1369 <test_cgcore_invalid_domain+0x1e9>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x18(%rbp)
je     137d <test_cgcore_invalid_domain+0x1fd>
mov    -0x18(%rbp),%rdi
call   1030 <cg_destroy@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_cgcore_invalid_domain>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbp
lea    0xe6b(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,%r14
lea    0xe70(%rip),%rsi
mov    %rbp,%rdi
call   1050 <cg_name@plt>
mov    %rax,%r15
lea    0xe81(%rip),%rsi
mov    %rbp,%rdi
call   1050 <cg_name@plt>
mov    %rax,%rbx
mov    $0x1,%r12d
test   %r15,%r15
je     1233 <test_cgcore_invalid_domain+0xb3>
test   %rbx,%rbx
je     1233 <test_cgcore_invalid_domain+0xb3>
test   %r14,%r14
je     1233 <test_cgcore_invalid_domain+0xb3>
mov    %r14,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    1233 <test_cgcore_invalid_domain+0xb3>
mov    %r15,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    1233 <test_cgcore_invalid_domain+0xb3>
mov    %rbx,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    1233 <test_cgcore_invalid_domain+0xb3>
lea    0xe64(%rip),%rsi
lea    0xe69(%rip),%rdx
mov    %r15,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    1233 <test_cgcore_invalid_domain+0xb3>
lea    0xe49(%rip),%rsi
lea    0xe57(%rip),%rdx
mov    %rbx,%rdi
call   1080 <cg_read_strcmp@plt>
test   %rax,%rax
je     128c <test_cgcore_invalid_domain+0x10c>
mov    %rbp,%rdi
call   10a0 <cg_enter_current@plt>
test   %rbx,%rbx
je     1248 <test_cgcore_invalid_domain+0xc8>
mov    %rbx,%rdi
call   1030 <cg_destroy@plt>
test   %r15,%r15
je     1255 <test_cgcore_invalid_domain+0xd5>
mov    %r15,%rdi
call   1030 <cg_destroy@plt>
test   %r14,%r14
je     1262 <test_cgcore_invalid_domain+0xe2>
mov    %r14,%rdi
call   1030 <cg_destroy@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
call   10a0 <cg_enter_current@plt>
test   %eax,%eax
je     1233 <test_cgcore_invalid_domain+0xb3>
mov    0x2d31(%rip),%r13
mov    0x0(%r13),%rax
mov    0x2d2e(%rip),%rcx
cmp    (%rcx),%rax
jne    1233 <test_cgcore_invalid_domain+0xb3>
mov    %rbx,%rdi
call   1090 <clone_into_cgroup_run_wait@plt>
test   %eax,%eax
je     1233 <test_cgcore_invalid_domain+0xb3>
mov    0x0(%r13),%rax
mov    0x2d1e(%rip),%rcx
cmp    (%rcx),%rax
setne  %cl
mov    0x2d01(%rip),%rdx
cmp    (%rdx),%rax
setne  %al
and    %cl,%al
movzbl %al,%r12d
jmp    1233 <test_cgcore_invalid_domain+0xb3>

LLVM IR (-O0):
@.str = [20 x i8] c"cg_test_grandparent\00"
@.str.1 = [35 x i8] c"cg_test_grandparent/cg_test_parent\00"
@.str.2 = [49 x i8] c"cg_test_grandparent/cg_test_parent/cg_test_child\00"
@.str.3 = [12 x i8] c"cgroup.type\00"
@.str.4 = [9 x i8] c"threaded\00"
@.str.5 = [16 x i8] c"domain invalid\0A\00"
@errno = global i64 0
@EOPNOTSUPP = global i64 0
@ENOSYS = global i64 0
define i32 @test_cgcore_invalid_domain(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %2
store i32 1, i32* %3
store i8* null, i8** %4
store i8* null, i8** %5
store i8* null, i8** %6
%7 = load i8*, i8** %2
%8 = call i8* @cg_name(i8* %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %4
%9 = load i8*, i8** %2
%10 = call i8* @cg_name(i8* %9, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
store i8* %10, i8** %5
%11 = load i8*, i8** %2
%12 = call i8* @cg_name(i8* %11, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
store i8* %12, i8** %6
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %21
15: ; preds = %1
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %22, label %21
21: ; preds = %18, %15, %1
br label %74
22: ; preds = %18
%23 = load i8*, i8** %4
%24 = call i64 @cg_create(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %22
br label %74
27: ; preds = %22
%28 = load i8*, i8** %5
%29 = call i64 @cg_create(i8* %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
br label %74
32: ; preds = %27
%33 = load i8*, i8** %6
%34 = call i64 @cg_create(i8* %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
br label %74
37: ; preds = %32
%38 = load i8*, i8** %5
%39 = call i64 @cg_write(i8* %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %37
br label %74
42: ; preds = %37
%43 = load i8*, i8** %6
%44 = call i64 @cg_read_strcmp(i8* %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %42
br label %74
47: ; preds = %42
%48 = load i8*, i8** %6
%49 = call i32 @cg_enter_current(i8* %48)
%50 = icmp ne i32 %49, 0
br i1 %50, label %52, label %51
51: ; preds = %47
br label %74
52: ; preds = %47
%53 = load i64, i64* @errno
%54 = load i64, i64* @EOPNOTSUPP
%55 = icmp ne i64 %53, %54
br i1 %55, label %56, label %57
56: ; preds = %52
br label %74
57: ; preds = %52
%58 = load i8*, i8** %6
%59 = call i32 @clone_into_cgroup_run_wait(i8* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %62, label %61
61: ; preds = %57
br label %74
62: ; preds = %57
%63 = load i64, i64* @errno
%64 = load i64, i64* @ENOSYS
%65 = icmp eq i64 %63, %64
br i1 %65, label %66, label %67
66: ; preds = %62
br label %73
67: ; preds = %62
%68 = load i64, i64* @errno
%69 = load i64, i64* @EOPNOTSUPP
%70 = icmp ne i64 %68, %69
br i1 %70, label %71, label %72
71: ; preds = %67
br label %74
72: ; preds = %67
br label %73
73: ; preds = %72, %66
store i32 0, i32* %3
br label %74
74: ; preds = %73, %71, %61, %56, %51, %46, %41, %36, %31, %26, %21
%75 = load i8*, i8** %2
%76 = call i32 @cg_enter_current(i8* %75)
%77 = load i8*, i8** %6
%78 = icmp ne i8* %77, null
br i1 %78, label %79, label %82
79: ; preds = %74
%80 = load i8*, i8** %6
%81 = call i32 @cg_destroy(i8* %80)
br label %82
82: ; preds = %79, %74
%83 = load i8*, i8** %5
%84 = icmp ne i8* %83, null
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = load i8*, i8** %5
%87 = call i32 @cg_destroy(i8* %86)
br label %88
88: ; preds = %85, %82
%89 = load i8*, i8** %4
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i8*, i8** %4
%93 = call i32 @cg_destroy(i8* %92)
br label %94
94: ; preds = %91, %88
%95 = load i8*, i8** %6
%96 = call i32 @free(i8* %95)
%97 = load i8*, i8** %5
%98 = call i32 @free(i8* %97)
%99 = load i8*, i8** %4
%100 = call i32 @free(i8* %99)
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@.str = [20 x i8] c"cg_test_grandparent\00"
@.str.1 = [35 x i8] c"cg_test_grandparent/cg_test_parent\00"
@.str.2 = [49 x i8] c"cg_test_grandparent/cg_test_parent/cg_test_child\00"
@.str.3 = [12 x i8] c"cgroup.type\00"
@.str.4 = [9 x i8] c"threaded\00"
@.str.5 = [16 x i8] c"domain invalid\0A\00"
@errno = global i64 0
@EOPNOTSUPP = global i64 0
@ENOSYS = global i64 0
define i32 @test_cgcore_invalid_domain(i8* %0) {
%2 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%3 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0))
%4 = tail call i8* @cg_name(i8* %0, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp ne i8* %3, null
%6 = icmp ne i8* %4, null
%7 = select i1 %5, i1 %6, i1 false
%8 = icmp ne i8* %2, null
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %10, label %43
10: ; preds = %1
%11 = tail call i64 @cg_create(i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %43
13: ; preds = %10
%14 = tail call i64 @cg_create(i8* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %43
16: ; preds = %13
%17 = tail call i64 @cg_create(i8* %4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %43
19: ; preds = %16
%20 = tail call i64 @cg_write(i8* %3, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %43
22: ; preds = %19
%23 = tail call i64 @cg_read_strcmp(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %43
25: ; preds = %22
%26 = tail call i32 @cg_enter_current(i8* %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %43, label %28
28: ; preds = %25
%29 = load i64, i64* @errno
%30 = load i64, i64* @EOPNOTSUPP
%31 = icmp eq i64 %29, %30
br i1 %31, label %32, label %43
32: ; preds = %28
%33 = tail call i32 @clone_into_cgroup_run_wait(i8* %4)
%34 = icmp eq i32 %33, 0
br i1 %34, label %43, label %35
35: ; preds = %32
%36 = load i64, i64* @errno
%37 = load i64, i64* @ENOSYS
%38 = icmp ne i64 %36, %37
%39 = load i64, i64* @EOPNOTSUPP
%40 = icmp ne i64 %36, %39
%41 = select i1 %38, i1 %40, i1 false
%42 = zext i1 %41 to i32
br label %43
43: ; preds = %35, %32, %28, %25, %22, %19, %16, %13, %10, %1
%44 = phi i32 [ 1, %10 ], [ 1, %13 ], [ 1, %16 ], [ 1, %19 ], [ 1, %22 ], [ 1, %28 ], [ 1, %32 ], [ 1, %25 ], [ 1, %1 ], [ %42, %35 ]
%45 = tail call i32 @cg_enter_current(i8* %0)
br i1 %6, label %46, label %48
46: ; preds = %43
%47 = tail call i32 @cg_destroy(i8* %4)
br label %48
48: ; preds = %46, %43
br i1 %5, label %49, label %51
49: ; preds = %48
%50 = tail call i32 @cg_destroy(i8* %3)
br label %51
51: ; preds = %49, %48
br i1 %8, label %52, label %54
52: ; preds = %51
%53 = tail call i32 @cg_destroy(i8* %2)
br label %54
54: ; preds = %52, %51
%55 = tail call i32 @free(i8* %4)
%56 = tail call i32 @free(i8* %3)
%57 = tail call i32 @free(i8* %2)
ret i32 %44
}