ats_void_type
atslib_randsize_r (ats_ref_type arg0, ats_size_type arg1, ats_ref_type arg2) {
/* local vardec */
// ATSlocal_void (tmp57) ;
ATSlocal (ats_double_type, tmp58) ;
ATSlocal (ats_int_type, tmp59) ;
ATSlocal (ats_ullint_type, tmp60) ;
ATSlocal (ats_double_type, tmp61) ;
ATSlocal (ats_double_type, tmp62) ;
ATSlocal (ats_bool_type, tmp63) ;
ATSlocal (ats_size_type, tmp64) ;

__ats_lab_atslib_randsize_r:
/* ats_double_type tmp58 ; */
tmp59 = atslib_drand48_r (arg0, (&tmp58)) ;
tmp62 = atspre_double_of_size (arg1) ;
tmp61 = atspre_mul_double_double (tmp58, tmp62) ;
tmp60 = atspre_ullint_of_double (tmp61) ;
tmp63 = atspre_lt_size1_size1 (ats_castfn_mac(ats_size_type, ats_castfn_mac(ats_size_type, tmp60)), arg1) ;
if (tmp63) {
ats_ptrget_mac(ats_size_type, arg2) = ats_castfn_mac(ats_size_type, ats_castfn_mac(ats_size_type, tmp60)) ;
} else {
tmp64 = atspre_size1_of_int1 (0) ;
ats_ptrget_mac(ats_size_type, arg2) = tmp64 ;
} /* end of [if] */
return /* (tmp57) */ ;
} /* end of [atslib_randsize_r] */
ats_void_type
atslib_fildes_write_all_exn (ats_int_type arg0, ats_ref_type arg1, ats_size_type arg2) {
/* local vardec */
// ATSlocal_void (tmp49) ;
ATSlocal (ats_int_type, tmp50) ;
ATSlocal (ats_ssize_type, tmp51) ;
ATSlocal (ats_bool_type, tmp53) ;
ATSlocal (ats_bool_type, tmp54) ;
ATSlocal (ats_int_type, tmp55) ;
ATSlocal (ats_int_type, tmp56) ;
ATSlocal (ats_bool_type, tmp57) ;
// ATSlocal_void (tmp58) ;

__ats_lab_atslib_fildes_write_all_exn:
/* ats_int_type tmp50 ; */
tmp50 = 0 ;
tmp51 = atslib_fildes_write_all_err (arg0, arg1, arg2) ;
tmp53 = atspre_gte_ssize1_int1 (tmp51, 0) ;
if (tmp53) {
tmp54 = atspre_lt_size1_size1 (ats_castfn_mac(ats_size_type, tmp51), arg2) ;
if (tmp54) {
tmp55 = atspre_iadd (tmp50, 1) ;
tmp50 = tmp55 ;
} else {
/* empty */
} /* end of [if] */
} else {
tmp56 = atspre_iadd (tmp50, 1) ;
tmp50 = tmp56 ;
} /* end of [if] */
tmp57 = atspre_gt_int_int (tmp50, 0) ;
if (tmp57) {
/* tmp58 = */ atslib_perror (ATSstrcst("write")) ;
/* tmp49 = */ ats_exit_errmsg (EXIT_FAILURE, ATSstrcst("exit(ATS): [write_all]: failed\n")) ;
} else {
/* empty */
} /* end of [if] */
return /* (tmp49) */ ;
} /* end of [atslib_fildes_write_all_exn] */
ats_size_type
atslib_randsize (ats_size_type arg0) {
/* local vardec */
ATSlocal (ats_size_type, tmp14) ;
ATSlocal (ats_double_type, tmp15) ;
ATSlocal (ats_ullint_type, tmp16) ;
ATSlocal (ats_double_type, tmp17) ;
ATSlocal (ats_double_type, tmp18) ;
ATSlocal (ats_bool_type, tmp19) ;

__ats_lab_atslib_randsize:
tmp15 = atslib_drand48 () ;
tmp18 = atspre_double_of_size (arg0) ;
tmp17 = atspre_mul_double_double (tmp15, tmp18) ;
tmp16 = atspre_ullint_of_double (tmp17) ;
tmp19 = atspre_lt_size1_size1 (ats_castfn_mac(ats_size_type, ats_castfn_mac(ats_size_type, tmp16)), arg0) ;
if (tmp19) {
tmp14 = ats_castfn_mac(ats_size_type, ats_castfn_mac(ats_size_type, tmp16)) ;
} else {
tmp14 = atspre_size1_of_int1 (0) ;
} /* end of [if] */
return (tmp14) ;
} /* end of [atslib_randsize] */