#include <stdio.h>

typedef struct
{
    int column;
    int row;
} STK;

STK stk[1024];
int top = 0;
int size = 3;

void putTo( int i, int j ){}
int checkIfPosIsOK( int i, int j ){ return 1; }
void removeFrom( int i, int j ){}

static STK pop()
{
    return stk[--top];
}

static void push( STK v )
{
    stk[top++] = v;
}

static int empty()
{
    return ( top == 0 );
}

void ff( int column )
{
    int row;
    STK tmp;

    for( ;; )
    {
L1:
        for( row = 1; row <= size; ++row )
        {
            if( checkIfPosIsOK( row, column ) )
            {
                putTo( row, column );

                if( column < size )
                {
                    printf( "if: %d\n", column );

                    tmp.column = column;
                    tmp.row = row;
                    push( tmp );

                    column = column + 1;

                    goto L1;
L2:
                    printf( "if: %d\n", column );
                }
                else
                {
                    printf( "else: %d\n", column );
                }

                removeFrom( row, column );
            }
        }

        if( !empty() )
        {
            tmp = pop();
            column = tmp.column;
            row = tmp.row;

            goto L2;
        }
        else
            break;
    }
}

int main()
{
    ff( 4 );

    return 0;
}
