// File: /workspace/github_c_makefile_star2_O0/arkanis[P]process-map/map.c
// Function: LoadTaskTraces
TaskTraces LoadTaskTraces(char* pid) {
	TaskTraces traces = { 0 };
	traces.focusedTaskIndex = -1;
	
	glEnable(GL_PROGRAM_POINT_SIZE);
	traces.particleShader = LoadShader("particle.vs", "particle.fs");
	int shaderPosLocation = GetShaderLocationAttrib(traces.particleShader, "pos");
	int shaderTimeLocation = GetShaderLocationAttrib(traces.particleShader, "time");
	traces.shaderColorLocation = GetShaderLocation(traces.particleShader, "color");
	traces.shaderCurrentTimeLocation = GetShaderLocation(traces.particleShader, "currentTime");
	
	char* tasksDirPath = NULL;
	asprintf(&tasksDirPath, "/proc/%s/task", pid);
	DIR* tasksDir = opendir(tasksDirPath);
	free(tasksDirPath);
	if (tasksDir == NULL)
		return traces;
	
	TaskSample* emptyParticleBuffer = calloc(particleCount, sizeof(emptyParticleBuffer[0]));
	
	struct dirent *entry;
	while ((entry = readdir(tasksDir)) != NULL) {
		if (entry->d_name[0] == '.')
			continue;
		
		pid_t tid = atoi(entry->d_name);
		
		if ( ptrace(PTRACE_SEIZE, tid, NULL, NULL) != 0 )
			perror("ptrace(PTRACE_SEIZE)");
		
		FILE* taskNameFile = fopen(TextFormat("/proc/%s/task/%d/comm", pid, tid), "rb");
		char* taskName = NULL;
		if (taskNameFile != NULL) {
			fscanf(taskNameFile, "%m[^\n]", &taskName);
			fclose(taskNameFile);
		}
		
		float hue        =       360 * (rand() / (float)RAND_MAX);
		float saturation = 0.5 + 0.5 * (rand() / (float)RAND_MAX);
		float value      = 0.5 + 0.5 * (rand() / (float)RAND_MAX);
		Color color = ColorFromHSV(hue, saturation, value);
		
		GLuint vao = 0, vbo = 0;
		glGenVertexArrays(1, &vao);
		glBindVertexArray(vao);
			glGenBuffers(1, &vbo);
			glBindBuffer(GL_ARRAY_BUFFER, vbo);
				glBufferData(GL_ARRAY_BUFFER, particleCount * sizeof(emptyParticleBuffer[0]), emptyParticleBuffer, GL_DYNAMIC_DRAW);
				glEnableVertexAttribArray(shaderPosLocation);
				glEnableVertexAttribArray(shaderTimeLocation);
				glVertexAttribPointer(shaderPosLocation,  2, GL_FLOAT, GL_FALSE, sizeof(TaskSample), 0);
				glVertexAttribPointer(shaderTimeLocation, 1, GL_UNSIGNED_INT, GL_FALSE, sizeof(TaskSample), (void*)offsetof(TaskSample, t));
			glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindVertexArray(0);
		
		traces.taskCount++;
		traces.tasks = realloc(traces.tasks, traces.taskCount * sizeof(traces.tasks[0]));
		traces.tasks[traces.taskCount - 1] = (Task){
			.pid = tid,
			.name = taskName,
			.color = color,
			.particleVAO = vao,
			.particleVBO = vbo,
			.dead = false
		};
	}
	closedir(tasksDir);
	free(emptyParticleBuffer);
	
	return traces;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x98(%rbp)
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
movq %rsi, -0x8(%rbp)
xorl %esi, %esi
movl $0x38, %edx
callq 0x6060
movq -0x98(%rbp), %rdi
movq $-0x1, 0x10(%rdi)
movl $0x8642, %edi           # imm = 0x8642
leaq 0xb59f9(%rip), %rax     # 0xcba40
callq *(%rax)
leaq 0x7633a(%rip), %rdi     # 0x8c38a
leaq 0x7633f(%rip), %rsi     # 0x8c396
callq 0x28890
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, -0x18(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rcx
movq %rcx, 0x20(%rax)
movl 0x18(%rax), %edi
movq 0x20(%rax), %rsi
leaq 0x80743(%rip), %rdx     # 0x967cd
callq 0x29150
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, -0x1c(%rbp)
movl 0x18(%rax), %edi
movq 0x20(%rax), %rsi
leaq 0x9e349(%rip), %rdx     # 0xb43f2
callq 0x29150
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, -0x20(%rbp)
movl 0x18(%rax), %edi
movq 0x20(%rax), %rsi
leaq 0x79be3(%rip), %rdx     # 0x8fcab
callq 0x290d0
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x28(%rax)
movl 0x18(%rax), %edi
movq 0x20(%rax), %rsi
leaq 0x762bb(%rip), %rdx     # 0x8c3a2
callq 0x290d0
movq -0x98(%rbp), %rdi
movl %eax, 0x2c(%rdi)
movq $0x0, -0x28(%rbp)
movq -0x8(%rbp), %rdx
leaq -0x28(%rbp), %rdi
leaq 0x762a1(%rip), %rsi     # 0x8c3ae
movb $0x0, %al
callq 0x64d0
movq -0x28(%rbp), %rdi
callq 0x6320
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x62e0
cmpq $0x0, -0x30(%rbp)
jne 0x16136
jmp 0x1643b
movl $0x7d0, %edi            # imm = 0x7D0
movl $0xc, %esi
callq 0x65b0
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x6330
movq %rax, -0x40(%rbp)
cmpq $0x0, %rax
je 0x16429
movq -0x40(%rbp), %rax
movsbl 0x13(%rax), %eax
cmpl $0x2e, %eax
jne 0x1616f
jmp 0x16149
movq -0x40(%rbp), %rdi
addq $0x13, %rdi
callq 0x63f0
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %esi
movl $0x4206, %edi           # imm = 0x4206
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
movb $0x0, %al
callq 0x63b0
cmpq $0x0, %rax
je 0x161a7
leaq 0x7621a(%rip), %rdi     # 0x8c3bc
callq 0x6700
movq -0x8(%rbp), %rsi
movl -0x44(%rbp), %edx
leaq 0x7621c(%rip), %rdi     # 0x8c3d1
movb $0x0, %al
callq 0x65400
movq %rax, %rdi
leaq 0x75fa7(%rip), %rsi     # 0x8c16d
callq 0x61e0
movq %rax, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x161fd
movq -0x50(%rbp), %rdi
leaq 0x76177(%rip), %rsi     # 0x8c360
leaq -0x58(%rbp), %rdx
movb $0x0, %al
callq 0x60e0
movq -0x50(%rbp), %rdi
callq 0x65f0
callq 0x6710
cvtsi2ss %eax, %xmm1
movss 0x75e72(%rip), %xmm0    # 0x8c080
divss %xmm0, %xmm1
movss 0x75e2a(%rip), %xmm0    # 0x8c044
mulss %xmm1, %xmm0
movss %xmm0, -0x5c(%rbp)
callq 0x6710
cvtsi2ss %eax, %xmm0
movss 0x75e4c(%rip), %xmm1    # 0x8c080
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x75ed4(%rip), %xmm1    # 0x8c118
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x60(%rbp)
callq 0x6710
cvtsi2ss %eax, %xmm0
movss 0x75e1a(%rip), %xmm1    # 0x8c080
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x75ea2(%rip), %xmm1    # 0x8c118
mulsd %xmm1, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x64(%rbp)
movss -0x5c(%rbp), %xmm0
movss -0x60(%rbp), %xmm1
movss -0x64(%rbp), %xmm2
callq 0x52340
movl %eax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x1, %edi
leaq -0x6c(%rbp), %rsi
leaq 0xb58bc(%rip), %rax     # 0xcbb78
callq *(%rax)
leaq 0xb58bb(%rip), %rax     # 0xcbb80
movq (%rax), %rax
movl -0x6c(%rbp), %edi
callq *%rax
movl $0x1, %edi
leaq -0x70(%rbp), %rsi
leaq 0xb58ab(%rip), %rax     # 0xcbb88
callq *(%rax)
leaq 0xb57c2(%rip), %rax     # 0xcbaa8
movq (%rax), %rax
movl -0x70(%rbp), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
leaq 0xb5896(%rip), %rax     # 0xcbb90
movq (%rax), %rax
movq -0x38(%rbp), %rdx
movl $0x8892, %edi           # imm = 0x8892
movl $0x5dc0, %esi           # imm = 0x5DC0
movl $0x88e8, %ecx           # imm = 0x88E8
callq *%rax
leaq 0xb5887(%rip), %rax     # 0xcbba0
movq (%rax), %rax
movl -0x1c(%rbp), %edi
callq *%rax
leaq 0xb5878(%rip), %rax     # 0xcbba0
movq (%rax), %rax
movl -0x20(%rbp), %edi
callq *%rax
leaq 0xb5861(%rip), %rax     # 0xcbb98
movq (%rax), %rax
movl -0x1c(%rbp), %edi
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0xc, %r8d
xorl %r9d, %r9d
callq *%rax
leaq 0xb583d(%rip), %rax     # 0xcbb98
movq (%rax), %rax
movl -0x20(%rbp), %edi
movl $0x1, %esi
movl $0x1405, %edx           # imm = 0x1405
xorl %ecx, %ecx
movl $0xc, %r8d
movl $0x8, %r9d
callq *%rax
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
leaq 0xb571f(%rip), %rax     # 0xcbaa8
callq *(%rax)
xorl %edi, %edi
leaq 0xb57ec(%rip), %rax     # 0xcbb80
callq *(%rax)
movq -0x98(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq (%rax), %rdi
movq 0x8(%rax), %rsi
shlq $0x5, %rsi
callq 0x66c0
movq -0x98(%rbp), %rcx
movq %rax, (%rcx)
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl -0x44(%rbp), %ecx
movl %ecx, -0x90(%rbp)
movq -0x58(%rbp), %rcx
movq %rcx, -0x88(%rbp)
movl -0x68(%rbp), %ecx
movl %ecx, -0x80(%rbp)
movl -0x6c(%rbp), %ecx
movl %ecx, -0x7c(%rbp)
movl -0x70(%rbp), %ecx
movl %ecx, -0x78(%rbp)
movb $0x0, -0x74(%rbp)
movq -0x90(%rbp), %rcx
movq %rcx, (%rax)
movq -0x88(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x78(%rbp), %rcx
movq %rcx, 0x18(%rax)
jmp 0x16149
movq -0x30(%rbp), %rdi
callq 0x6620
movq -0x38(%rbp), %rdi
callq 0x62e0
movq -0xa0(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)