[ { "index": 0, "before": "int main() { /* screen ( integer) coordinate */ int iX,iY; const int iXmax = 800; const int iYmax = 800; /* world ( double) coordinate = parameter plane*/ double Cx,Cy; const double CxMin=-2.5; const double CxMax=1.5; const double CyMin=-2.0; const double CyMax=2.0; /* */ double PixelWidth=(CxMax-CxMin)/iXmax; double PixelHeight=(CyMax-CyMin)/iYmax; /* color component ( R or G or B) is coded from 0 to 255 */ /* it is 24 bit color RGB file */ const int MaxColorComponentValue=255; FILE * fp; char *filename=\"new1.ppm\"; char *comment=\"# \";/* comment should start with # */ static unsigned char color[3]; /* Z=Zx+Zy*i ; Z0 = 0 */ double Zx, Zy; double Zx2, Zy2; /* Zx2=Zx*Zx; Zy2=Zy*Zy */ /* */ int Iteration; const int IterationMax=200; /* bail-out value , radius of circle ; */ const double EscapeRadius=2; double ER2=EscapeRadius*EscapeRadius; /*create new file,give it a name and open it in binary mode */ fp= fopen(filename,\"wb\"); /* b - binary mode */ /*write ASCII header to the file*/ fprintf(fp,\"P6\\n %s\\n %d\\n %d\\n %d\\n\",comment,iXmax,iYmax,MaxColorComponentValue); /* compute and write image data bytes to the file*/ for(iY=0;iY i32 { unsafe { let mut iX: i32 = 0; let mut iY: i32 = 0; let iXmax: i32 = 800; let iYmax: i32 = 800; let mut Cx: f64 = 0.; let mut Cy: f64 = 0.; let CxMin: f64 = -2.5f64; let CxMax: f64 = 1.5f64; let CyMin: f64 = -2.0f64; let CyMax: f64 = 2.0f64; let mut PixelWidth: f64 = (CxMax - CxMin) / iXmax as f64; let mut PixelHeight: f64 = (CyMax - CyMin) / iYmax as f64; let MaxColorComponentValue: i32 = 255; let mut fp: *mut FILE = 0 as *mut FILE; let mut filename: *mut i8 = b\"new1.ppm\\0\" as *const u8 as *const i8 as *mut i8; let mut comment: *mut i8 = b\"# \\0\" as *const u8 as *const i8 as *mut i8; static mut color: [u8; 3] = [0; 3]; let mut Zx: f64 = 0.; let mut Zy: f64 = 0.; let mut Zx2: f64 = 0.; let mut Zy2: f64 = 0.; let mut Iteration: i32 = 0; let IterationMax: i32 = 200; let EscapeRadius: f64 = 2 as f64; let mut ER2: f64 = EscapeRadius * EscapeRadius; fp = fopen(filename, b\"wb\\0\" as *const u8 as *const i8); fprintf( fp, b\"P6\\n %s\\n %d\\n %d\\n %d\\n\\0\" as *const u8 as *const i8, comment, iXmax, iYmax, MaxColorComponentValue, ); iY = 0; while iY < iYmax { Cy = CyMin + iY as f64 * PixelHeight; if fabs(Cy) < PixelHeight / 2 as f64 { Cy = 0.0f64; } iX = 0; while iX < iXmax { Cx = CxMin + iX as f64 * PixelWidth; Zx = 0.0f64; Zy = 0.0f64; Zx2 = Zx * Zx; Zy2 = Zy * Zy; Iteration = 0; while Iteration < IterationMax && Zx2 + Zy2 < ER2 { Zy = 2 as f64 * Zx * Zy + Cy; Zx = Zx2 - Zy2 + Cx; Zx2 = Zx * Zx; Zy2 = Zy * Zy; Iteration += 1; Iteration; } if Iteration == IterationMax { color[0 as usize] = 0; color[1 as usize] = 0; color[2 as usize] = 0; } else { color[0 as usize] = 255; color[1 as usize] = 255; color[2 as usize] = 255; } fwrite(color.as_mut_ptr() as *const libc::c_void, 1, 3, fp); iX += 1; iX; } iY += 1; iY; } fclose(fp); return 0; } }" }, { "index": 1, "before": "void display(const char* txt1, const char* txt2) { const size_t len = strlen(txt1); assert(len == strlen(txt2)); int score = 0; for (size_t i = 0; i < len; i++) if (txt1[i] == txt2[i]) score++; (void)printf(\"%s, %s, (%u)\\n\", txt1, txt2, score); }", "after": "pub extern \"C\" fn display(mut txt1: *const i8, mut txt2: *const i8) { unsafe { let len: u64 = strlen(txt1); if len == strlen(txt2) { } else { __assert_fail( b\"len == strlen(txt2)\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 85, (*::core::mem::transmute::<&[u8; 41], &[i8; 41]>( b\"void display(const char *, const char *)\\0\", )) .as_ptr(), ); } 'c_2427: { if len == strlen(txt2) { } else { __assert_fail( b\"len == strlen(txt2)\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 85, (*::core::mem::transmute::<&[u8; 41], &[i8; 41]>( b\"void display(const char *, const char *)\\0\", )) .as_ptr(), ); } }; let mut score: i32 = 0; let mut i: u64 = 0; while i < len { if *txt1.offset(i as isize) as i32 == *txt2.offset(i as isize) as i32 { score += 1; score; } i = i.wrapping_add(1); i; } print!( \"{}, {}, ({})\\n\", build_str_from_raw_ptr(txt1 as *mut u8), build_str_from_raw_ptr(txt2 as *mut u8), score ); } }" }, { "index": 2, "before": "void best_shuffle(const char* txt, char* result) { const size_t len = strlen(txt); if (len == 0) return; #ifdef DEBUG // txt and result must have the same length assert(len == strlen(result)); #endif // how many of each character? size_t counts[UCHAR_MAX]; memset(counts, '\\0', UCHAR_MAX * sizeof(int)); size_t fmax = 0; for (size_t i = 0; i < len; i++) { counts[(unsigned char)txt[i]]++; const size_t fnew = counts[(unsigned char)txt[i]]; if (fmax < fnew) fmax = fnew; } assert(fmax > 0 && fmax <= len); // all character positions, grouped by character size_t *ndx1 = malloc(len * sizeof(size_t)); if (ndx1 == NULL) exit(EXIT_FAILURE); for (size_t ch = 0, i = 0; ch < UCHAR_MAX; ch++) if (counts[ch]) for (size_t j = 0; j < len; j++) if (ch == (unsigned char)txt[j]) { ndx1[i] = j; i++; } // regroup them for cycles size_t *ndx2 = malloc(len * sizeof(size_t)); if (ndx2 == NULL) exit(EXIT_FAILURE); for (size_t i = 0, n = 0, m = 0; i < len; i++) { ndx2[i] = ndx1[n]; n += fmax; if (n >= len) { m++; n = m; } } // how long can our cyclic groups be? const size_t grp = 1 + (len - 1) / fmax; assert(grp > 0 && grp <= len); // how many of them are full length? const size_t lng = 1 + (len - 1) % fmax; assert(lng > 0 && lng <= len); // rotate each group for (size_t i = 0, j = 0; i < fmax; i++) { const size_t first = ndx2[j]; const size_t glen = grp - (i < lng ? 0 : 1); for (size_t k = 1; k < glen; k++) ndx1[j + k - 1] = ndx2[j + k]; ndx1[j + glen - 1] = first; j += glen; } // result is original permuted according to our cyclic groups result[len] = '\\0'; for (size_t i = 0; i < len; i++) result[ndx2[i]] = txt[ndx1[i]]; free(ndx1); free(ndx2); }", "after": "pub extern \"C\" fn best_shuffle(mut txt: *const i8, mut result: *mut i8) { unsafe { let len: u64 = strlen(txt); if len == 0 { return; } if len == strlen(result) { } else { __assert_fail( b\"len == strlen(result)\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 16, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"void best_shuffle(const char *, char *)\\0\", )) .as_ptr(), ); } 'c_2313: { if len == strlen(result) { } else { __assert_fail( b\"len == strlen(result)\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 16, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"void best_shuffle(const char *, char *)\\0\", )) .as_ptr(), ); } }; let mut counts: [u64; 255] = [0; 255]; memset( counts.as_mut_ptr() as *mut libc::c_void, '\\0' as i32, ((127 * 2 + 1i32) as u64).wrapping_mul(::core::mem::size_of::() as u64), ); let mut fmax: u64 = 0; let mut i: u64 = 0; while i < len { counts[*txt.offset(i as isize) as u8 as usize] = (counts[*txt.offset(i as isize) as u8 as usize]).wrapping_add(1); counts[*txt.offset(i as isize) as u8 as usize]; let fnew: u64 = counts[*txt.offset(i as isize) as u8 as usize]; if fmax < fnew { fmax = fnew; } i = i.wrapping_add(1); i; } if fmax > 0 && fmax <= len { } else { __assert_fail( b\"fmax > 0 && fmax <= len\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 29, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"void best_shuffle(const char *, char *)\\0\", )) .as_ptr(), ); } 'c_2197: { if fmax > 0 && fmax <= len { } else { __assert_fail( b\"fmax > 0 && fmax <= len\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 29, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"void best_shuffle(const char *, char *)\\0\", )) .as_ptr(), ); } }; let mut ndx1: *mut u64 = malloc(len.wrapping_mul(::core::mem::size_of::() as u64)) as *mut u64; if ndx1.is_null() { exit(1); } let mut ch: u64 = 0; let mut i_0: u64 = 0; while ch < (127 * 2 + 1i32) as u64 { if counts[ch as usize] != 0 { let mut j: u64 = 0; while j < len { if ch == *txt.offset(j as isize) as u64 { *ndx1.offset(i_0 as isize) = j; i_0 = i_0.wrapping_add(1); i_0; } j = j.wrapping_add(1); j; } } ch = ch.wrapping_add(1); ch; } let mut ndx2: *mut u64 = malloc(len.wrapping_mul(::core::mem::size_of::() as u64)) as *mut u64; if ndx2.is_null() { exit(1); } let mut i_1: u64 = 0; let mut n: u64 = 0; let mut m: u64 = 0; while i_1 < len { *ndx2.offset(i_1 as isize) = *ndx1.offset(n as isize); n = (n).wrapping_add(fmax) as u64; if n >= len { m = m.wrapping_add(1); m; n = m; } i_1 = i_1.wrapping_add(1); i_1; } let grp: u64 = 1u64.wrapping_add(len.wrapping_sub(1).wrapping_div(fmax)); if grp > 0 && grp <= len { } else { __assert_fail( b\"grp > 0 && grp <= len\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 58, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"void best_shuffle(const char *, char *)\\0\", )) .as_ptr(), ); } 'c_2002: { if grp > 0 && grp <= len { } else { __assert_fail( b\"grp > 0 && grp <= len\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 58, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"void best_shuffle(const char *, char *)\\0\", )) .as_ptr(), ); } }; let lng: u64 = 1u64.wrapping_add(len.wrapping_sub(1).wrapping_rem(fmax)); if lng > 0 && lng <= len { } else { __assert_fail( b\"lng > 0 && lng <= len\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 62, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"void best_shuffle(const char *, char *)\\0\", )) .as_ptr(), ); } 'c_1947: { if lng > 0 && lng <= len { } else { __assert_fail( b\"lng > 0 && lng <= len\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 62, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"void best_shuffle(const char *, char *)\\0\", )) .as_ptr(), ); } }; let mut i_2: u64 = 0; let mut j_0: u64 = 0; while i_2 < fmax { let first: u64 = *ndx2.offset(j_0 as isize); let glen: u64 = grp.wrapping_sub((if i_2 < lng { 0 } else { 1 }) as u64); let mut k: u64 = 1; while k < glen { *ndx1.offset(j_0.wrapping_add(k).wrapping_sub(1) as isize) = *ndx2.offset(j_0.wrapping_add(k) as isize); k = k.wrapping_add(1); k; } *ndx1.offset(j_0.wrapping_add(glen).wrapping_sub(1) as isize) = first; j_0 = (j_0).wrapping_add(glen) as u64; i_2 = i_2.wrapping_add(1); i_2; } *result.offset(len as isize) = '\\0' as i8; let mut i_3: u64 = 0; while i_3 < len { *result.offset(*ndx2.offset(i_3 as isize) as isize) = *txt.offset(*ndx1.offset(i_3 as isize) as isize); i_3 = i_3.wrapping_add(1); i_3; } free(ndx1 as *mut libc::c_void); free(ndx2 as *mut libc::c_void); } }" }, { "index": 3, "before": "int main() { const char* data[] = {\"abracadabra\", \"seesaw\", \"elk\", \"grrrrrr\", \"up\", \"a\", \"aabbbbaa\", \"\", \"xxxxx\"}; const size_t data_len = sizeof(data) / sizeof(data[0]); for (size_t i = 0; i < data_len; i++) { const size_t shuf_len = strlen(data[i]) + 1; char shuf[shuf_len]; #ifdef DEBUG memset(shuf, 0xFF, sizeof shuf); shuf[shuf_len - 1] = '\\0'; #endif best_shuffle(data[i], shuf); display(data[i], shuf); } return EXIT_SUCCESS; }", "after": "fn main() -> i32 { let mut data: [*const i8; 9] = [ b\"abracadabra\\0\" as *const u8 as *const i8, b\"seesaw\\0\" as *const u8 as *const i8, b\"elk\\0\" as *const u8 as *const i8, b\"grrrrrr\\0\" as *const u8 as *const i8, b\"up\\0\" as *const u8 as *const i8, b\"a\\0\" as *const u8 as *const i8, b\"aabbbbaa\\0\" as *const u8 as *const i8, b\"\\0\" as *const u8 as *const i8, b\"xxxxx\\0\" as *const u8 as *const i8, ]; let data_len: u64 = (::core::mem::size_of::<[*const i8; 9]>() as u64) .wrapping_div(::core::mem::size_of::<*const i8>() as u64); let mut i: u64 = 0; unsafe { while i < data_len { let shuf_len: u64 = (strlen(data[i as usize])).wrapping_add(1); let vla = shuf_len as usize; let mut shuf: Vec = ::std::vec::from_elem(0, vla); memset( shuf.as_mut_ptr() as *mut libc::c_void, 0xff, (vla * ::core::mem::size_of::()) as u64, ); *shuf.as_mut_ptr().offset(shuf_len.wrapping_sub(1) as isize) = '\\0' as i8; best_shuffle(data[i as usize], shuf.as_mut_ptr()); display(data[i as usize], shuf.as_mut_ptr()); i = i.wrapping_add(1); i; } } return 0; }" }, { "index": 4, "before": "void mat_del(mat x) { free(x[0]); free(x); }", "after": "pub extern \"C\" fn mat_del(mut x: mat) { unsafe { free(*x.offset(0 as isize) as *mut libc::c_void); free(x as *mut libc::c_void); } }" }, { "index": 5, "before": "void mat_LU(mat A, mat L, mat U, mat P, _dim) { \t_zero(L); _zero(U); \t_pivot(A, P); \tmat Aprime = _mul(P, A); \tfor_i { L[i][i] = 1; }", "after": "pub extern \"C\" fn mat_LU(mut A: mat, mut L: mat, mut U: mat, mut P: mat, mut n: i32) { mat_zero(L, n); mat_zero(U, n); mat_pivot(A, P, n); let mut Aprime: mat = mat_mul(P, A, n); let mut i: i32 = 0; unsafe { while i < n { *(*L.offset(i as isize)).offset(i as isize) = 1 as f64; i += 1; i; } } let mut i_0: i32 = 0; unsafe { while i_0 < n { let mut j: i32 = 0; while j < n { let mut s: f64 = 0.; if j <= i_0 { s = 0 as f64; let mut k: i32 = 0; while k < j { s += *(*L.offset(j as isize)).offset(k as isize) * *(*U.offset(k as isize)).offset(i_0 as isize); k += 1; k; } *(*U.offset(j as isize)).offset(i_0 as isize) = *(*Aprime.offset(j as isize)).offset(i_0 as isize) - s; } if j >= i_0 { s = 0 as f64; let mut k_0: i32 = 0; while k_0 < i_0 { s += *(*L.offset(j as isize)).offset(k_0 as isize) * *(*U.offset(k_0 as isize)).offset(i_0 as isize); k_0 += 1; k_0; } *(*L.offset(j as isize)).offset(i_0 as isize) = (*(*Aprime.offset(j as isize)).offset(i_0 as isize) - s) / *(*U.offset(i_0 as isize)).offset(i_0 as isize); } j += 1; j; } i_0 += 1; i_0; } } mat_del(Aprime); }" }, { "index": 6, "before": "int main() { \tint n = 3; \tmat A, L, P, U; \t_new(L); _new(P); _new(U); \tA = _copy(A3); \t_LU(A, L, U, P); \t_show(A); _show(L); _show(U); _show(P); \t_del(A); _del(L); _del(U); _del(P); \tprintf(\"\\n\"); \tn = 4; \t_new(L); _new(P); _new(U); \tA = _copy(A4); \t_LU(A, L, U, P); \t_show(A); _show(L); _show(U); _show(P); \t_del(A); _del(L); _del(U); _del(P); \treturn 0; }", "after": "fn main() -> i32 { let mut n: i32 = 3; let mut A: mat = 0 as *mut *mut f64; let mut L: mat = 0 as *mut *mut f64; let mut P: mat = 0 as *mut *mut f64; let mut U: mat = 0 as *mut *mut f64; L = mat_new(n); P = mat_new(n); U = mat_new(n); unsafe { A = mat_copy(A3.as_mut_ptr() as *mut libc::c_void, n); } mat_LU(A, L, U, P, n); print!(\"A =\"); mat_show(A, 0 as *mut i8, n); print!(\"L =\"); mat_show(L, 0 as *mut i8, n); print!(\"U =\"); mat_show(U, 0 as *mut i8, n); print!(\"P =\"); mat_show(P, 0 as *mut i8, n); mat_del(A); mat_del(L); mat_del(U); mat_del(P); print!(\"\\n\"); n = 4; L = mat_new(n); P = mat_new(n); U = mat_new(n); unsafe { A = mat_copy(A4.as_mut_ptr() as *mut libc::c_void, n); } mat_LU(A, L, U, P, n); print!(\"A =\"); mat_show(A, 0 as *mut i8, n); print!(\"L =\"); mat_show(L, 0 as *mut i8, n); print!(\"U =\"); mat_show(U, 0 as *mut i8, n); print!(\"P =\"); mat_show(P, 0 as *mut i8, n); mat_del(A); mat_del(L); mat_del(U); mat_del(P); return 0; }" }, { "index": 7, "before": "mat mat_mul(mat a, mat b, _dim) { \tmat c = _new(c); \tfor_ijk c[i][j] += a[i][k] * b[k][j]; \treturn c; }", "after": "pub extern \"C\" fn mat_mul(mut a: mat, mut b: mat, mut n: i32) -> mat { let mut c: mat = 0 as *mut *mut f64; c = mat_new(n); c = c; let mut i: i32 = 0; unsafe { while i < n { let mut j: i32 = 0; while j < n { let mut k: i32 = 0; while k < n { *(*c.offset(i as isize)).offset(j as isize) += *(*a.offset(i as isize)) .offset(k as isize) * *(*b.offset(k as isize)).offset(j as isize); k += 1; k; } j += 1; j; } i += 1; i; } } return c; }" }, { "index": 8, "before": "void mat_zero(mat x, int n) { for_ij x[i][j] = 0; }", "after": "pub extern \"C\" fn mat_zero(mut x: mat, mut n: i32) { let mut i: i32 = 0; unsafe { while i < n { let mut j: i32 = 0; while j < n { *(*x.offset(i as isize)).offset(j as isize) = 0 as f64; j += 1; j; } i += 1; i; } } }" }, { "index": 9, "before": "void mat_show(mat x, char *fmt, _dim) { \tif (!fmt) fmt = \"%8.4g\"; \tfor_i { \t\tprintf(i ? \" \" : \" [ \"); \t\tfor_j { \t\t\tprintf(fmt, x[i][j]); \t\t\tprintf(j < n - 1 ? \" \" : i == n - 1 ? \" ]\\n\" : \"\\n\"); \t\t} \t} }", "after": "pub extern \"C\" fn mat_show(mut x: mat, mut fmt: *mut i8, mut n: i32) { unsafe { if fmt.is_null() { fmt = b\"%8.4g\\0\" as *const u8 as *const i8 as *mut i8; } let mut i: i32 = 0; while i < n { if i != 0 { print!(\" \") } else { print!(\" [ \") }; let mut j: i32 = 0; while j < n { printf(fmt, *(*x.offset(i as isize)).offset(j as isize)); if j < n - 1 { print!(\" \") } else { if i == n - 1 { print!(\" ]\\n\") } else { print!(\"\\n\") } }; j += 1; j; } i += 1; i; } } }" }, { "index": 10, "before": "mat mat_new(_dim) { \tmat x = malloc(sizeof(double*) * n); \tx[0] = malloc(sizeof(double) * n * n); \tfor_i x[i] = x[0] + n * i; \t_zero(x); \treturn x; }", "after": "pub extern \"C\" fn mat_new(mut n: i32) -> mat { unsafe { let mut x: mat = malloc((::core::mem::size_of::<*mut f64>() as u64).wrapping_mul(n as u64)) as mat; let ref mut fresh0 = *x.offset(0 as isize); *fresh0 = malloc( (::core::mem::size_of::() as u64) .wrapping_mul(n as u64) .wrapping_mul(n as u64), ) as *mut f64; let mut i: i32 = 0; while i < n { let ref mut fresh1 = *x.offset(i as isize); *fresh1 = (*x.offset(0 as isize)).offset((n * i) as isize); i += 1; i; } mat_zero(x, n); return x; } }" }, { "index": 11, "before": "void mat_pivot(mat a, mat p, _dim) { \tfor_ij { p[i][j] = (i == j); }", "after": "pub extern \"C\" fn mat_pivot(mut a: mat, mut p: mat, mut n: i32) { let mut i: i32 = 0; unsafe { while i < n { let mut j: i32 = 0; while j < n { *(*p.offset(i as isize)).offset(j as isize) = (i == j) as i32 as f64; j += 1; j; } i += 1; i; } } let mut i_0: i32 = 0; unsafe { while i_0 < n { let mut max_j: i32 = i_0; let mut j_0: i32 = i_0; while j_0 < n { if fabs(*(*a.offset(j_0 as isize)).offset(i_0 as isize)) > fabs(*(*a.offset(max_j as isize)).offset(i_0 as isize)) { max_j = j_0; } j_0 += 1; j_0; } if max_j != i_0 { let mut k: i32 = 0; while k < n { let mut tmp: f64 = *(*p.offset(i_0 as isize)).offset(k as isize); *(*p.offset(i_0 as isize)).offset(k as isize) = *(*p.offset(max_j as isize)).offset(k as isize); *(*p.offset(max_j as isize)).offset(k as isize) = tmp; k += 1; k; } } i_0 += 1; i_0; } } }" }, { "index": 12, "before": "mat mat_copy(void *s, _dim) { \tmat x = mat_new(n); \tfor_ij x[i][j] = ((double (*)[n])s)[i][j]; \treturn x; }", "after": "pub extern \"C\" fn mat_copy(mut s: *mut libc::c_void, mut n: i32) -> mat { unsafe { let mut x: mat = mat_new(n); let mut i: i32 = 0; while i < n { let mut j: i32 = 0; while j < n { let vla = n as usize; *(*x.offset(i as isize)).offset(j as isize) = *(s as *mut f64) .offset(i as isize * vla as isize) .offset(j as isize); j += 1; j; } i += 1; i; } return x; } }" }, { "index": 13, "before": "int main(void) { \tint x[] = {123, 12345, 1234567, 987654321, 10001, -10001, \t\t-123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0, \t\t1234567890}; \tint i; \tchar *m; \tfor (i = 0; i < sizeof(x)/sizeof(x[0]); i++) { \t\tif (!(m = mid3(x[i]))) \t\t\tm = \"error\"; \t\tprintf(\"%d: %s\\n\", x[i], m); \t} \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut x: [i32; 18] = [ 123, 12345, 1234567, 987654321, 10001, -10001, -123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0, 1234567890, ]; let mut i: i32 = 0; let mut m: *mut i8 = 0 as *mut i8; i = 0; while (i as u64) < (::core::mem::size_of::<[i32; 18]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) { m = mid3(x[i as usize]); if m.is_null() { m = b\"error\\0\" as *const u8 as *const i8 as *mut i8; } print!( \"{}: {}\\n\", x[i as usize], build_str_from_raw_ptr(m as *mut u8) ); i += 1; i; } return 0; } }" }, { "index": 14, "before": "int main() { int curr[5][5]; int max_claim[5][5]; int avl[5]; int alloc[5] = {0, 0, 0, 0, 0}; int max_res[5]; int running[5]; int i, j, exec, r, p; int count = 0; bool safe = false; printf(\"\\nEnter the number of resources: \"); scanf(\"%d\", &r); printf(\"\\nEnter the number of processes: \"); scanf(\"%d\", &p); for (i = 0; i < p; i++) { running[i] = 1; count++; } printf(\"\\nEnter Claim Vector: \"); for (i = 0; i < r; i++) scanf(\"%d\", &max_res[i]); printf(\"\\nEnter Allocated Resource Table: \"); for (i = 0; i < p; i++) { for (j = 0; j < r; j++) scanf(\"%d\", &curr[i][j]); } printf(\"\\nEnter Maximum Claim table: \"); for (i = 0; i < p; i++) { for (j = 0; j < r; j++) scanf(\"%d\", &max_claim[i][j]); } printf(\"\\nThe Claim Vector is: \"); for (i = 0; i < r; i++) printf(\"%d \", max_res[i]); printf(\"\\nThe Allocated Resource Table:\\n\"); for (i = 0; i < p; i++) { for (j = 0; j < r; j++) printf(\"\\t%d\", curr[i][j]); printf(\"\\n\"); } printf(\"\\nThe Maximum Claim Table:\\n\"); for (i = 0; i < p; i++) { for (j = 0; j < r; j++) printf(\"\\t%d\", max_claim[i][j]); printf(\"\\n\"); } for (i = 0; i < p; i++) for (j = 0; j < r; j++) alloc[j] += curr[i][j]; printf(\"\\nAllocated resources: \"); for (i = 0; i < r; i++) printf(\"%d \", alloc[i]); for (i = 0; i < r; i++) avl[i] = max_res[i] - alloc[i]; printf(\"\\nAvailable resources: \"); for (i = 0; i < r; i++) printf(\"%d \", avl[i]); printf(\"\\n\"); while (count != 0) { safe = false; for (i = 0; i < p; i++) { if (running[i]) { exec = 1; for (j = 0; j < r; j++) { if (max_claim[i][j] - curr[i][j] > avl[j]) { exec = 0; break; } } if (exec) { printf(\"\\nProcess%d is executing.\\n\", i + 1); running[i] = 0; count--; safe = true; for (j = 0; j < r; j++) avl[j] += curr[i][j]; break; } } } if (!safe) { printf(\"\\nThe processes are in unsafe state.\"); break; } if (safe) printf(\"\\nThe process is in safe state.\"); printf(\"\\nAvailable vector: \"); for (i = 0; i < r; i++) printf(\"%d \", avl[i]); } return 0; }", "after": "fn main() -> i32 { let mut curr: [[i32; 5]; 5] = [[0; 5]; 5]; let mut max_claim: [[i32; 5]; 5] = [[0; 5]; 5]; let mut avl: [i32; 5] = [0; 5]; let mut alloc: [i32; 5] = [0; 5]; let mut max_res: [i32; 5] = [0; 5]; let mut running: [i32; 5] = [0; 5]; let mut i: i32 = 0; let mut j: i32 = 0; let mut exec: i32 = 0; let mut r: i32 = 0; let mut p: i32 = 0; let mut count: i32 = 0; let mut safe: bool = 0 != 0; print!(\"\\nEnter the number of resources: \"); unsafe { scanf(b\"%d\\0\" as *const u8 as *const i8, &mut r as *mut i32); } print!(\"\\nEnter the number of processes: \"); unsafe { scanf(b\"%d\\0\" as *const u8 as *const i8, &mut p as *mut i32); } i = 0; while i < p { running[i as usize] = 1; count += 1; count; i += 1; i; } print!(\"\\nEnter Claim Vector: \"); i = 0; unsafe { while i < r { scanf( b\"%d\\0\" as *const u8 as *const i8, &mut *max_res.as_mut_ptr().offset(i as isize) as *mut i32, ); i += 1; i; } } print!(\"\\nEnter Allocated Resource Table: \"); i = 0; unsafe { while i < p { j = 0; while j < r { scanf( b\"%d\\0\" as *const u8 as *const i8, &mut *(*curr.as_mut_ptr().offset(i as isize)) .as_mut_ptr() .offset(j as isize) as *mut i32, ); j += 1; j; } i += 1; i; } } print!(\"\\nEnter Maximum Claim table: \"); i = 0; unsafe { while i < p { j = 0; while j < r { scanf( b\"%d\\0\" as *const u8 as *const i8, &mut *(*max_claim.as_mut_ptr().offset(i as isize)) .as_mut_ptr() .offset(j as isize) as *mut i32, ); j += 1; j; } i += 1; i; } } print!(\"\\nThe Claim Vector is: \"); i = 0; while i < r { print!(\"{} \", max_res[i as usize]); i += 1; i; } print!(\"\\nThe Allocated Resource Table:\\n\"); i = 0; while i < p { j = 0; while j < r { print!(\"\t{}\", curr[i as usize][j as usize]); j += 1; j; } print!(\"\\n\"); i += 1; i; } print!(\"\\nThe Maximum Claim Table:\\n\"); i = 0; while i < p { j = 0; while j < r { print!(\"\t{}\", max_claim[i as usize][j as usize]); j += 1; j; } print!(\"\\n\"); i += 1; i; } i = 0; while i < p { j = 0; while j < r { alloc[j as usize] += curr[i as usize][j as usize]; j += 1; j; } i += 1; i; } print!(\"\\nAllocated resources: \"); i = 0; while i < r { print!(\"{} \", alloc[i as usize]); i += 1; i; } i = 0; while i < r { avl[i as usize] = max_res[i as usize] - alloc[i as usize]; i += 1; i; } print!(\"\\nAvailable resources: \"); i = 0; while i < r { print!(\"{} \", avl[i as usize]); i += 1; i; } print!(\"\\n\"); while count != 0 { safe = 0 != 0; i = 0; while i < p { if running[i as usize] != 0 { exec = 1; j = 0; while j < r { if max_claim[i as usize][j as usize] - curr[i as usize][j as usize] > avl[j as usize] { exec = 0; break; } else { j += 1; j; } } if exec != 0 { print!(\"\\nProcess{} is executing.\\n\", i + 1); running[i as usize] = 0; count -= 1; count; safe = 1 != 0; j = 0; while j < r { avl[j as usize] += curr[i as usize][j as usize]; j += 1; j; } break; } } i += 1; i; } if !safe { print!(\"\\nThe processes are in unsafe state.\"); break; } else { if safe { print!(\"\\nThe process is in safe state.\"); } print!(\"\\nAvailable vector: \"); i = 0; while i < r { print!(\"{} \", avl[i as usize]); i += 1; i; } } } return 0; }" }, { "index": 15, "before": "int main(int argc, char **argv) { \tpowerset(argv + 1, argc - 1, 0); \treturn 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { powerset(argv.offset(1 as isize), argc - 1, 0 as *mut node); return 0; } }" }, { "index": 16, "before": "void powerset(char **v, int n, struct node *up) { \tstruct node me; \tif (!n) { \t\tputchar('['); \t\twhile (up) { \t\t\tprintf(\" %s\", up->s); \t\t\tup = up->prev; \t\t} \t\tputs(\" ]\"); \t} else { \t\tme.s = *v; \t\tme.prev = up; \t\tpowerset(v + 1, n - 1, up); \t\tpowerset(v + 1, n - 1, &me); \t} }", "after": "pub extern \"C\" fn powerset(mut v: *mut *mut i8, mut n: i32, mut up: *mut node) { unsafe { let mut me: node = node { s: 0 as *mut i8, prev: 0 as *mut node, }; if n == 0 { print!(\"{}\", '[' as i32); while !up.is_null() { print!(\" {}\", build_str_from_raw_ptr((*up).s as *mut u8)); up = (*up).prev; } puts(b\" ]\\0\" as *const u8 as *const i8); } else { me.s = *v; me.prev = up; powerset(v.offset(1 as isize), n - 1, up); powerset(v.offset(1 as isize), n - 1, &mut me); }; } }" }, { "index": 17, "before": "void aliquotClassifier(unsigned long long n){ \tunsigned long long arr[16]; \tint i,j; \tarr[0] = n; \tfor(i=1;i<16;i++){ \t\tarr[i] = bruteForceProperDivisorSum(arr[i-1]); \t\tif(arr[i]==0||arr[i]==n||(arr[i]==arr[i-1] && arr[i]!=n)){ \t\t\tprintSeries(arr,i+1,(arr[i]==0)?\"Terminating\":(arr[i]==n && i==1)?\"Perfect\":(arr[i]==n && i==2)?\"Amicable\":(arr[i]==arr[i-1] && arr[i]!=n)?\"Aspiring\":\"Sociable\"); \t\t\treturn; \t\t} \t\tfor(j=1;j\",argV[0]); \telse{ \t\tif(strchr(argV[1],'.')!=NULL) \t\t\tprocessFile(argV[1]); \t\telse \t\t\taliquotClassifier(strtoull(argV[1],(char**)NULL,10)); \t} \treturn 0; }", "after": "fn main(mut argC: i32, mut argV: *mut *mut i8) -> i32 { unsafe { if argC != 2 { print!( \"Usage : {} \", build_str_from_raw_ptr(*argV.offset(0 as isize) as *mut u8) ); } else if !(strchr(*argV.offset(1 as isize), '.' as i32)).is_null() { processFile(*argV.offset(1 as isize)); } else { aliquotClassifier(strtoull( *argV.offset(1 as isize), 0 as *mut libc::c_void as *mut *mut i8, 10, )); } return 0; } }" }, { "index": 19, "before": "void processFile(char* fileName){ \tFILE* fp = fopen(fileName,\"r\"); \tchar str[21]; \twhile(fgets(str,21,fp)!=NULL) \t\taliquotClassifier(strtoull(str,(char**)NULL,10)); \tfclose(fp); }", "after": "pub extern \"C\" fn processFile(mut fileName: *mut i8) { unsafe { let mut fp: *mut FILE = fopen(fileName, b\"r\\0\" as *const u8 as *const i8); let mut str: [i8; 21] = [0; 21]; while !(fgets(str.as_mut_ptr(), 21, fp)).is_null() { aliquotClassifier(strtoull( str.as_mut_ptr(), 0 as *mut libc::c_void as *mut *mut i8, 10, )); } fclose(fp); } }" }, { "index": 20, "before": "unsigned long long bruteForceProperDivisorSum(unsigned long long n){ \tunsigned long long i,sum = 0; \tfor(i=1;i<(n+1)/2;i++) \t\tif(n%i==0 && n!=i) \t\t\tsum += i; \treturn sum; }", "after": "pub extern \"C\" fn bruteForceProperDivisorSum(mut n: u64) -> u64 { let mut i: u64 = 0; let mut sum: u64 = 0; i = 1; while i < n.wrapping_add(1).wrapping_div(2) { if n.wrapping_rem(i) == 0 && n != i { sum = sum.wrapping_add(i); } i = i.wrapping_add(1); i; } return sum; }" }, { "index": 21, "before": "void printSeries(unsigned long long* arr,int size,char* type){ \tint i; \tprintf(\"\\nInteger : %llu, Type : %s, Series : \",arr[0],type); \tfor(i=0;i= 0; i++); \treturn i; }", "after": "pub extern \"C\" fn rand_idx(mut p: *mut f64, mut n: i32) -> i32 { unsafe { let mut s: f64 = rand() as f64 / (2147483647 as f64 + 1.0f64); let mut i: i32 = 0; i = 0; while i < n - 1 && { s -= *p.offset(i as isize); s >= 0 as f64 } { i += 1; i; } return i; } }" }, { "index": 23, "before": "int main() { \tint user_action, my_action; \tint user_rec[] = {0, 0, 0}; \tconst char *names[] = { \"Rock\", \"Paper\", \"Scissors\" }; \tchar str[2]; \tconst char *winner[] = { \"We tied.\", \"Meself winned.\", \"You win.\" }; \tdouble p[LEN] = { 1./3, 1./3, 1./3 }; \twhile (1) { \t\tmy_action = rand_idx(p,LEN); \t\tprintf(\"\\nYour choice [1-3]:\\n\" \t\t\t\" 1. Rock\\n 2. Paper\\n 3. Scissors\\n> \"); \t\t/* scanf is a terrible way to do input. should use stty and keystrokes */ \t\tif (!scanf(\"%d\", &user_action)) { \t\t\tscanf(\"%1s\", str); \t\t\tif (*str == 'q') { \t\t\t\tprintf(\"Your choices [rock : %d , paper : %d , scissors %d] \",user_rec[0],user_rec[1], user_rec[2]); \t\t\t\treturn 0; \t\t\t} \t\t\tcontinue; \t\t} \t\tuser_action --; \t\tif (user_action > 2 || user_action < 0) { \t\t\tprintf(\"invalid choice; again\\n\"); \t\t\tcontinue; \t\t} \t\tprintf(\"You chose %s; I chose %s. %s\\n\", \t\t\tnames[user_action], names[my_action], \t\t\twinner[(my_action - user_action + 3) % 3]); \t\tuser_rec[user_action]++; \t} }", "after": "fn main() -> i32 { let mut user_action: i32 = 0; let mut my_action: i32 = 0; let mut user_rec: [i32; 3] = [0; 3]; let mut names: [*const i8; 3] = [ b\"Rock\\0\" as *const u8 as *const i8, b\"Paper\\0\" as *const u8 as *const i8, b\"Scissors\\0\" as *const u8 as *const i8, ]; let mut str: [i8; 2] = [0; 2]; let mut winner: [*const i8; 3] = [ b\"We tied.\\0\" as *const u8 as *const i8, b\"Meself winned.\\0\" as *const u8 as *const i8, b\"You win.\\0\" as *const u8 as *const i8, ]; let mut p: [f64; 3] = [1.0f64 / 3 as f64, 1.0f64 / 3 as f64, 1.0f64 / 3 as f64]; unsafe { loop { my_action = rand_idx(p.as_mut_ptr(), 3); print!(\"\\nYour choice [1-3]:\\n 1. Rock\\n 2. Paper\\n 3. Scissors\\n> \"); if scanf( b\"%d\\0\" as *const u8 as *const i8, &mut user_action as *mut i32, ) == 0 { scanf(b\"%1s\\0\" as *const u8 as *const i8, str.as_mut_ptr()); if *str.as_mut_ptr() as i32 == 'q' as i32 { print!( \"Your choices [rock : {} , paper : {} , scissors {}] \", user_rec[0 as usize], user_rec[1 as usize], user_rec[2 as usize] ); return 0; } } else { user_action -= 1; user_action; if user_action > 2 || user_action < 0 { print!(\"invalid choice; again\\n\"); } else { print!( \"You chose {}; I chose {}. {}\\n\", build_str_from_raw_ptr(names[user_action as usize] as *mut u8), build_str_from_raw_ptr(names[my_action as usize] as *mut u8), build_str_from_raw_ptr( winner[((my_action - user_action + 3i32) % 3i32) as usize] as *mut u8 ) ); user_rec[user_action as usize] += 1; user_rec[user_action as usize]; } } } } }" }, { "index": 24, "before": "int mul_inv(int a, int b) { \tint b0 = b, t, q; \tint x0 = 0, x1 = 1; \tif (b == 1) return 1; \twhile (a > 1) { \t\tq = a / b; \t\tt = b, b = a % b, a = t; \t\tt = x0, x0 = x1 - q * x0, x1 = t; \t} \tif (x1 < 0) x1 += b0; \treturn x1; }", "after": "pub extern \"C\" fn mul_inv(mut a: i32, mut b: i32) -> i32 { let mut b0: i32 = b; let mut t: i32 = 0; let mut q: i32 = 0; let mut x0: i32 = 0; let mut x1: i32 = 1; if b == 1 { return 1; } while a > 1 { q = a / b; t = b; b = a % b; a = t; t = x0; x0 = x1 - q * x0; x1 = t; } if x1 < 0 { x1 += b0; } return x1; }" }, { "index": 25, "before": "int main(void) { \tprintf(\"%d\\n\", mul_inv(42, 2017)); \treturn 0; }", "after": "fn main() -> i32 { print!(\"{}\\n\", mul_inv(42, 2017)); return 0; }" }, { "index": 26, "before": "int main() { \tsize_t len; \tchar src[] = \"Hello\"; \tchar dst1[80], dst2[80]; \tchar *dst3, *ref; \t/* \t * Option 1. Use strcpy() from . \t * \t * DANGER! strcpy() can overflow the destination buffer. \t * strcpy() is only safe if the source string is shorter than \t * the destination buffer. We know that \"Hello\" (6 characters \t * with the final '\\0') easily fits in dst1 (80 characters). \t */ \tstrcpy(dst1, src); \t/* \t * Option 2. Use strlen() and memcpy() from , to copy \t * strlen(src) + 1 bytes including the final '\\0'. \t */ \tlen = strlen(src); \tif (len >= sizeof dst2) { \t\tfputs(\"The buffer is too small!\\n\", stderr); \t\texit(1); \t} \tmemcpy(dst2, src, len + 1); \t/* \t * Option 3. Use strdup() from , to allocate a copy. \t */ \tdst3 = strdup(src); \tif (dst3 == NULL) { \t\t/* Failed to allocate memory! */ \t\tperror(\"strdup\"); \t\texit(1); \t} \t/* Create another reference to the source string. */ \tref = src; \t/* Modify the source string, not its copies. */ \tmemset(src, '-', 5); \tprintf(\" src: %s\\n\", src); /* src: ----- */ \tprintf(\"dst1: %s\\n\", dst1); /* dst1: Hello */ \tprintf(\"dst2: %s\\n\", dst2); /* dst2: Hello */ \tprintf(\"dst3: %s\\n\", dst3); /* dst3: Hello */ \tprintf(\" ref: %s\\n\", ref); /* ref: ----- */ \t/* Free memory from strdup(). */ \tfree(dst3); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut len: u64 = 0; let mut src: [i8; 6] = *::core::mem::transmute::<&[u8; 6], &mut [i8; 6]>(b\"Hello\\0\"); let mut dst1: [i8; 80] = [0; 80]; let mut dst2: [i8; 80] = [0; 80]; let mut dst3: *mut i8 = 0 as *mut i8; let mut ref_0: *mut i8 = 0 as *mut i8; strcpy(dst1.as_mut_ptr(), src.as_mut_ptr()); len = strlen(src.as_mut_ptr()); if len >= ::core::mem::size_of::<[i8; 80]>() as u64 { fputs( b\"The buffer is too small!\\n\\0\" as *const u8 as *const i8, stderr, ); exit(1); } memcpy( dst2.as_mut_ptr() as *mut libc::c_void, src.as_mut_ptr() as *const libc::c_void, len.wrapping_add(1), ); dst3 = strdup(src.as_mut_ptr()); if dst3.is_null() { perror(b\"strdup\\0\" as *const u8 as *const i8); exit(1); } ref_0 = src.as_mut_ptr(); memset(src.as_mut_ptr() as *mut libc::c_void, '-' as i32, 5); print!( \" src: {}\\n\", build_str_from_raw_ptr(src.as_mut_ptr() as *mut u8) ); print!( \"dst1: {}\\n\", build_str_from_raw_ptr(dst1.as_mut_ptr() as *mut u8) ); print!( \"dst2: {}\\n\", build_str_from_raw_ptr(dst2.as_mut_ptr() as *mut u8) ); print!(\"dst3: {}\\n\", build_str_from_raw_ptr(dst3 as *mut u8)); print!(\" ref: {}\\n\", build_str_from_raw_ptr(ref_0 as *mut u8)); free(dst3 as *mut libc::c_void); return 0; } }" }, { "index": 27, "before": "int filter_next(void *s) { \tgen_t *in = ((filter_gen_t*)s)->in, *wo = ((filter_gen_t*)s)->without; \tdo{ \t\tseq_next(in); \t\twhile (wo->output < in->output) \t\t\tseq_next(wo); \t} while(wo->output == in->output); \treturn in->output; }", "after": "pub extern \"C\" fn filter_next(mut s: *mut libc::c_void) -> i32 { unsafe { let mut in_0: *mut gen_t = (*(s as *mut filter_gen_t)).in_0 as *mut gen_t; let mut wo: *mut gen_t = (*(s as *mut filter_gen_t)).without as *mut gen_t; loop { seq_next(in_0 as *mut libc::c_void); while (*wo).output < (*in_0).output { seq_next(wo as *mut libc::c_void); } if !((*wo).output == (*in_0).output) { break; } } return (*in_0).output; } }" }, { "index": 28, "before": "int seq_next(void *state) { \treturn ((gen_t*)state)->output = (*(seq_func*)state)(state); }", "after": "pub extern \"C\" fn seq_next(mut state: *mut libc::c_void) -> i32 { unsafe { let ref mut fresh0 = (*(state as *mut gen_t)).output; *fresh0 = (*(state as *mut seq_func)).expect(\"non-null function pointer\")(state); return *fresh0; } }" }, { "index": 29, "before": "int main() { \tint i; \tvoid *s = filter_seq(power_seq(2), power_seq(3)); \tfor (i = 0; i < 20; i++) seq_next(s); \tfor (i = 0; i < 10; i++) \t\tprintf(\"%d\\n\", seq_next(s)); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut i: i32 = 0; let mut s: *mut libc::c_void = filter_seq(power_seq(2) as *mut gen_t, power_seq(3) as *mut gen_t); i = 0; while i < 20 { seq_next(s); i += 1; i; } i = 0; while i < 10 { print!(\"{}\\n\", seq_next(s)); i += 1; i; } return 0; } }" }, { "index": 30, "before": "int power_next(void *s) { \treturn (int)pow(++((power_gen_t*)s)->pos, ((power_gen_t*)s)->n); }", "after": "pub extern \"C\" fn power_next(mut s: *mut libc::c_void) -> i32 { unsafe { let ref mut fresh1 = (*(s as *mut power_gen_t)).pos; *fresh1 += 1; return pow(*fresh1 as f64, (*(s as *mut power_gen_t)).n as f64) as i32; } }" }, { "index": 31, "before": "int test (int a, int b) { /* mov EAX, [ESP+4] add EAX, [ESP+8] ret */ char code[] = {0x8B, 0x44, 0x24, 0x4, 0x3, 0x44, 0x24, 0x8, 0xC3}; void *buf; int c; /* copy code to executable buffer */ buf = mmap (0,sizeof(code),PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON,-1,0); memcpy (buf, code, sizeof(code)); /* run code */ c = ((int (*) (int, int))buf)(a, b); /* free buffer */ munmap (buf, sizeof(code)); return c; }", "after": "pub extern \"C\" fn test(mut a: i32, mut b: i32) -> i32 { unsafe { let mut code: [i8; 9] = [0x8b, 0x44, 0x24, 0x4, 0x3, 0x44, 0x24, 0x8, 0xc3]; let mut buf: *mut libc::c_void = 0 as *mut libc::c_void; let mut c: i32 = 0; buf = mmap( 0 as *mut libc::c_void, ::core::mem::size_of::<[i8; 9]>() as u64, 0x1 | 0x2 | 0x4, 0x2 | 0x20, -1, 0, ); memcpy( buf, code.as_mut_ptr() as *const libc::c_void, ::core::mem::size_of::<[i8; 9]>() as u64, ); c = (::core::mem::transmute::< *mut libc::c_void, Option i32>, >(buf)) .expect(\"non-null function pointer\")(a, b); munmap(buf, ::core::mem::size_of::<[i8; 9]>() as u64); return c; } }" }, { "index": 32, "before": "int main () { printf(\"%d\\n\", test(7,12)); return 0; }", "after": "fn main() -> i32 { print!(\"{}\\n\", test(7, 12)); return 0; }" }, { "index": 33, "before": "int main() { int n = 3; double m1[] = {25, 15, -5, 15, 18, 0, -5, 0, 11}; double *c1 = cholesky(m1, n); show_matrix(c1, n); printf(\"\\n\"); free(c1); n = 4; double m2[] = {18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106}; double *c2 = cholesky(m2, n); show_matrix(c2, n); free(c2); return 0; }", "after": "fn main() -> i32 { unsafe { let mut n: i32 = 3; let mut m1: [f64; 9] = [ 25 as f64, 15 as f64, -5i32 as f64, 15 as f64, 18 as f64, 0 as f64, -5i32 as f64, 0 as f64, 11 as f64, ]; let mut c1: *mut f64 = cholesky(m1.as_mut_ptr(), n); show_matrix(c1, n); print!(\"\\n\"); free(c1 as *mut libc::c_void); n = 4; let mut m2: [f64; 16] = [ 18 as f64, 22 as f64, 54 as f64, 42 as f64, 22 as f64, 70 as f64, 86 as f64, 62 as f64, 54 as f64, 86 as f64, 174 as f64, 134 as f64, 42 as f64, 62 as f64, 134 as f64, 106 as f64, ]; let mut c2: *mut f64 = cholesky(m2.as_mut_ptr(), n); show_matrix(c2, n); free(c2 as *mut libc::c_void); return 0; } }" }, { "index": 34, "before": "void show_matrix(double *A, int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) printf(\"%2.5f \", A[i * n + j]); printf(\"\\n\"); } }", "after": "pub extern \"C\" fn show_matrix(mut A: *mut f64, mut n: i32) { unsafe { let mut i: i32 = 0; while i < n { let mut j: i32 = 0; while j < n { print!(\"{:2.5} \", *A.offset((i * n + j) as isize)); j += 1; j; } print!(\"\\n\"); i += 1; i; } } }" }, { "index": 35, "before": "int walk_board(int w, int h, int x, int y, cell **b) { \tint i, nx, ny, least; \tint steps = 0; \tprintf(E\"H\"E\"J\"E\"%d;%dH\"E\"32m[]\"E\"m\", y + 1, 1 + 2 * x); \twhile (1) { \t\t/* occupy cell */ \t\tb[y][x] = 255; \t\t/* reduce all neighbors' neighbor count */ \t\tfor (i = 0; i < 8; i++) \t\t\tb[ y + dy[i] ][ x + dx[i] ]--; \t\t/* find neighbor with lowest neighbor count */ \t\tleast = 255; \t\tfor (i = 0; i < 8; i++) { \t\t\tif (b[ y + dy[i] ][ x + dx[i] ] < least) { \t\t\t\tnx = x + dx[i]; \t\t\t\tny = y + dy[i]; \t\t\t\tleast = b[ny][nx]; \t\t\t} \t\t} \t\tif (least > 7) { \t\t\tprintf(E\"%dH\", h + 2); \t\t\treturn steps == w * h - 1; \t\t} \t\tif (steps++) printf(E\"%d;%dH[]\", y + 1, 1 + 2 * x); \t\tx = nx, y = ny; \t\tprintf(E\"%d;%dH\"E\"31m[]\"E\"m\", y + 1, 1 + 2 * x); \t\tfflush(stdout); \t\tusleep(120000); \t}", "after": "pub extern \"C\" fn walk_board( mut w: i32, mut h: i32, mut x: i32, mut y: i32, mut b: *mut *mut u8, ) -> i32 { unsafe { let mut i: i32 = 0; let mut nx: i32 = 0; let mut ny: i32 = 0; let mut least: i32 = 0; let mut steps: i32 = 0; print!(\"\\x1B[H\\x1B[J\\x1B[{};{}H\\x1B[32m[]\\x1B[m\", y + 1, 1 + 2 * x); loop { *(*b.offset(y as isize)).offset(x as isize) = 255; i = 0; while i < 8 { let ref mut fresh5 = *(*b.offset((y + dy[i as usize]) as isize)) .offset((x + dx[i as usize]) as isize); *fresh5 = (*fresh5).wrapping_sub(1); *fresh5; i += 1; i; } least = 255; i = 0; while i < 8 { if (*(*b.offset((y + dy[i as usize]) as isize)) .offset((x + dx[i as usize]) as isize) as i32) < least { nx = x + dx[i as usize]; ny = y + dy[i as usize]; least = *(*b.offset(ny as isize)).offset(nx as isize) as i32; } i += 1; i; } if least > 7 { print!(\"\\x1B[{}H\", h + 2); return (steps == w * h - 1i32) as i32; } let fresh6 = steps; steps = steps + 1; if fresh6 != 0 { print!(\"\\x1B[{};{}H[]\", y + 1, 1 + 2 * x); } x = nx; y = ny; print!(\"\\x1B[{};{}H\\x1B[31m[]\\x1B[m\", y + 1, 1 + 2 * x); fflush(stdout); usleep(120000); } } }" }, { "index": 36, "before": "void init_board(int w, int h, cell **a, cell **b) { \tint i, j, k, x, y, p = w + 4, q = h + 4; \t/* b is board; a is board with 2 rows padded at each side */ \ta[0] = (cell*)(a + q); \tb[0] = a[0] + 2; \tfor (i = 1; i < q; i++) { \t\ta[i] = a[i-1] + p; \t\tb[i] = a[i] + 2; \t} \tmemset(a[0], 255, p * q); \tfor (i = 0; i < h; i++) { \t\tfor (j = 0; j < w; j++) { \t\t\tfor (k = 0; k < 8; k++) { \t\t\t\tx = j + dx[k], y = i + dy[k]; \t\t\t\tif (b[i+2][j] == 255) b[i+2][j] = 0; \t\t\t\tb[i+2][j] += x >= 0 && x < w && y >= 0 && y < h; \t\t\t} \t\t} \t} }", "after": "pub extern \"C\" fn init_board(mut w: i32, mut h: i32, mut a: *mut *mut u8, mut b: *mut *mut u8) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut k: i32 = 0; let mut x: i32 = 0; let mut y: i32 = 0; let mut p: i32 = w + 4; let mut q: i32 = h + 4; let ref mut fresh0 = *a.offset(0 as isize); *fresh0 = a.offset(q as isize) as *mut u8; let ref mut fresh1 = *b.offset(0 as isize); *fresh1 = (*a.offset(0 as isize)).offset(2 as isize); i = 1; while i < q { let ref mut fresh2 = *a.offset(i as isize); *fresh2 = (*a.offset((i - 1i32) as isize)).offset(p as isize); let ref mut fresh3 = *b.offset(i as isize); *fresh3 = (*a.offset(i as isize)).offset(2 as isize); i += 1; i; } memset( *a.offset(0 as isize) as *mut libc::c_void, 255, (p * q) as u64, ); i = 0; while i < h { j = 0; while j < w { k = 0; while k < 8 { x = j + dx[k as usize]; y = i + dy[k as usize]; if *(*b.offset((i + 2i32) as isize)).offset(j as isize) as i32 == 255 { *(*b.offset((i + 2i32) as isize)).offset(j as isize) = 0; } let ref mut fresh4 = *(*b.offset((i + 2i32) as isize)).offset(j as isize); *fresh4 = (*fresh4 as i32 + (x >= 0 && x < w && y >= 0 && y < h) as i32) as u8; k += 1; k; } j += 1; j; } i += 1; i; } } }" }, { "index": 37, "before": "int solve(int w, int h) { \tint x = 0, y = 0; \tcell **a, **b; \ta = malloc((w + 4) * (h + 4) + sizeof(cell*) * (h + 4)); \tb = malloc((h + 4) * sizeof(cell*)); \twhile (1) { \t\tinit_board(w, h, a, b); \t\tif (walk_board(w, h, x, y, b + 2)) { \t\t\tprintf(\"Success!\\n\"); \t\t\treturn 1; \t\t} \t\tif (++x >= w) x = 0, y++; \t\tif (y >= h) { \t\t\tprintf(\"Failed to find a solution\\n\"); \t\t\treturn 0; \t\t} \t\tprintf(\"Any key to try next start position\"); \t\tgetchar(); \t} }", "after": "pub extern \"C\" fn solve(mut w: i32, mut h: i32) -> i32 { unsafe { let mut x: i32 = 0; let mut y: i32 = 0; let mut a: *mut *mut u8 = 0 as *mut *mut u8; let mut b: *mut *mut u8 = 0 as *mut *mut u8; a = malloc((((w + 4i32) * (h + 4i32)) as u64).wrapping_add( (::core::mem::size_of::<*mut u8>() as u64).wrapping_mul((h + 4i32) as u64), )) as *mut *mut u8; b = malloc(((h + 4i32) as u64).wrapping_mul(::core::mem::size_of::<*mut u8>() as u64)) as *mut *mut u8; loop { init_board(w, h, a, b); if walk_board(w, h, x, y, b.offset(2 as isize)) != 0 { print!(\"Success!\\n\"); return 1; } x += 1; if x >= w { x = 0; y += 1; y; } if y >= h { print!(\"Failed to find a solution\\n\"); return 0; } print!(\"Any key to try next start position\"); rust_getchar() as i32; } } }" }, { "index": 38, "before": "int main(int c, char **v) { \tint w, h; \tif (c < 2 || (w = atoi(v[1])) <= 0) w = 8; \tif (c < 3 || (h = atoi(v[2])) <= 0) h = w; \tsolve(w, h); \treturn 0; }", "after": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { let mut w: i32 = 0; let mut h: i32 = 0; if c < 2 || { w = atoi(*v.offset(1 as isize)); w <= 0 } { w = 8; } if c < 3 || { h = atoi(*v.offset(2 as isize)); h <= 0 } { h = w; } solve(w, h); return 0; } }" }, { "index": 39, "before": "int gcd(int m, int n) { int tmp; while(m) { tmp = m; m = n % m; n = tmp; } return n; }", "after": "pub extern \"C\" fn gcd(mut m: i32, mut n: i32) -> i32 { let mut tmp: i32 = 0; while m != 0 { tmp = m; m = n % m; n = tmp; } return n; }" }, { "index": 40, "before": "int lcm(int m, int n) { return m / gcd(m, n) * n; }", "after": "pub extern \"C\" fn lcm(mut m: i32, mut n: i32) -> i32 { return m / gcd(m, n) * n; }" }, { "index": 41, "before": "int main() { printf(\"lcm(35, 21) = %d\\n\", lcm(21,35)); return 0; }", "after": "fn main() -> i32 { print!(\"lcm(35, 21) = {}\\n\", lcm(21, 35)); return 0; }" }, { "index": 42, "before": "void mpz_left_fac_ui(mpz_t rop, unsigned long op) { mpz_t t1; mpz_init_set_ui(t1, 1); mpz_set_ui(rop, 0); size_t i; for (i = 1; i <= op; ++i) { mpz_add(rop, rop, t1); mpz_mul_ui(t1, t1, i); } mpz_clear(t1); }", "after": "pub extern \"C\" fn mpz_left_fac_ui(mut rop: i32, mut op: u64) { let mut i: u64 = 0; i = 1; while i <= op { i = i.wrapping_add(1); i; } }" }, { "index": 43, "before": "size_t mpz_digitcount(mpz_t op) { /* mpz_sizeinbase can not be trusted to give accurate base 10 length */ char *t = mpz_get_str(NULL, 10, op); size_t ret = strlen(t); free(t); return ret; }", "after": "pub extern \"C\" fn mpz_digitcount(mut op: i32) -> u64 { unsafe { let mut t: *mut i8 = 0 as *mut i8; let mut ret: u64 = strlen(t); free(t as *mut libc::c_void); return ret; } }" }, { "index": 44, "before": "int main(void) { mpz_t t; mpz_init(t); size_t i; for (i = 0; i <= 110; ++i) { if (i <= 10 || i % 10 == 0) { mpz_left_fac_ui(t, i); gmp_printf(\"!%u = %Zd\\n\", i, t); } } for (i = 1000; i <= 10000; i += 1000) { mpz_left_fac_ui(t, i); printf(\"!%u has %u digits\\n\", i, mpz_digitcount(t)); } mpz_clear(t); return 0; }", "after": "fn main() -> i32 { let mut i: u64 = 0; i = 0; while i <= 110 { i <= 10 || i.wrapping_rem(10) == 0; i = i.wrapping_add(1); i; } i = 1000; while i <= 10000 { i = (i).wrapping_add(1000) as u64; } return 0; }" }, { "index": 45, "before": "int main() { \tconst char *s = \"The quick brown fox jumps over the lazy dog\"; \tprintf(\"%\" PRIX32 \"\\n\", rc_crc32(0, s, strlen(s))); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut s: *const i8 = b\"The quick brown fox jumps over the lazy dog\\0\" as *const u8 as *const i8; print!(\"{:X}\\n\", rc_crc32(0, s, strlen(s))); return 0; } }" }, { "index": 46, "before": "uint32_t rc_crc32(uint32_t crc, const char *buf, size_t len) { \tstatic uint32_t table[256]; \tstatic int have_table = 0; \tuint32_t rem; \tuint8_t octet; \tint i, j; \tconst char *p, *q; \t/* This check is not thread safe; there is no mutex. */ \tif (have_table == 0) { \t\t/* Calculate CRC table. */ \t\tfor (i = 0; i < 256; i++) { \t\t\trem = i; /* remainder from polynomial division */ \t\t\tfor (j = 0; j < 8; j++) { \t\t\t\tif (rem & 1) { \t\t\t\t\trem >>= 1; \t\t\t\t\trem ^= 0xedb88320; \t\t\t\t} else \t\t\t\t\trem >>= 1; \t\t\t} \t\t\ttable[i] = rem; \t\t} \t\thave_table = 1; \t} \tcrc = ~crc; \tq = buf + len; \tfor (p = buf; p < q; p++) { \t\toctet = *p; /* Cast to unsigned octet. */ \t\tcrc = (crc >> 8) ^ table[(crc & 0xff) ^ octet]; \t} \treturn ~crc; }", "after": "pub extern \"C\" fn rc_crc32(mut crc: u32, mut buf: *const i8, mut len: u64) -> u32 { unsafe { static mut table: [u32; 256] = [0; 256]; static mut have_table: i32 = 0; let mut rem: u32 = 0; let mut octet: u8 = 0; let mut i: i32 = 0; let mut j: i32 = 0; let mut p: *const i8 = 0 as *const i8; let mut q: *const i8 = 0 as *const i8; if have_table == 0 { i = 0; while i < 256 { rem = i as u32; j = 0; while j < 8 { if rem & 1 != 0 { rem >>= 1; rem ^= 0xedb88320; } else { rem >>= 1; } j += 1; j; } table[i as usize] = rem; i += 1; i; } have_table = 1; } crc = !crc; q = buf.offset(len as isize); p = buf; while p < q { octet = *p as u8; crc = crc >> 8 ^ table[(crc & 0xff ^ octet as u32) as usize]; p = p.offset(1); p; } return !crc; } }" }, { "index": 47, "before": "int item_cmp(const void *aa, const void *bb) { \tconst struct item *a = aa, *b = bb; \tdouble ua = a->v / a->w, ub = b->v / b->w; \treturn ua < ub ? -1 : ua > ub; }", "after": "pub extern \"C\" fn item_cmp(mut aa: *const libc::c_void, mut bb: *const libc::c_void) -> i32 { unsafe { let mut a: *const item = aa as *const item; let mut b: *const item = bb as *const item; let mut ua: f64 = (*a).v / (*a).w; let mut ub: f64 = (*b).v / (*b).w; return if ua < ub { -1 } else { (ua > ub) as i32 }; } }" }, { "index": 48, "before": "int main() { \tstruct item *it; \tdouble space = 15; \tqsort(items, 9, sizeof(struct item), item_cmp); \tfor (it = items + 9; it---items && space > 0; space -= it->w) \t\tif (space >= it->w) \t\t\tprintf(\"take all %s\\n\", it->name); \t\telse \t\t\tprintf(\"take %gkg of %g kg of %s\\n\", \t\t\t\tspace, it->w, it->name); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut it: *mut item = 0 as *mut item; let mut space: f64 = 15 as f64; qsort( items.as_mut_ptr() as *mut libc::c_void, 9, ::core::mem::size_of::() as u64, Some(item_cmp as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32), ); it = items.as_mut_ptr().offset(9 as isize); loop { let fresh0 = it; it = it.offset(-1); if !(fresh0.offset_from(items.as_mut_ptr()) as i64 != 0 && space > 0 as f64) { break; } if space >= (*it).w { print!( \"take all {}\\n\", build_str_from_raw_ptr((*it).name as *mut u8) ); } else { print!( \"take {}kg of {} kg of {}\\n\", space, (*it).w, build_str_from_raw_ptr((*it).name as *mut u8) ); } space -= (*it).w; } return 0; } }" }, { "index": 49, "before": "void cidr_format(const cidr_t* cidr, char* str, size_t size) { uint32_t address = cidr->address; unsigned int d = address & UINT8_MAX; address >>= 8; unsigned int c = address & UINT8_MAX; address >>= 8; unsigned int b = address & UINT8_MAX; address >>= 8; unsigned int a = address & UINT8_MAX; snprintf(str, size, \"%u.%u.%u.%u/%u\", a, b, c, d, cidr->mask_length); }", "after": "pub extern \"C\" fn cidr_format(mut cidr: *const cidr_t, mut str: *mut i8, mut size: u64) { unsafe { let mut address: u32 = (*cidr).address; let mut d: u32 = address & 255; address >>= 8; let mut c: u32 = address & 255; address >>= 8; let mut b: u32 = address & 255; address >>= 8; let mut a: u32 = address & 255; snprintf( str, size, b\"%u.%u.%u.%u/%u\\0\" as *const u8 as *const i8, a, b, c, d, (*cidr).mask_length, ); } }" }, { "index": 50, "before": "int main(int argc, char** argv) { const char* tests[] = { \"87.70.141.1/22\", \"36.18.154.103/12\", \"62.62.197.11/29\", \"67.137.119.181/4\", \"161.214.74.21/24\", \"184.232.176.184/18\" }; for (int i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) { cidr_t cidr; if (cidr_parse(tests[i], &cidr)) { char out[32]; cidr_format(&cidr, out, sizeof(out)); printf(\"%-18s -> %s\\n\", tests[i], out); } else { fprintf(stderr, \"%s: invalid CIDR\\n\", tests[i]); } } return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut tests: [*const i8; 6] = [ b\"87.70.141.1/22\\0\" as *const u8 as *const i8, b\"36.18.154.103/12\\0\" as *const u8 as *const i8, b\"62.62.197.11/29\\0\" as *const u8 as *const i8, b\"67.137.119.181/4\\0\" as *const u8 as *const i8, b\"161.214.74.21/24\\0\" as *const u8 as *const i8, b\"184.232.176.184/18\\0\" as *const u8 as *const i8, ]; let mut i: i32 = 0; while (i as u64) < (::core::mem::size_of::<[*const i8; 6]>() as u64) .wrapping_div(::core::mem::size_of::<*const i8>() as u64) { let mut cidr: cidr_t = cidr_t { address: 0, mask_length: 0, }; if cidr_parse(tests[i as usize], &mut cidr) { let mut out: [i8; 32] = [0; 32]; cidr_format( &mut cidr, out.as_mut_ptr(), ::core::mem::size_of::<[i8; 32]>() as u64, ); print!( \"{:-18} -> {}\\n\", build_str_from_raw_ptr(tests[i as usize] as *mut u8), build_str_from_raw_ptr(out.as_mut_ptr() as *mut u8) ); } else { fprintf( stderr, b\"%s: invalid CIDR\\n\\0\" as *const u8 as *const i8, tests[i as usize], ); } i += 1; i; } return 0; } }" }, { "index": 51, "before": "bool cidr_parse(const char* str, cidr_t* cidr) { int a, b, c, d, m; if (sscanf(str, \"%d.%d.%d.%d/%d\", &a, &b, &c, &d, &m) != 5) return false; if (m < 1 || m > 32 || a < 0 || a > UINT8_MAX || b < 0 || b > UINT8_MAX || c < 0 || c > UINT8_MAX || d < 0 || d > UINT8_MAX) return false; uint32_t mask = ~((1 << (32 - m)) - 1); uint32_t address = (a << 24) + (b << 16) + (c << 8) + d; address &= mask; cidr->address = address; cidr->mask_length = m; return true; }", "after": "pub extern \"C\" fn cidr_parse(mut str: *const i8, mut cidr: *mut cidr_t) -> bool { unsafe { let mut a: i32 = 0; let mut b: i32 = 0; let mut c: i32 = 0; let mut d: i32 = 0; let mut m: i32 = 0; if sscanf( str, b\"%d.%d.%d.%d/%d\\0\" as *const u8 as *const i8, &mut a as *mut i32, &mut b as *mut i32, &mut c as *mut i32, &mut d as *mut i32, &mut m as *mut i32, ) != 5 { return 0 != 0; } if m < 1 || m > 32 || a < 0 || a > 255 || b < 0 || b > 255 || c < 0 || c > 255 || d < 0 || d > 255 { return 0 != 0; } let mut mask: u32 = !((1i32 << 32 - m) - 1) as u32; let mut address: u32 = ((a << 24i32) + (b << 16) + (c << 8) + d) as u32; address &= mask; (*cidr).address = address; (*cidr).mask_length = m as u32; return 1 != 0; } }" }, { "index": 52, "before": "int main(int argc, char* argv[]) { int i, count=0; double f, sum=0.0, prod=1.0, resum=0.0; for (i=1; i i32 { unsafe { let mut i: i32 = 0; let mut count: i32 = 0; let mut f: f64 = 0.; let mut sum: f64 = 0.0f64; let mut prod: f64 = 1.0f64; let mut resum: f64 = 0.0f64; i = 1; while i < argc { f = atof(*argv.offset(i as isize)); count += 1; count; sum += f; prod *= f; resum += 1.0f64 / f; i += 1; i; } print!(\"Arithmetic mean = {}\\n\", sum / count as f64); print!(\"Geometric mean = {}\\n\", pow(prod, 1.0f64 / count as f64)); print!(\"Harmonic mean = {}\\n\", count as f64 / resum); return 0; } }" }, { "index": 53, "before": "int qselect(int *v, int len, int k) { #\tdefine SWAP(a, b) { tmp = v[a]; v[a] = v[b]; v[b] = tmp; } \tint i, st, tmp; \tfor (st = i = 0; i < len - 1; i++) { \t\tif (v[i] > v[len-1]) continue; \t\tSWAP(i, st); \t\tst++; \t} \tSWAP(len-1, st); \treturn k == st\t?v[st] \t\t\t:st > k\t? qselect(v, st, k) \t\t\t\t: qselect(v + st, len - st, k - st); }", "after": "pub extern \"C\" fn qselect(mut v: *mut i32, mut len: i32, mut k: i32) -> i32 { unsafe { let mut i: i32 = 0; let mut st: i32 = 0; let mut tmp: i32 = 0; i = 0; st = i; while i < len - 1 { if !(*v.offset(i as isize) > *v.offset((len - 1i32) as isize)) { tmp = *v.offset(i as isize); *v.offset(i as isize) = *v.offset(st as isize); *v.offset(st as isize) = tmp; st += 1; st; } i += 1; i; } tmp = *v.offset((len - 1i32) as isize); *v.offset((len - 1i32) as isize) = *v.offset(st as isize); *v.offset(st as isize) = tmp; return if k == st { *v.offset(st as isize) } else if st > k { qselect(v, st, k) } else { qselect(v.offset(st as isize), len - st, k - st) }; } }" }, { "index": 54, "before": "int main(void) { #\tdefine N (sizeof(x)/sizeof(x[0])) \tint x[] = {9, 8, 7, 6, 5, 0, 1, 2, 3, 4}; \tint y[N]; \tint i; \tfor (i = 0; i < 10; i++) { \t\tmemcpy(y, x, sizeof(x)); // qselect modifies array \t\tprintf(\"%d: %d\\n\", i, qselect(y, 10, i)); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut x: [i32; 10] = [9, 8, 7, 6, 5, 0, 1, 2, 3, 4]; let mut y: [i32; 10] = [0; 10]; let mut i: i32 = 0; i = 0; unsafe { while i < 10 { memcpy( y.as_mut_ptr() as *mut libc::c_void, x.as_mut_ptr() as *const libc::c_void, ::core::mem::size_of::<[i32; 10]>() as u64, ); print!(\"{}: {}\\n\", i, qselect(y.as_mut_ptr(), 10, i)); i += 1; i; } } return 0; }" }, { "index": 55, "before": "double f2(double x) { return 1.0/x; }", "after": "pub extern \"C\" fn f2(mut x: f64) -> f64 { return 1.0f64 / x; }" }, { "index": 56, "before": "double f3a(double x) { return x*x/2.0; }", "after": "pub extern \"C\" fn f3a(mut x: f64) -> f64 { return x * x / 2.0f64; }" }, { "index": 57, "before": "double f1a(double x) { return x*x*x*x/4.0; }", "after": "pub extern \"C\" fn f1a(mut x: f64) -> f64 { return x * x * x * x / 4.0f64; }" }, { "index": 58, "before": "int main() { int i, j; double ic; pfunc f[5] = { int_leftrect, int_rightrect, int_midrect, int_trapezium, int_simpson }; const char *names[5] = { \"leftrect\", \"rightrect\", \"midrect\", \"trapezium\", \"simpson\" }; rfunc rf[] = { f1, f2, f3, f3 }; rfunc If[] = { f1a, f2a, f3a, f3a }; double ivals[] = { 0.0, 1.0, 1.0, 100.0, 0.0, 5000.0, 0.0, 6000.0 }; double approx[] = { 100.0, 1000.0, 5000000.0, 6000000.0 }; for(j=0; j < (sizeof(rf) / sizeof(rfunc)); j++) { for(i=0; i < 5 ; i++) { ic = (*f[i])(ivals[2*j], ivals[2*j+1], approx[j], rf[j]); printf(\"%10s [ 0,1] num: %+lf, an: %lf\\n\", names[i], ic, INTG((*If[j]), ivals[2*j], ivals[2*j+1])); } printf(\"\\n\"); } }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut j: i32 = 0; let mut ic: f64 = 0.; unsafe { let mut f: [pfunc; 5] = [ Some( int_leftrect as unsafe extern \"C\" fn( f64, f64, f64, Option f64>, ) -> f64, ), Some( int_rightrect as unsafe extern \"C\" fn( f64, f64, f64, Option f64>, ) -> f64, ), Some( int_midrect as unsafe extern \"C\" fn( f64, f64, f64, Option f64>, ) -> f64, ), Some( int_trapezium as unsafe extern \"C\" fn( f64, f64, f64, Option f64>, ) -> f64, ), Some( int_simpson as unsafe extern \"C\" fn( f64, f64, f64, Option f64>, ) -> f64, ), ]; let mut names: [*const i8; 5] = [ b\"leftrect\\0\" as *const u8 as *const i8, b\"rightrect\\0\" as *const u8 as *const i8, b\"midrect\\0\" as *const u8 as *const i8, b\"trapezium\\0\" as *const u8 as *const i8, b\"simpson\\0\" as *const u8 as *const i8, ]; let mut rf: [rfunc; 4] = [ Some(f1 as unsafe extern \"C\" fn(f64) -> f64), Some(f2 as unsafe extern \"C\" fn(f64) -> f64), Some(f3 as unsafe extern \"C\" fn(f64) -> f64), Some(f3 as unsafe extern \"C\" fn(f64) -> f64), ]; let mut If: [rfunc; 4] = [ Some(f1a as unsafe extern \"C\" fn(f64) -> f64), Some(f2a as unsafe extern \"C\" fn(f64) -> f64), Some(f3a as unsafe extern \"C\" fn(f64) -> f64), Some(f3a as unsafe extern \"C\" fn(f64) -> f64), ]; let mut ivals: [f64; 8] = [ 0.0f64, 1.0f64, 1.0f64, 100.0f64, 0.0f64, 5000.0f64, 0.0f64, 6000.0f64, ]; let mut approx: [f64; 4] = [100.0f64, 1000.0f64, 5000000.0f64, 6000000.0f64]; j = 0; while (j as u64) < (::core::mem::size_of::<[rfunc; 4]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) { i = 0; while i < 5 { ic = (Some( (*f.as_mut_ptr().offset(i as isize)).expect(\"non-null function pointer\"), )) .expect(\"non-null function pointer\")( ivals[(2 * j) as usize], ivals[(2 * j + 1i32) as usize], approx[j as usize], ::core::mem::transmute:: f64>>( rf[j as usize], ), ); print!( \"{:10} [ 0,1] num: {:+}, an: {}\\n\", build_str_from_raw_ptr(names[i as usize] as *mut u8), ic, (Some( (*If.as_mut_ptr().offset(j as isize)).expect(\"non-null function pointer\") )) .expect(\"non-null function pointer\")( ivals[(2 * j + 1i32) as usize] ) - (Some( (*If.as_mut_ptr().offset(j as isize)).expect(\"non-null function pointer\"), )) .expect(\"non-null function pointer\")( ivals[(2 * j) as usize] ) ); i += 1; i; } print!(\"\\n\"); j += 1; j; } } return 0; }" }, { "index": 59, "before": "double f2a(double x) { return log(x); }", "after": "pub extern \"C\" fn f2a(mut x: f64) -> f64 { unsafe { return log(x); } }" }, { "index": 60, "before": "double int_trapezium(double from, double to, double n, double (*func)()) { double h = (to - from) / n; double sum = func(from) + func(to); int i; for(i = 1;i < n;i++) sum += 2.0*func(from + i * h); return h * sum / 2.0; }", "after": "pub extern \"C\" fn int_trapezium( mut from: f64, mut to: f64, mut n: f64, mut func: Option f64>, ) -> f64 { let mut h: f64 = (to - from) / n; unsafe { let mut sum: f64 = ::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(from) + ::core::mem::transmute::<_, fn(_) -> f64>(func.expect(\"non-null function pointer\"))( to, ); let mut i: i32 = 0; i = 1; while (i as f64) < n { sum += 2.0f64 * ::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(from + i as f64 * h); i += 1; i; } return h * sum / 2.0f64; } }" }, { "index": 61, "before": "double f1(double x) { return x*x*x; }", "after": "pub extern \"C\" fn f1(mut x: f64) -> f64 { return x * x * x; }" }, { "index": 62, "before": "double int_leftrect(double from, double to, double n, double (*func)()) { double h = (to-from)/n; double sum = 0.0, x; for(x=from; x <= (to-h); x += h) sum += func(x); return h*sum; }", "after": "pub extern \"C\" fn int_leftrect( mut from: f64, mut to: f64, mut n: f64, mut func: Option f64>, ) -> f64 { let mut h: f64 = (to - from) / n; let mut sum: f64 = 0.0f64; let mut x: f64 = 0.; x = from; unsafe { while x <= to - h { sum += ::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(x); x += h; } } return h * sum; }" }, { "index": 63, "before": "double int_simpson(double from, double to, double n, double (*func)()) { double h = (to - from) / n; double sum1 = 0.0; double sum2 = 0.0; int i; double x; for(i = 0;i < n;i++) sum1 += func(from + h * i + h / 2.0); for(i = 1;i < n;i++) sum2 += func(from + h * i); return h / 6.0 * (func(from) + func(to) + 4.0 * sum1 + 2.0 * sum2); }", "after": "pub extern \"C\" fn int_simpson( mut from: f64, mut to: f64, mut n: f64, mut func: Option f64>, ) -> f64 { let mut h: f64 = (to - from) / n; let mut sum1: f64 = 0.0f64; let mut sum2: f64 = 0.0f64; let mut i: i32 = 0; let mut x: f64 = 0.; i = 0; unsafe { while (i as f64) < n { sum1 += ::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(from + h * i as f64 + h / 2.0f64); i += 1; i; } } i = 1; unsafe { while (i as f64) < n { sum2 += ::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(from + h * i as f64); i += 1; i; } return h / 6.0f64 * (::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(from) + ::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(to) + 4.0f64 * sum1 + 2.0f64 * sum2); } }" }, { "index": 64, "before": "double int_rightrect(double from, double to, double n, double (*func)()) { double h = (to-from)/n; double sum = 0.0, x; for(x=from; x <= (to-h); x += h) sum += func(x+h); return h*sum; }", "after": "pub extern \"C\" fn int_rightrect( mut from: f64, mut to: f64, mut n: f64, mut func: Option f64>, ) -> f64 { let mut h: f64 = (to - from) / n; let mut sum: f64 = 0.0f64; let mut x: f64 = 0.; x = from; unsafe { while x <= to - h { sum += ::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(x + h); x += h; } } return h * sum; }" }, { "index": 65, "before": "double int_midrect(double from, double to, double n, double (*func)()) { double h = (to-from)/n; double sum = 0.0, x; for(x=from; x <= (to-h); x += h) sum += func(x+h/2.0); return h*sum; }", "after": "pub extern \"C\" fn int_midrect( mut from: f64, mut to: f64, mut n: f64, mut func: Option f64>, ) -> f64 { let mut h: f64 = (to - from) / n; let mut sum: f64 = 0.0f64; let mut x: f64 = 0.; x = from; unsafe { while x <= to - h { sum += ::core::mem::transmute::<_, fn(_) -> f64>( func.expect(\"non-null function pointer\"), )(x + h / 2.0f64); x += h; } } return h * sum; }" }, { "index": 66, "before": "double f3(double x) { return x; }", "after": "pub extern \"C\" fn f3(mut x: f64) -> f64 { return x; }" }, { "index": 67, "before": "int main(int argc, char*argv[]) { int nums2factor[] = { 2059, 223092870, 3135, 45 }; Factors ftors = { NULL, 0}; char sep; int i,j; for (i=0; i<4; i++) { factor( nums2factor[i], &ftors ); printf(\"\\nfactors of %d are:\\n \", nums2factor[i]); sep = ' '; for (j=0; j i32 { unsafe { let mut nums2factor: [i32; 4] = [2059, 223092870, 3135, 45]; let mut ftors: Factors = { let mut init = Factors { list: 0 as *mut i32, count: 0, }; init }; let mut sep: i8 = 0; let mut i: i32 = 0; let mut j: i32 = 0; i = 0; while i < 4 { factor(nums2factor[i as usize], &mut ftors); print!(\"\\nfactors of {} are:\\n \", nums2factor[i as usize]); sep = ' ' as i8; j = 0; while j < ftors.count as i32 { print!(\"{} {}\", sep as i32, *(ftors.list).offset(j as isize)); sep = ',' as i8; j += 1; j; } print!(\"\\n\"); i += 1; i; } return 0; } }" }, { "index": 68, "before": "void xferFactors( Factors *fctrs, int *flist, int flix ) { int ix, ij; int newSize = fctrs->count + flix; if (newSize > flix) { fctrs->list = realloc( fctrs->list, newSize * sizeof(int)); } else { fctrs->list = malloc( newSize * sizeof(int)); } for (ij=0,ix=fctrs->count; ixlist[ix] = flist[ij]; } fctrs->count = newSize; }", "after": "pub extern \"C\" fn xferFactors(mut fctrs: *mut Factors, mut flist: *mut i32, mut flix: i32) { unsafe { let mut ix: i32 = 0; let mut ij: i32 = 0; let mut newSize: i32 = (*fctrs).count as i32 + flix; if newSize > flix { (*fctrs).list = realloc( (*fctrs).list as *mut libc::c_void, (newSize as u64).wrapping_mul(::core::mem::size_of::() as u64), ) as *mut i32; } else { (*fctrs).list = malloc((newSize as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i32; } ij = 0; ix = (*fctrs).count as i32; while ix < newSize { *((*fctrs).list).offset(ix as isize) = *flist.offset(ij as isize); ij += 1; ij; ix += 1; ix; } (*fctrs).count = newSize as i16; } }" }, { "index": 69, "before": "int main(void) { const int dimx = 800, dimy = 800; int i, j; FILE *fp = fopen(\"first.ppm\", \"wb\"); /* b - binary mode */ (void) fprintf(fp, \"P6\\n%d %d\\n255\\n\", dimx, dimy); for (j = 0; j < dimy; ++j) { for (i = 0; i < dimx; ++i) { static unsigned char color[3]; color[0] = i % 256; /* red */ color[1] = j % 256; /* green */ color[2] = (i * j) % 256; /* blue */ (void) fwrite(color, 1, 3, fp); } } (void) fclose(fp); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { let dimx: i32 = 800; let dimy: i32 = 800; let mut i: i32 = 0; let mut j: i32 = 0; let mut fp: *mut FILE = fopen( b\"first.ppm\\0\" as *const u8 as *const i8, b\"wb\\0\" as *const u8 as *const i8, ); fprintf( fp, b\"P6\\n%d %d\\n255\\n\\0\" as *const u8 as *const i8, dimx, dimy, ); j = 0; while j < dimy { i = 0; while i < dimx { static mut color: [u8; 3] = [0; 3]; color[0 as usize] = (i % 256i32) as u8; color[1 as usize] = (j % 256i32) as u8; color[2 as usize] = (i * j % 256i32) as u8; fwrite(color.as_mut_ptr() as *const libc::c_void, 1, 3, fp); i += 1; i; } j += 1; j; } fclose(fp); return 0; } }" }, { "index": 70, "before": "int main() { printf(\"%d\\n\", 'a'); /* prints \"97\" */ printf(\"%c\\n\", 97); /* prints \"a\"; we don't have to cast because printf is type agnostic */ return 0; }", "after": "fn main() -> i32 { print!(\"{}\\n\", 'a' as i32); print!(\"{}\\n\", 97); return 0; }" }, { "index": 71, "before": "bool damm(unsigned char *input, size_t length) { static const unsigned char table[10][10] = { {0, 3, 1, 7, 5, 9, 8, 6, 4, 2}, {7, 0, 9, 2, 1, 5, 4, 8, 6, 3}, {4, 2, 0, 6, 8, 7, 1, 3, 5, 9}, {1, 7, 5, 0, 9, 8, 3, 4, 2, 6}, {6, 1, 2, 3, 0, 4, 5, 9, 7, 8}, {3, 6, 7, 4, 2, 0, 9, 5, 8, 1}, {5, 8, 6, 9, 7, 2, 0, 1, 3, 4}, {8, 9, 4, 5, 3, 6, 2, 0, 1, 7}, {9, 4, 3, 8, 6, 1, 7, 2, 0, 5}, {2, 5, 8, 1, 4, 3, 6, 7, 9, 0}, }; unsigned char interim = 0; for (size_t i = 0; i < length; i++) { interim = table[interim][input[i]]; } return interim == 0; }", "after": "pub extern \"C\" fn damm(mut input: *mut u8, mut length: u64) -> bool { unsafe { static mut table: [[u8; 10]; 10] = [ [0, 3, 1, 7, 5, 9, 8, 6, 4, 2], [7, 0, 9, 2, 1, 5, 4, 8, 6, 3], [4, 2, 0, 6, 8, 7, 1, 3, 5, 9], [1, 7, 5, 0, 9, 8, 3, 4, 2, 6], [6, 1, 2, 3, 0, 4, 5, 9, 7, 8], [3, 6, 7, 4, 2, 0, 9, 5, 8, 1], [5, 8, 6, 9, 7, 2, 0, 1, 3, 4], [8, 9, 4, 5, 3, 6, 2, 0, 1, 7], [9, 4, 3, 8, 6, 1, 7, 2, 0, 5], [2, 5, 8, 1, 4, 3, 6, 7, 9, 0], ]; let mut interim: u8 = 0; let mut i: u64 = 0; while i < length { interim = table[interim as usize][*input.offset(i as isize) as usize]; i = i.wrapping_add(1); i; } return interim as i32 == 0; } }" }, { "index": 72, "before": "int main() { unsigned char input[4] = {5, 7, 2, 4}; puts(damm(input, 4) ? \"Checksum correct\" : \"Checksum incorrect\"); return 0; }", "after": "fn main() -> i32 { let mut input: [u8; 4] = [5, 7, 2, 4]; unsafe { puts(if damm(input.as_mut_ptr(), 4) as i32 != 0 { b\"Checksum correct\\0\" as *const u8 as *const i8 } else { b\"Checksum incorrect\\0\" as *const u8 as *const i8 }); } return 0; }" }, { "index": 73, "before": "int main(void) { for (size_t i = 0; i < LEN(animals); i++) { printf(\"There was an old lady who swallowed a %s\\n%s\\n\", animals[i], verses[i]); for (size_t j = i; j > 0 && i < LEN(animals) - 1; j--) { printf(\"She swallowed the %s to catch the %s\\n\", animals[j], animals[j-1]); if (j == 1) { printf(\"%s\\n\", verses[0]); } } } }", "after": "fn main() -> i32 { let mut i: u64 = 0; unsafe { while i < (::core::mem::size_of::<[*const i8; 8]>() as u64) .wrapping_div(::core::mem::size_of::<*const i8>() as u64) { print!( \"There was an old lady who swallowed a {}\\n{}\\n\", build_str_from_raw_ptr(animals[i as usize] as *mut u8), build_str_from_raw_ptr(verses[i as usize] as *mut u8) ); let mut j: u64 = i; while j > 0 && i < (::core::mem::size_of::<[*const i8; 8]>() as u64) .wrapping_div(::core::mem::size_of::<*const i8>() as u64) .wrapping_sub(1) { print!( \"She swallowed the {} to catch the {}\\n\", build_str_from_raw_ptr(animals[j as usize] as *mut u8), build_str_from_raw_ptr(animals[j.wrapping_sub(1) as usize] as *mut u8) ); if j == 1 { print!( \"{}\\n\", build_str_from_raw_ptr(verses[0 as usize] as *mut u8) ); } j = j.wrapping_sub(1); j; } i = i.wrapping_add(1); i; } } return 0; }" }, { "index": 74, "before": "int main(int argc, char* argv[]) { double e; puts(\"The double precision in C give about 15 significant digits.\\n\" \"Values below are presented with 16 digits after the decimal point.\\n\"); // The most direct way to compute Euler constant. // e = exp(1); printf(\"Euler constant e = %.16lf\\n\", e); // The fast and independed method: e = lim (1 + 1/n)**n // int n = 8192; e = 1.0 + 1.0 / n; for (int i = 0; i < 13; i++) e *= e; printf(\"Euler constant e = %.16lf\\n\", e); // Taylor expansion e = 1 + 1/1 + 1/2 + 1/2/3 + 1/2/3/4 + 1/2/3/4/5 + ... // Actually Kahan summation may improve the accuracy, but is not necessary. // const int N = 1000; double a[1000]; a[0] = 1.0; for (int i = 1; i < N; i++) { a[i] = a[i-1] / i; } e = 1.; for (int i = N - 1; i > 0; i--) e += a[i]; printf(\"Euler constant e = %.16lf\\n\", e); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut e: f64 = 0.; puts (b\"The double precision in C give about 15 significant digits.\\nValues below are presented with 16 digits after the decimal point.\\n\\0\" as * const u8 as * const i8,); e = exp(1 as f64); print!(\"Euler constant e = {:.16}\\n\", e); let mut n: i32 = 8192; e = 1.0f64 + 1.0f64 / n as f64; let mut i: i32 = 0; while i < 13 { e *= e; i += 1; i; } print!(\"Euler constant e = {:.16}\\n\", e); let N: i32 = 1000; let mut a: [f64; 1000] = [0.; 1000]; a[0 as usize] = 1.0f64; let mut i_0: i32 = 1; while i_0 < N { a[i_0 as usize] = a[(i_0 - 1i32) as usize] / i_0 as f64; i_0 += 1; i_0; } e = 1.0f64; let mut i_1: i32 = N - 1; while i_1 > 0 { e += a[i_1 as usize]; i_1 -= 1; i_1; } print!(\"Euler constant e = {:.16}\\n\", e); return 0; } }" }, { "index": 75, "before": "int even_sel(int x) { return !(x & 1); }", "after": "pub extern \"C\" fn even_sel(mut x: i32) -> i32 { return (x & 1 == 0) as i32; }" }, { "index": 76, "before": "int tri_sel(int x) { return x % 3; }", "after": "pub extern \"C\" fn tri_sel(mut x: i32) -> i32 { return x % 3; }" }, { "index": 77, "before": "int main() { \tint in[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; \tint i, len; \tint *even = grep(in, 10, &len, even_sel, 0); \tprintf(\"Filtered even:\"); \tfor (i = 0; i < len; i++) printf(\" %d\", even[i]); \tprintf(\"\\n\"); \tgrep(in, 8, &len, tri_sel, 1); \tprintf(\"In-place filtered not multiple of 3:\"); \tfor (i = 0; i < len; i++) printf(\" %d\", in[i]); \tprintf(\"\\n\"); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut in_0: [i32; 10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; let mut i: i32 = 0; let mut len: i32 = 0; let mut even: *mut i32 = grep( in_0.as_mut_ptr(), 10, &mut len, Some(even_sel as unsafe extern \"C\" fn(i32) -> i32), 0, ); print!(\"Filtered even:\"); i = 0; while i < len { print!(\" {}\", *even.offset(i as isize)); i += 1; i; } print!(\"\\n\"); grep( in_0.as_mut_ptr(), 8, &mut len, Some(tri_sel as unsafe extern \"C\" fn(i32) -> i32), 1, ); print!(\"In-place filtered not multiple of 3:\"); i = 0; while i < len { print!(\" {}\", in_0[i as usize]); i += 1; i; } print!(\"\\n\"); return 0; } }" }, { "index": 78, "before": "int es_check(uint32_t *sieve, uint64_t n) { if ((n != 2 && !(n & 1)) || (n < 2)) return 0; else return !(sieve[n >> 6] & (1 << (n >> 1 & 31))); }", "after": "pub extern \"C\" fn es_check(mut sieve: *mut u32, mut n: u64) -> i32 { unsafe { if n != 2 && n & 1 == 0 || n < 2 { return 0; } else { return (*sieve.offset((n >> 6i32) as isize) & (1i32 << (n >> 1 & 31u64)) as u32 == 0) as i32; }; } }" }, { "index": 79, "before": "int main(void) { /* Construct a sieve of the first 1,000,000 primes */ uint64_t sieve_size; uint32_t *sieve = es_sieve(PRIMORIAL_LIMIT, &sieve_size); mpz_t primorial; mpz_init_set_ui(primorial, 1); uint64_t prime_count = 0; int print = 1; double unused; for (uint64_t i = 2; i < sieve_size && prime_count <= PRIMORIAL_LIMIT; ++i) { if (print) { if (prime_count < 10) gmp_printf(\"Primorial(%\" PRIu64 \") = %Zd\\n\", prime_count, primorial); /* Is the current number a power of 10? */ else if (!modf(log10(prime_count), &unused)) printf(\"Primorial(%\" PRIu64 \") has %zu digits\\n\", prime_count, mpz_number_of_digits(primorial)); print = 0; } if (es_check(sieve, i)) { mpz_mul_ui(primorial, primorial, i); prime_count++; print = 1; } } free(sieve); mpz_clear(primorial); return 0; }", "after": "fn main() -> i32 { unsafe { let mut sieve_size: u64 = 0; let mut sieve: *mut u32 = es_sieve(100000, &mut sieve_size); let mut prime_count: u64 = 0; let mut print: i32 = 1; let mut unused: f64 = 0.; let mut i: u64 = 2; while i < sieve_size && prime_count <= 100000 { if print != 0 { print = 0; } if es_check(sieve, i) != 0 { prime_count = prime_count.wrapping_add(1); prime_count; print = 1; } i = i.wrapping_add(1); i; } free(sieve as *mut libc::c_void); return 0; } }" }, { "index": 80, "before": "size_t mpz_number_of_digits(const mpz_t op) { char *opstr = mpz_get_str(NULL, 10, op); const size_t oplen = strlen(opstr); free(opstr); return oplen; }", "after": "pub extern \"C\" fn mpz_number_of_digits(op: i32) -> u64 { unsafe { let mut opstr: *mut i8 = 0 as *mut i8; let oplen: u64 = strlen(opstr); free(opstr as *mut libc::c_void); return oplen; } }" }, { "index": 81, "before": "double price_fix(double x) { \tint i; \tfor (i = 0; table[i][0] > 0; i++) \t\tif (x < table[i][0]) return table[i][1]; \tabort(); /* what else to do? */ }", "after": "pub extern \"C\" fn price_fix(mut x: f64) -> f64 { let mut i: i32 = 0; i = 0; unsafe { while table[i as usize][0 as usize] > 0 as f64 { if x < table[i as usize][0 as usize] { return table[i as usize][1 as usize]; } i += 1; i; } abort(); } }" }, { "index": 82, "before": "int main() { \tint i; \tfor (i = 0; i <= 100; i++) \t\tprintf(\"%.2f %.2f\\n\", i / 100., price_fix(i / 100.)); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; i = 0; while i <= 100 { print!( \"{:.2} {:.2}\\n\", i as f64 / 100.0f64, price_fix(i as f64 / 100.0f64) ); i += 1; i; } return 0; }" }, { "index": 83, "before": "void list_print(Node *words_list) { while (words_list != NULL) { printf(\"\\n%s\", words_list->word); words_list = words_list->next; } }", "after": "pub extern \"C\" fn list_print(mut words_list: *mut Node) { unsafe { while !words_list.is_null() { print!( \"\\n{}\", build_str_from_raw_ptr(((*words_list).word).as_mut_ptr() as *mut u8) ); words_list = (*words_list).next; } } }" }, { "index": 84, "before": "int is_ordered_word(const TWord word) { assert(word != NULL); int i; for (i = 0; word[i] != '\\0'; i++) if (word[i] > word[i + 1] && word[i + 1] != '\\0') return 0; return 1; }", "after": "pub extern \"C\" fn is_ordered_word(mut word: *const i8) -> i32 { unsafe { if !word.is_null() { } else { __assert_fail( b\"word != NULL\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 18, (*::core::mem::transmute::<&[u8; 34], &[i8; 34]>( b\"int is_ordered_word(const char *)\\0\", )) .as_ptr(), ); } 'c_1788: { if !word.is_null() { } else { __assert_fail( b\"word != NULL\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 18, (*::core::mem::transmute::<&[u8; 34], &[i8; 34]>( b\"int is_ordered_word(const char *)\\0\", )) .as_ptr(), ); } }; let mut i: i32 = 0; i = 0; while *word.offset(i as isize) as i32 != '\\0' as i32 { if *word.offset(i as isize) as i32 > *word.offset((i + 1i32) as isize) as i32 && *word.offset((i + 1i32) as isize) as i32 != '\\0' as i32 { return 0; } i += 1; i; } return 1; } }" }, { "index": 85, "before": "int main() { FILE *fp = fopen(\"unixdict.txt\", \"r\"); if (fp == NULL) return EXIT_FAILURE; Node *words = NULL; TWord line; unsigned int max_len = 0; while (fscanf(fp, \"%99s\\n\", line) != EOF) { if (strlen(line) > max_len && is_ordered_word(line)) { max_len = strlen(line); words = list_destroy(words); words = list_prepend(words, line); } else if (strlen(line) == max_len && is_ordered_word(line)) { words = list_prepend(words, line); } } fclose(fp); list_print(words); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { let mut fp: *mut FILE = fopen( b\"unixdict.txt\\0\" as *const u8 as *const i8, b\"r\\0\" as *const u8 as *const i8, ); if fp.is_null() { return 1; } let mut words: *mut Node = 0 as *mut Node; let mut line: TWord = [0; 100]; let mut max_len: u32 = 0; while fscanf(fp, b\"%99s\\n\\0\" as *const u8 as *const i8, line.as_mut_ptr()) != -1 { if strlen(line.as_mut_ptr()) > max_len as u64 && is_ordered_word(line.as_mut_ptr() as *const i8) != 0 { max_len = strlen(line.as_mut_ptr()) as u32; words = list_destroy(words); words = list_prepend(words, line.as_mut_ptr() as *const i8); } else if strlen(line.as_mut_ptr()) == max_len as u64 && is_ordered_word(line.as_mut_ptr() as *const i8) != 0 { words = list_prepend(words, line.as_mut_ptr() as *const i8); } } fclose(fp); list_print(words); return 0; } }" }, { "index": 86, "before": "int main(void){ unsigned i, j, k, choice, winsbyswitch=0, door[3]; srand(time(NULL)); //initialize random seed. for(i=0; i i32 { let mut i: u32 = 0; let mut j: u32 = 0; let mut k: u32 = 0; let mut choice: u32 = 0; let mut winsbyswitch: u32 = 0; let mut door: [u32; 3] = [0; 3]; unsafe { srand(rust_time(None) as u32); } i = 0; unsafe { while i < 3000000 { door[0 as usize] = (if rand() % 2 == 0 { 1i32 } else { 0 }) as u32; if door[0 as usize] != 0 { door[2 as usize] = 0; door[1 as usize] = door[2 as usize]; } else { door[1 as usize] = (if rand() % 2 == 0 { 1i32 } else { 0 }) as u32; door[2 as usize] = (if door[1 as usize] == 0 { 1 } else { 0 }) as u32; } choice = (rand() % 3i32) as u32; if door[choice.wrapping_add(1).wrapping_rem(3) as usize] == 0 && door[choice.wrapping_add(2).wrapping_rem(3) as usize] != 0 || door[choice.wrapping_add(2).wrapping_rem(3) as usize] == 0 && door[choice.wrapping_add(1).wrapping_rem(3) as usize] != 0 { winsbyswitch = winsbyswitch.wrapping_add(1); winsbyswitch; } i = i.wrapping_add(1); i; } } print!( \"\\nAfter {} games, I won {} by switching. That is {}%. \", 3000000, winsbyswitch, winsbyswitch as libc::c_float as f64 * 100.0f64 / i as libc::c_float as f64 ); return 0; }" }, { "index": 87, "before": "int main() { int i, j; double degrees[] = { 0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5, 84.37, 84.38, 101.25, 118.12, 118.13, 135.0, 151.87, 151.88, 168.75, 185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13, 270.0, 286.87, 286.88, 303.75, 320.62, 320.63, 337.5, 354.37, 354.38 }; const char * names = \"North \" \"North by east \" \"North-northeast \" \"Northeast by north \" \"Northeast \" \"Northeast by east \" \"East-northeast \" \"East by north \" \"East \" \"East by south \" \"East-southeast \" \"Southeast by east \" \"Southeast \" \"Southeast by south \" \"South-southeast \" \"South by east \" \"South \" \"South by west \" \"South-southwest \" \"Southwest by south \" \"Southwest \" \"Southwest by west \" \"West-southwest \" \"West by south \" \"West \" \"West by north \" \"West-northwest \" \"Northwest by west \" \"Northwest \" \"Northwest by north \" \"North-northwest \" \"North by west \" \"North \"; for (i = 0; i < 33; i++) { j = .5 + degrees[i] * 32 / 360; printf(\"%2d %.22s %6.2f\\n\", (j % 32) + 1, names + (j % 32) * 22, degrees[i]); } return 0; }", "after": "fn main() -> i32 { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut degrees: [f64; 33] = [ 0.0f64, 16.87f64, 16.88f64, 33.75f64, 50.62f64, 50.63f64, 67.5f64, 84.37f64, 84.38f64, 101.25f64, 118.12f64, 118.13f64, 135.0f64, 151.87f64, 151.88f64, 168.75f64, 185.62f64, 185.63f64, 202.5f64, 219.37f64, 219.38f64, 236.25f64, 253.12f64, 253.13f64, 270.0f64, 286.87f64, 286.88f64, 303.75f64, 320.62f64, 320.63f64, 337.5f64, 354.37f64, 354.38f64, ]; let mut names : * const i8 = b\"North North by east North-northeast Northeast by north Northeast Northeast by east East-northeast East by north East East by south East-southeast Southeast by east Southeast Southeast by south South-southeast South by east South South by west South-southwest Southwest by south Southwest Southwest by west West-southwest West by south West West by north West-northwest Northwest by west Northwest Northwest by north North-northwest North by west North \\0\" as * const u8 as * const i8; i = 0; while i < 33 { j = (0.5f64 + degrees[i as usize] * 32 as f64 / 360 as f64) as i32; print!( \"{:2} {:.22} {:6.2}\\n\", j % 32 + 1, build_str_from_raw_ptr(names.offset((j % 32 * 22i32) as isize) as *mut u8), degrees[i as usize] ); i += 1; i; } return 0; } }" }, { "index": 88, "before": "int is_prime(int n) { \tint i; \tcoef(n); \tc[0] += 1, c[i=n] -= 1; \twhile (i-- && !(c[i] % n)); \treturn i < 0; }", "after": "pub extern \"C\" fn is_prime(mut n: i32) -> i32 { let mut i: i32 = 0; coef(n); unsafe { c[0 as usize] += 1; } i = n; unsafe { c[i as usize] -= 1; loop { let fresh0 = i; i = i - 1; if !(fresh0 != 0 && c[i as usize] % n as i64 == 0) { break; } } } return (i < 0) as i32; }" }, { "index": 89, "before": "int main(void) { \tint n; \tfor (n = 0; n < 10; n++) { \t\tcoef(n); \t\tprintf(\"(x-1)^%d = \", n); \t\tshow(n); \t\tputchar('\\n'); \t} \tprintf(\"\\nprimes (never mind the 1):\"); \tfor (n = 1; n <= 63; n++) \t\tif (is_prime(n)) \t\t\tprintf(\" %d\", n); \tputchar('\\n'); \treturn 0; }", "after": "fn main() -> i32 { let mut n: i32 = 0; n = 0; while n < 10 { coef(n); print!(\"(x-1)^{} = \", n); show(n); print!(\"{}\", '\\n' as i32); n += 1; n; } print!(\"\\nprimes (never mind the 1):\"); n = 1; while n <= 63 { if is_prime(n) != 0 { print!(\" {}\", n); } n += 1; n; } print!(\"{}\", '\\n' as i32); return 0; }" }, { "index": 90, "before": "void show(int n) { \tdo printf(\"%+lldx^%d\", c[n], n); while (n--); }", "after": "pub extern \"C\" fn show(mut n: i32) { unsafe { loop { print!(\"{:+}x^{}\", c[n as usize], n); let fresh1 = n; n = n - 1; if !(fresh1 != 0) { break; } } } }" }, { "index": 91, "before": "void coef(int n) { \tint i, j; \tif (n < 0 || n > 63) abort(); // gracefully deal with range issue \tfor (c[i=0] = 1; i < n; c[0] = -c[0], i++) \t\tfor (c[1 + (j=i)] = 1; j > 0; j--) \t\t\tc[j] = c[j-1] - c[j]; }", "after": "pub extern \"C\" fn coef(mut n: i32) { let mut i: i32 = 0; let mut j: i32 = 0; unsafe { if n < 0 || n > 63 { abort(); } } i = 0; unsafe { c[i as usize] = 1; while i < n { j = i; c[(1 + j) as usize] = 1; while j > 0 { c[j as usize] = c[(j - 1i32) as usize] - c[j as usize]; j -= 1; j; } c[0 as usize] = -c[0 as usize]; i += 1; i; } } }" }, { "index": 92, "before": "int main() { puts(getenv(\"HOME\")); return 0; }", "after": "unsafe fn main() -> libc::c_int { puts(getenv(b\"HOME\\0\" as *const u8 as *const libc::c_char)); return 0 as libc::c_int; }" }, { "index": 93, "before": "int main(void) { \tt(5), t(14); \t// maybe not \t// t(10000); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { t(5 as libc::c_int); t(14 as libc::c_int); return 0 as libc::c_int; }" }, { "index": 94, "before": "void t(int n) { \tint i, j, c, len; \ti = n * (n - 1) / 2; \tfor (len = c = 1; c < i; c *= 10, len++); \tc -= i; // c is the col where width changes #define SPEED_MATTERS 0 #if SPEED_MATTERS\t// in case we really, really wanted to print huge triangles often \tchar tmp[32], s[4096], *p; \tsprintf(tmp, \"%*d\", len, 0); \tinline void inc_numstr(void) { \t\tint k = len; \tredo:\tif (!k--) return; \t\tif (tmp[k] == '9') { \t\t\ttmp[k] = '0'; \t\t\tgoto redo; \t\t} \t\tif (++tmp[k] == '!') \t\t\ttmp[k] = '1'; \t} \tfor (p = s, i = 1; i <= n; i++) { \t\tfor (j = 1; j <= i; j++) { \t\t\tinc_numstr(); \t\t\t__builtin_memcpy(p, tmp + 1 - (j >= c), len - (j < c)); \t\t\tp += len - (j < c); \t\t\t*(p++) = (i - j)? ' ' : '\\n'; \t\t\tif (p - s + len >= 4096) { \t\t\t\tfwrite(s, 1, p - s, stdout); \t\t\t\tp = s; \t\t\t} \t\t} \t} \tfwrite(s, 1, p - s, stdout); #else // NO_IT_DOESN'T \tint num; \tfor (num = i = 1; i <= n; i++) \t\tfor (j = 1; j <= i; j++) \t\t\tprintf(\"%*d%c\",\tlen - (j < c), num++, i - j ? ' ':'\\n'); #endif }", "after": "pub unsafe extern \"C\" fn t(mut n: libc::c_int) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut c: libc::c_int = 0; let mut len: libc::c_int = 0; i = n * (n - 1 as libc::c_int) / 2 as libc::c_int; c = 1 as libc::c_int; len = c; while c < i { c *= 10 as libc::c_int; len += 1; len; } c -= i; let mut num: libc::c_int = 0; i = 1 as libc::c_int; num = i; while i <= n { j = 1 as libc::c_int; while j <= i { let fresh0 = num; num = num + 1; printf( b\"%*d%c\\0\" as *const u8 as *const libc::c_char, len - (j < c) as libc::c_int, fresh0, if i - j != 0 { ' ' as i32 } else { '\\n' as i32 }, ); j += 1; j; } i += 1; i; } }" }, { "index": 95, "before": "int main() { \tdouble d = dist(36.12, -86.67, 33.94, -118.4); \t/* Americans don't know kilometers */ \tprintf(\"dist: %.1f km (%.1f mi.)\\n\", d, d / 1.609344); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut d: libc::c_double = dist(36.12f64, -86.67f64, 33.94f64, -118.4f64); printf( b\"dist: %.1f km (%.1f mi.)\\n\\0\" as *const u8 as *const libc::c_char, d, d / 1.609344f64, ); return 0 as libc::c_int; }" }, { "index": 96, "before": "double dist(double th1, double ph1, double th2, double ph2) { \tdouble dx, dy, dz; \tph1 -= ph2; \tph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; \tdz = sin(th1) - sin(th2); \tdx = cos(ph1) * cos(th1) - cos(th2); \tdy = sin(ph1) * cos(th1); \treturn asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * R; }", "after": "pub unsafe extern \"C\" fn dist( mut th1: libc::c_double, mut ph1: libc::c_double, mut th2: libc::c_double, mut ph2: libc::c_double, ) -> libc::c_double { let mut dx: libc::c_double = 0.; let mut dy: libc::c_double = 0.; let mut dz: libc::c_double = 0.; ph1 -= ph2; ph1 *= 3.1415926536f64 / 180 as libc::c_int as libc::c_double; th1 *= 3.1415926536f64 / 180 as libc::c_int as libc::c_double; th2 *= 3.1415926536f64 / 180 as libc::c_int as libc::c_double; dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy = sin(ph1) * cos(th1); return asin(sqrt(dx * dx + dy * dy + dz * dz) / 2 as libc::c_int as libc::c_double) * 2 as libc::c_int as libc::c_double * 6371 as libc::c_int as libc::c_double; }" }, { "index": 97, "before": "int add(int a, int b) { return a + b; }", "after": "pub unsafe extern \"C\" fn add(mut a: libc::c_int, mut b: libc::c_int) -> libc::c_int { return a + b; }" }, { "index": 98, "before": "int main(void) { int nums[] = {1, 2, 3, 4, 5}; printf(\"%d\\n\", reduce(add, 5, nums)); printf(\"%d\\n\", reduce(sub, 5, nums)); printf(\"%d\\n\", reduce(mul, 5, nums)); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut nums: [libc::c_int; 5] = [ 1 as libc::c_int, 2 as libc::c_int, 3 as libc::c_int, 4 as libc::c_int, 5 as libc::c_int, ]; printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, reduce( Some(add as unsafe extern \"C\" fn(libc::c_int, libc::c_int) -> libc::c_int), 5 as libc::c_int, nums.as_mut_ptr(), ), ); printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, reduce( Some(sub as unsafe extern \"C\" fn(libc::c_int, libc::c_int) -> libc::c_int), 5 as libc::c_int, nums.as_mut_ptr(), ), ); printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, reduce( Some(mul as unsafe extern \"C\" fn(libc::c_int, libc::c_int) -> libc::c_int), 5 as libc::c_int, nums.as_mut_ptr(), ), ); return 0 as libc::c_int; }" }, { "index": 99, "before": "int sub(int a, int b) { return a - b; }", "after": "pub unsafe extern \"C\" fn sub(mut a: libc::c_int, mut b: libc::c_int) -> libc::c_int { return a - b; }" }, { "index": 100, "before": "int mul(int a, int b) { return a * b; }", "after": "pub unsafe extern \"C\" fn mul(mut a: libc::c_int, mut b: libc::c_int) -> libc::c_int { return a * b; }" }, { "index": 101, "before": "int main() { \tint user_action, my_action; \tint user_rec[] = {0, 0, 0}; \tconst char *names[] = { \"Rock\", \"Paper\", \"Scissors\" }; \tchar str[2]; \tconst char *winner[] = { \"We tied.\", \"Meself winned.\", \"You win.\" }; \tdouble p[LEN] = { 1./3, 1./3, 1./3 }; \twhile (1) { \t\tmy_action = rand_idx(p,LEN); \t\tprintf(\"\\nYour choice [1-3]:\\n\" \t\t\t\" 1. Rock\\n 2. Paper\\n 3. Scissors\\n> \"); \t\t/* scanf is a terrible way to do input. should use stty and keystrokes */ \t\tif (!scanf(\"%d\", &user_action)) { \t\t\tscanf(\"%1s\", str); \t\t\tif (*str == 'q') { \t\t\t\tprintf(\"Your choices [rock : %d , paper : %d , scissors %d] \",user_rec[0],user_rec[1], user_rec[2]); \t\t\t\treturn 0; \t\t\t} \t\t\tcontinue; \t\t} \t\tuser_action --; \t\tif (user_action > 2 || user_action < 0) { \t\t\tprintf(\"invalid choice; again\\n\"); \t\t\tcontinue; \t\t} \t\tprintf(\"You chose %s; I chose %s. %s\\n\", \t\t\tnames[user_action], names[my_action], \t\t\twinner[(my_action - user_action + 3) % 3]); \t\tuser_rec[user_action]++; \t} }", "after": "unsafe fn main() -> libc::c_int { let mut user_action: libc::c_int = 0; let mut my_action: libc::c_int = 0; let mut user_rec: [libc::c_int; 3] = [ 0 as libc::c_int, 0 as libc::c_int, 0 as libc::c_int, ]; let mut names: [*const libc::c_char; 3] = [ b\"Rock\\0\" as *const u8 as *const libc::c_char, b\"Paper\\0\" as *const u8 as *const libc::c_char, b\"Scissors\\0\" as *const u8 as *const libc::c_char, ]; let mut str: [libc::c_char; 2] = [0; 2]; let mut winner: [*const libc::c_char; 3] = [ b\"We tied.\\0\" as *const u8 as *const libc::c_char, b\"Meself winned.\\0\" as *const u8 as *const libc::c_char, b\"You win.\\0\" as *const u8 as *const libc::c_char, ]; let mut p: [libc::c_double; 3] = [ 1.0f64 / 3 as libc::c_int as libc::c_double, 1.0f64 / 3 as libc::c_int as libc::c_double, 1.0f64 / 3 as libc::c_int as libc::c_double, ]; loop { my_action = rand_idx(p.as_mut_ptr(), 3 as libc::c_int); printf( b\"\\nYour choice [1-3]:\\n 1. Rock\\n 2. Paper\\n 3. Scissors\\n> \\0\" as *const u8 as *const libc::c_char, ); if scanf( b\"%d\\0\" as *const u8 as *const libc::c_char, &mut user_action as *mut libc::c_int, ) == 0 { scanf(b\"%1s\\0\" as *const u8 as *const libc::c_char, str.as_mut_ptr()); if *str.as_mut_ptr() as libc::c_int == 'q' as i32 { printf( b\"Your choices [rock : %d , paper : %d , scissors %d] \\0\" as *const u8 as *const libc::c_char, user_rec[0 as libc::c_int as usize], user_rec[1 as libc::c_int as usize], user_rec[2 as libc::c_int as usize], ); return 0 as libc::c_int; } } else { user_action -= 1; user_action; if user_action > 2 as libc::c_int || user_action < 0 as libc::c_int { printf(b\"invalid choice; again\\n\\0\" as *const u8 as *const libc::c_char); } else { printf( b\"You chose %s; I chose %s. %s\\n\\0\" as *const u8 as *const libc::c_char, names[user_action as usize], names[my_action as usize], winner[((my_action - user_action + 3 as libc::c_int) % 3 as libc::c_int) as usize], ); user_rec[user_action as usize] += 1; user_rec[user_action as usize]; } } }; }" }, { "index": 102, "before": "int rand_idx(double *p, int n) { \tdouble s = rand() / (RAND_MAX + 1.0); \tint i; \tfor (i = 0; i < n - 1 && (s -= p[i]) >= 0; i++); \treturn i; }", "after": "pub unsafe extern \"C\" fn rand_idx( mut p: *mut libc::c_double, mut n: libc::c_int, ) -> libc::c_int { let mut s: libc::c_double = rand() as libc::c_double / (2147483647 as libc::c_int as libc::c_double + 1.0f64); let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < n - 1 as libc::c_int && { s -= *p.offset(i as isize); s >= 0 as libc::c_int as libc::c_double } { i += 1; i; } return i; }" }, { "index": 103, "before": "int main() { int array[] = { 1, 2, 3, 4 }; map(array, 4, callbackFunction); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut array: [libc::c_int; 4] = [ 1 as libc::c_int, 2 as libc::c_int, 3 as libc::c_int, 4 as libc::c_int, ]; map( array.as_mut_ptr(), 4 as libc::c_int, Some(callbackFunction as unsafe extern \"C\" fn(libc::c_int, libc::c_int) -> ()), ); return 0 as libc::c_int; }" }, { "index": 104, "before": "static void callbackFunction(int location, int value) { printf(\"array[%d] = %d\\n\", location, value); }", "after": "unsafe extern \"C\" fn callbackFunction( mut location: libc::c_int, mut value: libc::c_int, ) { printf(b\"array[%d] = %d\\n\\0\" as *const u8 as *const libc::c_char, location, value); }" }, { "index": 105, "before": "void output(stream out, unsigned char* buf, int len) { \tint i; \tout->put(out, 128 + len); \tfor (i = 0; i < len; i++) \t\tout->put(out, buf[i]); }", "after": "pub unsafe extern \"C\" fn output( mut out: stream, mut buf: *mut libc::c_uchar, mut len: libc::c_int, ) { let mut i: libc::c_int = 0; ((*out).put).expect(\"non-null function pointer\")(out, 128 as libc::c_int + len); i = 0 as libc::c_int; while i < len { ((*out).put) .expect( \"non-null function pointer\", )(out, *buf.offset(i as isize) as libc::c_int); i += 1; i; } }" }, { "index": 106, "before": "void encode(stream in, stream out) { \tunsigned char buf[256]; \tint len = 0, repeat = 0, end = 0, c; \tint (*get)(stream) = in->get; \tint (*put)(stream, int) = out->put; \twhile (!end) { \t\tend = ((c = get(in)) == -1); \t\tif (!end) { \t\t\tbuf[len++] = c; \t\t\tif (len <= 1) continue; \t\t} \t\tif (repeat) { \t\t\tif (buf[len - 1] != buf[len - 2]) \t\t\t\trepeat = 0; \t\t\tif (!repeat || len == 129 || end) { \t\t\t\t/* write out repeating bytes */ \t\t\t\tput(out, end ? len : len - 1); \t\t\t\tput(out, buf[0]); \t\t\t\tbuf[0] = buf[len - 1]; \t\t\t\tlen = 1; \t\t\t} \t\t} else { \t\t\tif (buf[len - 1] == buf[len - 2]) { \t\t\t\trepeat = 1; \t\t\t\tif (len > 2) { \t\t\t\t\toutput(out, buf, len - 2); \t\t\t\t\tbuf[0] = buf[1] = buf[len - 1]; \t\t\t\t\tlen = 2; \t\t\t\t} \t\t\t\tcontinue; \t\t\t} \t\t\tif (len == 128 || end) { \t\t\t\toutput(out, buf, len); \t\t\t\tlen = 0; \t\t\t\trepeat = 0; \t\t\t} \t\t} \t} \tput(out, -1); }", "after": "pub unsafe extern \"C\" fn encode(mut in_0: stream, mut out: stream) { let mut buf: [libc::c_uchar; 256] = [0; 256]; let mut len: libc::c_int = 0 as libc::c_int; let mut repeat: libc::c_int = 0 as libc::c_int; let mut end: libc::c_int = 0 as libc::c_int; let mut c: libc::c_int = 0; let mut get: Option:: libc::c_int> = (*in_0).get; let mut put: Option:: libc::c_int> = (*out) .put; while end == 0 { c = get.expect(\"non-null function pointer\")(in_0); end = (c == -(1 as libc::c_int)) as libc::c_int; if end == 0 { let fresh1 = len; len = len + 1; buf[fresh1 as usize] = c as libc::c_uchar; if len <= 1 as libc::c_int { continue; } } if repeat != 0 { if buf[(len - 1 as libc::c_int) as usize] as libc::c_int != buf[(len - 2 as libc::c_int) as usize] as libc::c_int { repeat = 0 as libc::c_int; } if repeat == 0 || len == 129 as libc::c_int || end != 0 { put .expect( \"non-null function pointer\", )(out, if end != 0 { len } else { len - 1 as libc::c_int }); put .expect( \"non-null function pointer\", )(out, buf[0 as libc::c_int as usize] as libc::c_int); buf[0 as libc::c_int as usize] = buf[(len - 1 as libc::c_int) as usize]; len = 1 as libc::c_int; } } else if buf[(len - 1 as libc::c_int) as usize] as libc::c_int == buf[(len - 2 as libc::c_int) as usize] as libc::c_int { repeat = 1 as libc::c_int; if len > 2 as libc::c_int { output(out, buf.as_mut_ptr(), len - 2 as libc::c_int); buf[1 as libc::c_int as usize] = buf[(len - 1 as libc::c_int) as usize]; buf[0 as libc::c_int as usize] = buf[1 as libc::c_int as usize]; len = 2 as libc::c_int; } } else if len == 128 as libc::c_int || end != 0 { output(out, buf.as_mut_ptr(), len); len = 0 as libc::c_int; repeat = 0 as libc::c_int; } } put.expect(\"non-null function pointer\")(out, -(1 as libc::c_int)); }" }, { "index": 107, "before": "int sget(stream in) { \tint c; \tstring_stream* s = (string_stream*) in; \tc = (unsigned char)(s->string[s->pos]); \tif (c == '\\0') return -1; \ts->pos++; \treturn c; }", "after": "pub unsafe extern \"C\" fn sget(mut in_0: stream) -> libc::c_int { let mut c: libc::c_int = 0; let mut s: *mut string_stream = in_0 as *mut string_stream; c = *((*s).string).offset((*s).pos as isize) as libc::c_uchar as libc::c_int; if c == '\\0' as i32 { return -(1 as libc::c_int); } (*s).pos += 1; (*s).pos; return c; }" }, { "index": 108, "before": "int file_put(stream out, int c) { \tfile_stream *f = (file_stream*) out; \treturn fputc(c, f->fp); }", "after": "pub unsafe extern \"C\" fn file_put(mut out: stream, mut c: libc::c_int) -> libc::c_int { let mut f: *mut file_stream = out as *mut file_stream; return fputc(c, (*f).fp); }" }, { "index": 109, "before": "int main() { \tchar buf[256]; \tstring_stream str_in = { sget, 0, \t\t\"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW\", 0}; \tstring_stream str_out = { sget, sput, buf, 0 }; \tfile_stream file = { 0, file_put, stdout }; \t/* encode from str_in to str_out */ \tencode((stream)&str_in, (stream)&str_out); \t/* decode from str_out to file (stdout) */ \tdecode((stream)&str_out, (stream)&file); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut buf: [libc::c_char; 256] = [0; 256]; let mut str_in: string_stream = { let mut init = string_stream { get: Some(sget as unsafe extern \"C\" fn(stream) -> libc::c_int), put: None, string: b\"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, pos: 0 as libc::c_int, }; init }; let mut str_out: string_stream = { let mut init = string_stream { get: Some(sget as unsafe extern \"C\" fn(stream) -> libc::c_int), put: Some(sput as unsafe extern \"C\" fn(stream, libc::c_int) -> libc::c_int), string: buf.as_mut_ptr(), pos: 0 as libc::c_int, }; init }; let mut file: file_stream = { let mut init = file_stream { get: None, put: Some( file_put as unsafe extern \"C\" fn(stream, libc::c_int) -> libc::c_int, ), fp: stdout, }; init }; encode( &mut str_in as *mut string_stream as stream, &mut str_out as *mut string_stream as stream, ); decode( &mut str_out as *mut string_stream as stream, &mut file as *mut file_stream as stream, ); return 0 as libc::c_int; }" }, { "index": 110, "before": "int sput(stream out, int c) { \tstring_stream* s = (string_stream*) out; \ts->string[s->pos++] = (c == -1) ? '\\0' : c; \tif (c == -1) s->pos = 0; \treturn 0; }", "after": "pub unsafe extern \"C\" fn sput(mut out: stream, mut c: libc::c_int) -> libc::c_int { let mut s: *mut string_stream = out as *mut string_stream; let fresh0 = (*s).pos; (*s).pos = (*s).pos + 1; *((*s).string) .offset( fresh0 as isize, ) = (if c == -(1 as libc::c_int) { '\\0' as i32 } else { c }) as libc::c_char; if c == -(1 as libc::c_int) { (*s).pos = 0 as libc::c_int; } return 0 as libc::c_int; }" }, { "index": 111, "before": "void decode(stream in, stream out) { \tint c, i, cnt; \twhile (1) { \t\tc = in->get(in); \t\tif (c == -1) return; \t\tif (c > 128) { \t\t\tcnt = c - 128; \t\t\tfor (i = 0; i < cnt; i++) \t\t\t\tout->put(out, in->get(in)); \t\t} else { \t\t\tcnt = c; \t\t\tc = in->get(in); \t\t\tfor (i = 0; i < cnt; i++) \t\t\t\tout->put(out, c); \t\t} \t} }", "after": "pub unsafe extern \"C\" fn decode(mut in_0: stream, mut out: stream) { let mut c: libc::c_int = 0; let mut i: libc::c_int = 0; let mut cnt: libc::c_int = 0; loop { c = ((*in_0).get).expect(\"non-null function pointer\")(in_0); if c == -(1 as libc::c_int) { return; } if c > 128 as libc::c_int { cnt = c - 128 as libc::c_int; i = 0 as libc::c_int; while i < cnt { ((*out).put) .expect( \"non-null function pointer\", )(out, ((*in_0).get).expect(\"non-null function pointer\")(in_0)); i += 1; i; } } else { cnt = c; c = ((*in_0).get).expect(\"non-null function pointer\")(in_0); i = 0 as libc::c_int; while i < cnt { ((*out).put).expect(\"non-null function pointer\")(out, c); i += 1; i; } } }; }" }, { "index": 112, "before": "void printout(char *balls){ \tint i; \tchar str[NUMBALLS+1]; \tfor(i=0;istate)state=balls[i]; \t} \treturn true; }", "after": "pub unsafe extern \"C\" fn issorted(mut balls: *mut libc::c_char) -> bool { let mut i: libc::c_int = 0; let mut state: libc::c_int = 0; state = 0 as libc::c_int; i = 0 as libc::c_int; while i < 5 as libc::c_int { if (*balls.offset(i as isize) as libc::c_int) < state { return 0 as libc::c_int != 0; } if *balls.offset(i as isize) as libc::c_int > state { state = *balls.offset(i as isize) as libc::c_int; } i += 1; i; } return 1 as libc::c_int != 0; }" }, { "index": 114, "before": "int main(void) { \tchar balls[NUMBALLS]; //0=r, 1=w, 2=b \tint i; \tsrand(time(NULL)); //not a good seed but good enough for the example \trand(); //rand() always starts with the same values for certain seeds, making \t // testing pretty irritating \t// Generate balls \tfor(i=0;i libc::c_int { let mut balls: [libc::c_char; 5] = [0; 5]; let mut i: libc::c_int = 0; srand(time(0 as *mut time_t) as libc::c_uint); rand(); i = 0 as libc::c_int; while i < 5 as libc::c_int { balls[i as usize] = (rand() as libc::c_double / 2147483647 as libc::c_int as libc::c_double * 3 as libc::c_int as libc::c_double) as libc::c_char; i += 1; i; } while issorted(balls.as_mut_ptr()) { printf(b\"Accidentally still sorted: \\0\" as *const u8 as *const libc::c_char); printout(balls.as_mut_ptr()); i = 0 as libc::c_int; while i < 5 as libc::c_int { balls[i as usize] = (rand() as libc::c_double / 2147483647 as libc::c_int as libc::c_double * 3 as libc::c_int as libc::c_double) as libc::c_char; i += 1; i; } } printf(b\"Non-sorted: \\0\" as *const u8 as *const libc::c_char); printout(balls.as_mut_ptr()); qsort( balls.as_mut_ptr() as *mut libc::c_void, 5 as libc::c_int as size_t, ::core::mem::size_of::() as libc::c_ulong, Some( compar as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); if issorted(balls.as_mut_ptr()) { printf(b\"Sorted: \\0\" as *const u8 as *const libc::c_char); printout(balls.as_mut_ptr()); } else { printf(b\"Sort failed: \\0\" as *const u8 as *const libc::c_char); printout(balls.as_mut_ptr()); } return 0 as libc::c_int; }" }, { "index": 115, "before": "int main(int argc, char **argv) { int i,g,b; char bi[6],bg[6],bb[6]; for (i=0 ; i<32 ; i++) { \tg = gray_encode(i); \tb = gray_decode(g); \tfmtbool(i,bi); fmtbool(g,bg); fmtbool(b,bb); \tprintf(\"%2d : %5s => %5s => %5s : %2d\\n\", i, bi, bg, bb, b); } return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut g: libc::c_int = 0; let mut b: libc::c_int = 0; let mut bi: [libc::c_char; 6] = [0; 6]; let mut bg: [libc::c_char; 6] = [0; 6]; let mut bb: [libc::c_char; 6] = [0; 6]; i = 0 as libc::c_int; while i < 32 as libc::c_int { g = gray_encode(i); b = gray_decode(g); fmtbool(i, bi.as_mut_ptr()); fmtbool(g, bg.as_mut_ptr()); fmtbool(b, bb.as_mut_ptr()); printf( b\"%2d : %5s => %5s => %5s : %2d\\n\\0\" as *const u8 as *const libc::c_char, i, bi.as_mut_ptr(), bg.as_mut_ptr(), bb.as_mut_ptr(), b, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 116, "before": "int gray_encode(int n) { return n ^ (n >> 1); }", "after": "pub unsafe extern \"C\" fn gray_encode(mut n: libc::c_int) -> libc::c_int { return n ^ n >> 1 as libc::c_int; }" }, { "index": 117, "before": "int gray_decode(int n) { int p = n; while (n >>= 1) p ^= n; return p; }", "after": "pub unsafe extern \"C\" fn gray_decode(mut n: libc::c_int) -> libc::c_int { let mut p: libc::c_int = n; loop { n >>= 1 as libc::c_int; if !(n != 0) { break; } p ^= n; } return p; }" }, { "index": 118, "before": "void fmtbool(int n, char *buf) { char *b = buf + 5; *b=0; do { \t*--b = '0' + (n & 1); \tn >>= 1; } while (b != buf); }", "after": "pub unsafe extern \"C\" fn fmtbool(mut n: libc::c_int, mut buf: *mut libc::c_char) { let mut b: *mut libc::c_char = buf.offset(5 as libc::c_int as isize); *b = 0 as libc::c_int as libc::c_char; loop { b = b.offset(-1); *b = ('0' as i32 + (n & 1 as libc::c_int)) as libc::c_char; n >>= 1 as libc::c_int; if !(b != buf) { break; } }; }" }, { "index": 119, "before": "void quaternion_print(quaternion_t *q) { if (q == NULL) return; printf(\"(%lf, %lf, %lf, %lf)\\n\", \t q->q[0], q->q[1], q->q[2], q->q[3]); }", "after": "pub unsafe extern \"C\" fn quaternion_print(mut q: *mut quaternion_t) { if q.is_null() { return; } printf( b\"(%lf, %lf, %lf, %lf)\\n\\0\" as *const u8 as *const libc::c_char, (*q).q[0 as libc::c_int as usize], (*q).q[1 as libc::c_int as usize], (*q).q[2 as libc::c_int as usize], (*q).q[3 as libc::c_int as usize], ); }" }, { "index": 120, "before": "int main() { size_t i; double d = 7.0; quaternion_t *q[3]; quaternion_t *r = quaternion_new(); quaternion_t *qd = quaternion_new_set(7.0, 0.0, 0.0, 0.0); q[0] = quaternion_new_set(1.0, 2.0, 3.0, 4.0); q[1] = quaternion_new_set(2.0, 3.0, 4.0, 5.0); q[2] = quaternion_new_set(3.0, 4.0, 5.0, 6.0); printf(\"r = %lf\\n\", d); for(i = 0; i < 3; i++) { printf(\"q[%u] = \", i); quaternion_print(q[i]); printf(\"abs q[%u] = %lf\\n\", i, quaternion_norm(q[i])); } printf(\"-q[0] = \"); quaternion_neg(r, q[0]); quaternion_print(r); printf(\"conj q[0] = \"); quaternion_conj(r, q[0]); quaternion_print(r); printf(\"q[1] + q[2] = \"); quaternion_add(r, q[1], q[2]); quaternion_print(r); printf(\"q[2] + q[1] = \"); quaternion_add(r, q[2], q[1]); quaternion_print(r); printf(\"q[0] * r = \"); quaternion_mul_d(r, q[0], d); quaternion_print(r); printf(\"q[0] * (r, 0, 0, 0) = \"); quaternion_mul(r, q[0], qd); quaternion_print(r); printf(\"q[1] * q[2] = \"); quaternion_mul(r, q[1], q[2]); quaternion_print(r); printf(\"q[2] * q[1] = \"); quaternion_mul(r, q[2], q[1]); quaternion_print(r); free(q[0]); free(q[1]); free(q[2]); free(r); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut i: size_t = 0; let mut d: libc::c_double = 7.0f64; let mut q: [*mut quaternion_t; 3] = [0 as *mut quaternion_t; 3]; let mut r: *mut quaternion_t = quaternion_new(); let mut qd: *mut quaternion_t = quaternion_new_set(7.0f64, 0.0f64, 0.0f64, 0.0f64); q[0 as libc::c_int as usize] = quaternion_new_set(1.0f64, 2.0f64, 3.0f64, 4.0f64); q[1 as libc::c_int as usize] = quaternion_new_set(2.0f64, 3.0f64, 4.0f64, 5.0f64); q[2 as libc::c_int as usize] = quaternion_new_set(3.0f64, 4.0f64, 5.0f64, 6.0f64); printf(b\"r = %lf\\n\\0\" as *const u8 as *const libc::c_char, d); i = 0 as libc::c_int as size_t; while i < 3 as libc::c_int as libc::c_ulong { printf(b\"q[%u] = \\0\" as *const u8 as *const libc::c_char, i); quaternion_print(q[i as usize]); printf( b\"abs q[%u] = %lf\\n\\0\" as *const u8 as *const libc::c_char, i, quaternion_norm(q[i as usize]), ); i = i.wrapping_add(1); i; } printf(b\"-q[0] = \\0\" as *const u8 as *const libc::c_char); quaternion_neg(r, q[0 as libc::c_int as usize]); quaternion_print(r); printf(b\"conj q[0] = \\0\" as *const u8 as *const libc::c_char); quaternion_conj(r, q[0 as libc::c_int as usize]); quaternion_print(r); printf(b\"q[1] + q[2] = \\0\" as *const u8 as *const libc::c_char); quaternion_add(r, q[1 as libc::c_int as usize], q[2 as libc::c_int as usize]); quaternion_print(r); printf(b\"q[2] + q[1] = \\0\" as *const u8 as *const libc::c_char); quaternion_add(r, q[2 as libc::c_int as usize], q[1 as libc::c_int as usize]); quaternion_print(r); printf(b\"q[0] * r = \\0\" as *const u8 as *const libc::c_char); quaternion_mul_d(r, q[0 as libc::c_int as usize], d); quaternion_print(r); printf(b\"q[0] * (r, 0, 0, 0) = \\0\" as *const u8 as *const libc::c_char); quaternion_mul(r, q[0 as libc::c_int as usize], qd); quaternion_print(r); printf(b\"q[1] * q[2] = \\0\" as *const u8 as *const libc::c_char); quaternion_mul(r, q[1 as libc::c_int as usize], q[2 as libc::c_int as usize]); quaternion_print(r); printf(b\"q[2] * q[1] = \\0\" as *const u8 as *const libc::c_char); quaternion_mul(r, q[2 as libc::c_int as usize], q[1 as libc::c_int as usize]); quaternion_print(r); free(q[0 as libc::c_int as usize] as *mut libc::c_void); free(q[1 as libc::c_int as usize] as *mut libc::c_void); free(q[2 as libc::c_int as usize] as *mut libc::c_void); free(r as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 121, "before": "double quaternion_norm(quaternion_t *q) { size_t i; double r = 0.0; if (q == NULL) { fprintf(stderr, \"NULL quaternion in norm\\n\"); return 0.0; } for(i = 0; i < 4; i++) r += q->q[i] * q->q[i]; return sqrt(r); }", "after": "pub unsafe extern \"C\" fn quaternion_norm(mut q: *mut quaternion_t) -> libc::c_double { let mut i: size_t = 0; let mut r: libc::c_double = 0.0f64; if q.is_null() { fprintf( stderr, b\"NULL quaternion in norm\\n\\0\" as *const u8 as *const libc::c_char, ); return 0.0f64; } i = 0 as libc::c_int as size_t; while i < 4 as libc::c_int as libc::c_ulong { r += (*q).q[i as usize] * (*q).q[i as usize]; i = i.wrapping_add(1); i; } return sqrt(r); }" }, { "index": 122, "before": "void quaternion_conj(quaternion_t *r, quaternion_t *q) { size_t i; if (q == NULL || r == NULL) return; r->q[0] = q->q[0]; for(i = 1; i < 4; i++) r->q[i] = -q->q[i]; }", "after": "pub unsafe extern \"C\" fn quaternion_conj( mut r: *mut quaternion_t, mut q: *mut quaternion_t, ) { let mut i: size_t = 0; if q.is_null() || r.is_null() { return; } (*r).q[0 as libc::c_int as usize] = (*q).q[0 as libc::c_int as usize]; i = 1 as libc::c_int as size_t; while i < 4 as libc::c_int as libc::c_ulong { (*r).q[i as usize] = -(*q).q[i as usize]; i = i.wrapping_add(1); i; } }" }, { "index": 123, "before": "void quaternion_add_d(quaternion_t *r, quaternion_t *q, double d) { if (q == NULL || r == NULL) return; quaternion_copy(r, q); r->q[0] += d; }", "after": "pub unsafe extern \"C\" fn quaternion_add_d( mut r: *mut quaternion_t, mut q: *mut quaternion_t, mut d: libc::c_double, ) { if q.is_null() || r.is_null() { return; } quaternion_copy(r, q); (*r).q[0 as libc::c_int as usize] += d; }" }, { "index": 124, "before": "void quaternion_add(quaternion_t *r, quaternion_t *a, quaternion_t *b) { size_t i; if (r == NULL || a == NULL || b == NULL) return; for(i = 0; i < 4; i++) r->q[i] = a->q[i] + b->q[i]; }", "after": "pub unsafe extern \"C\" fn quaternion_add( mut r: *mut quaternion_t, mut a: *mut quaternion_t, mut b: *mut quaternion_t, ) { let mut i: size_t = 0; if r.is_null() || a.is_null() || b.is_null() { return; } i = 0 as libc::c_int as size_t; while i < 4 as libc::c_int as libc::c_ulong { (*r).q[i as usize] = (*a).q[i as usize] + (*b).q[i as usize]; i = i.wrapping_add(1); i; } }" }, { "index": 125, "before": "void quaternion_mul_d(quaternion_t *r, quaternion_t *q, double d) { size_t i; if (r == NULL || q == NULL) return; for(i = 0; i < 4; i++) r->q[i] = q->q[i] * d; }", "after": "pub unsafe extern \"C\" fn quaternion_mul_d( mut r: *mut quaternion_t, mut q: *mut quaternion_t, mut d: libc::c_double, ) { let mut i: size_t = 0; if r.is_null() || q.is_null() { return; } i = 0 as libc::c_int as size_t; while i < 4 as libc::c_int as libc::c_ulong { (*r).q[i as usize] = (*q).q[i as usize] * d; i = i.wrapping_add(1); i; } }" }, { "index": 126, "before": "void quaternion_neg(quaternion_t *r, quaternion_t *q) { size_t i; if (q == NULL || r == NULL) return; for(i = 0; i < 4; i++) r->q[i] = -q->q[i]; }", "after": "pub unsafe extern \"C\" fn quaternion_neg( mut r: *mut quaternion_t, mut q: *mut quaternion_t, ) { let mut i: size_t = 0; if q.is_null() || r.is_null() { return; } i = 0 as libc::c_int as size_t; while i < 4 as libc::c_int as libc::c_ulong { (*r).q[i as usize] = -(*q).q[i as usize]; i = i.wrapping_add(1); i; } }" }, { "index": 127, "before": "bool quaternion_equal(quaternion_t *a, quaternion_t *b) { size_t i; for(i = 0; i < 4; i++) if (a->q[i] != b->q[i]) return false; return true; }", "after": "pub unsafe extern \"C\" fn quaternion_equal( mut a: *mut quaternion_t, mut b: *mut quaternion_t, ) -> bool { let mut i: size_t = 0; i = 0 as libc::c_int as size_t; while i < 4 as libc::c_int as libc::c_ulong { if (*a).q[i as usize] != (*b).q[i as usize] { return 0 as libc::c_int != 0; } i = i.wrapping_add(1); i; } return 1 as libc::c_int != 0; }" }, { "index": 128, "before": "void quaternion_mul(quaternion_t *r, quaternion_t *a, quaternion_t *b) { size_t i; double ri = 0.0; if (r == NULL || a == NULL || b == NULL) return; R(0) = A(0)*B(0) - A(1)*B(1) - A(2)*B(2) - A(3)*B(3); R(1) = A(0)*B(1) + A(1)*B(0) + A(2)*B(3) - A(3)*B(2); R(2) = A(0)*B(2) - A(1)*B(3) + A(2)*B(0) + A(3)*B(1); R(3) = A(0)*B(3) + A(1)*B(2) - A(2)*B(1) + A(3)*B(0); }", "after": "pub unsafe extern \"C\" fn quaternion_mul( mut r: *mut quaternion_t, mut a: *mut quaternion_t, mut b: *mut quaternion_t, ) { let mut i: size_t = 0; let mut ri: libc::c_double = 0.0f64; if r.is_null() || a.is_null() || b.is_null() { return; } (*r) .q[0 as libc::c_int as usize] = (*a).q[0 as libc::c_int as usize] * (*b).q[0 as libc::c_int as usize] - (*a).q[1 as libc::c_int as usize] * (*b).q[1 as libc::c_int as usize] - (*a).q[2 as libc::c_int as usize] * (*b).q[2 as libc::c_int as usize] - (*a).q[3 as libc::c_int as usize] * (*b).q[3 as libc::c_int as usize]; (*r) .q[1 as libc::c_int as usize] = (*a).q[0 as libc::c_int as usize] * (*b).q[1 as libc::c_int as usize] + (*a).q[1 as libc::c_int as usize] * (*b).q[0 as libc::c_int as usize] + (*a).q[2 as libc::c_int as usize] * (*b).q[3 as libc::c_int as usize] - (*a).q[3 as libc::c_int as usize] * (*b).q[2 as libc::c_int as usize]; (*r) .q[2 as libc::c_int as usize] = (*a).q[0 as libc::c_int as usize] * (*b).q[2 as libc::c_int as usize] - (*a).q[1 as libc::c_int as usize] * (*b).q[3 as libc::c_int as usize] + (*a).q[2 as libc::c_int as usize] * (*b).q[0 as libc::c_int as usize] + (*a).q[3 as libc::c_int as usize] * (*b).q[1 as libc::c_int as usize]; (*r) .q[3 as libc::c_int as usize] = (*a).q[0 as libc::c_int as usize] * (*b).q[3 as libc::c_int as usize] + (*a).q[1 as libc::c_int as usize] * (*b).q[2 as libc::c_int as usize] - (*a).q[2 as libc::c_int as usize] * (*b).q[1 as libc::c_int as usize] + (*a).q[3 as libc::c_int as usize] * (*b).q[0 as libc::c_int as usize]; }" }, { "index": 129, "before": "void quaternion_copy(quaternion_t *r, quaternion_t *q) { size_t i; if (r == NULL || q == NULL) return; for(i = 0; i < 4; i++) r->q[i] = q->q[i]; }", "after": "pub unsafe extern \"C\" fn quaternion_copy( mut r: *mut quaternion_t, mut q: *mut quaternion_t, ) { let mut i: size_t = 0; if r.is_null() || q.is_null() { return; } i = 0 as libc::c_int as size_t; while i < 4 as libc::c_int as libc::c_ulong { (*r).q[i as usize] = (*q).q[i as usize]; i = i.wrapping_add(1); i; } }" }, { "index": 130, "before": "void initialize(int prisoners){ \tint i,j,card; \tbool unique; \tdrawerSet = ((drawer*)malloc(prisoners * sizeof(drawer))) -1; \tcard = rand()%prisoners + 1; \tdrawerSet[1] = (drawer){.cardNum = card, .hasBeenOpened = false}; \tfor(i=1 + 1;i() as libc::c_ulong), ) as *mut drawer) .offset(-(1 as libc::c_int as isize)); card = rand() % prisoners + 1 as libc::c_int; *drawerSet .offset( 1 as libc::c_int as isize, ) = { let mut init = drawer { cardNum: card, hasBeenOpened: 0 as libc::c_int != 0, }; init }; i = 1 as libc::c_int + 1 as libc::c_int; while i < prisoners + 1 as libc::c_int { unique = 0 as libc::c_int != 0; while unique as libc::c_int == 0 as libc::c_int { j = 0 as libc::c_int; while j < i { if (*drawerSet.offset(j as isize)).cardNum == card { card = rand() % prisoners + 1 as libc::c_int; break; } else { j += 1; j; } } if j == i { unique = 1 as libc::c_int != 0; } } *drawerSet .offset( i as isize, ) = { let mut init = drawer { cardNum: card, hasBeenOpened: 0 as libc::c_int != 0, }; init }; i += 1; i; } }" }, { "index": 131, "before": "bool libertyOrDeathAtRandom(int prisoners,int chances){ \tint i,j,chosenDrawer; \tfor(i= 1;i bool { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut chosenDrawer: libc::c_int = 0; i = 1 as libc::c_int; while i < prisoners + 1 as libc::c_int { let mut foundCard: bool = 0 as libc::c_int != 0; j = 0 as libc::c_int; while j < chances { loop { chosenDrawer = rand() % prisoners + 1 as libc::c_int; if !((*drawerSet.offset(chosenDrawer as isize)).hasBeenOpened as libc::c_int == 1 as libc::c_int) { break; } } if (*drawerSet.offset(chosenDrawer as isize)).cardNum == i { foundCard = 1 as libc::c_int != 0; break; } else { (*drawerSet.offset(chosenDrawer as isize)) .hasBeenOpened = 1 as libc::c_int != 0; j += 1; j; } } closeAllDrawers(prisoners); if foundCard as libc::c_int == 0 as libc::c_int { return 1 as libc::c_int != 0; } i += 1; i; } return 0 as libc::c_int != 0; }" }, { "index": 132, "before": "bool libertyOrDeathPlanned(int prisoners,int chances){ \tint i,j,chosenDrawer; \tfor(i=1;i bool { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut chosenDrawer: libc::c_int = 0; i = 1 as libc::c_int; while i < prisoners + 1 as libc::c_int { chosenDrawer = i; let mut foundCard: bool = 0 as libc::c_int != 0; j = 0 as libc::c_int; while j < chances { (*drawerSet.offset(chosenDrawer as isize)) .hasBeenOpened = 1 as libc::c_int != 0; if (*drawerSet.offset(chosenDrawer as isize)).cardNum == i { foundCard = 1 as libc::c_int != 0; break; } else { if chosenDrawer == (*drawerSet.offset(chosenDrawer as isize)).cardNum { loop { chosenDrawer = rand() % prisoners + 1 as libc::c_int; if !((*drawerSet.offset(chosenDrawer as isize)).hasBeenOpened as libc::c_int == 1 as libc::c_int) { break; } } } else { chosenDrawer = (*drawerSet.offset(chosenDrawer as isize)).cardNum; } j += 1; j; } } closeAllDrawers(prisoners); if foundCard as libc::c_int == 0 as libc::c_int { return 1 as libc::c_int != 0; } i += 1; i; } return 0 as libc::c_int != 0; }" }, { "index": 133, "before": "void closeAllDrawers(int prisoners){ \tint i; \tfor(i=1;i \",argv[0]); \tprisoners = atoi(argv[1]); \tchances = atoi(argv[2]); \ttrials = strtoull(argv[3],&end,10); \tsrand(time(NULL)); \tprintf(\"Running random trials...\"); \tfor(i=0;i libc::c_int { let mut prisoners: libc::c_int = 0; let mut chances: libc::c_int = 0; let mut trials: libc::c_ulonglong = 0; let mut i: libc::c_ulonglong = 0; let mut count: libc::c_ulonglong = 0 as libc::c_int as libc::c_ulonglong; let mut end: *mut libc::c_char = 0 as *mut libc::c_char; if argc != 4 as libc::c_int { return printf( b\"Usage : %s \\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); } prisoners = atoi(*argv.offset(1 as libc::c_int as isize)); chances = atoi(*argv.offset(2 as libc::c_int as isize)); trials = strtoull( *argv.offset(3 as libc::c_int as isize), &mut end, 10 as libc::c_int, ); srand(time(0 as *mut time_t) as libc::c_uint); printf(b\"Running random trials...\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int as libc::c_ulonglong; while i < trials { initialize(prisoners); count = count .wrapping_add( (if libertyOrDeathAtRandom(prisoners, chances) as libc::c_int == 1 as libc::c_int { 0 as libc::c_int } else { 1 as libc::c_int }) as libc::c_ulonglong, ); i = i.wrapping_add(1 as libc::c_long as libc::c_ulonglong); } printf( b\"\\n\\nGames Played : %llu\\nGames Won : %llu\\nChances : %lf %% \\n\\n\\0\" as *const u8 as *const libc::c_char, trials, count, 100.0f64 * count as libc::c_double / trials as libc::c_double, ); count = 0 as libc::c_int as libc::c_ulonglong; printf(b\"Running strategic trials...\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int as libc::c_ulonglong; while i < trials { initialize(prisoners); count = count .wrapping_add( (if libertyOrDeathPlanned(prisoners, chances) as libc::c_int == 1 as libc::c_int { 0 as libc::c_int } else { 1 as libc::c_int }) as libc::c_ulonglong, ); i = i.wrapping_add(1 as libc::c_long as libc::c_ulonglong); } printf( b\"\\n\\nGames Played : %llu\\nGames Won : %llu\\nChances : %lf %% \\n\\n\\0\" as *const u8 as *const libc::c_char, trials, count, 100.0f64 * count as libc::c_double / trials as libc::c_double, ); return 0 as libc::c_int; }" }, { "index": 135, "before": "bool is_prime(ull n) { ull d; if (n < 2) return FALSE; if (!(n % 2)) return n == 2; if (!(n % 3)) return n == 3; d = 5; while (d * d <= n) { if (!(n % d)) return FALSE; d += 2; if (!(n % d)) return FALSE; d += 4; } return TRUE; }", "after": "pub unsafe extern \"C\" fn is_prime(mut n: ull) -> bool_0 { let mut d: ull = 0; if n < 2 as libc::c_int as libc::c_ulonglong { return 0 as libc::c_int; } if n.wrapping_rem(2 as libc::c_int as libc::c_ulonglong) == 0 { return (n == 2 as libc::c_int as libc::c_ulonglong) as libc::c_int; } if n.wrapping_rem(3 as libc::c_int as libc::c_ulonglong) == 0 { return (n == 3 as libc::c_int as libc::c_ulonglong) as libc::c_int; } d = 5 as libc::c_int as ull; while d.wrapping_mul(d) <= n { if n.wrapping_rem(d) == 0 { return 0 as libc::c_int; } d = (d as libc::c_ulonglong).wrapping_add(2 as libc::c_int as libc::c_ulonglong) as ull as ull; if n.wrapping_rem(d) == 0 { return 0 as libc::c_int; } d = (d as libc::c_ulonglong).wrapping_add(4 as libc::c_int as libc::c_ulonglong) as ull as ull; } return 1 as libc::c_int; }" }, { "index": 136, "before": "bool is_magnanimous(ull n) { ull p, q, r; if (n < 10) return TRUE; for (p = 10; ; p *= 10) { q = n / p; r = n % p; if (!is_prime(q + r)) return FALSE; if (q < 10) break; } return TRUE; }", "after": "pub unsafe extern \"C\" fn is_magnanimous(mut n: ull) -> bool_0 { let mut p: ull = 0; let mut q: ull = 0; let mut r: ull = 0; if n < 10 as libc::c_int as libc::c_ulonglong { return 1 as libc::c_int; } p = 10 as libc::c_int as ull; loop { q = n.wrapping_div(p); r = n.wrapping_rem(p); if is_prime(q.wrapping_add(r)) == 0 { return 0 as libc::c_int; } if q < 10 as libc::c_int as libc::c_ulonglong { break; } p = (p as libc::c_ulonglong).wrapping_mul(10 as libc::c_int as libc::c_ulonglong) as ull as ull; } return 1 as libc::c_int; }" }, { "index": 137, "before": "void list_mags(int from, int thru, int digs, int per_line) { ull i = 0; int c = 0; char res1[13], res2[13]; if (from < 2) { printf(\"\\nFirst %d magnanimous numbers:\\n\", thru); } else { ord(res1, from); ord(res2, thru); printf(\"\\n%s through %s magnanimous numbers:\\n\", res1, res2); } for ( ; c < thru; ++i) { if (is_magnanimous(i)) { if (++c >= from) { printf(\"%*llu \", digs, i); if (!(c % per_line)) printf(\"\\n\"); } } } }", "after": "pub unsafe extern \"C\" fn list_mags( mut from: libc::c_int, mut thru: libc::c_int, mut digs: libc::c_int, mut per_line: libc::c_int, ) { let mut i: ull = 0 as libc::c_int as ull; let mut c: libc::c_int = 0 as libc::c_int; let mut res1: [libc::c_char; 13] = [0; 13]; let mut res2: [libc::c_char; 13] = [0; 13]; if from < 2 as libc::c_int { printf( b\"\\nFirst %d magnanimous numbers:\\n\\0\" as *const u8 as *const libc::c_char, thru, ); } else { ord(res1.as_mut_ptr(), from); ord(res2.as_mut_ptr(), thru); printf( b\"\\n%s through %s magnanimous numbers:\\n\\0\" as *const u8 as *const libc::c_char, res1.as_mut_ptr(), res2.as_mut_ptr(), ); } while c < thru { if is_magnanimous(i) != 0 { c += 1; if c >= from { printf(b\"%*llu \\0\" as *const u8 as *const libc::c_char, digs, i); if c % per_line == 0 { printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); } } } i = i.wrapping_add(1); i; } }" }, { "index": 138, "before": "void ord(char *res, int n) { char suffix[3]; int m = n % 100; if (m >= 4 && m <= 20) { sprintf(res,\"%dth\", n); return; } switch(m % 10) { case 1: strcpy(suffix, \"st\"); break; case 2: strcpy(suffix, \"nd\"); break; case 3: strcpy(suffix, \"rd\"); break; default: strcpy(suffix, \"th\"); break; } sprintf(res, \"%d%s\", n, suffix); }", "after": "pub unsafe extern \"C\" fn ord(mut res: *mut libc::c_char, mut n: libc::c_int) { let mut suffix: [libc::c_char; 3] = [0; 3]; let mut m: libc::c_int = n % 100 as libc::c_int; if m >= 4 as libc::c_int && m <= 20 as libc::c_int { sprintf(res, b\"%dth\\0\" as *const u8 as *const libc::c_char, n); return; } match m % 10 as libc::c_int { 1 => { strcpy(suffix.as_mut_ptr(), b\"st\\0\" as *const u8 as *const libc::c_char); } 2 => { strcpy(suffix.as_mut_ptr(), b\"nd\\0\" as *const u8 as *const libc::c_char); } 3 => { strcpy(suffix.as_mut_ptr(), b\"rd\\0\" as *const u8 as *const libc::c_char); } _ => { strcpy(suffix.as_mut_ptr(), b\"th\\0\" as *const u8 as *const libc::c_char); } } sprintf(res, b\"%d%s\\0\" as *const u8 as *const libc::c_char, n, suffix.as_mut_ptr()); }" }, { "index": 139, "before": "int main() { list_mags(1, 45, 3, 15); list_mags(241, 250, 1, 10); list_mags(391, 400, 1, 10); return 0; }", "after": "unsafe fn main() -> libc::c_int { list_mags(1 as libc::c_int, 45 as libc::c_int, 3 as libc::c_int, 15 as libc::c_int); list_mags( 241 as libc::c_int, 250 as libc::c_int, 1 as libc::c_int, 10 as libc::c_int, ); list_mags( 391 as libc::c_int, 400 as libc::c_int, 1 as libc::c_int, 10 as libc::c_int, ); return 0 as libc::c_int; }" }, { "index": 140, "before": "int main() { int i; /* first 22 values (as a list) has no squares: */ for (i = 1; i < 23; i++) printf(\"%d \", nonsqr(i)); printf(\"\\n\"); /* The following check shows no squares up to one million: */ for (i = 1; i < 1000000; i++) { double j = sqrt(nonsqr(i)); assert(j != floor(j)); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; i = 1 as libc::c_int; while i < 23 as libc::c_int { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, nonsqr(i)); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i = 1 as libc::c_int; while i < 1000000 as libc::c_int { let mut j: libc::c_double = sqrt(nonsqr(i) as libc::c_double); if j != floor(j) {} else { __assert_fail( b\"j != floor(j)\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 21 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 11], &[libc::c_char; 11], >(b\"int main()\\0\")) .as_ptr(), ); } 'c_1861: { if j != floor(j) {} else { __assert_fail( b\"j != floor(j)\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 21 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 11], &[libc::c_char; 11], >(b\"int main()\\0\")) .as_ptr(), ); } }; i += 1; i; } return 0 as libc::c_int; }" }, { "index": 141, "before": "int nonsqr(int n) { return n + (int)(0.5 + sqrt(n)); /* return n + (int)round(sqrt(n)); in C99 */ }", "after": "pub unsafe extern \"C\" fn nonsqr(mut n: libc::c_int) -> libc::c_int { return n + (0.5f64 + sqrt(n as libc::c_double)) as libc::c_int; }" }, { "index": 142, "before": "int main() { struct test t = {1, 2, 3}; struct test h = {4, 5, 6}; double alfa = 0.45, omega = 9.98; struct test *pt = &t; struct test *th = &h; printf(\"%d %d %d\\n\", t.a, t.b, t.c); Swap(t, h); printf(\"%d %d %d\\n\", t.a, t.b, t.c); printf(\"%d %d %d\\n\", h.a, h.b, h.c); printf(\"%lf\\n\", alfa); Swap(alfa, omega); printf(\"%lf\\n\", alfa); printf(\"%d\\n\", pt->a); Swap(pt, th); printf(\"%d\\n\", pt->a); }", "after": "unsafe fn main() -> libc::c_int { let mut t: test = { let mut init = test { a: 1 as libc::c_int, b: 2 as libc::c_int, c: 3 as libc::c_int, }; init }; let mut h: test = { let mut init = test { a: 4 as libc::c_int, b: 5 as libc::c_int, c: 6 as libc::c_int, }; init }; let mut alfa: libc::c_double = 0.45f64; let mut omega: libc::c_double = 9.98f64; let mut pt: *mut test = &mut t; let mut th: *mut test = &mut h; printf(b\"%d %d %d\\n\\0\" as *const u8 as *const libc::c_char, t.a, t.b, t.c); let mut _T: test = t; t = h; h = _T; printf(b\"%d %d %d\\n\\0\" as *const u8 as *const libc::c_char, t.a, t.b, t.c); printf(b\"%d %d %d\\n\\0\" as *const u8 as *const libc::c_char, h.a, h.b, h.c); printf(b\"%lf\\n\\0\" as *const u8 as *const libc::c_char, alfa); let mut _T_0: libc::c_double = alfa; alfa = omega; omega = _T_0; printf(b\"%lf\\n\\0\" as *const u8 as *const libc::c_char, alfa); printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, (*pt).a); let mut _T_1: *mut test = pt; pt = th; th = _T_1; printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, (*pt).a); return 0; }" }, { "index": 143, "before": "void swap(void *va, void *vb, size_t s) { char t, *a = (char *)va, *b = (char *)vb; while (s--) t = a[s], a[s] = b[s], b[s] = t; }", "after": "pub unsafe extern \"C\" fn swap( mut va: *mut libc::c_void, mut vb: *mut libc::c_void, mut s: size_t, ) { let mut t: libc::c_char = 0; let mut a: *mut libc::c_char = va as *mut libc::c_char; let mut b: *mut libc::c_char = vb as *mut libc::c_char; loop { let fresh0 = s; s = s.wrapping_sub(1); if !(fresh0 != 0) { break; } t = *a.offset(s as isize); *a.offset(s as isize) = *b.offset(s as isize); *b.offset(s as isize) = t; }; }" }, { "index": 144, "before": "int main(int argc, char*argv[]) { int nums2factor[] = { 2059, 223092870, 3135, 45 }; Factors ftors = { NULL, 0}; char sep; int i,j; for (i=0; i<4; i++) { factor( nums2factor[i], &ftors ); printf(\"\\nfactors of %d are:\\n \", nums2factor[i]); sep = ' '; for (j=0; j libc::c_int { let mut nums2factor: [libc::c_int; 4] = [ 2059 as libc::c_int, 223092870 as libc::c_int, 3135 as libc::c_int, 45 as libc::c_int, ]; let mut ftors: Factors = { let mut init = Factors { list: 0 as *mut libc::c_int, count: 0 as libc::c_int as libc::c_short, }; init }; let mut sep: libc::c_char = 0; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; i = 0 as libc::c_int; while i < 4 as libc::c_int { factor(nums2factor[i as usize], &mut ftors); printf( b\"\\nfactors of %d are:\\n \\0\" as *const u8 as *const libc::c_char, nums2factor[i as usize], ); sep = ' ' as i32 as libc::c_char; j = 0 as libc::c_int; while j < ftors.count as libc::c_int { printf( b\"%c %d\\0\" as *const u8 as *const libc::c_char, sep as libc::c_int, *(ftors.list).offset(j as isize), ); sep = ',' as i32 as libc::c_char; j += 1; j; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 145, "before": "void xferFactors( Factors *fctrs, int *flist, int flix ) { int ix, ij; int newSize = fctrs->count + flix; if (newSize > flix) { fctrs->list = realloc( fctrs->list, newSize * sizeof(int)); } else { fctrs->list = malloc( newSize * sizeof(int)); } for (ij=0,ix=fctrs->count; ixlist[ix] = flist[ij]; } fctrs->count = newSize; }", "after": "pub unsafe extern \"C\" fn xferFactors( mut fctrs: *mut Factors, mut flist: *mut libc::c_int, mut flix: libc::c_int, ) { let mut ix: libc::c_int = 0; let mut ij: libc::c_int = 0; let mut newSize: libc::c_int = (*fctrs).count as libc::c_int + flix; if newSize > flix { (*fctrs) .list = realloc( (*fctrs).list as *mut libc::c_void, (newSize as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_int; } else { (*fctrs) .list = malloc( (newSize as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_int; } ij = 0 as libc::c_int; ix = (*fctrs).count as libc::c_int; while ix < newSize { *((*fctrs).list).offset(ix as isize) = *flist.offset(ij as isize); ij += 1; ij; ix += 1; ix; } (*fctrs).count = newSize as libc::c_short; }" }, { "index": 146, "before": "int main() { print_table(15, '+', nimsum); printf(\"\\n\"); print_table(15, '*', nimprod); const uint32_t a = 21508, b = 42689; printf(\"\\n%d + %d = %d\\n\", a, b, nimsum(a, b)); printf(\"%d * %d = %d\\n\", a, b, nimprod(a, b)); return 0; }", "after": "unsafe fn main() -> libc::c_int { print_table( 15 as libc::c_int as uint32_t, '+' as i32 as libc::c_char, Some(nimsum as unsafe extern \"C\" fn(uint32_t, uint32_t) -> uint32_t), ); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); print_table( 15 as libc::c_int as uint32_t, '*' as i32 as libc::c_char, Some(nimprod as unsafe extern \"C\" fn(uint32_t, uint32_t) -> uint32_t), ); let a: uint32_t = 21508 as libc::c_int as uint32_t; let b: uint32_t = 42689 as libc::c_int as uint32_t; printf( b\"\\n%d + %d = %d\\n\\0\" as *const u8 as *const libc::c_char, a, b, nimsum(a, b), ); printf(b\"%d * %d = %d\\n\\0\" as *const u8 as *const libc::c_char, a, b, nimprod(a, b)); return 0 as libc::c_int; }" }, { "index": 147, "before": "uint32_t hpo2(uint32_t n) { return n & -n; }", "after": "pub unsafe extern \"C\" fn hpo2(mut n: uint32_t) -> uint32_t { return n & n.wrapping_neg(); }" }, { "index": 148, "before": "uint32_t nimsum(uint32_t x, uint32_t y) { return x ^ y; }", "after": "pub unsafe extern \"C\" fn nimsum(mut x: uint32_t, mut y: uint32_t) -> uint32_t { return x ^ y; }" }, { "index": 149, "before": "uint32_t nimprod(uint32_t x, uint32_t y) { if (x < 2 || y < 2) return x * y; uint32_t h = hpo2(x); if (x > h) return nimprod(h, y) ^ nimprod(x ^ h, y); if (hpo2(y) < y) return nimprod(y, x); uint32_t xp = lhpo2(x), yp = lhpo2(y); uint32_t comp = xp & yp; if (comp == 0) return x * y; h = hpo2(comp); return nimprod(nimprod(x >> h, y >> h), 3 << (h - 1)); }", "after": "pub unsafe extern \"C\" fn nimprod(mut x: uint32_t, mut y: uint32_t) -> uint32_t { if x < 2 as libc::c_int as libc::c_uint || y < 2 as libc::c_int as libc::c_uint { return x.wrapping_mul(y); } let mut h: uint32_t = hpo2(x); if x > h { return nimprod(h, y) ^ nimprod(x ^ h, y); } if hpo2(y) < y { return nimprod(y, x); } let mut xp: uint32_t = lhpo2(x); let mut yp: uint32_t = lhpo2(y); let mut comp: uint32_t = xp & yp; if comp == 0 as libc::c_int as libc::c_uint { return x.wrapping_mul(y); } h = hpo2(comp); return nimprod( nimprod(x >> h, y >> h), ((3 as libc::c_int) << h.wrapping_sub(1 as libc::c_int as libc::c_uint)) as uint32_t, ); }" }, { "index": 150, "before": "uint32_t lhpo2(uint32_t n) { uint32_t q = 0, m = hpo2(n); for (; m % 2 == 0; m >>= 1, ++q) {} return q; }", "after": "pub unsafe extern \"C\" fn lhpo2(mut n: uint32_t) -> uint32_t { let mut q: uint32_t = 0 as libc::c_int as uint32_t; let mut m: uint32_t = hpo2(n); while m.wrapping_rem(2 as libc::c_int as libc::c_uint) == 0 as libc::c_int as libc::c_uint { m >>= 1 as libc::c_int; q = q.wrapping_add(1); q; } return q; }" }, { "index": 151, "before": "void sieve(int limit, int primes[], int *count) { bool *c = calloc(limit + 1, sizeof(bool)); /* composite = TRUE */ /* no need to process even numbers */ int i, p = 3, p2, n = 0; p2 = p * p; while (p2 <= limit) { for (i = p2; i <= limit; i += 2 * p) c[i] = TRUE; do { p += 2; } while (c[p]); p2 = p * p; } for (i = 3; i <= limit; i += 2) { if (!c[i]) primes[n++] = i; } *count = n; free(c); }", "after": "pub unsafe extern \"C\" fn sieve( mut limit: libc::c_int, mut primes: *mut libc::c_int, mut count: *mut libc::c_int, ) { let mut c: *mut bool_0 = calloc( (limit + 1 as libc::c_int) as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut bool_0; let mut i: libc::c_int = 0; let mut p: libc::c_int = 3 as libc::c_int; let mut p2: libc::c_int = 0; let mut n: libc::c_int = 0 as libc::c_int; p2 = p * p; while p2 <= limit { i = p2; while i <= limit { *c.offset(i as isize) = 1 as libc::c_int; i += 2 as libc::c_int * p; } loop { p += 2 as libc::c_int; if !(*c.offset(p as isize) != 0) { break; } } p2 = p * p; } i = 3 as libc::c_int; while i <= limit { if *c.offset(i as isize) == 0 { let fresh0 = n; n = n + 1; *primes.offset(fresh0 as isize) = i; } i += 2 as libc::c_int; } *count = n; free(c as *mut libc::c_void); }" }, { "index": 152, "before": "int main() { int i, prime, count = 0, index = 0, primeCount, longCount = 0, numberCount; int *primes, *longPrimes, *totals; int numbers[] = {500, 1000, 2000, 4000, 8000, 16000, 32000, 64000}; primes = calloc(6500, sizeof(int)); numberCount = sizeof(numbers) / sizeof(int); totals = calloc(numberCount, sizeof(int)); sieve(64000, primes, &primeCount); longPrimes = calloc(primeCount, sizeof(int)); /* Surely longCount < primeCount */ for (i = 0; i < primeCount; ++i) { prime = primes[i]; if (findPeriod(prime) == prime - 1) { longPrimes[longCount++] = prime; } } for (i = 0; i < longCount; ++i, ++count) { if (longPrimes[i] > numbers[index]) { totals[index++] = count; } } totals[numberCount - 1] = count; printf(\"The long primes up to %d are:\\n\", numbers[0]); printf(\"[\"); for (i = 0; i < totals[0]; ++i) { printf(\"%d \", longPrimes[i]); } printf(\"\\b]\\n\"); printf(\"\\nThe number of long primes up to:\\n\"); for (i = 0; i < 8; ++i) { printf(\" %5d is %d\\n\", numbers[i], totals[i]); } free(totals); free(longPrimes); free(primes); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut prime: libc::c_int = 0; let mut count: libc::c_int = 0 as libc::c_int; let mut index: libc::c_int = 0 as libc::c_int; let mut primeCount: libc::c_int = 0; let mut longCount: libc::c_int = 0 as libc::c_int; let mut numberCount: libc::c_int = 0; let mut primes: *mut libc::c_int = 0 as *mut libc::c_int; let mut longPrimes: *mut libc::c_int = 0 as *mut libc::c_int; let mut totals: *mut libc::c_int = 0 as *mut libc::c_int; let mut numbers: [libc::c_int; 8] = [ 500 as libc::c_int, 1000 as libc::c_int, 2000 as libc::c_int, 4000 as libc::c_int, 8000 as libc::c_int, 16000 as libc::c_int, 32000 as libc::c_int, 64000 as libc::c_int, ]; primes = calloc( 6500 as libc::c_int as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; numberCount = (::core::mem::size_of::<[libc::c_int; 8]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int; totals = calloc( numberCount as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; sieve(64000 as libc::c_int, primes, &mut primeCount); longPrimes = calloc( primeCount as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; i = 0 as libc::c_int; while i < primeCount { prime = *primes.offset(i as isize); if findPeriod(prime) == prime - 1 as libc::c_int { let fresh1 = longCount; longCount = longCount + 1; *longPrimes.offset(fresh1 as isize) = prime; } i += 1; i; } i = 0 as libc::c_int; while i < longCount { if *longPrimes.offset(i as isize) > numbers[index as usize] { let fresh2 = index; index = index + 1; *totals.offset(fresh2 as isize) = count; } i += 1; i; count += 1; count; } *totals.offset((numberCount - 1 as libc::c_int) as isize) = count; printf( b\"The long primes up to %d are:\\n\\0\" as *const u8 as *const libc::c_char, numbers[0 as libc::c_int as usize], ); printf(b\"[\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < *totals.offset(0 as libc::c_int as isize) { printf( b\"%d \\0\" as *const u8 as *const libc::c_char, *longPrimes.offset(i as isize), ); i += 1; i; } printf(b\"\\x08]\\n\\0\" as *const u8 as *const libc::c_char); printf( b\"\\nThe number of long primes up to:\\n\\0\" as *const u8 as *const libc::c_char, ); i = 0 as libc::c_int; while i < 8 as libc::c_int { printf( b\" %5d is %d\\n\\0\" as *const u8 as *const libc::c_char, numbers[i as usize], *totals.offset(i as isize), ); i += 1; i; } free(totals as *mut libc::c_void); free(longPrimes as *mut libc::c_void); free(primes as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 153, "before": "int findPeriod(int n) { int i, r = 1, rr, period = 0; for (i = 1; i <= n + 1; ++i) { r = (10 * r) % n; } rr = r; do { r = (10 * r) % n; period++; } while (r != rr); return period; }", "after": "pub unsafe extern \"C\" fn findPeriod(mut n: libc::c_int) -> libc::c_int { let mut i: libc::c_int = 0; let mut r: libc::c_int = 1 as libc::c_int; let mut rr: libc::c_int = 0; let mut period: libc::c_int = 0 as libc::c_int; i = 1 as libc::c_int; while i <= n + 1 as libc::c_int { r = 10 as libc::c_int * r % n; i += 1; i; } rr = r; loop { r = 10 as libc::c_int * r % n; period += 1; period; if !(r != rr) { break; } } return period; }" }, { "index": 154, "before": "int luhn(const char* cc) { \tconst int m[] = {0,2,4,6,8,1,3,5,7,9}; // mapping for rule 3 \tint i, odd = 1, sum = 0; \tfor (i = strlen(cc); i--; odd = !odd) { \t\tint digit = cc[i] - '0'; \t\tsum += odd ? digit : m[digit]; \t} \treturn sum % 10 == 0; }", "after": "pub unsafe extern \"C\" fn luhn(mut cc: *const libc::c_char) -> libc::c_int { let m: [libc::c_int; 10] = [ 0 as libc::c_int, 2 as libc::c_int, 4 as libc::c_int, 6 as libc::c_int, 8 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 5 as libc::c_int, 7 as libc::c_int, 9 as libc::c_int, ]; let mut i: libc::c_int = 0; let mut odd: libc::c_int = 1 as libc::c_int; let mut sum: libc::c_int = 0 as libc::c_int; i = strlen(cc) as libc::c_int; loop { let fresh0 = i; i = i - 1; if !(fresh0 != 0) { break; } let mut digit: libc::c_int = *cc.offset(i as isize) as libc::c_int - '0' as i32; sum += if odd != 0 { digit } else { m[digit as usize] }; odd = (odd == 0) as libc::c_int; } return (sum % 10 as libc::c_int == 0 as libc::c_int) as libc::c_int; }" }, { "index": 155, "before": "int main() { \tconst char* cc[] = { \t\t\"49927398716\", \t\t\"49927398717\", \t\t\"1234567812345678\", \t\t\"1234567812345670\", \t\t0 \t}; \tint i; \tfor (i = 0; cc[i]; i++) \t\tprintf(\"%16s\\t%s\\n\", cc[i], luhn(cc[i]) ? \"ok\" : \"not ok\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut cc: [*const libc::c_char; 5] = [ b\"49927398716\\0\" as *const u8 as *const libc::c_char, b\"49927398717\\0\" as *const u8 as *const libc::c_char, b\"1234567812345678\\0\" as *const u8 as *const libc::c_char, b\"1234567812345670\\0\" as *const u8 as *const libc::c_char, 0 as *const libc::c_char, ]; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while !(cc[i as usize]).is_null() { printf( b\"%16s\\t%s\\n\\0\" as *const u8 as *const libc::c_char, cc[i as usize], if luhn(cc[i as usize]) != 0 { b\"ok\\0\" as *const u8 as *const libc::c_char } else { b\"not ok\\0\" as *const u8 as *const libc::c_char }, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 156, "before": "void solve(int n, int col, int *hist) { \tif (col == n) { \t\tprintf(\"\\nNo. %d\\n-----\\n\", ++count); \t\tfor (int i = 0; i < n; i++, putchar('\\n')) \t\t\tfor (int j = 0; j < n; j++) \t\t\t\tputchar(j == hist[i] ? 'Q' : ((i + j) & 1) ? ' ' : '.'); \t\treturn; \t} #\tdefine attack(i, j) (hist[j] == i || abs(hist[j] - i) == col - j) \tfor (int i = 0, j = 0; i < n; i++) { \t\tfor (j = 0; j < col && !attack(i, j); j++); \t\tif (j < col) continue; \t\thist[col] = i; \t\tsolve(n, col + 1, hist); \t} }", "after": "pub unsafe extern \"C\" fn solve( mut n: libc::c_int, mut col: libc::c_int, mut hist: *mut libc::c_int, ) { if col == n { count += 1; printf(b\"\\nNo. %d\\n-----\\n\\0\" as *const u8 as *const libc::c_char, count); let mut i: libc::c_int = 0 as libc::c_int; while i < n { let mut j: libc::c_int = 0 as libc::c_int; while j < n { putchar( if j == *hist.offset(i as isize) { 'Q' as i32 } else if i + j & 1 as libc::c_int != 0 { ' ' as i32 } else { '.' as i32 }, ); j += 1; j; } i += 1; i; putchar('\\n' as i32); } return; } let mut i_0: libc::c_int = 0 as libc::c_int; let mut j_0: libc::c_int = 0 as libc::c_int; while i_0 < n { j_0 = 0 as libc::c_int; while j_0 < col && !(*hist.offset(j_0 as isize) == i_0 || abs(*hist.offset(j_0 as isize) - i_0) == col - j_0) { j_0 += 1; j_0; } if !(j_0 < col) { *hist.offset(col as isize) = i_0; solve(n, col + 1 as libc::c_int, hist); } i_0 += 1; i_0; } }" }, { "index": 157, "before": "int main(int n, char **argv) { \tif (n <= 1 || (n = atoi(argv[1])) <= 0) n = 8; \tint hist[n]; \tsolve(n, 0, hist); }", "after": "unsafe fn main(mut n: libc::c_int, mut argv: *mut *mut libc::c_char) -> libc::c_int { if n <= 1 as libc::c_int || { n = atoi(*argv.offset(1 as libc::c_int as isize)); n <= 0 as libc::c_int } { n = 8 as libc::c_int; } let vla = n as usize; let mut hist: Vec:: = ::std::vec::from_elem(0, vla); solve(n, 0 as libc::c_int, hist.as_mut_ptr()); return 0; }" }, { "index": 158, "before": "int main(void) { \tconst char *items[] = {\"fee fie\", \"huff and puff\", \"mirror mirror\", \"tick tock\", NULL}; \tconst char *prompt = \"Which is from the three pigs?\"; \tprintf(\"You chose %s.\\n\", menu_select(items, prompt)); \treturn EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut items: [*const libc::c_char; 5] = [ b\"fee fie\\0\" as *const u8 as *const libc::c_char, b\"huff and puff\\0\" as *const u8 as *const libc::c_char, b\"mirror mirror\\0\" as *const u8 as *const libc::c_char, b\"tick tock\\0\" as *const u8 as *const libc::c_char, 0 as *const libc::c_char, ]; let mut prompt: *const libc::c_char = b\"Which is from the three pigs?\\0\" as *const u8 as *const libc::c_char; printf( b\"You chose %s.\\n\\0\" as *const u8 as *const libc::c_char, menu_select(items.as_mut_ptr(), prompt), ); return 0 as libc::c_int; }" }, { "index": 159, "before": "void deinit_square_matrix(SquareMatrix A) { for(int i = 0; i < A.n; ++i) free(A.elems[i]); free(A.elems); }", "after": "pub unsafe extern \"C\" fn deinit_square_matrix(mut A: SquareMatrix) { let mut i: libc::c_int = 0 as libc::c_int; while i < A.n { free(*(A.elems).offset(i as isize) as *mut libc::c_void); i += 1; i; } free(A.elems as *mut libc::c_void); }" }, { "index": 160, "before": "double det(SquareMatrix A) { double det = 1; for(int j = 0; j < A.n; ++j) { int i_max = j; for(int i = j; i < A.n; ++i) if(A.elems[i][j] > A.elems[i_max][j]) i_max = i; if(i_max != j) { for(int k = 0; k < A.n; ++k) { double tmp = A.elems[i_max][k]; A.elems[i_max][k] = A.elems[j][k]; A.elems[j][k] = tmp; } det *= -1; } if(abs(A.elems[j][j]) < 1e-12) { puts(\"Singular matrix!\"); return NAN; } for(int i = j + 1; i < A.n; ++i) { double mult = -A.elems[i][j] / A.elems[j][j]; for(int k = 0; k < A.n; ++k) A.elems[i][k] += mult * A.elems[j][k]; } } for(int i = 0; i < A.n; ++i) det *= A.elems[i][i]; return det; }", "after": "pub unsafe extern \"C\" fn det(mut A: SquareMatrix) -> libc::c_double { let mut det_0: libc::c_double = 1 as libc::c_int as libc::c_double; let mut j: libc::c_int = 0 as libc::c_int; while j < A.n { let mut i_max: libc::c_int = j; let mut i: libc::c_int = j; while i < A.n { if *(*(A.elems).offset(i as isize)).offset(j as isize) > *(*(A.elems).offset(i_max as isize)).offset(j as isize) { i_max = i; } i += 1; i; } if i_max != j { let mut k: libc::c_int = 0 as libc::c_int; while k < A.n { let mut tmp: libc::c_double = *(*(A.elems).offset(i_max as isize)) .offset(k as isize); *(*(A.elems).offset(i_max as isize)) .offset( k as isize, ) = *(*(A.elems).offset(j as isize)).offset(k as isize); *(*(A.elems).offset(j as isize)).offset(k as isize) = tmp; k += 1; k; } det_0 *= -(1 as libc::c_int) as libc::c_double; } if (abs(*(*(A.elems).offset(j as isize)).offset(j as isize) as libc::c_int) as libc::c_double) < 1e-12f64 { puts(b\"Singular matrix!\\0\" as *const u8 as *const libc::c_char); return ::core::f32::NAN as libc::c_double; } let mut i_0: libc::c_int = j + 1 as libc::c_int; while i_0 < A.n { let mut mult: libc::c_double = -*(*(A.elems).offset(i_0 as isize)) .offset(j as isize) / *(*(A.elems).offset(j as isize)).offset(j as isize); let mut k_0: libc::c_int = 0 as libc::c_int; while k_0 < A.n { *(*(A.elems).offset(i_0 as isize)).offset(k_0 as isize) += mult * *(*(A.elems).offset(j as isize)).offset(k_0 as isize); k_0 += 1; k_0; } i_0 += 1; i_0; } j += 1; j; } let mut i_1: libc::c_int = 0 as libc::c_int; while i_1 < A.n { det_0 *= *(*(A.elems).offset(i_1 as isize)).offset(i_1 as isize); i_1 += 1; i_1; } return det_0; }" }, { "index": 161, "before": "double cramer_solve(SquareMatrix A, double det_A, double *b, int var) { SquareMatrix tmp = copy_square_matrix(A); for(int i = 0; i < tmp.n; ++i) tmp.elems[i][var] = b[i]; double det_tmp = det(tmp); deinit_square_matrix(tmp); return det_tmp / det_A; }", "after": "pub unsafe extern \"C\" fn cramer_solve( mut A: SquareMatrix, mut det_A: libc::c_double, mut b: *mut libc::c_double, mut var: libc::c_int, ) -> libc::c_double { let mut tmp: SquareMatrix = copy_square_matrix(A); let mut i: libc::c_int = 0 as libc::c_int; while i < tmp.n { *(*(tmp.elems).offset(i as isize)).offset(var as isize) = *b.offset(i as isize); i += 1; i; } let mut det_tmp: libc::c_double = det(tmp); deinit_square_matrix(tmp); return det_tmp / det_A; }" }, { "index": 162, "before": "SquareMatrix init_square_matrix(int n, double elems[n][n]) { SquareMatrix A = { .n = n, .elems = malloc(n * sizeof(double *)) }; for(int i = 0; i < n; ++i) { A.elems[i] = malloc(n * sizeof(double)); for(int j = 0; j < n; ++j) A.elems[i][j] = elems[i][j]; } return A; }", "after": "pub unsafe extern \"C\" fn init_square_matrix( mut n: libc::c_int, mut elems: *mut libc::c_double, ) -> SquareMatrix { let vla = n as usize; let mut A: SquareMatrix = { let mut init = SquareMatrix { n: n, elems: malloc( (n as libc::c_ulong) .wrapping_mul( ::core::mem::size_of::<*mut libc::c_double>() as libc::c_ulong, ), ) as *mut *mut libc::c_double, }; init }; let mut i: libc::c_int = 0 as libc::c_int; while i < n { let ref mut fresh0 = *(A.elems).offset(i as isize); *fresh0 = malloc( (n as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_double; let mut j: libc::c_int = 0 as libc::c_int; while j < n { *(*(A.elems).offset(i as isize)) .offset( j as isize, ) = *elems.offset(i as isize * vla as isize).offset(j as isize); j += 1; j; } i += 1; i; } return A; }" }, { "index": 163, "before": "int main(int argc, char **argv) { #define N 4 double elems[N][N] = { { 2, -1, 5, 1}, { 3, 2, 2, -6}, { 1, 3, 3, -1}, { 5, -2, -3, 3} }; SquareMatrix A = init_square_matrix(N, elems); SquareMatrix tmp = copy_square_matrix(A); int det_A = det(tmp); deinit_square_matrix(tmp); double b[] = {-3, -32, -47, 49}; for(int i = 0; i < N; ++i) printf(\"%7.3lf\\n\", cramer_solve(A, det_A, b, i)); deinit_square_matrix(A); return EXIT_SUCCESS; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut elems: [[libc::c_double; 4]; 4] = [ [ 2 as libc::c_int as libc::c_double, -(1 as libc::c_int) as libc::c_double, 5 as libc::c_int as libc::c_double, 1 as libc::c_int as libc::c_double, ], [ 3 as libc::c_int as libc::c_double, 2 as libc::c_int as libc::c_double, 2 as libc::c_int as libc::c_double, -(6 as libc::c_int) as libc::c_double, ], [ 1 as libc::c_int as libc::c_double, 3 as libc::c_int as libc::c_double, 3 as libc::c_int as libc::c_double, -(1 as libc::c_int) as libc::c_double, ], [ 5 as libc::c_int as libc::c_double, -(2 as libc::c_int) as libc::c_double, -(3 as libc::c_int) as libc::c_double, 3 as libc::c_int as libc::c_double, ], ]; let mut A: SquareMatrix = init_square_matrix( 4 as libc::c_int, elems.as_mut_ptr() as *mut libc::c_double, ); let mut tmp: SquareMatrix = copy_square_matrix(A); let mut det_A: libc::c_int = det(tmp) as libc::c_int; deinit_square_matrix(tmp); let mut b: [libc::c_double; 4] = [ -(3 as libc::c_int) as libc::c_double, -(32 as libc::c_int) as libc::c_double, -(47 as libc::c_int) as libc::c_double, 49 as libc::c_int as libc::c_double, ]; let mut i: libc::c_int = 0 as libc::c_int; while i < 4 as libc::c_int { printf( b\"%7.3lf\\n\\0\" as *const u8 as *const libc::c_char, cramer_solve(A, det_A as libc::c_double, b.as_mut_ptr(), i), ); i += 1; i; } deinit_square_matrix(A); return 0 as libc::c_int; }" }, { "index": 164, "before": "SquareMatrix copy_square_matrix(SquareMatrix src) { SquareMatrix dest; dest.n = src.n; dest.elems = malloc(dest.n * sizeof(double *)); for(int i = 0; i < dest.n; ++i) { dest.elems[i] = malloc(dest.n * sizeof(double)); for(int j = 0; j < dest.n; ++j) dest.elems[i][j] = src.elems[i][j]; } return dest; }", "after": "pub unsafe extern \"C\" fn copy_square_matrix(mut src: SquareMatrix) -> SquareMatrix { let mut dest: SquareMatrix = SquareMatrix { n: 0, elems: 0 as *mut *mut libc::c_double, }; dest.n = src.n; dest .elems = malloc( (dest.n as libc::c_ulong) .wrapping_mul(::core::mem::size_of::<*mut libc::c_double>() as libc::c_ulong), ) as *mut *mut libc::c_double; let mut i: libc::c_int = 0 as libc::c_int; while i < dest.n { let ref mut fresh1 = *(dest.elems).offset(i as isize); *fresh1 = malloc( (dest.n as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_double; let mut j: libc::c_int = 0 as libc::c_int; while j < dest.n { *(*(dest.elems).offset(i as isize)) .offset( j as isize, ) = *(*(src.elems).offset(i as isize)).offset(j as isize); j += 1; j; } i += 1; i; } return dest; }" }, { "index": 165, "before": "int main (void) { printf (\"%f\\n\", x(5)); /* 6.000000 */ printf (\"%f\\n\", x(2.3)); /* 8.300000 */ printf (\"%i\\n\", y(5.0)); /* 8 */ printf (\"%i\\n\", y(3.3)); /* 11 */ printf (\"%c\\n\", z(5)); /* f */ return 0; }", "after": "unsafe fn main() -> libc::c_int { printf( b\"%f\\n\\0\" as *const u8 as *const libc::c_char, x(5 as libc::c_int as libc::c_double), ); printf(b\"%f\\n\\0\" as *const u8 as *const libc::c_char, x(2.3f64)); printf(b\"%i\\n\\0\" as *const u8 as *const libc::c_char, y(5.0f64 as libc::c_int)); printf(b\"%i\\n\\0\" as *const u8 as *const libc::c_char, y(3.3f64 as libc::c_int)); printf(b\"%c\\n\\0\" as *const u8 as *const libc::c_char, z(5 as libc::c_int)); return 0 as libc::c_int; }" }, { "index": 166, "before": "int main(int c, char ** v) { \tint size, depth; \tdepth = (c > 1) ? atoi(v[1]) : 10; \tsize = 1 << depth; \tfprintf(stderr, \"size: %d depth: %d\\n\", size, depth); \tdragon(size, depth * 2); \treturn 0; }", "after": "unsafe fn main(mut c: libc::c_int, mut v: *mut *mut libc::c_char) -> libc::c_int { let mut size: libc::c_int = 0; let mut depth: libc::c_int = 0; depth = if c > 1 as libc::c_int { atoi(*v.offset(1 as libc::c_int as isize)) } else { 10 as libc::c_int }; size = (1 as libc::c_int) << depth; fprintf( stderr, b\"size: %d depth: %d\\n\\0\" as *const u8 as *const libc::c_char, size, depth, ); dragon(size as libc::c_long, depth * 2 as libc::c_int); return 0 as libc::c_int; }" }, { "index": 167, "before": "void iter_string(const char * str, int d) { \tlong tmp; #\tdefine LEFT tmp = -dy; dy = dx; dx = tmp #\tdefine RIGHT tmp = dy; dy = -dx; dx = tmp \twhile (*str != '\\0') { \t\tswitch(*(str++)) { \t\tcase 'X':\tif (d) iter_string(\"X+YF+\", d - 1); continue; \t\tcase 'Y':\tif (d) iter_string(\"-FX-Y\", d - 1); continue; \t\tcase '+':\tRIGHT; continue; \t\tcase '-':\tLEFT; continue; \t\tcase 'F': /* draw: increment path length; add color; move. Here * is why the code does not allow user to choose arbitrary * image size: if it's not a power of two, aliasing will * occur and grid-like bright or dark lines will result * when normalized later. It can be gotten rid of, but that * involves computing multiplicative order and would be a huge * bore. */ \t\t\t\tclen ++; \t\t\t\th_rgb(x/scale, y/scale); \t\t\t\tx += dx; y += dy; \t\t\t\tcontinue; \t\t} \t} }", "after": "pub unsafe extern \"C\" fn iter_string(mut str: *const libc::c_char, mut d: libc::c_int) { let mut tmp: libc::c_long = 0; while *str as libc::c_int != '\\0' as i32 { let fresh0 = str; str = str.offset(1); match *fresh0 as libc::c_int { 88 => { if d != 0 { iter_string( b\"X+YF+\\0\" as *const u8 as *const libc::c_char, d - 1 as libc::c_int, ); } } 89 => { if d != 0 { iter_string( b\"-FX-Y\\0\" as *const u8 as *const libc::c_char, d - 1 as libc::c_int, ); } } 43 => { tmp = dy as libc::c_long; dy = -dx; dx = tmp as libc::c_longlong; } 45 => { tmp = -dy as libc::c_long; dy = dx; dx = tmp as libc::c_longlong; } 70 => { clen += 1; clen; h_rgb(x / scale, y / scale); x += dx; y += dy; } _ => {} } } }" }, { "index": 168, "before": "void sc_up() { \tlong long tmp = dx - dy; dy = dx + dy; dx = tmp; \tscale *= 2; x *= 2; y *= 2; }", "after": "pub unsafe extern \"C\" fn sc_up() { let mut tmp: libc::c_longlong = dx - dy; dy = dx + dy; dx = tmp; scale *= 2 as libc::c_int as libc::c_longlong; x *= 2 as libc::c_int as libc::c_longlong; y *= 2 as libc::c_int as libc::c_longlong; }" }, { "index": 169, "before": "void h_rgb(long long x, long long y) { \trgb *p = &pix[y][x]; #\tdefine SAT 1 \tdouble h = 6.0 * clen / scale; \tdouble VAL = 1 - (cos(3.141592653579 * 64 * clen / scale) - 1) / 4; \tdouble c = SAT * VAL; \tdouble X = c * (1 - fabs(fmod(h, 2) - 1)); \tswitch((int)h) { \tcase 0: p->r += c; p->g += X; return; \tcase 1:\tp->r += X; p->g += c; return; \tcase 2: p->g += c; p->b += X; return; \tcase 3: p->g += X; p->b += c; return; \tcase 4: p->r += X; p->b += c; return; \tdefault: \t\tp->r += c; p->b += X; \t} }", "after": "pub unsafe extern \"C\" fn h_rgb(mut x_0: libc::c_longlong, mut y_0: libc::c_longlong) { let mut p: *mut rgb = &mut *(*pix.offset(y_0 as isize)).offset(x_0 as isize) as *mut rgb; let mut h: libc::c_double = 6.0f64 * clen as libc::c_double / scale as libc::c_double; let mut VAL: libc::c_double = 1 as libc::c_int as libc::c_double - (cos( 3.141592653579f64 * 64 as libc::c_int as libc::c_double * clen as libc::c_double / scale as libc::c_double, ) - 1 as libc::c_int as libc::c_double) / 4 as libc::c_int as libc::c_double; let mut c: libc::c_double = 1 as libc::c_int as libc::c_double * VAL; let mut X: libc::c_double = c * (1 as libc::c_int as libc::c_double - fabs( fmod(h, 2 as libc::c_int as libc::c_double) - 1 as libc::c_int as libc::c_double, )); match h as libc::c_int { 0 => { (*p).r += c; (*p).g += X; return; } 1 => { (*p).r += X; (*p).g += c; return; } 2 => { (*p).g += c; (*p).b += X; return; } 3 => { (*p).g += X; (*p).b += c; return; } 4 => { (*p).r += X; (*p).b += c; return; } _ => { (*p).r += c; (*p).b += X; } }; }" }, { "index": 170, "before": "void dragon(long leng, int depth) { \tlong i, d = leng / 3 + 1; \tlong h = leng + 3, w = leng + d * 3 / 2 + 2; \t/* allocate pixel buffer */ \trgb *buf = malloc(sizeof(rgb) * w * h); \tpix = malloc(sizeof(rgb *) * h); \tfor (i = 0; i < h; i++) \t\tpix[i] = buf + w * i; \tmemset(buf, 0, sizeof(rgb) * w * h); /* init coords; scale up to desired; exec string */ \tx = y = d; dx = leng; dy = 0; scale = 1; clen = 0; \tfor (i = 0; i < depth; i++) sc_up(); \titer_string(\"FX\", depth); \t/* write color PNM file */ \tunsigned char *fpix = malloc(w * h * 3); \tdouble maxv = 0, *dbuf = (double*)buf; /* find highest value among pixels; normalize image according * to it. Highest value would be at points most travelled, so * this ends up giving curve edge a nice fade -- it's more apparaent * if we increase iteration depth by one or two. */ \tfor (i = 3 * w * h - 1; i >= 0; i--) \t\tif (dbuf[i] > maxv) maxv = dbuf[i]; \tfor (i = 3 * h * w - 1; i >= 0; i--) \t\tfpix[i] = 255 * dbuf[i] / maxv; \tprintf(\"P6\\n%ld %ld\\n255\\n\", w, h); \tfflush(stdout); /* printf and fwrite may treat buffer differently */ \tfwrite(fpix, h * w * 3, 1, stdout); }", "after": "pub unsafe extern \"C\" fn dragon(mut leng: libc::c_long, mut depth: libc::c_int) { let mut i: libc::c_long = 0; let mut d: libc::c_long = leng / 3 as libc::c_int as libc::c_long + 1 as libc::c_int as libc::c_long; let mut h: libc::c_long = leng + 3 as libc::c_int as libc::c_long; let mut w: libc::c_long = leng + d * 3 as libc::c_int as libc::c_long / 2 as libc::c_int as libc::c_long + 2 as libc::c_int as libc::c_long; let mut buf: *mut rgb = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(w as libc::c_ulong) .wrapping_mul(h as libc::c_ulong), ) as *mut rgb; pix = malloc( (::core::mem::size_of::<*mut rgb>() as libc::c_ulong) .wrapping_mul(h as libc::c_ulong), ) as *mut *mut rgb; i = 0 as libc::c_int as libc::c_long; while i < h { let ref mut fresh1 = *pix.offset(i as isize); *fresh1 = buf.offset((w * i) as isize); i += 1; i; } memset( buf as *mut libc::c_void, 0 as libc::c_int, (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(w as libc::c_ulong) .wrapping_mul(h as libc::c_ulong), ); y = d as libc::c_longlong; x = y; dx = leng as libc::c_longlong; dy = 0 as libc::c_int as libc::c_longlong; scale = 1 as libc::c_int as libc::c_longlong; clen = 0 as libc::c_int as libc::c_longlong; i = 0 as libc::c_int as libc::c_long; while i < depth as libc::c_long { sc_up(); i += 1; i; } iter_string(b\"FX\\0\" as *const u8 as *const libc::c_char, depth); let mut fpix: *mut libc::c_uchar = malloc( (w * h * 3 as libc::c_int as libc::c_long) as libc::c_ulong, ) as *mut libc::c_uchar; let mut maxv: libc::c_double = 0 as libc::c_int as libc::c_double; let mut dbuf: *mut libc::c_double = buf as *mut libc::c_double; i = 3 as libc::c_int as libc::c_long * w * h - 1 as libc::c_int as libc::c_long; while i >= 0 as libc::c_int as libc::c_long { if *dbuf.offset(i as isize) > maxv { maxv = *dbuf.offset(i as isize); } i -= 1; i; } i = 3 as libc::c_int as libc::c_long * h * w - 1 as libc::c_int as libc::c_long; while i >= 0 as libc::c_int as libc::c_long { *fpix .offset( i as isize, ) = (255 as libc::c_int as libc::c_double * *dbuf.offset(i as isize) / maxv) as libc::c_uchar; i -= 1; i; } printf(b\"P6\\n%ld %ld\\n255\\n\\0\" as *const u8 as *const libc::c_char, w, h); fflush(stdout); fwrite( fpix as *const libc::c_void, (h * w * 3 as libc::c_int as libc::c_long) as libc::c_ulong, 1 as libc::c_int as libc::c_ulong, stdout, ); }" }, { "index": 171, "before": "int main(int argc, char *argv[]) { int a, b; if (argc < 3) exit(1); b = atoi(argv[--argc]); if (b == 0) exit(2); a = atoi(argv[--argc]); printf(\"a+b = %d\\n\", a+b); printf(\"a-b = %d\\n\", a-b); printf(\"a*b = %d\\n\", a*b); printf(\"a/b = %d\\n\", a/b); /* truncates towards 0 (in C99) */ printf(\"a%%b = %d\\n\", a%b); /* same sign as first operand (in C99) */ return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut a: libc::c_int = 0; let mut b: libc::c_int = 0; if argc < 3 as libc::c_int { exit(1 as libc::c_int); } argc -= 1; b = atoi(*argv.offset(argc as isize)); if b == 0 as libc::c_int { exit(2 as libc::c_int); } argc -= 1; a = atoi(*argv.offset(argc as isize)); printf(b\"a+b = %d\\n\\0\" as *const u8 as *const libc::c_char, a + b); printf(b\"a-b = %d\\n\\0\" as *const u8 as *const libc::c_char, a - b); printf(b\"a*b = %d\\n\\0\" as *const u8 as *const libc::c_char, a * b); printf(b\"a/b = %d\\n\\0\" as *const u8 as *const libc::c_char, a / b); printf(b\"a%%b = %d\\n\\0\" as *const u8 as *const libc::c_char, a % b); return 0 as libc::c_int; }" }, { "index": 172, "before": "int main(int argc, char* argv[]) { double e; puts(\"The double precision in C give about 15 significant digits.\\n\" \"Values below are presented with 16 digits after the decimal point.\\n\"); // The most direct way to compute Euler constant. // e = exp(1); printf(\"Euler constant e = %.16lf\\n\", e); // The fast and independed method: e = lim (1 + 1/n)**n // int n = 8192; e = 1.0 + 1.0 / n; for (int i = 0; i < 13; i++) e *= e; printf(\"Euler constant e = %.16lf\\n\", e); // Taylor expansion e = 1 + 1/1 + 1/2 + 1/2/3 + 1/2/3/4 + 1/2/3/4/5 + ... // Actually Kahan summation may improve the accuracy, but is not necessary. // const int N = 1000; double a[1000]; a[0] = 1.0; for (int i = 1; i < N; i++) { a[i] = a[i-1] / i; } e = 1.; for (int i = N - 1; i > 0; i--) e += a[i]; printf(\"Euler constant e = %.16lf\\n\", e); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut e: libc::c_double = 0.; puts( b\"The double precision in C give about 15 significant digits.\\nValues below are presented with 16 digits after the decimal point.\\n\\0\" as *const u8 as *const libc::c_char, ); e = exp(1 as libc::c_int as libc::c_double); printf(b\"Euler constant e = %.16lf\\n\\0\" as *const u8 as *const libc::c_char, e); let mut n: libc::c_int = 8192 as libc::c_int; e = 1.0f64 + 1.0f64 / n as libc::c_double; let mut i: libc::c_int = 0 as libc::c_int; while i < 13 as libc::c_int { e *= e; i += 1; i; } printf(b\"Euler constant e = %.16lf\\n\\0\" as *const u8 as *const libc::c_char, e); let N: libc::c_int = 1000 as libc::c_int; let mut a: [libc::c_double; 1000] = [0.; 1000]; a[0 as libc::c_int as usize] = 1.0f64; let mut i_0: libc::c_int = 1 as libc::c_int; while i_0 < N { a[i_0 as usize] = a[(i_0 - 1 as libc::c_int) as usize] / i_0 as libc::c_double; i_0 += 1; i_0; } e = 1.0f64; let mut i_1: libc::c_int = N - 1 as libc::c_int; while i_1 > 0 as libc::c_int { e += a[i_1 as usize]; i_1 -= 1; i_1; } printf(b\"Euler constant e = %.16lf\\n\\0\" as *const u8 as *const libc::c_char, e); return 0 as libc::c_int; }" }, { "index": 173, "before": "double perpendicular_distance(point_t p, point_t p1, point_t p2) { double dx = p2.x - p1.x; double dy = p2.y - p1.y; double d = sqrt(dx * dx + dy * dy); return fabs(p.x * dy - p.y * dx + p2.x * p1.y - p2.y * p1.x)/d; }", "after": "pub unsafe extern \"C\" fn perpendicular_distance( mut p: point_t, mut p1: point_t, mut p2: point_t, ) -> libc::c_double { let mut dx: libc::c_double = p2.x - p1.x; let mut dy: libc::c_double = p2.y - p1.y; let mut d: libc::c_double = sqrt(dx * dx + dy * dy); return fabs(p.x * dy - p.y * dx + p2.x * p1.y - p2.y * p1.x) / d; }" }, { "index": 174, "before": "int main() { point_t points[] = { {0,0}, {1,0.1}, {2,-0.1}, {3,5}, {4,6}, {5,7}, {6,8.1}, {7,9}, {8,9}, {9,9} }; const size_t len = sizeof(points)/sizeof(points[0]); point_t out[len]; size_t n = douglas_peucker(points, len, 1.0, out, len); print_points(out, n); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut points: [point_t; 10] = [ { let mut init = point_tag { x: 0 as libc::c_int as libc::c_double, y: 0 as libc::c_int as libc::c_double, }; init }, { let mut init = point_tag { x: 1 as libc::c_int as libc::c_double, y: 0.1f64, }; init }, { let mut init = point_tag { x: 2 as libc::c_int as libc::c_double, y: -0.1f64, }; init }, { let mut init = point_tag { x: 3 as libc::c_int as libc::c_double, y: 5 as libc::c_int as libc::c_double, }; init }, { let mut init = point_tag { x: 4 as libc::c_int as libc::c_double, y: 6 as libc::c_int as libc::c_double, }; init }, { let mut init = point_tag { x: 5 as libc::c_int as libc::c_double, y: 7 as libc::c_int as libc::c_double, }; init }, { let mut init = point_tag { x: 6 as libc::c_int as libc::c_double, y: 8.1f64, }; init }, { let mut init = point_tag { x: 7 as libc::c_int as libc::c_double, y: 9 as libc::c_int as libc::c_double, }; init }, { let mut init = point_tag { x: 8 as libc::c_int as libc::c_double, y: 9 as libc::c_int as libc::c_double, }; init }, { let mut init = point_tag { x: 9 as libc::c_int as libc::c_double, y: 9 as libc::c_int as libc::c_double, }; init }, ]; let len: size_t = (::core::mem::size_of::<[point_t; 10]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong); let vla = len as usize; let mut out: Vec:: = ::std::vec::from_elem(point_t { x: 0., y: 0. }, vla); let mut n: size_t = douglas_peucker( points.as_mut_ptr(), len, 1.0f64, out.as_mut_ptr(), len, ); print_points(out.as_mut_ptr(), n); return 0 as libc::c_int; }" }, { "index": 175, "before": "void print_points(const point_t* points, size_t n) { for (size_t i = 0; i < n; ++i) { if (i > 0) printf(\" \"); printf(\"(%g, %g)\", points[i].x, points[i].y); } printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn print_points(mut points: *const point_t, mut n: size_t) { let mut i: size_t = 0 as libc::c_int as size_t; while i < n { if i > 0 as libc::c_int as libc::c_ulong { printf(b\" \\0\" as *const u8 as *const libc::c_char); } printf( b\"(%g, %g)\\0\" as *const u8 as *const libc::c_char, (*points.offset(i as isize)).x, (*points.offset(i as isize)).y, ); i = i.wrapping_add(1); i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 176, "before": "size_t douglas_peucker(const point_t* points, size_t n, double epsilon, point_t* dest, size_t destlen) { assert(n >= 2); assert(epsilon >= 0); double max_dist = 0; size_t index = 0; for (size_t i = 1; i + 1 < n; ++i) { double dist = perpendicular_distance(points[i], points[0], points[n - 1]); if (dist > max_dist) { max_dist = dist; index = i; } } if (max_dist > epsilon) { size_t n1 = douglas_peucker(points, index + 1, epsilon, dest, destlen); if (destlen >= n1 - 1) { destlen -= n1 - 1; dest += n1 - 1; } else { destlen = 0; } size_t n2 = douglas_peucker(points + index, n - index, epsilon, dest, destlen); return n1 + n2 - 1; } if (destlen >= 2) { dest[0] = points[0]; dest[1] = points[n - 1]; } return 2; }", "after": "pub unsafe extern \"C\" fn douglas_peucker( mut points: *const point_t, mut n: size_t, mut epsilon: libc::c_double, mut dest: *mut point_t, mut destlen: size_t, ) -> size_t { if n >= 2 as libc::c_int as libc::c_ulong {} else { __assert_fail( b\"n >= 2\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 22 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 75], &[libc::c_char; 75], >( b\"size_t douglas_peucker(const point_t *, size_t, double, point_t *, size_t)\\0\", )) .as_ptr(), ); } 'c_2158: { if n >= 2 as libc::c_int as libc::c_ulong {} else { __assert_fail( b\"n >= 2\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 22 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 75], &[libc::c_char; 75], >( b\"size_t douglas_peucker(const point_t *, size_t, double, point_t *, size_t)\\0\", )) .as_ptr(), ); } }; if epsilon >= 0 as libc::c_int as libc::c_double {} else { __assert_fail( b\"epsilon >= 0\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 23 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 75], &[libc::c_char; 75], >( b\"size_t douglas_peucker(const point_t *, size_t, double, point_t *, size_t)\\0\", )) .as_ptr(), ); } 'c_2115: { if epsilon >= 0 as libc::c_int as libc::c_double {} else { __assert_fail( b\"epsilon >= 0\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 23 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 75], &[libc::c_char; 75], >( b\"size_t douglas_peucker(const point_t *, size_t, double, point_t *, size_t)\\0\", )) .as_ptr(), ); } }; let mut max_dist: libc::c_double = 0 as libc::c_int as libc::c_double; let mut index: size_t = 0 as libc::c_int as size_t; let mut i: size_t = 1 as libc::c_int as size_t; while i.wrapping_add(1 as libc::c_int as libc::c_ulong) < n { let mut dist: libc::c_double = perpendicular_distance( *points.offset(i as isize), *points.offset(0 as libc::c_int as isize), *points.offset(n.wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize), ); if dist > max_dist { max_dist = dist; index = i; } i = i.wrapping_add(1); i; } if max_dist > epsilon { let mut n1: size_t = douglas_peucker( points, index.wrapping_add(1 as libc::c_int as libc::c_ulong), epsilon, dest, destlen, ); if destlen >= n1.wrapping_sub(1 as libc::c_int as libc::c_ulong) { destlen = (destlen as libc::c_ulong) .wrapping_sub(n1.wrapping_sub(1 as libc::c_int as libc::c_ulong)) as size_t as size_t; dest = dest .offset(n1.wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize); } else { destlen = 0 as libc::c_int as size_t; } let mut n2: size_t = douglas_peucker( points.offset(index as isize), n.wrapping_sub(index), epsilon, dest, destlen, ); return n1.wrapping_add(n2).wrapping_sub(1 as libc::c_int as libc::c_ulong); } if destlen >= 2 as libc::c_int as libc::c_ulong { *dest .offset( 0 as libc::c_int as isize, ) = *points.offset(0 as libc::c_int as isize); *dest .offset( 1 as libc::c_int as isize, ) = *points .offset(n.wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize); } return 2 as libc::c_int as size_t; }" }, { "index": 177, "before": "int is_pangram(const char *s) { \tconst char *alpha = \"\" \t\t\"abcdefghjiklmnopqrstuvwxyz\" \t\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"; \tchar ch, wasused[26] = {0}; \tint total = 0; \twhile ((ch = *s++) != '\\0') { \t\tconst char *p; \t\tint idx; \t\tif ((p = strchr(alpha, ch)) == NULL) \t\t\tcontinue; \t\tidx = (p - alpha) % 26; \t\ttotal += !wasused[idx]; \t\twasused[idx] = 1; \t\tif (total == 26) \t\t\treturn 1; \t} \treturn 0; }", "after": "pub unsafe extern \"C\" fn is_pangram(mut s: *const libc::c_char) -> libc::c_int { let mut alpha: *const libc::c_char = b\"abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\0\" as *const u8 as *const libc::c_char; let mut ch: libc::c_char = 0; let mut wasused: [libc::c_char; 26] = [ 0 as libc::c_int as libc::c_char, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut total: libc::c_int = 0 as libc::c_int; loop { let fresh0 = s; s = s.offset(1); ch = *fresh0; if !(ch as libc::c_int != '\\0' as i32) { break; } let mut p: *const libc::c_char = 0 as *const libc::c_char; let mut idx: libc::c_int = 0; p = strchr(alpha, ch as libc::c_int); if p.is_null() { continue; } idx = (p.offset_from(alpha) as libc::c_long % 26 as libc::c_int as libc::c_long) as libc::c_int; total += (wasused[idx as usize] == 0) as libc::c_int; wasused[idx as usize] = 1 as libc::c_int as libc::c_char; if total == 26 as libc::c_int { return 1 as libc::c_int; } } return 0 as libc::c_int; }" }, { "index": 178, "before": "int main(void) { \tint i; \tconst char *tests[] = { \t\t\"The quick brown fox jumps over the lazy dog.\", \t\t\"The qu1ck brown fox jumps over the lazy d0g.\" \t}; \tfor (i = 0; i < 2; i++) \t\tprintf(\"\\\"%s\\\" is %sa pangram\\n\", \t\t\ttests[i], is_pangram(tests[i])?\"\":\"not \"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut tests: [*const libc::c_char; 2] = [ b\"The quick brown fox jumps over the lazy dog.\\0\" as *const u8 as *const libc::c_char, b\"The qu1ck brown fox jumps over the lazy d0g.\\0\" as *const u8 as *const libc::c_char, ]; i = 0 as libc::c_int; while i < 2 as libc::c_int { printf( b\"\\\"%s\\\" is %sa pangram\\n\\0\" as *const u8 as *const libc::c_char, tests[i as usize], if is_pangram(tests[i as usize]) != 0 { b\"\\0\" as *const u8 as *const libc::c_char } else { b\"not \\0\" as *const u8 as *const libc::c_char }, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 179, "before": "int main() { \tvec vsq[] = {\t{0,0}, {10,0}, {10,10}, {0,10}, \t\t\t{2.5,2.5}, {7.5,0.1}, {7.5,7.5}, {2.5,7.5}}; \tpolygon_t sq = { 4, vsq }, /* outer square */ \t\tsq_hole = { 8, vsq }; /* outer and inner square, ie hole */ \tvec c = { 10, 5 }; /* on edge */ \tvec d = { 5, 5 }; \tprintf(\"%d\\n\", inside(c, &sq, 1e-10)); \tprintf(\"%d\\n\", inside(c, &sq_hole, 1e-10)); \tprintf(\"%d\\n\", inside(d, &sq, 1e-10));\t/* in */ \tprintf(\"%d\\n\", inside(d, &sq_hole, 1e-10)); /* out (in the hole) */ \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut vsq: [vec; 8] = [ { let mut init = vec { x: 0 as libc::c_int as libc::c_double, y: 0 as libc::c_int as libc::c_double, }; init }, { let mut init = vec { x: 10 as libc::c_int as libc::c_double, y: 0 as libc::c_int as libc::c_double, }; init }, { let mut init = vec { x: 10 as libc::c_int as libc::c_double, y: 10 as libc::c_int as libc::c_double, }; init }, { let mut init = vec { x: 0 as libc::c_int as libc::c_double, y: 10 as libc::c_int as libc::c_double, }; init }, { let mut init = vec { x: 2.5f64, y: 2.5f64 }; init }, { let mut init = vec { x: 7.5f64, y: 0.1f64 }; init }, { let mut init = vec { x: 7.5f64, y: 7.5f64 }; init }, { let mut init = vec { x: 2.5f64, y: 7.5f64 }; init }, ]; let mut sq: polygon_t = { let mut init = polygon_t { n: 4 as libc::c_int, v: vsq.as_mut_ptr(), }; init }; let mut sq_hole: polygon_t = { let mut init = polygon_t { n: 8 as libc::c_int, v: vsq.as_mut_ptr(), }; init }; let mut c: vec = { let mut init = vec { x: 10 as libc::c_int as libc::c_double, y: 5 as libc::c_int as libc::c_double, }; init }; let mut d: vec = { let mut init = vec { x: 5 as libc::c_int as libc::c_double, y: 5 as libc::c_int as libc::c_double, }; init }; printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, inside(c, &mut sq, 1e-10f64)); printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, inside(c, &mut sq_hole, 1e-10f64), ); printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, inside(d, &mut sq, 1e-10f64)); printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, inside(d, &mut sq_hole, 1e-10f64), ); return 0 as libc::c_int; }" }, { "index": 180, "before": "int intersect(vec x0, vec x1, vec y0, vec y1, double tol, vec *sect) { \tvec dx = vsub(x1, x0), dy = vsub(y1, y0); \tdouble d = vcross(dy, dx), a; \tif (!d) return 0; /* edges are parallel */ \ta = (vcross(x0, dx) - vcross(y0, dx)) / d; \tif (sect) \t\t*sect = vmadd(y0, a, dy); \tif (a < -tol || a > 1 + tol) return -1; \tif (a < tol || a > 1 - tol) return 0; \ta = (vcross(x0, dy) - vcross(y0, dy)) / d; \tif (a < 0 || a > 1) return -1; \treturn 1; }", "after": "pub unsafe extern \"C\" fn intersect( mut x0: vec, mut x1: vec, mut y0: vec, mut y1: vec, mut tol: libc::c_double, mut sect: *mut vec, ) -> libc::c_int { let mut dx: vec = vsub(x1, x0); let mut dy: vec = vsub(y1, y0); let mut d: libc::c_double = vcross(dy, dx); let mut a: libc::c_double = 0.; if d == 0. { return 0 as libc::c_int; } a = (vcross(x0, dx) - vcross(y0, dx)) / d; if !sect.is_null() { *sect = vmadd(y0, a, dy); } if a < -tol || a > 1 as libc::c_int as libc::c_double + tol { return -(1 as libc::c_int); } if a < tol || a > 1 as libc::c_int as libc::c_double - tol { return 0 as libc::c_int; } a = (vcross(x0, dy) - vcross(y0, dy)) / d; if a < 0 as libc::c_int as libc::c_double || a > 1 as libc::c_int as libc::c_double { return -(1 as libc::c_int); } return 1 as libc::c_int; }" }, { "index": 181, "before": "int inside(vec v, polygon p, double tol) { \t/* should assert p->n > 1 */ \tint i, k, crosses, intersectResult; \tvec *pv; \tdouble min_x, max_x, min_y, max_y; \tfor (i = 0; i < p->n; i++) { \t\tk = (i + 1) % p->n; \t\tmin_x = dist(v, p->v[i], p->v[k], tol); \t\tif (min_x < tol) return 0; \t} \tmin_x = max_x = p->v[0].x; \tmin_y = max_y = p->v[1].y; \t/* calculate extent of polygon */ \tfor_v(i, pv, p) { \t\tif (pv->x > max_x) max_x = pv->x; \t\tif (pv->x < min_x) min_x = pv->x; \t\tif (pv->y > max_y) max_y = pv->y; \t\tif (pv->y < min_y) min_y = pv->y; \t} \tif (v.x < min_x || v.x > max_x || v.y < min_y || v.y > max_y) \t\treturn -1; \tmax_x -= min_x; max_x *= 2; \tmax_y -= min_y; max_y *= 2; \tmax_x += max_y; \tvec e; \twhile (1) { \t\tcrosses = 0; \t\t/* pick a rand point far enough to be outside polygon */ \t\te.x = v.x + (1 + rand() / (RAND_MAX + 1.)) * max_x; \t\te.y = v.y + (1 + rand() / (RAND_MAX + 1.)) * max_x; \t\tfor (i = 0; i < p->n; i++) { \t\t\tk = (i + 1) % p->n; \t\t\tintersectResult = intersect(v, e, p->v[i], p->v[k], tol, 0); \t\t\t/* picked a bad point, ray got too close to vertex. \t\t\t re-pick */ \t\t\tif (!intersectResult) break; \t\t\tif (intersectResult == 1) crosses++; \t\t} \t\tif (i == p->n) break; \t} \treturn (crosses & 1) ? 1 : -1; }", "after": "pub unsafe extern \"C\" fn inside( mut v: vec, mut p: polygon, mut tol: libc::c_double, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut k: libc::c_int = 0; let mut crosses: libc::c_int = 0; let mut intersectResult: libc::c_int = 0; let mut pv: *mut vec = 0 as *mut vec; let mut min_x: libc::c_double = 0.; let mut max_x: libc::c_double = 0.; let mut min_y: libc::c_double = 0.; let mut max_y: libc::c_double = 0.; i = 0 as libc::c_int; while i < (*p).n { k = (i + 1 as libc::c_int) % (*p).n; min_x = dist(v, *((*p).v).offset(i as isize), *((*p).v).offset(k as isize), tol); if min_x < tol { return 0 as libc::c_int; } i += 1; i; } max_x = (*((*p).v).offset(0 as libc::c_int as isize)).x; min_x = max_x; max_y = (*((*p).v).offset(1 as libc::c_int as isize)).y; min_y = max_y; i = 0 as libc::c_int; pv = (*p).v; while i < (*p).n { if (*pv).x > max_x { max_x = (*pv).x; } if (*pv).x < min_x { min_x = (*pv).x; } if (*pv).y > max_y { max_y = (*pv).y; } if (*pv).y < min_y { min_y = (*pv).y; } i += 1; i; pv = pv.offset(1); pv; } if v.x < min_x || v.x > max_x || v.y < min_y || v.y > max_y { return -(1 as libc::c_int); } max_x -= min_x; max_x *= 2 as libc::c_int as libc::c_double; max_y -= min_y; max_y *= 2 as libc::c_int as libc::c_double; max_x += max_y; let mut e: vec = vec { x: 0., y: 0. }; loop { crosses = 0 as libc::c_int; e .x = v.x + (1 as libc::c_int as libc::c_double + rand() as libc::c_double / (2147483647 as libc::c_int as libc::c_double + 1.0f64)) * max_x; e .y = v.y + (1 as libc::c_int as libc::c_double + rand() as libc::c_double / (2147483647 as libc::c_int as libc::c_double + 1.0f64)) * max_x; i = 0 as libc::c_int; while i < (*p).n { k = (i + 1 as libc::c_int) % (*p).n; intersectResult = intersect( v, e, *((*p).v).offset(i as isize), *((*p).v).offset(k as isize), tol, 0 as *mut vec, ); if intersectResult == 0 { break; } if intersectResult == 1 as libc::c_int { crosses += 1; crosses; } i += 1; i; } if i == (*p).n { break; } } return if crosses & 1 as libc::c_int != 0 { 1 as libc::c_int } else { -(1 as libc::c_int) }; }" }, { "index": 182, "before": "vec vmadd(vec a, double s, vec b) { \tvec c; \tc.x = a.x + s * b.x; \tc.y = a.y + s * b.y; \treturn c; }", "after": "pub unsafe extern \"C\" fn vmadd(mut a: vec, mut s: libc::c_double, mut b: vec) -> vec { let mut c: vec = vec { x: 0., y: 0. }; c.x = a.x + s * b.x; c.y = a.y + s * b.y; return c; }" }, { "index": 183, "before": "double dist(vec x, vec y0, vec y1, double tol) { \tvec dy = vsub(y1, y0); \tvec x1, s; \tint r; \tx1.x = x.x + dy.y; x1.y = x.y - dy.x; \tr = intersect(x, x1, y0, y1, tol, &s); \tif (r == -1) return HUGE_VAL; \ts = vsub(s, x); \treturn sqrt(vdot(s, s)); }", "after": "pub unsafe extern \"C\" fn dist( mut x: vec, mut y0: vec, mut y1: vec, mut tol: libc::c_double, ) -> libc::c_double { let mut dy: vec = vsub(y1, y0); let mut x1: vec = vec { x: 0., y: 0. }; let mut s: vec = vec { x: 0., y: 0. }; let mut r: libc::c_int = 0; x1.x = x.x + dy.y; x1.y = x.y - dy.x; r = intersect(x, x1, y0, y1, tol, &mut s); if r == -(1 as libc::c_int) { return ::core::f64::INFINITY; } s = vsub(s, x); return sqrt(vdot(s, s)); }" }, { "index": 184, "before": "int main() { test(100000000000000.01, 100000000000000.011); test(100.01, 100.011); test(10000000000000.001 / 10000.0, 1000000000.0000001000); test(0.001, 0.0010000001); test(0.000000000000000000000101, 0.0); test(sqrt(2.0) * sqrt(2.0), 2.0); test(-sqrt(2.0) * sqrt(2.0), -2.0); test(3.14159265358979323846, 3.14159265358979324); return 0; }", "after": "unsafe fn main() -> libc::c_int { test(100000000000000.01f64, 100000000000000.011f64); test(100.01f64, 100.011f64); test(10000000000000.001f64 / 10000.0f64, 1000000000.0000001000f64); test(0.001f64, 0.0010000001f64); test(0.000000000000000000000101f64, 0.0f64); test(sqrt(2.0f64) * sqrt(2.0f64), 2.0f64); test(-sqrt(2.0f64) * sqrt(2.0f64), -2.0f64); test(3.14159265358979323846f64, 3.14159265358979324f64); return 0 as libc::c_int; }" }, { "index": 185, "before": "bool approxEquals(double value, double other, double epsilon) { return fabs(value - other) < epsilon; }", "after": "pub unsafe extern \"C\" fn approxEquals( mut value: libc::c_double, mut other: libc::c_double, mut epsilon: libc::c_double, ) -> bool { return fabs(value - other) < epsilon; }" }, { "index": 186, "before": "void test(double a, double b) { double epsilon = 1e-18; printf(\"%f, %f => %d\\n\", a, b, approxEquals(a, b, epsilon)); }", "after": "pub unsafe extern \"C\" fn test(mut a: libc::c_double, mut b: libc::c_double) { let mut epsilon: libc::c_double = 1e-18f64; printf( b\"%f, %f => %d\\n\\0\" as *const u8 as *const libc::c_char, a, b, approxEquals(a, b, epsilon) as libc::c_int, ); }" }, { "index": 187, "before": "void placePieces(const char *pieces, bool isPawn) { int n, r, c; int numToPlace = rand() % strlen(pieces); for (n = 0; n < numToPlace; ++n) { do { r = rand() % 8; c = rand() % 8; } while (grid[r][c] != 0 || (isPawn && (r == 7 || r == 0))); grid[r][c] = pieces[n]; } }", "after": "pub unsafe extern \"C\" fn placePieces( mut pieces: *const libc::c_char, mut isPawn: bool_0, ) { let mut n: libc::c_int = 0; let mut r: libc::c_int = 0; let mut c: libc::c_int = 0; let mut numToPlace: libc::c_int = (rand() as libc::c_ulong) .wrapping_rem(strlen(pieces)) as libc::c_int; n = 0 as libc::c_int; while n < numToPlace { loop { r = rand() % 8 as libc::c_int; c = rand() % 8 as libc::c_int; if !(grid[r as usize][c as usize] as libc::c_int != 0 as libc::c_int || isPawn != 0 && (r == 7 as libc::c_int || r == 0 as libc::c_int)) { break; } } grid[r as usize][c as usize] = *pieces.offset(n as isize); n += 1; n; } }" }, { "index": 188, "before": "int main() { srand(time(NULL)); createFen(); return 0; }", "after": "unsafe fn main() -> libc::c_int { srand(time(0 as *mut time_t) as libc::c_uint); createFen(); return 0 as libc::c_int; }" }, { "index": 189, "before": "void placeKings() { int r1, r2, c1, c2; for (;;) { r1 = rand() % 8; c1 = rand() % 8; r2 = rand() % 8; c2 = rand() % 8; if (r1 != r2 && abs(r1 - r2) > 1 && abs(c1 - c2) > 1) { grid[r1][c1] = 'K'; grid[r2][c2] = 'k'; return; } } }", "after": "pub unsafe extern \"C\" fn placeKings() { let mut r1: libc::c_int = 0; let mut r2: libc::c_int = 0; let mut c1: libc::c_int = 0; let mut c2: libc::c_int = 0; loop { r1 = rand() % 8 as libc::c_int; c1 = rand() % 8 as libc::c_int; r2 = rand() % 8 as libc::c_int; c2 = rand() % 8 as libc::c_int; if r1 != r2 && abs(r1 - r2) > 1 as libc::c_int && abs(c1 - c2) > 1 as libc::c_int { grid[r1 as usize][c1 as usize] = 'K' as i32 as libc::c_char; grid[r2 as usize][c2 as usize] = 'k' as i32 as libc::c_char; return; } }; }" }, { "index": 190, "before": "void toFen() { char fen[80], ch; int r, c, countEmpty = 0, index = 0; for (r = 0; r < 8; ++r) { for (c = 0; c < 8; ++c) { ch = grid[r][c]; printf(\"%2c \", ch == 0 ? '.' : ch); if (ch == 0) { countEmpty++; } else { if (countEmpty > 0) { fen[index++] = countEmpty + 48; countEmpty = 0; } fen[index++] = ch; } } if (countEmpty > 0) { fen[index++] = countEmpty + 48; countEmpty = 0; } fen[index++]= '/'; printf(\"\\n\"); } strcpy(fen + index, \" w - - 0 1\"); printf(\"%s\\n\", fen); }", "after": "pub unsafe extern \"C\" fn toFen() { let mut fen: [libc::c_char; 80] = [0; 80]; let mut ch: libc::c_char = 0; let mut r: libc::c_int = 0; let mut c: libc::c_int = 0; let mut countEmpty: libc::c_int = 0 as libc::c_int; let mut index: libc::c_int = 0 as libc::c_int; r = 0 as libc::c_int; while r < 8 as libc::c_int { c = 0 as libc::c_int; while c < 8 as libc::c_int { ch = grid[r as usize][c as usize]; printf( b\"%2c \\0\" as *const u8 as *const libc::c_char, if ch as libc::c_int == 0 as libc::c_int { '.' as i32 } else { ch as libc::c_int }, ); if ch as libc::c_int == 0 as libc::c_int { countEmpty += 1; countEmpty; } else { if countEmpty > 0 as libc::c_int { let fresh0 = index; index = index + 1; fen[fresh0 as usize] = (countEmpty + 48 as libc::c_int) as libc::c_char; countEmpty = 0 as libc::c_int; } let fresh1 = index; index = index + 1; fen[fresh1 as usize] = ch; } c += 1; c; } if countEmpty > 0 as libc::c_int { let fresh2 = index; index = index + 1; fen[fresh2 as usize] = (countEmpty + 48 as libc::c_int) as libc::c_char; countEmpty = 0 as libc::c_int; } let fresh3 = index; index = index + 1; fen[fresh3 as usize] = '/' as i32 as libc::c_char; printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); r += 1; r; } strcpy( fen.as_mut_ptr().offset(index as isize), b\" w - - 0 1\\0\" as *const u8 as *const libc::c_char, ); printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, fen.as_mut_ptr()); }" }, { "index": 191, "before": "int main(void){ unsigned i, j, k, choice, winsbyswitch=0, door[3]; srand(time(NULL)); //initialize random seed. for(i=0; i libc::c_int { let mut i: libc::c_uint = 0; let mut j: libc::c_uint = 0; let mut k: libc::c_uint = 0; let mut choice: libc::c_uint = 0; let mut winsbyswitch: libc::c_uint = 0 as libc::c_int as libc::c_uint; let mut door: [libc::c_uint; 3] = [0; 3]; srand(time(0 as *mut time_t) as libc::c_uint); i = 0 as libc::c_int as libc::c_uint; while i < 3000000 as libc::c_int as libc::c_uint { door[0 as libc::c_int as usize] = (if rand() % 2 as libc::c_int == 0 { 1 as libc::c_int } else { 0 as libc::c_int }) as libc::c_uint; if door[0 as libc::c_int as usize] != 0 { door[2 as libc::c_int as usize] = 0 as libc::c_int as libc::c_uint; door[1 as libc::c_int as usize] = door[2 as libc::c_int as usize]; } else { door[1 as libc::c_int as usize] = (if rand() % 2 as libc::c_int == 0 { 1 as libc::c_int } else { 0 as libc::c_int }) as libc::c_uint; door[2 as libc::c_int as usize] = (if door[1 as libc::c_int as usize] == 0 { 1 as libc::c_int } else { 0 as libc::c_int }) as libc::c_uint; } choice = (rand() % 3 as libc::c_int) as libc::c_uint; if door[choice .wrapping_add(1 as libc::c_int as libc::c_uint) .wrapping_rem(3 as libc::c_int as libc::c_uint) as usize] == 0 && door[choice .wrapping_add(2 as libc::c_int as libc::c_uint) .wrapping_rem(3 as libc::c_int as libc::c_uint) as usize] != 0 || door[choice .wrapping_add(2 as libc::c_int as libc::c_uint) .wrapping_rem(3 as libc::c_int as libc::c_uint) as usize] == 0 && door[choice .wrapping_add(1 as libc::c_int as libc::c_uint) .wrapping_rem(3 as libc::c_int as libc::c_uint) as usize] != 0 { winsbyswitch = winsbyswitch.wrapping_add(1); winsbyswitch; } i = i.wrapping_add(1); i; } printf( b\"\\nAfter %u games, I won %u by switching. That is %f%%. \\0\" as *const u8 as *const libc::c_char, 3000000 as libc::c_int, winsbyswitch, winsbyswitch as libc::c_float as libc::c_double * 100.0f64 / i as libc::c_float as libc::c_double, ); return 0; }" }, { "index": 192, "before": "int main() { const char *fruit[2] = { \"apples\", \"oranges\" }; // Acquire the length of the array by dividing the size of all elements (found // with sizeof(fruit)) by the size of the first element. // Note that since the array elements are pointers to null-terminated character // arrays, the size of the first element is actually the size of the pointer // type - not the length of the string. // This size, regardless of the type being pointed to, is 8 bytes, 4 bytes, or // 2 bytes on 64-bit, 32-bit, or 16-bit platforms respectively. int length = sizeof(fruit) / sizeof(fruit[0]); printf(\"%d\\n\", length); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut fruit: [*const libc::c_char; 2] = [ b\"apples\\0\" as *const u8 as *const libc::c_char, b\"oranges\\0\" as *const u8 as *const libc::c_char, ]; let mut length: libc::c_int = (::core::mem::size_of::<[*const libc::c_char; 2]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong) as libc::c_int; printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, length); return 0 as libc::c_int; }" }, { "index": 193, "before": "int main() { int i, j; double degrees[] = { 0.0, 16.87, 16.88, 33.75, 50.62, 50.63, 67.5, 84.37, 84.38, 101.25, 118.12, 118.13, 135.0, 151.87, 151.88, 168.75, 185.62, 185.63, 202.5, 219.37, 219.38, 236.25, 253.12, 253.13, 270.0, 286.87, 286.88, 303.75, 320.62, 320.63, 337.5, 354.37, 354.38 }; const char * names = \"North \" \"North by east \" \"North-northeast \" \"Northeast by north \" \"Northeast \" \"Northeast by east \" \"East-northeast \" \"East by north \" \"East \" \"East by south \" \"East-southeast \" \"Southeast by east \" \"Southeast \" \"Southeast by south \" \"South-southeast \" \"South by east \" \"South \" \"South by west \" \"South-southwest \" \"Southwest by south \" \"Southwest \" \"Southwest by west \" \"West-southwest \" \"West by south \" \"West \" \"West by north \" \"West-northwest \" \"Northwest by west \" \"Northwest \" \"Northwest by north \" \"North-northwest \" \"North by west \" \"North \"; for (i = 0; i < 33; i++) { j = .5 + degrees[i] * 32 / 360; printf(\"%2d %.22s %6.2f\\n\", (j % 32) + 1, names + (j % 32) * 22, degrees[i]); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut degrees: [libc::c_double; 33] = [ 0.0f64, 16.87f64, 16.88f64, 33.75f64, 50.62f64, 50.63f64, 67.5f64, 84.37f64, 84.38f64, 101.25f64, 118.12f64, 118.13f64, 135.0f64, 151.87f64, 151.88f64, 168.75f64, 185.62f64, 185.63f64, 202.5f64, 219.37f64, 219.38f64, 236.25f64, 253.12f64, 253.13f64, 270.0f64, 286.87f64, 286.88f64, 303.75f64, 320.62f64, 320.63f64, 337.5f64, 354.37f64, 354.38f64, ]; let mut names: *const libc::c_char = b\"North North by east North-northeast Northeast by north Northeast Northeast by east East-northeast East by north East East by south East-southeast Southeast by east Southeast Southeast by south South-southeast South by east South South by west South-southwest Southwest by south Southwest Southwest by west West-southwest West by south West West by north West-northwest Northwest by west Northwest Northwest by north North-northwest North by west North \\0\" as *const u8 as *const libc::c_char; i = 0 as libc::c_int; while i < 33 as libc::c_int { j = (0.5f64 + degrees[i as usize] * 32 as libc::c_int as libc::c_double / 360 as libc::c_int as libc::c_double) as libc::c_int; printf( b\"%2d %.22s %6.2f\\n\\0\" as *const u8 as *const libc::c_char, j % 32 as libc::c_int + 1 as libc::c_int, names.offset((j % 32 as libc::c_int * 22 as libc::c_int) as isize), degrees[i as usize], ); i += 1; i; } return 0 as libc::c_int; }" } ]