// File: /workspace/github_c_makefile_star2_O3/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, %r13
movl %esi, 0x24(%rsp)
movl %edi, %esi
leaq 0x494a(%rip), %rdi      # 0xed9a
xorl %eax, %eax
callq 0x4380
movq %rax, %r14
leaq 0x402b(%rip), %rsi      # 0xe48c
movq %rax, %rdi
callq 0x4260
testq %rax, %rax
je 0xa56a
movq %rax, %r12
xorl %r15d, %r15d
leaq 0x10(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x30(%rsp), %rsi
movq %r15, (%rsi)
movq %rax, %rdx
callq 0x4630
cmpq $-0x1, %rax
je 0xa682
movq %r14, 0x8(%rsp)
xorl %r15d, %r15d
movq %r12, 0x28(%rsp)
movq 0x10(%rsp), %rbp
movq %rbp, %rdi
movl $0x3a, %esi
callq 0x4550
testq %rax, %rax
je 0xa5dd
movq %rax, %r14
incq %r14
movq %r14, %rdi
movl $0x3a, %esi
callq 0x4550
testq %rax, %rax
je 0xa62e
movq %rax, %rbx
movb $0x0, (%rax)
cmpb $0x0, 0x24(%rsp)
jne 0xa646
movq %r14, %rdi
leaq 0x49a9(%rip), %rsi      # 0xeea2
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x4650
movq %rax, 0x18(%rsp)
movq (%rax), %rbp
testq %rbp, %rbp
je 0xa535
movq 0x18(%rsp), %r12
addq $0x8, %r12
movq %rbp, %rdi
movq %r13, %rsi
callq 0x4610
testl %eax, %eax
je 0xa582
movq (%r12), %rbp
addq $0x8, %r12
testq %rbp, %rbp
jne 0xa519
movq 0x18(%rsp), %rdi
callq 0x4790
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
movq 0x28(%rsp), %r12
movq %r12, %rdx
callq 0x4630
cmpq $-0x1, %rax
jne 0xa4a7
movq 0x8(%rsp), %r14
jmp 0xa682
leaq 0xaf23(%rip), %rax      # 0x15494
cmpl $0x0, (%rax)
jne 0xa6ae
xorl %r15d, %r15d
jmp 0xa694
incq %rbx
movq %rbp, %rdi
movl $0x3d, %esi
callq 0x4550
testq %rax, %rax
je 0xa59d
movb $0x0, (%rax)
movq %rax, %r14
leaq 0x4900(%rip), %rdi      # 0xeea4
leaq 0x4614(%rip), %rsi      # 0xebbf
movq %r14, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x4380
movq %rax, %r15
movq %rax, %rdi
callq 0x4360
movb $0x0, -0x1(%r15,%rax)
movq 0x8(%rsp), %r14
movq 0x28(%rsp), %r12
movq 0x18(%rsp), %r13
jmp 0xa67a
leaq 0xaeb0(%rip), %rax      # 0x15494
cmpl $0x0, (%rax)
je 0xa63e
movq 0xaa00(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x47b0(%rip), %rsi      # 0xedaa
xorl %r13d, %r13d
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4820
leaq 0x1f8ba(%rip), %rax     # 0x29ec8
cmpl $0x0, (%rax)
je 0xa641
leaq 0x1f8a6(%rip), %rax     # 0x29ec0
movq (%rax), %rdx
movq 0x10(%rsp), %rcx
leaq 0x47b6(%rip), %rsi      # 0xeddf
jmp 0xa707
leaq 0xae5f(%rip), %rax      # 0x15494
cmpl $0x0, (%rax)
jne 0xa6c3
xorl %r13d, %r13d
xorl %r15d, %r15d
jmp 0xa675
incq %rbx
leaq 0x4857(%rip), %rdi      # 0xeea7
leaq 0x4568(%rip), %rsi      # 0xebbf
xorl %r13d, %r13d
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4380
movq %rax, %r15
movq %rax, %rdi
callq 0x4360
movb $0x0, -0x1(%r15,%rax)
movq 0x8(%rsp), %r14
movq %r13, %rdi
callq 0x4790
movq 0x10(%rsp), %rdi
callq 0x48e8
movq %r12, %rdi
callq 0x46b0
movq %r14, %rdi
callq 0x48e8
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x6505
movq (%rbx), %r15
jmp 0xa694
movq 0xa926(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x474b(%rip), %rsi      # 0xee1f
xorl %r13d, %r13d
movq %rbp, %rdx
xorl %eax, %eax
callq 0x4820
leaq 0x1f7e0(%rip), %rax     # 0x29ec8
cmpl $0x0, (%rax)
je 0xa641
leaq 0x1f7c8(%rip), %rax     # 0x29ec0
movq (%rax), %rdx
movq 0x10(%rsp), %rcx
leaq 0x4754(%rip), %rsi      # 0xee5b
xorl %r13d, %r13d
movl $0x6, %edi
xorl %eax, %eax
callq 0x4120
jmp 0xa641