/* =====================================
 * Generated by Mod-c 0.22.1
 * PROGRAM PrimeSieve
 * ===================================== */

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <float.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdarg.h>
#include <errno.h>

#define nil NULL
typedef int8_t int8;
typedef int16_t	int16;
typedef int32_t int32;
typedef int64_t	int64;
typedef uint8_t	uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef uint64_t uint64;
typedef char* pchar;
typedef char* string;
typedef intptr_t integer;
typedef uintptr_t cardinal;
typedef double_t real;

void PrimeSieve(void);

#include "utils.h"
static void PrintPrimes(integer LIMIT)
{
    bool* is_prime = malloc(LIMIT + 1 * sizeof(bool));
    integer i = {0};
    integer p = {0};
    integer q = {0};
    /* DEFER begin */
    for (i = 0; i <= LIMIT; i++)
    {
        {
            is_prime[i] = true;
        }
    }
    is_prime[0] = false;
    is_prime[1] = false;
    p = 2;
    q = utils_power(p, 2);
    while (q <= LIMIT)
    {
        {
            if (is_prime[p])
            {
                i = q;
                while (i <= LIMIT)
                {
                    {
                        is_prime[i] = false;
                        i = i + p;
                    }
                }
            }
            p = p + 1;
            q = utils_power(p, 2);
        }
    }
    q = 0;
    i = LIMIT;
    while (i > 0 && q < 10)
    {
        {
            if (is_prime[i])
            {
                q++;
            }
            i--;
        }
    }
        while (i <= LIMIT)
    {
        {
            if (is_prime[i])
            {
                printf("%zu\n", i);
            }
            i++;
        }
    }
    /* DEFER end */
    if (true)
    {
        free(is_prime);
        printf("done\n");
    }
}


void PrimeSieve(void)
{
    const size_t LIMIT = 1000000000;
    PrintPrimes(LIMIT);
}

int main(void)
{
    PrimeSieve();
    return 0;
}
