/* Compiler: ECL 26.3.27                                                      */
/* Source: /build/ecl/src/ecl-26.3.27/contrib/serve-event/serve-event.lisp    */
#include <ecl/ecl-cmp.h>
#include "ext/serve-event.eclh"
/* function definition for MAKE-HANDLER                                       */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5391make_handler(cl_object v1descriptor, cl_object v2direction, cl_object v3function)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v4thread;
  v4thread = ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*CURRENT-PROCESS*",1442));
  if (cl_functionp(v3function)!=ECL_NIL) {
   goto L3;
  }
  si_structure_type_error(v3function, ECL_SYM("FUNCTION",398), VV[4], ECL_SYM("FUNCTION",398));
L3:;
  if (!((v2direction)==(ECL_SYM("INPUT",1289)))){
   goto L9;
  }
  goto L5;
L9:;
  goto L7;
L7:;
  if (!((v2direction)==(ECL_SYM("OUTPUT",1319)))){
   goto L12;
  }
  goto L5;
L12:;
  goto L6;
L6:;
  si_structure_type_error(v2direction, VV[10], VV[4], VV[11]);
L5:;
  value0 = si_make_structure(5, VV[12], v2direction, v1descriptor, v3function, v4thread);
  return value0;
 }
}
static cl_object L5391make_handler_va(cl_narg narg, cl_object v5descriptor, cl_object v6direction, cl_object v7function, ...)
{
 if (ecl_unlikely(narg!=3)) FEwrong_num_arguments(VV[6]);
 {
  return L5391make_handler(v5descriptor, v6direction, v7function);
 }
}
/* local function LAMBDA24                                                    */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5392__lambda24(cl_object v1, cl_object v2si__x)
{
 cl_object T0, T1, T2, T3;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4;
  v3 = cl_gensym(0);
  v4 = cl_gensym(0);
  T0 = cl_list(2, ECL_SYM("QUOTE",682), VV[4]);
  T1 = cl_list(6, ECL_SYM("COMPARE-AND-SWAP-STRUCTURE",1527), v2si__x, T0, ecl_make_int8_t(3), v3, v4);
  T2 = cl_list(2, ECL_SYM("QUOTE",682), VV[4]);
  T3 = cl_list(4, ECL_SYM("STRUCTURE-REF",1178), v2si__x, T2, ecl_make_int8_t(3));
  cl_env_copy->nvalues = 6;
  cl_env_copy->values[5] = T3;
  cl_env_copy->values[4] = T1;
  cl_env_copy->values[3] = v4;
  cl_env_copy->values[2] = v3;
  cl_env_copy->values[1] = ECL_NIL;
  cl_env_copy->values[0] = ECL_NIL;
  return cl_env_copy->values[0];
 }
}
static cl_object LC5392__lambda24_va(cl_narg narg, cl_object v5, cl_object v6si__x, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[16]);
 {
  return LC5392__lambda24(v5, v6si__x);
 }
}
/* local function LAMBDA29                                                    */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5393__lambda29(cl_object v1, cl_object v2si__x)
{
 cl_object T0, T1, T2, T3;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4;
  v3 = cl_gensym(0);
  v4 = cl_gensym(0);
  T0 = cl_list(2, ECL_SYM("QUOTE",682), VV[4]);
  T1 = cl_list(6, ECL_SYM("COMPARE-AND-SWAP-STRUCTURE",1527), v2si__x, T0, ecl_make_int8_t(2), v3, v4);
  T2 = cl_list(2, ECL_SYM("QUOTE",682), VV[4]);
  T3 = cl_list(4, ECL_SYM("STRUCTURE-REF",1178), v2si__x, T2, ecl_make_int8_t(2));
  cl_env_copy->nvalues = 6;
  cl_env_copy->values[5] = T3;
  cl_env_copy->values[4] = T1;
  cl_env_copy->values[3] = v4;
  cl_env_copy->values[2] = v3;
  cl_env_copy->values[1] = ECL_NIL;
  cl_env_copy->values[0] = ECL_NIL;
  return cl_env_copy->values[0];
 }
}
static cl_object LC5393__lambda29_va(cl_narg narg, cl_object v5, cl_object v6si__x, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[18]);
 {
  return LC5393__lambda29(v5, v6si__x);
 }
}
/* local function LAMBDA34                                                    */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5394__lambda34(cl_object v1, cl_object v2si__x)
{
 cl_object T0, T1, T2, T3;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4;
  v3 = cl_gensym(0);
  v4 = cl_gensym(0);
  T0 = cl_list(2, ECL_SYM("QUOTE",682), VV[4]);
  T1 = cl_list(6, ECL_SYM("COMPARE-AND-SWAP-STRUCTURE",1527), v2si__x, T0, ecl_make_int8_t(1), v3, v4);
  T2 = cl_list(2, ECL_SYM("QUOTE",682), VV[4]);
  T3 = cl_list(4, ECL_SYM("STRUCTURE-REF",1178), v2si__x, T2, ecl_make_int8_t(1));
  cl_env_copy->nvalues = 6;
  cl_env_copy->values[5] = T3;
  cl_env_copy->values[4] = T1;
  cl_env_copy->values[3] = v4;
  cl_env_copy->values[2] = v3;
  cl_env_copy->values[1] = ECL_NIL;
  cl_env_copy->values[0] = ECL_NIL;
  return cl_env_copy->values[0];
 }
}
static cl_object LC5394__lambda34_va(cl_narg narg, cl_object v5, cl_object v6si__x, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[20]);
 {
  return LC5394__lambda34(v5, v6si__x);
 }
}
/* local function LAMBDA39                                                    */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5395__lambda39(cl_object v1, cl_object v2si__x)
{
 cl_object T0, T1, T2, T3;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4;
  v3 = cl_gensym(0);
  v4 = cl_gensym(0);
  T0 = cl_list(2, ECL_SYM("QUOTE",682), VV[4]);
  T1 = cl_list(6, ECL_SYM("COMPARE-AND-SWAP-STRUCTURE",1527), v2si__x, T0, ecl_make_int8_t(0), v3, v4);
  T2 = cl_list(2, ECL_SYM("QUOTE",682), VV[4]);
  T3 = cl_list(4, ECL_SYM("STRUCTURE-REF",1178), v2si__x, T2, ecl_make_int8_t(0));
  cl_env_copy->nvalues = 6;
  cl_env_copy->values[5] = T3;
  cl_env_copy->values[4] = T1;
  cl_env_copy->values[3] = v4;
  cl_env_copy->values[2] = v3;
  cl_env_copy->values[1] = ECL_NIL;
  cl_env_copy->values[0] = ECL_NIL;
  return cl_env_copy->values[0];
 }
}
static cl_object LC5395__lambda39_va(cl_narg narg, cl_object v5, cl_object v6si__x, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[22]);
 {
  return LC5395__lambda39(v5, v6si__x);
 }
}
/* function definition for COERCE-TO-DESCRIPTOR                               */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5396coerce_to_descriptor(cl_object v1stream_or_fd, cl_object v2direction)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 if (!(ECL_FIXNUMP(v1stream_or_fd))){
  goto L2;
 }
 value0 = v1stream_or_fd;
 cl_env_copy->nvalues = 1;
 return value0;
L2:;
 if (Null(si_of_class_p(2, v1stream_or_fd, ECL_SYM("FILE-STREAM",360)))){
  goto L4;
 }
 value0 = si_file_stream_fd(v1stream_or_fd);
 return value0;
L4:;
 if (Null(si_of_class_p(2, v1stream_or_fd, ECL_SYM("TWO-WAY-STREAM",869)))){
  goto L6;
 }
 if (!((v2direction)==(ECL_SYM("INPUT",1289)))){
  goto L10;
 }
 v1stream_or_fd = cl_two_way_stream_input_stream(v1stream_or_fd);
 goto L9;
L10:;
 if (!((v2direction)==(ECL_SYM("OUTPUT",1319)))){
  goto L12;
 }
 v1stream_or_fd = cl_two_way_stream_output_stream(v1stream_or_fd);
 goto L9;
L12:;
 v1stream_or_fd = ECL_NIL;
L9:;
 goto L1;
L6:;
 if (Null(cl_streamp(v1stream_or_fd))){
  goto L15;
 }
 value0 = (cl_env_copy->function=ecl_fdefinition(ECL_SYM("STREAM-FILE-DESCRIPTOR",1698)))->cfun.entry(2, v1stream_or_fd, v2direction) /*  STREAM-FILE-DESCRIPTOR */;
 return value0;
L15:;
 value0 = si_etypecase_error(v1stream_or_fd, VV[25]);
 return value0;
}
static cl_object L5396coerce_to_descriptor_va(cl_narg narg, cl_object v3stream_or_fd, cl_object v4direction, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[24]);
 {
  return L5396coerce_to_descriptor(v3stream_or_fd, v4direction);
 }
}
/* local function DO-HANDLERS                                                 */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5397do_handlers(cl_object v1, cl_object v2)
{
 cl_object T0, T1, T2, T3;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4;
  cl_object v5;
  cl_object v6handler_symbol;
  cl_object v7handler_list;
  v3 = ecl_cdr(v1);
  if (!(v3==ECL_NIL)){
   goto L4;
  }
  si_dm_too_few_arguments(v1);
L4:;
  {
   cl_object v8;
   v8 = ecl_car(v3);
   v3 = ecl_cdr(v3);
   v4 = v8;
  }
  v5 = v4;
  if (!(v5==ECL_NIL)){
   goto L11;
  }
  si_dm_too_few_arguments(v1);
L11:;
  {
   cl_object v8;
   v8 = ecl_car(v5);
   v5 = ecl_cdr(v5);
   v6handler_symbol = v8;
  }
  if (!(v5==ECL_NIL)){
   goto L17;
  }
  si_dm_too_few_arguments(v1);
L17:;
  {
   cl_object v8;
   v8 = ecl_car(v5);
   v5 = ecl_cdr(v5);
   v7handler_list = v8;
  }
  if (Null(v5)){
   goto L22;
  }
  si_dm_too_many_arguments(v1);
L22:;
  T0 = cl_list(2, v6handler_symbol, v7handler_list);
  T1 = cl_list(2, VV[14], v6handler_symbol);
  T2 = cl_list(3, ECL_SYM("EQ",335), ECL_SYM("*CURRENT-PROCESS*",1442), T1);
  T3 = cl_listX(3, ECL_SYM("WHEN",909), T2, v3);
  value0 = cl_list(3, ECL_SYM("DOLIST",315), T0, T3);
  return value0;
 }
}
static cl_object LC5397do_handlers_va(cl_narg narg, cl_object v8, cl_object v9, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[28]);
 {
  return LC5397do_handlers(v8, v9);
 }
}
/* function definition for ADD-FD-HANDLER                                     */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5398add_fd_handler(cl_object v1stream_or_fd, cl_object v2direction, cl_object v3function)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 if (!((v2direction)==(ECL_SYM("INPUT",1289)))){
  goto L6;
 }
 goto L2;
L6:;
 goto L4;
L4:;
 if (!((v2direction)==(ECL_SYM("OUTPUT",1319)))){
  goto L9;
 }
 goto L2;
L9:;
 goto L3;
L3:;
 T0 = ecl_list1(v2direction);
 cl_error(9, ECL_SYM("SIMPLE-TYPE-ERROR",776), ECL_SYM("FORMAT-CONTROL",1272), VV[32], ECL_SYM("FORMAT-ARGUMENTS",1271), T0, ECL_SYM("DATUM",1245), v2direction, ECL_SYM("EXPECTED-TYPE",1263), VV[10]);
L2:;
 {
  cl_object v4handler;
  T0 = L5396coerce_to_descriptor(v1stream_or_fd, v2direction);
  v4handler = L5391make_handler(T0, v2direction, v3function);
  {
   cl_object v5;
   cl_object v6;
   v5 = ecl_cmp_symbol_value(cl_env_copy,VV[23]);
   v6 = CONS(v4handler,v5);
L15:;
   T0 = v5;
   v5 = mp_compare_and_swap_symbol_value(VV[23], v5, v6);
   if (!((T0)==(v5))){
    goto L17;
   }
   goto L16;
L17:;
   {
    cl_object v7;
    v7 = v5;
    {
     cl_object v8;
     v8 = v6;
     if (ecl_unlikely(ECL_ATOM(v8))) FEtype_error_cons(v8);
     value0 = ECL_NIL;
     cl_env_copy->nvalues = 0;
     T0 = v8;
    }
    (ECL_CONS_CDR(T0)=v7,T0);
   }
   goto L15;
L16:;
   goto L12;
  }
L12:;
  value0 = v4handler;
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
static cl_object L5398add_fd_handler_va(cl_narg narg, cl_object v5stream_or_fd, cl_object v6direction, cl_object v7function, ...)
{
 if (ecl_unlikely(narg!=3)) FEwrong_num_arguments(VV[31]);
 {
  return L5398add_fd_handler(v5stream_or_fd, v6direction, v7function);
 }
}
/* function definition for REMOVE-FD-HANDLER                                  */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5399remove_fd_handler(cl_object v1handler)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v2;
  v2 = ecl_cmp_symbol_value(cl_env_copy,VV[23]);
  {
   cl_object v3;
   v3 = ECL_NIL;
L4:;
   v3 = cl_remove(2, v1handler, v2);
   T0 = v2;
   v2 = mp_compare_and_swap_symbol_value(VV[23], v2, v3);
   if (!((T0)==(v2))){
    goto L8;
   }
   goto L5;
L8:;
   goto L4;
L5:;
   value0 = v3;
   cl_env_copy->nvalues = 1;
   return value0;
  }
 }
}
static cl_object L5399remove_fd_handler_va(cl_narg narg, cl_object v4handler, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[35]);
 {
  return L5399remove_fd_handler(v4handler);
 }
}
/* local function WITH-FD-HANDLER                                             */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5400with_fd_handler(cl_object v1, cl_object v2)
{
 cl_object T0, T1, T2, T3, T4, T5, T6;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4;
  cl_object v5;
  cl_object v6fd;
  cl_object v7direction;
  cl_object v8function;
  v3 = ecl_cdr(v1);
  if (!(v3==ECL_NIL)){
   goto L4;
  }
  si_dm_too_few_arguments(v1);
L4:;
  {
   cl_object v9;
   v9 = ecl_car(v3);
   v3 = ecl_cdr(v3);
   v4 = v9;
  }
  v5 = v4;
  if (!(v5==ECL_NIL)){
   goto L11;
  }
  si_dm_too_few_arguments(v1);
L11:;
  {
   cl_object v9;
   v9 = ecl_car(v5);
   v5 = ecl_cdr(v5);
   v6fd = v9;
  }
  if (!(v5==ECL_NIL)){
   goto L17;
  }
  si_dm_too_few_arguments(v1);
L17:;
  {
   cl_object v9;
   v9 = ecl_car(v5);
   v5 = ecl_cdr(v5);
   v7direction = v9;
  }
  if (!(v5==ECL_NIL)){
   goto L23;
  }
  si_dm_too_few_arguments(v1);
L23:;
  {
   cl_object v9;
   v9 = ecl_car(v5);
   v5 = ecl_cdr(v5);
   v8function = v9;
  }
  if (Null(v5)){
   goto L28;
  }
  si_dm_too_many_arguments(v1);
L28:;
  {
   cl_object v9handler;
   v9handler = cl_gensym(0);
   T0 = ecl_list1(v9handler);
   T1 = cl_list(4, VV[31], v6fd, v7direction, v8function);
   T2 = cl_list(3, ECL_SYM("SETF",753), v9handler, T1);
   T3 = cl_listX(3, ECL_SYM("PROGN",674), T2, v3);
   T4 = cl_list(2, VV[35], v9handler);
   T5 = cl_list(3, ECL_SYM("WHEN",909), v9handler, T4);
   T6 = cl_list(3, ECL_SYM("UNWIND-PROTECT",892), T3, T5);
   value0 = cl_list(3, ECL_SYM("LET",479), T0, T6);
   return value0;
  }
 }
}
static cl_object LC5400with_fd_handler_va(cl_narg narg, cl_object v10, cl_object v11, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[38]);
 {
  return LC5400with_fd_handler(v10, v11);
 }
}
/* local function FD-ZERO                                                     */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5401fd_zero(cl_object v1, cl_object v2)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4fdset;
  v3 = ecl_cdr(v1);
  if (!(v3==ECL_NIL)){
   goto L4;
  }
  si_dm_too_few_arguments(v1);
L4:;
  {
   cl_object v5;
   v5 = ecl_car(v3);
   v3 = ecl_cdr(v3);
   v4fdset = v5;
  }
  if (Null(v3)){
   goto L9;
  }
  si_dm_too_many_arguments(v1);
L9:;
  T0 = ecl_list1(v4fdset);
  value0 = cl_listX(3, ECL_SYM("C-INLINE",2106), T0, VV[41]);
  return value0;
 }
}
static cl_object LC5401fd_zero_va(cl_narg narg, cl_object v5, cl_object v6, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[40]);
 {
  return LC5401fd_zero(v5, v6);
 }
}
/* local function FD-SET                                                      */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5402fd_set(cl_object v1, cl_object v2)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4fd;
  cl_object v5fdset;
  v3 = ecl_cdr(v1);
  if (!(v3==ECL_NIL)){
   goto L4;
  }
  si_dm_too_few_arguments(v1);
L4:;
  {
   cl_object v6;
   v6 = ecl_car(v3);
   v3 = ecl_cdr(v3);
   v4fd = v6;
  }
  if (!(v3==ECL_NIL)){
   goto L10;
  }
  si_dm_too_few_arguments(v1);
L10:;
  {
   cl_object v6;
   v6 = ecl_car(v3);
   v3 = ecl_cdr(v3);
   v5fdset = v6;
  }
  if (Null(v3)){
   goto L15;
  }
  si_dm_too_many_arguments(v1);
L15:;
  T0 = cl_list(2, v4fd, v5fdset);
  value0 = cl_listX(3, ECL_SYM("C-INLINE",2106), T0, VV[44]);
  return value0;
 }
}
static cl_object LC5402fd_set_va(cl_narg narg, cl_object v6, cl_object v7, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[43]);
 {
  return LC5402fd_set(v6, v7);
 }
}
/* local function FD-ISSET                                                    */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5403fd_isset(cl_object v1, cl_object v2)
{
 cl_object T0;
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 {
  cl_object v3;
  cl_object v4fd;
  cl_object v5fdset;
  v3 = ecl_cdr(v1);
  if (!(v3==ECL_NIL)){
   goto L4;
  }
  si_dm_too_few_arguments(v1);
L4:;
  {
   cl_object v6;
   v6 = ecl_car(v3);
   v3 = ecl_cdr(v3);
   v4fd = v6;
  }
  if (!(v3==ECL_NIL)){
   goto L10;
  }
  si_dm_too_few_arguments(v1);
L10:;
  {
   cl_object v6;
   v6 = ecl_car(v3);
   v3 = ecl_cdr(v3);
   v5fdset = v6;
  }
  if (Null(v3)){
   goto L15;
  }
  si_dm_too_many_arguments(v1);
L15:;
  T0 = cl_list(2, v4fd, v5fdset);
  value0 = cl_listX(3, ECL_SYM("C-INLINE",2106), T0, VV[47]);
  return value0;
 }
}
static cl_object LC5403fd_isset_va(cl_narg narg, cl_object v6, cl_object v7, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[46]);
 {
  return LC5403fd_isset(v6, v7);
 }
}
/* function definition for FDSET-SIZE                                         */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5404fdset_size()
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
L1:;
 value0 = ecl_make_int(sizeof(fd_set));
 cl_env_copy->nvalues = 1;
 return value0;
}
static cl_object L5404fdset_size_va(cl_narg narg, ...)
{
 if (ecl_unlikely(narg!=0)) FEwrong_num_arguments(VV[49]);
 {
  return L5404fdset_size();
 }
}
/* function definition for SERVE-EVENT                                        */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5405serve_event(volatile cl_narg narg, ...)
{
 cl_object T0, T1;
 cl_object volatile env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object volatile value0;
 ecl_cs_check(cl_env_copy,value0);
 if (ecl_unlikely(narg>1)) FEwrong_num_arguments(VV[51]);
 {
  cl_object volatile v1seconds;
  va_list args; va_start(args,narg);
  {
   int i = 0;
   if (i >= narg) {
    v1seconds = ECL_NIL;
   } else {
    i++;
    v1seconds = va_arg(args,cl_object);
   }
  }
  va_end(args);
  {
   volatile cl_object v2fsize;
   v2fsize = L5404fdset_size();
   {
    volatile cl_object v3rfd;
    T0 = cl_list(3, ECL_SYM("ARRAY",1229), ECL_SYM("UNSIGNED-CHAR",1430), v2fsize);
    v3rfd = (cl_env_copy->function=ecl_fdefinition(ECL_SYM("ALLOCATE-FOREIGN-OBJECT",2104)))->cfun.entry(1, T0) /*  ALLOCATE-FOREIGN-OBJECT */;
    {
     struct ecl_stack_frame _ecl_inner_frame_aux;
     volatile cl_object _ecl_inner_frame=ecl_stack_frame_open(cl_env_copy,(cl_object)&_ecl_inner_frame_aux,0);
     {
      volatile cl_object v4;
      v4 = ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*INTERRUPTS-ENABLED*",7));
      ecl_bds_bind(cl_env_copy,ECL_SYM("*INTERRUPTS-ENABLED*",7),ECL_NIL); /*  *INTERRUPTS-ENABLED* */
      ecl_bds_bind(cl_env_copy,ECL_SYM("*ALLOW-WITH-INTERRUPTS*",1821),ECL_NIL); /*  *ALLOW-WITH-INTERRUPTS* */
      {
       struct ecl_stack_frame _ecl_inner_frame_aux;
       volatile cl_object _ecl_inner_frame=ecl_stack_frame_open(cl_env_copy,(cl_object)&_ecl_inner_frame_aux,0);
       volatile bool unwinding = FALSE;
       ecl_frame_ptr next_fr;
       {
        ecl_frs_push(cl_env_copy,ECL_PROTECT_TAG);
        if (__ecl_frs_push_result!=0) {
          unwinding = TRUE; next_fr=cl_env_copy->frs_stack.nlj_fr;
        } else {
        ecl_bds_bind(cl_env_copy,ECL_SYM("*INTERRUPTS-ENABLED*",7),v4); /*  *INTERRUPTS-ENABLED* */
        {
         volatile cl_object v5wfd;
         T0 = cl_list(3, ECL_SYM("ARRAY",1229), ECL_SYM("UNSIGNED-CHAR",1430), v2fsize);
         v5wfd = (cl_env_copy->function=ecl_fdefinition(ECL_SYM("ALLOCATE-FOREIGN-OBJECT",2104)))->cfun.entry(1, T0) /*  ALLOCATE-FOREIGN-OBJECT */;
         {
          struct ecl_stack_frame _ecl_inner_frame_aux;
          volatile cl_object _ecl_inner_frame=ecl_stack_frame_open(cl_env_copy,(cl_object)&_ecl_inner_frame_aux,0);
          {
          volatile cl_object v6;
          v6 = ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*INTERRUPTS-ENABLED*",7));
          ecl_bds_bind(cl_env_copy,ECL_SYM("*INTERRUPTS-ENABLED*",7),ECL_NIL); /*  *INTERRUPTS-ENABLED* */
          ecl_bds_bind(cl_env_copy,ECL_SYM("*ALLOW-WITH-INTERRUPTS*",1821),ECL_NIL); /*  *ALLOW-WITH-INTERRUPTS* */
          {
          struct ecl_stack_frame _ecl_inner_frame_aux;
          volatile cl_object _ecl_inner_frame=ecl_stack_frame_open(cl_env_copy,(cl_object)&_ecl_inner_frame_aux,0);
          volatile bool unwinding = FALSE;
          ecl_frame_ptr next_fr;
          {
          ecl_frs_push(cl_env_copy,ECL_PROTECT_TAG);
          if (__ecl_frs_push_result!=0) {
            unwinding = TRUE; next_fr=cl_env_copy->frs_stack.nlj_fr;
          } else {
          ecl_bds_bind(cl_env_copy,ECL_SYM("*INTERRUPTS-ENABLED*",7),v6); /*  *INTERRUPTS-ENABLED* */
          FD_ZERO((fd_set*)v3rfd->foreign.data);
          value0 = ECL_NIL;
          cl_env_copy->nvalues = 0;
          FD_ZERO((fd_set*)v5wfd->foreign.data);
          value0 = ECL_NIL;
          cl_env_copy->nvalues = 0;
          {
          cl_object v7maxfd;
          v7maxfd = ecl_make_int8_t(0);
          {
          cl_object v8;
          v8 = ecl_cmp_symbol_value(cl_env_copy,VV[23]);
          goto L18;
L17:;
          {
          cl_object v9handler;
          v9handler = ecl_car(v8);
          T0 = ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*CURRENT-PROCESS*",1442));
          T1 = (cl_env_copy->function=ecl_fdefinition(VV[14]))->cfun.entry(1, v9handler) /*  HANDLER-THREAD */;
          if (!((T0)==(T1))){
          goto L22;
          }
          {
          cl_object v10fd;
          v10fd = (cl_env_copy->function=ecl_fdefinition(VV[19]))->cfun.entry(1, v9handler) /*  HANDLER-DESCRIPTOR */;
          {
          cl_object v11;
          v11 = (cl_env_copy->function=ecl_fdefinition(VV[21]))->cfun.entry(1, v9handler) /*  HANDLER-DIRECTION */;
          if (!((v11)==(ECL_SYM("INPUT",1289)))){
          goto L28;
          }
          FD_SET(ecl_to_int(v10fd), (fd_set*)v3rfd->foreign.data);;
          value0 = ECL_NIL;
          cl_env_copy->nvalues = 0;
          goto L26;
L28:;
          if (!((v11)==(ECL_SYM("OUTPUT",1319)))){
          goto L30;
          }
          FD_SET(ecl_to_int(v10fd), (fd_set*)v5wfd->foreign.data);;
          value0 = ECL_NIL;
          cl_env_copy->nvalues = 0;
          goto L26;
L30:;
          si_ecase_error(v11, VV[8]);
          }
L26:;
          if (!(ecl_greater(v10fd,v7maxfd))){
          goto L22;
          }
          v7maxfd = v10fd;
          }
L22:;
          }
          v8 = ecl_cdr(v8);
L18:;
          if (Null(v8)){
          goto L36;
          }
          goto L17;
L36:;
          }
          {
          cl_object v8;                           /*  RETVAL                  */
          cl_object v9;                           /*  ERRNO                   */
          if (!(v1seconds==ECL_NIL)){
          goto L39;
          }
          T0 = ecl_one_plus(v7maxfd);
          {
          int v10;
          int v11;
          { v10= select(ecl_to_int(T0), (fd_set*)v3rfd->foreign.data,
                                                      (fd_set*)v5wfd->foreign.data,
                                                      NULL, NULL);
                             v11= errno; }
          cl_env_copy->values[0] = ecl_make_int(v10);
          cl_env_copy->values[1] = ecl_make_int(v11);cl_env_copy->nvalues = 2;
          value0 = cl_env_copy->values[0];
          goto L38;
          }
L39:;
          T0 = ecl_one_plus(v7maxfd);
          {
          int v10;
          int v11;
          { struct timeval tv;
                             double seconds = ecl_to_double(v1seconds);
                                tv.tv_sec = seconds;
                                tv.tv_usec = (seconds * 1e6);
                                v10= select(ecl_to_int(T0), (fd_set*)v3rfd->foreign.data,
                                                         (fd_set*)v5wfd->foreign.data,
                                                         NULL, &tv);
                                v11= errno; }
          cl_env_copy->values[0] = ecl_make_int(v10);
          cl_env_copy->values[1] = ecl_make_int(v11);cl_env_copy->nvalues = 2;
          value0 = cl_env_copy->values[0];
          }
L38:;
          {
          v8 = value0;
          v9 = cl_env_copy->values[1];
          }
          if (!((ecl_fixnum(v8))==0)){
          goto L41;
          }
          cl_env_copy->values[0] = ECL_NIL;
          cl_env_copy->nvalues = 1;
          ecl_bds_unwind1(cl_env_copy);
          goto L10;
L41:;
          if (!((ecl_fixnum(v8))<0)){
          goto L43;
          }
          if (!(ecl_number_equalp(v9,ecl_cmp_symbol_value(cl_env_copy,VV[1])))){
          goto L45;
          }
          cl_env_copy->values[0] = ECL_NIL;
          cl_env_copy->nvalues = 1;
          ecl_bds_unwind1(cl_env_copy);
          goto L10;
L45:;
          cl_env_copy->values[0] = cl_error(1, VV[52]);
          ecl_bds_unwind1(cl_env_copy);
          goto L10;
L43:;
          if (!((ecl_fixnum(v8))>0)){
          goto L47;
          }
          {
          cl_object v10;
          v10 = ecl_cmp_symbol_value(cl_env_copy,VV[23]);
          goto L53;
L52:;
          {
          cl_object v11handler;
          v11handler = ecl_car(v10);
          T0 = ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*CURRENT-PROCESS*",1442));
          T1 = (cl_env_copy->function=ecl_fdefinition(VV[14]))->cfun.entry(1, v11handler) /*  HANDLER-THREAD */;
          if (!((T0)==(T1))){
          goto L57;
          }
          {
          cl_object v12fd;
          v12fd = (cl_env_copy->function=ecl_fdefinition(VV[19]))->cfun.entry(1, v11handler) /*  HANDLER-DESCRIPTOR */;
          {
          cl_object v13;
          v13 = (cl_env_copy->function=ecl_fdefinition(VV[21]))->cfun.entry(1, v11handler) /*  HANDLER-DIRECTION */;
          if (!((v13)==(ECL_SYM("INPUT",1289)))){
          goto L64;
          }
          T0 = ecl_make_int(FD_ISSET(ecl_to_int(v12fd), (fd_set*)v3rfd->foreign.data));
          goto L62;
L64:;
          if (!((v13)==(ECL_SYM("OUTPUT",1319)))){
          goto L66;
          }
          T0 = ecl_make_int(FD_ISSET(ecl_to_int(v12fd), (fd_set*)v5wfd->foreign.data));
          goto L62;
L66:;
          T0 = si_ecase_error(v13, VV[8]);
          }
L62:;
          if (!(ecl_plusp(T0))){
          goto L57;
          }
          T0 = (cl_env_copy->function=ecl_fdefinition(VV[17]))->cfun.entry(1, v11handler) /*  HANDLER-FUNCTION */;
          T1 = (cl_env_copy->function=ecl_fdefinition(VV[19]))->cfun.entry(1, v11handler) /*  HANDLER-DESCRIPTOR */;
          ecl_function_dispatch(cl_env_copy,T0)(1, T1);
          }
L57:;
          }
          v10 = ecl_cdr(v10);
L53:;
          if (Null(v10)){
          goto L70;
          }
          goto L52;
L70:;
          }
          cl_env_copy->values[0] = ECL_T;
          cl_env_copy->nvalues = 1;
          ecl_bds_unwind1(cl_env_copy);
          goto L10;
L47:;
          cl_env_copy->values[0] = ECL_NIL;
          cl_env_copy->nvalues = 1;
          ecl_bds_unwind1(cl_env_copy);
          }
          }
L10:;
          }
          }
          ecl_frs_pop(cl_env_copy);
          ecl_stack_frame_push_values(_ecl_inner_frame);
          (cl_env_copy->function=ecl_fdefinition(ECL_SYM("FREE-FOREIGN-OBJECT",2140)))->cfun.entry(1, v5wfd) /*  FREE-FOREIGN-OBJECT */;
          ecl_stack_frame_pop_values(_ecl_inner_frame);
          if (unwinding) ecl_unwind(cl_env_copy,next_fr);
          ecl_stack_frame_close(_ecl_inner_frame);
          ecl_bds_unwind1(cl_env_copy);
          ecl_bds_unwind1(cl_env_copy);
          }
          }
          ecl_stack_frame_push_values(_ecl_inner_frame);
          if (Null(ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*INTERRUPTS-ENABLED*",7)))){
          goto L73;
          }
          si_check_pending_interrupts();
L73:;
          ecl_stack_frame_pop_values(_ecl_inner_frame);
          ecl_stack_frame_close(_ecl_inner_frame);
          ecl_bds_unwind1(cl_env_copy);
         }
        }
        }
       }
       ecl_frs_pop(cl_env_copy);
       ecl_stack_frame_push_values(_ecl_inner_frame);
       (cl_env_copy->function=ecl_fdefinition(ECL_SYM("FREE-FOREIGN-OBJECT",2140)))->cfun.entry(1, v3rfd) /*  FREE-FOREIGN-OBJECT */;
       ecl_stack_frame_pop_values(_ecl_inner_frame);
       if (unwinding) ecl_unwind(cl_env_copy,next_fr);
       ecl_stack_frame_close(_ecl_inner_frame);
       ecl_bds_unwind1(cl_env_copy);
       ecl_bds_unwind1(cl_env_copy);
      }
     }
     ecl_stack_frame_push_values(_ecl_inner_frame);
     if (Null(ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*INTERRUPTS-ENABLED*",7)))){
      goto L76;
     }
     si_check_pending_interrupts();
L76:;
     ecl_stack_frame_pop_values(_ecl_inner_frame);
     ecl_stack_frame_close(_ecl_inner_frame);
     return cl_env_copy->values[0];
    }
   }
  }
 }
}
/* function definition for SERVE-ALL-EVENTS                                   */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5406serve_all_events(cl_narg narg, ...)
{
 cl_object env0 = ECL_NIL;
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 ecl_cs_check(cl_env_copy,value0);
 if (ecl_unlikely(narg>1)) FEwrong_num_arguments(VV[54]);
 {
  cl_object v1timeout;
  va_list args; va_start(args,narg);
  {
   int i = 0;
   if (i >= narg) {
    v1timeout = ECL_NIL;
   } else {
    i++;
    v1timeout = va_arg(args,cl_object);
   }
  }
  va_end(args);
  {
   cl_object v2;
   cl_object v3res;
   cl_object v4sval;
   v2 = L5405serve_event(1, v1timeout);
   v3res = ECL_NIL;
   v4sval = v2;
   goto L7;
L6:;
   v3res = ECL_T;
   v4sval = L5405serve_event(1, ecl_make_int8_t(0));
L7:;
   if (v4sval==ECL_NIL) {
    goto L13;
   }
   goto L6;
L13:;
   value0 = v3res;
   cl_env_copy->nvalues = 1;
   return value0;
  }
 }
}
#include "ext/serve-event.data"
#ifdef __cplusplus
extern "C"
#endif

ECL_DLLEXPORT void _eclrvERBJLFNbNm9_JoV1M881(cl_object flag)
{
 const cl_env_ptr cl_env_copy = ecl_process_env();
 cl_object value0;
 cl_object *VVtemp;
 if (flag != OBJNULL){
 Cblock = flag;
 #ifndef ECL_DYNAMIC_VV
 flag->cblock.data = VV;
 #endif
 flag->cblock.data_size = VM;
 flag->cblock.temp_data_size = VMtemp;
 flag->cblock.data_text = compiler_data_text;
 flag->cblock.cfuns_size = compiler_cfuns_size;
 flag->cblock.cfuns = compiler_cfuns;
 flag->cblock.source = ecl_make_constant_base_string("EXT:SERVE-EVENT;SERVE-EVENT.LISP.NEWEST",-1);
 return;}
 #ifdef ECL_DYNAMIC_VV
 VV = Cblock->cblock.data;
 #endif
 Cblock->cblock.data_text = (const cl_object *)"@EcLtAg:_eclrvERBJLFNbNm9_JoV1M881@";
 VVtemp = Cblock->cblock.temp_data;
 ECL_DEFINE_SETF_FUNCTIONS
 {
  cl_object T0;
  cl_object volatile env0 = ECL_NIL;
/* MAKE-LOAD-FORMs                                                            */
/* TOP-LEVEL-FORMs                                                            */
  (cl_env_copy->function=(VV[0]->symbol.gfdef))->cfun.entry(12, _ecl_static_0, ECL_NIL, ECL_NIL, ECL_NIL, VVtemp[0], ECL_NIL, ECL_NIL, ECL_NIL, VVtemp[1], ECL_NIL, ECL_NIL, ECL_NIL) /*  DODEFPACKAGE */;
  si_select_package(_ecl_static_0);
  T0 = ecl_make_int(EINTR);
  si_Xmake_constant(VV[1], T0);
  si_define_structure(VV[4], _ecl_static_1, ECL_NIL, ECL_NIL, VVtemp[2], VVtemp[3], ECL_NIL, ECL_NIL, ECL_NIL, ECL_NIL, VVtemp[4], ecl_make_int8_t(4), ECL_NIL, ECL_NIL, VV[5]);
  VV[12]=cl_find_class(1, VV[4]);
  ecl_cmp_defun(VV[57]);                          /*  MAKE-HANDLER            */
  {
   cl_object v1package;
   v1package = cl_symbol_package(VV[14]);
   if (Null(v1package)){
    goto L17;
   }
   if (Null(si_package_locked_p(v1package))){
    goto L17;
   }
   if (!(ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*IGNORE-PACKAGE-LOCKS*",1128))==ECL_NIL)){
    goto L17;
   }
   si_signal_simple_error(6, ECL_SYM("PACKAGE-ERROR",620), VVtemp[5], VVtemp[6], VVtemp[7], ECL_SYM("PACKAGE",1321), v1package);
  }
L17:;
  {
   cl_object volatile v2;
   v2 = ecl_make_cfun_va((cl_objectfn)LC5392__lambda24_va,ECL_NIL,Cblock,2);
   T0 = v2;
  }
  si_put_sysprop(VV[14], VV[15], T0);
  {
   cl_object v2package;
   v2package = cl_symbol_package(VV[17]);
   if (Null(v2package)){
    goto L25;
   }
   if (Null(si_package_locked_p(v2package))){
    goto L25;
   }
   if (!(ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*IGNORE-PACKAGE-LOCKS*",1128))==ECL_NIL)){
    goto L25;
   }
   si_signal_simple_error(6, ECL_SYM("PACKAGE-ERROR",620), VVtemp[5], VVtemp[6], VVtemp[8], ECL_SYM("PACKAGE",1321), v2package);
  }
L25:;
  {
   cl_object volatile v3;
   v3 = ecl_make_cfun_va((cl_objectfn)LC5393__lambda29_va,ECL_NIL,Cblock,2);
   T0 = v3;
  }
  si_put_sysprop(VV[17], VV[15], T0);
  {
   cl_object v3package;
   v3package = cl_symbol_package(VV[19]);
   if (Null(v3package)){
    goto L33;
   }
   if (Null(si_package_locked_p(v3package))){
    goto L33;
   }
   if (!(ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*IGNORE-PACKAGE-LOCKS*",1128))==ECL_NIL)){
    goto L33;
   }
   si_signal_simple_error(6, ECL_SYM("PACKAGE-ERROR",620), VVtemp[5], VVtemp[6], VVtemp[9], ECL_SYM("PACKAGE",1321), v3package);
  }
L33:;
  {
   cl_object volatile v4;
   v4 = ecl_make_cfun_va((cl_objectfn)LC5394__lambda34_va,ECL_NIL,Cblock,2);
   T0 = v4;
  }
  si_put_sysprop(VV[19], VV[15], T0);
  {
   cl_object v4package;
   v4package = cl_symbol_package(VV[21]);
   if (Null(v4package)){
    goto L41;
   }
   if (Null(si_package_locked_p(v4package))){
    goto L41;
   }
   if (!(ecl_cmp_symbol_value(cl_env_copy,ECL_SYM("*IGNORE-PACKAGE-LOCKS*",1128))==ECL_NIL)){
    goto L41;
   }
   si_signal_simple_error(6, ECL_SYM("PACKAGE-ERROR",620), VVtemp[5], VVtemp[6], VVtemp[10], ECL_SYM("PACKAGE",1321), v4package);
  }
L41:;
  {
   cl_object volatile v5;
   v5 = ecl_make_cfun_va((cl_objectfn)LC5395__lambda39_va,ECL_NIL,Cblock,2);
   T0 = v5;
  }
  si_put_sysprop(VV[21], VV[15], T0);
  si_Xmake_special(VV[23]);
  if (ecl_boundp(cl_env_copy,VV[23])) {
   goto L51;
  }
  T0 = ECL_NIL;
  ecl_cmp_setq(cl_env_copy,VV[23],T0);
L51:;
  ecl_cmp_defun(VV[58]);                          /*  COERCE-TO-DESCRIPTOR    */
  ecl_cmp_defmacro(VV[59]);                       /*  DO-HANDLERS             */
  ecl_cmp_defun(VV[60]);                          /*  ADD-FD-HANDLER          */
  ecl_cmp_defun(VV[61]);                          /*  REMOVE-FD-HANDLER       */
  ecl_cmp_defmacro(VV[62]);                       /*  WITH-FD-HANDLER         */
  ecl_cmp_defmacro(VV[63]);                       /*  FD-ZERO                 */
  ecl_cmp_defmacro(VV[64]);                       /*  FD-SET                  */
  ecl_cmp_defmacro(VV[65]);                       /*  FD-ISSET                */
  ecl_cmp_defun(VV[66]);                          /*  FDSET-SIZE              */
  ecl_cmp_defun(VV[67]);                          /*  SERVE-EVENT             */
  ecl_cmp_defun(VV[68]);                          /*  SERVE-ALL-EVENTS        */
  cl_provide(VV[56]);
 }
}
