// File: /workspace/github_c_makefile_star2_O2/igaw[P]jitterdebugger/jd_sysinfo.c
// Function: store_system_info
void store_system_info(const char *path, struct system_info *sysinfo)
{
	char *buf;
	FILE *fd;
	unsigned int len;

	jd_cp("/proc/cmdline", path);
	jd_cp("/proc/config.gz", path);
	jd_cp("/proc/cpuinfo", path);
	jd_cp("/proc/interrupts", path);
	jd_cp("/proc/sched_debug", path);

	// cpus_online
	fd = jd_fopen(path, "cpus_online", "w");
	if (!fd)
		return;
	fprintf(fd, "%d\n", sysinfo->cpus_online);
	fclose(fd);

	// uname
	fd = jd_fopen(path, "uname", "w");
	if (!fd)
		return;
	fprintf(fd, "%s %s %s %s %s\n",
		sysinfo->sysname,
		sysinfo->nodename,
		sysinfo->release,
		sysinfo->version,
		sysinfo->machine);
	fclose(fd);

	// dmesg
	len = klogctl(SYSLOG_ACTION_SIZE_BUFFER, NULL, 0);
	buf = malloc(len * sizeof(char));
	if (!buf)
		err_handler(errno, "malloc()");

	if (klogctl(SYSLOG_ACTION_READ_ALL, buf, len) < 0)
		return;

	fd = jd_fopen(path, "dmesg", "w");
	if (!fd) {
		free(buf);
		return;
	}

	if (fwrite(buf, sizeof(char), len, fd) != len)
		warn_handler("writing dmesg failed\n");

	fclose(fd);
	free(buf);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x17f4(%rip), %rdi      # 0x6098
movq %rbx, %rsi
callq 0x4542
leaq 0x17f3(%rip), %rdi      # 0x60a6
movq %rbx, %rsi
callq 0x4542
leaq 0x17f4(%rip), %rdi      # 0x60b6
movq %rbx, %rsi
callq 0x4542
leaq 0x17f3(%rip), %rdi      # 0x60c4
movq %rbx, %rsi
callq 0x4542
leaq 0x17f5(%rip), %rdi      # 0x60d5
movq %rbx, %rsi
callq 0x4542
leaq 0x17f8(%rip), %rsi      # 0x60e7
leaq 0xa5b(%rip), %rdx       # 0x5351
movq %rbx, %rdi
callq 0x44b1
testq %rax, %rax
je 0x4a36
movq %rax, %r15
movl 0x28(%r14), %edx
leaq 0x1718(%rip), %rsi      # 0x602d
movq %rax, %rdi
xorl %eax, %eax
callq 0x2230
movq %r15, %rdi
callq 0x2110
leaq 0x17c5(%rip), %rsi      # 0x60f3
leaq 0xa1c(%rip), %rdx       # 0x5351
movq %rbx, %rdi
callq 0x44b1
testq %rax, %rax
je 0x4a36
movq %rax, %r15
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movq 0x10(%r14), %r8
movq 0x18(%r14), %r9
movq 0x20(%r14), %rax
movq %rax, (%rsp)
leaq 0x1792(%rip), %rsi      # 0x60f9
movq %r15, %rdi
xorl %eax, %eax
callq 0x2230
movq %r15, %rdi
callq 0x2110
pushq $0xa
popq %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22d0
movl %eax, %r15d
movq %r15, %rdi
callq 0x22a0
movq %rax, %r14
testq %rax, %rax
jne 0x49bb
callq 0x2070
movl (%rax), %edi
leaq 0x93e(%rip), %rsi       # 0x52e4
leaq 0x1684(%rip), %rdx      # 0x6031
leaq 0x1755(%rip), %rcx      # 0x6109
xorl %eax, %eax
callq 0x3ee1
pushq $0x3
popq %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x22d0
testl %eax, %eax
js 0x4a36
leaq 0x1747(%rip), %rsi      # 0x611b
leaq 0x976(%rip), %rdx       # 0x5351
movq %rbx, %rdi
callq 0x44b1
testq %rax, %rax
je 0x4a25
movq %rax, %rbx
pushq $0x1
popq %rsi
movq %r14, %rdi
movq %r15, %rdx
movq %rax, %rcx
callq 0x23c0
cmpq %r15, %rax
je 0x4a1d
leaq 0x1719(%rip), %rdi      # 0x6121
leaq 0x1622(%rip), %rsi      # 0x6031
leaq 0x16f3(%rip), %rdx      # 0x6109
xorl %eax, %eax
callq 0x3fae
movq %rbx, %rdi
callq 0x2110
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2040
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq