import simuvex

class allocate(simuvex.SimProcedure):
    #pylint:disable=arguments-differ

    def run(self, length, is_x, addr): #pylint:disable=unused-argument
        # return code (see allocate() docs)
        r = self.state.se.ite_cases((
                (length == 0, self.state.cgc.EINVAL),
                (length > self.state.cgc.max_allocation, self.state.cgc.EINVAL),
                (self.state.cgc.addr_invalid(addr), self.state.cgc.EFAULT),
            ), self.state.se.BVV(0, self.state.arch.bits))

        aligned_length = ((length + 0xfff) / 0x1000) * 0x1000
        self.state.cgc.allocation_base += self.state.se.If(r == 0, aligned_length, self.state.se.BVV(0, self.state.arch.bits))

        self.state.store_mem(addr, self.state.cgc.allocation_base, condition=self.state.se.And(r == 0, addr != 0), endness='Iend_LE')
        return r

@@ -571,32 +571,46 @@
  0x1000%0A        
+if isinstance(
 self.state.cgc.a
@@ -627,52 +627,68 @@
 base
- += self.state.se.If(r == 0, aligned_length,
+, (int, long)):%0A            self.state.cgc.allocation_base =
  sel
@@ -691,34 +691,28 @@
  self.state.
-se.
 BVV(
-0, 
 self.state.a
@@ -706,36 +706,44 @@
 (self.state.
-arch.bits))%0A
+cgc.allocation_base)
 %0A        sel
@@ -864,16 +864,144 @@
 end_LE')
+%0A%0A        self.state.cgc.allocation_base += self.state.se.If(r == 0, aligned_length, self.state.se.BVV(0, self.state.arch.bits))
 %0A       

return the correct base address