// File: /workspace/github_c_makefile_star2_O1/containers[P]conmon/src/cgroup.c
// Function: oom_cb_cgroup_v1
static gboolean oom_cb_cgroup_v1(int fd, GIOCondition condition, gpointer user_data)
{
	char *cgroup_event_control_path = (char *)user_data;
	if ((condition & G_IO_IN) == 0) {
		/* End of input */
		close(fd);
		oom_event_fd = -1;
		g_free(cgroup_event_control_path);
		return G_SOURCE_REMOVE;
	}

	/* Attempt to read the container's cgroup path.
	 * if the cgroup.memory_control file does not exist,
	 * we know one of the events on this fd was a cgroup removal
	 */
	gboolean cgroup_removed = FALSE;
	if (access(cgroup_event_control_path, F_OK) < 0) {
		ndebugf("Memory cgroup removal event received");
		cgroup_removed = TRUE;
	}

	/* there are three cases we need to worry about:
	 * oom kill happened (1 event)
	 * cgroup was removed (1 event)
	 * oom kill happened and cgroup was removed (2 events)
	 */
	uint64_t event_count;
	ssize_t num_read = read(fd, &event_count, sizeof(uint64_t));
	if (num_read < 0) {
		nwarn("Failed to read oom event from eventfd");
		return G_SOURCE_CONTINUE;
	}

	if (num_read == 0) {
		close(fd);
		oom_event_fd = -1;
		g_free(cgroup_event_control_path);
		return G_SOURCE_REMOVE;
	}

	if (num_read != sizeof(uint64_t)) {
		nwarn("Failed to read full oom event from eventfd");
		return G_SOURCE_CONTINUE;
	}

	ndebugf("Memory cgroup event count: %ld", (long)event_count);
	if (event_count == 0) {
		nwarn("Unexpected event count (zero) when reading for oom event");
		return G_SOURCE_CONTINUE;
	}

	/* if there's only one event, and the cgroup was removed
	 * we know the event was for a cgroup removal, not an OOM kill
	 */
	if (event_count == 1 && cgroup_removed)
		return G_SOURCE_CONTINUE;

	/* we catch the two other cases here, both of which are OOM kill events */
	ninfo("OOM event received");
	create_oom_files();

	return G_SOURCE_CONTINUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movl %edi, %ebp
testb $0x1, %sil
jne 0xa9aa
movl %ebp, %edi
callq 0x4100
movl $0xffffffff, 0xb3ce(%rip) # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x48e0
xorl %ebx, %ebx
jmp 0xaa12
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4750
movl %eax, %r14d
leaq 0xaad6(%rip), %r15      # 0x15494
testl %eax, %eax
jns 0xa9cc
cmpl $0x3, (%r15)
jae 0xaa6c
leaq 0x10(%rsp), %rsi
movl $0x8, %edx
movl %ebp, %edi
callq 0x4230
testq %rax, %rax
js 0xaa07
cmpq $0x8, %rax
je 0xaa1f
testq %rax, %rax
je 0xa98d
movl $0x1, %ebx
cmpl $0x0, (%r15)
je 0xaa12
leaq 0xc(%rsp), %rbx
movq %rbx, %rdi
callq 0x6763
jmp 0xaa83
movl $0x1, %ebx
cmpl $0x0, (%r15)
jne 0xaa76
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3, (%r15)
jae 0xaa87
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0xaa52
testl %r14d, %r14d
sets %cl
cmpq $0x1, %rax
sete %al
movl $0x1, %ebx
testb %al, %cl
jne 0xaa12
cmpl $0x2, (%r15)
jae 0xaa93
callq 0xaa9a
jmp 0xaa12
movl $0x1, %ebx
cmpl $0x0, (%r15)
je 0xaa12
leaq 0xc(%rsp), %rbx
movq %rbx, %rdi
callq 0x670a
jmp 0xaa83
callq 0x6622
jmp 0xa9cc
leaq 0xc(%rsp), %rbx
movq %rbx, %rdi
callq 0x67bc
movl (%rbx), %ebx
jmp 0xaa12
leaq 0x10(%rsp), %rdi
callq 0x6669
jmp 0xaa25
callq 0x66b8
jmp 0xaa4b