|
[ |
|
{ |
|
"index": 0, |
|
"before": "void rat_approx(double f, int64_t md, int64_t *num, int64_t *denom) { \t/* a: continued fraction coefficients. */ \tint64_t a, h[3] = { 0, 1, 0 }, k[3] = { 1, 0, 0 }; \tint64_t x, d, n = 1; \tint i, neg = 0; \tif (md <= 1) { *denom = 1; *num = (int64_t) f; return; } \tif (f < 0) { neg = 1; f = -f; } \twhile (f != floor(f)) { n <<= 1; f *= 2; } \td = f; \t/* continued fraction and check denominator each step */ \tfor (i = 0; i < 64; i++) { \t\ta = n ? d / n : 0; \t\tif (i && !a) break; \t\tx = d; d = n; n = x % n; \t\tx = a; \t\tif (k[1] * a + k[0] >= md) { \t\t\tx = (md - k[0]) / k[1]; \t\t\tif (x * 2 >= a || k[1] >= md) \t\t\t\ti = 65; \t\t\telse \t\t\t\tbreak; \t\t} \t\th[2] = x * h[1] + h[0]; h[0] = h[1]; h[1] = h[2]; \t\tk[2] = x * k[1] + k[0]; k[0] = k[1]; k[1] = k[2]; \t} \t*denom = k[1]; \t*num = neg ? -h[1] : h[1]; }", |
|
"after": "pub extern \"C\" fn rat_approx(mut f: f64, mut md: i64, mut num: *mut i64, mut denom: *mut i64) { unsafe { let mut a: i64 = 0; let mut h: [i64; 3] = [0, 1, 0]; let mut k: [i64; 3] = [1, 0, 0]; let mut x: i64 = 0; let mut d: i64 = 0; let mut n: i64 = 1; let mut i: i32 = 0; let mut neg: i32 = 0; if md <= 1 { *denom = 1; *num = f as i64; return; } if f < 0 as f64 { neg = 1; f = -f; } while f != floor(f) { n <<= 1; f *= 2 as f64; } d = f as i64; i = 0; while i < 64 { a = if n != 0 { d / n } else { 0 }; if i != 0 && a == 0 { break; } x = d; d = n; n = x % n; x = a; if k[1 as usize] * a + k[0 as usize] >= md { x = (md - k[0 as usize]) / k[1 as usize]; if !(x * 2 >= a || k[1 as usize] >= md) { break; } i = 65; } h[2 as usize] = x * h[1 as usize] + h[0 as usize]; h[0 as usize] = h[1 as usize]; h[1 as usize] = h[2 as usize]; k[2 as usize] = x * k[1 as usize] + k[0 as usize]; k[0 as usize] = k[1 as usize]; k[1 as usize] = k[2 as usize]; i += 1; i; } *denom = k[1 as usize]; *num = if neg != 0 { -h[1 as usize] } else { h[1 as usize] }; } }" |
|
}, |
|
{ |
|
"index": 1, |
|
"before": "int main() { \tint i; \tint64_t d, n; \tdouble f; \tprintf(\"f = %16.14f\\n\", f = 1.0/7); \tfor (i = 1; i <= 20000000; i *= 16) { \t\tprintf(\"denom <= %d: \", i); \t\trat_approx(f, i, &n, &d); \t\tprintf(\"%lld/%lld\\n\", n, d); \t} \tprintf(\"\\nf = %16.14f\\n\", f = atan2(1,1) * 4); \tfor (i = 1; i <= 20000000; i *= 16) { \t\tprintf(\"denom <= %d: \", i); \t\trat_approx(f, i, &n, &d); \t\tprintf(\"%lld/%lld\\n\", n, d); \t} \treturn 0; }", |
|
"after": "fn main() -> i32 { let mut i: i32 = 0; let mut d: i64 = 0; let mut n: i64 = 0; let mut f: f64 = 0.; f = 1.0f64 / 7 as f64; print!(\"f = {:16.14}\\n\", f); i = 1; while i <= 20000000 { print!(\"denom <= {}: \", i); rat_approx(f, i as i64, &mut n, &mut d); print!(\"{}/{}\\n\", n, d); i *= 16; } unsafe { f = atan2(1 as f64, 1 as f64) * 4 as f64; } print!(\"\\nf = {:16.14}\\n\", f); i = 1; while i <= 20000000 { print!(\"denom <= {}: \", i); rat_approx(f, i as i64, &mut n, &mut d); print!(\"{}/{}\\n\", n, d); i *= 16; } return 0; }" |
|
}, |
|
{ |
|
"index": 2, |
|
"before": "void push (heap_t *h, int priority, char *data) { if (h->len + 1 >= h->size) { h->size = h->size ? h->size * 2 : 4; h->nodes = (node_t *)realloc(h->nodes, h->size * sizeof (node_t)); } int i = h->len + 1; int j = i / 2; while (i > 1 && h->nodes[j].priority > priority) { h->nodes[i] = h->nodes[j]; i = j; j = j / 2; } h->nodes[i].priority = priority; h->nodes[i].data = data; h->len++; }", |
|
"after": "pub extern \"C\" fn push(mut h: *mut heap_t, mut priority: i32, mut data: *mut i8) { unsafe { if (*h).len + 1 >= (*h).size { (*h).size = if (*h).size != 0 { (*h).size * 2 } else { 4 }; (*h).nodes = realloc( (*h).nodes as *mut libc::c_void, ((*h).size as u64).wrapping_mul(::core::mem::size_of::<node_t>() as u64), ) as *mut node_t; } let mut i: i32 = (*h).len + 1; let mut j: i32 = i / 2; while i > 1 && (*((*h).nodes).offset(j as isize)).priority > priority { *((*h).nodes).offset(i as isize) = *((*h).nodes).offset(j as isize); i = j; j = j / 2; } (*((*h).nodes).offset(i as isize)).priority = priority; let ref mut fresh0 = (*((*h).nodes).offset(i as isize)).data; *fresh0 = data; (*h).len += 1; (*h).len; } }" |
|
}, |
|
{ |
|
"index": 3, |
|
"before": "int main () { heap_t *h = (heap_t *)calloc(1, sizeof (heap_t)); push(h, 3, \"Clear drains\"); push(h, 4, \"Feed cat\"); push(h, 5, \"Make tea\"); push(h, 1, \"Solve RC tasks\"); push(h, 2, \"Tax return\"); int i; for (i = 0; i < 5; i++) { printf(\"%s\\n\", pop(h)); } return 0; }", |
|
"after": "fn main() -> i32 { unsafe { let mut h: *mut heap_t = calloc(1, ::core::mem::size_of::<heap_t>() as u64) as *mut heap_t; push(h, 3, b\"Clear drains\\0\" as *const u8 as *const i8 as *mut i8); push(h, 4, b\"Feed cat\\0\" as *const u8 as *const i8 as *mut i8); push(h, 5, b\"Make tea\\0\" as *const u8 as *const i8 as *mut i8); push( h, 1, b\"Solve RC tasks\\0\" as *const u8 as *const i8 as *mut i8, ); push(h, 2, b\"Tax return\\0\" as *const u8 as *const i8 as *mut i8); let mut i: i32 = 0; i = 0; while i < 5 { print!(\"{}\\n\", build_str_from_raw_ptr(pop(h) as *mut u8)); i += 1; i; } return 0; } }" |
|
}, |
|
{ |
|
"index": 4, |
|
"before": "bool elem(int *a, size_t n, int e) { for (size_t i = 0; i < n; ++i) if (a[i] == e) return true; return false; }", |
|
"after": "pub extern \"C\" fn elem(mut a: *mut i32, mut n: u64, mut e: i32) -> bool { unsafe { let mut i: u64 = 0; while i < n { if *a.offset(i as isize) == e { return 1 != 0; } i = i.wrapping_add(1); i; } return 0 != 0; } }" |
|
}, |
|
{ |
|
"index": 5, |
|
"before": "int main(void) { int a[] = {1, 2, 1, 4, 5, 2, 15, 1, 3, 4}; int *b; size_t n = nub_new(&b, a, sizeof(a) / sizeof(a[0])); for (size_t i = 0; i < n; ++i) printf(\"%d \", b[i]); puts(\"\"); free(b); return 0; }", |
|
"after": "fn main() -> i32 { unsafe { let mut a: [i32; 10] = [1, 2, 1, 4, 5, 2, 15, 1, 3, 4]; let mut b: *mut i32 = 0 as *mut i32; let mut n: u64 = nub_new( &mut b, a.as_mut_ptr(), (::core::mem::size_of::<[i32; 10]>() as u64) .wrapping_div(::core::mem::size_of::<i32>() as u64), ); let mut i: u64 = 0; while i < n { print!(\"{} \", *b.offset(i as isize)); i = i.wrapping_add(1); i; } puts(b\"\\0\" as *const u8 as *const i8); free(b as *mut libc::c_void); return 0; } }" |
|
}, |
|
{ |
|
"index": 6, |
|
"before": "size_t nub_new(int **b, int *a, size_t n) { int *c = malloc(n * sizeof(int)); memcpy(c, a, n * sizeof(int)); int m = nub(c, n); *b = malloc(m * sizeof(int)); memcpy(*b, c, m * sizeof(int)); free(c); return m; }", |
|
"after": "pub extern \"C\" fn nub_new(mut b: *mut *mut i32, mut a: *mut i32, mut n: u64) -> u64 { unsafe { let mut c: *mut i32 = malloc(n.wrapping_mul(::core::mem::size_of::<i32>() as u64)) as *mut i32; memcpy( c as *mut libc::c_void, a as *const libc::c_void, n.wrapping_mul(::core::mem::size_of::<i32>() as u64), ); let mut m: i32 = nub(c, n) as i32; *b = malloc((m as u64).wrapping_mul(::core::mem::size_of::<i32>() as u64)) as *mut i32; memcpy( *b as *mut libc::c_void, c as *const libc::c_void, (m as u64).wrapping_mul(::core::mem::size_of::<i32>() as u64), ); free(c as *mut libc::c_void); return m as u64; } }" |
|
}, |
|
{ |
|
"index": 7, |
|
"before": "size_t nub(int *a, size_t n) { size_t m = 0; for (size_t i = 0; i < n; ++i) if (!elem(a, m, a[i])) a[m++] = a[i]; return m; }", |
|
"after": "pub extern \"C\" fn nub(mut a: *mut i32, mut n: u64) -> u64 { unsafe { let mut m: u64 = 0; let mut i: u64 = 0; while i < n { if !elem(a, m, *a.offset(i as isize)) { let fresh0 = m; m = m.wrapping_add(1); *a.offset(fresh0 as isize) = *a.offset(i as isize); } i = i.wrapping_add(1); i; } return m; } }" |
|
}, |
|
{ |
|
"index": 8, |
|
"before": "int main(){ \tprintf(\"\\nLongest common prefix : %s\",lcp(3,\"interspecies\",\"interstellar\",\"interstate\")); printf(\"\\nLongest common prefix : %s\",lcp(2,\"throne\",\"throne\")); printf(\"\\nLongest common prefix : %s\",lcp(2,\"throne\",\"dungeon\")); printf(\"\\nLongest common prefix : %s\",lcp(3,\"throne\",\"\",\"throne\")); printf(\"\\nLongest common prefix : %s\",lcp(1,\"cheese\")); printf(\"\\nLongest common prefix : %s\",lcp(1,\"\")); printf(\"\\nLongest common prefix : %s\",lcp(0,NULL)); printf(\"\\nLongest common prefix : %s\",lcp(2,\"prefix\",\"suffix\")); printf(\"\\nLongest common prefix : %s\",lcp(2,\"foo\",\"foobar\")); \treturn 0; }", |
|
"after": "fn main() -> i32 { unsafe { print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr( lcp(3, \"interspecies\\0\", \"interstellar\\0\", \"interstate\\0\",) as *mut u8 ) ); print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr(lcp(2, \"throne\\0\", \"throne\\0\",) as *mut u8) ); print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr(lcp(2, \"throne\\0\", \"dungeon\\0\",) as *mut u8) ); print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr(lcp(3, \"throne\\0\", \"\\0\", \"throne\\0\",) as *mut u8) ); print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr(lcp(1, \"cheese\\0\") as *mut u8) ); print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr(lcp(1, \"\\0\") as *mut u8) ); print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr(lcp(0, 0 as *mut libc::c_void) as *mut u8) ); print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr(lcp(2, \"prefix\\0\", \"suffix\\0\",) as *mut u8) ); print!( \"\\nLongest common prefix : {}\", build_str_from_raw_ptr(lcp(2, \"foo\\0\", \"foobar\\0\",) as *mut u8) ); } return 0; }" |
|
}, |
|
{ |
|
"index": 9, |
|
"before": "int main(void) { \tint i, c, k; \tfor (k = 1; k <= 5; k++) { \t\tprintf(\"k = %d:\", k); \t\tfor (i = 2, c = 0; c < 10; i++) \t\t\tif (kprime(i, k)) { \t\t\t\tprintf(\" %d\", i); \t\t\t\tc++; \t\t\t} \t\tputchar('\\n'); \t} \treturn 0; }", |
|
"after": "fn main() -> i32 { let mut i: i32 = 0; let mut c: i32 = 0; let mut k: i32 = 0; k = 1; while k <= 5 { print!(\"k = {}:\", k); i = 2; c = 0; while c < 10 { if kprime(i, k) != 0 { print!(\" {}\", i); c += 1; c; } i += 1; i; } print!(\"{}\", '\\n' as i32); k += 1; k; } return 0; }" |
|
}, |
|
{ |
|
"index": 10, |
|
"before": "int kprime(int n, int k) { \tint p, f = 0; \tfor (p = 2; f < k && p*p <= n; p++) \t\twhile (0 == n % p) \t\t\tn /= p, f++; \treturn f + (n > 1) == k; }", |
|
"after": "pub extern \"C\" fn kprime(mut n: i32, mut k: i32) -> i32 { let mut p: i32 = 0; let mut f: i32 = 0; p = 2; while f < k && p * p <= n { while 0 == n % p { n /= p; f += 1; f; } p += 1; p; } return (f + (n > 1i32) as i32 == k) as i32; }" |
|
}, |
|
{ |
|
"index": 11, |
|
"before": "int main(int argc, char** argv) { \tint i,j,sandPileEdge, centerPileHeight, processAgain = 1,top,down,left,right;\t \tint** sandPile; \tchar* fileName; \tstatic unsigned char colour[3]; \tif(argc!=3){ \t\tprintf(\"Usage: %s <Sand pile side> <Center pile height>\",argv[0]); \t\treturn 0; \t} \tsandPileEdge = atoi(argv[1]); \tcenterPileHeight = atoi(argv[2]); \tif(sandPileEdge<=0 || centerPileHeight<=0){ \t\tprintf(\"Sand pile and center pile dimensions must be positive integers.\"); \t\treturn 0; \t} \tsandPile = (int**)malloc(sandPileEdge * sizeof(int*)); \tfor(i=0;i<sandPileEdge;i++){ \t\tsandPile[i] = (int*)calloc(sandPileEdge,sizeof(int)); \t} \tsandPile[sandPileEdge/2][sandPileEdge/2] = centerPileHeight; \tprintf(\"Initial sand pile :\\n\\n\"); \tfor(i=0;i<sandPileEdge;i++){ \t\tfor(j=0;j<sandPileEdge;j++){ \t\t\tprintf(\"%3d\",sandPile[i][j]); \t\t} \t\tprintf(\"\\n\"); \t} \twhile(processAgain == 1){ \t\tprocessAgain = 0; \t\ttop = 0; \t\tdown = 0; \t\tleft = 0; \t\tright = 0; \t\tfor(i=0;i<sandPileEdge;i++){ \t\t\tfor(j=0;j<sandPileEdge;j++){ \t\t\t\tif(sandPile[i][j]>=4){\t\t\t\t \t\t\t\t\tif(i-1>=0){ \t\t\t\t\t\ttop = 1; \t\t\t\t\t\tsandPile[i-1][j]+=1; \t\t\t\t\t\tif(sandPile[i-1][j]>=4) \t\t\t\t\t\t\tprocessAgain = 1; \t\t\t\t\t} \t\t\t\t\tif(i+1<sandPileEdge){ \t\t\t\t\t\tdown = 1; \t\t\t\t\t\tsandPile[i+1][j]+=1; \t\t\t\t\t\tif(sandPile[i+1][j]>=4) \t\t\t\t\t\t\tprocessAgain = 1; \t\t\t\t\t} \t\t\t\t\tif(j-1>=0){ \t\t\t\t\t\tleft = 1; \t\t\t\t\t\tsandPile[i][j-1]+=1; \t\t\t\t\t\tif(sandPile[i][j-1]>=4) \t\t\t\t\t\t\tprocessAgain = 1; \t\t\t\t\t} \t\t\t\t\tif(j+1<sandPileEdge){ \t\t\t\t\t\tright = 1; \t\t\t\t\t\tsandPile[i][j+1]+=1; \t\t\t\t\t\tif(sandPile[i][j+1]>=4) \t\t\t\t\t\t\tprocessAgain = 1; \t\t\t\t\t} \t\t\t\tsandPile[i][j] -= (top + down + left + right); \t\t\t\tif(sandPile[i][j]>=4) \t\t\t\t\tprocessAgain = 1; \t\t\t\t} \t\t\t} \t\t} \t} \tprintf(\"Final sand pile : \\n\\n\"); \tfor(i=0;i<sandPileEdge;i++){ \t\tfor(j=0;j<sandPileEdge;j++){ \t\t\tprintf(\"%3d\",sandPile[i][j]); \t\t} \t\tprintf(\"\\n\"); \t} \tfileName = (char*)malloc((strlen(argv[1]) + strlen(argv[2]) + 23)*sizeof(char)); \tstrcpy(fileName,\"Final_Sand_Pile_\"); \tstrcat(fileName,argv[1]); \tstrcat(fileName,\"_\"); \tstrcat(fileName,argv[2]); \tstrcat(fileName,\".ppm\"); \tFILE *fp = fopen(fileName,\"wb\"); \tfprintf(fp,\"P6\\n%d %d\\n255\\n\",sandPileEdge,sandPileEdge); \tfor(i=0;i<sandPileEdge;i++){ \t\tfor(j=0;j<sandPileEdge;j++){ \t\t\tcolour[0] = (sandPile[i][j] + i)%256; \t\t\tcolour[1] = (sandPile[i][j] + j)%256; \t\t\tcolour[2] = (sandPile[i][j] + i*j)%256; \t\t\tfwrite(colour,1,3,fp); \t\t} \t} \tfclose(fp); \tprintf(\"\\nImage file written to %s\\n\",fileName); \treturn 0; }", |
|
"after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut sandPileEdge: i32 = 0; let mut centerPileHeight: i32 = 0; let mut processAgain: i32 = 1; let mut top: i32 = 0; let mut down: i32 = 0; let mut left: i32 = 0; let mut right: i32 = 0; let mut sandPile: *mut *mut i32 = 0 as *mut *mut i32; let mut fileName: *mut i8 = 0 as *mut i8; static mut colour: [u8; 3] = [0; 3]; if argc != 3 { print!( \"Usage: {} <Sand pile side> <Center pile height>\", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); return 0; } sandPileEdge = atoi(*argv.offset(1 as isize)); centerPileHeight = atoi(*argv.offset(2 as isize)); if sandPileEdge <= 0 || centerPileHeight <= 0 { print!(\"Sand pile and center pile dimensions must be positive integers.\"); return 0; } sandPile = malloc((sandPileEdge as u64).wrapping_mul(::core::mem::size_of::<*mut i32>() as u64)) as *mut *mut i32; i = 0; while i < sandPileEdge { let ref mut fresh0 = *sandPile.offset(i as isize); *fresh0 = calloc(sandPileEdge as u64, ::core::mem::size_of::<i32>() as u64) as *mut i32; i += 1; i; } *(*sandPile.offset((sandPileEdge / 2i32) as isize)) .offset((sandPileEdge / 2i32) as isize) = centerPileHeight; print!(\"Initial sand pile :\\n\\n\"); i = 0; while i < sandPileEdge { j = 0; while j < sandPileEdge { print!(\"{:3}\", *(*sandPile.offset(i as isize)).offset(j as isize)); j += 1; j; } print!(\"\\n\"); i += 1; i; } while processAgain == 1 { processAgain = 0; top = 0; down = 0; left = 0; right = 0; i = 0; while i < sandPileEdge { j = 0; while j < sandPileEdge { if *(*sandPile.offset(i as isize)).offset(j as isize) >= 4 { if i - 1 >= 0 { top = 1; *(*sandPile.offset((i - 1i32) as isize)).offset(j as isize) += 1; if *(*sandPile.offset((i - 1i32) as isize)).offset(j as isize) >= 4 { processAgain = 1; } } if (i + 1) < sandPileEdge { down = 1; *(*sandPile.offset((i + 1i32) as isize)).offset(j as isize) += 1; if *(*sandPile.offset((i + 1i32) as isize)).offset(j as isize) >= 4 { processAgain = 1; } } if j - 1 >= 0 { left = 1; *(*sandPile.offset(i as isize)).offset((j - 1i32) as isize) += 1; if *(*sandPile.offset(i as isize)).offset((j - 1i32) as isize) >= 4 { processAgain = 1; } } if (j + 1) < sandPileEdge { right = 1; *(*sandPile.offset(i as isize)).offset((j + 1i32) as isize) += 1; if *(*sandPile.offset(i as isize)).offset((j + 1i32) as isize) >= 4 { processAgain = 1; } }; *(*sandPile.offset(i as isize)).offset(j as isize) -= top + down + left + right; if *(*sandPile.offset(i as isize)).offset(j as isize) >= 4 { processAgain = 1; } } j += 1; j; } i += 1; i; } } print!(\"Final sand pile : \\n\\n\"); i = 0; while i < sandPileEdge { j = 0; while j < sandPileEdge { print!(\"{:3}\", *(*sandPile.offset(i as isize)).offset(j as isize)); j += 1; j; } print!(\"\\n\"); i += 1; i; } fileName = malloc( (strlen(*argv.offset(1 as isize))) .wrapping_add(strlen(*argv.offset(2 as isize))) .wrapping_add(23) .wrapping_mul(::core::mem::size_of::<i8>() as u64), ) as *mut i8; strcpy(fileName, b\"Final_Sand_Pile_\\0\" as *const u8 as *const i8); strcat(fileName, *argv.offset(1 as isize)); strcat(fileName, b\"_\\0\" as *const u8 as *const i8); strcat(fileName, *argv.offset(2 as isize)); strcat(fileName, b\".ppm\\0\" as *const u8 as *const i8); let mut fp: *mut FILE = fopen(fileName, 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, sandPileEdge, sandPileEdge, ); i = 0; while i < sandPileEdge { j = 0; while j < sandPileEdge { colour[0 as usize] = ((*(*sandPile.offset(i as isize)).offset(j as isize) + i) % 256i32) as u8; colour[1 as usize] = ((*(*sandPile.offset(i as isize)).offset(j as isize) + j) % 256i32) as u8; colour[2 as usize] = ((*(*sandPile.offset(i as isize)).offset(j as isize) + i * j) % 256i32) as u8; fwrite(colour.as_mut_ptr() as *const libc::c_void, 1, 3, fp); j += 1; j; } i += 1; i; } fclose(fp); print!( \"\\nImage file written to {}\\n\", build_str_from_raw_ptr(fileName as *mut u8) ); return 0; } }" |
|
}, |
|
{ |
|
"index": 12, |
|
"before": "void generateFirstRank(){ \t int kPos,qPos,bPos1,bPos2,rPos1,rPos2,nPos1,nPos2,i; \t for(i=0;i<8;i++){ \t\t rank[i] = 'e'; \t\t pos[i] = i; \t } \t do{ \t\t kPos = rand()%8; \t\t rPos1 = rand()%8; \t\t rPos2 = rand()%8; \t }while((rPos1-kPos<=0 && rPos2-kPos<=0)||(rPos1-kPos>=0 && rPos2-kPos>=0)||(rPos1==rPos2 || kPos==rPos1 || kPos==rPos2)); \t rank[pos[rPos1]] = 'R'; \t rank[pos[kPos]] = 'K'; \t rank[pos[rPos2]] = 'R'; \t swap(rPos1,7); \t swap(rPos2,6); \t swap(kPos,5); \t do{ \t\t bPos1 = rand()%5; \t\t bPos2 = rand()%5; \t }while(((pos[bPos1]-pos[bPos2])%2==0)||(bPos1==bPos2)); \t rank[pos[bPos1]] = 'B'; \t rank[pos[bPos2]] = 'B'; \t swap(bPos1,4); \t swap(bPos2,3); \t do{ \t\t qPos = rand()%3; \t\t nPos1 = rand()%3; \t }while(qPos==nPos1); \t rank[pos[qPos]] = 'Q'; \t rank[pos[nPos1]] = 'N'; \t for(i=0;i<8;i++) \t\t if(rank[i]=='e'){ \t\t\t rank[i] = 'N'; \t\t\t break; \t\t }\t\t }", |
|
"after": "pub extern \"C\" fn generateFirstRank() { let mut kPos: i32 = 0; let mut qPos: i32 = 0; let mut bPos1: i32 = 0; let mut bPos2: i32 = 0; let mut rPos1: i32 = 0; let mut rPos2: i32 = 0; let mut nPos1: i32 = 0; let mut nPos2: i32 = 0; let mut i: i32 = 0; i = 0; unsafe { while i < 8 { rank[i as usize] = 'e' as i8; pos[i as usize] = i; i += 1; i; } loop { kPos = rand() % 8; rPos1 = rand() % 8; rPos2 = rand() % 8; if !(rPos1 - kPos <= 0 && rPos2 - kPos <= 0 || rPos1 - kPos >= 0 && rPos2 - kPos >= 0 || (rPos1 == rPos2 || kPos == rPos1 || kPos == rPos2)) { break; } } rank[pos[rPos1 as usize] as usize] = 'R' as i8; rank[pos[kPos as usize] as usize] = 'K' as i8; rank[pos[rPos2 as usize] as usize] = 'R' as i8; } swap(rPos1, 7); swap(rPos2, 6); swap(kPos, 5); unsafe { loop { bPos1 = rand() % 5; bPos2 = rand() % 5; if !((pos[bPos1 as usize] - pos[bPos2 as usize]) % 2 == 0 || bPos1 == bPos2) { break; } } rank[pos[bPos1 as usize] as usize] = 'B' as i8; rank[pos[bPos2 as usize] as usize] = 'B' as i8; } swap(bPos1, 4); swap(bPos2, 3); unsafe { loop { qPos = rand() % 3; nPos1 = rand() % 3; if !(qPos == nPos1) { break; } } rank[pos[qPos as usize] as usize] = 'Q' as i8; rank[pos[nPos1 as usize] as usize] = 'N' as i8; } i = 0; unsafe { while i < 8 { if rank[i as usize] as i32 == 'e' as i32 { rank[i as usize] = 'N' as i8; break; } else { i += 1; i; } } } }" |
|
}, |
|
{ |
|
"index": 13, |
|
"before": "int main() { \tint i; \tsrand((unsigned)time(NULL)); \tfor(i=0;i<9;i++){ \t\tgenerateFirstRank(); \t\tprintRank(); \t} \treturn 0; }", |
|
"after": "fn main() -> i32 { let mut i: i32 = 0; unsafe { srand(rust_time(None) as u32); } i = 0; while i < 9 { generateFirstRank(); printRank(); i += 1; i; } return 0; }" |
|
}, |
|
{ |
|
"index": 14, |
|
"before": "void swap(int i,int j){ \tint temp = pos[i]; \tpos[i] = pos[j]; \tpos[j] = temp; }", |
|
"after": "pub extern \"C\" fn swap(mut i: i32, mut j: i32) { unsafe { let mut temp: i32 = pos[i as usize]; pos[i as usize] = pos[j as usize]; pos[j as usize] = temp; } }" |
|
}, |
|
{ |
|
"index": 15, |
|
"before": "void printRank(){ \tint i; \t#ifdef _WIN32 \t\tprintf(\"%s\\n\",rank); \t#else \t{ \t\tsetlocale(LC_ALL,\"\"); \t\tprintf(\"\\n\"); \t\tfor(i=0;i<8;i++){ \t\t\tif(rank[i]=='K') \t\t\t\tprintf(\"%lc\",(wint_t)9812); \t\t\telse if(rank[i]=='Q') \t\t\t\tprintf(\"%lc\",(wint_t)9813); \t\t\telse if(rank[i]=='R') \t\t\t\tprintf(\"%lc\",(wint_t)9814); \t\t\telse if(rank[i]=='B') \t\t\t\tprintf(\"%lc\",(wint_t)9815); \t\t\tif(rank[i]=='N') \t\t\t\tprintf(\"%lc\",(wint_t)9816); \t\t} \t} \t#endif }", |
|
"after": "pub extern \"C\" fn printRank() { let mut i: i32 = 0; unsafe { setlocale(6, b\"\\0\" as *const u8 as *const i8); } print!(\"\\n\"); i = 0; unsafe { while i < 8 { if rank[i as usize] as i32 == 'K' as i32 { print!(\"{}\", 9812); } else if rank[i as usize] as i32 == 'Q' as i32 { print!(\"{}\", 9813); } else if rank[i as usize] as i32 == 'R' as i32 { print!(\"{}\", 9814); } else if rank[i as usize] as i32 == 'B' as i32 { print!(\"{}\", 9815); } if rank[i as usize] as i32 == 'N' as i32 { print!(\"{}\", 9816); } i += 1; i; } } }" |
|
}, |
|
{ |
|
"index": 16, |
|
"before": "int main(void) { char str[] = \"rosetta code phrase reversal\"; size_t lenstr = sizeof(str) / sizeof(str[0]); char scopy[lenstr]; char delim = ' '; /* Original String */ printf(\"Original: \\\"%s\\\"\\n\", str); /* Reversed string */ strncpy(scopy, str, lenstr); reverse_string(scopy); printf(\"Reversed: \\\"%s\\\"\\n\", scopy); /* Reversed words in string */ strncpy(scopy, str, lenstr); reverse_words_in_order(scopy, delim); printf(\"Reversed words: \\\"%s\\\"\\n\", scopy); /* Reversed order of words in string */ strncpy(scopy, str, lenstr); reverse_order_of_words(scopy, delim); printf(\"Reversed order: \\\"%s\\\"\\n\", scopy); return 0; }", |
|
"after": "fn main() -> i32 { unsafe { let mut str: [i8; 29] = *::core::mem::transmute::<&[u8; 29], &mut [i8; 29]>(b\"rosetta code phrase reversal\\0\"); let mut lenstr: u64 = (::core::mem::size_of::<[i8; 29]>() as u64) .wrapping_div(::core::mem::size_of::<i8>() as u64); let vla = lenstr as usize; let mut scopy: Vec<i8> = ::std::vec::from_elem(0, vla); let mut delim: i8 = ' ' as i8; print!( \"Original: \\\"{}\\\"\\n\", build_str_from_raw_ptr(str.as_mut_ptr() as *mut u8) ); strncpy(scopy.as_mut_ptr(), str.as_mut_ptr(), lenstr); reverse_string(scopy.as_mut_ptr()); print!( \"Reversed: \\\"{}\\\"\\n\", build_str_from_raw_ptr(scopy.as_mut_ptr() as *mut u8) ); strncpy(scopy.as_mut_ptr(), str.as_mut_ptr(), lenstr); reverse_words_in_order(scopy.as_mut_ptr(), delim); print!( \"Reversed words: \\\"{}\\\"\\n\", build_str_from_raw_ptr(scopy.as_mut_ptr() as *mut u8) ); strncpy(scopy.as_mut_ptr(), str.as_mut_ptr(), lenstr); reverse_order_of_words(scopy.as_mut_ptr(), delim); print!( \"Reversed order: \\\"{}\\\"\\n\", build_str_from_raw_ptr(scopy.as_mut_ptr() as *mut u8) ); } return 0; }" |
|
}, |
|
{ |
|
"index": 17, |
|
"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 extern \"C\" fn solve(mut n: i32, mut col: i32, mut hist: *mut i32) { unsafe { if col == n { count += 1; print!(\"\\nNo. {}\\n-----\\n\", count); let mut i: i32 = 0; while i < n { let mut j: i32 = 0; while j < n { print!( \"{}\", if j == *hist.offset(i as isize) { 'Q' as i32 } else if i + j & 1 != 0 { ' ' as i32 } else { '.' as i32 } ); j += 1; j; } i += 1; i; print!(\"{}\", '\\n' as i32); } return; } let mut i_0: i32 = 0; let mut j_0: i32 = 0; while i_0 < n { j_0 = 0; 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, hist); } i_0 += 1; i_0; } } }" |
|
}, |
|
{ |
|
"index": 18, |
|
"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": "fn main(mut n: i32, mut argv: *mut *mut i8) -> i32 { unsafe { if n <= 1 || { n = atoi(*argv.offset(1 as isize)); n <= 0 } { n = 8; } let vla = n as usize; let mut hist: Vec<i32> = ::std::vec::from_elem(0, vla); solve(n, 0, hist.as_mut_ptr()); return 0; } }" |
|
}, |
|
{ |
|
"index": 19, |
|
"before": "int main() { for (int i = 1; i < 5000; i++) { // loop through each digit in i // e.g. for 1000 we get 0, 0, 0, 1. int sum = 0; for (int number = i; number > 0; number /= 10) { int digit = number % 10; // find the sum of the digits // raised to themselves sum += pow(digit, digit); } if (sum == i) { // the sum is equal to the number // itself; thus it is a // munchausen number printf(\"%i\\n\", i); } } return 0; }", |
|
"after": "fn main() -> i32 { let mut i: i32 = 1; unsafe { while i < 5000 { let mut sum: i32 = 0; let mut number: i32 = i; while number > 0 { let mut digit: i32 = number % 10; sum = (sum as f64 + pow(digit as f64, digit as f64)) as i32; number /= 10; } if sum == i { print!(\"{}\\n\", i); } i += 1; i; } } return 0; }" |
|
}, |
|
{ |
|
"index": 20, |
|
"before": "bool find_prime_partition(const sieve* s, uint32_t number, uint32_t count, uint32_t min_prime, uint32_t* p) { if (count == 1) { if (number >= min_prime && is_prime(s, number)) { *p = number; return true; } return false; } for (uint32_t prime = min_prime; prime < number; ++prime) { if (!is_prime(s, prime)) continue; if (find_prime_partition(s, number - prime, count - 1, prime + 1, p + 1)) { *p = prime; return true; } } return false; }", |
|
"after": "pub extern \"C\" fn find_prime_partition( mut s: *const sieve, mut number: u32, mut count: u32, mut min_prime: u32, mut p: *mut u32, ) -> bool { unsafe { if count == 1 { if number >= min_prime && is_prime(s, number) as i32 != 0 { *p = number; return 1 != 0; } return 0 != 0; } let mut prime: u32 = min_prime; while prime < number { if is_prime(s, prime) { if find_prime_partition( s, number.wrapping_sub(prime), count.wrapping_sub(1), prime.wrapping_add(1), p.offset(1 as isize), ) { *p = prime; return 1 != 0; } } prime = prime.wrapping_add(1); prime; } return 0 != 0; } }" |
|
}, |
|
{ |
|
"index": 21, |
|
"before": "bool is_prime(const sieve* s, uint32_t n) { assert(n <= s->limit); return bit_array_get(&s->not_prime, n) == false; }", |
|
"after": "pub extern \"C\" fn is_prime(mut s: *const sieve, mut n: u32) -> bool { unsafe { if n <= (*s).limit { } else { __assert_fail( b\"n <= s->limit\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 67, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"_Bool is_prime(const sieve *, uint32_t)\\0\", )) .as_ptr(), ); } 'c_1919: { if n <= (*s).limit { } else { __assert_fail( b\"n <= s->limit\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 67, (*::core::mem::transmute::<&[u8; 40], &[i8; 40]>( b\"_Bool is_prime(const sieve *, uint32_t)\\0\", )) .as_ptr(), ); } }; return bit_array_get(&(*s).not_prime, n) as i32 == 0; } }" |
|
}, |
|
{ |
|
"index": 22, |
|
"before": "void print_prime_partition(const sieve* s, uint32_t number, uint32_t count) { assert(count > 0); uint32_t* primes = malloc(count * sizeof(uint32_t)); if (primes == NULL) { fprintf(stderr, \"Out of memory\\n\"); return; } if (!find_prime_partition(s, number, count, 2, primes)) { printf(\"%u cannot be partitioned into %u primes.\\n\", number, count); } else { printf(\"%u = %u\", number, primes[0]); for (uint32_t i = 1; i < count; ++i) printf(\" + %u\", primes[i]); printf(\"\\n\"); } free(primes); }", |
|
"after": "pub extern \"C\" fn print_prime_partition(mut s: *const sieve, mut number: u32, mut count: u32) { unsafe { if count > 0 { } else { __assert_fail( b\"count > 0\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 93, (*::core::mem::transmute::<&[u8; 62], &[i8; 62]>( b\"void print_prime_partition(const sieve *, uint32_t, uint32_t)\\0\", )) .as_ptr(), ); } 'c_2193: { if count > 0 { } else { __assert_fail( b\"count > 0\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 93, (*::core::mem::transmute::<&[u8; 62], &[i8; 62]>( b\"void print_prime_partition(const sieve *, uint32_t, uint32_t)\\0\", )) .as_ptr(), ); } }; let mut primes: *mut u32 = malloc((count as u64).wrapping_mul(::core::mem::size_of::<u32>() as u64)) as *mut u32; if primes.is_null() { fprintf(stderr, b\"Out of memory\\n\\0\" as *const u8 as *const i8); return; } if !find_prime_partition(s, number, count, 2, primes) { print!(\"{} cannot be partitioned into {} primes.\\n\", number, count); } else { print!(\"{} = {}\", number, *primes.offset(0 as isize)); let mut i: u32 = 1; while i < count { print!(\" + {}\", *primes.offset(i as isize)); i = i.wrapping_add(1); i; } print!(\"\\n\"); } free(primes as *mut libc::c_void); } }" |
|
}, |
|
{ |
|
"index": 23, |
|
"before": "int main() { const uint32_t limit = 100000; sieve s = { 0 }; if (!sieve_create(&s, limit)) { fprintf(stderr, \"Out of memory\\n\"); return 1; } print_prime_partition(&s, 99809, 1); print_prime_partition(&s, 18, 2); print_prime_partition(&s, 19, 3); print_prime_partition(&s, 20, 4); print_prime_partition(&s, 2017, 24); print_prime_partition(&s, 22699, 1); print_prime_partition(&s, 22699, 2); print_prime_partition(&s, 22699, 3); print_prime_partition(&s, 22699, 4); print_prime_partition(&s, 40355, 3); sieve_destroy(&s); return 0; }", |
|
"after": "fn main() -> i32 { let limit: u32 = 100000; let mut s: sieve = { let mut init = sieve_tag { limit: 0, not_prime: bit_array { size: 0, array: 0 as *mut u32, }, }; init }; unsafe { if !sieve_create(&mut s, limit) { fprintf(stderr, b\"Out of memory\\n\\0\" as *const u8 as *const i8); return 1; } } print_prime_partition(&mut s, 99809, 1); print_prime_partition(&mut s, 18, 2); print_prime_partition(&mut s, 19, 3); print_prime_partition(&mut s, 20, 4); print_prime_partition(&mut s, 2017, 24); print_prime_partition(&mut s, 22699, 1); print_prime_partition(&mut s, 22699, 2); print_prime_partition(&mut s, 22699, 3); print_prime_partition(&mut s, 22699, 4); print_prime_partition(&mut s, 40355, 3); sieve_destroy(&mut s); return 0; }" |
|
}, |
|
{ |
|
"index": 24, |
|
"before": "bool bit_array_create(bit_array* b, uint32_t size) { uint32_t* array = calloc((size + 31)/32, sizeof(uint32_t)); if (array == NULL) return false; b->size = size; b->array = array; return true; }", |
|
"after": "pub extern \"C\" fn bit_array_create(mut b: *mut bit_array, mut size: u32) -> bool { unsafe { let mut array: *mut u32 = calloc( size.wrapping_add(31).wrapping_div(32) as u64, ::core::mem::size_of::<u32>() as u64, ) as *mut u32; if array.is_null() { return 0 != 0; }; (*b).size = size; (*b).array = array; return 1 != 0; } }" |
|
}, |
|
{ |
|
"index": 25, |
|
"before": "void bit_array_set(bit_array* b, uint32_t index, bool value) { assert(index < b->size); uint32_t* p = &b->array[index >> 5]; uint32_t bit = 1 << (index & 31); if (value) *p |= bit; else *p &= ~bit; }", |
|
"after": "pub extern \"C\" fn bit_array_set(mut b: *mut bit_array, mut index: u32, mut value: bool) { unsafe { if index < (*b).size { } else { __assert_fail( b\"index < b->size\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 27, (*::core::mem::transmute::<&[u8; 49], &[i8; 49]>( b\"void bit_array_set(bit_array *, uint32_t, _Bool)\\0\", )) .as_ptr(), ); } 'c_1632: { if index < (*b).size { } else { __assert_fail( b\"index < b->size\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 27, (*::core::mem::transmute::<&[u8; 49], &[i8; 49]>( b\"void bit_array_set(bit_array *, uint32_t, _Bool)\\0\", )) .as_ptr(), ); } }; let mut p: *mut u32 = &mut *((*b).array).offset((index >> 5i32) as isize) as *mut u32; let mut bit: u32 = (1i32 << (index & 31)) as u32; if value { *p |= bit; } else { *p &= !bit; }; } }" |
|
}, |
|
{ |
|
"index": 26, |
|
"before": "bool bit_array_get(const bit_array* b, uint32_t index) { assert(index < b->size); uint32_t bit = 1 << (index & 31); return (b->array[index >> 5] & bit) != 0; }", |
|
"after": "pub extern \"C\" fn bit_array_get(mut b: *const bit_array, mut index: u32) -> bool { unsafe { if index < (*b).size { } else { __assert_fail( b\"index < b->size\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 37, (*::core::mem::transmute::<&[u8; 49], &[i8; 49]>( b\"_Bool bit_array_get(const bit_array *, uint32_t)\\0\", )) .as_ptr(), ); } 'c_1716: { if index < (*b).size { } else { __assert_fail( b\"index < b->size\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 37, (*::core::mem::transmute::<&[u8; 49], &[i8; 49]>( b\"_Bool bit_array_get(const bit_array *, uint32_t)\\0\", )) .as_ptr(), ); } }; let mut bit: u32 = (1i32 << (index & 31)) as u32; return *((*b).array).offset((index >> 5i32) as isize) & bit != 0; } }" |
|
}, |
|
{ |
|
"index": 27, |
|
"before": "void bit_array_destroy(bit_array* b) { free(b->array); b->array = NULL; }", |
|
"after": "pub extern \"C\" fn bit_array_destroy(mut b: *mut bit_array) { unsafe { free((*b).array as *mut libc::c_void); (*b).array = 0 as *mut u32; } }" |
|
}, |
|
{ |
|
"index": 28, |
|
"before": "void sieve_destroy(sieve* s) { bit_array_destroy(&s->not_prime); }", |
|
"after": "pub extern \"C\" fn sieve_destroy(mut s: *mut sieve) { unsafe { bit_array_destroy(&mut (*s).not_prime); } }" |
|
}, |
|
{ |
|
"index": 29, |
|
"before": "bool sieve_create(sieve* s, uint32_t limit) { if (!bit_array_create(&s->not_prime, limit + 1)) return false; bit_array_set(&s->not_prime, 0, true); bit_array_set(&s->not_prime, 1, true); for (uint32_t p = 2; p * p <= limit; ++p) { if (bit_array_get(&s->not_prime, p) == false) { for (uint32_t q = p * p; q <= limit; q += p) bit_array_set(&s->not_prime, q, true); } } s->limit = limit; return true; }", |
|
"after": "pub extern \"C\" fn sieve_create(mut s: *mut sieve, mut limit: u32) -> bool { unsafe { if !bit_array_create(&mut (*s).not_prime, limit.wrapping_add(1)) { return 0 != 0; } bit_array_set(&mut (*s).not_prime, 0, 1 != 0); bit_array_set(&mut (*s).not_prime, 1, 1 != 0); let mut p: u32 = 2; while p.wrapping_mul(p) <= limit { if bit_array_get(&mut (*s).not_prime, p) as i32 == 0 { let mut q: u32 = p.wrapping_mul(p); while q <= limit { bit_array_set(&mut (*s).not_prime, q, 1 != 0); q = (q).wrapping_add(p) as u32; } } p = p.wrapping_add(1); p; } (*s).limit = limit; return 1 != 0; } }" |
|
}, |
|
{ |
|
"index": 30, |
|
"before": "int main() { char *question = NULL; size_t len = 0; ssize_t read; const char* answers[20] = { \"It is certain\", \"It is decidedly so\", \"Without a doubt\", \"Yes, definitely\", \"You may rely on it\", \"As I see it, yes\", \"Most likely\", \"Outlook good\", \"Signs point to yes\", \"Yes\", \"Reply hazy, try again\", \"Ask again later\", \"Better not tell you now\", \"Cannot predict now\", \"Concentrate and ask again\", \"Don't bet on it\", \"My reply is no\", \"My sources say no\", \"Outlook not so good\", \"Very doubtful\" }; srand(time(NULL)); printf(\"Please enter your question or a blank line to quit.\\n\"); while (1) { printf(\"\\n? : \"); read = getline(&question, &len, stdin); if (read < 2) break; printf(\"\\n%s\\n\", answers[rand() % 20]); } if (question) free(question); return 0; }", |
|
"after": "fn main() -> i32 { unsafe { let mut question: *mut i8 = 0 as *mut i8; let mut len: u64 = 0; let mut read: i64 = 0; let mut answers: [*const i8; 20] = [ b\"It is certain\\0\" as *const u8 as *const i8, b\"It is decidedly so\\0\" as *const u8 as *const i8, b\"Without a doubt\\0\" as *const u8 as *const i8, b\"Yes, definitely\\0\" as *const u8 as *const i8, b\"You may rely on it\\0\" as *const u8 as *const i8, b\"As I see it, yes\\0\" as *const u8 as *const i8, b\"Most likely\\0\" as *const u8 as *const i8, b\"Outlook good\\0\" as *const u8 as *const i8, b\"Signs point to yes\\0\" as *const u8 as *const i8, b\"Yes\\0\" as *const u8 as *const i8, b\"Reply hazy, try again\\0\" as *const u8 as *const i8, b\"Ask again later\\0\" as *const u8 as *const i8, b\"Better not tell you now\\0\" as *const u8 as *const i8, b\"Cannot predict now\\0\" as *const u8 as *const i8, b\"Concentrate and ask again\\0\" as *const u8 as *const i8, b\"Don't bet on it\\0\" as *const u8 as *const i8, b\"My reply is no\\0\" as *const u8 as *const i8, b\"My sources say no\\0\" as *const u8 as *const i8, b\"Outlook not so good\\0\" as *const u8 as *const i8, b\"Very doubtful\\0\" as *const u8 as *const i8, ]; srand(rust_time(None) as u32); print!(\"Please enter your question or a blank line to quit.\\n\"); loop { print!(\"\\n? : \"); read = getline(&mut question, &mut len, stdin); if read < 2 { break; } print!( \"\\n{}\\n\", build_str_from_raw_ptr(answers[(rand() % 20i32) as usize] as *mut u8) ); } if !question.is_null() { free(question as *mut libc::c_void); } return 0; } }" |
|
}, |
|
{ |
|
"index": 31, |
|
"before": "int empty(queue q) { return q->tail == q->head; }", |
|
"after": "pub extern \"C\" fn empty(mut q: queue) -> i32 { return ((*q).tail == (*q).head) as i32; }" |
|
}, |
|
{ |
|
"index": 32, |
|
"before": "int dequeue(queue q, DATA *n) { if (q->head == q->tail) return 0; *n = q->buf[q->head++]; if (q->head >= q->alloc) { /* reduce allocated storage no longer needed */ q->head = 0; if (q->alloc >= 512 && q->tail < q->alloc / 2) q->buf = realloc(q->buf, sizeof(DATA) * (q->alloc /= 2)); } return 1; }", |
|
"after": "pub extern \"C\" fn dequeue(mut q: queue, mut n: *mut i32) -> i32 { unsafe { if (*q).head == (*q).tail { return 0; } let fresh1 = (*q).head; (*q).head = ((*q).head).wrapping_add(1); *n = *((*q).buf).offset(fresh1 as isize); if (*q).head >= (*q).alloc { (*q).head = 0; if (*q).alloc >= 512 && (*q).tail < ((*q).alloc).wrapping_div(2) { (*q).alloc = ((*q).alloc as u64).wrapping_div(2) as u64; (*q).buf = realloc( (*q).buf as *mut libc::c_void, (::core::mem::size_of::<i32>() as u64).wrapping_mul((*q).alloc), ) as *mut i32; } } return 1; } }" |
|
}, |
|
{ |
|
"index": 33, |
|
"before": "int main() { int i, n; queue q = q_new(); for (i = 0; i < 100000000; i++) { n = rand(); if (n > RAND_MAX / 2) { // printf(\"+ %d\\n\", n); enqueue(q, n); } else { if (!dequeue(q, &n)) { // printf(\"empty\\n\"); continue; } // printf(\"- %d\\n\", n); } } while (dequeue(q, &n)) ; // printf(\"- %d\\n\", n); return 0; }", |
|
"after": "fn main() -> i32 { let mut i: i32 = 0; let mut n: i32 = 0; let mut q: queue = q_new(); i = 0; unsafe { while i < 100000000 { n = rand(); if n > 2147483647 / 2 { enqueue(q, n); } else { dequeue(q, &mut n) == 0; } i += 1; i; } } while dequeue(q, &mut n) != 0 {} return 0; }" |
|
}, |
|
{ |
|
"index": 34, |
|
"before": "void enqueue(queue q, DATA n) { if (q->tail >= q->alloc) q->tail = 0; q->buf[q->tail++] = n; // Fixed bug where it failed to resizes if (q->tail == q->alloc) { /* needs more room */ q->buf = realloc(q->buf, sizeof(DATA) * q->alloc * 2); if (q->head) { memcpy(q->buf + q->head + q->alloc, q->buf + q->head, sizeof(DATA) * (q->alloc - q->head)); q->head += q->alloc; } else q->tail = q->alloc; q->alloc *= 2; } }", |
|
"after": "pub extern \"C\" fn enqueue(mut q: queue, mut n: i32) { if (*q).tail >= (*q).alloc { (*q).tail = 0; } let fresh0 = (*q).tail; (*q).tail = ((*q).tail).wrapping_add(1); unsafe { *((*q).buf).offset(fresh0 as isize) = n; if (*q).tail == (*q).alloc { (*q).buf = realloc( (*q).buf as *mut libc::c_void, (::core::mem::size_of::<i32>() as u64) .wrapping_mul((*q).alloc) .wrapping_mul(2), ) as *mut i32; if (*q).head != 0 { memcpy( ((*q).buf) .offset((*q).head as isize) .offset((*q).alloc as isize) as *mut libc::c_void, ((*q).buf).offset((*q).head as isize) as *const libc::c_void, (::core::mem::size_of::<i32>() as u64) .wrapping_mul(((*q).alloc).wrapping_sub((*q).head)), ); (*q).head = ((*q).head as u64).wrapping_add((*q).alloc) as u64; } else { (*q).tail = (*q).alloc; }; (*q).alloc = ((*q).alloc as u64).wrapping_mul(2) as u64; } } }" |
|
}, |
|
{ |
|
"index": 35, |
|
"before": "queue q_new() { queue q = malloc(sizeof(queue_t)); q->buf = malloc(sizeof(DATA) * (q->alloc = 4)); q->head = q->tail = 0; return q; }", |
|
"after": "pub extern \"C\" fn q_new() -> queue { unsafe { let mut q: queue = malloc(::core::mem::size_of::<queue_t>() as u64) as queue; (*q).alloc = 4; (*q).buf = malloc((::core::mem::size_of::<i32>() as u64).wrapping_mul((*q).alloc)) as *mut i32; (*q).tail = 0; (*q).head = (*q).tail; return q; } }" |
|
}, |
|
{ |
|
"index": 36, |
|
"before": "int main() { int a[10][10], i, j; srand(time(NULL)); for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) a[i][j] = rand() % 20 + 1; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { printf(\" %d\", a[i][j]); if (a[i][j] == 20) goto Done; } printf(\"\\n\"); } Done: printf(\"\\n\"); return 0; }", |
|
"after": "fn main() -> i32 { let mut a: [[i32; 10]; 10] = [[0; 10]; 10]; let mut i: i32 = 0; let mut j: i32 = 0; unsafe { srand(rust_time(None) as u32); } i = 0; unsafe { while i < 10 { j = 0; while j < 10 { a[i as usize][j as usize] = rand() % 20 + 1; j += 1; j; } i += 1; i; } } i = 0; 's_32: while i < 10 { j = 0; while j < 10 { print!(\" {}\", a[i as usize][j as usize]); if a[i as usize][j as usize] == 20 { break 's_32; } j += 1; j; } print!(\"\\n\"); i += 1; i; } print!(\"\\n\"); return 0; }" |
|
}, |
|
{ |
|
"index": 37, |
|
"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 extern \"C\" fn douglas_peucker( mut points: *const point_t, mut n: u64, mut epsilon: f64, mut dest: *mut point_t, mut destlen: u64, ) -> u64 { unsafe { if n >= 2 { } else { __assert_fail( b\"n >= 2\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 22, (*::core::mem::transmute::<&[u8; 75], &[i8; 75]>( b\"size_t douglas_peucker(const point_t *, size_t, double, point_t *, size_t)\\0\", )) .as_ptr(), ); } 'c_2158: { if n >= 2 { } else { __assert_fail (b\"n >= 2\\0\" as * const u8 as * const i8, b\"main.c\\0\" as * const u8 as * const i8, 22, (* :: core :: mem :: transmute :: < & [u8; 75], & [i8; 75] > ( b\"size_t douglas_peucker(const point_t *, size_t, double, point_t *, size_t)\\0\",)).as_ptr (),); } }; if epsilon >= 0 as f64 { } else { __assert_fail( b\"epsilon >= 0\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 23, (*::core::mem::transmute::<&[u8; 75], &[i8; 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 f64 { } else { __assert_fail (b\"epsilon >= 0\\0\" as * const u8 as * const i8, b\"main.c\\0\" as * const u8 as * const i8, 23, (* :: core :: mem :: transmute :: < & [u8; 75], & [i8; 75] > ( b\"size_t douglas_peucker(const point_t *, size_t, double, point_t *, size_t)\\0\",)).as_ptr (),); } }; let mut max_dist: f64 = 0 as f64; let mut index: u64 = 0; let mut i: u64 = 1; while i.wrapping_add(1) < n { let mut dist: f64 = perpendicular_distance( *points.offset(i as isize), *points.offset(0 as isize), *points.offset(n.wrapping_sub(1) as isize), ); if dist > max_dist { max_dist = dist; index = i; } i = i.wrapping_add(1); i; } if max_dist > epsilon { let mut n1: u64 = douglas_peucker(points, index.wrapping_add(1), epsilon, dest, destlen); if destlen >= n1.wrapping_sub(1) { destlen = (destlen as u64).wrapping_sub(n1.wrapping_sub(1)) as u64; dest = dest.offset(n1.wrapping_sub(1) as isize); } else { destlen = 0; } let mut n2: u64 = douglas_peucker( points.offset(index as isize), n.wrapping_sub(index), epsilon, dest, destlen, ); return n1.wrapping_add(n2).wrapping_sub(1); } if destlen >= 2 { *dest.offset(0 as isize) = *points.offset(0 as isize); *dest.offset(1 as isize) = *points.offset(n.wrapping_sub(1) as isize); } return 2; } }" |
|
}, |
|
{ |
|
"index": 38, |
|
"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": "fn main() -> i32 { let mut points: [point_t; 10] = [ { let mut init = point_tag { x: 0 as f64, y: 0 as f64, }; init }, { let mut init = point_tag { x: 1 as f64, y: 0.1f64, }; init }, { let mut init = point_tag { x: 2 as f64, y: -0.1f64, }; init }, { let mut init = point_tag { x: 3 as f64, y: 5 as f64, }; init }, { let mut init = point_tag { x: 4 as f64, y: 6 as f64, }; init }, { let mut init = point_tag { x: 5 as f64, y: 7 as f64, }; init }, { let mut init = point_tag { x: 6 as f64, y: 8.1f64, }; init }, { let mut init = point_tag { x: 7 as f64, y: 9 as f64, }; init }, { let mut init = point_tag { x: 8 as f64, y: 9 as f64, }; init }, { let mut init = point_tag { x: 9 as f64, y: 9 as f64, }; init }, ]; let len: u64 = (::core::mem::size_of::<[point_t; 10]>() as u64) .wrapping_div(::core::mem::size_of::<point_t>() as u64); let vla = len as usize; let mut out: Vec<point_t> = ::std::vec::from_elem(point_t { x: 0., y: 0. }, vla); let mut n: u64 = douglas_peucker(points.as_mut_ptr(), len, 1.0f64, out.as_mut_ptr(), len); print_points(out.as_mut_ptr(), n); return 0; }" |
|
}, |
|
{ |
|
"index": 39, |
|
"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 extern \"C\" fn perpendicular_distance(mut p: point_t, mut p1: point_t, mut p2: point_t) -> f64 { let mut dx: f64 = p2.x - p1.x; let mut dy: f64 = p2.y - p1.y; unsafe { let mut d: f64 = sqrt(dx * dx + dy * dy); return fabs(p.x * dy - p.y * dx + p2.x * p1.y - p2.y * p1.x) / d; } }" |
|
}, |
|
{ |
|
"index": 40, |
|
"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 extern \"C\" fn print_points(mut points: *const point_t, mut n: u64) { unsafe { let mut i: u64 = 0; while i < n { if i > 0 { print!(\" \"); } print!( \"({}, {})\", (*points.offset(i as isize)).x, (*points.offset(i as isize)).y ); i = i.wrapping_add(1); i; } print!(\"\\n\"); } }" |
|
}, |
|
{ |
|
"index": 41, |
|
"before": "unsigned sum_proper_divisors(const unsigned n) { unsigned sum = 1; for (unsigned i = 3, j; i < sqrt(n)+1; i += 2) if (n % i == 0) sum += i + (i == (j = n / i) ? 0 : j); return sum; }", |
|
"after": "pub extern \"C\" fn sum_proper_divisors(n: u32) -> u32 { let mut sum: u32 = 1; let mut i: u32 = 3; let mut j: u32 = 0; unsafe { while (i as f64) < sqrt(n as f64) + 1 as f64 { if n.wrapping_rem(i) == 0 { j = n.wrapping_div(i); sum = sum.wrapping_add(i.wrapping_add((if i == j { 0 } else { j }))); } i = i.wrapping_add(2); } } return sum; }" |
|
}, |
|
{ |
|
"index": 42, |
|
"before": "int main(int argc, char const *argv[]) { unsigned n, c; for (n = 1, c = 0; c < 25; n += 2) if (n < sum_proper_divisors(n)) printf(\"%u: %u\\n\", ++c, n); for ( ; c < 1000; n += 2) if (n < sum_proper_divisors(n)) c ++; printf(\"\\nThe one thousandth abundant odd number is: %u\\n\", n); for (n = 1000000001 ;; n += 2) if (n < sum_proper_divisors(n)) break; printf(\"The first abundant odd number above one billion is: %u\\n\", n); return 0; }", |
|
"after": "fn main(mut argc: i32, mut argv: *mut *const i8) -> i32 { unsafe { let mut n: u32 = 0; let mut c: u32 = 0; n = 1; c = 0; while c < 25 { if n < sum_proper_divisors(n) { c = c.wrapping_add(1); print!(\"{}: {}\\n\", c, n); } n = n.wrapping_add(2); } while c < 1000 { if n < sum_proper_divisors(n) { c = c.wrapping_add(1); c; } n = n.wrapping_add(2); } print!(\"\\nThe one thousandth abundant odd number is: {}\\n\", n); n = 1000000001; while !(n < sum_proper_divisors(n)) { n = n.wrapping_add(2); } print!( \"The first abundant odd number above one billion is: {}\\n\", n ); return 0; } }" |
|
}, |
|
{ |
|
"index": 43, |
|
"before": "int main() { \tmpz_t a, b, m, r; \tmpz_init_set_str(a,\t\"2988348162058574136915891421498819466320\" \t\t\t\t\"163312926952423791023078876139\", 0); \tmpz_init_set_str(b,\t\"2351399303373464486466122544523690094744\" \t\t\t\t\"975233415544072992656881240319\", 0); \tmpz_init(m); \tmpz_ui_pow_ui(m, 10, 40); \tmpz_init(r); \tmpz_powm(r, a, b, m); \tgmp_printf(\"%Zd\\n\", r); /* ...16808958343740453059 */ \tmpz_clear(a); \tmpz_clear(b); \tmpz_clear(m); \tmpz_clear(r); \treturn 0; }", |
|
"after": "fn main() -> i32 { return 0; }" |
|
}, |
|
{ |
|
"index": 44, |
|
"before": "matrix mat_new(int h, int w) { \tmatrix r = malloc(sizeof(matrix_t) + sizeof(double) * w * h); \tr->h = h, r->w = w; \tr->x = (double *)(r + 1); \treturn r; }", |
|
"after": "pub extern \"C\" fn mat_new(mut h: i32, mut w: i32) -> matrix { unsafe { let mut r: matrix = malloc( (::core::mem::size_of::<matrix_t>() as u64).wrapping_add( (::core::mem::size_of::<f64>() as u64) .wrapping_mul(w as u64) .wrapping_mul(h as u64), ), ) as matrix; (*r).h = h; (*r).w = w; (*r).x = r.offset(1 as isize) as *mut f64; return r; } }" |
|
}, |
|
{ |
|
"index": 45, |
|
"before": "matrix mat_mul(matrix a, matrix b) { \tmatrix r; \tdouble *p, *pa; \tint i, j; \tif (a->w != b->h) \t\treturn 0; \tr = mat_new(a->h, b->w); \tp = r->x; \tfor (pa = a->x, i = 0; i < a->h; i++, pa += a->w) \t\tfor (j = 0; j < b->w; j++) \t\t\t*p++ = dot(pa, b->x + j, a->w, b->w); \treturn r; }", |
|
"after": "pub extern \"C\" fn mat_mul(mut a: matrix, mut b: matrix) -> matrix { unsafe { let mut r: matrix = 0 as *mut matrix_t; let mut p: *mut f64 = 0 as *mut f64; let mut pa: *mut f64 = 0 as *mut f64; let mut i: i32 = 0; let mut j: i32 = 0; if (*a).w != (*b).h { return 0 as matrix; } r = mat_new((*a).h, (*b).w); p = (*r).x; pa = (*a).x; i = 0; while i < (*a).h { j = 0; while j < (*b).w { let fresh2 = p; p = p.offset(1); *fresh2 = dot(pa, ((*b).x).offset(j as isize), (*a).w, (*b).w); j += 1; j; } i += 1; i; pa = pa.offset((*a).w as isize); } return r; } }" |
|
}, |
|
{ |
|
"index": 46, |
|
"before": "int main() { \tdouble da[] = {1, 1, 1, 1, \t\t\t\t 2, 4, 8, 16, \t\t\t\t 3, 9, 27, 81, \t\t\t\t 4, 16, 64, 256}; \tdouble db[] = {4.0, -3.0, 4.0 / 3, \t\t\t\t -13.0 / 3, 19.0 / 4, -7.0 / 3, \t\t\t\t 3.0 / 2, -2.0, 7.0 / 6, \t\t\t\t -1.0 / 6, 1.0 / 4, -1.0 / 6}; \tmatrix_t a = {4, 4, da}, b = {4, 3, db}; \tmatrix c = mat_mul(&a, &b); \t/* mat_show(&a), mat_show(&b); */ \tmat_show(c); \t/* free(c) */ \treturn 0; }", |
|
"after": "fn main() -> i32 { let mut da: [f64; 16] = [ 1 as f64, 1 as f64, 1 as f64, 1 as f64, 2 as f64, 4 as f64, 8 as f64, 16 as f64, 3 as f64, 9 as f64, 27 as f64, 81 as f64, 4 as f64, 16 as f64, 64 as f64, 256 as f64, ]; let mut db: [f64; 12] = [ 4.0f64, -3.0f64, 4.0f64 / 3 as f64, -13.0f64 / 3 as f64, 19.0f64 / 4 as f64, -7.0f64 / 3 as f64, 3.0f64 / 2 as f64, -2.0f64, 7.0f64 / 6 as f64, -1.0f64 / 6 as f64, 1.0f64 / 4 as f64, -1.0f64 / 6 as f64, ]; let mut a: matrix_t = { let mut init = matrix_t { h: 4, w: 4, x: da.as_mut_ptr(), }; init }; let mut b: matrix_t = { let mut init = matrix_t { h: 4, w: 3, x: db.as_mut_ptr(), }; init }; let mut c: matrix = mat_mul(&mut a, &mut b); mat_show(c); return 0; }" |
|
}, |
|
{ |
|
"index": 47, |
|
"before": "double dot(double *a, double *b, int len, int step) { \tdouble r = 0; \twhile (len--) \t{ \t\tr += *a++ * *b; \t\tb += step; \t} \treturn r; }", |
|
"after": "pub extern \"C\" fn dot(mut a: *mut f64, mut b: *mut f64, mut len: i32, mut step: i32) -> f64 { unsafe { let mut r: f64 = 0 as f64; loop { let fresh0 = len; len = len - 1; if !(fresh0 != 0) { break; } let fresh1 = a; a = a.offset(1); r += *fresh1 * *b; b = b.offset(step as isize); } return r; } }" |
|
}, |
|
{ |
|
"index": 48, |
|
"before": "void mat_show(matrix a) { \tint i, j; \tdouble *p = a->x; \tfor (i = 0; i < a->h; i++, putchar('\\n')) \t\tfor (j = 0; j < a->w; j++) \t\t\tprintf(\"\\t%7.3f\", *p++); \tputchar('\\n'); }", |
|
"after": "pub extern \"C\" fn mat_show(mut a: matrix) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut p: *mut f64 = (*a).x; i = 0; while i < (*a).h { j = 0; while j < (*a).w { let fresh3 = p; p = p.offset(1); print!(\"\t{:7.3}\", *fresh3); j += 1; j; } i += 1; i; print!(\"{}\", '\\n' as i32); } print!(\"{}\", '\\n' as i32); } }" |
|
}, |
|
{ |
|
"index": 49, |
|
"before": "int F(const int n) { return (n == 0) ? 1 : n - M(F(n - 1)); }", |
|
"after": "pub extern \"C\" fn F(n: i32) -> i32 { return if n == 0 { 1 } else { n - M(F(n - 1)) }; }" |
|
}, |
|
{ |
|
"index": 50, |
|
"before": "int main(void) { int i; for (i = 0; i < 20; i++) printf(\"%2d \", F(i)); printf(\"\\n\"); for (i = 0; i < 20; i++) printf(\"%2d \", M(i)); printf(\"\\n\"); return EXIT_SUCCESS; }", |
|
"after": "fn main() -> i32 { let mut i: i32 = 0; i = 0; while i < 20 { print!(\"{:2} \", F(i)); i += 1; i; } print!(\"\\n\"); i = 0; while i < 20 { print!(\"{:2} \", M(i)); i += 1; i; } print!(\"\\n\"); return 0; }" |
|
}, |
|
{ |
|
"index": 51, |
|
"before": "int M(const int n) { return (n == 0) ? 0 : n - F(M(n - 1)); }", |
|
"after": "pub extern \"C\" fn M(n: i32) -> i32 { return if n == 0 { 0 } else { n - F(M(n - 1)) }; }" |
|
}, |
|
{ |
|
"index": 52, |
|
"before": "void walk() { \tint dx = 0, dy = 1, i, k; \tint x = w / 2, y = h / 2; \tpix = calloc(1, w * h); \tprintf(\"\\033[H\\033[J\"); \twhile (1) { \t\ti = (y * w + x); \t\tif (pix[i]) k = dx, dx = -dy, dy = k; \t\telse\t k = dy, dy = -dx, dx = k; \t\tpix[i] = !pix[i]; \t\tprintf(\"\\033[%d;%dH%c\", y + 1, x + 1, pix[i] ? '#' : ' '); \t\tx += dx, y += dy; \t\tk = 0; \t\tif (x < 0) { \t\t\tmemmove(pix + 1, pix, w * h - 1); \t\t\tfor (i = 0; i < w * h; i += w) pix[i] = 0; \t\t\tx++, k = 1; \t\t} \t\telse if (x >= w) { \t\t\tmemmove(pix, pix + 1, w * h - 1); \t\t\tfor (i = w-1; i < w * h; i += w) pix[i] = 0; \t\t\tx--, k = 1; \t\t} \t\tif (y >= h) { \t\t\tmemmove(pix, pix + w, w * (h - 1)); \t\t\tmemset(pix + w * (h - 1), 0, w); \t\t\ty--, k = 1; \t\t} \t\telse if (y < 0) { \t\t\tmemmove(pix + w, pix, w * (h - 1)); \t\t\tmemset(pix, 0, w); \t\t\ty++, k = 1; \t\t} \t\tif (k) refresh(x, y); \t\tprintf(\"\\033[%d;%dH\\033[31m@\\033[m\", y + 1, x + 1); \t\tfflush(stdout); \t\tusleep(10000); \t} }", |
|
"after": "pub extern \"C\" fn walk() { let mut dx: i32 = 0; let mut dy: i32 = 1; let mut i: i32 = 0; let mut k: i32 = 0; unsafe { let mut x: i32 = w / 2; let mut y: i32 = h / 2; pix = calloc(1, (w * h) as u64) as *mut u8; print!(\"\\x1B[H\\x1B[J\"); loop { i = y * w + x; if *pix.offset(i as isize) != 0 { k = dx; dx = -dy; dy = k; } else { k = dy; dy = -dx; dx = k; }; *pix.offset(i as isize) = (*pix.offset(i as isize) == 0) as u8; if *pix.offset(i as isize) as i32 != 0 { print!(\"\\x1B[{};{}H{}\", y + 1, x + 1, '#' as i32) } else { print!(\"\\x1B[{};{}H{}\", y + 1, x + 1, ' ' as i32) }; x += dx; y += dy; k = 0; if x < 0 { memmove( pix.offset(1 as isize) as *mut libc::c_void, pix as *const libc::c_void, (w * h - 1i32) as u64, ); i = 0; while i < w * h { *pix.offset(i as isize) = 0; i += w; } x += 1; x; k = 1; } else if x >= w { memmove( pix as *mut libc::c_void, pix.offset(1 as isize) as *const libc::c_void, (w * h - 1i32) as u64, ); i = w - 1; while i < w * h { *pix.offset(i as isize) = 0; i += w; } x -= 1; x; k = 1; } if y >= h { memmove( pix as *mut libc::c_void, pix.offset(w as isize) as *const libc::c_void, (w * (h - 1i32)) as u64, ); memset( pix.offset((w * (h - 1i32)) as isize) as *mut libc::c_void, 0, w as u64, ); y -= 1; y; k = 1; } else if y < 0 { memmove( pix.offset(w as isize) as *mut libc::c_void, pix as *const libc::c_void, (w * (h - 1i32)) as u64, ); memset(pix as *mut libc::c_void, 0, w as u64); y += 1; y; k = 1; } if k != 0 { refresh(x, y); } print!(\"\\x1B[{};{}H\\x1B[31m@\\x1B[m\", y + 1, x + 1); fflush(stdout); usleep(10000); } } }" |
|
}, |
|
{ |
|
"index": 53, |
|
"before": "void refresh(int x, int y) { \tint i, j, k; \tprintf(\"\\033[H\"); \tfor (i = k = 0; i < h; putchar('\\n'), i++) \t\tfor (j = 0; j < w; j++, k++) \t\t\tputchar(pix[k] ? '#' : ' '); }", |
|
"after": "pub extern \"C\" fn refresh(mut x: i32, mut y: i32) { let mut i: i32 = 0; let mut j: i32 = 0; let mut k: i32 = 0; print!(\"\\x1B[H\"); k = 0; i = k; unsafe { while i < h { j = 0; while j < w { print!( \"{}\", if *pix.offset(k as isize) as i32 != 0 { '#' as i32 } else { ' ' as i32 } ); j += 1; j; k += 1; k; } print!(\"{}\", '\\n' as i32); i += 1; i; } } }" |
|
}, |
|
{ |
|
"index": 54, |
|
"before": "int main(int c, char **v) { \tif (c > 1) w = atoi(v[1]); \tif (c > 2) h = atoi(v[2]); \tif (w < 40) w = 40; \tif (h < 25) h = 25; \twalk(); \treturn 0; }", |
|
"after": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { if c > 1 { w = atoi(*v.offset(1 as isize)); } if c > 2 { h = atoi(*v.offset(2 as isize)); } if w < 40 { w = 40; } if h < 25 { h = 25; } walk(); return 0; } }" |
|
}, |
|
{ |
|
"index": 55, |
|
"before": "int main(void) { \tchar* blocks[] = { \t\t\"BO\", \"XK\", \"DQ\", \"CP\", \"NA\", \t\t\"GT\", \"RE\", \"TG\", \"QD\", \"FS\", \t\t\"JW\", \"HU\", \"VI\", \"AN\", \"OB\", \t\t\"ER\", \"FS\", \"LY\", \"PC\", \"ZM\", \t\t0 }; \tchar *words[] = { \t\t\"\", \"A\", \"BARK\", \"BOOK\", \"TREAT\", \"COMMON\", \"SQUAD\", \"Confuse\", 0 \t}; \tchar **w; \tfor (w = words; *w; w++) \t\tprintf(\"%s\\t%d\\n\", *w, can_make_words(blocks, *w)); \treturn 0; }", |
|
"after": "fn main() -> i32 { unsafe { let mut blocks: [*mut i8; 21] = [ b\"BO\\0\" as *const u8 as *const i8 as *mut i8, b\"XK\\0\" as *const u8 as *const i8 as *mut i8, b\"DQ\\0\" as *const u8 as *const i8 as *mut i8, b\"CP\\0\" as *const u8 as *const i8 as *mut i8, b\"NA\\0\" as *const u8 as *const i8 as *mut i8, b\"GT\\0\" as *const u8 as *const i8 as *mut i8, b\"RE\\0\" as *const u8 as *const i8 as *mut i8, b\"TG\\0\" as *const u8 as *const i8 as *mut i8, b\"QD\\0\" as *const u8 as *const i8 as *mut i8, b\"FS\\0\" as *const u8 as *const i8 as *mut i8, b\"JW\\0\" as *const u8 as *const i8 as *mut i8, b\"HU\\0\" as *const u8 as *const i8 as *mut i8, b\"VI\\0\" as *const u8 as *const i8 as *mut i8, b\"AN\\0\" as *const u8 as *const i8 as *mut i8, b\"OB\\0\" as *const u8 as *const i8 as *mut i8, b\"ER\\0\" as *const u8 as *const i8 as *mut i8, b\"FS\\0\" as *const u8 as *const i8 as *mut i8, b\"LY\\0\" as *const u8 as *const i8 as *mut i8, b\"PC\\0\" as *const u8 as *const i8 as *mut i8, b\"ZM\\0\" as *const u8 as *const i8 as *mut i8, 0 as *mut i8, ]; let mut words: [*mut i8; 9] = [ b\"\\0\" as *const u8 as *const i8 as *mut i8, b\"A\\0\" as *const u8 as *const i8 as *mut i8, b\"BARK\\0\" as *const u8 as *const i8 as *mut i8, b\"BOOK\\0\" as *const u8 as *const i8 as *mut i8, b\"TREAT\\0\" as *const u8 as *const i8 as *mut i8, b\"COMMON\\0\" as *const u8 as *const i8 as *mut i8, b\"SQUAD\\0\" as *const u8 as *const i8 as *mut i8, b\"Confuse\\0\" as *const u8 as *const i8 as *mut i8, 0 as *mut i8, ]; let mut w: *mut *mut i8 = 0 as *mut *mut i8; w = words.as_mut_ptr(); while !(*w).is_null() { print!( \"{}\t{}\\n\", build_str_from_raw_ptr(*w as *mut u8), can_make_words(blocks.as_mut_ptr(), *w) ); w = w.offset(1); w; } return 0; } }" |
|
}, |
|
{ |
|
"index": 56, |
|
"before": "int can_make_words(char **b, char *word) { \tint i, ret = 0, c = toupper(*word); #define SWAP(a, b) if (a != b) { char * tmp = a; a = b; b = tmp; } \tif (!c) return 1; \tif (!b[0]) return 0; \tfor (i = 0; b[i] && !ret; i++) { \t\tif (b[i][0] != c && b[i][1] != c) continue; \t\tSWAP(b[i], b[0]); \t\tret = can_make_words(b + 1, word + 1); \t\tSWAP(b[i], b[0]); \t} \treturn ret; }", |
|
"after": "pub extern \"C\" fn can_make_words(mut b: *mut *mut i8, mut word: *mut i8) -> i32 { unsafe { let mut i: i32 = 0; let mut ret: i32 = 0; let mut c: i32 = toupper(*word as i32); if c == 0 { return 1; } if (*b.offset(0 as isize)).is_null() { return 0; } i = 0; while !(*b.offset(i as isize)).is_null() && ret == 0 { if !(*(*b.offset(i as isize)).offset(0 as isize) as i32 != c && *(*b.offset(i as isize)).offset(1 as isize) as i32 != c) { if *b.offset(i as isize) != *b.offset(0 as isize) { let mut tmp: *mut i8 = *b.offset(i as isize); let ref mut fresh0 = *b.offset(i as isize); *fresh0 = *b.offset(0 as isize); let ref mut fresh1 = *b.offset(0 as isize); *fresh1 = tmp; } ret = can_make_words(b.offset(1 as isize), word.offset(1 as isize)); if *b.offset(i as isize) != *b.offset(0 as isize) { let mut tmp_0: *mut i8 = *b.offset(i as isize); let ref mut fresh2 = *b.offset(i as isize); *fresh2 = *b.offset(0 as isize); let ref mut fresh3 = *b.offset(0 as isize); *fresh3 = tmp_0; } } i += 1; i; } return ret; } }" |
|
}, |
|
{ |
|
"index": 57, |
|
"before": "void sc_up() { \tscale *= 2; x *= 2; y *= 2; \tcscale *= 3; }", |
|
"after": "pub unsafe extern \"C\" fn sc_up() { 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; cscale *= 3 as libc::c_int as libc::c_longlong; }" |
|
}, |
|
{ |
|
"index": 58, |
|
"before": "void sierp(long leng, int depth) { \tlong i; \tlong h = leng + 20, w = leng + 20; \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 = 10; dx = leng; dy = leng; scale = 1; clen = 0; cscale = 3; \tfor (i = 0; i < depth; i++) sc_up(); \titer_string(\"VXH\", depth); \t/* write color PNM file */ \tunsigned char *fpix = malloc(w * h * 3); \tdouble maxv = 0, *dbuf = (double*)buf; \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 sierp(mut leng: libc::c_long, mut depth: libc::c_int) { let mut i: libc::c_long = 0; let mut h: libc::c_long = leng + 20 as libc::c_int as libc::c_long; let mut w: libc::c_long = leng + 20 as libc::c_int as libc::c_long; let mut buf: *mut rgb = malloc( (::core::mem::size_of::<rgb>() 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 fresh3 = *pix.offset(i as isize); *fresh3 = 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::<rgb>() as libc::c_ulong) .wrapping_mul(w as libc::c_ulong) .wrapping_mul(h as libc::c_ulong), ); y = 10 as libc::c_int as libc::c_longlong; x = y; dx = leng as libc::c_longlong; dy = leng as libc::c_longlong; scale = 1 as libc::c_int as libc::c_longlong; clen = 0 as libc::c_int as libc::c_longlong; cscale = 3 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\"VXH\\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": 59, |
|
"before": "void iter_string(const char * str, int d) { \tlong long len; \twhile (*str != '\\0') { \t\tswitch(*(str++)) { \t\tcase 'X': \t\t\tif (d)\titer_string(\"XHXVX\", d - 1); \t\t\telse{ \t\t\t\tclen ++; \t\t\t\th_rgb(x/scale, y/scale); \t\t\t\tx += dx; \t\t\t\ty -= dy; \t\t\t} \t\t\tcontinue; \t\tcase 'V': \t\t\tlen = 1LLU << d; \t\t\twhile (len--) { \t\t\t\tclen ++; \t\t\t\th_rgb(x/scale, y/scale); \t\t\t\ty += dy; \t\t\t} \t\t\tcontinue; \t\tcase 'H': \t\t\tlen = 1LLU << d; \t\t\twhile(len --) { \t\t\t\tclen ++; \t\t\t\th_rgb(x/scale, y/scale); \t\t\t\tx -= dx; \t\t\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 len: libc::c_longlong = 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\"XHXVX\\0\" as *const u8 as *const libc::c_char, d - 1 as libc::c_int, ); } else { clen += 1; clen; h_rgb(x / scale, y / scale); x += dx; y -= dy; } } 86 => { len = ((1 as libc::c_ulonglong) << d) as libc::c_longlong; loop { let fresh1 = len; len = len - 1; if !(fresh1 != 0) { break; } clen += 1; clen; h_rgb(x / scale, y / scale); y += dy; } } 72 => { len = ((1 as libc::c_ulonglong) << d) as libc::c_longlong; loop { let fresh2 = len; len = len - 1; if !(fresh2 != 0) { break; } clen += 1; clen; h_rgb(x / scale, y / scale); x -= dx; } } _ => {} } } }" |
|
}, |
|
{ |
|
"index": 60, |
|
"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); \tsierp(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, ); sierp(size as libc::c_long, depth + 2 as libc::c_int); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 61, |
|
"before": "void h_rgb(long long x, long long y) { \trgb *p = &pix[y][x]; #\tdefine SAT 1 \tdouble h = 6.0 * clen / cscale; \tdouble VAL = 1; \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 / cscale as libc::c_double; let mut VAL: libc::c_double = 1 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": 62, |
|
"before": "int main(void) { \tint i; \tfor (i = 2; i < 100; i++) \t\tif (semiprime(i)) printf(\" %d\", i); \tputchar('\\n'); \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; i = 2 as libc::c_int; while i < 100 as libc::c_int { if semiprime(i) != 0 { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, i); } i += 1; i; } putchar('\\n' as i32); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 63, |
|
"before": "int semiprime(int n) { \tint p, f = 0; \tfor (p = 2; f < 2 && p*p <= n; p++) \t\twhile (0 == n % p) \t\t\tn /= p, f++; \treturn f + (n > 1) == 2; }", |
|
"after": "pub unsafe extern \"C\" fn semiprime(mut n: libc::c_int) -> libc::c_int { let mut p: libc::c_int = 0; let mut f: libc::c_int = 0 as libc::c_int; p = 2 as libc::c_int; while f < 2 as libc::c_int && p * p <= n { while 0 as libc::c_int == n % p { n /= p; f += 1; f; } p += 1; p; } return (f + (n > 1 as libc::c_int) as libc::c_int == 2 as libc::c_int) as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 64, |
|
"before": "void lcs(const char *const sa, const char *const sb, char **const beg, char **const end) { size_t apos, bpos; ptrdiff_t len; *beg = 0; *end = 0; len = 0; for (apos = 0; sa[apos] != 0; ++apos) { for (bpos = 0; sb[bpos] != 0; ++bpos) { if (sa[apos] == sb[bpos]) { len = 1; while (sa[apos + len] != 0 && sb[bpos + len] != 0 && sa[apos + len] == sb[bpos + len]) { len++; } } if (len > *end - *beg) { *beg = sa + apos; *end = *beg + len; len = 0; } } } }", |
|
"after": "pub unsafe extern \"C\" fn lcs( sa: *const libc::c_char, sb: *const libc::c_char, beg: *mut *mut libc::c_char, end: *mut *mut libc::c_char, ) { let mut apos: size_t = 0; let mut bpos: size_t = 0; let mut len: ptrdiff_t = 0; *beg = 0 as *mut libc::c_char; *end = 0 as *mut libc::c_char; len = 0 as libc::c_int; apos = 0 as libc::c_int as size_t; while *sa.offset(apos as isize) as libc::c_int != 0 as libc::c_int { bpos = 0 as libc::c_int as size_t; while *sb.offset(bpos as isize) as libc::c_int != 0 as libc::c_int { if *sa.offset(apos as isize) as libc::c_int == *sb.offset(bpos as isize) as libc::c_int { len = 1 as libc::c_int; while *sa.offset(apos.wrapping_add(len as libc::c_ulong) as isize) as libc::c_int != 0 as libc::c_int && *sb.offset(bpos.wrapping_add(len as libc::c_ulong) as isize) as libc::c_int != 0 as libc::c_int && *sa.offset(apos.wrapping_add(len as libc::c_ulong) as isize) as libc::c_int == *sb.offset(bpos.wrapping_add(len as libc::c_ulong) as isize) as libc::c_int { len += 1; len; } } if len as libc::c_long > (*end).offset_from(*beg) as libc::c_long { *beg = sa.offset(apos as isize) as *mut libc::c_char; *end = (*beg).offset(len as isize); len = 0 as libc::c_int; } bpos = bpos.wrapping_add(1); bpos; } apos = apos.wrapping_add(1); apos; } }" |
|
}, |
|
{ |
|
"index": 65, |
|
"before": "int main() { char *s1 = \"thisisatest\"; char *s2 = \"testing123testing\"; char *beg, *end, *it; lcs(s1, s2, &beg, &end); for (it = beg; it != end; it++) { putchar(*it); } printf(\"\\n\"); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut s1: *mut libc::c_char = b\"thisisatest\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; let mut s2: *mut libc::c_char = b\"testing123testing\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; let mut beg: *mut libc::c_char = 0 as *mut libc::c_char; let mut end: *mut libc::c_char = 0 as *mut libc::c_char; let mut it: *mut libc::c_char = 0 as *mut libc::c_char; lcs(s1, s2, &mut beg, &mut end); it = beg; while it != end { putchar(*it as libc::c_int); it = it.offset(1); it; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 66, |
|
"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<i;j++){ \t\t\tif(arr[j]==arr[i]){ \t\t\t\tprintSeries(arr,i+1,\"Cyclic\"); \t\t\t\treturn; \t\t\t} \t\t} \t} \tprintSeries(arr,i+1,\"Non-Terminating\"); }", |
|
"after": "pub unsafe extern \"C\" fn aliquotClassifier(mut n: libc::c_ulonglong) { let mut arr: [libc::c_ulonglong; 16] = [0; 16]; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; arr[0 as libc::c_int as usize] = n; i = 1 as libc::c_int; while i < 16 as libc::c_int { arr[i as usize] = bruteForceProperDivisorSum(arr[(i - 1 as libc::c_int) as usize]); if arr[i as usize] == 0 as libc::c_int as libc::c_ulonglong || arr[i as usize] == n || arr[i as usize] == arr[(i - 1 as libc::c_int) as usize] && arr[i as usize] != n { printSeries( arr.as_mut_ptr(), i + 1 as libc::c_int, (if arr[i as usize] == 0 as libc::c_int as libc::c_ulonglong { b\"Terminating\\0\" as *const u8 as *const libc::c_char } else if arr[i as usize] == n && i == 1 as libc::c_int { b\"Perfect\\0\" as *const u8 as *const libc::c_char } else if arr[i as usize] == n && i == 2 as libc::c_int { b\"Amicable\\0\" as *const u8 as *const libc::c_char } else if arr[i as usize] == arr[(i - 1 as libc::c_int) as usize] && arr[i as usize] != n { b\"Aspiring\\0\" as *const u8 as *const libc::c_char } else { b\"Sociable\\0\" as *const u8 as *const libc::c_char }) as *mut libc::c_char, ); return; } j = 1 as libc::c_int; while j < i { if arr[j as usize] == arr[i as usize] { printSeries( arr.as_mut_ptr(), i + 1 as libc::c_int, b\"Cyclic\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); return; } j += 1; j; } i += 1; i; } printSeries( arr.as_mut_ptr(), i + 1 as libc::c_int, b\"Non-Terminating\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); }" |
|
}, |
|
{ |
|
"index": 67, |
|
"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<size-1;i++) \t\tprintf(\"%llu, \",arr[i]); \tprintf(\"%llu\",arr[i]); }", |
|
"after": "pub unsafe extern \"C\" fn printSeries( mut arr: *mut libc::c_ulonglong, mut size: libc::c_int, mut type_0: *mut libc::c_char, ) { let mut i: libc::c_int = 0; printf( b\"\\nInteger : %llu, Type : %s, Series : \\0\" as *const u8 as *const libc::c_char, *arr.offset(0 as libc::c_int as isize), type_0, ); i = 0 as libc::c_int; while i < size - 1 as libc::c_int { printf(b\"%llu, \\0\" as *const u8 as *const libc::c_char, *arr.offset(i as isize)); i += 1; i; } printf(b\"%llu\\0\" as *const u8 as *const libc::c_char, *arr.offset(i as isize)); }" |
|
}, |
|
{ |
|
"index": 68, |
|
"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 unsafe extern \"C\" fn processFile(mut fileName: *mut libc::c_char) { let mut fp: *mut FILE = fopen(fileName, b\"r\\0\" as *const u8 as *const libc::c_char); let mut str: [libc::c_char; 21] = [0; 21]; while !(fgets(str.as_mut_ptr(), 21 as libc::c_int, fp)).is_null() { aliquotClassifier( strtoull( str.as_mut_ptr(), 0 as *mut libc::c_void as *mut *mut libc::c_char, 10 as libc::c_int, ), ); } fclose(fp); }" |
|
}, |
|
{ |
|
"index": 69, |
|
"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 unsafe extern \"C\" fn bruteForceProperDivisorSum( mut n: libc::c_ulonglong, ) -> libc::c_ulonglong { let mut i: libc::c_ulonglong = 0; let mut sum: libc::c_ulonglong = 0 as libc::c_int as libc::c_ulonglong; i = 1 as libc::c_int as libc::c_ulonglong; while i < n .wrapping_add(1 as libc::c_int as libc::c_ulonglong) .wrapping_div(2 as libc::c_int as libc::c_ulonglong) { if n.wrapping_rem(i) == 0 as libc::c_int as libc::c_ulonglong && n != i { sum = sum.wrapping_add(i); } i = i.wrapping_add(1); i; } return sum; }" |
|
}, |
|
{ |
|
"index": 70, |
|
"before": "int main(int argC,char* argV[]) { if(argC!=2) \t\tprintf(\"Usage : %s <positive integer>\",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": "unsafe fn main( mut argC: libc::c_int, mut argV: *mut *mut libc::c_char, ) -> libc::c_int { if argC != 2 as libc::c_int { printf( b\"Usage : %s <positive integer>\\0\" as *const u8 as *const libc::c_char, *argV.offset(0 as libc::c_int as isize), ); } else if !(strchr(*argV.offset(1 as libc::c_int as isize), '.' as i32)).is_null() { processFile(*argV.offset(1 as libc::c_int as isize)); } else { aliquotClassifier( strtoull( *argV.offset(1 as libc::c_int as isize), 0 as *mut libc::c_void as *mut *mut libc::c_char, 10 as libc::c_int, ), ); } return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 71, |
|
"before": "int main() { int n = 0, y, i, m; struct tm t = {0}; printf(\"Months with five weekends:\\n\"); for (y = 1900; y <= 2100; y++) { for (i = 0; i < 7; i++) { m = long_months[i]; t.tm_year = y-1900; \t t.tm_mon = m; \t t.tm_mday = 1; if (mktime(&t) == -1) { /* date not supported */ printf(\"Error: %d %s\\n\", y, months[m]); continue; } if (t.tm_wday == 5) { /* Friday */ printf(\" %d %s\\n\", y, months[m]); n++; } } } printf(\"%d total\\n\", n); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 0 as libc::c_int; let mut y: libc::c_int = 0; let mut i: libc::c_int = 0; let mut m: libc::c_int = 0; let mut t: tm = { let mut init = tm { tm_sec: 0 as libc::c_int, tm_min: 0, tm_hour: 0, tm_mday: 0, tm_mon: 0, tm_year: 0, tm_wday: 0, tm_yday: 0, tm_isdst: 0, tm_gmtoff: 0, tm_zone: 0 as *const libc::c_char, }; init }; printf(b\"Months with five weekends:\\n\\0\" as *const u8 as *const libc::c_char); y = 1900 as libc::c_int; while y <= 2100 as libc::c_int { i = 0 as libc::c_int; while i < 7 as libc::c_int { m = long_months[i as usize]; t.tm_year = y - 1900 as libc::c_int; t.tm_mon = m; t.tm_mday = 1 as libc::c_int; if mktime(&mut t) == -(1 as libc::c_int) as libc::c_long { printf( b\"Error: %d %s\\n\\0\" as *const u8 as *const libc::c_char, y, months[m as usize], ); } else if t.tm_wday == 5 as libc::c_int { printf( b\" %d %s\\n\\0\" as *const u8 as *const libc::c_char, y, months[m as usize], ); n += 1; n; } i += 1; i; } y += 1; y; } printf(b\"%d total\\n\\0\" as *const u8 as *const libc::c_char, n); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 72, |
|
"before": "int main(int argc, char* argv[]) { int i; (void) printf(\"This program is named %s.\\n\", argv[0]); for (i = 1; i < argc; ++i) (void) printf(\"the argument #%d is %s\\n\", i, argv[i]); return EXIT_SUCCESS; }", |
|
"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; printf( b\"This program is named %s.\\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); i = 1 as libc::c_int; while i < argc { printf( b\"the argument #%d is %s\\n\\0\" as *const u8 as *const libc::c_char, i, *argv.offset(i as isize), ); i += 1; i; } return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 73, |
|
"before": "int main() { int a, b; scanf(\"%d%d\", &a, &b); printf(\"%d\\n\", a + b); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut a: libc::c_int = 0; let mut b: libc::c_int = 0; scanf( b\"%d%d\\0\" as *const u8 as *const libc::c_char, &mut a as *mut libc::c_int, &mut b as *mut libc::c_int, ); printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, a + b); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 74, |
|
"before": "int main() { printf(\"%lu\\n\", binomial(5, 3)); printf(\"%lu\\n\", binomial(40, 19)); printf(\"%lu\\n\", binomial(67, 31)); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { printf( b\"%lu\\n\\0\" as *const u8 as *const libc::c_char, binomial(5 as libc::c_int as libc::c_ulong, 3 as libc::c_int as libc::c_ulong), ); printf( b\"%lu\\n\\0\" as *const u8 as *const libc::c_char, binomial(40 as libc::c_int as libc::c_ulong, 19 as libc::c_int as libc::c_ulong), ); printf( b\"%lu\\n\\0\" as *const u8 as *const libc::c_char, binomial(67 as libc::c_int as libc::c_ulong, 31 as libc::c_int as libc::c_ulong), ); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 75, |
|
"before": "unsigned long binomial(unsigned long n, unsigned long k) { unsigned long d, g, r = 1; if (k == 0) return 1; if (k == 1) return n; if (k >= n) return (k == n); if (k > n/2) k = n-k; for (d = 1; d <= k; d++) { if (r >= ULONG_MAX/n) { /* Possible overflow */ unsigned long nr, dr; /* reduced numerator / denominator */ g = gcd_ui(n, d); nr = n/g; dr = d/g; g = gcd_ui(r, dr); r = r/g; dr = dr/g; if (r >= ULONG_MAX/nr) return 0; /* Unavoidable overflow */ r *= nr; r /= dr; n--; } else { r *= n--; r /= d; } } return r; }", |
|
"after": "pub unsafe extern \"C\" fn binomial( mut n: libc::c_ulong, mut k: libc::c_ulong, ) -> libc::c_ulong { let mut d: libc::c_ulong = 0; let mut g: libc::c_ulong = 0; let mut r: libc::c_ulong = 1 as libc::c_int as libc::c_ulong; if k == 0 as libc::c_int as libc::c_ulong { return 1 as libc::c_int as libc::c_ulong; } if k == 1 as libc::c_int as libc::c_ulong { return n; } if k >= n { return (k == n) as libc::c_int as libc::c_ulong; } if k > n.wrapping_div(2 as libc::c_int as libc::c_ulong) { k = n.wrapping_sub(k); } d = 1 as libc::c_int as libc::c_ulong; while d <= k { if r >= (9223372036854775807 as libc::c_long as libc::c_ulong) .wrapping_mul(2 as libc::c_ulong) .wrapping_add(1 as libc::c_ulong) .wrapping_div(n) { let mut nr: libc::c_ulong = 0; let mut dr: libc::c_ulong = 0; g = gcd_ui(n, d); nr = n.wrapping_div(g); dr = d.wrapping_div(g); g = gcd_ui(r, dr); r = r.wrapping_div(g); dr = dr.wrapping_div(g); if r >= (9223372036854775807 as libc::c_long as libc::c_ulong) .wrapping_mul(2 as libc::c_ulong) .wrapping_add(1 as libc::c_ulong) .wrapping_div(nr) { return 0 as libc::c_int as libc::c_ulong; } r = r.wrapping_mul(nr); r = r.wrapping_div(dr); n = n.wrapping_sub(1); n; } else { let fresh0 = n; n = n.wrapping_sub(1); r = r.wrapping_mul(fresh0); r = r.wrapping_div(d); } d = d.wrapping_add(1); d; } return r; }" |
|
}, |
|
{ |
|
"index": 76, |
|
"before": "static unsigned long gcd_ui(unsigned long x, unsigned long y) { unsigned long t; if (y < x) { t = x; x = y; y = t; } while (y > 0) { t = y; y = x % y; x = t; /* y1 <- x0 % y0 ; x1 <- y0 */ } return x; }", |
|
"after": "unsafe extern \"C\" fn gcd_ui( mut x: libc::c_ulong, mut y: libc::c_ulong, ) -> libc::c_ulong { let mut t: libc::c_ulong = 0; if y < x { t = x; x = y; y = t; } while y > 0 as libc::c_int as libc::c_ulong { t = y; y = x.wrapping_rem(y); x = t; } return x; }" |
|
}, |
|
{ |
|
"index": 77, |
|
"before": "size_t nub(int *a, size_t n) { size_t m = 0; for (size_t i = 0; i < n; ++i) if (!elem(a, m, a[i])) a[m++] = a[i]; return m; }", |
|
"after": "pub unsafe extern \"C\" fn nub(mut a: *mut libc::c_int, mut n: size_t) -> size_t { let mut m: size_t = 0 as libc::c_int as size_t; let mut i: size_t = 0 as libc::c_int as size_t; while i < n { if !elem(a, m, *a.offset(i as isize)) { let fresh0 = m; m = m.wrapping_add(1); *a.offset(fresh0 as isize) = *a.offset(i as isize); } i = i.wrapping_add(1); i; } return m; }" |
|
}, |
|
{ |
|
"index": 78, |
|
"before": "size_t nub_new(int **b, int *a, size_t n) { int *c = malloc(n * sizeof(int)); memcpy(c, a, n * sizeof(int)); int m = nub(c, n); *b = malloc(m * sizeof(int)); memcpy(*b, c, m * sizeof(int)); free(c); return m; }", |
|
"after": "pub unsafe extern \"C\" fn nub_new( mut b: *mut *mut libc::c_int, mut a: *mut libc::c_int, mut n: size_t, ) -> size_t { let mut c: *mut libc::c_int = malloc( n.wrapping_mul(::core::mem::size_of::<libc::c_int>() as libc::c_ulong), ) as *mut libc::c_int; memcpy( c as *mut libc::c_void, a as *const libc::c_void, n.wrapping_mul(::core::mem::size_of::<libc::c_int>() as libc::c_ulong), ); let mut m: libc::c_int = nub(c, n) as libc::c_int; *b = malloc( (m as libc::c_ulong) .wrapping_mul(::core::mem::size_of::<libc::c_int>() as libc::c_ulong), ) as *mut libc::c_int; memcpy( *b as *mut libc::c_void, c as *const libc::c_void, (m as libc::c_ulong) .wrapping_mul(::core::mem::size_of::<libc::c_int>() as libc::c_ulong), ); free(c as *mut libc::c_void); return m as size_t; }" |
|
}, |
|
{ |
|
"index": 79, |
|
"before": "int main(void) { int a[] = {1, 2, 1, 4, 5, 2, 15, 1, 3, 4}; int *b; size_t n = nub_new(&b, a, sizeof(a) / sizeof(a[0])); for (size_t i = 0; i < n; ++i) printf(\"%d \", b[i]); puts(\"\"); free(b); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut a: [libc::c_int; 10] = [ 1 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 4 as libc::c_int, 5 as libc::c_int, 2 as libc::c_int, 15 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 4 as libc::c_int, ]; let mut b: *mut libc::c_int = 0 as *mut libc::c_int; let mut n: size_t = nub_new( &mut b, a.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 10]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::<libc::c_int>() as libc::c_ulong), ); let mut i: size_t = 0 as libc::c_int as size_t; while i < n { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, *b.offset(i as isize)); i = i.wrapping_add(1); i; } puts(b\"\\0\" as *const u8 as *const libc::c_char); free(b as *mut libc::c_void); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 80, |
|
"before": "bool elem(int *a, size_t n, int e) { for (size_t i = 0; i < n; ++i) if (a[i] == e) return true; return false; }", |
|
"after": "pub unsafe extern \"C\" fn elem( mut a: *mut libc::c_int, mut n: size_t, mut e: libc::c_int, ) -> bool { let mut i: size_t = 0 as libc::c_int as size_t; while i < n { if *a.offset(i as isize) == e { return 1 as libc::c_int != 0; } i = i.wrapping_add(1); i; } return 0 as libc::c_int != 0; }" |
|
}, |
|
{ |
|
"index": 81, |
|
"before": "int main(void) { \tint x[] = {1, 34, 3, 98, 9, 76, 45, 4}; \tint y[] = {54, 546, 548, 60}; \tmaxcat(x, sizeof(x)/sizeof(x[0])); \tmaxcat(y, sizeof(y)/sizeof(y[0])); \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut x: [libc::c_int; 8] = [ 1 as libc::c_int, 34 as libc::c_int, 3 as libc::c_int, 98 as libc::c_int, 9 as libc::c_int, 76 as libc::c_int, 45 as libc::c_int, 4 as libc::c_int, ]; let mut y: [libc::c_int; 4] = [ 54 as libc::c_int, 546 as libc::c_int, 548 as libc::c_int, 60 as libc::c_int, ]; maxcat( x.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 8]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::<libc::c_int>() as libc::c_ulong) as libc::c_int, ); maxcat( y.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 4]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::<libc::c_int>() as libc::c_ulong) as libc::c_int, ); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 82, |
|
"before": "void maxcat(int *a, int len) { \tint i; \tqsort(a, len, sizeof(int), catcmp); \tfor (i = 0; i < len; i++) \t\tprintf(\"%d\", a[i]); \tputchar('\\n'); }", |
|
"after": "pub unsafe extern \"C\" fn maxcat(mut a: *mut libc::c_int, mut len: libc::c_int) { let mut i: libc::c_int = 0; qsort( a as *mut libc::c_void, len as size_t, ::core::mem::size_of::<libc::c_int>() as libc::c_ulong, Some( catcmp as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); i = 0 as libc::c_int; while i < len { printf(b\"%d\\0\" as *const u8 as *const libc::c_char, *a.offset(i as isize)); i += 1; i; } putchar('\\n' as i32); }" |
|
}, |
|
{ |
|
"index": 83, |
|
"before": "int main() { int i; point cases[] = \t {\t{0.1234, 0.9876}, {0.8765, 0.2345}, \t{0.0000, 2.0000}, {0.0000, 0.0000}, \t{0.1234, 0.9876}, {0.1234, 0.9876}, \t{0.1234, 0.9876}, {0.8765, 0.2345}, \t{0.1234, 0.9876}, {0.1234, 0.9876} }; double radii[] = {2.0,1.0,2.0,0.5,0.0}; for(i=0;i<5;i++) {\t \tprintf(\"\\nCase %d)\",i+1); \tfindCircles(cases[2*i],cases[2*i+1],radii[i]); } return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut cases: [point; 10] = [ { let mut init = point { x: 0.1234f64, y: 0.9876f64, }; init }, { let mut init = point { x: 0.8765f64, y: 0.2345f64, }; init }, { let mut init = point { x: 0.0000f64, y: 2.0000f64, }; init }, { let mut init = point { x: 0.0000f64, y: 0.0000f64, }; init }, { let mut init = point { x: 0.1234f64, y: 0.9876f64, }; init }, { let mut init = point { x: 0.1234f64, y: 0.9876f64, }; init }, { let mut init = point { x: 0.1234f64, y: 0.9876f64, }; init }, { let mut init = point { x: 0.8765f64, y: 0.2345f64, }; init }, { let mut init = point { x: 0.1234f64, y: 0.9876f64, }; init }, { let mut init = point { x: 0.1234f64, y: 0.9876f64, }; init }, ]; let mut radii: [libc::c_double; 5] = [2.0f64, 1.0f64, 2.0f64, 0.5f64, 0.0f64]; i = 0 as libc::c_int; while i < 5 as libc::c_int { printf( b\"\\nCase %d)\\0\" as *const u8 as *const libc::c_char, i + 1 as libc::c_int, ); findCircles( cases[(2 as libc::c_int * i) as usize], cases[(2 as libc::c_int * i + 1 as libc::c_int) as usize], radii[i as usize], ); i += 1; i; } return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 84, |
|
"before": "void findCircles(point p1,point p2,double radius) { \tdouble separation = distance(p1,p2),mirrorDistance; \tif(separation == 0.0) \t{ \t\tradius == 0.0 ? printf(\"\\nNo circles can be drawn through (%.4f,%.4f)\",p1.x,p1.y): \t\t\t\t\t\t\t printf(\"\\nInfinitely many circles can be drawn through (%.4f,%.4f)\",p1.x,p1.y); \t} \telse if(separation == 2*radius) \t{ \t\tprintf(\"\\nGiven points are opposite ends of a diameter of the circle with center (%.4f,%.4f) and radius %.4f\",(p1.x+p2.x)/2,(p1.y+p2.y)/2,radius); \t} \telse if(separation > 2*radius) \t{ \t\tprintf(\"\\nGiven points are farther away from each other than a diameter of a circle with radius %.4f\",radius); \t} \telse \t{ \t\tmirrorDistance =sqrt(pow(radius,2) - pow(separation/2,2)); \t\tprintf(\"\\nTwo circles are possible.\"); \t\tprintf(\"\\nCircle C1 with center (%.4f,%.4f), radius %.4f and Circle C2 with center (%.4f,%.4f), radius %.4f\",(p1.x+p2.x)/2 + mirrorDistance*(p1.y-p2.y)/separation,(p1.y+p2.y)/2 + mirrorDistance*(p2.x-p1.x)/separation,radius,(p1.x+p2.x)/2 - mirrorDistance*(p1.y-p2.y)/separation,(p1.y+p2.y)/2 - mirrorDistance*(p2.x-p1.x)/separation,radius); \t} }", |
|
"after": "pub unsafe extern \"C\" fn findCircles( mut p1: point, mut p2: point, mut radius: libc::c_double, ) { let mut separation: libc::c_double = distance(p1, p2); let mut mirrorDistance: libc::c_double = 0.; if separation == 0.0f64 { if radius == 0.0f64 { printf( b\"\\nNo circles can be drawn through (%.4f,%.4f)\\0\" as *const u8 as *const libc::c_char, p1.x, p1.y, ); } else { printf( b\"\\nInfinitely many circles can be drawn through (%.4f,%.4f)\\0\" as *const u8 as *const libc::c_char, p1.x, p1.y, ); }; } else if separation == 2 as libc::c_int as libc::c_double * radius { printf( b\"\\nGiven points are opposite ends of a diameter of the circle with center (%.4f,%.4f) and radius %.4f\\0\" as *const u8 as *const libc::c_char, (p1.x + p2.x) / 2 as libc::c_int as libc::c_double, (p1.y + p2.y) / 2 as libc::c_int as libc::c_double, radius, ); } else if separation > 2 as libc::c_int as libc::c_double * radius { printf( b\"\\nGiven points are farther away from each other than a diameter of a circle with radius %.4f\\0\" as *const u8 as *const libc::c_char, radius, ); } else { mirrorDistance = sqrt( pow(radius, 2 as libc::c_int as libc::c_double) - pow( separation / 2 as libc::c_int as libc::c_double, 2 as libc::c_int as libc::c_double, ), ); printf(b\"\\nTwo circles are possible.\\0\" as *const u8 as *const libc::c_char); printf( b\"\\nCircle C1 with center (%.4f,%.4f), radius %.4f and Circle C2 with center (%.4f,%.4f), radius %.4f\\0\" as *const u8 as *const libc::c_char, (p1.x + p2.x) / 2 as libc::c_int as libc::c_double + mirrorDistance * (p1.y - p2.y) / separation, (p1.y + p2.y) / 2 as libc::c_int as libc::c_double + mirrorDistance * (p2.x - p1.x) / separation, radius, (p1.x + p2.x) / 2 as libc::c_int as libc::c_double - mirrorDistance * (p1.y - p2.y) / separation, (p1.y + p2.y) / 2 as libc::c_int as libc::c_double - mirrorDistance * (p2.x - p1.x) / separation, radius, ); }; }" |
|
}, |
|
{ |
|
"index": 85, |
|
"before": "double distance(point p1,point p2) { \treturn sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); }", |
|
"after": "pub unsafe extern \"C\" fn distance(mut p1: point, mut p2: point) -> libc::c_double { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); }" |
|
}, |
|
{ |
|
"index": 86, |
|
"before": "int main() { \tint i, flip, *q = (int*)malloc(sizeof(int) * N) - 1; \tq[1] = q[2] = 1; \tfor (i = 3; i <= N; i++) \t\tq[i] = q[i - q[i - 1]] + q[i - q[i - 2]]; \tfor (i = 1; i <= 10; i++) \t\tprintf(\"%d%c\", q[i], i == 10 ? '\\n' : ' '); \tprintf(\"%d\\n\", q[1000]); \tfor (flip = 0, i = 1; i < N; i++) \t\tflip += q[i] > q[i + 1]; \tprintf(\"flips: %d\\n\", flip); \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut flip: libc::c_int = 0; let mut q: *mut libc::c_int = (malloc( (::core::mem::size_of::<libc::c_int>() as libc::c_ulong) .wrapping_mul(100000 as libc::c_int as libc::c_ulong), ) as *mut libc::c_int) .offset(-(1 as libc::c_int as isize)); let ref mut fresh0 = *q.offset(2 as libc::c_int as isize); *fresh0 = 1 as libc::c_int; *q.offset(1 as libc::c_int as isize) = *fresh0; i = 3 as libc::c_int; while i <= 100000 as libc::c_int { *q .offset( i as isize, ) = *q.offset((i - *q.offset((i - 1 as libc::c_int) as isize)) as isize) + *q.offset((i - *q.offset((i - 2 as libc::c_int) as isize)) as isize); i += 1; i; } i = 1 as libc::c_int; while i <= 10 as libc::c_int { printf( b\"%d%c\\0\" as *const u8 as *const libc::c_char, *q.offset(i as isize), if i == 10 as libc::c_int { '\\n' as i32 } else { ' ' as i32 }, ); i += 1; i; } printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, *q.offset(1000 as libc::c_int as isize), ); flip = 0 as libc::c_int; i = 1 as libc::c_int; while i < 100000 as libc::c_int { flip += (*q.offset(i as isize) > *q.offset((i + 1 as libc::c_int) as isize)) as libc::c_int; i += 1; i; } printf(b\"flips: %d\\n\\0\" as *const u8 as *const libc::c_char, flip); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 87, |
|
"before": "long int factorial(int n){ \tif(n>1) \t\treturn n*factorial(n-1); \treturn 1; }", |
|
"after": "pub unsafe extern \"C\" fn factorial(mut n: libc::c_int) -> libc::c_long { if n > 1 as libc::c_int { return n as libc::c_long * factorial(n - 1 as libc::c_int); } return 1 as libc::c_int as libc::c_long; }" |
|
}, |
|
{ |
|
"index": 88, |
|
"before": "int main() { \tprintf(\"\\nSum of factorials of [1,5] : %ld\",sumOfFactorials(5,1,2,3,4,5)); \tprintf(\"\\nSum of factorials of [3,5] : %ld\",sumOfFactorials(3,3,4,5)); \tprintf(\"\\nSum of factorials of [1,3] : %ld\",sumOfFactorials(3,1,2,3)); \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { printf( b\"\\nSum of factorials of [1,5] : %ld\\0\" as *const u8 as *const libc::c_char, sumOfFactorials( 5 as libc::c_int, 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\"\\nSum of factorials of [3,5] : %ld\\0\" as *const u8 as *const libc::c_char, sumOfFactorials( 3 as libc::c_int, 3 as libc::c_int, 4 as libc::c_int, 5 as libc::c_int, ), ); printf( b\"\\nSum of factorials of [1,3] : %ld\\0\" as *const u8 as *const libc::c_char, sumOfFactorials( 3 as libc::c_int, 1 as libc::c_int, 2 as libc::c_int, 3 as libc::c_int, ), ); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 89, |
|
"before": "long int sumOfFactorials(int num,...){ \tva_list vaList; \tlong int sum = 0; \tva_start(vaList,num); \twhile(num--) \t\tsum += factorial(va_arg(vaList,int)); \tva_end(vaList); \treturn sum; }", |
|
"after": "pub unsafe extern \"C\" fn sumOfFactorials( mut num: libc::c_int, mut args: ... ) -> libc::c_long { let mut vaList: ::core::ffi::VaListImpl; let mut sum: libc::c_long = 0 as libc::c_int as libc::c_long; vaList = args.clone(); loop { let fresh0 = num; num = num - 1; if !(fresh0 != 0) { break; } sum += factorial(vaList.arg::<libc::c_int>()); } return sum; }" |
|
}, |
|
{ |
|
"index": 90, |
|
"before": "int main(int argc, char* argv[]) { unsigned long i, n = 43112609; if (argc >= 2) n = strtoul(argv[1], 0, 10); for (i = 1; i <= n; i++) { if (lucas_lehmer(i)) { printf(\"M%lu \", i); fflush(stdout); } } printf(\"\\n\"); 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_ulong = 0; let mut n: libc::c_ulong = 43112609 as libc::c_int as libc::c_ulong; if argc >= 2 as libc::c_int { n = strtoul( *argv.offset(1 as libc::c_int as isize), 0 as *mut *mut libc::c_char, 10 as libc::c_int, ); } i = 1 as libc::c_int as libc::c_ulong; while i <= n { if lucas_lehmer(i) != 0 { printf(b\"M%lu \\0\" as *const u8 as *const libc::c_char, i); fflush(stdout); } i = i.wrapping_add(1); i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 91, |
|
"before": "int main(){ int a; /* ...input or change a here */ assert(a == 42); /* aborts program when a is not 42, unless the NDEBUG macro was defined */ return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut a: libc::c_int = 0; if a == 42 as libc::c_int {} else { __assert_fail( b\"a == 42\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 6 as libc::c_int as libc::c_uint, (*::core::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b\"int main()\\0\")) .as_ptr(), ); } 'c_59: { if a == 42 as libc::c_int {} else { __assert_fail( b\"a == 42\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 6 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 11], &[libc::c_char; 11], >(b\"int main()\\0\")) .as_ptr(), ); } }; return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 92, |
|
"before": "void leonardo(int a,int b,int step,int num){ \tint i,temp; \tprintf(\"First 25 Leonardo numbers : \\n\"); \tfor(i=1;i<=num;i++){ \t\tif(i==1) \t\t\tprintf(\" %d\",a); \t\telse if(i==2) \t\t\tprintf(\" %d\",b); \t\telse{ \t\t\tprintf(\" %d\",a+b+step); \t\t\ttemp = a; \t\t\ta = b; \t\t\tb = temp+b+step; \t\t} \t} }", |
|
"after": "pub unsafe extern \"C\" fn leonardo( mut a: libc::c_int, mut b: libc::c_int, mut step: libc::c_int, mut num: libc::c_int, ) { let mut i: libc::c_int = 0; let mut temp: libc::c_int = 0; printf(b\"First 25 Leonardo numbers : \\n\\0\" as *const u8 as *const libc::c_char); i = 1 as libc::c_int; while i <= num { if i == 1 as libc::c_int { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, a); } else if i == 2 as libc::c_int { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, b); } else { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, a + b + step); temp = a; a = b; b = temp + b + step; } i += 1; i; } }" |
|
}, |
|
{ |
|
"index": 93, |
|
"before": "int main() { \tint a,b,step; \tprintf(\"Enter first two Leonardo numbers and increment step : \"); \tscanf(\"%d%d%d\",&a,&b,&step); \tleonardo(a,b,step,25); \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut a: libc::c_int = 0; let mut b: libc::c_int = 0; let mut step: libc::c_int = 0; printf( b\"Enter first two Leonardo numbers and increment step : \\0\" as *const u8 as *const libc::c_char, ); scanf( b\"%d%d%d\\0\" as *const u8 as *const libc::c_char, &mut a as *mut libc::c_int, &mut b as *mut libc::c_int, &mut step as *mut libc::c_int, ); leonardo(a, b, step, 25 as libc::c_int); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 94, |
|
"before": "int main() { ubyte data[] = \"VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo\"; ubyte decoded[1024]; printf(\"%s\\n\\n\", data); decode(data, decoded); printf(\"%s\\n\\n\", decoded); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut data: [ubyte; 117] = *::core::mem::transmute::< &[u8; 117], &mut [ubyte; 117], >( b\"VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo\\0\", ); let mut decoded: [ubyte; 1024] = [0; 1024]; printf(b\"%s\\n\\n\\0\" as *const u8 as *const libc::c_char, data.as_mut_ptr()); decode(data.as_mut_ptr() as *const ubyte, decoded.as_mut_ptr()); printf(b\"%s\\n\\n\\0\" as *const u8 as *const libc::c_char, decoded.as_mut_ptr()); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 95, |
|
"before": "int decode(const ubyte source[], ubyte sink[]) { const size_t length = strlen(source); const ubyte *it = source; const ubyte *end = source + length; int acc; if (length % 4 != 0) { return 1; } while (it != end) { const ubyte b1 = *it++; const ubyte b2 = *it++; const ubyte b3 = *it++; // might be the first padding byte const ubyte b4 = *it++; // might be the first or second padding byte const int i1 = findIndex(b1); const int i2 = findIndex(b2); acc = i1 << 2; // six bits came from the first byte acc |= i2 >> 4; // two bits came from the first byte *sink++ = acc; // output the first byte if (b3 != '=') { const int i3 = findIndex(b3); acc = (i2 & 0xF) << 4; // four bits came from the second byte acc += i3 >> 2; // four bits came from the second byte *sink++ = acc; // output the second byte if (b4 != '=') { const int i4 = findIndex(b4); acc = (i3 & 0x3) << 6; // two bits came from the third byte acc |= i4; // six bits came from the third byte *sink++ = acc; // output the third byte } } } *sink = '\\0'; // add the sigil for end of string return 0; }", |
|
"after": "pub unsafe extern \"C\" fn decode( mut source: *const ubyte, mut sink: *mut ubyte, ) -> libc::c_int { let length: size_t = strlen(source as *const libc::c_char); let mut it: *const ubyte = source; let mut end: *const ubyte = source.offset(length as isize); let mut acc: libc::c_int = 0; if length.wrapping_rem(4 as libc::c_int as libc::c_ulong) != 0 as libc::c_int as libc::c_ulong { return 1 as libc::c_int; } while it != end { let fresh0 = it; it = it.offset(1); let b1: ubyte = *fresh0; let fresh1 = it; it = it.offset(1); let b2: ubyte = *fresh1; let fresh2 = it; it = it.offset(1); let b3: ubyte = *fresh2; let fresh3 = it; it = it.offset(1); let b4: ubyte = *fresh3; let i1: libc::c_int = findIndex(b1); let i2: libc::c_int = findIndex(b2); acc = i1 << 2 as libc::c_int; acc |= i2 >> 4 as libc::c_int; let fresh4 = sink; sink = sink.offset(1); *fresh4 = acc as ubyte; if b3 as libc::c_int != '=' as i32 { let i3: libc::c_int = findIndex(b3); acc = (i2 & 0xf as libc::c_int) << 4 as libc::c_int; acc += i3 >> 2 as libc::c_int; let fresh5 = sink; sink = sink.offset(1); *fresh5 = acc as ubyte; if b4 as libc::c_int != '=' as i32 { let i4: libc::c_int = findIndex(b4); acc = (i3 & 0x3 as libc::c_int) << 6 as libc::c_int; acc |= i4; let fresh6 = sink; sink = sink.offset(1); *fresh6 = acc as ubyte; } } } *sink = '\\0' as i32 as ubyte; return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 96, |
|
"before": "int findIndex(const ubyte val) { if ('A' <= val && val <= 'Z') { return val - 'A'; } if ('a' <= val && val <= 'z') { return val - 'a' + 26; } if ('0' <= val && val <= '9') { return val - '0' + 52; } if (val == '+') { return 62; } if (val == '/') { return 63; } return -1; }", |
|
"after": "pub unsafe extern \"C\" fn findIndex(val: ubyte) -> libc::c_int { if 'A' as i32 <= val as libc::c_int && val as libc::c_int <= 'Z' as i32 { return val as libc::c_int - 'A' as i32; } if 'a' as i32 <= val as libc::c_int && val as libc::c_int <= 'z' as i32 { return val as libc::c_int - 'a' as i32 + 26 as libc::c_int; } if '0' as i32 <= val as libc::c_int && val as libc::c_int <= '9' as i32 { return val as libc::c_int - '0' as i32 + 52 as libc::c_int; } if val as libc::c_int == '+' as i32 { return 62 as libc::c_int; } if val as libc::c_int == '/' as i32 { return 63 as libc::c_int; } return -(1 as libc::c_int); }" |
|
}, |
|
{ |
|
"index": 97, |
|
"before": "void evolve(ull state, int rule) { \tint i, p, q, b; \tfor (p = 0; p < 10; p++) { \t\tfor (b = 0, q = 8; q--; ) { \t\t\tull st = state; \t\t\tb |= (st&1) << q; \t\t\tfor (state = i = 0; i < N; i++) \t\t\t\tif (rule & B(7 & (st>>(i-1) | st<<(N+1-i)))) \t\t\t\t\tstate |= B(i); \t\t} \t\tprintf(\" %d\", b); \t} \tputchar('\\n'); \treturn; }", |
|
"after": "pub unsafe extern \"C\" fn evolve(mut state: ull, mut rule: libc::c_int) { let mut i: libc::c_int = 0; let mut p: libc::c_int = 0; let mut q: libc::c_int = 0; let mut b: libc::c_int = 0; p = 0 as libc::c_int; while p < 10 as libc::c_int { b = 0 as libc::c_int; q = 8 as libc::c_int; loop { let fresh0 = q; q = q - 1; if !(fresh0 != 0) { break; } let mut st: ull = state; b = (b as libc::c_ulonglong | (st & 1 as libc::c_int as libc::c_ulonglong) << q) as libc::c_int; i = 0 as libc::c_int; state = i as ull; while (i as libc::c_ulong) < (::core::mem::size_of::<ull>() as libc::c_ulong) .wrapping_mul(8 as libc::c_int as libc::c_ulong) { if rule as libc::c_ulonglong & (1 as libc::c_ulonglong) << (7 as libc::c_int as libc::c_ulonglong & (st >> i - 1 as libc::c_int | st << (::core::mem::size_of::<ull>() as libc::c_ulong) .wrapping_mul(8 as libc::c_int as libc::c_ulong) .wrapping_add(1 as libc::c_int as libc::c_ulong) .wrapping_sub(i as libc::c_ulong))) != 0 { state |= (1 as libc::c_ulonglong) << i; } i += 1; i; } } printf(b\" %d\\0\" as *const u8 as *const libc::c_char, b); p += 1; p; } putchar('\\n' as i32); }" |
|
}, |
|
{ |
|
"index": 98, |
|
"before": "int main(void) { \tevolve(1, 30); \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { evolve(1 as libc::c_int as ull, 30 as libc::c_int); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 99, |
|
"before": "int main() { puts(isatty(fileno(stdout)) ? \"stdout is tty\" : \"stdout is not tty\"); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { puts( if isatty(fileno(stdout)) != 0 { b\"stdout is tty\\0\" as *const u8 as *const libc::c_char } else { b\"stdout is not tty\\0\" as *const u8 as *const libc::c_char }, ); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 100, |
|
"before": "int main(int argc, char* argv[]) { srand(time(NULL)); puts(_(DESCRIPTION)); while (true) { puts(_(\"\\n---- NEW GAME ----\\n\")); puts(_(\"\\nThe running total is currently zero.\\n\")); total = 0; if (rand() % NUMBER_OF_PLAYERS) { puts(_(\"The first move is AI move.\\n\")); ai(); } else puts(_(\"The first move is human move.\\n\")); while (total < GOAL) { human(); ai(); } } }", |
|
"after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { srand(time(0 as *mut time_t) as libc::c_uint); puts(DESCRIPTION.as_mut_ptr()); loop { puts(b\"\\n---- NEW GAME ----\\n\\0\" as *const u8 as *const libc::c_char); puts( b\"\\nThe running total is currently zero.\\n\\0\" as *const u8 as *const libc::c_char, ); total = 0 as libc::c_int; if rand() % 2 as libc::c_int != 0 { puts(b\"The first move is AI move.\\n\\0\" as *const u8 as *const libc::c_char); ai(); } else { puts( b\"The first move is human move.\\n\\0\" as *const u8 as *const libc::c_char, ); } while total < 21 as libc::c_int { human(); ai(); } }; }" |
|
}, |
|
{ |
|
"index": 101, |
|
"before": "int ai() { /* * There is a winning strategy for the first player. The second player can win * then and only then the frist player does not use the winning strategy. * * The winning strategy may be defined as best move for the given running total. * The running total is a number from 0 to GOAL. Therefore, for given GOAL, best * moves may be precomputed (and stored in a lookup table). Actually (when legal * moves are 1 or 2 or 3) the table may be truncated to four first elements. */ #if GOAL < 32 && MIN_MOVE == 1 && MAX_MOVE == 3 static const int precomputed[] = { 1, 1, 3, 2, 1, 1, 3, 2, 1, 1, 3, 2, 1, 1, 3, 2, 1, 1, 3, 2, 1, 1, 3, 2, 1, 1, 3, 2, 1, 1, 3 }; update(_(\"ai\"), precomputed[total]); #elif MIN_MOVE == 1 && MAX_MOVE == 3 static const int precomputed[] = { 1, 1, 3, 2}; update(_(\"ai\"), precomputed[total % (MAX_MOVE + 1)]); #else int i; int move = 1; for (i = MIN_MOVE; i <= MAX_MOVE; i++) if ((total + i - 1) % (MAX_MOVE + 1) == 0) move = i; for (i = MIN_MOVE; i <= MAX_MOVE; i++) if (total + i == GOAL) move = i; update(_(\"ai\"), move); #endif }", |
|
"after": "pub unsafe extern \"C\" fn ai() -> libc::c_int { static mut precomputed: [libc::c_int; 31] = [ 1 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 1 as libc::c_int, 3 as libc::c_int, ]; update( b\"ai\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, precomputed[total as usize], ); panic!(\"Reached end of non-void function without returning\"); }" |
|
}, |
|
{ |
|
"index": 102, |
|
"before": "void human(void) { char buffer[BUFFER_SIZE]; int move; while ( printf(_(\"enter your move to play (or enter 0 to exit game): \")), fgets(buffer, BUFFER_SIZE, stdin), sscanf(buffer, \"%d\", &move) != 1 || (move && (move < MIN_MOVE || move > MAX_MOVE || total+move > GOAL))) puts(_(\"\\nYour answer is not a valid choice.\\n\")); putchar('\\n'); if (!move) exit(EXIT_SUCCESS); update(_(\"human\"), move); }", |
|
"after": "pub unsafe extern \"C\" fn human() { let mut buffer: [libc::c_char; 256] = [0; 256]; let mut move_0: libc::c_int = 0; loop { printf( b\"enter your move to play (or enter 0 to exit game): \\0\" as *const u8 as *const libc::c_char, ); fgets(buffer.as_mut_ptr(), 256 as libc::c_int, stdin); if !(sscanf( buffer.as_mut_ptr(), b\"%d\\0\" as *const u8 as *const libc::c_char, &mut move_0 as *mut libc::c_int, ) != 1 as libc::c_int || move_0 != 0 && (move_0 < 1 as libc::c_int || move_0 > 3 as libc::c_int || total + move_0 > 21 as libc::c_int)) { break; } puts( b\"\\nYour answer is not a valid choice.\\n\\0\" as *const u8 as *const libc::c_char, ); } putchar('\\n' as i32); if move_0 == 0 { exit(0 as libc::c_int); } update(b\"human\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, move_0); }" |
|
}, |
|
{ |
|
"index": 103, |
|
"before": "void update(char* player, int move) { printf(\"%8s: %d = %d + %d\\n\\n\", player, total + move, total, move); total += move; if (total == GOAL) printf(_(\"The winner is %s.\\n\\n\"), player); }", |
|
"after": "pub unsafe extern \"C\" fn update(mut player: *mut libc::c_char, mut move_0: libc::c_int) { printf( b\"%8s: %d = %d + %d\\n\\n\\0\" as *const u8 as *const libc::c_char, player, total + move_0, total, move_0, ); total += move_0; if total == 21 as libc::c_int { printf(b\"The winner is %s.\\n\\n\\0\" as *const u8 as *const libc::c_char, player); } }" |
|
}, |
|
{ |
|
"index": 104, |
|
"before": "void append(char*s,const char*morse) { for (; *morse; ++morse) strcat(s,dd['3'==*morse]); strcat(s,medium); }", |
|
"after": "pub unsafe extern \"C\" fn append( mut s: *mut libc::c_char, mut morse: *const libc::c_char, ) { while *morse != 0 { strcat(s, dd[('3' as i32 == *morse as libc::c_int) as libc::c_int as usize]); morse = morse.offset(1); morse; } strcat(s, medium.as_mut_ptr()); }" |
|
}, |
|
{ |
|
"index": 105, |
|
"before": "int main(int ac,char*av[]) { char sin[73],sout[100000]; int dit = 100; if (1 < ac) { if (strlen(av[1]) != strspn(av[1],\"0123456789\")) return 0*fprintf(stderr,\"use: %s [duration] dit in ms, default %d\\n\",*av,dit); dit = BIND(atoi(av[1]),1,1000); } sprintf(dah,\" -n -f 440 -l %d -D %d\",3*dit,dit); sprintf(dih,\" -n -f 440 -l %d -D %d\",dit,dit); sprintf(medium,\" -n -D %d\",(3-1)*dit); sprintf(word,\" -n -D %d\",(7-(3-1)-1)*dit); while (NULL != fgets(sin,72,stdin)) puts(translate(sin,sout)); return 0; }", |
|
"after": "unsafe fn main(mut ac: libc::c_int, mut av: *mut *mut libc::c_char) -> libc::c_int { let mut sin: [libc::c_char; 73] = [0; 73]; let mut sout: [libc::c_char; 100000] = [0; 100000]; let mut dit: libc::c_int = 100 as libc::c_int; if (1 as libc::c_int) < ac { if strlen(*av.offset(1 as libc::c_int as isize)) != strspn( *av.offset(1 as libc::c_int as isize), b\"0123456789\\0\" as *const u8 as *const libc::c_char, ) { return 0 as libc::c_int * fprintf( stderr, b\"use: %s [duration] dit in ms, default %d\\n\\0\" as *const u8 as *const libc::c_char, *av, dit, ); } dit = if (1 as libc::c_int) < atoi(*av.offset(1 as libc::c_int as isize)) { if atoi(*av.offset(1 as libc::c_int as isize)) < 1000 as libc::c_int { atoi(*av.offset(1 as libc::c_int as isize)) } else { 1000 as libc::c_int } } else { 1 as libc::c_int }; } sprintf( dah.as_mut_ptr(), b\" -n -f 440 -l %d -D %d\\0\" as *const u8 as *const libc::c_char, 3 as libc::c_int * dit, dit, ); sprintf( dih.as_mut_ptr(), b\" -n -f 440 -l %d -D %d\\0\" as *const u8 as *const libc::c_char, dit, dit, ); sprintf( medium.as_mut_ptr(), b\" -n -D %d\\0\" as *const u8 as *const libc::c_char, (3 as libc::c_int - 1 as libc::c_int) * dit, ); sprintf( word.as_mut_ptr(), b\" -n -D %d\\0\" as *const u8 as *const libc::c_char, (7 as libc::c_int - (3 as libc::c_int - 1 as libc::c_int) - 1 as libc::c_int) * dit, ); while !(fgets(sin.as_mut_ptr(), 72 as libc::c_int, stdin)).is_null() { puts(translate(sin.as_mut_ptr(), sout.as_mut_ptr())); } return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 106, |
|
"before": "int countProperDivisors(int n){ \tint prod = 1,i,count=0; \twhile(n%2==0){ \t\tcount++; \t\tn /= 2; \t} \tprod *= (1+count); \tfor(i=3;i*i<=n;i+=2){ \t\tcount = 0; \t\twhile(n%i==0){ \t\t\tcount++; \t\t\tn /= i; \t\t} \t\tprod *= (1+count); \t} \tif(n>2) \t\tprod *= 2; \treturn prod - 1; }", |
|
"after": "pub unsafe extern \"C\" fn countProperDivisors(mut n: libc::c_int) -> libc::c_int { let mut prod: libc::c_int = 1 as libc::c_int; let mut i: libc::c_int = 0; let mut count: libc::c_int = 0 as libc::c_int; while n % 2 as libc::c_int == 0 as libc::c_int { count += 1; count; n /= 2 as libc::c_int; } prod *= 1 as libc::c_int + count; i = 3 as libc::c_int; while i * i <= n { count = 0 as libc::c_int; while n % i == 0 as libc::c_int { count += 1; count; n /= i; } prod *= 1 as libc::c_int + count; i += 2 as libc::c_int; } if n > 2 as libc::c_int { prod *= 2 as libc::c_int; } return prod - 1 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 107, |
|
"before": "int main(void) { for (int i = 1; i <= 10; ++i) { printf(\"%d: \", i); proper_divisors(i, true); } int max = 0; int max_i = 1; for (int i = 1; i <= 20000; ++i) { int v = countProperDivisors(i); if (v >= max) { max = v; max_i = i; } } printf(\"%d with %d divisors\\n\", max_i, max); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 1 as libc::c_int; while i <= 10 as libc::c_int { printf(b\"%d: \\0\" as *const u8 as *const libc::c_char, i); proper_divisors(i, 1 as libc::c_int != 0); i += 1; i; } let mut max: libc::c_int = 0 as libc::c_int; let mut max_i: libc::c_int = 1 as libc::c_int; let mut i_0: libc::c_int = 1 as libc::c_int; while i_0 <= 20000 as libc::c_int { let mut v: libc::c_int = countProperDivisors(i_0); if v >= max { max = v; max_i = i_0; } i_0 += 1; i_0; } printf(b\"%d with %d divisors\\n\\0\" as *const u8 as *const libc::c_char, max_i, max); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 108, |
|
"before": "int proper_divisors(const int n, bool print_flag) { int count = 0; for (int i = 1; i < n; ++i) { if (n % i == 0) { count++; if (print_flag) printf(\"%d \", i); } } if (print_flag) printf(\"\\n\"); return count; }", |
|
"after": "pub unsafe extern \"C\" fn proper_divisors( n: libc::c_int, mut print_flag: bool, ) -> libc::c_int { let mut count: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 1 as libc::c_int; while i < n { if n % i == 0 as libc::c_int { count += 1; count; if print_flag { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, i); } } i += 1; i; } if print_flag { printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); } return count; }" |
|
}, |
|
{ |
|
"index": 109, |
|
"before": "int main(void) { volatile int x, y, z; const int n = 20; List * pTriples = SEQ( T(x, y, z), ( (x, R(1, n)), (y, R(x, n)), (z, R(y, n)) ), (x*x + y*y == z*z) ); volatile Triple t; FOR_EACH(t, Triple, pTriples, printf(\"%d, %d, %d\\n\", t._1, t._2, t._3) ); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut x: libc::c_int = 0; let mut y: libc::c_int = 0; let mut z: libc::c_int = 0; let n: libc::c_int = 20 as libc::c_int; SEQ_var = &mut { let mut init = ITERATOR { l: 0 as *mut List, old: 0 as *mut List, p: SEQ_var, }; init } as *mut ITERATOR; FE_var = &mut { let mut init = ITERATOR { l: (intRangeList as unsafe extern \"C\" fn( libc::c_int, libc::c_int, ) -> *mut List)(1 as libc::c_int, n), old: 0 as *mut List, p: FE_var, }; init } as *mut ITERATOR; ::core::ptr::write_volatile( &mut x as *mut libc::c_int, *(&mut (*(*FE_var).l).val as *mut [libc::c_char; 0] as *mut libc::c_int), ); while (if !((*FE_var).l).is_null() { ::core::ptr::write_volatile( &mut x as *mut libc::c_int, *(&mut (*(*FE_var).l).val as *mut [libc::c_char; 0] as *mut libc::c_int), ); 1 as libc::c_int } else { 0 as libc::c_int }) != 0 { FE_var = &mut { let mut init = ITERATOR { l: (intRangeList as unsafe extern \"C\" fn( libc::c_int, libc::c_int, ) -> *mut List)(x, n), old: 0 as *mut List, p: FE_var, }; init } as *mut ITERATOR; ::core::ptr::write_volatile( &mut y as *mut libc::c_int, *(&mut (*(*FE_var).l).val as *mut [libc::c_char; 0] as *mut libc::c_int), ); while (if !((*FE_var).l).is_null() { ::core::ptr::write_volatile( &mut y as *mut libc::c_int, *(&mut (*(*FE_var).l).val as *mut [libc::c_char; 0] as *mut libc::c_int), ); 1 as libc::c_int } else { 0 as libc::c_int }) != 0 { FE_var = &mut { let mut init = ITERATOR { l: (intRangeList as unsafe extern \"C\" fn( libc::c_int, libc::c_int, ) -> *mut List)(y, n), old: 0 as *mut List, p: FE_var, }; init } as *mut ITERATOR; ::core::ptr::write_volatile( &mut z as *mut libc::c_int, *(&mut (*(*FE_var).l).val as *mut [libc::c_char; 0] as *mut libc::c_int), ); while (if !((*FE_var).l).is_null() { ::core::ptr::write_volatile( &mut z as *mut libc::c_int, *(&mut (*(*FE_var).l).val as *mut [libc::c_char; 0] as *mut libc::c_int), ); 1 as libc::c_int } else { 0 as libc::c_int }) != 0 { if x * x + y * y == z * z { if !((*SEQ_var).l).is_null() { listAppend( (*SEQ_var).l, ::core::mem::size_of::<Triple>() as libc::c_ulong as libc::c_int, &mut { let mut init = Triple { _1: x, _2: y, _3: z }; init } as *mut Triple as *mut libc::c_void, ); } else { (*SEQ_var) .l = listNew( ::core::mem::size_of::<Triple>() as libc::c_ulong as libc::c_int, &mut { let mut init = Triple { _1: x, _2: y, _3: z }; init } as *mut Triple as *mut libc::c_void, ); }; } else {}; (*FE_var).l = (*(*FE_var).l).nx; } FE_var = (*FE_var).p; (*FE_var).l = (*(*FE_var).l).nx; } FE_var = (*FE_var).p; (*FE_var).l = (*(*FE_var).l).nx; } FE_var = (*FE_var).p; (*(*SEQ_var).p).old = (*SEQ_var).l; SEQ_var = (*SEQ_var).p; let mut pTriples: *mut List = (*SEQ_var).old; let mut t: Triple = Triple { _1: 0, _2: 0, _3: 0 }; FE_var = &mut { let mut init = ITERATOR { l: pTriples, old: 0 as *mut List, p: FE_var, }; init } as *mut ITERATOR; ::core::ptr::write_volatile( &mut t as *mut Triple, *(&mut (*(*FE_var).l).val as *mut [libc::c_char; 0] as *mut Triple), ); while (if !((*FE_var).l).is_null() { ::core::ptr::write_volatile( &mut t as *mut Triple, *(&mut (*(*FE_var).l).val as *mut [libc::c_char; 0] as *mut Triple), ); 1 as libc::c_int } else { 0 as libc::c_int }) != 0 { printf(b\"%d, %d, %d\\n\\0\" as *const u8 as *const libc::c_char, t._1, t._2, t._3); (*FE_var).l = (*(*FE_var).l).nx; } FE_var = (*FE_var).p; return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 110, |
|
"before": "void printMagicSquare(int** square,int rows){ \t\tint i,j; \t\tfor(i=0;i<rows;i++){ \t\t\tfor(j=0;j<rows;j++){ \t\t\t\tprintf(\"%*s%d\",rows - numDigits(square[i][j]),\"\",square[i][j]); \t\t\t} \t\t\tprintf(\"\\n\"); \t\t} \t\tprintf(\"\\nMagic constant: %d \", (rows * rows + 1) * rows / 2); \t}", |
|
"after": "pub unsafe extern \"C\" fn printMagicSquare( mut square: *mut *mut libc::c_int, mut rows: libc::c_int, ) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; i = 0 as libc::c_int; while i < rows { j = 0 as libc::c_int; while j < rows { printf( b\"%*s%d\\0\" as *const u8 as *const libc::c_char, rows - numDigits(*(*square.offset(i as isize)).offset(j as isize)), b\"\\0\" as *const u8 as *const libc::c_char, *(*square.offset(i as isize)).offset(j as isize), ); j += 1; j; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } printf( b\"\\nMagic constant: %d \\0\" as *const u8 as *const libc::c_char, (rows * rows + 1 as libc::c_int) * rows / 2 as libc::c_int, ); }" |
|
}, |
|
{ |
|
"index": 111, |
|
"before": "int numDigits(int n){ \t\tint count = 1; \t\twhile(n>=10){ \t\t\tn /= 10; \t\t\tcount++; \t\t} \t\treturn count; \t}", |
|
"after": "pub unsafe extern \"C\" fn numDigits(mut n: libc::c_int) -> libc::c_int { let mut count: libc::c_int = 1 as libc::c_int; while n >= 10 as libc::c_int { n /= 10 as libc::c_int; count += 1; count; } return count; }" |
|
}, |
|
{ |
|
"index": 112, |
|
"before": "int main(int argC,char* argV[]) \t{ \t\tint n; \t\tif(argC!=2||isdigit(argV[1][0])==0) \t\t\tprintf(\"Usage : %s <integer specifying rows in magic square>\",argV[0]); \t\telse{ \t\t\tn = atoi(argV[1]); \t\t\tprintMagicSquare(singlyEvenMagicSquare(n),n); \t\t} \t\treturn 0; \t}", |
|
"after": "unsafe fn main( mut argC: libc::c_int, mut argV: *mut *mut libc::c_char, ) -> libc::c_int { let mut n: libc::c_int = 0; if argC != 2 as libc::c_int || *(*__ctype_b_loc()) .offset( *(*argV.offset(1 as libc::c_int as isize)) .offset(0 as libc::c_int as isize) as libc::c_int as isize, ) as libc::c_int & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int == 0 as libc::c_int { printf( b\"Usage : %s <integer specifying rows in magic square>\\0\" as *const u8 as *const libc::c_char, *argV.offset(0 as libc::c_int as isize), ); } else { n = atoi(*argV.offset(1 as libc::c_int as isize)); printMagicSquare(singlyEvenMagicSquare(n), n); } return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 113, |
|
"before": "double sqrt2_a(unsigned n) { \treturn n ? 2.0 : 1.0; }", |
|
"after": "pub unsafe extern \"C\" fn sqrt2_a(mut n: libc::c_uint) -> libc::c_double { return if n != 0 { 2.0f64 } else { 1.0f64 }; }" |
|
}, |
|
{ |
|
"index": 114, |
|
"before": "double pi_b(unsigned n) { \tdouble c = 2.0 * n - 1.0; \treturn c * c; }", |
|
"after": "pub unsafe extern \"C\" fn pi_b(mut n: libc::c_uint) -> libc::c_double { let mut c: libc::c_double = 2.0f64 * n as libc::c_double - 1.0f64; return c * c; }" |
|
}, |
|
{ |
|
"index": 115, |
|
"before": "double pi_a(unsigned n) { \treturn n ? 6.0 : 3.0; }", |
|
"after": "pub unsafe extern \"C\" fn pi_a(mut n: libc::c_uint) -> libc::c_double { return if n != 0 { 6.0f64 } else { 3.0f64 }; }" |
|
}, |
|
{ |
|
"index": 116, |
|
"before": "int main(void) { \tdouble sqrt2, napier, pi; \tsqrt2 = calc(sqrt2_a, sqrt2_b, 1000); \tnapier = calc(napier_a, napier_b, 1000); \tpi = calc(pi_a, pi_b, 1000); \tprintf(\"%12.10g\\n%12.10g\\n%12.10g\\n\", sqrt2, napier, pi); \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut sqrt2: libc::c_double = 0.; let mut napier: libc::c_double = 0.; let mut pi: libc::c_double = 0.; sqrt2 = calc( Some(sqrt2_a as unsafe extern \"C\" fn(libc::c_uint) -> libc::c_double), Some(sqrt2_b as unsafe extern \"C\" fn(libc::c_uint) -> libc::c_double), 1000 as libc::c_int as libc::c_uint, ); napier = calc( Some(napier_a as unsafe extern \"C\" fn(libc::c_uint) -> libc::c_double), Some(napier_b as unsafe extern \"C\" fn(libc::c_uint) -> libc::c_double), 1000 as libc::c_int as libc::c_uint, ); pi = calc( Some(pi_a as unsafe extern \"C\" fn(libc::c_uint) -> libc::c_double), Some(pi_b as unsafe extern \"C\" fn(libc::c_uint) -> libc::c_double), 1000 as libc::c_int as libc::c_uint, ); printf( b\"%12.10g\\n%12.10g\\n%12.10g\\n\\0\" as *const u8 as *const libc::c_char, sqrt2, napier, pi, ); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 117, |
|
"before": "double napier_a(unsigned n) { \treturn n ? n : 2.0; }", |
|
"after": "pub unsafe extern \"C\" fn napier_a(mut n: libc::c_uint) -> libc::c_double { return if n != 0 { n as libc::c_double } else { 2.0f64 }; }" |
|
}, |
|
{ |
|
"index": 118, |
|
"before": "double sqrt2_b(unsigned n) { \treturn 1.0; }", |
|
"after": "pub unsafe extern \"C\" fn sqrt2_b(mut n: libc::c_uint) -> libc::c_double { return 1.0f64; }" |
|
}, |
|
{ |
|
"index": 119, |
|
"before": "double napier_b(unsigned n) { \treturn n > 1.0 ? n - 1.0 : 1.0; }", |
|
"after": "pub unsafe extern \"C\" fn napier_b(mut n: libc::c_uint) -> libc::c_double { return if n as libc::c_double > 1.0f64 { n as libc::c_double - 1.0f64 } else { 1.0f64 }; }" |
|
}, |
|
{ |
|
"index": 120, |
|
"before": "int main() { int i, ix, n, lim = 1000035; int pairs = 0, trips = 0, quads = 0, quins = 0, unsexy = 2; int pr = 0, tr = 0, qd = 0, qn = 0, un = 2; int lpr = 5, ltr = 5, lqd = 5, lqn = 5, lun = 10; int last_pr[5][2], last_tr[5][3], last_qd[5][4], last_qn[5][5]; int last_un[10]; bool *sv = calloc(lim - 1, sizeof(bool)); // all FALSE by default setlocale(LC_NUMERIC, \"\"); sieve(sv, lim); // get the counts first for (i = 3; i < lim; i += 2) { if (i > 5 && i < lim-6 && !sv[i] && sv[i-6] && sv[i+6]) { unsexy++; continue; } if (i < lim-6 && !sv[i] && !sv[i+6]) { pairs++; } else continue; if (i < lim-12 && !sv[i+12]) { trips++; } else continue; if (i < lim-18 && !sv[i+18]) { quads++; } else continue; if (i < lim-24 && !sv[i+24]) { quins++; } } if (pairs < lpr) lpr = pairs; if (trips < ltr) ltr = trips; if (quads < lqd) lqd = quads; if (quins < lqn) lqn = quins; if (unsexy < lun) lun = unsexy; // now get the last 'x' for each category for (i = 3; i < lim; i += 2) { if (i > 5 && i < lim-6 && !sv[i] && sv[i-6] && sv[i+6]) { un++; if (un > unsexy - lun) { last_un[un + lun - 1 - unsexy] = i; } continue; } if (i < lim-6 && !sv[i] && !sv[i+6]) { pr++; if (pr > pairs - lpr) { ix = pr + lpr - 1 - pairs; last_pr[ix][0] = i; last_pr[ix][1] = i + 6; } } else continue; if (i < lim-12 && !sv[i+12]) { tr++; if (tr > trips - ltr) { ix = tr + ltr - 1 - trips; last_tr[ix][0] = i; last_tr[ix][1] = i + 6; last_tr[ix][2] = i + 12; } } else continue; if (i < lim-18 && !sv[i+18]) { qd++; if (qd > quads - lqd) { ix = qd + lqd - 1 - quads; last_qd[ix][0] = i; last_qd[ix][1] = i + 6; last_qd[ix][2] = i + 12; last_qd[ix][3] = i + 18; } } else continue; if (i < lim-24 && !sv[i+24]) { qn++; if (qn > quins - lqn) { ix = qn + lqn - 1 - quins; last_qn[ix][0] = i; last_qn[ix][1] = i + 6; last_qn[ix][2] = i + 12; last_qn[ix][3] = i + 18; last_qn[ix][4] = i + 24; } } } printHelper(\"pairs\", pairs, lim, lpr); printf(\" [\"); for (i = 0; i < lpr; ++i) { printArray(last_pr[i], 2); printf(\"\\b] \"); } printf(\"\\b]\\n\\n\"); printHelper(\"triplets\", trips, lim, ltr); printf(\" [\"); for (i = 0; i < ltr; ++i) { printArray(last_tr[i], 3); printf(\"\\b] \"); } printf(\"\\b]\\n\\n\"); printHelper(\"quadruplets\", quads, lim, lqd); printf(\" [\"); for (i = 0; i < lqd; ++i) { printArray(last_qd[i], 4); printf(\"\\b] \"); } printf(\"\\b]\\n\\n\"); printHelper(\"quintuplets\", quins, lim, lqn); printf(\" [\"); for (i = 0; i < lqn; ++i) { printArray(last_qn[i], 5); printf(\"\\b] \"); } printf(\"\\b]\\n\\n\"); printHelper(\"unsexy primes\", unsexy, lim, lun); printf(\" [\"); printArray(last_un, lun); printf(\"\\b]\\n\"); free(sv); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut ix: libc::c_int = 0; let mut n: libc::c_int = 0; let mut lim: libc::c_int = 1000035 as libc::c_int; let mut pairs: libc::c_int = 0 as libc::c_int; let mut trips: libc::c_int = 0 as libc::c_int; let mut quads: libc::c_int = 0 as libc::c_int; let mut quins: libc::c_int = 0 as libc::c_int; let mut unsexy: libc::c_int = 2 as libc::c_int; let mut pr: libc::c_int = 0 as libc::c_int; let mut tr: libc::c_int = 0 as libc::c_int; let mut qd: libc::c_int = 0 as libc::c_int; let mut qn: libc::c_int = 0 as libc::c_int; let mut un: libc::c_int = 2 as libc::c_int; let mut lpr: libc::c_int = 5 as libc::c_int; let mut ltr: libc::c_int = 5 as libc::c_int; let mut lqd: libc::c_int = 5 as libc::c_int; let mut lqn: libc::c_int = 5 as libc::c_int; let mut lun: libc::c_int = 10 as libc::c_int; let mut last_pr: [[libc::c_int; 2]; 5] = [[0; 2]; 5]; let mut last_tr: [[libc::c_int; 3]; 5] = [[0; 3]; 5]; let mut last_qd: [[libc::c_int; 4]; 5] = [[0; 4]; 5]; let mut last_qn: [[libc::c_int; 5]; 5] = [[0; 5]; 5]; let mut last_un: [libc::c_int; 10] = [0; 10]; let mut sv: *mut bool_0 = calloc( (lim - 1 as libc::c_int) as libc::c_ulong, ::core::mem::size_of::<bool_0>() as libc::c_ulong, ) as *mut bool_0; setlocale(1 as libc::c_int, b\"\\0\" as *const u8 as *const libc::c_char); sieve(sv, lim); i = 3 as libc::c_int; while i < lim { if i > 5 as libc::c_int && i < lim - 6 as libc::c_int && *sv.offset(i as isize) == 0 && *sv.offset((i - 6 as libc::c_int) as isize) as libc::c_int != 0 && *sv.offset((i + 6 as libc::c_int) as isize) as libc::c_int != 0 { unsexy += 1; unsexy; } else if i < lim - 6 as libc::c_int && *sv.offset(i as isize) == 0 && *sv.offset((i + 6 as libc::c_int) as isize) == 0 { pairs += 1; pairs; if i < lim - 12 as libc::c_int && *sv.offset((i + 12 as libc::c_int) as isize) == 0 { trips += 1; trips; if i < lim - 18 as libc::c_int && *sv.offset((i + 18 as libc::c_int) as isize) == 0 { quads += 1; quads; if i < lim - 24 as libc::c_int && *sv.offset((i + 24 as libc::c_int) as isize) == 0 { quins += 1; quins; } } } } i += 2 as libc::c_int; } if pairs < lpr { lpr = pairs; } if trips < ltr { ltr = trips; } if quads < lqd { lqd = quads; } if quins < lqn { lqn = quins; } if unsexy < lun { lun = unsexy; } i = 3 as libc::c_int; while i < lim { if i > 5 as libc::c_int && i < lim - 6 as libc::c_int && *sv.offset(i as isize) == 0 && *sv.offset((i - 6 as libc::c_int) as isize) as libc::c_int != 0 && *sv.offset((i + 6 as libc::c_int) as isize) as libc::c_int != 0 { un += 1; un; if un > unsexy - lun { last_un[(un + lun - 1 as libc::c_int - unsexy) as usize] = i; } } else if i < lim - 6 as libc::c_int && *sv.offset(i as isize) == 0 && *sv.offset((i + 6 as libc::c_int) as isize) == 0 { pr += 1; pr; if pr > pairs - lpr { ix = pr + lpr - 1 as libc::c_int - pairs; last_pr[ix as usize][0 as libc::c_int as usize] = i; last_pr[ix as usize][1 as libc::c_int as usize] = i + 6 as libc::c_int; } if i < lim - 12 as libc::c_int && *sv.offset((i + 12 as libc::c_int) as isize) == 0 { tr += 1; tr; if tr > trips - ltr { ix = tr + ltr - 1 as libc::c_int - trips; last_tr[ix as usize][0 as libc::c_int as usize] = i; last_tr[ix as usize][1 as libc::c_int as usize] = i + 6 as libc::c_int; last_tr[ix as usize][2 as libc::c_int as usize] = i + 12 as libc::c_int; } if i < lim - 18 as libc::c_int && *sv.offset((i + 18 as libc::c_int) as isize) == 0 { qd += 1; qd; if qd > quads - lqd { ix = qd + lqd - 1 as libc::c_int - quads; last_qd[ix as usize][0 as libc::c_int as usize] = i; last_qd[ix as usize][1 as libc::c_int as usize] = i + 6 as libc::c_int; last_qd[ix as usize][2 as libc::c_int as usize] = i + 12 as libc::c_int; last_qd[ix as usize][3 as libc::c_int as usize] = i + 18 as libc::c_int; } if i < lim - 24 as libc::c_int && *sv.offset((i + 24 as libc::c_int) as isize) == 0 { qn += 1; qn; if qn > quins - lqn { ix = qn + lqn - 1 as libc::c_int - quins; last_qn[ix as usize][0 as libc::c_int as usize] = i; last_qn[ix as usize][1 as libc::c_int as usize] = i + 6 as libc::c_int; last_qn[ix as usize][2 as libc::c_int as usize] = i + 12 as libc::c_int; last_qn[ix as usize][3 as libc::c_int as usize] = i + 18 as libc::c_int; last_qn[ix as usize][4 as libc::c_int as usize] = i + 24 as libc::c_int; } } } } } i += 2 as libc::c_int; } printHelper(b\"pairs\\0\" as *const u8 as *const libc::c_char, pairs, lim, lpr); printf(b\" [\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < lpr { printArray((last_pr[i as usize]).as_mut_ptr(), 2 as libc::c_int); printf(b\"\\x08] \\0\" as *const u8 as *const libc::c_char); i += 1; i; } printf(b\"\\x08]\\n\\n\\0\" as *const u8 as *const libc::c_char); printHelper(b\"triplets\\0\" as *const u8 as *const libc::c_char, trips, lim, ltr); printf(b\" [\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < ltr { printArray((last_tr[i as usize]).as_mut_ptr(), 3 as libc::c_int); printf(b\"\\x08] \\0\" as *const u8 as *const libc::c_char); i += 1; i; } printf(b\"\\x08]\\n\\n\\0\" as *const u8 as *const libc::c_char); printHelper(b\"quadruplets\\0\" as *const u8 as *const libc::c_char, quads, lim, lqd); printf(b\" [\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < lqd { printArray((last_qd[i as usize]).as_mut_ptr(), 4 as libc::c_int); printf(b\"\\x08] \\0\" as *const u8 as *const libc::c_char); i += 1; i; } printf(b\"\\x08]\\n\\n\\0\" as *const u8 as *const libc::c_char); printHelper(b\"quintuplets\\0\" as *const u8 as *const libc::c_char, quins, lim, lqn); printf(b\" [\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < lqn { printArray((last_qn[i as usize]).as_mut_ptr(), 5 as libc::c_int); printf(b\"\\x08] \\0\" as *const u8 as *const libc::c_char); i += 1; i; } printf(b\"\\x08]\\n\\n\\0\" as *const u8 as *const libc::c_char); printHelper( b\"unsexy primes\\0\" as *const u8 as *const libc::c_char, unsexy, lim, lun, ); printf(b\" [\\0\" as *const u8 as *const libc::c_char); printArray(last_un.as_mut_ptr(), lun); printf(b\"\\x08]\\n\\0\" as *const u8 as *const libc::c_char); free(sv as *mut libc::c_void); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 121, |
|
"before": "void sieve(bool *c, int limit) { int i, p = 3, p2; // TRUE denotes composite, FALSE denotes prime. c[0] = TRUE; c[1] = TRUE; // no need to bother with even numbers over 2 for this task for (;;) { p2 = p * p; if (p2 >= limit) { break; } for (i = p2; i < limit; i += 2*p) { c[i] = TRUE; } for (;;) { p += 2; if (!c[p]) { break; } } } }", |
|
"after": "pub unsafe extern \"C\" fn sieve(mut c: *mut bool_0, mut limit: libc::c_int) { 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; *c.offset(0 as libc::c_int as isize) = 1 as libc::c_int as bool_0; *c.offset(1 as libc::c_int as isize) = 1 as libc::c_int as bool_0; loop { p2 = p * p; if p2 >= limit { break; } i = p2; while i < limit { *c.offset(i as isize) = 1 as libc::c_int as bool_0; i += 2 as libc::c_int * p; } loop { p += 2 as libc::c_int; if *c.offset(p as isize) == 0 { break; } } }; }" |
|
}, |
|
{ |
|
"index": 122, |
|
"before": "void printArray(int *a, int len) { int i; printf(\"[\"); for (i = 0; i < len; ++i) printf(\"%d \", a[i]); printf(\"\\b]\"); }", |
|
"after": "pub unsafe extern \"C\" fn printArray(mut a: *mut libc::c_int, mut len: libc::c_int) { let mut i: libc::c_int = 0; printf(b\"[\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < len { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, *a.offset(i as isize)); i += 1; i; } printf(b\"\\x08]\\0\" as *const u8 as *const libc::c_char); }" |
|
}, |
|
{ |
|
"index": 123, |
|
"before": "void printHelper(const char *cat, int len, int lim, int n) { const char *sp = strcmp(cat, \"unsexy primes\") ? \"sexy prime \" : \"\"; const char *verb = (len == 1) ? \"is\" : \"are\"; printf(\"Number of %s%s less than %'d = %'d\\n\", sp, cat, lim, len); printf(\"The last %d %s:\\n\", n, verb); }", |
|
"after": "pub unsafe extern \"C\" fn printHelper( mut cat: *const libc::c_char, mut len: libc::c_int, mut lim: libc::c_int, mut n: libc::c_int, ) { let mut sp: *const libc::c_char = if strcmp( cat, b\"unsexy primes\\0\" as *const u8 as *const libc::c_char, ) != 0 { b\"sexy prime \\0\" as *const u8 as *const libc::c_char } else { b\"\\0\" as *const u8 as *const libc::c_char }; let mut verb: *const libc::c_char = if len == 1 as libc::c_int { b\"is\\0\" as *const u8 as *const libc::c_char } else { b\"are\\0\" as *const u8 as *const libc::c_char }; printf( b\"Number of %s%s less than %'d = %'d\\n\\0\" as *const u8 as *const libc::c_char, sp, cat, lim, len, ); printf(b\"The last %d %s:\\n\\0\" as *const u8 as *const libc::c_char, n, verb); }" |
|
}, |
|
{ |
|
"index": 124, |
|
"before": "int main() { int i; double rands[1000]; for (i=0; i<1000; i++) rands[i] = 1.0 + 0.5*random_normal(); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut rands: [libc::c_double; 1000] = [0.; 1000]; i = 0 as libc::c_int; while i < 1000 as libc::c_int { rands[i as usize] = 1.0f64 + 0.5f64 * random_normal(); i += 1; i; } return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 125, |
|
"before": "double drand() /* uniform distribution, (0..1] */ { return (rand()+1.0)/(RAND_MAX+1.0); }", |
|
"after": "pub unsafe extern \"C\" fn drand() -> libc::c_double { return (rand() as libc::c_double + 1.0f64) / (2147483647 as libc::c_int as libc::c_double + 1.0f64); }" |
|
}, |
|
{ |
|
"index": 126, |
|
"before": "double random_normal() /* normal distribution, centered on 0, std dev 1 */ { return sqrt(-2*log(drand())) * cos(2*M_PI*drand()); }", |
|
"after": "pub unsafe extern \"C\" fn random_normal() -> libc::c_double { return sqrt(-(2 as libc::c_int) as libc::c_double * log(drand())) * cos(2 as libc::c_int as libc::c_double * 3.14159265358979323846f64 * drand()); }" |
|
}, |
|
{ |
|
"index": 127, |
|
"before": "void ffMatxSquare( double *cells, int rw, int dim, SquareMtx m0 ) { int col, ix; double sum; double *m0rw = m0->m[rw]; for (col = 0; col < dim; col++) { sum = 0.0; for (ix=0; ix<dim; ix++) sum += m0rw[ix] * m0->m[ix][col]; cells[col] = sum; } }", |
|
"after": "pub unsafe extern \"C\" fn ffMatxSquare( mut cells: *mut libc::c_double, mut rw: libc::c_int, mut dim: libc::c_int, mut m0: SquareMtx, ) { let mut col: libc::c_int = 0; let mut ix: libc::c_int = 0; let mut sum: libc::c_double = 0.; let mut m0rw: *mut libc::c_double = *((*m0).m).offset(rw as isize); col = 0 as libc::c_int; while col < dim { sum = 0.0f64; ix = 0 as libc::c_int; while ix < dim { sum += *m0rw.offset(ix as isize) * *(*((*m0).m).offset(ix as isize)).offset(col as isize); ix += 1; ix; } *cells.offset(col as isize) = sum; col += 1; col; } }" |
|
}, |
|
{ |
|
"index": 128, |
|
"before": "void FreeSquareMtx( SquareMtx m ) { free(m->m); free(m->cells); free(m); }", |
|
"after": "pub unsafe extern \"C\" fn FreeSquareMtx(mut m: SquareMtx) { free((*m).m as *mut libc::c_void); free((*m).cells as *mut libc::c_void); free(m as *mut libc::c_void); }" |
|
}, |
|
{ |
|
"index": 129, |
|
"before": "void fillInit( double *cells, int rw, int dim, void *data) { double theta = 3.1415926536/6.0; double c1 = cos( theta); double s1 = sin( theta); switch(rw) { case 0: cells[0]=c1; cells[1]=s1; cells[2]=0.0; break; case 1: cells[0]=-s1; cells[1]=c1; cells[2]=0; break; case 2: cells[0]=0.0; cells[1]=0.0; cells[2]=1.0; break; } }", |
|
"after": "pub unsafe extern \"C\" fn fillInit( mut cells: *mut libc::c_double, mut rw: libc::c_int, mut dim: libc::c_int, mut data: *mut libc::c_void, ) { let mut theta: libc::c_double = 3.1415926536f64 / 6.0f64; let mut c1: libc::c_double = cos(theta); let mut s1: libc::c_double = sin(theta); match rw { 0 => { *cells.offset(0 as libc::c_int as isize) = c1; *cells.offset(1 as libc::c_int as isize) = s1; *cells.offset(2 as libc::c_int as isize) = 0.0f64; } 1 => { *cells.offset(0 as libc::c_int as isize) = -s1; *cells.offset(1 as libc::c_int as isize) = c1; *cells .offset(2 as libc::c_int as isize) = 0 as libc::c_int as libc::c_double; } 2 => { *cells.offset(0 as libc::c_int as isize) = 0.0f64; *cells.offset(1 as libc::c_int as isize) = 0.0f64; *cells.offset(2 as libc::c_int as isize) = 1.0f64; } _ => {} }; }" |
|
}, |
|
{ |
|
"index": 130, |
|
"before": "void ffIdentity( double *cells, int rw, int dim, void *v ) { int col; for (col=0; col<dim; col++) cells[col] = 0.0; cells[rw] = 1.0; }", |
|
"after": "pub unsafe extern \"C\" fn ffIdentity( mut cells: *mut libc::c_double, mut rw: libc::c_int, mut dim: libc::c_int, mut v: *mut libc::c_void, ) { let mut col: libc::c_int = 0; col = 0 as libc::c_int; while col < dim { *cells.offset(col as isize) = 0.0f64; col += 1; col; } *cells.offset(rw as isize) = 1.0f64; }" |
|
}, |
|
{ |
|
"index": 131, |
|
"before": "int main() { SquareMtx m0 = NewSquareMtx( 3, fillInit, NULL); SquareMtx m1 = SquareMtxPow( m0, 5); SquareMtx m2 = SquareMtxPow( m0, 9); SquareMtx m3 = SquareMtxPow( m0, 2); // fout = stdout; fout = fopen(\"matrx_exp.txt\", \"w\"); SquareMtxPrint(m0, \"m0\"); FreeSquareMtx(m0); SquareMtxPrint(m1, \"m0^5\"); FreeSquareMtx(m1); SquareMtxPrint(m2, \"m0^9\"); FreeSquareMtx(m2); SquareMtxPrint(m3, \"m0^2\"); FreeSquareMtx(m3); fclose(fout); return 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut m0: SquareMtx = NewSquareMtx( 3 as libc::c_int, Some( fillInit as unsafe extern \"C\" fn( *mut libc::c_double, libc::c_int, libc::c_int, *mut libc::c_void, ) -> (), ), 0 as *mut libc::c_void, ); let mut m1: SquareMtx = SquareMtxPow(m0, 5 as libc::c_int); let mut m2: SquareMtx = SquareMtxPow(m0, 9 as libc::c_int); let mut m3: SquareMtx = SquareMtxPow(m0, 2 as libc::c_int); fout = fopen( b\"matrx_exp.txt\\0\" as *const u8 as *const libc::c_char, b\"w\\0\" as *const u8 as *const libc::c_char, ); SquareMtxPrint(m0, b\"m0\\0\" as *const u8 as *const libc::c_char); FreeSquareMtx(m0); SquareMtxPrint(m1, b\"m0^5\\0\" as *const u8 as *const libc::c_char); FreeSquareMtx(m1); SquareMtxPrint(m2, b\"m0^9\\0\" as *const u8 as *const libc::c_char); FreeSquareMtx(m2); SquareMtxPrint(m3, b\"m0^2\\0\" as *const u8 as *const libc::c_char); FreeSquareMtx(m3); fclose(fout); return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 132, |
|
"before": "void ffMatxMulply( double *cells, int rw, int dim, SquareMtx mplcnds[] ) { SquareMtx mleft = mplcnds[0]; SquareMtx mrigt = mplcnds[1]; double sum; double *m0rw = mleft->m[rw]; int col, ix; for (col = 0; col < dim; col++) { sum = 0.0; for (ix=0; ix<dim; ix++) sum += m0rw[ix] * mrigt->m[ix][col]; cells[col] = sum; } }", |
|
"after": "pub unsafe extern \"C\" fn ffMatxMulply( mut cells: *mut libc::c_double, mut rw: libc::c_int, mut dim: libc::c_int, mut mplcnds: *mut SquareMtx, ) { let mut mleft: SquareMtx = *mplcnds.offset(0 as libc::c_int as isize); let mut mrigt: SquareMtx = *mplcnds.offset(1 as libc::c_int as isize); let mut sum: libc::c_double = 0.; let mut m0rw: *mut libc::c_double = *((*mleft).m).offset(rw as isize); let mut col: libc::c_int = 0; let mut ix: libc::c_int = 0; col = 0 as libc::c_int; while col < dim { sum = 0.0f64; ix = 0 as libc::c_int; while ix < dim { sum += *m0rw.offset(ix as isize) * *(*((*mrigt).m).offset(ix as isize)).offset(col as isize); ix += 1; ix; } *cells.offset(col as isize) = sum; col += 1; col; } }" |
|
}, |
|
{ |
|
"index": 133, |
|
"before": "void ffCopy(double *cells, int rw, int dim, SquareMtx m1) { int col; for (col=0; col<dim; col++) cells[col] = m1->m[rw][col]; }", |
|
"after": "pub unsafe extern \"C\" fn ffCopy( mut cells: *mut libc::c_double, mut rw: libc::c_int, mut dim: libc::c_int, mut m1: SquareMtx, ) { let mut col: libc::c_int = 0; col = 0 as libc::c_int; while col < dim { *cells .offset( col as isize, ) = *(*((*m1).m).offset(rw as isize)).offset(col as isize); col += 1; col; } }" |
|
}, |
|
{ |
|
"index": 134, |
|
"before": "void MatxMul( SquareMtx mr, SquareMtx left, SquareMtx rigt) { int rw; SquareMtx mplcnds[2]; mplcnds[0] = left; mplcnds[1] = rigt; for (rw = 0; rw < left->dim; rw++) ffMatxMulply( mr->m[rw], rw, left->dim, mplcnds); }", |
|
"after": "pub unsafe extern \"C\" fn MatxMul( mut mr: SquareMtx, mut left: SquareMtx, mut rigt: SquareMtx, ) { let mut rw: libc::c_int = 0; let mut mplcnds: [SquareMtx; 2] = [0 as *mut squareMtxStruct; 2]; mplcnds[0 as libc::c_int as usize] = left; mplcnds[1 as libc::c_int as usize] = rigt; rw = 0 as libc::c_int; while rw < (*left).dim { ffMatxMulply( *((*mr).m).offset(rw as isize), rw, (*left).dim, mplcnds.as_mut_ptr(), ); rw += 1; rw; } }" |
|
}, |
|
{ |
|
"index": 135, |
|
"before": "SquareMtx SquareMtxPow( SquareMtx m0, int exp ) { SquareMtx v0 = NewSquareMtx(m0->dim, ffIdentity, NULL); SquareMtx v1 = NULL; SquareMtx base0 = NewSquareMtx( m0->dim, ffCopy, m0); SquareMtx base1 = NULL; SquareMtx mplcnds[2], t; while (exp) { if (exp % 2) { if (v1) MatxMul( v1, v0, base0); else { mplcnds[0] = v0; mplcnds[1] = base0; v1 = NewSquareMtx(m0->dim, ffMatxMulply, mplcnds); } {t = v0; v0=v1; v1 = t;} } if (base1) MatxMul( base1, base0, base0); else base1 = NewSquareMtx( m0->dim, ffMatxSquare, base0); t = base0; base0 = base1; base1 = t; exp = exp/2; } if (base0) FreeSquareMtx(base0); if (base1) FreeSquareMtx(base1); if (v1) FreeSquareMtx(v1); return v0; }", |
|
"after": "pub unsafe extern \"C\" fn SquareMtxPow( mut m0: SquareMtx, mut exp: libc::c_int, ) -> SquareMtx { let mut v0: SquareMtx = NewSquareMtx( (*m0).dim, Some( ffIdentity as unsafe extern \"C\" fn( *mut libc::c_double, libc::c_int, libc::c_int, *mut libc::c_void, ) -> (), ), 0 as *mut libc::c_void, ); let mut v1: SquareMtx = 0 as SquareMtx; let mut base0: SquareMtx = NewSquareMtx( (*m0).dim, ::core::mem::transmute::< Option::< unsafe extern \"C\" fn( *mut libc::c_double, libc::c_int, libc::c_int, SquareMtx, ) -> (), >, FillFunc, >( Some( ffCopy as unsafe extern \"C\" fn( *mut libc::c_double, libc::c_int, libc::c_int, SquareMtx, ) -> (), ), ), m0 as *mut libc::c_void, ); let mut base1: SquareMtx = 0 as SquareMtx; let mut mplcnds: [SquareMtx; 2] = [0 as *mut squareMtxStruct; 2]; let mut t: SquareMtx = 0 as *mut squareMtxStruct; while exp != 0 { if exp % 2 as libc::c_int != 0 { if !v1.is_null() { MatxMul(v1, v0, base0); } else { mplcnds[0 as libc::c_int as usize] = v0; mplcnds[1 as libc::c_int as usize] = base0; v1 = NewSquareMtx( (*m0).dim, ::core::mem::transmute::< Option::< unsafe extern \"C\" fn( *mut libc::c_double, libc::c_int, libc::c_int, *mut SquareMtx, ) -> (), >, FillFunc, >( Some( ffMatxMulply as unsafe extern \"C\" fn( *mut libc::c_double, libc::c_int, libc::c_int, *mut SquareMtx, ) -> (), ), ), mplcnds.as_mut_ptr() as *mut libc::c_void, ); } t = v0; v0 = v1; v1 = t; } if !base1.is_null() { MatxMul(base1, base0, base0); } else { base1 = NewSquareMtx( (*m0).dim, ::core::mem::transmute::< Option::< unsafe extern \"C\" fn( *mut libc::c_double, libc::c_int, libc::c_int, SquareMtx, ) -> (), >, FillFunc, >( Some( ffMatxSquare as unsafe extern \"C\" fn( *mut libc::c_double, libc::c_int, libc::c_int, SquareMtx, ) -> (), ), ), base0 as *mut libc::c_void, ); } t = base0; base0 = base1; base1 = t; exp = exp / 2 as libc::c_int; } if !base0.is_null() { FreeSquareMtx(base0); } if !base1.is_null() { FreeSquareMtx(base1); } if !v1.is_null() { FreeSquareMtx(v1); } return v0; }" |
|
}, |
|
{ |
|
"index": 136, |
|
"before": "void SquareMtxPrint( SquareMtx mtx, const char *mn ) { int rw, col; int d = mtx->dim; fprintf(fout, \"%s dim:%d =\\n\", mn, mtx->dim); for (rw=0; rw<d; rw++) { fprintf(fout, \" |\"); for(col=0; col<d; col++) fprintf(fout, \"%8.5f \",mtx->m[rw][col] ); fprintf(fout, \" |\\n\"); } fprintf(fout, \"\\n\"); }", |
|
"after": "pub unsafe extern \"C\" fn SquareMtxPrint( mut mtx: SquareMtx, mut mn: *const libc::c_char, ) { let mut rw: libc::c_int = 0; let mut col: libc::c_int = 0; let mut d: libc::c_int = (*mtx).dim; fprintf( fout, b\"%s dim:%d =\\n\\0\" as *const u8 as *const libc::c_char, mn, (*mtx).dim, ); rw = 0 as libc::c_int; while rw < d { fprintf(fout, b\" |\\0\" as *const u8 as *const libc::c_char); col = 0 as libc::c_int; while col < d { fprintf( fout, b\"%8.5f \\0\" as *const u8 as *const libc::c_char, *(*((*mtx).m).offset(rw as isize)).offset(col as isize), ); col += 1; col; } fprintf(fout, b\" |\\n\\0\" as *const u8 as *const libc::c_char); rw += 1; rw; } fprintf(fout, b\"\\n\\0\" as *const u8 as *const libc::c_char); }" |
|
}, |
|
{ |
|
"index": 137, |
|
"before": "int main() { \tmpz_t a, b, m, r; \tmpz_init_set_str(a,\t\"2988348162058574136915891421498819466320\" \t\t\t\t\"163312926952423791023078876139\", 0); \tmpz_init_set_str(b,\t\"2351399303373464486466122544523690094744\" \t\t\t\t\"975233415544072992656881240319\", 0); \tmpz_init(m); \tmpz_ui_pow_ui(m, 10, 40); \tmpz_init(r); \tmpz_powm(r, a, b, m); \tgmp_printf(\"%Zd\\n\", r); /* ...16808958343740453059 */ \tmpz_clear(a); \tmpz_clear(b); \tmpz_clear(m); \tmpz_clear(r); \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { return 0 as libc::c_int; }" |
|
}, |
|
{ |
|
"index": 138, |
|
"before": "int main() { \tchar *object = 0; \tif (object == NULL) { \t\tputs(\"object is null\"); \t} \treturn 0; }", |
|
"after": "unsafe fn main() -> libc::c_int { let mut object: *mut libc::c_char = 0 as *mut libc::c_char; if object.is_null() { puts(b\"object is null\\0\" as *const u8 as *const libc::c_char); } return 0 as libc::c_int; }" |
|
} |
|
] |