/* Compiler: ECL 26.3.27                                                      */
/* Source: /build/ecl/src/ecl-26.3.27/contrib/ecl-curl/ecl-curl.lisp          */
#include <ecl/ecl-cmp.h>
#include "ext/ecl-curl.eclh"
/* local function LAMBDA0                                                     */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5408__lambda0()
{
 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 v1;
  v1 = ecl_make_cfun_va((cl_objectfn)LC5407__lambda2_va,ECL_NIL,Cblock,2);
  value0 = v1;
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
static cl_object LC5408__lambda0_va(cl_narg narg, ...)
{
 if (ecl_unlikely(narg!=0)) FEwrong_num_arguments(VV[4]);
 {
  return LC5408__lambda0();
 }
}
/* function definition for COPY-STREAM                                        */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5409copy_stream(cl_object v1from, cl_object v2to)
{
 cl_object T0, T1;
 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:;
 T0 = cl_stream_element_type(v2to);
 T1 = cl_stream_element_type(v1from);
 if (cl_subtypep(2, T0, T1)!=ECL_NIL) {
  goto L2;
 }
 cl_error(3, VV[11], v1from, v2to);
L2:;
 {
  cl_object v3buf;
  {
   cl_object v4;
   cl_object v5;
   v4 = ecl_cmp_symbol_value(cl_env_copy,VV[9]);
   v5 = cl_stream_element_type(v1from);
   v3buf = si_make_pure_array(v5, v4, ECL_NIL, ECL_NIL, ECL_NIL, ecl_make_int8_t(0));
  }
L7:;
  {
   cl_object v4pos;
   v4pos = cl_read_sequence(2, v3buf, v1from);
   if (!((ecl_fixnum(v4pos))==0)){
    goto L10;
   }
   value0 = ECL_NIL;
   cl_env_copy->nvalues = 1;
   return value0;
L10:;
   cl_write_sequence(4, v3buf, v2to, ECL_SYM("END",1256), v4pos);
  }
  goto L7;
 }
}
static cl_object L5409copy_stream_va(cl_narg narg, cl_object v4from, cl_object v5to, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[10]);
 {
  return L5409copy_stream(v4from, v5to);
 }
}
/* function definition for MAKE-STREAM-FROM-URL                               */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5410make_stream_from_url(cl_object v1url)
{
 cl_object T0, T1, T2, T3, T4;
 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 v2s;
  v2s = (cl_env_copy->function=(ECL_SYM("MAKE-INSTANCE",953)->symbol.gfdef))->cfun.entry(5, VV[14], ECL_SYM("TYPE",1356), ECL_SYM("STREAM",1350), VV[15], VV[16]) /*  MAKE-INSTANCE */;
  T0 = L5411url_host(v1url);
  T1 = (cl_env_copy->function=ecl_fdefinition(VV[19]))->cfun.entry(1, T0) /*  GET-HOST-BY-NAME */;
  T2 = (cl_env_copy->function=ecl_fdefinition(VV[18]))->cfun.entry(1, T1) /*  HOST-ENT-ADDRESSES */;
  T3 = ecl_car(T2);
  T4 = L5412url_port(v1url);
  (cl_env_copy->function=ecl_fdefinition(VV[17]))->cfun.entry(3, v2s, T3, T4) /*  SOCKET-CONNECT */;
  value0 = (cl_env_copy->function=ecl_fdefinition(VV[22]))->cfun.entry(9, v2s, ECL_SYM("INPUT",1289), ECL_T, ECL_SYM("OUTPUT",1319), ECL_T, VV[23], ECL_SYM("FULL",1678), ECL_SYM("EXTERNAL-FORMAT",1267), ECL_SYM("ISO-8859-1",1758)) /*  SOCKET-MAKE-STREAM */;
  return value0;
 }
}
static cl_object L5410make_stream_from_url_va(cl_narg narg, cl_object v3url, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[13]);
 {
  return L5410make_stream_from_url(v3url);
 }
}
/* function definition for URL-HOST                                           */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5411url_host(cl_object v1url)
{
 cl_object T0, T1;
 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:;
 goto L4;
L3:;
 si_assert_failure(1, VV[25]);
L4:;
 if (cl_string_equal(4, v1url, VV[26], ECL_SYM("END1",1257), ecl_make_int8_t(7))!=ECL_NIL) {
  goto L7;
 }
 goto L3;
L7:;
 {
  cl_object v2port_start;
  cl_object v3host_end;
  v2port_start = cl_position(4, ECL_CODE_CHAR(58), v1url, ECL_SYM("START",1347), ecl_make_int8_t(7));
  value0 = cl_position(4, ECL_CODE_CHAR(47), v1url, ECL_SYM("START",1347), ecl_make_int8_t(7));
  if (value0!=ECL_NIL) {
   goto L13;
  }
  T0 = ecl_make_fixnum(ecl_length(v1url));
  goto L11;
L13:;
  T0 = value0;
  goto L11;
L11:;
  value0 = v2port_start;
  if (value0!=ECL_NIL) {
   goto L17;
  }
  T1 = ecl_make_fixnum(ecl_length(v1url));
  goto L15;
L17:;
  T1 = value0;
  goto L15;
L15:;
  v3host_end = ecl_make_fixnum((ecl_fixnum(T0))<=(ecl_fixnum(T1))?ecl_fixnum(T0):ecl_fixnum(T1));
  value0 = cl_subseq(3, v1url, ecl_make_int8_t(7), v3host_end);
  return value0;
 }
}
static cl_object L5411url_host_va(cl_narg narg, cl_object v4url, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[20]);
 {
  return L5411url_host(v4url);
 }
}
/* function definition for URL-PORT                                           */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5412url_port(cl_object v1url)
{
 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:;
 goto L4;
L3:;
 si_assert_failure(1, VV[25]);
L4:;
 if (cl_string_equal(4, v1url, VV[26], ECL_SYM("END1",1257), ecl_make_int8_t(7))!=ECL_NIL) {
  goto L7;
 }
 goto L3;
L7:;
 {
  cl_object v2port_start;
  v2port_start = cl_position(4, ECL_CODE_CHAR(58), v1url, ECL_SYM("START",1347), ecl_make_int8_t(7));
  if (Null(v2port_start)){
   goto L10;
  }
  T0 = ecl_one_plus(v2port_start);
  value0 = cl_parse_integer(5, v1url, ECL_SYM("START",1347), T0, ECL_SYM("JUNK-ALLOWED",1296), ECL_T);
  return value0;
L10:;
  value0 = ecl_make_int8_t(80);
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
static cl_object L5412url_port_va(cl_narg narg, cl_object v3url, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[21]);
 {
  return L5412url_port(v3url);
 }
}
/* function definition for BASE64-ENCODE                                      */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5413base64_encode(cl_object v1string)
{
 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 v2result;
  {
   cl_object v3;
   {
    cl_fixnum v4;
    v4 = ecl_length(v1string);
    T0 = ecl_plus(ecl_make_int8_t(2),ecl_make_fixnum(v4));
    T1 = ecl_divide(T0,ecl_make_int8_t(3));
    T2 = ecl_truncate1(T1);
    T3 = ecl_times(ecl_make_int8_t(4),T2);
    v3 = ecl_list1(T3);
   }
   v2result = si_make_pure_array(ECL_SYM("BASE-CHAR",122), v3, ECL_NIL, ECL_NIL, ECL_NIL, ecl_make_int8_t(0));
  }
  {
   cl_object v3sidx;
   cl_object v4didx;
   cl_object v5chars;
   cl_object v6value;
   v3sidx = ecl_make_int8_t(0);
   v4didx = ecl_make_int8_t(0);
   v5chars = ecl_make_int8_t(2);
   v6value = ECL_NIL;
   goto L11;
L10:;
   T0 = cl_char(v1string, v3sidx);
   {
    cl_fixnum v7;
    v7 = ECL_CHAR_CODE(T0);
    {
     cl_fixnum v8;
     v8 = (((cl_fixnum)(255)) & (v7));
     v6value = cl_ash(ecl_make_fixnum(v8), ecl_make_int8_t(8));
    }
   }
   {
    cl_fixnum v7n;
    v7n = (cl_fixnum)(0);
    goto L18;
L17:;
    T0 = ecl_plus(v3sidx,ecl_make_fixnum(v7n));
    T1 = ecl_plus(T0,ecl_make_int8_t(1));
    {
     cl_fixnum v8;
     v8 = ecl_length(v1string);
     if (!(ecl_lower(T1,ecl_make_fixnum(v8)))){
      goto L20;
     }
    }
    T0 = ecl_plus(v3sidx,ecl_make_fixnum(v7n));
    T1 = ecl_plus(T0,ecl_make_int8_t(1));
    T2 = cl_char(v1string, T1);
    {
     cl_fixnum v8;
     v8 = ECL_CHAR_CODE(T2);
     {
      cl_fixnum v9;
      v9 = (((cl_fixnum)(255)) & (v8));
      v6value = ecl_boole(ECL_BOOLIOR,(v6value),(ecl_make_fixnum(v9)));
     }
    }
    v5chars = ecl_plus(v5chars,ecl_make_int8_t(1));
L20:;
    if (!((v7n)==((cl_fixnum)(0)))){
     goto L25;
    }
    v6value = cl_ash(v6value, ecl_make_int8_t(8));
L25:;
    v7n = (v7n)+1;
L18:;
    if (!((v7n)<((cl_fixnum)(2)))){
     goto L30;
    }
    goto L17;
L30:;
   }
   T0 = ecl_plus(v4didx,ecl_make_int8_t(3));
   T1 = ecl_cmp_symbol_value(cl_env_copy,VV[29]);
   if (!(ecl_greater(v5chars,ecl_make_int8_t(3)))){
    goto L35;
   }
   T2 = ecl_boole(ECL_BOOLAND,(v6value),(ecl_make_int8_t(63)));
   goto L34;
L35:;
   T2 = ecl_make_int8_t(64);
L34:;
   T3 = ecl_elt(T1,ecl_to_size(T2));
   ecl_elt_set(v2result,ecl_to_size(T0),T3);
   v6value = cl_ash(v6value, ecl_make_int8_t(-6));
   T0 = ecl_plus(v4didx,ecl_make_int8_t(2));
   T1 = ecl_cmp_symbol_value(cl_env_copy,VV[29]);
   if (!(ecl_greater(v5chars,ecl_make_int8_t(2)))){
    goto L42;
   }
   T2 = ecl_boole(ECL_BOOLAND,(v6value),(ecl_make_int8_t(63)));
   goto L41;
L42:;
   T2 = ecl_make_int8_t(64);
L41:;
   T3 = ecl_elt(T1,ecl_to_size(T2));
   ecl_elt_set(v2result,ecl_to_size(T0),T3);
   v6value = cl_ash(v6value, ecl_make_int8_t(-6));
   T0 = ecl_plus(v4didx,ecl_make_int8_t(1));
   T1 = ecl_cmp_symbol_value(cl_env_copy,VV[29]);
   T2 = ecl_boole(ECL_BOOLAND,(v6value),(ecl_make_int8_t(63)));
   T3 = ecl_elt(T1,ecl_to_size(T2));
   ecl_elt_set(v2result,ecl_to_size(T0),T3);
   v6value = cl_ash(v6value, ecl_make_int8_t(-6));
   T0 = ecl_cmp_symbol_value(cl_env_copy,VV[29]);
   T1 = ecl_boole(ECL_BOOLAND,(v6value),(ecl_make_int8_t(63)));
   T2 = ecl_elt(T0,ecl_to_size(T1));
   ecl_elt_set(v2result,ecl_to_size(v4didx),T2);
   v3sidx = ecl_plus(v3sidx,ecl_make_int8_t(3));
   v4didx = ecl_plus(v4didx,ecl_make_int8_t(4));
   v5chars = ecl_make_int8_t(2);
   v6value = ECL_NIL;
L11:;
   {
    cl_fixnum v7;
    v7 = ecl_length(v1string);
    if (ecl_greatereq(v3sidx,ecl_make_fixnum(v7))) {
     goto L57;
    }
   }
   goto L10;
L57:;
  }
  value0 = v2result;
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
static cl_object L5413base64_encode_va(cl_narg narg, cl_object v3string, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[30]);
 {
  return L5413base64_encode(v3string);
 }
}
/* function definition for REQUEST-URI                                        */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5414request_uri(cl_object v1url)
{
 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:;
 goto L4;
L3:;
 si_assert_failure(1, VV[25]);
L4:;
 if (cl_string_equal(4, v1url, VV[26], ECL_SYM("END1",1257), ecl_make_int8_t(7))!=ECL_NIL) {
  goto L7;
 }
 goto L3;
L7:;
 if (Null(ecl_cmp_symbol_value(cl_env_copy,VV[32]))){
  goto L9;
 }
 value0 = v1url;
 cl_env_copy->nvalues = 1;
 return value0;
L9:;
 {
  cl_object v2path_start;
  v2path_start = cl_position(4, ECL_CODE_CHAR(47), v1url, ECL_SYM("START",1347), ecl_make_int8_t(7));
  if (Null(v2path_start)){
   goto L12;
  }
  value0 = cl_subseq(2, v1url, v2path_start);
  return value0;
L12:;
  value0 = VV[36];
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
static cl_object L5414request_uri_va(cl_narg narg, cl_object v3url, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[35]);
 {
  return L5414request_uri(v3url);
 }
}
/* function definition for HEADER-PAIR                                        */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5416header_pair(cl_object v1name, cl_object v2headers)
{
 cl_object T0, T1;
 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;
   v4 = ecl_make_cfun_va((cl_objectfn)LC5415__lambda92_va,ECL_NIL,Cblock,2);
   v3 = v4;
  }
  {
   cl_object v4;
   v4 = v2headers;
   goto L6;
L5:;
   {
    cl_object v5;
    cl_object v6;
    {
     cl_object v7;
     v7 = v4;
     if (ecl_unlikely(ECL_ATOM(v7))) FEtype_error_cons(v7);
     value0 = ECL_NIL;
     cl_env_copy->nvalues = 0;
     v5 = v7;
    }
    v6 = ECL_CONS_CAR(v5);
    if (Null(v6)){
     goto L8;
    }
    {
     cl_object v7;
     {
      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;
     }
     v7 = ECL_CONS_CAR(T0);
     T0 = ecl_symbol_name(v1name);
     T1 = ecl_symbol_name(v7);
     if (Null(cl_string_equal(2, T0, T1))){
      goto L8;
     }
     value0 = v6;
     cl_env_copy->nvalues = 1;
     return value0;
    }
   }
L8:;
   v4 = ECL_CONS_CDR(v4);
L6:;
   if (v4==ECL_NIL) {
    goto L21;
   }
   goto L5;
L21:;
   value0 = ECL_NIL;
   cl_env_copy->nvalues = 1;
   return value0;
  }
 }
}
static cl_object L5416header_pair_va(cl_narg narg, cl_object v5name, cl_object v6headers, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[38]);
 {
  return L5416header_pair(v5name, v6headers);
 }
}
/* function definition for HEADER-VALUE                                       */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5417header_value(cl_object v1name, cl_object v2headers)
{
 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:;
 T0 = L5416header_pair(v1name, v2headers);
 value0 = ecl_cdr(T0);
 cl_env_copy->nvalues = 1;
 return value0;
}
static cl_object L5417header_value_va(cl_narg narg, cl_object v3name, cl_object v4headers, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[44]);
 {
  return L5417header_value(v3name, v4headers);
 }
}
/* function definition for URL-CONNECTION                                     */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5418url_connection(cl_object v1url)
{
 cl_object T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10;
 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;
  cl_object v3;
  value0 = ecl_cmp_symbol_value(cl_env_copy,VV[32]);
  if (value0!=ECL_NIL) {
   goto L5;
  }
  T0 = v1url;
  goto L3;
L5:;
  T0 = value0;
  goto L3;
L3:;
  v2 = L5410make_stream_from_url(T0);
  v3 = L5411url_host(v1url);
  T0 = L5414request_uri(v1url);
  cl_format(8, v2, VV[47], T0, ECL_CODE_CHAR(13), ECL_CODE_CHAR(10), v3, ECL_CODE_CHAR(13), ECL_CODE_CHAR(10));
  if (Null(ecl_cmp_symbol_value(cl_env_copy,VV[34]))){
   goto L9;
  }
  if (Null(ecl_cmp_symbol_value(cl_env_copy,VV[33]))){
   goto L9;
  }
  T0 = cl_format(4, ECL_NIL, VV[49], ecl_cmp_symbol_value(cl_env_copy,VV[33]), ecl_cmp_symbol_value(cl_env_copy,VV[34]));
  T1 = L5413base64_encode(T0);
  cl_format(5, v2, VV[48], T1, ECL_CODE_CHAR(13), ECL_CODE_CHAR(10));
L9:;
  cl_format(4, v2, VV[50], ECL_CODE_CHAR(13), ECL_CODE_CHAR(10));
  cl_force_output(1, v2);
  {
   cl_object v4l;
   cl_object v5space;
   v4l = cl_read_line(1, v2);
   v5space = cl_position(2, ECL_CODE_CHAR(32), v4l);
   T1 = ecl_one_plus(v5space);
   T0 = cl_parse_integer(5, v4l, ECL_SYM("START",1347), T1, ECL_SYM("JUNK-ALLOWED",1296), ECL_T);
  }
  {
   cl_object v4line;
   v4line = ECL_NIL;
   {
    cl_object v5;
    cl_object v6;
    v5 = ecl_list1(ECL_NIL);
    v6 = v5;
L21:;
    v4line = cl_read_line(1, v2);
    if (v4line==ECL_NIL) {
     goto L27;
    }
    {
     cl_fixnum v7;
     v7 = ecl_length(v4line);
     if ((v7)==0) {
      goto L27;
     }
    }
    T2 = ecl_elt(v4line,(cl_fixnum)(0));
    {
     ecl_character v7;
     v7 = (cl_fixnum)(13);
     if (!(((T2)==ECL_CODE_CHAR(v7)))){
      goto L25;
     }
     goto L26;
    }
L27:;
L26:;
    goto L22;
L25:;
    {
     cl_object v7;
     v7 = v6;
     if (ecl_unlikely(ECL_ATOM(v7))) FEtype_error_cons(v7);
     value0 = ECL_NIL;
     cl_env_copy->nvalues = 0;
     T2 = v7;
    }
    {
     cl_object v7colon;
     v7colon = cl_position(2, ECL_CODE_CHAR(58), v4line);
     T4 = cl_subseq(3, v4line, ecl_make_int8_t(0), v7colon);
     T5 = cl_string_upcase(1, T4);
     T6 = cl_intern(2, T5, VV[55]);
     {
      ecl_character v8;
      v8 = (cl_fixnum)(13);
      T7 = cl_list(2, ECL_CODE_CHAR(32), ECL_CODE_CHAR(v8));
      T8 = ecl_one_plus(v7colon);
      T9 = cl_subseq(2, v4line, T8);
      T10 = cl_string_trim(T7, T9);
      T3 = CONS(T6,T10);
     }
    }
    v6 = ecl_list1(T3);
    (ECL_CONS_CDR(T2)=v6,T2);
    goto L21;
L22:;
    T1 = ecl_cdr(v5);
    goto L17;
   }
  }
L17:;
  cl_env_copy->nvalues = 3;
  cl_env_copy->values[2] = v2;
  cl_env_copy->values[1] = T1;
  cl_env_copy->values[0] = T0;
  return cl_env_copy->values[0];
 }
}
static cl_object L5418url_connection_va(cl_narg narg, cl_object v4url, ...)
{
 if (ecl_unlikely(narg!=1)) FEwrong_num_arguments(VV[46]);
 {
  return L5418url_connection(v4url);
 }
}
/* function definition for DOWNLOAD-URL-TO-FILE                               */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object L5419download_url_to_file(volatile cl_narg narg, cl_object volatile v1url, cl_object volatile v2file_name, ...)
{
 cl_object T0;
 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<2)) FEwrong_num_arguments(VV[58]);
 {
  cl_object volatile v3quiet;
  ecl_va_list args; ecl_va_start(args,v2file_name,narg,2);
  {
   cl_object keyvars[2];
   cl_parse_key(args,1,L5419download_url_to_filekeys,keyvars,NULL,FALSE);
   ecl_va_end(args);
   v3quiet = keyvars[0];
  }
  {
   cl_object volatile v4;                         /*  RESPONSE                */
   cl_object volatile v5;                         /*  HEADERS                 */
   cl_object volatile v6;                         /*  STREAM                  */
L3:;
   {
    cl_object volatile v7;                        /*  RESPONSE                */
    cl_object volatile v8;                        /*  HEADERS                 */
    cl_object volatile v9;                        /*  STREAM                  */
    value0 = L5418url_connection(v1url);
    {
     const int v10 = cl_env_copy->nvalues;
     v7 = value0;
     cl_object v11;
     v11 = (v10<=1)? ECL_NIL : cl_env_copy->values[1];
     v8 = v11;
     v11 = (v10<=2)? ECL_NIL : cl_env_copy->values[2];
     v9 = v11;
    }
    if (!((v7)==(ecl_make_fixnum(301)))){
     goto L10;
    }
    goto L6;
L10:;
    goto L8;
L8:;
    if (!((v7)==(ecl_make_fixnum(302)))){
     goto L13;
    }
    goto L6;
L13:;
    goto L7;
L7:;
    cl_env_copy->nvalues = 3;
    cl_env_copy->values[2] = v9;
    cl_env_copy->values[1] = v8;
    cl_env_copy->values[0] = v7;
    value0 = cl_env_copy->values[0];
    goto L2;
L6:;
    cl_close(1, v9);
    v1url = L5417header_value(ECL_SYM("LOCATION",1003), v8);
   }
   goto L3;
L2:;
   {
    const int v7 = cl_env_copy->nvalues;
    v4 = value0;
    cl_object v8;
    v8 = (v7<=1)? ECL_NIL : cl_env_copy->values[1];
    v5 = v8;
    v8 = (v7<=2)? ECL_NIL : cl_env_copy->values[2];
    v6 = v8;
   }
   if (!(ecl_greatereq(v4,ecl_make_fixnum(400)))){
    goto L18;
   }
   cl_error(5, VV[3], VV[61], v1url, VV[62], v4);
L18:;
   {
    volatile cl_object v7length;
    value0 = L5417header_value(VV[63], v5);
    if (value0!=ECL_NIL) {
     goto L24;
    }
    T0 = VV[64];
    goto L22;
L24:;
    T0 = value0;
    goto L22;
L22:;
    v7length = cl_parse_integer(3, T0, ECL_SYM("JUNK-ALLOWED",1296), ECL_T);
    if (v3quiet!=ECL_NIL) {
     goto L26;
    }
    value0 = v7length;
    if (value0!=ECL_NIL) {
     goto L30;
    }
    T0 = VV[66];
    goto L28;
L30:;
    T0 = value0;
    goto L28;
L28:;
    cl_format(5, ECL_T, VV[65], T0, v1url, v2file_name);
L26:;
    cl_force_output(0);
    {
     volatile cl_object v8ok_;
     volatile cl_object v9o;
     v8ok_ = ECL_NIL;
     v9o = ECL_NIL;
     {
      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 {
       v9o = cl_open(7, v2file_name, ECL_SYM("DIRECTION",1249), ECL_SYM("OUTPUT",1319), ECL_SYM("IF-EXISTS",1279), ECL_SYM("SUPERSEDE",1351), ECL_SYM("EXTERNAL-FORMAT",1267), ECL_SYM("LATIN-1",1757));
       if (Null(v7length)){
        goto L39;
       }
       {
        cl_object v10buf;
        {
         cl_object v11;
         v11 = cl_stream_element_type(v6);
         v10buf = si_make_pure_array(v11, v7length, ECL_NIL, ECL_NIL, ECL_NIL, ecl_make_int8_t(0));
        }
        cl_read_sequence(2, v10buf, v6);
        cl_write_sequence(2, v10buf, v9o);
        goto L38;
       }
L39:;
       L5409copy_stream(v6, v9o);
L38:;
       v8ok_ = ECL_T;
       cl_env_copy->values[0] = ECL_T;
       cl_env_copy->nvalues = 1;
       }
      }
      ecl_frs_pop(cl_env_copy);
      ecl_stack_frame_push_values(_ecl_inner_frame);
      if (Null(v9o)){
       goto L45;
      }
      {
       bool v10;
       v10 = v8ok_==ECL_NIL;
       cl_close(3, v9o, ECL_SYM("ABORT",1225), ecl_make_bool(v10));
      }
L45:;
      ecl_stack_frame_pop_values(_ecl_inner_frame);
      if (unwinding) ecl_unwind(cl_env_copy,next_fr);
      ecl_stack_frame_close(_ecl_inner_frame);
     }
    }
   }
   cl_close(1, v6);
  }
  value0 = v1url;
  cl_env_copy->nvalues = 1;
  return value0;
 }
}
/* local function LAMBDA2                                                     */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5407__lambda2(cl_object v1c, cl_object v2s)
{
 cl_object T0, T1;
 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:;
 T0 = (cl_env_copy->function=ecl_fdefinition(VV[7]))->cfun.entry(1, v1c) /*  DOWNLOAD-RESPONSE */;
 T1 = (cl_env_copy->function=ecl_fdefinition(VV[8]))->cfun.entry(1, v1c) /*  DOWNLOAD-URL */;
 value0 = cl_format(4, v2s, VV[6], T0, T1);
 return value0;
}
static cl_object LC5407__lambda2_va(cl_narg narg, cl_object v3c, cl_object v4s, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[5]);
 {
  return LC5407__lambda2(v3c, v4s);
 }
}
/* local function LAMBDA92                                                    */
/* optimize speed 1, debug 1, space 1, safety 2                               */
static cl_object LC5415__lambda92(cl_object v1a, cl_object v2b)
{
 cl_object T0, T1;
 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:;
 T0 = ecl_symbol_name(v1a);
 T1 = ecl_symbol_name(v2b);
 value0 = cl_string_equal(2, T0, T1);
 return value0;
}
static cl_object LC5415__lambda92_va(cl_narg narg, cl_object v3a, cl_object v4b, ...)
{
 if (ecl_unlikely(narg!=2)) FEwrong_num_arguments(VV[39]);
 {
  return LC5415__lambda92(v3a, v4b);
 }
}
#include "ext/ecl-curl.data"
#ifdef __cplusplus
extern "C"
#endif

ECL_DLLEXPORT void _ecl53imhXwD6d7l9_mUW1M881(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:ECL-CURL;ECL-CURL.LISP.NEWEST",-1);
 return;}
 #ifdef ECL_DYNAMIC_VV
 VV = Cblock->cblock.data;
 #endif
 Cblock->cblock.data_text = (const cl_object *)"@EcLtAg:_ecl53imhXwD6d7l9_mUW1M881@";
 VVtemp = Cblock->cblock.temp_data;
 ECL_DEFINE_SETF_FUNCTIONS
 {
  cl_object T0, T1, T2;
  cl_object volatile env0 = ECL_NIL;
/* MAKE-LOAD-FORMs                                                            */
/* TOP-LEVEL-FORMs                                                            */
  cl_require(1, VV[0]);
  (cl_env_copy->function=(VV[1]->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);
  clos_load_defclass(VV[2], VVtemp[2], VVtemp[3], ECL_NIL);
  {
   cl_object volatile v1;
   v1 = ecl_make_cfun_va((cl_objectfn)LC5408__lambda0_va,ECL_NIL,Cblock,0);
   T0 = v1;
  }
  T1 = cl_listX(3, ECL_SYM("INITFUNCTION",1001), T0, VVtemp[5]);
  T2 = cl_list(2, T1, VVtemp[6]);
  clos_load_defclass(VV[3], VVtemp[4], T2, ECL_NIL);
  si_Xmake_special(VV[9]);
  if (ecl_boundp(cl_env_copy,VV[9])) {
   goto L12;
  }
  T0 = ecl_make_fixnum(8192);
  ecl_cmp_setq(cl_env_copy,VV[9],T0);
L12:;
  ecl_cmp_defun(VV[69]);                          /*  COPY-STREAM             */
  ecl_cmp_defun(VV[70]);                          /*  MAKE-STREAM-FROM-URL    */
  ecl_cmp_defun(VV[71]);                          /*  URL-HOST                */
  ecl_cmp_defun(VV[72]);                          /*  URL-PORT                */
  si_Xmake_special(VV[29]);
  T0 = VVtemp[7];
  ecl_cmp_setq(cl_env_copy,VV[29],T0);
  ecl_cmp_defun(VV[73]);                          /*  BASE64-ENCODE           */
  si_Xmake_special(VV[32]);
  if (ecl_boundp(cl_env_copy,VV[32])) {
   goto L40;
  }
  T0 = si_getenv(VVtemp[8]);
  ecl_cmp_setq(cl_env_copy,VV[32],T0);
L40:;
  si_Xmake_special(VV[33]);
  if (ecl_boundp(cl_env_copy,VV[33])) {
   goto L47;
  }
  T0 = ECL_NIL;
  ecl_cmp_setq(cl_env_copy,VV[33],T0);
L47:;
  si_Xmake_special(VV[34]);
  if (ecl_boundp(cl_env_copy,VV[34])) {
   goto L54;
  }
  T0 = ECL_NIL;
  ecl_cmp_setq(cl_env_copy,VV[34],T0);
L54:;
  ecl_cmp_defun(VV[74]);                          /*  REQUEST-URI             */
  ecl_cmp_defun(VV[75]);                          /*  HEADER-PAIR             */
  ecl_cmp_defun(VV[76]);                          /*  HEADER-VALUE            */
  ecl_cmp_defun(VV[77]);                          /*  URL-CONNECTION          */
  ecl_cmp_defun(VV[78]);                          /*  DOWNLOAD-URL-TO-FILE    */
  cl_provide(VV[68]);
 }
}
