// File: /workspace/github_c_makefile_star2_O2/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, %r14
movl %esi, 0x1c(%rsp)
movl %edi, %esi
leaq 0x68e5(%rip), %rdi      # 0xed9a
xorl %eax, %eax
callq 0x4380
leaq 0x5fc9(%rip), %rsi      # 0xe48c
movq %rax, 0x10(%rsp)
movq %rax, %rdi
callq 0x4260
movq %rax, 0x30(%rsp)
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x8705
leaq 0x8(%rsp), %rax
andq $0x0, (%rax)
leaq 0x28(%rsp), %rax
andq $0x0, (%rax)
pushq $0x3a
popq %rbx
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x4640
cmpq $-0x1, %rax
je 0x871b
movq 0x8(%rsp), %r12
movq %r12, %rdi
movl %ebx, %esi
callq 0x4560
testq %rax, %rax
je 0x8585
movq %rax, %r13
incq %r13
movq %r13, %rdi
movl %ebx, %esi
callq 0x4560
testq %rax, %rax
je 0x85a7
movq %rax, %rbx
movb $0x0, (%rax)
incq %rbx
cmpb $0x0, 0x1c(%rsp)
je 0x85c9
xorl %ebp, %ebp
leaq 0x694f(%rip), %rdi      # 0xeea7
leaq 0x6660(%rip), %rsi      # 0xebbf
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4380
movq %rax, %rbx
movq %rax, %rdi
callq 0x4360
movq %rbx, (%rsp)
movb $0x0, -0x1(%rbx,%rax)
xorl %r15d, %r15d
jmp 0x864a
leaq 0xbf18(%rip), %rax      # 0x144a4
cmpl $0x0, (%rax)
jne 0x8663
xorl %ebp, %ebp
xorl %r15d, %r15d
movq $0x0, (%rsp)
jmp 0x864d
leaq 0xbef6(%rip), %rax      # 0x144a4
cmpl $0x0, (%rax)
jne 0x86aa
xorl %ebp, %ebp
xorl %r15d, %r15d
movq $0x0, (%rsp)
jmp 0x864a
movq %r13, %rdi
leaq 0x68cf(%rip), %rsi      # 0xeea2
pushq $-0x1
popq %rdx
callq 0x4660
movq %rax, %rbp
movq %rax, %r12
movq (%r12), %r15
testq %r15, %r15
je 0x8647
movq %r15, %rdi
movq %r14, %rsi
callq 0x4620
addq $0x8, %r12
testl %eax, %eax
jne 0x85e1
movq %r15, %rdi
pushq $0x3d
popq %rsi
callq 0x4560
testq %rax, %rax
je 0x8613
movb $0x0, (%rax)
movq %rax, %r13
xorl %r15d, %r15d
leaq 0x6887(%rip), %rdi      # 0xeea4
leaq 0x659b(%rip), %rsi      # 0xebbf
movq %r13, %rdx
movq %rbx, %rcx
xorl %eax, %eax
callq 0x4380
movq %rax, %rbx
movq %rax, %rdi
callq 0x4360
movq %rbx, (%rsp)
movb $0x0, -0x1(%rbx,%rax)
jmp 0x864a
movb $0x1, %r15b
pushq $0x3a
popq %rbx
movq %rbp, %rdi
callq 0x47a0
testb %r15b, %r15b
jne 0x84f8
jmp 0x8723
movq 0xb986(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
xorl %r15d, %r15d
leaq 0x6733(%rip), %rsi      # 0xedaa
movq %r12, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x20850(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x86fe
leaq 0x2083c(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
movq 0x8(%rsp), %rcx
xorl %ebp, %ebp
pushq $0x6
popq %rdi
leaq 0x6737(%rip), %rsi      # 0xeddf
jmp 0x86f2
movq 0xb93f(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
xorl %r15d, %r15d
leaq 0x6761(%rip), %rsi      # 0xee1f
movq %r12, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x20809(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
pushq $0x3a
popq %rbx
je 0x86fe
leaq 0x207f2(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
movq 0x8(%rsp), %rcx
xorl %ebp, %ebp
pushq $0x6
popq %rdi
leaq 0x6769(%rip), %rsi      # 0xee5b
xorl %eax, %eax
callq 0x4120
jmp 0x8597
xorl %ebp, %ebp
jmp 0x859a
leaq 0xbd98(%rip), %rax      # 0x144a4
cmpl $0x0, (%rax)
jne 0x875a
xorl %r14d, %r14d
movq 0x10(%rsp), %rbx
jmp 0x8736
movq $0x0, (%rsp)
movq 0x8(%rsp), %rdi
callq 0x48f8
movq 0x10(%rsp), %rbx
movq (%rsp), %r14
leaq 0x30(%rsp), %rdi
callq 0x8480
movq %rbx, %rdi
callq 0x48f8
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xb88f(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x6471(%rip), %rsi      # 0xebdc
xorl %r14d, %r14d
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4830
leaq 0x20754(%rip), %rax     # 0x28ed8
cmpl $0x0, (%rax)
je 0x8736
leaq 0x20740(%rip), %rax     # 0x28ed0
movq (%rax), %rdx
leaq 0x646f(%rip), %rsi      # 0xec09
xorl %r14d, %r14d
pushq $0x6
popq %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x4120
jmp 0x8736