|
| 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 append_to_reference_0(s: Ptr<Vec<i8>>) { |
| 10 | + { |
| 11 | + s.with_mut(|__v: &mut Vec<i8>| __v.pop()); |
| 12 | + s.with_mut(|__v: &mut Vec<i8>| { |
| 13 | + __v.resize( |
| 14 | + (*s.upgrade().deref()).len() + (1_usize) as usize, |
| 15 | + ('r' as i8), |
| 16 | + ) |
| 17 | + }); |
| 18 | + s.with_mut(|__v: &mut Vec<i8>| __v.push(0)); |
| 19 | + (*s.upgrade().deref()).clone() |
| 20 | + }; |
| 21 | +} |
| 22 | +pub fn main() { |
| 23 | + __cpp2rust_init_globals(); |
| 24 | + std::process::exit(main_0()); |
| 25 | +} |
| 26 | +fn main_0() -> i32 { |
| 27 | + let lengths: Value<Box<[usize]>> = Rc::new(RefCell::new(Box::new([ |
| 28 | + 0_usize, 1_usize, 2_usize, 3_usize, 7_usize, 8_usize, 15_usize, 16_usize, 31_usize, |
| 29 | + 64_usize, |
| 30 | + ]))); |
| 31 | + let counts: Value<Box<[usize]>> = Rc::new(RefCell::new(Box::new([ |
| 32 | + 0_usize, 1_usize, 2_usize, 3_usize, 8_usize, 33_usize, |
| 33 | + ]))); |
| 34 | + let characters: Value<Box<[i8]>> = Rc::new(RefCell::new(Box::new([ |
| 35 | + 0_i8, |
| 36 | + 1_i8, |
| 37 | + 2_i8, |
| 38 | + 7_i8, |
| 39 | + 9_i8, |
| 40 | + 10_i8, |
| 41 | + 13_i8, |
| 42 | + 31_i8, |
| 43 | + 32_i8, |
| 44 | + 42_i8, |
| 45 | + 65_i8, |
| 46 | + 90_i8, |
| 47 | + 97_i8, |
| 48 | + 100_i8, |
| 49 | + 127_i8, |
| 50 | + (-128_i32 as i8), |
| 51 | + (-127_i32 as i8), |
| 52 | + (-64_i32 as i8), |
| 53 | + (-2_i32 as i8), |
| 54 | + (-1_i32 as i8), |
| 55 | + ]))); |
| 56 | + let mut initial: [i8; 5] = [ |
| 57 | + ('a' as i8), |
| 58 | + 0_i8, |
| 59 | + ('b' as i8), |
| 60 | + (-128_i32 as i8), |
| 61 | + (-1_i32 as i8), |
| 62 | + ]; |
| 63 | + let mut cases: usize = 0_usize; |
| 64 | + 'loop_: for length in IterRange::new( |
| 65 | + (lengths.as_pointer() as Ptr<usize>), |
| 66 | + (lengths.as_pointer() as Ptr<usize>).offset((10_i64) as isize), |
| 67 | + ) { |
| 68 | + let mut length: usize = (length.read()); |
| 69 | + 'loop_: for count in IterRange::new( |
| 70 | + (counts.as_pointer() as Ptr<usize>), |
| 71 | + (counts.as_pointer() as Ptr<usize>).offset((6_i64) as isize), |
| 72 | + ) { |
| 73 | + let mut count: usize = (count.read()); |
| 74 | + 'loop_: for character in IterRange::new( |
| 75 | + (characters.as_pointer() as Ptr<i8>), |
| 76 | + (characters.as_pointer() as Ptr<i8>).offset((20_i64) as isize), |
| 77 | + ) { |
| 78 | + let character: Value<i8> = Rc::new(RefCell::new((character.read()))); |
| 79 | + let mut shrink: i32 = 0; |
| 80 | + 'loop_: while (shrink < 2) { |
| 81 | + let s: Value<Vec<i8>> = Rc::new(RefCell::new( |
| 82 | + vec![('x' as i8); (length) as usize] |
| 83 | + .iter() |
| 84 | + .cloned() |
| 85 | + .chain(std::iter::once(0)) |
| 86 | + .collect(), |
| 87 | + )); |
| 88 | + let mut i: usize = 0_usize; |
| 89 | + 'loop_: while (i < length) { |
| 90 | + let __rhs = initial[((i as u64) |
| 91 | + .wrapping_rem((::std::mem::size_of::<[i8; 5]>() as u64))) |
| 92 | + as usize]; |
| 93 | + (*s.borrow_mut())[i] = __rhs; |
| 94 | + i.prefix_inc(); |
| 95 | + } |
| 96 | + if (shrink != 0) { |
| 97 | + (*s.borrow_mut()).shrink_to_fit(); |
| 98 | + } |
| 99 | + { |
| 100 | + (*s.borrow_mut()).pop(); |
| 101 | + (*s.borrow_mut()).resize( |
| 102 | + (*s.borrow()).len() + (count) as usize, |
| 103 | + ({ (*character.borrow()) }), |
| 104 | + ); |
| 105 | + (*s.borrow_mut()).push(0); |
| 106 | + (*s.borrow()).clone() |
| 107 | + }; |
| 108 | + assert!(({ (((*s.borrow()).len() - 1) == (length).wrapping_add(count)) })); |
| 109 | + let mut data: Ptr<i8> = s.decay(); |
| 110 | + let mut i: usize = 0_usize; |
| 111 | + 'loop_: while (i < (length).wrapping_add(count)) { |
| 112 | + assert!( |
| 113 | + ({ |
| 114 | + ({ ((elem!(data, i).read()) as i32) } == { |
| 115 | + ((if (i < length) { |
| 116 | + initial[((i as u64).wrapping_rem( |
| 117 | + (::std::mem::size_of::<[i8; 5]>() as u64), |
| 118 | + )) as usize] |
| 119 | + } else { |
| 120 | + (*character.borrow()) |
| 121 | + }) as i32) |
| 122 | + }) |
| 123 | + }) |
| 124 | + ); |
| 125 | + i.prefix_inc(); |
| 126 | + } |
| 127 | + assert!(({ (((elem!(data, ((*s.borrow()).len() - 1)).read()) as i32) == 0) })); |
| 128 | + cases.prefix_inc(); |
| 129 | + shrink.prefix_inc(); |
| 130 | + } |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + let mut unboxed: Vec<i8> = { |
| 135 | + let mut __bytes = Ptr::<i8>::from_string_literal(b"a").to_c_bytes(); |
| 136 | + __bytes.push(0); |
| 137 | + __bytes |
| 138 | + }; |
| 139 | + { |
| 140 | + unboxed.pop(); |
| 141 | + unboxed.resize(unboxed.len() + (2_usize) as usize, ('b' as i8)); |
| 142 | + unboxed.push(0); |
| 143 | + unboxed.clone() |
| 144 | + }; |
| 145 | + assert!( |
| 146 | + Ptr::<i8>::from_string_literal(b"abb") |
| 147 | + .with_c_str(|__s| unboxed[..unboxed.len().saturating_sub(1)] == *__s) |
| 148 | + ); |
| 149 | + let indirect: Value<Vec<i8>> = Rc::new(RefCell::new({ |
| 150 | + let mut __bytes = Ptr::<i8>::from_string_literal(b"c").to_c_bytes(); |
| 151 | + __bytes.push(0); |
| 152 | + __bytes |
| 153 | + })); |
| 154 | + ({ append_to_reference_0(indirect.as_pointer()) }); |
| 155 | + assert!( |
| 156 | + ({ |
| 157 | + Ptr::<i8>::from_string_literal(b"cr").with_c_str(|__s| { |
| 158 | + (*indirect.borrow())[..(*indirect.borrow()).len().saturating_sub(1)] == *__s |
| 159 | + }) |
| 160 | + }) |
| 161 | + ); |
| 162 | + let mut pointer: Ptr<Vec<i8>> = (indirect.as_pointer()); |
| 163 | + { |
| 164 | + pointer.with_mut(|__v: &mut Vec<i8>| __v.pop()); |
| 165 | + pointer.with_mut(|__v: &mut Vec<i8>| { |
| 166 | + __v.resize( |
| 167 | + (*pointer.upgrade().deref()).len() + (0_usize) as usize, |
| 168 | + ('\0' as i8), |
| 169 | + ) |
| 170 | + }); |
| 171 | + pointer.with_mut(|__v: &mut Vec<i8>| __v.push(0)); |
| 172 | + (*pointer.upgrade().deref()).clone() |
| 173 | + }; |
| 174 | + assert!( |
| 175 | + ({ |
| 176 | + Ptr::<i8>::from_string_literal(b"cr").with_c_str(|__s| { |
| 177 | + (*indirect.borrow())[..(*indirect.borrow()).len().saturating_sub(1)] == *__s |
| 178 | + }) |
| 179 | + }) |
| 180 | + ); |
| 181 | + println!("checked {} appends", cases); |
| 182 | + return 0; |
| 183 | +} |
| 184 | +pub fn __cpp2rust_init_globals() {} |
0 commit comments