// File: /workspace/github_c_makefile_star2_O1/containers[P]conmon/src/cgroup.c
// Function: process_cgroup_subsystem_path
static char *process_cgroup_subsystem_path(int pid, bool cgroup2, const char *subsystem)
{
	_cleanup_free_ char *cgroups_file_path = g_strdup_printf("/proc/%d/cgroup", pid);
	_cleanup_fclose_ FILE *fp = fopen(cgroups_file_path, "re");
	if (fp == NULL) {
		nwarnf("Failed to open cgroups file: %s", cgroups_file_path);
		return NULL;
	}

	_cleanup_free_ char *line = NULL;
	ssize_t read;
	size_t len = 0;
	char *ptr, *path;
	while ((read = getline(&line, &len, fp)) != -1) {
		_cleanup_strv_ char **subsystems = NULL;
		ptr = strchr(line, ':');
		if (ptr == NULL) {
			nwarnf("Error parsing cgroup, ':' not found: %s", line);
			return NULL;
		}
		ptr++;
		path = strchr(ptr, ':');
		if (path == NULL) {
			nwarnf("Error parsing cgroup, second ':' not found: %s", line);
			return NULL;
		}
		*path = 0;
		path++;
		if (cgroup2) {
			char *subsystem_path = g_strdup_printf("%s%s", CGROUP_ROOT, path);
			subsystem_path[strlen(subsystem_path) - 1] = '\0';
			return subsystem_path;
		}
		subsystems = g_strsplit(ptr, ",", -1);
		for (int i = 0; subsystems[i] != NULL; i++) {
			if (strcmp(subsystems[i], subsystem) == 0) {
				char *subpath = strchr(subsystems[i], '=');
				if (subpath == NULL) {
					subpath = ptr;
				} else {
					*subpath = 0;
				}

				char *subsystem_path = g_strdup_printf("%s/%s%s", CGROUP_ROOT, subpath, path);
				subsystem_path[strlen(subsystem_path) - 1] = '\0';
				return subsystem_path;
			}
		}
	}

	return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x28(%rsp)
movl %esi, 0x14(%rsp)
movl %edi, %esi
leaq 0x4776(%rip), %rdi      # 0xedba
xorl %eax, %eax
callq 0x4380
leaq 0x3e5a(%rip), %rsi      # 0xe4ac
movq %rax, 0x18(%rsp)
movq %rax, %rdi
callq 0x4260
movq %rax, %r14
testq %rax, %rax
je 0xa8a0
xorl %eax, %eax
movq %rsp, %rcx
movq %rax, (%rcx)
leaq 0x30(%rsp), %rcx
movq %rax, (%rcx)
movq %r14, 0x8(%rsp)
movq %rsp, %rdi
leaq 0x30(%rsp), %rsi
movq %r14, %rdx
callq 0x4630
cmpq $-0x1, %rax
je 0xa8b1
movq (%rsp), %rbp
movq %rbp, %rdi
movl $0x3a, %esi
callq 0x4550
testq %rax, %rax
je 0xa715
movq %rax, %r12
movq %r13, 0x20(%rsp)
incq %r12
movq %r12, %rdi
movl $0x3a, %esi
callq 0x4550
testq %rax, %rax
je 0xa770
movq %rax, %r13
movb $0x0, (%rax)
incq %r13
cmpb $0x0, 0x14(%rsp)
je 0xa79e
xorl %ebx, %ebx
leaq 0x47d9(%rip), %rdi      # 0xeec7
leaq 0x44ea(%rip), %rsi      # 0xebdf
movq %r13, %rdx
xorl %eax, %eax
callq 0x4380
movq %rax, %r13
movq %rax, %rdi
callq 0x4360
movb $0x0, -0x1(%r13,%rax)
xorl %r15d, %r15d
jmp 0xa788
leaq 0xad78(%rip), %rax      # 0x15494
cmpl $0x0, (%rax)
je 0xa780
movq 0xa8c8(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
xorl %r15d, %r15d
leaq 0x4695(%rip), %rsi      # 0xedca
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4820
leaq 0x1f782(%rip), %rax     # 0x29ec8
cmpl $0x0, (%rax)
je 0xa899
leaq 0x1f76a(%rip), %rax     # 0x29ec0
movq (%rax), %rdx
movq (%rsp), %rcx
xorl %ebx, %ebx
movl $0x6, %edi
leaq 0x4694(%rip), %rsi      # 0xedff
jmp 0xa88d
leaq 0xad1d(%rip), %rax      # 0x15494
cmpl $0x0, (%rax)
jne 0xa847
xorl %ebx, %ebx
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %rbx, %rdi
callq 0x4790
testb %r15b, %r15b
jne 0xa680
jmp 0xa8b4
movq %r12, %rdi
leaq 0x471a(%rip), %rsi      # 0xeec2
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4650
movq %rax, %rbx
movq (%rax), %r14
testq %r14, %r14
sete %r15b
je 0xa7ea
movq %rbx, %rbp
addq $0x8, %rbp
movq %r14, %rdi
movq 0x28(%rsp), %rsi
callq 0x4610
testl %eax, %eax
je 0xa7f6
movq (%rbp), %r14
addq $0x8, %rbp
testq %r14, %r14
sete %r15b
jne 0xa7c8
movq 0x8(%rsp), %r14
movq 0x20(%rsp), %r13
jmp 0xa788
movq %r14, %rdi
movl $0x3d, %esi
callq 0x4550
testq %rax, %rax
je 0xa80e
movb $0x0, (%rax)
movq %rax, %r12
xorl %r15d, %r15d
leaq 0x46ac(%rip), %rdi      # 0xeec4
leaq 0x43c0(%rip), %rsi      # 0xebdf
movq %r12, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x4380
movq %rax, %r13
movq %rax, %rdi
callq 0x4360
movb $0x0, -0x1(%r13,%rax)
movq 0x8(%rsp), %r14
jmp 0xa788
movq 0xa7a2(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
xorl %r15d, %r15d
leaq 0x45e4(%rip), %rsi      # 0xee3f
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4820
leaq 0x1f65c(%rip), %rax     # 0x29ec8
cmpl $0x0, (%rax)
je 0xa899
leaq 0x1f648(%rip), %rax     # 0x29ec0
movq (%rax), %rdx
movq (%rsp), %rcx
xorl %ebx, %ebx
movl $0x6, %edi
leaq 0x45ee(%rip), %rsi      # 0xee7b
xorl %eax, %eax
callq 0x4120
jmp 0xa782
xorl %ebx, %ebx
jmp 0xa785
leaq 0xabed(%rip), %rax      # 0x15494
cmpl $0x0, (%rax)
jne 0xa8e6
xorl %r13d, %r13d
jmp 0xa8bd
xorl %r13d, %r13d
movq (%rsp), %rdi
callq 0x48e8
testq %r14, %r14
je 0xa8ca
movq %r14, %rdi
callq 0x46b0
movq 0x18(%rsp), %rdi
callq 0x48e8
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rbx
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x656e
movq (%rbx), %r13
jmp 0xa8bd