#!/bin/csh

set p_cpus = ($1 $2)
set p_plat = ($3 $4)

set p_two  = (1 0)
set p_four = (2 0)
set p_six  = (1 1)
set p_eight  = (3 0)

./.pwr1_le_pwr2 $p_cpus $p_six
if( $status ) then
  set p_thrd = ($p_two)
else
  set p_thrd = ($p_four)
endif

set lim = `./.pwr2num $p_eight`
set nthrd = `./.pwr2num $p_thrd`

while( $nthrd <= $lim )
  set p_procs = `./.div_pwrs $p_cpus $p_thrd`
  ./.valid_pwr $p_procs
  if( $status ) then
    set p_wrk   = `./.div_pwrs $p_plat $p_procs`
    ./.valid_pwr $p_wrk
    if( $status ) then
      ./.pwr1_ge_pwr2 $p_wrk $p_four
      if( $status ) then
        break
      endif
    endif
  endif

  if( $p_cpus[2] == 0 ) then
    @ p_thrd[1]++
  else
    set p_thrd = `.inc_pwr $p_thrd`
  endif
  set nthrd = `./.pwr2num $p_thrd`
end

./.pwr1_le_pwr2 $p_thrd $p_eight
if( $status ) then
  echo $p_procs $p_thrd
  exit 0
endif

echo -1 -1 -1 -1
exit -1
