|
| 1 | +extern crate libcc2rs; |
| 2 | +use libcc2rs::*; |
| 3 | +use std::cell::RefCell; |
| 4 | +use std::collections::BTreeMap; |
| 5 | +use std::io::prelude::*; |
| 6 | +use std::io::{Read, Seek, Write}; |
| 7 | +use std::os::fd::AsFd; |
| 8 | +use std::rc::{Rc, Weak}; |
| 9 | +pub fn main() { |
| 10 | + std::process::exit(main_0()); |
| 11 | +} |
| 12 | +fn main_0() -> i32 { |
| 13 | + let mut __do_while = true; |
| 14 | + 'loop_: while __do_while || (0 != 0) { |
| 15 | + __do_while = false; |
| 16 | + let p: Value<Ptr<i32>> = Rc::new(RefCell::new( |
| 17 | + libcc2rs::malloc_refcount(::std::mem::size_of::<i32>()).reinterpret_cast::<i32>(), |
| 18 | + )); |
| 19 | + (*p.borrow()).write(42); |
| 20 | + assert!((((((*p.borrow()).read()) == 42) as i32) != 0)); |
| 21 | + libcc2rs::free_refcount(((*p.borrow()).clone() as Ptr<i32>).to_any()); |
| 22 | + let arr: Value<Ptr<i32>> = Rc::new(RefCell::new( |
| 23 | + libcc2rs::malloc_refcount( |
| 24 | + (4_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)), |
| 25 | + ) |
| 26 | + .reinterpret_cast::<i32>(), |
| 27 | + )); |
| 28 | + let i: Value<i32> = Rc::new(RefCell::new(0)); |
| 29 | + 'loop_: while ((((*i.borrow()) < 4) as i32) != 0) { |
| 30 | + let __rhs = ((*i.borrow()) * 10); |
| 31 | + (*arr.borrow()).offset((*i.borrow()) as isize).write(__rhs); |
| 32 | + (*i.borrow_mut()).postfix_inc(); |
| 33 | + } |
| 34 | + assert!((((((*arr.borrow()).offset((0) as isize).read()) == 0) as i32) != 0)); |
| 35 | + assert!((((((*arr.borrow()).offset((3) as isize).read()) == 30) as i32) != 0)); |
| 36 | + libcc2rs::free_refcount(((*arr.borrow()).clone() as Ptr<i32>).to_any()); |
| 37 | + let grow: Value<Ptr<i32>> = Rc::new(RefCell::new( |
| 38 | + libcc2rs::malloc_refcount( |
| 39 | + (2_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)), |
| 40 | + ) |
| 41 | + .reinterpret_cast::<i32>(), |
| 42 | + )); |
| 43 | + (*grow.borrow()).offset((0) as isize).write(1); |
| 44 | + (*grow.borrow()).offset((1) as isize).write(2); |
| 45 | + let __rhs = libcc2rs::realloc_refcount( |
| 46 | + ((*grow.borrow()).clone() as Ptr<i32>).to_any(), |
| 47 | + (4_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)), |
| 48 | + ) |
| 49 | + .reinterpret_cast::<i32>(); |
| 50 | + (*grow.borrow_mut()) = __rhs; |
| 51 | + (*grow.borrow()).offset((2) as isize).write(3); |
| 52 | + (*grow.borrow()).offset((3) as isize).write(4); |
| 53 | + assert!((((((*grow.borrow()).offset((0) as isize).read()) == 1) as i32) != 0)); |
| 54 | + assert!((((((*grow.borrow()).offset((1) as isize).read()) == 2) as i32) != 0)); |
| 55 | + assert!((((((*grow.borrow()).offset((2) as isize).read()) == 3) as i32) != 0)); |
| 56 | + assert!((((((*grow.borrow()).offset((3) as isize).read()) == 4) as i32) != 0)); |
| 57 | + libcc2rs::free_refcount(((*grow.borrow()).clone() as Ptr<i32>).to_any()); |
| 58 | + let zeros: Value<Ptr<i32>> = Rc::new(RefCell::new( |
| 59 | + libcc2rs::calloc_refcount(4_usize, ::std::mem::size_of::<i32>()) |
| 60 | + .reinterpret_cast::<i32>(), |
| 61 | + )); |
| 62 | + let i: Value<i32> = Rc::new(RefCell::new(0)); |
| 63 | + 'loop_: while ((((*i.borrow()) < 4) as i32) != 0) { |
| 64 | + assert!( |
| 65 | + (((((*zeros.borrow()).offset((*i.borrow()) as isize).read()) == 0) as i32) != 0) |
| 66 | + ); |
| 67 | + (*i.borrow_mut()).postfix_inc(); |
| 68 | + } |
| 69 | + libcc2rs::free_refcount(((*zeros.borrow()).clone() as Ptr<i32>).to_any()); |
| 70 | + } |
| 71 | + let pmalloc: Value<FnPtr<fn(usize) -> AnyPtr>> = |
| 72 | + Rc::new(RefCell::new(FnPtr::<fn(usize) -> AnyPtr>::new( |
| 73 | + libcc2rs::malloc_refcount, |
| 74 | + ))); |
| 75 | + let pfree: Value<FnPtr<fn(AnyPtr)>> = Rc::new(RefCell::new(FnPtr::<fn(AnyPtr)>::new( |
| 76 | + libcc2rs::free_refcount, |
| 77 | + ))); |
| 78 | + let prealloc: Value<FnPtr<fn(AnyPtr, usize) -> AnyPtr>> = |
| 79 | + Rc::new(RefCell::new(FnPtr::<fn(AnyPtr, usize) -> AnyPtr>::new( |
| 80 | + libcc2rs::realloc_refcount, |
| 81 | + ))); |
| 82 | + let pcalloc: Value<FnPtr<fn(usize, usize) -> AnyPtr>> = |
| 83 | + Rc::new(RefCell::new(FnPtr::<fn(usize, usize) -> AnyPtr>::new( |
| 84 | + libcc2rs::calloc_refcount, |
| 85 | + ))); |
| 86 | + let mut __do_while = true; |
| 87 | + 'loop_: while __do_while || (0 != 0) { |
| 88 | + __do_while = false; |
| 89 | + let p: Value<Ptr<i32>> = Rc::new(RefCell::new( |
| 90 | + ({ (*(*pmalloc.borrow()))(::std::mem::size_of::<i32>()) }).reinterpret_cast::<i32>(), |
| 91 | + )); |
| 92 | + (*p.borrow()).write(42); |
| 93 | + assert!((((((*p.borrow()).read()) == 42) as i32) != 0)); |
| 94 | + ({ (*(*pfree.borrow()))(((*p.borrow()).clone() as Ptr<i32>).to_any()) }); |
| 95 | + let arr: Value<Ptr<i32>> = Rc::new(RefCell::new( |
| 96 | + ({ |
| 97 | + (*(*pmalloc.borrow()))( |
| 98 | + (4_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)), |
| 99 | + ) |
| 100 | + }) |
| 101 | + .reinterpret_cast::<i32>(), |
| 102 | + )); |
| 103 | + let i: Value<i32> = Rc::new(RefCell::new(0)); |
| 104 | + 'loop_: while ((((*i.borrow()) < 4) as i32) != 0) { |
| 105 | + let __rhs = ((*i.borrow()) * 10); |
| 106 | + (*arr.borrow()).offset((*i.borrow()) as isize).write(__rhs); |
| 107 | + (*i.borrow_mut()).postfix_inc(); |
| 108 | + } |
| 109 | + assert!((((((*arr.borrow()).offset((0) as isize).read()) == 0) as i32) != 0)); |
| 110 | + assert!((((((*arr.borrow()).offset((3) as isize).read()) == 30) as i32) != 0)); |
| 111 | + ({ (*(*pfree.borrow()))(((*arr.borrow()).clone() as Ptr<i32>).to_any()) }); |
| 112 | + let grow: Value<Ptr<i32>> = Rc::new(RefCell::new( |
| 113 | + ({ |
| 114 | + (*(*pmalloc.borrow()))( |
| 115 | + (2_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)), |
| 116 | + ) |
| 117 | + }) |
| 118 | + .reinterpret_cast::<i32>(), |
| 119 | + )); |
| 120 | + (*grow.borrow()).offset((0) as isize).write(1); |
| 121 | + (*grow.borrow()).offset((1) as isize).write(2); |
| 122 | + let __rhs = ({ |
| 123 | + (*(*prealloc.borrow()))( |
| 124 | + ((*grow.borrow()).clone() as Ptr<i32>).to_any(), |
| 125 | + (4_usize).wrapping_mul((::std::mem::size_of::<i32>() as usize)), |
| 126 | + ) |
| 127 | + }) |
| 128 | + .reinterpret_cast::<i32>(); |
| 129 | + (*grow.borrow_mut()) = __rhs; |
| 130 | + (*grow.borrow()).offset((2) as isize).write(3); |
| 131 | + (*grow.borrow()).offset((3) as isize).write(4); |
| 132 | + assert!((((((*grow.borrow()).offset((0) as isize).read()) == 1) as i32) != 0)); |
| 133 | + assert!((((((*grow.borrow()).offset((1) as isize).read()) == 2) as i32) != 0)); |
| 134 | + assert!((((((*grow.borrow()).offset((2) as isize).read()) == 3) as i32) != 0)); |
| 135 | + assert!((((((*grow.borrow()).offset((3) as isize).read()) == 4) as i32) != 0)); |
| 136 | + ({ (*(*pfree.borrow()))(((*grow.borrow()).clone() as Ptr<i32>).to_any()) }); |
| 137 | + let zeros: Value<Ptr<i32>> = Rc::new(RefCell::new( |
| 138 | + ({ (*(*pcalloc.borrow()))(4_usize, ::std::mem::size_of::<i32>()) }) |
| 139 | + .reinterpret_cast::<i32>(), |
| 140 | + )); |
| 141 | + let i: Value<i32> = Rc::new(RefCell::new(0)); |
| 142 | + 'loop_: while ((((*i.borrow()) < 4) as i32) != 0) { |
| 143 | + assert!( |
| 144 | + (((((*zeros.borrow()).offset((*i.borrow()) as isize).read()) == 0) as i32) != 0) |
| 145 | + ); |
| 146 | + (*i.borrow_mut()).postfix_inc(); |
| 147 | + } |
| 148 | + ({ (*(*pfree.borrow()))(((*zeros.borrow()).clone() as Ptr<i32>).to_any()) }); |
| 149 | + } |
| 150 | + return 0; |
| 151 | +} |
0 commit comments