static int calculate_geometry(int64_t total_sectors, uint16_t* cyls,

    uint8_t* heads, uint8_t* secs_per_cyl)

{

    uint32_t cyls_times_heads;



    if (total_sectors > 65535 * 16 * 255)

        return -EFBIG;



    if (total_sectors > 65535 * 16 * 63) {

        *secs_per_cyl = 255;

        *heads = 16;

        cyls_times_heads = total_sectors / *secs_per_cyl;

    } else {

        *secs_per_cyl = 17;

        cyls_times_heads = total_sectors / *secs_per_cyl;

        *heads = (cyls_times_heads + 1023) / 1024;



        if (*heads < 4)

            *heads = 4;



        if (cyls_times_heads >= (*heads * 1024) || *heads > 16) {

            *secs_per_cyl = 31;

            *heads = 16;

            cyls_times_heads = total_sectors / *secs_per_cyl;

        }



        if (cyls_times_heads >= (*heads * 1024)) {

            *secs_per_cyl = 63;

            *heads = 16;

            cyls_times_heads = total_sectors / *secs_per_cyl;

        }

    }



    *cyls = cyls_times_heads / *heads;



    return 0;

}

static int calculate_geometry(int64_t total_sectors, uint16_t* cyls,

    uint8_t* heads, uint8_t* secs_per_cyl)

{

    uint32_t cyls_times_heads;



    if (total_sectors > 65535 * 16 * 255)

        return -EFBIG;



    if (total_sectors > 65535 * 16 * 63) {

        *secs_per_cyl = 255;

        *heads = 16;

        cyls_times_heads = total_sectors / *secs_per_cyl;

    } else {

        *secs_per_cyl = 17;

        cyls_times_heads = total_sectors / *secs_per_cyl;

        *heads = (cyls_times_heads + 1023) / 1024;



        if (*heads < 4)

            *heads = 4;



        if (cyls_times_heads >= (*heads * 1024) || *heads > 16) {

            *secs_per_cyl = 31;

            *heads = 16;

            cyls_times_heads = total_sectors / *secs_per_cyl;

        }



        if (cyls_times_heads >= (*heads * 1024)) {

            *secs_per_cyl = 63;

            *heads = 16;

            cyls_times_heads = total_sectors / *secs_per_cyl;

        }

    }



    *cyls = cyls_times_heads / *heads;



    return 0;

}

static int FUNC_0(int64_t VAR_0, uint16_t* VAR_1,

    uint8_t* VAR_2, uint8_t* VAR_3)

{

    uint32_t cyls_times_heads;



    if (VAR_0 > 65535 * 16 * 255)

        return -EFBIG;



    if (VAR_0 > 65535 * 16 * 63) {

        *VAR_3 = 255;

        *VAR_2 = 16;

        cyls_times_heads = VAR_0 / *VAR_3;

    } else {

        *VAR_3 = 17;

        cyls_times_heads = VAR_0 / *VAR_3;

        *VAR_2 = (cyls_times_heads + 1023) / 1024;



        if (*VAR_2 < 4)

            *VAR_2 = 4;



        if (cyls_times_heads >= (*VAR_2 * 1024) || *VAR_2 > 16) {

            *VAR_3 = 31;

            *VAR_2 = 16;

            cyls_times_heads = VAR_0 / *VAR_3;

        }



        if (cyls_times_heads >= (*VAR_2 * 1024)) {

            *VAR_3 = 63;

            *VAR_2 = 16;

            cyls_times_heads = VAR_0 / *VAR_3;

        }

    }



    *VAR_1 = cyls_times_heads / *VAR_2;



    return 0;

}

static int FUNC_0(int64_t VAR_0, uint16_t* VAR_1,
uint8_t* VAR_2, uint8_t* VAR_3)
{ uint32_t cyls_times_heads; if (VAR_0 > 65535 * 16 * 255)
return -EFBIG; if (VAR_0 > 65535 * 16 * 63) { *VAR_3 = 255; *VAR_2 = 16; cyls_times_heads = VAR_0 / *VAR_3; } else { *VAR_3 = 17; cyls_times_heads = VAR_0 / *VAR_3; *VAR_2 = (cyls_times_heads + 1023) / 1024; if (*VAR_2 < 4)
*VAR_2 = 4; if (cyls_times_heads >= (*VAR_2 * 1024) || *VAR_2 > 16) { *VAR_3 = 31; *VAR_2 = 16; cyls_times_heads = VAR_0 / *VAR_3; } if (cyls_times_heads >= (*VAR_2 * 1024)) { *VAR_3 = 63; *VAR_2 = 16; cyls_times_heads = VAR_0 / *VAR_3; } } *VAR_1 = cyls_times_heads / *VAR_2; return 0; }