#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 */
struct cgroup_node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ ENAMETOOLONG;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ asprintf(char **, char *, long);
struct cgroup_node *create_cgroup(char const *, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
scalar_t__ getpid();
int /*<<< orphan*/ log_error(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
struct cgroup_node *create_cgroup_root(const char *root_path) {
  struct cgroup_node *root;
  char *path;
  if (asprintf(&path, "cgt-%ld", (long int)getpid()) < 0)
    do {
      log_error("ERROR: %s: "
                "asprintf"
                "\n",
                strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  root = create_cgroup(root_path, path);
  if (!root)
    do {
      errno = ENAMETOOLONG;
      log_error("ERROR: %s: "
                "create root node"
                "\n",
                strerror(errno));
      exit(EXIT_FAILURE);
    } while (0);
  free(path);
  return root;
}


x86 assembly (clang, -O0):
<create_cgroup_root>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,%rdx
lea    -0x18(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <asprintf@plt>
cmp    $0x0,%rax
jge    11cf <create_cgroup_root+0x5f>
jmp    11a5 <create_cgroup_root+0x35>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe4c(%rip),%rdi
call   1050 <log_error@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <create_cgroup@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    122c <create_cgroup_root+0xbc>
jmp    11f0 <create_cgroup_root+0x80>
mov    0x2dd9(%rip),%rax
mov    (%rax),%ecx
mov    0x2de0(%rip),%rax
mov    %ecx,(%rax)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %eax,%esi
lea    0xe04(%rip),%rdi
call   1050 <log_error@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_cgroup_root>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe7a(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rax,%rdx
call   1070 <asprintf@plt>
test   %rax,%rax
js     11c0 <create_cgroup_root+0x50>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <create_cgroup@plt>
test   %rax,%rax
je     11d7 <create_cgroup_root+0x67>
mov    %rax,%rbx
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe33(%rip),%rdi
jmp    11f5 <create_cgroup_root+0x85>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2df9(%rip),%rax
mov    %edi,(%rax)
call   1090 <strerror@plt>
lea    0xe28(%rip),%rdi
mov    %eax,%esi
call   1050 <log_error@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.cgroup_node = type { i32 }
@.str = [8 x i8] c"cgt-%ld\00"
@.str.1 = [21 x i8] c"ERROR: %s: asprintf\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@ENAMETOOLONG = global i32 0
@.str.2 = [29 x i8] c"ERROR: %s: create root node\0A\00"
define %struct.cgroup_node* @create_cgroup_root(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.cgroup_node*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = call i64 (...) @getpid()
%6 = call i64 @asprintf(i8** %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %16
8: ; preds = %1
br label %9
9: ; preds = %8
%10 = load i32, i32* @errno
%11 = call i32 @strerror(i32 %10)
%12 = call i32 @log_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; No predecessors!
br label %16
16: ; preds = %15, %1
%17 = load i8*, i8** %2
%18 = load i8*, i8** %4
%19 = call %struct.cgroup_node* @create_cgroup(i8* %17, i8* %18)
store %struct.cgroup_node* %19, %struct.cgroup_node** %3
%20 = load %struct.cgroup_node*, %struct.cgroup_node** %3
%21 = icmp ne %struct.cgroup_node* %20, null
br i1 %21, label %31, label %22
22: ; preds = %16
br label %23
23: ; preds = %22
%24 = load i32, i32* @ENAMETOOLONG
store i32 %24, i32* @errno
%25 = load i32, i32* @errno
%26 = call i32 @strerror(i32 %25)
%27 = call i32 @log_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; No predecessors!
br label %31
31: ; preds = %30, %16
%32 = load i8*, i8** %4
%33 = call i32 @free(i8* %32)
%34 = load %struct.cgroup_node*, %struct.cgroup_node** %3
ret %struct.cgroup_node* %34
}

LLVM IR (-O2):
%struct.cgroup_node = type { i32 }
@.str = [8 x i8] c"cgt-%ld\00"
@.str.1 = [21 x i8] c"ERROR: %s: asprintf\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@ENAMETOOLONG = global i32 0
@.str.2 = [29 x i8] c"ERROR: %s: create root node\0A\00"
define %struct.cgroup_node* @create_cgroup_root(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = tail call i64 (...) @getpid()
%5 = call i64 @asprintf(i8** %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i64 %4)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* @errno
%9 = call i32 @strerror(i32 %8)
%10 = call i32 @log_error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = load i8*, i8** %2
%15 = call %struct.cgroup_node* @create_cgroup(i8* %0, i8* %14)
%16 = icmp eq %struct.cgroup_node* %15, null
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = load i32, i32* @ENAMETOOLONG
store i32 %18, i32* @errno
%19 = call i32 @strerror(i32 %18)
%20 = call i32 @log_error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = load i8*, i8** %2
%25 = call i32 @free(i8* %24)
ret %struct.cgroup_node* %15
}