#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 */
int asprintf(char **, char *, ...);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ free(char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ stripBeerFridgeCgroup(char *);
int /*<<< orphan*/ system2(char *);
void addToCGroup(const char *typeSignifier, char *locationSignifier,
                 char *currentCgroup, long pid, long createDirectory) {
  char *directoryBuffer;
  char *echoBuffer;
  int errorCheck;
  char *newCheckLoc;
  stripBeerFridgeCgroup(currentCgroup);
  if (currentCgroup[0] == '\0' || strcmp(currentCgroup, "/") == 0) {
    errorCheck = asprintf(&directoryBuffer, "/sys/fs/cgroup/%s/%s",
                          typeSignifier, locationSignifier);
  } else {
    errorCheck = asprintf(&directoryBuffer, "/sys/fs/cgroup/%s%s/%s",
                          typeSignifier, currentCgroup, locationSignifier);
  }
  assert(errorCheck != -1);
  if (createDirectory) {
    char *mkdirBuffer;
    errorCheck = asprintf(&mkdirBuffer, "mkdir -p %s", directoryBuffer);
    assert(errorCheck != -1);
    system2(mkdirBuffer);
    free(mkdirBuffer);
  }
  errorCheck =
      asprintf(&echoBuffer, "echo %d > %s/cgroup.procs", pid, directoryBuffer);
  assert(errorCheck != -1);
  system2(echoBuffer);
  free(directoryBuffer);
  free(echoBuffer);
}


x86 assembly (clang, -O0):
<addToCGroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <stripBeerFridgeCgroup@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11af <addToCGroup+0x4f>
mov    -0x18(%rbp),%rdi
lea    0xe60(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d1 <addToCGroup+0x71>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x30(%rbp),%rdi
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
mov    %eax,-0x3c(%rbp)
jmp    11f2 <addToCGroup+0x92>
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    -0x30(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x28(%rbp)
je     124a <addToCGroup+0xea>
mov    -0x30(%rbp),%rdx
lea    -0x50(%rbp),%rdi
lea    0xe11(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x50(%rbp),%rdi
call   1040 <system2@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%rdi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1070 <asprintf@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x38(%rbp),%rdi
call   1040 <system2@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addToCGroup>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %r8,%r15
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
mov    %rdx,%rdi
call   1080 <stripBeerFridgeCgroup@plt>
cmpb   $0x0,(%rbx)
je     11bb <addToCGroup+0x5b>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11bb <addToCGroup+0x5b>
lea    0xe73(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1070 <asprintf@plt>
jmp    11d4 <addToCGroup+0x74>
lea    0xe40(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r13,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1070 <asprintf@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
test   %r15,%r15
je     121d <addToCGroup+0xbd>
mov    0x8(%rsp),%rdx
lea    0xe3b(%rip),%rsi
mov    %rsp,%rdi
xor    %eax,%eax
call   1070 <asprintf@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
call   1040 <system2@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rcx
lea    0xe11(%rip),%rsi
mov    %rsp,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <asprintf@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
call   1040 <system2@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [21 x i8] c"/sys/fs/cgroup/%s/%s\00"
@.str.2 = [23 x i8] c"/sys/fs/cgroup/%s%s/%s\00"
@.str.3 = [12 x i8] c"mkdir -p %s\00"
@.str.4 = [26 x i8] c"echo %d > %s/cgroup.procs\00"
define void @addToCGroup(i8* %0, i8* %1, i8* %2, i64 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%16 = load i8*, i8** %8
%17 = call i32 @stripBeerFridgeCgroup(i8* %16)
%18 = load i8*, i8** %8
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %5
%24 = load i8*, i8** %8
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %23, %5
%28 = load i8*, i8** %6
%29 = load i8*, i8** %7
%30 = call i32 (i8**, i8*, ...) @asprintf(i8** %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29)
store i32 %30, i32* %13
br label %36
31: ; preds = %23
%32 = load i8*, i8** %6
%33 = load i8*, i8** %8
%34 = load i8*, i8** %7
%35 = call i32 (i8**, i8*, ...) @asprintf(i8** %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %32, i8* %33, i8* %34)
store i32 %35, i32* %13
br label %36
36: ; preds = %31, %27
%37 = load i32, i32* %13
%38 = icmp ne i32 %37, -1
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i64, i64* %10
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %54
43: ; preds = %36
%44 = load i8*, i8** %11
%45 = call i32 (i8**, i8*, ...) @asprintf(i8** %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %44)
store i32 %45, i32* %13
%46 = load i32, i32* %13
%47 = icmp ne i32 %46, -1
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i8*, i8** %15
%51 = call i32 @system2(i8* %50)
%52 = load i8*, i8** %15
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %43, %36
%55 = load i64, i64* %9
%56 = load i8*, i8** %11
%57 = call i32 (i8**, i8*, ...) @asprintf(i8** %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i64 %55, i8* %56)
store i32 %57, i32* %13
%58 = load i32, i32* %13
%59 = icmp ne i32 %58, -1
%60 = zext i1 %59 to i32
%61 = call i32 @assert(i32 %60)
%62 = load i8*, i8** %12
%63 = call i32 @system2(i8* %62)
%64 = load i8*, i8** %11
%65 = call i32 @free(i8* %64)
%66 = load i8*, i8** %12
%67 = call i32 @free(i8* %66)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [21 x i8] c"/sys/fs/cgroup/%s/%s\00"
@.str.2 = [23 x i8] c"/sys/fs/cgroup/%s%s/%s\00"
@.str.3 = [12 x i8] c"mkdir -p %s\00"
@.str.4 = [26 x i8] c"echo %d > %s/cgroup.procs\00"
define void @addToCGroup(i8* %0, i8* %1, i8* %2, i64 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = bitcast i8** %6 to i8*
%10 = bitcast i8** %7 to i8*
%11 = tail call i32 @stripBeerFridgeCgroup(i8* %2)
%12 = load i8, i8* %2
%13 = icmp eq i8 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %5
%15 = tail call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14, %5
%18 = call i32 (i8**, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %21
19: ; preds = %14
%20 = call i32 (i8**, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %2, i8* %1)
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %18, %17 ], [ %20, %19 ]
%23 = icmp ne i32 %22, -1
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = icmp eq i64 %4, 0
br i1 %26, label %38, label %27
27: ; preds = %21
%28 = bitcast i8** %8 to i8*
%29 = load i8*, i8** %6
%30 = call i32 (i8**, i8*, ...) @asprintf(i8** %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %29)
%31 = icmp ne i32 %30, -1
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i8*, i8** %8
%35 = call i32 @system2(i8* %34)
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %27, %21
%39 = load i8*, i8** %6
%40 = call i32 (i8**, i8*, ...) @asprintf(i8** %7, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i64 %3, i8* %39)
%41 = icmp ne i32 %40, -1
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i8*, i8** %7
%45 = call i32 @system2(i8* %44)
%46 = load i8*, i8** %6
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %7
%49 = call i32 @free(i8* %48)
ret void
}