#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__ 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 *);
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;
  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    0xe5a(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11f8 <test_cgcore_invalid_domain+0x88>
cmpq   $0x0,-0x28(%rbp)
je     11f8 <test_cgcore_invalid_domain+0x88>
cmpq   $0x0,-0x18(%rbp)
jne    11fd <test_cgcore_invalid_domain+0x8d>
jmp    12ce <test_cgcore_invalid_domain+0x15e>
mov    -0x18(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     1215 <test_cgcore_invalid_domain+0xa5>
jmp    12ce <test_cgcore_invalid_domain+0x15e>
mov    -0x20(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     122d <test_cgcore_invalid_domain+0xbd>
jmp    12ce <test_cgcore_invalid_domain+0x15e>
mov    -0x28(%rbp),%rdi
call   1060 <cg_create@plt>
cmp    $0x0,%rax
je     1245 <test_cgcore_invalid_domain+0xd5>
jmp    12ce <test_cgcore_invalid_domain+0x15e>
mov    -0x20(%rbp),%rdi
lea    0xe18(%rip),%rsi
lea    0xe1d(%rip),%rdx
call   1070 <cg_write@plt>
cmp    $0x0,%rax
je     126b <test_cgcore_invalid_domain+0xfb>
jmp    12ce <test_cgcore_invalid_domain+0x15e>
mov    -0x28(%rbp),%rdi
lea    0xdf2(%rip),%rsi
lea    0xe00(%rip),%rdx
call   1080 <cg_read_strcmp@plt>
cmp    $0x0,%rax
je     1291 <test_cgcore_invalid_domain+0x121>
jmp    12ce <test_cgcore_invalid_domain+0x15e>
mov    -0x28(%rbp),%rdi
call   1090 <cg_enter_current@plt>
cmp    $0x0,%eax
jne    12a8 <test_cgcore_invalid_domain+0x138>
jmp    12ce <test_cgcore_invalid_domain+0x15e>
mov    0x2d29(%rip),%rax
mov    (%rax),%rax
mov    0x2d27(%rip),%rcx
cmp    (%rcx),%rax
je     12c7 <test_cgcore_invalid_domain+0x157>
jmp    12ce <test_cgcore_invalid_domain+0x15e>
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <cg_enter_current@plt>
cmpq   $0x0,-0x28(%rbp)
je     12eb <test_cgcore_invalid_domain+0x17b>
mov    -0x28(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x20(%rbp)
je     12ff <test_cgcore_invalid_domain+0x18f>
mov    -0x20(%rbp),%rdi
call   1030 <cg_destroy@plt>
cmpq   $0x0,-0x18(%rbp)
je     1313 <test_cgcore_invalid_domain+0x1a3>
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   %r12
push   %rbx
mov    %rdi,%rbx
lea    0xe7e(%rip),%rsi
call   1050 <cg_name@plt>
mov    %rax,%r14
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
call   1050 <cg_name@plt>
mov    %rax,%r12
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1050 <cg_name@plt>
mov    %rax,%rbp
mov    $0x1,%r15d
test   %r12,%r12
je     1253 <test_cgcore_invalid_domain+0xe3>
test   %rbp,%rbp
je     1253 <test_cgcore_invalid_domain+0xe3>
test   %r14,%r14
je     1253 <test_cgcore_invalid_domain+0xe3>
mov    %r14,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    1253 <test_cgcore_invalid_domain+0xe3>
mov    %r12,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    1253 <test_cgcore_invalid_domain+0xe3>
mov    %rbp,%rdi
call   1060 <cg_create@plt>
test   %rax,%rax
jne    1253 <test_cgcore_invalid_domain+0xe3>
lea    0xe6b(%rip),%rsi
lea    0xe70(%rip),%rdx
mov    %r12,%rdi
call   1070 <cg_write@plt>
test   %rax,%rax
jne    1253 <test_cgcore_invalid_domain+0xe3>
lea    0xe50(%rip),%rsi
lea    0xe5e(%rip),%rdx
mov    %rbp,%rdi
call   1080 <cg_read_strcmp@plt>
test   %rax,%rax
jne    1253 <test_cgcore_invalid_domain+0xe3>
mov    %rbp,%rdi
call   1090 <cg_enter_current@plt>
test   %eax,%eax
je     1253 <test_cgcore_invalid_domain+0xe3>
mov    0x2d99(%rip),%rax
mov    (%rax),%rax
mov    0x2d97(%rip),%rcx
xor    %r15d,%r15d
cmp    (%rcx),%rax
setne  %r15b
mov    %rbx,%rdi
call   1090 <cg_enter_current@plt>
test   %rbp,%rbp
je     1268 <test_cgcore_invalid_domain+0xf8>
mov    %rbp,%rdi
call   1030 <cg_destroy@plt>
test   %r12,%r12
je     1275 <test_cgcore_invalid_domain+0x105>
mov    %r12,%rdi
call   1030 <cg_destroy@plt>
test   %r14,%r14
je     1282 <test_cgcore_invalid_domain+0x112>
mov    %r14,%rdi
call   1030 <cg_destroy@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
mov    %r14,%rdi
call   1040 <free@plt>
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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
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 %58
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 %58
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 %58
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 %58
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 %58
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 %58
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 %58
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 %58
57: ; preds = %52
store i32 0, i32* %3
br label %58
58: ; preds = %57, %56, %51, %46, %41, %36, %31, %26, %21
%59 = load i8*, i8** %2
%60 = call i32 @cg_enter_current(i8* %59)
%61 = load i8*, i8** %6
%62 = icmp ne i8* %61, null
br i1 %62, label %63, label %66
63: ; preds = %58
%64 = load i8*, i8** %6
%65 = call i32 @cg_destroy(i8* %64)
br label %66
66: ; preds = %63, %58
%67 = load i8*, i8** %5
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = load i8*, i8** %5
%71 = call i32 @cg_destroy(i8* %70)
br label %72
72: ; preds = %69, %66
%73 = load i8*, i8** %4
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = load i8*, i8** %4
%77 = call i32 @cg_destroy(i8* %76)
br label %78
78: ; preds = %75, %72
%79 = load i8*, i8** %6
%80 = call i32 @free(i8* %79)
%81 = load i8*, i8** %5
%82 = call i32 @free(i8* %81)
%83 = load i8*, i8** %4
%84 = call i32 @free(i8* %83)
%85 = load i32, i32* %3
ret i32 %85
}

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
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 %33
10: ; preds = %1
%11 = tail call i64 @cg_create(i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %33
13: ; preds = %10
%14 = tail call i64 @cg_create(i8* %3)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = tail call i64 @cg_create(i8* %4)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %33
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 %33
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 %33
25: ; preds = %22
%26 = tail call i32 @cg_enter_current(i8* %4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %33, label %28
28: ; preds = %25
%29 = load i64, i64* @errno
%30 = load i64, i64* @EOPNOTSUPP
%31 = icmp ne i64 %29, %30
%32 = zext i1 %31 to i32
br label %33
33: ; preds = %28, %25, %22, %19, %16, %13, %10, %1
%34 = phi i32 [ 1, %10 ], [ 1, %13 ], [ 1, %16 ], [ 1, %19 ], [ 1, %22 ], [ 1, %25 ], [ 1, %1 ], [ %32, %28 ]
%35 = tail call i32 @cg_enter_current(i8* %0)
br i1 %6, label %36, label %38
36: ; preds = %33
%37 = tail call i32 @cg_destroy(i8* %4)
br label %38
38: ; preds = %36, %33
br i1 %5, label %39, label %41
39: ; preds = %38
%40 = tail call i32 @cg_destroy(i8* %3)
br label %41
41: ; preds = %39, %38
br i1 %8, label %42, label %44
42: ; preds = %41
%43 = tail call i32 @cg_destroy(i8* %2)
br label %44
44: ; preds = %42, %41
%45 = tail call i32 @free(i8* %4)
%46 = tail call i32 @free(i8* %3)
%47 = tail call i32 @free(i8* %2)
ret i32 %34
}