#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Function to report kernel version
void report_kernel_info() {
    FILE *file = fopen("/proc/version", "r"); // Open the file with kernel version info
    if (file == NULL) { // Check if file opened successfully
        perror("Failed to open /proc/version");
        exit(EXIT_FAILURE);
    }

    char line[256];
    if (fgets(line, sizeof(line), file)) { // Read the first line
        printf("Kernel Version: %s", line); // Print kernel version
    }
    fclose(file); // Close the file
}

// Function to report CPU details
void report_cpu_info() {
    FILE *file = fopen("/proc/cpuinfo", "r"); // Open the file with CPU info
    if (file == NULL) { // Check if file opened successfully
        perror("Failed to open /proc/cpuinfo");
        exit(EXIT_FAILURE);
    }

    char line[256];
    char cpu_model[256] = "Unknown"; // Placeholder for CPU model
    char cpu_architecture[256] = "Unknown"; // Placeholder for CPU architecture

    while (fgets(line, sizeof(line), file)) { // Read file line by line
        if (strncmp(line, "model name", 10) == 0) { // Check for CPU model
            sscanf(line, "model name\t: %[^\n]", cpu_model);
        }
        if (strncmp(line, "architecture", 12) == 0) { // Check for CPU architecture
            sscanf(line, "architecture\t: %[^\n]", cpu_architecture);
        }
    }
    fclose(file); // Close the file

    printf("CPU Type: %s\n", cpu_model); // Print CPU model
    printf("CPU Architecture: %s\n", cpu_architecture); // Print CPU architecture
}

int main() {
    printf("System Information Report\n");
    printf("------------------------------\n");
    report_kernel_info(); // Call function to display kernel version
    report_cpu_info(); // Call function to display CPU details
    printf("------------------------------\n");
    return 0; // Exit program
}

