def divmod_by_constant(builder, val, divisor):
 assert (divisor > 0)
 divisor = val.type(divisor)
 one = val.type(1)
 quot = alloca_once(builder, val.type)
 with builder.if_else(is_neg_int(builder, val)) as (if_neg, if_pos):
  with if_pos:
   quot_val = builder.sdiv(val, divisor)
   builder.store(quot_val, quot)
  with if_neg:
   val_plus_one = builder.add(val, one)
   quot_val = builder.sdiv(val_plus_one, divisor)
   builder.store(builder.sub(quot_val, one), quot)
 quot_val = builder.load(quot)
 rem_val = builder.sub(val, builder.mul(quot_val, divisor))
 return (quot_val, rem_val)

def divmod_by_constant ( builder , val , divisor ) : assert ( divisor > 0 ) divisor = val . type ( divisor ) one = val . type ( 1 ) quot = alloca_once ( builder , val . type ) with builder . if_else ( is_neg_int ( builder , val ) ) as ( if_neg , if_pos ) : with if_pos : quot_val = builder . sdiv ( val , divisor ) builder . store ( quot_val , quot ) with if_neg : val_plus_one = builder . add ( val , one ) quot_val = builder . sdiv ( val_plus_one , divisor ) builder . store ( builder . sub ( quot_val , one ) , quot ) quot_val = builder . load ( quot ) rem_val = builder . sub ( val , builder . mul ( quot_val , divisor ) ) return ( quot_val , rem_val )
compute the of *val* divided by the constant positive *divisor* .