[ { "index": 0, "before": "int main() { puts(getenv(\"HOME\")); return 0; }", "after": "fn main() -> i32 { unsafe { puts(getenv(b\"HOME\\0\" as *const u8 as *const i8)); } return 0; }" }, { "index": 1, "before": "int gcd(int m, int n) { \tint t; \twhile (m) { \t\tt = m; m = n % m; n = t; \t} \treturn n; }", "after": "pub extern \"C\" fn gcd(mut m: i32, mut n: i32) -> i32 { let mut t: i32 = 0; while m != 0 { t = m; m = n % m; n = t; } return n; }" }, { "index": 2, "before": "void reset() { \tint i; \tmsg = 0; \tpool_ptr = pos = 0; \tfor (i = 0; i < POOL_SIZE; i++) { \t\tpool[i].op = OP_NONE; \t\tpool[i].left = pool[i].right = 0; \t} \tfor (i = 0; i < N_DIGITS; i++) \t\tdigits[i].used = 0; }", "after": "pub extern \"C\" fn reset() { let mut i: i32 = 0; unsafe { msg = 0 as *const i8; pos = 0; pool_ptr = pos; } i = 0; unsafe { while i < 8 { pool[i as usize].op = OP_NONE as i32; pool[i as usize].right = 0 as expr; pool[i as usize].left = pool[i as usize].right; i += 1; i; } } i = 0; unsafe { while i < 4 { digits[i as usize].used = 0; i += 1; i; } } }" }, { "index": 3, "before": "void get_input() { \tint i; reinput: \treset(); \tprintf(\"\\nAvailable digits are:\"); \tfor (i = 0; i < N_DIGITS; i++) \t\tprintf(\" %d\", digits[i].val); \tprintf(\". Type an expression and I'll check it for you, or make new numbers.\\n\" \t\t\"Your choice? [Expr/n/q] \"); \twhile (1) { \t\tfor (i = 0; i < MAX_INPUT; i++) str[i] = '\\n'; \t\tfgets(str, MAX_INPUT, stdin); \t\tif (*str == '\\0') goto reinput; \t\tif (str[MAX_INPUT - 1] != '\\n') \t\t\tbail(\"string too long\"); \t\tfor (i = 0; i < MAX_INPUT; i++) \t\t\tif (str[i] == '\\n') str[i] = '\\0'; \t\tif (str[0] == 'q') { \t\t\tprintf(\"Bye\\n\"); \t\t\texit(0); \t\t} \t\tif (str[0] == 'n') { \t\t\tgen_digits(); \t\t\tgoto reinput; \t\t} \t\treturn; \t} }", "after": "pub extern \"C\" fn get_input() { let mut i: i32 = 0; unsafe { loop { reset(); print!(\"\\nAvailable digits are:\"); i = 0; while i < 4 { print!(\" {}\", digits[i as usize].val); i += 1; i; } printf (b\". Type an expression and I'll check it for you, or make new numbers.\\nYour choice? [Expr/n/q] \\0\" as * const u8 as * const i8,); i = 0; while i < 64 { str[i as usize] = '\\n' as i8; i += 1; i; } fgets(str.as_mut_ptr(), 64, stdin); if *str.as_mut_ptr() as i32 == '\\0' as i32 { continue; } if str[(64 - 1i32) as usize] as i32 != '\\n' as i32 { bail(b\"string too long\\0\" as *const u8 as *const i8); } i = 0; while i < 64 { if str[i as usize] as i32 == '\\n' as i32 { str[i as usize] = '\\0' as i8; } i += 1; i; } if str[0 as usize] as i32 == 'q' as i32 { print!(\"Bye\\n\"); exit(0); } if !(str[0 as usize] as i32 == 'n' as i32) { break; } gen_digits(); } } }" }, { "index": 4, "before": "expr parse() { \tint i; \texpr ret = get_expr(); \tif (next_tok() != '\\0') \t\tbail(\"Trailing garbage\"); \tfor (i = 0; i < N_DIGITS; i++) \t\tif (!digits[i].used) \t\t\tbail(\"Not all digits are used\"); \treturn ret; }", "after": "pub extern \"C\" fn parse() -> expr { let mut i: i32 = 0; let mut ret: expr = get_expr(); if next_tok() != '\\0' as i32 { bail(b\"Trailing garbage\\0\" as *const u8 as *const i8); } i = 0; unsafe { while i < 4 { if digits[i as usize].used == 0 { bail(b\"Not all digits are used\\0\" as *const u8 as *const i8); } i += 1; i; } } return ret; }" }, { "index": 5, "before": "void gen_digits() { \tint i; \tfor (i = 0; i < N_DIGITS; i++) \t\tdigits[i].val = 1 + rand() % 9; }", "after": "pub extern \"C\" fn gen_digits() { let mut i: i32 = 0; i = 0; unsafe { while i < 4 { digits[i as usize].val = 1 + rand() % 9; i += 1; i; } } }" }, { "index": 6, "before": "expr new_expr() { \tif (pool_ptr < POOL_SIZE) \t\treturn pool + pool_ptr++; \treturn 0; }", "after": "pub extern \"C\" fn new_expr() -> expr { unsafe { if pool_ptr < 8 { let fresh0 = pool_ptr; pool_ptr = pool_ptr + 1; return pool.as_mut_ptr().offset(fresh0 as isize); } } return 0 as expr; }" }, { "index": 7, "before": "expr get_digit() { \tint i, c = next_tok(); \texpr ret; \tif (c >= '0' && c <= '9') { \t\ttake(); \t\tret = new_expr(); \t\tret->op = OP_NUM; \t\tret->val = c - '0'; \t\tfor (i = 0; i < N_DIGITS; i++) \t\t\tif (digits[i].val == ret->val && !digits[i].used) { \t\t\t\tdigits[i].used = 1; \t\t\t\treturn ret; \t\t\t} \t\tbail(\"Invalid digit\"); \t} \treturn 0; }", "after": "pub extern \"C\" fn get_digit() -> expr { let mut i: i32 = 0; let mut c: i32 = next_tok(); let mut ret: expr = 0 as *mut expr_t; unsafe { if c >= '0' as i32 && c <= '9' as i32 { take(); ret = new_expr(); (*ret).op = OP_NUM as i32; (*ret).val = c - '0' as i32; i = 0; while i < 4 { if digits[i as usize].val == (*ret).val && digits[i as usize].used == 0 { digits[i as usize].used = 1; return ret; } i += 1; i; } bail(b\"Invalid digit\\0\" as *const u8 as *const i8); } } return 0 as expr; }" }, { "index": 8, "before": "int take() { \tif (str[pos] != '\\0') return ++pos; \treturn 0; }", "after": "pub extern \"C\" fn take() -> i32 { unsafe { if str[pos as usize] as i32 != '\\0' as i32 { pos += 1; return pos; } } return 0; }" }, { "index": 9, "before": "int next_tok() { \twhile (isspace(str[pos])) pos++; \treturn str[pos]; }", "after": "pub extern \"C\" fn next_tok() -> i32 { unsafe { while *(*__ctype_b_loc()).offset(str[pos as usize] as i32 as isize) as i32 & _ISspace as i32 != 0 { pos += 1; pos; } return str[pos as usize] as i32; } }" }, { "index": 10, "before": "int main() { \tfrac_t f; \tsrand(time(0)); \tgen_digits(); \twhile(1) { \t\tget_input(); \t\tsetjmp(ctx); /* if parse error, jump back here with err msg set */ \t\tif (msg) { \t\t\t/* after error jump; announce, reset, redo */ \t\t\tprintf(\"%s at '%.*s'\\n\", msg, pos, str); \t\t\tcontinue; \t\t} \t\teval_tree(parse(), &f); \t\tif (f.denom == 0) bail(\"Divide by zero\"); \t\tif (f.denom == 1 && f.num == 24) \t\t\tprintf(\"You got 24. Very good.\\n\"); \t\telse { \t\t\tif (f.denom == 1) \t\t\t\tprintf(\"Eval to: %d, \", f.num); \t\t\telse \t\t\t\tprintf(\"Eval to: %d/%d, \", f.num, f.denom); \t\t\tprintf(\"no good. Try again.\\n\"); \t\t} \t} \treturn 0; }", "after": "fn main() -> i32 { let mut f: frac_t = frac_t { denom: 0, num: 0 }; unsafe { srand(rust_time(None) as u32); } gen_digits(); unsafe { loop { get_input(); _setjmp(ctx.as_mut_ptr()); if !msg.is_null() { print!( \"{0:} at {2:.2$}\\n\", build_str_from_raw_ptr(msg as *mut u8), pos, build_str_from_raw_ptr(str.as_mut_ptr() as *mut u8) ); } else { eval_tree(parse(), &mut f); if f.denom == 0 { bail(b\"Divide by zero\\0\" as *const u8 as *const i8); } if f.denom == 1 && f.num == 24 { print!(\"You got 24. Very good.\\n\"); } else { if f.denom == 1 { print!(\"Eval to: {}, \", f.num); } else { print!(\"Eval to: {}/{}, \", f.num, f.denom); } print!(\"no good. Try again.\\n\"); } } } } }" }, { "index": 11, "before": "expr get_term() { \tint c; \texpr l, r, ret; \tret = get_fact(); \twhile((c = next_tok()) == '*' || c == '/') { \t\tif (!take()) bail(\"Unexpected end of input\"); \t\tr = get_fact(); \t\tl = ret; \t\tret = new_expr(); \t\tret->op = (c == '*') ? OP_MUL : OP_DIV; \t\tret->left = l; \t\tret->right = r; \t} \treturn ret; }", "after": "pub extern \"C\" fn get_term() -> expr { let mut c: i32 = 0; let mut l: expr = 0 as *mut expr_t; let mut r: expr = 0 as *mut expr_t; let mut ret: expr = 0 as *mut expr_t; ret = get_fact(); loop { c = next_tok(); if !(c == '*' as i32 || c == '/' as i32) { break; } if take() == 0 { bail(b\"Unexpected end of input\\0\" as *const u8 as *const i8); } r = get_fact(); l = ret; ret = new_expr(); (*ret).op = if c == '*' as i32 { OP_MUL as i32 } else { OP_DIV as i32 }; (*ret).left = l; (*ret).right = r; } return ret; }" }, { "index": 12, "before": "expr get_fact() { \tint c; \texpr l = get_digit(); \tif (l) return l; \tif ((c = next_tok()) == '(') { \t\ttake(); \t\tl = get_expr(); \t\tif (next_tok() != ')') bail(\"Unbalanced parens\"); \t\ttake(); \t\treturn l; \t} \treturn 0; }", "after": "pub extern \"C\" fn get_fact() -> expr { let mut c: i32 = 0; let mut l: expr = get_digit(); if !l.is_null() { return l; } c = next_tok(); if c == '(' as i32 { take(); l = get_expr(); if next_tok() != ')' as i32 { bail(b\"Unbalanced parens\\0\" as *const u8 as *const i8); } take(); return l; } return 0 as expr; }" }, { "index": 13, "before": "void bail(const char *s) { \tmsg = s; \tlongjmp(ctx, 1); }", "after": "pub extern \"C\" fn bail(mut s: *const i8) { unsafe { msg = s; longjmp(ctx.as_mut_ptr(), 1); } }" }, { "index": 14, "before": "void eval_tree(expr e, frac res) { \tfrac_t l, r; \tint t; \tif (e->op == OP_NUM) { \t\tres->num = e->val; \t\tres->denom = 1; \t\treturn; \t} \teval_tree(e->left, &l); \teval_tree(e->right, &r); \tswitch(e->op) { \tcase OP_ADD: \t\tres->num = l.num * r.denom + l.denom * r.num; \t\tres->denom = l.denom * r.denom; \t\tbreak; \tcase OP_SUB: \t\tres->num = l.num * r.denom - l.denom * r.num; \t\tres->denom = l.denom * r.denom; \t\tbreak; \tcase OP_MUL: \t\tres->num = l.num * r.num; \t\tres->denom = l.denom * r.denom; \t\tbreak; \tcase OP_DIV: \t\tres->num = l.num * r.denom; \t\tres->denom = l.denom * r.num; \t\tbreak; \t} \tif ((t = gcd(res->denom, res->num))) { \t\tres->denom /= t; \t\tres->num /= t; \t} }", "after": "pub extern \"C\" fn eval_tree(mut e: expr, mut res: frac) { let mut l: frac_t = frac_t { denom: 0, num: 0 }; let mut r: frac_t = frac_t { denom: 0, num: 0 }; let mut t: i32 = 0; if (*e).op == OP_NUM as i32 { (*res).num = (*e).val; (*res).denom = 1; return; } eval_tree((*e).left, &mut l); eval_tree((*e).right, &mut r); match (*e).op { 2 => { (*res).num = l.num * r.denom + l.denom * r.num; (*res).denom = l.denom * r.denom; } 3 => { (*res).num = l.num * r.denom - l.denom * r.num; (*res).denom = l.denom * r.denom; } 4 => { (*res).num = l.num * r.num; (*res).denom = l.denom * r.denom; } 5 => { (*res).num = l.num * r.denom; (*res).denom = l.denom * r.num; } _ => {} } t = gcd((*res).denom, (*res).num); if t != 0 { (*res).denom /= t; (*res).num /= t; } }" }, { "index": 15, "before": "expr get_expr() { \tint c; \texpr l, r, ret; \tif (!(ret = get_term())) bail(\"Expected term\"); \twhile ((c = next_tok()) == '+' || c == '-') { \t\tif (!take()) bail(\"Unexpected end of input\"); \t\tif (!(r = get_term())) bail(\"Expected term\"); \t\tl = ret; \t\tret = new_expr(); \t\tret->op = (c == '+') ? OP_ADD : OP_SUB; \t\tret->left = l; \t\tret->right = r; \t} \treturn ret; }", "after": "pub extern \"C\" fn get_expr() -> expr { let mut c: i32 = 0; let mut l: expr = 0 as *mut expr_t; let mut r: expr = 0 as *mut expr_t; let mut ret: expr = 0 as *mut expr_t; ret = get_term(); if ret.is_null() { bail(b\"Expected term\\0\" as *const u8 as *const i8); } loop { c = next_tok(); if !(c == '+' as i32 || c == '-' as i32) { break; } if take() == 0 { bail(b\"Unexpected end of input\\0\" as *const u8 as *const i8); } r = get_term(); if r.is_null() { bail(b\"Expected term\\0\" as *const u8 as *const i8); } l = ret; ret = new_expr(); (*ret).op = if c == '+' as i32 { OP_ADD as i32 } else { OP_SUB as i32 }; (*ret).left = l; (*ret).right = r; } return ret; }" }, { "index": 16, "before": "int main() { int i; pthread_t a[3]; threadfunc p[3] = {t_enjoy, t_rosetta, t_code}; for(i=0;i<3;i++) { pthread_create(&a[i], NULL, p[i], NULL); } sleep(1); bang = 1; pthread_cond_broadcast(&cond); for(i=0;i<3;i++) { pthread_join(a[i], NULL); } }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut a: [u64; 3] = [0; 3]; unsafe { let mut p: [threadfunc; 3] = [ Some(t_enjoy as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), Some(t_rosetta as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), Some(t_code as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), ]; i = 0; while i < 3 { pthread_create( &mut *a.as_mut_ptr().offset(i as isize), 0 as *const pthread_attr_t, p[i as usize], 0 as *mut libc::c_void, ); i += 1; i; } sleep(1); bang = 1; pthread_cond_broadcast(&mut cond); } i = 0; unsafe { while i < 3 { pthread_join(a[i as usize], 0 as *mut *mut libc::c_void); i += 1; i; } } return 0; }" }, { "index": 17, "before": "int main() { \tchar str[] = \"This is a top secret text message!\"; \tprintf(\"Original: %s\\n\", str); \tcaesar(str); \tprintf(\"Encrypted: %s\\n\", str); \tdecaesar(str); \tprintf(\"Decrypted: %s\\n\", str); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut str: [i8; 35] = *::core::mem::transmute::<&[u8; 35], &mut [i8; 35]>( b\"This is a top secret text message!\\0\", ); print!( \"Original: {}\\n\", build_str_from_raw_ptr(str.as_mut_ptr() as *mut u8) ); rot(13, str.as_mut_ptr()); print!( \"Encrypted: {}\\n\", build_str_from_raw_ptr(str.as_mut_ptr() as *mut u8) ); rot(13, str.as_mut_ptr()); print!( \"Decrypted: {}\\n\", build_str_from_raw_ptr(str.as_mut_ptr() as *mut u8) ); } return 0; }" }, { "index": 18, "before": "void rot(int c, char *str) { \tint l = strlen(str); \tconst char *alpha[2] = { \"abcdefghijklmnopqrstuvwxyz\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"}; \tint i; \tfor (i = 0; i < l; i++) \t{ \t\tif (!isalpha(str[i])) \t\t\tcontinue; \t\tif (isupper(str[i])) str[i] = alpha[1][((int)(tolower(str[i]) - 'a') + c) % 26]; else str[i] = alpha[0][((int)(tolower(str[i]) - 'a') + c) % 26]; \t} }", "after": "pub extern \"C\" fn rot(mut c: i32, mut str: *mut i8) { unsafe { let mut l: i32 = strlen(str) as i32; let mut alpha: [*const i8; 2] = [ b\"abcdefghijklmnopqrstuvwxyz\\0\" as *const u8 as *const i8, b\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\\0\" as *const u8 as *const i8, ]; let mut i: i32 = 0; i = 0; while i < l { if !(*(*__ctype_b_loc()).offset(*str.offset(i as isize) as i32 as isize) as i32 & _ISalpha as i32 == 0) { if *(*__ctype_b_loc()).offset(*str.offset(i as isize) as i32 as isize) as i32 & _ISupper as i32 != 0 { *str.offset(i as isize) = *(alpha[1 as usize]).offset( ((tolower(*str.offset(i as isize) as i32) - 'a' as i32 + c) % 26i32) as isize, ); } else { *str.offset(i as isize) = *(alpha[0 as usize]).offset( ((tolower(*str.offset(i as isize) as i32) - 'a' as i32 + c) % 26i32) as isize, ); } } i += 1; i; } } }" }, { "index": 19, "before": "void chao(const char *in, char *out, cmode mode, bool show_steps) { int i, j, index; char store; size_t len = strlen(in); char left[27], right[27], temp[27]; strcpy(left, l_alphabet); strcpy(right, r_alphabet); temp[26] = '\\0'; for (i = 0; i < len; ++i ) { if (show_steps) printf(\"%s %s\\n\", left, right); if (mode == ENCRYPT) { index = strchr(right, in[i]) - right; out[i] = left[index]; } else { index = strchr(left, in[i]) - left; out[i] = right[index]; } if (i == len - 1) break; /* permute left */ for (j = index; j < 26; ++j) temp[j - index] = left[j]; for (j = 0; j < index; ++j) temp[26 - index + j] = left[j]; store = temp[1]; for (j = 2; j < 14; ++j) temp[j - 1] = temp[j]; temp[13] = store; strcpy(left, temp); /* permute right */ for (j = index; j < 26; ++j) temp[j - index] = right[j]; for (j = 0; j < index; ++j) temp[26 - index + j] = right[j]; store = temp[0]; for (j = 1; j < 26; ++j) temp[j - 1] = temp[j]; temp[25] = store; store = temp[2]; for (j = 3; j < 14; ++j) temp[j - 1] = temp[j]; temp[13] = store; strcpy(right, temp); } }", "after": "pub extern \"C\" fn chao(mut in_0: *const i8, mut out: *mut i8, mut mode: u32, mut show_steps: i32) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut index: i32 = 0; let mut store: i8 = 0; let mut len: u64 = strlen(in_0); let mut left: [i8; 27] = [0; 27]; let mut right: [i8; 27] = [0; 27]; let mut temp: [i8; 27] = [0; 27]; strcpy(left.as_mut_ptr(), l_alphabet); strcpy(right.as_mut_ptr(), r_alphabet); temp[26 as usize] = '\\0' as i8; i = 0; while (i as u64) < len { if show_steps != 0 { print!( \"{} {}\\n\", build_str_from_raw_ptr(left.as_mut_ptr() as *mut u8), build_str_from_raw_ptr(right.as_mut_ptr() as *mut u8) ); } if mode as u32 == ENCRYPT as u32 { index = (strchr(right.as_mut_ptr(), *in_0.offset(i as isize) as i32)) .offset_from(right.as_mut_ptr()) as i32; *out.offset(i as isize) = left[index as usize]; } else { index = (strchr(left.as_mut_ptr(), *in_0.offset(i as isize) as i32)) .offset_from(left.as_mut_ptr()) as i32; *out.offset(i as isize) = right[index as usize]; } if i as u64 == len.wrapping_sub(1) { break; } j = index; while j < 26 { temp[(j - index) as usize] = left[j as usize]; j += 1; j; } j = 0; while j < index { temp[(26 - index + j) as usize] = left[j as usize]; j += 1; j; } store = temp[1 as usize]; j = 2; while j < 14 { temp[(j - 1i32) as usize] = temp[j as usize]; j += 1; j; } temp[13 as usize] = store; strcpy(left.as_mut_ptr(), temp.as_mut_ptr()); j = index; while j < 26 { temp[(j - index) as usize] = right[j as usize]; j += 1; j; } j = 0; while j < index { temp[(26 - index + j) as usize] = right[j as usize]; j += 1; j; } store = temp[0 as usize]; j = 1; while j < 26 { temp[(j - 1i32) as usize] = temp[j as usize]; j += 1; j; } temp[25 as usize] = store; store = temp[2 as usize]; j = 3; while j < 14 { temp[(j - 1i32) as usize] = temp[j as usize]; j += 1; j; } temp[13 as usize] = store; strcpy(right.as_mut_ptr(), temp.as_mut_ptr()); i += 1; i; } } }" }, { "index": 20, "before": "int main() { const char *plain_text = \"WELLDONEISBETTERTHANWELLSAID\"; char *cipher_text = malloc(strlen(plain_text) + 1); char *plain_text2 = malloc(strlen(plain_text) + 1); printf(\"The original plaintext is : %s\\n\", plain_text); printf(\"\\nThe left and right alphabets after each permutation\" \" during encryption are :\\n\\n\"); chao(plain_text, cipher_text, ENCRYPT, TRUE); printf(\"\\nThe ciphertext is : %s\\n\", cipher_text); chao(cipher_text, plain_text2, DECRYPT, FALSE); printf(\"\\nThe recovered plaintext is : %s\\n\", plain_text2); free(cipher_text); free(plain_text2); return 0; }", "after": "fn main() -> i32 { unsafe { let mut plain_text: *const i8 = b\"WELLDONEISBETTERTHANWELLSAID\\0\" as *const u8 as *const i8; let mut cipher_text: *mut i8 = malloc((strlen(plain_text)).wrapping_add(1)) as *mut i8; let mut plain_text2: *mut i8 = malloc((strlen(plain_text)).wrapping_add(1)) as *mut i8; print!( \"The original plaintext is : {}\\n\", build_str_from_raw_ptr(plain_text as *mut u8) ); print!(\"\\nThe left and right alphabets after each permutation during encryption are :\\n\\n\"); chao(plain_text, cipher_text, ENCRYPT, 1); print!( \"\\nThe ciphertext is : {}\\n\", build_str_from_raw_ptr(cipher_text as *mut u8) ); chao(cipher_text, plain_text2, DECRYPT, 0); print!( \"\\nThe recovered plaintext is : {}\\n\", build_str_from_raw_ptr(plain_text2 as *mut u8) ); free(cipher_text as *mut libc::c_void); free(plain_text2 as *mut libc::c_void); return 0; } }" }, { "index": 21, "before": "int main() { int a, b; scanf(\"%d %d\", &a, &b); if (a < b) printf(\"%d is less than %d\\n\", a, b); if (a == b) printf(\"%d is equal to %d\\n\", a, b); if (a > b) printf(\"%d is greater than %d\\n\", a, b); return 0; }", "after": "fn main() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0; unsafe { scanf( b\"%d %d\\0\" as *const u8 as *const i8, &mut a as *mut i32, &mut b as *mut i32, ); } if a < b { print!(\"{} is less than {}\\n\", a, b); } if a == b { print!(\"{} is equal to {}\\n\", a, b); } if a > b { print!(\"{} is greater than {}\\n\", a, b); } return 0; }" }, { "index": 22, "before": "int main(void) { oldColor = 1; newColor = oldColor ? 0 : 1; readPortableBitMap(stdin); floodFill(height/2,width/2); writePortableBitMap(stdout); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { oldColor = 1; newColor = (if oldColor as i32 != 0 { 0 } else { 1 }) as u8; readPortableBitMap(stdin); floodFill(height / 2, width / 2); writePortableBitMap(stdout); } return 0; }" }, { "index": 23, "before": "void skipCommentLines(FILE* file) { int c; int comment = '#'; while ((c = fgetc(file)) == comment) skipLine(file); ungetc(c,file); }", "after": "pub extern \"C\" fn skipCommentLines(mut file: *mut FILE) { unsafe { let mut c: i32 = 0; let mut comment: i32 = '#' as i32; loop { c = fgetc(file); if !(c == comment) { break; } skipLine(file); } ungetc(c, file); } }" }, { "index": 24, "before": "void floodFill(int i, int j) { if ( 0 <= i && i < height && 0 <= j && j < width && bitmap[i][j] == oldColor ) { bitmap[i][j] = newColor; floodFill(i-1,j); floodFill(i+1,j); floodFill(i,j-1); floodFill(i,j+1); } }", "after": "pub extern \"C\" fn floodFill(mut i: i32, mut j: i32) { unsafe { if 0 <= i && i < height && 0 <= j && j < width && bitmap[i as usize][j as usize] as i32 == oldColor as i32 { bitmap[i as usize][j as usize] = newColor; floodFill(i - 1, j); floodFill(i + 1, j); floodFill(i, j - 1); floodFill(i, j + 1); } } }" }, { "index": 25, "before": "void skipLine(FILE* file) { while(!ferror(file) && !feof(file) && fgetc(file) != '\\n') ; }", "after": "pub extern \"C\" fn skipLine(mut file: *mut FILE) { unsafe { while ferror(file) == 0 && feof(file) == 0 && fgetc(file) != '\\n' as i32 {} } }" }, { "index": 26, "before": "void writePortableBitMap(FILE* file) { int i,j; fprintf(file,\"P1\\n\"); fprintf(file,\"%d %d\\n\", width, height); for ( i = 0; i < height; i++ ) { for ( j = 0; j < width; j++ ) fprintf(file,\"%1d\", bitmap[i][j]); fprintf(file,\"\\n\"); } }", "after": "pub extern \"C\" fn writePortableBitMap(mut file: *mut FILE) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; fprintf(file, b\"P1\\n\\0\" as *const u8 as *const i8); fprintf(file, b\"%d %d\\n\\0\" as *const u8 as *const i8, width, height); i = 0; while i < height { j = 0; while j < width { fprintf( file, b\"%1d\\0\" as *const u8 as *const i8, bitmap[i as usize][j as usize] as i32, ); j += 1; j; } fprintf(file, b\"\\n\\0\" as *const u8 as *const i8); i += 1; i; } } }" }, { "index": 27, "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 extern \"C\" fn iter_string(mut str: *const i8, mut d: i32) { unsafe { let mut len: i64 = 0; while *str as i32 != '\\0' as i32 { let fresh0 = str; str = str.offset(1); match *fresh0 as i32 { 88 => { if d != 0 { iter_string(b\"XHXVX\\0\" as *const u8 as *const i8, d - 1); } else { clen += 1; clen; h_rgb(x / scale, y / scale); x += dx; y -= dy; } } 86 => { len = (1u64 << d) as i64; loop { let fresh1 = len; len = len - 1; if !(fresh1 != 0) { break; } clen += 1; clen; h_rgb(x / scale, y / scale); y += dy; } } 72 => { len = (1u64 << d) as i64; loop { let fresh2 = len; len = len - 1; if !(fresh2 != 0) { break; } clen += 1; clen; h_rgb(x / scale, y / scale); x -= dx; } } _ => {} } } } }" }, { "index": 28, "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 extern \"C\" fn sierp(mut leng: i64, mut depth: i32) { unsafe { let mut i: i64 = 0; let mut h: i64 = leng + 20; let mut w: i64 = leng + 20; let mut buf: *mut rgb = malloc( (::core::mem::size_of::() as u64) .wrapping_mul(w as u64) .wrapping_mul(h as u64), ) as *mut rgb; pix = malloc((::core::mem::size_of::<*mut rgb>() as u64).wrapping_mul(h as u64)) as *mut *mut rgb; i = 0; 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, (::core::mem::size_of::() as u64) .wrapping_mul(w as u64) .wrapping_mul(h as u64), ); y = 10; x = y; dx = leng as i64; dy = leng as i64; scale = 1; clen = 0; cscale = 3; i = 0; while i < depth as i64 { sc_up(); i += 1; i; } iter_string(b\"VXH\\0\" as *const u8 as *const i8, depth); let mut fpix: *mut u8 = malloc((w * h * 3i64) as u64) as *mut u8; let mut maxv: f64 = 0 as f64; let mut dbuf: *mut f64 = buf as *mut f64; i = 3 * w * h - 1; while i >= 0 { if *dbuf.offset(i as isize) > maxv { maxv = *dbuf.offset(i as isize); } i -= 1; i; } i = 3 * h * w - 1; while i >= 0 { *fpix.offset(i as isize) = (255 as f64 * *dbuf.offset(i as isize) / maxv) as u8; i -= 1; i; } print!(\"P6\\n{} {}\\n255\\n\", w, h); fflush(stdout); fwrite( fpix as *const libc::c_void, (h * w * 3i64) as u64, 1, stdout, ); } }" }, { "index": 29, "before": "void sc_up() { \tscale *= 2; x *= 2; y *= 2; \tcscale *= 3; }", "after": "pub extern \"C\" fn sc_up() { unsafe { scale *= 2; x *= 2; y *= 2; cscale *= 3; } }" }, { "index": 30, "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": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { let mut size: i32 = 0; let mut depth: i32 = 0; depth = if c > 1 { atoi(*v.offset(1 as isize)) } else { 10 }; size = 1 << depth; fprintf( stderr, b\"size: %d depth: %d\\n\\0\" as *const u8 as *const i8, size, depth, ); sierp(size as i64, depth + 2); return 0; } }" }, { "index": 31, "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 extern \"C\" fn h_rgb(mut x_0: i64, mut y_0: i64) { unsafe { let mut p: *mut rgb = &mut *(*pix.offset(y_0 as isize)).offset(x_0 as isize) as *mut rgb; let mut h: f64 = 6.0f64 * clen as f64 / cscale as f64; let mut VAL: f64 = 1 as f64; let mut c: f64 = 1 as f64 * VAL; let mut X: f64 = c * (1 as f64 - fabs(fmod(h, 2 as f64) - 1 as f64)); match h as i32 { 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": 32, "before": "int main(int argc, char **argv) { if (argc != 2) { printf(\"Usage: benford \\n\"); return EXIT_FAILURE; } float *actual = get_actual_distribution(argv[1]); float *expected = benford_distribution(); puts(\"digit\\tactual\\texpected\"); for (int i = 0; i < 9; i++) printf(\"%d\\t%.3f\\t%.3f\\n\", i + 1, actual[i], expected[i]); return EXIT_SUCCESS; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { if argc != 2 { print!(\"Usage: benford \\n\"); return 1; } let mut actual: *mut libc::c_float = get_actual_distribution(*argv.offset(1 as isize)); let mut expected: *mut libc::c_float = benford_distribution(); puts(b\"digit\\tactual\\texpected\\0\" as *const u8 as *const i8); let mut i: i32 = 0; while i < 9 { print!( \"{}\t{:.3}\t{:.3}\\n\", i + 1, *actual.offset(i as isize) as f64, *expected.offset(i as isize) as f64 ); i += 1; i; } return 0; } }" }, { "index": 33, "before": "int main(void) { int i; printf(\"Set [0,25]:\\n\"); for (i = 0; i < 26; i++) { char s[5]; printf(\"%s \", addSuffix(i, s, 5)); } putchar('\\n'); printf(\"Set [250,265]:\\n\"); for (i = 250; i < 266; i++) { char s[6]; printf(\"%s \", addSuffix(i, s, 6)); } putchar('\\n'); printf(\"Set [1000,1025]:\\n\"); for (i = 1000; i < 1026; i++) { char s[7]; printf(\"%s \", addSuffix(i, s, 7)); } putchar('\\n'); return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; print!(\"Set [0,25]:\\n\"); i = 0; unsafe { while i < 26 { let mut s: [i8; 5] = [0; 5]; print!( \"{} \", build_str_from_raw_ptr(addSuffix(i, s.as_mut_ptr(), 5) as *mut u8) ); i += 1; i; } } print!(\"{}\", '\\n' as i32); print!(\"Set [250,265]:\\n\"); i = 250; unsafe { while i < 266 { let mut s_0: [i8; 6] = [0; 6]; print!( \"{} \", build_str_from_raw_ptr(addSuffix(i, s_0.as_mut_ptr(), 6) as *mut u8) ); i += 1; i; } } print!(\"{}\", '\\n' as i32); print!(\"Set [1000,1025]:\\n\"); i = 1000; unsafe { while i < 1026 { let mut s_1: [i8; 7] = [0; 7]; print!( \"{} \", build_str_from_raw_ptr(addSuffix(i, s_1.as_mut_ptr(), 7) as *mut u8) ); i += 1; i; } } print!(\"{}\", '\\n' as i32); return 0; }" }, { "index": 34, "before": "int main() { range_t test1[] = { {1.1, 2.2} }; range_t test2[] = { {6.1, 7.2}, {7.2, 8.3} }; range_t test3[] = { {4, 3}, {2, 1} }; range_t test4[] = { {4, 3}, {2, 1}, {-1, -2}, {3.9, 10} }; range_t test5[] = { {1, 3}, {-6, -1}, {-4, -5}, {8, 2}, {-6, -6} }; test_consolidate_ranges(test1, LENGTHOF(test1)); test_consolidate_ranges(test2, LENGTHOF(test2)); test_consolidate_ranges(test3, LENGTHOF(test3)); test_consolidate_ranges(test4, LENGTHOF(test4)); test_consolidate_ranges(test5, LENGTHOF(test5)); return 0; }", "after": "fn main() -> i32 { let mut test1: [range_t; 1] = [{ let mut init = range_tag { low: 1.1f64, high: 2.2f64, }; init }]; let mut test2: [range_t; 2] = [ { let mut init = range_tag { low: 6.1f64, high: 7.2f64, }; init }, { let mut init = range_tag { low: 7.2f64, high: 8.3f64, }; init }, ]; let mut test3: [range_t; 2] = [ { let mut init = range_tag { low: 4 as f64, high: 3 as f64, }; init }, { let mut init = range_tag { low: 2 as f64, high: 1 as f64, }; init }, ]; let mut test4: [range_t; 4] = [ { let mut init = range_tag { low: 4 as f64, high: 3 as f64, }; init }, { let mut init = range_tag { low: 2 as f64, high: 1 as f64, }; init }, { let mut init = range_tag { low: -1i32 as f64, high: -2i32 as f64, }; init }, { let mut init = range_tag { low: 3.9f64, high: 10 as f64, }; init }, ]; let mut test5: [range_t; 5] = [ { let mut init = range_tag { low: 1 as f64, high: 3 as f64, }; init }, { let mut init = range_tag { low: -6i32 as f64, high: -1i32 as f64, }; init }, { let mut init = range_tag { low: -4i32 as f64, high: -5i32 as f64, }; init }, { let mut init = range_tag { low: 8 as f64, high: 2 as f64, }; init }, { let mut init = range_tag { low: -6i32 as f64, high: -6i32 as f64, }; init }, ]; test_consolidate_ranges( test1.as_mut_ptr(), (::core::mem::size_of::<[range_t; 1]>() as u64) .wrapping_div(::core::mem::size_of::() as u64), ); test_consolidate_ranges( test2.as_mut_ptr(), (::core::mem::size_of::<[range_t; 2]>() as u64) .wrapping_div(::core::mem::size_of::() as u64), ); test_consolidate_ranges( test3.as_mut_ptr(), (::core::mem::size_of::<[range_t; 2]>() as u64) .wrapping_div(::core::mem::size_of::() as u64), ); test_consolidate_ranges( test4.as_mut_ptr(), (::core::mem::size_of::<[range_t; 4]>() as u64) .wrapping_div(::core::mem::size_of::() as u64), ); test_consolidate_ranges( test5.as_mut_ptr(), (::core::mem::size_of::<[range_t; 5]>() as u64) .wrapping_div(::core::mem::size_of::() as u64), ); return 0; }" }, { "index": 35, "before": "size_t consolidate_ranges(range_t* ranges, size_t count) { normalize_ranges(ranges, count); size_t out_index = 0; for (size_t i = 0; i < count; ) { size_t j = i; while (++j < count && ranges[j].low <= ranges[i].high) { if (ranges[i].high < ranges[j].high) ranges[i].high = ranges[j].high; } ranges[out_index++] = ranges[i]; i = j; } return out_index; }", "after": "pub extern \"C\" fn consolidate_ranges(mut ranges: *mut range_t, mut count: u64) -> u64 { unsafe { normalize_ranges(ranges, count); let mut out_index: u64 = 0; let mut i: u64 = 0; while i < count { let mut j: u64 = i; loop { j = j.wrapping_add(1); if !(j < count && (*ranges.offset(j as isize)).low <= (*ranges.offset(i as isize)).high) { break; } if (*ranges.offset(i as isize)).high < (*ranges.offset(j as isize)).high { (*ranges.offset(i as isize)).high = (*ranges.offset(j as isize)).high; } } let fresh0 = out_index; out_index = out_index.wrapping_add(1); *ranges.offset(fresh0 as isize) = *ranges.offset(i as isize); i = j; } return out_index; } }" }, { "index": 36, "before": "void test_consolidate_ranges(range_t* ranges, size_t count) { print_ranges(ranges, count); printf(\" -> \"); count = consolidate_ranges(ranges, count); print_ranges(ranges, count); printf(\"\\n\"); }", "after": "pub extern \"C\" fn test_consolidate_ranges(mut ranges: *mut range_t, mut count: u64) { unsafe { print_ranges(ranges, count); print!(\" -> \"); count = consolidate_ranges(ranges, count); print_ranges(ranges, count); print!(\"\\n\"); } }" }, { "index": 37, "before": "void normalize_ranges(range_t* ranges, size_t count) { for (size_t i = 0; i < count; ++i) normalize_range(&ranges[i]); qsort(ranges, count, sizeof(range_t), range_compare); }", "after": "pub extern \"C\" fn normalize_ranges(mut ranges: *mut range_t, mut count: u64) { unsafe { let mut i: u64 = 0; while i < count { normalize_range(&mut *ranges.offset(i as isize)); i = i.wrapping_add(1); i; } qsort( ranges as *mut libc::c_void, count, ::core::mem::size_of::() as u64, Some( range_compare as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32, ), ); } }" }, { "index": 38, "before": "void normalize_range(range_t* range) { if (range->high < range->low) { double tmp = range->low; range->low = range->high; range->high = tmp; } }", "after": "pub extern \"C\" fn normalize_range(mut range: *mut range_t) { unsafe { if (*range).high < (*range).low { let mut tmp: f64 = (*range).low; (*range).low = (*range).high; (*range).high = tmp; } } }" }, { "index": 39, "before": "int range_compare(const void* p1, const void* p2) { const range_t* r1 = p1; const range_t* r2 = p2; if (r1->low < r2->low) return -1; if (r1->low > r2->low) return 1; if (r1->high < r2->high) return -1; if (r1->high > r2->high) return 1; return 0; }", "after": "pub extern \"C\" fn range_compare(mut p1: *const libc::c_void, mut p2: *const libc::c_void) -> i32 { unsafe { let mut r1: *const range_t = p1 as *const range_t; let mut r2: *const range_t = p2 as *const range_t; if (*r1).low < (*r2).low { return -1; } if (*r1).low > (*r2).low { return 1; } if (*r1).high < (*r2).high { return -1; } if (*r1).high > (*r2).high { return 1; } return 0; } }" }, { "index": 40, "before": "void print_ranges(const range_t* ranges, size_t count) { if (count == 0) return; print_range(&ranges[0]); for (size_t i = 1; i < count; ++i) { printf(\", \"); print_range(&ranges[i]); } }", "after": "pub extern \"C\" fn print_ranges(mut ranges: *const range_t, mut count: u64) { unsafe { if count == 0 { return; } print_range(&*ranges.offset(0 as isize)); let mut i: u64 = 1; while i < count { print!(\", \"); print_range(&*ranges.offset(i as isize)); i = i.wrapping_add(1); i; } } }" }, { "index": 41, "before": "void print_range(const range_t* range) { printf(\"[%g, %g]\", range->low, range->high); }", "after": "pub extern \"C\" fn print_range(mut range: *const range_t) { print!(\"[{}, {}]\", (*range).low, (*range).high); }" }, { "index": 42, "before": "int main(void) { \tint us_coins[] = { 100, 50, 25, 10, 5, 1, 0 }; \tint eu_coins[] = { 200, 100, 50, 20, 10, 5, 2, 1, 0 }; \tshow(count( 100, us_coins + 2)); \tshow(count( 1000, us_coins)); \tshow(count( 1000 * 100, us_coins)); \tshow(count( 10000 * 100, us_coins)); \tshow(count(100000 * 100, us_coins)); \tputchar('\\n'); \tshow(count( 1 * 100, eu_coins)); \tshow(count( 1000 * 100, eu_coins)); \tshow(count( 10000 * 100, eu_coins)); \tshow(count(100000 * 100, eu_coins)); \treturn 0; }", "after": "fn main() -> i32 { let mut us_coins: [i32; 7] = [100, 50, 25, 10, 5, 1, 0]; let mut eu_coins: [i32; 9] = [200, 100, 50, 20, 10, 5, 2, 1, 0]; unsafe { show(count(100, us_coins.as_mut_ptr().offset(2 as isize))); } show(count(1000, us_coins.as_mut_ptr())); show(count(1000 * 100, us_coins.as_mut_ptr())); show(count(10000 * 100, us_coins.as_mut_ptr())); show(count(100000 * 100, us_coins.as_mut_ptr())); print!(\"{}\", '\\n' as i32); show(count(1 * 100, eu_coins.as_mut_ptr())); show(count(1000 * 100, eu_coins.as_mut_ptr())); show(count(10000 * 100, eu_coins.as_mut_ptr())); show(count(100000 * 100, eu_coins.as_mut_ptr())); return 0; }" }, { "index": 43, "before": "int count2(int sum, int *coins) { \tif (!*coins || sum < 0) return 0; \tif (!sum) return 1; \treturn count2(sum - *coins, coins) + count2(sum, coins + 1); }", "after": "pub extern \"C\" fn count2(mut sum: i32, mut coins: *mut i32) -> i32 { unsafe { if *coins == 0 || sum < 0 { return 0; } if sum == 0 { return 1; } return count2(sum - *coins, coins) + count2(sum, coins.offset(1 as isize)); } }" }, { "index": 44, "before": "i128 count(int sum, int *coins) { \tint n, i, k; \tfor (n = 0; coins[n]; n++); \ti128 **v = malloc(sizeof(int*) * n); \tint *idx = malloc(sizeof(int) * n); \tfor (i = 0; i < n; i++) { \t\tidx[i] = coins[i]; \t\t// each v[i] is a cyclic buffer \t\tv[i] = calloc(sizeof(i128), coins[i]); \t} \tv[0][coins[0] - 1] = (i128) {{1, 0}}; \tfor (k = 0; k <= sum; k++) { \t\tfor (i = 0; i < n; i++) \t\t\tif (!idx[i]--) idx[i] = coins[i] - 1; \t\ti128 c = v[0][ idx[0] ]; \t\tfor (i = 1; i < n; i++) { \t\t\ti128 *p = v[i] + idx[i]; \t\t\t// 128 bit addition \t\t\tp->x[0] += c.x[0]; \t\t\tp->x[1] += c.x[1]; \t\t\tif (p->x[0] < c.x[0]) // carry \t\t\t\tp->x[1] ++; \t\t\tc = *p; \t\t} \t} \ti128 r = v[n - 1][idx[n-1]]; \tfor (i = 0; i < n; i++) free(v[i]); \tfree(v); \tfree(idx); \treturn r; }", "after": "pub extern \"C\" fn count(mut sum: i32, mut coins: *mut i32) -> i128_0 { unsafe { let mut n: i32 = 0; let mut i: i32 = 0; let mut k: i32 = 0; n = 0; while *coins.offset(n as isize) != 0 { n += 1; n; } let mut v: *mut *mut i128_0 = malloc((::core::mem::size_of::<*mut i32>() as u64).wrapping_mul(n as u64)) as *mut *mut i128_0; let mut idx: *mut i32 = malloc((::core::mem::size_of::() as u64).wrapping_mul(n as u64)) as *mut i32; i = 0; while i < n { *idx.offset(i as isize) = *coins.offset(i as isize); let ref mut fresh3 = *v.offset(i as isize); *fresh3 = calloc( ::core::mem::size_of::() as u64, *coins.offset(i as isize) as u64, ) as *mut i128_0; i += 1; i; } *(*v.offset(0 as isize)).offset((*coins.offset(0 as isize) - 1i32) as isize) = { let mut init = i128_0 { x: [1, 0] }; init }; k = 0; while k <= sum { i = 0; while i < n { let ref mut fresh4 = *idx.offset(i as isize); let fresh5 = *fresh4; *fresh4 = *fresh4 - 1; if fresh5 == 0 { *idx.offset(i as isize) = *coins.offset(i as isize) - 1; } i += 1; i; } let mut c: i128_0 = *(*v.offset(0 as isize)).offset(*idx.offset(0 as isize) as isize); i = 1; while i < n { let mut p: *mut i128_0 = (*v.offset(i as isize)).offset(*idx.offset(i as isize) as isize); (*p).x[0 as usize] = ((*p).x[0 as usize] as u64).wrapping_add(c.x[0 as usize]) as u64; (*p).x[1 as usize] = ((*p).x[1 as usize] as u64).wrapping_add(c.x[1 as usize]) as u64; if (*p).x[0 as usize] < c.x[0 as usize] { (*p).x[1 as usize] = ((*p).x[1 as usize]).wrapping_add(1); (*p).x[1 as usize]; } c = *p; i += 1; i; } k += 1; k; } let mut r: i128_0 = *(*v.offset((n - 1i32) as isize)).offset(*idx.offset((n - 1i32) as isize) as isize); i = 0; while i < n { free(*v.offset(i as isize) as *mut libc::c_void); i += 1; i; } free(v as *mut libc::c_void); free(idx as *mut libc::c_void); return r; } }" }, { "index": 45, "before": "void show(i128 v) { \tuint32_t x[4] = {v.x[0], v.x[0] >> 32, v.x[1], v.x[1] >> 32}; \tint i, j = 0, len = 4; \tchar buf[100]; \tdo { \t\tuint64_t c = 0; \t\tfor (i = len; i--; ) { \t\t\tc = (c << 32) + x[i]; \t\t\tx[i] = c / 10, c %= 10; \t\t} \t\tbuf[j++] = c + '0'; \t\tfor (len = 4; !x[len - 1]; len--); \t} while (len); \twhile (j--) putchar(buf[j]); \tputchar('\\n'); }", "after": "pub extern \"C\" fn show(mut v: i128_0) { let mut x: [u32; 4] = [ v.x[0 as usize] as u32, (v.x[0 as usize] >> 32i32) as u32, v.x[1 as usize] as u32, (v.x[1 as usize] >> 32i32) as u32, ]; let mut i: i32 = 0; let mut j: i32 = 0; let mut len: i32 = 4; let mut buf: [i8; 100] = [0; 100]; loop { let mut c: u64 = 0; i = len; loop { let fresh0 = i; i = i - 1; if !(fresh0 != 0) { break; } c = (c << 32i32).wrapping_add(x[i as usize] as u64); x[i as usize] = c.wrapping_div(10) as u32; c = (c).wrapping_rem(10) as u64; } let fresh1 = j; j = j + 1; buf[fresh1 as usize] = c.wrapping_add('0' as u64) as i8; len = 4; while x[(len - 1i32) as usize] == 0 { len -= 1; len; } if !(len != 0) { break; } } loop { let fresh2 = j; j = j - 1; if !(fresh2 != 0) { break; } print!(\"{}\", buf[j as usize] as i32); } print!(\"{}\", '\\n' as i32); }" }, { "index": 46, "before": "int main(void) { \tint i; \tfor (i = 2; i < 100; i++) \t\tif (semiprime(i)) printf(\" %d\", i); \tputchar('\\n'); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; i = 2; while i < 100 { if semiprime(i) != 0 { print!(\" {}\", i); } i += 1; i; } print!(\"{}\", '\\n' as i32); return 0; }" }, { "index": 47, "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 extern \"C\" fn semiprime(mut n: i32) -> i32 { let mut p: i32 = 0; let mut f: i32 = 0; p = 2; while f < 2 && p * p <= n { while 0 == n % p { n /= p; f += 1; f; } p += 1; p; } return (f + (n > 1i32) as i32 == 2) as i32; }" }, { "index": 48, "before": "int main() { { unsigned long long n = 1; for (int i = 0; i < 30; i++) { // __builtin_popcount() for unsigned int // __builtin_popcountl() for unsigned long // __builtin_popcountll() for unsigned long long printf(\"%d \", __builtin_popcountll(n)); n *= 3; } printf(\"\\n\"); } int od[30]; int ne = 0, no = 0; printf(\"evil : \"); for (int n = 0; ne+no < 60; n++) { if ((__builtin_popcount(n) & 1) == 0) { if (ne < 30) { \tprintf(\"%d \", n); \tne++; } } else { if (no < 30) { \tod[no++] = n; } } } printf(\"\\n\"); printf(\"odious: \"); for (int i = 0; i < 30; i++) { printf(\"%d \", od[i]); } printf(\"\\n\"); return 0; }", "after": "fn main() -> i32 { let mut n: u64 = 1; let mut i: i32 = 0; while i < 30 { print!(\"{} \", n.count_ones() as i32); n = n.wrapping_mul(3); i += 1; i; } print!(\"\\n\"); let mut od: [i32; 30] = [0; 30]; let mut ne: i32 = 0; let mut no: i32 = 0; print!(\"evil : \"); let mut n_0: i32 = 0; while ne + no < 60 { if (n_0 as u32).count_ones() as i32 & 1 == 0 { if ne < 30 { print!(\"{} \", n_0); ne += 1; ne; } } else if no < 30 { let fresh0 = no; no = no + 1; od[fresh0 as usize] = n_0; } n_0 += 1; n_0; } print!(\"\\n\"); print!(\"odious: \"); let mut i_0: i32 = 0; while i_0 < 30 { print!(\"{} \", od[i_0 as usize]); i_0 += 1; i_0; } print!(\"\\n\"); return 0; }" }, { "index": 49, "before": "double InvokeComposed( Class2Func f1, Class2Func f2, double val ) { return f1(f2(val)); }", "after": "pub extern \"C\" fn InvokeComposed(mut f1: Class2Func, mut f2: Class2Func, mut val: f64) -> f64 { unsafe { return f1.expect(\"non-null function pointer\")(f2.expect(\"non-null function pointer\")(val)); } }" }, { "index": 50, "before": "Class2Func WhichFunc( int idx) { return (idx < 4) ? &functionA : &functionB; }", "after": "pub extern \"C\" fn WhichFunc(mut idx: i32) -> Class2Func { return if idx < 4 { Some(functionA as unsafe extern \"C\" fn(f64) -> f64) } else { Some(functionB as unsafe extern \"C\" fn(f64) -> f64) }; }" }, { "index": 51, "before": "int main(int argc, char *argv[]) { int ix; Composition c; printf(\"Function1(functionA, 3.0) = %f\\n\", Function1(WhichFunc(0), 3.0)); for (ix=0; ix<4; ix++) { c = Compose(funcListA[ix], funcListB[ix]); printf(\"Compostion %d(0.9) = %f\\n\", ix, CallComposed(c, 0.9)); } return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut ix: i32 = 0; let mut c: Composition = 0 as *mut sComposition; print!( \"Function1(functionA, 3.0) = {}\\n\", Function1(WhichFunc(0), 3.0f64) ); ix = 0; while ix < 4 { c = Compose(funcListA[ix as usize], funcListB[ix as usize]); print!(\"Compostion {}(0.9) = {}\\n\", ix, CallComposed(c, 0.9f64)); ix += 1; ix; } return 0; } }" }, { "index": 52, "before": "double Function1( Class2Func f2, double val ) { return f2(val); }", "after": "pub extern \"C\" fn Function1(mut f2: Class2Func, mut val: f64) -> f64 { unsafe { return f2.expect(\"non-null function pointer\")(val); } }" }, { "index": 53, "before": "double functionB(double v) { return exp(log(v)/3); }", "after": "pub extern \"C\" fn functionB(mut v: f64) -> f64 { unsafe { return exp(log(v) / 3 as f64); } }" }, { "index": 54, "before": "Composition Compose( Class2Func f1, Class2Func f2) { Composition comp = malloc(sizeof(struct sComposition)); comp->f1 = f1; comp->f2 = f2; return comp; }", "after": "pub extern \"C\" fn Compose(mut f1: Class2Func, mut f2: Class2Func) -> Composition { unsafe { let mut comp: Composition = malloc(::core::mem::size_of::() as u64) as Composition; (*comp).f1 = f1; (*comp).f2 = f2; return comp; } }" }, { "index": 55, "before": "double functionA( double v) { return v*v*v; }", "after": "pub extern \"C\" fn functionA(mut v: f64) -> f64 { return v * v * v; }" }, { "index": 56, "before": "double CallComposed( Composition comp, double val ) { return comp->f1( comp->f2(val) ); }", "after": "pub extern \"C\" fn CallComposed(mut comp: Composition, mut val: f64) -> f64 { return ((*comp).f1).expect(\"non-null function pointer\")(((*comp).f2) .expect(\"non-null function pointer\")( val )); }" }, { "index": 57, "before": "void testcase(const char *pszTest) { unsigned char abyAddr[16]; int bIsIPv6; int nPort; int bSuccess; printf(\"Test case '%s'\\n\", pszTest); const char *pszTextCursor = pszTest; bSuccess = ParseIPv4OrIPv6(&pszTextCursor, abyAddr, &nPort, &bIsIPv6); if (!bSuccess) { printf(\"parse failed, at about index %d; rest: '%s'\\n\", pszTextCursor - pszTest, pszTextCursor); return; } printf(\"addr: \"); dumpbin(abyAddr, bIsIPv6 ? 16 : 4); printf(\"\\n\"); if (0 == nPort) printf(\"port absent\"); else printf(\"port: %d\", htons(nPort)); printf(\"\\n\\n\"); }", "after": "pub extern \"C\" fn testcase(mut pszTest: *const i8) { unsafe { let mut abyAddr: [u8; 16] = [0; 16]; let mut bIsIPv6: i32 = 0; let mut nPort: i32 = 0; let mut bSuccess: i32 = 0; print!(\"Test case {}\\n\", build_str_from_raw_ptr(pszTest as *mut u8)); let mut pszTextCursor: *const i8 = pszTest; bSuccess = ParseIPv4OrIPv6( &mut pszTextCursor, abyAddr.as_mut_ptr(), &mut nPort, &mut bIsIPv6, ); if bSuccess == 0 { print!( \"parse failed, at about index {}; rest: {}\\n\", pszTextCursor.offset_from(pszTest) as i64, build_str_from_raw_ptr(pszTextCursor as *mut u8) ); return; } print!(\"addr: \"); dumpbin(abyAddr.as_mut_ptr(), if bIsIPv6 != 0 { 16 } else { 4 }); print!(\"\\n\"); if 0 == nPort { print!(\"port absent\"); } else { print!(\"port: {}\", htons(nPort as u16) as i32); } print!(\"\\n\\n\"); } }" }, { "index": 58, "before": "unsigned short htons(unsigned short us) { return (((unsigned char *)&us)[0] << 8) + ((unsigned char *)&us)[1]; }", "after": "pub extern \"C\" fn htons(mut us: u16) -> u16 { unsafe { return (((*(&mut us as *mut u16 as *mut u8).offset(0 as isize) as i32) << 8i32) + *(&mut us as *mut u16 as *mut u8).offset(1 as isize) as i32) as u16; } }" }, { "index": 59, "before": "int ParseIPv4OrIPv6_2(const char *pszText, unsigned char *abyAddr, int *pnPort, int *pbIsIPv6) { const char *pszTextLocal = pszText; return ParseIPv4OrIPv6(&pszTextLocal, abyAddr, pnPort, pbIsIPv6); }", "after": "pub extern \"C\" fn ParseIPv4OrIPv6_2( mut pszText: *const i8, mut abyAddr: *mut u8, mut pnPort: *mut i32, mut pbIsIPv6: *mut i32, ) -> i32 { unsafe { let mut pszTextLocal: *const i8 = pszText; return ParseIPv4OrIPv6(&mut pszTextLocal, abyAddr, pnPort, pbIsIPv6); } }" }, { "index": 60, "before": "void dumpbin(unsigned char *pbyBin, int nLen) { int i; for (i = 0; i < nLen; ++i) { printf(\"%02x\", pbyBin[i]); } }", "after": "pub extern \"C\" fn dumpbin(mut pbyBin: *mut u8, mut nLen: i32) { unsafe { let mut i: i32 = 0; i = 0; while i < nLen { print!(\"{:02x}\", *pbyBin.offset(i as isize) as i32); i += 1; i; } } }" }, { "index": 61, "before": "static unsigned int _parseHex(const char **pchCursor) { unsigned int nVal = 0; char chNow; while (chNow = **pchCursor & 0x5f, //(collapses case, but mutilates digits) (chNow >= ('0' & 0x5f) && chNow <= ('9' & 0x5f)) || (chNow >= 'A' && chNow <= 'F')) { unsigned char nybbleValue; chNow -= 0x10; //scootch digital values down; hex now offset by x31 nybbleValue = (chNow > 9 ? chNow - (0x31 - 0x0a) : chNow); //shift nybble in nVal <<= 4; nVal += nybbleValue; ++*pchCursor; } return nVal; }", "after": "extern \"C\" fn _parseHex(mut pchCursor: *mut *const i8) -> u32 { unsafe { let mut nVal: u32 = 0; let mut chNow: i8 = 0; loop { chNow = (**pchCursor as i32 & 0x5fi32) as i8; if !(chNow as i32 >= '0' as i32 & 0x5f && chNow as i32 <= '9' as i32 & 0x5f || chNow as i32 >= 'A' as i32 && chNow as i32 <= 'F' as i32) { break; } let mut nybbleValue: u8 = 0; chNow = (chNow as i32 - 0x10i32) as i8; nybbleValue = (if chNow as i32 > 9i32 { chNow as i32 - (0x31 - 0xa) } else { chNow as i32 }) as u8; nVal <<= 4; nVal = nVal.wrapping_add(nybbleValue as u32); *pchCursor = (*pchCursor).offset(1); *pchCursor; } return nVal; } }" }, { "index": 62, "before": "int ParseIPv4OrIPv6(const char **ppszText, unsigned char *abyAddr, int *pnPort, int *pbIsIPv6) { unsigned char *abyAddrLocal; unsigned char abyDummyAddr[16]; //find first colon, dot, and open bracket const char *pchColon = strchr(*ppszText, ':'); const char *pchDot = strchr(*ppszText, '.'); const char *pchOpenBracket = strchr(*ppszText, '['); const char *pchCloseBracket = NULL; //we'll consider this to (probably) be IPv6 if we find an open //bracket, or an absence of dots, or if there is a colon, and it //precedes any dots that may or may not be there int bIsIPv6local = NULL != pchOpenBracket || NULL == pchDot || (NULL != pchColon && (NULL == pchDot || pchColon < pchDot)); //OK, now do a little further sanity check our initial guess... if (bIsIPv6local) { //if open bracket, then must have close bracket that follows somewhere pchCloseBracket = strchr(*ppszText, ']'); if (NULL != pchOpenBracket && (NULL == pchCloseBracket || pchCloseBracket < pchOpenBracket)) return 0; } else //probably ipv4 { //dots must exist, and precede any colons if (NULL == pchDot || (NULL != pchColon && pchColon < pchDot)) return 0; } //we figured out this much so far.... if (NULL != pbIsIPv6) *pbIsIPv6 = bIsIPv6local; //especially for IPv6 (where we will be decompressing and validating) //we really need to have a working buffer even if the caller didn't //care about the results. abyAddrLocal = abyAddr; //prefer to use the caller's if (NULL == abyAddrLocal) //but use a dummy if we must abyAddrLocal = abyDummyAddr; //OK, there should be no correctly formed strings which are miscategorized, //and now any format errors will be found out as we continue parsing //according to plan. if (!bIsIPv6local) //try to parse as IPv4 { //4 dotted quad decimal; optional port if there is a colon //since there are just 4, and because the last one can be terminated //differently, I'm just going to unroll any potential loop. unsigned char *pbyAddrCursor = abyAddrLocal; unsigned int nVal; const char *pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); //get first val if ('.' != **ppszText || nVal > 255 || pszTextBefore == *ppszText) //must be in range and followed by dot and nonempty return 0; *(pbyAddrCursor++) = (unsigned char)nVal; //stick it in addr ++(*ppszText); //past the dot pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); //get second val if ('.' != **ppszText || nVal > 255 || pszTextBefore == *ppszText) return 0; *(pbyAddrCursor++) = (unsigned char)nVal; ++(*ppszText); //past the dot pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); //get third val if ('.' != **ppszText || nVal > 255 || pszTextBefore == *ppszText) return 0; *(pbyAddrCursor++) = (unsigned char)nVal; ++(*ppszText); //past the dot pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); //get fourth val if (nVal > 255 || pszTextBefore == *ppszText) //(we can terminate this one in several ways) return 0; *(pbyAddrCursor++) = (unsigned char)nVal; if (':' == **ppszText && NULL != pnPort) //have port part, and we want it { unsigned short usPortNetwork; //save value in network order ++(*ppszText); //past the colon pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if (nVal > 65535 || pszTextBefore == *ppszText) return 0; ((unsigned char *)&usPortNetwork)[0] = (nVal & 0xff00) >> 8; ((unsigned char *)&usPortNetwork)[1] = (nVal & 0xff); *pnPort = usPortNetwork; return 1; } else //finished just with ip address { if (NULL != pnPort) *pnPort = 0; //indicate we have no port part return 1; } } else //try to parse as IPv6 { unsigned char *pbyAddrCursor; unsigned char *pbyZerosLoc; int bIPv4Detected; int nIdx; //up to 8 16-bit hex quantities, separated by colons, with at most one //empty quantity, acting as a stretchy run of zeroes. optional port //if there are brackets followed by colon and decimal port number. //A further form allows an ipv4 dotted quad instead of the last two //16-bit quantities, but only if in the ipv4 space ::ffff:x:x . if (NULL != pchOpenBracket) //start past the open bracket, if it exists *ppszText = pchOpenBracket + 1; pbyAddrCursor = abyAddrLocal; pbyZerosLoc = NULL; //if we find a 'zero compression' location bIPv4Detected = 0; for (nIdx = 0; nIdx < 8; ++nIdx) //we've got up to 8 of these, so we will use a loop { const char *pszTextBefore = *ppszText; unsigned nVal = _parseHex(ppszText); //get value; these are hex if (pszTextBefore == *ppszText) //if empty, we are zero compressing; note the loc { if (NULL != pbyZerosLoc) //there can be only one! { //unless it's a terminal empty field, then this is OK, it just means we're done with the host part if (pbyZerosLoc == pbyAddrCursor) { --nIdx; break; } return 0; //otherwise, it's a format error } if (':' != **ppszText) //empty field can only be via : return 0; if (0 == nIdx) //leading zero compression requires an extra peek, and adjustment { ++(*ppszText); if (':' != **ppszText) return 0; } pbyZerosLoc = pbyAddrCursor; ++(*ppszText); } else { if ('.' == **ppszText) //special case of ipv4 convenience notation { //who knows how to parse ipv4? we do! const char *pszTextlocal = pszTextBefore; //back it up unsigned char abyAddrlocal[16]; int bIsIPv6local; int bParseResultlocal = ParseIPv4OrIPv6(&pszTextlocal, abyAddrlocal, NULL, &bIsIPv6local); *ppszText = pszTextlocal; //success or fail, remember the terminating char if (!bParseResultlocal || bIsIPv6local) //must parse and must be ipv4 return 0; //transfer addrlocal into the present location *(pbyAddrCursor++) = abyAddrlocal[0]; *(pbyAddrCursor++) = abyAddrlocal[1]; *(pbyAddrCursor++) = abyAddrlocal[2]; *(pbyAddrCursor++) = abyAddrlocal[3]; ++nIdx; //pretend like we took another short, since the ipv4 effectively is two shorts bIPv4Detected = 1; //remember how we got here for further validation later break; //totally done with address } if (nVal > 65535) //must be 16 bit quantity return 0; *(pbyAddrCursor++) = nVal >> 8; //transfer in network order *(pbyAddrCursor++) = nVal & 0xff; if (':' == **ppszText) //typical case inside; carry on { ++(*ppszText); } else //some other terminating character; done with this parsing parts { break; } } } //handle any zero compression we found if (NULL != pbyZerosLoc) { int nHead = (int)(pbyZerosLoc - abyAddrLocal); //how much before zero compression int nTail = nIdx * 2 - (int)(pbyZerosLoc - abyAddrLocal); //how much after zero compression int nZeros = 16 - nTail - nHead; //how much zeros memmove(&abyAddrLocal[16 - nTail], pbyZerosLoc, nTail); //scootch stuff down memset(pbyZerosLoc, 0, nZeros); //clear the compressed zeros } //validation of ipv4 subspace ::ffff:x.x if (bIPv4Detected) { static const unsigned char abyPfx[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff}; if (0 != memcmp(abyAddrLocal, abyPfx, sizeof(abyPfx))) return 0; } //close bracket if (NULL != pchOpenBracket) { if (']' != **ppszText) return 0; ++(*ppszText); } if (':' == **ppszText && NULL != pnPort) //have port part, and we want it { const char *pszTextBefore; unsigned int nVal; unsigned short usPortNetwork; //save value in network order ++(*ppszText); //past the colon pszTextBefore = *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if (nVal > 65535 || pszTextBefore == *ppszText) return 0; ((unsigned char *)&usPortNetwork)[0] = (nVal & 0xff00) >> 8; ((unsigned char *)&usPortNetwork)[1] = (nVal & 0xff); *pnPort = usPortNetwork; return 1; } else //finished just with ip address { if (NULL != pnPort) *pnPort = 0; //indicate we have no port part return 1; } } }", "after": "pub extern \"C\" fn ParseIPv4OrIPv6( mut ppszText: *mut *const i8, mut abyAddr: *mut u8, mut pnPort: *mut i32, mut pbIsIPv6: *mut i32, ) -> i32 { unsafe { let mut abyAddrLocal: *mut u8 = 0 as *mut u8; let mut abyDummyAddr: [u8; 16] = [0; 16]; let mut pchColon: *const i8 = strchr(*ppszText, ':' as i32); let mut pchDot: *const i8 = strchr(*ppszText, '.' as i32); let mut pchOpenBracket: *const i8 = strchr(*ppszText, '[' as i32); let mut pchCloseBracket: *const i8 = 0 as *const i8; let mut bIsIPv6local: i32 = (!pchOpenBracket.is_null() || pchDot.is_null() || !pchColon.is_null() && (pchDot.is_null() || pchColon < pchDot)) as i32; if bIsIPv6local != 0 { pchCloseBracket = strchr(*ppszText, ']' as i32); if !pchOpenBracket.is_null() && (pchCloseBracket.is_null() || pchCloseBracket < pchOpenBracket) { return 0; } } else if pchDot.is_null() || !pchColon.is_null() && pchColon < pchDot { return 0; } if !pbIsIPv6.is_null() { *pbIsIPv6 = bIsIPv6local; } abyAddrLocal = abyAddr; if abyAddrLocal.is_null() { abyAddrLocal = abyDummyAddr.as_mut_ptr(); } if bIsIPv6local == 0 { let mut pbyAddrCursor: *mut u8 = abyAddrLocal; let mut nVal: u32 = 0; let mut pszTextBefore: *const i8 = *ppszText; nVal = _parseDecimal(ppszText); if '.' as i32 != **ppszText as i32 || nVal > 255 || pszTextBefore == *ppszText { return 0; } let fresh0 = pbyAddrCursor; pbyAddrCursor = pbyAddrCursor.offset(1); *fresh0 = nVal as u8; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if '.' as i32 != **ppszText as i32 || nVal > 255 || pszTextBefore == *ppszText { return 0; } let fresh1 = pbyAddrCursor; pbyAddrCursor = pbyAddrCursor.offset(1); *fresh1 = nVal as u8; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if '.' as i32 != **ppszText as i32 || nVal > 255 || pszTextBefore == *ppszText { return 0; } let fresh2 = pbyAddrCursor; pbyAddrCursor = pbyAddrCursor.offset(1); *fresh2 = nVal as u8; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if nVal > 255 || pszTextBefore == *ppszText { return 0; } let fresh3 = pbyAddrCursor; pbyAddrCursor = pbyAddrCursor.offset(1); *fresh3 = nVal as u8; if ':' as i32 == **ppszText as i32 && !pnPort.is_null() { let mut usPortNetwork: u16 = 0; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if nVal > 65535 || pszTextBefore == *ppszText { return 0; }; *(&mut usPortNetwork as *mut u16 as *mut u8).offset(0 as isize) = ((nVal & 0xff00u32) >> 8) as u8; *(&mut usPortNetwork as *mut u16 as *mut u8).offset(1 as isize) = (nVal & 0xffu32) as u8; *pnPort = usPortNetwork as i32; return 1; } else { if !pnPort.is_null() { *pnPort = 0; } return 1; } } else { let mut pbyAddrCursor_0: *mut u8 = 0 as *mut u8; let mut pbyZerosLoc: *mut u8 = 0 as *mut u8; let mut bIPv4Detected: i32 = 0; let mut nIdx: i32 = 0; if !pchOpenBracket.is_null() { *ppszText = pchOpenBracket.offset(1 as isize); } pbyAddrCursor_0 = abyAddrLocal; pbyZerosLoc = 0 as *mut u8; bIPv4Detected = 0; nIdx = 0; while nIdx < 8 { let mut pszTextBefore_0: *const i8 = *ppszText; let mut nVal_0: u32 = _parseHex(ppszText); if pszTextBefore_0 == *ppszText { if !pbyZerosLoc.is_null() { if pbyZerosLoc == pbyAddrCursor_0 { nIdx -= 1; nIdx; break; } else { return 0; } } else { if ':' as i32 != **ppszText as i32 { return 0; } if 0 == nIdx { *ppszText = (*ppszText).offset(1); *ppszText; if ':' as i32 != **ppszText as i32 { return 0; } } pbyZerosLoc = pbyAddrCursor_0; *ppszText = (*ppszText).offset(1); *ppszText; } } else if '.' as i32 == **ppszText as i32 { let mut pszTextlocal: *const i8 = pszTextBefore_0; let mut abyAddrlocal: [u8; 16] = [0; 16]; let mut bIsIPv6local_0: i32 = 0; let mut bParseResultlocal: i32 = ParseIPv4OrIPv6( &mut pszTextlocal, abyAddrlocal.as_mut_ptr(), 0 as *mut i32, &mut bIsIPv6local_0, ); *ppszText = pszTextlocal; if bParseResultlocal == 0 || bIsIPv6local_0 != 0 { return 0; } let fresh4 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh4 = abyAddrlocal[0 as usize]; let fresh5 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh5 = abyAddrlocal[1 as usize]; let fresh6 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh6 = abyAddrlocal[2 as usize]; let fresh7 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh7 = abyAddrlocal[3 as usize]; nIdx += 1; nIdx; bIPv4Detected = 1; break; } else { if nVal_0 > 65535 { return 0; } let fresh8 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh8 = (nVal_0 >> 8i32) as u8; let fresh9 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh9 = (nVal_0 & 0xffu32) as u8; if !(':' as i32 == **ppszText as i32) { break; } *ppszText = (*ppszText).offset(1); *ppszText; } nIdx += 1; nIdx; } if !pbyZerosLoc.is_null() { let mut nHead: i32 = pbyZerosLoc.offset_from(abyAddrLocal) as i32; let mut nTail: i32 = nIdx * 2 - pbyZerosLoc.offset_from(abyAddrLocal) as i32; let mut nZeros: i32 = 16 - nTail - nHead; memmove( &mut *abyAddrLocal.offset((16 - nTail) as isize) as *mut u8 as *mut libc::c_void, pbyZerosLoc as *const libc::c_void, nTail as u64, ); memset(pbyZerosLoc as *mut libc::c_void, 0, nZeros as u64); } if bIPv4Detected != 0 { static mut abyPfx: [u8; 12] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff]; if 0 != memcmp( abyAddrLocal as *const libc::c_void, abyPfx.as_ptr() as *const libc::c_void, ::core::mem::size_of::<[u8; 12]>() as u64, ) { return 0; } } if !pchOpenBracket.is_null() { if ']' as i32 != **ppszText as i32 { return 0; } *ppszText = (*ppszText).offset(1); *ppszText; } if ':' as i32 == **ppszText as i32 && !pnPort.is_null() { let mut pszTextBefore_1: *const i8 = 0 as *const i8; let mut nVal_1: u32 = 0; let mut usPortNetwork_0: u16 = 0; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore_1 = *ppszText; pszTextBefore_1 = *ppszText; nVal_1 = _parseDecimal(ppszText); if nVal_1 > 65535 || pszTextBefore_1 == *ppszText { return 0; }; *(&mut usPortNetwork_0 as *mut u16 as *mut u8).offset(0 as isize) = ((nVal_1 & 0xff00u32) >> 8) as u8; *(&mut usPortNetwork_0 as *mut u16 as *mut u8).offset(1 as isize) = (nVal_1 & 0xffu32) as u8; *pnPort = usPortNetwork_0 as i32; return 1; } else { if !pnPort.is_null() { *pnPort = 0; } return 1; } }; } }" }, { "index": 63, "before": "static unsigned int _parseDecimal(const char **pchCursor) { unsigned int nVal = 0; char chNow; while (chNow = **pchCursor, chNow >= '0' && chNow <= '9') { //shift digit in nVal *= 10; nVal += chNow - '0'; ++*pchCursor; } return nVal; }", "after": "extern \"C\" fn _parseDecimal(mut pchCursor: *mut *const i8) -> u32 { unsafe { let mut nVal: u32 = 0; let mut chNow: i8 = 0; loop { chNow = **pchCursor; if !(chNow as i32 >= '0' as i32 && chNow as i32 <= '9' as i32) { break; } nVal = nVal.wrapping_mul(10); nVal = nVal.wrapping_add((chNow as i32 - '0' as i32) as u32); *pchCursor = (*pchCursor).offset(1); *pchCursor; } return nVal; } }" }, { "index": 64, "before": "int main(int argc, char *argv[]) { //The \"localhost\" IPv4 address testcase(\"127.0.0.1\"); //The \"localhost\" IPv4 address, with a specified port (80) testcase(\"127.0.0.1:80\"); //The \"localhost\" IPv6 address testcase(\"::1\"); //The \"localhost\" IPv6 address, with a specified port (80) testcase(\"[::1]:80\"); //Rosetta Code's primary server's public IPv6 address testcase(\"2605:2700:0:3::4713:93e3\"); //Rosetta Code's primary server's public IPv6 address, with a specified port (80) testcase(\"[2605:2700:0:3::4713:93e3]:80\"); //ipv4 space testcase(\"::ffff:192.168.173.22\"); //ipv4 space with port testcase(\"[::ffff:192.168.173.22]:80\"); //trailing compression testcase(\"1::\"); //trailing compression with port testcase(\"[1::]:80\"); //'any' address compression testcase(\"::\"); //'any' address compression with port testcase(\"[::]:80\"); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { testcase(b\"127.0.0.1\\0\" as *const u8 as *const i8); testcase(b\"127.0.0.1:80\\0\" as *const u8 as *const i8); testcase(b\"::1\\0\" as *const u8 as *const i8); testcase(b\"[::1]:80\\0\" as *const u8 as *const i8); testcase(b\"2605:2700:0:3::4713:93e3\\0\" as *const u8 as *const i8); testcase(b\"[2605:2700:0:3::4713:93e3]:80\\0\" as *const u8 as *const i8); testcase(b\"::ffff:192.168.173.22\\0\" as *const u8 as *const i8); testcase(b\"[::ffff:192.168.173.22]:80\\0\" as *const u8 as *const i8); testcase(b\"1::\\0\" as *const u8 as *const i8); testcase(b\"[1::]:80\\0\" as *const u8 as *const i8); testcase(b\"::\\0\" as *const u8 as *const i8); testcase(b\"[::]:80\\0\" as *const u8 as *const i8); return 0; } }" }, { "index": 65, "before": "void example() { printf(\"Example\\n\"); }", "after": "pub extern \"C\" fn example() { print!(\"Example\\n\"); }" }, { "index": 66, "before": "int main(int argc, char *argv[]) { repeat(example, 4); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { repeat( ::core::mem::transmute::< Option ()>, Option ()>, >(Some(::core::mem::transmute::< unsafe extern \"C\" fn() -> (), unsafe extern \"C\" fn() -> (), >(example))), 4, ); return 0; } }" }, { "index": 67, "before": "void repeat(void (*f)(void), unsigned int n) { while (n-->0) (*f)(); //or just f() }", "after": "pub extern \"C\" fn repeat(mut f: Option ()>, mut n: u32) { unsafe { loop { let fresh0 = n; n = n.wrapping_sub(1); if !(fresh0 > 0) { break; }; (Some(f.expect(\"non-null function pointer\"))).expect(\"non-null function pointer\")(); } } }" }, { "index": 68, "before": "int vc_cmp(const void *a, const void *b) { \treturn ((const vcount*)b)->c - ((const vcount*)a)->c; }", "after": "pub extern \"C\" fn vc_cmp(mut a: *const libc::c_void, mut b: *const libc::c_void) -> i32 { unsafe { return (*(b as *const vcount)).c - (*(a as *const vcount)).c; } }" }, { "index": 69, "before": "int cmp_dbl(const void *a, const void *b) { \tdouble x = *(const double*)a - *(const double*)b; \treturn x < 0 ? -1 : x > 0; }", "after": "pub extern \"C\" fn cmp_dbl(mut a: *const libc::c_void, mut b: *const libc::c_void) -> i32 { unsafe { let mut x: f64 = *(a as *const f64) - *(b as *const f64); return if x < 0 as f64 { -1 } else { (x > 0 as f64) as i32 }; } }" }, { "index": 70, "before": "int get_mode(double* x, int len, vcount **list) { \tint i, j; \tvcount *vc; \t/* sort values */ \tqsort(x, len, sizeof(double), cmp_dbl); \t/* count occurence of each value */ \tfor (i = 0, j = 1; i < len - 1; i++, j += (x[i] != x[i + 1])); \t*list = vc = malloc(sizeof(vcount) * j); \tvc[0].v = x[0]; \tvc[0].c = 1; \t/* generate list value-count pairs */ \tfor (i = j = 0; i < len - 1; i++, vc[j].c++) \t\tif (x[i] != x[i + 1]) vc[++j].v = x[i + 1]; \t/* sort that by count in descending order */ \tqsort(vc, j + 1, sizeof(vcount), vc_cmp); \t/* the number of entries with same count as the highest */ \tfor (i = 0; i <= j && vc[i].c == vc[0].c; i++); \treturn i; }", "after": "pub extern \"C\" fn get_mode(mut x: *mut f64, mut len_0: i32, mut list: *mut *mut vcount) -> i32 { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut vc: *mut vcount = 0 as *mut vcount; qsort( x as *mut libc::c_void, len_0 as u64, ::core::mem::size_of::() as u64, Some(cmp_dbl as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32), ); i = 0; j = 1; while i < len_0 - 1 { i += 1; i; j += (*x.offset(i as isize) != *x.offset((i + 1i32) as isize)) as i32; } vc = malloc((::core::mem::size_of::() as u64).wrapping_mul(j as u64)) as *mut vcount; *list = vc; (*vc.offset(0 as isize)).v = *x.offset(0 as isize); (*vc.offset(0 as isize)).c = 1; j = 0; i = j; while i < len_0 - 1 { if *x.offset(i as isize) != *x.offset((i + 1i32) as isize) { j += 1; (*vc.offset(j as isize)).v = *x.offset((i + 1i32) as isize); } i += 1; i; let ref mut fresh0 = (*vc.offset(j as isize)).c; *fresh0 += 1; *fresh0; } qsort( vc as *mut libc::c_void, (j + 1i32) as u64, ::core::mem::size_of::() as u64, Some(vc_cmp as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32), ); i = 0; while i <= j && (*vc.offset(i as isize)).c == (*vc.offset(0 as isize)).c { i += 1; i; } return i; } }" }, { "index": 71, "before": "int main() { \tdouble values[] = { 1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 12, 12, 17 }; #\tdefine len sizeof(values)/sizeof(double) \tvcount *vc; \tint i, n_modes = get_mode(values, len, &vc); \tprintf(\"got %d modes:\\n\", n_modes); \tfor (i = 0; i < n_modes; i++) \t\tprintf(\"\\tvalue = %g, count = %d\\n\", vc[i].v, vc[i].c); \tfree(vc); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut values: [f64; 13] = [ 1 as f64, 3 as f64, 6 as f64, 6 as f64, 6 as f64, 6 as f64, 7 as f64, 7 as f64, 12 as f64, 12 as f64, 12 as f64, 12 as f64, 17 as f64, ]; let mut vc: *mut vcount = 0 as *mut vcount; let mut i: i32 = 0; let mut n_modes: i32 = get_mode( values.as_mut_ptr(), (::core::mem::size_of::<[f64; 13]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, &mut vc, ); print!(\"got {} modes:\\n\", n_modes); i = 0; while i < n_modes { print!( \"\tvalue = {}, count = {}\\n\", (*vc.offset(i as isize)).v, (*vc.offset(i as isize)).c ); i += 1; i; } free(vc as *mut libc::c_void); return 0; } }" }, { "index": 72, "before": "int main() { \tprintf(\"Pi is %f\\n\", pi(3e-4)); /* set to 1e-4 for some fun */ \treturn 0; }", "after": "fn main() -> i32 { print!(\"Pi is {}\\n\", pi(3e-4f64)); return 0; }" }, { "index": 73, "before": "double pi(double tolerance) { \tdouble x, y, val, error; \tunsigned long sampled = 0, hit = 0, i; \tdo { \t\t/* don't check error every turn, make loop tight */ \t\tfor (i = 1000000; i; i--, sampled++) { \t\t\tx = rand() / (RAND_MAX + 1.0); \t\t\ty = rand() / (RAND_MAX + 1.0); \t\t\tif (x * x + y * y < 1) hit ++; \t\t} \t\tval = (double) hit / sampled; \t\terror = sqrt(val * (1 - val) / sampled) * 4; \t\tval *= 4; \t\t/* some feedback, or user gets bored */ \t\tfprintf(stderr, \"Pi = %f +/- %5.3e at %ldM samples.\\r\", \t\t\tval, error, sampled/1000000); \t} while (!hit || error > tolerance); /* !hit is for completeness's sake; if no hit after 1M samples, your rand() is BROKEN */ \treturn val; }", "after": "pub extern \"C\" fn pi(mut tolerance: f64) -> f64 { let mut x: f64 = 0.; let mut y: f64 = 0.; let mut val: f64 = 0.; let mut error: f64 = 0.; let mut sampled: u64 = 0; let mut hit: u64 = 0; let mut i: u64 = 0; unsafe { loop { i = 1000000; while i != 0 { x = rand() as f64 / (2147483647 as f64 + 1.0f64); y = rand() as f64 / (2147483647 as f64 + 1.0f64); if x * x + y * y < 1 as f64 { hit = hit.wrapping_add(1); hit; } i = i.wrapping_sub(1); i; sampled = sampled.wrapping_add(1); sampled; } val = hit as f64 / sampled as f64; error = sqrt(val * (1 as f64 - val) / sampled as f64) * 4 as f64; val *= 4 as f64; fprintf( stderr, b\"Pi = %f +/- %5.3e at %ldM samples.\\r\\0\" as *const u8 as *const i8, val, error, sampled.wrapping_div(1000000), ); if !(hit == 0 || error > tolerance) { break; } } } return val; }" }, { "index": 74, "before": "sma_result_t sma(enum Action action, ...) { va_list vl; sma_result_t r; sma_obj_t *o; double v; va_start(vl, action); switch(action) { case SMA_NEW: // args: int period r.handle = malloc(sizeof(sma_obj_t)); r.handle->sma = 0.0; r.handle->period = va_arg(vl, int); r.handle->values = malloc(r.handle->period * sizeof(double)); r.handle->lv = 0; r.handle->sum = 0.0; break; case SMA_FREE: // args: sma_obj_t *handle r.handle = va_arg(vl, sma_obj_t *); free(r.handle->values); free(r.handle); r.handle = NULL; break; case SMA_VALUES: // args: sma_obj_t *handle o = va_arg(vl, sma_obj_t *); r.values = o->values; break; case SMA_MEAN: // args: sma_obj_t *handle o = va_arg(vl, sma_obj_t *); r.sma = o->sma; break; case SMA_ADD: // args: sma_obj_t *handle, double value o = va_arg(vl, sma_obj_t *); v = va_arg(vl, double); if ( o->lv < o->period ) { o->values[o->lv++] = v; o->sum += v; o->sma = o->sum / o->lv; } else { o->sum -= o->values[ o->lv % o->period]; o->sum += v; o->sma = o->sum / o->period; o->values[ o->lv % o->period ] = v; o->lv++; } r.sma = o->sma; break; } va_end(vl); return r; }", "after": "pub unsafe extern \"C\" fn sma(mut action: u32, mut args: ...) -> sma_result_t { let mut vl: ::core::ffi::VaListImpl; let mut r: sma_result_t = sma_result { handle: 0 as *mut sma_obj_t, }; let mut o: *mut sma_obj_t = 0 as *mut sma_obj_t; let mut v_0: f64 = 0.; vl = args.clone(); match action as u32 { 0 => { r.handle = malloc(::core::mem::size_of::() as u64) as *mut sma_obj_t; (*r.handle).sma = 0.0f64; (*r.handle).period = vl.arg::(); (*r.handle).values = malloc( ((*r.handle).period as u64).wrapping_mul(::core::mem::size_of::() as u64), ) as *mut f64; (*r.handle).lv = 0; (*r.handle).sum = 0.0f64; } 1 => { r.handle = vl.arg::<*mut sma_obj_t>(); free((*r.handle).values as *mut libc::c_void); free(r.handle as *mut libc::c_void); r.handle = 0 as *mut sma_obj_t; } 2 => { o = vl.arg::<*mut sma_obj_t>(); r.values = (*o).values; } 4 => { o = vl.arg::<*mut sma_obj_t>(); r.sma = (*o).sma; } 3 => { o = vl.arg::<*mut sma_obj_t>(); v_0 = vl.arg::(); if (*o).lv < (*o).period { let fresh0 = (*o).lv; (*o).lv = (*o).lv + 1; *((*o).values).offset(fresh0 as isize) = v_0; (*o).sum += v_0; (*o).sma = (*o).sum / (*o).lv as f64; } else { (*o).sum -= *((*o).values).offset(((*o).lv % (*o).period) as isize); (*o).sum += v_0; (*o).sma = (*o).sum / (*o).period as f64; *((*o).values).offset(((*o).lv % (*o).period) as isize) = v_0; (*o).lv += 1; (*o).lv; } r.sma = (*o).sma; } _ => {} } return r; }" }, { "index": 75, "before": "int main() { int i; sma_obj_t *h3 = sma(SMA_NEW, 3).handle; sma_obj_t *h5 = sma(SMA_NEW, 5).handle; for(i=0; i < sizeof(v)/sizeof(double) ; i++) { printf(\"next number %lf, SMA_3 = %lf, SMA_5 = %lf\\n\", \t v[i], sma(SMA_ADD, h3, v[i]).sma, sma(SMA_ADD, h5, v[i]).sma); } sma(SMA_FREE, h3); sma(SMA_FREE, h5); return 0; }", "after": "fn main() -> i32 { unsafe { let mut i: i32 = 0; let mut h3: *mut sma_obj_t = (sma(SMA_NEW, 3)).handle; let mut h5: *mut sma_obj_t = (sma(SMA_NEW, 5)).handle; i = 0; while (i as u64) < (::core::mem::size_of::<[f64; 10]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) { print!( \"next number {}, SMA_3 = {}, SMA_5 = {}\\n\", v[i as usize], (sma(SMA_ADD, h3, v[i as usize])).sma, (sma(SMA_ADD, h5, v[i as usize])).sma ); i += 1; i; } sma(SMA_FREE, h3); sma(SMA_FREE, h5); return 0; } }" }, { "index": 76, "before": "double mapRange(double a1,double a2,double b1,double b2,double s) { \treturn b1 + (s-a1)*(b2-b1)/(a2-a1); }", "after": "pub extern \"C\" fn mapRange(mut a1: f64, mut a2: f64, mut b1: f64, mut b2: f64, mut s: f64) -> f64 { return b1 + (s - a1) * (b2 - b1) / (a2 - a1); }" }, { "index": 77, "before": "int main() { \tint i; \tputs(\"Mapping [0,10] to [-1,0] at intervals of 1:\"); \tfor(i=0;i<=10;i++) \t{ \t\tprintf(\"f(%d) = %g\\n\",i,mapRange(0,10,-1,0,i)); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; unsafe { puts(b\"Mapping [0,10] to [-1,0] at intervals of 1:\\0\" as *const u8 as *const i8); } i = 0; while i <= 10 { print!( \"f({}) = {}\\n\", i, mapRange(0 as f64, 10 as f64, -1i32 as f64, 0 as f64, i as f64) ); i += 1; i; } return 0; }" }, { "index": 78, "before": "int do_tick(int d) { game.have_moved = 0; do_gravity(d); do_merge(d); do_gravity(d); return game.have_moved; }", "after": "pub extern \"C\" fn do_tick(mut d: i32) -> i32 { unsafe { game.have_moved = 0; } do_gravity(d); do_merge(d); do_gravity(d); unsafe { return game.have_moved; } }" }, { "index": 79, "before": "void do_newblock(void) { if (game.blocks_in_play >= 16) return; int bn = rand() % (16 - game.blocks_in_play); int pn = 0; for (int x = 0; x < 4; ++x) { for (int y = 0; y < 4; ++y) { if (game.grid[x][y]) continue; if (pn == bn){ game.grid[x][y] = rand() % 10 ? 1 : 2; game.blocks_in_play += 1; return; } else { ++pn; } } } }", "after": "pub extern \"C\" fn do_newblock() { unsafe { if game.blocks_in_play >= 16 { return; } let mut bn: i32 = rand() % (16 - game.blocks_in_play); let mut pn: i32 = 0; let mut x: i32 = 0; while x < 4 { let mut y: i32 = 0; while y < 4 { if !(game.grid[x as usize][y as usize] != 0) { if pn == bn { game.grid[x as usize][y as usize] = if rand() % 10 != 0 { 1 } else { 2 }; game.blocks_in_play += 1; return; } else { pn += 1; pn; } } y += 1; y; } x += 1; x; } } }" }, { "index": 80, "before": "void do_gravity(int d) { #define GRAVITATE_DIRECTION(_v1, _v2, _xs, _xc, _xi, _ys, _yc, _yi, _x, _y) \\ do { \\ int break_cond = 0; \\ while (!break_cond) { \\ break_cond = 1; \\ for (int _v1 = _xs; _v1 _xc; _v1 += _xi) { \\ for (int _v2 = _ys; _v2 _yc; _v2 += _yi) { \\ if (!game.grid[x][y] && game.grid[x + _x][y + _y]) { \\ game.grid[x][y] = game.grid[x + _x][y + _y]; \\ game.grid[x + _x][y + _y] = break_cond = 0; \\ game.have_moved = 1; \\ } \\ } \\ } \\ do_draw(); usleep(40000); \\ } \\ } while (0) switch (d) { case D_LEFT: GRAVITATE_DIRECTION(x, y, 0, < 3, 1, 0, < 4, 1, 1, 0); break; case D_RIGHT: GRAVITATE_DIRECTION(x, y, 3, > 0, -1, 0, < 4, 1, -1, 0); break; case D_DOWN: GRAVITATE_DIRECTION(y, x, 3, > 0, -1, 0, < 4, 1, 0, -1); break; case D_UP: GRAVITATE_DIRECTION(y, x, 0, < 3, 1, 0, < 4, 1, 0, 1); break; } #undef GRAVITATE_DIRECTION }", "after": "pub extern \"C\" fn do_gravity(mut d: i32) { unsafe { match d { 4 => { let mut break_cond: i32 = 0; while break_cond == 0 { break_cond = 1; let mut x: i32 = 0; while x < 3 { let mut y: i32 = 0; while y < 4 { if game.grid[x as usize][y as usize] == 0 && game.grid[(x + 1i32) as usize][(y + 0i32) as usize] != 0 { game.grid[x as usize][y as usize] = game.grid[(x + 1i32) as usize][(y + 0i32) as usize]; break_cond = 0; game.grid[(x + 1i32) as usize][(y + 0i32) as usize] = break_cond; game.have_moved = 1; } y += 1; } x += 1; } do_draw(); usleep(40000); } } 3 => { let mut break_cond_0: i32 = 0; while break_cond_0 == 0 { break_cond_0 = 1; let mut x_0: i32 = 3; while x_0 > 0 { let mut y_0: i32 = 0; while y_0 < 4 { if game.grid[x_0 as usize][y_0 as usize] == 0 && game.grid[(x_0 + -1i32) as usize][(y_0 + 0i32) as usize] != 0 { game.grid[x_0 as usize][y_0 as usize] = game.grid[(x_0 + -1i32) as usize][(y_0 + 0i32) as usize]; break_cond_0 = 0; game.grid[(x_0 + -1i32) as usize][(y_0 + 0i32) as usize] = break_cond_0; game.have_moved = 1; } y_0 += 1; } x_0 += -1; } do_draw(); usleep(40000); } } 2 => { let mut break_cond_1: i32 = 0; while break_cond_1 == 0 { break_cond_1 = 1; let mut y_1: i32 = 3; while y_1 > 0 { let mut x_1: i32 = 0; while x_1 < 4 { if game.grid[x_1 as usize][y_1 as usize] == 0 && game.grid[(x_1 + 0i32) as usize][(y_1 + -1i32) as usize] != 0 { game.grid[x_1 as usize][y_1 as usize] = game.grid[(x_1 + 0i32) as usize][(y_1 + -1i32) as usize]; break_cond_1 = 0; game.grid[(x_1 + 0i32) as usize][(y_1 + -1i32) as usize] = break_cond_1; game.have_moved = 1; } x_1 += 1; } y_1 += -1; } do_draw(); usleep(40000); } } 1 => { let mut break_cond_2: i32 = 0; while break_cond_2 == 0 { break_cond_2 = 1; let mut y_2: i32 = 0; while y_2 < 3 { let mut x_2: i32 = 0; while x_2 < 4 { if game.grid[x_2 as usize][y_2 as usize] == 0 && game.grid[(x_2 + 0i32) as usize][(y_2 + 1i32) as usize] != 0 { game.grid[x_2 as usize][y_2 as usize] = game.grid[(x_2 + 0i32) as usize][(y_2 + 1i32) as usize]; break_cond_2 = 0; game.grid[(x_2 + 0i32) as usize][(y_2 + 1i32) as usize] = break_cond_2; game.have_moved = 1; } x_2 += 1; } y_2 += 1; } do_draw(); usleep(40000); } } _ => {} }; } }" }, { "index": 81, "before": "void do_merge(int d) { /* These macros look pretty scary, but mainly demonstrate some space saving */ #define MERGE_DIRECTION(_v1, _v2, _xs, _xc, _xi, _ys, _yc, _yi, _x, _y) \\ do { \\ for (int _v1 = _xs; _v1 _xc; _v1 += _xi) { \\ for (int _v2 = _ys; _v2 _yc; _v2 += _yi) { \\ if (game.grid[x][y] && (game.grid[x][y] == \\ game.grid[x + _x][y + _y])) { \\ game.grid[x][y] += (game.have_moved = 1); \\ game.grid[x + _x][y + _y] = (0 * game.blocks_in_play--);\\ game.score_last_move += values[game.grid[x][y]]; \\ game.total_score += values[game.grid[x][y]]; \\ } \\ } \\ } \\ } while (0) game.score_last_move = 0; switch (d) { case D_LEFT: MERGE_DIRECTION(x, y, 0, < 3, 1, 0, < 4, 1, 1, 0); break; case D_RIGHT: MERGE_DIRECTION(x, y, 3, > 0, -1, 0, < 4, 1, -1, 0); break; case D_DOWN: MERGE_DIRECTION(y, x, 3, > 0, -1, 0, < 4, 1, 0, -1); break; case D_UP: MERGE_DIRECTION(y, x, 0, < 3, 1, 0, < 4, 1, 0, 1); break; } #undef MERGE_DIRECTION }", "after": "pub extern \"C\" fn do_merge(mut d: i32) { unsafe { game.score_last_move = 0; match d { 4 => { let mut x: i32 = 0; while x < 3 { let mut y: i32 = 0; while y < 4 { if game.grid[x as usize][y as usize] != 0 && game.grid[x as usize][y as usize] == game.grid[(x + 1i32) as usize][(y + 0i32) as usize] { game.have_moved = 1; game.grid[x as usize][y as usize] += game.have_moved; let fresh0 = game.blocks_in_play; game.blocks_in_play = game.blocks_in_play - 1; game.grid[(x + 1i32) as usize][(y + 0i32) as usize] = 0 * fresh0; game.score_last_move += values[game.grid[x as usize][y as usize] as usize]; game.total_score += values[game.grid[x as usize][y as usize] as usize]; } y += 1; } x += 1; } } 3 => { let mut x_0: i32 = 3; while x_0 > 0 { let mut y_0: i32 = 0; while y_0 < 4 { if game.grid[x_0 as usize][y_0 as usize] != 0 && game.grid[x_0 as usize][y_0 as usize] == game.grid[(x_0 + -1i32) as usize][(y_0 + 0i32) as usize] { game.have_moved = 1; game.grid[x_0 as usize][y_0 as usize] += game.have_moved; let fresh1 = game.blocks_in_play; game.blocks_in_play = game.blocks_in_play - 1; game.grid[(x_0 + -1i32) as usize][(y_0 + 0i32) as usize] = 0 * fresh1; game.score_last_move += values[game.grid[x_0 as usize][y_0 as usize] as usize]; game.total_score += values[game.grid[x_0 as usize][y_0 as usize] as usize]; } y_0 += 1; } x_0 += -1; } } 2 => { let mut y_1: i32 = 3; while y_1 > 0 { let mut x_1: i32 = 0; while x_1 < 4 { if game.grid[x_1 as usize][y_1 as usize] != 0 && game.grid[x_1 as usize][y_1 as usize] == game.grid[(x_1 + 0i32) as usize][(y_1 + -1i32) as usize] { game.have_moved = 1; game.grid[x_1 as usize][y_1 as usize] += game.have_moved; let fresh2 = game.blocks_in_play; game.blocks_in_play = game.blocks_in_play - 1; game.grid[(x_1 + 0i32) as usize][(y_1 + -1i32) as usize] = 0 * fresh2; game.score_last_move += values[game.grid[x_1 as usize][y_1 as usize] as usize]; game.total_score += values[game.grid[x_1 as usize][y_1 as usize] as usize]; } x_1 += 1; } y_1 += -1; } } 1 => { let mut y_2: i32 = 0; while y_2 < 3 { let mut x_2: i32 = 0; while x_2 < 4 { if game.grid[x_2 as usize][y_2 as usize] != 0 && game.grid[x_2 as usize][y_2 as usize] == game.grid[(x_2 + 0i32) as usize][(y_2 + 1i32) as usize] { game.have_moved = 1; game.grid[x_2 as usize][y_2 as usize] += game.have_moved; let fresh3 = game.blocks_in_play; game.blocks_in_play = game.blocks_in_play - 1; game.grid[(x_2 + 0i32) as usize][(y_2 + 1i32) as usize] = 0 * fresh3; game.score_last_move += values[game.grid[x_2 as usize][y_2 as usize] as usize]; game.total_score += values[game.grid[x_2 as usize][y_2 as usize] as usize]; } x_2 += 1; } y_2 += 1; } } _ => {} }; } }" }, { "index": 82, "before": "int main(void) { /* Initialize terminal settings */ tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); srand(time(NULL)); memset(&game, 0, sizeof(game)); do_newblock(); do_newblock(); do_draw(); while (1) { int found_valid_key, direction, value; do { found_valid_key = 1; direction = D_INVALID; value = getchar(); switch (value) { case 'h': case 'a': direction = D_LEFT; break; case 'l': case 'd': direction = D_RIGHT; break; case 'j': case 's': direction = D_DOWN; break; case 'k': case 'w': direction = D_UP; break; case 'q': goto game_quit; break; case 27: if (getchar() == 91) { value = getchar(); switch (value) { case 65: direction = D_UP; break; case 66: direction = D_DOWN; break; case 67: direction = D_RIGHT; break; case 68: direction = D_LEFT; break; default: found_valid_key = 0; break; } } break; default: found_valid_key = 0; break; } } while (!found_valid_key); do_tick(direction); if (game.have_moved != 0){ do_newblock(); } do_draw(); switch (do_check_end_condition()) { case -1: goto game_lose; case 1: goto game_win; case 0: break; } } if (0) game_lose: printf(\"You lose!\\n\"); goto game_quit; if (0) game_win: printf(\"You win!\\n\"); goto game_quit; if (0) game_quit: /* Restore terminal settings */ tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return 0; }", "after": "fn main() -> i32 { let mut current_block: u64; unsafe { tcgetattr(0, &mut oldt); newt = oldt; newt.c_lflag &= !(0o2 | 0o10i32) as u32; tcsetattr(0, 0, &mut newt); srand(rust_time(None) as u32); memset( &mut game as *mut gamestate_struct__ as *mut libc::c_void, 0, ::core::mem::size_of::() as u64, ); } do_newblock(); do_newblock(); do_draw(); unsafe { 's_31: loop { let mut found_valid_key: i32 = 0; let mut direction: i32 = 0; let mut value: i32 = 0; loop { found_valid_key = 1; direction = -1; value = rust_getchar() as i32; match value { 104 | 97 => { direction = 4; } 108 | 100 => { direction = 3; } 106 | 115 => { direction = 2; } 107 | 119 => { direction = 1; } 113 => { current_block = 1947375109854664918; break 's_31; } 27 => { if rust_getchar() as i32 == 91 { value = rust_getchar() as i32; match value { 65 => { direction = 1; } 66 => { direction = 2; } 67 => { direction = 3; } 68 => { direction = 4; } _ => { found_valid_key = 0; } } } } _ => { found_valid_key = 0; } } if !(found_valid_key == 0) { break; } } do_tick(direction); if game.have_moved != 0 { do_newblock(); } do_draw(); match do_check_end_condition() { -1 => { current_block = 267910298023665031; break; } 1 => { current_block = 340875295666714687; break; } 0 | _ => {} } } } match current_block { 267910298023665031 => { print!(\"You lose!\\n\"); } 340875295666714687 => { print!(\"You win!\\n\"); } _ => {} } unsafe { tcsetattr(0, 0, &mut oldt); } return 0; }" }, { "index": 83, "before": "int do_check_end_condition(void) { int ret = -1; for (int x = 0; x < 4; ++x) { for (int y = 0; y < 4; ++y) { if (values[game.grid[x][y]] == 2048) return 1; if (!game.grid[x][y] || ((x + 1 < 4) && (game.grid[x][y] == game.grid[x + 1][y])) || ((y + 1 < 4) && (game.grid[x][y] == game.grid[x][y + 1]))) ret = 0; } } return ret; }", "after": "pub extern \"C\" fn do_check_end_condition() -> i32 { let mut ret: i32 = -1; let mut x: i32 = 0; unsafe { while x < 4 { let mut y: i32 = 0; while y < 4 { if values[game.grid[x as usize][y as usize] as usize] == 2048 { return 1; } if game.grid[x as usize][y as usize] == 0 || (x + 1) < 4 && game.grid[x as usize][y as usize] == game.grid[(x + 1i32) as usize][y as usize] || (y + 1) < 4 && game.grid[x as usize][y as usize] == game.grid[x as usize][(y + 1i32) as usize] { ret = 0; } y += 1; y; } x += 1; x; } } return ret; }" }, { "index": 84, "before": "void do_draw(void) { printf(\"\\033[2J\\033[HScore: %ld\", game.total_score); if (game.score_last_move) printf(\" (+%ld)\", game.score_last_move); printf(\"\\n\"); for (int i = 0; i < 25; ++i) printf(\"-\"); printf(\"\\n\"); for (int y = 0; y < 4; ++y) { printf(\"|\"); for (int x = 0; x < 4; ++x) { if (game.grid[x][y]) printf(\"\\033[7m\\033[%sm%*zd \\033[0m|\", colors[game.grid[x][y]], 4, values[game.grid[x][y]]); else printf(\"%*s |\", 4, \"\"); } printf(\"\\n\"); } for (int i = 0; i < 25; ++i) { printf(\"-\"); } printf(\"\\n\"); }", "after": "pub extern \"C\" fn do_draw() { unsafe { print!(\"\\x1B[2J\\x1B[HScore: {}\", game.total_score); if game.score_last_move != 0 { print!(\" (+{})\", game.score_last_move); } } print!(\"\\n\"); let mut i: i32 = 0; while i < 25 { print!(\"-\"); i += 1; i; } print!(\"\\n\"); let mut y: i32 = 0; unsafe { while y < 4 { print!(\"|\"); let mut x: i32 = 0; while x < 4 { if game.grid[x as usize][y as usize] != 0 { print!( \"\\x1B[7m\\x1B[{0:}m{2:1$} \\x1B[0m|\", build_str_from_raw_ptr( colors[game.grid[x as usize][y as usize] as usize] as *mut u8 ), 4, values[game.grid[x as usize][y as usize] as usize] ); } else { print!(\"{1:0$} |\", 4, \"\\0\"); } x += 1; x; } print!(\"\\n\"); y += 1; y; } } let mut i_0: i32 = 0; while i_0 < 25 { print!(\"-\"); i_0 += 1; i_0; } print!(\"\\n\"); }" }, { "index": 85, "before": "int ord(char v) { return v-'0'; }", "after": "pub extern \"C\" fn ord(mut v: i8) -> i32 { return v as i32 - '0' as i32; }" }, { "index": 86, "before": "void printTable( Table tbl, FILE *fout, const char *colFmts[]) { int row, col; for (row=0; rown_rows; row++) { fprintf(fout, \" \"); for(col=0; coln_cols; col++) { fprintf(fout, colFmts[col], tbl->rows[row][col]); } fprintf(fout, \"\\n\"); } fprintf(fout, \"\\n\"); }", "after": "pub extern \"C\" fn printTable(mut tbl: Table, mut fout: *mut FILE, mut colFmts: *mut *const i8) { unsafe { let mut row: i32 = 0; let mut col: i32 = 0; row = 0; while row < (*tbl).n_rows { fprintf(fout, b\" \\0\" as *const u8 as *const i8); col = 0; while col < (*tbl).n_cols { fprintf( fout, *colFmts.offset(col as isize), *(*((*tbl).rows).offset(row as isize)).offset(col as isize), ); col += 1; col; } fprintf(fout, b\"\\n\\0\" as *const u8 as *const i8); row += 1; row; } fprintf(fout, b\"\\n\\0\" as *const u8 as *const i8); } }" }, { "index": 87, "before": "int CmprRows( const void *aa, const void *bb) { String *rA = *(String *const *)aa; String *rB = *(String *const *)bb; int sortCol = sortSpec.column; String left = sortSpec.reversed ? rB[sortCol] : rA[sortCol]; String right = sortSpec.reversed ? rA[sortCol] : rB[sortCol]; return sortSpec.compare( left, right ); }", "after": "pub extern \"C\" fn CmprRows(mut aa: *const libc::c_void, mut bb: *const libc::c_void) -> i32 { unsafe { let mut rA: *mut String_0 = *(aa as *const *mut String_0); let mut rB: *mut String_0 = *(bb as *const *mut String_0); let mut sortCol: i32 = sortSpec.column; let mut left: String_0 = if sortSpec.reversed != 0 { *rB.offset(sortCol as isize) } else { *rA.offset(sortCol as isize) }; let mut right: String_0 = if sortSpec.reversed != 0 { *rA.offset(sortCol as isize) } else { *rB.offset(sortCol as isize) }; return (sortSpec.compare).expect(\"non-null function pointer\")(left, right); } }" }, { "index": 88, "before": "int sortTable(Table tbl, const char* argSpec,... ) { va_list vl; const char *p; int c; sortSpec.compare = &strcmp; sortSpec.column = 0; sortSpec.reversed = 0; va_start(vl, argSpec); if (argSpec) for (p=argSpec; *p; p++) { switch (*p) { case 'o': sortSpec.compare = va_arg(vl,CompareFctn); break; case 'c': c = va_arg(vl,int); if ( 0<=c && cn_cols) sortSpec.column = c; break; case 'r': sortSpec.reversed = (0!=va_arg(vl,int)); break; } } va_end(vl); qsort( tbl->rows, tbl->n_rows, sizeof(String *), CmprRows); return 0; }", "after": "pub unsafe extern \"C\" fn sortTable(mut tbl: Table, mut argSpec: *const i8, mut args: ...) -> i32 { let mut vl: ::core::ffi::VaListImpl; let mut p: *const i8 = 0 as *const i8; let mut c: i32 = 0; sortSpec.compare = Some(strcmp as unsafe extern \"C\" fn(*const i8, *const i8) -> i32); sortSpec.column = 0; sortSpec.reversed = 0; vl = args.clone(); if !argSpec.is_null() { p = argSpec; while *p != 0 { match *p as i32 { 111 => { sortSpec.compare = ::core::mem::transmute(vl.arg::<*mut unsafe extern \"C\" fn( String_0, String_0, ) -> i32>()); } 99 => { c = vl.arg::(); if 0 <= c && c < (*tbl).n_cols { sortSpec.column = c; } } 114 => { sortSpec.reversed = (0 != vl.arg::()) as i32; } _ => {} } p = p.offset(1); p; } } qsort( (*tbl).rows as *mut libc::c_void, (*tbl).n_rows as u64, ::core::mem::size_of::<*mut String_0>() as u64, Some(CmprRows as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32), ); return 0; }" }, { "index": 89, "before": "int cmprStrgs(String s1, String s2) { const char *p1 = s1; const char *p2 = s2; const char *mrk1, *mrk2; while ((tolower(*p1) == tolower(*p2)) && *p1) { p1++; p2++; } if (isdigit(*p1) && isdigit(*p2)) { long v1, v2; if ((*p1 == '0') ||(*p2 == '0')) { while (p1 > s1) { p1--; p2--; if (*p1 != '0') break; } if (!isdigit(*p1)) { p1++; p2++; } } mrk1 = p1; mrk2 = p2; v1 = 0; while(isdigit(*p1)) { v1 = 10*v1+ord(*p1); p1++; } v2 = 0; while(isdigit(*p2)) { v2 = 10*v2+ord(*p2); p2++; } if (v1 == v2) return(p2-mrk2)-(p1-mrk1); return v1 - v2; } if (tolower(*p1) != tolower(*p2)) return (tolower(*p1) - tolower(*p2)); for(p1=s1, p2=s2; (*p1 == *p2) && *p1; p1++, p2++); return (*p1 -*p2); }", "after": "pub extern \"C\" fn cmprStrgs(mut s1: String_0, mut s2: String_0) -> i32 { unsafe { let mut p1: *const i8 = s1; let mut p2: *const i8 = s2; let mut mrk1: *const i8 = 0 as *const i8; let mut mrk2: *const i8 = 0 as *const i8; while tolower(*p1 as i32) == tolower(*p2 as i32) && *p1 as i32 != 0 { p1 = p1.offset(1); p1; p2 = p2.offset(1); p2; } if *(*__ctype_b_loc()).offset(*p1 as i32 as isize) as i32 & _ISdigit as i32 != 0 && *(*__ctype_b_loc()).offset(*p2 as i32 as isize) as i32 & _ISdigit as i32 != 0 { let mut v1: i64 = 0; let mut v2: i64 = 0; if *p1 as i32 == '0' as i32 || *p2 as i32 == '0' as i32 { while p1 > s1 { p1 = p1.offset(-1); p1; p2 = p2.offset(-1); p2; if *p1 as i32 != '0' as i32 { break; } } if *(*__ctype_b_loc()).offset(*p1 as i32 as isize) as i32 & _ISdigit as i32 == 0 { p1 = p1.offset(1); p1; p2 = p2.offset(1); p2; } } mrk1 = p1; mrk2 = p2; v1 = 0; while *(*__ctype_b_loc()).offset(*p1 as i32 as isize) as i32 & _ISdigit as i32 != 0 { v1 = 10 * v1 + ord(*p1) as i64; p1 = p1.offset(1); p1; } v2 = 0; while *(*__ctype_b_loc()).offset(*p2 as i32 as isize) as i32 & _ISdigit as i32 != 0 { v2 = 10 * v2 + ord(*p2) as i64; p2 = p2.offset(1); p2; } if v1 == v2 { return (p2.offset_from(mrk2) as i64 - p1.offset_from(mrk1) as i64) as i32; } return (v1 - v2) as i32; } if tolower(*p1 as i32) != tolower(*p2 as i32) { return tolower(*p1 as i32) - tolower(*p2 as i32); } p1 = s1; p2 = s2; while *p1 as i32 == *p2 as i32 && *p1 as i32 != 0 { p1 = p1.offset(1); p1; p2 = p2.offset(1); p2; } return *p1 as i32 - *p2 as i32; } }" }, { "index": 90, "before": "int main() { const char *colFmts[] = {\" %-5.5s\",\" %-5.5s\",\" %-9.9s\"}; String r1[] = { \"a101\", \"red\", \"Java\" }; String r2[] = { \"ab40\", \"gren\", \"Smalltalk\" }; String r3[] = { \"ab9\", \"blue\", \"Fortran\" }; String r4[] = { \"ab09\", \"ylow\", \"Python\" }; String r5[] = { \"ab1a\", \"blak\", \"Factor\" }; String r6[] = { \"ab1b\", \"brwn\", \"C Sharp\" }; String r7[] = { \"Ab1b\", \"pink\", \"Ruby\" }; String r8[] = { \"ab1\", \"orng\", \"Scheme\" }; String *rows[] = { r1, r2, r3, r4, r5, r6, r7, r8 }; struct sTable table; table.rows = rows; table.n_rows = 8; table.n_cols = 3; sortTable(&table, \"\"); printf(\"sort on col 0, ascending\\n\"); printTable(&table, stdout, colFmts); sortTable(&table, \"ro\", 1, &cmprStrgs); printf(\"sort on col 0, reverse.special\\n\"); printTable(&table, stdout, colFmts); sortTable(&table, \"c\", 1); printf(\"sort on col 1, ascending\\n\"); printTable(&table, stdout, colFmts); sortTable(&table, \"cr\", 2, 1); printf(\"sort on col 2, reverse\\n\"); printTable(&table, stdout, colFmts); return 0; }", "after": "fn main() -> i32 { let mut colFmts: [*const i8; 3] = [ b\" %-5.5s\\0\" as *const u8 as *const i8, b\" %-5.5s\\0\" as *const u8 as *const i8, b\" %-9.9s\\0\" as *const u8 as *const i8, ]; let mut r1: [String_0; 3] = [ b\"a101\\0\" as *const u8 as *const i8, b\"red\\0\" as *const u8 as *const i8, b\"Java\\0\" as *const u8 as *const i8, ]; let mut r2: [String_0; 3] = [ b\"ab40\\0\" as *const u8 as *const i8, b\"gren\\0\" as *const u8 as *const i8, b\"Smalltalk\\0\" as *const u8 as *const i8, ]; let mut r3: [String_0; 3] = [ b\"ab9\\0\" as *const u8 as *const i8, b\"blue\\0\" as *const u8 as *const i8, b\"Fortran\\0\" as *const u8 as *const i8, ]; let mut r4: [String_0; 3] = [ b\"ab09\\0\" as *const u8 as *const i8, b\"ylow\\0\" as *const u8 as *const i8, b\"Python\\0\" as *const u8 as *const i8, ]; let mut r5: [String_0; 3] = [ b\"ab1a\\0\" as *const u8 as *const i8, b\"blak\\0\" as *const u8 as *const i8, b\"Factor\\0\" as *const u8 as *const i8, ]; let mut r6: [String_0; 3] = [ b\"ab1b\\0\" as *const u8 as *const i8, b\"brwn\\0\" as *const u8 as *const i8, b\"C Sharp\\0\" as *const u8 as *const i8, ]; let mut r7: [String_0; 3] = [ b\"Ab1b\\0\" as *const u8 as *const i8, b\"pink\\0\" as *const u8 as *const i8, b\"Ruby\\0\" as *const u8 as *const i8, ]; let mut r8: [String_0; 3] = [ b\"ab1\\0\" as *const u8 as *const i8, b\"orng\\0\" as *const u8 as *const i8, b\"Scheme\\0\" as *const u8 as *const i8, ]; let mut rows: [*mut String_0; 8] = [ r1.as_mut_ptr(), r2.as_mut_ptr(), r3.as_mut_ptr(), r4.as_mut_ptr(), r5.as_mut_ptr(), r6.as_mut_ptr(), r7.as_mut_ptr(), r8.as_mut_ptr(), ]; let mut table: sTable = sTable { rows: 0 as *mut *mut String_0, n_rows: 0, n_cols: 0, }; table.rows = rows.as_mut_ptr(); table.n_rows = 8; table.n_cols = 3; unsafe { sortTable(&mut table as *mut sTable, b\"\\0\" as *const u8 as *const i8); } print!(\"sort on col 0, ascending\\n\"); unsafe { printTable(&mut table, stdout, colFmts.as_mut_ptr()); sortTable( &mut table as *mut sTable, b\"ro\\0\" as *const u8 as *const i8, 1, Some(cmprStrgs as unsafe extern \"C\" fn(String_0, String_0) -> i32), ); } print!(\"sort on col 0, reverse.special\\n\"); unsafe { printTable(&mut table, stdout, colFmts.as_mut_ptr()); sortTable( &mut table as *mut sTable, b\"c\\0\" as *const u8 as *const i8, 1, ); } print!(\"sort on col 1, ascending\\n\"); unsafe { printTable(&mut table, stdout, colFmts.as_mut_ptr()); sortTable( &mut table as *mut sTable, b\"cr\\0\" as *const u8 as *const i8, 2, 1, ); } print!(\"sort on col 2, reverse\\n\"); unsafe { printTable(&mut table, stdout, colFmts.as_mut_ptr()); } return 0; }" }, { "index": 91, "before": "int main(int argc, char** argv) { const char* filename = \"sierpinski_arrowhead.svg\"; if (argc == 2) filename = argv[1]; FILE* out = fopen(filename, \"w\"); if (!out) { perror(filename); return EXIT_FAILURE; } write_sierpinski_arrowhead(out, 600, 8); fclose(out); return EXIT_SUCCESS; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut filename: *const i8 = b\"sierpinski_arrowhead.svg\\0\" as *const u8 as *const i8; if argc == 2 { filename = *argv.offset(1 as isize); } let mut out: *mut FILE = fopen(filename, b\"w\\0\" as *const u8 as *const i8); if out.is_null() { perror(filename); return 1; } write_sierpinski_arrowhead(out, 600, 8); fclose(out); return 0; } }" }, { "index": 92, "before": "void write_sierpinski_arrowhead(FILE* out, int size, int order) { const double margin = 20.0; const double side = size - 2.0 * margin; cursor_t cursor; cursor.angle = 0; cursor.x = margin; cursor.y = 0.5 * size + 0.25 * sqrt(3) * side; if ((order & 1) != 0) turn(&cursor, -60); fprintf(out, \"\\n\", size, size); fprintf(out, \"\\n\"); fprintf(out, \"\\n\\n\"); }", "after": "pub extern \"C\" fn write_sierpinski_arrowhead(mut out: *mut FILE, mut size: i32, mut order: i32) { unsafe { let margin: f64 = 20.0f64; let side: f64 = size as f64 - 2.0f64 * margin; let mut cursor: cursor_t = cursor_t { x: 0., y: 0., angle: 0, }; cursor.angle = 0; cursor.x = margin; cursor.y = 0.5f64 * size as f64 + 0.25f64 * sqrt(3 as f64) * side; if order & 1 != 0 { turn(&mut cursor, -60); } fprintf( out, b\"\\n\\0\" as *const u8 as *const i8, size, size, ); fprintf( out, b\"\\n\\0\" as *const u8 as *const i8, ); fprintf( out, b\"\\n\\n\\0\" as *const u8 as *const i8); } }" }, { "index": 93, "before": "void curve(FILE* out, int order, double length, cursor_t* cursor, int angle) { if (order == 0) { draw_line(out, cursor, length); } else { curve(out, order - 1, length/2, cursor, -angle); turn(cursor, angle); curve(out, order - 1, length/2, cursor, angle); turn(cursor, angle); curve(out, order - 1, length/2, cursor, -angle); } }", "after": "pub extern \"C\" fn curve( mut out: *mut FILE, mut order: i32, mut length: f64, mut cursor: *mut cursor_t, mut angle: i32, ) { unsafe { if order == 0 { draw_line(out, cursor, length); } else { curve(out, order - 1, length / 2 as f64, cursor, -angle); turn(cursor, angle); curve(out, order - 1, length / 2 as f64, cursor, angle); turn(cursor, angle); curve(out, order - 1, length / 2 as f64, cursor, -angle); }; } }" }, { "index": 94, "before": "void turn(cursor_t* cursor, int angle) { cursor->angle = (cursor->angle + angle) % 360; }", "after": "pub extern \"C\" fn turn(mut cursor: *mut cursor_t, mut angle: i32) { unsafe { (*cursor).angle = ((*cursor).angle + angle) % 360; } }" }, { "index": 95, "before": "void draw_line(FILE* out, cursor_t* cursor, double length) { double theta = (M_PI * cursor->angle)/180.0; cursor->x += length * cos(theta); cursor->y += length * sin(theta); fprintf(out, \"L%g,%g\\n\", cursor->x, cursor->y); }", "after": "pub extern \"C\" fn draw_line(mut out: *mut FILE, mut cursor: *mut cursor_t, mut length: f64) { unsafe { let mut theta: f64 = 3.14159265358979323846f64 * (*cursor).angle as f64 / 180.0f64; (*cursor).x += length * cos(theta); (*cursor).y += length * sin(theta); fprintf( out, b\"L%g,%g\\n\\0\" as *const u8 as *const i8, (*cursor).x, (*cursor).y, ); } }" }, { "index": 96, "before": "int main(void) { int p1; for (p1 = 2; p1 < 62; ++p1) carmichael3(p1); return 0; }", "after": "fn main() -> i32 { let mut p1: i32 = 0; p1 = 2; while p1 < 62 { carmichael3(p1); p1 += 1; p1; } return 0; }" }, { "index": 97, "before": "int is_prime(unsigned int n) { if (n <= 3) { return n > 1; } else if (!(n % 2) || !(n % 3)) { return 0; } else { unsigned int i; for (i = 5; i*i <= n; i += 6) if (!(n % i) || !(n % (i + 2))) return 0; return 1; } }", "after": "pub extern \"C\" fn is_prime(mut n: u32) -> i32 { if n <= 3 { return (n > 1) as i32; } else if n.wrapping_rem(2) == 0 || n.wrapping_rem(3) == 0 { return 0; } else { let mut i: u32 = 0; i = 5; while i.wrapping_mul(i) <= n { if n.wrapping_rem(i) == 0 || n.wrapping_rem(i.wrapping_add(2)) == 0 { return 0; } i = i.wrapping_add(6); } return 1; }; }" }, { "index": 98, "before": "void carmichael3(int p1) { if (!is_prime(p1)) return; int h3, d, p2, p3; for (h3 = 1; h3 < p1; ++h3) { for (d = 1; d < h3 + p1; ++d) { if ((h3 + p1)*(p1 - 1) % d == 0 && mod(-p1 * p1, h3) == d % h3) { p2 = 1 + ((p1 - 1) * (h3 + p1)/d); if (!is_prime(p2)) continue; p3 = 1 + (p1 * p2 / h3); if (!is_prime(p3) || (p2 * p3) % (p1 - 1) != 1) continue; printf(\"%d %d %d\\n\", p1, p2, p3); } } } }", "after": "pub extern \"C\" fn carmichael3(mut p1: i32) { if is_prime(p1 as u32) == 0 { return; } let mut h3: i32 = 0; let mut d: i32 = 0; let mut p2: i32 = 0; let mut p3: i32 = 0; h3 = 1; while h3 < p1 { d = 1; while d < h3 + p1 { if (h3 + p1) * (p1 - 1) % d == 0 && (-p1 * p1 % h3 + h3) % h3 == d % h3 { p2 = 1 + (p1 - 1) * (h3 + p1) / d; if !(is_prime(p2 as u32) == 0) { p3 = 1 + p1 * p2 / h3; if !(is_prime(p3 as u32) == 0 || p2 * p3 % (p1 - 1) != 1) { print!(\"{} {} {}\\n\", p1, p2, p3); } } } d += 1; d; } h3 += 1; h3; } }" }, { "index": 99, "before": "int myopenimage(const char *in) { static int handle=0; fprintf(stderr, \"internal openimage opens %s...\\n\", in); return handle++; }", "after": "pub extern \"C\" fn myopenimage(mut in_0: *const i8) -> i32 { unsafe { static mut handle: i32 = 0; fprintf( stderr, b\"internal openimage opens %s...\\n\\0\" as *const u8 as *const i8, in_0, ); let fresh0 = handle; handle = handle + 1; return fresh0; } }" }, { "index": 100, "before": "int main() { void *imglib; int (*extopenimage)(const char *); int imghandle; imglib = dlopen(\"./fakeimglib.so\", RTLD_LAZY); if ( imglib != NULL ) { /* extopenimage = (int (*)(const char *))dlsym(imglib,...) \"man dlopen\" says that C99 standard leaves casting from \"void *\" to a function pointer undefined. The following is the POSIX.1-2003 workaround found in man */ *(void **)(&extopenimage) = dlsym(imglib, \"openimage\"); /* the following works with gcc, gives no warning even with -Wall -std=c99 -pedantic options... :D */ /* extopenimage = dlsym(imglib, \"openimage\"); */ imghandle = extopenimage(\"fake.img\"); } else { imghandle = myopenimage(\"fake.img\"); } printf(\"opened with handle %d\\n\", imghandle); /* ... */ if (imglib != NULL ) dlclose(imglib); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { let mut imglib: *mut libc::c_void = 0 as *mut libc::c_void; let mut extopenimage: Option i32> = None; let mut imghandle: i32 = 0; imglib = dlopen(b\"./fakeimglib.so\\0\" as *const u8 as *const i8, 0x1); if !imglib.is_null() { let ref mut fresh1 = *(&mut extopenimage as *mut Option i32> as *mut *mut libc::c_void); *fresh1 = dlsym(imglib, b\"openimage\\0\" as *const u8 as *const i8); imghandle = extopenimage.expect(\"non-null function pointer\")( b\"fake.img\\0\" as *const u8 as *const i8, ); } else { imghandle = myopenimage(b\"fake.img\\0\" as *const u8 as *const i8); } print!(\"opened with handle {}\\n\", imghandle); if !imglib.is_null() { dlclose(imglib); } return 0; } }" }, { "index": 101, "before": "int main(void) { \tt(5), t(14); \t// maybe not \t// t(10000); \treturn 0; }", "after": "fn main() -> i32 { t(5); t(14); return 0; }" }, { "index": 102, "before": "void t(int n) { \tint i, j, c, len; \ti = n * (n - 1) / 2; \tfor (len = c = 1; c < i; c *= 10, len++); \tc -= i; // c is the col where width changes #define SPEED_MATTERS 0 #if SPEED_MATTERS\t// in case we really, really wanted to print huge triangles often \tchar tmp[32], s[4096], *p; \tsprintf(tmp, \"%*d\", len, 0); \tinline void inc_numstr(void) { \t\tint k = len; \tredo:\tif (!k--) return; \t\tif (tmp[k] == '9') { \t\t\ttmp[k] = '0'; \t\t\tgoto redo; \t\t} \t\tif (++tmp[k] == '!') \t\t\ttmp[k] = '1'; \t} \tfor (p = s, i = 1; i <= n; i++) { \t\tfor (j = 1; j <= i; j++) { \t\t\tinc_numstr(); \t\t\t__builtin_memcpy(p, tmp + 1 - (j >= c), len - (j < c)); \t\t\tp += len - (j < c); \t\t\t*(p++) = (i - j)? ' ' : '\\n'; \t\t\tif (p - s + len >= 4096) { \t\t\t\tfwrite(s, 1, p - s, stdout); \t\t\t\tp = s; \t\t\t} \t\t} \t} \tfwrite(s, 1, p - s, stdout); #else // NO_IT_DOESN'T \tint num; \tfor (num = i = 1; i <= n; i++) \t\tfor (j = 1; j <= i; j++) \t\t\tprintf(\"%*d%c\",\tlen - (j < c), num++, i - j ? ' ':'\\n'); #endif }", "after": "pub extern \"C\" fn t(mut n: i32) { let mut i: i32 = 0; let mut j: i32 = 0; let mut c: i32 = 0; let mut len: i32 = 0; i = n * (n - 1) / 2; c = 1; len = c; while c < i { c *= 10; len += 1; len; } c -= i; let mut num: i32 = 0; i = 1; num = i; while i <= n { j = 1; while j <= i { let fresh0 = num; num = num + 1; if i - j != 0 { print!( \"{1:0$}{2:}\", (len - (j < c) as i32).abs() as usize, fresh0, ' ' as i32 ) } else { print!( \"{1:0$}{2:}\", (len - (j < c) as i32).abs() as usize, fresh0, '\\n' as i32 ) }; j += 1; j; } i += 1; i; } }" }, { "index": 103, "before": "void fail(const char *message) { \tperror(message); \texit(1); }", "after": "pub extern \"C\" fn fail(mut message: *const i8) { unsafe { perror(message); exit(1); } }" }, { "index": 104, "before": "int main() { \tint i; \tonly_one_instance(); \t/* Play for 10 seconds. */ \tfor(i = 10; i > 0; i--) { \t\tprintf(\"%d...%s\", i, i % 5 == 1 ? \"\\n\" : \" \"); \t\tfflush(stdout); \t\tsleep(1); \t} \tputs(\"Fin!\"); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; only_one_instance(); i = 10; unsafe { while i > 0 { if i % 5 == 1 { print!(\"{}...{}\", i, \"\\n\\0\") } else { print!(\"{}...{}\", i, \" \\0\") }; fflush(stdout); sleep(1); i -= 1; i; } puts(b\"Fin!\\0\" as *const u8 as *const i8); } return 0; }" }, { "index": 105, "before": "void ooi_unlink(void) { \tunlink(ooi_path); }", "after": "pub extern \"C\" fn ooi_unlink() { unsafe { unlink(ooi_path); } }" }, { "index": 106, "before": "void only_one_instance(void) { \tstruct flock fl; \tsize_t dirlen; \tint fd; \tchar *dir; \t/* \t * Place the lock in the home directory of this user; \t * therefore we only check for other instances by the same \t * user (and the user can trick us by changing HOME). \t */ \tdir = getenv(\"HOME\"); \tif (dir == NULL || dir[0] != '/') { \t\tfputs(\"Bad home directory.\\n\", stderr); \t\texit(1); \t} \tdirlen = strlen(dir); \tooi_path = malloc(dirlen + sizeof(\"/\" INSTANCE_LOCK)); \tif (ooi_path == NULL) \t\tfail(\"malloc\"); \tmemcpy(ooi_path, dir, dirlen); \tmemcpy(ooi_path + dirlen, \"/\" INSTANCE_LOCK, \t sizeof(\"/\" INSTANCE_LOCK)); /* copies '\\0' */ \tfd = open(ooi_path, O_RDWR | O_CREAT, 0600); \tif (fd < 0) \t\tfail(ooi_path); \tfl.l_start = 0; \tfl.l_len = 0; \tfl.l_type = F_WRLCK; \tfl.l_whence = SEEK_SET; \tif (fcntl(fd, F_SETLK, &fl) < 0) { \t\tfputs(\"Another instance of this program is running.\\n\", \t\t stderr); \t\texit(1); \t} \t/* \t * Run unlink(ooi_path) when the program exits. The program \t * always releases locks when it exits. \t */ \tatexit(ooi_unlink); }", "after": "pub extern \"C\" fn only_one_instance() { unsafe { let mut fl: flock = flock { l_type: 0, l_whence: 0, l_start: 0, l_len: 0, l_pid: 0, }; let mut dirlen: u64 = 0; let mut fd: i32 = 0; let mut dir: *mut i8 = 0 as *mut i8; dir = getenv(b\"HOME\\0\" as *const u8 as *const i8); if dir.is_null() || *dir.offset(0 as isize) as i32 != '/' as i32 { fputs(b\"Bad home directory.\\n\\0\" as *const u8 as *const i8, stderr); exit(1); } dirlen = strlen(dir); ooi_path = malloc(dirlen.wrapping_add(::core::mem::size_of::<[i8; 19]>() as u64)) as *mut i8; if ooi_path.is_null() { fail(b\"malloc\\0\" as *const u8 as *const i8); } memcpy( ooi_path as *mut libc::c_void, dir as *const libc::c_void, dirlen, ); memcpy( ooi_path.offset(dirlen as isize) as *mut libc::c_void, b\"/rosetta-code-lock\\0\" as *const u8 as *const i8 as *const libc::c_void, ::core::mem::size_of::<[i8; 19]>() as u64, ); fd = open(ooi_path, 0o2 | 0o100, 0o600); if fd < 0 { fail(ooi_path); } fl.l_start = 0; fl.l_len = 0; fl.l_type = 1; fl.l_whence = 0; if fcntl(fd, 6, &mut fl as *mut flock) < 0 { fputs( b\"Another instance of this program is running.\\n\\0\" as *const u8 as *const i8, stderr, ); exit(1); } atexit(Some(ooi_unlink as unsafe extern \"C\" fn() -> ())); } }" }, { "index": 107, "before": "int _tmpl() { \tvolatile int x = TAG; \treturn x * x; }", "after": "pub extern \"C\" fn _tmpl() -> i32 { let mut x: i32 = 0xdeadbeef; return x * x; }" }, { "index": 108, "before": "f_int dupf(int v) { \tsize_t len = (void*)dupf - (void*)_tmpl; \tf_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0); \tchar *p; \tif(ret == MAP_FAILED) { \t\tperror(\"mmap\"); \t\texit(-1); \t} \tmemcpy(ret, _tmpl, len); \tfor (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++) \t\tif (*(int *)p == TAG) *(int *)p = v; \treturn ret; }", "after": "pub extern \"C\" fn dupf(mut v: i32) -> f_int { unsafe { let mut len: u64 = (::core::mem::transmute::< Option f_int>, *mut libc::c_void, >(Some(dupf as unsafe extern \"C\" fn(i32) -> f_int))) .offset_from(::core::mem::transmute::< Option i32>, *mut libc::c_void, >(Some(::core::mem::transmute::< unsafe extern \"C\" fn() -> i32, unsafe extern \"C\" fn() -> i32, >(_tmpl)))) as u64; let mut ret: f_int = ::core::mem::transmute::<*mut libc::c_void, f_int>(mmap( 0 as *mut libc::c_void, len, 0x4 | 0x2, 0x2 | 0x20, 0, 0, )); let mut p: *mut i8 = 0 as *mut i8; if ret == ::core::mem::transmute::<*mut libc::c_void, f_int>(-1i32 as *mut libc::c_void) { perror(b\"mmap\\0\" as *const u8 as *const i8); exit(-1); } memcpy( ::core::mem::transmute::(ret), ::core::mem::transmute:: i32>, *const libc::c_void>( Some(::core::mem::transmute::< unsafe extern \"C\" fn() -> i32, unsafe extern \"C\" fn() -> i32, >(_tmpl)), ), len, ); p = ::core::mem::transmute::(ret); while p < (::core::mem::transmute::(ret)) .offset(len as isize) .offset(-(::core::mem::size_of::() as u64 as isize)) { if *(p as *mut i32) as u32 == 0xdeadbeef { *(p as *mut i32) = v; } p = p.offset(1); p; } return ret; } }" }, { "index": 109, "before": "int main() { \tf_int funcs[10]; \tint i; \tfor (i = 0; i < 10; i++) funcs[i] = dupf(i); \tfor (i = 0; i < 9; i++) \t\tprintf(\"func[%d]: %d\\n\", i, funcs[i]()); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut funcs: [f_int; 10] = [None; 10]; let mut i: i32 = 0; i = 0; while i < 10 { funcs[i as usize] = dupf(i); i += 1; i; } i = 0; while i < 9 { print!( \"func[{}]: {}\\n\", i, ::core::mem::transmute::<_, fn() -> i32>( (funcs[i as usize]).expect(\"non-null function pointer\"), )() ); i += 1; i; } } return 0; }" }, { "index": 110, "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 extern \"C\" fn lcs(sa: *const i8, sb: *const i8, beg: *mut *mut i8, end: *mut *mut i8) { unsafe { let mut apos: u64 = 0; let mut bpos: u64 = 0; let mut len: i32 = 0; *beg = 0 as *mut i8; *end = 0 as *mut i8; len = 0; apos = 0; while *sa.offset(apos as isize) as i32 != 0 { bpos = 0; while *sb.offset(bpos as isize) as i32 != 0 { if *sa.offset(apos as isize) as i32 == *sb.offset(bpos as isize) as i32 { len = 1; while *sa.offset(apos.wrapping_add(len as u64) as isize) as i32 != 0 && *sb.offset(bpos.wrapping_add(len as u64) as isize) as i32 != 0 && *sa.offset(apos.wrapping_add(len as u64) as isize) as i32 == *sb.offset(bpos.wrapping_add(len as u64) as isize) as i32 { len += 1; len; } } if len as i64 > (*end).offset_from(*beg) as i64 { *beg = sa.offset(apos as isize) as *mut i8; *end = (*beg).offset(len as isize); len = 0; } bpos = bpos.wrapping_add(1); bpos; } apos = apos.wrapping_add(1); apos; } } }" }, { "index": 111, "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": "fn main() -> i32 { unsafe { let mut s1: *mut i8 = b\"thisisatest\\0\" as *const u8 as *const i8 as *mut i8; let mut s2: *mut i8 = b\"testing123testing\\0\" as *const u8 as *const i8 as *mut i8; let mut beg: *mut i8 = 0 as *mut i8; let mut end: *mut i8 = 0 as *mut i8; let mut it: *mut i8 = 0 as *mut i8; lcs(s1, s2, &mut beg, &mut end); it = beg; while it != end { print!(\"{}\", *it as i32); it = it.offset(1); it; } print!(\"\\n\"); return 0; } }" }, { "index": 112, "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": "fn main() -> i32 { let mut n: i32 = 0; let mut y: i32 = 0; let mut i: i32 = 0; let mut m: i32 = 0; let mut t: tm = { let mut init = tm { tm_sec: 0, 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 i8, }; init }; print!(\"Months with five weekends:\\n\"); y = 1900; unsafe { while y <= 2100 { i = 0; while i < 7 { m = long_months[i as usize]; t.tm_year = y - 1900; t.tm_mon = m; t.tm_mday = 1; if mktime(&mut t) == -1 as i64 { print!( \"Error: {} {}\\n\", y, build_str_from_raw_ptr(months[m as usize] as *mut u8) ); } else if t.tm_wday == 5 { print!( \" {} {}\\n\", y, build_str_from_raw_ptr(months[m as usize] as *mut u8) ); n += 1; n; } i += 1; i; } y += 1; y; } } print!(\"{} total\\n\", n); return 0; }" }, { "index": 113, "before": "int dot_product(int *a, int *b, size_t n) { int sum = 0; size_t i; for (i = 0; i < n; i++) { sum += a[i] * b[i]; } return sum; }", "after": "pub extern \"C\" fn dot_product(mut a: *mut i32, mut b: *mut i32, mut n: u64) -> i32 { unsafe { let mut sum: i32 = 0; let mut i: u64 = 0; i = 0; while i < n { sum += *a.offset(i as isize) * *b.offset(i as isize); i = i.wrapping_add(1); i; } return sum; } }" }, { "index": 114, "before": "int main(void) { int a[3] = {1, 3, -5}; int b[3] = {4, -2, -1}; printf(\"%d\\n\", dot_product(a, b, sizeof(a) / sizeof(a[0]))); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { let mut a: [i32; 3] = [1, 3, -5]; let mut b: [i32; 3] = [4, -2, -1]; print!( \"{}\\n\", dot_product( a.as_mut_ptr(), b.as_mut_ptr(), (::core::mem::size_of::<[i32; 3]>() as u64) .wrapping_div(::core::mem::size_of::() as u64), ) ); return 0; }" }, { "index": 115, "before": "void kpp(point pts, int len, point cent, int n_cent) { #define for_len for (j = 0, p = pts; j < len; j++, p++) \tint i, j; \tint n_cluster; \tdouble sum, *d = malloc(sizeof(double) * len); \tpoint p, c; \tcent[0] = pts[rand() % len]; \tfor (n_cluster = 1; n_cluster < n_cent; n_cluster++) \t{ \t\tsum = 0; \t\tfor_len \t\t{ \t\t\tnearest(p, cent, n_cluster, d + j); \t\t\tsum += d[j]; \t\t} \t\tsum = randf(sum); \t\tfor_len \t\t{ \t\t\tif ((sum -= d[j]) > 0) \t\t\t\tcontinue; \t\t\tcent[n_cluster] = pts[j]; \t\t\tbreak; \t\t} \t} \tfor_len p->group = nearest(p, cent, n_cluster, 0); \tfree(d); }", "after": "pub extern \"C\" fn kpp(mut pts: point, mut len: i32, mut cent: point, mut n_cent: i32) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut n_cluster: i32 = 0; let mut sum: f64 = 0.; let mut d: *mut f64 = malloc((::core::mem::size_of::() as u64).wrapping_mul(len as u64)) as *mut f64; let mut p: point = 0 as *mut point_t; let mut c: point = 0 as *mut point_t; *cent.offset(0 as isize) = *pts.offset((rand() % len) as isize); n_cluster = 1; while n_cluster < n_cent { sum = 0 as f64; j = 0; p = pts; while j < len { nearest(p, cent, n_cluster, d.offset(j as isize)); sum += *d.offset(j as isize); j += 1; j; p = p.offset(1); p; } sum = randf(sum); j = 0; p = pts; while j < len { sum -= *d.offset(j as isize); if sum > 0 as f64 { j += 1; j; p = p.offset(1); p; } else { *cent.offset(n_cluster as isize) = *pts.offset(j as isize); break; } } n_cluster += 1; n_cluster; } j = 0; p = pts; while j < len { (*p).group = nearest(p, cent, n_cluster, 0 as *mut f64); j += 1; j; p = p.offset(1); p; } free(d as *mut libc::c_void); } }" }, { "index": 116, "before": "void print_eps(point pts, int len, point cent, int n_cluster) { #define W 400 #define H 400 \tint i, j; \tpoint p, c; \tdouble min_x, max_x, min_y, max_y, scale, cx, cy; \tdouble *colors = malloc(sizeof(double) * n_cluster * 3); \tfor_n \t{ \t\tcolors[3 * i + 0] = (3 * (i + 1) % 11) / 11.; \t\tcolors[3 * i + 1] = (7 * i % 11) / 11.; \t\tcolors[3 * i + 2] = (9 * i % 11) / 11.; \t}", "after": "pub extern \"C\" fn print_eps(mut pts: point, mut len: i32, mut cent: point, mut n_cluster: i32) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut p: point = 0 as *mut point_t; let mut c: point = 0 as *mut point_t; let mut min_x: f64 = 0.; let mut max_x: f64 = 0.; let mut min_y: f64 = 0.; let mut max_y: f64 = 0.; let mut scale: f64 = 0.; let mut cx: f64 = 0.; let mut cy: f64 = 0.; let mut colors: *mut f64 = malloc( (::core::mem::size_of::() as u64) .wrapping_mul(n_cluster as u64) .wrapping_mul(3), ) as *mut f64; c = cent; i = 0; while i < n_cluster { *colors.offset((3 * i + 0i32) as isize) = (3 * (i + 1i32) % 11i32) as f64 / 11.0f64; *colors.offset((3 * i + 1i32) as isize) = (7 * i % 11i32) as f64 / 11.0f64; *colors.offset((3 * i + 2i32) as isize) = (9 * i % 11i32) as f64 / 11.0f64; i += 1; i; c = c.offset(1); c; } min_y = ::core::f64::INFINITY; min_x = min_y; max_y = -min_x; max_x = max_y; j = 0; p = pts; while j < len { if max_x < (*p).x { max_x = (*p).x; } if min_x > (*p).x { min_x = (*p).x; } if max_y < (*p).y { max_y = (*p).y; } if min_y > (*p).y { min_y = (*p).y; } j += 1; j; p = p.offset(1); p; } scale = 400 as f64 / (max_x - min_x); if scale > 400 as f64 / (max_y - min_y) { scale = 400 as f64 / (max_y - min_y); } cx = (max_x + min_x) / 2 as f64; cy = (max_y + min_y) / 2 as f64; print!( \"%!PS-Adobe-3.0\\n%%BoundingBox: -5 -5 {} {}\\n\", 400 + 10, 400 + 10 ); printf ( b\"/l {rlineto} def /m {rmoveto} def\\n/c { .25 sub exch .25 sub exch .5 0 360 arc fill } def\\n/s { moveto -2 0 m 2 2 l 2 -2 l -2 -2 l closepath \\tgsave 1 setgray fill grestore gsave 3 setlinewidth 1 setgray stroke grestore 0 setgray stroke }def\\n\\0\" as * const u8 as * const i8,); c = cent; i = 0; while i < n_cluster { print!( \"{} {} {} setrgbcolor\\n\", *colors.offset((3 * i) as isize), *colors.offset((3 * i + 1i32) as isize), *colors.offset((3 * i + 2i32) as isize) ); j = 0; p = pts; while j < len { if !((*p).group != i) { print!( \"{:.3} {:.3} c\\n\", ((*p).x - cx) * scale + (400 / 2i32) as f64, ((*p).y - cy) * scale + (400 / 2i32) as f64 ); } j += 1; j; p = p.offset(1); p; } print!( \"\\n0 setgray {} {} s\\n\", ((*c).x - cx) * scale + (400 / 2i32) as f64, ((*c).y - cy) * scale + (400 / 2i32) as f64 ); i += 1; i; c = c.offset(1); c; } printf(b\"\\n%%%%EOF\\0\" as *const u8 as *const i8); free(colors as *mut libc::c_void); } }" }, { "index": 117, "before": "double randf(double m) { \treturn m * rand() / (RAND_MAX - 1.); }", "after": "pub extern \"C\" fn randf(mut m: f64) -> f64 { unsafe { return m * rand() as f64 / (2147483647 as f64 - 1.0f64); } }" }, { "index": 118, "before": "point gen_xy(int count, double radius) { \tdouble ang, r; \tpoint p, pt = malloc(sizeof(point_t) * count); \t/* note: this is not a uniform 2-d distribution */ \tfor (p = pt + count; p-- > pt;) \t{ \t\tang = randf(2 * M_PI); \t\tr = randf(radius); \t\tp->x = r * cos(ang); \t\tp->y = r * sin(ang); \t} \treturn pt; }", "after": "pub extern \"C\" fn gen_xy(mut count: i32, mut radius: f64) -> point { let mut ang: f64 = 0.; let mut r: f64 = 0.; let mut p: point = 0 as *mut point_t; unsafe { let mut pt: point = malloc((::core::mem::size_of::() as u64).wrapping_mul(count as u64)) as point; p = pt.offset(count as isize); loop { let fresh0 = p; p = p.offset(-1); if !(fresh0 > pt) { break; } ang = randf(2 as f64 * 3.14159265358979323846f64); r = randf(radius); (*p).x = r * cos(ang); (*p).y = r * sin(ang); } return pt; } }" }, { "index": 119, "before": "int nearest(point pt, point cent, int n_cluster, double *d2) { \tint i, min_i; \tpoint c; \tdouble d, min_d; #define for_n for (c = cent, i = 0; i < n_cluster; i++, c++) \tfor_n \t{ \t\tmin_d = HUGE_VAL; \t\tmin_i = pt->group; \t\tfor_n \t\t{ \t\t\tif (min_d > (d = dist2(c, pt))) \t\t\t{ \t\t\t\tmin_d = d; \t\t\t\tmin_i = i; \t\t\t} \t\t} \t}", "after": "pub extern \"C\" fn nearest( mut pt: point, mut cent: point, mut n_cluster: i32, mut d2: *mut f64, ) -> i32 { unsafe { let mut i: i32 = 0; let mut min_i: i32 = 0; let mut c: point = 0 as *mut point_t; let mut d: f64 = 0.; let mut min_d: f64 = 0.; c = cent; i = 0; while i < n_cluster { min_d = ::core::f64::INFINITY; min_i = (*pt).group; c = cent; i = 0; while i < n_cluster { d = dist2(c, pt); if min_d > d { min_d = d; min_i = i; } i += 1; i; c = c.offset(1); c; } i += 1; i; c = c.offset(1); c; } if !d2.is_null() { *d2 = min_d; } return min_i; } }" }, { "index": 120, "before": "double dist2(point a, point b) { \tdouble x = a->x - b->x, y = a->y - b->y; \treturn x * x + y * y; }", "after": "pub extern \"C\" fn dist2(mut a: point, mut b: point) -> f64 { let mut x: f64 = (*a).x - (*b).x; let mut y: f64 = (*a).y - (*b).y; return x * x + y * y; }" }, { "index": 121, "before": "point lloyd(point pts, int len, int n_cluster) { \tint i, j, min_i; \tint changed; \tpoint cent = malloc(sizeof(point_t) * n_cluster), p, c; \t/* assign init grouping randomly */ \t//for_len p->group = j % n_cluster; \t/* or call k++ init */ \tkpp(pts, len, cent, n_cluster); \tdo \t{ \t\t/* group element for centroids are used as counters */ \t\tfor_n \t\t{ \t\t\tc->group = 0; \t\t\tc->x = c->y = 0; \t\t} \t\tfor_len \t\t{ \t\t\tc = cent + p->group; \t\t\tc->group++; \t\t\tc->x += p->x; \t\t\tc->y += p->y; \t\t} \t\tfor_n \t\t{ \t\t\tc->x /= c->group; \t\t\tc->y /= c->group; \t\t} \t\tchanged = 0; \t\t/* find closest centroid of each point */ \t\tfor_len \t\t{ \t\t\tmin_i = nearest(p, cent, n_cluster, 0); \t\t\tif (min_i != p->group) \t\t\t{ \t\t\t\tchanged++; \t\t\t\tp->group = min_i; \t\t\t} \t\t} \t} while (changed > (len >> 10)); /* stop when 99.9% of points are good */ \tfor_n { c->group = i; } \treturn cent; }", "after": "pub extern \"C\" fn lloyd(mut pts: point, mut len: i32, mut n_cluster: i32) -> point { let mut i: i32 = 0; let mut j: i32 = 0; let mut min_i: i32 = 0; let mut changed: i32 = 0; unsafe { let mut cent: point = malloc((::core::mem::size_of::() as u64).wrapping_mul(n_cluster as u64)) as point; let mut p: point = 0 as *mut point_t; let mut c: point = 0 as *mut point_t; kpp(pts, len, cent, n_cluster); loop { c = cent; i = 0; while i < n_cluster { (*c).group = 0; (*c).y = 0 as f64; (*c).x = (*c).y; i += 1; i; c = c.offset(1); c; } j = 0; p = pts; while j < len { c = cent.offset((*p).group as isize); (*c).group += 1; (*c).group; (*c).x += (*p).x; (*c).y += (*p).y; j += 1; j; p = p.offset(1); p; } c = cent; i = 0; while i < n_cluster { (*c).x /= (*c).group as f64; (*c).y /= (*c).group as f64; i += 1; i; c = c.offset(1); c; } changed = 0; j = 0; p = pts; while j < len { min_i = nearest(p, cent, n_cluster, 0 as *mut f64); if min_i != (*p).group { changed += 1; changed; (*p).group = min_i; } j += 1; j; p = p.offset(1); p; } if !(changed > len >> 10) { break; } } c = cent; i = 0; while i < n_cluster { (*c).group = i; i += 1; i; c = c.offset(1); c; } return cent; } }" }, { "index": 122, "before": "int main() { \tint i; \tpoint v = gen_xy(PTS, 10); \tpoint c = lloyd(v, PTS, K); \tprint_eps(v, PTS, c, K); \t// free(v); free(c); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut v: point = gen_xy(100000, 10 as f64); let mut c: point = lloyd(v, 100000, 11); print_eps(v, 100000, c, 11); return 0; }" }, { "index": 123, "before": "void acd() { for (c = lo;c <= hi; c++) for (d = lo;d <= hi; d++) if ((!unique) || (c != d)) { a = c + d; if ((a >= lo) && (a <= hi) && ((!unique) || ((c != 0) && (d != 0)))) ge(); } }", "after": "pub extern \"C\" fn acd() { unsafe { c = lo; while c <= hi { d = lo; while d <= hi { if unique == 0 || c != d { a = c + d; if a >= lo && a <= hi && (unique == 0 || c != 0 && d != 0) { ge(); } } d += 1; d; } c += 1; c; } } }" }, { "index": 124, "before": "void foursquares(int plo,int phi, int punique,int pshow) { lo = plo; hi = phi; unique = punique; show = pshow; solutions = 0; printf(\"\\n\"); acd(); if (unique) printf(\"\\n%d unique solutions in %d to %d\\n\",solutions,lo,hi); else printf(\"\\n%d non-unique solutions in %d to %d\\n\",solutions,lo,hi); }", "after": "pub extern \"C\" fn foursquares(mut plo: i32, mut phi: i32, mut punique: i32, mut pshow: i32) { unsafe { lo = plo; hi = phi; unique = punique; show = pshow; solutions = 0; } print!(\"\\n\"); acd(); unsafe { if unique != 0 { print!(\"\\n{} unique solutions in {} to {}\\n\", solutions, lo, hi); } else { print!(\"\\n{} non-unique solutions in {} to {}\\n\", solutions, lo, hi); }; } }" }, { "index": 125, "before": "void bf() { for (f = lo;f <= hi; f++) if ((!unique) || ((f != a) && (f != c) && (f != d) && (f != g) && (f != e))) { b = e + f - c; if ((b >= lo) && (b <= hi) && ((!unique) || ((b != a) && (b != c) && (b != d) && (b != g) && (b != e) && (b != f)))) { solutions++; if (show) printf(\"%d %d %d %d %d %d %d\\n\",a,b,c,d,e,f,g); } } }", "after": "pub extern \"C\" fn bf() { unsafe { f = lo; while f <= hi { if unique == 0 || f != a && f != c && f != d && f != g && f != e { b = e + f - c; if b >= lo && b <= hi && (unique == 0 || b != a && b != c && b != d && b != g && b != e && b != f) { solutions += 1; solutions; if show != 0 { print!(\"{} {} {} {} {} {} {}\\n\", a, b, c, d, e, f, g); } } } f += 1; f; } } }" }, { "index": 126, "before": "void ge() { for (e = lo;e <= hi; e++) if ((!unique) || ((e != a) && (e != c) && (e != d))) { g = d + e; if ((g >= lo) && (g <= hi) && ((!unique) || ((g != a) && (g != c) && (g != d) && (g != e)))) bf(); } }", "after": "pub extern \"C\" fn ge() { unsafe { e = lo; while e <= hi { if unique == 0 || e != a && e != c && e != d { g = d + e; if g >= lo && g <= hi && (unique == 0 || g != a && g != c && g != d && g != e) { bf(); } } e += 1; e; } } }" }, { "index": 127, "before": "void print(Node *ptr) { printf(\"[\"); if (ptr != NULL) { printf(\"(%d, %d)\", ptr->data.x, ptr->data.y); ptr = ptr->next; } while (ptr != NULL) { printf(\", (%d, %d)\", ptr->data.x, ptr->data.y); ptr = ptr->next; } printf(\"]\"); }", "after": "pub extern \"C\" fn print(mut ptr: *mut Node) { unsafe { print!(\"[\"); } if !ptr.is_null() { print!(\"({}, {})\", (*ptr).data.x, (*ptr).data.y); ptr = (*ptr).next; } while !ptr.is_null() { print!(\", ({}, {})\", (*ptr).data.x, (*ptr).data.y); ptr = (*ptr).next; } unsafe { print!(\"]\"); } }" }, { "index": 128, "before": "bool ccw(const Point *a, const Point *b, const Point *c) { return (b->x - a->x) * (c->y - a->y) > (b->y - a->y) * (c->x - a->x); }", "after": "pub extern \"C\" fn ccw(mut a: *const Point, mut b: *const Point, mut c: *const Point) -> bool { unsafe { return ((*b).x - (*a).x) * ((*c).y - (*a).y) > ((*b).y - (*a).y) * ((*c).x - (*a).x); } }" }, { "index": 129, "before": "int comp(const void *lhs, const void *rhs) { Point lp = *((Point *)lhs); Point rp = *((Point *)rhs); if (lp.x < rp.x) return -1; if (rp.x < lp.x) return 1; return 0; }", "after": "pub extern \"C\" fn comp(mut lhs: *const libc::c_void, mut rhs: *const libc::c_void) -> i32 { unsafe { let mut lp: Point = *(lhs as *mut Point); let mut rp: Point = *(rhs as *mut Point); if lp.x < rp.x { return -1; } if rp.x < lp.x { return 1; } return 0; } }" }, { "index": 130, "before": "void freeNode(Node *ptr) { if (ptr == NULL) { return; } freeNode(ptr->next); ptr->next = NULL; free(ptr); }", "after": "pub extern \"C\" fn freeNode(mut ptr: *mut Node) { unsafe { if ptr.is_null() { return; } freeNode((*ptr).next); (*ptr).next = 0 as *mut tNode; free(ptr as *mut libc::c_void); } }" }, { "index": 131, "before": "int main() { Point points[] = { {16, 3}, {12, 17}, { 0, 6}, {-4, -6}, {16, 6}, {16, -7}, {16, -3}, {17, -4}, { 5, 19}, {19, -8}, { 3, 16}, {12, 13}, { 3, -4}, {17, 5}, {-3, 15}, {-3, -9}, { 0, 11}, {-9, -3}, {-4, -2}, {12, 10} }; Node *hull = convexHull(sizeof(points) / sizeof(Point), points); printf(\"Convex Hull: \"); print(hull); printf(\"\\n\"); freeNode(hull); hull = NULL; return 0; }", "after": "fn main() -> i32 { unsafe { let mut points: [Point; 20] = [ { let mut init = tPoint { x: 16, y: 3 }; init }, { let mut init = tPoint { x: 12, y: 17 }; init }, { let mut init = tPoint { x: 0, y: 6 }; init }, { let mut init = tPoint { x: -4, y: -6 }; init }, { let mut init = tPoint { x: 16, y: 6 }; init }, { let mut init = tPoint { x: 16, y: -7 }; init }, { let mut init = tPoint { x: 16, y: -3 }; init }, { let mut init = tPoint { x: 17, y: -4 }; init }, { let mut init = tPoint { x: 5, y: 19 }; init }, { let mut init = tPoint { x: 19, y: -8 }; init }, { let mut init = tPoint { x: 3, y: 16 }; init }, { let mut init = tPoint { x: 12, y: 13 }; init }, { let mut init = tPoint { x: 3, y: -4 }; init }, { let mut init = tPoint { x: 17, y: 5 }; init }, { let mut init = tPoint { x: -3, y: 15 }; init }, { let mut init = tPoint { x: -3, y: -9 }; init }, { let mut init = tPoint { x: 0, y: 11 }; init }, { let mut init = tPoint { x: -9, y: -3 }; init }, { let mut init = tPoint { x: -4, y: -2 }; init }, { let mut init = tPoint { x: 12, y: 10 }; init }, ]; let mut hull: *mut Node = convexHull( (::core::mem::size_of::<[Point; 20]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, points.as_mut_ptr(), ); print!(\"Convex Hull: \"); print(hull); print!(\"\\n\"); freeNode(hull); hull = 0 as *mut Node; return 0; } }" }, { "index": 132, "before": "int main() { int i, j; char k[4]; for (i = 0; i < 16; ++i) { for (j = 32 + i; j < 128; j += 16) { switch (j) { default: sprintf(k, \"%c\", j); break; case 32: sprintf(k, \"Spc\"); break; case 127: sprintf(k, \"Del\"); break; } printf(\"%3d : %-3s \", j, k); } printf(\"\\n\"); } return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut j: i32 = 0; let mut k: [i8; 4] = [0; 4]; i = 0; unsafe { while i < 16 { j = 32 + i; while j < 128 { match j { 32 => { sprintf(k.as_mut_ptr(), b\"Spc\\0\" as *const u8 as *const i8); } 127 => { sprintf(k.as_mut_ptr(), b\"Del\\0\" as *const u8 as *const i8); } _ => { sprintf(k.as_mut_ptr(), b\"%c\\0\" as *const u8 as *const i8, j); } } print!( \"{:3} : {:-3} \", j, build_str_from_raw_ptr(k.as_mut_ptr() as *mut u8) ); j += 16; } print!(\"\\n\"); i += 1; i; } } return 0; }" }, { "index": 133, "before": "static void _heap_add(heap_t *heap, int c) { if ( (heap->n + 1) > heap->s ) { heap->h = realloc(heap->h, heap->s + heap->cs); heap->s += heap->cs; } heap->h[heap->n] = c; heap->n++; _heap_sort(heap); }", "after": "extern \"C\" fn _heap_add(mut heap: *mut heap_t, mut c: i32) { unsafe { if (*heap).n + 1 > (*heap).s { (*heap).h = realloc( (*heap).h as *mut libc::c_void, ((*heap).s + (*heap).cs) as u64, ) as *mut i32; (*heap).s += (*heap).cs; }; *((*heap).h).offset((*heap).n as isize) = c; (*heap).n += 1; (*heap).n; _heap_sort(heap); } }" }, { "index": 134, "before": "void inttobits(int c, int n, char *s) { s[n] = 0; while(n > 0) { s[n-1] = (c%2) + '0'; c >>= 1; n--; } }", "after": "pub extern \"C\" fn inttobits(mut c: i32, mut n: i32, mut s: *mut i8) { unsafe { *s.offset(n as isize) = 0; while n > 0 { *s.offset((n - 1i32) as isize) = (c % 2 + '0' as i32) as i8; c >>= 1; n -= 1; n; } } }" }, { "index": 135, "before": "void free_huffman_codes(huffcode_t **c) { int i; for(i=0; i < BYTES; i++) free(c[i]); free(c); }", "after": "pub extern \"C\" fn free_huffman_codes(mut c: *mut *mut huffcode_t) { unsafe { let mut i: i32 = 0; i = 0; while i < 256 { free(*c.offset(i as isize) as *mut libc::c_void); i += 1; i; } free(c as *mut libc::c_void); } }" }, { "index": 136, "before": "int main() { huffcode_t **r; int i; char strbit[MAXBITSPERCODE]; const char *p; long freqs[BYTES]; memset(freqs, 0, sizeof freqs); p = test; while(*p != '\\0') freqs[*p++]++; r = create_huffman_codes(freqs); for(i=0; i < BYTES; i++) { if ( r[i] != NULL ) { inttobits(r[i]->code, r[i]->nbits, strbit); printf(\"%c (%d) %s\\n\", i, r[i]->code, strbit); } } free_huffman_codes(r); return 0; }", "after": "fn main() -> i32 { unsafe { let mut r: *mut *mut huffcode_t = 0 as *mut *mut huffcode_t; let mut i: i32 = 0; let mut strbit: [i8; 100] = [0; 100]; let mut p: *const i8 = 0 as *const i8; let mut freqs: [i64; 256] = [0; 256]; memset( freqs.as_mut_ptr() as *mut libc::c_void, 0, ::core::mem::size_of::<[i64; 256]>() as u64, ); p = test; while *p as i32 != '\\0' as i32 { let fresh3 = p; p = p.offset(1); freqs[*fresh3 as usize] += 1; freqs[*fresh3 as usize]; } r = create_huffman_codes(freqs.as_mut_ptr()); i = 0; while i < 256 { if !(*r.offset(i as isize)).is_null() { inttobits( (**r.offset(i as isize)).code, (**r.offset(i as isize)).nbits, strbit.as_mut_ptr(), ); print!( \"{} ({}) {}\\n\", i, (**r.offset(i as isize)).code, build_str_from_raw_ptr(strbit.as_mut_ptr() as *mut u8) ); } i += 1; i; } free_huffman_codes(r); return 0; } }" }, { "index": 137, "before": "static void _heap_sort(heap_t *heap) { int i=1, j=2; /* gnome sort */ int *a = heap->h; while(i < heap->n) { /* smaller values are kept at the end */ if ( heap->f[a[i-1]] >= heap->f[a[i]] ) { i = j; j++; } else { swap_(i-1, i); i--; i = (i==0) ? j++ : i; } } }", "after": "extern \"C\" fn _heap_sort(mut heap: *mut heap_t) { unsafe { let mut i: i32 = 1; let mut j: i32 = 2; let mut a: *mut i32 = (*heap).h; while i < (*heap).n { if *((*heap).f).offset(*a.offset((i - 1i32) as isize) as isize) >= *((*heap).f).offset(*a.offset(i as isize) as isize) { i = j; j += 1; j; } else { let mut t_: i32 = 0; t_ = *a.offset((i - 1i32) as isize); *a.offset((i - 1i32) as isize) = *a.offset(i as isize); *a.offset(i as isize) = t_; i -= 1; i; i = if i == 0 { let fresh0 = j; j = j + 1; fresh0 } else { i }; } } } }" }, { "index": 138, "before": "static void _heap_destroy(heap_t *heap) { free(heap->h); free(heap); }", "after": "extern \"C\" fn _heap_destroy(mut heap: *mut heap_t) { unsafe { free((*heap).h as *mut libc::c_void); free(heap as *mut libc::c_void); } }" }, { "index": 139, "before": "static int _heap_remove(heap_t *heap) { if ( heap->n > 0 ) { heap->n--; return heap->h[heap->n]; } return -1; }", "after": "extern \"C\" fn _heap_remove(mut heap: *mut heap_t) -> i32 { unsafe { if (*heap).n > 0 { (*heap).n -= 1; (*heap).n; return *((*heap).h).offset((*heap).n as isize); } return -1; } }" }, { "index": 140, "before": "int main() { \tcomb(5, 3, 0, 0); \treturn 0; }", "after": "fn main() -> i32 { comb(5, 3, 0, 0); return 0; }" }, { "index": 141, "before": "void comb(int pool, int need, marker chosen, int at) { \tif (pool < need + at) return; /* not enough bits left */ \tif (!need) { \t\t/* got all we needed; print the thing. if other actions are \t\t * desired, we could have passed in a callback function. */ \t\tfor (at = 0; at < pool; at++) \t\t\tif (chosen & (one << at)) printf(\"%d \", at); \t\tprintf(\"\\n\"); \t\treturn; \t} \t/* if we choose the current item, \"or\" (|) the bit to mark it so. */ \tcomb(pool, need - 1, chosen | (one << at), at + 1); \tcomb(pool, need, chosen, at + 1); /* or don't choose it, go to next */ }", "after": "pub extern \"C\" fn comb(mut pool: i32, mut need: i32, mut chosen: u64, mut at: i32) { if pool < need + at { return; } unsafe { if need == 0 { at = 0; while at < pool { if chosen & one << at != 0 { print!(\"{} \", at); } at += 1; at; } print!(\"\\n\"); return; } comb(pool, need - 1, chosen | one << at, at + 1); } comb(pool, need, chosen, at + 1); }" }, { "index": 142, "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": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut i: i32 = 0; print!( \"This program is named {}.\\n\", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); i = 1; while i < argc { print!( \"the argument #{} is {}\\n\", i, build_str_from_raw_ptr(*argv.offset(i as isize) as *mut u8) ); i += 1; i; } return 0; } }" }, { "index": 143, "before": "int main(int c, char **v) { \tint i, year_set = 0; \tfor (i = 1; i < c; i++) { \t\tif (!strcmp(v[i], \"-w\")) { \t\t\tif (++i == c || (width = atoi(v[i])) < 20) \t\t\t\tgoto bail; \t\t} else if (!year_set) { \t\t\tif (!sscanf(v[i], \"%d\", &year) || year <= 0) \t\t\t\tyear = 1969; \t\t\tyear_set = 1; \t\t} else \t\t\tgoto bail; \t} \tinit_months(); \tprint_year(); \treturn 0; bail:\tfprintf(stderr, \"bad args\\nUsage: %s year [-w width (>= 20)]\\n\", v[0]); \texit(1); }", "after": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { let mut current_block: u64; let mut i: i32 = 0; let mut year_set: i32 = 0; i = 1; loop { if !(i < c) { current_block = 1394248824506584008; break; } if strcmp(*v.offset(i as isize), b\"-w\\0\" as *const u8 as *const i8) == 0 { i += 1; if i == c || { width = atoi(*v.offset(i as isize)); width < 20 } { current_block = 2002819764153645144; break; } } else { if !(year_set == 0) { current_block = 2002819764153645144; break; } if sscanf( *v.offset(i as isize), b\"%d\\0\" as *const u8 as *const i8, &mut year as *mut i32, ) == 0 || year <= 0 { year = 1969; } year_set = 1; } i += 1; i; } match current_block { 2002819764153645144 => { fprintf( stderr, b\"bad args\\nUsage: %s year [-w width (>= 20)]\\n\\0\" as *const u8 as *const i8, *v.offset(0 as isize), ); exit(1); } _ => { init_months(); print_year(); return 0; } }; } }" }, { "index": 144, "before": "void init_months() { \tint i; \tif ((!(year % 4) && (year % 100)) || !(year % 400)) \t\tmonths[1].days = 29; \tyear--; \tmonths[0].start_wday \t\t= (year * 365 + year/4 - year/100 + year/400 + 1) % 7; \tfor (i = 1; i < 12; i++) \t\tmonths[i].start_wday = \t\t\t(months[i-1].start_wday + months[i-1].days) % 7; \tcols = (width + 2) / 22; \twhile (12 % cols) cols--; \tgap = cols - 1 ? (width - 20 * cols) / (cols - 1) : 0; \tif (gap > 4) gap = 4; \tlead = (width - (20 + gap) * cols + gap + 1) / 2; year++; }", "after": "pub extern \"C\" fn init_months() { let mut i: i32 = 0; unsafe { if year % 4 == 0 && year % 100 != 0 || year % 400 == 0 { months[1 as usize].days = 29; } year -= 1; year; months[0 as usize].start_wday = (year * 365 + year / 4 - year / 100 + year / 400 + 1) % 7; } i = 1; unsafe { while i < 12 { months[i as usize].start_wday = (months[(i - 1i32) as usize].start_wday + months[(i - 1i32) as usize].days) % 7; i += 1; i; } cols = (width + 2) / 22; while 12 % cols != 0 { cols -= 1; cols; } gap = if cols - 1 != 0 { (width - 20 * cols) / (cols - 1) } else { 0 }; if gap > 4 { gap = 4; } lead = (width - (20 + gap) * cols + gap + 1) / 2; year += 1; year; } }" }, { "index": 145, "before": "void print_year() { \tint row; \tchar buf[32]; \tsprintf(buf, \"%d\", year); \tspace((width - strlen(buf)) / 2); \tprintf(\"%s\\n\\n\", buf); \tfor (row = 0; row * cols < 12; row++) \t\tprint_row(row); }", "after": "pub extern \"C\" fn print_year() { let mut row: i32 = 0; let mut buf: [i8; 32] = [0; 32]; unsafe { sprintf(buf.as_mut_ptr(), b\"%d\\0\" as *const u8 as *const i8, year); space( (width as u64) .wrapping_sub(strlen(buf.as_mut_ptr())) .wrapping_div(2) as i32, ); print!( \"{}\\n\\n\", build_str_from_raw_ptr(buf.as_mut_ptr() as *mut u8) ); } row = 0; unsafe { while row * cols < 12 { print_row(row); row += 1; row; } } }" }, { "index": 146, "before": "void space(int n) { while (n-- > 0) putchar(' '); }", "after": "pub extern \"C\" fn space(mut n: i32) { loop { let fresh0 = n; n = n - 1; if !(fresh0 > 0) { break; } print!(\"{}\", ' ' as i32); } }" }, { "index": 147, "before": "void print_row(int row) { \tint c, i, from = row * cols, to = from + cols; \tspace(lead); \tfor (c = from; c < to; c++) { \t\ti = strlen(months[c].name); \t\tspace((20 - i)/2); \t\tprintf(\"%s\", months[c].name); \t\tspace(20 - i - (20 - i)/2 + ((c == to - 1) ? 0 : gap)); \t} \tputchar('\\n'); \tspace(lead); \tfor (c = from; c < to; c++) { \t\tfor (i = 0; i < 7; i++) \t\t\tprintf(\"%s%s\", wdays[i], i == 6 ? \"\" : \" \"); \t\tif (c < to - 1) space(gap); \t\telse putchar('\\n'); \t} \twhile (1) { \t\tfor (c = from; c < to; c++) \t\t\tif (months[c].at < months[c].days) break; \t\tif (c == to) break; \t\tspace(lead); \t\tfor (c = from; c < to; c++) { \t\t\tfor (i = 0; i < months[c].start_wday; i++) space(3); \t\t\twhile(i++ < 7 && months[c].at < months[c].days) { \t\t\t\tprintf(\"%2d\", ++months[c].at); \t\t\t\tif (i < 7 || c < to - 1) putchar(' '); \t\t\t} \t\t\twhile (i++ <= 7 && c < to - 1) space(3); \t\t\tif (c < to - 1) space(gap - 1); \t\t\tmonths[c].start_wday = 0; \t\t} \t\tputchar('\\n'); \t} \tputchar('\\n'); }", "after": "pub extern \"C\" fn print_row(mut row: i32) { let mut c: i32 = 0; let mut i: i32 = 0; unsafe { let mut from: i32 = row * cols; let mut to: i32 = from + cols; space(lead); c = from; while c < to { i = strlen(months[c as usize].name) as i32; space((20 - i) / 2); print!( \"{}\", build_str_from_raw_ptr(months[c as usize].name as *mut u8) ); space(20 - i - (20 - i) / 2 + (if c == to - 1 { 0 } else { gap })); c += 1; c; } print!(\"{}\", '\\n' as i32); space(lead); c = from; while c < to { i = 0; while i < 7 { if i == 6 { print!( \"{}{}\", build_str_from_raw_ptr(wdays[i as usize] as *mut u8), \"\\0\" ) } else { print!( \"{}{}\", build_str_from_raw_ptr(wdays[i as usize] as *mut u8), \" \\0\" ) }; i += 1; i; } if c < to - 1 { space(gap); } else { print!(\"{}\", '\\n' as i32); } c += 1; c; } loop { c = from; while c < to { if months[c as usize].at < months[c as usize].days { break; } c += 1; c; } if c == to { break; } space(lead); c = from; while c < to { i = 0; while i < months[c as usize].start_wday { space(3); i += 1; i; } loop { let fresh1 = i; i = i + 1; if !(fresh1 < 7 && months[c as usize].at < months[c as usize].days) { break; } months[c as usize].at += 1; print!(\"{:2}\", months[c as usize].at); if i < 7 || c < to - 1 { print!(\"{}\", ' ' as i32); } } loop { let fresh2 = i; i = i + 1; if !(fresh2 <= 7 && c < to - 1) { break; } space(3); } if c < to - 1 { space(gap - 1); } months[c as usize].start_wday = 0; c += 1; c; } print!(\"{}\", '\\n' as i32); } } print!(\"{}\", '\\n' as i32); }" }, { "index": 148, "before": "bool b(bool in) { printf(\"I am b\\n\"); return in; }", "after": "pub extern \"C\" fn b(mut in_0: bool) -> bool { print!(\"I am b\\n\"); return in_0; }" }, { "index": 149, "before": "bool a(bool in) { printf(\"I am a\\n\"); return in; }", "after": "pub extern \"C\" fn a(mut in_0: bool) -> bool { print!(\"I am a\\n\"); return in_0; }" }, { "index": 150, "before": "int main() { bool x; TEST(false, true, &&); // b is not evaluated TEST(true, false, ||); // b is not evaluated TEST(true, false, &&); // b is evaluated TEST(false, false, ||); // b is evaluated return 0; }", "after": "fn main() -> i32 { let mut x: bool = false; x = a(0 != 0) as i32 != 0 && b(1 != 0) as i32 != 0; if x as i32 != 0 { print!(\"false && true = {}\\n\\n\", \"true\\0\") } else { print!(\"false && true = {}\\n\\n\", \"false\\0\") }; x = a(1 != 0) as i32 != 0 || b(0 != 0) as i32 != 0; if x as i32 != 0 { print!(\"true || false = {}\\n\\n\", \"true\\0\") } else { print!(\"true || false = {}\\n\\n\", \"false\\0\") }; x = a(1 != 0) as i32 != 0 && b(0 != 0) as i32 != 0; if x as i32 != 0 { print!(\"true && false = {}\\n\\n\", \"true\\0\") } else { print!(\"true && false = {}\\n\\n\", \"false\\0\") }; x = a(0 != 0) as i32 != 0 || b(0 != 0) as i32 != 0; if x as i32 != 0 { print!(\"false || false = {}\\n\\n\", \"true\\0\") } else { print!(\"false || false = {}\\n\\n\", \"false\\0\") }; return 0; }" }, { "index": 151, "before": "int main() { \tdouble d = dist(36.12, -86.67, 33.94, -118.4); \t/* Americans don't know kilometers */ \tprintf(\"dist: %.1f km (%.1f mi.)\\n\", d, d / 1.609344); \treturn 0; }", "after": "fn main() -> i32 { let mut d: f64 = dist(36.12f64, -86.67f64, 33.94f64, -118.4f64); print!(\"dist: {:.1} km ({:.1} mi.)\\n\", d, d / 1.609344f64); return 0; }" }, { "index": 152, "before": "double dist(double th1, double ph1, double th2, double ph2) { \tdouble dx, dy, dz; \tph1 -= ph2; \tph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD; \tdz = sin(th1) - sin(th2); \tdx = cos(ph1) * cos(th1) - cos(th2); \tdy = sin(ph1) * cos(th1); \treturn asin(sqrt(dx * dx + dy * dy + dz * dz) / 2) * 2 * R; }", "after": "pub extern \"C\" fn dist(mut th1: f64, mut ph1: f64, mut th2: f64, mut ph2: f64) -> f64 { let mut dx: f64 = 0.; let mut dy: f64 = 0.; let mut dz: f64 = 0.; ph1 -= ph2; ph1 *= 3.1415926536f64 / 180 as f64; th1 *= 3.1415926536f64 / 180 as f64; th2 *= 3.1415926536f64 / 180 as f64; unsafe { dz = sin(th1) - sin(th2); dx = cos(ph1) * cos(th1) - cos(th2); dy = sin(ph1) * cos(th1); return asin(sqrt(dx * dx + dy * dy + dz * dz) / 2 as f64) * 2 as f64 * 6371 as f64; } }" }, { "index": 153, "before": "double mean(double *v, int len) { \tdouble sum = 0; \tint i; \tfor (i = 0; i < len; i++) \t\tsum += v[i]; \treturn sum / len; }", "after": "pub extern \"C\" fn mean(mut v: *mut f64, mut len: i32) -> f64 { unsafe { let mut sum: f64 = 0 as f64; let mut i: i32 = 0; i = 0; while i < len { sum += *v.offset(i as isize); i += 1; i; } return sum / len as f64; } }" }, { "index": 154, "before": "int main(void) { \tdouble v[] = {1, 2, 2.718, 3, 3.142}; \tint i, len; \tfor (len = 5; len >= 0; len--) { \t\tprintf(\"mean[\"); \t\tfor (i = 0; i < len; i++) \t\t\tprintf(i ? \", %g\" : \"%g\", v[i]); \t\tprintf(\"] = %g\\n\", mean(v, len)); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut v: [f64; 5] = [1 as f64, 2 as f64, 2.718f64, 3 as f64, 3.142f64]; let mut i: i32 = 0; let mut len: i32 = 0; len = 5; while len >= 0 { print!(\"mean[\"); i = 0; while i < len { if i != 0 { print!(\", {}\", v[i as usize]) } else { print!(\"{}\", v[i as usize]) }; i += 1; i; } print!(\"] = {}\\n\", mean(v.as_mut_ptr(), len)); len -= 1; len; } return 0; }" }, { "index": 155, "before": "int sub(int a, int b) { return a - b; }", "after": "pub extern \"C\" fn sub(mut a: i32, mut b: i32) -> i32 { return a - b; }" }, { "index": 156, "before": "int add(int a, int b) { return a + b; }", "after": "pub extern \"C\" fn add(mut a: i32, mut b: i32) -> i32 { return a + b; }" }, { "index": 157, "before": "int mul(int a, int b) { return a * b; }", "after": "pub extern \"C\" fn mul(mut a: i32, mut b: i32) -> i32 { return a * b; }" }, { "index": 158, "before": "int reduce(intFn fn, int size, int *elms) { int i, val = *elms; for (i = 1; i < size; ++i) val = fn(val, elms[i]); return val; }", "after": "pub extern \"C\" fn reduce(mut fn_0: intFn, mut size: i32, mut elms: *mut i32) -> i32 { unsafe { let mut i: i32 = 0; let mut val: i32 = *elms; i = 1; while i < size { val = fn_0.expect(\"non-null function pointer\")(val, *elms.offset(i as isize)); i += 1; i; } return val; } }" }, { "index": 159, "before": "int main(void) { int nums[] = {1, 2, 3, 4, 5}; printf(\"%d\\n\", reduce(add, 5, nums)); printf(\"%d\\n\", reduce(sub, 5, nums)); printf(\"%d\\n\", reduce(mul, 5, nums)); return 0; }", "after": "fn main() -> i32 { let mut nums: [i32; 5] = [1, 2, 3, 4, 5]; print!( \"{}\\n\", reduce( Some(add as unsafe extern \"C\" fn(i32, i32) -> i32), 5, nums.as_mut_ptr(), ) ); print!( \"{}\\n\", reduce( Some(sub as unsafe extern \"C\" fn(i32, i32) -> i32), 5, nums.as_mut_ptr(), ) ); print!( \"{}\\n\", reduce( Some(mul as unsafe extern \"C\" fn(i32, i32) -> i32), 5, nums.as_mut_ptr(), ) ); return 0; }" }, { "index": 160, "before": "int main() { \tint i; \tprintf(\"\" \t\t\"\"); \tfor (i = 0; i < 4; i++) { \t\tprintf(\"\", i, \t\t\trand() % 10000, rand() % 10000, rand() % 10000); \t} \tprintf(\"
XYZ
%d%d%d%d
\"); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; print! (\"\"); i = 0; unsafe { while i < 4 { print!( \"\", i, rand() % 10000, rand() % 10000, rand() % 10000 ); i += 1; i; } } print!(\"
XYZ
{}{}{}{}
\"); return 0; }" }, { "index": 161, "before": "double rms(double *v, int n) { int i; double sum = 0.0; for(i = 0; i < n; i++) sum += v[i] * v[i]; return sqrt(sum / n); }", "after": "pub extern \"C\" fn rms(mut v: *mut f64, mut n: i32) -> f64 { unsafe { let mut i: i32 = 0; let mut sum: f64 = 0.0f64; i = 0; while i < n { sum += *v.offset(i as isize) * *v.offset(i as isize); i += 1; i; } return sqrt(sum / n as f64); } }" }, { "index": 162, "before": "int main(void) { double v[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}; printf(\"%f\\n\", rms(v, sizeof(v)/sizeof(double))); return 0; }", "after": "fn main() -> i32 { let mut v: [f64; 10] = [ 1.0f64, 2.0f64, 3.0f64, 4.0f64, 5.0f64, 6.0f64, 7.0f64, 8.0f64, 9.0f64, 10.0f64, ]; print!( \"{}\\n\", rms( v.as_mut_ptr(), (::core::mem::size_of::<[f64; 10]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, ) ); return 0; }" }, { "index": 163, "before": "int main() { int a, b; scanf(\"%d%d\", &a, &b); printf(\"%d\\n\", a + b); return 0; }", "after": "fn main() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0; unsafe { scanf( b\"%d%d\\0\" as *const u8 as *const i8, &mut a as *mut i32, &mut b as *mut i32, ); } print!(\"{}\\n\", a + b); return 0; }" }, { "index": 164, "before": "int main() { int *ints = malloc(SIZEOF_MEMB*NMEMB); /* realloc can be used to increase or decrease an already allocated memory (same as malloc if ints is NULL) */ ints = realloc(ints, sizeof(int)*(NMEMB+1)); /* calloc set the memory to 0s */ int *int2 = calloc(NMEMB, SIZEOF_MEMB); /* all use the same free */ free(ints); free(int2); return 0; }", "after": "fn main() -> i32 { unsafe { let mut ints: *mut i32 = malloc((::core::mem::size_of::() as u64).wrapping_mul(100)) as *mut i32; ints = realloc( ints as *mut libc::c_void, (::core::mem::size_of::() as u64).wrapping_mul((100 + 1i32) as u64), ) as *mut i32; let mut int2: *mut i32 = calloc(100, ::core::mem::size_of::() as u64) as *mut i32; free(ints as *mut libc::c_void); free(int2 as *mut libc::c_void); return 0; } }" }, { "index": 165, "before": "void printResults(char originalString[100], char finalString[100], int operation, char squeezeChar){ if(operation==SQUEEZE){ printf(\"Specified Operation : SQUEEZE\\nTarget Character : %c\",squeezeChar); } else printf(\"Specified Operation : COLLAPSE\"); printf(\"\\nOriginal %c%c%c%s%c%c%c\\nLength : %d\",174,174,174,originalString,175,175,175,(int)strlen(originalString)); printf(\"\\nFinal %c%c%c%s%c%c%c\\nLength : %d\\n\",174,174,174,finalString,175,175,175,(int)strlen(finalString)); }", "after": "pub extern \"C\" fn printResults( mut originalString: *mut i8, mut finalString: *mut i8, mut operation: i32, mut squeezeChar: i8, ) { unsafe { if operation == 1 { print!( \"Specified Operation : SQUEEZE\\nTarget Character : {}\", squeezeChar as i32 ); } else { print!(\"Specified Operation : COLLAPSE\"); } print!( \"\\nOriginal {}{}{}{}{}{}{}\\nLength : {}\", 174, 174, 174, build_str_from_raw_ptr(originalString as *mut u8), 175, 175, 175, strlen(originalString as *const i8) as i32 ); print!( \"\\nFinal {}{}{}{}{}{}{}\\nLength : {}\\n\", 174, 174, 174, build_str_from_raw_ptr(finalString as *mut u8), 175, 175, 175, strlen(finalString as *const i8) as i32 ); } }" }, { "index": 166, "before": "int strcmpi(char* str1,char* str2){ int len1 = strlen(str1), len2 = strlen(str2), i; if(len1!=len2){ return 1; } else{ for(i=0;i='A'&&str1[i]<='Z')&&(str2[i]>='a'&&str2[i]<='z')&&(str2[i]-65!=str1[i])) return 1; else if((str2[i]>='A'&&str2[i]<='Z')&&(str1[i]>='a'&&str1[i]<='z')&&(str1[i]-65!=str2[i])) return 1; else if(str1[i]!=str2[i]) return 1; } } return 0; }", "after": "pub extern \"C\" fn strcmpi(mut str1: *mut i8, mut str2: *mut i8) -> i32 { unsafe { let mut len1: i32 = strlen(str1) as i32; let mut len2: i32 = strlen(str2) as i32; let mut i: i32 = 0; if len1 != len2 { return 1; } else { i = 0; while i < len1 { if *str1.offset(i as isize) as i32 >= 'A' as i32 && *str1.offset(i as isize) as i32 <= 'Z' as i32 && (*str2.offset(i as isize) as i32 >= 'a' as i32 && *str2.offset(i as isize) as i32 <= 'z' as i32) && *str2.offset(i as isize) as i32 - 65 != *str1.offset(i as isize) as i32 { return 1; } else if *str2.offset(i as isize) as i32 >= 'A' as i32 && *str2.offset(i as isize) as i32 <= 'Z' as i32 && (*str1.offset(i as isize) as i32 >= 'a' as i32 && *str1.offset(i as isize) as i32 <= 'z' as i32) && *str1.offset(i as isize) as i32 - 65 != *str2.offset(i as isize) as i32 { return 1; } else if *str1.offset(i as isize) as i32 != *str2.offset(i as isize) as i32 { return 1; } i += 1; i; } } return 0; } }" }, { "index": 167, "before": "int main(int argc, char** argv){ int operation; char squeezeChar; if(argc<3||argc>4){ printf(\"Usage : %s \\n\",argv[0]); return 0; } if(strcmpi(argv[1],\"SQUEEZE\")==0 && argc!=4){ scanf(\"Please enter characted to be squeezed : %c\",&squeezeChar); operation = SQUEEZE; } else if(argc==4){ operation = SQUEEZE; squeezeChar = argv[3][0]; } else if(strcmpi(argv[1],\"COLLAPSE\")==0){ operation = COLLAPSE; } if(strlen(argv[2])<2){ printResults(argv[2],argv[2],operation,squeezeChar); } else{ printResults(argv[2],processString(argv[2],operation,squeezeChar),operation,squeezeChar); } return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut operation: i32 = 0; let mut squeezeChar: i8 = 0; if argc < 3 || argc > 4 { print! (\"Usage : {} \\n\", build_str_from_raw_ptr (* argv.offset (0 as isize) as * mut u8)); return 0; } if strcmpi( *argv.offset(1 as isize), b\"SQUEEZE\\0\" as *const u8 as *const i8 as *mut i8, ) == 0 && argc != 4 { scanf( b\"Please enter characted to be squeezed : %c\\0\" as *const u8 as *const i8, &mut squeezeChar as *mut i8, ); operation = 1; } else if argc == 4 { operation = 1; squeezeChar = *(*argv.offset(3 as isize)).offset(0 as isize); } else if strcmpi( *argv.offset(1 as isize), b\"COLLAPSE\\0\" as *const u8 as *const i8 as *mut i8, ) == 0 { operation = 0; } if strlen(*argv.offset(2 as isize)) < 2 { printResults( *argv.offset(2 as isize), *argv.offset(2 as isize), operation, squeezeChar, ); } else { printResults( *argv.offset(2 as isize), processString(*argv.offset(2 as isize), operation, squeezeChar), operation, squeezeChar, ); } return 0; } }" }, { "index": 168, "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": "extern \"C\" fn gcd_ui(mut x: u64, mut y: u64) -> u64 { let mut t: u64 = 0; if y < x { t = x; x = y; y = t; } while y > 0 { t = y; y = x.wrapping_rem(y); x = t; } return x; }" }, { "index": 169, "before": "int main() { printf(\"%lu\\n\", binomial(5, 3)); printf(\"%lu\\n\", binomial(40, 19)); printf(\"%lu\\n\", binomial(67, 31)); return 0; }", "after": "fn main() -> i32 { print!(\"{}\\n\", binomial(5, 3)); print!(\"{}\\n\", binomial(40, 19)); print!(\"{}\\n\", binomial(67, 31)); return 0; }" }, { "index": 170, "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 extern \"C\" fn binomial(mut n: u64, mut k: u64) -> u64 { let mut d: u64 = 0; let mut g: u64 = 0; let mut r: u64 = 1; if k == 0 { return 1; } if k == 1 { return n; } if k >= n { return (k == n) as u64; } if k > n.wrapping_div(2) { k = n.wrapping_sub(k); } d = 1; while d <= k { if r >= 9223372036854775807u64 .wrapping_mul(2) .wrapping_add(1) .wrapping_div(n) { let mut nr: u64 = 0; let mut dr: u64 = 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 >= 9223372036854775807u64 .wrapping_mul(2) .wrapping_add(1) .wrapping_div(nr) { return 0; } 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": 171, "before": "int main() { \tint i; \tfor (i = 1; i < 100000000; i++) /* don't handle 0 */ \t\tif (self_desc(i)) \t\t\tprintf(\"%d\\n\", i); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; i = 1; while i < 100000000 { if self_desc(i as u64) != 0 { print!(\"{}\\n\", i); } i += 1; i; } return 0; }" }, { "index": 172, "before": "int self_desc(unsigned long long xx) { \tregister unsigned int d, x; \tunsigned char cnt[10] = {0}, dig[10] = {0}; \tfor (d = 0; xx > ~0U; xx /= 10) \t\tcnt[dig[d++] = xx % 10]++; \tfor (x = xx; x; x /= 10) \t\tcnt[dig[d++] = x % 10]++; \twhile (d-- && dig[x++] == cnt[d]) \t\t; \treturn d == -1; }", "after": "pub extern \"C\" fn self_desc(mut xx: u64) -> i32 { let mut d: u32 = 0; let mut x: u32 = 0; let mut cnt: [u8; 10] = [0; 10]; let mut dig: [u8; 10] = [0; 10]; d = 0; while xx > !0 as u64 { let fresh0 = d; d = d.wrapping_add(1); dig[fresh0 as usize] = xx.wrapping_rem(10) as u8; cnt[dig[fresh0 as usize] as usize] = (cnt[dig[fresh0 as usize] as usize]).wrapping_add(1); cnt[dig[fresh0 as usize] as usize]; xx = xx.wrapping_div(10); } x = xx as u32; while x != 0 { let fresh1 = d; d = d.wrapping_add(1); dig[fresh1 as usize] = x.wrapping_rem(10) as u8; cnt[dig[fresh1 as usize] as usize] = (cnt[dig[fresh1 as usize] as usize]).wrapping_add(1); cnt[dig[fresh1 as usize] as usize]; x = x.wrapping_div(10); } loop { let fresh2 = d; d = d.wrapping_sub(1); if !(fresh2 != 0 && { let fresh3 = x; x = x.wrapping_add(1); dig[fresh3 as usize] as i32 == cnt[d as usize] as i32 }) { break; } } return (d == (-1) as i32 as u32) as i32; }" }, { "index": 173, "before": "void roman(char *s, unsigned int n) { if (n == 0) { fputs(\"Roman numeral for zero requested.\", stderr); exit(EXIT_FAILURE); } #define digit(loop, num, c) \\ loop (n >= num) \\ {*(s++) = c; \\ n -= num;} #define digits(loop, num, c1, c2) \\ loop (n >= num) \\ {*(s++) = c1; \\ *(s++) = c2; \\ n -= num;} digit ( while, 1000, 'M' ) digits ( if, 900, 'C', 'M' ) digit ( if, 500, 'D' ) digits ( if, 400, 'C', 'D' ) digit ( while, 100, 'C' ) digits ( if, 90, 'X', 'C' ) digit ( if, 50, 'L' ) digits ( if, 40, 'X', 'L' ) digit ( while, 10, 'X' ) digits ( if, 9, 'I', 'X' ) digit ( if, 5, 'V' ) digits ( if, 4, 'I', 'V' ) digit ( while, 1, 'I' ) #undef digit #undef digits *s = 0;}", "after": "pub extern \"C\" fn roman(mut s: *mut i8, mut n: u32) { unsafe { if n == 0 { fputs( b\"Roman numeral for zero requested.\\0\" as *const u8 as *const i8, stderr, ); exit(1); } while n >= 1000 { let fresh0 = s; s = s.offset(1); *fresh0 = 'M' as i8; n = n.wrapping_sub(1000); } if n >= 900 { let fresh1 = s; s = s.offset(1); *fresh1 = 'C' as i8; let fresh2 = s; s = s.offset(1); *fresh2 = 'M' as i8; n = n.wrapping_sub(900); } if n >= 500 { let fresh3 = s; s = s.offset(1); *fresh3 = 'D' as i8; n = n.wrapping_sub(500); } if n >= 400 { let fresh4 = s; s = s.offset(1); *fresh4 = 'C' as i8; let fresh5 = s; s = s.offset(1); *fresh5 = 'D' as i8; n = n.wrapping_sub(400); } while n >= 100 { let fresh6 = s; s = s.offset(1); *fresh6 = 'C' as i8; n = n.wrapping_sub(100); } if n >= 90 { let fresh7 = s; s = s.offset(1); *fresh7 = 'X' as i8; let fresh8 = s; s = s.offset(1); *fresh8 = 'C' as i8; n = n.wrapping_sub(90); } if n >= 50 { let fresh9 = s; s = s.offset(1); *fresh9 = 'L' as i8; n = n.wrapping_sub(50); } if n >= 40 { let fresh10 = s; s = s.offset(1); *fresh10 = 'X' as i8; let fresh11 = s; s = s.offset(1); *fresh11 = 'L' as i8; n = n.wrapping_sub(40); } while n >= 10 { let fresh12 = s; s = s.offset(1); *fresh12 = 'X' as i8; n = n.wrapping_sub(10); } if n >= 9 { let fresh13 = s; s = s.offset(1); *fresh13 = 'I' as i8; let fresh14 = s; s = s.offset(1); *fresh14 = 'X' as i8; n = n.wrapping_sub(9); } if n >= 5 { let fresh15 = s; s = s.offset(1); *fresh15 = 'V' as i8; n = n.wrapping_sub(5); } if n >= 4 { let fresh16 = s; s = s.offset(1); *fresh16 = 'I' as i8; let fresh17 = s; s = s.offset(1); *fresh17 = 'V' as i8; n = n.wrapping_sub(4); } while n >= 1 { let fresh18 = s; s = s.offset(1); *fresh18 = 'I' as i8; n = n.wrapping_sub(1); } *s = 0; } }" }, { "index": 174, "before": "int main(void) { char buffer[16]; unsigned int i; for (i = 1 ; i < 4000 ; ++i) { roman(buffer, i); printf(\"%4u: %s\\n\", i, buffer); } return EXIT_SUCCESS; }", "after": "fn main() -> i32 { let mut buffer: [i8; 16] = [0; 16]; let mut i: u32 = 0; i = 1; unsafe { while i < 4000 { roman(buffer.as_mut_ptr(), i); print!( \"{:4}: {}\\n\", i, build_str_from_raw_ptr(buffer.as_mut_ptr() as *mut u8) ); i = i.wrapping_add(1); i; } } return 0; }" }, { "index": 175, "before": "void fairshare(int base, int count) { int i; printf(\"Base %2d:\", base); for (i = 0; i < count; i++) { int t = turn(base, i); printf(\" %2d\", t); } printf(\"\\n\"); }", "after": "pub extern \"C\" fn fairshare(mut base: i32, mut count: i32) { let mut i: i32 = 0; print!(\"Base {:2}:\", base); i = 0; while i < count { let mut t: i32 = turn(base, i); print!(\" {:2}\", t); i += 1; i; } print!(\"\\n\"); }" }, { "index": 176, "before": "void turnCount(int base, int count) { int *cnt = calloc(base, sizeof(int)); int i, minTurn, maxTurn, portion; if (NULL == cnt) { printf(\"Failed to allocate space to determine the spread of turns.\\n\"); return; } for (i = 0; i < count; i++) { int t = turn(base, i); cnt[t]++; } minTurn = INT_MAX; maxTurn = INT_MIN; portion = 0; for (i = 0; i < base; i++) { if (cnt[i] > 0) { portion++; } if (cnt[i] < minTurn) { minTurn = cnt[i]; } if (cnt[i] > maxTurn) { maxTurn = cnt[i]; } } printf(\" With %d people: \", base); if (0 == minTurn) { printf(\"Only %d have a turn\\n\", portion); } else if (minTurn == maxTurn) { printf(\"%d\\n\", minTurn); } else { printf(\"%d or %d\\n\", minTurn, maxTurn); } free(cnt); }", "after": "pub extern \"C\" fn turnCount(mut base: i32, mut count: i32) { unsafe { let mut cnt: *mut i32 = calloc(base as u64, ::core::mem::size_of::() as u64) as *mut i32; let mut i: i32 = 0; let mut minTurn: i32 = 0; let mut maxTurn: i32 = 0; let mut portion: i32 = 0; if cnt.is_null() { print!(\"Failed to allocate space to determine the spread of turns.\\n\"); return; } i = 0; while i < count { let mut t: i32 = turn(base, i); let ref mut fresh0 = *cnt.offset(t as isize); *fresh0 += 1; *fresh0; i += 1; i; } minTurn = 2147483647; maxTurn = -2147483647 - 1; portion = 0; i = 0; while i < base { if *cnt.offset(i as isize) > 0 { portion += 1; portion; } if *cnt.offset(i as isize) < minTurn { minTurn = *cnt.offset(i as isize); } if *cnt.offset(i as isize) > maxTurn { maxTurn = *cnt.offset(i as isize); } i += 1; i; } print!(\" With {} people: \", base); if 0 == minTurn { print!(\"Only {} have a turn\\n\", portion); } else if minTurn == maxTurn { print!(\"{}\\n\", minTurn); } else { print!(\"{} or {}\\n\", minTurn, maxTurn); } free(cnt as *mut libc::c_void); } }" }, { "index": 177, "before": "int turn(int base, int n) { int sum = 0; while (n != 0) { int rem = n % base; n = n / base; sum += rem; } return sum % base; }", "after": "pub extern \"C\" fn turn(mut base: i32, mut n: i32) -> i32 { let mut sum: i32 = 0; while n != 0 { let mut rem: i32 = n % base; n = n / base; sum += rem; } return sum % base; }" }, { "index": 178, "before": "int main() { fairshare(2, 25); fairshare(3, 25); fairshare(5, 25); fairshare(11, 25); printf(\"How many times does each get a turn in 50000 iterations?\\n\"); turnCount(191, 50000); turnCount(1377, 50000); turnCount(49999, 50000); turnCount(50000, 50000); turnCount(50001, 50000); return 0; }", "after": "fn main() -> i32 { fairshare(2, 25); fairshare(3, 25); fairshare(5, 25); fairshare(11, 25); print!(\"How many times does each get a turn in 50000 iterations?\\n\"); turnCount(191, 50000); turnCount(1377, 50000); turnCount(49999, 50000); turnCount(50000, 50000); turnCount(50001, 50000); return 0; }" }, { "index": 179, "before": "int Game_isFinished(void){ int i,j; int k = 1; for ( i = 0; i < NROWS; i++ ) for ( j = 0; j < NCOLLUMNS; j++ ) if ( (k < NROWS*NCOLLUMNS) && (cells[i][j] != k++ ) ) return 0; return 1; }", "after": "pub extern \"C\" fn Game_isFinished() -> i32 { let mut i: i32 = 0; let mut j: i32 = 0; let mut k: i32 = 1; i = 0; unsafe { while i < 4 { j = 0; while j < 4 { if k < 4 * 4 && { let fresh0 = k; k = k + 1; cells[i as usize][j as usize] != fresh0 } { return 0; } j += 1; j; } i += 1; i; } } return 1; }" }, { "index": 180, "before": "enum Move Controller_getMove(void){ int c; for(;;){ printf(\"%s\", \"enter u/d/l/r : \"); c = getchar(); while( getchar() != '\\n' ) ; switch ( c ){ case 27: exit(EXIT_SUCCESS); case 'd' : return MOVE_UP; case 'u' : return MOVE_DOWN; case 'r' : return MOVE_LEFT; case 'l' : return MOVE_RIGHT; } } }", "after": "pub extern \"C\" fn Controller_getMove() -> u32 { let mut c: i32 = 0; unsafe { loop { print!(\"{}\", \"enter u/d/l/r : \\0\"); c = rust_getchar() as i32; while rust_getchar() as i32 != '\\n' as i32 {} match c { 27 => { exit(0); } 100 => return MOVE_UP, 117 => return MOVE_DOWN, 114 => return MOVE_LEFT, 108 => return MOVE_RIGHT, _ => {} } } } }" }, { "index": 181, "before": "void Controller_pause(void){ getchar(); }", "after": "pub extern \"C\" fn Controller_pause() { rust_getchar() as i32; }" }, { "index": 182, "before": "int main(void){ srand((unsigned)time(NULL)); do Game_setup(); while ( Game_isFinished() ); View_showBoard(); while( !Game_isFinished() ){ Game_update( Controller_getMove() ); View_showBoard(); } View_displayMessage(\"You win\"); Controller_pause(); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { srand(rust_time(None) as u32); } loop { Game_setup(); if !(Game_isFinished() != 0) { break; } } View_showBoard(); while Game_isFinished() == 0 { Game_update(Controller_getMove()); View_showBoard(); } View_displayMessage(b\"You win\\0\" as *const u8 as *const i8 as *mut i8); Controller_pause(); return 0; }" }, { "index": 183, "before": "int Game_update(enum Move move){ const int dx[] = { 0, 0, -1, +1 }; const int dy[] = { -1, +1, 0, 0 }; int i = holeRow + dy[move]; int j = holeCollumn + dx[move]; if ( i >= 0 && i < NROWS && j >= 0 && j < NCOLLUMNS ){ cells[holeRow][holeCollumn] = cells[i][j]; cells[i][j] = 0; holeRow = i; holeCollumn = j; return 1; } return 0; }", "after": "pub extern \"C\" fn Game_update(mut move_0: u32) -> i32 { let dx: [i32; 4] = [0, 0, -1, 1]; let dy: [i32; 4] = [-1, 1, 0, 0]; unsafe { let mut i: i32 = holeRow + dy[move_0 as usize]; let mut j: i32 = holeCollumn + dx[move_0 as usize]; if i >= 0 && i < 4 && j >= 0 && j < 4 { cells[holeRow as usize][holeCollumn as usize] = cells[i as usize][j as usize]; cells[i as usize][j as usize] = 0; holeRow = i; holeCollumn = j; return 1; } } return 0; }" }, { "index": 184, "before": "void Game_setup(void){ int i,j,k; for ( i = 0; i < NROWS; i++ ) for ( j = 0; j < NCOLLUMNS; j++ ) cells[i][j] = i * NCOLLUMNS + j + 1; cells[NROWS-1][NCOLLUMNS-1] = 0; holeRow = NROWS - 1; holeCollumn = NCOLLUMNS - 1; k = 0; while ( k < nShuffles ) k += Game_update((enum Move)(rand() % 4)); }", "after": "pub extern \"C\" fn Game_setup() { let mut i: i32 = 0; let mut j: i32 = 0; let mut k: i32 = 0; i = 0; unsafe { while i < 4 { j = 0; while j < 4 { cells[i as usize][j as usize] = i * 4 + j + 1; j += 1; j; } i += 1; i; } cells[(4 - 1i32) as usize][(4 - 1i32) as usize] = 0; holeRow = 4 - 1; holeCollumn = 4 - 1; } k = 0; unsafe { while k < nShuffles { k += Game_update((rand() % 4i32) as u32); } } }" }, { "index": 185, "before": "void View_displayMessage(char* text){ printf(\"\\n%s\\n\", text); }", "after": "pub extern \"C\" fn View_displayMessage(mut text: *mut i8) { unsafe { print!(\"\\n{}\\n\", build_str_from_raw_ptr(text as *mut u8)); } }" }, { "index": 186, "before": "void View_showBoard(){ int i,j; putchar('\\n'); for ( i = 0; i < NROWS; i++ ) for ( j = 0; j < NCOLLUMNS; j++ ){ if ( cells[i][j] ) printf(j != NCOLLUMNS-1 ? \" %2d \" : \" %2d \\n\", cells[i][j]); else printf(j != NCOLLUMNS-1 ? \" %2s \" : \" %2s \\n\", \"\"); } putchar('\\n'); }", "after": "pub extern \"C\" fn View_showBoard() { let mut i: i32 = 0; let mut j: i32 = 0; print!(\"{}\", '\\n' as i32); i = 0; unsafe { while i < 4 { j = 0; while j < 4 { if cells[i as usize][j as usize] != 0 { if j != 4 - 1 { print!(\" {:2} \", cells[i as usize][j as usize]) } else { print!(\" {:2} \\n\", cells[i as usize][j as usize]) }; } else { if j != 4 - 1 { print!(\" {:2} \", \"\\0\") } else { print!(\" {:2} \\n\", \"\\0\") }; } j += 1; j; } i += 1; i; } } print!(\"{}\", '\\n' as i32); }" }, { "index": 187, "before": "void map(int* array, int len, void(*callback)(int,int)) { int i; for(i = 0; i < len; i++) { callback(i, array[i]); } }", "after": "pub extern \"C\" fn map( mut array: *mut i32, mut len: i32, mut callback: Option ()>, ) { unsafe { let mut i: i32 = 0; i = 0; while i < len { callback.expect(\"non-null function pointer\")(i, *array.offset(i as isize)); i += 1; i; } } }" }, { "index": 188, "before": "int main() { int array[] = { 1, 2, 3, 4 }; map(array, 4, callbackFunction); return 0; }", "after": "fn main() -> i32 { let mut array: [i32; 4] = [1, 2, 3, 4]; map( array.as_mut_ptr(), 4, Some(callbackFunction as unsafe extern \"C\" fn(i32, i32) -> ()), ); return 0; }" }, { "index": 189, "before": "static void callbackFunction(int location, int value) { printf(\"array[%d] = %d\\n\", location, value); }", "after": "extern \"C\" fn callbackFunction(mut location: i32, mut value: i32) { print!(\"array[{}] = {}\\n\", location, value); }" }, { "index": 190, "before": "void record(int prev, int curr) { byte pd = prev % 10; byte cd = curr % 10; int i; for (i = 0; i < 100; i++) { int z = 0; if (transitions[i].a == pd) { int t = 0; if (transitions[i].b == cd) { transitions[i].c++; break; } } } }", "after": "pub extern \"C\" fn record(mut prev: i32, mut curr: i32) { let mut pd: u8 = (prev % 10i32) as u8; let mut cd: u8 = (curr % 10i32) as u8; let mut i: i32 = 0; i = 0; unsafe { while i < 100 { let mut z: i32 = 0; if transitions[i as usize].a as i32 == pd as i32 { let mut t: i32 = 0; if transitions[i as usize].b as i32 == cd as i32 { transitions[i as usize].c = (transitions[i as usize].c).wrapping_add(1); transitions[i as usize].c; break; } } i += 1; i; } } }" }, { "index": 191, "before": "int main() { int last_prime = 3, n = 5, count = 2; init(); record(2, 3); while (count < LIMIT) { if (isPrime(n)) { record(last_prime, n); last_prime = n; count++; } n += 2; if (count < LIMIT) { if (isPrime(n)) { record(last_prime, n); last_prime = n; count++; } n += 4; } } printTransitions(LIMIT, last_prime); return 0; }", "after": "fn main() -> i32 { let mut last_prime: i32 = 3; let mut n: i32 = 5; let mut count: i32 = 2; init(); record(2, 3); while count < 1000000 { if isPrime(n) { record(last_prime, n); last_prime = n; count += 1; count; } n += 2; if count < 1000000 { if isPrime(n) { record(last_prime, n); last_prime = n; count += 1; count; } n += 4; } } printTransitions(1000000, last_prime); return 0; }" }, { "index": 192, "before": "void init() { int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { int idx = i * 10 + j; transitions[idx].a = i; transitions[idx].b = j; transitions[idx].c = 0; } } }", "after": "pub extern \"C\" fn init() { let mut i: i32 = 0; let mut j: i32 = 0; i = 0; unsafe { while i < 10 { j = 0; while j < 10 { let mut idx: i32 = i * 10 + j; transitions[idx as usize].a = i as u8; transitions[idx as usize].b = j as u8; transitions[idx as usize].c = 0; j += 1; j; } i += 1; i; } } }" }, { "index": 193, "before": "bool isPrime(int n) { int s, t, a1, a2; if (n % 2 == 0) return n == 2; if (n % 3 == 0) return n == 3; if (n % 5 == 0) return n == 5; if (n % 7 == 0) return n == 7; if (n % 11 == 0) return n == 11; if (n % 13 == 0) return n == 13; if (n % 17 == 0) return n == 17; if (n % 19 == 0) return n == 19; // assuming that addition is faster then multiplication t = 23; a1 = 96; a2 = 216; s = t * t; while (s <= n) { if (n % t == 0) return false; // first increment s += a1; t += 2; a1 += 24; assert(t * t == s); if (s <= n) { if (n % t == 0) return false; // second increment s += a2; t += 4; a2 += 48; assert(t * t == s); } } return true; }", "after": "pub extern \"C\" fn isPrime(mut n: i32) -> bool { let mut s: i32 = 0; let mut t: i32 = 0; let mut a1: i32 = 0; let mut a2: i32 = 0; if n % 2 == 0 { return n == 2; } if n % 3 == 0 { return n == 3; } if n % 5 == 0 { return n == 5; } if n % 7 == 0 { return n == 7; } if n % 11 == 0 { return n == 11; } if n % 13 == 0 { return n == 13; } if n % 17 == 0 { return n == 17; } if n % 19 == 0 { return n == 19; } t = 23; a1 = 96; a2 = 216; s = t * t; unsafe { while s <= n { if n % t == 0 { return 0 != 0; } s += a1; t += 2; a1 += 24; if t * t == s { } else { __assert_fail( b\"t * t == s\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 77, (*::core::mem::transmute::<&[u8; 19], &[i8; 19]>(b\"_Bool isPrime(int)\\0\")) .as_ptr(), ); } 'c_923: { if t * t == s { } else { __assert_fail( b\"t * t == s\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 77, (*::core::mem::transmute::<&[u8; 19], &[i8; 19]>(b\"_Bool isPrime(int)\\0\")) .as_ptr(), ); } }; if s <= n { if n % t == 0 { return 0 != 0; } s += a2; t += 4; a2 += 48; if t * t == s { } else { __assert_fail( b\"t * t == s\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 86, (*::core::mem::transmute::<&[u8; 19], &[i8; 19]>(b\"_Bool isPrime(int)\\0\")) .as_ptr(), ); } 'c_846: { if t * t == s { } else { __assert_fail( b\"t * t == s\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 86, (*::core::mem::transmute::<&[u8; 19], &[i8; 19]>( b\"_Bool isPrime(int)\\0\", )) .as_ptr(), ); } }; } } } return 1 != 0; }" }, { "index": 194, "before": "void printTransitions(int limit, int last_prime) { int i; printf(\"%d primes, last prime considered: %d\\n\", limit, last_prime); for (i = 0; i < 100; i++) { if (transitions[i].c > 0) { printf(\"%d->%d count: %5d frequency: %.2f\\n\", transitions[i].a, transitions[i].b, transitions[i].c, 100.0 * transitions[i].c / limit); } } }", "after": "pub extern \"C\" fn printTransitions(mut limit: i32, mut last_prime: i32) { let mut i: i32 = 0; print!(\"{} primes, last prime considered: {}\\n\", limit, last_prime); i = 0; unsafe { while i < 100 { if transitions[i as usize].c > 0 { print!( \"{}->{} count: {:5} frequency: {:.2}\\n\", transitions[i as usize].a as i32, transitions[i as usize].b as i32, transitions[i as usize].c, 100.0f64 * transitions[i as usize].c as f64 / limit as f64 ); } i += 1; i; } } }" }, { "index": 195, "before": "int irand(int n) { \tint r, rand_max = RAND_MAX - (RAND_MAX % n); \twhile((r = rand()) >= rand_max); \treturn r / (rand_max / n); }", "after": "pub extern \"C\" fn irand(mut n: i32) -> i32 { let mut r: i32 = 0; let mut rand_max: i32 = 2147483647 - 2147483647 % n; unsafe { loop { r = rand(); if !(r >= rand_max) { break; } } } return r / (rand_max / n); }" }, { "index": 196, "before": "int unfitness(const char *a, const char *b) { \tint i, sum = 0; \tfor (i = 0; a[i]; i++) \t\tsum += (a[i] != b[i]); \treturn sum; }", "after": "pub extern \"C\" fn unfitness(mut a: *const i8, mut b: *const i8) -> i32 { unsafe { let mut i: i32 = 0; let mut sum: i32 = 0; i = 0; while *a.offset(i as isize) != 0 { sum += (*a.offset(i as isize) as i32 != *b.offset(i as isize) as i32) as i32; i += 1; i; } return sum; } }" }, { "index": 197, "before": "void mutate(const char *a, char *b) { \tint i; \tfor (i = 0; a[i]; i++) \t\tb[i] = irand(MUTATE) ? a[i] : tbl[irand(CHOICE)]; \tb[i] = '\\0'; }", "after": "pub extern \"C\" fn mutate(mut a: *const i8, mut b: *mut i8) { unsafe { let mut i: i32 = 0; i = 0; while *a.offset(i as isize) != 0 { *b.offset(i as isize) = (if irand(15) != 0 { *a.offset(i as isize) as i32 } else { tbl[irand((::core::mem::size_of::<[i8; 28]>() as u64).wrapping_sub(1) as i32) as usize] as i32 }) as i8; i += 1; i; } *b.offset(i as isize) = '\\0' as i8; } }" }, { "index": 198, "before": "int main() { \tint i, best_i, unfit, best, iters = 0; \tchar specimen[COPIES][sizeof(target) / sizeof(char)]; \t/* init rand string */ \tfor (i = 0; target[i]; i++) \t\tspecimen[0][i] = tbl[irand(CHOICE)]; \tspecimen[0][i] = 0; \tdo { \t\tfor (i = 1; i < COPIES; i++) \t\t\tmutate(specimen[0], specimen[i]); \t\t/* find best fitting string */ \t\tfor (best_i = i = 0; i < COPIES; i++) { \t\t\tunfit = unfitness(target, specimen[i]); \t\t\tif(unfit < best || !i) { \t\t\t\tbest = unfit; \t\t\t\tbest_i = i; \t\t\t} \t\t} \t\tif (best_i) strcpy(specimen[0], specimen[best_i]); \t\tprintf(\"iter %d, score %d: %s\\n\", iters++, best, specimen[0]); \t} while (best); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut best_i: i32 = 0; let mut unfit: i32 = 0; let mut best: i32 = 0; let mut iters: i32 = 0; let mut specimen: [[i8; 29]; 30] = [[0; 29]; 30]; i = 0; unsafe { while target[i as usize] != 0 { specimen[0 as usize][i as usize] = tbl[irand((::core::mem::size_of::<[i8; 28]>() as u64).wrapping_sub(1) as i32) as usize]; i += 1; i; } } specimen[0 as usize][i as usize] = 0; unsafe { loop { i = 1; while i < 30 { mutate( (specimen[0 as usize]).as_mut_ptr(), (specimen[i as usize]).as_mut_ptr(), ); i += 1; i; } i = 0; best_i = i; while i < 30 { unfit = unfitness(target.as_ptr(), (specimen[i as usize]).as_mut_ptr()); if unfit < best || i == 0 { best = unfit; best_i = i; } i += 1; i; } if best_i != 0 { strcpy( (specimen[0 as usize]).as_mut_ptr(), (specimen[best_i as usize]).as_mut_ptr(), ); } let fresh0 = iters; iters = iters + 1; print!( \"iter {}, score {}: {}\\n\", fresh0, best, build_str_from_raw_ptr((specimen[0 as usize]).as_mut_ptr() as *mut u8) ); if !(best != 0) { break; } } } return 0; }" }, { "index": 199, "before": "int main() { \tint police,sanitation,fire; \tprintf(\"Police Sanitation Fire\\n\"); \tprintf(\"----------------------------------\"); \tfor(police=2;police<=6;police+=2){ \t\tfor(sanitation=1;sanitation<=7;sanitation++){ \t\t\tfor(fire=1;fire<=7;fire++){ \t\t\t\tif(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ \t\t\t\t\tprintf(\"\\n%d\\t\\t%d\\t\\t%d\",police,sanitation,fire); \t\t\t\t} \t\t\t} \t\t} \t} \treturn 0; }", "after": "fn main() -> i32 { let mut police: i32 = 0; let mut sanitation: i32 = 0; let mut fire: i32 = 0; print!(\"Police Sanitation Fire\\n\"); print!(\"----------------------------------\"); police = 2; while police <= 6 { sanitation = 1; while sanitation <= 7 { fire = 1; while fire <= 7 { if police != sanitation && sanitation != fire && fire != police && police + fire + sanitation == 12 { print!(\"\\n{}\t\t{}\t\t{}\", police, sanitation, fire); } fire += 1; fire; } sanitation += 1; sanitation; } police += 2; } return 0; }" }, { "index": 200, "before": "void go(uint64_t a, uint64_t b) { \tuint64_t x, y; \tx = egyptian_division(a, b, &y); \tprintf(\"%llu / %llu = %llu remainder %llu\\n\", a, b, x, y); \tassert(a == b * x + y); }", "after": "pub extern \"C\" fn go(mut a: u64, mut b: u64) { let mut x: u64 = 0; let mut y: u64 = 0; x = egyptian_division(a, b, &mut y); print!(\"{} / {} = {} remainder {}\\n\", a, b, x, y); unsafe { if a == b.wrapping_mul(x).wrapping_add(y) { } else { __assert_fail( b\"a == b * x + y\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 43, (*::core::mem::transmute::<&[u8; 28], &[i8; 28]>(b\"void go(uint64_t, uint64_t)\\0\")) .as_ptr(), ); } 'c_1638: { if a == b.wrapping_mul(x).wrapping_add(y) { } else { __assert_fail( b\"a == b * x + y\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 43, (*::core::mem::transmute::<&[u8; 28], &[i8; 28]>( b\"void go(uint64_t, uint64_t)\\0\", )) .as_ptr(), ); } }; } }" }, { "index": 201, "before": "uint64_t egyptian_division(uint64_t dividend, uint64_t divisor, uint64_t *remainder) { \t// remainder is an out parameter, pass NULL if you do not need the remainder \tstatic uint64_t powers[64]; \tstatic uint64_t doublings[64]; \tint i; \tfor(i = 0; i < 64; i++) { \t\tpowers[i] = 1 << i; \t\tdoublings[i] = divisor << i; \t\tif(doublings[i] > dividend) \t\t\tbreak; \t} \tuint64_t answer = 0; \tuint64_t accumulator = 0; \tfor(i = i - 1; i >= 0; i--) { \t\t// If the current value of the accumulator added to the \t\t// doublings cell would be less than or equal to the \t\t// dividend then add it to the accumulator \t\tif(accumulator + doublings[i] <= dividend) { \t\t\taccumulator += doublings[i]; \t\t\tanswer += powers[i]; \t\t} \t} \tif(remainder) \t\t*remainder = dividend - accumulator; \treturn answer; }", "after": "pub extern \"C\" fn egyptian_division( mut dividend: u64, mut divisor: u64, mut remainder: *mut u64, ) -> u64 { unsafe { static mut powers: [u64; 64] = [0; 64]; static mut doublings: [u64; 64] = [0; 64]; let mut i: i32 = 0; i = 0; while i < 64 { powers[i as usize] = (1i32 << i) as u64; doublings[i as usize] = divisor << i; if doublings[i as usize] > dividend { break; } i += 1; i; } let mut answer: u64 = 0; let mut accumulator: u64 = 0; i = i - 1; while i >= 0 { if accumulator.wrapping_add(doublings[i as usize]) <= dividend { accumulator = (accumulator).wrapping_add(doublings[i as usize]) as u64; answer = (answer).wrapping_add(powers[i as usize]) as u64; } i -= 1; i; } if !remainder.is_null() { *remainder = dividend.wrapping_sub(accumulator); } return answer; } }" }, { "index": 202, "before": "int main(void) { \tgo(580, 32); }", "after": "fn main() -> i32 { go(580, 32); return 0; }" }, { "index": 203, "before": "int main() { char is_open[100] = { 0 }; int pass, door; /* do the 100 passes */ for (pass = 0; pass < 100; ++pass) for (door = pass; door < 100; door += pass+1) is_open[door] = !is_open[door]; /* output the result */ for (door = 0; door < 100; ++door) printf(\"door #%d is %s.\\n\", door+1, (is_open[door]? \"open\" : \"closed\")); return 0; }", "after": "fn main() -> i32 { let mut is_open: [i8; 100] = [0; 100]; let mut pass: i32 = 0; let mut door: i32 = 0; pass = 0; while pass < 100 { door = pass; while door < 100 { is_open[door as usize] = (is_open[door as usize] == 0) as i8; door += pass + 1; } pass += 1; pass; } door = 0; while door < 100 { if is_open[door as usize] as i32 != 0 { print!(\"door #{} is {}.\\n\", door + 1, \"open\\0\") } else { print!(\"door #{} is {}.\\n\", door + 1, \"closed\\0\") }; door += 1; door; } return 0; }" }, { "index": 204, "before": "int main() { char * result = string_repeat(5, \"ha\"); puts(result); free(result); return 0; }", "after": "fn main() -> i32 { unsafe { let mut result: *mut i8 = string_repeat(5, b\"ha\\0\" as *const u8 as *const i8); puts(result); free(result as *mut libc::c_void); return 0; } }" }, { "index": 205, "before": "void insert(struct node **rootp, int value) { \tstruct node *root = *rootp; \tif (root == nnil) \t\t*rootp = new_node(value); \telse if (value != root->payload) \t{ // don't allow dup keys \t\tinsert(&root->kid[value > root->payload], value); \t\tadjust_balance(rootp); \t} }", "after": "pub extern \"C\" fn insert(mut rootp: *mut *mut node, mut value: i32) { unsafe { let mut root: *mut node = *rootp; if root == nnil { *rootp = new_node(value); } else if value != (*root).payload { insert( &mut *((*root).kid) .as_mut_ptr() .offset((value > (*root).payload) as i32 as isize), value, ); adjust_balance(rootp); } } }" }, { "index": 206, "before": "int max(int a, int b) { return a > b ? a : b; }", "after": "pub extern \"C\" fn max(mut a: i32, mut b: i32) -> i32 { return if a > b { a } else { b }; }" }, { "index": 207, "before": "void show_tree(struct node *root, struct trunk *prev, int is_left) { \tif (root == nnil) \t\treturn; \tstruct trunk this_disp = {prev, \" \"}; \tchar *prev_str = this_disp.str; \tshow_tree(root->kid[0], &this_disp, 1); \tif (!prev) \t\tthis_disp.str = \"---\"; \telse if (is_left) \t{ \t\tthis_disp.str = \".--\"; \t\tprev_str = \" |\"; \t} \telse \t{ \t\tthis_disp.str = \"`--\"; \t\tprev->str = prev_str; \t} \tshow_trunks(&this_disp); \tprintf(\"%d\\n\", root->payload); \tif (prev) \t\tprev->str = prev_str; \tthis_disp.str = \" |\"; \tshow_tree(root->kid[1], &this_disp, 0); \tif (!prev) \t\tputs(\"\"); }", "after": "pub extern \"C\" fn show_tree(mut root: *mut node, mut prev: *mut trunk, mut is_left: i32) { unsafe { if root == nnil { return; } let mut this_disp: trunk = { let mut init = trunk { prev: prev, str_0: b\" \\0\" as *const u8 as *const i8 as *mut i8, }; init }; let mut prev_str: *mut i8 = this_disp.str_0; show_tree((*root).kid[0 as usize], &mut this_disp, 1); if prev.is_null() { this_disp.str_0 = b\"---\\0\" as *const u8 as *const i8 as *mut i8; } else if is_left != 0 { this_disp.str_0 = b\".--\\0\" as *const u8 as *const i8 as *mut i8; prev_str = b\" |\\0\" as *const u8 as *const i8 as *mut i8; } else { this_disp.str_0 = b\"`--\\0\" as *const u8 as *const i8 as *mut i8; (*prev).str_0 = prev_str; } show_trunks(&mut this_disp); print!(\"{}\\n\", (*root).payload); if !prev.is_null() { (*prev).str_0 = prev_str; } this_disp.str_0 = b\" |\\0\" as *const u8 as *const i8 as *mut i8; show_tree((*root).kid[1 as usize], &mut this_disp, 0); if prev.is_null() { puts(b\"\\0\" as *const u8 as *const i8); } } }" }, { "index": 208, "before": "int main(void) { \tint x; \tstruct node *root = nnil; \tsrand(time(0)); \tfor (x = 0; x < 10 * MAX_VAL; x++) \t{ \t\t// random insertion and deletion \t\tif (rand() & 1) \t\t\tinsert(&root, rand() % MAX_VAL); \t\telse \t\t\tdelete (&root, rand() % MAX_VAL); \t\tverify(root); \t} \tputs(\"Tree is:\"); \tshow_tree(root, 0, 0); \tputs(\"\\nQuerying values:\"); \tfor (x = 0; x < MAX_VAL; x++) \t{ \t\tstruct node *p = query(root, x); \t\tif (p) \t\t\tprintf(\"%2d found: %p %d\\n\", x, p, p->payload); \t} \tfor (x = 0; x < MAX_VAL; x++) \t{ \t\tdelete (&root, x); \t\tverify(root); \t} \tputs(\"\\nAfter deleting all values, tree is:\"); \tshow_tree(root, 0, 0); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut x: i32 = 0; let mut root: *mut node = nnil; srand(rust_time(None) as u32); x = 0; while x < 10 * 32 { if rand() & 1 != 0 { insert(&mut root, rand() % 32); } else { delete(&mut root, rand() % 32); } verify(root); x += 1; x; } puts(b\"Tree is:\\0\" as *const u8 as *const i8); show_tree(root, 0 as *mut trunk, 0); puts(b\"\\nQuerying values:\\0\" as *const u8 as *const i8); x = 0; while x < 32 { let mut p: *mut node = query(root, x); if !p.is_null() { print!(\"{:2} found: {:p} {}\\n\", x, p, (*p).payload); } x += 1; x; } x = 0; while x < 32 { delete(&mut root, x); verify(root); x += 1; x; } puts(b\"\\nAfter deleting all values, tree is:\\0\" as *const u8 as *const i8); show_tree(root, 0 as *mut trunk, 0); return 0; } }" }, { "index": 209, "before": "void delete (struct node **rootp, int value) { \tstruct node *root = *rootp; \tif (root == nnil) \t\treturn; // not found \t// if this is the node we want, rotate until off the tree \tif (root->payload == value) \t\tif (nnil == (root = rotate(rootp, ballance(root) < 0))) \t\t\treturn; \tdelete (&root->kid[value > root->payload], value); \tadjust_balance(rootp); }", "after": "pub extern \"C\" fn delete(mut rootp: *mut *mut node, mut value: i32) { unsafe { let mut root: *mut node = *rootp; if root == nnil { return; } if (*root).payload == value { root = rotate(rootp, (ballance(root) < 0) as i32); if nnil == root { return; } } delete( &mut *((*root).kid) .as_mut_ptr() .offset((value > (*root).payload) as i32 as isize), value, ); adjust_balance(rootp); } }" }, { "index": 210, "before": "int ballance(struct node *n) { \treturn n->kid[0]->height - n->kid[1]->height; }", "after": "pub extern \"C\" fn ballance(mut n: *mut node) -> i32 { unsafe { return (*(*n).kid[0 as usize]).height - (*(*n).kid[1 as usize]).height; } }" }, { "index": 211, "before": "void adjust_balance(struct node **rootp) { \tstruct node *root = *rootp; \tint b = ballance(root) / 2; \tif (b) \t{ \t\tint dir = (1 - b) / 2; \t\tif (ballance(root->kid[dir]) == -b) \t\t\trotate(&root->kid[dir], !dir); \t\troot = rotate(rootp, dir); \t} \tif (root != nnil) \t\tset_height(root); }", "after": "pub extern \"C\" fn adjust_balance(mut rootp: *mut *mut node) { unsafe { let mut root: *mut node = *rootp; let mut b: i32 = ballance(root) / 2; if b != 0 { let mut dir: i32 = (1 - b) / 2; if ballance((*root).kid[dir as usize]) == -b { rotate( &mut *((*root).kid).as_mut_ptr().offset(dir as isize), (dir == 0) as i32, ); } root = rotate(rootp, dir); } if root != nnil { set_height(root); } } }" }, { "index": 212, "before": "void set_height(struct node *n) { \tn->height = 1 + max(n->kid[0]->height, n->kid[1]->height); }", "after": "pub extern \"C\" fn set_height(mut n: *mut node) { unsafe { (*n).height = 1 + max( (*(*n).kid[0 as usize]).height, (*(*n).kid[1 as usize]).height, ); } }" }, { "index": 213, "before": "void show_trunks(struct trunk *p) { \tif (!p) \t\treturn; \tshow_trunks(p->prev); \tprintf(\"%s\", p->str); }", "after": "pub extern \"C\" fn show_trunks(mut p: *mut trunk) { unsafe { if p.is_null() { return; } show_trunks((*p).prev); print!(\"{}\", build_str_from_raw_ptr((*p).str_0 as *mut u8)); } }" }, { "index": 214, "before": "int verify(struct node *p) { \tif (p == nnil) \t\treturn 1; \tint h0 = p->kid[0]->height, h1 = p->kid[1]->height; \tint b = h0 - h1; \tif (p->height != 1 + max(h0, h1) || b < -1 || b > 1) \t{ \t\tprintf(\"node %d bad, balance %d\\n\", p->payload, b); \t\tshow_tree(p, 0, 0); \t\tabort(); \t} \treturn verify(p->kid[0]) && verify(p->kid[1]); }", "after": "pub extern \"C\" fn verify(mut p: *mut node) -> i32 { unsafe { if p == nnil { return 1; } let mut h0: i32 = (*(*p).kid[0 as usize]).height; let mut h1: i32 = (*(*p).kid[1 as usize]).height; let mut b: i32 = h0 - h1; if (*p).height != 1 + max(h0, h1) || b < -1 || b > 1 { print!(\"node {} bad, balance {}\\n\", (*p).payload, b); show_tree(p, 0 as *mut trunk, 0); abort(); } return (verify((*p).kid[0 as usize]) != 0 && verify((*p).kid[1 as usize]) != 0) as i32; } }" }, { "index": 215, "before": "int main(int argc, char **argv) { int a[] = {-1 , -2 , 3 , 5 , 6 , -2 , -1 , 4 , -4 , 2 , -1}; int alength = sizeof(a)/sizeof(a[0]); Range r = maxSubseq(a, alength); printf(\"Max sum = %d\\n\", r.sum); int i; for (i = r.start; i < r.end; i++) printf(\"%d \", a[i]); printf(\"\\n\"); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut a: [i32; 11] = [-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1]; let mut alength: i32 = (::core::mem::size_of::<[i32; 11]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32; let mut r: Range = maxSubseq(a.as_mut_ptr() as *const i32, alength); print!(\"Max sum = {}\\n\", r.sum); let mut i: i32 = 0; i = r.start; while i < r.end { print!(\"{} \", a[i as usize]); i += 1; i; } print!(\"\\n\"); return 0; } }" }, { "index": 216, "before": "Range maxSubseq(const int sequence[], const int len) { int maxSum = 0, thisSum = 0, i = 0; int start = 0, end = -1, j; for (j = 0; j < len; j++) { thisSum += sequence[j]; if (thisSum < 0) { i = j + 1; thisSum = 0; } else if (thisSum > maxSum) { maxSum = thisSum; start = i; end = j; } } Range r; if (start <= end && start >= 0 && end >= 0) { r.start = start; r.end = end + 1; r.sum = maxSum; } else { r.start = 0; r.end = 0; r.sum = 0; } return r; }", "after": "pub extern \"C\" fn maxSubseq(mut sequence: *const i32, len: i32) -> Range { unsafe { let mut maxSum: i32 = 0; let mut thisSum: i32 = 0; let mut i: i32 = 0; let mut start: i32 = 0; let mut end: i32 = -1; let mut j: i32 = 0; j = 0; while j < len { thisSum += *sequence.offset(j as isize); if thisSum < 0 { i = j + 1; thisSum = 0; } else if thisSum > maxSum { maxSum = thisSum; start = i; end = j; } j += 1; j; } let mut r: Range = Range { start: 0, end: 0, sum: 0, }; if start <= end && start >= 0 && end >= 0 { r.start = start; r.end = end + 1; r.sum = maxSum; } else { r.start = 0; r.end = 0; r.sum = 0; } return r; } }" }, { "index": 217, "before": "float median(FloatList fl) { qsort(fl->list, fl->size, sizeof(float), floatcmp); return 0.5 * (fl->list[fl->size / 2] + fl->list[(fl->size - 1) / 2]); }", "after": "pub extern \"C\" fn median(mut fl: FloatList) -> libc::c_float { unsafe { qsort( (*fl).list as *mut libc::c_void, (*fl).size as u64, ::core::mem::size_of::() as u64, Some(floatcmp as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32), ); return (0.5f64 * (*((*fl).list).offset(((*fl).size / 2i32) as isize) + *((*fl).list).offset((((*fl).size - 1i32) / 2i32) as isize)) as f64) as libc::c_float; } }" }, { "index": 218, "before": "int main() { float floats1[] = {5.1, 2.6, 6.2, 8.8, 4.6, 4.1}; struct floatList flist1 = {floats1, sizeof(floats1) / sizeof(float)}; float floats2[] = {5.1, 2.6, 8.8, 4.6, 4.1}; struct floatList flist2 = {floats2, sizeof(floats2) / sizeof(float)}; printf(\"flist1 median is %7.2f\\n\", median(&flist1)); /* 4.85 */ printf(\"flist2 median is %7.2f\\n\", median(&flist2)); /* 4.60 */ return 0; }", "after": "fn main() -> i32 { let mut floats1: [libc::c_float; 6] = [ 5.1f64 as libc::c_float, 2.6f64 as libc::c_float, 6.2f64 as libc::c_float, 8.8f64 as libc::c_float, 4.6f64 as libc::c_float, 4.1f64 as libc::c_float, ]; let mut flist1: floatList = { let mut init = floatList { list: floats1.as_mut_ptr(), size: (::core::mem::size_of::<[libc::c_float; 6]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, }; init }; let mut floats2: [libc::c_float; 5] = [ 5.1f64 as libc::c_float, 2.6f64 as libc::c_float, 8.8f64 as libc::c_float, 4.6f64 as libc::c_float, 4.1f64 as libc::c_float, ]; let mut flist2: floatList = { let mut init = floatList { list: floats2.as_mut_ptr(), size: (::core::mem::size_of::<[libc::c_float; 5]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, }; init }; print!(\"flist1 median is {:7.2}\\n\", median(&mut flist1) as f64); print!(\"flist2 median is {:7.2}\\n\", median(&mut flist2) as f64); return 0; }" }, { "index": 219, "before": "int floatcmp(const void *a, const void *b) { if (*(const float *)a < *(const float *)b) return -1; else return *(const float *)a > *(const float *)b; }", "after": "pub extern \"C\" fn floatcmp(mut a: *const libc::c_void, mut b: *const libc::c_void) -> i32 { unsafe { if *(a as *const libc::c_float) < *(b as *const libc::c_float) { return -1; } else { return (*(a as *const libc::c_float) > *(b as *const libc::c_float)) as i32; }; } }" }, { "index": 220, "before": "int main(int argc, char const *argv[]) { mpz_t fermat; mpz_init_set_ui(fermat, 3); printf(\"F(0) = 3 -> PRIME\\n\"); for (unsigned i = 1; i < 7; i++) { mpz_sub_ui(fermat, fermat, 1); mpz_mul(fermat, fermat, fermat); mpz_add_ui(fermat, fermat, 1); gmp_printf(\"F(%d) = %Zd -> \", i, fermat); mpz_factors(fermat); } return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *const i8) -> i32 { unsafe { print!(\"F(0) = 3 -> PRIME\\n\"); let mut i: u32 = 1; while i < 7 { i = i.wrapping_add(1); i; } return 0; } }" }, { "index": 221, "before": "int DuplicateDeck( int **dest, const int *orig, int nCards ) { if( orig != NULL && CreateDeck(dest,nCards) ) { memcpy( *dest, orig, nCards*sizeof(*orig) ); return 1; /* success */ } else { return 0; /* failure */ } }", "after": "pub extern \"C\" fn DuplicateDeck( mut dest: *mut *mut i32, mut orig: *const i32, mut nCards: i32, ) -> i32 { unsafe { if !orig.is_null() && CreateDeck(dest, nCards) != 0 { memcpy( *dest as *mut libc::c_void, orig as *const libc::c_void, (nCards as u64).wrapping_mul(::core::mem::size_of::() as u64), ); return 1; } else { return 0; }; } }" }, { "index": 222, "before": "void FreeDeck( int **deck ) { if( *deck != NULL ) { free( *deck ); *deck = NULL; } }", "after": "pub extern \"C\" fn FreeDeck(mut deck: *mut *mut i32) { unsafe { if !(*deck).is_null() { free(*deck as *mut libc::c_void); *deck = 0 as *mut i32; } } }" }, { "index": 223, "before": "int ShuffleDeck( int *deck, int nCards ) { int *copy = NULL; if( DuplicateDeck(©,deck,nCards) ) { int i, j; for( i=j=0; i i32 { unsafe { let mut copy: *mut i32 = 0 as *mut i32; if DuplicateDeck(&mut copy, deck, nCards) != 0 { let mut i: i32 = 0; let mut j: i32 = 0; j = 0; i = j; while i < nCards / 2 { *deck.offset(j as isize) = *copy.offset(i as isize); *deck.offset((j + 1i32) as isize) = *copy.offset((i + nCards / 2i32) as isize); i += 1; i; j += 2; } FreeDeck(&mut copy); return 1; } else { return 0; }; } }" }, { "index": 224, "before": "int CreateDeck( int **deck, int nCards ) { int *tmp = NULL; if( deck != NULL ) tmp = malloc( nCards*sizeof(*tmp) ); return tmp!=NULL ? (*deck=tmp)!=NULL : 0; /* (?success) (:failure) */ }", "after": "pub extern \"C\" fn CreateDeck(mut deck: *mut *mut i32, mut nCards: i32) -> i32 { unsafe { let mut tmp: *mut i32 = 0 as *mut i32; if !deck.is_null() { tmp = malloc((nCards as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i32; } return if !tmp.is_null() { *deck = tmp; (*deck != 0 as *mut libc::c_void as *mut i32) as i32 } else { 0 }; } }" }, { "index": 225, "before": "int main() { int i, nCards, nShuffles; int *deck = NULL; for( i=0; i i32 { unsafe { let mut i: i32 = 0; let mut nCards: i32 = 0; let mut nShuffles: i32 = 0; let mut deck: *mut i32 = 0 as *mut i32; i = 0; while i < 7 { nCards = kDecks[i as usize]; if CreateDeck(&mut deck, nCards) == 0 { fprintf( stderr, b\"Error: malloc() failed!\\n\\0\" as *const u8 as *const i8, ); return 1; } InitDeck(deck, nCards); nShuffles = 0; loop { ShuffleDeck(deck, nCards); nShuffles += 1; nShuffles; if !(InitedDeck(deck, nCards) == 0) { break; } } print!( \"Cards count: {}, shuffles required: {}.\\n\", nCards, nShuffles ); FreeDeck(&mut deck); i += 1; i; } return 0; } }" }, { "index": 226, "before": "void InitDeck( int *deck, int nCards ) { if( deck != NULL ) { int i; for( i=0; i i32 { unsafe { let mut i: i32 = 0; i = 0; while i < nCards { if *deck.offset(i as isize) != i { return 0; } i += 1; i; } return 1; } }" }, { "index": 228, "before": "int main(){ int bounds[ 2 ] = {1, 100}; char input[ 2 ] = \" \"; /* second char is for the newline from hitting [return] */ int choice = (bounds[ 0 ] + bounds[ 1 ]) / 2; /* using a binary search */ printf( \"Choose a number between %d and %d.\\n\", bounds[ 0 ], bounds[ 1 ] ); do{ switch( input[ 0 ] ){ case 'H': bounds[ 1 ] = choice; break; case 'L': bounds[ 0 ] = choice; break; case 'Y': printf( \"\\nAwwwright\\n\" ); return 0; } choice = (bounds[ 0 ] + bounds[ 1 ]) / 2; printf( \"Is the number %d? (Y/H/L) \", choice ); }while( scanf( \"%1s\", input ) == 1 ); return 0; }", "after": "fn main() -> i32 { let mut bounds: [i32; 2] = [1, 100]; unsafe { let mut input: [i8; 2] = *::core::mem::transmute::<&[u8; 2], &mut [i8; 2]>(b\" \"); let mut choice: i32 = (bounds[0 as usize] + bounds[1 as usize]) / 2; print!( \"Choose a number between {} and {}.\\n\", bounds[0 as usize], bounds[1 as usize] ); loop { match input[0 as usize] as i32 { 72 => { bounds[1 as usize] = choice; } 76 => { bounds[0 as usize] = choice; } 89 => { print!(\"\\nAwwwright\\n\"); return 0; } _ => {} } choice = (bounds[0 as usize] + bounds[1 as usize]) / 2; print!(\"Is the number {}? (Y/H/L) \", choice); if !(scanf(b\"%1s\\0\" as *const u8 as *const i8, input.as_mut_ptr()) == 1) { break; } } } return 0; }" }, { "index": 229, "before": "int catcmp(const void *a, const void *b) { \tchar ab[32], ba[32]; \tsprintf(ab, \"%d%d\", *(int*)a, *(int*)b); \tsprintf(ba, \"%d%d\", *(int*)b, *(int*)a); \treturn strcmp(ba, ab); }", "after": "pub extern \"C\" fn catcmp(mut a: *const libc::c_void, mut b: *const libc::c_void) -> i32 { unsafe { let mut ab: [i8; 32] = [0; 32]; let mut ba: [i8; 32] = [0; 32]; sprintf( ab.as_mut_ptr(), b\"%d%d\\0\" as *const u8 as *const i8, *(a as *mut i32), *(b as *mut i32), ); sprintf( ba.as_mut_ptr(), b\"%d%d\\0\" as *const u8 as *const i8, *(b as *mut i32), *(a as *mut i32), ); return strcmp(ba.as_mut_ptr(), ab.as_mut_ptr()); } }" }, { "index": 230, "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": "fn main() -> i32 { let mut x: [i32; 8] = [1, 34, 3, 98, 9, 76, 45, 4]; let mut y: [i32; 4] = [54, 546, 548, 60]; maxcat( x.as_mut_ptr(), (::core::mem::size_of::<[i32; 8]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, ); maxcat( y.as_mut_ptr(), (::core::mem::size_of::<[i32; 4]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, ); return 0; }" }, { "index": 231, "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 extern \"C\" fn maxcat(mut a: *mut i32, mut len: i32) { unsafe { let mut i: i32 = 0; qsort( a as *mut libc::c_void, len as u64, ::core::mem::size_of::() as u64, Some(catcmp as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32), ); i = 0; while i < len { print!(\"{}\", *a.offset(i as isize)); i += 1; i; } print!(\"{}\", '\\n' as i32); } }" }, { "index": 232, "before": "void output(stream out, unsigned char* buf, int len) { \tint i; \tout->put(out, 128 + len); \tfor (i = 0; i < len; i++) \t\tout->put(out, buf[i]); }", "after": "pub extern \"C\" fn output(mut out: stream, mut buf: *mut u8, mut len: i32) { unsafe { let mut i: i32 = 0; ((*out).put).expect(\"non-null function pointer\")(out, 128 + len); i = 0; while i < len { ((*out).put).expect(\"non-null function pointer\")(out, *buf.offset(i as isize) as i32); i += 1; i; } } }" }, { "index": 233, "before": "void encode(stream in, stream out) { \tunsigned char buf[256]; \tint len = 0, repeat = 0, end = 0, c; \tint (*get)(stream) = in->get; \tint (*put)(stream, int) = out->put; \twhile (!end) { \t\tend = ((c = get(in)) == -1); \t\tif (!end) { \t\t\tbuf[len++] = c; \t\t\tif (len <= 1) continue; \t\t} \t\tif (repeat) { \t\t\tif (buf[len - 1] != buf[len - 2]) \t\t\t\trepeat = 0; \t\t\tif (!repeat || len == 129 || end) { \t\t\t\t/* write out repeating bytes */ \t\t\t\tput(out, end ? len : len - 1); \t\t\t\tput(out, buf[0]); \t\t\t\tbuf[0] = buf[len - 1]; \t\t\t\tlen = 1; \t\t\t} \t\t} else { \t\t\tif (buf[len - 1] == buf[len - 2]) { \t\t\t\trepeat = 1; \t\t\t\tif (len > 2) { \t\t\t\t\toutput(out, buf, len - 2); \t\t\t\t\tbuf[0] = buf[1] = buf[len - 1]; \t\t\t\t\tlen = 2; \t\t\t\t} \t\t\t\tcontinue; \t\t\t} \t\t\tif (len == 128 || end) { \t\t\t\toutput(out, buf, len); \t\t\t\tlen = 0; \t\t\t\trepeat = 0; \t\t\t} \t\t} \t} \tput(out, -1); }", "after": "pub extern \"C\" fn encode(mut in_0: stream, mut out: stream) { let mut buf: [u8; 256] = [0; 256]; let mut len: i32 = 0; let mut repeat: i32 = 0; let mut end: i32 = 0; let mut c: i32 = 0; unsafe { let mut get: Option i32> = (*in_0).get; let mut put: Option i32> = (*out).put; while end == 0 { c = get.expect(\"non-null function pointer\")(in_0); end = (c == -1) as i32; if end == 0 { let fresh1 = len; len = len + 1; buf[fresh1 as usize] = c as u8; if len <= 1 { continue; } } if repeat != 0 { if buf[(len - 1i32) as usize] as i32 != buf[(len - 2i32) as usize] as i32 { repeat = 0; } if repeat == 0 || len == 129 || end != 0 { put.expect(\"non-null function pointer\")( out, if end != 0 { len } else { len - 1 }, ); put.expect(\"non-null function pointer\")(out, buf[0 as usize] as i32); buf[0 as usize] = buf[(len - 1i32) as usize]; len = 1; } } else if buf[(len - 1i32) as usize] as i32 == buf[(len - 2i32) as usize] as i32 { repeat = 1; if len > 2 { output(out, buf.as_mut_ptr(), len - 2); buf[1 as usize] = buf[(len - 1i32) as usize]; buf[0 as usize] = buf[1 as usize]; len = 2; } } else if len == 128 || end != 0 { output(out, buf.as_mut_ptr(), len); len = 0; repeat = 0; } } put.expect(\"non-null function pointer\")(out, -1); } }" }, { "index": 234, "before": "int main() { \tchar buf[256]; \tstring_stream str_in = { sget, 0, \t\t\"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW\", 0}; \tstring_stream str_out = { sget, sput, buf, 0 }; \tfile_stream file = { 0, file_put, stdout }; \t/* encode from str_in to str_out */ \tencode((stream)&str_in, (stream)&str_out); \t/* decode from str_out to file (stdout) */ \tdecode((stream)&str_out, (stream)&file); \treturn 0; }", "after": "fn main() -> i32 { let mut buf: [i8; 256] = [0; 256]; unsafe { let mut str_in: string_stream = { let mut init = string_stream { get: Some(sget as unsafe extern \"C\" fn(stream) -> i32), put: None, string: b\"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW\\0\" as *const u8 as *const i8 as *mut i8, pos: 0, }; init }; let mut str_out: string_stream = { let mut init = string_stream { get: Some(sget as unsafe extern \"C\" fn(stream) -> i32), put: Some(sput as unsafe extern \"C\" fn(stream, i32) -> i32), string: buf.as_mut_ptr(), pos: 0, }; init }; let mut file: file_stream = { let mut init = file_stream { get: None, put: Some(file_put as unsafe extern \"C\" fn(stream, i32) -> i32), fp: stdout, }; init }; encode( &mut str_in as *mut string_stream as stream, &mut str_out as *mut string_stream as stream, ); decode( &mut str_out as *mut string_stream as stream, &mut file as *mut file_stream as stream, ); } return 0; }" }, { "index": 235, "before": "int file_put(stream out, int c) { \tfile_stream *f = (file_stream*) out; \treturn fputc(c, f->fp); }", "after": "pub extern \"C\" fn file_put(mut out: stream, mut c: i32) -> i32 { unsafe { let mut f: *mut file_stream = out as *mut file_stream; return fputc(c, (*f).fp); } }" }, { "index": 236, "before": "void decode(stream in, stream out) { \tint c, i, cnt; \twhile (1) { \t\tc = in->get(in); \t\tif (c == -1) return; \t\tif (c > 128) { \t\t\tcnt = c - 128; \t\t\tfor (i = 0; i < cnt; i++) \t\t\t\tout->put(out, in->get(in)); \t\t} else { \t\t\tcnt = c; \t\t\tc = in->get(in); \t\t\tfor (i = 0; i < cnt; i++) \t\t\t\tout->put(out, c); \t\t} \t} }", "after": "pub extern \"C\" fn decode(mut in_0: stream, mut out: stream) { let mut c: i32 = 0; let mut i: i32 = 0; let mut cnt: i32 = 0; loop { c = ((*in_0).get).expect(\"non-null function pointer\")(in_0); if c == -1 { return; } if c > 128 { cnt = c - 128; i = 0; while i < cnt { ((*out).put).expect(\"non-null function pointer\")( out, ((*in_0).get).expect(\"non-null function pointer\")(in_0), ); i += 1; i; } } else { cnt = c; c = ((*in_0).get).expect(\"non-null function pointer\")(in_0); i = 0; while i < cnt { ((*out).put).expect(\"non-null function pointer\")(out, c); i += 1; i; } } } }" }, { "index": 237, "before": "int sget(stream in) { \tint c; \tstring_stream* s = (string_stream*) in; \tc = (unsigned char)(s->string[s->pos]); \tif (c == '\\0') return -1; \ts->pos++; \treturn c; }", "after": "pub extern \"C\" fn sget(mut in_0: stream) -> i32 { unsafe { let mut c: i32 = 0; let mut s: *mut string_stream = in_0 as *mut string_stream; c = *((*s).string).offset((*s).pos as isize) as i32; if c == '\\0' as i32 { return -1; }; (*s).pos += 1; (*s).pos; return c; } }" }, { "index": 238, "before": "int sput(stream out, int c) { \tstring_stream* s = (string_stream*) out; \ts->string[s->pos++] = (c == -1) ? '\\0' : c; \tif (c == -1) s->pos = 0; \treturn 0; }", "after": "pub extern \"C\" fn sput(mut out: stream, mut c: i32) -> i32 { unsafe { let mut s: *mut string_stream = out as *mut string_stream; let fresh0 = (*s).pos; (*s).pos = (*s).pos + 1; *((*s).string).offset(fresh0 as isize) = (if c == -1 { '\\0' as i32 } else { c }) as i8; if c == -1 { (*s).pos = 0; } return 0; } }" }, { "index": 239, "before": "bool is_palindrome(const char* str) { size_t n = strlen(str); for (size_t i = 0; i + 1 < n; ++i, --n) { if (str[i] != str[n - 1]) return false; } return true; }", "after": "pub extern \"C\" fn is_palindrome(mut str: *const i8) -> bool { unsafe { let mut n: u64 = strlen(str); let mut i: u64 = 0; while i.wrapping_add(1) < n { if *str.offset(i as isize) as i32 != *str.offset(n.wrapping_sub(1) as isize) as i32 { return 0 != 0; } i = i.wrapping_add(1); i; n = n.wrapping_sub(1); n; } return 1 != 0; } }" }, { "index": 240, "before": "int main() { time_t timestamp = time(0); const int seconds_per_day = 24*60*60; int count = 15; char str[32]; printf(\"Next %d palindrome dates:\\n\", count); for (; count > 0; timestamp += seconds_per_day) { struct tm* ptr = gmtime(×tamp); strftime(str, sizeof(str), \"%Y%m%d\", ptr); if (is_palindrome(str)) { strftime(str, sizeof(str), \"%F\", ptr); printf(\"%s\\n\", str); --count; } } return 0; }", "after": "fn main() -> i32 { unsafe { let mut timestamp: i64 = rust_time(None); let seconds_per_day: i32 = 24 * 60 * 60; let mut count: i32 = 15; let mut str: [i8; 32] = [0; 32]; print!(\"Next {} palindrome dates:\\n\", count); while count > 0 { let mut ptr: *mut tm = gmtime(&mut timestamp); strftime( str.as_mut_ptr(), ::core::mem::size_of::<[i8; 32]>() as u64, b\"%Y%m%d\\0\" as *const u8 as *const i8, ptr, ); if is_palindrome(str.as_mut_ptr()) { strftime( str.as_mut_ptr(), ::core::mem::size_of::<[i8; 32]>() as u64, b\"%F\\0\" as *const u8 as *const i8, ptr, ); print!(\"{}\\n\", build_str_from_raw_ptr(str.as_mut_ptr() as *mut u8)); count -= 1; count; } timestamp += seconds_per_day as i64; } return 0; } }" }, { "index": 241, "before": "trie trie_new() { return calloc(sizeof(trie_t), 1); }", "after": "pub extern \"C\" fn trie_new() -> trie { unsafe { return calloc(::core::mem::size_of::() as u64, 1) as trie; } }" }, { "index": 242, "before": "trie init_tables() { int i, j; trie root = trie_new(); for (i = 0; i < sizeof(chr_legal); i++) { chr_idx[(int)chr_legal[i]] = i + 1; idx_chr[i + 1] = chr_legal[i]; } /* Enable USE_ADVANCED_FILE_HANDLING to use advanced file handling. * You need to have files named like above files[], with words in them * like in text[][]. Case doesn't matter (told you it's advanced). */ #define USE_ADVANCED_FILE_HANDLING 0 #if USE_ADVANCED_FILE_HANDLING void read_file(const char * fname) { char cmd[1024]; char word[1024]; sprintf(cmd, \"perl -p -e 'while(/(\\\\w+)/g) {print lc($1),\\\"\\\\n\\\"}' %s\", fname); FILE *in = popen(cmd, \"r\"); while (!feof(in)) { fscanf(in, \"%1000s\", word); add_index(root, word, fname); } pclose(in); }; read_file(\"f1.txt\"); read_file(\"source/f2.txt\"); read_file(\"other_file\"); #else for (i = 0; i < 3; i++) { for (j = 0; j < 5; j++) { if (!text[i][j]) break; add_index(root, text[i][j], files[i]); } } #endif /*USE_ADVANCED_FILE_HANDLING*/ return root; }", "after": "pub extern \"C\" fn init_tables() -> trie { let mut i: i32 = 0; let mut j: i32 = 0; let mut root: trie = trie_new(); i = 0; unsafe { while (i as u64) < ::core::mem::size_of::<[i8; 41]>() as u64 { chr_idx[chr_legal[i as usize] as i32 as usize] = i + 1; idx_chr[(i + 1i32) as usize] = chr_legal[i as usize]; i += 1; i; } } i = 0; unsafe { while i < 3 { j = 0; while j < 5 { if (text[i as usize][j as usize]).is_null() { break; } add_index(root, text[i as usize][j as usize], files[i as usize]); j += 1; j; } i += 1; i; } } return root; }" }, { "index": 243, "before": "int main() { trie root = init_tables(); search_index(root, \"what\"); search_index(root, \"is\"); search_index(root, \"banana\"); search_index(root, \"boo\"); return 0; }", "after": "fn main() -> i32 { let mut root: trie = init_tables(); search_index(root, b\"what\\0\" as *const u8 as *const i8); search_index(root, b\"is\\0\" as *const u8 as *const i8); search_index(root, b\"banana\\0\" as *const u8 as *const i8); search_index(root, b\"boo\\0\" as *const u8 as *const i8); return 0; }" }, { "index": 244, "before": "trie trie_trav(trie root, const char * str, int no_create) { int c; while (root) { if ((c = str[0]) == '\\0') { if (!root->eow && no_create) return 0; break; } if (! (c = chr_idx[c]) ) { str++; continue; } if (!root->next[c]) { if (no_create) return 0; root->next[c] = trie_new(); } root = root->next[c]; str++; } return root; }", "after": "pub extern \"C\" fn trie_trav(mut root: trie, mut str: *const i8, mut no_create: i32) -> trie { unsafe { let mut c: i32 = 0; while !root.is_null() { c = *str.offset(0 as isize) as i32; if c == '\\0' as i32 { if (*root).eow == 0 && no_create != 0 { return 0 as trie; } break; } else { c = chr_idx[c as usize]; if c == 0 { str = str.offset(1); str; } else { if ((*root).next[c as usize]).is_null() { if no_create != 0 { return 0 as trie; }; (*root).next[c as usize] = trie_new(); } root = (*root).next[c as usize]; str = str.offset(1); str; } } } return root; } }" }, { "index": 245, "before": "int trie_all(trie root, char path[], int depth, int (*callback)(char *)) { int i; if (root->eow && !callback(path)) return 0; for (i = 1; i < sizeof(chr_legal); i++) { if (!root->next[i]) continue; path[depth] = idx_chr[i]; path[depth + 1] = '\\0'; if (!trie_all(root->next[i], path, depth + 1, callback)) return 0; } return 1; }", "after": "pub extern \"C\" fn trie_all( mut root: trie, mut path: *mut i8, mut depth: i32, mut callback: Option i32>, ) -> i32 { unsafe { let mut i: i32 = 0; if (*root).eow != 0 && callback.expect(\"non-null function pointer\")(path) == 0 { return 0; } i = 1; while (i as u64) < ::core::mem::size_of::<[i8; 41]>() as u64 { if !((*root).next[i as usize]).is_null() { *path.offset(depth as isize) = idx_chr[i as usize]; *path.offset((depth + 1i32) as isize) = '\\0' as i8; if trie_all((*root).next[i as usize], path, depth + 1, callback) == 0 { return 0; } } i += 1; i; } return 1; } }" }, { "index": 246, "before": "void search_index(trie root, const char *word) { char path[1024]; printf(\"Search for \\\"%s\\\": \", word); trie found = find_word(root, word); if (!found) printf(\"not found\\n\"); else { trie_all(found->next[FNAME], path, 0, print_path); printf(\"\\n\"); } }", "after": "pub extern \"C\" fn search_index(mut root: trie, mut word: *const i8) { unsafe { let mut path: [i8; 1024] = [0; 1024]; print!( \"Search for \\\"{}\\\": \", build_str_from_raw_ptr(word as *mut u8) ); let mut found: trie = trie_trav(root, word, 1); if found.is_null() { print!(\"not found\\n\"); } else { trie_all( (*found).next[0 as usize], path.as_mut_ptr(), 0, Some(print_path as unsafe extern \"C\" fn(*mut i8) -> i32), ); print!(\"\\n\"); }; } }" }, { "index": 247, "before": "int print_path(char *path) { printf(\" %s\", path); return 1; }", "after": "pub extern \"C\" fn print_path(mut path: *mut i8) -> i32 { unsafe { print!(\" {}\", build_str_from_raw_ptr(path as *mut u8)); return 1; } }" }, { "index": 248, "before": "void add_index(trie root, const char *word, const char *fname) { trie x = trie_trav(root, word, 0); x->eow = 1; if (!x->next[FNAME]) x->next[FNAME] = trie_new(); x = trie_trav(x->next[FNAME], fname, 0); x->eow = 1; }", "after": "pub extern \"C\" fn add_index(mut root: trie, mut word: *const i8, mut fname: *const i8) { unsafe { let mut x: trie = trie_trav(root, word, 0); (*x).eow = 1; if ((*x).next[0 as usize]).is_null() { (*x).next[0 as usize] = trie_new(); } x = trie_trav((*x).next[0 as usize], fname, 0); (*x).eow = 1; } }" }, { "index": 249, "before": "double meanAngle (double *angles, int size) { double y_part = 0, x_part = 0; int i; for (i = 0; i < size; i++) { x_part += cos (angles[i] * M_PI / 180); y_part += sin (angles[i] * M_PI / 180); } return atan2 (y_part / size, x_part / size) * 180 / M_PI; }", "after": "pub extern \"C\" fn meanAngle(mut angles: *mut f64, mut size: i32) -> f64 { unsafe { let mut y_part: f64 = 0 as f64; let mut x_part: f64 = 0 as f64; let mut i: i32 = 0; i = 0; while i < size { x_part += cos(*angles.offset(i as isize) * 3.14159265358979323846f64 / 180 as f64); y_part += sin(*angles.offset(i as isize) * 3.14159265358979323846f64 / 180 as f64); i += 1; i; } return atan2(y_part / size as f64, x_part / size as f64) * 180 as f64 / 3.14159265358979323846f64; } }" }, { "index": 250, "before": "int main () { double angleSet1[] = { 350, 10 }; double angleSet2[] = { 90, 180, 270, 360}; double angleSet3[] = { 10, 20, 30}; printf (\"\\nMean Angle for 1st set : %lf degrees\", meanAngle (angleSet1, 2)); printf (\"\\nMean Angle for 2nd set : %lf degrees\", meanAngle (angleSet2, 4)); printf (\"\\nMean Angle for 3rd set : %lf degrees\\n\", meanAngle (angleSet3, 3)); return 0; }", "after": "fn main() -> i32 { let mut angleSet1: [f64; 2] = [350 as f64, 10 as f64]; let mut angleSet2: [f64; 4] = [90 as f64, 180 as f64, 270 as f64, 360 as f64]; let mut angleSet3: [f64; 3] = [10 as f64, 20 as f64, 30 as f64]; print!( \"\\nMean Angle for 1st set : {} degrees\", meanAngle(angleSet1.as_mut_ptr(), 2) ); print!( \"\\nMean Angle for 2nd set : {} degrees\", meanAngle(angleSet2.as_mut_ptr(), 4) ); print!( \"\\nMean Angle for 3rd set : {} degrees\\n\", meanAngle(angleSet3.as_mut_ptr(), 3) ); return 0; }" }, { "index": 251, "before": "int main () { int fibo[] = { 1, 1, 0 }, tribo[] = { 1, 1, 2, 0 }, tetra[] = { 1, 1, 2, 4, 0 }, luca[] = { 2, 1, 0 }; int *fibonacci = anynacci (fibo, 10), *tribonacci = anynacci (tribo, 10), *tetranacci = anynacci (tetra, 10), *lucas = anynacci(luca, 10); int i; printf (\"\\nFibonacci\\tTribonacci\\tTetranacci\\tLucas\\n\"); for (i = 0; i < 10; i++) printf (\"\\n%d\\t\\t%d\\t\\t%d\\t\\t%d\", fibonacci[i], tribonacci[i], tetranacci[i], lucas[i]); return 0; }", "after": "fn main() -> i32 { unsafe { let mut fibo: [i32; 3] = [1, 1, 0]; let mut tribo: [i32; 4] = [1, 1, 2, 0]; let mut tetra: [i32; 5] = [1, 1, 2, 4, 0]; let mut luca: [i32; 3] = [2, 1, 0]; let mut fibonacci: *mut i32 = anynacci(fibo.as_mut_ptr(), 10); let mut tribonacci: *mut i32 = anynacci(tribo.as_mut_ptr(), 10); let mut tetranacci: *mut i32 = anynacci(tetra.as_mut_ptr(), 10); let mut lucas: *mut i32 = anynacci(luca.as_mut_ptr(), 10); let mut i: i32 = 0; print!(\"\\nFibonacci\tTribonacci\tTetranacci\tLucas\\n\"); i = 0; while i < 10 { print!( \"\\n{}\t\t{}\t\t{}\t\t{}\", *fibonacci.offset(i as isize), *tribonacci.offset(i as isize), *tetranacci.offset(i as isize), *lucas.offset(i as isize) ); i += 1; i; } return 0; } }" }, { "index": 252, "before": "int main() { \tsay_number(\"-42\"); \tsay_number(\"1984\"); \tsay_number(\"10000\"); \tsay_number(\"1024\"); \tsay_number(\"1001001001001\"); \tsay_number(\"123456789012345678901234567890123456789012345678900000001\"); \treturn 0; }", "after": "fn main() -> i32 { say_number(b\"-42\\0\" as *const u8 as *const i8); say_number(b\"1984\\0\" as *const u8 as *const i8); say_number(b\"10000\\0\" as *const u8 as *const i8); say_number(b\"1024\\0\" as *const u8 as *const i8); say_number(b\"1001001001001\\0\" as *const u8 as *const i8); say_number( b\"123456789012345678901234567890123456789012345678900000001\\0\" as *const u8 as *const i8, ); return 0; }" }, { "index": 253, "before": "int say_hundred(const char *s, int len, int depth, int has_lead) { \tint c[3], i; \tfor (i = -3; i < 0; i++) { \t\tif (len + i >= 0) c[i + 3] = s[len + i] - '0'; \t\telse c[i + 3] = 0; \t} \tif (!(c[0] + c[1] + c[2])) return 0; \tif (c[0]) { \t\tprintf(\"%s hundred\", ones[c[0]]); \t\thas_lead = 1; \t} \tif (has_lead && (c[1] || c[2])) \t\tprintf((!depth || c[0]) && (!c[0] || !c[1]) ? \"and \" : \t\t\tc[0] ? \" \" : \"\"); \tif (c[1] < 2) { \t\tif (c[1] || c[2]) printf(\"%s\", ones[c[1] * 10 + c[2]]); \t} else { \t\tif (c[1]) { \t\t\tprintf(\"%s\", tens[c[1]]); \t\t\tif (c[2]) putchar('-'); \t\t} \t\tif (c[2]) printf(\"%s\", ones[c[2]]); \t} \treturn 1; }", "after": "pub extern \"C\" fn say_hundred( mut s: *const i8, mut len: i32, mut depth: i32, mut has_lead: i32, ) -> i32 { unsafe { let mut c: [i32; 3] = [0; 3]; let mut i: i32 = 0; i = -3; while i < 0 { if len + i >= 0 { c[(i + 3i32) as usize] = *s.offset((len + i) as isize) as i32 - '0' as i32; } else { c[(i + 3i32) as usize] = 0; } i += 1; i; } if c[0 as usize] + c[1 as usize] + c[2 as usize] == 0 { return 0; } if c[0 as usize] != 0 { print!( \"{} hundred\", build_str_from_raw_ptr(ones[c[0 as usize] as usize] as *mut u8) ); has_lead = 1; } if has_lead != 0 && (c[1 as usize] != 0 || c[2 as usize] != 0) { if (depth == 0 || c[0 as usize] != 0) && (c[0 as usize] == 0 || c[1 as usize] == 0) { print!(\"and \") } else { if c[0 as usize] != 0 { print!(\" \") } else { print!(\"\") } }; } if c[1 as usize] < 2 { if c[1 as usize] != 0 || c[2 as usize] != 0 { print!( \"{}\", build_str_from_raw_ptr( ones[(c[1 as usize] * 10 + c[2 as usize]) as usize] as *mut u8 ) ); } } else { if c[1 as usize] != 0 { print!( \"{}\", build_str_from_raw_ptr(tens[c[1 as usize] as usize] as *mut u8) ); if c[2 as usize] != 0 { print!(\"{}\", '-' as i32); } } if c[2 as usize] != 0 { print!( \"{}\", build_str_from_raw_ptr(ones[c[2 as usize] as usize] as *mut u8) ); } } return 1; } }" }, { "index": 254, "before": "void say_number(const char *s) { \tint len, i, got_sign = 0; \twhile (*s == ' ') s++; \tif (*s < '0' || *s > '9') { \t\tif (*s == '-') got_sign = -1; \t\telse if (*s == '+') got_sign = 1; \t\telse goto nan; \t\ts++; \t} else \t\tgot_sign = 1; \twhile (*s == '0') { \t\ts++; \t\tif (*s == '\\0') { \t\t\tprintf(\"zero\\n\"); \t\t\treturn; \t\t} \t} \tlen = strlen(s); \tif (!len) goto nan; \tfor (i = 0; i < len; i++) { \t\tif (s[i] < '0' || s[i] > '9') { \t\t\tprintf(\"(not a number)\"); \t\t\treturn; \t\t} \t} \tif (got_sign == -1) printf(\"minus \"); \tint n = len / maxillion; \tint r = len % maxillion; \tif (!r) { \t\tr = maxillion; \t\tn--; \t} \tconst char *end = s + len - n * maxillion; \tint has_lead = 0; \tdo { \t\tif ((has_lead = say_maxillion(s, r, n, has_lead))) { \t\t\tfor (i = 0; i < n; i++) \t\t\t\tprintf(\" %s\", llions[maxillion / 3]); \t\t\tif (n) printf(\", \"); \t\t} \t\tn--; \t\tr = maxillion; \t\ts = end; \t\tend += r; \t} while (n >= 0); \tprintf(\"\\n\"); \treturn; nan:\tprintf(\"not a number\\n\"); \treturn; }", "after": "pub extern \"C\" fn say_number(mut s: *const i8) { unsafe { let mut n: i32 = 0; let mut r: i32 = 0; let mut end: *const i8 = 0 as *const i8; let mut has_lead: i32 = 0; let mut current_block: u64; let mut len: i32 = 0; let mut i: i32 = 0; let mut got_sign: i32 = 0; while *s as i32 == ' ' as i32 { s = s.offset(1); s; } if (*s as i32) < '0' as i32 || *s as i32 > '9' as i32 { if *s as i32 == '-' as i32 { got_sign = -1; current_block = 15619007995458559411; } else if *s as i32 == '+' as i32 { got_sign = 1; current_block = 15619007995458559411; } else { current_block = 1693057788147685417; } match current_block { 1693057788147685417 => {} _ => { s = s.offset(1); s; current_block = 14523784380283086299; } } } else { got_sign = 1; current_block = 14523784380283086299; } match current_block { 14523784380283086299 => { while *s as i32 == '0' as i32 { s = s.offset(1); s; if *s as i32 == '\\0' as i32 { print!(\"zero\\n\"); return; } } len = strlen(s) as i32; if !(len == 0) { i = 0; while i < len { if (*s.offset(i as isize) as i32) < '0' as i32 || *s.offset(i as isize) as i32 > '9' as i32 { print!(\"(not a number)\"); return; } i += 1; i; } if got_sign == -1 { print!(\"minus \"); } n = len / maxillion; r = len % maxillion; if r == 0 { r = maxillion; n -= 1; n; } end = s.offset(len as isize).offset(-((n * maxillion) as isize)); has_lead = 0; loop { has_lead = say_maxillion(s, r, n, has_lead); if has_lead != 0 { i = 0; while i < n { print!( \" {}\", build_str_from_raw_ptr( llions[(maxillion / 3i32) as usize] as *mut u8 ) ); i += 1; i; } if n != 0 { print!(\", \"); } } n -= 1; n; r = maxillion; s = end; end = end.offset(r as isize); if !(n >= 0) { break; } } print!(\"\\n\"); return; } } _ => {} } print!(\"not a number\\n\"); } }" }, { "index": 255, "before": "int say_maxillion(const char *s, int len, int depth, int has_lead) { \tint n = len / 3, r = len % 3; \tif (!r) { \t\tn--; \t\tr = 3; \t} \tconst char *e = s + r; \tdo { \t\tif (say_hundred(s, r, n, has_lead) && n) { \t\t\thas_lead = 1; \t\t\tprintf(\" %s\", llions[n]); \t\t\tif (!depth) printf(\", \"); \t\t\telse printf(\" \"); \t\t} \t\ts = e; e += 3; \t} while (r = 3, n--); \treturn 1; }", "after": "pub extern \"C\" fn say_maxillion( mut s: *const i8, mut len: i32, mut depth: i32, mut has_lead: i32, ) -> i32 { unsafe { let mut n: i32 = len / 3; let mut r: i32 = len % 3; if r == 0 { n -= 1; n; r = 3; } let mut e: *const i8 = s.offset(r as isize); loop { if say_hundred(s, r, n, has_lead) != 0 && n != 0 { has_lead = 1; print!(\" {}\", build_str_from_raw_ptr(llions[n as usize] as *mut u8)); if depth == 0 { print!(\", \"); } else { print!(\" \"); } } s = e; e = e.offset(3 as isize); r = 3; let fresh0 = n; n = n - 1; if !(fresh0 != 0) { break; } } return 1; } }" }, { "index": 256, "before": "int compareInts(const void *i1, const void *i2) { int a = *((int *)i1); int b = *((int *)i2); return a - b; }", "after": "pub extern \"C\" fn compareInts(mut i1: *const libc::c_void, mut i2: *const libc::c_void) -> i32 { unsafe { let mut a: i32 = *(i1 as *mut i32); let mut b: i32 = *(i2 as *mut i32); return a - b; } }" }, { "index": 257, "before": "int main() { int i, j, nsum, vsum, vcount, values[6], numbers[4]; srand(time(NULL)); for (;;) { vsum = 0; for (i = 0; i < 6; ++i) { for (j = 0; j < 4; ++j) { numbers[j] = 1 + rand() % 6; } qsort(numbers, 4, sizeof(int), compareInts); nsum = 0; for (j = 1; j < 4; ++j) { nsum += numbers[j]; } values[i] = nsum; vsum += values[i]; } if (vsum < 75) continue; vcount = 0; for (j = 0; j < 6; ++j) { if (values[j] >= 15) vcount++; } if (vcount < 2) continue; printf(\"The 6 random numbers generated are:\\n\"); printf(\"[\"); for (j = 0; j < 6; ++j) printf(\"%d \", values[j]); printf(\"\\b]\\n\"); printf(\"\\nTheir sum is %d and %d of them are >= 15\\n\", vsum, vcount); break; } return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut j: i32 = 0; let mut nsum: i32 = 0; let mut vsum: i32 = 0; let mut vcount: i32 = 0; let mut values: [i32; 6] = [0; 6]; let mut numbers: [i32; 4] = [0; 4]; unsafe { srand(rust_time(None) as u32); loop { vsum = 0; i = 0; while i < 6 { j = 0; while j < 4 { numbers[j as usize] = 1 + rand() % 6; j += 1; j; } qsort( numbers.as_mut_ptr() as *mut libc::c_void, 4, ::core::mem::size_of::() as u64, Some( compareInts as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> i32, ), ); nsum = 0; j = 1; while j < 4 { nsum += numbers[j as usize]; j += 1; j; } values[i as usize] = nsum; vsum += values[i as usize]; i += 1; i; } if vsum < 75 { continue; } vcount = 0; j = 0; while j < 6 { if values[j as usize] >= 15 { vcount += 1; vcount; } j += 1; j; } if vcount < 2 { continue; } print!(\"The 6 random numbers generated are:\\n\"); print!(\"[\"); j = 0; while j < 6 { print!(\"{} \", values[j as usize]); j += 1; j; } print!(\"\\x08]\\n\"); print!(\"\\nTheir sum is {} and {} of them are >= 15\\n\", vsum, vcount); break; } } return 0; }" }, { "index": 258, "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 extern \"C\" fn findCircles(mut p1: point, mut p2: point, mut radius: f64) { let mut separation: f64 = distance(p1, p2); let mut mirrorDistance: f64 = 0.; unsafe { if separation == 0.0f64 { if radius == 0.0f64 { print!( \"\\nNo circles can be drawn through ({:.4},{:.4})\", p1.x, p1.y ); } else { print!( \"\\nInfinitely many circles can be drawn through ({:.4},{:.4})\", p1.x, p1.y ); }; } else if separation == 2 as f64 * radius { print! (\"\\nGiven points are opposite ends of a diameter of the circle with center ({:.4},{:.4}) and radius {:.4}\", (p1.x + p2.x) / 2 as f64, (p1.y + p2.y) / 2 as f64, radius); } else if separation > 2 as f64 * radius { print! (\"\\nGiven points are farther away from each other than a diameter of a circle with radius {:.4}\", radius); } else { mirrorDistance = sqrt(pow(radius, 2 as f64) - pow(separation / 2 as f64, 2 as f64)); print!(\"\\nTwo circles are possible.\"); print! (\"\\nCircle C1 with center ({:.4},{:.4}), radius {:.4} and Circle C2 with center ({:.4},{:.4}), radius {:.4}\", (p1.x + p2.x) / 2 as f64 + mirrorDistance * (p1.y - p2.y) / separation, (p1.y + p2.y) / 2 as f64 + mirrorDistance * (p2.x - p1 .x) / separation, radius, (p1.x + p2.x) / 2 as f64 - mirrorDistance * (p1.y - p2.y) / separation, (p1.y + p2.y) / 2 as f64 - mirrorDistance * (p2.x - p1.x) / separation, radius); }; } }" }, { "index": 259, "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 extern \"C\" fn distance(mut p1: point, mut p2: point) -> f64 { unsafe { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); } }" }, { "index": 260, "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": "fn main() -> i32 { let mut i: i32 = 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: [f64; 5] = [2.0f64, 1.0f64, 2.0f64, 0.5f64, 0.0f64]; i = 0; while i < 5 { print!(\"\\nCase {})\", i + 1); findCircles( cases[(2 * i) as usize], cases[(2 * i + 1i32) as usize], radii[i as usize], ); i += 1; i; } return 0; }" }, { "index": 261, "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": "fn main() -> i32 { unsafe { let mut i: i32 = 0; let mut flip: i32 = 0; let mut q: *mut i32 = (malloc((::core::mem::size_of::() as u64).wrapping_mul(100000)) as *mut i32) .offset(-(1 as isize)); let ref mut fresh0 = *q.offset(2 as isize); *fresh0 = 1; *q.offset(1 as isize) = *fresh0; i = 3; while i <= 100000 { *q.offset(i as isize) = *q.offset((i - *q.offset((i - 1i32) as isize)) as isize) + *q.offset((i - *q.offset((i - 2i32) as isize)) as isize); i += 1; i; } i = 1; while i <= 10 { if i == 10 { print!(\"{}{}\", *q.offset(i as isize), '\\n' as i32) } else { print!(\"{}{}\", *q.offset(i as isize), ' ' as i32) }; i += 1; i; } print!(\"{}\\n\", *q.offset(1000 as isize)); flip = 0; i = 1; while i < 100000 { flip += (*q.offset(i as isize) > *q.offset((i + 1i32) as isize)) as i32; i += 1; i; } print!(\"flips: {}\\n\", flip); return 0; } }" }, { "index": 262, "before": "vector extractVector(char* str){ \tvector coeff; \tint i=0,count = 1; \tchar* token; \twhile(str[i]!=00){ \t\tif(str[i++]==' ') \t\t\tcount++; \t} \tcoeff.values = (float*)malloc(count*sizeof(float)); \tcoeff.size = count; \ttoken = strtok(str,\" \"); \ti = 0; \twhile(token!=NULL){ \t\tcoeff.values[i++] = atof(token); \t\ttoken = strtok(NULL,\" \"); \t} \treturn coeff; }", "after": "pub extern \"C\" fn extractVector(mut str: *mut i8) -> vector { unsafe { let mut coeff: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut i: i32 = 0; let mut count: i32 = 1; let mut token: *mut i8 = 0 as *mut i8; while *str.offset(i as isize) as i32 != 0 { let fresh0 = i; i = i + 1; if *str.offset(fresh0 as isize) as i32 == ' ' as i32 { count += 1; count; } } coeff.values = malloc((count as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut libc::c_float; coeff.size = count; token = strtok(str, b\" \\0\" as *const u8 as *const i8); i = 0; while !token.is_null() { let fresh1 = i; i = i + 1; *(coeff.values).offset(fresh1 as isize) = atof(token) as libc::c_float; token = strtok(0 as *mut i8, b\" \\0\" as *const u8 as *const i8); } return coeff; } }" }, { "index": 263, "before": "vector processSignalFile(char* fileName){ \tint i,j; \tfloat sum; \tchar str[MAX_LEN]; \tvector coeff1,coeff2,signal,filteredSignal; \tFILE* fp = fopen(fileName,\"r\"); \tfgets(str,MAX_LEN,fp); \tcoeff1 = extractVector(str); \tfgets(str,MAX_LEN,fp); \tcoeff2 = extractVector(str); \tfgets(str,MAX_LEN,fp); \tsignal = extractVector(str); fclose(fp); \tfilteredSignal.values = (float*)calloc(signal.size,sizeof(float)); \tfilteredSignal.size = signal.size; \tfor(i=0;i=0) \t\t\t\tsum += coeff2.values[j]*signal.values[i-j]; \t\t} \t\tfor(j=0;j=0) \t\t\t\tsum -= coeff1.values[j]*filteredSignal.values[i-j]; \t\t} \t\tsum /= coeff1.values[0]; \t\tfilteredSignal.values[i] = sum; \t} \treturn filteredSignal; }", "after": "pub extern \"C\" fn processSignalFile(mut fileName: *mut i8) -> vector { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut sum: libc::c_float = 0.; let mut str: [i8; 1000] = [0; 1000]; let mut coeff1: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut coeff2: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut signal: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut filteredSignal: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut fp: *mut FILE = fopen(fileName, b\"r\\0\" as *const u8 as *const i8); fgets(str.as_mut_ptr(), 1000, fp); coeff1 = extractVector(str.as_mut_ptr()); fgets(str.as_mut_ptr(), 1000, fp); coeff2 = extractVector(str.as_mut_ptr()); fgets(str.as_mut_ptr(), 1000, fp); signal = extractVector(str.as_mut_ptr()); fclose(fp); filteredSignal.values = calloc( signal.size as u64, ::core::mem::size_of::() as u64, ) as *mut libc::c_float; filteredSignal.size = signal.size; i = 0; while i < signal.size { sum = 0 as libc::c_float; j = 0; while j < coeff2.size { if i - j >= 0 { sum += *(coeff2.values).offset(j as isize) * *(signal.values).offset((i - j) as isize); } j += 1; j; } j = 0; while j < coeff1.size { if i - j >= 0 { sum -= *(coeff1.values).offset(j as isize) * *(filteredSignal.values).offset((i - j) as isize); } j += 1; j; } sum /= *(coeff1.values).offset(0 as isize); *(filteredSignal.values).offset(i as isize) = sum; i += 1; i; } return filteredSignal; } }" }, { "index": 264, "before": "int main(int argC,char* argV[]) { \tchar *str; \tif(argC<2||argC>3) \t\tprintf(\"Usage : %s \",argV[0]); \telse{ \t\tif(argC!=2){ \t\t\tstr = (char*)malloc((strlen(argV[2]) + strlen(str) + 1)*sizeof(char)); \t\t\tstrcpy(str,\"written to \"); \t\t} \t\tprintf(\"Filtered signal %s\",(argC==2)?\"is:\\n\":strcat(str,argV[2])); \t\tprintVector(processSignalFile(argV[1]),argV[2]); \t} \treturn 0; }", "after": "fn main(mut argC: i32, mut argV: *mut *mut i8) -> i32 { unsafe { let mut str: *mut i8 = 0 as *mut i8; if argC < 2 || argC > 3 { print!( \"Usage : {} \", build_str_from_raw_ptr(*argV.offset(0 as isize) as *mut u8) ); } else { if argC != 2 { str = malloc( (strlen(*argV.offset(2 as isize))) .wrapping_add(strlen(str)) .wrapping_add(1) .wrapping_mul(::core::mem::size_of::() as u64), ) as *mut i8; strcpy(str, b\"written to \\0\" as *const u8 as *const i8); } if argC == 2 { print!(\"Filtered signal {}\", \"is:\\n\\0\") } else { print!( \"Filtered signal {}\", build_str_from_raw_ptr( strcat(str, *argV.offset(2 as isize)) as *const i8 as *mut u8 ) ) }; printVector( processSignalFile(*argV.offset(1 as isize)), *argV.offset(2 as isize), ); } return 0; } }" }, { "index": 265, "before": "void printVector(vector v, char* outputFile){ \tint i; \tif(outputFile==NULL){ \t\tprintf(\"[\"); \t\tfor(i=0;i i32 { unsafe { let mut convertedArray: *mut i32 = 0 as *mut i32; convertedArray = convert_array(*argv.offset(1 as isize), argc - 1); if isSorted(convertedArray, argc - 1) == 1 { print!(\"Did you forgot to turn on your brain?! This array is already sorted!\\n\"); } else if argc - 1 <= 10 { print!(\"Am I really supposed to sort this? Sort it by yourself!\\n\"); } else { print!(\"Am I really supposed to sort this? Bhahahaha!\\n\"); } free(convertedArray as *mut libc::c_void); return 0; } }" }, { "index": 267, "before": "int isSorted(int array[], int numberOfElements){ int sorted=1; for(int counter=0;counterarray[counter]) sorted--; } return sorted; }", "after": "pub extern \"C\" fn isSorted(mut array: *mut i32, mut numberOfElements: i32) -> i32 { unsafe { let mut sorted: i32 = 1; let mut counter: i32 = 0; while counter < numberOfElements { if counter != 0 && *array.offset((counter - 1i32) as isize) > *array.offset(counter as isize) { sorted -= 1; sorted; } counter += 1; counter; } return sorted; } }" }, { "index": 268, "before": "int number_of_digits(int x){ int NumberOfDigits; for(NumberOfDigits=0;x!=0;NumberOfDigits++){ x=x/10; } return NumberOfDigits; }", "after": "pub extern \"C\" fn number_of_digits(mut x: i32) -> i32 { let mut NumberOfDigits: i32 = 0; NumberOfDigits = 0; while x != 0 { x = x / 10; NumberOfDigits += 1; NumberOfDigits; } return NumberOfDigits; }" }, { "index": 269, "before": "int main(void) { \tchar balls[NUMBALLS]; //0=r, 1=w, 2=b \tint i; \tsrand(time(NULL)); //not a good seed but good enough for the example \trand(); //rand() always starts with the same values for certain seeds, making \t // testing pretty irritating \t// Generate balls \tfor(i=0;i i32 { let mut balls: [i8; 5] = [0; 5]; let mut i: i32 = 0; unsafe { srand(rust_time(None) as u32); rand(); } i = 0; unsafe { while i < 5 { balls[i as usize] = (rand() as f64 / 2147483647 as f64 * 3 as f64) as i8; i += 1; i; } while issorted(balls.as_mut_ptr()) { print!(\"Accidentally still sorted: \"); printout(balls.as_mut_ptr()); i = 0; while i < 5 { balls[i as usize] = (rand() as f64 / 2147483647 as f64 * 3 as f64) as i8; i += 1; i; } } } print!(\"Non-sorted: \"); printout(balls.as_mut_ptr()); unsafe { qsort( balls.as_mut_ptr() as *mut libc::c_void, 5, ::core::mem::size_of::() as u64, Some(compar as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32), ); } if issorted(balls.as_mut_ptr()) { print!(\"Sorted: \"); printout(balls.as_mut_ptr()); } else { print!(\"Sort failed: \"); printout(balls.as_mut_ptr()); } return 0; }" }, { "index": 270, "before": "void printout(char *balls){ \tint i; \tchar str[NUMBALLS+1]; \tfor(i=0;i i32 { unsafe { let mut c1: i8 = *(a as *const i8); let mut c2: i8 = *(b as *const i8); return c1 as i32 - c2 as i32; } }" }, { "index": 272, "before": "_Bool issorted(char *balls){ \tint i,state; \tstate=0; \tfor(i=0;istate)state=balls[i]; \t} \treturn true; }", "after": "pub extern \"C\" fn issorted(mut balls: *mut i8) -> bool { unsafe { let mut i: i32 = 0; let mut state: i32 = 0; state = 0; i = 0; while i < 5 { if (*balls.offset(i as isize) as i32) < state { return 0 != 0; } if *balls.offset(i as isize) as i32 > state { state = *balls.offset(i as isize) as i32; } i += 1; i; } return 1 != 0; } }" }, { "index": 273, "before": "int main () { int a[] = {-31, 0, 1, 2, 2, 4, 65, 83, 99, 782}; int n = sizeof a / sizeof a[0]; int x = 2; int i = bsearch(a, n, x); printf(\"%d is at index %d\\n\", x, i); x = 5; i = bsearch_r(a, x, 0, n - 1); printf(\"%d is at index %d\\n\", x, i); return 0; }", "after": "fn main() -> i32 { let mut a: [i32; 10] = [-31, 0, 1, 2, 2, 4, 65, 83, 99, 782]; let mut n: i32 = (::core::mem::size_of::<[i32; 10]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32; let mut x: i32 = 2; let mut i: i32 = bsearch(a.as_mut_ptr(), n, x); print!(\"{} is at index {}\\n\", x, i); x = 5; i = bsearch_r(a.as_mut_ptr(), x, 0, n - 1); print!(\"{} is at index {}\\n\", x, i); return 0; }" }, { "index": 274, "before": "int bsearch_r (int *a, int x, int i, int j) { if (j < i) { return -1; } int k = i + ((j - i) / 2); if (a[k] == x) { return k; } else if (a[k] < x) { return bsearch_r(a, x, k + 1, j); } else { return bsearch_r(a, x, i, k - 1); } }", "after": "pub extern \"C\" fn bsearch_r(mut a: *mut i32, mut x: i32, mut i: i32, mut j: i32) -> i32 { unsafe { if j < i { return -1; } let mut k: i32 = i + (j - i) / 2; if *a.offset(k as isize) == x { return k; } else if *a.offset(k as isize) < x { return bsearch_r(a, x, k + 1, j); } else { return bsearch_r(a, x, i, k - 1); }; } }" }, { "index": 275, "before": "int bsearch (int *a, int n, int x) { int i = 0, j = n - 1; while (i <= j) { int k = i + ((j - i) / 2); if (a[k] == x) { return k; } else if (a[k] < x) { i = k + 1; } else { j = k - 1; } } return -1; }", "after": "pub extern \"C\" fn bsearch(mut a: *mut i32, mut n: i32, mut x: i32) -> i32 { unsafe { let mut i: i32 = 0; let mut j: i32 = n - 1; while i <= j { let mut k: i32 = i + (j - i) / 2; if *a.offset(k as isize) == x { return k; } else if *a.offset(k as isize) < x { i = k + 1; } else { j = k - 1; } } return -1; } }" }, { "index": 276, "before": "int main(){ \tint sum = 0, i, j; \tint try_max = 0; \t//1 is deficient by default and can add it deficient list \tint count_list[3] = {1,0,0}; \tfor(i=2; i <= 20000; i++){ \t\t//Set maximum to check for proper division \t\ttry_max = i/2; \t\t//1 is in all proper division number \t\tsum = 1; \t\tfor(j=2; j i){ \t\t\tcount_list[ab]++; \t\t\tcontinue; \t\t} \t\tcount_list[pe]++; \t} \tprintf(\"\\nThere are %d deficient,\" ,count_list[de]); \tprintf(\" %d perfect,\" ,count_list[pe]); \tprintf(\" %d abundant numbers between 1 and 20000.\\n\" ,count_list[ab]); return 0; }", "after": "fn main() -> i32 { let mut sum: i32 = 0; let mut i: i32 = 0; let mut j: i32 = 0; let mut try_max: i32 = 0; let mut count_list: [i32; 3] = [1, 0, 0]; i = 2; while i <= 20000 { try_max = i / 2; sum = 1; j = 2; while j < try_max { if !(i % j != 0) { try_max = i / j; sum += j; if j != try_max { sum += try_max; } } j += 1; j; } if sum < i { count_list[0 as usize] += 1; count_list[0 as usize]; } else if sum > i { count_list[2 as usize] += 1; count_list[2 as usize]; } else { count_list[1 as usize] += 1; count_list[1 as usize]; } i += 1; i; } print!(\"\\nThere are {} deficient,\", count_list[0 as usize]); print!(\" {} perfect,\", count_list[1 as usize]); print!( \" {} abundant numbers between 1 and 20000.\\n\", count_list[2 as usize] ); return 0; }" }, { "index": 277, "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: i32, mut args: ...) -> i64 { let mut vaList: ::core::ffi::VaListImpl; let mut sum: i64 = 0; vaList = args.clone(); loop { let fresh0 = num; num = num - 1; if !(fresh0 != 0) { break; } sum += factorial(vaList.arg::()); } return sum; }" }, { "index": 278, "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": "fn main() -> i32 { unsafe { print!( \"\\nSum of factorials of [1,5] : {}\", sumOfFactorials(5, 1, 2, 3, 4, 5) ); print!( \"\\nSum of factorials of [3,5] : {}\", sumOfFactorials(3, 3, 4, 5) ); print!( \"\\nSum of factorials of [1,3] : {}\", sumOfFactorials(3, 1, 2, 3) ); } return 0; }" }, { "index": 279, "before": "long int factorial(int n){ \tif(n>1) \t\treturn n*factorial(n-1); \treturn 1; }", "after": "pub extern \"C\" fn factorial(mut n: i32) -> i64 { if n > 1 { return n as i64 * factorial(n - 1); } return 1; }" }, { "index": 280, "before": "int main() { \tchar *s; \twhile ((s = get_line(stdin))) { \t\tprintf(\"%s\",s); \t\tfree(s); \t} \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut s: *mut i8 = 0 as *mut i8; loop { s = get_line(stdin); if s.is_null() { break; } print!(\"{}\", build_str_from_raw_ptr(s as *mut u8)); free(s as *mut libc::c_void); } return 0; } }" }, { "index": 281, "before": "void fmtbool(int n, char *buf) { char *b = buf + 5; *b=0; do { \t*--b = '0' + (n & 1); \tn >>= 1; } while (b != buf); }", "after": "pub extern \"C\" fn fmtbool(mut n: i32, mut buf: *mut i8) { unsafe { let mut b: *mut i8 = buf.offset(5 as isize); *b = 0; loop { b = b.offset(-1); *b = ('0' as i32 + (n & 1i32)) as i8; n >>= 1; if !(b != buf) { break; } } } }" }, { "index": 282, "before": "int main(int argc, char **argv) { int i,g,b; char bi[6],bg[6],bb[6]; for (i=0 ; i<32 ; i++) { \tg = gray_encode(i); \tb = gray_decode(g); \tfmtbool(i,bi); fmtbool(g,bg); fmtbool(b,bb); \tprintf(\"%2d : %5s => %5s => %5s : %2d\\n\", i, bi, bg, bb, b); } return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut i: i32 = 0; let mut g: i32 = 0; let mut b: i32 = 0; let mut bi: [i8; 6] = [0; 6]; let mut bg: [i8; 6] = [0; 6]; let mut bb: [i8; 6] = [0; 6]; i = 0; while i < 32 { g = gray_encode(i); b = gray_decode(g); fmtbool(i, bi.as_mut_ptr()); fmtbool(g, bg.as_mut_ptr()); fmtbool(b, bb.as_mut_ptr()); print!( \"{:2} : {:5} => {:5} => {:5} : {:2}\\n\", i, build_str_from_raw_ptr(bi.as_mut_ptr() as *mut u8), build_str_from_raw_ptr(bg.as_mut_ptr() as *mut u8), build_str_from_raw_ptr(bb.as_mut_ptr() as *mut u8), b ); i += 1; i; } return 0; } }" }, { "index": 283, "before": "int gray_decode(int n) { int p = n; while (n >>= 1) p ^= n; return p; }", "after": "pub extern \"C\" fn gray_decode(mut n: i32) -> i32 { let mut p: i32 = n; loop { n >>= 1; if !(n != 0) { break; } p ^= n; } return p; }" }, { "index": 284, "before": "int gray_encode(int n) { return n ^ (n >> 1); }", "after": "pub extern \"C\" fn gray_encode(mut n: i32) -> i32 { return n ^ n >> 1; }" }, { "index": 285, "before": "int main(void) { \tint i, j, n = 12; \tfor (j = 1; j <= n; j++) printf(\"%3d%c\", j, j != n ? ' ' : '\\n'); \tfor (j = 0; j <= n; j++) printf(j != n ? \"----\" : \"+\\n\"); \tfor (i = 1; i <= n; i++) { \t\tfor (j = 1; j <= n; j++) \t\t\tprintf(j < i ? \" \" : \"%3d \", i * j); printf(\"| %d\\n\", i); } \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut j: i32 = 0; let mut n: i32 = 12; j = 1; while j <= n { if j != n { print!(\"{:3}{}\", j, ' ' as i32) } else { print!(\"{:3}{}\", j, '\\n' as i32) }; j += 1; j; } j = 0; while j <= n { if j != n { print!(\"----\") } else { print!(\"+\\n\") }; j += 1; j; } i = 1; while i <= n { j = 1; while j <= n { if j < i { print!(\" \") } else { print!(\"{:3} \", i * j) }; j += 1; j; } print!(\"| {}\\n\", i); i += 1; i; } return 0; }" }, { "index": 286, "before": "static void rot13_file(FILE *fp) { \tint ch; \twhile ((ch = fgetc(fp)) != EOF) { \t\tfputc(rot13_table[ch], stdout); \t} }", "after": "extern \"C\" fn rot13_file(mut fp: *mut FILE) { unsafe { let mut ch: i32 = 0; loop { ch = fgetc(fp); if !(ch != -1) { break; } fputc(rot13_table[ch as usize] as i32, stdout); } } }" }, { "index": 287, "before": "static void init_rot13_table(void) { \tstatic const unsigned char upper[] = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"; \tstatic const unsigned char lower[] = \"abcdefghijklmnopqrstuvwxyz\"; \tfor (int ch = '\\0'; ch <= UCHAR_MAX; ch++) { \t\trot13_table[ch] = ch; \t} \tfor (const unsigned char *p = upper; p[13] != '\\0'; p++) { \t\trot13_table[p[0]] = p[13]; \t\trot13_table[p[13]] = p[0]; \t} \tfor (const unsigned char *p = lower; p[13] != '\\0'; p++) { \t\trot13_table[p[0]] = p[13]; \t\trot13_table[p[13]] = p[0]; \t} }", "after": "extern \"C\" fn init_rot13_table() { unsafe { static mut upper: [u8; 27] = unsafe { *::core::mem::transmute::<&[u8; 27], &[u8; 27]>(b\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\\0\") }; static mut lower: [u8; 27] = unsafe { *::core::mem::transmute::<&[u8; 27], &[u8; 27]>(b\"abcdefghijklmnopqrstuvwxyz\\0\") }; let mut ch: i32 = '\\0' as i32; while ch <= 127 * 2 + 1 { rot13_table[ch as usize] = ch as i8; ch += 1; ch; } let mut p: *const u8 = upper.as_ptr(); while *p.offset(13 as isize) as i32 != '\\0' as i32 { rot13_table[*p.offset(0 as isize) as usize] = *p.offset(13 as isize) as i8; rot13_table[*p.offset(13 as isize) as usize] = *p.offset(0 as isize) as i8; p = p.offset(1); p; } let mut p_0: *const u8 = lower.as_ptr(); while *p_0.offset(13 as isize) as i32 != '\\0' as i32 { rot13_table[*p_0.offset(0 as isize) as usize] = *p_0.offset(13 as isize) as i8; rot13_table[*p_0.offset(13 as isize) as usize] = *p_0.offset(0 as isize) as i8; p_0 = p_0.offset(1); p_0; } } }" }, { "index": 288, "before": "int main(int argc, char *argv[]) { \tinit_rot13_table(); \tif (argc > 1) { \t\tfor (int i = 1; i < argc; i++) { \t\t\tFILE *fp = fopen(argv[i], \"r\"); \t\t\tif (fp == NULL) { \t\t\t\tperror(argv[i]); \t\t\t\treturn EXIT_FAILURE; \t\t\t} \t\t\trot13_file(fp); \t\t\tfclose(fp); \t\t} \t} else { \t\trot13_file(stdin); \t} \treturn EXIT_SUCCESS; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { init_rot13_table(); if argc > 1 { let mut i: i32 = 1; while i < argc { let mut fp: *mut FILE = fopen(*argv.offset(i as isize), b\"r\\0\" as *const u8 as *const i8); if fp.is_null() { perror(*argv.offset(i as isize)); return 1; } rot13_file(fp); fclose(fp); i += 1; i; } } else { rot13_file(stdin); } return 0; } }" }, { "index": 289, "before": "void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) { \tmpf_add (out1, in1, in2); \tmpf_div_ui (out1, out1, 2); \tmpf_mul (out2, in1, in2); \tmpf_sqrt (out2, out2); }", "after": "pub extern \"C\" fn agm(in1: i32, in2: i32, mut out1: i32, mut out2: i32) {}" }, { "index": 290, "before": "int main (void) { \tmpf_set_default_prec (300000); \tmpf_t x0, y0, resA, resB, Z, var; \tmpf_init_set_ui (x0, 1); \tmpf_init_set_d (y0, 0.5); \tmpf_sqrt (y0, y0); \tmpf_init (resA); \tmpf_init (resB); \tmpf_init_set_d (Z, 0.25); \tmpf_init (var); \tint n = 1; int i; \tfor(i=0; i<8; i++){ \t\tagm(x0, y0, resA, resB); \t\tmpf_sub(var, resA, x0); \t\tmpf_mul(var, var, var); \t\tmpf_mul_ui(var, var, n); \t\tmpf_sub(Z, Z, var); \t\tn += n; \t\tagm(resA, resB, x0, y0); \t\tmpf_sub(var, x0, resA); \t\tmpf_mul(var, var, var); \t\tmpf_mul_ui(var, var, n); \t\tmpf_sub(Z, Z, var); \t\tn += n; \t} \tmpf_mul(x0, x0, x0); \tmpf_div(x0, x0, Z); \tgmp_printf (\"%.100000Ff\\n\", x0); \treturn 0; }", "after": "fn main() -> i32 { mpf_set_default_prec(300000); let mut n: i32 = 1; let mut i: i32 = 0; i = 0; while i < 8 { n += n; n += n; i += 1; i; } return 0; }" }, { "index": 291, "before": "int main() { \tchar\tc[] = \"_###_##_#_#_#_#__#__\\n\", \t\tb[] = \"____________________\\n\"; \tdo { printf(c + 1); } while (evolve(c + 1, b + 1, sizeof(c) - 3)); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut c: [i8; 22] = *::core::mem::transmute::<&[u8; 22], &mut [i8; 22]>(b\"_###_##_#_#_#_#__#__\\n\\0\"); let mut b: [i8; 22] = *::core::mem::transmute::<&[u8; 22], &mut [i8; 22]>(b\"____________________\\n\\0\"); loop { printf(c.as_mut_ptr().offset(1 as isize)); if !(evolve( c.as_mut_ptr().offset(1 as isize), b.as_mut_ptr().offset(1 as isize), (::core::mem::size_of::<[i8; 22]>() as u64).wrapping_sub(3) as i32, ) != 0) { break; } } } return 0; }" }, { "index": 292, "before": "int evolve(char cell[], char backup[], int len) { \tint i, diff = 0; \tfor (i = 0; i < len; i++) { \t\t/* use left, self, right as binary number bits for table index */ \t\tbackup[i] = trans[ v(i-1) * 4 + v(i) * 2 + v(i + 1) ]; \t\tdiff += (backup[i] != cell[i]); \t} \tstrcpy(cell, backup); \treturn diff; }", "after": "pub extern \"C\" fn evolve(mut cell: *mut i8, mut backup: *mut i8, mut len: i32) -> i32 { unsafe { let mut i: i32 = 0; let mut diff: i32 = 0; i = 0; while i < len { *backup.offset(i as isize) = trans[((*cell.offset((i - 1i32) as isize) as i32 != '_' as i32) as i32 * 4 + (*cell.offset(i as isize) as i32 != '_' as i32) as i32 * 2 + (*cell.offset((i + 1i32) as isize) as i32 != '_' as i32) as i32) as usize]; diff += (*backup.offset(i as isize) as i32 != *cell.offset(i as isize) as i32) as i32; i += 1; i; } strcpy(cell, backup as *const i8); return diff; } }" }, { "index": 293, "before": "void generic_fizz_buzz(int max, struct replace_info *info, int info_length) { int i, it; int found_word; for (i = 1; i < max; ++i) { found_word = 0; /* Assume sorted order of values in the info array */ for (it = 0; it < info_length; ++it) { if (0 == i % info[it].n) { printf(\"%s\", info[it].text); found_word = 1; } } if (0 == found_word) printf(\"%d\", i); printf(\"\\n\"); } }", "after": "pub extern \"C\" fn generic_fizz_buzz( mut max: i32, mut info: *mut replace_info, mut info_length: i32, ) { unsafe { let mut i: i32 = 0; let mut it: i32 = 0; let mut found_word: i32 = 0; i = 1; while i < max { found_word = 0; it = 0; while it < info_length { if 0 == i % (*info.offset(it as isize)).n { print!( \"{}\", build_str_from_raw_ptr((*info.offset(it as isize)).text as *mut u8) ); found_word = 1; } it += 1; it; } if 0 == found_word { print!(\"{}\", i); } print!(\"\\n\"); i += 1; i; } } }" }, { "index": 294, "before": "int main(void) { struct replace_info info[3] = { {5, \"Buzz\"}, {7, \"Baxx\"}, {3, \"Fizz\"} }; /* Sort information array */ qsort(info, 3, sizeof(struct replace_info), compare); /* Print output for generic FizzBuzz */ generic_fizz_buzz(20, info, 3); return 0; }", "after": "fn main() -> i32 { let mut info: [replace_info; 3] = [ { let mut init = replace_info { n: 5, text: b\"Buzz\\0\" as *const u8 as *const i8 as *mut i8, }; init }, { let mut init = replace_info { n: 7, text: b\"Baxx\\0\" as *const u8 as *const i8 as *mut i8, }; init }, { let mut init = replace_info { n: 3, text: b\"Fizz\\0\" as *const u8 as *const i8 as *mut i8, }; init }, ]; unsafe { qsort( info.as_mut_ptr() as *mut libc::c_void, 3, ::core::mem::size_of::() as u64, Some(compare as unsafe extern \"C\" fn(*const libc::c_void, *const libc::c_void) -> i32), ); } generic_fizz_buzz(20, info.as_mut_ptr(), 3); return 0; }" }, { "index": 295, "before": "int compare(const void *a, const void *b) { struct replace_info *x = (struct replace_info *) a; struct replace_info *y = (struct replace_info *) b; return x->n - y->n; }", "after": "pub extern \"C\" fn compare(mut a: *const libc::c_void, mut b: *const libc::c_void) -> i32 { unsafe { let mut x: *mut replace_info = a as *mut replace_info; let mut y: *mut replace_info = b as *mut replace_info; return (*x).n - (*y).n; } }" }, { "index": 296, "before": "int makehist(char *S,int *hist,int len){ \tint wherechar[256]; \tint i,histlen; \thistlen=0; \tfor(i=0;i<256;i++)wherechar[i]=-1; \tfor(i=0;i i32 { unsafe { let mut wherechar: [i32; 256] = [0; 256]; let mut i: i32 = 0; let mut histlen: i32 = 0; histlen = 0; i = 0; while i < 256 { wherechar[i as usize] = -1; i += 1; i; } i = 0; while i < len { if wherechar[*S.offset(i as isize) as i32 as usize] == -1 { wherechar[*S.offset(i as isize) as i32 as usize] = histlen; histlen += 1; histlen; } let ref mut fresh0 = *hist.offset(wherechar[*S.offset(i as isize) as i32 as usize] as isize); *fresh0 += 1; *fresh0; i += 1; i; } return histlen; } }" }, { "index": 297, "before": "double entropy(int *hist,int histlen,int len){ \tint i; \tdouble H; \tH=0; \tfor(i=0;i f64 { unsafe { let mut i: i32 = 0; let mut H: f64 = 0.; H = 0 as f64; i = 0; while i < histlen { H -= *hist.offset(i as isize) as f64 / len as f64 * log2(*hist.offset(i as isize) as f64 / len as f64); i += 1; i; } return H; } }" }, { "index": 298, "before": "int main(void){ \tchar S[MAXLEN]; \tint len,*hist,histlen; \tdouble H; \tscanf(\"%[^\\n]\",S); \tlen=strlen(S); \thist=(int*)calloc(len,sizeof(int)); \thistlen=makehist(S,hist,len); \t//hist now has no order (known to the program) but that doesn't matter \tH=entropy(hist,histlen,len); \tprintf(\"%lf\\n\",H); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut S: [i8; 100] = [0; 100]; let mut len: i32 = 0; let mut hist: *mut i32 = 0 as *mut i32; let mut histlen: i32 = 0; let mut H: f64 = 0.; scanf(b\"%[^\\n]\\0\" as *const u8 as *const i8, S.as_mut_ptr()); len = strlen(S.as_mut_ptr()) as i32; hist = calloc(len as u64, ::core::mem::size_of::() as u64) as *mut i32; histlen = makehist(S.as_mut_ptr(), hist, len); H = entropy(hist, histlen, len); print!(\"{}\\n\", H); return 0; } }" }, { "index": 299, "before": "int main() { int max = 0, i = 0, sixes, nines, twenties; loopstart: while (i < 100) { for (sixes = 0; sixes*6 < i; sixes++) { if (sixes*6 == i) { i++; goto loopstart; } for (nines = 0; nines*9 < i; nines++) { if (sixes*6 + nines*9 == i) { i++; goto loopstart; } for (twenties = 0; twenties*20 < i; twenties++) { if (sixes*6 + nines*9 + twenties*20 == i) { i++; goto loopstart; } } } } max = i; i++; } printf(\"Maximum non-McNuggets number is %d\\n\", max); return 0; }", "after": "fn main() -> i32 { let mut max: i32 = 0; let mut i: i32 = 0; let mut sixes: i32 = 0; let mut nines: i32 = 0; let mut twenties: i32 = 0; 's_3: while i < 100 { sixes = 0; while (sixes * 6) < i { if sixes * 6 == i { i += 1; i; continue 's_3; } else { nines = 0; while (nines * 9) < i { if sixes * 6 + nines * 9 == i { i += 1; i; continue 's_3; } else { twenties = 0; while (twenties * 20) < i { if sixes * 6 + nines * 9 + twenties * 20 == i { i += 1; i; continue 's_3; } else { twenties += 1; twenties; } } nines += 1; nines; } } sixes += 1; sixes; } } max = i; i += 1; i; } print!(\"Maximum non-McNuggets number is {}\\n\", max); return 0; }" }, { "index": 300, "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": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut i: u64 = 0; let mut n: u64 = 43112609; if argc >= 2 { n = strtoul(*argv.offset(1 as isize), 0 as *mut *mut i8, 10); } i = 1; while i <= n { if lucas_lehmer(i) != 0 { print!(\"M{} \", i); fflush(stdout); } i = i.wrapping_add(1); i; } print!(\"\\n\"); return 0; } }" }, { "index": 301, "before": "int main(int argc, char *argv[]) { int days[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int m, y, w; if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1; days[1] -= (y % 4) || (!(y % 100) && (y % 400)); w = y * 365 + 97 * (y - 1) / 400 + 4; for(m = 0; m < 12; m++) { w = (w + days[m]) % 7; printf(\"%d-%02d-%d\\n\", y, m + 1,days[m] - w); } return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut days: [i32; 12] = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; let mut m: i32 = 0; let mut y: i32 = 0; let mut w: i32 = 0; if argc < 2 || { y = atoi(*argv.offset(1 as isize)); y <= 1752 } { return 1; } days[1 as usize] -= (y % 4 != 0 || y % 100 == 0 && y % 400 != 0) as i32; w = y * 365 + 97 * (y - 1) / 400 + 4; m = 0; while m < 12 { w = (w + days[m as usize]) % 7; print!(\"{}-{:02}-{}\\n\", y, m + 1, days[m as usize] - w); m += 1; m; } return 0; } }" }, { "index": 302, "before": "int main(void) { \tputs(isatty(fileno(stdin)) \t\t? \"stdin is tty\" \t\t: \"stdin is not tty\"); \treturn 0; }", "after": "fn main() -> i32 { unsafe { puts(if isatty(fileno(stdin)) != 0 { b\"stdin is tty\\0\" as *const u8 as *const i8 } else { b\"stdin is not tty\\0\" as *const u8 as *const i8 }); } return 0; }" }, { "index": 303, "before": "int main(int argc, char **argv) { uint top = atoi(argv[1]); uint *divsum = malloc((top + 1) * sizeof(*divsum)); uint pows[32] = {1, 0}; for (uint i = 0; i <= top; i++) divsum[i] = 1; // sieve // only sieve within lower half , the modification starts at 2*p for (uint p = 2; p+p <= top; p++) { if (divsum[p] > 1) { divsum[p] -= p;// subtract number itself from divisor sum ('proper') continue;} // p not prime uint x; // highest power of p we need //checking x <= top/y instead of x*y <= top to avoid overflow for (x = 1; pows[x - 1] <= top/p; x++) pows[x] = p*pows[x - 1]; //counter where n is not a*p with a = ?*p, useful for most p. //think of p>31 seldom divisions or p>sqrt(top) than no division is needed //n = 2*p, so the prime itself is left unchanged => k=p-1 uint k= p-1; for (uint n = p+p; n <= top; n += p) { uint s=1+pows[1]; k--; // search the right power only if needed if ( k==0) { for (uint i = 2; i < x && !(n%pows[i]); s += pows[i++]); k = p; } divsum[n] *= s; } } //now correct the upper half for (uint p = (top >> 1)+1; p <= top; p++) { if (divsum[p] > 1){ divsum[p] -= p;} } uint cnt = 0; for (uint a = 1; a <= top; a++) { uint b = divsum[a]; if (b > a && b <= top && divsum[b] == a){ printf(\"%u %u\\n\", a, b); cnt++;} } printf(\"\\nTop %u count : %u\\n\",top,cnt); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut top: u32 = atoi(*argv.offset(1 as isize)) as u32; let mut divsum: *mut u32 = malloc( (top.wrapping_add(1u32) as u64).wrapping_mul(::core::mem::size_of::() as u64), ) as *mut u32; let mut pows: [u32; 32] = [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut i: u32 = 0; while i <= top { *divsum.offset(i as isize) = 1; i = i.wrapping_add(1); i; } let mut p: u32 = 2; while p.wrapping_add(p) <= top { if *divsum.offset(p as isize) > 1 { let ref mut fresh0 = *divsum.offset(p as isize); *fresh0 = (*fresh0 as u32).wrapping_sub(p) as u32; } else { let mut x: u32 = 0; x = 1; while pows[x.wrapping_sub(1) as usize] <= top.wrapping_div(p) { pows[x as usize] = p.wrapping_mul(pows[x.wrapping_sub(1) as usize]); x = x.wrapping_add(1); x; } let mut k: u32 = p.wrapping_sub(1); let mut n: u32 = p.wrapping_add(p); while n <= top { let mut s: u32 = 1u32.wrapping_add(pows[1 as usize]); k = k.wrapping_sub(1); k; if k == 0 { let mut i_0: u32 = 2; while i_0 < x && n.wrapping_rem(pows[i_0 as usize]) == 0 { let fresh1 = i_0; i_0 = i_0.wrapping_add(1); s = (s).wrapping_add(pows[fresh1 as usize]) as u32; } k = p; } let ref mut fresh2 = *divsum.offset(n as isize); *fresh2 = (*fresh2 as u32).wrapping_mul(s) as u32; n = (n).wrapping_add(p) as u32; } } p = p.wrapping_add(1); p; } let mut p_0: u32 = (top >> 1i32).wrapping_add(1); while p_0 <= top { if *divsum.offset(p_0 as isize) > 1 { let ref mut fresh3 = *divsum.offset(p_0 as isize); *fresh3 = (*fresh3 as u32).wrapping_sub(p_0) as u32; } p_0 = p_0.wrapping_add(1); p_0; } let mut cnt: u32 = 0; let mut a: u32 = 1; while a <= top { let mut b: u32 = *divsum.offset(a as isize); if b > a && b <= top && *divsum.offset(b as isize) == a { print!(\"{} {}\\n\", a, b); cnt = cnt.wrapping_add(1); cnt; } a = a.wrapping_add(1); a; } print!(\"\\nTop {} count : {}\\n\", top, cnt); return 0; } }" }, { "index": 304, "before": "int main() { double inf = 1/0.0; double minus_inf = -1/0.0; double minus_zero = -1/ inf ; double nan = 0.0/0.0; printf(\"positive infinity: %f\\n\",inf); printf(\"negative infinity: %f\\n\",minus_inf); printf(\"negative zero: %f\\n\",minus_zero); printf(\"not a number: %f\\n\",nan); /* some arithmetic */ printf(\"+inf + 2.0 = %f\\n\",inf + 2.0); printf(\"+inf - 10.1 = %f\\n\",inf - 10.1); printf(\"+inf + -inf = %f\\n\",inf + minus_inf); printf(\"0.0 * +inf = %f\\n\",0.0 * inf); printf(\"1.0/-0.0 = %f\\n\",1.0/minus_zero); printf(\"NaN + 1.0 = %f\\n\",nan + 1.0); printf(\"NaN + NaN = %f\\n\",nan + nan); /* some comparisons */ printf(\"NaN == NaN = %s\\n\",nan == nan ? \"true\" : \"false\"); printf(\"0.0 == -0.0 = %s\\n\",0.0 == minus_zero ? \"true\" : \"false\"); return 0; }", "after": "fn main() -> i32 { let mut inf: f64 = 1 as f64 / 0.0f64; let mut minus_inf: f64 = -1i32 as f64 / 0.0f64; let mut minus_zero: f64 = -1i32 as f64 / inf; let mut nan: f64 = 0.0f64 / 0.0f64; print!(\"positive infinity: {}\\n\", inf); print!(\"negative infinity: {}\\n\", minus_inf); print!(\"negative zero: {}\\n\", minus_zero); print!(\"not a number: {}\\n\", nan); print!(\"+inf + 2.0 = {}\\n\", inf + 2.0f64); print!(\"+inf - 10.1 = {}\\n\", inf - 10.1f64); print!(\"+inf + -inf = {}\\n\", inf + minus_inf); print!(\"0.0 * +inf = {}\\n\", 0.0f64 * inf); print!(\"1.0/-0.0 = {}\\n\", 1.0f64 / minus_zero); print!(\"NaN + 1.0 = {}\\n\", nan + 1.0f64); print!(\"NaN + NaN = {}\\n\", nan + nan); if nan == nan { print!(\"NaN == NaN = {}\\n\", \"true\\0\") } else { print!(\"NaN == NaN = {}\\n\", \"false\\0\") }; if 0.0f64 == minus_zero { print!(\"0.0 == -0.0 = {}\\n\", \"true\\0\") } else { print!(\"0.0 == -0.0 = {}\\n\", \"false\\0\") }; return 0; }" }, { "index": 305, "before": "int main(int argc, char** argv){ int operation; char squeezeChar; if(argc<3||argc>4){ printf(\"Usage : %s \\n\",argv[0]); return 0; } if(strcmpi(argv[1],\"SQUEEZE\")==0 && argc!=4){ scanf(\"Please enter characted to be squeezed : %c\",&squeezeChar); operation = SQUEEZE; } else if(argc==4){ operation = SQUEEZE; squeezeChar = argv[3][0]; } else if(strcmpi(argv[1],\"COLLAPSE\")==0){ operation = COLLAPSE; } if(strlen(argv[2])<2){ printResults(argv[2],argv[2],operation,squeezeChar); } else{ printResults(argv[2],processString(argv[2],operation,squeezeChar),operation,squeezeChar); } return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut operation: i32 = 0; let mut squeezeChar: i8 = 0; if argc < 3 || argc > 4 { print! (\"Usage : {} \\n\", build_str_from_raw_ptr (* argv.offset (0 as isize) as * mut u8)); return 0; } if strcmpi( *argv.offset(1 as isize), b\"SQUEEZE\\0\" as *const u8 as *const i8 as *mut i8, ) == 0 && argc != 4 { scanf( b\"Please enter characted to be squeezed : %c\\0\" as *const u8 as *const i8, &mut squeezeChar as *mut i8, ); operation = 1; } else if argc == 4 { operation = 1; squeezeChar = *(*argv.offset(3 as isize)).offset(0 as isize); } else if strcmpi( *argv.offset(1 as isize), b\"COLLAPSE\\0\" as *const u8 as *const i8 as *mut i8, ) == 0 { operation = 0; } if strlen(*argv.offset(2 as isize)) < 2 { printResults( *argv.offset(2 as isize), *argv.offset(2 as isize), operation, squeezeChar, ); } else { printResults( *argv.offset(2 as isize), processString(*argv.offset(2 as isize), operation, squeezeChar), operation, squeezeChar, ); } return 0; } }" }, { "index": 306, "before": "void printResults(char originalString[100], char finalString[100], int operation, char squeezeChar){ if(operation==SQUEEZE){ printf(\"Specified Operation : SQUEEZE\\nTarget Character : %c\",squeezeChar); } else printf(\"Specified Operation : COLLAPSE\"); printf(\"\\nOriginal %c%c%c%s%c%c%c\\nLength : %d\",174,174,174,originalString,175,175,175,(int)strlen(originalString)); printf(\"\\nFinal %c%c%c%s%c%c%c\\nLength : %d\\n\",174,174,174,finalString,175,175,175,(int)strlen(finalString)); }", "after": "pub extern \"C\" fn printResults( mut originalString: *mut i8, mut finalString: *mut i8, mut operation: i32, mut squeezeChar: i8, ) { unsafe { if operation == 1 { print!( \"Specified Operation : SQUEEZE\\nTarget Character : {}\", squeezeChar as i32 ); } else { print!(\"Specified Operation : COLLAPSE\"); } print!( \"\\nOriginal {}{}{}{}{}{}{}\\nLength : {}\", 174, 174, 174, build_str_from_raw_ptr(originalString as *mut u8), 175, 175, 175, strlen(originalString as *const i8) as i32 ); print!( \"\\nFinal {}{}{}{}{}{}{}\\nLength : {}\\n\", 174, 174, 174, build_str_from_raw_ptr(finalString as *mut u8), 175, 175, 175, strlen(finalString as *const i8) as i32 ); } }" }, { "index": 307, "before": "int strcmpi(char str1[100],char str2[100]){ int len1 = strlen(str1), len2 = strlen(str2), i; if(len1!=len2){ return 1; } else{ for(i=0;i='A'&&str1[i]<='Z')&&(str2[i]>='a'&&str2[i]<='z')&&(str2[i]-65!=str1[i])) return 1; else if((str2[i]>='A'&&str2[i]<='Z')&&(str1[i]>='a'&&str1[i]<='z')&&(str1[i]-65!=str2[i])) return 1; else if(str1[i]!=str2[i]) return 1; } } return 0; }", "after": "pub extern \"C\" fn strcmpi(mut str1: *mut i8, mut str2: *mut i8) -> i32 { unsafe { let mut len1: i32 = strlen(str1 as *const i8) as i32; let mut len2: i32 = strlen(str2 as *const i8) as i32; let mut i: i32 = 0; if len1 != len2 { return 1; } else { i = 0; while i < len1 { if *str1.offset(i as isize) as i32 >= 'A' as i32 && *str1.offset(i as isize) as i32 <= 'Z' as i32 && (*str2.offset(i as isize) as i32 >= 'a' as i32 && *str2.offset(i as isize) as i32 <= 'z' as i32) && *str2.offset(i as isize) as i32 - 65 != *str1.offset(i as isize) as i32 { return 1; } else if *str2.offset(i as isize) as i32 >= 'A' as i32 && *str2.offset(i as isize) as i32 <= 'Z' as i32 && (*str1.offset(i as isize) as i32 >= 'a' as i32 && *str1.offset(i as isize) as i32 <= 'z' as i32) && *str1.offset(i as isize) as i32 - 65 != *str2.offset(i as isize) as i32 { return 1; } else if *str1.offset(i as isize) as i32 != *str2.offset(i as isize) as i32 { return 1; } i += 1; i; } } return 0; } }" }, { "index": 308, "before": "int main(void) { \tint idx[] = { 23, 123, 1234, 12345, 20000, 30000, 40000, 50000, N, 0 }; \tint at = 0; \tmpz_init_set_ui(p[0], 1); \tfor (int i = 1; idx[at]; i++) { \t\tcalc(i); \t\tif (i != idx[at]) continue; \t\tgmp_printf(\"%2d:\\t%Zd\\n\", i, p[i]); \t\tat++; \t} }", "after": "fn main() -> i32 { let mut idx: [i32; 10] = [23, 123, 1234, 12345, 20000, 30000, 40000, 50000, 100000, 0]; let mut at: i32 = 0; let mut i: i32 = 1; while idx[at as usize] != 0 { calc(i); if !(i != idx[at as usize]) { at += 1; at; } i += 1; i; } return 0; }" }, { "index": 309, "before": "void calc(int n) { \tmpz_init_set_ui(p[n], 0); \tfor (int k = 1; k <= n; k++) { \t\tint d = n - k * (3 * k - 1) / 2; \t\tif (d < 0) break; \t\tif (k&1)mpz_add(p[n], p[n], p[d]); \t\telse\tmpz_sub(p[n], p[n], p[d]); \t\td -= k; \t\tif (d < 0) break; \t\tif (k&1)mpz_add(p[n], p[n], p[d]); \t\telse\tmpz_sub(p[n], p[n], p[d]); \t} }", "after": "pub extern \"C\" fn calc(mut n: i32) { let mut k: i32 = 1; while k <= n { let mut d: i32 = n - k * (3 * k - 1) / 2; if d < 0 { break; } d -= k; if d < 0 { break; } k += 1; k; } }" }, { "index": 310, "before": "void quaternion_print(quaternion_t *q) { if (q == NULL) return; printf(\"(%lf, %lf, %lf, %lf)\\n\", \t q->q[0], q->q[1], q->q[2], q->q[3]); }", "after": "pub extern \"C\" fn quaternion_print(mut q: *mut quaternion_t) { unsafe { if q.is_null() { return; } } print!( \"({}, {}, {}, {})\\n\", (*q).q[0 as usize], (*q).q[1 as usize], (*q).q[2 as usize], (*q).q[3 as usize] ); }" }, { "index": 311, "before": "void quaternion_add_d(quaternion_t *r, quaternion_t *q, double d) { if (q == NULL || r == NULL) return; quaternion_copy(r, q); r->q[0] += d; }", "after": "pub extern \"C\" fn quaternion_add_d(mut r: *mut quaternion_t, mut q: *mut quaternion_t, mut d: f64) { unsafe { if q.is_null() || r.is_null() { return; } quaternion_copy(r, q); (*r).q[0 as usize] += d; } }" }, { "index": 312, "before": "void quaternion_mul(quaternion_t *r, quaternion_t *a, quaternion_t *b) { size_t i; double ri = 0.0; if (r == NULL || a == NULL || b == NULL) return; R(0) = A(0)*B(0) - A(1)*B(1) - A(2)*B(2) - A(3)*B(3); R(1) = A(0)*B(1) + A(1)*B(0) + A(2)*B(3) - A(3)*B(2); R(2) = A(0)*B(2) - A(1)*B(3) + A(2)*B(0) + A(3)*B(1); R(3) = A(0)*B(3) + A(1)*B(2) - A(2)*B(1) + A(3)*B(0); }", "after": "pub extern \"C\" fn quaternion_mul( mut r: *mut quaternion_t, mut a: *mut quaternion_t, mut b: *mut quaternion_t, ) { unsafe { let mut i: u64 = 0; let mut ri: f64 = 0.0f64; if r.is_null() || a.is_null() || b.is_null() { return; }; (*r).q[0 as usize] = (*a).q[0 as usize] * (*b).q[0 as usize] - (*a).q[1 as usize] * (*b).q[1 as usize] - (*a).q[2 as usize] * (*b).q[2 as usize] - (*a).q[3 as usize] * (*b).q[3 as usize]; (*r).q[1 as usize] = (*a).q[0 as usize] * (*b).q[1 as usize] + (*a).q[1 as usize] * (*b).q[0 as usize] + (*a).q[2 as usize] * (*b).q[3 as usize] - (*a).q[3 as usize] * (*b).q[2 as usize]; (*r).q[2 as usize] = (*a).q[0 as usize] * (*b).q[2 as usize] - (*a).q[1 as usize] * (*b).q[3 as usize] + (*a).q[2 as usize] * (*b).q[0 as usize] + (*a).q[3 as usize] * (*b).q[1 as usize]; (*r).q[3 as usize] = (*a).q[0 as usize] * (*b).q[3 as usize] + (*a).q[1 as usize] * (*b).q[2 as usize] - (*a).q[2 as usize] * (*b).q[1 as usize] + (*a).q[3 as usize] * (*b).q[0 as usize]; } }" }, { "index": 313, "before": "void quaternion_neg(quaternion_t *r, quaternion_t *q) { size_t i; if (q == NULL || r == NULL) return; for(i = 0; i < 4; i++) r->q[i] = -q->q[i]; }", "after": "pub extern \"C\" fn quaternion_neg(mut r: *mut quaternion_t, mut q: *mut quaternion_t) { unsafe { let mut i: u64 = 0; if q.is_null() || r.is_null() { return; } i = 0; while i < 4 { (*r).q[i as usize] = -(*q).q[i as usize]; i = i.wrapping_add(1); i; } } }" }, { "index": 314, "before": "void quaternion_copy(quaternion_t *r, quaternion_t *q) { size_t i; if (r == NULL || q == NULL) return; for(i = 0; i < 4; i++) r->q[i] = q->q[i]; }", "after": "pub extern \"C\" fn quaternion_copy(mut r: *mut quaternion_t, mut q: *mut quaternion_t) { unsafe { let mut i: u64 = 0; if r.is_null() || q.is_null() { return; } i = 0; while i < 4 { (*r).q[i as usize] = (*q).q[i as usize]; i = i.wrapping_add(1); i; } } }" }, { "index": 315, "before": "void quaternion_conj(quaternion_t *r, quaternion_t *q) { size_t i; if (q == NULL || r == NULL) return; r->q[0] = q->q[0]; for(i = 1; i < 4; i++) r->q[i] = -q->q[i]; }", "after": "pub extern \"C\" fn quaternion_conj(mut r: *mut quaternion_t, mut q: *mut quaternion_t) { unsafe { let mut i: u64 = 0; if q.is_null() || r.is_null() { return; }; (*r).q[0 as usize] = (*q).q[0 as usize]; i = 1; while i < 4 { (*r).q[i as usize] = -(*q).q[i as usize]; i = i.wrapping_add(1); i; } } }" }, { "index": 316, "before": "bool quaternion_equal(quaternion_t *a, quaternion_t *b) { size_t i; for(i = 0; i < 4; i++) if (a->q[i] != b->q[i]) return false; return true; }", "after": "pub extern \"C\" fn quaternion_equal(mut a: *mut quaternion_t, mut b: *mut quaternion_t) -> bool { unsafe { let mut i: u64 = 0; i = 0; while i < 4 { if (*a).q[i as usize] != (*b).q[i as usize] { return 0 != 0; } i = i.wrapping_add(1); i; } return 1 != 0; } }" }, { "index": 317, "before": "int main() { size_t i; double d = 7.0; quaternion_t *q[3]; quaternion_t *r = quaternion_new(); quaternion_t *qd = quaternion_new_set(7.0, 0.0, 0.0, 0.0); q[0] = quaternion_new_set(1.0, 2.0, 3.0, 4.0); q[1] = quaternion_new_set(2.0, 3.0, 4.0, 5.0); q[2] = quaternion_new_set(3.0, 4.0, 5.0, 6.0); printf(\"r = %lf\\n\", d); for(i = 0; i < 3; i++) { printf(\"q[%u] = \", i); quaternion_print(q[i]); printf(\"abs q[%u] = %lf\\n\", i, quaternion_norm(q[i])); } printf(\"-q[0] = \"); quaternion_neg(r, q[0]); quaternion_print(r); printf(\"conj q[0] = \"); quaternion_conj(r, q[0]); quaternion_print(r); printf(\"q[1] + q[2] = \"); quaternion_add(r, q[1], q[2]); quaternion_print(r); printf(\"q[2] + q[1] = \"); quaternion_add(r, q[2], q[1]); quaternion_print(r); printf(\"q[0] * r = \"); quaternion_mul_d(r, q[0], d); quaternion_print(r); printf(\"q[0] * (r, 0, 0, 0) = \"); quaternion_mul(r, q[0], qd); quaternion_print(r); printf(\"q[1] * q[2] = \"); quaternion_mul(r, q[1], q[2]); quaternion_print(r); printf(\"q[2] * q[1] = \"); quaternion_mul(r, q[2], q[1]); quaternion_print(r); free(q[0]); free(q[1]); free(q[2]); free(r); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { let mut i: u64 = 0; let mut d: f64 = 7.0f64; let mut q: [*mut quaternion_t; 3] = [0 as *mut quaternion_t; 3]; let mut r: *mut quaternion_t = quaternion_new(); let mut qd: *mut quaternion_t = quaternion_new_set(7.0f64, 0.0f64, 0.0f64, 0.0f64); q[0 as usize] = quaternion_new_set(1.0f64, 2.0f64, 3.0f64, 4.0f64); q[1 as usize] = quaternion_new_set(2.0f64, 3.0f64, 4.0f64, 5.0f64); q[2 as usize] = quaternion_new_set(3.0f64, 4.0f64, 5.0f64, 6.0f64); print!(\"r = {}\\n\", d); i = 0; while i < 3 { print!(\"q[{}] = \", i); quaternion_print(q[i as usize]); print!(\"abs q[{}] = {}\\n\", i, quaternion_norm(q[i as usize])); i = i.wrapping_add(1); i; } print!(\"-q[0] = \"); quaternion_neg(r, q[0 as usize]); quaternion_print(r); print!(\"conj q[0] = \"); quaternion_conj(r, q[0 as usize]); quaternion_print(r); print!(\"q[1] + q[2] = \"); quaternion_add(r, q[1 as usize], q[2 as usize]); quaternion_print(r); print!(\"q[2] + q[1] = \"); quaternion_add(r, q[2 as usize], q[1 as usize]); quaternion_print(r); print!(\"q[0] * r = \"); quaternion_mul_d(r, q[0 as usize], d); quaternion_print(r); print!(\"q[0] * (r, 0, 0, 0) = \"); quaternion_mul(r, q[0 as usize], qd); quaternion_print(r); print!(\"q[1] * q[2] = \"); quaternion_mul(r, q[1 as usize], q[2 as usize]); quaternion_print(r); print!(\"q[2] * q[1] = \"); quaternion_mul(r, q[2 as usize], q[1 as usize]); quaternion_print(r); free(q[0 as usize] as *mut libc::c_void); free(q[1 as usize] as *mut libc::c_void); free(q[2 as usize] as *mut libc::c_void); free(r as *mut libc::c_void); return 0; } }" }, { "index": 318, "before": "double quaternion_norm(quaternion_t *q) { size_t i; double r = 0.0; if (q == NULL) { fprintf(stderr, \"NULL quaternion in norm\\n\"); return 0.0; } for(i = 0; i < 4; i++) r += q->q[i] * q->q[i]; return sqrt(r); }", "after": "pub extern \"C\" fn quaternion_norm(mut q: *mut quaternion_t) -> f64 { unsafe { let mut i: u64 = 0; let mut r: f64 = 0.0f64; if q.is_null() { fprintf( stderr, b\"NULL quaternion in norm\\n\\0\" as *const u8 as *const i8, ); return 0.0f64; } i = 0; while i < 4 { r += (*q).q[i as usize] * (*q).q[i as usize]; i = i.wrapping_add(1); i; } return sqrt(r); } }" }, { "index": 319, "before": "void quaternion_mul_d(quaternion_t *r, quaternion_t *q, double d) { size_t i; if (r == NULL || q == NULL) return; for(i = 0; i < 4; i++) r->q[i] = q->q[i] * d; }", "after": "pub extern \"C\" fn quaternion_mul_d(mut r: *mut quaternion_t, mut q: *mut quaternion_t, mut d: f64) { unsafe { let mut i: u64 = 0; if r.is_null() || q.is_null() { return; } i = 0; while i < 4 { (*r).q[i as usize] = (*q).q[i as usize] * d; i = i.wrapping_add(1); i; } } }" }, { "index": 320, "before": "void quaternion_add(quaternion_t *r, quaternion_t *a, quaternion_t *b) { size_t i; if (r == NULL || a == NULL || b == NULL) return; for(i = 0; i < 4; i++) r->q[i] = a->q[i] + b->q[i]; }", "after": "pub extern \"C\" fn quaternion_add( mut r: *mut quaternion_t, mut a: *mut quaternion_t, mut b: *mut quaternion_t, ) { unsafe { let mut i: u64 = 0; if r.is_null() || a.is_null() || b.is_null() { return; } i = 0; while i < 4 { (*r).q[i as usize] = (*a).q[i as usize] + (*b).q[i as usize]; i = i.wrapping_add(1); i; } } }" }, { "index": 321, "before": "int main( void ) { double x, y; printf( \"Enter two numbers: \" ); scanf( \"%lf%lf\", &x, &y ); printf( \"The arithmetic-geometric mean is %lf\\n\", agm(x, y) ); return 0; }", "after": "fn main() -> i32 { let mut x: f64 = 0.; let mut y: f64 = 0.; print!(\"Enter two numbers: \"); unsafe { scanf( b\"%lf%lf\\0\" as *const u8 as *const i8, &mut x as *mut f64, &mut y as *mut f64, ); } print!(\"The arithmetic-geometric mean is {}\\n\", agm(x, y)); return 0; }" }, { "index": 322, "before": "double agm( double a, double g ) { /* arithmetic-geometric mean */ double iota = 1.0E-16; double a1, g1; if( a*g < 0.0 ) { printf( \"arithmetic-geometric mean undefined when x*y<0\\n\" ); exit(1); } while( fabs(a-g)>iota ) { a1 = (a + g) / 2.0; g1 = sqrt(a * g); a = a1; g = g1; } return a; }", "after": "pub extern \"C\" fn agm(mut a: f64, mut g: f64) -> f64 { let mut iota: f64 = 1.0E-16f64; let mut a1: f64 = 0.; let mut g1: f64 = 0.; unsafe { if a * g < 0.0f64 { print!(\"arithmetic-geometric mean undefined when x*y<0\\n\"); exit(1); } while fabs(a - g) > iota { a1 = (a + g) / 2.0f64; g1 = sqrt(a * g); a = a1; g = g1; } } return a; }" }, { "index": 323, "before": "int check_isbn13(const char *isbn) { int ch = *isbn, count = 0, sum = 0; /* check isbn contains 13 digits and calculate weighted sum */ for ( ; ch != 0; ch = *++isbn, ++count) { /* skip hyphens or spaces */ if (ch == ' ' || ch == '-') { --count; continue; } if (ch < '0' || ch > '9') { return 0; } if (count & 1) { sum += 3 * (ch - '0'); } else { sum += ch - '0'; } } if (count != 13) return 0; return !(sum%10); }", "after": "pub extern \"C\" fn check_isbn13(mut isbn: *const i8) -> i32 { unsafe { let mut ch: i32 = *isbn as i32; let mut count: i32 = 0; let mut sum: i32 = 0; while ch != 0 { if ch == ' ' as i32 || ch == '-' as i32 { count -= 1; count; } else { if ch < '0' as i32 || ch > '9' as i32 { return 0; } if count & 1 != 0 { sum += 3 * (ch - '0' as i32); } else { sum += ch - '0' as i32; } } isbn = isbn.offset(1); ch = *isbn as i32; count += 1; count; } if count != 13 { return 0; } return (sum % 10 == 0) as i32; } }" }, { "index": 324, "before": "int main() { int i; const char* isbns[] = {\"978-1734314502\", \"978-1734314509\", \"978-1788399081\", \"978-1788399083\"}; for (i = 0; i < 4; ++i) { printf(\"%s: %s\\n\", isbns[i], check_isbn13(isbns[i]) ? \"good\" : \"bad\"); } return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut isbns: [*const i8; 4] = [ b\"978-1734314502\\0\" as *const u8 as *const i8, b\"978-1734314509\\0\" as *const u8 as *const i8, b\"978-1788399081\\0\" as *const u8 as *const i8, b\"978-1788399083\\0\" as *const u8 as *const i8, ]; i = 0; unsafe { while i < 4 { if check_isbn13(isbns[i as usize]) != 0 { print!( \"{}: {}\\n\", build_str_from_raw_ptr(isbns[i as usize] as *mut u8), \"good\\0\" ) } else { print!( \"{}: {}\\n\", build_str_from_raw_ptr(isbns[i as usize] as *mut u8), \"bad\\0\" ) }; i += 1; i; } } return 0; }" }, { "index": 325, "before": "int main() { regex_t preg; regmatch_t substmatch[1]; const char *tp = \"string$\"; const char *t1 = \"this is a matching string\"; const char *t2 = \"this is not a matching string!\"; const char *ss = \"istyfied\"; regcomp(&preg, \"string$\", REG_EXTENDED); printf(\"'%s' %smatched with '%s'\\n\", t1, (regexec(&preg, t1, 0, NULL, 0)==0) ? \"\" : \"did not \", tp); printf(\"'%s' %smatched with '%s'\\n\", t2, (regexec(&preg, t2, 0, NULL, 0)==0) ? \"\" : \"did not \", tp); regfree(&preg); /* change \"a[a-z]+\" into \"istifyed\"?*/ regcomp(&preg, \"a[a-z]+\", REG_EXTENDED); if ( regexec(&preg, t1, 1, substmatch, 0) == 0 ) { //fprintf(stderr, \"%d, %d\\n\", substmatch[0].rm_so, substmatch[0].rm_eo); char *ns = malloc(substmatch[0].rm_so + 1 + strlen(ss) + (strlen(t1) - substmatch[0].rm_eo) + 2); memcpy(ns, t1, substmatch[0].rm_so+1); memcpy(&ns[substmatch[0].rm_so], ss, strlen(ss)); memcpy(&ns[substmatch[0].rm_so+strlen(ss)], &t1[substmatch[0].rm_eo], strlen(&t1[substmatch[0].rm_eo])); ns[ substmatch[0].rm_so + strlen(ss) + strlen(&t1[substmatch[0].rm_eo]) ] = 0; printf(\"mod string: '%s'\\n\", ns); free(ns); } else { printf(\"the string '%s' is the same: no matching!\\n\", t1); } regfree(&preg); return 0; }", "after": "fn main() -> i32 { unsafe { let mut preg : regex_t = regex_t { __buffer : 0 as * mut re_dfa_t, __allocated : 0, __used : 0, __syntax : 0, __fastmap : 0 as * mut i8, __translate : 0 as * mut u8, re_nsub : 0, __can_be_null___regs_allocated___fastmap_accurate___no_sub___not_bol___not_eol___newline_anchor : [0; 1], c2rust_padding : [0; 7], }; let mut substmatch: [regmatch_t; 1] = [regmatch_t { rm_so: 0, rm_eo: 0 }; 1]; let mut tp: *const i8 = b\"string$\\0\" as *const u8 as *const i8; let mut t1: *const i8 = b\"this is a matching string\\0\" as *const u8 as *const i8; let mut t2: *const i8 = b\"this is not a matching string!\\0\" as *const u8 as *const i8; let mut ss: *const i8 = b\"istyfied\\0\" as *const u8 as *const i8; regcomp(&mut preg, b\"string$\\0\" as *const u8 as *const i8, 1); if regexec(&mut preg, t1, 0, 0 as *mut regmatch_t, 0) == 0 { print!( \"{} {}matched with {}\\n\", build_str_from_raw_ptr(t1 as *mut u8), \"\\0\", build_str_from_raw_ptr(tp as *mut u8) ) } else { print!( \"{} {}matched with {}\\n\", build_str_from_raw_ptr(t1 as *mut u8), \"did not \\0\", build_str_from_raw_ptr(tp as *mut u8) ) }; if regexec(&mut preg, t2, 0, 0 as *mut regmatch_t, 0) == 0 { print!( \"{} {}matched with {}\\n\", build_str_from_raw_ptr(t2 as *mut u8), \"\\0\", build_str_from_raw_ptr(tp as *mut u8) ) } else { print!( \"{} {}matched with {}\\n\", build_str_from_raw_ptr(t2 as *mut u8), \"did not \\0\", build_str_from_raw_ptr(tp as *mut u8) ) }; regfree(&mut preg); regcomp(&mut preg, b\"a[a-z]+\\0\" as *const u8 as *const i8, 1); if regexec(&mut preg, t1, 1, substmatch.as_mut_ptr(), 0) == 0 { let mut ns: *mut i8 = malloc( ((substmatch[0 as usize].rm_so + 1i32) as u64) .wrapping_add(strlen(ss)) .wrapping_add((strlen(t1)).wrapping_sub(substmatch[0 as usize].rm_eo as u64)) .wrapping_add(2), ) as *mut i8; memcpy( ns as *mut libc::c_void, t1 as *const libc::c_void, (substmatch[0 as usize].rm_so + 1i32) as u64, ); memcpy( &mut *ns.offset((*substmatch.as_mut_ptr().offset(0 as isize)).rm_so as isize) as *mut i8 as *mut libc::c_void, ss as *const libc::c_void, strlen(ss), ); memcpy( &mut *ns.offset( ((*substmatch.as_mut_ptr().offset(0 as isize)).rm_so as u64) .wrapping_add((strlen as unsafe extern \"C\" fn(*const i8) -> u64)(ss)) as isize, ) as *mut i8 as *mut libc::c_void, &*t1.offset((*substmatch.as_mut_ptr().offset(0 as isize)).rm_eo as isize) as *const i8 as *const libc::c_void, strlen(&*t1.offset((*substmatch.as_mut_ptr().offset(0 as isize)).rm_eo as isize)), ); *ns.offset( (substmatch[0 as usize].rm_so as u64) .wrapping_add(strlen(ss)) .wrapping_add(strlen( &*t1.offset((*substmatch.as_mut_ptr().offset(0 as isize)).rm_eo as isize), )) as isize, ) = 0; print!(\"mod string: {}\\n\", build_str_from_raw_ptr(ns as *mut u8)); free(ns as *mut libc::c_void); } else { print!( \"the string {} is the same: no matching!\\n\", build_str_from_raw_ptr(t1 as *mut u8) ); } regfree(&mut preg); return 0; } }" }, { "index": 326, "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": "fn main() -> i32 { let mut a: i32 = 0; unsafe { if a == 42 { } else { __assert_fail( b\"a == 42\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 6, (*::core::mem::transmute::<&[u8; 11], &[i8; 11]>(b\"int main()\\0\")).as_ptr(), ); } 'c_59: { if a == 42 { } else { __assert_fail( b\"a == 42\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 6, (*::core::mem::transmute::<&[u8; 11], &[i8; 11]>(b\"int main()\\0\")).as_ptr(), ); } }; } return 0; }" }, { "index": 327, "before": "uint64_t digit_sum(uint64_t n, uint64_t sum) { ++sum; while (n > 0 && n % 10 == 0) { sum -= 9; n /= 10; } return sum; }", "after": "pub extern \"C\" fn digit_sum(mut n: u64, mut sum: u64) -> u64 { sum = sum.wrapping_add(1); sum; while n > 0 && n.wrapping_rem(10) == 0 { sum = (sum as u64).wrapping_sub(9) as u64; n = (n as u64).wrapping_div(10) as u64; } return sum; }" }, { "index": 328, "before": "bool divisible(uint64_t n, uint64_t d) { if ((d & 1) == 0 && (n & 1) == 1) return false; return n % d == 0; }", "after": "pub extern \"C\" fn divisible(mut n: u64, mut d: u64) -> bool { if d & 1 == 0 && n & 1 == 1 { return 0 != 0; } return n.wrapping_rem(d) == 0; }" }, { "index": 329, "before": "int main() { setlocale(LC_ALL, \"\"); uint64_t previous = 1, gap = 0, sum = 0; int niven_index = 0, gap_index = 1; printf(\"Gap index Gap Niven index Niven number\\n\"); for (uint64_t niven = 1; gap_index <= 32; ++niven) { sum = digit_sum(niven, sum); if (divisible(niven, sum)) { if (niven > previous + gap) { gap = niven - previous; printf(\"%'9d %'4llu %'14d %'15llu\\n\", gap_index++, gap, niven_index, previous); } previous = niven; ++niven_index; } } return 0; }", "after": "fn main() -> i32 { unsafe { setlocale(6, b\"\\0\" as *const u8 as *const i8); } let mut previous: u64 = 1; let mut gap: u64 = 0; let mut sum: u64 = 0; let mut niven_index: i32 = 0; let mut gap_index: i32 = 1; print!(\"Gap index Gap Niven index Niven number\\n\"); let mut niven: u64 = 1; while gap_index <= 32 { sum = digit_sum(niven, sum); if divisible(niven, sum) { if niven > previous.wrapping_add(gap) { gap = niven.wrapping_sub(previous); let fresh0 = gap_index; gap_index = gap_index + 1; print!( \"{:9} {:4} {:14} {:15}\\n\", fresh0, gap, niven_index, previous ); } previous = niven; niven_index += 1; niven_index; } niven = niven.wrapping_add(1); niven; } return 0; }" }, { "index": 330, "before": "int main() { \tint i, id[N]; \tpthread_t tid[N]; \tfor (i = 0; i < N; i++) \t\tpthread_mutex_init(forks + (id[i] = i), 0); \tfor (i = 0; i < N; i++) \t\tpthread_create(tid + i, 0, philosophize, id + i); \t/* wait forever: the threads don't actually stop */ \treturn pthread_join(tid[0], 0); }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut id: [i32; 5] = [0; 5]; let mut tid: [u64; 5] = [0; 5]; i = 0; unsafe { while i < 5 { id[i as usize] = i; pthread_mutex_init( forks.as_mut_ptr().offset(id[i as usize] as isize), 0 as *const pthread_mutexattr_t, ); i += 1; i; } } i = 0; unsafe { while i < 5 { pthread_create( tid.as_mut_ptr().offset(i as isize), 0 as *const pthread_attr_t, Some(philosophize as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), id.as_mut_ptr().offset(i as isize) as *mut libc::c_void, ); i += 1; i; } return pthread_join(tid[0 as usize], 0 as *mut *mut libc::c_void); } }" }, { "index": 331, "before": "void print(int y, int x, const char *fmt, ...) { \tstatic pthread_mutex_t screen = PTHREAD_MUTEX_INITIALIZER; \tva_list ap; \tva_start(ap, fmt); \tlock(&screen); \txy(y + 1, x), vprintf(fmt, ap); \txy(N + 1, 1), fflush(stdout); \tunlock(&screen); }", "after": "pub unsafe extern \"C\" fn print(mut y: i32, mut x: i32, mut fmt: *const i8, mut args: ...) { static mut screen: pthread_mutex_t = pthread_mutex_t { __data: { let mut init = __pthread_mutex_s { __lock: 0, __count: 0, __owner: 0, __nusers: 0, __kind: PTHREAD_MUTEX_TIMED_NP as i32, __spins: 0, __elision: 0, __list: { let mut init = __pthread_internal_list { __prev: 0 as *const __pthread_internal_list as *mut __pthread_internal_list, __next: 0 as *const __pthread_internal_list as *mut __pthread_internal_list, }; init }, }; init }, }; let mut ap: ::core::ffi::VaListImpl; ap = args.clone(); pthread_mutex_lock(&mut screen); print!(\"\\x1B[{};{}H\", y + 1, x); vprintf(fmt, ap.as_va_list()); print!(\"\\x1B[{};{}H\", 5 + 1, 1); fflush(stdout); pthread_mutex_unlock(&mut screen); }" }, { "index": 332, "before": "void think(int id) { \tint i, t; \tchar buf[64] = {0}; \tdo { \t\tclear_eol(id); \t\tsprintf(buf, \"..oO (%s)\", topic[t = rand() % M]); \t\tfor (i = 0; buf[i]; i++) { \t\t\tprint(id, i+12, \"%c\", buf[i]); \t\t\tif (i < 5) usleep(200000); \t\t} \t\tusleep(500000 + rand() % 1000000); \t} while (t); }", "after": "pub extern \"C\" fn think(mut id: i32) { let mut i: i32 = 0; let mut t: i32 = 0; let mut buf: [i8; 64] = [0; 64]; unsafe { loop { print(id, 12, b\"\\x1B[K\\0\" as *const u8 as *const i8); t = rand() % 5; sprintf( buf.as_mut_ptr(), b\"..oO (%s)\\0\" as *const u8 as *const i8, topic[t as usize], ); i = 0; while buf[i as usize] != 0 { print( id, i + 12, b\"%c\\0\" as *const u8 as *const i8, buf[i as usize] as i32, ); if i < 5 { usleep(200000); } i += 1; i; } usleep((500000 + rand() % 1000000i32) as u32); if !(t != 0) { break; } } } }" }, { "index": 333, "before": "void eat(int id) { \tint f[2], ration, i; /* forks */ \tf[0] = f[1] = id; \t/* make some (but not all) philosophers leftie. \t could have been f[!id] = (id + 1) %N; for example */ \tf[id & 1] = (id + 1) % N; \tclear_eol(id); \tprint(id, 12, \"..oO (forks, need forks)\"); \tfor (i = 0; i < 2; i++) { \t\tlock(forks + f[i]); \t\tif (!i) clear_eol(id); \t\tprint(id, 12 + (f[i] != id) * 6, \"fork%d\", f[i]); \t\t/* delay 1 sec to clearly show the order of fork acquisition */ \t\tsleep(1); \t} \tfor (i = 0, ration = 3 + rand() % 8; i < ration; i++) \t\tprint(id, 24 + i * 4, \"nom\"), sleep(1); \t/* done nomming, give up forks (order doesn't matter) */ \tfor (i = 0; i < 2; i++) unlock(forks + f[i]); }", "after": "pub extern \"C\" fn eat(mut id: i32) { let mut f: [i32; 2] = [0; 2]; let mut ration: i32 = 0; let mut i: i32 = 0; f[1 as usize] = id; f[0 as usize] = f[1 as usize]; f[(id & 1i32) as usize] = (id + 1) % 5; unsafe { print(id, 12, b\"\\x1B[K\\0\" as *const u8 as *const i8); print( id, 12, b\"..oO (forks, need forks)\\0\" as *const u8 as *const i8, ); } i = 0; unsafe { while i < 2 { pthread_mutex_lock(forks.as_mut_ptr().offset(f[i as usize] as isize)); if i == 0 { print(id, 12, b\"\\x1B[K\\0\" as *const u8 as *const i8); } print( id, 12 + (f[i as usize] != id) as i32 * 6, b\"fork%d\\0\" as *const u8 as *const i8, f[i as usize], ); sleep(1); i += 1; i; } } i = 0; unsafe { ration = 3 + rand() % 8; while i < ration { print(id, 24 + i * 4, b\"nom\\0\" as *const u8 as *const i8); sleep(1); i += 1; i; } } i = 0; unsafe { while i < 2 { pthread_mutex_unlock(forks.as_mut_ptr().offset(f[i as usize] as isize)); i += 1; i; } } }" }, { "index": 334, "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": "fn main() -> i32 { let mut a: i32 = 0; let mut b: i32 = 0; let mut step: i32 = 0; print!(\"Enter first two Leonardo numbers and increment step : \"); unsafe { scanf( b\"%d%d%d\\0\" as *const u8 as *const i8, &mut a as *mut i32, &mut b as *mut i32, &mut step as *mut i32, ); } leonardo(a, b, step, 25); return 0; }" }, { "index": 335, "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 extern \"C\" fn leonardo(mut a: i32, mut b: i32, mut step: i32, mut num: i32) { let mut i: i32 = 0; let mut temp: i32 = 0; print!(\"First 25 Leonardo numbers : \\n\"); i = 1; while i <= num { if i == 1 { print!(\" {}\", a); } else if i == 2 { print!(\" {}\", b); } else { print!(\" {}\", a + b + step); temp = a; a = b; b = temp + b + step; } i += 1; i; } }" }, { "index": 336, "before": "int main(void) { const char *test[] = {\"ABC\", \"DEF\", \"G\", \"H\"}; char *s; for (size_t i = 0; i < 5; i++) { s = quib(test, i); printf(\"%s\\n\", s); free(s); } return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { let mut test: [*const i8; 4] = [ b\"ABC\\0\" as *const u8 as *const i8, b\"DEF\\0\" as *const u8 as *const i8, b\"G\\0\" as *const u8 as *const i8, b\"H\\0\" as *const u8 as *const i8, ]; let mut s: *mut i8 = 0 as *mut i8; let mut i: u64 = 0; while i < 5 { s = quib(test.as_mut_ptr(), i); print!(\"{}\\n\", build_str_from_raw_ptr(s as *mut u8)); free(s as *mut libc::c_void); i = i.wrapping_add(1); i; } return 0; } }" }, { "index": 337, "before": "int main() { int n; for (n = 2; n < 200; n++) if (perfect(n)) printf(\"%d\\n\", n); return 0; }", "after": "fn main() -> i32 { let mut n: i32 = 0; n = 2; while n < 200 { if perfect(n) != 0 { print!(\"{}\\n\", n); } n += 1; n; } return 0; }" }, { "index": 338, "before": "int perfect(int n) { int max = (int)sqrt((double)n) + 1; int tot = 1; int i; for (i = 2; i < max; i++) if ((n % i) == 0) { tot += i; int q = n / i; if (q > i) tot += q; } return tot == n; }", "after": "pub extern \"C\" fn perfect(mut n: i32) -> i32 { unsafe { let mut max: i32 = sqrt(n as f64) as i32 + 1; let mut tot: i32 = 1; let mut i: i32 = 0; i = 2; while i < max { if n % i == 0 { tot += i; let mut q: i32 = n / i; if q > i { tot += q; } } i += 1; i; } return (tot == n) as i32; } }" }, { "index": 339, "before": "void leven(char *a, char *b) { \tint i, j, la = strlen(a), lb = strlen(b); \tedit *tbl = malloc(sizeof(edit) * (1 + la)); \ttbl[0] = calloc((1 + la) * (1 + lb), sizeof(edit_t)); \tfor (i = 1; i <= la; i++) \t\ttbl[i] = tbl[i-1] + (1+lb); \tfor (i = la; i >= 0; i--) { \t\tchar *aa = a + i; \t\tfor (j = lb; j >= 0; j--) { \t\t\tchar *bb = b + j; \t\t\tif (!*aa && !*bb) continue; \t\t\tedit e = &tbl[i][j]; \t\t\tedit repl = &tbl[i+1][j+1]; \t\t\tedit dela = &tbl[i+1][j]; \t\t\tedit delb = &tbl[i][j+1]; \t\t\te->c1 = *aa; \t\t\te->c2 = *bb; \t\t\tif (!*aa) { \t\t\t\te->next = delb; \t\t\t\te->n = e->next->n + 1; \t\t\t\tcontinue; \t\t\t} \t\t\tif (!*bb) { \t\t\t\te->next = dela; \t\t\t\te->n = e->next->n + 1; \t\t\t\tcontinue; \t\t\t} \t\t\te->next = repl; \t\t\tif (*aa == *bb) { \t\t\t\te->n = e->next->n; \t\t\t\tcontinue; \t\t\t} \t\t\tif (e->next->n > delb->n) { \t\t\t\te->next = delb; \t\t\t\te->c1 = 0; \t\t\t} \t\t\tif (e->next->n > dela->n) { \t\t\t\te->next = dela; \t\t\t\te->c1 = *aa; \t\t\t\te->c2 = 0; \t\t\t} \t\t\te->n = e->next->n + 1; \t\t} \t} \tedit p = tbl[0]; \tprintf(\"%s -> %s: %d edits\\n\", a, b, p->n); \twhile (p->next) { \t\tif (p->c1 == p->c2) \t\t\tprintf(\"%c\", p->c1); \t\telse { \t\t\tputchar('('); \t\t\tif (p->c1) putchar(p->c1); \t\t\tputchar(','); \t\t\tif (p->c2) putchar(p->c2); \t\t\tputchar(')'); \t\t} \t\tp = p->next; \t} \tputchar('\\n'); \tfree(tbl[0]); \tfree(tbl); }", "after": "pub extern \"C\" fn leven(mut a: *mut i8, mut b: *mut i8) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut la: i32 = strlen(a) as i32; let mut lb: i32 = strlen(b) as i32; let mut tbl: *mut edit = malloc((::core::mem::size_of::() as u64).wrapping_mul((1 + la) as u64)) as *mut edit; let ref mut fresh0 = *tbl.offset(0 as isize); *fresh0 = calloc( ((1 + la) * (1 + lb)) as u64, ::core::mem::size_of::() as u64, ) as edit; i = 1; while i <= la { let ref mut fresh1 = *tbl.offset(i as isize); *fresh1 = (*tbl.offset((i - 1i32) as isize)).offset((1 + lb) as isize); i += 1; i; } i = la; while i >= 0 { let mut aa: *mut i8 = a.offset(i as isize); j = lb; while j >= 0 { let mut bb: *mut i8 = b.offset(j as isize); if !(*aa == 0 && *bb == 0) { let mut e: edit = &mut *(*tbl.offset(i as isize)).offset(j as isize) as *mut edit_s; let mut repl: edit = &mut *(*tbl.offset((i + 1i32) as isize)) .offset((j + 1i32) as isize) as *mut edit_s; let mut dela: edit = &mut *(*tbl.offset((i + 1i32) as isize)).offset(j as isize) as *mut edit_s; let mut delb: edit = &mut *(*tbl.offset(i as isize)).offset((j + 1i32) as isize) as *mut edit_s; (*e).c1 = *aa; (*e).c2 = *bb; if *aa == 0 { (*e).next = delb; (*e).n = (*(*e).next).n + 1; } else if *bb == 0 { (*e).next = dela; (*e).n = (*(*e).next).n + 1; } else { (*e).next = repl; if *aa as i32 == *bb as i32 { (*e).n = (*(*e).next).n; } else { if (*(*e).next).n > (*delb).n { (*e).next = delb; (*e).c1 = 0; } if (*(*e).next).n > (*dela).n { (*e).next = dela; (*e).c1 = *aa; (*e).c2 = 0; }; (*e).n = (*(*e).next).n + 1; } } } j -= 1; j; } i -= 1; i; } let mut p: edit = *tbl.offset(0 as isize); print!( \"{} -> {}: {} edits\\n\", build_str_from_raw_ptr(a as *mut u8), build_str_from_raw_ptr(b as *mut u8), (*p).n ); while !((*p).next).is_null() { if (*p).c1 as i32 == (*p).c2 as i32 { print!(\"{}\", (*p).c1 as i32); } else { print!(\"{}\", '(' as i32); if (*p).c1 != 0 { print!(\"{}\", (*p).c1 as i32); } print!(\"{}\", ',' as i32); if (*p).c2 != 0 { print!(\"{}\", (*p).c2 as i32); } print!(\"{}\", ')' as i32); } p = (*p).next; } print!(\"{}\", '\\n' as i32); free(*tbl.offset(0 as isize) as *mut libc::c_void); free(tbl as *mut libc::c_void); } }" }, { "index": 340, "before": "int main(void) { \tleven(\"raisethysword\", \"rosettacode\"); \treturn 0; }", "after": "fn main() -> i32 { leven( b\"raisethysword\\0\" as *const u8 as *const i8 as *mut i8, b\"rosettacode\\0\" as *const u8 as *const i8 as *mut i8, ); return 0; }" }, { "index": 341, "before": "void main() { \tFILE * fp; \tchar * line = NULL; \tsize_t len = 0; \tssize_t read; \tfp = fopen(\"fasta.txt\", \"r\"); \tif (fp == NULL) \t\texit(EXIT_FAILURE); \tint state = 0; \twhile ((read = getline(&line, &len, fp)) != -1) { \t\t/* Delete trailing newline */ \t\tif (line[read - 1] == '\\n') \t\t\tline[read - 1] = 0; \t\t/* Handle comment lines*/ \t\tif (line[0] == '>') { \t\t\tif (state == 1) \t\t\t\tprintf(\"\\n\"); \t\t\tprintf(\"%s: \", line+1); \t\t\tstate = 1; \t\t} else { \t\t\t/* Print everything else */ \t\t\tprintf(\"%s\", line); \t\t} \t} \tprintf(\"\\n\"); \tfclose(fp); \tif (line) \t\tfree(line); \texit(EXIT_SUCCESS); }", "after": "fn main() { unsafe { let mut fp: *mut FILE = 0 as *mut FILE; let mut line: *mut i8 = 0 as *mut i8; let mut len: u64 = 0; let mut read: i64 = 0; fp = fopen( b\"fasta.txt\\0\" as *const u8 as *const i8, b\"r\\0\" as *const u8 as *const i8, ); if fp.is_null() { exit(1); } let mut state: i32 = 0; loop { read = getline(&mut line, &mut len, fp); if !(read != -1 as i64) { break; } if *line.offset((read - 1i64) as isize) as i32 == '\\n' as i32 { *line.offset((read - 1i64) as isize) = 0; } if *line.offset(0 as isize) as i32 == '>' as i32 { if state == 1 { print!(\"\\n\"); } print!( \"{}: \", build_str_from_raw_ptr(line.offset(1 as isize) as *mut u8) ); state = 1; } else { print!(\"{}\", build_str_from_raw_ptr(line as *mut u8)); } } print!(\"\\n\"); fclose(fp); if !line.is_null() { free(line as *mut libc::c_void); } exit(0); } }" }, { "index": 342, "before": "int main(void) { for (size_t i = 0; i < 20; i++) { char *binstr = bin(i); printf(\"%s\\n\", binstr); free(binstr); } }", "after": "fn main() -> i32 { unsafe { let mut i: u64 = 0; while i < 20 { let mut binstr: *mut i8 = bin(i as u32); print!(\"{}\\n\", build_str_from_raw_ptr(binstr as *mut u8)); free(binstr as *mut libc::c_void); i = i.wrapping_add(1); i; } return 0; } }" }, { "index": 343, "before": "int main(void) { \tdouble a[] = { \t\t1.00, 0.00, 0.00, 0.00, 0.00, 0.00, \t\t1.00, 0.63, 0.39, 0.25, 0.16, 0.10, \t\t1.00, 1.26, 1.58, 1.98, 2.49, 3.13, \t\t1.00, 1.88, 3.55, 6.70, 12.62, 23.80, \t\t1.00, 2.51, 6.32, 15.88, 39.90, 100.28, \t\t1.00, 3.14, 9.87, 31.01, 97.41, 306.02 \t}; \tdouble b[] = { -0.01, 0.61, 0.91, 0.99, 0.60, 0.02 }; \tdouble x[6]; \tint i; \tgauss_eliminate(a, b, x, 6); \tfor (i = 0; i < 6; i++) \t\tprintf(\"%g\\n\", x[i]); \treturn 0; }", "after": "fn main() -> i32 { let mut a: [f64; 36] = [ 1.00f64, 0.00f64, 0.00f64, 0.00f64, 0.00f64, 0.00f64, 1.00f64, 0.63f64, 0.39f64, 0.25f64, 0.16f64, 0.10f64, 1.00f64, 1.26f64, 1.58f64, 1.98f64, 2.49f64, 3.13f64, 1.00f64, 1.88f64, 3.55f64, 6.70f64, 12.62f64, 23.80f64, 1.00f64, 2.51f64, 6.32f64, 15.88f64, 39.90f64, 100.28f64, 1.00f64, 3.14f64, 9.87f64, 31.01f64, 97.41f64, 306.02f64, ]; let mut b: [f64; 6] = [-0.01f64, 0.61f64, 0.91f64, 0.99f64, 0.60f64, 0.02f64]; let mut x: [f64; 6] = [0.; 6]; let mut i: i32 = 0; gauss_eliminate(a.as_mut_ptr(), b.as_mut_ptr(), x.as_mut_ptr(), 6); i = 0; while i < 6 { print!(\"{}\\n\", x[i as usize]); i += 1; i; } return 0; }" }, { "index": 344, "before": "void swap_row(double *a, double *b, int r1, int r2, int n) { \tdouble tmp, *p1, *p2; \tint i; \tif (r1 == r2) return; \tfor (i = 0; i < n; i++) { \t\tp1 = mat_elem(a, r1, i, n); \t\tp2 = mat_elem(a, r2, i, n); \t\ttmp = *p1, *p1 = *p2, *p2 = tmp; \t} \ttmp = b[r1], b[r1] = b[r2], b[r2] = tmp; }", "after": "pub extern \"C\" fn swap_row(mut a: *mut f64, mut b: *mut f64, mut r1: i32, mut r2: i32, mut n: i32) { unsafe { let mut tmp: f64 = 0.; let mut p1: *mut f64 = 0 as *mut f64; let mut p2: *mut f64 = 0 as *mut f64; let mut i: i32 = 0; if r1 == r2 { return; } i = 0; while i < n { p1 = a.offset((r1 * n + i) as isize); p2 = a.offset((r2 * n + i) as isize); tmp = *p1; *p1 = *p2; *p2 = tmp; i += 1; i; } tmp = *b.offset(r1 as isize); *b.offset(r1 as isize) = *b.offset(r2 as isize); *b.offset(r2 as isize) = tmp; } }" }, { "index": 345, "before": "void gauss_eliminate(double *a, double *b, double *x, int n) { #define A(y, x) (*mat_elem(a, y, x, n)) \tint i, j, col, row, max_row,dia; \tdouble max, tmp; \tfor (dia = 0; dia < n; dia++) { \t\tmax_row = dia, max = A(dia, dia); \t\tfor (row = dia + 1; row < n; row++) \t\t\tif ((tmp = fabs(A(row, dia))) > max) \t\t\t\tmax_row = row, max = tmp; \t\tswap_row(a, b, dia, max_row, n); \t\tfor (row = dia + 1; row < n; row++) { \t\t\ttmp = A(row, dia) / A(dia, dia); \t\t\tfor (col = dia+1; col < n; col++) \t\t\t\tA(row, col) -= tmp * A(dia, col); \t\t\tA(row, dia) = 0; \t\t\tb[row] -= tmp * b[dia]; \t\t} \t} \tfor (row = n - 1; row >= 0; row--) { \t\ttmp = b[row]; \t\tfor (j = n - 1; j > row; j--) \t\t\ttmp -= x[j] * A(row, j); \t\tx[row] = tmp / A(row, row); \t} #undef A }", "after": "pub extern \"C\" fn gauss_eliminate(mut a: *mut f64, mut b: *mut f64, mut x: *mut f64, mut n: i32) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut col: i32 = 0; let mut row: i32 = 0; let mut max_row: i32 = 0; let mut dia: i32 = 0; let mut max: f64 = 0.; let mut tmp: f64 = 0.; dia = 0; while dia < n { max_row = dia; max = *a.offset((dia * n + dia) as isize); row = dia + 1; while row < n { tmp = fabs(*a.offset((row * n + dia) as isize)); if tmp > max { max_row = row; max = tmp; } row += 1; row; } swap_row(a, b, dia, max_row, n); row = dia + 1; while row < n { tmp = *a.offset((row * n + dia) as isize) / *a.offset((dia * n + dia) as isize); col = dia + 1; while col < n { *a.offset((row * n + col) as isize) -= tmp * *a.offset((dia * n + col) as isize); col += 1; col; } *a.offset((row * n + dia) as isize) = 0 as f64; *b.offset(row as isize) -= tmp * *b.offset(dia as isize); row += 1; row; } dia += 1; dia; } row = n - 1; while row >= 0 { tmp = *b.offset(row as isize); j = n - 1; while j > row { tmp -= *x.offset(j as isize) * *a.offset((row * n + j) as isize); j -= 1; j; } *x.offset(row as isize) = tmp / *a.offset((row * n + row) as isize); row -= 1; row; } } }" }, { "index": 346, "before": "bool libertyOrDeathAtRandom(int prisoners,int chances){ \tint i,j,chosenDrawer; \tfor(i= 1;i bool { let mut i: i32 = 0; let mut j: i32 = 0; let mut chosenDrawer: i32 = 0; i = 1; unsafe { while i < prisoners + 1 { let mut foundCard: bool = 0 != 0; j = 0; while j < chances { loop { chosenDrawer = rand() % prisoners + 1; if !((*drawerSet.offset(chosenDrawer as isize)).hasBeenOpened as i32 == 1) { break; } } if (*drawerSet.offset(chosenDrawer as isize)).cardNum == i { foundCard = 1 != 0; break; } else { (*drawerSet.offset(chosenDrawer as isize)).hasBeenOpened = 1 != 0; j += 1; j; } } closeAllDrawers(prisoners); if foundCard as i32 == 0 { return 1 != 0; } i += 1; i; } } return 0 != 0; }" }, { "index": 347, "before": "void closeAllDrawers(int prisoners){ \tint i; \tfor(i=1;i() as u64)) as *mut drawer) .offset(-(1 as isize)); card = rand() % prisoners + 1; *drawerSet.offset(1 as isize) = { let mut init = drawer { cardNum: card, hasBeenOpened: 0 != 0, }; init }; i = 1 + 1; while i < prisoners + 1 { unique = 0 != 0; while unique as i32 == 0 { j = 0; while j < i { if (*drawerSet.offset(j as isize)).cardNum == card { card = rand() % prisoners + 1; break; } else { j += 1; j; } } if j == i { unique = 1 != 0; } } *drawerSet.offset(i as isize) = { let mut init = drawer { cardNum: card, hasBeenOpened: 0 != 0, }; init }; i += 1; i; } } }" }, { "index": 349, "before": "bool libertyOrDeathPlanned(int prisoners,int chances){ \tint i,j,chosenDrawer; \tfor(i=1;i bool { let mut i: i32 = 0; let mut j: i32 = 0; let mut chosenDrawer: i32 = 0; i = 1; unsafe { while i < prisoners + 1 { chosenDrawer = i; let mut foundCard: bool = 0 != 0; j = 0; while j < chances { (*drawerSet.offset(chosenDrawer as isize)).hasBeenOpened = 1 != 0; if (*drawerSet.offset(chosenDrawer as isize)).cardNum == i { foundCard = 1 != 0; break; } else { if chosenDrawer == (*drawerSet.offset(chosenDrawer as isize)).cardNum { loop { chosenDrawer = rand() % prisoners + 1; if !((*drawerSet.offset(chosenDrawer as isize)).hasBeenOpened as i32 == 1) { break; } } } else { chosenDrawer = (*drawerSet.offset(chosenDrawer as isize)).cardNum; } j += 1; j; } } closeAllDrawers(prisoners); if foundCard as i32 == 0 { return 1 != 0; } i += 1; i; } } return 0 != 0; }" }, { "index": 350, "before": "int main(int argc,char** argv) { \tint prisoners, chances; \tunsigned long long int trials,i,count = 0; char* end; \tif(argc!=4) \t\treturn printf(\"Usage : %s \",argv[0]); \tprisoners = atoi(argv[1]); \tchances = atoi(argv[2]); \ttrials = strtoull(argv[3],&end,10); \tsrand(time(NULL)); \tprintf(\"Running random trials...\"); \tfor(i=0;i i32 { unsafe { let mut prisoners: i32 = 0; let mut chances: i32 = 0; let mut trials: u64 = 0; let mut i: u64 = 0; let mut count: u64 = 0; let mut end: *mut i8 = 0 as *mut i8; if argc != 4 { let str_to_print = format!( \"Usage : {} \", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); print!(\"{}\", str_to_print); return str_to_print.chars().count() as i32; } prisoners = atoi(*argv.offset(1 as isize)); chances = atoi(*argv.offset(2 as isize)); trials = strtoull(*argv.offset(3 as isize), &mut end, 10); srand(rust_time(None) as u32); print!(\"Running random trials...\"); i = 0; while i < trials { initialize(prisoners); count = count.wrapping_add( (if libertyOrDeathAtRandom(prisoners, chances) as i32 == 1 { 0 } else { 1 }) as u64, ); i = i.wrapping_add(1); } print!( \"\\n\\nGames Played : {}\\nGames Won : {}\\nChances : {} % \\n\\n\", trials, count, 100.0f64 * count as f64 / trials as f64 ); count = 0; print!(\"Running strategic trials...\"); i = 0; while i < trials { initialize(prisoners); count = count.wrapping_add( (if libertyOrDeathPlanned(prisoners, chances) as i32 == 1 { 0 } else { 1 }) as u64, ); i = i.wrapping_add(1); } print!( \"\\n\\nGames Played : {}\\nGames Won : {}\\nChances : {} % \\n\\n\", trials, count, 100.0f64 * count as f64 / trials as f64 ); return 0; } }" }, { "index": 351, "before": "int main() { double coeffs[] = { -19.0, 7.0, -4.0, 6.0 }; printf(\"%5.1f\\n\", horner(coeffs, sizeof(coeffs)/sizeof(double), 3.0)); return 0; }", "after": "fn main() -> i32 { let mut coeffs: [f64; 4] = [-19.0f64, 7.0f64, -4.0f64, 6.0f64]; print!( \"{:5.1}\\n\", horner( coeffs.as_mut_ptr(), (::core::mem::size_of::<[f64; 4]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, 3.0f64, ) ); return 0; }" }, { "index": 352, "before": "double horner(double *coeffs, int s, double x) { int i; double res = 0.0; for(i=s-1; i >= 0; i--) { res = res * x + coeffs[i]; } return res; }", "after": "pub extern \"C\" fn horner(mut coeffs: *mut f64, mut s: i32, mut x: f64) -> f64 { unsafe { let mut i: i32 = 0; let mut res: f64 = 0.0f64; i = s - 1; while i >= 0 { res = res * x + *coeffs.offset(i as isize); i -= 1; i; } return res; } }" }, { "index": 353, "before": "int main(void) { \txint n, k, i; \tn = 41; \tk = 3; \tprintf(\"n = %llu, k = %llu, final survivor: %d\\n\", n, k, jos(n, k, 0)); \tn = 9876543210987654321ULL; \tk = 12031; \tprintf(\"n = %llu, k = %llu, three survivors:\", n, k); \tfor (i = 3; i--; ) \t\tprintf(\" %llu\", jos_large(n, k, i)); \tputchar('\\n'); \treturn 0; }", "after": "fn main() -> i32 { let mut n: u64 = 0; let mut k: u64 = 0; let mut i: u64 = 0; n = 41; k = 3; print!( \"n = {}, k = {}, final survivor: {}\\n\", n, k, jos(n as i32, k as i32, 0) ); n = 9876543210987654321; k = 12031; print!(\"n = {}, k = {}, three survivors:\", n, k); i = 3; loop { let fresh0 = i; i = i.wrapping_sub(1); if !(fresh0 != 0) { break; } print!(\" {}\", jos_large(n, k, i)); } print!(\"{}\", '\\n' as i32); return 0; }" }, { "index": 354, "before": "int jos(int n, int k, int m) { \tint a; \tfor (a = m + 1; a <= n; a++) \t\tm = (m + k) % a; \treturn m; }", "after": "pub extern \"C\" fn jos(mut n: i32, mut k: i32, mut m: i32) -> i32 { let mut a: i32 = 0; a = m + 1; while a <= n { m = (m + k) % a; a += 1; a; } return m; }" }, { "index": 355, "before": "xint jos_large(xint n, xint k, xint m) { \tif (k <= 1) return n - m - 1; \txint a = m; \twhile (a < n) { \t\txint q = (a - m + k - 2) / (k - 1); \t\tif (a + q > n)\tq = n - a; \t\telse if (!q)\tq = 1; \t\tm = (m + q * k) % (a += q); \t} \treturn m; }", "after": "pub extern \"C\" fn jos_large(mut n: u64, mut k: u64, mut m: u64) -> u64 { if k <= 1 { return n.wrapping_sub(m).wrapping_sub(1); } let mut a: u64 = m; while a < n { let mut q: u64 = a .wrapping_sub(m) .wrapping_add(k) .wrapping_sub(2) .wrapping_div(k.wrapping_sub(1)); if a.wrapping_add(q) > n { q = n.wrapping_sub(a); } else if q == 0 { q = 1; } a = (a).wrapping_add(q) as u64; m = m.wrapping_add(q.wrapping_mul(k)).wrapping_rem(a); } return m; }" }, { "index": 356, "before": "size_t rprint(char *s, int *x, int len) { #define sep (a > s ? \",\" : \"\") /* use comma except before first output */ #define ol (s ? 100 : 0) /* print only if not testing for length */ \tint i, j; \tchar *a = s; \tfor (i = j = 0; i < len; i = ++j) { \t\tfor (; j < len - 1 && x[j + 1] == x[j] + 1; j++); \t\tif (i + 1 < j) \t\t\ta += snprintf(s?a:s, ol, \"%s%d-%d\", sep, x[i], x[j]); \t\telse \t\t\twhile (i <= j) \t\t\t\ta += snprintf(s?a:s, ol, \"%s%d\", sep, x[i++]); \t} \treturn a - s; #undef sep #undef ol }", "after": "pub extern \"C\" fn rprint(mut s: *mut i8, mut x: *mut i32, mut len: i32) -> u64 { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut a: *mut i8 = s; j = 0; i = j; while i < len { while j < len - 1 && *x.offset((j + 1i32) as isize) == *x.offset(j as isize) + 1 { j += 1; j; } if (i + 1) < j { a = a.offset(snprintf( if !s.is_null() { a } else { s }, (if !s.is_null() { 100 } else { 0 }) as u64, b\"%s%d-%d\\0\" as *const u8 as *const i8, if a > s { b\",\\0\" as *const u8 as *const i8 } else { b\"\\0\" as *const u8 as *const i8 }, *x.offset(i as isize), *x.offset(j as isize), ) as isize); } else { while i <= j { let fresh0 = i; i = i + 1; a = a.offset(snprintf( if !s.is_null() { a } else { s }, (if !s.is_null() { 100 } else { 0 }) as u64, b\"%s%d\\0\" as *const u8 as *const i8, if a > s { b\",\\0\" as *const u8 as *const i8 } else { b\"\\0\" as *const u8 as *const i8 }, *x.offset(fresh0 as isize), ) as isize); } } j += 1; i = j; } return a.offset_from(s) as u64; } }" }, { "index": 357, "before": "int main() { \tint x[] = {\t0, 1, 2, 4, 6, 7, 8, 11, 12, 14, \t\t\t15, 16, 17, 18, 19, 20, 21, 22, 23, 24, \t\t\t25, 27, 28, 29, 30, 31, 32, 33, 35, 36, \t\t\t37, 38, 39 }; \tchar *s = malloc(rprint(0, x, sizeof(x) / sizeof(int)) + 1); \trprint(s, x, sizeof(x) / sizeof(int)); \tprintf(\"%s\\n\", s); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut x: [i32; 33] = [ 0, 1, 2, 4, 6, 7, 8, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, ]; let mut s: *mut i8 = malloc( (rprint( 0 as *mut i8, x.as_mut_ptr(), (::core::mem::size_of::<[i32; 33]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, )) .wrapping_add(1), ) as *mut i8; rprint( s, x.as_mut_ptr(), (::core::mem::size_of::<[i32; 33]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, ); print!(\"{}\\n\", build_str_from_raw_ptr(s as *mut u8)); return 0; } }" }, { "index": 358, "before": "int numDigits(int num){ int len = 1; while(num>10){ num = num/10; len++; } return len; }", "after": "pub extern \"C\" fn numDigits(mut num: i32) -> i32 { let mut len: i32 = 1; while num > 10 { num = num / 10; len += 1; len; } return len; }" }, { "index": 359, "before": "int main(int argc,char** argv) { char str[100]; int counter = 0, len; if(argc!=2){ printf(\"Usage : %s \\n\",argv[0]); return 0; } FILE *fp = fopen(argv[1],\"r\"); while(fscanf(fp,\"%s\",str)!=EOF) buildGenome(str); fclose(fp); printGenome(); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut str: [i8; 100] = [0; 100]; let mut counter: i32 = 0; let mut len: i32 = 0; if argc != 2 { print!( \"Usage : {} \\n\", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); return 0; } let mut fp: *mut FILE = fopen(*argv.offset(1 as isize), b\"r\\0\" as *const u8 as *const i8); while fscanf(fp, b\"%s\\0\" as *const u8 as *const i8, str.as_mut_ptr()) != -1 { buildGenome(str.as_mut_ptr()); } fclose(fp); printGenome(); return 0; } }" }, { "index": 360, "before": "void buildGenome(char str[100]){ int len = strlen(str),i; genome *genomeIterator, *newGenome; totalLength += len; for(i=0;istrand = (char*)malloc(len*sizeof(char)); strcpy(genomeData->strand,str); genomeData->length = len; genomeData->next = NULL; } else{ genomeIterator = genomeData; while(genomeIterator->next!=NULL) genomeIterator = genomeIterator->next; newGenome = (genome*)malloc(sizeof(genome)); newGenome->strand = (char*)malloc(len*sizeof(char)); strcpy(newGenome->strand,str); newGenome->length = len; newGenome->next = NULL; genomeIterator->next = newGenome; } }", "after": "pub extern \"C\" fn buildGenome(mut str: *mut i8) { unsafe { let mut len: i32 = strlen(str as *const i8) as i32; let mut i: i32 = 0; let mut genomeIterator: *mut genome = 0 as *mut genome; let mut newGenome: *mut genome = 0 as *mut genome; totalLength += len; i = 0; while i < len { match *str.offset(i as isize) as i32 { 65 => { Adenine += 1; Adenine; } 84 => { Thymine += 1; Thymine; } 67 => { Cytosine += 1; Cytosine; } 71 => { Guanine += 1; Guanine; } _ => {} } i += 1; i; } if genomeData.is_null() { genomeData = malloc(::core::mem::size_of::() as u64) as *mut genome; (*genomeData).strand = malloc((len as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i8; strcpy((*genomeData).strand, str as *const i8); (*genomeData).length = len; (*genomeData).next = 0 as *mut genome; } else { genomeIterator = genomeData; while !((*genomeIterator).next).is_null() { genomeIterator = (*genomeIterator).next; } newGenome = malloc(::core::mem::size_of::() as u64) as *mut genome; (*newGenome).strand = malloc((len as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i8; strcpy((*newGenome).strand, str as *const i8); (*newGenome).length = len; (*newGenome).next = 0 as *mut genome; (*genomeIterator).next = newGenome; }; } }" }, { "index": 361, "before": "void printGenome(){ genome* genomeIterator = genomeData; int width = numDigits(totalLength), len = 0; printf(\"Sequence:\\n\"); while(genomeIterator!=NULL){ printf(\"\\n%*d%3s%3s\",width+1,len,\":\",genomeIterator->strand); len += genomeIterator->length; genomeIterator = genomeIterator->next; } printf(\"\\n\\nBase Count\\n----------\\n\\n\"); printf(\"%3c%3s%*d\\n\",'A',\":\",width+1,Adenine); printf(\"%3c%3s%*d\\n\",'T',\":\",width+1,Thymine); printf(\"%3c%3s%*d\\n\",'C',\":\",width+1,Cytosine); printf(\"%3c%3s%*d\\n\",'G',\":\",width+1,Guanine); printf(\"\\n%3s%*d\\n\",\"Total:\",width+1,Adenine + Thymine + Cytosine + Guanine); free(genomeData); }", "after": "pub extern \"C\" fn printGenome() { unsafe { let mut genomeIterator: *mut genome = genomeData; let mut width: i32 = numDigits(totalLength); let mut len: i32 = 0; print!(\"Sequence:\\n\"); while !genomeIterator.is_null() { print!( \"\\n{1:0$}{2:3}{3:3}\", (width + 1).abs() as usize, len, \":\\0\", build_str_from_raw_ptr((*genomeIterator).strand as *mut u8) ); len += (*genomeIterator).length; genomeIterator = (*genomeIterator).next; } print!(\"\\n\\nBase Count\\n----------\\n\\n\"); print!( \"{0:3}{1:3}{3:2$}\\n\", 'A' as i32, \":\\0\", (width + 1).abs() as usize, Adenine ); print!( \"{0:3}{1:3}{3:2$}\\n\", 'T' as i32, \":\\0\", (width + 1).abs() as usize, Thymine ); print!( \"{0:3}{1:3}{3:2$}\\n\", 'C' as i32, \":\\0\", (width + 1).abs() as usize, Cytosine ); print!( \"{0:3}{1:3}{3:2$}\\n\", 'G' as i32, \":\\0\", (width + 1).abs() as usize, Guanine ); print!( \"\\n{0:3}{2:1$}\\n\", \"Total:\\0\", (width + 1).abs() as usize, Adenine + Thymine + Cytosine + Guanine ); free(genomeData as *mut libc::c_void); } }" }, { "index": 362, "before": "bool is_prime(ull n) { ull d; if (n < 2) return FALSE; if (!(n % 2)) return n == 2; if (!(n % 3)) return n == 3; d = 5; while (d * d <= n) { if (!(n % d)) return FALSE; d += 2; if (!(n % d)) return FALSE; d += 4; } return TRUE; }", "after": "pub extern \"C\" fn is_prime(mut n: u64) -> i32 { let mut d: u64 = 0; if n < 2 { return 0; } if n.wrapping_rem(2) == 0 { return (n == 2) as i32; } if n.wrapping_rem(3) == 0 { return (n == 3) as i32; } d = 5; while d.wrapping_mul(d) <= n { if n.wrapping_rem(d) == 0 { return 0; } d = (d).wrapping_add(2) as u64; if n.wrapping_rem(d) == 0 { return 0; } d = (d).wrapping_add(4) as u64; } return 1; }" }, { "index": 363, "before": "void ord(char *res, int n) { char suffix[3]; int m = n % 100; if (m >= 4 && m <= 20) { sprintf(res,\"%dth\", n); return; } switch(m % 10) { case 1: strcpy(suffix, \"st\"); break; case 2: strcpy(suffix, \"nd\"); break; case 3: strcpy(suffix, \"rd\"); break; default: strcpy(suffix, \"th\"); break; } sprintf(res, \"%d%s\", n, suffix); }", "after": "pub extern \"C\" fn ord(mut res: *mut i8, mut n: i32) { unsafe { let mut suffix: [i8; 3] = [0; 3]; let mut m: i32 = n % 100; if m >= 4 && m <= 20 { sprintf(res, b\"%dth\\0\" as *const u8 as *const i8, n); return; } match m % 10 { 1 => { strcpy(suffix.as_mut_ptr(), b\"st\\0\" as *const u8 as *const i8); } 2 => { strcpy(suffix.as_mut_ptr(), b\"nd\\0\" as *const u8 as *const i8); } 3 => { strcpy(suffix.as_mut_ptr(), b\"rd\\0\" as *const u8 as *const i8); } _ => { strcpy(suffix.as_mut_ptr(), b\"th\\0\" as *const u8 as *const i8); } } sprintf( res, b\"%d%s\\0\" as *const u8 as *const i8, n, suffix.as_mut_ptr(), ); } }" }, { "index": 364, "before": "void list_mags(int from, int thru, int digs, int per_line) { ull i = 0; int c = 0; char res1[13], res2[13]; if (from < 2) { printf(\"\\nFirst %d magnanimous numbers:\\n\", thru); } else { ord(res1, from); ord(res2, thru); printf(\"\\n%s through %s magnanimous numbers:\\n\", res1, res2); } for ( ; c < thru; ++i) { if (is_magnanimous(i)) { if (++c >= from) { printf(\"%*llu \", digs, i); if (!(c % per_line)) printf(\"\\n\"); } } } }", "after": "pub extern \"C\" fn list_mags(mut from: i32, mut thru: i32, mut digs: i32, mut per_line: i32) { let mut i: u64 = 0; let mut c: i32 = 0; let mut res1: [i8; 13] = [0; 13]; let mut res2: [i8; 13] = [0; 13]; unsafe { if from < 2 { print!(\"\\nFirst {} magnanimous numbers:\\n\", thru); } else { ord(res1.as_mut_ptr(), from); ord(res2.as_mut_ptr(), thru); print!( \"\\n{} through {} magnanimous numbers:\\n\", build_str_from_raw_ptr(res1.as_mut_ptr() as *mut u8), build_str_from_raw_ptr(res2.as_mut_ptr() as *mut u8) ); } } while c < thru { if is_magnanimous(i) != 0 { c += 1; if c >= from { print!(\"{1:0$} \", (digs).abs() as usize, i); if c % per_line == 0 { print!(\"\\n\"); } } } i = i.wrapping_add(1); i; } }" }, { "index": 365, "before": "int main() { list_mags(1, 45, 3, 15); list_mags(241, 250, 1, 10); list_mags(391, 400, 1, 10); return 0; }", "after": "fn main() -> i32 { list_mags(1, 45, 3, 15); list_mags(241, 250, 1, 10); list_mags(391, 400, 1, 10); return 0; }" }, { "index": 366, "before": "bool is_magnanimous(ull n) { ull p, q, r; if (n < 10) return TRUE; for (p = 10; ; p *= 10) { q = n / p; r = n % p; if (!is_prime(q + r)) return FALSE; if (q < 10) break; } return TRUE; }", "after": "pub extern \"C\" fn is_magnanimous(mut n: u64) -> i32 { let mut p: u64 = 0; let mut q: u64 = 0; let mut r: u64 = 0; if n < 10 { return 1; } p = 10; loop { q = n.wrapping_div(p); r = n.wrapping_rem(p); if is_prime(q.wrapping_add(r)) == 0 { return 0; } if q < 10 { break; } p = (p).wrapping_mul(10) as u64; } return 1; }" }, { "index": 367, "before": "int main(void) { \t// array bounds is sort of random here, it's big enough for 64bit unsigned. \tull sums[32*81 + 1] = {1, 0}; \tfor (int n = 1; ; n++) { \t\tfor (int i = n*81; i; i--) { \t\t\tfor (int j = 1; j < 10; j++) { \t\t\t\tint s = j*j; \t\t\t\tif (s > i) break; \t\t\t\tsums[i] += sums[i-s]; \t\t\t} \t\t} \t\tull count89 = 0; \t\tfor (int i = 1; i < n*81 + 1; i++) { \t\t\tif (!is89(i)) continue; \t\t\tif (sums[i] > ~0ULL - count89) { \t\t\t\tprintf(\"counter overflow for 10^%d\\n\", n); \t\t\t\treturn 0; \t\t\t} \t\t\tcount89 += sums[i]; \t\t} \t\tprintf(\"1->10^%d: %llu\\n\", n, count89); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut sums: [u64; 2593] = [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut n: i32 = 1; loop { let mut i: i32 = n * 81; while i != 0 { let mut j: i32 = 1; while j < 10 { let mut s: i32 = j * j; if s > i { break; } sums[i as usize] = (sums[i as usize] as u64).wrapping_add(sums[(i - s) as usize]) as u64; j += 1; j; } i -= 1; i; } let mut count89: u64 = 0; let mut i_0: i32 = 1; while i_0 < n * 81 + 1 { if !(is89(i_0) == 0) { if sums[i_0 as usize] > (!0u64).wrapping_sub(count89) { print!(\"counter overflow for 10^{}\\n\", n); return 0; } count89 = (count89).wrapping_add(sums[i_0 as usize]) as u64; } i_0 += 1; i_0; } print!(\"1->10^{}: {}\\n\", n, count89); n += 1; n; } }" }, { "index": 368, "before": "int is89(int x) { \twhile (1) { \t\tint s = 0; \t\tdo s += (x%10)*(x%10); while ((x /= 10)); \t\tif (s == 89) return 1; \t\tif (s == 1) return 0; \t\tx = s; \t} }", "after": "pub extern \"C\" fn is89(mut x: i32) -> i32 { loop { let mut s: i32 = 0; loop { s += x % 10 * (x % 10); x /= 10; if !(x != 0) { break; } } if s == 89 { return 1; } if s == 1 { return 0; } x = s; } }" }, { "index": 369, "before": "int main() { int i; /* first 22 values (as a list) has no squares: */ for (i = 1; i < 23; i++) printf(\"%d \", nonsqr(i)); printf(\"\\n\"); /* The following check shows no squares up to one million: */ for (i = 1; i < 1000000; i++) { double j = sqrt(nonsqr(i)); assert(j != floor(j)); } return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; i = 1; while i < 23 { print!(\"{} \", nonsqr(i)); i += 1; i; } print!(\"\\n\"); i = 1; unsafe { while i < 1000000 { let mut j: f64 = sqrt(nonsqr(i) as f64); if j != floor(j) { } else { __assert_fail( b\"j != floor(j)\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 21, (*::core::mem::transmute::<&[u8; 11], &[i8; 11]>(b\"int main()\\0\")).as_ptr(), ); } 'c_1861: { if j != floor(j) { } else { __assert_fail( b\"j != floor(j)\\0\" as *const u8 as *const i8, b\"main.c\\0\" as *const u8 as *const i8, 21, (*::core::mem::transmute::<&[u8; 11], &[i8; 11]>(b\"int main()\\0\")).as_ptr(), ); } }; i += 1; i; } } return 0; }" }, { "index": 370, "before": "int nonsqr(int n) { return n + (int)(0.5 + sqrt(n)); /* return n + (int)round(sqrt(n)); in C99 */ }", "after": "pub extern \"C\" fn nonsqr(mut n: i32) -> i32 { unsafe { return n + (0.5f64 + sqrt(n as f64)) as i32; } }" }, { "index": 371, "before": "int main() { int one = 1; /* * Best bet: size_t typically is exactly one word. */ printf(\"word size = %d bits\\n\", (int)(CHAR_BIT * sizeof(size_t))); /* * Check if the least significant bit is located * in the lowest-address byte. */ if (*(char *)&one) printf(\"little endian\\n\"); else printf(\"big endian\\n\"); return 0; }", "after": "fn main() -> i32 { let mut one: i32 = 1; print!( \"word size = {} bits\\n\", 8u64.wrapping_mul(::core::mem::size_of::() as u64) as i32 ); if *(&mut one as *mut i32 as *mut i8) != 0 { print!(\"little endian\\n\"); } else { print!(\"big endian\\n\"); } return 0; }" }, { "index": 372, "before": "int main() { int i; StatObject so = NewStatObject( STDDEV ); for(i=0; i < sizeof(v)/sizeof(double) ; i++) printf(\"val: %lf std dev: %lf\\n\", v[i], stat_object_add(so, v[i])); FREE_STAT_OBJECT(so); return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut so: StatObject = NewStatObject(STDDEV); i = 0; unsafe { while (i as u64) < (::core::mem::size_of::<[f64; 8]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) { print!( \"val: {} std dev: {}\\n\", v[i as usize], stat_object_add(so, v[i as usize]) ); i += 1; i; } free(so as *mut libc::c_void); } so = 0 as StatObject; return 0; }" }, { "index": 373, "before": "StatObject NewStatObject( Action action ) { StatObject so; so = malloc(sizeof(sStatObject)); so->sum = 0.0; so->sum2 = 0.0; so->num = 0; so->action = action; return so; }", "after": "pub extern \"C\" fn NewStatObject(mut action: u32) -> StatObject { let mut so: StatObject = 0 as *mut stat_obj_struct; unsafe { so = malloc(::core::mem::size_of::() as u64) as StatObject; } (*so).sum = 0.0f64; (*so).sum2 = 0.0f64; (*so).num = 0; (*so).action = action; return so; }" }, { "index": 374, "before": "double stat_object_add(StatObject so, double v) { so->num++; so->sum += v; so->sum2 += v*v; return stat_obj_value(so, so->action); }", "after": "pub extern \"C\" fn stat_object_add(mut so: StatObject, mut v_0: f64) -> f64 { (*so).num = ((*so).num).wrapping_add(1); (*so).num; (*so).sum += v_0; (*so).sum2 += v_0 * v_0; return stat_obj_value(so, (*so).action); }" }, { "index": 375, "before": "double stat_obj_value(StatObject so, Action action) { double num, mean, var, stddev; if (so->num == 0.0) return 0.0; num = so->num; if (action==COUNT) return num; mean = so->sum/num; if (action==MEAN) return mean; var = so->sum2/num - mean*mean; if (action==VAR) return var; stddev = sqrt(var); if (action==STDDEV) return stddev; return 0; }", "after": "pub extern \"C\" fn stat_obj_value(mut so: StatObject, mut action: u32) -> f64 { let mut num: f64 = 0.; let mut mean: f64 = 0.; let mut var: f64 = 0.; let mut stddev: f64 = 0.; if (*so).num as f64 == 0.0f64 { return 0.0f64; } num = (*so).num as f64; if action as u32 == COUNT as u32 { return num; } mean = (*so).sum / num; if action as u32 == MEAN as u32 { return mean; } var = (*so).sum2 / num - mean * mean; if action as u32 == VAR as u32 { return var; } unsafe { stddev = sqrt(var); } if action as u32 == STDDEV as u32 { return stddev; } return 0 as f64; }" }, { "index": 376, "before": "int deranged(const char *s1, const char *s2) { \tint i; \tfor (i = 0; s1[i]; i++) \t\tif (s1[i] == s2[i]) return 0; \treturn 1; }", "after": "pub extern \"C\" fn deranged(mut s1: *const i8, mut s2: *const i8) -> i32 { unsafe { let mut i: i32 = 0; i = 0; while *s1.offset(i as isize) != 0 { if *s1.offset(i as isize) as i32 == *s2.offset(i as isize) as i32 { return 0; } i += 1; i; } return 1; } }" }, { "index": 377, "before": "int main(int c, char **v) { \tint i, j = 0; \tchar *words; \tstruct stat st; \tint fd = open(c < 2 ? \"unixdict.txt\" : v[1], O_RDONLY); \tif (fstat(fd, &st) < 0) return 1; \twords = malloc(st.st_size); \tread(fd, words, st.st_size); \tclose(fd); \tunion node root = {{0}}; \tunsigned char cnt[26]; \tint best_len = 0; \tconst char *b1, *b2; \tfor (i = 0; freq[i]; i++) \t\tchar_to_idx[(unsigned char)freq[i]] = i; \t/* count words, change newline to null */ \tfor (i = j = 0; i < st.st_size; i++) { \t\tif (words[i] != '\\n') continue; \t\twords[i] = '\\0'; \t\tif (i - j > best_len) { \t\t\tcount_letters(words + j, cnt); \t\t\tconst char *match = insert(&root, words + j, cnt); \t\t\tif (match) { \t\t\t\tbest_len = i - j; \t\t\t\tb1 = words + j; \t\t\t\tb2 = match; \t\t\t} \t\t} \t\tj = ++i; \t} \tif (best_len) printf(\"longest derangement: %s %s\\n\", b1, b2); \treturn 0; }", "after": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut words: *mut i8 = 0 as *mut i8; let mut st: stat = stat { st_dev: 0, st_ino: 0, st_nlink: 0, st_mode: 0, st_uid: 0, st_gid: 0, __pad0: 0, st_rdev: 0, st_size: 0, st_blksize: 0, st_blocks: 0, st_atim: timespec { tv_sec: 0, tv_nsec: 0, }, st_mtim: timespec { tv_sec: 0, tv_nsec: 0, }, st_ctim: timespec { tv_sec: 0, tv_nsec: 0, }, __glibc_reserved: [0; 3], }; let mut fd: i32 = open( if c < 2 { b\"unixdict.txt\\0\" as *const u8 as *const i8 } else { *v.offset(1 as isize) as *const i8 }, 0, ); if fstat(fd, &mut st) < 0 { return 1; } words = malloc(st.st_size as u64) as *mut i8; read(fd, words as *mut libc::c_void, st.st_size as u64); close(fd); let mut root: node = node { down: [ 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, ], }; let mut cnt: [u8; 26] = [0; 26]; let mut best_len: i32 = 0; let mut b1: *const i8 = 0 as *const i8; let mut b2: *const i8 = 0 as *const i8; i = 0; while *freq.offset(i as isize) != 0 { char_to_idx[*freq.offset(i as isize) as u8 as usize] = i; i += 1; i; } j = 0; i = j; while (i as i64) < st.st_size { if !(*words.offset(i as isize) as i32 != '\\n' as i32) { *words.offset(i as isize) = '\\0' as i8; if i - j > best_len { count_letters(words.offset(j as isize), cnt.as_mut_ptr()); let mut match_0: *const i8 = insert(&mut root, words.offset(j as isize), cnt.as_mut_ptr()); if !match_0.is_null() { best_len = i - j; b1 = words.offset(j as isize); b2 = match_0; } } i += 1; j = i; } i += 1; i; } if best_len != 0 { print!( \"longest derangement: {} {}\\n\", build_str_from_raw_ptr(b1 as *mut u8), build_str_from_raw_ptr(b2 as *mut u8) ); } return 0; } }" }, { "index": 378, "before": "int count_letters(const char *s, unsigned char *c) { \tint i, len; \tmemset(c, 0, 26); \tfor (len = i = 0; s[i]; i++) { \t\tif (s[i] < 'a' || s[i] > 'z') \t\t\treturn 0; \t\tlen++, c[char_to_idx[(unsigned char)s[i]]]++; \t} \treturn len; }", "after": "pub extern \"C\" fn count_letters(mut s: *const i8, mut c: *mut u8) -> i32 { unsafe { let mut i: i32 = 0; let mut len: i32 = 0; memset(c as *mut libc::c_void, 0, 26); i = 0; len = i; while *s.offset(i as isize) != 0 { if (*s.offset(i as isize) as i32) < 'a' as i32 || *s.offset(i as isize) as i32 > 'z' as i32 { return 0; } len += 1; len; let ref mut fresh0 = *c.offset(char_to_idx[*s.offset(i as isize) as u8 as usize] as isize); *fresh0 = (*fresh0).wrapping_add(1); *fresh0; i += 1; i; } return len; } }" }, { "index": 379, "before": "int main() { \tint i; \tprintf(\"Running the examples :\"); \tfor(i=0;i i32 { let mut i: i32 = 0; print!(\"Running the examples :\"); i = 0; unsafe { while (i as u64) < (::core::mem::size_of::<[fraction; 6]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) { print!( \"\\nFor N = {}, D = {} :\", examples[i as usize].num, examples[i as usize].den ); while examples[i as usize].den != 0 { print!( \" {} \", r2cf( &mut (*examples.as_mut_ptr().offset(i as isize)).num, &mut (*examples.as_mut_ptr().offset(i as isize)).den, ) ); } i += 1; i; } printf(b\"\\n\\nRunning for %c2 :\\0\" as *const u8 as *const i8, 251); } i = 0; unsafe { while (i as u64) < (::core::mem::size_of::<[fraction; 4]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) { print!( \"\\nFor N = {}, D = {} :\", sqrt2[i as usize].num, sqrt2[i as usize].den ); while sqrt2[i as usize].den != 0 { print!( \" {} \", r2cf( &mut (*sqrt2.as_mut_ptr().offset(i as isize)).num, &mut (*sqrt2.as_mut_ptr().offset(i as isize)).den, ) ); } i += 1; i; } } print!(\"\\n\\nRunning for {} :\", 227); i = 0; unsafe { while (i as u64) < (::core::mem::size_of::<[fraction; 8]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) { print!( \"\\nFor N = {}, D = {} :\", pi[i as usize].num, pi[i as usize].den ); while pi[i as usize].den != 0 { print!( \" {} \", r2cf( &mut (*pi.as_mut_ptr().offset(i as isize)).num, &mut (*pi.as_mut_ptr().offset(i as isize)).den, ) ); } i += 1; i; } } return 0; }" }, { "index": 380, "before": "int r2cf(int *numerator,int *denominator) { \tint quotient=0,temp; \tif(denominator != 0) \t{ \t\tquotient = *numerator / *denominator; \t\ttemp = *numerator; \t\t*numerator = *denominator; \t\t*denominator = temp % *denominator; \t} \treturn quotient; }", "after": "pub extern \"C\" fn r2cf(mut numerator: *mut i32, mut denominator: *mut i32) -> i32 { unsafe { let mut quotient: i32 = 0; let mut temp: i32 = 0; if !denominator.is_null() { quotient = *numerator / *denominator; temp = *numerator; *numerator = *denominator; *denominator = temp % *denominator; } return quotient; } }" }, { "index": 381, "before": "int main() { const char* pokemon[] = {\"audino\", \"bagon\", \"baltoy\", \"banette\", \"bidoof\", \"braviary\", \"bronzor\", \"carracosta\", \"charmeleon\", \"cresselia\", \"croagunk\", \"darmanitan\", \"deino\", \"emboar\", \"emolga\", \"exeggcute\", \"gabite\", \"girafarig\", \"gulpin\", \"haxorus\", \"heatmor\", \"heatran\", \"ivysaur\", \"jellicent\", \"jumpluff\", \"kangaskhan\", \"kricketune\", \"landorus\", \"ledyba\", \"loudred\", \"lumineon\", \"lunatone\", \"machamp\", \"magnezone\", \"mamoswine\", \"nosepass\", \"petilil\", \"pidgeotto\", \"pikachu\", \"pinsir\", \"poliwrath\", \"poochyena\", \"porygon2\", \"porygonz\", \"registeel\", \"relicanth\", \"remoraid\", \"rufflet\", \"sableye\", \"scolipede\", \"scrafty\", \"seaking\", \"sealeo\", \"silcoon\", \"simisear\", \"snivy\", \"snorlax\", \"spoink\", \"starly\", \"tirtouga\", \"trapinch\", \"treecko\", \"tyrogue\", \"vigoroth\", \"vulpix\", \"wailord\", \"wartortle\", \"whismur\", \"wingull\", \"yamask\"}; size_t pokemon_len = sizeof(pokemon) / sizeof(pokemon[0]); find_longest_chain(pokemon, pokemon_len); printf(\"Maximum path length: %u\\n\", longest_path_len); printf(\"Paths of that length: %u\\n\", n_solutions); printf(\"Example path of that length:\\n\"); for (size_t i = 0; i < longest_path_len; i += 7) { printf(\" \"); for (size_t j = i; j < (i+7) && j < longest_path_len; j++) printf(\"%s \", longest_path[j]); printf(\"\\n\"); } free(longest_path); return 0; }", "after": "fn main() -> i32 { let mut pokemon: [*const i8; 70] = [ b\"audino\\0\" as *const u8 as *const i8, b\"bagon\\0\" as *const u8 as *const i8, b\"baltoy\\0\" as *const u8 as *const i8, b\"banette\\0\" as *const u8 as *const i8, b\"bidoof\\0\" as *const u8 as *const i8, b\"braviary\\0\" as *const u8 as *const i8, b\"bronzor\\0\" as *const u8 as *const i8, b\"carracosta\\0\" as *const u8 as *const i8, b\"charmeleon\\0\" as *const u8 as *const i8, b\"cresselia\\0\" as *const u8 as *const i8, b\"croagunk\\0\" as *const u8 as *const i8, b\"darmanitan\\0\" as *const u8 as *const i8, b\"deino\\0\" as *const u8 as *const i8, b\"emboar\\0\" as *const u8 as *const i8, b\"emolga\\0\" as *const u8 as *const i8, b\"exeggcute\\0\" as *const u8 as *const i8, b\"gabite\\0\" as *const u8 as *const i8, b\"girafarig\\0\" as *const u8 as *const i8, b\"gulpin\\0\" as *const u8 as *const i8, b\"haxorus\\0\" as *const u8 as *const i8, b\"heatmor\\0\" as *const u8 as *const i8, b\"heatran\\0\" as *const u8 as *const i8, b\"ivysaur\\0\" as *const u8 as *const i8, b\"jellicent\\0\" as *const u8 as *const i8, b\"jumpluff\\0\" as *const u8 as *const i8, b\"kangaskhan\\0\" as *const u8 as *const i8, b\"kricketune\\0\" as *const u8 as *const i8, b\"landorus\\0\" as *const u8 as *const i8, b\"ledyba\\0\" as *const u8 as *const i8, b\"loudred\\0\" as *const u8 as *const i8, b\"lumineon\\0\" as *const u8 as *const i8, b\"lunatone\\0\" as *const u8 as *const i8, b\"machamp\\0\" as *const u8 as *const i8, b\"magnezone\\0\" as *const u8 as *const i8, b\"mamoswine\\0\" as *const u8 as *const i8, b\"nosepass\\0\" as *const u8 as *const i8, b\"petilil\\0\" as *const u8 as *const i8, b\"pidgeotto\\0\" as *const u8 as *const i8, b\"pikachu\\0\" as *const u8 as *const i8, b\"pinsir\\0\" as *const u8 as *const i8, b\"poliwrath\\0\" as *const u8 as *const i8, b\"poochyena\\0\" as *const u8 as *const i8, b\"porygon2\\0\" as *const u8 as *const i8, b\"porygonz\\0\" as *const u8 as *const i8, b\"registeel\\0\" as *const u8 as *const i8, b\"relicanth\\0\" as *const u8 as *const i8, b\"remoraid\\0\" as *const u8 as *const i8, b\"rufflet\\0\" as *const u8 as *const i8, b\"sableye\\0\" as *const u8 as *const i8, b\"scolipede\\0\" as *const u8 as *const i8, b\"scrafty\\0\" as *const u8 as *const i8, b\"seaking\\0\" as *const u8 as *const i8, b\"sealeo\\0\" as *const u8 as *const i8, b\"silcoon\\0\" as *const u8 as *const i8, b\"simisear\\0\" as *const u8 as *const i8, b\"snivy\\0\" as *const u8 as *const i8, b\"snorlax\\0\" as *const u8 as *const i8, b\"spoink\\0\" as *const u8 as *const i8, b\"starly\\0\" as *const u8 as *const i8, b\"tirtouga\\0\" as *const u8 as *const i8, b\"trapinch\\0\" as *const u8 as *const i8, b\"treecko\\0\" as *const u8 as *const i8, b\"tyrogue\\0\" as *const u8 as *const i8, b\"vigoroth\\0\" as *const u8 as *const i8, b\"vulpix\\0\" as *const u8 as *const i8, b\"wailord\\0\" as *const u8 as *const i8, b\"wartortle\\0\" as *const u8 as *const i8, b\"whismur\\0\" as *const u8 as *const i8, b\"wingull\\0\" as *const u8 as *const i8, b\"yamask\\0\" as *const u8 as *const i8, ]; let mut pokemon_len: u64 = (::core::mem::size_of::<[*const i8; 70]>() as u64) .wrapping_div(::core::mem::size_of::<*const i8>() as u64); find_longest_chain(pokemon.as_mut_ptr(), pokemon_len); unsafe { print!(\"Maximum path length: {}\\n\", longest_path_len); print!(\"Paths of that length: {}\\n\", n_solutions); } print!(\"Example path of that length:\\n\"); let mut i: u64 = 0; unsafe { while i < longest_path_len { print!(\" \"); let mut j: u64 = i; while j < i.wrapping_add(7) && j < longest_path_len { print!( \"{} \", build_str_from_raw_ptr(*longest_path.offset(j as isize) as *mut u8) ); j = j.wrapping_add(1); j; } print!(\"\\n\"); i = (i).wrapping_add(7) as u64; } free(longest_path as *mut libc::c_void); } return 0; }" }, { "index": 382, "before": "void find_longest_chain(const char* items[], size_t items_len) { refs_len = items_len; refs = calloc(refs_len, sizeof(Ref)); // enough space for all items longest_path_refs_len = 0; longest_path_refs = calloc(refs_len, sizeof(Ref)); for (size_t i = 0; i < items_len; i++) { size_t itemsi_len = strlen(items[i]); if (itemsi_len <= 1) exit(1); refs[i].index = (uint16_t)i; refs[i].last_char = items[i][itemsi_len - 1]; refs[i].first_char = items[i][0]; } // try each item as possible start for (size_t i = 0; i < items_len; i++) { Ref aux = refs[0]; refs[0] = refs[i]; refs[i] = aux; search(1); refs[i] = refs[0]; refs[0] = aux; } longest_path_len = longest_path_refs_len; longest_path = calloc(longest_path_len, sizeof(const char*)); for (size_t i = 0; i < longest_path_len; i++) longest_path[i] = items[longest_path_refs[i].index]; free(longest_path_refs); free(refs); }", "after": "pub extern \"C\" fn find_longest_chain(mut items: *mut *const i8, mut items_len: u64) { unsafe { refs_len = items_len; refs = calloc(refs_len, ::core::mem::size_of::() as u64) as *mut Ref; longest_path_refs_len = 0; longest_path_refs = calloc(refs_len, ::core::mem::size_of::() as u64) as *mut Ref; let mut i: u64 = 0; while i < items_len { let mut itemsi_len: u64 = strlen(*items.offset(i as isize)); if itemsi_len <= 1 { exit(1); }; (*refs.offset(i as isize)).index = i as u16; (*refs.offset(i as isize)).last_char = *(*items.offset(i as isize)).offset(itemsi_len.wrapping_sub(1) as isize); (*refs.offset(i as isize)).first_char = *(*items.offset(i as isize)).offset(0 as isize); i = i.wrapping_add(1); i; } let mut i_0: u64 = 0; while i_0 < items_len { let mut aux: Ref = *refs.offset(0 as isize); *refs.offset(0 as isize) = *refs.offset(i_0 as isize); *refs.offset(i_0 as isize) = aux; search(1); *refs.offset(i_0 as isize) = *refs.offset(0 as isize); *refs.offset(0 as isize) = aux; i_0 = i_0.wrapping_add(1); i_0; } longest_path_len = longest_path_refs_len; longest_path = calloc(longest_path_len, ::core::mem::size_of::<*const i8>() as u64) as *mut *const i8; let mut i_1: u64 = 0; while i_1 < longest_path_len { let ref mut fresh0 = *longest_path.offset(i_1 as isize); *fresh0 = *items.offset((*longest_path_refs.offset(i_1 as isize)).index as isize); i_1 = i_1.wrapping_add(1); i_1; } free(longest_path_refs as *mut libc::c_void); free(refs as *mut libc::c_void); } }" }, { "index": 383, "before": "void search(size_t curr_len) { if (curr_len == longest_path_refs_len) { n_solutions++; } else if (curr_len > longest_path_refs_len) { n_solutions = 1; longest_path_refs_len = curr_len; memcpy(longest_path_refs, refs, curr_len * sizeof(Ref)); } // recursive search intptr_t last_char = refs[curr_len - 1].last_char; for (size_t i = curr_len; i < refs_len; i++) if (refs[i].first_char == last_char) { Ref aux = refs[curr_len]; refs[curr_len] = refs[i]; refs[i] = aux; search(curr_len + 1); refs[i] = refs[curr_len]; refs[curr_len] = aux; } }", "after": "pub extern \"C\" fn search(mut curr_len: u64) { unsafe { if curr_len == longest_path_refs_len { n_solutions = n_solutions.wrapping_add(1); n_solutions; } else if curr_len > longest_path_refs_len { n_solutions = 1; longest_path_refs_len = curr_len; memcpy( longest_path_refs as *mut libc::c_void, refs as *const libc::c_void, curr_len.wrapping_mul(::core::mem::size_of::() as u64), ); } let mut last_char: i64 = (*refs.offset(curr_len.wrapping_sub(1) as isize)).last_char as i64; let mut i: u64 = curr_len; while i < refs_len { if (*refs.offset(i as isize)).first_char as i64 == last_char { let mut aux: Ref = *refs.offset(curr_len as isize); *refs.offset(curr_len as isize) = *refs.offset(i as isize); *refs.offset(i as isize) = aux; search(curr_len.wrapping_add(1)); *refs.offset(i as isize) = *refs.offset(curr_len as isize); *refs.offset(curr_len as isize) = aux; } i = i.wrapping_add(1); i; } } }" }, { "index": 384, "before": "bool is_prime(int n) { int d = 5; if (n < 2) return FALSE; if (!(n % 2)) return n == 2; if (!(n % 3)) return n == 3; while (d *d <= n) { if (!(n % d)) return FALSE; d += 2; if (!(n % d)) return FALSE; d += 4; } return TRUE; }", "after": "pub extern \"C\" fn is_prime(mut n: i32) -> i32 { let mut d: i32 = 5; if n < 2 { return 0; } if n % 2 == 0 { return (n == 2) as i32; } if n % 3 == 0 { return (n == 3) as i32; } while d * d <= n { if n % d == 0 { return 0; } d += 2; if n % d == 0 { return 0; } d += 4; } return 1; }" }, { "index": 385, "before": "int count_prime_factors(int n) { int count = 0, f = 2; if (n == 1) return 0; if (is_prime(n)) return 1; while (TRUE) { if (!(n % f)) { count++; n /= f; if (n == 1) return count; if (is_prime(n)) f = n; } else if (f >= 3) f += 2; else f = 3; } }", "after": "pub extern \"C\" fn count_prime_factors(mut n: i32) -> i32 { let mut count: i32 = 0; let mut f: i32 = 2; if n == 1 { return 0; } if is_prime(n) != 0 { return 1; } loop { if n % f == 0 { count += 1; count; n /= f; if n == 1 { return count; } if is_prime(n) != 0 { f = n; } } else if f >= 3 { f += 2; } else { f = 3; } } }" }, { "index": 386, "before": "int main() { int i, n, count = 0; printf(\"The attractive numbers up to and including %d are:\\n\", MAX); for (i = 1; i <= MAX; ++i) { n = count_prime_factors(i); if (is_prime(n)) { printf(\"%4d\", i); if (!(++count % 20)) printf(\"\\n\"); } } printf(\"\\n\"); return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut n: i32 = 0; let mut count: i32 = 0; print!(\"The attractive numbers up to and including {} are:\\n\", 120); i = 1; while i <= 120 { n = count_prime_factors(i); if is_prime(n) != 0 { print!(\"{:4}\", i); count += 1; if count % 20 == 0 { print!(\"\\n\"); } } i += 1; i; } print!(\"\\n\"); return 0; }" }, { "index": 387, "before": "int main() { int i; tree_node(double) root_d = node_new(double, (double)rand() / RAND_MAX); for (i = 0; i < 10000; i++) node_insert(double, root_d, (double)rand() / RAND_MAX); tree_node(int) root_i = node_new(int, rand()); for (i = 0; i < 10000; i++) node_insert(int, root_i, rand()); return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; unsafe { let mut root_d: node_double = node_double_new(rand() as f64 / 2147483647 as f64); i = 0; while i < 10000 { node_double_insert(root_d, rand() as f64 / 2147483647 as f64); i += 1; i; } let mut root_i: node_int = node_int_new(rand()); i = 0; while i < 10000 { node_int_insert(root_i, rand()); i += 1; i; } } return 0; }" }, { "index": 388, "before": "int levenshtein(const char *s, int ls, const char *t, int lt) { int a, b, c; /* if either string is empty, difference is inserting all chars * from the other */ if (!ls) return lt; if (!lt) return ls; /* if last letters are the same, the difference is whatever is * required to edit the rest of the strings */ if (s[ls - 1] == t[lt - 1]) return levenshtein(s, ls - 1, t, lt - 1); /* else try: * changing last letter of s to that of t; or * remove last letter of s; or * remove last letter of t, * any of which is 1 edit plus editing the rest of the strings */ a = levenshtein(s, ls - 1, t, lt - 1); b = levenshtein(s, ls, t, lt - 1); c = levenshtein(s, ls - 1, t, lt ); if (a > b) a = b; if (a > c) a = c; return a + 1; }", "after": "pub extern \"C\" fn levenshtein(mut s: *const i8, mut ls: i32, mut t: *const i8, mut lt: i32) -> i32 { unsafe { let mut a: i32 = 0; let mut b: i32 = 0; let mut c: i32 = 0; if ls == 0 { return lt; } if lt == 0 { return ls; } if *s.offset((ls - 1i32) as isize) as i32 == *t.offset((lt - 1i32) as isize) as i32 { return levenshtein(s, ls - 1, t, lt - 1); } a = levenshtein(s, ls - 1, t, lt - 1); b = levenshtein(s, ls, t, lt - 1); c = levenshtein(s, ls - 1, t, lt); if a > b { a = b; } if a > c { a = c; } return a + 1; } }" }, { "index": 389, "before": "int main() { const char *s1 = \"rosettacode\"; const char *s2 = \"raisethysword\"; printf(\"distance between `%s' and `%s': %d\\n\", s1, s2, levenshtein(s1, strlen(s1), s2, strlen(s2))); return 0; }", "after": "fn main() -> i32 { unsafe { let mut s1: *const i8 = b\"rosettacode\\0\" as *const u8 as *const i8; let mut s2: *const i8 = b\"raisethysword\\0\" as *const u8 as *const i8; printf( b\"distance between `%s' and `%s': %d\\n\\0\" as *const u8 as *const i8, s1, s2, levenshtein(s1, strlen(s1) as i32, s2, strlen(s2) as i32), ); return 0; } }" }, { "index": 390, "before": "int main(void) { for (int i = 0; i < 3; i++) { printf(\"%c%c%i\\n\", a1[i], a2[i], a3[i]); } }", "after": "fn main() -> i32 { let mut i: i32 = 0; unsafe { while i < 3 { print!( \"{}{}{}\\n\", a1[i as usize] as i32, a2[i as usize] as i32, a3[i as usize] ); i += 1; i; } } return 0; }" }, { "index": 391, "before": "void swap(void *va, void *vb, size_t s) { char t, *a = (char *)va, *b = (char *)vb; while (s--) t = a[s], a[s] = b[s], b[s] = t; }", "after": "pub extern \"C\" fn swap(mut va: *mut libc::c_void, mut vb: *mut libc::c_void, mut s: u64) { unsafe { let mut t: i8 = 0; let mut a: *mut i8 = va as *mut i8; let mut b: *mut i8 = vb as *mut i8; loop { let fresh0 = s; s = s.wrapping_sub(1); if !(fresh0 != 0) { break; } t = *a.offset(s as isize); *a.offset(s as isize) = *b.offset(s as isize); *b.offset(s as isize) = t; } } }" }, { "index": 392, "before": "int main() { struct test t = {1, 2, 3}; struct test h = {4, 5, 6}; double alfa = 0.45, omega = 9.98; struct test *pt = &t; struct test *th = &h; printf(\"%d %d %d\\n\", t.a, t.b, t.c); Swap(t, h); printf(\"%d %d %d\\n\", t.a, t.b, t.c); printf(\"%d %d %d\\n\", h.a, h.b, h.c); printf(\"%lf\\n\", alfa); Swap(alfa, omega); printf(\"%lf\\n\", alfa); printf(\"%d\\n\", pt->a); Swap(pt, th); printf(\"%d\\n\", pt->a); }", "after": "fn main() -> i32 { unsafe { let mut t: test = { let mut init = test { a: 1, b: 2, c: 3 }; init }; let mut h: test = { let mut init = test { a: 4, b: 5, c: 6 }; init }; let mut alfa: f64 = 0.45f64; let mut omega: f64 = 9.98f64; let mut pt: *mut test = &mut t; let mut th: *mut test = &mut h; print!(\"{} {} {}\\n\", t.a, t.b, t.c); let mut _T: test = t; t = h; h = _T; print!(\"{} {} {}\\n\", t.a, t.b, t.c); print!(\"{} {} {}\\n\", h.a, h.b, h.c); print!(\"{}\\n\", alfa); let mut _T_0: f64 = alfa; alfa = omega; omega = _T_0; print!(\"{}\\n\", alfa); print!(\"{}\\n\", (*pt).a); let mut _T_1: *mut test = pt; pt = th; th = _T_1; print!(\"{}\\n\", (*pt).a); return 0; } }" }, { "index": 393, "before": "int main() { \tdouble a, c, s, PI2 = atan2(1, 1) * 8; \tint n, i; \tfor (n = 1; n < 10; n++) for (i = 0; i < n; i++) { \t\tc = s = 0; \t\tif (!i )\t\tc = 1; \t\telse if(n == 4 * i)\ts = 1; \t\telse if(n == 2 * i)\tc = -1; \t\telse if(3 * n == 4 * i)\ts = -1; \t\telse \t\t\ta = i * PI2 / n, c = cos(a), s = sin(a); \t\tif (c) printf(\"%.2g\", c); \t\tprintf(s == 1 ? \"i\" : s == -1 ? \"-i\" : s ? \"%+.2gi\" : \"\", s); \t\tprintf(i == n - 1 ?\"\\n\":\", \"); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut a: f64 = 0.; let mut c: f64 = 0.; let mut s: f64 = 0.; unsafe { let mut PI2: f64 = atan2(1 as f64, 1 as f64) * 8 as f64; let mut n: i32 = 0; let mut i: i32 = 0; n = 1; while n < 10 { i = 0; while i < n { s = 0 as f64; c = s; if i == 0 { c = 1 as f64; } else if n == 4 * i { s = 1 as f64; } else if n == 2 * i { c = -1i32 as f64; } else if 3 * n == 4 * i { s = -1i32 as f64; } else { a = i as f64 * PI2 / n as f64; c = cos(a); s = sin(a); } if c != 0. { print!(\"{:.2}\", c); } if s == 1 as f64 { print!(\"i\") } else { if s == -1i32 as f64 { print!(\"-i\") } else { if s != 0. { print!(\"{:+.2}i\", s) } else { print!(\"\") } } }; if i == n - 1 { print!(\"\\n\") } else { print!(\", \") }; i += 1; i; } n += 1; n; } } return 0; }" }, { "index": 394, "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 extern \"C\" fn decode(mut source: *const u8, mut sink: *mut u8) -> i32 { unsafe { let length: u64 = strlen(source as *const i8); let mut it: *const u8 = source; let mut end: *const u8 = source.offset(length as isize); let mut acc: i32 = 0; if length.wrapping_rem(4) != 0 { return 1; } while it != end { let fresh0 = it; it = it.offset(1); let b1: u8 = *fresh0; let fresh1 = it; it = it.offset(1); let b2: u8 = *fresh1; let fresh2 = it; it = it.offset(1); let b3: u8 = *fresh2; let fresh3 = it; it = it.offset(1); let b4: u8 = *fresh3; let i1: i32 = findIndex(b1); let i2: i32 = findIndex(b2); acc = i1 << 2; acc |= i2 >> 4; let fresh4 = sink; sink = sink.offset(1); *fresh4 = acc as u8; if b3 as i32 != '=' as i32 { let i3: i32 = findIndex(b3); acc = (i2 & 0xf) << 4; acc += i3 >> 2; let fresh5 = sink; sink = sink.offset(1); *fresh5 = acc as u8; if b4 as i32 != '=' as i32 { let i4: i32 = findIndex(b4); acc = (i3 & 0x3) << 6; acc |= i4; let fresh6 = sink; sink = sink.offset(1); *fresh6 = acc as u8; } } } *sink = '\\0' as u8; return 0; } }" }, { "index": 395, "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 extern \"C\" fn findIndex(val: u8) -> i32 { if 'A' as i32 <= val as i32 && val as i32 <= 'Z' as i32 { return val as i32 - 'A' as i32; } if 'a' as i32 <= val as i32 && val as i32 <= 'z' as i32 { return val as i32 - 'a' as i32 + 26; } if '0' as i32 <= val as i32 && val as i32 <= '9' as i32 { return val as i32 - '0' as i32 + 52; } if val as i32 == '+' as i32 { return 62; } if val as i32 == '/' as i32 { return 63; } return -1; }" }, { "index": 396, "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": "fn main() -> i32 { unsafe { let mut data : [u8; 117] = * :: core :: mem :: transmute :: < & [u8; 117], & mut [u8; 117], > (b\"VG8gZXJyIGlzIGh1bWFuLCBidXQgdG8gcmVhbGx5IGZvdWwgdGhpbmdzIHVwIHlvdSBuZWVkIGEgY29tcHV0ZXIuCiAgICAtLVBhdWwgUi5FaHJsaWNo\\0\",); let mut decoded: [u8; 1024] = [0; 1024]; print!( \"{}\\n\\n\", build_str_from_raw_ptr(data.as_mut_ptr() as *mut u8) ); decode(data.as_mut_ptr() as *const u8, decoded.as_mut_ptr()); print!( \"{}\\n\\n\", build_str_from_raw_ptr(decoded.as_mut_ptr() as *mut u8) ); } return 0; }" }, { "index": 397, "before": "int main() { \tconst char *s; \tprintf(\"\\n\\n\\n
\"); \tfor (s = input; *s; s++) { \t\tswitch(*s) { \t\tcase '\\n': printf(\"
\"); break; \t\tcase ',': printf(\"\"); break; \t\tcase '<': printf(\"<\"); break; \t\tcase '>': printf(\">\"); break; \t\tcase '&': printf(\"&\"); break; \t\tdefault: putchar(*s); \t\t} \t} \tputs(\"
\"); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut s: *const i8 = 0 as *const i8; print!(\"\\n\\n\\n
\"); s = input; while *s != 0 { match *s as i32 { 10 => { print!(\"
\"); } 44 => { print!(\"\"); } 60 => { print!(\"<\"); } 62 => { print!(\">\"); } 38 => { print!(\"&\"); } _ => { print!(\"{}\", *s as i32); } } s = s.offset(1); s; } puts(b\"
\\0\" as *const u8 as *const i8); return 0; } }" }, { "index": 398, "before": "int main() { ulong b = (ulong)2e18; printf(\"3rd root of 8 = %lld\\n\", root(8, 3)); printf(\"3rd root of 9 = %lld\\n\", root(9, 3)); printf(\"2nd root of %lld = %lld\\n\", b, root(b, 2)); return 0; }", "after": "fn main() -> i32 { let mut b: u64 = 2e18f64 as u64; print!(\"3rd root of 8 = {}\\n\", root(8, 3)); print!(\"3rd root of 9 = {}\\n\", root(9, 3)); print!(\"2nd root of {} = {}\\n\", b, root(b, 2)); return 0; }" }, { "index": 399, "before": "ulong root(ulong base, ulong n) { ulong n1, n2, n3, c, d, e; if (base < 2) return base; if (n == 0) return 1; n1 = n - 1; n2 = n; n3 = n1; c = 1; d = (n3 + base) / n2; e = (n3 * d + base / (ulong)powl(d, n1)) / n2; while (c != d && c != e) { c = d; d = e; e = (n3*e + base / (ulong)powl(e, n1)) / n2; } if (d < e) return d; return e; }", "after": "pub extern \"C\" fn root(mut base: u64, mut n: u64) -> u64 { let mut n1: u64 = 0; let mut n2: u64 = 0; let mut n3: u64 = 0; let mut c: u64 = 0; let mut d: u64 = 0; let mut e: u64 = 0; if base < 2 { return base; } if n == 0 { return 1; } n1 = n.wrapping_sub(1); n2 = n; n3 = n1; c = 1; d = n3.wrapping_add(base).wrapping_div(n2); unsafe { e = n3 .wrapping_mul(d) .wrapping_add( base.wrapping_div( (powl(f128::f128::new(d), f128::f128::new(n1))) .to_u64() .unwrap(), ), ) .wrapping_div(n2); while c != d && c != e { c = d; d = e; e = n3 .wrapping_mul(e) .wrapping_add( base.wrapping_div( (powl(f128::f128::new(e), f128::f128::new(n1))) .to_u64() .unwrap(), ), ) .wrapping_div(n2); } } if d < e { return d; } return e; }" }, { "index": 400, "before": "uint32_t nimprod(uint32_t x, uint32_t y) { if (x < 2 || y < 2) return x * y; uint32_t h = hpo2(x); if (x > h) return nimprod(h, y) ^ nimprod(x ^ h, y); if (hpo2(y) < y) return nimprod(y, x); uint32_t xp = lhpo2(x), yp = lhpo2(y); uint32_t comp = xp & yp; if (comp == 0) return x * y; h = hpo2(comp); return nimprod(nimprod(x >> h, y >> h), 3 << (h - 1)); }", "after": "pub extern \"C\" fn nimprod(mut x: u32, mut y: u32) -> u32 { if x < 2 || y < 2 { return x.wrapping_mul(y); } let mut h: u32 = hpo2(x); if x > h { return nimprod(h, y) ^ nimprod(x ^ h, y); } if hpo2(y) < y { return nimprod(y, x); } let mut xp: u32 = lhpo2(x); let mut yp: u32 = lhpo2(y); let mut comp: u32 = xp & yp; if comp == 0 { return x.wrapping_mul(y); } h = hpo2(comp); return nimprod( nimprod(x >> h, y >> h), (3i32 << h.wrapping_sub(1u32)) as u32, ); }" }, { "index": 401, "before": "void print_table(uint32_t n, char op, uint32_t(*func)(uint32_t, uint32_t)) { printf(\" %c |\", op); for (uint32_t a = 0; a <= n; ++a) printf(\"%3d\", a); printf(\"\\n--- -\"); for (uint32_t a = 0; a <= n; ++a) printf(\"---\"); printf(\"\\n\"); for (uint32_t b = 0; b <= n; ++b) { printf(\"%2d |\", b); for (uint32_t a = 0; a <= n; ++a) printf(\"%3d\", func(a, b)); printf(\"\\n\"); } }", "after": "pub extern \"C\" fn print_table( mut n: u32, mut op: i8, mut func: Option u32>, ) { print!(\" {} |\", op as i32); let mut a: u32 = 0; while a <= n { print!(\"{:3}\", a); a = a.wrapping_add(1); a; } print!(\"\\n--- -\"); let mut a_0: u32 = 0; while a_0 <= n { print!(\"---\"); a_0 = a_0.wrapping_add(1); a_0; } print!(\"\\n\"); let mut b: u32 = 0; unsafe { while b <= n { print!(\"{:2} |\", b); let mut a_1: u32 = 0; while a_1 <= n { print!(\"{:3}\", func.expect(\"non-null function pointer\")(a_1, b)); a_1 = a_1.wrapping_add(1); a_1; } print!(\"\\n\"); b = b.wrapping_add(1); b; } } }" }, { "index": 402, "before": "uint32_t lhpo2(uint32_t n) { uint32_t q = 0, m = hpo2(n); for (; m % 2 == 0; m >>= 1, ++q) {} return q; }", "after": "pub extern \"C\" fn lhpo2(mut n: u32) -> u32 { let mut q: u32 = 0; let mut m: u32 = hpo2(n); while m.wrapping_rem(2) == 0 { m >>= 1; q = q.wrapping_add(1); q; } return q; }" }, { "index": 403, "before": "uint32_t nimsum(uint32_t x, uint32_t y) { return x ^ y; }", "after": "pub extern \"C\" fn nimsum(mut x: u32, mut y: u32) -> u32 { return x ^ y; }" }, { "index": 404, "before": "int main() { print_table(15, '+', nimsum); printf(\"\\n\"); print_table(15, '*', nimprod); const uint32_t a = 21508, b = 42689; printf(\"\\n%d + %d = %d\\n\", a, b, nimsum(a, b)); printf(\"%d * %d = %d\\n\", a, b, nimprod(a, b)); return 0; }", "after": "fn main() -> i32 { print_table( 15, '+' as i8, Some(nimsum as unsafe extern \"C\" fn(u32, u32) -> u32), ); print!(\"\\n\"); print_table( 15, '*' as i8, Some(nimprod as unsafe extern \"C\" fn(u32, u32) -> u32), ); let a: u32 = 21508; let b: u32 = 42689; print!(\"\\n{} + {} = {}\\n\", a, b, nimsum(a, b)); print!(\"{} * {} = {}\\n\", a, b, nimprod(a, b)); return 0; }" }, { "index": 405, "before": "uint32_t hpo2(uint32_t n) { return n & -n; }", "after": "pub extern \"C\" fn hpo2(mut n: u32) -> u32 { return n & n.wrapping_neg(); }" }, { "index": 406, "before": "int main() { \tint current = 0, \t//the current number \t square;\t\t//the square of the current number \t//the strategy of take the rest of division by 1e06 is \t//to take the a number how 6 last digits are 269696 \twhile (((square=current*current) % 1000000 != 269696) && (square+INT_MAX) \t printf(\"Condition not satisfied before INT_MAX reached.\"); \telse\t\t \t printf (\"The smallest number whose square ends in 269696 is %d\\n\", current); //the end \treturn 0 ; }", "after": "fn main() -> i32 { let mut current: i32 = 0; let mut square: i32 = 0; loop { square = current * current; if !(square % 1000000 != 269696 && square < 2147483647) { break; } current += 1; current; } if square > 2147483647 { print!(\"Condition not satisfied before INT_MAX reached.\"); } else { print!( \"The smallest number whose square ends in 269696 is {}\\n\", current ); } return 0; }" }, { "index": 407, "before": "int csv_set(CSV *csv, unsigned int col, unsigned int row, char *value) { \tunsigned int idx; \tidx = col + (row * csv->cols); \tcsv->table[idx] = value; \treturn 0; }", "after": "pub extern \"C\" fn csv_set( mut csv: *mut CSV, mut col: u32, mut row: u32, mut value: *mut i8, ) -> i32 { unsafe { let mut idx: u32 = 0; idx = col.wrapping_add(row.wrapping_mul((*csv).cols)); let ref mut fresh0 = *((*csv).table).offset(idx as isize); *fresh0 = value; return 0; } }" }, { "index": 408, "before": "int csv_open(CSV *csv, char *filename) { \tFILE *fp; \tunsigned int m_rows; \tunsigned int m_cols, cols; \tchar line[2048]; \tchar *lineptr; \tchar *token; \tfp = fopen(filename, \"r\"); \tif (fp == NULL) \t{ \t\tgoto error; \t} \tm_rows = 0; \tm_cols = 0; \twhile (fgets(line, sizeof(line), fp) != NULL) \t{ \t\tm_rows += 1; \t\tcols = 0; \t\tlineptr = line; \t\twhile ((token = strtok(lineptr, csv->delim)) != NULL) \t\t{ \t\t\tlineptr = NULL; \t\t\ttrim(&token); \t\t\tcols += 1; \t\t\tif (cols > m_cols) \t\t\t{ \t\t\t\tm_cols = cols; \t\t\t} \t\t\tcsv_resize(csv, m_cols, m_rows); \t\t\tcsv_set(csv, cols - 1, m_rows - 1, strdup(token)); \t\t} \t} \tfclose(fp); \tcsv->rows = m_rows; \tcsv->cols = m_cols; \treturn 0; error: \tfclose(fp); \tprintf(\"Unable to open %s for reading.\", filename); \treturn -1; }", "after": "pub extern \"C\" fn csv_open(mut csv: *mut CSV, mut filename: *mut i8) -> i32 { unsafe { let mut fp: *mut FILE = 0 as *mut FILE; let mut m_rows: u32 = 0; let mut m_cols: u32 = 0; let mut cols: u32 = 0; let mut line: [i8; 2048] = [0; 2048]; let mut lineptr: *mut i8 = 0 as *mut i8; let mut token: *mut i8 = 0 as *mut i8; fp = fopen(filename, b\"r\\0\" as *const u8 as *const i8); if fp.is_null() { fclose(fp); print!( \"Unable to open {} for reading.\", build_str_from_raw_ptr(filename as *mut u8) ); return -1; } else { m_rows = 0; m_cols = 0; while !(fgets( line.as_mut_ptr(), ::core::mem::size_of::<[i8; 2048]>() as i32, fp, )) .is_null() { m_rows = m_rows.wrapping_add(1); cols = 0; lineptr = line.as_mut_ptr(); loop { token = strtok(lineptr, (*csv).delim); if token.is_null() { break; } lineptr = 0 as *mut i8; trim(&mut token); cols = cols.wrapping_add(1); if cols > m_cols { m_cols = cols; } csv_resize(csv, m_cols, m_rows); csv_set( csv, cols.wrapping_sub(1), m_rows.wrapping_sub(1), strdup(token), ); } } fclose(fp); (*csv).rows = m_rows; (*csv).cols = m_cols; return 0; }; } }" }, { "index": 409, "before": "int main(int argc, char **argv) { \tCSV *csv; \tprintf(\"%s\\n%s\\n\\n\", TITLE, URL); \tcsv = csv_create(0, 0); \tcsv_open(csv, \"input.csv\"); \tcsv_display(csv); \tcsv_set(csv, 0, 0, \"Column0\"); \tcsv_set(csv, 1, 1, \"100\"); \tcsv_set(csv, 2, 2, \"200\"); \tcsv_set(csv, 3, 3, \"300\"); \tcsv_set(csv, 4, 4, \"400\"); \tcsv_display(csv); \tcsv_save(csv, \"output.csv\"); \tcsv_destroy(csv); \treturn 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut csv: *mut CSV = 0 as *mut CSV; print!( \"{}\\n{}\\n\\n\", \"CSV data manipulation\\0\", \"http://rosettacode.org/wiki/CSV_data_manipulation\\0\" ); csv = csv_create(0, 0); csv_open(csv, b\"input.csv\\0\" as *const u8 as *const i8 as *mut i8); csv_display(csv); csv_set(csv, 0, 0, b\"Column0\\0\" as *const u8 as *const i8 as *mut i8); csv_set(csv, 1, 1, b\"100\\0\" as *const u8 as *const i8 as *mut i8); csv_set(csv, 2, 2, b\"200\\0\" as *const u8 as *const i8 as *mut i8); csv_set(csv, 3, 3, b\"300\\0\" as *const u8 as *const i8 as *mut i8); csv_set(csv, 4, 4, b\"400\\0\" as *const u8 as *const i8 as *mut i8); csv_display(csv); csv_save(csv, b\"output.csv\\0\" as *const u8 as *const i8 as *mut i8); csv_destroy(csv); return 0; } }" }, { "index": 410, "before": "int csv_save(CSV *csv, char *filename) { \tFILE *fp; \tint row, col; \tchar *content; \tfp = fopen(filename, \"w\"); \tfor (row = 0; row < csv->rows; row++) \t{ \t\tfor (col = 0; col < csv->cols; col++) \t\t{ \t\t\tcontent = csv_get(csv, col, row); \t\t\tfprintf(fp, \"%s%s\", content, \t\t\t\t\t((col == csv->cols - 1) ? \"\" : csv->delim)); \t\t} \t\tfprintf(fp, \"\\n\"); \t} \tfclose(fp); \treturn 0; }", "after": "pub extern \"C\" fn csv_save(mut csv: *mut CSV, mut filename: *mut i8) -> i32 { unsafe { let mut fp: *mut FILE = 0 as *mut FILE; let mut row: i32 = 0; let mut col: i32 = 0; let mut content: *mut i8 = 0 as *mut i8; fp = fopen(filename, b\"w\\0\" as *const u8 as *const i8); row = 0; while (row as u32) < (*csv).rows { col = 0; while (col as u32) < (*csv).cols { content = csv_get(csv, col as u32, row as u32); fprintf( fp, b\"%s%s\\0\" as *const u8 as *const i8, content, if col as u32 == ((*csv).cols).wrapping_sub(1) { b\"\\0\" as *const u8 as *const i8 } else { (*csv).delim as *const i8 }, ); col += 1; col; } fprintf(fp, b\"\\n\\0\" as *const u8 as *const i8); row += 1; row; } fclose(fp); return 0; } }" }, { "index": 411, "before": "int trim(char **str) { \tint trimmed; \tint n; \tint len; \tlen = strlen(*str); \tn = len - 1; \t/* from right */ \twhile ((n >= 0) && isspace((*str)[n])) \t{ \t\t(*str)[n] = '\\0'; \t\ttrimmed += 1; \t\tn--; \t} \t/* from left */ \tn = 0; \twhile ((n < len) && (isspace((*str)[0]))) \t{ \t\t(*str)[0] = '\\0'; \t\t*str = (*str) + 1; \t\ttrimmed += 1; \t\tn++; \t} \treturn trimmed; }", "after": "pub extern \"C\" fn trim(mut str: *mut *mut i8) -> i32 { unsafe { let mut trimmed: i32 = 0; let mut n: i32 = 0; let mut len: i32 = 0; len = strlen(*str) as i32; n = len - 1; while n >= 0 && *(*__ctype_b_loc()).offset(*(*str).offset(n as isize) as i32 as isize) as i32 & _ISspace as i32 != 0 { *(*str).offset(n as isize) = '\\0' as i8; trimmed += 1; n -= 1; n; } n = 0; while n < len && *(*__ctype_b_loc()).offset(*(*str).offset(0 as isize) as i32 as isize) as i32 & _ISspace as i32 != 0 { *(*str).offset(0 as isize) = '\\0' as i8; *str = (*str).offset(1 as isize); trimmed += 1; n += 1; n; } return trimmed; } }" }, { "index": 412, "before": "int csv_resize(CSV *old_csv, unsigned int new_cols, unsigned int new_rows) { \tunsigned int cur_col, \t\tcur_row, \t\tmax_cols, \t\tmax_rows; \tCSV *new_csv; \tchar *content; \tbool in_old, in_new; \t/* Build a new (fake) csv */ \tnew_csv = csv_create(new_cols, new_rows); \tif (new_csv == NULL) \t{ \t\tgoto error; \t} \tnew_csv->rows = new_rows; \tnew_csv->cols = new_cols; \tmax_cols = (new_cols > old_csv->cols) ? new_cols : old_csv->cols; \tmax_rows = (new_rows > old_csv->rows) ? new_rows : old_csv->rows; \tfor (cur_col = 0; cur_col < max_cols; cur_col++) \t{ \t\tfor (cur_row = 0; cur_row < max_rows; cur_row++) \t\t{ \t\t\tin_old = (cur_col < old_csv->cols) && (cur_row < old_csv->rows); \t\t\tin_new = (cur_col < new_csv->cols) && (cur_row < new_csv->rows); \t\t\tif (in_old && in_new) \t\t\t{ \t\t\t\t/* re-link data */ \t\t\t\tcontent = csv_get(old_csv, cur_col, cur_row); \t\t\t\tcsv_set(new_csv, cur_col, cur_row, content); \t\t\t} \t\t\telse if (in_old) \t\t\t{ \t\t\t\t/* destroy data */ \t\t\t\tcontent = csv_get(old_csv, cur_col, cur_row); \t\t\t\tfree(content); \t\t\t} \t\t\telse \t\t\t{ /* skip */ \t\t\t} \t\t} \t} \t/* on rows */ \tfree(old_csv->table); \told_csv->rows = new_rows; \told_csv->cols = new_cols; \told_csv->table = new_csv->table; \tnew_csv->table = NULL; \tcsv_destroy(new_csv); \treturn 0; error: \tprintf(\"Unable to resize CSV table: error %d - %s\\n\", errno, strerror(errno)); \treturn -1; }", "after": "pub extern \"C\" fn csv_resize(mut old_csv: *mut CSV, mut new_cols: u32, mut new_rows: u32) -> i32 { unsafe { let mut cur_col: u32 = 0; let mut cur_row: u32 = 0; let mut max_cols: u32 = 0; let mut max_rows: u32 = 0; let mut new_csv: *mut CSV = 0 as *mut CSV; let mut content: *mut i8 = 0 as *mut i8; let mut in_old: i32 = 0; let mut in_new: i32 = 0; new_csv = csv_create(new_cols, new_rows); if new_csv.is_null() { print!( \"Unable to resize CSV table: error {} - {}\\n\", *__errno_location(), build_str_from_raw_ptr(strerror(*__errno_location()) as *mut u8) ); return -1; } else { (*new_csv).rows = new_rows; (*new_csv).cols = new_cols; max_cols = if new_cols > (*old_csv).cols { new_cols } else { (*old_csv).cols }; max_rows = if new_rows > (*old_csv).rows { new_rows } else { (*old_csv).rows }; cur_col = 0; while cur_col < max_cols { cur_row = 0; while cur_row < max_rows { in_old = (cur_col < (*old_csv).cols && cur_row < (*old_csv).rows) as i32; in_new = (cur_col < (*new_csv).cols && cur_row < (*new_csv).rows) as i32; if in_old != 0 && in_new != 0 { content = csv_get(old_csv, cur_col, cur_row); csv_set(new_csv, cur_col, cur_row, content); } else if in_old != 0 { content = csv_get(old_csv, cur_col, cur_row); free(content as *mut libc::c_void); } cur_row = cur_row.wrapping_add(1); cur_row; } cur_col = cur_col.wrapping_add(1); cur_col; } free((*old_csv).table as *mut libc::c_void); (*old_csv).rows = new_rows; (*old_csv).cols = new_cols; (*old_csv).table = (*new_csv).table; (*new_csv).table = 0 as *mut *mut i8; csv_destroy(new_csv); return 0; }; } }" }, { "index": 413, "before": "void csv_display(CSV *csv) { \tint row, col; \tchar *content; \tif ((csv->rows == 0) || (csv->cols == 0)) \t{ \t\tprintf(\"[Empty table]\\n\"); \t\treturn; \t} \tprintf(\"\\n[Table cols=%d rows=%d]\\n\", csv->cols, csv->rows); \tfor (row = 0; row < csv->rows; row++) \t{ \t\tprintf(\"[|\"); \t\tfor (col = 0; col < csv->cols; col++) \t\t{ \t\t\tcontent = csv_get(csv, col, row); \t\t\tprintf(\"%s\\t|\", content); \t\t} \t\tprintf(\"]\\n\"); \t} \tprintf(\"\\n\"); }", "after": "pub extern \"C\" fn csv_display(mut csv: *mut CSV) { unsafe { let mut row: i32 = 0; let mut col: i32 = 0; let mut content: *mut i8 = 0 as *mut i8; if (*csv).rows == 0 || (*csv).cols == 0 { print!(\"[Empty table]\\n\"); return; } print!(\"\\n[Table cols={} rows={}]\\n\", (*csv).cols, (*csv).rows); row = 0; while (row as u32) < (*csv).rows { print!(\"[|\"); col = 0; while (col as u32) < (*csv).cols { content = csv_get(csv, col as u32, row as u32); print!(\"{}\t|\", build_str_from_raw_ptr(content as *mut u8)); col += 1; col; } print!(\"]\\n\"); row += 1; row; } print!(\"\\n\"); } }" }, { "index": 414, "before": "int csv_destroy(CSV *csv) { \tif (csv == NULL) \t{ \t\treturn 0; \t} \tif (csv->table != NULL) \t{ \t\tfree(csv->table); \t} \tif (csv->delim != NULL) \t{ \t\tfree(csv->delim); \t} \tfree(csv); \treturn 0; }", "after": "pub extern \"C\" fn csv_destroy(mut csv: *mut CSV) -> i32 { unsafe { if csv.is_null() { return 0; } if !((*csv).table).is_null() { free((*csv).table as *mut libc::c_void); } if !((*csv).delim).is_null() { free((*csv).delim as *mut libc::c_void); } free(csv as *mut libc::c_void); return 0; } }" }, { "index": 415, "before": "void hue_to_rgb(double hue, double sat, unsigned char *p) { \tdouble x; \tint c = 255 * sat; \thue /= 60; \tx = (1 - fabs(fmod(hue, 2) - 1)) * 255; \tswitch((int)hue) { \tcase 0:\tp[0] = c; p[1] = x; p[2] = 0; return; \tcase 1:\tp[0] = x; p[1] = c; p[2] = 0; return; \tcase 2:\tp[0] = 0; p[1] = c; p[2] = x; return; \tcase 3:\tp[0] = 0; p[1] = x; p[2] = c; return; \tcase 4:\tp[0] = x; p[1] = 0; p[2] = c; return; \tcase 5:\tp[0] = c; p[1] = 0; p[2] = x; return; \t} }", "after": "pub extern \"C\" fn hue_to_rgb(mut hue: f64, mut sat: f64, mut p: *mut u8) { unsafe { let mut x: f64 = 0.; let mut c: i32 = (255 as f64 * sat) as i32; hue /= 60 as f64; x = (1 as f64 - fabs(fmod(hue, 2 as f64) - 1 as f64)) * 255 as f64; match hue as i32 { 0 => { *p.offset(0 as isize) = c as u8; *p.offset(1 as isize) = x as u8; *p.offset(2 as isize) = 0; return; } 1 => { *p.offset(0 as isize) = x as u8; *p.offset(1 as isize) = c as u8; *p.offset(2 as isize) = 0; return; } 2 => { *p.offset(0 as isize) = 0; *p.offset(1 as isize) = c as u8; *p.offset(2 as isize) = x as u8; return; } 3 => { *p.offset(0 as isize) = 0; *p.offset(1 as isize) = x as u8; *p.offset(2 as isize) = c as u8; return; } 4 => { *p.offset(0 as isize) = x as u8; *p.offset(1 as isize) = 0; *p.offset(2 as isize) = c as u8; return; } 5 => { *p.offset(0 as isize) = c as u8; *p.offset(1 as isize) = 0; *p.offset(2 as isize) = x as u8; return; } _ => {} }; } }" }, { "index": 416, "before": "int main(void) { \tconst int size = 512; \tint i, j; \tunsigned char *colors = malloc(size * 3); \tunsigned char *pix = malloc(size * size * 3), *p; \tFILE *fp; \tfor (i = 0; i < size; i++) \t\thue_to_rgb(i * 240. / size, i * 1. / size, colors + 3 * i); \tfor (i = 0, p = pix; i < size; i++) \t\tfor (j = 0; j < size; j++, p += 3) \t\t\tmemcpy(p, colors + (i ^ j) * 3, 3); \tfp = fopen(\"xor.ppm\", \"wb\"); \tfprintf(fp, \"P6\\n%d %d\\n255\\n\", size, size); \tfwrite(pix, size * size * 3, 1, fp); \tfclose(fp); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let size: i32 = 512; let mut i: i32 = 0; let mut j: i32 = 0; let mut colors: *mut u8 = malloc((size * 3i32) as u64) as *mut u8; let mut pix: *mut u8 = malloc((size * size * 3i32) as u64) as *mut u8; let mut p: *mut u8 = 0 as *mut u8; let mut fp: *mut FILE = 0 as *mut FILE; i = 0; while i < size { hue_to_rgb( i as f64 * 240.0f64 / size as f64, i as f64 * 1.0f64 / size as f64, colors.offset((3 * i) as isize), ); i += 1; i; } i = 0; p = pix; while i < size { j = 0; while j < size { memcpy( p as *mut libc::c_void, colors.offset(((i ^ j) * 3i32) as isize) as *const libc::c_void, 3, ); j += 1; j; p = p.offset(3 as isize); } i += 1; i; } fp = fopen( b\"xor.ppm\\0\" as *const u8 as *const i8, b\"wb\\0\" as *const u8 as *const i8, ); fprintf( fp, b\"P6\\n%d %d\\n255\\n\\0\" as *const u8 as *const i8, size, size, ); fwrite( pix as *const libc::c_void, (size * size * 3i32) as u64, 1, fp, ); fclose(fp); return 0; } }" }, { "index": 417, "before": "void print_entropy(char *word) { \tint ones = 0; \tint zeros = 0; \tint i; \tfor (i = 0; word[i]; i++) { \t\tchar c = word[i]; \t\tswitch (c) { \t\t\tcase '0': \t\t\t\tzeros++; \t\t\t\tbreak; \t\t\tcase '1': \t\t\t\tones++; \t\t\t\tbreak; \t\t} \t} \tdouble entropy = calculate_entropy(ones, zeros); \tprintf(\" %-20.18f\", entropy); }", "after": "pub extern \"C\" fn print_entropy(mut word: *mut i8) { unsafe { let mut ones: i32 = 0; let mut zeros: i32 = 0; let mut i: i32 = 0; i = 0; while *word.offset(i as isize) != 0 { let mut c: i8 = *word.offset(i as isize); match c as i32 { 48 => { zeros += 1; zeros; } 49 => { ones += 1; ones; } _ => {} } i += 1; i; } let mut entropy: f64 = calculate_entropy(ones, zeros); print!(\" {:-20.18}\", entropy); } }" }, { "index": 418, "before": "double calculate_entropy(int ones, int zeros) { \tdouble result = 0; \tint total = ones + zeros; \tresult -= (double) ones / total * log2((double) ones / total); \tresult -= (double) zeros / total * log2((double) zeros / total); \tif (result != result) { // NAN \t\tresult = 0; \t} \treturn result; }", "after": "pub extern \"C\" fn calculate_entropy(mut ones: i32, mut zeros: i32) -> f64 { let mut result: f64 = 0 as f64; let mut total: i32 = ones + zeros; unsafe { result -= ones as f64 / total as f64 * log2(ones as f64 / total as f64); result -= zeros as f64 / total as f64 * log2(zeros as f64 / total as f64); } if result != result { result = 0 as f64; } return result; }" }, { "index": 419, "before": "void print_headings() { \tprintf(\"%2s\", \"N\"); \tprintf(\" %10s\", \"Length\"); \tprintf(\" %-20s\", \"Entropy\"); \tprintf(\" %-40s\", \"Word\"); \tprintf(\"\\n\"); }", "after": "pub extern \"C\" fn print_headings() { print!(\"{:2}\", \"N\\0\"); print!(\" {:10}\", \"Length\\0\"); print!(\" {:-20}\", \"Entropy\\0\"); print!(\" {:-40}\", \"Word\\0\"); print!(\"\\n\"); }" }, { "index": 420, "before": "void print_word(int n, char *word) { \tprintf(\"%2d\", n); \tprintf(\" %10ld\", strlen(word)); \tprint_entropy(word); \tif (n < 10) { \t\tprintf(\" %-40s\", word); \t} else { \t\tprintf(\" %-40s\", \"...\"); \t} \tprintf(\"\\n\"); }", "after": "pub extern \"C\" fn print_word(mut n: i32, mut word: *mut i8) { unsafe { print!(\"{:2}\", n); print!(\" {:10}\", strlen(word)); print_entropy(word); if n < 10 { print!(\" {:-40}\", build_str_from_raw_ptr(word as *mut u8)); } else { print!(\" {:-40}\", \"...\\0\"); } print!(\"\\n\"); } }" }, { "index": 421, "before": "int main(int argc, char *argv[]) { \tprint_headings(); \tchar *last_word = malloc(2); \tstrcpy(last_word, \"1\"); \tchar *current_word = malloc(2); \tstrcpy(current_word, \"0\"); \tprint_word(1, last_word); \tint i; \tfor (i = 2; i <= 37; i++) { \t\tprint_word(i, current_word); \t\tchar *next_word = malloc(strlen(current_word) + strlen(last_word) + 1); \t\tstrcpy(next_word, current_word); \t\tstrcat(next_word, last_word); \t\tfree(last_word); \t\tlast_word = current_word; \t\tcurrent_word = next_word; \t} \tfree(last_word); \tfree(current_word); \treturn 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { print_headings(); let mut last_word: *mut i8 = malloc(2) as *mut i8; strcpy(last_word, b\"1\\0\" as *const u8 as *const i8); let mut current_word: *mut i8 = malloc(2) as *mut i8; strcpy(current_word, b\"0\\0\" as *const u8 as *const i8); print_word(1, last_word); let mut i: i32 = 0; i = 2; while i <= 37 { print_word(i, current_word); let mut next_word: *mut i8 = malloc( (strlen(current_word)) .wrapping_add(strlen(last_word)) .wrapping_add(1), ) as *mut i8; strcpy(next_word, current_word); strcat(next_word, last_word); free(last_word as *mut libc::c_void); last_word = current_word; current_word = next_word; i += 1; i; } free(last_word as *mut libc::c_void); free(current_word as *mut libc::c_void); return 0; } }" }, { "index": 422, "before": "double rk4(double(*f)(double, double), double dx, double x, double y) { \tdouble\tk1 = dx * f(x, y), \t\tk2 = dx * f(x + dx / 2, y + k1 / 2), \t\tk3 = dx * f(x + dx / 2, y + k2 / 2), \t\tk4 = dx * f(x + dx, y + k3); \treturn y + (k1 + 2 * k2 + 2 * k3 + k4) / 6; }", "after": "pub extern \"C\" fn rk4( mut f: Option f64>, mut dx: f64, mut x: f64, mut y: f64, ) -> f64 { unsafe { let mut k1: f64 = dx * f.expect(\"non-null function pointer\")(x, y); let mut k2: f64 = dx * f.expect(\"non-null function pointer\")(x + dx / 2 as f64, y + k1 / 2 as f64); let mut k3: f64 = dx * f.expect(\"non-null function pointer\")(x + dx / 2 as f64, y + k2 / 2 as f64); let mut k4: f64 = dx * f.expect(\"non-null function pointer\")(x + dx, y + k3); return y + (k1 + 2 as f64 * k2 + 2 as f64 * k3 + k4) / 6 as f64; } }" }, { "index": 423, "before": "double rate(double x, double y) { \treturn x * sqrt(y); }", "after": "pub extern \"C\" fn rate(mut x: f64, mut y: f64) -> f64 { unsafe { return x * sqrt(y); } }" }, { "index": 424, "before": "int main(void) { \tdouble *y, x, y2; \tdouble x0 = 0, x1 = 10, dx = .1; \tint i, n = 1 + (x1 - x0)/dx; \ty = (double *)malloc(sizeof(double) * n); \tfor (y[0] = 1, i = 1; i < n; i++) \t\ty[i] = rk4(rate, dx, x0 + dx * (i - 1), y[i-1]); \tprintf(\"x\\ty\\trel. err.\\n------------\\n\"); \tfor (i = 0; i < n; i += 10) { \t\tx = x0 + dx * i; \t\ty2 = pow(x * x / 4 + 1, 2); \t\tprintf(\"%g\\t%g\\t%g\\n\", x, y[i], y[i]/y2 - 1); \t} \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut y: *mut f64 = 0 as *mut f64; let mut x: f64 = 0.; let mut y2: f64 = 0.; let mut x0: f64 = 0 as f64; let mut x1: f64 = 10 as f64; let mut dx: f64 = 0.1f64; let mut i: i32 = 0; let mut n: i32 = (1 as f64 + (x1 - x0) / dx) as i32; y = malloc((::core::mem::size_of::() as u64).wrapping_mul(n as u64)) as *mut f64; *y.offset(0 as isize) = 1 as f64; i = 1; while i < n { *y.offset(i as isize) = rk4( Some(rate as unsafe extern \"C\" fn(f64, f64) -> f64), dx, x0 + dx * (i - 1i32) as f64, *y.offset((i - 1i32) as isize), ); i += 1; i; } print!(\"x\ty\trel. err.\\n------------\\n\"); i = 0; while i < n { x = x0 + dx * i as f64; y2 = pow(x * x / 4 as f64 + 1 as f64, 2 as f64); print!( \"{}\t{}\t{}\\n\", x, *y.offset(i as isize), *y.offset(i as isize) / y2 - 1 as f64 ); i += 10; } return 0; } }" }, { "index": 425, "before": "void show(void *u, int w, int h) { \tint (*univ)[w] = u; \tprintf(\"\\033[H\"); \tfor_y { \t\tfor_x printf(univ[y][x] ? \"\\033[07m \\033[m\" : \" \"); \t\tprintf(\"\\033[E\"); \t} \tfflush(stdout); }", "after": "pub extern \"C\" fn show(mut u: *mut libc::c_void, mut w: i32, mut h: i32) { unsafe { let vla = w as usize; let mut univ: *mut i32 = u as *mut i32; print!(\"\\x1B[H\"); let mut y: i32 = 0; while y < h { let mut x: i32 = 0; while x < w { if *univ.offset(y as isize * vla as isize).offset(x as isize) != 0 { print!(\"\\x1B[07m \\x1B[m\") } else { print!(\" \") }; x += 1; x; } print!(\"\\x1B[E\"); y += 1; y; } fflush(stdout); } }" }, { "index": 426, "before": "int main(int c, char **v) { \tint w = 0, h = 0; \tif (c > 1) w = atoi(v[1]); \tif (c > 2) h = atoi(v[2]); \tif (w <= 0) w = 30; \tif (h <= 0) h = 30; \tgame(w, h); }", "after": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { let mut w: i32 = 0; let mut h: i32 = 0; if c > 1 { w = atoi(*v.offset(1 as isize)); } if c > 2 { h = atoi(*v.offset(2 as isize)); } if w <= 0 { w = 30; } if h <= 0 { h = 30; } game(w, h); return 0; } }" }, { "index": 427, "before": "void evolve(void *u, int w, int h) { \tunsigned (*univ)[w] = u; \tunsigned new[h][w]; \tfor_y for_x { \t\tint n = 0; \t\tfor (int y1 = y - 1; y1 <= y + 1; y1++) \t\t\tfor (int x1 = x - 1; x1 <= x + 1; x1++) \t\t\t\tif (univ[(y1 + h) % h][(x1 + w) % w]) \t\t\t\t\tn++; \t\tif (univ[y][x]) n--; \t\tnew[y][x] = (n == 3 || (n == 2 && univ[y][x])); \t} \tfor_y for_x univ[y][x] = new[y][x]; }", "after": "pub extern \"C\" fn evolve(mut u: *mut libc::c_void, mut w: i32, mut h: i32) { unsafe { let vla = w as usize; let mut univ: *mut u32 = u as *mut u32; let vla_0 = h as usize; let vla_1 = w as usize; let mut new: Vec = ::std::vec::from_elem(0, vla_0 * vla_1); let mut y: i32 = 0; while y < h { let mut x: i32 = 0; while x < w { let mut n: i32 = 0; let mut y1: i32 = y - 1; while y1 <= y + 1 { let mut x1: i32 = x - 1; while x1 <= x + 1 { if *univ .offset(((y1 + h) % h) as isize * vla as isize) .offset(((x1 + w) % w) as isize) != 0 { n += 1; n; } x1 += 1; x1; } y1 += 1; y1; } if *univ.offset(y as isize * vla as isize).offset(x as isize) != 0 { n -= 1; n; }; *new.as_mut_ptr() .offset(y as isize * vla_1 as isize) .offset(x as isize) = (n == 3 || n == 2 && *univ.offset(y as isize * vla as isize).offset(x as isize) != 0) as u32; x += 1; x; } y += 1; y; } let mut y_0: i32 = 0; while y_0 < h { let mut x_0: i32 = 0; while x_0 < w { *univ .offset(y_0 as isize * vla as isize) .offset(x_0 as isize) = *new .as_mut_ptr() .offset(y_0 as isize * vla_1 as isize) .offset(x_0 as isize); x_0 += 1; x_0; } y_0 += 1; y_0; } } }" }, { "index": 428, "before": "void game(int w, int h) { \tunsigned univ[h][w]; \tfor_xy univ[y][x] = rand() < RAND_MAX / 10 ? 1 : 0; \twhile (1) { \t\tshow(univ, w, h); \t\tevolve(univ, w, h); \t\tusleep(200000); \t} }", "after": "pub extern \"C\" fn game(mut w: i32, mut h: i32) { let vla = h as usize; let vla_0 = w as usize; let mut univ: Vec = ::std::vec::from_elem(0, vla * vla_0); let mut x: i32 = 0; unsafe { while x < w { let mut y: i32 = 0; while y < h { *univ .as_mut_ptr() .offset(y as isize * vla_0 as isize) .offset(x as isize) = (if rand() < 2147483647 / 10i32 { 1 } else { 0 }) as u32; y += 1; y; } x += 1; x; } loop { show(univ.as_mut_ptr() as *mut libc::c_void, w, h); evolve(univ.as_mut_ptr() as *mut libc::c_void, w, h); usleep(200000); } } }" }, { "index": 429, "before": "int main(void) { \tsrand(time(0)); \tputs(\" n\\tavg\\texp.\\tdiff\\n-------------------------------\"); \tint n; \tfor (n = 1; n <= MAX_N; n++) { \t\tint cnt = test(n, TIMES); \t\tdouble avg = (double)cnt / TIMES; \t\tdouble theory = expected(n); \t\tdouble diff = (avg / theory - 1) * 100; \t\tprintf(\"%2d %8.4f %8.4f %6.3f%%\\n\", n, avg, theory, diff); \t} \treturn 0; }", "after": "fn main() -> i32 { unsafe { srand(rust_time(None) as u32); puts(b\" n\\tavg\\texp.\\tdiff\\n-------------------------------\\0\" as *const u8 as *const i8); } let mut n: i32 = 0; n = 1; while n <= 20 { let mut cnt: i32 = test(n, 1000000); let mut avg: f64 = cnt as f64 / 1000000 as f64; let mut theory: f64 = expected(n); let mut diff: f64 = (avg / theory - 1 as f64) * 100 as f64; print!(\"{:2} {:8.4} {:8.4} {:6.3}%\\n\", n, avg, theory, diff); n += 1; n; } return 0; }" }, { "index": 430, "before": "double expected(int n) { \tdouble sum = 0; \tint i; \tfor (i = 1; i <= n; i++) \t\tsum += factorial(n) / pow(n, i) / factorial(n - i); \treturn sum; }", "after": "pub extern \"C\" fn expected(mut n: i32) -> f64 { let mut sum: f64 = 0 as f64; let mut i: i32 = 0; i = 1; unsafe { while i <= n { sum += factorial(n) / pow(n as f64, i as f64) / factorial(n - i); i += 1; i; } } return sum; }" }, { "index": 431, "before": "int test(int n, int times) { \tint i, count = 0; \tfor (i = 0; i < times; i++) { \t\tint x = 1, bits = 0; \t\twhile (!(bits & x)) { \t\t\tcount++; \t\t\tbits |= x; \t\t\tx = 1 << randint(n); \t\t} \t} \treturn count; }", "after": "pub extern \"C\" fn test(mut n: i32, mut times: i32) -> i32 { let mut i: i32 = 0; let mut count: i32 = 0; i = 0; while i < times { let mut x: i32 = 1; let mut bits: i32 = 0; while bits & x == 0 { count += 1; count; bits |= x; x = 1 << randint(n); } i += 1; i; } return count; }" }, { "index": 432, "before": "int randint(int n) { \tint r, rmax = RAND_MAX / n * n; \twhile ((r = rand()) >= rmax); \treturn r / (RAND_MAX / n); }", "after": "pub extern \"C\" fn randint(mut n: i32) -> i32 { let mut r: i32 = 0; let mut rmax: i32 = 2147483647 / n * n; unsafe { loop { r = rand(); if !(r >= rmax) { break; } } } return r / (2147483647 / n); }" }, { "index": 433, "before": "double factorial(int n) { \tdouble f = 1; \tint i; \tfor (i = 1; i <= n; i++) f *= i; \treturn f; }", "after": "pub extern \"C\" fn factorial(mut n: i32) -> f64 { let mut f: f64 = 1 as f64; let mut i: i32 = 0; i = 1; while i <= n { f *= i as f64; i += 1; i; } return f; }" }, { "index": 434, "before": "int playerTurn(int numTokens, int take) { \tif (take < 1 || take > 3) \t{ \t\tprintf(\"\\nTake must be between 1 and 3.\\n\\n\"); \t\treturn numTokens; \t} \tint remainingTokens = numTokens - take; \tprintf(\"\\nPlayer takes %i tokens.\\n\", take); \tprintf(\"%i tokens remaining.\\n\\n\", remainingTokens); \treturn remainingTokens; }", "after": "pub extern \"C\" fn playerTurn(mut numTokens: i32, mut take: i32) -> i32 { if take < 1 || take > 3 { print!(\"\\nTake must be between 1 and 3.\\n\\n\"); return numTokens; } let mut remainingTokens: i32 = numTokens - take; print!(\"\\nPlayer takes {} tokens.\\n\", take); print!(\"{} tokens remaining.\\n\\n\", remainingTokens); return remainingTokens; }" }, { "index": 435, "before": "int main(void) { \tprintf(\"Nim Game\\n\\n\"); \tint Tokens = 12; \twhile(Tokens > 0) \t{ \t\tprintf(\"How many tokens would you like to take?: \"); \t\tint uin; \t\tscanf(\"%i\", &uin); \t\tint nextTokens = playerTurn(Tokens, uin); \t\tif (nextTokens == Tokens) \t\t{ \t\t\tcontinue; \t\t} \t\tTokens = nextTokens; \t\tTokens = computerTurn(Tokens); \t} \tprintf(\"Computer wins.\"); \treturn 0; }", "after": "fn main() -> i32 { print!(\"Nim Game\\n\\n\"); let mut Tokens: i32 = 12; unsafe { while Tokens > 0 { print!(\"How many tokens would you like to take?: \"); let mut uin: i32 = 0; scanf(b\"%i\\0\" as *const u8 as *const i8, &mut uin as *mut i32); let mut nextTokens: i32 = playerTurn(Tokens, uin); if nextTokens == Tokens { continue; } Tokens = nextTokens; Tokens = computerTurn(Tokens); } } print!(\"Computer wins.\"); return 0; }" }, { "index": 436, "before": "int computerTurn(int numTokens) { \tint take = numTokens % 4; \tint remainingTokens = numTokens - take; \tprintf(\"Computer takes %u tokens.\\n\", take); \tprintf(\"%i tokens remaining.\\n\\n\", remainingTokens); \treturn remainingTokens; }", "after": "pub extern \"C\" fn computerTurn(mut numTokens: i32) -> i32 { let mut take: i32 = numTokens % 4; let mut remainingTokens: i32 = numTokens - take; print!(\"Computer takes {} tokens.\\n\", take); print!(\"{} tokens remaining.\\n\\n\", remainingTokens); return remainingTokens; }" }, { "index": 437, "before": "int main(void) { \tint x[] = { 3, 2, 6, 4, 5, 1 }; \tint y[] = { 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 }; \tlis(x, sizeof(x) / sizeof(int)); \tlis(y, sizeof(y) / sizeof(int)); \treturn 0; }", "after": "fn main() -> i32 { let mut x: [i32; 6] = [3, 2, 6, 4, 5, 1]; let mut y: [i32; 16] = [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]; lis( x.as_mut_ptr(), (::core::mem::size_of::<[i32; 6]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, ); lis( y.as_mut_ptr(), (::core::mem::size_of::<[i32; 16]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, ); return 0; }" }, { "index": 438, "before": "void lis(int *v, int len) { \tint i; \tstruct node *p, *n = calloc(len, sizeof *n); \tfor (i = 0; i < len; i++) \t\tn[i].val = v[i]; \tfor (i = len; i--; ) { \t\t// find longest chain that can follow n[i] \t\tfor (p = n + i; p++ < n + len; ) { \t\t\tif (p->val > n[i].val && p->len >= n[i].len) { \t\t\t\tn[i].next = p; \t\t\t\tn[i].len = p->len + 1; \t\t\t} \t\t} \t} \t// find longest chain \tfor (i = 0, p = n; i < len; i++) \t\tif (n[i].len > p->len) p = n + i; \tdo printf(\" %d\", p->val); while ((p = p->next)); \tputchar('\\n'); \tfree(n); }", "after": "pub extern \"C\" fn lis(mut v: *mut i32, mut len: i32) { unsafe { let mut i: i32 = 0; let mut p: *mut node = 0 as *mut node; let mut n: *mut node = calloc(len as u64, ::core::mem::size_of::() as u64) as *mut node; i = 0; while i < len { (*n.offset(i as isize)).val = *v.offset(i as isize); i += 1; i; } i = len; loop { let fresh0 = i; i = i - 1; if !(fresh0 != 0) { break; } p = n.offset(i as isize); loop { let fresh1 = p; p = p.offset(1); if !(fresh1 < n.offset(len as isize)) { break; } if (*p).val > (*n.offset(i as isize)).val && (*p).len >= (*n.offset(i as isize)).len { let ref mut fresh2 = (*n.offset(i as isize)).next; *fresh2 = p; (*n.offset(i as isize)).len = (*p).len + 1; } } } i = 0; p = n; while i < len { if (*n.offset(i as isize)).len > (*p).len { p = n.offset(i as isize); } i += 1; i; } loop { print!(\" {}\", (*p).val); p = (*p).next; if p.is_null() { break; } } print!(\"{}\", '\\n' as i32); free(n as *mut libc::c_void); } }" }, { "index": 439, "before": "int main(){ int n=0; while(n<9) doSeq(n++); return 0; }", "after": "fn main() -> i32 { let mut n: i32 = 0; while n < 9 { let fresh2 = n; n = n + 1; doSeq(fresh2); } return 0; }" }, { "index": 440, "before": "void shuffle(char*s,int h){ int x,t,i=h; while(i--){ \tt=s[x=rand()%h]; \ts[x]=s[i]; \ts[i]=t; } }", "after": "pub extern \"C\" fn shuffle(mut s: *mut i8, mut h: i32) { unsafe { let mut x: i32 = 0; let mut t: i32 = 0; let mut i: i32 = h; loop { let fresh1 = i; i = i - 1; if !(fresh1 != 0) { break; } x = rand() % h; t = *s.offset(x as isize) as i32; *s.offset(x as isize) = *s.offset(i as isize); *s.offset(i as isize) = t as i8; } } }" }, { "index": 441, "before": "int isBal(const char*s,int l){ signed c=0; while(l--) \tif(s[l]==']') ++c; \telse if(s[l]=='[') if(--c<0) break; return !c; }", "after": "pub extern \"C\" fn isBal(mut s: *const i8, mut l: i32) -> i32 { unsafe { let mut c: i32 = 0; loop { let fresh0 = l; l = l - 1; if !(fresh0 != 0) { break; } if *s.offset(l as isize) as i32 == ']' as i32 { c += 1; c; } else { if !(*s.offset(l as isize) as i32 == '[' as i32) { continue; } c -= 1; if c < 0 { break; } } } return (c == 0) as i32; } }" }, { "index": 442, "before": "void doSeq(int n){ char s[64]; const char *o=\"False\"; genSeq(s,n); if(isBal(s,n*2)) o=\"True\"; printf(\"'%s': %s\\n\",s,o); }", "after": "pub extern \"C\" fn doSeq(mut n: i32) { unsafe { let mut s: [i8; 64] = [0; 64]; let mut o: *const i8 = b\"False\\0\" as *const u8 as *const i8; genSeq(s.as_mut_ptr(), n); if isBal(s.as_mut_ptr(), n * 2) != 0 { o = b\"True\\0\" as *const u8 as *const i8; } print!( \"{}: {}\\n\", build_str_from_raw_ptr(s.as_mut_ptr() as *mut u8), build_str_from_raw_ptr(o as *mut u8) ); } }" }, { "index": 443, "before": "void genSeq(char*s,int n){ if(n){ \tmemset(s,'[',n); \tmemset(s+n,']',n); \tshuffle(s,n*2); } s[n*2]=0; }", "after": "pub extern \"C\" fn genSeq(mut s: *mut i8, mut n: i32) { unsafe { if n != 0 { memset(s as *mut libc::c_void, '[' as i32, n as u64); memset( s.offset(n as isize) as *mut libc::c_void, ']' as i32, n as u64, ); shuffle(s, n * 2); }; *s.offset((n * 2i32) as isize) = 0; } }" }, { "index": 444, "before": "int valid(const char *s) { \tunsigned char dec[32], d1[SHA256_DIGEST_LENGTH], d2[SHA256_DIGEST_LENGTH]; \tcoin_err = \"\"; \tif (!unbase58(s, dec)) return 0; \tSHA256(SHA256(dec, 21, d1), SHA256_DIGEST_LENGTH, d2); \tif (memcmp(dec + 21, d2, 4)) \t\tbail(\"bad digest\"); \treturn 1; }", "after": "pub extern \"C\" fn valid(mut s: *const i8) -> i32 { unsafe { let mut dec: [u8; 32] = [0; 32]; let mut d1: [u8; 32] = [0; 32]; let mut d2: [u8; 32] = [0; 32]; coin_err = b\"\\0\" as *const u8 as *const i8; if unbase58(s, dec.as_mut_ptr()) == 0 { return 0; } SHA256( SHA256(dec.as_mut_ptr(), 21, d1.as_mut_ptr()), 32, d2.as_mut_ptr(), ); if memcmp( dec.as_mut_ptr().offset(21 as isize) as *const libc::c_void, d2.as_mut_ptr() as *const libc::c_void, 4, ) != 0 { coin_err = b\"bad digest\\0\" as *const u8 as *const i8; return 0; } return 1; } }" }, { "index": 445, "before": "int unbase58(const char *s, unsigned char *out) { \tstatic const char *tmpl = \"123456789\" \t\t\"ABCDEFGHJKLMNPQRSTUVWXYZ\" \t\t\"abcdefghijkmnopqrstuvwxyz\"; \tint i, j, c; \tconst char *p; \tmemset(out, 0, 25); \tfor (i = 0; s[i]; i++) { \t\tif (!(p = strchr(tmpl, s[i]))) \t\t\tbail(\"bad char\"); \t\tc = p - tmpl; \t\tfor (j = 25; j--; ) { \t\t\tc += 58 * out[j]; \t\t\tout[j] = c % 256; \t\t\tc /= 256; \t\t} \t\tif (c) bail(\"address too long\"); \t} \treturn 1; }", "after": "pub extern \"C\" fn unbase58(mut s: *const i8, mut out: *mut u8) -> i32 { unsafe { static mut tmpl: *const i8 = b\"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\\0\" as *const u8 as *const i8; let mut i: i32 = 0; let mut j: i32 = 0; let mut c: i32 = 0; let mut p: *const i8 = 0 as *const i8; memset(out as *mut libc::c_void, 0, 25); i = 0; while *s.offset(i as isize) != 0 { p = strchr(tmpl, *s.offset(i as isize) as i32); if p.is_null() { coin_err = b\"bad char\\0\" as *const u8 as *const i8; return 0; } c = p.offset_from(tmpl) as i32; j = 25; loop { let fresh0 = j; j = j - 1; if !(fresh0 != 0) { break; } c += 58 * *out.offset(j as isize) as i32; *out.offset(j as isize) = (c % 256i32) as u8; c /= 256; } if c != 0 { coin_err = b\"address too long\\0\" as *const u8 as *const i8; return 0; } i += 1; i; } return 1; } }" }, { "index": 446, "before": "int main (void) { \tconst char *s[] = { \t\t\"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9\", \t\t\"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i\", \t\t\"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9\", \t\t\"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I\", \t\t0 }; \tint i; \tfor (i = 0; s[i]; i++) { \t\tint status = valid(s[i]); \t\tprintf(\"%s: %s\\n\", s[i], status ? \"Ok\" : coin_err); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut s: [*const i8; 5] = [ b\"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9\\0\" as *const u8 as *const i8, b\"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i\\0\" as *const u8 as *const i8, b\"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9\\0\" as *const u8 as *const i8, b\"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I\\0\" as *const u8 as *const i8, 0 as *const i8, ]; let mut i: i32 = 0; i = 0; unsafe { while !(s[i as usize]).is_null() { let mut status: i32 = valid(s[i as usize]); if status != 0 { print!( \"{}: {}\\n\", build_str_from_raw_ptr(s[i as usize] as *mut u8), \"Ok\\0\" ) } else { print!( \"{}: {}\\n\", build_str_from_raw_ptr(s[i as usize] as *mut u8), build_str_from_raw_ptr(coin_err as *mut u8) ) }; i += 1; i; } } return 0; }" }, { "index": 447, "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 extern \"C\" fn evolve(mut state: u64, mut rule: i32) { let mut i: i32 = 0; let mut p: i32 = 0; let mut q: i32 = 0; let mut b: i32 = 0; p = 0; while p < 10 { b = 0; q = 8; loop { let fresh0 = q; q = q - 1; if !(fresh0 != 0) { break; } let mut st: u64 = state; b = (b as u64 | (st & 1u64) << q) as i32; i = 0; state = i as u64; while (i as u64) < (::core::mem::size_of::() as u64).wrapping_mul(8) { if rule as u64 & 1u64 << (7 & (st >> i - 1 | st << (::core::mem::size_of::() as u64) .wrapping_mul(8) .wrapping_add(1) .wrapping_sub(i as u64))) != 0 { state |= 1 << i; } i += 1; i; } } print!(\" {}\", b); p += 1; p; } print!(\"{}\", '\\n' as i32); }" }, { "index": 448, "before": "int main(void) { \tevolve(1, 30); \treturn 0; }", "after": "fn main() -> i32 { evolve(1, 30); return 0; }" }, { "index": 449, "before": "int ackermann(int m, int n) { if (!m) return n + 1; if (!n) return ackermann(m - 1, 1); return ackermann(m - 1, ackermann(m, n - 1)); }", "after": "pub extern \"C\" fn ackermann(mut m: i32, mut n: i32) -> i32 { if m == 0 { return n + 1; } if n == 0 { return ackermann(m - 1, 1); } return ackermann(m - 1, ackermann(m, n - 1)); }" }, { "index": 450, "before": "int main() { int m, n; for (m = 0; m <= 4; m++) for (n = 0; n < 6 - m; n++) printf(\"A(%d, %d) = %d\\n\", m, n, ackermann(m, n)); return 0; }", "after": "fn main() -> i32 { let mut m: i32 = 0; let mut n: i32 = 0; m = 0; while m <= 4 { n = 0; while n < 6 - m { print!(\"A({}, {}) = {}\\n\", m, n, ackermann(m, n)); n += 1; n; } m += 1; m; } return 0; }" }, { "index": 451, "before": "int main() { \tint y, x; \tfor (y = 1; y <= 10; y++) \t\tfor (x = 1; x <= y; x++) \t\t\tif (!(x & 1) || !(y & 1)) \t\t\t\tprintf(\"%d x %d: %llu\\n\", y, x, solve(y, x, 1)); \treturn 0; }", "after": "fn main() -> i32 { let mut y: i32 = 0; let mut x: i32 = 0; y = 1; while y <= 10 { x = 1; while x <= y { if x & 1 == 0 || y & 1 == 0 { print!(\"{} x {}: {}\\n\", y, x, solve(y, x, 1)); } x += 1; x; } y += 1; y; } return 0; }" }, { "index": 452, "before": "unsigned long long solve(int hh, int ww, int recur) { \tint t, cx, cy, x; \th = hh, w = ww; \tif (h & 1) t = w, w = h, h = t; \tif (h & 1) return 0; \tif (w == 1) return 1; \tif (w == 2) return h; \tif (h == 2) return w; \tcy = h / 2, cx = w / 2; \tlen = (h + 1) * (w + 1); \tgrid = realloc(grid, len); \tmemset(grid, 0, len--); \tnext[0] = -1; \tnext[1] = -w - 1; \tnext[2] = 1; \tnext[3] = w + 1; \tif (recur) cnt = 0; \tfor (x = cx + 1; x < w; x++) { \t\tt = cy * (w + 1) + x; \t\tgrid[t] = 1; \t\tgrid[len - t] = 1; \t\twalk(cy - 1, x); \t} \tcnt++; \tif (h == w) \t\tcnt *= 2; \telse if (!(w & 1) && recur) \t\tsolve(w, h, 0); \treturn cnt; }", "after": "pub extern \"C\" fn solve(mut hh: i32, mut ww: i32, mut recur: i32) -> u64 { let mut t: i32 = 0; let mut cx: i32 = 0; let mut cy: i32 = 0; let mut x: i32 = 0; unsafe { h = hh; w = ww; if h & 1 != 0 { t = w; w = h; h = t; } if h & 1 != 0 { return 0; } if w == 1 { return 1; } if w == 2 { return h as u64; } if h == 2 { return w as u64; } cy = h / 2; cx = w / 2; len = (h + 1) * (w + 1); grid = realloc(grid as *mut libc::c_void, len as u64) as *mut u8; let fresh4 = len; len = len - 1; memset(grid as *mut libc::c_void, 0, fresh4 as u64); next[0 as usize] = -1; next[1 as usize] = -w - 1; next[2 as usize] = 1; next[3 as usize] = w + 1; if recur != 0 { cnt = 0; } } x = cx + 1; unsafe { while x < w { t = cy * (w + 1) + x; *grid.offset(t as isize) = 1; *grid.offset((len - t) as isize) = 1; walk(cy - 1, x); x += 1; x; } cnt = cnt.wrapping_add(1); cnt; if h == w { cnt = cnt.wrapping_mul(2); } else if w & 1 == 0 && recur != 0 { solve(w, h, 0); } return cnt; } }" }, { "index": 453, "before": "void walk(int y, int x) { \tint i, t; \tif (!y || y == h || !x || x == w) { \t\tcnt += 2; \t\treturn; \t} \tt = y * (w + 1) + x; \tgrid[t]++, grid[len - t]++; \tfor (i = 0; i < 4; i++) \t\tif (!grid[t + next[i]]) \t\t\twalk(y + dir[i][0], x + dir[i][1]); \tgrid[t]--, grid[len - t]--; }", "after": "pub extern \"C\" fn walk(mut y: i32, mut x: i32) { let mut i: i32 = 0; let mut t: i32 = 0; unsafe { if y == 0 || y == h || x == 0 || x == w { cnt = cnt.wrapping_add(2); return; } t = y * (w + 1) + x; let ref mut fresh0 = *grid.offset(t as isize); *fresh0 = (*fresh0).wrapping_add(1); *fresh0; let ref mut fresh1 = *grid.offset((len - t) as isize); *fresh1 = (*fresh1).wrapping_add(1); *fresh1; } i = 0; unsafe { while i < 4 { if *grid.offset((t + next[i as usize]) as isize) == 0 { walk( y + dir[i as usize][0 as usize], x + dir[i as usize][1 as usize], ); } i += 1; i; } let ref mut fresh2 = *grid.offset(t as isize); *fresh2 = (*fresh2).wrapping_sub(1); *fresh2; let ref mut fresh3 = *grid.offset((len - t) as isize); *fresh3 = (*fresh3).wrapping_sub(1); *fresh3; } }" }, { "index": 454, "before": "int main() { driver(10, -2); driver(146, -3); driver(15, -10); driver(12, -62); return 0; }", "after": "fn main() -> i32 { driver(10, -2 as i64); driver(146, -3 as i64); driver(15, -10 as i64); driver(12, -62 as i64); return 0; }" }, { "index": 455, "before": "long decodeNegativeBase(const char* ns, long base) { long value, bb; int i; const char *ptr; if (base < -62 || base > -1) { /* Bounds check */ return 0; } if (ns[0] == 0 || (ns[0] == '0' && ns[1] == 0)) { /* Trivial case */ return 0; } /* Find the end of the string */ ptr = ns; while (*ptr != 0) { ptr++; } /* Convert */ value = 0; bb = 1; ptr--; while (ptr >= ns) { for (i = 0; i < DIGITS_LEN; i++) { if (*ptr == DIGITS[i]) { value = value + i * bb; bb = bb * base; break; } } ptr--; } return value; }", "after": "pub extern \"C\" fn decodeNegativeBase(mut ns: *const i8, mut base: i64) -> i64 { unsafe { let mut value: i64 = 0; let mut bb: i64 = 0; let mut i: i32 = 0; let mut ptr: *const i8 = 0 as *const i8; if base < -62 as i64 || base > -1 as i64 { return 0; } if *ns.offset(0 as isize) as i32 == 0 || *ns.offset(0 as isize) as i32 == '0' as i32 && *ns.offset(1 as isize) as i32 == 0 { return 0; } ptr = ns; while *ptr as i32 != 0 { ptr = ptr.offset(1); ptr; } value = 0; bb = 1; ptr = ptr.offset(-1); ptr; while ptr >= ns { i = 0; while i < DIGITS_LEN { if *ptr as i32 == DIGITS[i as usize] as i32 { value = value + i as i64 * bb; bb = bb * base; break; } else { i += 1; i; } } ptr = ptr.offset(-1); ptr; } return value; } }" }, { "index": 456, "before": "void driver(long n, long b) { char buf[64]; long value; encodeNegativeBase(n, b, buf); printf(\"%12d encoded in base %3d = %12s\\n\", n, b, buf); value = decodeNegativeBase(buf, b); printf(\"%12s decoded in base %3d = %12d\\n\", buf, b, value); printf(\"\\n\"); }", "after": "pub extern \"C\" fn driver(mut n: i64, mut b: i64) { let mut buf: [i8; 64] = [0; 64]; let mut value: i64 = 0; encodeNegativeBase(n, b, buf.as_mut_ptr()); unsafe { print!( \"{:12} encoded in base {:3} = {:12}\\n\", n, b, build_str_from_raw_ptr(buf.as_mut_ptr() as *mut u8) ); } value = decodeNegativeBase(buf.as_mut_ptr(), b); unsafe { print!( \"{:12} decoded in base {:3} = {:12}\\n\", build_str_from_raw_ptr(buf.as_mut_ptr() as *mut u8), b, value ); } print!(\"\\n\"); }" }, { "index": 457, "before": "void encodeNegativeBase(long n, long base, char *out) { char *ptr = out; if (base > -1 || base < -62) { /* Bounds check*/ out = \"\"; return; } if (n == 0) { /* Trivial case */ out = \"0\"; return; } /* Convert the number into a string (in reverse) */ while (n != 0) { long rem = n % base; n = n / base; if (rem < 0) { n++; rem = rem - base; } *ptr = DIGITS[rem]; ptr++; } *ptr = 0; /* Reverse the current string to get the final result */ ptr--; while (out < ptr) { char t = *out; *out = *ptr; *ptr = t; out++; ptr--; } return; }", "after": "pub extern \"C\" fn encodeNegativeBase(mut n: i64, mut base: i64, mut out: *mut i8) { unsafe { let mut ptr: *mut i8 = out; if base > -1 as i64 || base < -62 as i64 { out = b\"\\0\" as *const u8 as *const i8 as *mut i8; return; } if n == 0 { out = b\"0\\0\" as *const u8 as *const i8 as *mut i8; return; } while n != 0 { let mut rem: i64 = n % base; n = n / base; if rem < 0 { n += 1; n; rem = rem - base; } *ptr = DIGITS[rem as usize]; ptr = ptr.offset(1); ptr; } *ptr = 0; ptr = ptr.offset(-1); ptr; while out < ptr { let mut t: i8 = *out; *out = *ptr; *ptr = t; out = out.offset(1); out; ptr = ptr.offset(-1); ptr; } } }" }, { "index": 458, "before": "ham qpop() { \tint i, j; \tham r, t; \t/* outer loop for skipping duplicates */ \tfor (r = q[1]; n > 1 && r == q[1]; q[i] = t) { \t\t/* inner loop is the normal down heap routine */ \t\tfor (i = 1, t = q[--n]; (j = i * 2) < n;) { \t\t\tif (j + 1 < n && q[j] > q[j+1]) j++; \t\t\tif (t <= q[j]) break; \t\t\tq[i] = q[j], i = j; \t\t} \t} \treturn r; }", "after": "pub extern \"C\" fn qpop() -> u64 { let mut i: i32 = 0; let mut j: i32 = 0; let mut r: u64 = 0; let mut t: u64 = 0; unsafe { r = *q.offset(1 as isize); while n > 1 && r == *q.offset(1 as isize) { i = 1; n = n.wrapping_sub(1); t = *q.offset(n as isize); loop { j = i * 2; if !((j as u64) < n) { break; } if ((j + 1i32) as u64) < n && *q.offset(j as isize) > *q.offset((j + 1i32) as isize) { j += 1; j; } if t <= *q.offset(j as isize) { break; }; *q.offset(i as isize) = *q.offset(j as isize); i = j; } *q.offset(i as isize) = t; } } return r; }" }, { "index": 459, "before": "void qpush(ham h) { \tint i, j; \tif (alloc <= n) { \t\talloc = alloc ? alloc * 2 : 16; \t\tq = realloc(q, sizeof(ham) * alloc); \t} \tfor (i = n++; (j = i/2) && q[j] > h; q[i] = q[j], i = j); \tq[i] = h; }", "after": "pub extern \"C\" fn qpush(mut h: u64) { let mut i: i32 = 0; let mut j: i32 = 0; unsafe { if alloc <= n { alloc = if alloc != 0 { alloc.wrapping_mul(2) } else { 16 }; q = realloc( q as *mut libc::c_void, (::core::mem::size_of::() as u64).wrapping_mul(alloc), ) as *mut u64; } let fresh0 = n; n = n.wrapping_add(1); i = fresh0 as i32; loop { j = i / 2; if !(j != 0 && *q.offset(j as isize) > h) { break; }; *q.offset(i as isize) = *q.offset(j as isize); i = j; } *q.offset(i as isize) = h; } }" }, { "index": 460, "before": "int main() { \tint i; \tham h; \tfor (qpush(i = 1); i <= 1691; i++) { \t\t/* takes smallest value, and queue its multiples */ \t\th = qpop(); \t\tqpush(h * 2); \t\tqpush(h * 3); \t\tqpush(h * 5); \t\tif (i <= 20 || i == 1691) \t\t\tprintf(\"%6d: %llu\\n\", i, h); \t} \t/* free(q); */ \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut h: u64 = 0; i = 1; qpush(i as u64); while i <= 1691 { h = qpop(); qpush(h.wrapping_mul(2)); qpush(h.wrapping_mul(3)); qpush(h.wrapping_mul(5)); if i <= 20 || i == 1691 { print!(\"{:6}: {}\\n\", i, h); } i += 1; i; } return 0; }" }, { "index": 461, "before": "int main(int c, char **v) { \tint ret = 0, i; \tif (c < 2) return -1; \tfor (i = 1; i < c; i++) { \t\tret = dir_empty(v[i]); \t\tif (ret >= 0) \t\t\tprintf(\"%s: %sempty\\n\", v[i], ret ? \"\" : \"not \"); \t} \treturn 0; }", "after": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { let mut ret: i32 = 0; let mut i: i32 = 0; if c < 2 { return -1; } i = 1; while i < c { ret = dir_empty(*v.offset(i as isize)); if ret >= 0 { if ret != 0 { print!( \"{}: {}empty\\n\", build_str_from_raw_ptr(*v.offset(i as isize) as *mut u8), \"\\0\" ) } else { print!( \"{}: {}empty\\n\", build_str_from_raw_ptr(*v.offset(i as isize) as *mut u8), \"not \\0\" ) }; } i += 1; i; } return 0; } }" }, { "index": 462, "before": "int dir_empty(const char *path) { \tstruct dirent *ent; \tint ret = 1; \tDIR *d = opendir(path); \tif (!d) { \t\tfprintf(stderr, \"%s: \", path); \t\tperror(\"\"); \t\treturn -1; \t} \twhile ((ent = readdir(d))) { \t\tif (!strcmp(ent->d_name, \".\") || !(strcmp(ent->d_name, \"..\"))) \t\t\tcontinue; \t\tret = 0; \t\tbreak; \t} \tclosedir(d); \treturn ret; }", "after": "pub extern \"C\" fn dir_empty(mut path: *const i8) -> i32 { unsafe { let mut ent: *mut dirent = 0 as *mut dirent; let mut ret: i32 = 1; let mut d: *mut DIR = opendir(path); if d.is_null() { fprintf(stderr, b\"%s: \\0\" as *const u8 as *const i8, path); perror(b\"\\0\" as *const u8 as *const i8); return -1; } loop { ent = readdir(d); if ent.is_null() { break; } if strcmp( ((*ent).d_name).as_mut_ptr(), b\".\\0\" as *const u8 as *const i8, ) == 0 || strcmp( ((*ent).d_name).as_mut_ptr(), b\"..\\0\" as *const u8 as *const i8, ) == 0 { continue; } ret = 0; break; } closedir(d); return ret; } }" }, { "index": 463, "before": "point extractPoint(char* str){ \tint i,j,start,end,length; \tchar* holder; \tpoint c; \tfor(i=0;str[i]!=00;i++){ \t\tif(str[i]=='(') \t\t\tstart = i; \t\tif(str[i]==','||str[i]==')') \t\t{ \t\t\tend = i; \t\t\tlength = end - start; \t\t\tholder = (char*)malloc(length*sizeof(char)); \t\t\tfor(j=0;j point { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut start: i32 = 0; let mut end: i32 = 0; let mut length: i32 = 0; let mut holder: *mut i8 = 0 as *mut i8; let mut c: point = point { x: 0., y: 0. }; i = 0; while *str.offset(i as isize) as i32 != 0 { if *str.offset(i as isize) as i32 == '(' as i32 { start = i; } if *str.offset(i as isize) as i32 == ',' as i32 || *str.offset(i as isize) as i32 == ')' as i32 { end = i; length = end - start; holder = malloc((length as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i8; j = 0; while j < length - 1 { *holder.offset(j as isize) = *str.offset((start + j + 1i32) as isize); j += 1; j; } *holder.offset(j as isize) = 0; if *str.offset(i as isize) as i32 == ',' as i32 { start = i; c.x = atof(holder); } else { c.y = atof(holder); } } i += 1; i; } return c; } }" }, { "index": 464, "before": "point intersectionPoint(point a1,point a2,point b1,point b2){ \tpoint c; \tdouble slopeA = lineSlope(a1,a2), slopeB = lineSlope(b1,b2); \tif(slopeA==slopeB){ \t\tc.x = NAN; \t\tc.y = NAN; \t} \telse if(isnan(slopeA) && !isnan(slopeB)){ \t\tc.x = a1.x; \t\tc.y = (a1.x-b1.x)*slopeB + b1.y; \t} \telse if(isnan(slopeB) && !isnan(slopeA)){ \t\tc.x = b1.x; \t\tc.y = (b1.x-a1.x)*slopeA + a1.y; \t} \telse{ \t\tc.x = (slopeA*a1.x - slopeB*b1.x + b1.y - a1.y)/(slopeA - slopeB); \t\tc.y = slopeB*(c.x - b1.x) + b1.y; \t} \treturn c; }", "after": "pub extern \"C\" fn intersectionPoint( mut a1: point, mut a2: point, mut b1: point, mut b2: point, ) -> point { let mut c: point = point { x: 0., y: 0. }; let mut slopeA: f64 = lineSlope(a1, a2); let mut slopeB: f64 = lineSlope(b1, b2); if slopeA == slopeB { c.x = ::core::f32::NAN as f64; c.y = ::core::f32::NAN as f64; } else if slopeA.is_nan() as i32 != 0 && slopeB.is_nan() as i32 == 0 { c.x = a1.x; c.y = (a1.x - b1.x) * slopeB + b1.y; } else if slopeB.is_nan() as i32 != 0 && slopeA.is_nan() as i32 == 0 { c.x = b1.x; c.y = (b1.x - a1.x) * slopeA + a1.y; } else { c.x = (slopeA * a1.x - slopeB * b1.x + b1.y - a1.y) / (slopeA - slopeB); c.y = slopeB * (c.x - b1.x) + b1.y; } return c; }" }, { "index": 465, "before": "double lineSlope(point a,point b){ \tif(a.x-b.x == 0.0) \t\treturn NAN; \telse \t\treturn (a.y-b.y)/(a.x-b.x); }", "after": "pub extern \"C\" fn lineSlope(mut a: point, mut b: point) -> f64 { if a.x - b.x == 0.0f64 { return ::core::f32::NAN as f64; } else { return (a.y - b.y) / (a.x - b.x); }; }" }, { "index": 466, "before": "int main(int argC,char* argV[]) { \tpoint c; \tif(argC < 5) \t\tprintf(\"Usage : %s \",argV[0]); \telse{ \t\tc = intersectionPoint(extractPoint(argV[1]),extractPoint(argV[2]),extractPoint(argV[3]),extractPoint(argV[4])); \t\tif(isnan(c.x)) \t\t\tprintf(\"The lines do not intersect, they are either parallel or co-incident.\"); \t\telse \t\t\tprintf(\"Point of intersection : (%lf,%lf)\",c.x,c.y); \t} \treturn 0; }", "after": "fn main(mut argC: i32, mut argV: *mut *mut i8) -> i32 { unsafe { let mut c: point = point { x: 0., y: 0. }; if argC < 5 { print!( \"Usage : {} \", build_str_from_raw_ptr(*argV.offset(0 as isize) as *mut u8) ); } else { c = intersectionPoint( extractPoint(*argV.offset(1 as isize)), extractPoint(*argV.offset(2 as isize)), extractPoint(*argV.offset(3 as isize)), extractPoint(*argV.offset(4 as isize)), ); if (c.x).is_nan() as i32 != 0 { print!(\"The lines do not intersect, they are either parallel or co-incident.\"); } else { print!(\"Point of intersection : ({},{})\", c.x, c.y); } } return 0; } }" }, { "index": 467, "before": "int main() { \tmpz_t a; \tmpz_init_set_ui(a, 5); \tmpz_pow_ui(a, a, 1 << 18); /* 2**18 == 4**9 */ \tint len = mpz_sizeinbase(a, 10); \tprintf(\"GMP says size is: %d\\n\", len); \t/* because GMP may report size 1 too big; see doc */ \tchar *s = mpz_get_str(0, 10, a); \tprintf(\"size really is %d\\n\", len = strlen(s)); \tprintf(\"Digits: %.20s...%s\\n\", s, s + len - 20); \t// free(s); /* we could, but we won't. we are exiting anyway */ \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut len: i32 = 0; print!(\"GMP says size is: {}\\n\", len); let mut s: *mut i8 = 0 as *mut i8; len = strlen(s) as i32; print!(\"size really is {}\\n\", len); print!( \"Digits: {:.20}...{}\\n\", build_str_from_raw_ptr(s as *mut u8), build_str_from_raw_ptr(s.offset(len as isize).offset(-(20 as isize)) as *mut u8) ); return 0; } }" }, { "index": 468, "before": "int main() { puts(isatty(fileno(stdout)) ? \"stdout is tty\" : \"stdout is not tty\"); return 0; }", "after": "fn main() -> i32 { unsafe { puts(if isatty(fileno(stdout)) != 0 { b\"stdout is tty\\0\" as *const u8 as *const i8 } else { b\"stdout is not tty\\0\" as *const u8 as *const i8 }); } return 0; }" }, { "index": 469, "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": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { srand(rust_time(None) as u32); puts(DESCRIPTION.as_mut_ptr()); loop { puts(b\"\\n---- NEW GAME ----\\n\\0\" as *const u8 as *const i8); puts(b\"\\nThe running total is currently zero.\\n\\0\" as *const u8 as *const i8); total = 0; if rand() % 2 != 0 { puts(b\"The first move is AI move.\\n\\0\" as *const u8 as *const i8); ai(); } else { puts(b\"The first move is human move.\\n\\0\" as *const u8 as *const i8); } while total < 21 { human(); ai(); } } } }" }, { "index": 470, "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 extern \"C\" fn ai() -> i32 { unsafe { static mut precomputed: [i32; 31] = [ 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( b\"ai\\0\" as *const u8 as *const i8 as *mut i8, precomputed[total as usize], ); } panic!(\"Reached end of non-void function without returning\"); }" }, { "index": 471, "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 extern \"C\" fn human() { let mut buffer: [i8; 256] = [0; 256]; let mut move_0: i32 = 0; unsafe { loop { print!(\"enter your move to play (or enter 0 to exit game): \"); fgets(buffer.as_mut_ptr(), 256, stdin); if !(sscanf( buffer.as_mut_ptr(), b\"%d\\0\" as *const u8 as *const i8, &mut move_0 as *mut i32, ) != 1 || move_0 != 0 && (move_0 < 1 || move_0 > 3 || total + move_0 > 21)) { break; } puts(b\"\\nYour answer is not a valid choice.\\n\\0\" as *const u8 as *const i8); } } print!(\"{}\", '\\n' as i32); unsafe { if move_0 == 0 { exit(0); } } update(b\"human\\0\" as *const u8 as *const i8 as *mut i8, move_0); }" }, { "index": 472, "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 extern \"C\" fn update(mut player: *mut i8, mut move_0: i32) { unsafe { print!( \"{:8}: {} = {} + {}\\n\\n\", build_str_from_raw_ptr(player as *mut u8), total + move_0, total, move_0 ); total += move_0; if total == 21 { print!( \"The winner is {}.\\n\\n\", build_str_from_raw_ptr(player as *mut u8) ); } } }" }, { "index": 473, "before": "int fusc(int n) { if (n == 0 || n == 1) return n; else if (n % 2 == 0) return fusc(n / 2); else return fusc((n - 1) / 2) + fusc((n + 1) / 2); }", "after": "pub extern \"C\" fn fusc(mut n: i32) -> i32 { if n == 0 || n == 1 { return n; } else if n % 2 == 0 { return fusc(n / 2); } else { return fusc((n - 1) / 2) + fusc((n + 1) / 2); }; }" }, { "index": 474, "before": "int numLen(int n) { int sum = 1; while (n > 9) { n = n / 10; sum++; } return sum; }", "after": "pub extern \"C\" fn numLen(mut n: i32) -> i32 { let mut sum: i32 = 1; while n > 9 { n = n / 10; sum += 1; sum; } return sum; }" }, { "index": 475, "before": "void printLargeFuscs(int limit) { int i, f, len, maxLen = 1; printf(\"\\n\\nPrinting all largest Fusc numbers upto %d \\nIndex-------Value\", limit); for (i = 0; i <= limit; i++) { f = fusc(i); len = numLen(f); if (len > maxLen) { maxLen = len; printf(\"\\n%5d%12d\", i, f); } } }", "after": "pub extern \"C\" fn printLargeFuscs(mut limit: i32) { let mut i: i32 = 0; let mut f: i32 = 0; let mut len: i32 = 0; let mut maxLen: i32 = 1; print!( \"\\n\\nPrinting all largest Fusc numbers upto {} \\nIndex-------Value\", limit ); i = 0; while i <= limit { f = fusc(i); len = numLen(f); if len > maxLen { maxLen = len; print!(\"\\n{:5}{:12}\", i, f); } i += 1; i; } }" }, { "index": 476, "before": "int main() { int i; printf(\"Index-------Value\"); for (i = 0; i < 61; i++) printf(\"\\n%5d%12d\", i, fusc(i)); //printLargeFuscs(INT_MAX); return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; print!(\"Index-------Value\"); i = 0; while i < 61 { print!(\"\\n{:5}{:12}\", i, fusc(i)); i += 1; i; } return 0; }" }, { "index": 477, "before": "void sieve(int limit, int primes[], int *count) { bool *c = calloc(limit + 1, sizeof(bool)); /* composite = TRUE */ /* no need to process even numbers */ int i, p = 3, p2, n = 0; p2 = p * p; while (p2 <= limit) { for (i = p2; i <= limit; i += 2 * p) c[i] = TRUE; do { p += 2; } while (c[p]); p2 = p * p; } for (i = 3; i <= limit; i += 2) { if (!c[i]) primes[n++] = i; } *count = n; free(c); }", "after": "pub extern \"C\" fn sieve(mut limit: i32, mut primes: *mut i32, mut count: *mut i32) { unsafe { let mut c: *mut i32 = calloc((limit + 1i32) as u64, ::core::mem::size_of::() as u64) as *mut i32; let mut i: i32 = 0; let mut p: i32 = 3; let mut p2: i32 = 0; let mut n: i32 = 0; p2 = p * p; while p2 <= limit { i = p2; while i <= limit { *c.offset(i as isize) = 1; i += 2 * p; } loop { p += 2; if !(*c.offset(p as isize) != 0) { break; } } p2 = p * p; } i = 3; while i <= limit { if *c.offset(i as isize) == 0 { let fresh0 = n; n = n + 1; *primes.offset(fresh0 as isize) = i; } i += 2; } *count = n; free(c as *mut libc::c_void); } }" }, { "index": 478, "before": "int findPeriod(int n) { int i, r = 1, rr, period = 0; for (i = 1; i <= n + 1; ++i) { r = (10 * r) % n; } rr = r; do { r = (10 * r) % n; period++; } while (r != rr); return period; }", "after": "pub extern \"C\" fn findPeriod(mut n: i32) -> i32 { let mut i: i32 = 0; let mut r: i32 = 1; let mut rr: i32 = 0; let mut period: i32 = 0; i = 1; while i <= n + 1 { r = 10 * r % n; i += 1; i; } rr = r; loop { r = 10 * r % n; period += 1; period; if !(r != rr) { break; } } return period; }" }, { "index": 479, "before": "int main() { int i, prime, count = 0, index = 0, primeCount, longCount = 0, numberCount; int *primes, *longPrimes, *totals; int numbers[] = {500, 1000, 2000, 4000, 8000, 16000, 32000, 64000}; primes = calloc(6500, sizeof(int)); numberCount = sizeof(numbers) / sizeof(int); totals = calloc(numberCount, sizeof(int)); sieve(64000, primes, &primeCount); longPrimes = calloc(primeCount, sizeof(int)); /* Surely longCount < primeCount */ for (i = 0; i < primeCount; ++i) { prime = primes[i]; if (findPeriod(prime) == prime - 1) { longPrimes[longCount++] = prime; } } for (i = 0; i < longCount; ++i, ++count) { if (longPrimes[i] > numbers[index]) { totals[index++] = count; } } totals[numberCount - 1] = count; printf(\"The long primes up to %d are:\\n\", numbers[0]); printf(\"[\"); for (i = 0; i < totals[0]; ++i) { printf(\"%d \", longPrimes[i]); } printf(\"\\b]\\n\"); printf(\"\\nThe number of long primes up to:\\n\"); for (i = 0; i < 8; ++i) { printf(\" %5d is %d\\n\", numbers[i], totals[i]); } free(totals); free(longPrimes); free(primes); return 0; }", "after": "fn main() -> i32 { unsafe { let mut i: i32 = 0; let mut prime: i32 = 0; let mut count: i32 = 0; let mut index: i32 = 0; let mut primeCount: i32 = 0; let mut longCount: i32 = 0; let mut numberCount: i32 = 0; let mut primes: *mut i32 = 0 as *mut i32; let mut longPrimes: *mut i32 = 0 as *mut i32; let mut totals: *mut i32 = 0 as *mut i32; let mut numbers: [i32; 8] = [500, 1000, 2000, 4000, 8000, 16000, 32000, 64000]; primes = calloc(6500, ::core::mem::size_of::() as u64) as *mut i32; numberCount = (::core::mem::size_of::<[i32; 8]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32; totals = calloc(numberCount as u64, ::core::mem::size_of::() as u64) as *mut i32; sieve(64000, primes, &mut primeCount); longPrimes = calloc(primeCount as u64, ::core::mem::size_of::() as u64) as *mut i32; i = 0; while i < primeCount { prime = *primes.offset(i as isize); if findPeriod(prime) == prime - 1 { let fresh1 = longCount; longCount = longCount + 1; *longPrimes.offset(fresh1 as isize) = prime; } i += 1; i; } i = 0; while i < longCount { if *longPrimes.offset(i as isize) > numbers[index as usize] { let fresh2 = index; index = index + 1; *totals.offset(fresh2 as isize) = count; } i += 1; i; count += 1; count; } *totals.offset((numberCount - 1i32) as isize) = count; print!(\"The long primes up to {} are:\\n\", numbers[0 as usize]); print!(\"[\"); i = 0; while i < *totals.offset(0 as isize) { print!(\"{} \", *longPrimes.offset(i as isize)); i += 1; i; } print!(\"\\x08]\\n\"); print!(\"\\nThe number of long primes up to:\\n\"); i = 0; while i < 8 { print!( \" {:5} is {}\\n\", numbers[i as usize], *totals.offset(i as isize) ); i += 1; i; } free(totals as *mut libc::c_void); free(longPrimes as *mut libc::c_void); free(primes as *mut libc::c_void); return 0; } }" }, { "index": 480, "before": "int check_reg(const char *path) { \tstruct stat sb; \treturn stat(path, &sb) == 0 && S_ISREG(sb.st_mode); }", "after": "pub extern \"C\" fn check_reg(mut path: *const i8) -> i32 { unsafe { let mut sb: stat = stat { st_dev: 0, st_ino: 0, st_nlink: 0, st_mode: 0, st_uid: 0, st_gid: 0, __pad0: 0, st_rdev: 0, st_size: 0, st_blksize: 0, st_blocks: 0, st_atim: timespec { tv_sec: 0, tv_nsec: 0, }, st_mtim: timespec { tv_sec: 0, tv_nsec: 0, }, st_ctim: timespec { tv_sec: 0, tv_nsec: 0, }, __glibc_reserved: [0; 3], }; return (stat(path, &mut sb) == 0 && sb.st_mode & 0o170000 == 0o100000u32) as i32; } }" }, { "index": 481, "before": "int main() { \tprintf(\"input.txt is a regular file? %s\\n\", \t check_reg(\"input.txt\") ? \"yes\" : \"no\"); \tprintf(\"docs is a directory? %s\\n\", \t check_dir(\"docs\") ? \"yes\" : \"no\"); \tprintf(\"/input.txt is a regular file? %s\\n\", \t check_reg(\"/input.txt\") ? \"yes\" : \"no\"); \tprintf(\"/docs is a directory? %s\\n\", \t check_dir(\"/docs\") ? \"yes\" : \"no\"); \treturn 0; }", "after": "fn main() -> i32 { if check_reg(b\"input.txt\\0\" as *const u8 as *const i8) != 0 { print!(\"input.txt is a regular file? {}\\n\", \"yes\\0\") } else { print!(\"input.txt is a regular file? {}\\n\", \"no\\0\") }; if check_dir(b\"docs\\0\" as *const u8 as *const i8) != 0 { print!(\"docs is a directory? {}\\n\", \"yes\\0\") } else { print!(\"docs is a directory? {}\\n\", \"no\\0\") }; if check_reg(b\"/input.txt\\0\" as *const u8 as *const i8) != 0 { print!(\"/input.txt is a regular file? {}\\n\", \"yes\\0\") } else { print!(\"/input.txt is a regular file? {}\\n\", \"no\\0\") }; if check_dir(b\"/docs\\0\" as *const u8 as *const i8) != 0 { print!(\"/docs is a directory? {}\\n\", \"yes\\0\") } else { print!(\"/docs is a directory? {}\\n\", \"no\\0\") }; return 0; }" }, { "index": 482, "before": "int check_dir(const char *path) { \tstruct stat sb; \treturn stat(path, &sb) == 0 && S_ISDIR(sb.st_mode); }", "after": "pub extern \"C\" fn check_dir(mut path: *const i8) -> i32 { unsafe { let mut sb: stat = stat { st_dev: 0, st_ino: 0, st_nlink: 0, st_mode: 0, st_uid: 0, st_gid: 0, __pad0: 0, st_rdev: 0, st_size: 0, st_blksize: 0, st_blocks: 0, st_atim: timespec { tv_sec: 0, tv_nsec: 0, }, st_mtim: timespec { tv_sec: 0, tv_nsec: 0, }, st_ctim: timespec { tv_sec: 0, tv_nsec: 0, }, __glibc_reserved: [0; 3], }; return (stat(path, &mut sb) == 0 && sb.st_mode & 0o170000 == 0o40000u32) as i32; } }" }, { "index": 483, "before": "int luhn(const char* cc) { \tconst int m[] = {0,2,4,6,8,1,3,5,7,9}; // mapping for rule 3 \tint i, odd = 1, sum = 0; \tfor (i = strlen(cc); i--; odd = !odd) { \t\tint digit = cc[i] - '0'; \t\tsum += odd ? digit : m[digit]; \t} \treturn sum % 10 == 0; }", "after": "pub extern \"C\" fn luhn(mut cc: *const i8) -> i32 { unsafe { let m: [i32; 10] = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]; let mut i: i32 = 0; let mut odd: i32 = 1; let mut sum: i32 = 0; i = strlen(cc) as i32; loop { let fresh0 = i; i = i - 1; if !(fresh0 != 0) { break; } let mut digit: i32 = *cc.offset(i as isize) as i32 - '0' as i32; sum += if odd != 0 { digit } else { m[digit as usize] }; odd = (odd == 0) as i32; } return (sum % 10 == 0i32) as i32; } }" }, { "index": 484, "before": "int main() { \tconst char* cc[] = { \t\t\"49927398716\", \t\t\"49927398717\", \t\t\"1234567812345678\", \t\t\"1234567812345670\", \t\t0 \t}; \tint i; \tfor (i = 0; cc[i]; i++) \t\tprintf(\"%16s\\t%s\\n\", cc[i], luhn(cc[i]) ? \"ok\" : \"not ok\"); \treturn 0; }", "after": "fn main() -> i32 { let mut cc: [*const i8; 5] = [ b\"49927398716\\0\" as *const u8 as *const i8, b\"49927398717\\0\" as *const u8 as *const i8, b\"1234567812345678\\0\" as *const u8 as *const i8, b\"1234567812345670\\0\" as *const u8 as *const i8, 0 as *const i8, ]; let mut i: i32 = 0; i = 0; unsafe { while !(cc[i as usize]).is_null() { if luhn(cc[i as usize]) != 0 { print!( \"{:16}\t{}\\n\", build_str_from_raw_ptr(cc[i as usize] as *mut u8), \"ok\\0\" ) } else { print!( \"{:16}\t{}\\n\", build_str_from_raw_ptr(cc[i as usize] as *mut u8), \"not ok\\0\" ) }; i += 1; i; } } return 0; }" }, { "index": 485, "before": "void append(node *root, node *elem) { if (root == NULL) { fprintf(stderr, \"Cannot append to uninitialized node.\"); exit(1); } if (elem == NULL) { return; } if (root->tag == NODE_SEQ || root->tag == NODE_TREE) { if (root->data.root == NULL) { root->data.root = elem; } else { node *it = root->data.root; while (it->next != NULL) { it = it->next; } it->next = elem; } } else { fprintf(stderr, \"Cannot append to node with tag: %d\\n\", root->tag); exit(1); } }", "after": "pub extern \"C\" fn append(mut root: *mut node, mut elem: *mut node) { unsafe { if root.is_null() { fprintf( stderr, b\"Cannot append to uninitialized node.\\0\" as *const u8 as *const i8, ); exit(1); } if elem.is_null() { return; } if (*root).tag as u32 == NODE_SEQ as u32 || (*root).tag as u32 == NODE_TREE as u32 { if ((*root).data.root).is_null() { (*root).data.root = elem; } else { let mut it: *mut node = (*root).data.root; while !((*it).next).is_null() { it = (*it).next; } (*it).next = elem; } } else { fprintf( stderr, b\"Cannot append to node with tag: %d\\n\\0\" as *const u8 as *const i8, (*root).tag as u32, ); exit(1); }; } }" }, { "index": 486, "before": "void expand(node *n, size_t pos) { if (n == NULL) { return; } if (n->tag == NODE_LEAF) { printf(n->data.str); } else if (n->tag == NODE_TREE) { node *it = n->data.root; while (true) { size_t cnt = count(it); if (pos < cnt) { expand(it, pos); break; } pos -= cnt; it = it->next; } } else if (n->tag == NODE_SEQ) { size_t prod = pos; node *it = n->data.root; while (it != NULL) { size_t cnt = count(it); size_t rem = prod % cnt; expand(it, rem); it = it->next; } } else { fprintf(stderr, \"Cannot expand node with tag: %d\\n\", n->tag); exit(1); } }", "after": "pub extern \"C\" fn expand(mut n: *mut node, mut pos: u64) { unsafe { if n.is_null() { return; } if (*n).tag as u32 == NODE_LEAF as u32 { printf((*n).data.str_0 as *const i8); } else if (*n).tag as u32 == NODE_TREE as u32 { let mut it: *mut node = (*n).data.root; loop { let mut cnt: u64 = count(it); if pos < cnt { expand(it, pos); break; } else { pos = (pos as u64).wrapping_sub(cnt) as u64; it = (*it).next; } } } else if (*n).tag as u32 == NODE_SEQ as u32 { let mut prod: u64 = pos; let mut it_0: *mut node = (*n).data.root; while !it_0.is_null() { let mut cnt_0: u64 = count(it_0); let mut rem: u64 = prod.wrapping_rem(cnt_0); expand(it_0, rem); it_0 = (*it_0).next; } } else { fprintf( stderr, b\"Cannot expand node with tag: %d\\n\\0\" as *const u8 as *const i8, (*n).tag as u32, ); exit(1); }; } }" }, { "index": 487, "before": "string allocate_string(string src) { size_t len = strlen(src); string out = calloc(len + 1, sizeof(character)); if (out == NULL) { fprintf(stderr, \"Failed to allocate a copy of the string.\"); exit(1); } strcpy(out, src); return out; }", "after": "pub extern \"C\" fn allocate_string(mut src: string) -> string { unsafe { let mut len: u64 = strlen(src as *const i8); let mut out: string = calloc(len.wrapping_add(1), ::core::mem::size_of::() as u64) as string; if out.is_null() { fprintf( stderr, b\"Failed to allocate a copy of the string.\\0\" as *const u8 as *const i8, ); exit(1); } strcpy(out as *mut i8, src as *const i8); return out; } }" }, { "index": 488, "before": "void deallocate_node(node *n) { if (n == NULL) { return; } deallocate_node(n->next); n->next = NULL; if (n->tag == NODE_LEAF) { free(n->data.str); n->data.str = NULL; } else if (n->tag == NODE_TREE || n->tag == NODE_SEQ) { deallocate_node(n->data.root); n->data.root = NULL; } else { fprintf(stderr, \"Cannot deallocate node with tag: %d\\n\", n->tag); exit(1); } free(n); }", "after": "pub extern \"C\" fn deallocate_node(mut n: *mut node) { unsafe { if n.is_null() { return; } deallocate_node((*n).next); (*n).next = 0 as *mut node; if (*n).tag as u32 == NODE_LEAF as u32 { free((*n).data.str_0 as *mut libc::c_void); (*n).data.str_0 = 0 as string; } else if (*n).tag as u32 == NODE_TREE as u32 || (*n).tag as u32 == NODE_SEQ as u32 { deallocate_node((*n).data.root); (*n).data.root = 0 as *mut node; } else { fprintf( stderr, b\"Cannot deallocate node with tag: %d\\n\\0\" as *const u8 as *const i8, (*n).tag as u32, ); exit(1); } free(n as *mut libc::c_void); } }" }, { "index": 489, "before": "size_t count(node *n) { if (n == NULL) { return 0; } if (n->tag == NODE_LEAF) { return 1; } if (n->tag == NODE_TREE) { size_t sum = 0; node *it = n->data.root; while (it != NULL) { sum += count(it); it = it->next; } return sum; } if (n->tag == NODE_SEQ) { size_t prod = 1; node *it = n->data.root; while (it != NULL) { prod *= count(it); it = it->next; } return prod; } fprintf(stderr, \"Cannot count node with tag: %d\\n\", n->tag); exit(1); }", "after": "pub extern \"C\" fn count(mut n: *mut node) -> u64 { unsafe { if n.is_null() { return 0; } if (*n).tag as u32 == NODE_LEAF as u32 { return 1; } if (*n).tag as u32 == NODE_TREE as u32 { let mut sum: u64 = 0; let mut it: *mut node = (*n).data.root; while !it.is_null() { sum = (sum).wrapping_add(count(it)) as u64; it = (*it).next; } return sum; } if (*n).tag as u32 == NODE_SEQ as u32 { let mut prod: u64 = 1; let mut it_0: *mut node = (*n).data.root; while !it_0.is_null() { prod = (prod).wrapping_mul(count(it_0)) as u64; it_0 = (*it_0).next; } return prod; } fprintf( stderr, b\"Cannot count node with tag: %d\\n\\0\" as *const u8 as *const i8, (*n).tag as u32, ); exit(1); } }" }, { "index": 490, "before": "int main() { test(\"~/{Downloads,Pictures}/*.{jpg,gif,png}\"); test(\"It{{em,alic}iz,erat}e{d,}, please.\"); test(\"{,{,gotta have{ ,\\\\, again\\\\, }}more }cowbell!\"); //not sure how to parse this one //test(\"{}} some }{,{\\\\{ edge, edge} \\,}{ cases, {here} \\\\\\\\\\}\"); return 0; }", "after": "fn main() -> i32 { test(b\"~/{Downloads,Pictures}/*.{jpg,gif,png}\\0\" as *const u8 as *const i8 as string); test(b\"It{{em,alic}iz,erat}e{d,}, please.\\0\" as *const u8 as *const i8 as string); test(b\"{,{,gotta have{ ,\\\\, again\\\\, }}more }cowbell!\\0\" as *const u8 as *const i8 as string); return 0; }" }, { "index": 491, "before": "void test(string input) { size_t pos = 0; node *n = parse_seq(input, &pos); size_t cnt = count(n); size_t i; printf(\"Pattern: %s\\n\", input); for (i = 0; i < cnt; i++) { expand(n, i); printf(\"\\n\"); } printf(\"\\n\"); deallocate_node(n); }", "after": "pub extern \"C\" fn test(mut input: string) { unsafe { let mut pos: u64 = 0; let mut n: *mut node = parse_seq(input, &mut pos); let mut cnt: u64 = count(n); let mut i: u64 = 0; print!(\"Pattern: {}\\n\", build_str_from_raw_ptr(input as *mut u8)); i = 0; while i < cnt { expand(n, i); print!(\"\\n\"); i = i.wrapping_add(1); i; } print!(\"\\n\"); deallocate_node(n); } }" }, { "index": 492, "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": "fn main(mut ac: i32, mut av: *mut *mut i8) -> i32 { unsafe { let mut sin: [i8; 73] = [0; 73]; let mut sout: [i8; 100000] = [0; 100000]; let mut dit: i32 = 100; if 1 < ac { if strlen(*av.offset(1 as isize)) != strspn( *av.offset(1 as isize), b\"0123456789\\0\" as *const u8 as *const i8, ) { return 0 * fprintf( stderr, b\"use: %s [duration] dit in ms, default %d\\n\\0\" as *const u8 as *const i8, *av, dit, ); } dit = if 1 < atoi(*av.offset(1 as isize)) { if atoi(*av.offset(1 as isize)) < 1000 { atoi(*av.offset(1 as isize)) } else { 1000 } } else { 1 }; } sprintf( dah.as_mut_ptr(), b\" -n -f 440 -l %d -D %d\\0\" as *const u8 as *const i8, 3 * dit, dit, ); sprintf( dih.as_mut_ptr(), b\" -n -f 440 -l %d -D %d\\0\" as *const u8 as *const i8, dit, dit, ); sprintf( medium.as_mut_ptr(), b\" -n -D %d\\0\" as *const u8 as *const i8, (3 - 1) * dit, ); sprintf( word.as_mut_ptr(), b\" -n -D %d\\0\" as *const u8 as *const i8, (7 - (3 - 1) - 1) * dit, ); while !(fgets(sin.as_mut_ptr(), 72, stdin)).is_null() { puts(translate(sin.as_mut_ptr(), sout.as_mut_ptr())); } return 0; } }" }, { "index": 493, "before": "void append(char*s,const char*morse) { for (; *morse; ++morse) strcat(s,dd['3'==*morse]); strcat(s,medium); }", "after": "pub extern \"C\" fn append(mut s: *mut i8, mut morse: *const i8) { unsafe { while *morse != 0 { strcat(s, dd[('3' as i32 == *morse as i32) as i32 as usize]); morse = morse.offset(1); morse; } strcat(s, medium.as_mut_ptr()); } }" }, { "index": 494, "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": "fn main() -> i32 { let mut i: i32 = 1; while i <= 10 { print!(\"{}: \", i); proper_divisors(i, 1 != 0); i += 1; i; } let mut max: i32 = 0; let mut max_i: i32 = 1; let mut i_0: i32 = 1; while i_0 <= 20000 { let mut v: i32 = countProperDivisors(i_0); if v >= max { max = v; max_i = i_0; } i_0 += 1; i_0; } print!(\"{} with {} divisors\\n\", max_i, max); return 0; }" }, { "index": 495, "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 extern \"C\" fn countProperDivisors(mut n: i32) -> i32 { let mut prod: i32 = 1; let mut i: i32 = 0; let mut count: i32 = 0; while n % 2 == 0 { count += 1; count; n /= 2; } prod *= 1 + count; i = 3; while i * i <= n { count = 0; while n % i == 0 { count += 1; count; n /= i; } prod *= 1 + count; i += 2; } if n > 2 { prod *= 2; } return prod - 1; }" }, { "index": 496, "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 extern \"C\" fn proper_divisors(n: i32, mut print_flag: bool) -> i32 { let mut count: i32 = 0; let mut i: i32 = 1; while i < n { if n % i == 0 { count += 1; count; if print_flag { print!(\"{} \", i); } } i += 1; i; } if print_flag { print!(\"\\n\"); } return count; }" }, { "index": 497, "before": "void processFile(char* name){ \tint i,records; \tdouble diff,b1,b2; \tFILE* fp = fopen(name,\"r\"); \tfscanf(fp,\"%d\\n\",&records); \tfor(i=0;i=180)?diff-360:diff));\t \t} \tfclose(fp); }", "after": "pub extern \"C\" fn processFile(mut name: *mut i8) { unsafe { let mut i: i32 = 0; let mut records: i32 = 0; let mut diff: f64 = 0.; let mut b1: f64 = 0.; let mut b2: f64 = 0.; let mut fp: *mut FILE = fopen(name, b\"r\\0\" as *const u8 as *const i8); fscanf( fp, b\"%d\\n\\0\" as *const u8 as *const i8, &mut records as *mut i32, ); i = 0; while i < records { fscanf( fp, b\"%lf%lf\\0\" as *const u8 as *const i8, &mut b1 as *mut f64, &mut b2 as *mut f64, ); diff = fmod(b2 - b1, 360.0f64); if diff < -180i32 as f64 { print!( \"\\nDifference between b2({}) and b1({}) is {}\", b2, b1, diff + 360 as f64 ) } else { if diff >= 180 as f64 { print!( \"\\nDifference between b2({}) and b1({}) is {}\", b2, b1, diff - 360 as f64 ) } else { print!(\"\\nDifference between b2({}) and b1({}) is {}\", b2, b1, diff) } }; i += 1; i; } fclose(fp); } }" }, { "index": 498, "before": "int main(int argC,char* argV[]) { \tdouble diff; \tif(argC < 2) \t\tprintf(\"Usage : %s \",argV[0]); \telse if(argC == 2) \t\tprocessFile(argV[1]); \telse{ \t\tdiff = fmod(atof(argV[2])-atof(argV[1]),360.0); \t\tprintf(\"Difference between b2(%s) and b1(%s) is %lf\",argV[2],argV[1],(diff<-180)?diff+360:((diff>=180)?diff-360:diff)); \t} \treturn 0; }", "after": "fn main(mut argC: i32, mut argV: *mut *mut i8) -> i32 { unsafe { let mut diff: f64 = 0.; if argC < 2 { print! (\"Usage : {} \", build_str_from_raw_ptr (* argV.offset (0 as isize) as * mut u8)); } else if argC == 2 { processFile(*argV.offset(1 as isize)); } else { diff = fmod( atof(*argV.offset(2 as isize)) - atof(*argV.offset(1 as isize)), 360.0f64, ); if diff < -180i32 as f64 { print!( \"Difference between b2({}) and b1({}) is {}\", build_str_from_raw_ptr(*argV.offset(2 as isize) as *mut u8), build_str_from_raw_ptr(*argV.offset(1 as isize) as *mut u8), diff + 360 as f64 ) } else { if diff >= 180 as f64 { print!( \"Difference between b2({}) and b1({}) is {}\", build_str_from_raw_ptr(*argV.offset(2 as isize) as *mut u8), build_str_from_raw_ptr(*argV.offset(1 as isize) as *mut u8), diff - 360 as f64 ) } else { print!( \"Difference between b2({}) and b1({}) is {}\", build_str_from_raw_ptr(*argV.offset(2 as isize) as *mut u8), build_str_from_raw_ptr(*argV.offset(1 as isize) as *mut u8), diff ) } }; } return 0; } }" }, { "index": 499, "before": "fr_int_t gcd(fr_int_t m, fr_int_t n) { \tfr_int_t t; \twhile (n) { t = n; n = m % n; m = t; } \treturn m; }", "after": "pub extern \"C\" fn gcd(mut m: i64, mut n: i64) -> i64 { let mut t: i64 = 0; while n != 0 { t = n; n = m % n; m = t; } return m; }" }, { "index": 500, "before": "int frtoi(frac a) { return a.den / a.num; }", "after": "pub extern \"C\" fn frtoi(mut a: frac) -> i32 { return (a.den / a.num) as i32; }" }, { "index": 501, "before": "double frtod(frac a) { return (double)a.den / a.num; }", "after": "pub extern \"C\" fn frtod(mut a: frac) -> f64 { return a.den as f64 / a.num as f64; }" }, { "index": 502, "before": "int main() { \tint n, k; \tfrac sum, kf; \tfor (n = 2; n < 1<<19; n++) { \t\tsum = frac_new(1, n); \t\tfor (k = 2; k * k < n; k++) { \t\t\tif (n % k) continue; \t\t\tkf = frac_new(1, k); \t\t\tsum = frac_add(sum, kf); \t\t\tkf = frac_new(1, n / k); \t\t\tsum = frac_add(sum, kf); \t\t} \t\tif (frac_cmp_int(sum, 1) == 0) printf(\"%d\\n\", n); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut n: i32 = 0; let mut k: i32 = 0; let mut sum: frac = frac { num: 0, den: 0 }; let mut kf: frac = frac { num: 0, den: 0 }; n = 2; while n < 1 << 19 { sum = frac_new(1, n as i64); k = 2; while k * k < n { if !(n % k != 0) { kf = frac_new(1, k as i64); sum = frac_add(sum, kf); kf = frac_new(1, (n / k) as i64); sum = frac_add(sum, kf); } k += 1; k; } if frac_cmp(sum, frac_new(1, 1)) == 0 { print!(\"{}\\n\", n); } n += 1; n; } return 0; }" }, { "index": 503, "before": "frac frac_new(fr_int_t num, fr_int_t den) { \tfrac a; \tif (!den) { \t\tprintf(\"divide by zero: \"FMT\"/\"FMT\"\\n\", num, den); \t\tabort(); \t} \tint g = gcd(num, den); \tif (g)\t{ num /= g; den /= g; } \telse\t{ num = 0; den = 1; } \tif (den < 0) { \t\tden = -den; \t\tnum = -num; \t} \ta.num = num; a.den = den; \treturn a; }", "after": "pub extern \"C\" fn frac_new(mut num: i64, mut den: i64) -> frac { let mut a: frac = frac { num: 0, den: 0 }; unsafe { if den == 0 { print!(\"divide by zero: {}/{}\\n\", num, den); abort(); } } let mut g: i32 = gcd(num, den) as i32; if g != 0 { num /= g as i64; den /= g as i64; } else { num = 0; den = 1; } if den < 0 { den = -den; num = -num; } a.num = num; a.den = den; return a; }" }, { "index": 504, "before": "int frac_cmp(frac a, frac b) { \tint l = a.num * b.den, r = a.den * b.num; \treturn l < r ? -1 : l > r; }", "after": "pub extern \"C\" fn frac_cmp(mut a: frac, mut b: frac) -> i32 { let mut l: i32 = (a.num * b.den) as i32; let mut r: i32 = (a.den * b.num) as i32; return if l < r { -1 } else { (l > r) as i32 }; }" }, { "index": 505, "before": "int day_of_year( int y, int m, int d ){ int month_lengths[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; for( ; m > 1; m -- ){ d += month_lengths[ m - 2 ]; if( m == 3 && leap_year( y ) ){ ++ d; } } return d; }", "after": "pub extern \"C\" fn day_of_year(mut y: i32, mut m: i32, mut d: i32) -> i32 { let mut month_lengths: [i32; 12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; while m > 1 { d += month_lengths[(m - 2i32) as usize]; if m == 3 && (y % 400 == 0 || y % 4 == 0 && y % 100 != 0) { d += 1; d; } m -= 1; m; } return d; }" }, { "index": 506, "before": "int main( int argc, char * argv[] ){ time_t now; struct tm * now_time; int year, doy; if( argc == 1 ){ now = time( NULL ); now_time = localtime( &now ); year = now_time->tm_year + 1900; doy = now_time->tm_yday + 1; } else if( argc == 4 ){ year = atoi( argv[ 1 ] ); doy = day_of_year( atoi( argv[ 1 ] ), atoi( argv[ 2 ] ), atoi( argv[ 3 ] ) ); } char * result = ddate( year, doy ); puts( result ); free( result ); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut now: i64 = 0; let mut now_time: *mut tm = 0 as *mut tm; let mut year: i32 = 0; let mut doy: i32 = 0; if argc == 1 { now = rust_time(None); now_time = localtime(&mut now); year = (*now_time).tm_year + 1900; doy = (*now_time).tm_yday + 1; } else if argc == 4 { year = atoi(*argv.offset(1 as isize)); doy = day_of_year( atoi(*argv.offset(1 as isize)), atoi(*argv.offset(2 as isize)), atoi(*argv.offset(3 as isize)), ); } let mut result: *mut i8 = ddate(year, doy); puts(result); free(result as *mut libc::c_void); return 0; } }" }, { "index": 507, "before": "int main(void) { \tconst char *items[] = {\"fee fie\", \"huff and puff\", \"mirror mirror\", \"tick tock\", NULL}; \tconst char *prompt = \"Which is from the three pigs?\"; \tprintf(\"You chose %s.\\n\", menu_select(items, prompt)); \treturn EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { let mut items: [*const i8; 5] = [ b\"fee fie\\0\" as *const u8 as *const i8, b\"huff and puff\\0\" as *const u8 as *const i8, b\"mirror mirror\\0\" as *const u8 as *const i8, b\"tick tock\\0\" as *const u8 as *const i8, 0 as *const i8, ]; let mut prompt: *const i8 = b\"Which is from the three pigs?\\0\" as *const u8 as *const i8; print!( \"You chose {}.\\n\", build_str_from_raw_ptr(menu_select(items.as_mut_ptr(), prompt) as *mut u8) ); return 0; } }" }, { "index": 508, "before": "SquareMatrix copy_square_matrix(SquareMatrix src) { SquareMatrix dest; dest.n = src.n; dest.elems = malloc(dest.n * sizeof(double *)); for(int i = 0; i < dest.n; ++i) { dest.elems[i] = malloc(dest.n * sizeof(double)); for(int j = 0; j < dest.n; ++j) dest.elems[i][j] = src.elems[i][j]; } return dest; }", "after": "pub extern \"C\" fn copy_square_matrix(mut src: SquareMatrix) -> SquareMatrix { let mut dest: SquareMatrix = SquareMatrix { n: 0, elems: 0 as *mut *mut f64, }; dest.n = src.n; unsafe { dest.elems = malloc((dest.n as u64).wrapping_mul(::core::mem::size_of::<*mut f64>() as u64)) as *mut *mut f64; } let mut i: i32 = 0; unsafe { while i < dest.n { let ref mut fresh1 = *(dest.elems).offset(i as isize); *fresh1 = malloc((dest.n as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut f64; let mut j: i32 = 0; while j < dest.n { *(*(dest.elems).offset(i as isize)).offset(j as isize) = *(*(src.elems).offset(i as isize)).offset(j as isize); j += 1; j; } i += 1; i; } } return dest; }" }, { "index": 509, "before": "SquareMatrix init_square_matrix(int n, double elems[n][n]) { SquareMatrix A = { .n = n, .elems = malloc(n * sizeof(double *)) }; for(int i = 0; i < n; ++i) { A.elems[i] = malloc(n * sizeof(double)); for(int j = 0; j < n; ++j) A.elems[i][j] = elems[i][j]; } return A; }", "after": "pub extern \"C\" fn init_square_matrix(mut n: i32, mut elems: *mut f64) -> SquareMatrix { unsafe { let vla = n as usize; let mut A: SquareMatrix = { let mut init = SquareMatrix { n: n, elems: malloc((n as u64).wrapping_mul(::core::mem::size_of::<*mut f64>() as u64)) as *mut *mut f64, }; init }; let mut i: i32 = 0; while i < n { let ref mut fresh0 = *(A.elems).offset(i as isize); *fresh0 = malloc((n as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut f64; let mut j: i32 = 0; while j < n { *(*(A.elems).offset(i as isize)).offset(j as isize) = *elems.offset(i as isize * vla as isize).offset(j as isize); j += 1; j; } i += 1; i; } return A; } }" }, { "index": 510, "before": "void deinit_square_matrix(SquareMatrix A) { for(int i = 0; i < A.n; ++i) free(A.elems[i]); free(A.elems); }", "after": "pub extern \"C\" fn deinit_square_matrix(mut A: SquareMatrix) { let mut i: i32 = 0; unsafe { while i < A.n { free(*(A.elems).offset(i as isize) as *mut libc::c_void); i += 1; i; } free(A.elems as *mut libc::c_void); } }" }, { "index": 511, "before": "double det(SquareMatrix A) { double det = 1; for(int j = 0; j < A.n; ++j) { int i_max = j; for(int i = j; i < A.n; ++i) if(A.elems[i][j] > A.elems[i_max][j]) i_max = i; if(i_max != j) { for(int k = 0; k < A.n; ++k) { double tmp = A.elems[i_max][k]; A.elems[i_max][k] = A.elems[j][k]; A.elems[j][k] = tmp; } det *= -1; } if(abs(A.elems[j][j]) < 1e-12) { puts(\"Singular matrix!\"); return NAN; } for(int i = j + 1; i < A.n; ++i) { double mult = -A.elems[i][j] / A.elems[j][j]; for(int k = 0; k < A.n; ++k) A.elems[i][k] += mult * A.elems[j][k]; } } for(int i = 0; i < A.n; ++i) det *= A.elems[i][i]; return det; }", "after": "pub extern \"C\" fn det(mut A: SquareMatrix) -> f64 { let mut det_0: f64 = 1 as f64; let mut j: i32 = 0; unsafe { while j < A.n { let mut i_max: i32 = j; let mut i: i32 = j; while i < A.n { if *(*(A.elems).offset(i as isize)).offset(j as isize) > *(*(A.elems).offset(i_max as isize)).offset(j as isize) { i_max = i; } i += 1; i; } if i_max != j { let mut k: i32 = 0; while k < A.n { let mut tmp: f64 = *(*(A.elems).offset(i_max as isize)).offset(k as isize); *(*(A.elems).offset(i_max as isize)).offset(k as isize) = *(*(A.elems).offset(j as isize)).offset(k as isize); *(*(A.elems).offset(j as isize)).offset(k as isize) = tmp; k += 1; k; } det_0 *= -1i32 as f64; } if (abs(*(*(A.elems).offset(j as isize)).offset(j as isize) as i32) as f64) < 1e-12f64 { puts(b\"Singular matrix!\\0\" as *const u8 as *const i8); return ::core::f32::NAN as f64; } let mut i_0: i32 = j + 1; while i_0 < A.n { let mut mult: f64 = -*(*(A.elems).offset(i_0 as isize)).offset(j as isize) / *(*(A.elems).offset(j as isize)).offset(j as isize); let mut k_0: i32 = 0; while k_0 < A.n { *(*(A.elems).offset(i_0 as isize)).offset(k_0 as isize) += mult * *(*(A.elems).offset(j as isize)).offset(k_0 as isize); k_0 += 1; k_0; } i_0 += 1; i_0; } j += 1; j; } } let mut i_1: i32 = 0; unsafe { while i_1 < A.n { det_0 *= *(*(A.elems).offset(i_1 as isize)).offset(i_1 as isize); i_1 += 1; i_1; } } return det_0; }" }, { "index": 512, "before": "double cramer_solve(SquareMatrix A, double det_A, double *b, int var) { SquareMatrix tmp = copy_square_matrix(A); for(int i = 0; i < tmp.n; ++i) tmp.elems[i][var] = b[i]; double det_tmp = det(tmp); deinit_square_matrix(tmp); return det_tmp / det_A; }", "after": "pub extern \"C\" fn cramer_solve( mut A: SquareMatrix, mut det_A: f64, mut b: *mut f64, mut var: i32, ) -> f64 { unsafe { let mut tmp: SquareMatrix = copy_square_matrix(A); let mut i: i32 = 0; while i < tmp.n { *(*(tmp.elems).offset(i as isize)).offset(var as isize) = *b.offset(i as isize); i += 1; i; } let mut det_tmp: f64 = det(tmp); deinit_square_matrix(tmp); return det_tmp / det_A; } }" }, { "index": 513, "before": "int main(int argc, char **argv) { #define N 4 double elems[N][N] = { { 2, -1, 5, 1}, { 3, 2, 2, -6}, { 1, 3, 3, -1}, { 5, -2, -3, 3} }; SquareMatrix A = init_square_matrix(N, elems); SquareMatrix tmp = copy_square_matrix(A); int det_A = det(tmp); deinit_square_matrix(tmp); double b[] = {-3, -32, -47, 49}; for(int i = 0; i < N; ++i) printf(\"%7.3lf\\n\", cramer_solve(A, det_A, b, i)); deinit_square_matrix(A); return EXIT_SUCCESS; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut elems: [[f64; 4]; 4] = [ [2 as f64, -1i32 as f64, 5 as f64, 1 as f64], [3 as f64, 2 as f64, 2 as f64, -6i32 as f64], [1 as f64, 3 as f64, 3 as f64, -1i32 as f64], [5 as f64, -2i32 as f64, -3i32 as f64, 3 as f64], ]; let mut A: SquareMatrix = init_square_matrix(4, elems.as_mut_ptr() as *mut f64); let mut tmp: SquareMatrix = copy_square_matrix(A); let mut det_A: i32 = det(tmp) as i32; deinit_square_matrix(tmp); let mut b: [f64; 4] = [-3i32 as f64, -32i32 as f64, -47i32 as f64, 49 as f64]; let mut i: i32 = 0; while i < 4 { print!(\"{:7.3}\\n\", cramer_solve(A, det_A as f64, b.as_mut_ptr(), i)); i += 1; i; } deinit_square_matrix(A); return 0; } }" }, { "index": 514, "before": "int main(void) { char buf[MAX_BUF]; time_t seconds = time(NULL); struct tm *now = localtime(&seconds); const char *months[] = {\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"}; const char *days[] = {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"}; (void) printf(\"%d-%d-%d\\n\", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday); (void) printf(\"%s, %s %d, %d\\n\",days[now->tm_wday], months[now->tm_mon], now->tm_mday, now->tm_year + 1900); /* using the strftime (the result depends on the locale) */ (void) strftime(buf, MAX_BUF, \"%A, %B %e, %Y\", now); (void) printf(\"%s\\n\", buf); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { let mut buf: [i8; 50] = [0; 50]; let mut seconds: i64 = rust_time(None); let mut now: *mut tm = localtime(&mut seconds); let mut months: [*const i8; 12] = [ b\"January\\0\" as *const u8 as *const i8, b\"February\\0\" as *const u8 as *const i8, b\"March\\0\" as *const u8 as *const i8, b\"April\\0\" as *const u8 as *const i8, b\"May\\0\" as *const u8 as *const i8, b\"June\\0\" as *const u8 as *const i8, b\"July\\0\" as *const u8 as *const i8, b\"August\\0\" as *const u8 as *const i8, b\"September\\0\" as *const u8 as *const i8, b\"October\\0\" as *const u8 as *const i8, b\"November\\0\" as *const u8 as *const i8, b\"December\\0\" as *const u8 as *const i8, ]; let mut days: [*const i8; 7] = [ b\"Sunday\\0\" as *const u8 as *const i8, b\"Monday\\0\" as *const u8 as *const i8, b\"Tuesday\\0\" as *const u8 as *const i8, b\"Wednesday\\0\" as *const u8 as *const i8, b\"Thursday\\0\" as *const u8 as *const i8, b\"Friday\\0\" as *const u8 as *const i8, b\"Saturday\\0\" as *const u8 as *const i8, ]; print!( \"{}-{}-{}\\n\", (*now).tm_year + 1900, (*now).tm_mon + 1, (*now).tm_mday ); print!( \"{}, {} {}, {}\\n\", build_str_from_raw_ptr(days[(*now).tm_wday as usize] as *mut u8), build_str_from_raw_ptr(months[(*now).tm_mon as usize] as *mut u8), (*now).tm_mday, (*now).tm_year + 1900 ); strftime( buf.as_mut_ptr(), 50, b\"%A, %B %e, %Y\\0\" as *const u8 as *const i8, now, ); print!(\"{}\\n\", build_str_from_raw_ptr(buf.as_mut_ptr() as *mut u8)); return 0; } }" }, { "index": 515, "before": "int main(void) { \tint n[] = { 3, 5, 7 }; \tint a[] = { 2, 3, 2 }; \tprintf(\"%d\\n\", chinese_remainder(n, a, sizeof(n)/sizeof(n[0]))); \treturn 0; }", "after": "fn main() -> i32 { let mut n: [i32; 3] = [3, 5, 7]; let mut a: [i32; 3] = [2, 3, 2]; print!( \"{}\\n\", chinese_remainder( n.as_mut_ptr(), a.as_mut_ptr(), (::core::mem::size_of::<[i32; 3]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32, ) ); return 0; }" }, { "index": 516, "before": "int mul_inv(int a, int b) { \tint b0 = b, t, q; \tint x0 = 0, x1 = 1; \tif (b == 1) return 1; \twhile (a > 1) { \t\tq = a / b; \t\tt = b, b = a % b, a = t; \t\tt = x0, x0 = x1 - q * x0, x1 = t; \t} \tif (x1 < 0) x1 += b0; \treturn x1; }", "after": "pub extern \"C\" fn mul_inv(mut a: i32, mut b: i32) -> i32 { let mut b0: i32 = b; let mut t: i32 = 0; let mut q: i32 = 0; let mut x0: i32 = 0; let mut x1: i32 = 1; if b == 1 { return 1; } while a > 1 { q = a / b; t = b; b = a % b; a = t; t = x0; x0 = x1 - q * x0; x1 = t; } if x1 < 0 { x1 += b0; } return x1; }" }, { "index": 517, "before": "int chinese_remainder(int *n, int *a, int len) { \tint p, i, prod = 1, sum = 0; \tfor (i = 0; i < len; i++) prod *= n[i]; \tfor (i = 0; i < len; i++) { \t\tp = prod / n[i]; \t\tsum += a[i] * mul_inv(p, n[i]) * p; \t} \treturn sum % prod; }", "after": "pub extern \"C\" fn chinese_remainder(mut n: *mut i32, mut a: *mut i32, mut len: i32) -> i32 { unsafe { let mut p: i32 = 0; let mut i: i32 = 0; let mut prod: i32 = 1; let mut sum: i32 = 0; i = 0; while i < len { prod *= *n.offset(i as isize); i += 1; i; } i = 0; while i < len { p = prod / *n.offset(i as isize); sum += *a.offset(i as isize) * mul_inv(p, *n.offset(i as isize)) * p; i += 1; i; } return sum % prod; } }" }, { "index": 518, "before": "void process(int lineNum, char buffer[]) { char days[7][64]; int i = 0, d = 0, j = 0; while (buffer[i] != 0) { if (buffer[i] == ' ') { days[d][j] = '\\0'; ++d; j = 0; } else if (buffer[i] == '\\n' || buffer[i] == '\\r') { days[d][j] = '\\0'; ++d; break; } else { days[d][j] = buffer[i]; ++j; } if (d >= 7) { printf(\"There aren't 7 days in line %d\\n\", lineNum); return; } ++i; } if (buffer[i] == '\\0') { days[d][j] = '\\0'; ++d; } if (d < 7) { printf(\"There aren't 7 days in line %d\\n\", lineNum); return; } else { int len = 0; for (len = 1; len < 64; ++len) { int d1; for (d1 = 0; d1 < 7; ++d1) { int d2; for (d2 = d1 + 1; d2 < 7; ++d2) { int unique = 0; for (i = 0; i < len; ++i) { if (days[d1][i] != days[d2][i]) { unique = 1; break; } } if (!unique) { goto next_length; } } } // uniqueness found for this length printf(\"%2d \", len); for (i = 0; i < 7; ++i) { printf(\" %s\", days[i]); } printf(\"\\n\"); return; // a duplication was found at the current length next_length: {} } } printf(\"Failed to find uniqueness within the bounds.\"); }", "after": "pub extern \"C\" fn process(mut lineNum: i32, mut buffer: *mut i8) { unsafe { let mut days: [[i8; 64]; 7] = [[0; 64]; 7]; let mut i: i32 = 0; let mut d: i32 = 0; let mut j: i32 = 0; while *buffer.offset(i as isize) as i32 != 0 { if *buffer.offset(i as isize) as i32 == ' ' as i32 { days[d as usize][j as usize] = '\\0' as i8; d += 1; d; j = 0; } else if *buffer.offset(i as isize) as i32 == '\\n' as i32 || *buffer.offset(i as isize) as i32 == '\\r' as i32 { days[d as usize][j as usize] = '\\0' as i8; d += 1; d; break; } else { days[d as usize][j as usize] = *buffer.offset(i as isize); j += 1; j; } if d >= 7 { printf( b\"There aren't 7 days in line %d\\n\\0\" as *const u8 as *const i8, lineNum, ); return; } i += 1; i; } if *buffer.offset(i as isize) as i32 == '\\0' as i32 { days[d as usize][j as usize] = '\\0' as i8; d += 1; d; } if d < 7 { printf( b\"There aren't 7 days in line %d\\n\\0\" as *const u8 as *const i8, lineNum, ); return; } else { let mut len: i32 = 0; len = 1; while len < 64 { let mut current_block_35: u64; let mut d1: i32 = 0; d1 = 0; 's_113: loop { if !(d1 < 7) { current_block_35 = 18153031941552419006; break; } let mut d2: i32 = 0; d2 = d1 + 1; while d2 < 7 { let mut unique: i32 = 0; i = 0; while i < len { if days[d1 as usize][i as usize] as i32 != days[d2 as usize][i as usize] as i32 { unique = 1; break; } else { i += 1; i; } } if unique == 0 { current_block_35 = 10891380440665537214; break 's_113; } d2 += 1; d2; } d1 += 1; d1; } match current_block_35 { 10891380440665537214 => {} _ => { print!(\"{:2} \", len); i = 0; while i < 7 { print!( \" {}\", build_str_from_raw_ptr((days[i as usize]).as_mut_ptr() as *mut u8) ); i += 1; i; } print!(\"\\n\"); return; } } len += 1; len; } } print!(\"Failed to find uniqueness within the bounds.\"); } }" }, { "index": 519, "before": "int main() { char buffer[1024]; int lineNum = 1, len; FILE *fp; fp = fopen(\"days_of_week.txt\", \"r\"); while (1) { memset(buffer, 0, sizeof(buffer)); fgets(buffer, sizeof(buffer), fp); len = strlen(buffer); if (len == 0 || buffer[len - 1] == '\\0') { break; } process(lineNum++, buffer); } fclose(fp); return 0; }", "after": "fn main() -> i32 { unsafe { let mut buffer: [i8; 1024] = [0; 1024]; let mut lineNum: i32 = 1; let mut len: i32 = 0; let mut fp: *mut FILE = 0 as *mut FILE; fp = fopen( b\"days_of_week.txt\\0\" as *const u8 as *const i8, b\"r\\0\" as *const u8 as *const i8, ); loop { memset( buffer.as_mut_ptr() as *mut libc::c_void, 0, ::core::mem::size_of::<[i8; 1024]>() as u64, ); fgets( buffer.as_mut_ptr(), ::core::mem::size_of::<[i8; 1024]>() as i32, fp, ); len = strlen(buffer.as_mut_ptr()) as i32; if len == 0 || buffer[(len - 1i32) as usize] as i32 == '\\0' as i32 { break; } let fresh0 = lineNum; lineNum = lineNum + 1; process(fresh0, buffer.as_mut_ptr()); } fclose(fp); return 0; } }" }, { "index": 520, "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": "fn main() -> i32 { unsafe { let mut x: i32 = 0; let mut y: i32 = 0; let mut z: i32 = 0; let n: i32 = 20; 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(i32, i32) -> *mut List)(1, n), old: 0 as *mut List, p: FE_var, }; init } as *mut ITERATOR; ::core::ptr::write_volatile( &mut x as *mut i32, *(&mut (*(*FE_var).l).val as *mut [i8; 0] as *mut i32), ); while (if !((*FE_var).l).is_null() { ::core::ptr::write_volatile( &mut x as *mut i32, *(&mut (*(*FE_var).l).val as *mut [i8; 0] as *mut i32), ); 1 } else { 0 }) != 0 { FE_var = &mut { let mut init = ITERATOR { l: (intRangeList as unsafe extern \"C\" fn(i32, i32) -> *mut List)(x, n), old: 0 as *mut List, p: FE_var, }; init } as *mut ITERATOR; ::core::ptr::write_volatile( &mut y as *mut i32, *(&mut (*(*FE_var).l).val as *mut [i8; 0] as *mut i32), ); while (if !((*FE_var).l).is_null() { ::core::ptr::write_volatile( &mut y as *mut i32, *(&mut (*(*FE_var).l).val as *mut [i8; 0] as *mut i32), ); 1 } else { 0 }) != 0 { FE_var = &mut { let mut init = ITERATOR { l: (intRangeList as unsafe extern \"C\" fn(i32, i32) -> *mut List)(y, n), old: 0 as *mut List, p: FE_var, }; init } as *mut ITERATOR; ::core::ptr::write_volatile( &mut z as *mut i32, *(&mut (*(*FE_var).l).val as *mut [i8; 0] as *mut i32), ); while (if !((*FE_var).l).is_null() { ::core::ptr::write_volatile( &mut z as *mut i32, *(&mut (*(*FE_var).l).val as *mut [i8; 0] as *mut i32), ); 1 } else { 0 }) != 0 { if x * x + y * y == z * z { if !((*SEQ_var).l).is_null() { listAppend( (*SEQ_var).l, ::core::mem::size_of::() as i32, &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::() as i32, &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 [i8; 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 [i8; 0] as *mut Triple), ); 1 } else { 0 }) != 0 { print!(\"{}, {}, {}\\n\", t._1, t._2, t._3); (*FE_var).l = (*(*FE_var).l).nx; } FE_var = (*FE_var).p; return 0; } }" }, { "index": 521, "before": "int main() { const char *t = \"ingirumimusnocteetconsumimurigni\"; const char *template = \"sequence \\\"%s\\\" is%s palindrome\\n\"; int l = strlen(t); printf(template, t, palindrome(t) ? \"\" : \"n't\"); printf(template, t, palindrome_r(t, 0, l) ? \"\" : \"n't\"); return 0; }", "after": "fn main() -> i32 { unsafe { let mut t: *const i8 = b\"ingirumimusnocteetconsumimurigni\\0\" as *const u8 as *const i8; let mut template: *const i8 = b\"sequence \\\"%s\\\" is%s palindrome\\n\\0\" as *const u8 as *const i8; let mut l: i32 = strlen(t) as i32; if palindrome(t) != 0 { printf(template, t, b\"\\0\" as *const u8 as *const i8) } else { printf(template, t, b\"n't\\0\" as *const u8 as *const i8) }; if palindrome_r(t, 0, l) != 0 { printf(template, t, b\"\\0\" as *const u8 as *const i8) } else { printf(template, t, b\"n't\\0\" as *const u8 as *const i8) }; return 0; } }" }, { "index": 522, "before": "int palindrome_r(const char *s, int b, int e) { if ((e - 1) <= b) return 1; if (s[b] != s[e - 1]) return 0; return palindrome_r(s, b + 1, e - 1); }", "after": "pub extern \"C\" fn palindrome_r(mut s: *const i8, mut b: i32, mut e: i32) -> i32 { unsafe { if e - 1 <= b { return 1; } if *s.offset(b as isize) as i32 != *s.offset((e - 1i32) as isize) as i32 { return 0; } return palindrome_r(s, b + 1, e - 1); } }" }, { "index": 523, "before": "int palindrome(const char *s) { int i, l; l = strlen(s); for (i = 0; i < l / 2; i++) { if (s[i] != s[l - i - 1]) return 0; } return 1; }", "after": "pub extern \"C\" fn palindrome(mut s: *const i8) -> i32 { unsafe { let mut i: i32 = 0; let mut l: i32 = 0; l = strlen(s) as i32; i = 0; while i < l / 2 { if *s.offset(i as isize) as i32 != *s.offset((l - i - 1i32) as isize) as i32 { return 0; } i += 1; i; } return 1; } }" }, { "index": 524, "before": "int main (void) { printf (\"%f\\n\", x(5)); /* 6.000000 */ printf (\"%f\\n\", x(2.3)); /* 8.300000 */ printf (\"%i\\n\", y(5.0)); /* 8 */ printf (\"%i\\n\", y(3.3)); /* 11 */ printf (\"%c\\n\", z(5)); /* f */ return 0; }", "after": "fn main() -> i32 { print!(\"{}\\n\", x(5 as f64)); print!(\"{}\\n\", x(2.3f64)); print!(\"{}\\n\", y(5.0f64 as i32)); print!(\"{}\\n\", y(3.3f64 as i32)); print!(\"{}\\n\", z(5)); return 0; }" }, { "index": 525, "before": "void sc_up() { \tlong long tmp = dx - dy; dy = dx + dy; dx = tmp; \tscale *= 2; x *= 2; y *= 2; }", "after": "pub extern \"C\" fn sc_up() { unsafe { let mut tmp: i64 = dx - dy; dy = dx + dy; dx = tmp; scale *= 2; x *= 2; y *= 2; } }" }, { "index": 526, "before": "void h_rgb(long long x, long long y) { \trgb *p = &pix[y][x]; #\tdefine SAT 1 \tdouble h = 6.0 * clen / scale; \tdouble VAL = 1 - (cos(3.141592653579 * 64 * clen / scale) - 1) / 4; \tdouble c = SAT * VAL; \tdouble X = c * (1 - fabs(fmod(h, 2) - 1)); \tswitch((int)h) { \tcase 0: p->r += c; p->g += X; return; \tcase 1:\tp->r += X; p->g += c; return; \tcase 2: p->g += c; p->b += X; return; \tcase 3: p->g += X; p->b += c; return; \tcase 4: p->r += X; p->b += c; return; \tdefault: \t\tp->r += c; p->b += X; \t} }", "after": "pub extern \"C\" fn h_rgb(mut x_0: i64, mut y_0: i64) { unsafe { let mut p: *mut rgb = &mut *(*pix.offset(y_0 as isize)).offset(x_0 as isize) as *mut rgb; let mut h: f64 = 6.0f64 * clen as f64 / scale as f64; let mut VAL: f64 = 1 as f64 - (cos(3.141592653579f64 * 64 as f64 * clen as f64 / scale as f64) - 1 as f64) / 4 as f64; let mut c: f64 = 1 as f64 * VAL; let mut X: f64 = c * (1 as f64 - fabs(fmod(h, 2 as f64) - 1 as f64)); match h as i32 { 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": 527, "before": "int main(int c, char ** v) { \tint size, depth; \tdepth = (c > 1) ? atoi(v[1]) : 10; \tsize = 1 << depth; \tfprintf(stderr, \"size: %d depth: %d\\n\", size, depth); \tdragon(size, depth * 2); \treturn 0; }", "after": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { let mut size: i32 = 0; let mut depth: i32 = 0; depth = if c > 1 { atoi(*v.offset(1 as isize)) } else { 10 }; size = 1 << depth; fprintf( stderr, b\"size: %d depth: %d\\n\\0\" as *const u8 as *const i8, size, depth, ); dragon(size as i64, depth * 2); return 0; } }" }, { "index": 528, "before": "void dragon(long leng, int depth) { \tlong i, d = leng / 3 + 1; \tlong h = leng + 3, w = leng + d * 3 / 2 + 2; \t/* allocate pixel buffer */ \trgb *buf = malloc(sizeof(rgb) * w * h); \tpix = malloc(sizeof(rgb *) * h); \tfor (i = 0; i < h; i++) \t\tpix[i] = buf + w * i; \tmemset(buf, 0, sizeof(rgb) * w * h); /* init coords; scale up to desired; exec string */ \tx = y = d; dx = leng; dy = 0; scale = 1; clen = 0; \tfor (i = 0; i < depth; i++) sc_up(); \titer_string(\"FX\", depth); \t/* write color PNM file */ \tunsigned char *fpix = malloc(w * h * 3); \tdouble maxv = 0, *dbuf = (double*)buf; /* find highest value among pixels; normalize image according * to it. Highest value would be at points most travelled, so * this ends up giving curve edge a nice fade -- it's more apparaent * if we increase iteration depth by one or two. */ \tfor (i = 3 * w * h - 1; i >= 0; i--) \t\tif (dbuf[i] > maxv) maxv = dbuf[i]; \tfor (i = 3 * h * w - 1; i >= 0; i--) \t\tfpix[i] = 255 * dbuf[i] / maxv; \tprintf(\"P6\\n%ld %ld\\n255\\n\", w, h); \tfflush(stdout); /* printf and fwrite may treat buffer differently */ \tfwrite(fpix, h * w * 3, 1, stdout); }", "after": "pub extern \"C\" fn dragon(mut leng: i64, mut depth: i32) { unsafe { let mut i: i64 = 0; let mut d: i64 = leng / 3 + 1; let mut h: i64 = leng + 3; let mut w: i64 = leng + d * 3 / 2 + 2; let mut buf: *mut rgb = malloc( (::core::mem::size_of::() as u64) .wrapping_mul(w as u64) .wrapping_mul(h as u64), ) as *mut rgb; pix = malloc((::core::mem::size_of::<*mut rgb>() as u64).wrapping_mul(h as u64)) as *mut *mut rgb; i = 0; while i < h { let ref mut fresh1 = *pix.offset(i as isize); *fresh1 = buf.offset((w * i) as isize); i += 1; i; } memset( buf as *mut libc::c_void, 0, (::core::mem::size_of::() as u64) .wrapping_mul(w as u64) .wrapping_mul(h as u64), ); y = d; x = y; dx = leng as i64; dy = 0; scale = 1; clen = 0; i = 0; while i < depth as i64 { sc_up(); i += 1; i; } iter_string(b\"FX\\0\" as *const u8 as *const i8, depth); let mut fpix: *mut u8 = malloc((w * h * 3i64) as u64) as *mut u8; let mut maxv: f64 = 0 as f64; let mut dbuf: *mut f64 = buf as *mut f64; i = 3 * w * h - 1; while i >= 0 { if *dbuf.offset(i as isize) > maxv { maxv = *dbuf.offset(i as isize); } i -= 1; i; } i = 3 * h * w - 1; while i >= 0 { *fpix.offset(i as isize) = (255 as f64 * *dbuf.offset(i as isize) / maxv) as u8; i -= 1; i; } print!(\"P6\\n{} {}\\n255\\n\", w, h); fflush(stdout); fwrite( fpix as *const libc::c_void, (h * w * 3i64) as u64, 1, stdout, ); } }" }, { "index": 529, "before": "void iter_string(const char * str, int d) { \tlong tmp; #\tdefine LEFT tmp = -dy; dy = dx; dx = tmp #\tdefine RIGHT tmp = dy; dy = -dx; dx = tmp \twhile (*str != '\\0') { \t\tswitch(*(str++)) { \t\tcase 'X':\tif (d) iter_string(\"X+YF+\", d - 1); continue; \t\tcase 'Y':\tif (d) iter_string(\"-FX-Y\", d - 1); continue; \t\tcase '+':\tRIGHT; continue; \t\tcase '-':\tLEFT; continue; \t\tcase 'F': /* draw: increment path length; add color; move. Here * is why the code does not allow user to choose arbitrary * image size: if it's not a power of two, aliasing will * occur and grid-like bright or dark lines will result * when normalized later. It can be gotten rid of, but that * involves computing multiplicative order and would be a huge * bore. */ \t\t\t\tclen ++; \t\t\t\th_rgb(x/scale, y/scale); \t\t\t\tx += dx; y += dy; \t\t\t\tcontinue; \t\t} \t} }", "after": "pub extern \"C\" fn iter_string(mut str: *const i8, mut d: i32) { unsafe { let mut tmp: i64 = 0; while *str as i32 != '\\0' as i32 { let fresh0 = str; str = str.offset(1); match *fresh0 as i32 { 88 => { if d != 0 { iter_string(b\"X+YF+\\0\" as *const u8 as *const i8, d - 1); } } 89 => { if d != 0 { iter_string(b\"-FX-Y\\0\" as *const u8 as *const i8, d - 1); } } 43 => { tmp = dy as i64; dy = -dx; dx = tmp; } 45 => { tmp = -dy as i64; dy = dx; dx = tmp; } 70 => { clen += 1; clen; h_rgb(x / scale, y / scale); x += dx; y += dy; } _ => {} } } } }" }, { "index": 530, "before": "void srnd(int x) { seed = x; }", "after": "pub extern \"C\" fn srnd(mut x: i32) { unsafe { seed = x; } }" }, { "index": 531, "before": "int rnd(void) { return (seed = (seed * 214013 + 2531011) & RMAX32) >> 16; }", "after": "pub extern \"C\" fn rnd() -> i32 { unsafe { seed = ((seed * 214013 + 2531011i32) as u32 & (1u32 << 31i32).wrapping_sub(1)) as i32; return seed >> 16; } }" }, { "index": 532, "before": "void show(const int *c) { \tint i; \tfor (i = 0; i < 52; c++) { \t\tprintf(\" \\033[%dm%lc\\033[m%lc\", 32 - (1 + *c) % 4 / 2, \t\t\ts_suits[*c % 4], s_nums[*c / 4]); \t\tif (!(++i % 8) || i == 52) putchar('\\n'); \t} }", "after": "pub extern \"C\" fn show(mut c: *const i32) { unsafe { let mut i: i32 = 0; i = 0; while i < 52 { print!( \" \\x1B[{}m{}\\x1B[m{}\", 32 - (1 + *c) % 4 / 2, s_suits[(*c % 4i32) as usize], s_nums[(*c / 4i32) as usize] ); i += 1; if i % 8 == 0 || i == 52 { print!(\"{}\", '\\n' as i32); } c = c.offset(1); c; } } }" }, { "index": 533, "before": "void deal(int s, int *t) { \tint i, j; \tsrnd(s); \tfor (i = 0; i < 52; i++) t[i] = 51 - i; \tfor (i = 0; i < 51; i++) { \t\tj = 51 - rnd() % (52 - i); \t\ts = t[i], t[i] = t[j], t[j] = s; \t} }", "after": "pub extern \"C\" fn deal(mut s: i32, mut t: *mut i32) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; srnd(s); i = 0; while i < 52 { *t.offset(i as isize) = 51 - i; i += 1; i; } i = 0; while i < 51 { j = 51 - rnd() % (52 - i); s = *t.offset(i as isize); *t.offset(i as isize) = *t.offset(j as isize); *t.offset(j as isize) = s; i += 1; i; } } }" }, { "index": 534, "before": "int main(int c, char **v) { \tint s, card[52]; \tif (c < 2 || (s = atoi(v[1])) <= 0) s = 11982; \tsetlocale(LC_ALL, \"\"); \tdeal(s, card); \tprintf(\"Hand %d\\n\", s); \tshow(card); \treturn 0; }", "after": "fn main(mut c: i32, mut v: *mut *mut i8) -> i32 { unsafe { let mut s: i32 = 0; let mut card: [i32; 52] = [0; 52]; if c < 2 || { s = atoi(*v.offset(1 as isize)); s <= 0 } { s = 11982; } setlocale(6, b\"\\0\" as *const u8 as *const i8); deal(s, card.as_mut_ptr()); print!(\"Hand {}\\n\", s); show(card.as_mut_ptr()); return 0; } }" }, { "index": 535, "before": "int main() { \tlayer3 cake1,cake2; \tcake1.d = 1; \tcake1.e = 2; \tcake1.l1.a = 3; \tcake1.l2.b = 4; \tcake1.l2.l1.a = 5; \tprintf(\"Cake 1 is : \"); \tshowCake(cake1); \tcake2 = cake1; \tcake2.l2.b += cake2.l2.l1.a; \tprintf(\"\\nCake 2 is : \"); \tshowCake(cake2); \treturn 0; }", "after": "fn main() -> i32 { let mut cake1: layer3 = layer3 { l2: layer2 { l1: layer1 { a: 0 }, b: 0., c: 0., }, l1: layer1 { a: 0 }, d: 0, e: 0, }; let mut cake2: layer3 = layer3 { l2: layer2 { l1: layer1 { a: 0 }, b: 0., c: 0., }, l1: layer1 { a: 0 }, d: 0, e: 0, }; cake1.d = 1; cake1.e = 2; cake1.l1.a = 3; cake1.l2.b = 4 as libc::c_float; cake1.l2.l1.a = 5; print!(\"Cake 1 is : \"); showCake(cake1); cake2 = cake1; cake2.l2.b += cake2.l2.l1.a as libc::c_float; print!(\"\\nCake 2 is : \"); showCake(cake2); return 0; }" }, { "index": 536, "before": "void showCake(layer3 cake){ \tprintf(\"\\ncake.d = %d\",cake.d); \tprintf(\"\\ncake.e = %d\",cake.e); \tprintf(\"\\ncake.l1.a = %d\",cake.l1.a); \tprintf(\"\\ncake.l2.b = %f\",cake.l2.b); \tprintf(\"\\ncake.l2.l1.a = %d\",cake.l2.l1.a); }", "after": "pub extern \"C\" fn showCake(mut cake: layer3) { print!(\"\\ncake.d = {}\", cake.d); print!(\"\\ncake.e = {}\", cake.e); print!(\"\\ncake.l1.a = {}\", cake.l1.a); print!(\"\\ncake.l2.b = {}\", cake.l2.b as f64); print!(\"\\ncake.l2.l1.a = {}\", cake.l2.l1.a); }" }, { "index": 537, "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 extern \"C\" fn numDigits(mut n: i32) -> i32 { let mut count: i32 = 1; while n >= 10 { n /= 10; count += 1; count; } return count; }" }, { "index": 538, "before": "void printMagicSquare(int** square,int rows){ \t\tint i,j; \t\tfor(i=0;i\",argV[0]); \t\telse{ \t\t\tn = atoi(argV[1]); \t\t\tprintMagicSquare(singlyEvenMagicSquare(n),n); \t\t} \t\treturn 0; \t}", "after": "fn main(mut argC: i32, mut argV: *mut *mut i8) -> i32 { unsafe { let mut n: i32 = 0; if argC != 2 || *(*__ctype_b_loc()) .offset(*(*argV.offset(1 as isize)).offset(0 as isize) as i32 as isize) as i32 & _ISdigit as i32 == 0 { print!( \"Usage : {} \", build_str_from_raw_ptr(*argV.offset(0 as isize) as *mut u8) ); } else { n = atoi(*argV.offset(1 as isize)); printMagicSquare(singlyEvenMagicSquare(n), n); } return 0; } }" }, { "index": 540, "before": "int main() { \tanalytic(); \tivp_euler(cooling, 100, 2, 100); \tivp_euler(cooling, 100, 5, 100); \tivp_euler(cooling, 100, 10, 100); \treturn 0; }", "after": "fn main() -> i32 { analytic(); ivp_euler( Some(cooling as unsafe extern \"C\" fn(f64, f64) -> f64), 100 as f64, 2, 100, ); ivp_euler( Some(cooling as unsafe extern \"C\" fn(f64, f64) -> f64), 100 as f64, 5, 100, ); ivp_euler( Some(cooling as unsafe extern \"C\" fn(f64, f64) -> f64), 100 as f64, 10, 100, ); return 0; }" }, { "index": 541, "before": "void ivp_euler(deriv_f f, double y, int step, int end_t) { \tint t = 0; \tprintf(\" Step %2d: \", (int)step); \tdo { \t\tif (t % 10 == 0) printf(FMT, y); \t\ty += step * f(t, y); \t} while ((t += step) <= end_t); \tprintf(\"\\n\"); }", "after": "pub extern \"C\" fn ivp_euler(mut f: deriv_f, mut y: f64, mut step: i32, mut end_t: i32) { let mut t: i32 = 0; print!(\" Step {:2}: \", step); unsafe { loop { if t % 10 == 0 { print!(\" {:7.3}\", y); } y += step as f64 * f.expect(\"non-null function pointer\")(t as f64, y); t += step; if !(t <= end_t) { break; } } } print!(\"\\n\"); }" }, { "index": 542, "before": "void analytic() { \tdouble t; \tprintf(\" Time: \"); \tfor (t = 0; t <= 100; t += 10) printf(\" %7g\", t); \tprintf(\"\\nAnalytic: \"); \tfor (t = 0; t <= 100; t += 10) \t\tprintf(FMT, 20 + 80 * exp(-0.07 * t)); \tprintf(\"\\n\"); }", "after": "pub extern \"C\" fn analytic() { let mut t: f64 = 0.; print!(\" Time: \"); t = 0 as f64; while t <= 100 as f64 { print!(\" {:7}\", t); t += 10 as f64; } print!(\"\\nAnalytic: \"); t = 0 as f64; unsafe { while t <= 100 as f64 { print!(\" {:7.3}\", 20 as f64 + 80 as f64 * exp(-0.07f64 * t)); t += 10 as f64; } } print!(\"\\n\"); }" }, { "index": 543, "before": "double cooling(double t, double temp) { \treturn -0.07 * (temp - 20); }", "after": "pub extern \"C\" fn cooling(mut t: f64, mut temp: f64) -> f64 { return -0.07f64 * (temp - 20 as f64); }" }, { "index": 544, "before": "int irand(int n) { \tint r, randmax = RAND_MAX / n * n; \twhile ((r = rand()) >= randmax) \t\t; \treturn r / (randmax / n); }", "after": "pub extern \"C\" fn irand(mut n: i32) -> i32 { let mut r: i32 = 0; let mut randmax: i32 = 2147483647 / n * n; unsafe { loop { r = rand(); if !(r >= randmax) { break; } } } return r / (randmax / n); }" }, { "index": 545, "before": "int one_of_n(int n) { \tint i, r = 0; \tfor (i = 1; i < n; i++) \t\tif (!irand(i + 1)) \t\t\tr = i; \treturn r; }", "after": "pub extern \"C\" fn one_of_n(mut n: i32) -> i32 { let mut i: i32 = 0; let mut r: i32 = 0; i = 1; while i < n { if irand(i + 1) == 0 { r = i; } i += 1; i; } return r; }" }, { "index": 546, "before": "int main(void) { \tint i, r[10] = {0}; \tfor (i = 0; i < 1000000; i++, r[one_of_n(10)]++) \t\t; \tfor (i = 0; i < 10; i++) \t\tprintf(\"%d%c\", r[i], i == 9 ? '\\n' : ' '); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut r: [i32; 10] = [0; 10]; i = 0; while i < 1000000 { i += 1; i; r[one_of_n(10) as usize] += 1; r[one_of_n(10) as usize]; } i = 0; while i < 10 { if i == 9 { print!(\"{}{}\", r[i as usize], '\\n' as i32) } else { print!(\"{}{}\", r[i as usize], ' ' as i32) }; i += 1; i; } return 0; }" }, { "index": 547, "before": "void sample_set_i(struct s_env *s_env, unsigned int i, void *item) { memcpy(s_env->sample + i * s_env->size, item, s_env->size); }", "after": "pub extern \"C\" fn sample_set_i(mut s_env: *mut s_env, mut i: u32, mut item: *mut libc::c_void) { unsafe { memcpy( ((*s_env).sample).offset((i as u64).wrapping_mul((*s_env).size) as isize), item, (*s_env).size, ); } }" }, { "index": 548, "before": "int main() { unsigned int i, j; unsigned int n = 3; unsigned int num_items = 10; unsigned int *frequencies; int *items_set; srand(time(NULL)); items_set = malloc(num_items * sizeof(int)); frequencies = malloc(num_items * sizeof(int)); for (i = 0; i < num_items; i++) { items_set[i] = i; frequencies[i] = 0; } for (i = 0; i < 100000; i++) { int *res = test(n, items_set, num_items); for (j = 0; j < n; j++) { frequencies[res[j]]++; } \tfree(res); } for (i = 0; i < num_items; i++) { printf(\" %d\", frequencies[i]); } puts(\"\"); return 0; }", "after": "fn main() -> i32 { unsafe { let mut i: u32 = 0; let mut j: u32 = 0; let mut n: u32 = 3; let mut num_items: u32 = 10; let mut frequencies: *mut u32 = 0 as *mut u32; let mut items_set: *mut i32 = 0 as *mut i32; srand(rust_time(None) as u32); items_set = malloc((num_items as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i32; frequencies = malloc((num_items as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut u32; i = 0; while i < num_items { *items_set.offset(i as isize) = i as i32; *frequencies.offset(i as isize) = 0; i = i.wrapping_add(1); i; } i = 0; while i < 100000 { let mut res: *mut i32 = test(n, items_set, num_items); j = 0; while j < n { let ref mut fresh0 = *frequencies.offset(*res.offset(j as isize) as isize); *fresh0 = (*fresh0).wrapping_add(1); *fresh0; j = j.wrapping_add(1); j; } free(res as *mut libc::c_void); i = i.wrapping_add(1); i; } i = 0; while i < num_items { print!(\" {}\", *frequencies.offset(i as isize)); i = i.wrapping_add(1); i; } puts(b\"\\0\" as *const u8 as *const i8); return 0; } }" }, { "index": 549, "before": "void s_of_n_init(struct s_env *s_env, size_t size, unsigned int n) { s_env->i = 0; s_env->n = n; s_env->size = size; s_env->sample = malloc(n * size); }", "after": "pub extern \"C\" fn s_of_n_init(mut s_env: *mut s_env, mut size: u64, mut n: u32) { unsafe { (*s_env).i = 0; (*s_env).n = n; (*s_env).size = size; (*s_env).sample = malloc((n as u64).wrapping_mul(size)); } }" }, { "index": 550, "before": "int main() { int d, x, y, cx, cy, px, py; char pts[MAX][MAX]; point curr, prev; for (x = 0; x < MAX; ++x) for (y = 0; y < MAX; ++y) pts[x][y] = ' '; prev.x = prev.y = 0; pts[0][0] = '.'; for (d = 1; d < N * N; ++d) { d2pt(N, d, &curr); cx = curr.x * K; cy = curr.y * K; px = prev.x * K; py = prev.y * K; pts[cx][cy] = '.'; if (cx == px ) { if (py < cy) for (y = py + 1; y < cy; ++y) pts[cx][y] = '|'; else for (y = cy + 1; y < py; ++y) pts[cx][y] = '|'; } else { if (px < cx) for (x = px + 1; x < cx; ++x) pts[x][cy] = '_'; else for (x = cx + 1; x < px; ++x) pts[x][cy] = '_'; } prev = curr; } for (x = 0; x < MAX; ++x) { for (y = 0; y < MAX; ++y) printf(\"%c\", pts[y][x]); printf(\"\\n\"); } return 0; }", "after": "fn main() -> i32 { let mut d: i32 = 0; let mut x: i32 = 0; let mut y: i32 = 0; let mut cx: i32 = 0; let mut cy: i32 = 0; let mut px: i32 = 0; let mut py: i32 = 0; let mut pts: [[i8; 96]; 96] = [[0; 96]; 96]; let mut curr: point = point { x: 0, y: 0 }; let mut prev: point = point { x: 0, y: 0 }; x = 0; while x < 32 * 3 { y = 0; while y < 32 * 3 { pts[x as usize][y as usize] = ' ' as i8; y += 1; y; } x += 1; x; } prev.y = 0; prev.x = prev.y; pts[0 as usize][0 as usize] = '.' as i8; d = 1; while d < 32 * 32 { d2pt(32, d, &mut curr); cx = curr.x * 3; cy = curr.y * 3; px = prev.x * 3; py = prev.y * 3; pts[cx as usize][cy as usize] = '.' as i8; if cx == px { if py < cy { y = py + 1; while y < cy { pts[cx as usize][y as usize] = '|' as i8; y += 1; y; } } else { y = cy + 1; while y < py { pts[cx as usize][y as usize] = '|' as i8; y += 1; y; } } } else if px < cx { x = px + 1; while x < cx { pts[x as usize][cy as usize] = '_' as i8; x += 1; x; } } else { x = cx + 1; while x < px { pts[x as usize][cy as usize] = '_' as i8; x += 1; x; } } prev = curr; d += 1; d; } x = 0; while x < 32 * 3 { y = 0; while y < 32 * 3 { print!(\"{}\", pts[y as usize][x as usize] as i32); y += 1; y; } print!(\"\\n\"); x += 1; x; } return 0; }" }, { "index": 551, "before": "void rot(int n, point *p, int rx, int ry) { int t; if (!ry) { if (rx == 1) { p->x = n - 1 - p->x; p->y = n - 1 - p->y; } t = p->x; p->x = p->y; p->y = t; } }", "after": "pub extern \"C\" fn rot(mut n: i32, mut p: *mut point, mut rx: i32, mut ry: i32) { unsafe { let mut t: i32 = 0; if ry == 0 { if rx == 1 { (*p).x = n - 1 - (*p).x; (*p).y = n - 1 - (*p).y; } t = (*p).x; (*p).x = (*p).y; (*p).y = t; } } }" }, { "index": 552, "before": "void d2pt(int n, int d, point *p) { int s = 1, t = d, rx, ry; p->x = 0; p->y = 0; while (s < n) { rx = 1 & (t / 2); ry = 1 & (t ^ rx); rot(s, p, rx, ry); p->x += s * rx; p->y += s * ry; t /= 4; s *= 2; } }", "after": "pub extern \"C\" fn d2pt(mut n: i32, mut d: i32, mut p: *mut point) { unsafe { let mut s: i32 = 1; let mut t: i32 = d; let mut rx: i32 = 0; let mut ry: i32 = 0; (*p).x = 0; (*p).y = 0; while s < n { rx = 1 & t / 2; ry = 1 & (t ^ rx); rot(s, p, rx, ry); (*p).x += s * rx; (*p).y += s * ry; t /= 4; s *= 2; } } }" }, { "index": 553, "before": "double calc(coeff_func f_a, coeff_func f_b, unsigned expansions) { \tdouble a, b, r; \ta = b = r = 0.0; \tunsigned i; \tfor (i = expansions; i > 0; i--) { \t\ta = f_a(i); \t\tb = f_b(i); \t\tr = b / (a + r); \t} \ta = f_a(0); \treturn a + r; }", "after": "pub extern \"C\" fn calc(mut f_a: coeff_func, mut f_b: coeff_func, mut expansions: u32) -> f64 { let mut a: f64 = 0.; let mut b: f64 = 0.; let mut r: f64 = 0.; r = 0.0f64; b = r; a = b; let mut i: u32 = 0; i = expansions; unsafe { while i > 0 { a = f_a.expect(\"non-null function pointer\")(i); b = f_b.expect(\"non-null function pointer\")(i); r = b / (a + r); i = i.wrapping_sub(1); i; } a = f_a.expect(\"non-null function pointer\")(0); } return a + r; }" }, { "index": 554, "before": "double pi_a(unsigned n) { \treturn n ? 6.0 : 3.0; }", "after": "pub extern \"C\" fn pi_a(mut n: u32) -> f64 { return if n != 0 { 6.0f64 } else { 3.0f64 }; }" }, { "index": 555, "before": "double napier_b(unsigned n) { \treturn n > 1.0 ? n - 1.0 : 1.0; }", "after": "pub extern \"C\" fn napier_b(mut n: u32) -> f64 { return if n as f64 > 1.0f64 { n as f64 - 1.0f64 } else { 1.0f64 }; }" }, { "index": 556, "before": "double sqrt2_b(unsigned n) { \treturn 1.0; }", "after": "pub extern \"C\" fn sqrt2_b(mut n: u32) -> f64 { return 1.0f64; }" }, { "index": 557, "before": "double pi_b(unsigned n) { \tdouble c = 2.0 * n - 1.0; \treturn c * c; }", "after": "pub extern \"C\" fn pi_b(mut n: u32) -> f64 { let mut c: f64 = 2.0f64 * n as f64 - 1.0f64; return c * c; }" }, { "index": 558, "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": "fn main() -> i32 { let mut sqrt2: f64 = 0.; let mut napier: f64 = 0.; let mut pi: f64 = 0.; sqrt2 = calc( Some(sqrt2_a as unsafe extern \"C\" fn(u32) -> f64), Some(sqrt2_b as unsafe extern \"C\" fn(u32) -> f64), 1000, ); napier = calc( Some(napier_a as unsafe extern \"C\" fn(u32) -> f64), Some(napier_b as unsafe extern \"C\" fn(u32) -> f64), 1000, ); pi = calc( Some(pi_a as unsafe extern \"C\" fn(u32) -> f64), Some(pi_b as unsafe extern \"C\" fn(u32) -> f64), 1000, ); print!(\"{:12.10}\\n{:12.10}\\n{:12.10}\\n\", sqrt2, napier, pi); return 0; }" }, { "index": 559, "before": "double sqrt2_a(unsigned n) { \treturn n ? 2.0 : 1.0; }", "after": "pub extern \"C\" fn sqrt2_a(mut n: u32) -> f64 { return if n != 0 { 2.0f64 } else { 1.0f64 }; }" }, { "index": 560, "before": "double napier_a(unsigned n) { \treturn n ? n : 2.0; }", "after": "pub extern \"C\" fn napier_a(mut n: u32) -> f64 { return if n != 0 { n as f64 } else { 2.0f64 }; }" }, { "index": 561, "before": "int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf(\"Enter two integers. Space delimited, please: \"); scanf(\"%d %d\",&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf(\"array[%d][%d] is %d\\n\",user1/2,user2/2,array[user1/2][user2/2]); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut user1: i32 = 0; let mut user2: i32 = 0; print!(\"Enter two integers. Space delimited, please: \"); scanf( b\"%d %d\\0\" as *const u8 as *const i8, &mut user1 as *mut i32, &mut user2 as *mut i32, ); let vla = user1 as usize; let vla_0 = user2 as usize; let mut array: Vec = ::std::vec::from_elem(0, vla * vla_0); *array .as_mut_ptr() .offset((user1 / 2i32) as isize * vla_0 as isize) .offset((user2 / 2i32) as isize) = user1 + user2; print!( \"array[{}][{}] is {}\\n\", user1 / 2, user2 / 2, *array .as_mut_ptr() .offset((user1 / 2i32) as isize * vla_0 as isize) .offset((user2 / 2i32) as isize) ); return 0; } }" }, { "index": 562, "before": "int main(int argc, char *argv[]) { int a, b; if (argc < 3) exit(1); b = atoi(argv[--argc]); if (b == 0) exit(2); a = atoi(argv[--argc]); printf(\"a+b = %d\\n\", a+b); printf(\"a-b = %d\\n\", a-b); printf(\"a*b = %d\\n\", a*b); printf(\"a/b = %d\\n\", a/b); /* truncates towards 0 (in C99) */ printf(\"a%%b = %d\\n\", a%b); /* same sign as first operand (in C99) */ return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut a: i32 = 0; let mut b: i32 = 0; if argc < 3 { exit(1); } argc -= 1; b = atoi(*argv.offset(argc as isize)); if b == 0 { exit(2); } argc -= 1; a = atoi(*argv.offset(argc as isize)); print!(\"a+b = {}\\n\", a + b); print!(\"a-b = {}\\n\", a - b); print!(\"a*b = {}\\n\", a * b); print!(\"a/b = {}\\n\", a / b); print!(\"a%b = {}\\n\", a % b); return 0; } }" }, { "index": 563, "before": "int main(int argc, char *argv[]) { if (argc < 2) return 0; FILE *fd = fopen(argv[1], \"r\"); if (!fd) err(\"Could not open file: '%s\\n\", argv[1]); dstr *story = readinput(fd); fclose(fd); if (!story) err(\"Failed to allocate memory\"); madlibs(story); printf(\"%s\\n\", story->data); dstr_delete(story); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { if argc < 2 { return 0; } let mut fd: *mut FILE = fopen(*argv.offset(1 as isize), b\"r\\0\" as *const u8 as *const i8); if fd.is_null() { fprintf( stderr, b\"Could not open file: '%s\\n\\0\" as *const u8 as *const i8, *argv.offset(1 as isize), ); exit(1); } let mut story: *mut dstr = readinput(fd); fclose(fd); if story.is_null() { fprintf( stderr, b\"Failed to allocate memory\\0\" as *const u8 as *const i8, ); exit(1); } madlibs(story); print!(\"{}\\n\", build_str_from_raw_ptr((*story).data as *mut u8)); dstr_delete(story); return 0; } }" }, { "index": 564, "before": "int dstr_grow(dstr *s) { s->alloc *= 2; char *attempt = realloc(s->data, s->alloc); if (!attempt) return 0; else s->data = attempt; return 1; }", "after": "pub extern \"C\" fn dstr_grow(mut s: *mut dstr) -> i32 { unsafe { (*s).alloc = ((*s).alloc as u64).wrapping_mul(2) as u64; let mut attempt: *mut i8 = realloc((*s).data as *mut libc::c_void, (*s).alloc) as *mut i8; if attempt.is_null() { return 0; } else { (*s).data = attempt; } return 1; } }" }, { "index": 565, "before": "void dstr_delete(dstr *s) { if (s->data) free(s->data); if (s) free(s); }", "after": "pub extern \"C\" fn dstr_delete(mut s: *mut dstr) { unsafe { if !((*s).data).is_null() { free((*s).data as *mut libc::c_void); } if !s.is_null() { free(s as *mut libc::c_void); } } }" }, { "index": 566, "before": "int dstr_space(dstr *s, size_t grow_amount) { return s->length + grow_amount < s->alloc; }", "after": "pub extern \"C\" fn dstr_space(mut s: *mut dstr, mut grow_amount: u64) -> i32 { unsafe { return (((*s).length).wrapping_add(grow_amount) < (*s).alloc) as i32; } }" }, { "index": 567, "before": "void dstr_replace_all(dstr *story, const char *replace, const char *insert) { const size_t replace_l = strlen(replace); const size_t insert_l = strlen(insert); char *start = story->data; while ((start = strstr(start, replace))) { if (!dstr_space(story, insert_l - replace_l)) if (!dstr_grow(story)) err(\"Failed to allocate memory\"); if (insert_l != replace_l) { memmove(start + insert_l, start + replace_l, story->length - (start + replace_l - story->data)); /* Remember to null terminate the data so we can utilize it * as we normally would */ story->length += insert_l - replace_l; story->data[story->length] = 0; } memmove(start, insert, insert_l); } }", "after": "pub extern \"C\" fn dstr_replace_all( mut story: *mut dstr, mut replace: *const i8, mut insert: *const i8, ) { unsafe { let replace_l: u64 = strlen(replace); let insert_l: u64 = strlen(insert); let mut start: *mut i8 = (*story).data; loop { start = strstr(start, replace); if start.is_null() { break; } if dstr_space(story, insert_l.wrapping_sub(replace_l)) == 0 { if dstr_grow(story) == 0 { fprintf( stderr, b\"Failed to allocate memory\\0\" as *const u8 as *const i8, ); exit(1); } } if insert_l != replace_l { memmove( start.offset(insert_l as isize) as *mut libc::c_void, start.offset(replace_l as isize) as *const libc::c_void, ((*story).length).wrapping_sub( start.offset(replace_l as isize).offset_from((*story).data) as u64, ), ); (*story).length = ((*story).length as u64).wrapping_add(insert_l.wrapping_sub(replace_l)) as u64; *((*story).data).offset((*story).length as isize) = 0; } memmove( start as *mut libc::c_void, insert as *const libc::c_void, insert_l, ); } } }" }, { "index": 568, "before": "void madlibs(dstr *story) { static const size_t buffer_size = 128; char insert[buffer_size]; char replace[buffer_size]; char *start, *end = story->data; while (start = strchr(end, '<')) { if (!(end = strchr(start, '>'))) err(\"Malformed brackets in input\"); /* One extra for current char and another for nul byte */ strncpy(replace, start, end - start + 1); replace[end - start + 1] = '\\0'; printf(\"Enter value for field %s: \", replace); fgets(insert, buffer_size, stdin); const size_t il = strlen(insert) - 1; if (insert[il] == '\\n') insert[il] = '\\0'; dstr_replace_all(story, replace, insert); } printf(\"\\n\"); }", "after": "pub extern \"C\" fn madlibs(mut story: *mut dstr) { unsafe { static mut buffer_size: u64 = 128; let vla = buffer_size as usize; let mut insert: Vec = ::std::vec::from_elem(0, vla); let vla_0 = buffer_size as usize; let mut replace: Vec = ::std::vec::from_elem(0, vla_0); let mut start: *mut i8 = 0 as *mut i8; let mut end: *mut i8 = (*story).data; loop { start = strchr(end, '<' as i32); if start.is_null() { break; } end = strchr(start, '>' as i32); if end.is_null() { fprintf( stderr, b\"Malformed brackets in input\\0\" as *const u8 as *const i8, ); exit(1); } strncpy( replace.as_mut_ptr(), start, (end.offset_from(start) as i64 + 1i64) as u64, ); *replace .as_mut_ptr() .offset((end.offset_from(start) as i64 + 1i64) as isize) = '\\0' as i8; print!( \"Enter value for field {}: \", build_str_from_raw_ptr(replace.as_mut_ptr() as *mut u8) ); fgets(insert.as_mut_ptr(), buffer_size as i32, stdin); let il: u64 = (strlen(insert.as_mut_ptr())).wrapping_sub(1); if *insert.as_mut_ptr().offset(il as isize) as i32 == '\\n' as i32 { *insert.as_mut_ptr().offset(il as isize) = '\\0' as i8; } dstr_replace_all(story, replace.as_mut_ptr(), insert.as_mut_ptr()); } print!(\"\\n\"); } }" }, { "index": 569, "before": "int main() { printf(\"First 25 n-smooth numbers for n = 2 -> 29:\\n\"); for (uint32_t n = 2; n <= 29; ++n) { if (is_prime(n)) print_nsmooth_numbers(n, 0, 25); } printf(\"\\n3 n-smooth numbers starting from 3000th for n = 3 -> 29:\\n\"); for (uint32_t n = 3; n <= 29; ++n) { if (is_prime(n)) print_nsmooth_numbers(n, 2999, 3); } printf(\"\\n20 n-smooth numbers starting from 30,000th for n = 503 -> 521:\\n\"); for (uint32_t n = 503; n <= 521; ++n) { if (is_prime(n)) print_nsmooth_numbers(n, 29999, 20); } return 0; }", "after": "fn main() -> i32 { print!(\"First 25 n-smooth numbers for n = 2 -> 29:\\n\"); let mut n: u32 = 2; while n <= 29 { if is_prime(n) { print_nsmooth_numbers(n, 0, 25); } n = n.wrapping_add(1); n; } print!(\"\\n3 n-smooth numbers starting from 3000th for n = 3 -> 29:\\n\"); let mut n_0: u32 = 3; while n_0 <= 29 { if is_prime(n_0) { print_nsmooth_numbers(n_0, 2999, 3); } n_0 = n_0.wrapping_add(1); n_0; } print!(\"\\n20 n-smooth numbers starting from 30,000th for n = 503 -> 521:\\n\"); let mut n_1: u32 = 503; while n_1 <= 521 { if is_prime(n_1) { print_nsmooth_numbers(n_1, 29999, 20); } n_1 = n_1.wrapping_add(1); n_1; } return 0; }" }, { "index": 570, "before": "uint32_t find_primes(uint32_t from, uint32_t to, uint32_t** primes) { uint32_t count = 0, buffer_length = 16; uint32_t* buffer = xmalloc(sizeof(uint32_t) * buffer_length); for (uint32_t p = from; p <= to; ++p) { if (is_prime(p)) { if (count >= buffer_length) { uint32_t new_length = buffer_length * 2; if (new_length < count + 1) new_length = count + 1; buffer = xrealloc(buffer, sizeof(uint32_t) * new_length); buffer_length = new_length; } buffer[count++] = p; } } *primes = buffer; return count; }", "after": "pub extern \"C\" fn find_primes(mut from: u32, mut to: u32, mut primes: *mut *mut u32) -> u32 { unsafe { let mut count: u32 = 0; let mut buffer_length: u32 = 16; let mut buffer: *mut u32 = xmalloc((::core::mem::size_of::() as u64).wrapping_mul(buffer_length as u64)) as *mut u32; let mut p: u32 = from; while p <= to { if is_prime(p) { if count >= buffer_length { let mut new_length: u32 = buffer_length.wrapping_mul(2); if new_length < count.wrapping_add(1) { new_length = count.wrapping_add(1); } buffer = xrealloc( buffer as *mut libc::c_void, (::core::mem::size_of::() as u64).wrapping_mul(new_length as u64), ) as *mut u32; buffer_length = new_length; } let fresh0 = count; count = count.wrapping_add(1); *buffer.offset(fresh0 as isize) = p; } p = p.wrapping_add(1); p; } *primes = buffer; return count; } }" }, { "index": 571, "before": "bool is_prime(uint32_t n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (uint32_t p = 3; p * p <= n; p += 2) { if (n % p == 0) return false; } return true; }", "after": "pub extern \"C\" fn is_prime(mut n: u32) -> bool { if n == 2 { return 1 != 0; } if n < 2 || n.wrapping_rem(2) == 0 { return 0 != 0; } let mut p: u32 = 3; while p.wrapping_mul(p) <= n { if n.wrapping_rem(p) == 0 { return 0 != 0; } p = (p).wrapping_add(2) as u32; } return 1 != 0; }" }, { "index": 572, "before": "void free_numbers(mpz_t* numbers, size_t count) { for (size_t i = 0; i < count; ++i) mpz_clear(numbers[i]); free(numbers); }", "after": "pub extern \"C\" fn free_numbers(mut numbers: *mut i32, mut count: u64) {}" }, { "index": 573, "before": "void print_nsmooth_numbers(uint32_t n, uint32_t begin, uint32_t count) { uint32_t num = begin + count; mpz_t* numbers = find_nsmooth_numbers(n, num); printf(\"%u: \", n); mpz_out_str(stdout, 10, numbers[begin]); for (uint32_t i = 1; i < count; ++i) { printf(\", \"); mpz_out_str(stdout, 10, numbers[begin + i]); } printf(\"\\n\"); free_numbers(numbers, num); }", "after": "pub extern \"C\" fn print_nsmooth_numbers(mut n: u32, mut begin: u32, mut count: u32) { let mut num: u32 = begin.wrapping_add(count); print!(\"{}: \", n); let mut i: u32 = 1; while i < count { print!(\", \"); i = i.wrapping_add(1); i; } print!(\"\\n\"); }" }, { "index": 574, "before": "double sin_call(double_to_double *this, double x) { return sin(x); }", "after": "pub extern \"C\" fn sin_call(mut this: *mut double_to_double, mut x: f64) -> f64 { unsafe { return sin(x); } }" }, { "index": 575, "before": "int main() { double_to_double *my_sin = malloc(sizeof(double_to_double)); my_sin->fn = &sin_call; double_to_double *my_asin = malloc(sizeof(double_to_double)); my_asin->fn = &asin_call; double_to_double *sin_asin = compose(my_sin, my_asin); printf(\"%f\\n\", CALL(sin_asin, 0.5)); /* prints \"0.500000\" */ free(sin_asin); free(my_sin); free(my_asin); return 0; }", "after": "fn main() -> i32 { unsafe { let mut my_sin: *mut double_to_double = malloc(::core::mem::size_of::() as u64) as *mut double_to_double; (*my_sin).fn_0 = Some(sin_call as unsafe extern \"C\" fn(*mut double_to_double, f64) -> f64); let mut my_asin: *mut double_to_double = malloc(::core::mem::size_of::() as u64) as *mut double_to_double; (*my_asin).fn_0 = Some(asin_call as unsafe extern \"C\" fn(*mut double_to_double, f64) -> f64); let mut sin_asin: *mut double_to_double = compose(my_sin, my_asin); print!( \"{}\\n\", ((*sin_asin).fn_0).expect(\"non-null function pointer\")(sin_asin, 0.5f64) ); free(sin_asin as *mut libc::c_void); free(my_sin as *mut libc::c_void); free(my_asin as *mut libc::c_void); return 0; } }" }, { "index": 576, "before": "double compose_call(compose_functor *this, double x) { return CALL(this->f, CALL(this->g, x)); }", "after": "pub extern \"C\" fn compose_call(mut this: *mut compose_functor, mut x: f64) -> f64 { unsafe { return ((*(*this).f).fn_0).expect(\"non-null function pointer\")( (*this).f, ((*(*this).g).fn_0).expect(\"non-null function pointer\")((*this).g, x), ); } }" }, { "index": 577, "before": "double asin_call(double_to_double *this, double x) { return asin(x); }", "after": "pub extern \"C\" fn asin_call(mut this: *mut double_to_double, mut x: f64) -> f64 { unsafe { return asin(x); } }" }, { "index": 578, "before": "int main() { int i; for (i = 1; i <= 10; i++) { printf(\"%d\", i); printf(i == 10 ? \"\\n\" : \", \"); } return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; i = 1; while i <= 10 { print!(\"{}\", i); if i == 10 { print!(\"\\n\") } else { print!(\", \") }; i += 1; i; } return 0; }" }, { "index": 579, "before": "int decompose(xint n, xint *f) { pint p = 0; int i = 0; /* check small primes: not strictly necessary */ if (n <= MAX_PRIME && is_prime(n)) { f[0] = n; return 1; } while (n >= (xint)p * p) { if (!(p = next_prime(p))) break; while (n % p == 0) { n /= p; f[i++] = p; } } if (n > 1) f[i++] = n; return i; }", "after": "pub extern \"C\" fn decompose(mut n: u64, mut f: *mut u64) -> i32 { unsafe { let mut p: u32 = 0; let mut i: i32 = 0; if n <= !0 as u64 && is_prime(n) != 0 { *f.offset(0 as isize) = n; return 1; } while n >= (p as u64).wrapping_mul(p as u64) { p = next_prime(p); if p == 0 { break; } while n.wrapping_rem(p as u64) == 0 { n = (n as u64).wrapping_div(p as u64) as u64; let fresh1 = i; i = i + 1; *f.offset(fresh1 as isize) = p as u64; } } if n > 1 { let fresh2 = i; i = i + 1; *f.offset(fresh2 as isize) = n; } return i; } }" }, { "index": 580, "before": "int is_prime(xint x) { pint p; if (x > 5) { if (x < MAX_PRIME) return pbits[x/30] & bit_pos[x % 30]; for (p = 2; p && (xint)p * p <= x; p = next_prime(p)) if (x % p == 0) return 0; return 1; } return x == 2 || x == 3 || x == 5; }", "after": "pub extern \"C\" fn is_prime(mut x: u64) -> i32 { let mut p: u32 = 0; unsafe { if x > 5 { if x < !0 as u64 { return *pbits.offset(x.wrapping_div(30) as isize) as i32 & bit_pos[x.wrapping_rem(30) as usize] as i32; } p = 2; while p != 0 && (p as u64).wrapping_mul(p as u64) <= x { if x.wrapping_rem(p as u64) == 0 { return 0; } p = next_prime(p); } return 1; } } return (x == 2 || x == 3 || x == 5) as i32; }" }, { "index": 581, "before": "int main() { int i, len; pint p = 0; xint f[MAX_FACTORS], po; init_primes(); for (p = 1; p < 64; p++) { po = (1LLU << p) - 1; printf(\"2^%\"PRIuPINT\" - 1 = %\"PRIuXINT, p, po); fflush(stdout); if ((len = decompose(po, f)) > 1) for (i = 0; i < len; i++) printf(\" %c %\"PRIuXINT, i?'x':'=', f[i]); putchar('\\n'); } return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut len: i32 = 0; let mut p: u32 = 0; let mut f: [u64; 63] = [0; 63]; let mut po: u64 = 0; init_primes(); p = 1; unsafe { while p < 64 { po = (1u64 << p).wrapping_sub(1) as u64; print!(\"2^{} - 1 = {}\", p, po); fflush(stdout); len = decompose(po, f.as_mut_ptr()); if len > 1 { i = 0; while i < len { if i != 0 { print!(\" {} {}\", 'x' as i32, f[i as usize]) } else { print!(\" {} {}\", '=' as i32, f[i as usize]) }; i += 1; i; } } print!(\"{}\", '\\n' as i32); p = p.wrapping_add(1); p; } } return 0; }" }, { "index": 582, "before": "void init_primes() { FILE *fp; pint s, tgt = 4; if (!(pbits = malloc(PBITS))) { perror(\"malloc\"); exit(1); } if ((fp = fopen(\"primebits\", \"r\"))) { fread(pbits, 1, PBITS, fp); fclose(fp); return; } memset(pbits, 255, PBITS); for (s = 7; s <= MAX_PRIME_SQ; s = next_prime(s)) { if (s > tgt) { tgt *= 2; fprintf(stderr, \"sieve %\"PRIuPINT\"\\n\", s); } sieve(s); } fp = fopen(\"primebits\", \"w\"); fwrite(pbits, 1, PBITS, fp); fclose(fp); }", "after": "pub extern \"C\" fn init_primes() { unsafe { let mut fp: *mut FILE = 0 as *mut FILE; let mut s: u32 = 0; let mut tgt: u32 = 4; pbits = malloc((!0u32).wrapping_div(30).wrapping_add(1) as u64) as *mut u8; if pbits.is_null() { perror(b\"malloc\\0\" as *const u8 as *const i8); exit(1); } fp = fopen( b\"primebits\\0\" as *const u8 as *const i8, b\"r\\0\" as *const u8 as *const i8, ); if !fp.is_null() { fread( pbits as *mut libc::c_void, 1, (!0u32).wrapping_div(30).wrapping_add(1) as u64, fp, ); fclose(fp); return; } memset( pbits as *mut libc::c_void, 255, (!0u32).wrapping_div(30).wrapping_add(1) as u64, ); s = 7; while s <= 65535 { if s > tgt { tgt = (tgt).wrapping_mul(2) as u32; fprintf(stderr, b\"sieve %u\\n\\0\" as *const u8 as *const i8, s); } sieve(s); s = next_prime(s); } fp = fopen( b\"primebits\\0\" as *const u8 as *const i8, b\"w\\0\" as *const u8 as *const i8, ); fwrite( pbits as *const libc::c_void, 1, (!0u32).wrapping_div(30).wrapping_add(1) as u64, fp, ); fclose(fp); } }" }, { "index": 583, "before": "pint next_prime(pint p) { off_t addr; uint8_t bits, rem; if (p > 5) { addr = p / 30; bits = bit_pos[ p % 30 ] << 1; for (rem = 0; (1 << rem) < bits; rem++); while (pbits[addr] < bits || !bits) { if (++addr >= PBITS) return 0; bits = 1; rem = 0; } if (addr >= PBITS) return 0; while (!(pbits[addr] & bits)) { rem++; bits <<= 1; } return p = addr * 30 + rem_num[rem]; } switch(p) { case 2: return 3; case 3: return 5; case 5: return 7; } return 2; }", "after": "pub extern \"C\" fn next_prime(mut p: u32) -> u32 { let mut addr: i64 = 0; let mut bits: u8 = 0; let mut rem: u8 = 0; unsafe { if p > 5 { addr = p.wrapping_div(30) as i64; bits = ((bit_pos[p.wrapping_rem(30u32) as usize] as i32) << 1) as u8; rem = 0; while (1 << rem as i32) < bits as i32 { rem = rem.wrapping_add(1); rem; } while (*pbits.offset(addr as isize) as i32) < bits as i32 || bits == 0 { addr += 1; if addr >= (!0u32).wrapping_div(30).wrapping_add(1) as i64 { return 0; } bits = 1; rem = 0; } if addr >= (!0u32).wrapping_div(30).wrapping_add(1) as i64 { return 0; } while *pbits.offset(addr as isize) as i32 & bits as i32 == 0 { rem = rem.wrapping_add(1); rem; bits = ((bits as i32) << 1i32) as u8; } p = (addr * 30 + rem_num[rem as usize] as i64) as u32; return p; } } match p { 2 => return 3, 3 => return 5, 5 => return 7, _ => {} } return 2; }" }, { "index": 584, "before": "void sieve(pint p) { unsigned char b[8]; off_t ofs[8]; int i, q; for (i = 0; i < 8; i++) { q = rem_num[i] * p; b[i] = ~bit_pos[q % 30]; ofs[i] = q / 30; } for (q = ofs[1], i = 7; i; i--) ofs[i] -= ofs[i-1]; for (ofs[0] = p, i = 1; i < 8; i++) ofs[0] -= ofs[i]; for (i = 1; q < PBITS; q += ofs[i = (i + 1) & 7]) pbits[q] &= b[i]; }", "after": "pub extern \"C\" fn sieve(mut p: u32) { let mut b: [u8; 8] = [0; 8]; let mut ofs: [i64; 8] = [0; 8]; let mut i: i32 = 0; let mut q: i32 = 0; i = 0; unsafe { while i < 8 { q = (rem_num[i as usize] as u32).wrapping_mul(p) as i32; b[i as usize] = !(bit_pos[(q % 30i32) as usize] as i32) as u8; ofs[i as usize] = (q / 30i32) as i64; i += 1; i; } } q = ofs[1 as usize] as i32; i = 7; while i != 0 { ofs[i as usize] -= ofs[(i - 1i32) as usize]; i -= 1; i; } ofs[0 as usize] = p as i64; i = 1; while i < 8 { ofs[0 as usize] -= ofs[i as usize]; i += 1; i; } i = 1; unsafe { while (q as u32) < (!0u32).wrapping_div(30).wrapping_add(1) { let ref mut fresh0 = *pbits.offset(q as isize); *fresh0 = (*fresh0 as i32 & b[i as usize] as i32) as u8; i = i + 1 & 7; q = (q as i64 + ofs[i as usize]) as i32; } } }" }, { "index": 585, "before": "int hailstone(int n, int *arry) { int hs = 1; while (n!=1) { hs++; if (arry) *arry++ = n; n = (n&1) ? (3*n+1) : (n/2); } if (arry) *arry++ = n; return hs; }", "after": "pub extern \"C\" fn hailstone(mut n: i32, mut arry: *mut i32) -> i32 { unsafe { let mut hs: i32 = 1; while n != 1 { hs += 1; hs; if !arry.is_null() { let fresh0 = arry; arry = arry.offset(1); *fresh0 = n; } n = if n & 1 != 0 { 3 * n + 1 } else { n / 2 }; } if !arry.is_null() { let fresh1 = arry; arry = arry.offset(1); *fresh1 = n; } return hs; } }" }, { "index": 586, "before": "int main() { int j, hmax = 0; int jatmax, n; int *arry; for (j=1; j<100000; j++) { n = hailstone(j, NULL); if (hmax < n) { hmax = n; jatmax = j; } } n = hailstone(27, NULL); arry = malloc(n*sizeof(int)); n = hailstone(27, arry); printf(\"[ %d, %d, %d, %d, ...., %d, %d, %d, %d] len=%d\\n\", arry[0],arry[1],arry[2],arry[3], arry[n-4], arry[n-3], arry[n-2], arry[n-1], n); printf(\"Max %d at j= %d\\n\", hmax, jatmax); free(arry); return 0; }", "after": "fn main() -> i32 { unsafe { let mut j: i32 = 0; let mut hmax: i32 = 0; let mut jatmax: i32 = 0; let mut n: i32 = 0; let mut arry: *mut i32 = 0 as *mut i32; j = 1; while j < 100000 { n = hailstone(j, 0 as *mut i32); if hmax < n { hmax = n; jatmax = j; } j += 1; j; } n = hailstone(27, 0 as *mut i32); arry = malloc((n as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i32; n = hailstone(27, arry); print!( \"[ {}, {}, {}, {}, ...., {}, {}, {}, {}] len={}\\n\", *arry.offset(0 as isize), *arry.offset(1 as isize), *arry.offset(2 as isize), *arry.offset(3 as isize), *arry.offset((n - 4i32) as isize), *arry.offset((n - 3i32) as isize), *arry.offset((n - 2i32) as isize), *arry.offset((n - 1i32) as isize), n ); print!(\"Max {} at j= {}\\n\", hmax, jatmax); free(arry as *mut libc::c_void); return 0; } }" }, { "index": 587, "before": "int main(void) { int *array, n = 10; array = (int *)malloc((n + 1) * sizeof(int)); sieve(array, n); return 0; }", "after": "fn main() -> i32 { unsafe { let mut array: *mut i32 = 0 as *mut i32; let mut n: i32 = 10; array = malloc(((n + 1i32) as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i32; sieve(array, n); return 0; } }" }, { "index": 588, "before": "void sieve(int *a, int n) { int i = 0, j = 0; for (i = 2; i <= n; i++) { a[i] = 1; } for (i = 2; i <= n; i++) { printf(\"\\ni:%d\", i); if (a[i] == 1) { for (j = i; (i * j) <= n; j++) { printf(\"\\nj:%d\", j); printf(\"\\nBefore a[%d*%d]: %d\", i, j, a[i * j]); a[(i * j)] = 0; printf(\"\\nAfter a[%d*%d]: %d\", i, j, a[i * j]); } } } printf(\"\\nPrimes numbers from 1 to %d are : \", n); for (i = 2; i <= n; i++) { if (a[i] == 1) printf(\"%d, \", i); } printf(\"\\n\\n\"); }", "after": "pub extern \"C\" fn sieve(mut a: *mut i32, mut n: i32) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; i = 2; while i <= n { *a.offset(i as isize) = 1; i += 1; i; } i = 2; while i <= n { print!(\"\\ni:{}\", i); if *a.offset(i as isize) == 1 { j = i; while i * j <= n { print!(\"\\nj:{}\", j); printf( b\"\\nBefore a[%d*%d]: %d\\0\" as *const u8 as *const i8, i, j, *a.offset((i * j) as isize), ); *a.offset((i * j) as isize) = 0; printf( b\"\\nAfter a[%d*%d]: %d\\0\" as *const u8 as *const i8, i, j, *a.offset((i * j) as isize), ); j += 1; j; } } i += 1; i; } print!(\"\\nPrimes numbers from 1 to {} are : \", n); i = 2; while i <= n { if *a.offset(i as isize) == 1 { print!(\"{}, \", i); } i += 1; i; } print!(\"\\n\\n\"); } }" }, { "index": 589, "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": "fn main() -> i32 { unsafe { let mut i: i32 = 0; let mut ix: i32 = 0; let mut n: i32 = 0; let mut lim: i32 = 1000035; let mut pairs: i32 = 0; let mut trips: i32 = 0; let mut quads: i32 = 0; let mut quins: i32 = 0; let mut unsexy: i32 = 2; let mut pr: i32 = 0; let mut tr: i32 = 0; let mut qd: i32 = 0; let mut qn: i32 = 0; let mut un: i32 = 2; let mut lpr: i32 = 5; let mut ltr: i32 = 5; let mut lqd: i32 = 5; let mut lqn: i32 = 5; let mut lun: i32 = 10; let mut last_pr: [[i32; 2]; 5] = [[0; 2]; 5]; let mut last_tr: [[i32; 3]; 5] = [[0; 3]; 5]; let mut last_qd: [[i32; 4]; 5] = [[0; 4]; 5]; let mut last_qn: [[i32; 5]; 5] = [[0; 5]; 5]; let mut last_un: [i32; 10] = [0; 10]; let mut sv: *mut u8 = calloc((lim - 1i32) as u64, ::core::mem::size_of::() as u64) as *mut u8; setlocale(1, b\"\\0\" as *const u8 as *const i8); sieve(sv, lim); i = 3; while i < lim { if i > 5 && i < lim - 6 && *sv.offset(i as isize) == 0 && *sv.offset((i - 6i32) as isize) as i32 != 0 && *sv.offset((i + 6i32) as isize) as i32 != 0 { unsexy += 1; unsexy; } else if i < lim - 6 && *sv.offset(i as isize) == 0 && *sv.offset((i + 6i32) as isize) == 0 { pairs += 1; pairs; if i < lim - 12 && *sv.offset((i + 12i32) as isize) == 0 { trips += 1; trips; if i < lim - 18 && *sv.offset((i + 18i32) as isize) == 0 { quads += 1; quads; if i < lim - 24 && *sv.offset((i + 24i32) as isize) == 0 { quins += 1; quins; } } } } i += 2; } 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; while i < lim { if i > 5 && i < lim - 6 && *sv.offset(i as isize) == 0 && *sv.offset((i - 6i32) as isize) as i32 != 0 && *sv.offset((i + 6i32) as isize) as i32 != 0 { un += 1; un; if un > unsexy - lun { last_un[(un + lun - 1 - unsexy) as usize] = i; } } else if i < lim - 6 && *sv.offset(i as isize) == 0 && *sv.offset((i + 6i32) as isize) == 0 { pr += 1; pr; if pr > pairs - lpr { ix = pr + lpr - 1 - pairs; last_pr[ix as usize][0 as usize] = i; last_pr[ix as usize][1 as usize] = i + 6; } if i < lim - 12 && *sv.offset((i + 12i32) as isize) == 0 { tr += 1; tr; if tr > trips - ltr { ix = tr + ltr - 1 - trips; last_tr[ix as usize][0 as usize] = i; last_tr[ix as usize][1 as usize] = i + 6; last_tr[ix as usize][2 as usize] = i + 12; } if i < lim - 18 && *sv.offset((i + 18i32) as isize) == 0 { qd += 1; qd; if qd > quads - lqd { ix = qd + lqd - 1 - quads; last_qd[ix as usize][0 as usize] = i; last_qd[ix as usize][1 as usize] = i + 6; last_qd[ix as usize][2 as usize] = i + 12; last_qd[ix as usize][3 as usize] = i + 18; } if i < lim - 24 && *sv.offset((i + 24i32) as isize) == 0 { qn += 1; qn; if qn > quins - lqn { ix = qn + lqn - 1 - quins; last_qn[ix as usize][0 as usize] = i; last_qn[ix as usize][1 as usize] = i + 6; last_qn[ix as usize][2 as usize] = i + 12; last_qn[ix as usize][3 as usize] = i + 18; last_qn[ix as usize][4 as usize] = i + 24; } } } } } i += 2; } printHelper(b\"pairs\\0\" as *const u8 as *const i8, pairs, lim, lpr); print!(\" [\"); i = 0; while i < lpr { printArray((last_pr[i as usize]).as_mut_ptr(), 2); print!(\"\\x08] \"); i += 1; i; } print!(\"\\x08]\\n\\n\"); printHelper(b\"triplets\\0\" as *const u8 as *const i8, trips, lim, ltr); print!(\" [\"); i = 0; while i < ltr { printArray((last_tr[i as usize]).as_mut_ptr(), 3); print!(\"\\x08] \"); i += 1; i; } print!(\"\\x08]\\n\\n\"); printHelper(b\"quadruplets\\0\" as *const u8 as *const i8, quads, lim, lqd); print!(\" [\"); i = 0; while i < lqd { printArray((last_qd[i as usize]).as_mut_ptr(), 4); print!(\"\\x08] \"); i += 1; i; } print!(\"\\x08]\\n\\n\"); printHelper(b\"quintuplets\\0\" as *const u8 as *const i8, quins, lim, lqn); print!(\" [\"); i = 0; while i < lqn { printArray((last_qn[i as usize]).as_mut_ptr(), 5); print!(\"\\x08] \"); i += 1; i; } print!(\"\\x08]\\n\\n\"); printHelper( b\"unsexy primes\\0\" as *const u8 as *const i8, unsexy, lim, lun, ); print!(\" [\"); printArray(last_un.as_mut_ptr(), lun); print!(\"\\x08]\\n\"); free(sv as *mut libc::c_void); return 0; } }" }, { "index": 590, "before": "void printArray(int *a, int len) { int i; printf(\"[\"); for (i = 0; i < len; ++i) printf(\"%d \", a[i]); printf(\"\\b]\"); }", "after": "pub extern \"C\" fn printArray(mut a: *mut i32, mut len: i32) { unsafe { let mut i: i32 = 0; print!(\"[\"); i = 0; while i < len { print!(\"{} \", *a.offset(i as isize)); i += 1; i; } print!(\"\\x08]\"); } }" }, { "index": 591, "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 extern \"C\" fn sieve(mut c: *mut u8, mut limit: i32) { unsafe { let mut i: i32 = 0; let mut p: i32 = 3; let mut p2: i32 = 0; *c.offset(0 as isize) = 1; *c.offset(1 as isize) = 1; loop { p2 = p * p; if p2 >= limit { break; } i = p2; while i < limit { *c.offset(i as isize) = 1; i += 2 * p; } loop { p += 2; if *c.offset(p as isize) == 0 { break; } } } } }" }, { "index": 592, "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 extern \"C\" fn printHelper(mut cat: *const i8, mut len: i32, mut lim: i32, mut n: i32) { unsafe { let mut sp: *const i8 = if strcmp(cat, b\"unsexy primes\\0\" as *const u8 as *const i8) != 0 { b\"sexy prime \\0\" as *const u8 as *const i8 } else { b\"\\0\" as *const u8 as *const i8 }; let mut verb: *const i8 = if len == 1 { b\"is\\0\" as *const u8 as *const i8 } else { b\"are\\0\" as *const u8 as *const i8 }; print!( \"Number of {}{} less than {} = {}\\n\", build_str_from_raw_ptr(sp as *mut u8), build_str_from_raw_ptr(cat as *mut u8), lim, len ); print!( \"The last {} {}:\\n\", n, build_str_from_raw_ptr(verb as *mut u8) ); } }" }, { "index": 593, "before": "Delegator NewDelegator( int p, char *phrase) { Delegator d = malloc(sizeof(struct sDelegator)); d->param = p; d->phrase = phrase; d->delegate = &defaultDel;\t/* default delegate */ return d; }", "after": "pub extern \"C\" fn NewDelegator(mut p: i32, mut phrase: *mut i8) -> Delegator { unsafe { let mut d: Delegator = malloc(::core::mem::size_of::() as u64) as Delegator; (*d).param = p; (*d).phrase = phrase; (*d).delegate = &mut defaultDel; return d; } }" }, { "index": 594, "before": "Delegate NewDelegate( Responder rspndr ) { Delegate dl = malloc(sizeof(struct sDelegate)); dl->operation = rspndr; return dl; }", "after": "pub extern \"C\" fn NewDelegate(mut rspndr: Responder) -> Delegate { unsafe { let mut dl: Delegate = malloc(::core::mem::size_of::() as u64) as Delegate; (*dl).operation = rspndr; return dl; } }" }, { "index": 595, "before": "int main() { Delegate del1 = NewDelegate(&thing1); Delegate del2 = NewDelegate(NULL); Delegator theDelegator = NewDelegator( 14, \"A stellar vista, Baby.\"); printf(\"Delegator returns %s\\n\\n\", Delegator_Operation( theDelegator, 3, NULL)); printf(\"Delegator returns %s\\n\\n\", Delegator_Operation( theDelegator, 3, del1)); printf(\"Delegator returns %s\\n\\n\", Delegator_Operation( theDelegator, 3, del2)); return 0; }", "after": "fn main() -> i32 { unsafe { let mut del1: Delegate = NewDelegate(Some(thing1 as unsafe extern \"C\" fn(i32) -> *const i8)); let mut del2: Delegate = NewDelegate(None); let mut theDelegator: Delegator = NewDelegator( 14, b\"A stellar vista, Baby.\\0\" as *const u8 as *const i8 as *mut i8, ); print!( \"Delegator returns {}\\n\\n\", build_str_from_raw_ptr(Delegator_Operation(theDelegator, 3, 0 as Delegate) as *mut u8) ); print!( \"Delegator returns {}\\n\\n\", build_str_from_raw_ptr(Delegator_Operation(theDelegator, 3, del1) as *mut u8) ); print!( \"Delegator returns {}\\n\\n\", build_str_from_raw_ptr(Delegator_Operation(theDelegator, 3, del2) as *mut u8) ); } return 0; }" }, { "index": 596, "before": "int main() { //loop variables int k, n; //necessarily ull for reach big values unsigned long long int num, den; //the nmmber int catalan; //the first is not calculated for the formula printf(\"1 \"); //iterating from 2 to 15 for (n=2; n<=N; ++n) { //initializaing for products num = den = 1; //applying the formula for (k=2; k<=n; ++k) { num *= (n+k); den *= k; catalan = num /den; } //output printf(\"%d \", catalan); } //the end printf(\"\\n\"); return 0; }", "after": "fn main() -> i32 { let mut k: i32 = 0; let mut n: i32 = 0; let mut num: u64 = 0; let mut den: u64 = 0; let mut catalan: i32 = 0; print!(\"1 \"); n = 2; unsafe { while n <= N { den = 1; num = den; k = 2; while k <= n { num = num.wrapping_mul((n + k) as u64); den = den.wrapping_mul(k as u64); catalan = num.wrapping_div(den) as i32; k += 1; k; } print!(\"{} \", catalan); n += 1; n; } } print!(\"\\n\"); return 0; }" }, { "index": 597, "before": "int main() { printf(\"%d\\n\", ethiopian(17, 34, true)); return 0; }", "after": "fn main() -> i32 { print!(\"{}\\n\", ethiopian(17, 34, 1 != 0)); return 0; }" }, { "index": 598, "before": "void doublit(int *x) { *x <<= 1; }", "after": "pub extern \"C\" fn doublit(mut x: *mut i32) { unsafe { *x <<= 1; } }" }, { "index": 599, "before": "void halve(int *x) { *x >>= 1; }", "after": "pub extern \"C\" fn halve(mut x: *mut i32) { unsafe { *x >>= 1; } }" }, { "index": 600, "before": "bool iseven(const int x) { return (x & 1) == 0; }", "after": "pub extern \"C\" fn iseven(x: i32) -> bool { return x & 1 == 0; }" }, { "index": 601, "before": "int ethiopian(int plier, \t int plicand, const bool tutor) { int result=0; if (tutor) printf(\"ethiopian multiplication of %d by %d\\n\", plier, plicand); while(plier >= 1) { if ( iseven(plier) ) { if (tutor) printf(\"%4d %6d struck\\n\", plier, plicand); } else { if (tutor) printf(\"%4d %6d kept\\n\", plier, plicand); result += plicand; } halve(&plier); doublit(&plicand); } return result; }", "after": "pub extern \"C\" fn ethiopian(mut plier: i32, mut plicand: i32, tutor: bool) -> i32 { let mut result: i32 = 0; if tutor { print!(\"ethiopian multiplication of {} by {}\\n\", plier, plicand); } while plier >= 1 { if iseven(plier) { if tutor { print!(\"{:4} {:6} struck\\n\", plier, plicand); } } else { if tutor { print!(\"{:4} {:6} kept\\n\", plier, plicand); } result += plicand; } halve(&mut plier); doublit(&mut plicand); } return result; }" }, { "index": 602, "before": "int main(void) { int n; for( n = 99; n > 2; n-- ) printf( \"%d bottles of beer on the wall, %d bottles of beer.\\n\" \"Take one down and pass it around, %d bottles of beer on the wall.\\n\\n\", n, n, n - 1); printf( \"2 bottles of beer on the wall, 2 bottles of beer.\\n\" \"Take one down and pass it around, 1 bottle of beer on the wall.\\n\\n\" \"1 bottle of beer on the wall, 1 bottle of beer.\\n\" \"Take one down and pass it around, no more bottles of beer on the wall.\\n\\n\" \"No more bottles of beer on the wall, no more bottles of beer.\\n\" \"Go to the store and buy some more, 99 bottles of beer on the wall.\\n\"); return 0; }", "after": "fn main() -> i32 { let mut n: i32 = 0; n = 99; while n > 2 { print! (\"{} bottles of beer on the wall, {} bottles of beer.\\nTake one down and pass it around, {} bottles of beer on the wall.\\n\\n\", n, n, n - 1); n -= 1; n; } print! ( \"2 bottles of beer on the wall, 2 bottles of beer.\\nTake one down and pass it around, 1 bottle of beer on the wall.\\n\\n1 bottle of beer on the wall, 1 bottle of beer.\\nTake one down and pass it around, no more bottles of beer on the wall.\\n\\nNo more bottles of beer on the wall, no more bottles of beer.\\nGo to the store and buy some more, 99 bottles of beer on the wall.\\n\" ); return 0; }" }, { "index": 603, "before": "void set_input(integ x, double (*func)(double)) { \tupdate(x); \tx->func = func; \tx->last_t = 0; \tx->last_v = func ? func(0) : 0; }", "after": "pub extern \"C\" fn set_input(mut x: integ, mut func: Option f64>) { update(x); unsafe { (*x).func = func; } (*x).last_t = 0 as f64; unsafe { (*x).last_v = if func.is_some() { func.expect(\"non-null function pointer\")(0 as f64) } else { 0 as f64 }; } }" }, { "index": 604, "before": "integ new_integ(double (*func)(double)) { \tinteg x = malloc(sizeof(integ_t)); \tx->v = x->last_v = 0; \tx->func = 0; \tgettimeofday(&x->start, 0); \tset_input(x, func); \tpthread_create(&x->id, 0, tick, x); \treturn x; }", "after": "pub extern \"C\" fn new_integ(mut func: Option f64>) -> integ { unsafe { let mut x: integ = malloc(::core::mem::size_of::() as u64) as integ; (*x).last_v = 0 as f64; (*x).v = (*x).last_v; (*x).func = None; gettimeofday(&mut (*x).start, 0 as *mut libc::c_void); set_input(x, func); pthread_create( &mut (*x).id, 0 as *const pthread_attr_t, Some(tick as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), x as *mut libc::c_void, ); return x; } }" }, { "index": 605, "before": "int main() { \tinteg x = new_integ(sine); \tsleep(2); \tset_input(x, 0); \tusleep(500000); \tprintf(\"%g\\n\", x->v); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut x: integ = new_integ(Some(sine as unsafe extern \"C\" fn(f64) -> f64)); sleep(2); set_input(x, None); usleep(500000); print!(\"{}\\n\", (*x).v); } return 0; }" }, { "index": 606, "before": "void update(integ x) { \tstruct timeval tv; \tdouble t, v, (*f)(double); \tf = x->func; \tgettimeofday(&tv, 0); \tt = ((tv.tv_sec - x->start.tv_sec) * 1000000 \t\t+ tv.tv_usec - x->start.tv_usec) * 1e-6; \tv = f ? f(t) : 0; \tx->v += (x->last_v + v) * (t - x->last_t) / 2; \tx->last_t = t; }", "after": "pub extern \"C\" fn update(mut x: integ) { let mut tv: timeval = timeval { tv_sec: 0, tv_usec: 0, }; let mut t: f64 = 0.; let mut v: f64 = 0.; unsafe { let mut f: Option f64> = None; f = (*x).func; gettimeofday(&mut tv, 0 as *mut libc::c_void); t = ((tv.tv_sec - (*x).start.tv_sec) * 1000000 + tv.tv_usec - (*x).start.tv_usec) as f64 * 1e-6f64; v = if f.is_some() { f.expect(\"non-null function pointer\")(t) } else { 0 as f64 }; } (*x).v += ((*x).last_v + v) * (t - (*x).last_t) / 2 as f64; (*x).last_t = t; }" }, { "index": 607, "before": "double sine(double t) { return sin(4 * atan2(1, 1) * t); }", "after": "pub extern \"C\" fn sine(mut t: f64) -> f64 { unsafe { return sin(4 as f64 * atan2(1 as f64, 1 as f64) * t); } }" }, { "index": 608, "before": "int main(int argc,char** argv) { functionPair response; if(argc!=2) return printf(\"Usage : %s \",argv[0]); else{ response = (functionPair){.x = atoi(argv[1]),.funcPtr=&factorial}; printf(\"\\nFactorial of %d is %d\\n\",response.x,response.funcPtr(response.x)); } return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut response: functionPair = functionPair { x: 0, funcPtr: None, }; if argc != 2 { let str_to_print = format!( \"Usage : {} \", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); print!(\"{}\", str_to_print); return str_to_print.chars().count() as i32; } else { response = { let mut init = functionPair { x: atoi(*argv.offset(1 as isize)), funcPtr: Some(factorial as unsafe extern \"C\" fn(i32) -> i32), }; init }; print!( \"\\nFactorial of {} is {}\\n\", response.x, (response.funcPtr).expect(\"non-null function pointer\")(response.x) ); } return 0; } }" }, { "index": 609, "before": "int factorial(int num){ if(num==0||num==1) return 1; else return num*factorial(num-1); }", "after": "pub extern \"C\" fn factorial(mut num: i32) -> i32 { if num == 0 || num == 1 { return 1; } else { return num * factorial(num - 1); }; }" }, { "index": 610, "before": "int is_prime(uint n) { if (!(n%2) || !(n%3)) return 0; uint p = 1; while(p*p < n) if (n%(p += 4) == 0 || n%(p += 2) == 0) return 0; return 1; }", "after": "pub extern \"C\" fn is_prime(mut n: u32) -> i32 { if n.wrapping_rem(2) == 0 || n.wrapping_rem(3) == 0 { return 0; } let mut p: u32 = 1; while p.wrapping_mul(p) < n { p = (p).wrapping_add(4) as u32; if n.wrapping_rem(p) == 0 || { p = (p).wrapping_add(2) as u32; n.wrapping_rem(p) == 0 } { return 0; } } return 1; }" }, { "index": 611, "before": "uint reverse(uint n) { uint r; for (r = 0; n; n /= 10) r = r*10 + (n%10); return r; }", "after": "pub extern \"C\" fn reverse(mut n: u32) -> u32 { let mut r: u32 = 0; r = 0; while n != 0 { r = r.wrapping_mul(10).wrapping_add(n.wrapping_rem(10)); n = (n as u32).wrapping_div(10) as u32; } return r; }" }, { "index": 612, "before": "int main(int argc, char **argv) { uint x, c = 0; switch(argc) { // advanced args parsing case 1: for (x = 11; c < 20; x += 2) if (is_emirp(x)) printf(\" %u\", x), ++c; break; case 2: for (x = 7701; x < 8000; x += 2) if (is_emirp(x)) printf(\" %u\", x); break; default: for (x = 11; ; x += 2) if (is_emirp(x) && ++c == 10000) { printf(\"%u\", x); break; } } putchar('\\n'); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut x: u32 = 0; let mut c: u32 = 0; match argc { 1 => { x = 11; while c < 20 { if is_emirp(x) != 0 { print!(\" {}\", x); c = c.wrapping_add(1); c; } x = (x).wrapping_add(2) as u32; } } 2 => { x = 7701; while x < 8000 { if is_emirp(x) != 0 { print!(\" {}\", x); } x = (x).wrapping_add(2) as u32; } } _ => { x = 11; loop { if is_emirp(x) != 0 && { c = c.wrapping_add(1); c == 10000 } { print!(\"{}\", x); break; } else { x = (x).wrapping_add(2) as u32; } } } } print!(\"{}\", '\\n' as i32); return 0; } }" }, { "index": 613, "before": "int is_emirp(uint n) { uint r = reverse(n); return r != n && is_prime(n) && is_prime(r); }", "after": "pub extern \"C\" fn is_emirp(mut n: u32) -> i32 { let mut r: u32 = reverse(n); return (r != n && is_prime(n) != 0 && is_prime(r) != 0) as i32; }" }, { "index": 614, "before": "bit_filter b_attach(FILE *f) { bit_filter b = malloc(sizeof(bit_io_t)); b->bits = b->accu = 0; b->fp = f; return b; }", "after": "pub extern \"C\" fn b_attach(mut f: *mut FILE) -> bit_filter { unsafe { let mut b: bit_filter = malloc(::core::mem::size_of::() as u64) as bit_filter; (*b).accu = 0; (*b).bits = (*b).accu as i32; (*b).fp = f; return b; } }" }, { "index": 615, "before": "void b_detach(bit_filter bf) { if (bf->bits) { bf->accu <<= 8 - bf->bits; fputc(bf->accu, bf->fp); } free(bf); }", "after": "pub extern \"C\" fn b_detach(mut bf: bit_filter) { unsafe { if (*bf).bits != 0 { (*bf).accu <<= 8 - (*bf).bits; fputc((*bf).accu as i32, (*bf).fp); } free(bf as *mut libc::c_void); } }" }, { "index": 616, "before": "int main() { unsigned char s[] = \"abcdefghijk\"; unsigned char s2[11] = {0}; int i; FILE *f = fopen(\"test.bin\", \"wb\"); bit_filter b = b_attach(f); /* for each byte in s, write 7 bits skipping 1 */ for (i = 0; i < 10; i++) b_write(s + i, 7, 1, b); b_detach(b); fclose(f); /* read 7 bits and expand to each byte of s2 skipping 1 bit */ f = fopen(\"test.bin\", \"rb\"); b = b_attach(f); for (i = 0; i < 10; i++) b_read(s2 + i, 7, 1, b); b_detach(b); fclose(f); printf(\"%10s\\n\", s2); /* should be the same first 10 bytes as in s */ return 0; }", "after": "fn main() -> i32 { unsafe { let mut s: [u8; 12] = *::core::mem::transmute::<&[u8; 12], &mut [u8; 12]>(b\"abcdefghijk\\0\"); let mut s2: [u8; 11] = [0; 11]; let mut i: i32 = 0; let mut f: *mut FILE = fopen( b\"test.bin\\0\" as *const u8 as *const i8, b\"wb\\0\" as *const u8 as *const i8, ); let mut b: bit_filter = b_attach(f); i = 0; while i < 10 { b_write(s.as_mut_ptr().offset(i as isize), 7, 1, b); i += 1; i; } b_detach(b); fclose(f); f = fopen( b\"test.bin\\0\" as *const u8 as *const i8, b\"rb\\0\" as *const u8 as *const i8, ); b = b_attach(f); i = 0; while i < 10 { b_read(s2.as_mut_ptr().offset(i as isize), 7, 1, b); i += 1; i; } b_detach(b); fclose(f); print!( \"{:10}\\n\", build_str_from_raw_ptr(s2.as_mut_ptr() as *mut u8) ); return 0; } }" }, { "index": 617, "before": "void b_write(byte *buf, size_t n_bits, size_t shift, bit_filter bf) { uint32_t accu = bf->accu; int bits = bf->bits; buf += shift / 8; shift %= 8; while (n_bits || bits >= 8) { while (bits >= 8) { bits -= 8; fputc(accu >> bits, bf->fp); accu &= (1 << bits) - 1; } while (bits < 8 && n_bits) { accu = (accu << 1) | (((128 >> shift) & *buf) >> (7 - shift)); --n_bits; bits++; if (++shift == 8) { shift = 0; buf++; } } } bf->accu = accu; bf->bits = bits; }", "after": "pub extern \"C\" fn b_write(mut buf: *mut u8, mut n_bits: u64, mut shift: u64, mut bf: bit_filter) { unsafe { let mut accu: u32 = (*bf).accu; let mut bits: i32 = (*bf).bits; buf = buf.offset(shift.wrapping_div(8) as isize); shift = (shift as u64).wrapping_rem(8) as u64; while n_bits != 0 || bits >= 8 { while bits >= 8 { bits -= 8; fputc((accu >> bits) as i32, (*bf).fp); accu &= ((1i32 << bits) - 1) as u32; } while bits < 8 && n_bits != 0 { accu = accu << 1 | ((128 >> shift & *buf as i32) >> 7u64.wrapping_sub(shift)) as u32; n_bits = n_bits.wrapping_sub(1); n_bits; bits += 1; bits; shift = shift.wrapping_add(1); if shift == 8 { shift = 0; buf = buf.offset(1); buf; } } } (*bf).accu = accu; (*bf).bits = bits; } }" }, { "index": 618, "before": "size_t b_read(byte *buf, size_t n_bits, size_t shift, bit_filter bf) { uint32_t accu = bf->accu; int bits = bf->bits; int mask, i = 0; buf += shift / 8; shift %= 8; while (n_bits) { while (bits && n_bits) { mask = 128 >> shift; if (accu & (1 << (bits - 1))) *buf |= mask; else *buf &= ~mask; n_bits--; bits--; if (++shift >= 8) { shift = 0; buf++; } } if (!n_bits) break; accu = (accu << 8) | fgetc(bf->fp); bits += 8; } bf->accu = accu; bf->bits = bits; return i; }", "after": "pub extern \"C\" fn b_read( mut buf: *mut u8, mut n_bits: u64, mut shift: u64, mut bf: bit_filter, ) -> u64 { unsafe { let mut accu: u32 = (*bf).accu; let mut bits: i32 = (*bf).bits; let mut mask: i32 = 0; let mut i: i32 = 0; buf = buf.offset(shift.wrapping_div(8) as isize); shift = (shift as u64).wrapping_rem(8) as u64; while n_bits != 0 { while bits != 0 && n_bits != 0 { mask = 128 >> shift; if accu & (1i32 << bits - 1) as u32 != 0 { *buf = (*buf as i32 | mask) as u8; } else { *buf = (*buf as i32 & !mask) as u8; } n_bits = n_bits.wrapping_sub(1); n_bits; bits -= 1; bits; shift = shift.wrapping_add(1); if shift >= 8 { shift = 0; buf = buf.offset(1); buf; } } if n_bits == 0 { break; } accu = accu << 8 | fgetc((*bf).fp) as u32; bits += 8; } (*bf).accu = accu; (*bf).bits = bits; return i as u64; } }" }, { "index": 619, "before": "int main(void) { \tprintf(\"10! = %d\\n\", val); \treturn 0; }", "after": "fn main() -> i32 { unsafe { print!(\"10! = {}\\n\", val); } return 0; }" }, { "index": 620, "before": "int main(void) { unsigned int i; int *c = ARRAY_CONCAT(int, a, 5, b, 5); for (i = 0; i < 10; i++) printf(\"%d\\n\", c[i]); free(c); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { unsafe { let mut i: u32 = 0; let mut c: *mut i32 = array_concat( a.as_ptr() as *const libc::c_void, 5, b.as_ptr() as *const libc::c_void, 5, ::core::mem::size_of::() as u64, ) as *mut i32; i = 0; while i < 10 { print!(\"{}\\n\", *c.offset(i as isize)); i = i.wrapping_add(1); i; } free(c as *mut libc::c_void); return 0; } }" }, { "index": 621, "before": "void show_set(set_t x, const char *name) { \tint i; \tprintf(\"%s is:\", name); \tfor (i = 0; (1U << i) <= x; i++) \t\tif (x & (1U << i)) \t\t\tprintf(\" %d\", i); \tputchar('\\n'); }", "after": "pub extern \"C\" fn show_set(mut x: u32, mut name: *const i8) { unsafe { let mut i: i32 = 0; print!(\"{} is:\", build_str_from_raw_ptr(name as *mut u8)); i = 0; while 1 << i <= x { if x & 1 << i != 0 { print!(\" {}\", i); } i += 1; i; } print!(\"{}\", '\\n' as i32); } }" }, { "index": 622, "before": "int main(void) { \tint i; \tset_t a, b, c; \ta = 0; /* empty set */ \tfor (i = 0; i < 10; i += 3) /* add 0 3 6 9 to set a */ \t\ta |= (1U << i); \tshow_set(a, \"a\"); \tfor (i = 0; i < 5; i++) \t\tprintf(\"\\t%d%s in set a\\n\", i, (a & (1U << i)) ? \"\":\" not\"); \tb = a; \tb |= (1U << 5); b |= (1U << 10); /* b is a plus 5, 10 */ \tb &= ~(1U << 0);\t/* sans 0 */ \tshow_set(b, \"b\"); \tshow_set(a | b, \"union(a, b)\"); \tshow_set(c = a & b, \"c = common(a, b)\"); \tshow_set(a & ~b, \"a - b\"); /* diff, not arithmetic minus */ \tshow_set(b & ~a, \"b - a\"); \tprintf(\"b is%s a subset of a\\n\", !(b & ~a) ? \"\" : \" not\"); \tprintf(\"c is%s a subset of a\\n\", !(c & ~a) ? \"\" : \" not\"); \tprintf(\"union(a, b) - common(a, b) %s union(a - b, b - a)\\n\", \t\t((a | b) & ~(a & b)) == ((a & ~b) | (b & ~a)) \t\t\t? \"equals\" : \"does not equal\"); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut a: u32 = 0; let mut b: u32 = 0; let mut c: u32 = 0; a = 0; i = 0; while i < 10 { a |= 1 << i; i += 3; } show_set(a, b\"a\\0\" as *const u8 as *const i8); i = 0; while i < 5 { if a & 1 << i != 0 { print!(\"\t{}{} in set a\\n\", i, \"\\0\") } else { print!(\"\t{}{} in set a\\n\", i, \" not\\0\") }; i += 1; i; } b = a; b |= 1 << 5; b |= 1 << 10; b &= !(1 << 0); show_set(b, b\"b\\0\" as *const u8 as *const i8); show_set(a | b, b\"union(a, b)\\0\" as *const u8 as *const i8); c = a & b; show_set(c, b\"c = common(a, b)\\0\" as *const u8 as *const i8); show_set(a & !b, b\"a - b\\0\" as *const u8 as *const i8); show_set(b & !a, b\"b - a\\0\" as *const u8 as *const i8); if b & !a == 0 { print!(\"b is{} a subset of a\\n\", \"\\0\") } else { print!(\"b is{} a subset of a\\n\", \" not\\0\") }; if c & !a == 0 { print!(\"c is{} a subset of a\\n\", \"\\0\") } else { print!(\"c is{} a subset of a\\n\", \" not\\0\") }; if (a | b) & !(a & b) == a & !b | b & !a { print!( \"union(a, b) - common(a, b) {} union(a - b, b - a)\\n\", \"equals\\0\" ) } else { print!( \"union(a, b) - common(a, b) {} union(a - b, b - a)\\n\", \"does not equal\\0\" ) }; return 0; }" }, { "index": 623, "before": "void transfer_value(int from, int to, int howmuch) { bool swapped = false; if ((from == to) || (howmuch < 0) || (from < 0) || (to < 0) || (from >= N_BUCKETS) || (to >= N_BUCKETS)) return; if (from > to) { int temp1 = from; from = to; to = temp1; swapped = true; howmuch = -howmuch; } pthread_mutex_lock(&bucket_mutex[from]); pthread_mutex_lock(&bucket_mutex[to]); if (howmuch > buckets[from] && !swapped) howmuch = buckets[from]; if (-howmuch > buckets[to] && swapped) howmuch = -buckets[to]; buckets[from] -= howmuch; buckets[to] += howmuch; pthread_mutex_unlock(&bucket_mutex[from]); pthread_mutex_unlock(&bucket_mutex[to]); }", "after": "pub extern \"C\" fn transfer_value(mut from: i32, mut to: i32, mut howmuch: i32) { let mut swapped: bool = 0 != 0; if from == to || howmuch < 0 || from < 0 || to < 0 || from >= 15 || to >= 15 { return; } if from > to { let mut temp1: i32 = from; from = to; to = temp1; swapped = 1 != 0; howmuch = -howmuch; } unsafe { pthread_mutex_lock(&mut *bucket_mutex.as_mut_ptr().offset(from as isize)); pthread_mutex_lock(&mut *bucket_mutex.as_mut_ptr().offset(to as isize)); if howmuch > buckets[from as usize] && !swapped { howmuch = buckets[from as usize]; } if -howmuch > buckets[to as usize] && swapped as i32 != 0 { howmuch = -buckets[to as usize]; } buckets[from as usize] -= howmuch; buckets[to as usize] += howmuch; pthread_mutex_unlock(&mut *bucket_mutex.as_mut_ptr().offset(from as isize)); pthread_mutex_unlock(&mut *bucket_mutex.as_mut_ptr().offset(to as isize)); } }" }, { "index": 624, "before": "void print_buckets() { int i; int sum = 0; for (i = 0; i < N_BUCKETS; i++) pthread_mutex_lock(&bucket_mutex[i]); for (i = 0; i < N_BUCKETS; i++) { printf(\"%3d \", buckets[i]); sum += buckets[i]; } printf(\"= %d\\n\", sum); for (i = 0; i < N_BUCKETS; i++) pthread_mutex_unlock(&bucket_mutex[i]); }", "after": "pub extern \"C\" fn print_buckets() { let mut i: i32 = 0; let mut sum: i32 = 0; i = 0; unsafe { while i < 15 { pthread_mutex_lock(&mut *bucket_mutex.as_mut_ptr().offset(i as isize)); i += 1; i; } } i = 0; unsafe { while i < 15 { print!(\"{:3} \", buckets[i as usize]); sum += buckets[i as usize]; i += 1; i; } } print!(\"= {}\\n\", sum); i = 0; unsafe { while i < 15 { pthread_mutex_unlock(&mut *bucket_mutex.as_mut_ptr().offset(i as isize)); i += 1; i; } } }" }, { "index": 625, "before": "int main() { int i, total = 0; for (i = 0; i < N_BUCKETS; i++) pthread_mutex_init(&bucket_mutex[i], NULL); for (i = 0; i < N_BUCKETS; i++) { buckets[i] = rand() % 100; total += buckets[i]; printf(\"%3d \", buckets[i]); } printf(\"= %d\\n\", total); // we should check if these succeeded pthread_create(&equalizer, NULL, equalizer_start, NULL); pthread_create(&randomizer, NULL, randomizer_start, NULL); for (int i = 0; i < 2; i++) { sleep(1); print_buckets(); } // we do not provide a \"good\" way to stop this run, so the following // is never reached indeed... for (i = 0; i < N_BUCKETS; i++) pthread_mutex_destroy(bucket_mutex + i); return EXIT_SUCCESS; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut total: i32 = 0; i = 0; unsafe { while i < 15 { pthread_mutex_init( &mut *bucket_mutex.as_mut_ptr().offset(i as isize), 0 as *const pthread_mutexattr_t, ); i += 1; i; } } i = 0; unsafe { while i < 15 { buckets[i as usize] = rand() % 100; total += buckets[i as usize]; print!(\"{:3} \", buckets[i as usize]); i += 1; i; } } print!(\"= {}\\n\", total); unsafe { pthread_create( &mut equalizer, 0 as *const pthread_attr_t, Some(equalizer_start as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), 0 as *mut libc::c_void, ); pthread_create( &mut randomizer, 0 as *const pthread_attr_t, Some(randomizer_start as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), 0 as *mut libc::c_void, ); } let mut i_0: i32 = 0; unsafe { while i_0 < 2 { sleep(1); print_buckets(); i_0 += 1; i_0; } } i = 0; unsafe { while i < 15 { pthread_mutex_destroy(bucket_mutex.as_mut_ptr().offset(i as isize)); i += 1; i; } } return 0; }" }, { "index": 626, "before": "void HashAdd( KeyType key, ValType value ) { HashAddH( key, value, ©Str, ©Int, &strhashkey, &strCompare); }", "after": "pub extern \"C\" fn HashAdd(mut key: *const i8, mut value: i32) { unsafe { HashAddH( key, value, Some(copyStr as unsafe extern \"C\" fn(*mut *const i8, *const i8) -> ()), Some(copyInt as unsafe extern \"C\" fn(*mut i32, i32) -> ()), Some(strhashkey as unsafe extern \"C\" fn(*const i8, i32) -> u32), Some(strCompare as unsafe extern \"C\" fn(*const i8, *const i8) -> i32), ); } }" }, { "index": 627, "before": "int HashGetH(ValType *val, KeyType key, KeyHashF hashKey, KeyCmprF keySame ) { unsigned hix = (*hashKey)(key, HASH_SIZE); MapEntry m_ent; for (m_ent= hash[hix].first; m_ent && !(*keySame)(m_ent->key,key); m_ent=m_ent->link); if (m_ent) { *val = m_ent->value; } return (m_ent != NULL); }", "after": "pub extern \"C\" fn HashGetH( mut val: *mut i32, mut key: *const i8, mut hashKey: KeyHashF, mut keySame: KeyCmprF, ) -> i32 { unsafe { let mut hix: u32 = (Some(hashKey.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")(key, 4096); let mut m_ent: MapEntry = 0 as *mut sHme; m_ent = hash[hix as usize].first; while !m_ent.is_null() && (Some(keySame.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")((*m_ent).key, key) == 0 { m_ent = (*m_ent).link; } if !m_ent.is_null() { *val = (*m_ent).value; } return (m_ent != 0 as *mut libc::c_void as MapEntry) as i32; } }" }, { "index": 628, "before": "int strCompare( const char *key1, const char *key2) { return strcmp(key1, key2) == 0; }", "after": "pub extern \"C\" fn strCompare(mut key1: *const i8, mut key2: *const i8) -> i32 { unsafe { return (strcmp(key1, key2) == 0) as i32; } }" }, { "index": 629, "before": "void copyInt( int *dest, int src) { *dest = src; }", "after": "pub extern \"C\" fn copyInt(mut dest: *mut i32, mut src: i32) { unsafe { *dest = src; } }" }, { "index": 630, "before": "void HashAddH( KeyType key, ValType value, KeyCopyF copyKey, ValCopyF copyVal, KeyHashF hashKey, KeyCmprF keySame ) { unsigned hix = (*hashKey)(key, HASH_SIZE); MapEntry m_ent; for (m_ent= hash[hix].first; m_ent && !(*keySame)(m_ent->key,key); m_ent=m_ent->link); if (m_ent) { (*copyVal)(&m_ent->value, value); } else { MapEntry last; MapEntry hme = malloc(sizeof(struct sHme)); (*copyKey)(&hme->key, key); (*copyVal)(&hme->value, value); hme->link = NULL; last = hash[hix].last; if (last) { //\t printf(\"Dup. hash key\\n\"); last->link = hme; } else hash[hix].first = hme; hash[hix].last = hme; } }", "after": "pub extern \"C\" fn HashAddH( mut key: *const i8, mut value: i32, mut copyKey: KeyCopyF, mut copyVal: ValCopyF, mut hashKey: KeyHashF, mut keySame: KeyCmprF, ) { unsafe { let mut hix: u32 = (Some(hashKey.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")(key, 4096); let mut m_ent: MapEntry = 0 as *mut sHme; m_ent = hash[hix as usize].first; while !m_ent.is_null() && (Some(keySame.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")((*m_ent).key, key) == 0 { m_ent = (*m_ent).link; } if !m_ent.is_null() { (Some(copyVal.expect(\"non-null function pointer\"))).expect(\"non-null function pointer\")( &mut (*m_ent).value, value, ); } else { let mut last: MapEntry = 0 as *mut sHme; let mut hme: MapEntry = malloc(::core::mem::size_of::() as u64) as MapEntry; (Some(copyKey.expect(\"non-null function pointer\"))).expect(\"non-null function pointer\")( &mut (*hme).key, key, ); (Some(copyVal.expect(\"non-null function pointer\"))).expect(\"non-null function pointer\")( &mut (*hme).value, value, ); (*hme).link = 0 as *mut sHme; last = hash[hix as usize].last; if !last.is_null() { (*last).link = hme; } else { hash[hix as usize].first = hme; } hash[hix as usize].last = hme; }; } }" }, { "index": 631, "before": "unsigned strhashkey( const char * key, int max) { unsigned h=0; unsigned hl, hr; while(*key) { h += *key; hl= 0x5C5 ^ (h&0xfff00000 )>>18; hr =(h&0x000fffff ); h = hl ^ hr ^ *key++; } return h % max; }", "after": "pub extern \"C\" fn strhashkey(mut key: *const i8, mut max: i32) -> u32 { unsafe { let mut h: u32 = 0; let mut hl: u32 = 0; let mut hr: u32 = 0; while *key != 0 { h = h.wrapping_add(*key as u32); hl = 0x5c5 ^ (h & 0xfff00000) >> 18; hr = h & 0xfffff; let fresh0 = key; key = key.offset(1); h = hl ^ hr ^ *fresh0 as u32; } return h.wrapping_rem(max as u32); } }" }, { "index": 632, "before": "int HashGet(ValType *val, KeyType key) { return HashGetH( val, key, &strhashkey, &strCompare); }", "after": "pub extern \"C\" fn HashGet(mut val: *mut i32, mut key: *const i8) -> i32 { unsafe { return HashGetH( val, key, Some(strhashkey as unsafe extern \"C\" fn(*const i8, i32) -> u32), Some(strCompare as unsafe extern \"C\" fn(*const i8, *const i8) -> i32), ); } }" }, { "index": 633, "before": "void copyStr(const char**dest, const char *src) { *dest = strdup(src); }", "after": "pub extern \"C\" fn copyStr(mut dest: *mut *const i8, mut src: *const i8) { unsafe { *dest = strdup(src); } }" }, { "index": 634, "before": "int main() { static const char * keyList[] = {\"red\",\"orange\",\"yellow\",\"green\", \"blue\", \"violet\" }; static int valuList[] = {1,43,640, 747, 42, 42}; int ix; for (ix=0; ix<6; ix++) { HashAdd(keyList[ix], valuList[ix]); } return 0; }", "after": "fn main() -> i32 { unsafe { static mut keyList: [*const i8; 6] = [ b\"red\\0\" as *const u8 as *const i8, b\"orange\\0\" as *const u8 as *const i8, b\"yellow\\0\" as *const u8 as *const i8, b\"green\\0\" as *const u8 as *const i8, b\"blue\\0\" as *const u8 as *const i8, b\"violet\\0\" as *const u8 as *const i8, ]; static mut valuList: [i32; 6] = [1, 43, 640, 747, 42, 42]; let mut ix: i32 = 0; ix = 0; while ix < 6 { HashAdd(keyList[ix as usize], valuList[ix as usize]); ix += 1; ix; } } return 0; }" }, { "index": 635, "before": "double random_normal() /* normal distribution, centered on 0, std dev 1 */ { return sqrt(-2*log(drand())) * cos(2*M_PI*drand()); }", "after": "pub extern \"C\" fn random_normal() -> f64 { unsafe { return sqrt(-2i32 as f64 * log(drand())) * cos(2 as f64 * 3.14159265358979323846f64 * drand()); } }" }, { "index": 636, "before": "double drand() /* uniform distribution, (0..1] */ { return (rand()+1.0)/(RAND_MAX+1.0); }", "after": "pub extern \"C\" fn drand() -> f64 { unsafe { return (rand() as f64 + 1.0f64) / (2147483647 as f64 + 1.0f64); } }" }, { "index": 637, "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": "fn main() -> i32 { let mut i: i32 = 0; let mut rands: [f64; 1000] = [0.; 1000]; i = 0; while i < 1000 { rands[i as usize] = 1.0f64 + 0.5f64 * random_normal(); i += 1; i; } return 0; }" }, { "index": 638, "before": "void ffCopy(double *cells, int rw, int dim, SquareMtx m1) { int col; for (col=0; colm[rw][col]; }", "after": "pub extern \"C\" fn ffCopy(mut cells: *mut f64, mut rw: i32, mut dim: i32, mut m1: SquareMtx) { unsafe { let mut col: i32 = 0; col = 0; while col < dim { *cells.offset(col as isize) = *(*((*m1).m).offset(rw as isize)).offset(col as isize); col += 1; col; } } }" }, { "index": 639, "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; rwm[rw][col] ); fprintf(fout, \" |\\n\"); } fprintf(fout, \"\\n\"); }", "after": "pub extern \"C\" fn SquareMtxPrint(mut mtx: SquareMtx, mut mn: *const i8) { unsafe { let mut rw: i32 = 0; let mut col: i32 = 0; let mut d: i32 = (*mtx).dim; fprintf( fout, b\"%s dim:%d =\\n\\0\" as *const u8 as *const i8, mn, (*mtx).dim, ); rw = 0; while rw < d { fprintf(fout, b\" |\\0\" as *const u8 as *const i8); col = 0; while col < d { fprintf( fout, b\"%8.5f \\0\" as *const u8 as *const i8, *(*((*mtx).m).offset(rw as isize)).offset(col as isize), ); col += 1; col; } fprintf(fout, b\" |\\n\\0\" as *const u8 as *const i8); rw += 1; rw; } fprintf(fout, b\"\\n\\0\" as *const u8 as *const i8); } }" }, { "index": 640, "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 extern \"C\" fn fillInit( mut cells: *mut f64, mut rw: i32, mut dim: i32, mut data: *mut libc::c_void, ) { unsafe { let mut theta: f64 = 3.1415926536f64 / 6.0f64; let mut c1: f64 = cos(theta); let mut s1: f64 = sin(theta); match rw { 0 => { *cells.offset(0 as isize) = c1; *cells.offset(1 as isize) = s1; *cells.offset(2 as isize) = 0.0f64; } 1 => { *cells.offset(0 as isize) = -s1; *cells.offset(1 as isize) = c1; *cells.offset(2 as isize) = 0 as f64; } 2 => { *cells.offset(0 as isize) = 0.0f64; *cells.offset(1 as isize) = 0.0f64; *cells.offset(2 as isize) = 1.0f64; } _ => {} }; } }" }, { "index": 641, "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; ixm[ix][col]; cells[col] = sum; } }", "after": "pub extern \"C\" fn ffMatxMulply( mut cells: *mut f64, mut rw: i32, mut dim: i32, mut mplcnds: *mut SquareMtx, ) { unsafe { let mut mleft: SquareMtx = *mplcnds.offset(0 as isize); let mut mrigt: SquareMtx = *mplcnds.offset(1 as isize); let mut sum: f64 = 0.; let mut m0rw: *mut f64 = *((*mleft).m).offset(rw as isize); let mut col: i32 = 0; let mut ix: i32 = 0; col = 0; while col < dim { sum = 0.0f64; ix = 0; 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": 642, "before": "SquareMtx NewSquareMtx( int dim, FillFunc fillFunc, void *ff_data ) { SquareMtx sm = malloc(sizeof(struct squareMtxStruct)); if (sm) { int rw; sm->dim = dim; sm->cells = malloc(dim*dim * sizeof(double)); sm->m = malloc( dim * sizeof(double *)); if ((sm->cells != NULL) && (sm->m != NULL)) { for (rw=0; rwm[rw] = sm->cells + dim*rw; fillFunc( sm->m[rw], rw, dim, ff_data ); } } else { free(sm->m); free(sm->cells); free(sm); printf(\"Square Matrix allocation failure\\n\"); return NULL; } } else { printf(\"Malloc failed for square matrix\\n\"); } return sm; }", "after": "pub extern \"C\" fn NewSquareMtx( mut dim: i32, mut fillFunc: FillFunc, mut ff_data: *mut libc::c_void, ) -> SquareMtx { unsafe { let mut sm: SquareMtx = malloc(::core::mem::size_of::() as u64) as SquareMtx; if !sm.is_null() { let mut rw: i32 = 0; (*sm).dim = dim; (*sm).cells = malloc(((dim * dim) as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut f64; (*sm).m = malloc((dim as u64).wrapping_mul(::core::mem::size_of::<*mut f64>() as u64)) as *mut *mut f64; if !((*sm).cells).is_null() && !((*sm).m).is_null() { rw = 0; while rw < dim { let ref mut fresh0 = *((*sm).m).offset(rw as isize); *fresh0 = ((*sm).cells).offset((dim * rw) as isize); fillFunc.expect(\"non-null function pointer\")( *((*sm).m).offset(rw as isize), rw, dim, ff_data, ); rw += 1; rw; } } else { free((*sm).m as *mut libc::c_void); free((*sm).cells as *mut libc::c_void); free(sm as *mut libc::c_void); print!(\"Square Matrix allocation failure\\n\"); return 0 as SquareMtx; } } else { print!(\"Malloc failed for square matrix\\n\"); } return sm; } }" }, { "index": 643, "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 extern \"C\" fn SquareMtxPow(mut m0: SquareMtx, mut exp: i32) -> SquareMtx { unsafe { let mut v0: SquareMtx = NewSquareMtx( (*m0).dim, Some(ffIdentity as unsafe extern \"C\" fn(*mut f64, i32, i32, *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 ()>, FillFunc, >(Some( ffCopy as unsafe extern \"C\" fn(*mut f64, i32, i32, 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 != 0 { if !v1.is_null() { MatxMul(v1, v0, base0); } else { mplcnds[0 as usize] = v0; mplcnds[1 as usize] = base0; v1 = NewSquareMtx( (*m0).dim, ::core::mem::transmute::< Option ()>, FillFunc, >(Some( ffMatxMulply as unsafe extern \"C\" fn(*mut f64, i32, i32, *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 ()>, FillFunc, >(Some( ffMatxSquare as unsafe extern \"C\" fn(*mut f64, i32, i32, SquareMtx) -> (), )), base0 as *mut libc::c_void, ); } t = base0; base0 = base1; base1 = t; exp = exp / 2; } if !base0.is_null() { FreeSquareMtx(base0); } if !base1.is_null() { FreeSquareMtx(base1); } if !v1.is_null() { FreeSquareMtx(v1); } return v0; } }" }, { "index": 644, "before": "void ffIdentity( double *cells, int rw, int dim, void *v ) { int col; for (col=0; colm); free(m->cells); free(m); }", "after": "pub extern \"C\" fn FreeSquareMtx(mut m: SquareMtx) { unsafe { free((*m).m as *mut libc::c_void); free((*m).cells as *mut libc::c_void); free(m as *mut libc::c_void); } }" }, { "index": 646, "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": "fn main() -> i32 { unsafe { let mut m0: SquareMtx = NewSquareMtx( 3, Some(fillInit as unsafe extern \"C\" fn(*mut f64, i32, i32, *mut libc::c_void) -> ()), 0 as *mut libc::c_void, ); let mut m1: SquareMtx = SquareMtxPow(m0, 5); let mut m2: SquareMtx = SquareMtxPow(m0, 9); let mut m3: SquareMtx = SquareMtxPow(m0, 2); fout = fopen( b\"matrx_exp.txt\\0\" as *const u8 as *const i8, b\"w\\0\" as *const u8 as *const i8, ); SquareMtxPrint(m0, b\"m0\\0\" as *const u8 as *const i8); FreeSquareMtx(m0); SquareMtxPrint(m1, b\"m0^5\\0\" as *const u8 as *const i8); FreeSquareMtx(m1); SquareMtxPrint(m2, b\"m0^9\\0\" as *const u8 as *const i8); FreeSquareMtx(m2); SquareMtxPrint(m3, b\"m0^2\\0\" as *const u8 as *const i8); FreeSquareMtx(m3); fclose(fout); } return 0; }" }, { "index": 647, "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; ixm[ix][col]; cells[col] = sum; } }", "after": "pub extern \"C\" fn ffMatxSquare(mut cells: *mut f64, mut rw: i32, mut dim: i32, mut m0: SquareMtx) { unsafe { let mut col: i32 = 0; let mut ix: i32 = 0; let mut sum: f64 = 0.; let mut m0rw: *mut f64 = *((*m0).m).offset(rw as isize); col = 0; while col < dim { sum = 0.0f64; ix = 0; 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": 648, "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 extern \"C\" fn MatxMul(mut mr: SquareMtx, mut left: SquareMtx, mut rigt: SquareMtx) { let mut rw: i32 = 0; let mut mplcnds: [SquareMtx; 2] = [0 as *mut squareMtxStruct; 2]; mplcnds[0 as usize] = left; mplcnds[1 as usize] = rigt; rw = 0; unsafe { while rw < (*left).dim { ffMatxMulply( *((*mr).m).offset(rw as isize), rw, (*left).dim, mplcnds.as_mut_ptr(), ); rw += 1; rw; } } }" }, { "index": 649, "before": "int numDigits(int n){ \tint count = 1; \twhile(n>=10){ \t\tn /= 10; \t\tcount++; \t} \treturn count; }", "after": "pub extern \"C\" fn numDigits(mut n: i32) -> i32 { let mut count: i32 = 1; while n >= 10 { n /= 10; count += 1; count; } return count; }" }, { "index": 650, "before": "int main(int argC,char* argV[]) { \tint n; \tif(argC!=2||isdigit(argV[1][0])==0) \t\tprintf(\"Usage : %s \",argV[0]); \telse{ \t\tn = atoi(argV[1]); \t\tprintMagicSquare(doublyEvenMagicSquare(n),n); \t} \treturn 0; }", "after": "fn main(mut argC: i32, mut argV: *mut *mut i8) -> i32 { unsafe { let mut n: i32 = 0; if argC != 2 || *(*__ctype_b_loc()) .offset(*(*argV.offset(1 as isize)).offset(0 as isize) as i32 as isize) as i32 & _ISdigit as i32 == 0 { print!( \"Usage : {} \", build_str_from_raw_ptr(*argV.offset(0 as isize) as *mut u8) ); } else { n = atoi(*argV.offset(1 as isize)); printMagicSquare(doublyEvenMagicSquare(n), n); } return 0; } }" }, { "index": 651, "before": "void printMagicSquare(int** square,int rows){ \tint i,j,baseWidth = numDigits(rows*rows) + 3; \tprintf(\"Doubly Magic Square of Order : %d and Magic Constant : %d\\n\\n\",rows,(rows * rows + 1) * rows / 2); \tfor(i=0;i i32 { unsafe { let mut bigger: *const i8 = 0 as *const i8; let mut current: i32 = 0; let mut arabic: i32 = 0; while *roman as i32 != '\\0' as i32 { current = digits[((!0x20i32 & *roman as i32) - 'A' as i32) as usize]; bigger = roman; while digits[((!0x20i32 & *bigger as i32) - 'A' as i32) as usize] <= current && { bigger = bigger.offset(1); *bigger as i32 != '\\0' as i32 } {} if *bigger as i32 == '\\0' as i32 { arabic += current; } else { arabic += digits[((!0x20i32 & *bigger as i32) - 'A' as i32) as usize]; while roman < bigger { let fresh0 = roman; roman = roman.offset(1); arabic -= digits[((!0x20i32 & *fresh0 as i32) - 'A' as i32) as usize]; } } roman = roman.offset(1); roman; } return arabic; } }" }, { "index": 653, "before": "int main() { const char * romans[] = { \"MCmxC\", \"MMVIII\", \"MDClXVI\", \"MCXLUJ\" }; int i; for (i = 0; i < 4; i++) printf(\"%s\\t%d\\n\", romans[i], decode(romans[i])); return 0; }", "after": "fn main() -> i32 { let mut romans: [*const i8; 4] = [ b\"MCmxC\\0\" as *const u8 as *const i8, b\"MMVIII\\0\" as *const u8 as *const i8, b\"MDClXVI\\0\" as *const u8 as *const i8, b\"MCXLUJ\\0\" as *const u8 as *const i8, ]; let mut i: i32 = 0; i = 0; unsafe { while i < 4 { print!( \"{}\t{}\\n\", build_str_from_raw_ptr(romans[i as usize] as *mut u8), decode(romans[i as usize]) ); i += 1; i; } } return 0; }" }, { "index": 654, "before": "void throw_die(const uint n_sides, const uint n_dice, const uint s, uint counts[]) { if (n_dice == 0) { counts[s]++; return; } for (uint i = 1; i < n_sides + 1; i++) throw_die(n_sides, n_dice - 1, s + i, counts); }", "after": "pub extern \"C\" fn throw_die(n_sides: u32, n_dice: u32, s: u32, mut counts: *mut u32) { unsafe { if n_dice == 0 { let ref mut fresh0 = *counts.offset(s as isize); *fresh0 = (*fresh0).wrapping_add(1); *fresh0; return; } let mut i: u32 = 1; while i < n_sides.wrapping_add(1) { throw_die(n_sides, n_dice.wrapping_sub(1), s.wrapping_add(i), counts); i = i.wrapping_add(1); i; } } }" }, { "index": 655, "before": "uint min(const uint x, const uint y) { return (x < y) ? x : y; }", "after": "pub extern \"C\" fn min(x: u32, y: u32) -> u32 { return if x < y { x } else { y }; }" }, { "index": 656, "before": "double beating_probability(const uint n_sides1, const uint n_dice1, const uint n_sides2, const uint n_dice2) { const uint len1 = (n_sides1 + 1) * n_dice1; uint C1[len1]; for (uint i = 0; i < len1; i++) C1[i] = 0; throw_die(n_sides1, n_dice1, 0, C1); const uint len2 = (n_sides2 + 1) * n_dice2; uint C2[len2]; for (uint j = 0; j < len2; j++) C2[j] = 0; throw_die(n_sides2, n_dice2, 0, C2); const double p12 = (double)(ipow(n_sides1, n_dice1) * ipow(n_sides2, n_dice2)); double tot = 0; for (uint i = 0; i < len1; i++) for (uint j = 0; j < min(i, len2); j++) tot += (double)C1[i] * C2[j] / p12; return tot; }", "after": "pub extern \"C\" fn beating_probability( n_sides1: u32, n_dice1: u32, n_sides2: u32, n_dice2: u32, ) -> f64 { let len1: u32 = n_sides1.wrapping_add(1).wrapping_mul(n_dice1); let vla = len1 as usize; let mut C1: Vec = ::std::vec::from_elem(0, vla); let mut i: u32 = 0; unsafe { while i < len1 { *C1.as_mut_ptr().offset(i as isize) = 0; i = i.wrapping_add(1); i; } } throw_die(n_sides1, n_dice1, 0, C1.as_mut_ptr()); let len2: u32 = n_sides2.wrapping_add(1).wrapping_mul(n_dice2); let vla_0 = len2 as usize; let mut C2: Vec = ::std::vec::from_elem(0, vla_0); let mut j: u32 = 0; unsafe { while j < len2 { *C2.as_mut_ptr().offset(j as isize) = 0; j = j.wrapping_add(1); j; } } throw_die(n_sides2, n_dice2, 0, C2.as_mut_ptr()); let p12: f64 = (ipow(n_sides1, n_dice1)).wrapping_mul(ipow(n_sides2, n_dice2)) as f64; let mut tot: f64 = 0 as f64; let mut i_0: u32 = 0; unsafe { while i_0 < len1 { let mut j_0: u32 = 0; while j_0 < min(i_0, len2) { tot += *C1.as_mut_ptr().offset(i_0 as isize) as f64 * *C2.as_mut_ptr().offset(j_0 as isize) as f64 / p12; j_0 = j_0.wrapping_add(1); j_0; } i_0 = i_0.wrapping_add(1); i_0; } } return tot; }" }, { "index": 657, "before": "int main() { printf(\"%1.16f\\n\", beating_probability(4, 9, 6, 6)); printf(\"%1.16f\\n\", beating_probability(10, 5, 7, 6)); return 0; }", "after": "fn main() -> i32 { print!(\"{:1.16}\\n\", beating_probability(4, 9, 6, 6)); print!(\"{:1.16}\\n\", beating_probability(10, 5, 7, 6)); return 0; }" }, { "index": 658, "before": "ulong ipow(const uint x, const uint y) { ulong result = 1; for (uint i = 1; i <= y; i++) result *= x; return result; }", "after": "pub extern \"C\" fn ipow(x: u32, y: u32) -> u64 { let mut result: u64 = 1; let mut i: u32 = 1; while i <= y { result = (result).wrapping_mul(x as u64) as u64; i = i.wrapping_add(1); i; } return result; }" }, { "index": 659, "before": "int move_to_front(char *str,char c) { char *q,*p; int shift=0; p=(char *)malloc(strlen(str)+1); strcpy(p,str); q=strchr(p,c); //returns pointer to location of char c in string str shift=q-p; // no of characters from 0 to position of c in str strncpy(str+1,p,shift); str[0]=c; free(p); // printf(\"\\n%s\\n\",str); return shift; }", "after": "pub extern \"C\" fn move_to_front(mut str: *mut i8, mut c: i8) -> i32 { unsafe { let mut q: *mut i8 = 0 as *mut i8; let mut p: *mut i8 = 0 as *mut i8; let mut shift: i32 = 0; p = malloc((strlen(str)).wrapping_add(1)) as *mut i8; strcpy(p, str); q = strchr(p, c as i32); shift = q.offset_from(p) as i32; strncpy(str.offset(1 as isize), p, shift as u64); *str.offset(0 as isize) = c; free(p as *mut libc::c_void); return shift; } }" }, { "index": 660, "before": "int main() { char sym[3][MAX_SIZE]={\"broood\",\"bananaaa\",\"hiphophiphop\"}; int pass[MAX_SIZE]={0}; int i,len,j; for(i=0;i<3;i++) { len=strlen(sym[i]); encode(sym[i],len,pass); printf(\"%s : [\",sym[i]); for(j=0;j i32 { unsafe { let mut sym : [[i8; 100]; 3] = [* :: core :: mem :: transmute :: < & [u8; 100], & mut [i8; 100], > ( b\"broood\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\",), * :: core :: mem :: transmute :: < & [u8; 100 ], & mut [i8; 100], > (b\"bananaaa\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\",), * :: core :: mem :: transmute :: < & [u8; 100], & mut [i8; 100], > (b\"hiphophiphop\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\",),]; let mut pass: [i32; 100] = [0; 100]; let mut i: i32 = 0; let mut len: i32 = 0; let mut j: i32 = 0; i = 0; while i < 3 { len = strlen((sym[i as usize]).as_mut_ptr()) as i32; encode((sym[i as usize]).as_mut_ptr(), len, pass.as_mut_ptr()); print!( \"{} : [\", build_str_from_raw_ptr((sym[i as usize]).as_mut_ptr() as *mut u8) ); j = 0; while j < len { print!(\"{} \", pass[j as usize]); j += 1; j; } print!(\"]\\n\"); if check((sym[i as usize]).as_mut_ptr(), len, pass.as_mut_ptr()) != 0 { print!(\"Correct :)\\n\"); } else { print!(\"Incorrect :(\\n\"); } i += 1; i; } } return 0; }" }, { "index": 661, "before": "void decode(int* pass,int size,char *sym) { int i,index; char c; char table[]=\"abcdefghijklmnopqrstuvwxyz\"; for(i=0;i(b\"abcdefghijklmnopqrstuvwxyz\\0\"); i = 0; while i < size { c = table[*pass.offset(i as isize) as usize]; index = move_to_front(table.as_mut_ptr(), c); if *pass.offset(i as isize) != index { print!(\"there is an error\"); }; *sym.offset(i as isize) = c; i += 1; i; } *sym.offset(size as isize) = '\\0' as i8; } }" }, { "index": 662, "before": "int check(char *sym,int size,int *pass) { int *pass2=malloc(sizeof(int)*size); char *sym2=malloc(sizeof(char)*size); int i,val=1; encode(sym,size,pass2); i=0; while(i i32 { unsafe { let mut pass2: *mut i32 = malloc((::core::mem::size_of::() as u64).wrapping_mul(size as u64)) as *mut i32; let mut sym2: *mut i8 = malloc((::core::mem::size_of::() as u64).wrapping_mul(size as u64)) as *mut i8; let mut i: i32 = 0; let mut val: i32 = 1; encode(sym, size, pass2); i = 0; while i < size && *pass.offset(i as isize) == *pass2.offset(i as isize) { i += 1; i; } if i != size { val = 0; } decode(pass, size, sym2); if strcmp(sym, sym2) != 0 { val = 0; } free(sym2 as *mut libc::c_void); free(pass2 as *mut libc::c_void); return val; } }" }, { "index": 663, "before": "void encode(char *sym,int size,int *pass) { int i=0; char c; char table[]=\"abcdefghijklmnopqrstuvwxyz\"; for(i=0;i(b\"abcdefghijklmnopqrstuvwxyz\\0\"); i = 0; while i < size { c = *sym.offset(i as isize); *pass.offset(i as isize) = move_to_front(table.as_mut_ptr(), c); i += 1; i; } } }" }, { "index": 664, "before": "void add_number(int x) { \tprintf(\"%d \", x); }", "after": "pub extern \"C\" fn add_number(mut x: i32) { print!(\"{} \", x); }" }, { "index": 665, "before": "int get_list(const char *s, char **e) { \tint x; \twhile (1) { \t\tskip_space; \t\tif (!get_rnge(s, e) && !get_number(x, s, e)) break; \t\ts = *e; \t\tskip_space; \t\tif ((*s) == '\\0') { putchar('\\n'); return 1; } \t\tif ((*s) == ',') { s++; continue; } \t\tbreak; \t} \t*(const char **)e = s; \tprintf(\"\\nSyntax error at %s\\n\", s); \treturn 0; }", "after": "pub extern \"C\" fn get_list(mut s: *const i8, mut e: *mut *mut i8) -> i32 { unsafe { let mut x: i32 = 0; loop { while *(*__ctype_b_loc()).offset(*s as i32 as isize) as i32 & _ISspace as i32 != 0 { s = s.offset(1); s; } if get_rnge(s, e) == 0 && { x = strtol(s, e, 10) as i32; !(*e != s as *mut i8) } { break; } s = *e; while *(*__ctype_b_loc()).offset(*s as i32 as isize) as i32 & _ISspace as i32 != 0 { s = s.offset(1); s; } if *s as i32 == '\\0' as i32 { print!(\"{}\", '\\n' as i32); return 1; } if !(*s as i32 == ',' as i32) { break; } s = s.offset(1); s; } let ref mut fresh0 = *(e as *mut *const i8); *fresh0 = s; print!( \"\\nSyntax error at {}\\n\", build_str_from_raw_ptr(s as *mut u8) ); return 0; } }" }, { "index": 666, "before": "int get_rnge(const char *s, char **e) { \tint x, y; \tchar *ee; \tif (!get_number(x, s, &ee)) return 0; \ts = ee; \tskip_space; \tif (*s != '-') { \t\t*(const char **)e = s; \t\treturn 0; \t} \ts++; \tif(!get_number(y, s, e)) return 0; \treturn add_range(x, y); }", "after": "pub extern \"C\" fn get_rnge(mut s: *const i8, mut e: *mut *mut i8) -> i32 { unsafe { let mut x: i32 = 0; let mut y: i32 = 0; let mut ee: *mut i8 = 0 as *mut i8; x = strtol(s, &mut ee, 10) as i32; if !(ee != s as *mut i8) { return 0; } s = ee; while *(*__ctype_b_loc()).offset(*s as i32 as isize) as i32 & _ISspace as i32 != 0 { s = s.offset(1); s; } if *s as i32 != '-' as i32 { let ref mut fresh1 = *(e as *mut *const i8); *fresh1 = s; return 0; } s = s.offset(1); s; y = strtol(s, e, 10) as i32; if !(*e != s as *mut i8) { return 0; } return add_range(x, y); } }" }, { "index": 667, "before": "int add_range(int x, int y) { \tif (y <= x) return 0; \twhile (x <= y) printf(\"%d \", x++); \treturn 1; }", "after": "pub extern \"C\" fn add_range(mut x: i32, mut y: i32) -> i32 { if y <= x { return 0; } while x <= y { let fresh2 = x; x = x + 1; print!(\"{} \", fresh2); } return 1; }" }, { "index": 668, "before": "int main() { \tchar *end; \t/* this is correct */ \tif (get_list(\"-6,-3--1,3-5,7-11,14,15,17-20\", &end)) puts(\"Ok\"); \t/* this is not. note the subtle error: \"-6 -3\" is parsed \t * as range(-6, 3), so synax error comes after that */ \tget_list(\"-6 -3--1,3-5,7-11,14,15,17-20\", &end); \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut end: *mut i8 = 0 as *mut i8; if get_list( b\"-6,-3--1,3-5,7-11,14,15,17-20\\0\" as *const u8 as *const i8, &mut end, ) != 0 { puts(b\"Ok\\0\" as *const u8 as *const i8); } get_list( b\"-6 -3--1,3-5,7-11,14,15,17-20\\0\" as *const u8 as *const i8, &mut end, ); return 0; } }" }, { "index": 669, "before": "int randn(int m) { \tint rand_max = RAND_MAX - (RAND_MAX % m); \tint r; \twhile ((r = rand()) > rand_max) \t\t; \treturn r / (rand_max / m); }", "after": "pub extern \"C\" fn randn(mut m: i32) -> i32 { let mut rand_max: i32 = 2147483647 - 2147483647 % m; let mut r: i32 = 0; unsafe { loop { r = rand(); if !(r > rand_max) { break; } } } return r / (rand_max / m); }" }, { "index": 670, "before": "int main() { \tint i, x, y, r2; \tunsigned long buf[31] = {0}; /* could just use 2d array */ \tfor (i = 0; i < 100;) \t{ \t\tx = randn(31) - 15; \t\ty = randn(31) - 15; \t\tr2 = x * x + y * y; \t\tif (r2 >= 100 && r2 <= 225) \t\t{ \t\t\tbuf[15 + y] |= 1 << (x + 15); \t\t\ti++; \t\t} \t} \tfor (y = 0; y < 31; y++) \t{ \t\tfor (x = 0; x < 31; x++) \t\t\tprintf((buf[y] & 1 << x) ? \". \" : \" \"); \t\tprintf(\"\\n\"); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut x: i32 = 0; let mut y: i32 = 0; let mut r2: i32 = 0; let mut buf: [u64; 31] = [0; 31]; i = 0; while i < 100 { x = randn(31) - 15; y = randn(31) - 15; r2 = x * x + y * y; if r2 >= 100 && r2 <= 225 { buf[(15 + y) as usize] |= (1i32 << x + 15) as u64; i += 1; i; } } y = 0; while y < 31 { x = 0; while x < 31 { if buf[y as usize] & (1i32 << x) as u64 != 0 { print!(\". \") } else { print!(\" \") }; x += 1; x; } print!(\"\\n\"); y += 1; y; } return 0; }" }, { "index": 671, "before": "int is_pangram(const char *s) { \tconst char *alpha = \"\" \t\t\"abcdefghjiklmnopqrstuvwxyz\" \t\t\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"; \tchar ch, wasused[26] = {0}; \tint total = 0; \twhile ((ch = *s++) != '\\0') { \t\tconst char *p; \t\tint idx; \t\tif ((p = strchr(alpha, ch)) == NULL) \t\t\tcontinue; \t\tidx = (p - alpha) % 26; \t\ttotal += !wasused[idx]; \t\twasused[idx] = 1; \t\tif (total == 26) \t\t\treturn 1; \t} \treturn 0; }", "after": "pub extern \"C\" fn is_pangram(mut s: *const i8) -> i32 { unsafe { let mut alpha: *const i8 = b\"abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\\0\" as *const u8 as *const i8; let mut ch: i8 = 0; let mut wasused: [i8; 26] = [0; 26]; let mut total: i32 = 0; loop { let fresh0 = s; s = s.offset(1); ch = *fresh0; if !(ch as i32 != '\\0' as i32) { break; } let mut p: *const i8 = 0 as *const i8; let mut idx: i32 = 0; p = strchr(alpha, ch as i32); if p.is_null() { continue; } idx = (p.offset_from(alpha) as i64 % 26i64) as i32; total += (wasused[idx as usize] == 0) as i32; wasused[idx as usize] = 1; if total == 26 { return 1; } } return 0; } }" }, { "index": 672, "before": "int main(void) { \tint i; \tconst char *tests[] = { \t\t\"The quick brown fox jumps over the lazy dog.\", \t\t\"The qu1ck brown fox jumps over the lazy d0g.\" \t}; \tfor (i = 0; i < 2; i++) \t\tprintf(\"\\\"%s\\\" is %sa pangram\\n\", \t\t\ttests[i], is_pangram(tests[i])?\"\":\"not \"); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut tests: [*const i8; 2] = [ b\"The quick brown fox jumps over the lazy dog.\\0\" as *const u8 as *const i8, b\"The qu1ck brown fox jumps over the lazy d0g.\\0\" as *const u8 as *const i8, ]; i = 0; unsafe { while i < 2 { if is_pangram(tests[i as usize]) != 0 { print!( \"\\\"{}\\\" is {}a pangram\\n\", build_str_from_raw_ptr(tests[i as usize] as *mut u8), \"\\0\" ) } else { print!( \"\\\"{}\\\" is {}a pangram\\n\", build_str_from_raw_ptr(tests[i as usize] as *mut u8), \"not \\0\" ) }; i += 1; i; } } return 0; }" }, { "index": 673, "before": "int main() { FILE *fp; char *line = NULL; size_t len = 0; ssize_t read; char *lw, *lt; fp = fopen(\"data.txt\", \"r\"); if (fp == NULL) { printf(\"Unable to open file\\n\"); exit(1); } printf(\"Those earthquakes with a magnitude > 6.0 are:\\n\\n\"); while ((read = getline(&line, &len, fp)) != EOF) { if (read < 2) continue; /* ignore blank lines */ lw = strrchr(line, ' '); /* look for last space */ lt = strrchr(line, '\\t'); /* look for last tab */ if (!lw && !lt) continue; /* ignore lines with no whitespace */ if (lt > lw) lw = lt; /* lw points to last space or tab */ if (atof(lw + 1) > 6.0) printf(\"%s\", line); } fclose(fp); if (line) free(line); return 0; }", "after": "fn main() -> i32 { unsafe { let mut fp: *mut FILE = 0 as *mut FILE; let mut line: *mut i8 = 0 as *mut i8; let mut len: u64 = 0; let mut read: i64 = 0; let mut lw: *mut i8 = 0 as *mut i8; let mut lt: *mut i8 = 0 as *mut i8; fp = fopen( b\"data.txt\\0\" as *const u8 as *const i8, b\"r\\0\" as *const u8 as *const i8, ); if fp.is_null() { print!(\"Unable to open file\\n\"); exit(1); } print!(\"Those earthquakes with a magnitude > 6.0 are:\\n\\n\"); loop { read = getline(&mut line, &mut len, fp); if !(read != -1 as i64) { break; } if read < 2 { continue; } lw = strrchr(line, ' ' as i32); lt = strrchr(line, '\\t' as i32); if lw.is_null() && lt.is_null() { continue; } if lt > lw { lw = lt; } if atof(lw.offset(1 as isize)) > 6.0f64 { print!(\"{}\", build_str_from_raw_ptr(line as *mut u8)); } } fclose(fp); if !line.is_null() { free(line as *mut libc::c_void); } return 0; } }" }, { "index": 674, "before": "int main(int argc,char** argv) { int i,len; char reference; if(argc>2){ printf(\"Usage : %s \\n\",argv[0]); return 0; } if(argc==1||strlen(argv[1])==1){ printf(\"Input string : \\\"%s\\\"\\nLength : %d\\nAll characters are identical.\\n\",argc==1?\"\":argv[1],argc==1?0:(int)strlen(argv[1])); return 0; } reference = argv[1][0]; len = strlen(argv[1]); for(i=1;i i32 { unsafe { let mut i: i32 = 0; let mut len: i32 = 0; let mut reference: i8 = 0; if argc > 2 { print!( \"Usage : {} \\n\", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); return 0; } if argc == 1 || strlen(*argv.offset(1 as isize)) == 1 { if argc == 1 { if argc == 1 { print!( \"Input string : \\\"{}\\\"\\nLength : {}\\nAll characters are identical.\\n\", \"\\0\", 0 ) } else { print!( \"Input string : \\\"{}\\\"\\nLength : {}\\nAll characters are identical.\\n\", \"\\0\", strlen(*argv.offset(1 as isize)) as i32 ) } } else { if argc == 1 { print!( \"Input string : \\\"{}\\\"\\nLength : {}\\nAll characters are identical.\\n\", build_str_from_raw_ptr(*argv.offset(1 as isize) as *const i8 as *mut u8), 0 ) } else { print!( \"Input string : \\\"{}\\\"\\nLength : {}\\nAll characters are identical.\\n\", build_str_from_raw_ptr(*argv.offset(1 as isize) as *const i8 as *mut u8), strlen(*argv.offset(1 as isize)) as i32 ) } }; return 0; } reference = *(*argv.offset(1 as isize)).offset(0 as isize); len = strlen(*argv.offset(1 as isize)) as i32; i = 1; while i < len { if *(*argv.offset(1 as isize)).offset(i as isize) as i32 != reference as i32 { print! (\"Input string : \\\"{}\\\"\\nLength : {}\\nFirst different character : \\\"{}\\\"(0x{:x}) at position : {}\\n\", build_str_from_raw_ptr (* argv.offset (1 as isize) as * mut u8), len, * (* argv.offset (1 as isize)).offset (i as isize) as i32, * (* argv.offset (1 as isize)).offset (i as isize) as i32, i + 1); return 0; } i += 1; i; } print!( \"Input string : \\\"{}\\\"\\nLength : {}\\nAll characters are identical.\\n\", build_str_from_raw_ptr(*argv.offset(1 as isize) as *mut u8), len ); return 0; } }" }, { "index": 675, "before": "list new_list() { \tlist x = malloc(sizeof(list_t)); \tx->ival = 0; \tx->is_list = 1; \tx->lst = 0; \treturn x; }", "after": "pub extern \"C\" fn new_list() -> list { unsafe { let mut x: list = malloc(::core::mem::size_of::() as u64) as list; (*x).ival = 0; (*x).is_list = 1; (*x).lst = 0 as *mut list; return x; } }" }, { "index": 676, "before": "void delete_list(list l) { \tint i; \tif (!l) return; \tif (l->is_list && l->ival) { \t\tfor (i = 0; i < l->ival; i++) \t\t\tdelete_list(l->lst[i]); \t\tfree(l->lst); \t} \tfree(l); }", "after": "pub extern \"C\" fn delete_list(mut l: list) { let mut i: i32 = 0; if l.is_null() { return; } unsafe { if (*l).is_list != 0 && (*l).ival != 0 { i = 0; while i < (*l).ival { delete_list(*((*l).lst).offset(i as isize)); i += 1; i; } free((*l).lst as *mut libc::c_void); } free(l as *mut libc::c_void); } }" }, { "index": 677, "before": "list flatten(list from, list to) { \tint i; \tlist t; \tif (!to) to = new_list(); \tif (!from->is_list) { \t\tt = new_list(); \t\t*t = *from; \t\tappend(to, t); \t} else \t\tfor (i = 0; i < from->ival; i++) \t\t\tflatten(from->lst[i], to); \treturn to; }", "after": "pub extern \"C\" fn flatten(mut from: list, mut to: list) -> list { let mut i: i32 = 0; let mut t: list = 0 as *mut list_t; if to.is_null() { to = new_list(); } unsafe { if (*from).is_list == 0 { t = new_list(); *t = *from; append(to, t); } else { i = 0; while i < (*from).ival { flatten(*((*from).lst).offset(i as isize), to); i += 1; i; } } } return to; }" }, { "index": 678, "before": "void append(list parent, list child) { \tparent->lst = realloc(parent->lst, sizeof(list) * (parent->ival + 1)); \tparent->lst[parent->ival++] = child; }", "after": "pub extern \"C\" fn append(mut parent: list, mut child: list) { unsafe { (*parent).lst = realloc( (*parent).lst as *mut libc::c_void, (::core::mem::size_of::() as u64).wrapping_mul(((*parent).ival + 1i32) as u64), ) as *mut list; } let fresh0 = (*parent).ival; (*parent).ival = (*parent).ival + 1; unsafe { let ref mut fresh1 = *((*parent).lst).offset(fresh0 as isize); *fresh1 = child; } }" }, { "index": 679, "before": "int main() { \tlist l = from_string(\"[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []\", 0, 0); \tprintf(\"Nested: \"); \tshow_list(l); \tprintf(\"\\n\"); \tlist flat = flatten(l, 0); \tprintf(\"Flattened: \"); \tshow_list(flat); \t/* delete_list(l); delete_list(flat); */ \treturn 0; }", "after": "fn main() -> i32 { let mut l: list = from_string( b\"[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []\\0\" as *const u8 as *const i8 as *mut i8, 0 as *mut *mut i8, 0 as list, ); print!(\"Nested: \"); show_list(l); print!(\"\\n\"); let mut flat: list = flatten(l, 0 as list); print!(\"Flattened: \"); show_list(flat); return 0; }" }, { "index": 680, "before": "void show_list(list l) { \tint i; \tif (!l) return; \tif (!l->is_list) { \t\tprintf(\"%d\", l->ival); \t\treturn; \t} \tprintf(\"[\"); \tfor (i = 0; i < l->ival; i++) { \t\tshow_list(l->lst[i]); \t\tif (i < l->ival - 1) printf(\", \"); \t} \tprintf(\"]\"); }", "after": "pub extern \"C\" fn show_list(mut l: list) { let mut i: i32 = 0; if l.is_null() { return; } if (*l).is_list == 0 { print!(\"{}\", (*l).ival); return; } print!(\"[\"); i = 0; unsafe { while i < (*l).ival { show_list(*((*l).lst).offset(i as isize)); if i < (*l).ival - 1 { print!(\", \"); } i += 1; i; } } print!(\"]\"); }" }, { "index": 681, "before": "list from_string(char *s, char **e, list parent) { \tlist ret = 0; \tif (!parent) parent = new_list(); \twhile (*s != '\\0') { \t\tif (*s == ']') { \t\t\tif (e) *e = s + 1; \t\t\treturn parent; \t\t} \t\tif (*s == '[') { \t\t\tret = new_list(); \t\t\tret->is_list = 1; \t\t\tret->ival = 0; \t\t\tappend(parent, ret); \t\t\tfrom_string(s + 1, &s, ret); \t\t\tcontinue; \t\t} \t\tif (*s >= '0' && *s <= '9') { \t\t\tret = new_list(); \t\t\tret->is_list = 0; \t\t\tret->ival = strtol(s, &s, 10); \t\t\tappend(parent, ret); \t\t\tcontinue; \t\t} \t\ts++; \t} \tif (e) *e = s; \treturn parent; }", "after": "pub extern \"C\" fn from_string(mut s: *mut i8, mut e: *mut *mut i8, mut parent: list) -> list { unsafe { let mut ret: list = 0 as list; if parent.is_null() { parent = new_list(); } while *s as i32 != '\\0' as i32 { if *s as i32 == ']' as i32 { if !e.is_null() { *e = s.offset(1 as isize); } return parent; } if *s as i32 == '[' as i32 { ret = new_list(); (*ret).is_list = 1; (*ret).ival = 0; append(parent, ret); from_string(s.offset(1 as isize), &mut s, ret); } else if *s as i32 >= '0' as i32 && *s as i32 <= '9' as i32 { ret = new_list(); (*ret).is_list = 0; (*ret).ival = strtol(s, &mut s, 10) as i32; append(parent, ret); } else { s = s.offset(1); s; } } if !e.is_null() { *e = s; } return parent; } }" }, { "index": 682, "before": "int Str_Hash( const char *key, int ix_max ) { const char *cp; short mash; int hash = 33501551; for (cp = key; *cp; cp++) { mash = cxmap[*cp % CXMAP_SIZE]; hash = (hash >>4) ^ 0x5C5CF5C ^ ((hash<<1) + (mash<<5)); hash &= 0x3FFFFFFF; } return hash % ix_max; }", "after": "pub extern \"C\" fn Str_Hash(mut key: *const i8, mut ix_max: i32) -> i32 { unsafe { let mut cp: *const i8 = 0 as *const i8; let mut mash: i16 = 0; let mut hash: i32 = 33501551; cp = key; while *cp != 0 { mash = cxmap[(*cp as u64).wrapping_rem( (::core::mem::size_of::<[i16; 96]>() as u64) .wrapping_div(::core::mem::size_of::() as u64), ) as usize]; hash = hash >> 4 ^ 0x5c5cf5c ^ (hash << 1) + ((mash as i32) << 5); hash &= 0x3fffffff; cp = cp.offset(1); cp; } return hash % ix_max; } }" }, { "index": 683, "before": "int buildAnagrams( FILE *fin ) { char buffer[40]; char bufr2[40]; char *hkey; int hix; HashEntry he, *hep; DictWord we; int maxPC = 2; int numWords = 0; while ( fgets(buffer, 40, fin)) { for(hkey = buffer; *hkey && (*hkey!='\\n'); hkey++); *hkey = 0; hkey = sortedWord(buffer, bufr2); hix = Str_Hash(hkey, HT_SIZE); he = hashTable[hix]; hep = &hashTable[hix]; while( he && strcmp(he->key , hkey) ) { hep = &he->next; he = he->next; } if ( ! he ) { he = malloc(sizeof(struct sHashEntry)); he->next = NULL; he->key = strdup(hkey); he->wordCount = 0; he->words = NULL; he->link = NULL; *hep = he; } we = malloc(sizeof(struct sDictWord)); we->word = strdup(buffer); we->next = he->words; he->words = we; he->wordCount++; if ( maxPC < he->wordCount) { maxPC = he->wordCount; mostPerms = he; he->link = NULL; } else if (maxPC == he->wordCount) { he->link = mostPerms; mostPerms = he; } numWords++; } printf(\"%d words in dictionary max ana=%d\\n\", numWords, maxPC); return maxPC; }", "after": "pub extern \"C\" fn buildAnagrams(mut fin: *mut FILE) -> i32 { unsafe { let mut buffer: [i8; 40] = [0; 40]; let mut bufr2: [i8; 40] = [0; 40]; let mut hkey: *mut i8 = 0 as *mut i8; let mut hix: i32 = 0; let mut he: HashEntry = 0 as *mut sHashEntry; let mut hep: *mut HashEntry = 0 as *mut HashEntry; let mut we: DictWord = 0 as *mut sDictWord; let mut maxPC: i32 = 2; let mut numWords: i32 = 0; while !(fgets(buffer.as_mut_ptr(), 40, fin)).is_null() { hkey = buffer.as_mut_ptr(); while *hkey as i32 != 0 && *hkey as i32 != '\\n' as i32 { hkey = hkey.offset(1); hkey; } *hkey = 0; hkey = sortedWord(buffer.as_mut_ptr(), bufr2.as_mut_ptr()); hix = Str_Hash(hkey, 8192); he = hashTable[hix as usize]; hep = &mut *hashTable.as_mut_ptr().offset(hix as isize) as *mut HashEntry; while !he.is_null() && strcmp((*he).key, hkey) != 0 { hep = &mut (*he).next; he = (*he).next; } if he.is_null() { he = malloc(::core::mem::size_of::() as u64) as HashEntry; (*he).next = 0 as HashEntry; (*he).key = strdup(hkey); (*he).wordCount = 0; (*he).words = 0 as DictWord; (*he).link = 0 as HashEntry; *hep = he; } we = malloc(::core::mem::size_of::() as u64) as DictWord; (*we).word = strdup(buffer.as_mut_ptr()); (*we).next = (*he).words; (*he).words = we; (*he).wordCount += 1; (*he).wordCount; if maxPC < (*he).wordCount as i32 { maxPC = (*he).wordCount as i32; mostPerms = he; (*he).link = 0 as HashEntry; } else if maxPC == (*he).wordCount as i32 { (*he).link = mostPerms; mostPerms = he; } numWords += 1; numWords; } print!(\"{} words in dictionary max ana={}\\n\", numWords, maxPC); return maxPC; } }" }, { "index": 684, "before": "int main( ) { HashEntry he; DictWord we; FILE *f1; f1 = fopen(\"unixdict.txt\",\"r\"); buildAnagrams(f1); fclose(f1); f1 = fopen(\"anaout.txt\",\"w\"); // f1 = stdout; for (he = mostPerms; he; he = he->link) { fprintf(f1,\"%d:\", he->wordCount); for(we = he->words; we; we = we->next) { fprintf(f1,\"%s, \", we->word); } fprintf(f1, \"\\n\"); } fclose(f1); return 0; }", "after": "fn main() -> i32 { unsafe { let mut he: HashEntry = 0 as *mut sHashEntry; let mut we: DictWord = 0 as *mut sDictWord; let mut f1: *mut FILE = 0 as *mut FILE; f1 = fopen( b\"unixdict.txt\\0\" as *const u8 as *const i8, b\"r\\0\" as *const u8 as *const i8, ); buildAnagrams(f1); fclose(f1); f1 = fopen( b\"anaout.txt\\0\" as *const u8 as *const i8, b\"w\\0\" as *const u8 as *const i8, ); he = mostPerms; while !he.is_null() { fprintf( f1, b\"%d:\\0\" as *const u8 as *const i8, (*he).wordCount as i32, ); we = (*he).words; while !we.is_null() { fprintf(f1, b\"%s, \\0\" as *const u8 as *const i8, (*we).word); we = (*we).next; } fprintf(f1, b\"\\n\\0\" as *const u8 as *const i8); he = (*he).link; } fclose(f1); return 0; } }" }, { "index": 685, "before": "void setBell(int *bellTri, int row, int col, int value) { size_t index = bellIndex(row, col); bellTri[index] = value; }", "after": "pub extern \"C\" fn setBell(mut bellTri: *mut i32, mut row: i32, mut col: i32, mut value: i32) { unsafe { let mut index: u64 = bellIndex(row, col); *bellTri.offset(index as isize) = value; } }" }, { "index": 686, "before": "int main() { const int rows = 15; int *bt = bellTriangle(rows); int i, j; printf(\"First fifteen Bell numbers:\\n\"); for (i = 1; i <= rows; ++i) { printf(\"%2d: %d\\n\", i, getBell(bt, i, 0)); } printf(\"\\nThe first ten rows of Bell's triangle:\\n\"); for (i = 1; i <= 10; ++i) { printf(\"%d\", getBell(bt, i, 0)); for (j = 1; j < i; ++j) { printf(\", %d\", getBell(bt, i, j)); } printf(\"\\n\"); } free(bt); return 0; }", "after": "fn main() -> i32 { unsafe { let rows: i32 = 15; let mut bt: *mut i32 = bellTriangle(rows); let mut i: i32 = 0; let mut j: i32 = 0; print!(\"First fifteen Bell numbers:\\n\"); i = 1; while i <= rows { print!(\"{:2}: {}\\n\", i, getBell(bt, i, 0)); i += 1; i; } printf(b\"\\nThe first ten rows of Bell's triangle:\\n\\0\" as *const u8 as *const i8); i = 1; while i <= 10 { print!(\"{}\", getBell(bt, i, 0)); j = 1; while j < i { print!(\", {}\", getBell(bt, i, j)); j += 1; j; } print!(\"\\n\"); i += 1; i; } free(bt as *mut libc::c_void); return 0; } }" }, { "index": 687, "before": "int getBell(int *bellTri, int row, int col) { size_t index = bellIndex(row, col); return bellTri[index]; }", "after": "pub extern \"C\" fn getBell(mut bellTri: *mut i32, mut row: i32, mut col: i32) -> i32 { unsafe { let mut index: u64 = bellIndex(row, col); return *bellTri.offset(index as isize); } }" }, { "index": 688, "before": "size_t bellIndex(int row, int col) { return row * (row - 1) / 2 + col; }", "after": "pub extern \"C\" fn bellIndex(mut row: i32, mut col: i32) -> u64 { return (row * (row - 1i32) / 2 + col) as u64; }" }, { "index": 689, "before": "int main() { \tint i, j; \tdouble a[3][5] = {{ 0, 1, 2, 3, 4 }, \t\t\t { 5, 6, 7, 8, 9 }, \t\t\t { 1, 0, 0, 0, 42}}; \tdouble b[5][3]; \ttranspose(b, a, 3, 5); \tfor (i = 0; i < 5; i++) \t\tfor (j = 0; j < 3; j++) \t\t\tprintf(\"%g%c\", b[i][j], j == 2 ? '\\n' : ' '); \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut j: i32 = 0; let mut a: [[f64; 5]; 3] = [ [0 as f64, 1 as f64, 2 as f64, 3 as f64, 4 as f64], [5 as f64, 6 as f64, 7 as f64, 8 as f64, 9 as f64], [1 as f64, 0 as f64, 0 as f64, 0 as f64, 42 as f64], ]; let mut b: [[f64; 3]; 5] = [[0.; 3]; 5]; transpose( b.as_mut_ptr() as *mut libc::c_void, a.as_mut_ptr() as *mut libc::c_void, 3, 5, ); i = 0; while i < 5 { j = 0; while j < 3 { if j == 2 { print!(\"{}{}\", b[i as usize][j as usize], '\\n' as i32) } else { print!(\"{}{}\", b[i as usize][j as usize], ' ' as i32) }; j += 1; j; } i += 1; i; } return 0; }" }, { "index": 690, "before": "void transpose(void *dest, void *src, int src_h, int src_w) { \tint i, j; \tdouble (*d)[src_h] = dest, (*s)[src_w] = src; \tfor (i = 0; i < src_h; i++) \t\tfor (j = 0; j < src_w; j++) \t\t\td[j][i] = s[i][j]; }", "after": "pub extern \"C\" fn transpose( mut dest: *mut libc::c_void, mut src: *mut libc::c_void, mut src_h: i32, mut src_w: i32, ) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let vla = src_h as usize; let mut d: *mut f64 = dest as *mut f64; let vla_0 = src_w as usize; let mut s: *mut f64 = src as *mut f64; i = 0; while i < src_h { j = 0; while j < src_w { *d.offset(j as isize * vla as isize).offset(i as isize) = *s.offset(i as isize * vla_0 as isize).offset(j as isize); j += 1; j; } i += 1; i; } } }" }, { "index": 691, "before": "int inside(vec v, polygon p, double tol) { \t/* should assert p->n > 1 */ \tint i, k, crosses, intersectResult; \tvec *pv; \tdouble min_x, max_x, min_y, max_y; \tfor (i = 0; i < p->n; i++) { \t\tk = (i + 1) % p->n; \t\tmin_x = dist(v, p->v[i], p->v[k], tol); \t\tif (min_x < tol) return 0; \t} \tmin_x = max_x = p->v[0].x; \tmin_y = max_y = p->v[1].y; \t/* calculate extent of polygon */ \tfor_v(i, pv, p) { \t\tif (pv->x > max_x) max_x = pv->x; \t\tif (pv->x < min_x) min_x = pv->x; \t\tif (pv->y > max_y) max_y = pv->y; \t\tif (pv->y < min_y) min_y = pv->y; \t} \tif (v.x < min_x || v.x > max_x || v.y < min_y || v.y > max_y) \t\treturn -1; \tmax_x -= min_x; max_x *= 2; \tmax_y -= min_y; max_y *= 2; \tmax_x += max_y; \tvec e; \twhile (1) { \t\tcrosses = 0; \t\t/* pick a rand point far enough to be outside polygon */ \t\te.x = v.x + (1 + rand() / (RAND_MAX + 1.)) * max_x; \t\te.y = v.y + (1 + rand() / (RAND_MAX + 1.)) * max_x; \t\tfor (i = 0; i < p->n; i++) { \t\t\tk = (i + 1) % p->n; \t\t\tintersectResult = intersect(v, e, p->v[i], p->v[k], tol, 0); \t\t\t/* picked a bad point, ray got too close to vertex. \t\t\t re-pick */ \t\t\tif (!intersectResult) break; \t\t\tif (intersectResult == 1) crosses++; \t\t} \t\tif (i == p->n) break; \t} \treturn (crosses & 1) ? 1 : -1; }", "after": "pub extern \"C\" fn inside(mut v: vec, mut p: polygon, mut tol: f64) -> i32 { unsafe { let mut i: i32 = 0; let mut k: i32 = 0; let mut crosses: i32 = 0; let mut intersectResult: i32 = 0; let mut pv: *mut vec = 0 as *mut vec; let mut min_x: f64 = 0.; let mut max_x: f64 = 0.; let mut min_y: f64 = 0.; let mut max_y: f64 = 0.; i = 0; while i < (*p).n { k = (i + 1) % (*p).n; min_x = dist( v, *((*p).v).offset(i as isize), *((*p).v).offset(k as isize), tol, ); if min_x < tol { return 0; } i += 1; i; } max_x = (*((*p).v).offset(0 as isize)).x; min_x = max_x; max_y = (*((*p).v).offset(1 as isize)).y; min_y = max_y; i = 0; pv = (*p).v; while i < (*p).n { if (*pv).x > max_x { max_x = (*pv).x; } if (*pv).x < min_x { min_x = (*pv).x; } if (*pv).y > max_y { max_y = (*pv).y; } if (*pv).y < min_y { min_y = (*pv).y; } i += 1; i; pv = pv.offset(1); pv; } if v.x < min_x || v.x > max_x || v.y < min_y || v.y > max_y { return -1; } max_x -= min_x; max_x *= 2 as f64; max_y -= min_y; max_y *= 2 as f64; max_x += max_y; let mut e: vec = vec { x: 0., y: 0. }; loop { crosses = 0; e.x = v.x + (1 as f64 + rand() as f64 / (2147483647 as f64 + 1.0f64)) * max_x; e.y = v.y + (1 as f64 + rand() as f64 / (2147483647 as f64 + 1.0f64)) * max_x; i = 0; while i < (*p).n { k = (i + 1) % (*p).n; intersectResult = intersect( v, e, *((*p).v).offset(i as isize), *((*p).v).offset(k as isize), tol, 0 as *mut vec, ); if intersectResult == 0 { break; } if intersectResult == 1 { crosses += 1; crosses; } i += 1; i; } if i == (*p).n { break; } } return if crosses & 1 != 0 { 1 } else { -1 }; } }" }, { "index": 692, "before": "double dist(vec x, vec y0, vec y1, double tol) { \tvec dy = vsub(y1, y0); \tvec x1, s; \tint r; \tx1.x = x.x + dy.y; x1.y = x.y - dy.x; \tr = intersect(x, x1, y0, y1, tol, &s); \tif (r == -1) return HUGE_VAL; \ts = vsub(s, x); \treturn sqrt(vdot(s, s)); }", "after": "pub extern \"C\" fn dist(mut x: vec, mut y0: vec, mut y1: vec, mut tol: f64) -> f64 { let mut dy: vec = vsub(y1, y0); let mut x1: vec = vec { x: 0., y: 0. }; let mut s: vec = vec { x: 0., y: 0. }; let mut r: i32 = 0; x1.x = x.x + dy.y; x1.y = x.y - dy.x; r = intersect(x, x1, y0, y1, tol, &mut s); if r == -1 { return ::core::f64::INFINITY; } s = vsub(s, x); unsafe { return sqrt(vdot(s, s)); } }" }, { "index": 693, "before": "int intersect(vec x0, vec x1, vec y0, vec y1, double tol, vec *sect) { \tvec dx = vsub(x1, x0), dy = vsub(y1, y0); \tdouble d = vcross(dy, dx), a; \tif (!d) return 0; /* edges are parallel */ \ta = (vcross(x0, dx) - vcross(y0, dx)) / d; \tif (sect) \t\t*sect = vmadd(y0, a, dy); \tif (a < -tol || a > 1 + tol) return -1; \tif (a < tol || a > 1 - tol) return 0; \ta = (vcross(x0, dy) - vcross(y0, dy)) / d; \tif (a < 0 || a > 1) return -1; \treturn 1; }", "after": "pub extern \"C\" fn intersect( mut x0: vec, mut x1: vec, mut y0: vec, mut y1: vec, mut tol: f64, mut sect: *mut vec, ) -> i32 { unsafe { let mut dx: vec = vsub(x1, x0); let mut dy: vec = vsub(y1, y0); let mut d: f64 = vcross(dy, dx); let mut a: f64 = 0.; if d == 0. { return 0; } a = (vcross(x0, dx) - vcross(y0, dx)) / d; if !sect.is_null() { *sect = vmadd(y0, a, dy); } if a < -tol || a > 1 as f64 + tol { return -1; } if a < tol || a > 1 as f64 - tol { return 0; } a = (vcross(x0, dy) - vcross(y0, dy)) / d; if a < 0 as f64 || a > 1 as f64 { return -1; } return 1; } }" }, { "index": 694, "before": "vec vmadd(vec a, double s, vec b) { \tvec c; \tc.x = a.x + s * b.x; \tc.y = a.y + s * b.y; \treturn c; }", "after": "pub extern \"C\" fn vmadd(mut a: vec, mut s: f64, mut b: vec) -> vec { let mut c: vec = vec { x: 0., y: 0. }; c.x = a.x + s * b.x; c.y = a.y + s * b.y; return c; }" }, { "index": 695, "before": "int main() { \tvec vsq[] = {\t{0,0}, {10,0}, {10,10}, {0,10}, \t\t\t{2.5,2.5}, {7.5,0.1}, {7.5,7.5}, {2.5,7.5}}; \tpolygon_t sq = { 4, vsq }, /* outer square */ \t\tsq_hole = { 8, vsq }; /* outer and inner square, ie hole */ \tvec c = { 10, 5 }; /* on edge */ \tvec d = { 5, 5 }; \tprintf(\"%d\\n\", inside(c, &sq, 1e-10)); \tprintf(\"%d\\n\", inside(c, &sq_hole, 1e-10)); \tprintf(\"%d\\n\", inside(d, &sq, 1e-10));\t/* in */ \tprintf(\"%d\\n\", inside(d, &sq_hole, 1e-10)); /* out (in the hole) */ \treturn 0; }", "after": "fn main() -> i32 { let mut vsq: [vec; 8] = [ { let mut init = vec { x: 0 as f64, y: 0 as f64, }; init }, { let mut init = vec { x: 10 as f64, y: 0 as f64, }; init }, { let mut init = vec { x: 10 as f64, y: 10 as f64, }; init }, { let mut init = vec { x: 0 as f64, y: 10 as f64, }; init }, { let mut init = vec { x: 2.5f64, y: 2.5f64, }; init }, { let mut init = vec { x: 7.5f64, y: 0.1f64, }; init }, { let mut init = vec { x: 7.5f64, y: 7.5f64, }; init }, { let mut init = vec { x: 2.5f64, y: 7.5f64, }; init }, ]; let mut sq: polygon_t = { let mut init = polygon_t { n: 4, v: vsq.as_mut_ptr(), }; init }; let mut sq_hole: polygon_t = { let mut init = polygon_t { n: 8, v: vsq.as_mut_ptr(), }; init }; let mut c: vec = { let mut init = vec { x: 10 as f64, y: 5 as f64, }; init }; let mut d: vec = { let mut init = vec { x: 5 as f64, y: 5 as f64, }; init }; print!(\"{}\\n\", inside(c, &mut sq, 1e-10f64)); print!(\"{}\\n\", inside(c, &mut sq_hole, 1e-10f64)); print!(\"{}\\n\", inside(d, &mut sq, 1e-10f64)); print!(\"{}\\n\", inside(d, &mut sq_hole, 1e-10f64)); return 0; }" }, { "index": 696, "before": "int main() { \tint y; \tfor (y = 2008; y <= 2121; y++) { \t\tif (wday(y, 12, 25) == 0) printf(\"%04d-12-25\\n\", y); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut y: i32 = 0; y = 2008; unsafe { while y <= 2121 { if wday(y, 12, 25) == 0 { printf(b\"%04d-12-25\\n\\0\" as *const u8 as *const i8, y); } y += 1; y; } } return 0; }" }, { "index": 697, "before": "int wday(int year, int month, int day) { \tint adjustment, mm, yy; \tadjustment = (14 - month) / 12; \tmm = month + 12 * adjustment - 2; \tyy = year - adjustment; \treturn (day + (13 * mm - 1) / 5 + \t\tyy + yy / 4 - yy / 100 + yy / 400) % 7; }", "after": "pub extern \"C\" fn wday(mut year: i32, mut month: i32, mut day: i32) -> i32 { let mut adjustment: i32 = 0; let mut mm: i32 = 0; let mut yy: i32 = 0; adjustment = (14 - month) / 12; mm = month + 12 * adjustment - 2; yy = year - adjustment; return (day + (13 * mm - 1) / 5 + yy + yy / 4 - yy / 100 + yy / 400) % 7; }" }, { "index": 698, "before": "void processInputString(char* str){ \tint **sets, *currentSet, *setLengths, setLength, numSets = 0, i,j,k,l,start,counter=0; \tchar *token,*holder,*holderToken; \tfor(i=0;str[i]!=00;i++) \t\tif(str[i]=='x') \t\t\tnumSets++; \tif(numSets==0){ \t\t\tprintf(\"\\n%s\",str); \t\t\treturn; \t} \tcurrentSet = (int*)calloc(sizeof(int),numSets + 1); \tsetLengths = (int*)calloc(sizeof(int),numSets + 1); \tsets = (int**)malloc((numSets + 1)*sizeof(int*)); \ttoken = strtok(str,\"x\"); \twhile(token!=NULL){ \t\tholder = (char*)malloc(strlen(token)*sizeof(char)); \t\tj = 0; \t\tfor(i=0;token[i]!=00;i++){ \t\t\tif(token[i]>='0' && token[i]<='9') \t\t\t\tholder[j++] = token[i]; \t\t\telse if(token[i]==',') \t\t\t\tholder[j++] = ' '; \t\t} \t\tholder[j] = 00; \t\tsetLength = 0; \t\tfor(i=0;holder[i]!=00;i++) \t\t\tif(holder[i]==' ') \t\t\t\tsetLength++; \t\tif(setLength==0 && strlen(holder)==0){ \t\t\tprintf(\"\\n{}\"); \t\t\treturn; \t\t} \t\tsetLengths[counter] = setLength+1; \t\tsets[counter] = (int*)malloc((1+setLength)*sizeof(int)); \t\tk = 0; \t\tstart = 0; \t\tfor(l=0;holder[l]!=00;l++){ \t\t\tif(holder[l+1]==' '||holder[l+1]==00){ \t\t\t\tholderToken = (char*)malloc((l+1-start)*sizeof(char)); \t\t\t\tstrncpy(holderToken,holder + start,l+1-start); \t\t\t\tsets[counter][k++] = atoi(holderToken); \t\t\t\tstart = l+2; \t\t\t} \t\t} \t\tcounter++; \t\ttoken = strtok(NULL,\"x\"); \t} \tprintf(\"\\n{\"); \tcartesianProduct(sets,setLengths,currentSet,numSets + 1,0); \tprintf(\"\\b}\"); }", "after": "pub extern \"C\" fn processInputString(mut str: *mut i8) { unsafe { let mut sets: *mut *mut i32 = 0 as *mut *mut i32; let mut currentSet: *mut i32 = 0 as *mut i32; let mut setLengths: *mut i32 = 0 as *mut i32; let mut setLength: i32 = 0; let mut numSets: i32 = 0; let mut i: i32 = 0; let mut j: i32 = 0; let mut k: i32 = 0; let mut l: i32 = 0; let mut start: i32 = 0; let mut counter: i32 = 0; let mut token: *mut i8 = 0 as *mut i8; let mut holder: *mut i8 = 0 as *mut i8; let mut holderToken: *mut i8 = 0 as *mut i8; i = 0; while *str.offset(i as isize) as i32 != 0 { if *str.offset(i as isize) as i32 == 'x' as i32 { numSets += 1; numSets; } i += 1; i; } if numSets == 0 { print!(\"\\n{}\", build_str_from_raw_ptr(str as *mut u8)); return; } currentSet = calloc( ::core::mem::size_of::() as u64, (numSets + 1i32) as u64, ) as *mut i32; setLengths = calloc( ::core::mem::size_of::() as u64, (numSets + 1i32) as u64, ) as *mut i32; sets = malloc( ((numSets + 1i32) as u64).wrapping_mul(::core::mem::size_of::<*mut i32>() as u64), ) as *mut *mut i32; token = strtok(str, b\"x\\0\" as *const u8 as *const i8); while !token.is_null() { holder = malloc((strlen(token)).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i8; j = 0; i = 0; while *token.offset(i as isize) as i32 != 0 { if *token.offset(i as isize) as i32 >= '0' as i32 && *token.offset(i as isize) as i32 <= '9' as i32 { let fresh0 = j; j = j + 1; *holder.offset(fresh0 as isize) = *token.offset(i as isize); } else if *token.offset(i as isize) as i32 == ',' as i32 { let fresh1 = j; j = j + 1; *holder.offset(fresh1 as isize) = ' ' as i8; } i += 1; i; } *holder.offset(j as isize) = 0; setLength = 0; i = 0; while *holder.offset(i as isize) as i32 != 0 { if *holder.offset(i as isize) as i32 == ' ' as i32 { setLength += 1; setLength; } i += 1; i; } if setLength == 0 && strlen(holder) == 0 { print!(\"\\n{{}}\"); return; }; *setLengths.offset(counter as isize) = setLength + 1; let ref mut fresh2 = *sets.offset(counter as isize); *fresh2 = malloc(((1 + setLength) as u64).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i32; k = 0; start = 0; l = 0; while *holder.offset(l as isize) as i32 != 0 { if *holder.offset((l + 1i32) as isize) as i32 == ' ' as i32 || *holder.offset((l + 1i32) as isize) as i32 == 0 { holderToken = malloc( ((l + 1 - start) as u64).wrapping_mul(::core::mem::size_of::() as u64), ) as *mut i8; strncpy( holderToken, holder.offset(start as isize), (l + 1 - start) as u64, ); let fresh3 = k; k = k + 1; *(*sets.offset(counter as isize)).offset(fresh3 as isize) = atoi(holderToken); start = l + 2; } l += 1; l; } counter += 1; counter; token = strtok(0 as *mut i8, b\"x\\0\" as *const u8 as *const i8); } print!(\"\\n{{\"); cartesianProduct(sets, setLengths, currentSet, numSets + 1, 0); print!(\"\\x08}}\"); } }" }, { "index": 699, "before": "void printSets(int** sets, int* setLengths, int numSets){ \tint i,j; \tprintf(\"\\nNumber of sets : %d\",numSets); \tfor(i=0;i\",argV[0]); \telse \t\tprocessInputString(argV[1]); \treturn 0; }", "after": "fn main(mut argC: i32, mut argV: *mut *mut i8) -> i32 { unsafe { if argC != 2 { print!( \"Usage : {} \", build_str_from_raw_ptr(*argV.offset(0 as isize) as *mut u8) ); } else { processInputString(*argV.offset(1 as isize)); } return 0; } }" }, { "index": 702, "before": "int isPrime(int n){ \tif (n%2==0) return n==2; \tif (n%3==0) return n==3; \tint d=5; \twhile(d*d<=n){ \t\tif(n%d==0) return 0; \t\td+=2; \t\tif(n%d==0) return 0; \t\td+=4;} \treturn 1;}", "after": "pub extern \"C\" fn isPrime(mut n: i32) -> i32 { if n % 2 == 0 { return (n == 2) as i32; } if n % 3 == 0 { return (n == 3) as i32; } let mut d: i32 = 5; while d * d <= n { if n % d == 0 { return 0; } d += 2; if n % d == 0 { return 0; } d += 4; } return 1; }" }, { "index": 703, "before": "void fatal(const char* message) { fprintf(stderr, \"%s\\n\", message); exit(1); }", "after": "pub extern \"C\" fn fatal(mut message: *const i8) { unsafe { fprintf(stderr, b\"%s\\n\\0\" as *const u8 as *const i8, message); exit(1); } }" }, { "index": 704, "before": "void test(const command_t* commands, const char* input) { printf(\" input: %s\\n\", input); printf(\"output:\"); size_t count = 0; char** words = split_into_words(input, &count); for (size_t i = 0; i < count; ++i) { char* word = words[i]; uppercase(word, strlen(word)); const command_t* cmd_ptr = find_command(commands, word); printf(\" %s\", cmd_ptr ? cmd_ptr->cmd : \"*error*\"); free(word); } free(words); printf(\"\\n\"); }", "after": "pub extern \"C\" fn test(mut commands: *const command_t, mut input: *const i8) { unsafe { print!(\" input: {}\\n\", build_str_from_raw_ptr(input as *mut u8)); print!(\"output:\"); let mut count: u64 = 0; let mut words: *mut *mut i8 = split_into_words(input, &mut count); let mut i: u64 = 0; while i < count { let mut word: *mut i8 = *words.offset(i as isize); uppercase(word, strlen(word)); let mut cmd_ptr: *const command_t = find_command(commands, word); if !cmd_ptr.is_null() { print!( \" {}\", build_str_from_raw_ptr((*cmd_ptr).cmd as *const i8 as *mut u8) ) } else { print!(\" {}\", \"*error*\\0\") }; free(word as *mut libc::c_void); i = i.wrapping_add(1); i; } free(words as *mut libc::c_void); print!(\"\\n\"); } }" }, { "index": 705, "before": "void free_command_list(command_t* cmd) { while (cmd != NULL) { command_t* next = cmd->next; free(cmd->cmd); free(cmd); cmd = next; } }", "after": "pub extern \"C\" fn free_command_list(mut cmd: *mut command_t) { unsafe { while !cmd.is_null() { let mut next: *mut command_t = (*cmd).next; free((*cmd).cmd as *mut libc::c_void); free(cmd as *mut libc::c_void); cmd = next; } } }" }, { "index": 706, "before": "bool command_match(const command_t* command, const char* str) { size_t olen = strlen(str); return olen >= command->min_len && olen <= command->length && strncmp(str, command->cmd, olen) == 0; }", "after": "pub extern \"C\" fn command_match(mut command: *const command_t, mut str: *const i8) -> bool { unsafe { let mut olen: u64 = strlen(str); return olen >= (*command).min_len && olen <= (*command).length && strncmp(str, (*command).cmd, olen) == 0; } }" }, { "index": 707, "before": "int main() { command_t* commands = make_command_list(command_table); const char* input = \"riG rePEAT copies put mo rest types fup. 6 poweRin\"; test(commands, input); free_command_list(commands); return 0; }", "after": "fn main() -> i32 { unsafe { let mut commands: *mut command_t = make_command_list(command_table); let mut input: *const i8 = b\"riG rePEAT copies put mo rest types fup. 6 poweRin\\0\" as *const u8 as *const i8; test(commands, input); free_command_list(commands); return 0; } }" }, { "index": 708, "before": "void bernoulli(mpq_t rop, unsigned int n) { unsigned int m, j; mpq_t *a = malloc(sizeof(mpq_t) * (n + 1)); mpq_for(a, init, n + 1); for (m = 0; m <= n; ++m) { mpq_set_ui(a[m], 1, m + 1); for (j = m; j > 0; --j) { mpq_sub(a[j-1], a[j], a[j-1]); mpq_set_ui(rop, j, 1); mpq_mul(a[j-1], a[j-1], rop); } } mpq_set(rop, a[0]); mpq_for(a, clear, n + 1); free(a); }", "after": "pub extern \"C\" fn bernoulli(mut rop: i32, mut n: u32) { let mut m: u32 = 0; let mut j: u32 = 0; let mut i: u64 = 0; m = 0; while m <= n { j = m; while j > 0 { j = j.wrapping_sub(1); j; } m = m.wrapping_add(1); m; } let mut i_0: u64 = 0; }" }, { "index": 709, "before": "int main() { const int N = 2; int base = 10; int c1 = 0; int c2 = 0; int k; for (k = 1; k < pow(base, N); k++) { c1++; if (k % (base - 1) == (k * k) % (base - 1)) { c2++; printf(\"%d \", k); } } printf(\"\\nTring %d numbers instead of %d numbers saves %f%%\\n\", c2, c1, 100.0 - 100.0 * c2 / c1); return 0; }", "after": "fn main() -> i32 { let N: i32 = 2; let mut base: i32 = 10; let mut c1: i32 = 0; let mut c2: i32 = 0; let mut k: i32 = 0; k = 1; unsafe { while (k as f64) < pow(base as f64, N as f64) { c1 += 1; c1; if k % (base - 1) == k * k % (base - 1) { c2 += 1; c2; print!(\"{} \", k); } k += 1; k; } } print!( \"\\nTring {} numbers instead of {} numbers saves {}%\\n\", c2, c1, 100.0f64 - 100.0f64 * c2 as f64 / c1 as f64 ); return 0; }" }, { "index": 710, "before": "int main() { const int cutOff = 200, bigUn = 100000, chunks = 50, little = bigUn / chunks; struct PrimeArray primes = allocate(); int c = 0; bool showEach = true; llong_t u = 0, v = 1, i; push_back(&primes, 3); push_back(&primes, 5); printf(\"The first %d cuban primes:\\n\", cutOff); for (i = 1; i < LLONG_MAX; ++i) { bool found = false; llong_t mx = ceil(sqrt(v += (u += 6))); llong_t j; for (j = 0; j < primes.size; ++j) { if (primes.ptr[j] > mx) { break; } if (v % primes.ptr[j] == 0) { found = true; break; } } if (!found) { c += 1; if (showEach) { llong_t z; for (z = primes.ptr[primes.size - 1] + 2; z <= v - 2; z += 2) { bool fnd = false; for (j = 0; j < primes.size; ++j) { if (primes.ptr[j] > mx) { break; } if (z % primes.ptr[j] == 0) { fnd = true; break; } } if (!fnd) { push_back(&primes, z); } } push_back(&primes, v); printf(\"%11lld\", v); if (c % 10 == 0) { printf(\"\\n\"); } if (c == cutOff) { showEach = false; printf(\"\\nProgress to the %dth cuban prime: \", bigUn); } } if (c % little == 0) { printf(\".\"); if (c == bigUn) { break; } } } } printf(\"\\nThe %dth cuban prime is %lld\\n\", c, v); deallocate(&primes); return 0; }", "after": "fn main() -> i32 { let cutOff: i32 = 200; let bigUn: i32 = 100000; let chunks: i32 = 50; let little: i32 = bigUn / chunks; let mut primes: PrimeArray = allocate(); let mut c: i32 = 0; let mut showEach: bool = 1 != 0; let mut u: i64 = 0; let mut v: i64 = 1; let mut i: i64 = 0; push_back(&mut primes, 3); push_back(&mut primes, 5); print!(\"The first {} cuban primes:\\n\", cutOff); i = 1; unsafe { while i < 9223372036854775807 { let mut found: bool = 0 != 0; u += 6; v += u; let mut mx: i64 = ceil(sqrt(v as f64)) as i64; let mut j: i64 = 0; j = 0; while (j as u64) < primes.size as u64 { if *(primes.ptr).offset(j as isize) > mx { break; } if v % *(primes.ptr).offset(j as isize) == 0 { found = 1 != 0; break; } else { j += 1; j; } } if !found { c += 1; if showEach { let mut z: i64 = 0; z = *(primes.ptr).offset((primes.size).wrapping_sub(1) as isize) + 2; while z <= v - 2 { let mut fnd: bool = 0 != 0; j = 0; while (j as u64) < primes.size as u64 { if *(primes.ptr).offset(j as isize) > mx { break; } if z % *(primes.ptr).offset(j as isize) == 0 { fnd = 1 != 0; break; } else { j += 1; j; } } if !fnd { push_back(&mut primes, z); } z += 2; } push_back(&mut primes, v); print!(\"{:11}\", v); if c % 10 == 0 { print!(\"\\n\"); } if c == cutOff { showEach = 0 != 0; print!(\"\\nProgress to the {}th cuban prime: \", bigUn); } } if c % little == 0 { print!(\".\"); if c == bigUn { break; } } } i += 1; i; } } print!(\"\\nThe {}th cuban prime is {}\\n\", c, v); deallocate(&mut primes); return 0; }" }, { "index": 711, "before": "void deallocate(struct PrimeArray *primes) { free(primes->ptr); primes->ptr = NULL; }", "after": "pub extern \"C\" fn deallocate(mut primes: *mut PrimeArray) { unsafe { free((*primes).ptr as *mut libc::c_void); (*primes).ptr = 0 as *mut i64; } }" }, { "index": 712, "before": "struct PrimeArray allocate() { struct PrimeArray primes; primes.size = 0; primes.capacity = 10; primes.ptr = malloc(primes.capacity * sizeof(llong_t)); return primes; }", "after": "pub extern \"C\" fn allocate() -> PrimeArray { let mut primes: PrimeArray = PrimeArray { ptr: 0 as *mut i64, size: 0, capacity: 0, }; primes.size = 0; primes.capacity = 10; unsafe { primes.ptr = malloc((primes.capacity).wrapping_mul(::core::mem::size_of::() as u64)) as *mut i64; } return primes; }" }, { "index": 713, "before": "void push_back(struct PrimeArray *primes, llong_t p) { if (primes->size >= primes->capacity) { size_t new_capacity = (3 * primes->capacity) / 2 + 1; llong_t *temp = realloc(primes->ptr, new_capacity * sizeof(llong_t)); if (NULL == temp) { fprintf(stderr, \"Failed to reallocate the prime array.\"); exit(1); } else { primes->ptr = temp; primes->capacity = new_capacity; } } primes->ptr[primes->size++] = p; }", "after": "pub extern \"C\" fn push_back(mut primes: *mut PrimeArray, mut p: i64) { unsafe { if (*primes).size >= (*primes).capacity { let mut new_capacity: u64 = 3u64 .wrapping_mul((*primes).capacity) .wrapping_div(2) .wrapping_add(1); let mut temp: *mut i64 = realloc( (*primes).ptr as *mut libc::c_void, new_capacity.wrapping_mul(::core::mem::size_of::() as u64), ) as *mut i64; if temp.is_null() { fprintf( stderr, b\"Failed to reallocate the prime array.\\0\" as *const u8 as *const i8, ); exit(1); } else { (*primes).ptr = temp; (*primes).capacity = new_capacity; } } let fresh0 = (*primes).size; (*primes).size = ((*primes).size).wrapping_add(1); *((*primes).ptr).offset(fresh0 as isize) = p; } }" }, { "index": 714, "before": "double inf(void) { return HUGE_VAL; }", "after": "pub extern \"C\" fn inf() -> f64 { return ::core::f64::INFINITY; }" }, { "index": 715, "before": "int main() { printf(\"%g\\n\", inf()); return 0; }", "after": "fn main() -> i32 { print!(\"{}\\n\", inf()); return 0; }" }, { "index": 716, "before": "void test(double a, double b) { double epsilon = 1e-18; printf(\"%f, %f => %d\\n\", a, b, approxEquals(a, b, epsilon)); }", "after": "pub extern \"C\" fn test(mut a: f64, mut b: f64) { let mut epsilon: f64 = 1e-18f64; print!(\"{}, {} => {}\\n\", a, b, approxEquals(a, b, epsilon) as i32); }" }, { "index": 717, "before": "bool approxEquals(double value, double other, double epsilon) { return fabs(value - other) < epsilon; }", "after": "pub extern \"C\" fn approxEquals(mut value: f64, mut other: f64, mut epsilon: f64) -> bool { unsafe { return fabs(value - other) < epsilon; } }" }, { "index": 718, "before": "int main() { test(100000000000000.01, 100000000000000.011); test(100.01, 100.011); test(10000000000000.001 / 10000.0, 1000000000.0000001000); test(0.001, 0.0010000001); test(0.000000000000000000000101, 0.0); test(sqrt(2.0) * sqrt(2.0), 2.0); test(-sqrt(2.0) * sqrt(2.0), -2.0); test(3.14159265358979323846, 3.14159265358979324); return 0; }", "after": "fn main() -> i32 { test(100000000000000.01f64, 100000000000000.011f64); test(100.01f64, 100.011f64); test(10000000000000.001f64 / 10000.0f64, 1000000000.0000001000f64); test(0.001f64, 0.0010000001f64); test(0.000000000000000000000101f64, 0.0f64); unsafe { test(sqrt(2.0f64) * sqrt(2.0f64), 2.0f64); test(-sqrt(2.0f64) * sqrt(2.0f64), -2.0f64); } test(3.14159265358979323846f64, 3.14159265358979324f64); return 0; }" }, { "index": 719, "before": "ULONG get_prime(int idx) { static long n_primes = 0, alloc = 0; static ULONG *primes = 0; ULONG last, p; int i; if (idx >= n_primes) { if (n_primes >= alloc) { alloc += 16; /* be conservative */ primes = realloc(primes, sizeof(ULONG) * alloc); } if (!n_primes) { primes[0] = 2; primes[1] = 3; n_primes = 2; } last = primes[n_primes - 1]; while (idx >= n_primes) { last += 2; for (i = 0; i < n_primes; i++) { p = primes[i]; if (p * p > last) { primes[n_primes++] = last; break; } if (last % p == 0) break; } } } return primes[idx]; }", "after": "pub extern \"C\" fn get_prime(mut idx: i32) -> u64 { unsafe { static mut n_primes: i64 = 0; static mut alloc: i64 = 0; static mut primes: *mut u64 = 0 as *const u64 as *mut u64; let mut last: u64 = 0; let mut p: u64 = 0; let mut i: i32 = 0; if idx as i64 >= n_primes { if n_primes >= alloc { alloc += 16; primes = realloc( primes as *mut libc::c_void, (::core::mem::size_of::() as u64).wrapping_mul(alloc as u64), ) as *mut u64; } if n_primes == 0 { *primes.offset(0 as isize) = 2; *primes.offset(1 as isize) = 3; n_primes = 2; } last = *primes.offset((n_primes - 1i64) as isize); while idx as i64 >= n_primes { last = (last).wrapping_add(2) as u64; i = 0; while (i as i64) < n_primes { p = *primes.offset(i as isize); if p.wrapping_mul(p) > last { let fresh0 = n_primes; n_primes = n_primes + 1; *primes.offset(fresh0 as isize) = last; break; } else { if last.wrapping_rem(p) == 0 { break; } i += 1; i; } } } } return *primes.offset(idx as isize); } }" }, { "index": 720, "before": "int main() { ULONG n, x, p; int i, first; for (x = 1; x < 1000; x++) { printf(\"%lld = \", n = x); for (i = 0, first = 1;; i++) { p = get_prime(i); while (n % p == 0) { n /= p; if (!first) printf(\" x \"); first = 0; printf(\"%lld\", p); } if (n <= p * p) break; } if (first) printf(\"%lld\\n\", n); else if (n > 1) printf(\" x %lld\\n\", n); else printf(\"\\n\"); } return 0; }", "after": "fn main() -> i32 { let mut n: u64 = 0; let mut x: u64 = 0; let mut p: u64 = 0; let mut i: i32 = 0; let mut first: i32 = 0; x = 1; while x < 1000 { n = x; print!(\"{} = \", n); i = 0; first = 1; loop { p = get_prime(i); while n.wrapping_rem(p) == 0 { n = (n).wrapping_div(p) as u64; if first == 0 { print!(\" x \"); } first = 0; print!(\"{}\", p); } if n <= p.wrapping_mul(p) { break; } i += 1; i; } if first != 0 { print!(\"{}\\n\", n); } else if n > 1 { print!(\" x {}\\n\", n); } else { print!(\"\\n\"); } x = x.wrapping_add(1); x; } return 0; }" }, { "index": 721, "before": "double dot(double *x, double *y) { double d = x[0]*y[0] + x[1]*y[1] + x[2]*y[2]; return d < 0 ? -d : 0; }", "after": "pub extern \"C\" fn dot(mut x: *mut f64, mut y: *mut f64) -> f64 { unsafe { let mut d: f64 = *x.offset(0 as isize) * *y.offset(0 as isize) + *x.offset(1 as isize) * *y.offset(1 as isize) + *x.offset(2 as isize) * *y.offset(2 as isize); return if d < 0 as f64 { -d } else { 0 as f64 }; } }" }, { "index": 722, "before": "void draw_sphere(double R, double k, double ambient) { int i, j, intensity; double b; double vec[3], x, y; for (i = floor(-R); i <= ceil(R); i++) { x = i + .5; for (j = floor(-2 * R); j <= ceil(2 * R); j++) { y = j / 2. + .5; if (x * x + y * y <= R * R) { vec[0] = x; vec[1] = y; vec[2] = sqrt(R * R - x * x - y * y); normalize(vec); b = pow(dot(light, vec), k) + ambient; intensity = (1 - b) * (sizeof(shades) - 1); if (intensity < 0) intensity = 0; if (intensity >= sizeof(shades) - 1) intensity = sizeof(shades) - 2; putchar(shades[intensity]); } else putchar(' '); } putchar('\\n'); } }", "after": "pub extern \"C\" fn draw_sphere(mut R: f64, mut k: f64, mut ambient: f64) { let mut i: i32 = 0; let mut j: i32 = 0; let mut intensity: i32 = 0; let mut b: f64 = 0.; let mut vec: [f64; 3] = [0.; 3]; let mut x: f64 = 0.; let mut y: f64 = 0.; unsafe { i = floor(-R) as i32; while i as f64 <= ceil(R) { x = i as f64 + 0.5f64; j = floor(-2i32 as f64 * R) as i32; while j as f64 <= ceil(2 as f64 * R) { y = j as f64 / 2.0f64 + 0.5f64; if x * x + y * y <= R * R { vec[0 as usize] = x; vec[1 as usize] = y; vec[2 as usize] = sqrt(R * R - x * x - y * y); normalize(vec.as_mut_ptr()); b = pow(dot(light.as_mut_ptr(), vec.as_mut_ptr()), k) + ambient; intensity = ((1 as f64 - b) * (::core::mem::size_of::<*const i8>() as u64).wrapping_sub(1u64) as f64) as i32; if intensity < 0 { intensity = 0; } if intensity as u64 >= (::core::mem::size_of::<*const i8>() as u64).wrapping_sub(1) { intensity = (::core::mem::size_of::<*const i8>() as u64).wrapping_sub(2) as i32; } print!(\"{}\", *shades.offset(intensity as isize) as i32); } else { print!(\"{}\", ' ' as i32); } j += 1; j; } print!(\"{}\", '\\n' as i32); i += 1; i; } } }" }, { "index": 723, "before": "int main() { normalize(light); draw_sphere(20, 4, .1); draw_sphere(10, 2, .4); return 0; }", "after": "fn main() -> i32 { unsafe { normalize(light.as_mut_ptr()); } draw_sphere(20 as f64, 4 as f64, 0.1f64); draw_sphere(10 as f64, 2 as f64, 0.4f64); return 0; }" }, { "index": 724, "before": "void normalize(double * v) { double len = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); v[0] /= len; v[1] /= len; v[2] /= len; }", "after": "pub extern \"C\" fn normalize(mut v: *mut f64) { unsafe { let mut len: f64 = sqrt( *v.offset(0 as isize) * *v.offset(0 as isize) + *v.offset(1 as isize) * *v.offset(1 as isize) + *v.offset(2 as isize) * *v.offset(2 as isize), ); *v.offset(0 as isize) /= len; *v.offset(1 as isize) /= len; *v.offset(2 as isize) /= len; } }" }, { "index": 725, "before": "int main() { time_t t = 0; printf(\"%s\", asctime(gmtime(&t))); return 0; }", "after": "fn main() -> i32 { let mut t: i64 = 0; unsafe { print!( \"{}\", build_str_from_raw_ptr(asctime(gmtime(&mut t)) as *mut u8) ); } return 0; }" }, { "index": 726, "before": "date extractDate(char* str){ return (date){.year = 1000 * (str[0]-'0') + 100 * (str[1]-'0') + 10 * (str[2]-'0') + (str[3]-'0'), .month = 10*(str[5]-'0') + (str[6]-'0'), .day = 10*(str[8]-'0') + (str[9]-'0')}; }", "after": "pub extern \"C\" fn extractDate(mut str: *mut i8) -> date { unsafe { return { let mut init = date { year: 1000 * (*str.offset(0 as isize) as i32 - '0' as i32) + 100 * (*str.offset(1 as isize) as i32 - '0' as i32) + 10 * (*str.offset(2 as isize) as i32 - '0' as i32) + (*str.offset(3 as isize) as i32 - '0' as i32), month: 10 * (*str.offset(5 as isize) as i32 - '0' as i32) + (*str.offset(6 as isize) as i32 - '0' as i32), day: 10 * (*str.offset(8 as isize) as i32 - '0' as i32) + (*str.offset(9 as isize) as i32 - '0' as i32), }; init }; } }" }, { "index": 727, "before": "bool isValidDate(char* str){ date newDate; if(strlen(str)!=10 && str[4]!='-' && str[7]!='-'){ return false; } newDate = extractDate(str); if(newDate.year<=0 || newDate.month<=0 || newDate.day<=0 || newDate.month>12 || (newDate.month==2 && newDate.day>29) || ((newDate.month==1 || newDate.month==3 || newDate.month==5 || newDate.month==7 || newDate.month==8 || newDate.month==10 || newDate.month==12) && newDate.day>31) || newDate.day>30 || (newDate.year%4==0 && newDate.month==2 && newDate.month>28)){ return false; } return true; }", "after": "pub extern \"C\" fn isValidDate(mut str: *mut i8) -> bool { unsafe { let mut newDate: date = date { year: 0, month: 0, day: 0, }; if strlen(str) != 10 && *str.offset(4 as isize) as i32 != '-' as i32 && *str.offset(7 as isize) as i32 != '-' as i32 { return 0 != 0; } newDate = extractDate(str); if newDate.year <= 0 || newDate.month <= 0 || newDate.day <= 0 || newDate.month > 12 || newDate.month == 2 && newDate.day > 29 || (newDate.month == 1 || newDate.month == 3 || newDate.month == 5 || newDate.month == 7 || newDate.month == 8 || newDate.month == 10 || newDate.month == 12) && newDate.day > 31 || newDate.day > 30 || newDate.year % 4 == 0 && newDate.month == 2 && newDate.month > 28 { return 0 != 0; } return 1 != 0; } }" }, { "index": 728, "before": "int diffDays(date date1,date date2){ int days1, days2; date1.month = (date1.month + 9)%12; date1.year = date1.year - date1.month/10; date2.month = (date2.month + 9)%12; date2.year = date2.year - date2.month/10; days1 = 365*date1.year + date1.year/4 - date1.year/100 + date1.year/400 + (date1.month*306 + 5)/10 + ( date1.day - 1 ); days2 = 365*date2.year + date2.year/4 - date2.year/100 + date2.year/400 + (date2.month*306 + 5)/10 + ( date2.day - 1 ); return days2 - days1; }", "after": "pub extern \"C\" fn diffDays(mut date1: date, mut date2: date) -> i32 { let mut days1: i32 = 0; let mut days2: i32 = 0; date1.month = (date1.month + 9) % 12; date1.year = date1.year - date1.month / 10; date2.month = (date2.month + 9) % 12; date2.year = date2.year - date2.month / 10; days1 = 365 * date1.year + date1.year / 4 - date1.year / 100 + date1.year / 400 + (date1.month * 306 + 5) / 10 + (date1.day - 1); days2 = 365 * date2.year + date2.year / 4 - date2.year / 100 + date2.year / 400 + (date2.month * 306 + 5) / 10 + (date2.day - 1); return days2 - days1; }" }, { "index": 729, "before": "int main(int argc,char** argv) { if(argc!=3){ return printf(\"Usage : %s \",argv[0]); } if(isValidDate(argv[1])&&isValidDate(argv[2]) == false){ return printf(\"Dates are invalid.\\n\"); } printf(\"Days Difference : %d\\n\", diffDays(extractDate(argv[1]),extractDate(argv[2]))); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { if argc != 3 { let str_to_print = format!( \"Usage : {} \", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); print!(\"{}\", str_to_print); return str_to_print.chars().count() as i32; } if isValidDate(*argv.offset(1 as isize)) as i32 != 0 && isValidDate(*argv.offset(2 as isize)) as i32 == 0 { let str_to_print = format!(\"Dates are invalid.\\n\"); print!(\"{}\", str_to_print); return str_to_print.chars().count() as i32; } print!( \"Days Difference : {}\\n\", diffDays( extractDate(*argv.offset(1 as isize)), extractDate(*argv.offset(2 as isize)), ) ); return 0; } }" }, { "index": 730, "before": "void placeKings() { int r1, r2, c1, c2; for (;;) { r1 = rand() % 8; c1 = rand() % 8; r2 = rand() % 8; c2 = rand() % 8; if (r1 != r2 && abs(r1 - r2) > 1 && abs(c1 - c2) > 1) { grid[r1][c1] = 'K'; grid[r2][c2] = 'k'; return; } } }", "after": "pub extern \"C\" fn placeKings() { let mut r1: i32 = 0; let mut r2: i32 = 0; let mut c1: i32 = 0; let mut c2: i32 = 0; unsafe { loop { r1 = rand() % 8; c1 = rand() % 8; r2 = rand() % 8; c2 = rand() % 8; if r1 != r2 && abs(r1 - r2) > 1 && abs(c1 - c2) > 1 { grid[r1 as usize][c1 as usize] = 'K' as i8; grid[r2 as usize][c2 as usize] = 'k' as i8; return; } } } }" }, { "index": 731, "before": "void toFen() { char fen[80], ch; int r, c, countEmpty = 0, index = 0; for (r = 0; r < 8; ++r) { for (c = 0; c < 8; ++c) { ch = grid[r][c]; printf(\"%2c \", ch == 0 ? '.' : ch); if (ch == 0) { countEmpty++; } else { if (countEmpty > 0) { fen[index++] = countEmpty + 48; countEmpty = 0; } fen[index++] = ch; } } if (countEmpty > 0) { fen[index++] = countEmpty + 48; countEmpty = 0; } fen[index++]= '/'; printf(\"\\n\"); } strcpy(fen + index, \" w - - 0 1\"); printf(\"%s\\n\", fen); }", "after": "pub extern \"C\" fn toFen() { let mut fen: [i8; 80] = [0; 80]; let mut ch: i8 = 0; let mut r: i32 = 0; let mut c: i32 = 0; let mut countEmpty: i32 = 0; let mut index: i32 = 0; r = 0; unsafe { while r < 8 { c = 0; while c < 8 { ch = grid[r as usize][c as usize]; if ch as i32 == 0 { print!(\"{:2} \", '.' as i32) } else { print!(\"{:2} \", ch as i32) }; if ch as i32 == 0 { countEmpty += 1; countEmpty; } else { if countEmpty > 0 { let fresh0 = index; index = index + 1; fen[fresh0 as usize] = (countEmpty + 48i32) as i8; countEmpty = 0; } let fresh1 = index; index = index + 1; fen[fresh1 as usize] = ch; } c += 1; c; } if countEmpty > 0 { let fresh2 = index; index = index + 1; fen[fresh2 as usize] = (countEmpty + 48i32) as i8; countEmpty = 0; } let fresh3 = index; index = index + 1; fen[fresh3 as usize] = '/' as i8; print!(\"\\n\"); r += 1; r; } strcpy( fen.as_mut_ptr().offset(index as isize), b\" w - - 0 1\\0\" as *const u8 as *const i8, ); print!(\"{}\\n\", build_str_from_raw_ptr(fen.as_mut_ptr() as *mut u8)); } }" }, { "index": 732, "before": "void placePieces(const char *pieces, bool isPawn) { int n, r, c; int numToPlace = rand() % strlen(pieces); for (n = 0; n < numToPlace; ++n) { do { r = rand() % 8; c = rand() % 8; } while (grid[r][c] != 0 || (isPawn && (r == 7 || r == 0))); grid[r][c] = pieces[n]; } }", "after": "pub extern \"C\" fn placePieces(mut pieces: *const i8, mut isPawn: i32) { unsafe { let mut n: i32 = 0; let mut r: i32 = 0; let mut c: i32 = 0; let mut numToPlace: i32 = (rand() as u64).wrapping_rem(strlen(pieces)) as i32; n = 0; while n < numToPlace { loop { r = rand() % 8; c = rand() % 8; if !(grid[r as usize][c as usize] as i32 != 0 || isPawn != 0 && (r == 7 || r == 0)) { break; } } grid[r as usize][c as usize] = *pieces.offset(n as isize); n += 1; n; } } }" }, { "index": 733, "before": "int main() { srand(time(NULL)); createFen(); return 0; }", "after": "fn main() -> i32 { unsafe { srand(rust_time(None) as u32); } createFen(); return 0; }" }, { "index": 734, "before": "int main () { int i, n, tw = 0, tv = 0, *s; n = sizeof (items) / sizeof (item_t); s = knapsack(items, n, 400); for (i = 0; i < n; i++) { if (s[i]) { printf(\"%-22s %5d %5d\\n\", items[i].name, items[i].weight, items[i].value); tw += items[i].weight; tv += items[i].value; } } printf(\"%-22s %5d %5d\\n\", \"totals:\", tw, tv); return 0; }", "after": "fn main() -> i32 { unsafe { let mut i: i32 = 0; let mut n: i32 = 0; let mut tw: i32 = 0; let mut tv: i32 = 0; let mut s: *mut i32 = 0 as *mut i32; n = (::core::mem::size_of::<[item_t; 22]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32; s = knapsack(items.as_mut_ptr(), n, 400); i = 0; while i < n { if *s.offset(i as isize) != 0 { print!( \"{:-22} {:5} {:5}\\n\", build_str_from_raw_ptr(items[i as usize].name as *mut u8), items[i as usize].weight, items[i as usize].value ); tw += items[i as usize].weight; tv += items[i as usize].value; } i += 1; i; } print!(\"{:-22} {:5} {:5}\\n\", \"totals:\\0\", tw, tv); return 0; } }" }, { "index": 735, "before": "void printLetterList(){ positionList* positionIterator; letterList* letterIterator = letterSet; while(letterIterator!=NULL){ if(letterIterator->repititions>0){ printf(\"\\n'%c' (0x%x) at positions :\",letterIterator->letter,letterIterator->letter); positionIterator = letterIterator->positions; while(positionIterator!=NULL){ printf(\"%3d\",positionIterator->position + 1); positionIterator = positionIterator->next; } } letterIterator = letterIterator->next; } printf(\"\\n\"); }", "after": "pub extern \"C\" fn printLetterList() { unsafe { let mut positionIterator: *mut positionList = 0 as *mut positionList; let mut letterIterator: *mut letterList = letterSet; while !letterIterator.is_null() { if (*letterIterator).repititions > 0 { print!( \"\\n{} (0x{:x}) at positions :\", (*letterIterator).letter as i32, (*letterIterator).letter as i32 ); positionIterator = (*letterIterator).positions; while !positionIterator.is_null() { print!(\"{:3}\", (*positionIterator).position + 1); positionIterator = (*positionIterator).next; } } letterIterator = (*letterIterator).next; } print!(\"\\n\"); } }" }, { "index": 736, "before": "void checkAndUpdateLetterList(char c,int pos){ bool letterOccurs = false; letterList *letterIterator,*newLetter; positionList *positionIterator,*newPosition; if(letterSet==NULL){ letterSet = (letterList*)malloc(sizeof(letterList)); letterSet->letter = c; letterSet->repititions = 0; letterSet->positions = (positionList*)malloc(sizeof(positionList)); letterSet->positions->position = pos; letterSet->positions->next = NULL; letterSet->next = NULL; } else{ letterIterator = letterSet; while(letterIterator!=NULL){ if(letterIterator->letter==c){ letterOccurs = true; duplicatesFound = true; letterIterator->repititions++; positionIterator = letterIterator->positions; while(positionIterator->next!=NULL) positionIterator = positionIterator->next; newPosition = (positionList*)malloc(sizeof(positionList)); newPosition->position = pos; newPosition->next = NULL; positionIterator->next = newPosition; } if(letterOccurs==false && letterIterator->next==NULL) break; else letterIterator = letterIterator->next; } if(letterOccurs==false){ newLetter = (letterList*)malloc(sizeof(letterList)); newLetter->letter = c; newLetter->repititions = 0; newLetter->positions = (positionList*)malloc(sizeof(positionList)); newLetter->positions->position = pos; newLetter->positions->next = NULL; newLetter->next = NULL; letterIterator->next = newLetter; } } }", "after": "pub extern \"C\" fn checkAndUpdateLetterList(mut c: i8, mut pos: i32) { unsafe { let mut letterOccurs: bool = 0 != 0; let mut letterIterator: *mut letterList = 0 as *mut letterList; let mut newLetter: *mut letterList = 0 as *mut letterList; let mut positionIterator: *mut positionList = 0 as *mut positionList; let mut newPosition: *mut positionList = 0 as *mut positionList; if letterSet.is_null() { letterSet = malloc(::core::mem::size_of::() as u64) as *mut letterList; (*letterSet).letter = c; (*letterSet).repititions = 0; (*letterSet).positions = malloc(::core::mem::size_of::() as u64) as *mut positionList; (*(*letterSet).positions).position = pos; (*(*letterSet).positions).next = 0 as *mut positionList; (*letterSet).next = 0 as *mut letterList; } else { letterIterator = letterSet; while !letterIterator.is_null() { if (*letterIterator).letter as i32 == c as i32 { letterOccurs = 1 != 0; duplicatesFound = 1 != 0; (*letterIterator).repititions += 1; (*letterIterator).repititions; positionIterator = (*letterIterator).positions; while !((*positionIterator).next).is_null() { positionIterator = (*positionIterator).next; } newPosition = malloc(::core::mem::size_of::() as u64) as *mut positionList; (*newPosition).position = pos; (*newPosition).next = 0 as *mut positionList; (*positionIterator).next = newPosition; } if letterOccurs as i32 == 0 && ((*letterIterator).next).is_null() { break; } letterIterator = (*letterIterator).next; } if letterOccurs as i32 == 0 { newLetter = malloc(::core::mem::size_of::() as u64) as *mut letterList; (*newLetter).letter = c; (*newLetter).repititions = 0; (*newLetter).positions = malloc(::core::mem::size_of::() as u64) as *mut positionList; (*(*newLetter).positions).position = pos; (*(*newLetter).positions).next = 0 as *mut positionList; (*newLetter).next = 0 as *mut letterList; (*letterIterator).next = newLetter; } }; } }" }, { "index": 737, "before": "int main(int argc,char** argv) { int i,len; if(argc>2){ printf(\"Usage : %s \\n\",argv[0]); return 0; } if(argc==1||strlen(argv[1])==1){ printf(\"\\\"%s\\\" - Length %d - Contains only unique characters.\\n\",argc==1?\"\":argv[1],argc==1?0:1); return 0; } len = strlen(argv[1]); for(i=0;i i32 { unsafe { let mut i: i32 = 0; let mut len: i32 = 0; if argc > 2 { print!( \"Usage : {} \\n\", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); return 0; } if argc == 1 || strlen(*argv.offset(1 as isize)) == 1 { if argc == 1 { if argc == 1 { print!( \"\\\"{}\\\" - Length {} - Contains only unique characters.\\n\", \"\\0\", 0 ) } else { print!( \"\\\"{}\\\" - Length {} - Contains only unique characters.\\n\", \"\\0\", 1 ) } } else { if argc == 1 { print!( \"\\\"{}\\\" - Length {} - Contains only unique characters.\\n\", build_str_from_raw_ptr(*argv.offset(1 as isize) as *const i8 as *mut u8), 0 ) } else { print!( \"\\\"{}\\\" - Length {} - Contains only unique characters.\\n\", build_str_from_raw_ptr(*argv.offset(1 as isize) as *const i8 as *mut u8), 1 ) } }; return 0; } len = strlen(*argv.offset(1 as isize)) as i32; i = 0; while i < len { checkAndUpdateLetterList(*(*argv.offset(1 as isize)).offset(i as isize), i); i += 1; i; } if duplicatesFound as i32 == 0 { print!( \"\\\"{}\\\" - Length {} - {}\", build_str_from_raw_ptr(*argv.offset(1 as isize) as *mut u8), len, \"Contains only unique characters.\\n\\0\" ) } else { print!( \"\\\"{}\\\" - Length {} - {}\", build_str_from_raw_ptr(*argv.offset(1 as isize) as *mut u8), len, \"Contains the following duplicate characters :\\0\" ) }; if duplicatesFound as i32 == 1 { printLetterList(); } return 0; } }" }, { "index": 738, "before": "int main(void) { \tint i, d, pers; \tlong long x[] = {627615, 39390, 588225, 393900588225LL}; \tfor (i = 0; i < 4; i++) { \t\td = droot(x[i], 10, &pers); \t\tprintf(\"%lld: pers %d, root %d\\n\", x[i], pers, d); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut d: i32 = 0; let mut pers: i32 = 0; let mut x: [i64; 4] = [627615, 39390, 588225, 393900588225]; i = 0; while i < 4 { d = droot(x[i as usize], 10, &mut pers); print!(\"{}: pers {}, root {}\\n\", x[i as usize], pers, d); i += 1; i; } return 0; }" }, { "index": 739, "before": "int droot(long long int x, int base, int *pers) { \tint d = 0; \tif (pers) \t\tfor (*pers = 0; x >= base; x = d, (*pers)++) \t\t\tfor (d = 0; x; d += x % base, x /= base); \telse if (x && !(d = x % (base - 1))) \t\t\td = base - 1; \treturn d; }", "after": "pub extern \"C\" fn droot(mut x: i64, mut base: i32, mut pers: *mut i32) -> i32 { unsafe { let mut d: i32 = 0; if !pers.is_null() { *pers = 0; while x >= base as i64 { d = 0; while x != 0 { d = (d as i64 + x % base as i64) as i32; x /= base as i64; } x = d as i64; *pers += 1; *pers; } } else if x != 0 && { d = (x % (base - 1i32) as i64) as i32; d == 0 } { d = base - 1; } return d; } }" }, { "index": 740, "before": "void string_test(const char *s) { \tchar *ret = malloc(strlen(s)); \tstrcpy(ret, s); \tprintf(\"text: %s\\n\", ret); \tprintf(\" ->: %s\\n\", ret = incr(ret)); \tfree(ret); }", "after": "pub extern \"C\" fn string_test(mut s: *const i8) { unsafe { let mut ret: *mut i8 = malloc(strlen(s)) as *mut i8; strcpy(ret, s); print!(\"text: {}\\n\", build_str_from_raw_ptr(ret as *mut u8)); ret = incr(ret); print!(\" ->: {}\\n\", build_str_from_raw_ptr(ret as *mut u8)); free(ret as *mut libc::c_void); } }" }, { "index": 741, "before": "int main() { \tstring_test(\"+0\"); \tstring_test(\"-1\"); \tstring_test(\"-41\"); \tstring_test(\"+41\"); \tstring_test(\"999\"); \tstring_test(\"+999\"); \tstring_test(\"109999999999999999999999999999999999999999\"); \tstring_test(\"-100000000000000000000000000000000000000000000\"); \treturn 0; }", "after": "fn main() -> i32 { string_test(b\"+0\\0\" as *const u8 as *const i8); string_test(b\"-1\\0\" as *const u8 as *const i8); string_test(b\"-41\\0\" as *const u8 as *const i8); string_test(b\"+41\\0\" as *const u8 as *const i8); string_test(b\"999\\0\" as *const u8 as *const i8); string_test(b\"+999\\0\" as *const u8 as *const i8); string_test(b\"109999999999999999999999999999999999999999\\0\" as *const u8 as *const i8); string_test(b\"-100000000000000000000000000000000000000000000\\0\" as *const u8 as *const i8); return 0; }" }, { "index": 742, "before": "int main (int argc, char *argv[]) { //here we check arguments \tif (argc < 2) { printf(\"Enter an argument. Example 1234 or dcba:\\n\"); return 0; \t} //it calculates an array's length int x; for (x = 0; argv[1][x] != '\\0'; x++); //buble sort the array \tint f, v, m; \t for(f=0; f < x; f++) { \t for(v = x-1; v > f; v-- ) { \t if (argv[1][v-1] > argv[1][v]) { \tm=argv[1][v-1]; \targv[1][v-1]=argv[1][v]; \targv[1][v]=m; } } } //it calculates a factorial to stop the algorithm char a[x]; \tint k=0; \tint fact=k+1; while (k!=x) { a[k]=argv[1][k]; \t k++; \t\t fact = k*fact; } a[k]='\\0'; //Main part: here we permutate int i, j; int y=0; char c; while (y != fact) { printf(\"%s\\n\", a); i=x-2; while(a[i] > a[i+1] ) i--; j=x-1; while(a[j] < a[i] ) j--; c=a[j]; a[j]=a[i]; a[i]=c; i++; for (j = x-1; j > i; i++, j--) { c = a[i]; a[i] = a[j]; a[j] = c; } y++; } }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { if argc < 2 { print!(\"Enter an argument. Example 1234 or dcba:\\n\"); return 0; } let mut x: i32 = 0; x = 0; while *(*argv.offset(1 as isize)).offset(x as isize) as i32 != '\\0' as i32 { x += 1; x; } let mut f: i32 = 0; let mut v: i32 = 0; let mut m: i32 = 0; f = 0; while f < x { v = x - 1; while v > f { if *(*argv.offset(1 as isize)).offset((v - 1i32) as isize) as i32 > *(*argv.offset(1 as isize)).offset(v as isize) as i32 { m = *(*argv.offset(1 as isize)).offset((v - 1i32) as isize) as i32; *(*argv.offset(1 as isize)).offset((v - 1i32) as isize) = *(*argv.offset(1 as isize)).offset(v as isize); *(*argv.offset(1 as isize)).offset(v as isize) = m as i8; } v -= 1; v; } f += 1; f; } let vla = x as usize; let mut a: Vec = ::std::vec::from_elem(0, vla); let mut k: i32 = 0; let mut fact: i32 = k + 1; while k != x { *a.as_mut_ptr().offset(k as isize) = *(*argv.offset(1 as isize)).offset(k as isize); k += 1; k; fact = k * fact; } *a.as_mut_ptr().offset(k as isize) = '\\0' as i8; let mut i: i32 = 0; let mut j: i32 = 0; let mut y: i32 = 0; let mut c: i8 = 0; while y != fact { print!(\"{}\\n\", build_str_from_raw_ptr(a.as_mut_ptr() as *mut u8)); i = x - 2; while *a.as_mut_ptr().offset(i as isize) as i32 > *a.as_mut_ptr().offset((i + 1i32) as isize) as i32 { i -= 1; i; } j = x - 1; while (*a.as_mut_ptr().offset(j as isize) as i32) < *a.as_mut_ptr().offset(i as isize) as i32 { j -= 1; j; } c = *a.as_mut_ptr().offset(j as isize); *a.as_mut_ptr().offset(j as isize) = *a.as_mut_ptr().offset(i as isize); *a.as_mut_ptr().offset(i as isize) = c; i += 1; i; j = x - 1; while j > i { c = *a.as_mut_ptr().offset(i as isize); *a.as_mut_ptr().offset(i as isize) = *a.as_mut_ptr().offset(j as isize); *a.as_mut_ptr().offset(j as isize) = c; i += 1; i; j -= 1; j; } y += 1; y; } return 0; } }" }, { "index": 743, "before": "int main() { int years[] = { 1935, 1938, 1968, 1972, 1976, 2017 }; int i; //the zodiac cycle didnt start until 4 CE, so years <4 shouldnt be valid for (i = 0; i < 6; ++i) { int year = years[i]; printf(\"%d is the year of the %s %s (%s).\\n\", year, getElement(year), getAnimal(year), getYY(year)); } return 0; }", "after": "fn main() -> i32 { let mut years: [i32; 6] = [1935, 1938, 1968, 1972, 1976, 2017]; let mut i: i32 = 0; i = 0; unsafe { while i < 6 { let mut year: i32 = years[i as usize]; print!( \"{} is the year of the {} {} ({}).\\n\", year, build_str_from_raw_ptr(getElement(year) as *mut u8), build_str_from_raw_ptr(getAnimal(year) as *mut u8), build_str_from_raw_ptr(getYY(year) as *mut u8) ); i += 1; i; } } return 0; }" }, { "index": 744, "before": "int main() { const char *fruit[2] = { \"apples\", \"oranges\" }; // Acquire the length of the array by dividing the size of all elements (found // with sizeof(fruit)) by the size of the first element. // Note that since the array elements are pointers to null-terminated character // arrays, the size of the first element is actually the size of the pointer // type - not the length of the string. // This size, regardless of the type being pointed to, is 8 bytes, 4 bytes, or // 2 bytes on 64-bit, 32-bit, or 16-bit platforms respectively. int length = sizeof(fruit) / sizeof(fruit[0]); printf(\"%d\\n\", length); return 0; }", "after": "fn main() -> i32 { let mut fruit: [*const i8; 2] = [ b\"apples\\0\" as *const u8 as *const i8, b\"oranges\\0\" as *const u8 as *const i8, ]; let mut length: i32 = (::core::mem::size_of::<[*const i8; 2]>() as u64) .wrapping_div(::core::mem::size_of::<*const i8>() as u64) as i32; print!(\"{}\\n\", length); return 0; }" }, { "index": 745, "before": "void optimal_matrix_chain_order(int *dims, int n) { int len, i, j, k, temp, cost; n--; m = (int **)malloc(n * sizeof(int *)); for (i = 0; i < n; ++i) { m[i] = (int *)calloc(n, sizeof(int)); } s = (int **)malloc(n * sizeof(int *)); for (i = 0; i < n; ++i) { s[i] = (int *)calloc(n, sizeof(int)); } for (len = 1; len < n; ++len) { for (i = 0; i < n - len; ++i) { j = i + len; m[i][j] = INT_MAX; for (k = i; k < j; ++k) { temp = dims[i] * dims[k + 1] * dims[j + 1]; cost = m[i][k] + m[k + 1][j] + temp; if (cost < m[i][j]) { m[i][j] = cost; s[i][j] = k; } } } } }", "after": "pub extern \"C\" fn optimal_matrix_chain_order(mut dims: *mut i32, mut n: i32) { unsafe { let mut len: i32 = 0; let mut i: i32 = 0; let mut j: i32 = 0; let mut k: i32 = 0; let mut temp: i32 = 0; let mut cost: i32 = 0; n -= 1; n; m = malloc((n as u64).wrapping_mul(::core::mem::size_of::<*mut i32>() as u64)) as *mut *mut i32; i = 0; while i < n { let ref mut fresh0 = *m.offset(i as isize); *fresh0 = calloc(n as u64, ::core::mem::size_of::() as u64) as *mut i32; i += 1; i; } s = malloc((n as u64).wrapping_mul(::core::mem::size_of::<*mut i32>() as u64)) as *mut *mut i32; i = 0; while i < n { let ref mut fresh1 = *s.offset(i as isize); *fresh1 = calloc(n as u64, ::core::mem::size_of::() as u64) as *mut i32; i += 1; i; } len = 1; while len < n { i = 0; while i < n - len { j = i + len; *(*m.offset(i as isize)).offset(j as isize) = 2147483647; k = i; while k < j { temp = *dims.offset(i as isize) * *dims.offset((k + 1i32) as isize) * *dims.offset((j + 1i32) as isize); cost = *(*m.offset(i as isize)).offset(k as isize) + *(*m.offset((k + 1i32) as isize)).offset(j as isize) + temp; if cost < *(*m.offset(i as isize)).offset(j as isize) { *(*m.offset(i as isize)).offset(j as isize) = cost; *(*s.offset(i as isize)).offset(j as isize) = k; } k += 1; k; } i += 1; i; } len += 1; len; } } }" }, { "index": 746, "before": "void print_optimal_chain_order(int i, int j) { if (i == j) printf(\"%c\", i + 65); else { printf(\"(\"); print_optimal_chain_order(i, s[i][j]); print_optimal_chain_order(s[i][j] + 1, j); printf(\")\"); } }", "after": "pub extern \"C\" fn print_optimal_chain_order(mut i: i32, mut j: i32) { unsafe { if i == j { print!(\"{}\", i + 65); } else { print!(\"(\"); print_optimal_chain_order(i, *(*s.offset(i as isize)).offset(j as isize)); print_optimal_chain_order(*(*s.offset(i as isize)).offset(j as isize) + 1, j); print!(\")\"); }; } }" }, { "index": 747, "before": "int main() { int i, j, n; int a1[4] = {5, 6, 3, 1}; int a2[13] = {1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2}; int a3[12] = {1000, 1, 500, 12, 1, 700, 2500, 3, 2, 5, 14, 10}; int *dims_list[3] = {a1, a2, a3}; int sizes[3] = {4, 13, 12}; for (i = 0; i < 3; ++i) { printf(\"Dims : [\"); n = sizes[i]; for (j = 0; j < n; ++j) { printf(\"%d\", dims_list[i][j]); if (j < n - 1) printf(\", \"); else printf(\"]\\n\"); } optimal_matrix_chain_order(dims_list[i], n); printf(\"Order : \"); print_optimal_chain_order(0, n - 2); printf(\"\\nCost : %d\\n\\n\", m[0][n - 2]); for (j = 0; j <= n - 2; ++j) free(m[j]); free(m); for (j = 0; j <= n - 2; ++j) free(s[j]); free(s); } return 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; let mut j: i32 = 0; let mut n: i32 = 0; let mut a1: [i32; 4] = [5, 6, 3, 1]; let mut a2: [i32; 13] = [1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2]; let mut a3: [i32; 12] = [1000, 1, 500, 12, 1, 700, 2500, 3, 2, 5, 14, 10]; let mut dims_list: [*mut i32; 3] = [a1.as_mut_ptr(), a2.as_mut_ptr(), a3.as_mut_ptr()]; let mut sizes: [i32; 3] = [4, 13, 12]; i = 0; unsafe { while i < 3 { print!(\"Dims : [\"); n = sizes[i as usize]; j = 0; while j < n { print!(\"{}\", *(dims_list[i as usize]).offset(j as isize)); if j < n - 1 { print!(\", \"); } else { print!(\"]\\n\"); } j += 1; j; } optimal_matrix_chain_order(dims_list[i as usize], n); print!(\"Order : \"); print_optimal_chain_order(0, n - 2); print!( \"\\nCost : {}\\n\\n\", *(*m.offset(0 as isize)).offset((n - 2i32) as isize) ); j = 0; while j <= n - 2 { free(*m.offset(j as isize) as *mut libc::c_void); j += 1; j; } free(m as *mut libc::c_void); j = 0; while j <= n - 2 { free(*s.offset(j as isize) as *mut libc::c_void); j += 1; j; } free(s as *mut libc::c_void); i += 1; i; } } return 0; }" }, { "index": 748, "before": "int main(void) { const int len = sizeof(tri) / sizeof(tri[0]); const int base = (sqrt(8*len + 1) - 1) / 2; int step = base - 1; int stepc = 0; int i; for (i = len - base - 1; i >= 0; --i) { tri[i] += max(tri[i + step], tri[i + step + 1]); if (++stepc == step) { step--; stepc = 0; } } printf(\"%d\\n\", tri[0]); return 0; }", "after": "fn main() -> i32 { let len: i32 = (::core::mem::size_of::<[i32; 171]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32; unsafe { let base: i32 = ((sqrt((8 * len + 1i32) as f64) - 1 as f64) / 2 as f64) as i32; let mut step: i32 = base - 1; let mut stepc: i32 = 0; let mut i: i32 = 0; i = len - base - 1; while i >= 0 { tri[i as usize] += if tri[(i + step) as usize] > tri[(i + step + 1i32) as usize] { tri[(i + step) as usize] } else { tri[(i + step + 1i32) as usize] }; stepc += 1; if stepc == step { step -= 1; step; stepc = 0; } i -= 1; i; } print!(\"{}\\n\", tri[0 as usize]); } return 0; }" }, { "index": 749, "before": "ull binomial(ull m, ull n) { \tull r = 1, d = m - n; \tif (d > n) { n = d; d = m - n; } \twhile (m > n) { \t\tr *= m--; \t\twhile (d > 1 && ! (r%d) ) r /= d--; \t} \treturn r; }", "after": "pub extern \"C\" fn binomial(mut m: u64, mut n: u64) -> u64 { let mut r: u64 = 1; let mut d: u64 = m.wrapping_sub(n); if d > n { n = d; d = m.wrapping_sub(n); } while m > n { let fresh0 = m; m = m.wrapping_sub(1); r = (r).wrapping_mul(fresh0) as u64; while d > 1 && r.wrapping_rem(d) == 0 { let fresh1 = d; d = d.wrapping_sub(1); r = (r).wrapping_div(fresh1) as u64; } } return r; }" }, { "index": 750, "before": "ull catalan2(int n) { \tint i; \tull r = !n; \tfor (i = 0; i < n; i++) \t\tr += catalan2(i) * catalan2(n - 1 - i); \treturn r; }", "after": "pub extern \"C\" fn catalan2(mut n: i32) -> u64 { let mut i: i32 = 0; let mut r: u64 = (n == 0) as u64; i = 0; while i < n { r = (r).wrapping_add((catalan2(i)).wrapping_mul(catalan2(n - 1 - i))) as u64; i += 1; i; } return r; }" }, { "index": 751, "before": "ull catalan1(int n) { \treturn binomial(2 * n, n) / (1 + n); }", "after": "pub extern \"C\" fn catalan1(mut n: i32) -> u64 { return (binomial((2 * n) as u64, n as u64)).wrapping_div((1 + n) as u64); }" }, { "index": 752, "before": "ull catalan3(int n) { \treturn n ? 2 * (2 * n - 1) * catalan3(n - 1) / (1 + n) : 1; }", "after": "pub extern \"C\" fn catalan3(mut n: i32) -> u64 { return if n != 0 { ((2 * (2 * n - 1i32)) as u64) .wrapping_mul(catalan3(n - 1)) .wrapping_div((1 + n) as u64) } else { 1 }; }" }, { "index": 753, "before": "int main(void) { \tint i; \tputs(\"\\tdirect\\tsumming\\tfrac\"); \tfor (i = 0; i < 16; i++) { \t\tprintf(\"%d\\t%llu\\t%llu\\t%llu\\n\", i, \t\t\tcatalan1(i), catalan2(i), catalan3(i)); \t} \treturn 0; }", "after": "fn main() -> i32 { let mut i: i32 = 0; unsafe { puts(b\"\\tdirect\\tsumming\\tfrac\\0\" as *const u8 as *const i8); } i = 0; while i < 16 { print!(\"{}\t{}\t{}\t{}\\n\", i, catalan1(i), catalan2(i), catalan3(i)); i += 1; i; } return 0; }" }, { "index": 754, "before": "void new_tri(xint in[]) { int i; xint t[3], p = in[0] + in[1] + in[2]; if (p > max_peri) return; prim ++; /* for every primitive triangle, its multiples would be right-angled too; * count them up to the max perimeter */ total += max_peri / p; /* recursively produce next tier by multiplying the matrices */ for (i = 0; i < 3; i++) { t[0] = U[i][0] * in[0] + U[i][1] * in[1] + U[i][2] * in[2]; t[1] = U[i][3] * in[0] + U[i][4] * in[1] + U[i][5] * in[2]; t[2] = U[i][6] * in[0] + U[i][7] * in[1] + U[i][8] * in[2]; new_tri(t); } }", "after": "pub extern \"C\" fn new_tri(mut in_0: *mut u64) { unsafe { let mut i: i32 = 0; let mut t: [u64; 3] = [0; 3]; let mut p: u64 = (*in_0.offset(0 as isize)) .wrapping_add(*in_0.offset(1 as isize)) .wrapping_add(*in_0.offset(2 as isize)); if p > max_peri { return; } prim = prim.wrapping_add(1); prim; total = (total as u64).wrapping_add(max_peri.wrapping_div(p)) as u64; i = 0; while i < 3 { t[0 as usize] = (U[i as usize][0 as usize]) .wrapping_mul(*in_0.offset(0 as isize)) .wrapping_add((U[i as usize][1 as usize]).wrapping_mul(*in_0.offset(1 as isize))) .wrapping_add((U[i as usize][2 as usize]).wrapping_mul(*in_0.offset(2 as isize))); t[1 as usize] = (U[i as usize][3 as usize]) .wrapping_mul(*in_0.offset(0 as isize)) .wrapping_add((U[i as usize][4 as usize]).wrapping_mul(*in_0.offset(1 as isize))) .wrapping_add((U[i as usize][5 as usize]).wrapping_mul(*in_0.offset(2 as isize))); t[2 as usize] = (U[i as usize][6 as usize]) .wrapping_mul(*in_0.offset(0 as isize)) .wrapping_add((U[i as usize][7 as usize]).wrapping_mul(*in_0.offset(1 as isize))) .wrapping_add((U[i as usize][8 as usize]).wrapping_mul(*in_0.offset(2 as isize))); new_tri(t.as_mut_ptr()); i += 1; i; } } }" }, { "index": 755, "before": "int main() { xint seed[3] = {3, 4, 5}; for (max_peri = 10; max_peri <= 100000000; max_peri *= 10) { total = prim = 0; new_tri(seed); printf( \"Up to \"FMT\": \"FMT\" triples, \"FMT\" primitives.\\n\", max_peri, total, prim); } return 0; }", "after": "fn main() -> i32 { let mut seed: [u64; 3] = [3, 4, 5]; unsafe { max_peri = 10; while max_peri <= 100000000 { prim = 0; total = prim; new_tri(seed.as_mut_ptr()); print!( \"Up to {}: {} triples, {} primitives.\\n\", max_peri, total, prim ); max_peri = (max_peri as u64).wrapping_mul(10) as u64; } } return 0; }" }, { "index": 756, "before": "int main() { int test_case[] = {1900, 1994, 1996, 1997, 2000}, key, end, year; for (key = 0, end = sizeof(test_case)/sizeof(test_case[0]); key < end; ++key) { year = test_case[key]; printf(\"%d is %sa leap year.\\n\", year, (is_leap_year(year) == 1 ? \"\" : \"not \")); } }", "after": "fn main() -> i32 { let mut test_case: [i32; 5] = [1900, 1994, 1996, 1997, 2000]; let mut key: i32 = 0; let mut end: i32 = 0; let mut year: i32 = 0; key = 0; end = (::core::mem::size_of::<[i32; 5]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32; while key < end { year = test_case[key as usize]; if is_leap_year(year) == 1 { print!(\"{} is {}a leap year.\\n\", year, \"\\0\") } else { print!(\"{} is {}a leap year.\\n\", year, \"not \\0\") }; key += 1; key; } return 0; }" }, { "index": 757, "before": "int is_leap_year(int year) { return (!(year % 4) && year % 100 || !(year % 400)) ? 1 : 0; }", "after": "pub extern \"C\" fn is_leap_year(mut year: i32) -> i32 { return if year % 4 == 0 && year % 100 != 0 || year % 400 == 0 { 1 } else { 0 }; }" }, { "index": 758, "before": "bool is_prime(uint32_t n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (uint32_t p = 3; p * p <= n; p += 2) { if (n % p == 0) return false; } return true; }", "after": "pub extern \"C\" fn is_prime(mut n: u32) -> bool { if n == 2 { return 1 != 0; } if n < 2 || n.wrapping_rem(2) == 0 { return 0 != 0; } let mut p: u32 = 3; while p.wrapping_mul(p) <= n { if n.wrapping_rem(p) == 0 { return 0 != 0; } p = (p).wrapping_add(2) as u32; } return 1 != 0; }" }, { "index": 759, "before": "bool is_circular_prime(uint32_t p) { if (!is_prime(p)) return false; uint32_t p2 = cycle(p); while (p2 != p) { if (p2 < p || !is_prime(p2)) return false; p2 = cycle(p2); } return true; }", "after": "pub extern \"C\" fn is_circular_prime(mut p: u32) -> bool { if !is_prime(p) { return 0 != 0; } let mut p2: u32 = cycle(p); while p2 != p { if p2 < p || !is_prime(p2) { return 0 != 0; } p2 = cycle(p2); } return 1 != 0; }" }, { "index": 760, "before": "uint32_t cycle(uint32_t n) { uint32_t m = n, p = 1; while (m >= 10) { p *= 10; m /= 10; } return m + 10 * (n % p); }", "after": "pub extern \"C\" fn cycle(mut n: u32) -> u32 { let mut m: u32 = n; let mut p: u32 = 1; while m >= 10 { p = (p).wrapping_mul(10) as u32; m = (m).wrapping_div(10) as u32; } return m.wrapping_add(10u32.wrapping_mul(n.wrapping_rem(p))); }" }, { "index": 761, "before": "bool command_match(const command_t* command, const char* str) { size_t olen = strlen(str); return olen >= command->min_len && olen <= command->length && strncmp(str, command->cmd, olen) == 0; }", "after": "pub extern \"C\" fn command_match(mut command: *const command_t, mut str: *const i8) -> bool { unsafe { let mut olen: u64 = strlen(str); return olen >= (*command).min_len && olen <= (*command).length && strncmp(str, (*command).cmd, olen) == 0; } }" }, { "index": 762, "before": "size_t get_min_length(const char* str, size_t n) { size_t len = 0; while (len < n && isupper((unsigned char)str[len])) ++len; return len; }", "after": "pub extern \"C\" fn get_min_length(mut str: *const i8, mut n: u64) -> u64 { unsafe { let mut len: u64 = 0; while len < n && *(*__ctype_b_loc()).offset(*str.offset(len as isize) as i32 as isize) as i32 & _ISupper as i32 != 0 { len = len.wrapping_add(1); len; } return len; } }" }, { "index": 763, "before": "int main() { command_t* commands = make_command_list(command_table); const char* input = \"riG rePEAT copies put mo rest types fup. 6 poweRin\"; test(commands, input); free_command_list(commands); return 0; }", "after": "fn main() -> i32 { unsafe { let mut commands: *mut command_t = make_command_list(command_table); let mut input: *const i8 = b\"riG rePEAT copies put mo rest types fup. 6 poweRin\\0\" as *const u8 as *const i8; test(commands, input); free_command_list(commands); return 0; } }" }, { "index": 764, "before": "void fatal(const char* message) { fprintf(stderr, \"%s\\n\", message); exit(1); }", "after": "pub extern \"C\" fn fatal(mut message: *const i8) { unsafe { fprintf(stderr, b\"%s\\n\\0\" as *const u8 as *const i8, message); exit(1); } }" }, { "index": 765, "before": "void free_command_list(command_t* cmd) { while (cmd != NULL) { command_t* next = cmd->next; free(cmd->cmd); free(cmd); cmd = next; } }", "after": "pub extern \"C\" fn free_command_list(mut cmd: *mut command_t) { unsafe { while !cmd.is_null() { let mut next: *mut command_t = (*cmd).next; free((*cmd).cmd as *mut libc::c_void); free(cmd as *mut libc::c_void); cmd = next; } } }" }, { "index": 766, "before": "void test(const command_t* commands, const char* input) { printf(\" input: %s\\n\", input); printf(\"output:\"); size_t count = 0; char** words = split_into_words(input, &count); for (size_t i = 0; i < count; ++i) { char* word = words[i]; uppercase(word, strlen(word)); const command_t* cmd_ptr = find_command(commands, word); printf(\" %s\", cmd_ptr ? cmd_ptr->cmd : \"*error*\"); free(word); } free(words); printf(\"\\n\"); }", "after": "pub extern \"C\" fn test(mut commands: *const command_t, mut input: *const i8) { unsafe { print!(\" input: {}\\n\", build_str_from_raw_ptr(input as *mut u8)); print!(\"output:\"); let mut count: u64 = 0; let mut words: *mut *mut i8 = split_into_words(input, &mut count); let mut i: u64 = 0; while i < count { let mut word: *mut i8 = *words.offset(i as isize); uppercase(word, strlen(word)); let mut cmd_ptr: *const command_t = find_command(commands, word); if !cmd_ptr.is_null() { print!( \" {}\", build_str_from_raw_ptr((*cmd_ptr).cmd as *const i8 as *mut u8) ) } else { print!(\" {}\", \"*error*\\0\") }; free(word as *mut libc::c_void); i = i.wrapping_add(1); i; } free(words as *mut libc::c_void); print!(\"\\n\"); } }" }, { "index": 767, "before": "int f(int n, int x, int y) { \treturn (x + y*2 + 1)%n; }", "after": "pub extern \"C\" fn f(mut n: i32, mut x: i32, mut y: i32) -> i32 { return (x + y * 2 + 1) % n; }" }, { "index": 768, "before": "int main(int argc, char **argv) { \tint i, j, n; \t//Edit: Add argument checking \tif(argc!=2) return 1; \t//Edit: Input must be odd and not less than 3. \tn = atoi(argv[1]); \tif (n < 3 || (n%2) == 0) return 2; \tfor (i = 0; i < n; i++) { \t\tfor (j = 0; j < n; j++) \t\t\tprintf(\"% 4d\", f(n, n - j - 1, i)*n + f(n, j, i) + 1); \t\tputchar('\\n'); \t} \tprintf(\"\\n Magic Constant: %d.\\n\", (n*n+1)/2*n); \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 n: i32 = 0; if argc != 2 { return 1; } n = atoi(*argv.offset(1 as isize)); if n < 3 || n % 2 == 0 { return 2; } i = 0; while i < n { j = 0; while j < n { print!(\"% 4d\"); j += 1; j; } print!(\"{}\", '\\n' as i32); i += 1; i; } print!(\"\\n Magic Constant: {}.\\n\", (n * n + 1) / 2 * n); return 0; } }" }, { "index": 769, "before": "uintmax_t sec_to_week(uintmax_t seconds) { return sec_to_day(seconds)/7; }", "after": "pub extern \"C\" fn sec_to_week(mut seconds: u64) -> u64 { return (sec_to_day(seconds)).wrapping_div(7); }" }, { "index": 770, "before": "uintmax_t hour_to_sec(uintmax_t hours) { return min_to_sec(hours*60); }", "after": "pub extern \"C\" fn hour_to_sec(mut hours: u64) -> u64 { return min_to_sec(hours.wrapping_mul(60)); }" }, { "index": 771, "before": "uintmax_t sec_to_hour(uintmax_t seconds) { return sec_to_min(seconds)/60; }", "after": "pub extern \"C\" fn sec_to_hour(mut seconds: u64) -> u64 { return (sec_to_min(seconds)).wrapping_div(60); }" }, { "index": 772, "before": "uintmax_t day_to_sec(uintmax_t days) { return hour_to_sec(days*24); }", "after": "pub extern \"C\" fn day_to_sec(mut days: u64) -> u64 { return hour_to_sec(days.wrapping_mul(24)); }" }, { "index": 773, "before": "uintmax_t min_to_sec(uintmax_t minutes) { return minutes*60; }", "after": "pub extern \"C\" fn min_to_sec(mut minutes: u64) -> u64 { return minutes.wrapping_mul(60); }" }, { "index": 774, "before": "int main(int argc, char *argv[]) { uintmax_t input; char *a; if(argc<2) { printf(\"usage: %s #seconds\\n\", argv[0]); return 1; } input = strtoumax(argv[1],(void *)0, 10 /*base 10*/); if(input<1) { printf(\"Bad input: %s\\n\", argv[1]); printf(\"usage: %s #seconds\\n\", argv[0]); return 1; } printf(\"Number entered: %\" PRIuMAX \"\\n\", input); a = format_sec(input); printf(a); free(a); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut input: u64 = 0; let mut a: *mut i8 = 0 as *mut i8; if argc < 2 { print!( \"usage: {} #seconds\\n\", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); return 1; } input = strtoumax(*argv.offset(1 as isize), 0 as *mut *mut i8, 10); if input < 1 { print!( \"Bad input: {}\\n\", build_str_from_raw_ptr(*argv.offset(1 as isize) as *mut u8) ); print!( \"usage: {} #seconds\\n\", build_str_from_raw_ptr(*argv.offset(0 as isize) as *mut u8) ); return 1; } print!(\"Number entered: {}\\n\", input); a = format_sec(input); printf(a); free(a as *mut libc::c_void); return 0; } }" }, { "index": 775, "before": "uintmax_t week_to_sec(uintmax_t weeks) { return day_to_sec(weeks*7); }", "after": "pub extern \"C\" fn week_to_sec(mut weeks: u64) -> u64 { return day_to_sec(weeks.wrapping_mul(7)); }" }, { "index": 776, "before": "uintmax_t sec_to_day(uintmax_t seconds) { return sec_to_hour(seconds)/24; }", "after": "pub extern \"C\" fn sec_to_day(mut seconds: u64) -> u64 { return (sec_to_hour(seconds)).wrapping_div(24); }" }, { "index": 777, "before": "uintmax_t sec_to_min(uintmax_t seconds) { return seconds/60; }", "after": "pub extern \"C\" fn sec_to_min(mut seconds: u64) -> u64 { return seconds.wrapping_div(60); }" }, { "index": 778, "before": "int main(int argc, char **argv) { int a, b, c, d, a2, s = 3, s1, s2; int r[N + 1]; memset(r, 0, sizeof(r)); int *ab = calloc(N2 + 1, sizeof(int)); // allocate on heap, zero filled for (a = 1; a <= N; a++) { a2 = a * a; for (b = a; b <= N; b++) ab[a2 + b * b] = 1; } for (c = 1; c <= N; c++) { s1 = s; s += 2; s2 = s; for (d = c + 1; d <= N; d++) { if (ab[s1]) r[d] = 1; s1 += s2; s2 += 2; } } for (d = 1; d <= N; d++) { if (!r[d]) printf(\"%d \", d); } printf(\"\\n\"); free(ab); return 0; }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { let mut a: i32 = 0; let mut b: i32 = 0; let mut c: i32 = 0; let mut d: i32 = 0; let mut a2: i32 = 0; let mut s: i32 = 3; let mut s1: i32 = 0; let mut s2: i32 = 0; let mut r: [i32; 2201] = [0; 2201]; memset( r.as_mut_ptr() as *mut libc::c_void, 0, ::core::mem::size_of::<[i32; 2201]>() as u64, ); let mut ab: *mut i32 = calloc( (2200 * 2200 * 2 + 1i32) as u64, ::core::mem::size_of::() as u64, ) as *mut i32; a = 1; while a <= 2200 { a2 = a * a; b = a; while b <= 2200 { *ab.offset((a2 + b * b) as isize) = 1; b += 1; b; } a += 1; a; } c = 1; while c <= 2200 { s1 = s; s += 2; s2 = s; d = c + 1; while d <= 2200 { if *ab.offset(s1 as isize) != 0 { r[d as usize] = 1; } s1 += s2; s2 += 2; d += 1; d; } c += 1; c; } d = 1; while d <= 2200 { if r[d as usize] == 0 { print!(\"{} \", d); } d += 1; d; } print!(\"\\n\"); free(ab as *mut libc::c_void); return 0; } }" }, { "index": 779, "before": "int main() { \tchar *object = 0; \tif (object == NULL) { \t\tputs(\"object is null\"); \t} \treturn 0; }", "after": "fn main() -> i32 { unsafe { let mut object: *mut i8 = 0 as *mut i8; if object.is_null() { puts(b\"object is null\\0\" as *const u8 as *const i8); } return 0; } }" }, { "index": 780, "before": "uint32_t next_highest_int(uint32_t n) { char str[16]; snprintf(str, sizeof(str), \"%u\", n); if (!next_permutation(str)) return 0; return strtoul(str, 0, 10); }", "after": "pub extern \"C\" fn next_highest_int(mut n: u32) -> u32 { let mut str: [i8; 16] = [0; 16]; unsafe { snprintf( str.as_mut_ptr(), ::core::mem::size_of::<[i8; 16]>() as u64, b\"%u\\0\" as *const u8 as *const i8, n, ); } if !next_permutation(str.as_mut_ptr()) { return 0; } unsafe { return strtoul(str.as_mut_ptr(), 0 as *mut *mut i8, 10) as u32; } }" }, { "index": 781, "before": "void reverse(char* str, int i, int j) { for (; i < j; ++i, --j) swap(str, i, j); }", "after": "pub extern \"C\" fn reverse(mut str: *mut i8, mut i: i32, mut j: i32) { unsafe { while i < j { swap(str, i, j); i += 1; i; j -= 1; j; } } }" }, { "index": 782, "before": "void swap(char* str, int i, int j) { char c = str[i]; str[i] = str[j]; str[j] = c; }", "after": "pub extern \"C\" fn swap(mut str: *mut i8, mut i: i32, mut j: i32) { unsafe { let mut c: i8 = *str.offset(i as isize); *str.offset(i as isize) = *str.offset(j as isize); *str.offset(j as isize) = c; } }" }, { "index": 783, "before": "bool next_permutation(char* str) { int len = strlen(str); if (len < 2) return false; for (int i = len - 1; i > 0; ) { int j = i, k; if (str[--i] < str[j]) { k = len; while (str[i] >= str[--k]) {} swap(str, i, k); reverse(str, j, len - 1); return true; } } return false; }", "after": "pub extern \"C\" fn next_permutation(mut str: *mut i8) -> bool { unsafe { let mut len: i32 = strlen(str) as i32; if len < 2 { return 0 != 0; } let mut i: i32 = len - 1; while i > 0 { let mut j: i32 = i; let mut k: i32 = 0; i -= 1; if (*str.offset(i as isize) as i32) < *str.offset(j as isize) as i32 { k = len; loop { k -= 1; if !(*str.offset(i as isize) as i32 >= *str.offset(k as isize) as i32) { break; } } swap(str, i, k); reverse(str, j, len - 1); return 1 != 0; } } return 0 != 0; } }" }, { "index": 784, "before": "int main() { uint32_t numbers[] = {0, 9, 12, 21, 12453, 738440, 45072010, 95322020}; const int count = sizeof(numbers)/sizeof(int); for (int i = 0; i < count; ++i) printf(\"%d -> %d\\n\", numbers[i], next_highest_int(numbers[i])); // Last one is too large to convert to an integer const char big[] = \"9589776899767587796600\"; char next[sizeof(big)]; memcpy(next, big, sizeof(big)); next_permutation(next); printf(\"%s -> %s\\n\", big, next); return 0; }", "after": "fn main() -> i32 { let mut numbers: [u32; 8] = [0, 9, 12, 21, 12453, 738440, 45072010, 95322020]; let count: i32 = (::core::mem::size_of::<[u32; 8]>() as u64) .wrapping_div(::core::mem::size_of::() as u64) as i32; let mut i: i32 = 0; while i < count { print!( \"{} -> {}\\n\", numbers[i as usize], next_highest_int(numbers[i as usize]) ); i += 1; i; } unsafe { let big: [i8; 23] = *::core::mem::transmute::<&[u8; 23], &[i8; 23]>(b\"9589776899767587796600\\0\"); let mut next: [i8; 23] = [0; 23]; memcpy( next.as_mut_ptr() as *mut libc::c_void, big.as_ptr() as *const libc::c_void, ::core::mem::size_of::<[i8; 23]>() as u64, ); next_permutation(next.as_mut_ptr()); print!( \"{} -> {}\\n\", build_str_from_raw_ptr(big.as_ptr() as *mut u8), build_str_from_raw_ptr(next.as_mut_ptr() as *mut u8) ); } return 0; }" }, { "index": 785, "before": "ull farey_len(int n) { \tif (n >= ccap) { \t\tsize_t old = ccap; \t\tif (!ccap) ccap = 16; \t\twhile (ccap <= n) ccap *= 2; \t\tcache = realloc(cache, sizeof(ull) * ccap); \t\tmemset(cache + old, 0, sizeof(ull) * (ccap - old)); \t} else if (cache[n]) \t\treturn cache[n]; \tull len = (ull)n*(n + 3) / 2; \tint p, q = 0; \tfor (p = 2; p <= n; p = q) { \t\tq = n/(n/p) + 1; \t\tlen -= farey_len(n/p) * (q - p); \t} \tcache[n] = len; \treturn len; }", "after": "pub extern \"C\" fn farey_len(mut n: i32) -> u64 { unsafe { if n as u64 >= ccap { let mut old: u64 = ccap; if ccap == 0 { ccap = 16; } while ccap <= n as u64 { ccap = (ccap as u64).wrapping_mul(2) as u64; } cache = realloc( cache as *mut libc::c_void, (::core::mem::size_of::() as u64).wrapping_mul(ccap), ) as *mut u64; memset( cache.offset(old as isize) as *mut libc::c_void, 0, (::core::mem::size_of::() as u64).wrapping_mul(ccap.wrapping_sub(old)), ); } else if *cache.offset(n as isize) != 0 { return *cache.offset(n as isize); } } let mut len: u64 = (n as u64).wrapping_mul((n + 3i32) as u64).wrapping_div(2); let mut p: i32 = 0; let mut q: i32 = 0; p = 2; unsafe { while p <= n { q = n / (n / p) + 1; len = (len).wrapping_sub((farey_len(n / p)).wrapping_mul((q - p) as u64)) as u64; p = q; } *cache.offset(n as isize) = len; } return len; }" }, { "index": 786, "before": "int main(void) { \tint n; \tfor (n = 1; n <= 11; n++) { \t\tprintf(\"%d: \", n); \t\tfarey(n); \t} \tfor (n = 100; n <= 1000; n += 100) \t\tprintf(\"%d: %llu items\\n\", n, farey_len(n)); \tn = 10000000; \tprintf(\"\\n%d: %llu items\\n\", n, farey_len(n)); \treturn 0; }", "after": "fn main() -> i32 { let mut n: i32 = 0; n = 1; while n <= 11 { print!(\"{}: \", n); farey(n); n += 1; n; } n = 100; while n <= 1000 { print!(\"{}: {} items\\n\", n, farey_len(n)); n += 100; } n = 10000000; print!(\"\\n{}: {} items\\n\", n, farey_len(n)); return 0; }" }, { "index": 787, "before": "void farey(int n) { \ttypedef struct { int d, n; } frac; \tfrac f1 = {0, 1}, f2 = {1, n}, t; \tint k; \tprintf(\"%d/%d %d/%d\", 0, 1, 1, n); \twhile (f2.n > 1) { \t\tk = (n + f1.n) / f2.n; \t\tt = f1, f1 = f2, f2 = (frac) { f2.d * k - t.d, f2.n * k - t.n }; \t\tprintf(\" %d/%d\", f2.d, f2.n); \t} \tputchar('\\n'); }", "after": "pub extern \"C\" fn farey(mut n: i32) { let mut f1: frac = { let mut init = frac { d: 0, n: 1 }; init }; let mut f2: frac = { let mut init = frac { d: 1, n: n }; init }; let mut t: frac = frac { d: 0, n: 0 }; let mut k: i32 = 0; print!(\"{}/{} {}/{}\", 0, 1, 1, n); while f2.n > 1 { k = (n + f1.n) / f2.n; t = f1; f1 = f2; f2 = { let mut init = frac { d: f2.d * k - t.d, n: f2.n * k - t.n, }; init }; print!(\" {}/{}\", f2.d, f2.n); } print!(\"{}\", '\\n' as i32); }" }, { "index": 788, "before": "int main(int argc, char** argv) { if (argc < 2) { printf(\"usage: identitymatrix \\n\"); exit(EXIT_FAILURE); } signed int rowsize = atoi(argv[1]); if (rowsize < 0) { printf(\"Dimensions of matrix cannot be negative\\n\"); exit(EXIT_FAILURE); } volatile int numElements = rowsize * rowsize; if (numElements < rowsize) { printf(\"Squaring %d caused result to overflow to %d.\\n\", rowsize, numElements); abort(); } int** matrix = calloc(numElements, sizeof(int*)); if (!matrix) { printf(\"Failed to allocate %d elements of %d bytes each\\n\", numElements, sizeof(int*)); abort(); } for (unsigned int row = 0;row < rowsize;row++) { matrix[row] = calloc(numElements, sizeof(int)); if (!matrix[row]) { printf(\"Failed to allocate %d elements of %d bytes each\\n\", numElements, sizeof(int)); abort(); } matrix[row][row] = 1; } printf(\"Matrix is: \\n\"); for (unsigned int row = 0;row < rowsize;row++) { for (unsigned int column = 0;column < rowsize;column++) { printf(\"%d \", matrix[row][column]); } printf(\"\\n\"); } }", "after": "fn main(mut argc: i32, mut argv: *mut *mut i8) -> i32 { unsafe { if argc < 2 { print!(\"usage: identitymatrix \\n\"); exit(1); } let mut rowsize: i32 = atoi(*argv.offset(1 as isize)); if rowsize < 0 { print!(\"Dimensions of matrix cannot be negative\\n\"); exit(1); } let mut numElements: i32 = rowsize * rowsize; if numElements < rowsize { print!( \"Squaring {} caused result to overflow to {}.\\n\", rowsize, numElements ); abort(); } let mut matrix: *mut *mut i32 = calloc( numElements as u64, ::core::mem::size_of::<*mut i32>() as u64, ) as *mut *mut i32; if matrix.is_null() { print!( \"Failed to allocate {} elements of {} bytes each\\n\", numElements, ::core::mem::size_of::<*mut i32>() as u64 ); abort(); } let mut row: u32 = 0; while row < rowsize as u32 { let ref mut fresh0 = *matrix.offset(row as isize); *fresh0 = calloc(numElements as u64, ::core::mem::size_of::() as u64) as *mut i32; if (*matrix.offset(row as isize)).is_null() { print!( \"Failed to allocate {} elements of {} bytes each\\n\", numElements, ::core::mem::size_of::() as u64 ); abort(); }; *(*matrix.offset(row as isize)).offset(row as isize) = 1; row = row.wrapping_add(1); row; } print!(\"Matrix is: \\n\"); let mut row_0: u32 = 0; while row_0 < rowsize as u32 { let mut column: u32 = 0; while column < rowsize as u32 { print!( \"{} \", *(*matrix.offset(row_0 as isize)).offset(column as isize) ); column = column.wrapping_add(1); column; } print!(\"\\n\"); row_0 = row_0.wrapping_add(1); row_0; } return 0; } }" }, { "index": 789, "before": "int cusipCheck(char str[10]){ \tint sum=0,i,v; \tfor(i=0;i<8;i++){ \t\tif(str[i]>='0'&&str[i]<='9') \t\t\tv = str[i]-'0'; \t\telse if(str[i]>='A'&&str[i]<='Z') \t\t\tv = (str[i] - 'A' + 10); \t\telse if(str[i]=='*') \t\t\tv = 36; \t\telse if(str[i]=='@') \t\t\tv = 37; \t\telse if(str[i]=='#') \t\t\tv = 38; \t\tif(i%2!=0) \t\t\tv*=2; \t\tsum += ((int)(v/10) + v%10); \t} \treturn ((10 - (sum%10))%10); }", "after": "pub extern \"C\" fn cusipCheck(mut str: *mut i8) -> i32 { unsafe { let mut sum: i32 = 0; let mut i: i32 = 0; let mut v: i32 = 0; i = 0; while i < 8 { if *str.offset(i as isize) as i32 >= '0' as i32 && *str.offset(i as isize) as i32 <= '9' as i32 { v = *str.offset(i as isize) as i32 - '0' as i32; } else if *str.offset(i as isize) as i32 >= 'A' as i32 && *str.offset(i as isize) as i32 <= 'Z' as i32 { v = *str.offset(i as isize) as i32 - 'A' as i32 + 10; } else if *str.offset(i as isize) as i32 == '*' as i32 { v = 36; } else if *str.offset(i as isize) as i32 == '@' as i32 { v = 37; } else if *str.offset(i as isize) as i32 == '#' as i32 { v = 38; } if i % 2 != 0 { v *= 2; } sum += v / 10 + v % 10; i += 1; i; } return (10 - sum % 10) % 10; } }" }, { "index": 790, "before": "int main(int argC,char* argV[]) { \tchar cusipStr[10]; \tint i,numLines; \tif(argC==1) \t\tprintf(\"Usage : %s \",argV[0]); \telse{ \t\tFILE* fp = fopen(argV[1],\"r\"); \t\tfscanf(fp,\"%d\",&numLines); \t\tprintf(\"CUSIP Verdict\\n\"); \t\tprintf(\"-------------------\"); \t\tfor(i=0;i i32 { unsafe { let mut cusipStr: [i8; 10] = [0; 10]; let mut i: i32 = 0; let mut numLines: i32 = 0; if argC == 1 { print!( \"Usage : {} \", build_str_from_raw_ptr(*argV.offset(0 as isize) as *mut u8) ); } else { let mut fp: *mut FILE = fopen(*argV.offset(1 as isize), b\"r\\0\" as *const u8 as *const i8); fscanf( fp, b\"%d\\0\" as *const u8 as *const i8, &mut numLines as *mut i32, ); print!(\"CUSIP Verdict\\n\"); print!(\"-------------------\"); i = 0; while i < numLines { fscanf(fp, b\"%s\\0\" as *const u8 as *const i8, cusipStr.as_mut_ptr()); if cusipCheck(cusipStr.as_mut_ptr()) == cusipStr[8 as usize] as i32 - '0' as i32 { print!( \"\\n{} : {}\", build_str_from_raw_ptr(cusipStr.as_mut_ptr() as *mut u8), \"Valid\\0\" ) } else { print!( \"\\n{} : {}\", build_str_from_raw_ptr(cusipStr.as_mut_ptr() as *mut u8), \"Invalid\\0\" ) }; i += 1; i; } fclose(fp); } return 0; } }" }, { "index": 791, "before": "expr get_fact() { \tint c; \texpr l = get_digit(); \tif (l) return l; \tif ((c = next_tok()) == '(') { \t\ttake(); \t\tl = get_expr(); \t\tif (next_tok() != ')') bail(\"Unbalanced parens\"); \t\ttake(); \t\treturn l; \t} \treturn 0; }", "after": "pub unsafe extern \"C\" fn get_fact() -> expr { let mut c: libc::c_int = 0; let mut l: expr = get_digit(); if !l.is_null() { return l; } c = next_tok(); if c == '(' as i32 { take(); l = get_expr(); if next_tok() != ')' as i32 { bail(b\"Unbalanced parens\\0\" as *const u8 as *const libc::c_char); } take(); return l; } return 0 as expr; }" }, { "index": 792, "before": "void reset() { \tint i; \tmsg = 0; \tpool_ptr = pos = 0; \tfor (i = 0; i < POOL_SIZE; i++) { \t\tpool[i].op = OP_NONE; \t\tpool[i].left = pool[i].right = 0; \t} \tfor (i = 0; i < N_DIGITS; i++) \t\tdigits[i].used = 0; }", "after": "pub unsafe extern \"C\" fn reset() { let mut i: libc::c_int = 0; msg = 0 as *const libc::c_char; pos = 0 as libc::c_int; pool_ptr = pos; i = 0 as libc::c_int; while i < 8 as libc::c_int { pool[i as usize].op = OP_NONE as libc::c_int; pool[i as usize].right = 0 as expr; pool[i as usize].left = pool[i as usize].right; i += 1; i; } i = 0 as libc::c_int; while i < 4 as libc::c_int { digits[i as usize].used = 0 as libc::c_int; i += 1; i; } }" }, { "index": 793, "before": "void bail(const char *s) { \tmsg = s; \tlongjmp(ctx, 1); }", "after": "pub unsafe extern \"C\" fn bail(mut s: *const libc::c_char) { msg = s; longjmp(ctx.as_mut_ptr(), 1 as libc::c_int); }" }, { "index": 794, "before": "expr parse() { \tint i; \texpr ret = get_expr(); \tif (next_tok() != '\\0') \t\tbail(\"Trailing garbage\"); \tfor (i = 0; i < N_DIGITS; i++) \t\tif (!digits[i].used) \t\t\tbail(\"Not all digits are used\"); \treturn ret; }", "after": "pub unsafe extern \"C\" fn parse() -> expr { let mut i: libc::c_int = 0; let mut ret: expr = get_expr(); if next_tok() != '\\0' as i32 { bail(b\"Trailing garbage\\0\" as *const u8 as *const libc::c_char); } i = 0 as libc::c_int; while i < 4 as libc::c_int { if digits[i as usize].used == 0 { bail(b\"Not all digits are used\\0\" as *const u8 as *const libc::c_char); } i += 1; i; } return ret; }" }, { "index": 795, "before": "void eval_tree(expr e, frac res) { \tfrac_t l, r; \tint t; \tif (e->op == OP_NUM) { \t\tres->num = e->val; \t\tres->denom = 1; \t\treturn; \t} \teval_tree(e->left, &l); \teval_tree(e->right, &r); \tswitch(e->op) { \tcase OP_ADD: \t\tres->num = l.num * r.denom + l.denom * r.num; \t\tres->denom = l.denom * r.denom; \t\tbreak; \tcase OP_SUB: \t\tres->num = l.num * r.denom - l.denom * r.num; \t\tres->denom = l.denom * r.denom; \t\tbreak; \tcase OP_MUL: \t\tres->num = l.num * r.num; \t\tres->denom = l.denom * r.denom; \t\tbreak; \tcase OP_DIV: \t\tres->num = l.num * r.denom; \t\tres->denom = l.denom * r.num; \t\tbreak; \t} \tif ((t = gcd(res->denom, res->num))) { \t\tres->denom /= t; \t\tres->num /= t; \t} }", "after": "pub unsafe extern \"C\" fn eval_tree(mut e: expr, mut res: frac) { let mut l: frac_t = frac_t { denom: 0, num: 0 }; let mut r: frac_t = frac_t { denom: 0, num: 0 }; let mut t: libc::c_int = 0; if (*e).op == OP_NUM as libc::c_int { (*res).num = (*e).val; (*res).denom = 1 as libc::c_int; return; } eval_tree((*e).left, &mut l); eval_tree((*e).right, &mut r); match (*e).op { 2 => { (*res).num = l.num * r.denom + l.denom * r.num; (*res).denom = l.denom * r.denom; } 3 => { (*res).num = l.num * r.denom - l.denom * r.num; (*res).denom = l.denom * r.denom; } 4 => { (*res).num = l.num * r.num; (*res).denom = l.denom * r.denom; } 5 => { (*res).num = l.num * r.denom; (*res).denom = l.denom * r.num; } _ => {} } t = gcd((*res).denom, (*res).num); if t != 0 { (*res).denom /= t; (*res).num /= t; } }" }, { "index": 796, "before": "int gcd(int m, int n) { \tint t; \twhile (m) { \t\tt = m; m = n % m; n = t; \t} \treturn n; }", "after": "pub unsafe extern \"C\" fn gcd(mut m: libc::c_int, mut n: libc::c_int) -> libc::c_int { let mut t: libc::c_int = 0; while m != 0 { t = m; m = n % m; n = t; } return n; }" }, { "index": 797, "before": "int next_tok() { \twhile (isspace(str[pos])) pos++; \treturn str[pos]; }", "after": "pub unsafe extern \"C\" fn next_tok() -> libc::c_int { while *(*__ctype_b_loc()).offset(str[pos as usize] as libc::c_int as isize) as libc::c_int & _ISspace as libc::c_int as libc::c_ushort as libc::c_int != 0 { pos += 1; pos; } return str[pos as usize] as libc::c_int; }" }, { "index": 798, "before": "expr new_expr() { \tif (pool_ptr < POOL_SIZE) \t\treturn pool + pool_ptr++; \treturn 0; }", "after": "pub unsafe extern \"C\" fn new_expr() -> expr { if pool_ptr < 8 as libc::c_int { let fresh0 = pool_ptr; pool_ptr = pool_ptr + 1; return pool.as_mut_ptr().offset(fresh0 as isize); } return 0 as expr; }" }, { "index": 799, "before": "expr get_expr() { \tint c; \texpr l, r, ret; \tif (!(ret = get_term())) bail(\"Expected term\"); \twhile ((c = next_tok()) == '+' || c == '-') { \t\tif (!take()) bail(\"Unexpected end of input\"); \t\tif (!(r = get_term())) bail(\"Expected term\"); \t\tl = ret; \t\tret = new_expr(); \t\tret->op = (c == '+') ? OP_ADD : OP_SUB; \t\tret->left = l; \t\tret->right = r; \t} \treturn ret; }", "after": "pub unsafe extern \"C\" fn get_expr() -> expr { let mut c: libc::c_int = 0; let mut l: expr = 0 as *mut expr_t; let mut r: expr = 0 as *mut expr_t; let mut ret: expr = 0 as *mut expr_t; ret = get_term(); if ret.is_null() { bail(b\"Expected term\\0\" as *const u8 as *const libc::c_char); } loop { c = next_tok(); if !(c == '+' as i32 || c == '-' as i32) { break; } if take() == 0 { bail(b\"Unexpected end of input\\0\" as *const u8 as *const libc::c_char); } r = get_term(); if r.is_null() { bail(b\"Expected term\\0\" as *const u8 as *const libc::c_char); } l = ret; ret = new_expr(); (*ret) .op = if c == '+' as i32 { OP_ADD as libc::c_int } else { OP_SUB as libc::c_int }; (*ret).left = l; (*ret).right = r; } return ret; }" }, { "index": 800, "before": "expr get_digit() { \tint i, c = next_tok(); \texpr ret; \tif (c >= '0' && c <= '9') { \t\ttake(); \t\tret = new_expr(); \t\tret->op = OP_NUM; \t\tret->val = c - '0'; \t\tfor (i = 0; i < N_DIGITS; i++) \t\t\tif (digits[i].val == ret->val && !digits[i].used) { \t\t\t\tdigits[i].used = 1; \t\t\t\treturn ret; \t\t\t} \t\tbail(\"Invalid digit\"); \t} \treturn 0; }", "after": "pub unsafe extern \"C\" fn get_digit() -> expr { let mut i: libc::c_int = 0; let mut c: libc::c_int = next_tok(); let mut ret: expr = 0 as *mut expr_t; if c >= '0' as i32 && c <= '9' as i32 { take(); ret = new_expr(); (*ret).op = OP_NUM as libc::c_int; (*ret).val = c - '0' as i32; i = 0 as libc::c_int; while i < 4 as libc::c_int { if digits[i as usize].val == (*ret).val && digits[i as usize].used == 0 { digits[i as usize].used = 1 as libc::c_int; return ret; } i += 1; i; } bail(b\"Invalid digit\\0\" as *const u8 as *const libc::c_char); } return 0 as expr; }" }, { "index": 801, "before": "void gen_digits() { \tint i; \tfor (i = 0; i < N_DIGITS; i++) \t\tdigits[i].val = 1 + rand() % 9; }", "after": "pub unsafe extern \"C\" fn gen_digits() { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 4 as libc::c_int { digits[i as usize].val = 1 as libc::c_int + rand() % 9 as libc::c_int; i += 1; i; } }" }, { "index": 802, "before": "int take() { \tif (str[pos] != '\\0') return ++pos; \treturn 0; }", "after": "pub unsafe extern \"C\" fn take() -> libc::c_int { if str[pos as usize] as libc::c_int != '\\0' as i32 { pos += 1; return pos; } return 0 as libc::c_int; }" }, { "index": 803, "before": "int main() { \tfrac_t f; \tsrand(time(0)); \tgen_digits(); \twhile(1) { \t\tget_input(); \t\tsetjmp(ctx); /* if parse error, jump back here with err msg set */ \t\tif (msg) { \t\t\t/* after error jump; announce, reset, redo */ \t\t\tprintf(\"%s at '%.*s'\\n\", msg, pos, str); \t\t\tcontinue; \t\t} \t\teval_tree(parse(), &f); \t\tif (f.denom == 0) bail(\"Divide by zero\"); \t\tif (f.denom == 1 && f.num == 24) \t\t\tprintf(\"You got 24. Very good.\\n\"); \t\telse { \t\t\tif (f.denom == 1) \t\t\t\tprintf(\"Eval to: %d, \", f.num); \t\t\telse \t\t\t\tprintf(\"Eval to: %d/%d, \", f.num, f.denom); \t\t\tprintf(\"no good. Try again.\\n\"); \t\t} \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut f: frac_t = frac_t { denom: 0, num: 0 }; srand(time(0 as *mut time_t) as libc::c_uint); gen_digits(); loop { get_input(); _setjmp(ctx.as_mut_ptr()); if !msg.is_null() { printf( b\"%s at '%.*s'\\n\\0\" as *const u8 as *const libc::c_char, msg, pos, str.as_mut_ptr(), ); } else { eval_tree(parse(), &mut f); if f.denom == 0 as libc::c_int { bail(b\"Divide by zero\\0\" as *const u8 as *const libc::c_char); } if f.denom == 1 as libc::c_int && f.num == 24 as libc::c_int { printf( b\"You got 24. Very good.\\n\\0\" as *const u8 as *const libc::c_char, ); } else { if f.denom == 1 as libc::c_int { printf( b\"Eval to: %d, \\0\" as *const u8 as *const libc::c_char, f.num, ); } else { printf( b\"Eval to: %d/%d, \\0\" as *const u8 as *const libc::c_char, f.num, f.denom, ); } printf(b\"no good. Try again.\\n\\0\" as *const u8 as *const libc::c_char); } } }; }" }, { "index": 804, "before": "void get_input() { \tint i; reinput: \treset(); \tprintf(\"\\nAvailable digits are:\"); \tfor (i = 0; i < N_DIGITS; i++) \t\tprintf(\" %d\", digits[i].val); \tprintf(\". Type an expression and I'll check it for you, or make new numbers.\\n\" \t\t\"Your choice? [Expr/n/q] \"); \twhile (1) { \t\tfor (i = 0; i < MAX_INPUT; i++) str[i] = '\\n'; \t\tfgets(str, MAX_INPUT, stdin); \t\tif (*str == '\\0') goto reinput; \t\tif (str[MAX_INPUT - 1] != '\\n') \t\t\tbail(\"string too long\"); \t\tfor (i = 0; i < MAX_INPUT; i++) \t\t\tif (str[i] == '\\n') str[i] = '\\0'; \t\tif (str[0] == 'q') { \t\t\tprintf(\"Bye\\n\"); \t\t\texit(0); \t\t} \t\tif (str[0] == 'n') { \t\t\tgen_digits(); \t\t\tgoto reinput; \t\t} \t\treturn; \t} }", "after": "pub unsafe extern \"C\" fn get_input() { let mut i: libc::c_int = 0; loop { reset(); printf(b\"\\nAvailable digits are:\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < 4 as libc::c_int { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, digits[i as usize].val); i += 1; i; } printf( b\". Type an expression and I'll check it for you, or make new numbers.\\nYour choice? [Expr/n/q] \\0\" as *const u8 as *const libc::c_char, ); i = 0 as libc::c_int; while i < 64 as libc::c_int { str[i as usize] = '\\n' as i32 as libc::c_char; i += 1; i; } fgets(str.as_mut_ptr(), 64 as libc::c_int, stdin); if *str.as_mut_ptr() as libc::c_int == '\\0' as i32 { continue; } if str[(64 as libc::c_int - 1 as libc::c_int) as usize] as libc::c_int != '\\n' as i32 { bail(b\"string too long\\0\" as *const u8 as *const libc::c_char); } i = 0 as libc::c_int; while i < 64 as libc::c_int { if str[i as usize] as libc::c_int == '\\n' as i32 { str[i as usize] = '\\0' as i32 as libc::c_char; } i += 1; i; } if str[0 as libc::c_int as usize] as libc::c_int == 'q' as i32 { printf(b\"Bye\\n\\0\" as *const u8 as *const libc::c_char); exit(0 as libc::c_int); } if !(str[0 as libc::c_int as usize] as libc::c_int == 'n' as i32) { break; } gen_digits(); }; }" }, { "index": 805, "before": "expr get_term() { \tint c; \texpr l, r, ret; \tret = get_fact(); \twhile((c = next_tok()) == '*' || c == '/') { \t\tif (!take()) bail(\"Unexpected end of input\"); \t\tr = get_fact(); \t\tl = ret; \t\tret = new_expr(); \t\tret->op = (c == '*') ? OP_MUL : OP_DIV; \t\tret->left = l; \t\tret->right = r; \t} \treturn ret; }", "after": "pub unsafe extern \"C\" fn get_term() -> expr { let mut c: libc::c_int = 0; let mut l: expr = 0 as *mut expr_t; let mut r: expr = 0 as *mut expr_t; let mut ret: expr = 0 as *mut expr_t; ret = get_fact(); loop { c = next_tok(); if !(c == '*' as i32 || c == '/' as i32) { break; } if take() == 0 { bail(b\"Unexpected end of input\\0\" as *const u8 as *const libc::c_char); } r = get_fact(); l = ret; ret = new_expr(); (*ret) .op = if c == '*' as i32 { OP_MUL as libc::c_int } else { OP_DIV as libc::c_int }; (*ret).left = l; (*ret).right = r; } return ret; }" }, { "index": 806, "before": "int main() { int i; pthread_t a[3]; threadfunc p[3] = {t_enjoy, t_rosetta, t_code}; for(i=0;i<3;i++) { pthread_create(&a[i], NULL, p[i], NULL); } sleep(1); bang = 1; pthread_cond_broadcast(&cond); for(i=0;i<3;i++) { pthread_join(a[i], NULL); } }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut a: [pthread_t; 3] = [0; 3]; let mut p: [threadfunc; 3] = [ Some(t_enjoy as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), Some(t_rosetta as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), Some(t_code as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void), ]; i = 0 as libc::c_int; while i < 3 as libc::c_int { pthread_create( &mut *a.as_mut_ptr().offset(i as isize), 0 as *const pthread_attr_t, p[i as usize], 0 as *mut libc::c_void, ); i += 1; i; } sleep(1 as libc::c_int as libc::c_uint); bang = 1 as libc::c_int; pthread_cond_broadcast(&mut cond); i = 0 as libc::c_int; while i < 3 as libc::c_int { pthread_join(a[i as usize], 0 as *mut *mut libc::c_void); i += 1; i; } return 0; }" }, { "index": 807, "before": "int main() { /* screen ( integer) coordinate */ int iX,iY; const int iXmax = 800; const int iYmax = 800; /* world ( double) coordinate = parameter plane*/ double Cx,Cy; const double CxMin=-2.5; const double CxMax=1.5; const double CyMin=-2.0; const double CyMax=2.0; /* */ double PixelWidth=(CxMax-CxMin)/iXmax; double PixelHeight=(CyMax-CyMin)/iYmax; /* color component ( R or G or B) is coded from 0 to 255 */ /* it is 24 bit color RGB file */ const int MaxColorComponentValue=255; FILE * fp; char *filename=\"new1.ppm\"; char *comment=\"# \";/* comment should start with # */ static unsigned char color[3]; /* Z=Zx+Zy*i ; Z0 = 0 */ double Zx, Zy; double Zx2, Zy2; /* Zx2=Zx*Zx; Zy2=Zy*Zy */ /* */ int Iteration; const int IterationMax=200; /* bail-out value , radius of circle ; */ const double EscapeRadius=2; double ER2=EscapeRadius*EscapeRadius; /*create new file,give it a name and open it in binary mode */ fp= fopen(filename,\"wb\"); /* b - binary mode */ /*write ASCII header to the file*/ fprintf(fp,\"P6\\n %s\\n %d\\n %d\\n %d\\n\",comment,iXmax,iYmax,MaxColorComponentValue); /* compute and write image data bytes to the file*/ for(iY=0;iY libc::c_int { let mut iX: libc::c_int = 0; let mut iY: libc::c_int = 0; let iXmax: libc::c_int = 800 as libc::c_int; let iYmax: libc::c_int = 800 as libc::c_int; let mut Cx: libc::c_double = 0.; let mut Cy: libc::c_double = 0.; let CxMin: libc::c_double = -2.5f64; let CxMax: libc::c_double = 1.5f64; let CyMin: libc::c_double = -2.0f64; let CyMax: libc::c_double = 2.0f64; let mut PixelWidth: libc::c_double = (CxMax - CxMin) / iXmax as libc::c_double; let mut PixelHeight: libc::c_double = (CyMax - CyMin) / iYmax as libc::c_double; let MaxColorComponentValue: libc::c_int = 255 as libc::c_int; let mut fp: *mut FILE = 0 as *mut FILE; let mut filename: *mut libc::c_char = b\"new1.ppm\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; let mut comment: *mut libc::c_char = b\"# \\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; static mut color: [libc::c_uchar; 3] = [0; 3]; let mut Zx: libc::c_double = 0.; let mut Zy: libc::c_double = 0.; let mut Zx2: libc::c_double = 0.; let mut Zy2: libc::c_double = 0.; let mut Iteration: libc::c_int = 0; let IterationMax: libc::c_int = 200 as libc::c_int; let EscapeRadius: libc::c_double = 2 as libc::c_int as libc::c_double; let mut ER2: libc::c_double = EscapeRadius * EscapeRadius; fp = fopen(filename, b\"wb\\0\" as *const u8 as *const libc::c_char); fprintf( fp, b\"P6\\n %s\\n %d\\n %d\\n %d\\n\\0\" as *const u8 as *const libc::c_char, comment, iXmax, iYmax, MaxColorComponentValue, ); iY = 0 as libc::c_int; while iY < iYmax { Cy = CyMin + iY as libc::c_double * PixelHeight; if fabs(Cy) < PixelHeight / 2 as libc::c_int as libc::c_double { Cy = 0.0f64; } iX = 0 as libc::c_int; while iX < iXmax { Cx = CxMin + iX as libc::c_double * PixelWidth; Zx = 0.0f64; Zy = 0.0f64; Zx2 = Zx * Zx; Zy2 = Zy * Zy; Iteration = 0 as libc::c_int; while Iteration < IterationMax && Zx2 + Zy2 < ER2 { Zy = 2 as libc::c_int as libc::c_double * Zx * Zy + Cy; Zx = Zx2 - Zy2 + Cx; Zx2 = Zx * Zx; Zy2 = Zy * Zy; Iteration += 1; Iteration; } if Iteration == IterationMax { color[0 as libc::c_int as usize] = 0 as libc::c_int as libc::c_uchar; color[1 as libc::c_int as usize] = 0 as libc::c_int as libc::c_uchar; color[2 as libc::c_int as usize] = 0 as libc::c_int as libc::c_uchar; } else { color[0 as libc::c_int as usize] = 255 as libc::c_int as libc::c_uchar; color[1 as libc::c_int as usize] = 255 as libc::c_int as libc::c_uchar; color[2 as libc::c_int as usize] = 255 as libc::c_int as libc::c_uchar; } fwrite( color.as_mut_ptr() as *const libc::c_void, 1 as libc::c_int as libc::c_ulong, 3 as libc::c_int as libc::c_ulong, fp, ); iX += 1; iX; } iY += 1; iY; } fclose(fp); return 0 as libc::c_int; }" }, { "index": 808, "before": "int main() { \tchar str[] = \"This is a top secret text message!\"; \tprintf(\"Original: %s\\n\", str); \tcaesar(str); \tprintf(\"Encrypted: %s\\n\", str); \tdecaesar(str); \tprintf(\"Decrypted: %s\\n\", str); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut str: [libc::c_char; 35] = *::core::mem::transmute::< &[u8; 35], &mut [libc::c_char; 35], >(b\"This is a top secret text message!\\0\"); printf(b\"Original: %s\\n\\0\" as *const u8 as *const libc::c_char, str.as_mut_ptr()); rot(13 as libc::c_int, str.as_mut_ptr()); printf(b\"Encrypted: %s\\n\\0\" as *const u8 as *const libc::c_char, str.as_mut_ptr()); rot(13 as libc::c_int, str.as_mut_ptr()); printf(b\"Decrypted: %s\\n\\0\" as *const u8 as *const libc::c_char, str.as_mut_ptr()); return 0 as libc::c_int; }" }, { "index": 809, "before": "void rot(int c, char *str) { \tint l = strlen(str); \tconst char *alpha[2] = { \"abcdefghijklmnopqrstuvwxyz\", \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"}; \tint i; \tfor (i = 0; i < l; i++) \t{ \t\tif (!isalpha(str[i])) \t\t\tcontinue; \t\tif (isupper(str[i])) str[i] = alpha[1][((int)(tolower(str[i]) - 'a') + c) % 26]; else str[i] = alpha[0][((int)(tolower(str[i]) - 'a') + c) % 26]; \t} }", "after": "pub unsafe extern \"C\" fn rot(mut c: libc::c_int, mut str: *mut libc::c_char) { let mut l: libc::c_int = strlen(str) as libc::c_int; let mut alpha: [*const libc::c_char; 2] = [ b\"abcdefghijklmnopqrstuvwxyz\\0\" as *const u8 as *const libc::c_char, b\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\\0\" as *const u8 as *const libc::c_char, ]; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < l { if !(*(*__ctype_b_loc()).offset(*str.offset(i as isize) as libc::c_int as isize) as libc::c_int & _ISalpha as libc::c_int as libc::c_ushort as libc::c_int == 0) { if *(*__ctype_b_loc()) .offset(*str.offset(i as isize) as libc::c_int as isize) as libc::c_int & _ISupper as libc::c_int as libc::c_ushort as libc::c_int != 0 { *str .offset( i as isize, ) = *(alpha[1 as libc::c_int as usize]) .offset( ((tolower(*str.offset(i as isize) as libc::c_int) - 'a' as i32 + c) % 26 as libc::c_int) as isize, ); } else { *str .offset( i as isize, ) = *(alpha[0 as libc::c_int as usize]) .offset( ((tolower(*str.offset(i as isize) as libc::c_int) - 'a' as i32 + c) % 26 as libc::c_int) as isize, ); } } i += 1; i; } }" }, { "index": 810, "before": "int main() { const char *plain_text = \"WELLDONEISBETTERTHANWELLSAID\"; char *cipher_text = malloc(strlen(plain_text) + 1); char *plain_text2 = malloc(strlen(plain_text) + 1); printf(\"The original plaintext is : %s\\n\", plain_text); printf(\"\\nThe left and right alphabets after each permutation\" \" during encryption are :\\n\\n\"); chao(plain_text, cipher_text, ENCRYPT, TRUE); printf(\"\\nThe ciphertext is : %s\\n\", cipher_text); chao(cipher_text, plain_text2, DECRYPT, FALSE); printf(\"\\nThe recovered plaintext is : %s\\n\", plain_text2); free(cipher_text); free(plain_text2); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut plain_text: *const libc::c_char = b\"WELLDONEISBETTERTHANWELLSAID\\0\" as *const u8 as *const libc::c_char; let mut cipher_text: *mut libc::c_char = malloc( (strlen(plain_text)).wrapping_add(1 as libc::c_int as libc::c_ulong), ) as *mut libc::c_char; let mut plain_text2: *mut libc::c_char = malloc( (strlen(plain_text)).wrapping_add(1 as libc::c_int as libc::c_ulong), ) as *mut libc::c_char; printf( b\"The original plaintext is : %s\\n\\0\" as *const u8 as *const libc::c_char, plain_text, ); printf( b\"\\nThe left and right alphabets after each permutation during encryption are :\\n\\n\\0\" as *const u8 as *const libc::c_char, ); chao(plain_text, cipher_text, ENCRYPT, 1 as libc::c_int); printf( b\"\\nThe ciphertext is : %s\\n\\0\" as *const u8 as *const libc::c_char, cipher_text, ); chao(cipher_text, plain_text2, DECRYPT, 0 as libc::c_int); printf( b\"\\nThe recovered plaintext is : %s\\n\\0\" as *const u8 as *const libc::c_char, plain_text2, ); free(cipher_text as *mut libc::c_void); free(plain_text2 as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 811, "before": "void chao(const char *in, char *out, cmode mode, bool show_steps) { int i, j, index; char store; size_t len = strlen(in); char left[27], right[27], temp[27]; strcpy(left, l_alphabet); strcpy(right, r_alphabet); temp[26] = '\\0'; for (i = 0; i < len; ++i ) { if (show_steps) printf(\"%s %s\\n\", left, right); if (mode == ENCRYPT) { index = strchr(right, in[i]) - right; out[i] = left[index]; } else { index = strchr(left, in[i]) - left; out[i] = right[index]; } if (i == len - 1) break; /* permute left */ for (j = index; j < 26; ++j) temp[j - index] = left[j]; for (j = 0; j < index; ++j) temp[26 - index + j] = left[j]; store = temp[1]; for (j = 2; j < 14; ++j) temp[j - 1] = temp[j]; temp[13] = store; strcpy(left, temp); /* permute right */ for (j = index; j < 26; ++j) temp[j - index] = right[j]; for (j = 0; j < index; ++j) temp[26 - index + j] = right[j]; store = temp[0]; for (j = 1; j < 26; ++j) temp[j - 1] = temp[j]; temp[25] = store; store = temp[2]; for (j = 3; j < 14; ++j) temp[j - 1] = temp[j]; temp[13] = store; strcpy(right, temp); } }", "after": "pub unsafe extern \"C\" fn chao( mut in_0: *const libc::c_char, mut out: *mut libc::c_char, mut mode: cmode, mut show_steps: bool_0, ) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut index: libc::c_int = 0; let mut store: libc::c_char = 0; let mut len: size_t = strlen(in_0); let mut left: [libc::c_char; 27] = [0; 27]; let mut right: [libc::c_char; 27] = [0; 27]; let mut temp: [libc::c_char; 27] = [0; 27]; strcpy(left.as_mut_ptr(), l_alphabet); strcpy(right.as_mut_ptr(), r_alphabet); temp[26 as libc::c_int as usize] = '\\0' as i32 as libc::c_char; i = 0 as libc::c_int; while (i as libc::c_ulong) < len { if show_steps != 0 { printf( b\"%s %s\\n\\0\" as *const u8 as *const libc::c_char, left.as_mut_ptr(), right.as_mut_ptr(), ); } if mode as libc::c_uint == ENCRYPT as libc::c_int as libc::c_uint { index = (strchr(right.as_mut_ptr(), *in_0.offset(i as isize) as libc::c_int)) .offset_from(right.as_mut_ptr()) as libc::c_long as libc::c_int; *out.offset(i as isize) = left[index as usize]; } else { index = (strchr(left.as_mut_ptr(), *in_0.offset(i as isize) as libc::c_int)) .offset_from(left.as_mut_ptr()) as libc::c_long as libc::c_int; *out.offset(i as isize) = right[index as usize]; } if i as libc::c_ulong == len.wrapping_sub(1 as libc::c_int as libc::c_ulong) { break; } j = index; while j < 26 as libc::c_int { temp[(j - index) as usize] = left[j as usize]; j += 1; j; } j = 0 as libc::c_int; while j < index { temp[(26 as libc::c_int - index + j) as usize] = left[j as usize]; j += 1; j; } store = temp[1 as libc::c_int as usize]; j = 2 as libc::c_int; while j < 14 as libc::c_int { temp[(j - 1 as libc::c_int) as usize] = temp[j as usize]; j += 1; j; } temp[13 as libc::c_int as usize] = store; strcpy(left.as_mut_ptr(), temp.as_mut_ptr()); j = index; while j < 26 as libc::c_int { temp[(j - index) as usize] = right[j as usize]; j += 1; j; } j = 0 as libc::c_int; while j < index { temp[(26 as libc::c_int - index + j) as usize] = right[j as usize]; j += 1; j; } store = temp[0 as libc::c_int as usize]; j = 1 as libc::c_int; while j < 26 as libc::c_int { temp[(j - 1 as libc::c_int) as usize] = temp[j as usize]; j += 1; j; } temp[25 as libc::c_int as usize] = store; store = temp[2 as libc::c_int as usize]; j = 3 as libc::c_int; while j < 14 as libc::c_int { temp[(j - 1 as libc::c_int) as usize] = temp[j as usize]; j += 1; j; } temp[13 as libc::c_int as usize] = store; strcpy(right.as_mut_ptr(), temp.as_mut_ptr()); i += 1; i; } }" }, { "index": 812, "before": "int main() { int a, b; scanf(\"%d %d\", &a, &b); if (a < b) printf(\"%d is less than %d\\n\", a, b); if (a == b) printf(\"%d is equal to %d\\n\", a, b); if (a > b) printf(\"%d is greater than %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, ); if a < b { printf(b\"%d is less than %d\\n\\0\" as *const u8 as *const libc::c_char, a, b); } if a == b { printf(b\"%d is equal to %d\\n\\0\" as *const u8 as *const libc::c_char, a, b); } if a > b { printf(b\"%d is greater than %d\\n\\0\" as *const u8 as *const libc::c_char, a, b); } return 0 as libc::c_int; }" }, { "index": 813, "before": "void writePortableBitMap(FILE* file) { int i,j; fprintf(file,\"P1\\n\"); fprintf(file,\"%d %d\\n\", width, height); for ( i = 0; i < height; i++ ) { for ( j = 0; j < width; j++ ) fprintf(file,\"%1d\", bitmap[i][j]); fprintf(file,\"\\n\"); } }", "after": "pub unsafe extern \"C\" fn writePortableBitMap(mut file: *mut FILE) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; fprintf(file, b\"P1\\n\\0\" as *const u8 as *const libc::c_char); fprintf(file, b\"%d %d\\n\\0\" as *const u8 as *const libc::c_char, width, height); i = 0 as libc::c_int; while i < height { j = 0 as libc::c_int; while j < width { fprintf( file, b\"%1d\\0\" as *const u8 as *const libc::c_char, bitmap[i as usize][j as usize] as libc::c_int, ); j += 1; j; } fprintf(file, b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } }" }, { "index": 814, "before": "void skipCommentLines(FILE* file) { int c; int comment = '#'; while ((c = fgetc(file)) == comment) skipLine(file); ungetc(c,file); }", "after": "pub unsafe extern \"C\" fn skipCommentLines(mut file: *mut FILE) { let mut c: libc::c_int = 0; let mut comment: libc::c_int = '#' as i32; loop { c = fgetc(file); if !(c == comment) { break; } skipLine(file); } ungetc(c, file); }" }, { "index": 815, "before": "void floodFill(int i, int j) { if ( 0 <= i && i < height && 0 <= j && j < width && bitmap[i][j] == oldColor ) { bitmap[i][j] = newColor; floodFill(i-1,j); floodFill(i+1,j); floodFill(i,j-1); floodFill(i,j+1); } }", "after": "pub unsafe extern \"C\" fn floodFill(mut i: libc::c_int, mut j: libc::c_int) { if 0 as libc::c_int <= i && i < height && 0 as libc::c_int <= j && j < width && bitmap[i as usize][j as usize] as libc::c_int == oldColor as libc::c_int { bitmap[i as usize][j as usize] = newColor; floodFill(i - 1 as libc::c_int, j); floodFill(i + 1 as libc::c_int, j); floodFill(i, j - 1 as libc::c_int); floodFill(i, j + 1 as libc::c_int); } }" }, { "index": 816, "before": "void skipLine(FILE* file) { while(!ferror(file) && !feof(file) && fgetc(file) != '\\n') ; }", "after": "pub unsafe extern \"C\" fn skipLine(mut file: *mut FILE) { while ferror(file) == 0 && feof(file) == 0 && fgetc(file) != '\\n' as i32 {} }" }, { "index": 817, "before": "int main(void) { oldColor = 1; newColor = oldColor ? 0 : 1; readPortableBitMap(stdin); floodFill(height/2,width/2); writePortableBitMap(stdout); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { oldColor = 1 as libc::c_int as libc::c_uchar; newColor = (if oldColor as libc::c_int != 0 { 0 as libc::c_int } else { 1 as libc::c_int }) as libc::c_uchar; readPortableBitMap(stdin); floodFill(height / 2 as libc::c_int, width / 2 as libc::c_int); writePortableBitMap(stdout); return 0 as libc::c_int; }" }, { "index": 818, "before": "int main(int argc, char **argv) { if (argc != 2) { printf(\"Usage: benford \\n\"); return EXIT_FAILURE; } float *actual = get_actual_distribution(argv[1]); float *expected = benford_distribution(); puts(\"digit\\tactual\\texpected\"); for (int i = 0; i < 9; i++) printf(\"%d\\t%.3f\\t%.3f\\n\", i + 1, actual[i], expected[i]); return EXIT_SUCCESS; }", "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: benford \\n\\0\" as *const u8 as *const libc::c_char); return 1 as libc::c_int; } let mut actual: *mut libc::c_float = get_actual_distribution( *argv.offset(1 as libc::c_int as isize), ); let mut expected: *mut libc::c_float = benford_distribution(); puts(b\"digit\\tactual\\texpected\\0\" as *const u8 as *const libc::c_char); let mut i: libc::c_int = 0 as libc::c_int; while i < 9 as libc::c_int { printf( b\"%d\\t%.3f\\t%.3f\\n\\0\" as *const u8 as *const libc::c_char, i + 1 as libc::c_int, *actual.offset(i as isize) as libc::c_double, *expected.offset(i as isize) as libc::c_double, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 819, "before": "void best_shuffle(const char* txt, char* result) { const size_t len = strlen(txt); if (len == 0) return; #ifdef DEBUG // txt and result must have the same length assert(len == strlen(result)); #endif // how many of each character? size_t counts[UCHAR_MAX]; memset(counts, '\\0', UCHAR_MAX * sizeof(int)); size_t fmax = 0; for (size_t i = 0; i < len; i++) { counts[(unsigned char)txt[i]]++; const size_t fnew = counts[(unsigned char)txt[i]]; if (fmax < fnew) fmax = fnew; } assert(fmax > 0 && fmax <= len); // all character positions, grouped by character size_t *ndx1 = malloc(len * sizeof(size_t)); if (ndx1 == NULL) exit(EXIT_FAILURE); for (size_t ch = 0, i = 0; ch < UCHAR_MAX; ch++) if (counts[ch]) for (size_t j = 0; j < len; j++) if (ch == (unsigned char)txt[j]) { ndx1[i] = j; i++; } // regroup them for cycles size_t *ndx2 = malloc(len * sizeof(size_t)); if (ndx2 == NULL) exit(EXIT_FAILURE); for (size_t i = 0, n = 0, m = 0; i < len; i++) { ndx2[i] = ndx1[n]; n += fmax; if (n >= len) { m++; n = m; } } // how long can our cyclic groups be? const size_t grp = 1 + (len - 1) / fmax; assert(grp > 0 && grp <= len); // how many of them are full length? const size_t lng = 1 + (len - 1) % fmax; assert(lng > 0 && lng <= len); // rotate each group for (size_t i = 0, j = 0; i < fmax; i++) { const size_t first = ndx2[j]; const size_t glen = grp - (i < lng ? 0 : 1); for (size_t k = 1; k < glen; k++) ndx1[j + k - 1] = ndx2[j + k]; ndx1[j + glen - 1] = first; j += glen; } // result is original permuted according to our cyclic groups result[len] = '\\0'; for (size_t i = 0; i < len; i++) result[ndx2[i]] = txt[ndx1[i]]; free(ndx1); free(ndx2); }", "after": "pub unsafe extern \"C\" fn best_shuffle( mut txt: *const libc::c_char, mut result: *mut libc::c_char, ) { let len: size_t = strlen(txt); if len == 0 as libc::c_int as libc::c_ulong { return; } if len == strlen(result) {} else { __assert_fail( b\"len == strlen(result)\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 16 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"void best_shuffle(const char *, char *)\\0\")) .as_ptr(), ); } 'c_2313: { if len == strlen(result) {} else { __assert_fail( b\"len == strlen(result)\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 16 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"void best_shuffle(const char *, char *)\\0\")) .as_ptr(), ); } }; let mut counts: [size_t; 255] = [0; 255]; memset( counts.as_mut_ptr() as *mut libc::c_void, '\\0' as i32, ((127 as libc::c_int * 2 as libc::c_int + 1 as libc::c_int) as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ); let mut fmax: 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 < len { counts[*txt.offset(i as isize) as libc::c_uchar as usize] = (counts[*txt.offset(i as isize) as libc::c_uchar as usize]) .wrapping_add(1); counts[*txt.offset(i as isize) as libc::c_uchar as usize]; let fnew: size_t = counts[*txt.offset(i as isize) as libc::c_uchar as usize]; if fmax < fnew { fmax = fnew; } i = i.wrapping_add(1); i; } if fmax > 0 as libc::c_int as libc::c_ulong && fmax <= len {} else { __assert_fail( b\"fmax > 0 && fmax <= len\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 29 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"void best_shuffle(const char *, char *)\\0\")) .as_ptr(), ); } 'c_2197: { if fmax > 0 as libc::c_int as libc::c_ulong && fmax <= len {} else { __assert_fail( b\"fmax > 0 && fmax <= len\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 29 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"void best_shuffle(const char *, char *)\\0\")) .as_ptr(), ); } }; let mut ndx1: *mut size_t = malloc( len.wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut size_t; if ndx1.is_null() { exit(1 as libc::c_int); } let mut ch: size_t = 0 as libc::c_int as size_t; let mut i_0: size_t = 0 as libc::c_int as size_t; while ch < (127 as libc::c_int * 2 as libc::c_int + 1 as libc::c_int) as libc::c_ulong { if counts[ch as usize] != 0 { let mut j: size_t = 0 as libc::c_int as size_t; while j < len { if ch == *txt.offset(j as isize) as libc::c_uchar as libc::c_ulong { *ndx1.offset(i_0 as isize) = j; i_0 = i_0.wrapping_add(1); i_0; } j = j.wrapping_add(1); j; } } ch = ch.wrapping_add(1); ch; } let mut ndx2: *mut size_t = malloc( len.wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut size_t; if ndx2.is_null() { exit(1 as libc::c_int); } let mut i_1: size_t = 0 as libc::c_int as size_t; let mut n: size_t = 0 as libc::c_int as size_t; let mut m: size_t = 0 as libc::c_int as size_t; while i_1 < len { *ndx2.offset(i_1 as isize) = *ndx1.offset(n as isize); n = (n as libc::c_ulong).wrapping_add(fmax) as size_t as size_t; if n >= len { m = m.wrapping_add(1); m; n = m; } i_1 = i_1.wrapping_add(1); i_1; } let grp: size_t = (1 as libc::c_int as libc::c_ulong) .wrapping_add( len.wrapping_sub(1 as libc::c_int as libc::c_ulong).wrapping_div(fmax), ); if grp > 0 as libc::c_int as libc::c_ulong && grp <= len {} else { __assert_fail( b\"grp > 0 && grp <= len\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 58 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"void best_shuffle(const char *, char *)\\0\")) .as_ptr(), ); } 'c_2002: { if grp > 0 as libc::c_int as libc::c_ulong && grp <= len {} else { __assert_fail( b\"grp > 0 && grp <= len\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 58 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"void best_shuffle(const char *, char *)\\0\")) .as_ptr(), ); } }; let lng: size_t = (1 as libc::c_int as libc::c_ulong) .wrapping_add( len.wrapping_sub(1 as libc::c_int as libc::c_ulong).wrapping_rem(fmax), ); if lng > 0 as libc::c_int as libc::c_ulong && lng <= len {} else { __assert_fail( b\"lng > 0 && lng <= len\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 62 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"void best_shuffle(const char *, char *)\\0\")) .as_ptr(), ); } 'c_1947: { if lng > 0 as libc::c_int as libc::c_ulong && lng <= len {} else { __assert_fail( b\"lng > 0 && lng <= len\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 62 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"void best_shuffle(const char *, char *)\\0\")) .as_ptr(), ); } }; let mut i_2: size_t = 0 as libc::c_int as size_t; let mut j_0: size_t = 0 as libc::c_int as size_t; while i_2 < fmax { let first: size_t = *ndx2.offset(j_0 as isize); let glen: size_t = grp .wrapping_sub( (if i_2 < lng { 0 as libc::c_int } else { 1 as libc::c_int }) as libc::c_ulong, ); let mut k: size_t = 1 as libc::c_int as size_t; while k < glen { *ndx1 .offset( j_0.wrapping_add(k).wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize, ) = *ndx2.offset(j_0.wrapping_add(k) as isize); k = k.wrapping_add(1); k; } *ndx1 .offset( j_0.wrapping_add(glen).wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize, ) = first; j_0 = (j_0 as libc::c_ulong).wrapping_add(glen) as size_t as size_t; i_2 = i_2.wrapping_add(1); i_2; } *result.offset(len as isize) = '\\0' as i32 as libc::c_char; let mut i_3: size_t = 0 as libc::c_int as size_t; while i_3 < len { *result .offset( *ndx2.offset(i_3 as isize) as isize, ) = *txt.offset(*ndx1.offset(i_3 as isize) as isize); i_3 = i_3.wrapping_add(1); i_3; } free(ndx1 as *mut libc::c_void); free(ndx2 as *mut libc::c_void); }" }, { "index": 820, "before": "void display(const char* txt1, const char* txt2) { const size_t len = strlen(txt1); assert(len == strlen(txt2)); int score = 0; for (size_t i = 0; i < len; i++) if (txt1[i] == txt2[i]) score++; (void)printf(\"%s, %s, (%u)\\n\", txt1, txt2, score); }", "after": "pub unsafe extern \"C\" fn display( mut txt1: *const libc::c_char, mut txt2: *const libc::c_char, ) { let len: size_t = strlen(txt1); if len == strlen(txt2) {} else { __assert_fail( b\"len == strlen(txt2)\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 85 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 41], &[libc::c_char; 41], >(b\"void display(const char *, const char *)\\0\")) .as_ptr(), ); } 'c_2427: { if len == strlen(txt2) {} else { __assert_fail( b\"len == strlen(txt2)\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 85 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 41], &[libc::c_char; 41], >(b\"void display(const char *, const char *)\\0\")) .as_ptr(), ); } }; let mut score: libc::c_int = 0 as libc::c_int; let mut i: size_t = 0 as libc::c_int as size_t; while i < len { if *txt1.offset(i as isize) as libc::c_int == *txt2.offset(i as isize) as libc::c_int { score += 1; score; } i = i.wrapping_add(1); i; } printf(b\"%s, %s, (%u)\\n\\0\" as *const u8 as *const libc::c_char, txt1, txt2, score); }" }, { "index": 821, "before": "int main() { const char* data[] = {\"abracadabra\", \"seesaw\", \"elk\", \"grrrrrr\", \"up\", \"a\", \"aabbbbaa\", \"\", \"xxxxx\"}; const size_t data_len = sizeof(data) / sizeof(data[0]); for (size_t i = 0; i < data_len; i++) { const size_t shuf_len = strlen(data[i]) + 1; char shuf[shuf_len]; #ifdef DEBUG memset(shuf, 0xFF, sizeof shuf); shuf[shuf_len - 1] = '\\0'; #endif best_shuffle(data[i], shuf); display(data[i], shuf); } return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut data: [*const libc::c_char; 9] = [ b\"abracadabra\\0\" as *const u8 as *const libc::c_char, b\"seesaw\\0\" as *const u8 as *const libc::c_char, b\"elk\\0\" as *const u8 as *const libc::c_char, b\"grrrrrr\\0\" as *const u8 as *const libc::c_char, b\"up\\0\" as *const u8 as *const libc::c_char, b\"a\\0\" as *const u8 as *const libc::c_char, b\"aabbbbaa\\0\" as *const u8 as *const libc::c_char, b\"\\0\" as *const u8 as *const libc::c_char, b\"xxxxx\\0\" as *const u8 as *const libc::c_char, ]; let data_len: size_t = (::core::mem::size_of::<[*const libc::c_char; 9]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong); let mut i: size_t = 0 as libc::c_int as size_t; while i < data_len { let shuf_len: size_t = (strlen(data[i as usize])) .wrapping_add(1 as libc::c_int as libc::c_ulong); let vla = shuf_len as usize; let mut shuf: Vec:: = ::std::vec::from_elem(0, vla); memset( shuf.as_mut_ptr() as *mut libc::c_void, 0xff as libc::c_int, (vla * ::core::mem::size_of::()) as libc::c_ulong, ); *shuf .as_mut_ptr() .offset( shuf_len.wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize, ) = '\\0' as i32 as libc::c_char; best_shuffle(data[i as usize], shuf.as_mut_ptr()); display(data[i as usize], shuf.as_mut_ptr()); i = i.wrapping_add(1); i; } return 0 as libc::c_int; }" }, { "index": 822, "before": "int main(void) { int i; printf(\"Set [0,25]:\\n\"); for (i = 0; i < 26; i++) { char s[5]; printf(\"%s \", addSuffix(i, s, 5)); } putchar('\\n'); printf(\"Set [250,265]:\\n\"); for (i = 250; i < 266; i++) { char s[6]; printf(\"%s \", addSuffix(i, s, 6)); } putchar('\\n'); printf(\"Set [1000,1025]:\\n\"); for (i = 1000; i < 1026; i++) { char s[7]; printf(\"%s \", addSuffix(i, s, 7)); } putchar('\\n'); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; printf(b\"Set [0,25]:\\n\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < 26 as libc::c_int { let mut s: [libc::c_char; 5] = [0; 5]; printf( b\"%s \\0\" as *const u8 as *const libc::c_char, addSuffix(i, s.as_mut_ptr(), 5 as libc::c_int as size_t), ); i += 1; i; } putchar('\\n' as i32); printf(b\"Set [250,265]:\\n\\0\" as *const u8 as *const libc::c_char); i = 250 as libc::c_int; while i < 266 as libc::c_int { let mut s_0: [libc::c_char; 6] = [0; 6]; printf( b\"%s \\0\" as *const u8 as *const libc::c_char, addSuffix(i, s_0.as_mut_ptr(), 6 as libc::c_int as size_t), ); i += 1; i; } putchar('\\n' as i32); printf(b\"Set [1000,1025]:\\n\\0\" as *const u8 as *const libc::c_char); i = 1000 as libc::c_int; while i < 1026 as libc::c_int { let mut s_1: [libc::c_char; 7] = [0; 7]; printf( b\"%s \\0\" as *const u8 as *const libc::c_char, addSuffix(i, s_1.as_mut_ptr(), 7 as libc::c_int as size_t), ); i += 1; i; } putchar('\\n' as i32); return 0 as libc::c_int; }" }, { "index": 823, "before": "void print_range(const range_t* range) { printf(\"[%g, %g]\", range->low, range->high); }", "after": "pub unsafe extern \"C\" fn print_range(mut range: *const range_t) { printf( b\"[%g, %g]\\0\" as *const u8 as *const libc::c_char, (*range).low, (*range).high, ); }" }, { "index": 824, "before": "void normalize_range(range_t* range) { if (range->high < range->low) { double tmp = range->low; range->low = range->high; range->high = tmp; } }", "after": "pub unsafe extern \"C\" fn normalize_range(mut range: *mut range_t) { if (*range).high < (*range).low { let mut tmp: libc::c_double = (*range).low; (*range).low = (*range).high; (*range).high = tmp; } }" }, { "index": 825, "before": "void normalize_ranges(range_t* ranges, size_t count) { for (size_t i = 0; i < count; ++i) normalize_range(&ranges[i]); qsort(ranges, count, sizeof(range_t), range_compare); }", "after": "pub unsafe extern \"C\" fn normalize_ranges(mut ranges: *mut range_t, mut count: size_t) { let mut i: size_t = 0 as libc::c_int as size_t; while i < count { normalize_range(&mut *ranges.offset(i as isize)); i = i.wrapping_add(1); i; } qsort( ranges as *mut libc::c_void, count, ::core::mem::size_of::() as libc::c_ulong, Some( range_compare as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); }" }, { "index": 826, "before": "size_t consolidate_ranges(range_t* ranges, size_t count) { normalize_ranges(ranges, count); size_t out_index = 0; for (size_t i = 0; i < count; ) { size_t j = i; while (++j < count && ranges[j].low <= ranges[i].high) { if (ranges[i].high < ranges[j].high) ranges[i].high = ranges[j].high; } ranges[out_index++] = ranges[i]; i = j; } return out_index; }", "after": "pub unsafe extern \"C\" fn consolidate_ranges( mut ranges: *mut range_t, mut count: size_t, ) -> size_t { normalize_ranges(ranges, count); let mut out_index: 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 < count { let mut j: size_t = i; loop { j = j.wrapping_add(1); if !(j < count && (*ranges.offset(j as isize)).low <= (*ranges.offset(i as isize)).high) { break; } if (*ranges.offset(i as isize)).high < (*ranges.offset(j as isize)).high { (*ranges.offset(i as isize)).high = (*ranges.offset(j as isize)).high; } } let fresh0 = out_index; out_index = out_index.wrapping_add(1); *ranges.offset(fresh0 as isize) = *ranges.offset(i as isize); i = j; } return out_index; }" }, { "index": 827, "before": "void test_consolidate_ranges(range_t* ranges, size_t count) { print_ranges(ranges, count); printf(\" -> \"); count = consolidate_ranges(ranges, count); print_ranges(ranges, count); printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn test_consolidate_ranges( mut ranges: *mut range_t, mut count: size_t, ) { print_ranges(ranges, count); printf(b\" -> \\0\" as *const u8 as *const libc::c_char); count = consolidate_ranges(ranges, count); print_ranges(ranges, count); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 828, "before": "int range_compare(const void* p1, const void* p2) { const range_t* r1 = p1; const range_t* r2 = p2; if (r1->low < r2->low) return -1; if (r1->low > r2->low) return 1; if (r1->high < r2->high) return -1; if (r1->high > r2->high) return 1; return 0; }", "after": "pub unsafe extern \"C\" fn range_compare( mut p1: *const libc::c_void, mut p2: *const libc::c_void, ) -> libc::c_int { let mut r1: *const range_t = p1 as *const range_t; let mut r2: *const range_t = p2 as *const range_t; if (*r1).low < (*r2).low { return -(1 as libc::c_int); } if (*r1).low > (*r2).low { return 1 as libc::c_int; } if (*r1).high < (*r2).high { return -(1 as libc::c_int); } if (*r1).high > (*r2).high { return 1 as libc::c_int; } return 0 as libc::c_int; }" }, { "index": 829, "before": "int main() { range_t test1[] = { {1.1, 2.2} }; range_t test2[] = { {6.1, 7.2}, {7.2, 8.3} }; range_t test3[] = { {4, 3}, {2, 1} }; range_t test4[] = { {4, 3}, {2, 1}, {-1, -2}, {3.9, 10} }; range_t test5[] = { {1, 3}, {-6, -1}, {-4, -5}, {8, 2}, {-6, -6} }; test_consolidate_ranges(test1, LENGTHOF(test1)); test_consolidate_ranges(test2, LENGTHOF(test2)); test_consolidate_ranges(test3, LENGTHOF(test3)); test_consolidate_ranges(test4, LENGTHOF(test4)); test_consolidate_ranges(test5, LENGTHOF(test5)); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut test1: [range_t; 1] = [ { let mut init = range_tag { low: 1.1f64, high: 2.2f64, }; init }, ]; let mut test2: [range_t; 2] = [ { let mut init = range_tag { low: 6.1f64, high: 7.2f64, }; init }, { let mut init = range_tag { low: 7.2f64, high: 8.3f64, }; init }, ]; let mut test3: [range_t; 2] = [ { let mut init = range_tag { low: 4 as libc::c_int as libc::c_double, high: 3 as libc::c_int as libc::c_double, }; init }, { let mut init = range_tag { low: 2 as libc::c_int as libc::c_double, high: 1 as libc::c_int as libc::c_double, }; init }, ]; let mut test4: [range_t; 4] = [ { let mut init = range_tag { low: 4 as libc::c_int as libc::c_double, high: 3 as libc::c_int as libc::c_double, }; init }, { let mut init = range_tag { low: 2 as libc::c_int as libc::c_double, high: 1 as libc::c_int as libc::c_double, }; init }, { let mut init = range_tag { low: -(1 as libc::c_int) as libc::c_double, high: -(2 as libc::c_int) as libc::c_double, }; init }, { let mut init = range_tag { low: 3.9f64, high: 10 as libc::c_int as libc::c_double, }; init }, ]; let mut test5: [range_t; 5] = [ { let mut init = range_tag { low: 1 as libc::c_int as libc::c_double, high: 3 as libc::c_int as libc::c_double, }; init }, { let mut init = range_tag { low: -(6 as libc::c_int) as libc::c_double, high: -(1 as libc::c_int) as libc::c_double, }; init }, { let mut init = range_tag { low: -(4 as libc::c_int) as libc::c_double, high: -(5 as libc::c_int) as libc::c_double, }; init }, { let mut init = range_tag { low: 8 as libc::c_int as libc::c_double, high: 2 as libc::c_int as libc::c_double, }; init }, { let mut init = range_tag { low: -(6 as libc::c_int) as libc::c_double, high: -(6 as libc::c_int) as libc::c_double, }; init }, ]; test_consolidate_ranges( test1.as_mut_ptr(), (::core::mem::size_of::<[range_t; 1]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong), ); test_consolidate_ranges( test2.as_mut_ptr(), (::core::mem::size_of::<[range_t; 2]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong), ); test_consolidate_ranges( test3.as_mut_ptr(), (::core::mem::size_of::<[range_t; 2]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong), ); test_consolidate_ranges( test4.as_mut_ptr(), (::core::mem::size_of::<[range_t; 4]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong), ); test_consolidate_ranges( test5.as_mut_ptr(), (::core::mem::size_of::<[range_t; 5]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong), ); return 0 as libc::c_int; }" }, { "index": 830, "before": "void print_ranges(const range_t* ranges, size_t count) { if (count == 0) return; print_range(&ranges[0]); for (size_t i = 1; i < count; ++i) { printf(\", \"); print_range(&ranges[i]); } }", "after": "pub unsafe extern \"C\" fn print_ranges(mut ranges: *const range_t, mut count: size_t) { if count == 0 as libc::c_int as libc::c_ulong { return; } print_range(&*ranges.offset(0 as libc::c_int as isize)); let mut i: size_t = 1 as libc::c_int as size_t; while i < count { printf(b\", \\0\" as *const u8 as *const libc::c_char); print_range(&*ranges.offset(i as isize)); i = i.wrapping_add(1); i; } }" }, { "index": 831, "before": "void show(i128 v) { \tuint32_t x[4] = {v.x[0], v.x[0] >> 32, v.x[1], v.x[1] >> 32}; \tint i, j = 0, len = 4; \tchar buf[100]; \tdo { \t\tuint64_t c = 0; \t\tfor (i = len; i--; ) { \t\t\tc = (c << 32) + x[i]; \t\t\tx[i] = c / 10, c %= 10; \t\t} \t\tbuf[j++] = c + '0'; \t\tfor (len = 4; !x[len - 1]; len--); \t} while (len); \twhile (j--) putchar(buf[j]); \tputchar('\\n'); }", "after": "pub unsafe extern \"C\" fn show(mut v: i128_0) { let mut x: [uint32_t; 4] = [ v.x[0 as libc::c_int as usize] as uint32_t, (v.x[0 as libc::c_int as usize] >> 32 as libc::c_int) as uint32_t, v.x[1 as libc::c_int as usize] as uint32_t, (v.x[1 as libc::c_int as usize] >> 32 as libc::c_int) as uint32_t, ]; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0 as libc::c_int; let mut len: libc::c_int = 4 as libc::c_int; let mut buf: [libc::c_char; 100] = [0; 100]; loop { let mut c: uint64_t = 0 as libc::c_int as uint64_t; i = len; loop { let fresh0 = i; i = i - 1; if !(fresh0 != 0) { break; } c = (c << 32 as libc::c_int).wrapping_add(x[i as usize] as libc::c_ulong); x[i as usize] = c.wrapping_div(10 as libc::c_int as libc::c_ulong) as uint32_t; c = (c as libc::c_ulong).wrapping_rem(10 as libc::c_int as libc::c_ulong) as uint64_t as uint64_t; } let fresh1 = j; j = j + 1; buf[fresh1 as usize] = c.wrapping_add('0' as i32 as libc::c_ulong) as libc::c_char; len = 4 as libc::c_int; while x[(len - 1 as libc::c_int) as usize] == 0 { len -= 1; len; } if !(len != 0) { break; } } loop { let fresh2 = j; j = j - 1; if !(fresh2 != 0) { break; } putchar(buf[j as usize] as libc::c_int); } putchar('\\n' as i32); }" }, { "index": 832, "before": "int count2(int sum, int *coins) { \tif (!*coins || sum < 0) return 0; \tif (!sum) return 1; \treturn count2(sum - *coins, coins) + count2(sum, coins + 1); }", "after": "pub unsafe extern \"C\" fn count2( mut sum: libc::c_int, mut coins: *mut libc::c_int, ) -> libc::c_int { if *coins == 0 || sum < 0 as libc::c_int { return 0 as libc::c_int; } if sum == 0 { return 1 as libc::c_int; } return count2(sum - *coins, coins) + count2(sum, coins.offset(1 as libc::c_int as isize)); }" }, { "index": 833, "before": "i128 count(int sum, int *coins) { \tint n, i, k; \tfor (n = 0; coins[n]; n++); \ti128 **v = malloc(sizeof(int*) * n); \tint *idx = malloc(sizeof(int) * n); \tfor (i = 0; i < n; i++) { \t\tidx[i] = coins[i]; \t\t// each v[i] is a cyclic buffer \t\tv[i] = calloc(sizeof(i128), coins[i]); \t} \tv[0][coins[0] - 1] = (i128) {{1, 0}}; \tfor (k = 0; k <= sum; k++) { \t\tfor (i = 0; i < n; i++) \t\t\tif (!idx[i]--) idx[i] = coins[i] - 1; \t\ti128 c = v[0][ idx[0] ]; \t\tfor (i = 1; i < n; i++) { \t\t\ti128 *p = v[i] + idx[i]; \t\t\t// 128 bit addition \t\t\tp->x[0] += c.x[0]; \t\t\tp->x[1] += c.x[1]; \t\t\tif (p->x[0] < c.x[0]) // carry \t\t\t\tp->x[1] ++; \t\t\tc = *p; \t\t} \t} \ti128 r = v[n - 1][idx[n-1]]; \tfor (i = 0; i < n; i++) free(v[i]); \tfree(v); \tfree(idx); \treturn r; }", "after": "pub unsafe extern \"C\" fn count( mut sum: libc::c_int, mut coins: *mut libc::c_int, ) -> i128_0 { let mut n: libc::c_int = 0; let mut i: libc::c_int = 0; let mut k: libc::c_int = 0; n = 0 as libc::c_int; while *coins.offset(n as isize) != 0 { n += 1; n; } let mut v: *mut *mut i128_0 = malloc( (::core::mem::size_of::<*mut libc::c_int>() as libc::c_ulong) .wrapping_mul(n as libc::c_ulong), ) as *mut *mut i128_0; let mut idx: *mut libc::c_int = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(n as libc::c_ulong), ) as *mut libc::c_int; i = 0 as libc::c_int; while i < n { *idx.offset(i as isize) = *coins.offset(i as isize); let ref mut fresh3 = *v.offset(i as isize); *fresh3 = calloc( ::core::mem::size_of::() as libc::c_ulong, *coins.offset(i as isize) as libc::c_ulong, ) as *mut i128_0; i += 1; i; } *(*v.offset(0 as libc::c_int as isize)) .offset( (*coins.offset(0 as libc::c_int as isize) - 1 as libc::c_int) as isize, ) = { let mut init = i128_0 { x: [1 as libc::c_int as uint64_t, 0 as libc::c_int as uint64_t], }; init }; k = 0 as libc::c_int; while k <= sum { i = 0 as libc::c_int; while i < n { let ref mut fresh4 = *idx.offset(i as isize); let fresh5 = *fresh4; *fresh4 = *fresh4 - 1; if fresh5 == 0 { *idx.offset(i as isize) = *coins.offset(i as isize) - 1 as libc::c_int; } i += 1; i; } let mut c: i128_0 = *(*v.offset(0 as libc::c_int as isize)) .offset(*idx.offset(0 as libc::c_int as isize) as isize); i = 1 as libc::c_int; while i < n { let mut p: *mut i128_0 = (*v.offset(i as isize)) .offset(*idx.offset(i as isize) as isize); (*p) .x[0 as libc::c_int as usize] = ((*p).x[0 as libc::c_int as usize] as libc::c_ulong) .wrapping_add(c.x[0 as libc::c_int as usize]) as uint64_t as uint64_t; (*p) .x[1 as libc::c_int as usize] = ((*p).x[1 as libc::c_int as usize] as libc::c_ulong) .wrapping_add(c.x[1 as libc::c_int as usize]) as uint64_t as uint64_t; if (*p).x[0 as libc::c_int as usize] < c.x[0 as libc::c_int as usize] { (*p) .x[1 as libc::c_int as usize] = ((*p).x[1 as libc::c_int as usize]).wrapping_add(1); (*p).x[1 as libc::c_int as usize]; } c = *p; i += 1; i; } k += 1; k; } let mut r: i128_0 = *(*v.offset((n - 1 as libc::c_int) as isize)) .offset(*idx.offset((n - 1 as libc::c_int) as isize) as isize); i = 0 as libc::c_int; while i < n { free(*v.offset(i as isize) as *mut libc::c_void); i += 1; i; } free(v as *mut libc::c_void); free(idx as *mut libc::c_void); return r; }" }, { "index": 834, "before": "int main(void) { \tint us_coins[] = { 100, 50, 25, 10, 5, 1, 0 }; \tint eu_coins[] = { 200, 100, 50, 20, 10, 5, 2, 1, 0 }; \tshow(count( 100, us_coins + 2)); \tshow(count( 1000, us_coins)); \tshow(count( 1000 * 100, us_coins)); \tshow(count( 10000 * 100, us_coins)); \tshow(count(100000 * 100, us_coins)); \tputchar('\\n'); \tshow(count( 1 * 100, eu_coins)); \tshow(count( 1000 * 100, eu_coins)); \tshow(count( 10000 * 100, eu_coins)); \tshow(count(100000 * 100, eu_coins)); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut us_coins: [libc::c_int; 7] = [ 100 as libc::c_int, 50 as libc::c_int, 25 as libc::c_int, 10 as libc::c_int, 5 as libc::c_int, 1 as libc::c_int, 0 as libc::c_int, ]; let mut eu_coins: [libc::c_int; 9] = [ 200 as libc::c_int, 100 as libc::c_int, 50 as libc::c_int, 20 as libc::c_int, 10 as libc::c_int, 5 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 0 as libc::c_int, ]; show( count( 100 as libc::c_int, us_coins.as_mut_ptr().offset(2 as libc::c_int as isize), ), ); show(count(1000 as libc::c_int, us_coins.as_mut_ptr())); show(count(1000 as libc::c_int * 100 as libc::c_int, us_coins.as_mut_ptr())); show(count(10000 as libc::c_int * 100 as libc::c_int, us_coins.as_mut_ptr())); show(count(100000 as libc::c_int * 100 as libc::c_int, us_coins.as_mut_ptr())); putchar('\\n' as i32); show(count(1 as libc::c_int * 100 as libc::c_int, eu_coins.as_mut_ptr())); show(count(1000 as libc::c_int * 100 as libc::c_int, eu_coins.as_mut_ptr())); show(count(10000 as libc::c_int * 100 as libc::c_int, eu_coins.as_mut_ptr())); show(count(100000 as libc::c_int * 100 as libc::c_int, eu_coins.as_mut_ptr())); return 0 as libc::c_int; }" }, { "index": 835, "before": "int main() { { unsigned long long n = 1; for (int i = 0; i < 30; i++) { // __builtin_popcount() for unsigned int // __builtin_popcountl() for unsigned long // __builtin_popcountll() for unsigned long long printf(\"%d \", __builtin_popcountll(n)); n *= 3; } printf(\"\\n\"); } int od[30]; int ne = 0, no = 0; printf(\"evil : \"); for (int n = 0; ne+no < 60; n++) { if ((__builtin_popcount(n) & 1) == 0) { if (ne < 30) { \tprintf(\"%d \", n); \tne++; } } else { if (no < 30) { \tod[no++] = n; } } } printf(\"\\n\"); printf(\"odious: \"); for (int i = 0; i < 30; i++) { printf(\"%d \", od[i]); } printf(\"\\n\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_ulonglong = 1 as libc::c_int as libc::c_ulonglong; let mut i: libc::c_int = 0 as libc::c_int; while i < 30 as libc::c_int { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, n.count_ones() as i32); n = n.wrapping_mul(3 as libc::c_int as libc::c_ulonglong); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); let mut od: [libc::c_int; 30] = [0; 30]; let mut ne: libc::c_int = 0 as libc::c_int; let mut no: libc::c_int = 0 as libc::c_int; printf(b\"evil : \\0\" as *const u8 as *const libc::c_char); let mut n_0: libc::c_int = 0 as libc::c_int; while ne + no < 60 as libc::c_int { if (n_0 as libc::c_uint).count_ones() as i32 & 1 as libc::c_int == 0 as libc::c_int { if ne < 30 as libc::c_int { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, n_0); ne += 1; ne; } } else if no < 30 as libc::c_int { let fresh0 = no; no = no + 1; od[fresh0 as usize] = n_0; } n_0 += 1; n_0; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); printf(b\"odious: \\0\" as *const u8 as *const libc::c_char); let mut i_0: libc::c_int = 0 as libc::c_int; while i_0 < 30 as libc::c_int { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, od[i_0 as usize]); i_0 += 1; i_0; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 836, "before": "void mat_pivot(mat a, mat p, _dim) { \tfor_ij { p[i][j] = (i == j); }", "after": "pub unsafe extern \"C\" fn mat_pivot(mut a: mat, mut p: mat, mut n: libc::c_int) { let mut i: libc::c_int = 0 as libc::c_int; while i < n { let mut j: libc::c_int = 0 as libc::c_int; while j < n { *(*p.offset(i as isize)) .offset(j as isize) = (i == j) as libc::c_int as libc::c_double; j += 1; j; } i += 1; i; } let mut i_0: libc::c_int = 0 as libc::c_int; while i_0 < n { let mut max_j: libc::c_int = i_0; let mut j_0: libc::c_int = i_0; while j_0 < n { if fabs(*(*a.offset(j_0 as isize)).offset(i_0 as isize)) > fabs(*(*a.offset(max_j as isize)).offset(i_0 as isize)) { max_j = j_0; } j_0 += 1; j_0; } if max_j != i_0 { let mut k: libc::c_int = 0 as libc::c_int; while k < n { let mut tmp: libc::c_double = *(*p.offset(i_0 as isize)) .offset(k as isize); *(*p.offset(i_0 as isize)) .offset( k as isize, ) = *(*p.offset(max_j as isize)).offset(k as isize); *(*p.offset(max_j as isize)).offset(k as isize) = tmp; k += 1; k; } } i_0 += 1; i_0; } }" }, { "index": 837, "before": "void mat_show(mat x, char *fmt, _dim) { \tif (!fmt) fmt = \"%8.4g\"; \tfor_i { \t\tprintf(i ? \" \" : \" [ \"); \t\tfor_j { \t\t\tprintf(fmt, x[i][j]); \t\t\tprintf(j < n - 1 ? \" \" : i == n - 1 ? \" ]\\n\" : \"\\n\"); \t\t} \t} }", "after": "pub unsafe extern \"C\" fn mat_show( mut x: mat, mut fmt: *mut libc::c_char, mut n: libc::c_int, ) { if fmt.is_null() { fmt = b\"%8.4g\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; } let mut i: libc::c_int = 0 as libc::c_int; while i < n { printf( if i != 0 { b\" \\0\" as *const u8 as *const libc::c_char } else { b\" [ \\0\" as *const u8 as *const libc::c_char }, ); let mut j: libc::c_int = 0 as libc::c_int; while j < n { printf(fmt, *(*x.offset(i as isize)).offset(j as isize)); printf( if j < n - 1 as libc::c_int { b\" \\0\" as *const u8 as *const libc::c_char } else if i == n - 1 as libc::c_int { b\" ]\\n\\0\" as *const u8 as *const libc::c_char } else { b\"\\n\\0\" as *const u8 as *const libc::c_char }, ); j += 1; j; } i += 1; i; } }" }, { "index": 838, "before": "mat mat_new(_dim) { \tmat x = malloc(sizeof(double*) * n); \tx[0] = malloc(sizeof(double) * n * n); \tfor_i x[i] = x[0] + n * i; \t_zero(x); \treturn x; }", "after": "pub unsafe extern \"C\" fn mat_new(mut n: libc::c_int) -> mat { let mut x: mat = malloc( (::core::mem::size_of::<*mut libc::c_double>() as libc::c_ulong) .wrapping_mul(n as libc::c_ulong), ) as mat; let ref mut fresh0 = *x.offset(0 as libc::c_int as isize); *fresh0 = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(n as libc::c_ulong) .wrapping_mul(n as libc::c_ulong), ) as *mut libc::c_double; let mut i: libc::c_int = 0 as libc::c_int; while i < n { let ref mut fresh1 = *x.offset(i as isize); *fresh1 = (*x.offset(0 as libc::c_int as isize)).offset((n * i) as isize); i += 1; i; } mat_zero(x, n); return x; }" }, { "index": 839, "before": "void mat_zero(mat x, int n) { for_ij x[i][j] = 0; }", "after": "pub unsafe extern \"C\" fn mat_zero(mut x: mat, mut n: libc::c_int) { let mut i: libc::c_int = 0 as libc::c_int; while i < n { let mut j: libc::c_int = 0 as libc::c_int; while j < n { *(*x.offset(i as isize)) .offset(j as isize) = 0 as libc::c_int as libc::c_double; j += 1; j; } i += 1; i; } }" }, { "index": 840, "before": "mat mat_copy(void *s, _dim) { \tmat x = mat_new(n); \tfor_ij x[i][j] = ((double (*)[n])s)[i][j]; \treturn x; }", "after": "pub unsafe extern \"C\" fn mat_copy(mut s: *mut libc::c_void, mut n: libc::c_int) -> mat { let mut x: mat = mat_new(n); let mut i: libc::c_int = 0 as libc::c_int; while i < n { let mut j: libc::c_int = 0 as libc::c_int; while j < n { let vla = n as usize; *(*x.offset(i as isize)) .offset( j as isize, ) = *(s as *mut libc::c_double) .offset(i as isize * vla as isize) .offset(j as isize); j += 1; j; } i += 1; i; } return x; }" }, { "index": 841, "before": "void mat_LU(mat A, mat L, mat U, mat P, _dim) { \t_zero(L); _zero(U); \t_pivot(A, P); \tmat Aprime = _mul(P, A); \tfor_i { L[i][i] = 1; }", "after": "pub unsafe extern \"C\" fn mat_LU( mut A: mat, mut L: mat, mut U: mat, mut P: mat, mut n: libc::c_int, ) { mat_zero(L, n); mat_zero(U, n); mat_pivot(A, P, n); let mut Aprime: mat = mat_mul(P, A, n); let mut i: libc::c_int = 0 as libc::c_int; while i < n { *(*L.offset(i as isize)).offset(i as isize) = 1 as libc::c_int as libc::c_double; i += 1; i; } let mut i_0: libc::c_int = 0 as libc::c_int; while i_0 < n { let mut j: libc::c_int = 0 as libc::c_int; while j < n { let mut s: libc::c_double = 0.; if j <= i_0 { s = 0 as libc::c_int as libc::c_double; let mut k: libc::c_int = 0 as libc::c_int; while k < j { s += *(*L.offset(j as isize)).offset(k as isize) * *(*U.offset(k as isize)).offset(i_0 as isize); k += 1; k; } *(*U.offset(j as isize)) .offset( i_0 as isize, ) = *(*Aprime.offset(j as isize)).offset(i_0 as isize) - s; } if j >= i_0 { s = 0 as libc::c_int as libc::c_double; let mut k_0: libc::c_int = 0 as libc::c_int; while k_0 < i_0 { s += *(*L.offset(j as isize)).offset(k_0 as isize) * *(*U.offset(k_0 as isize)).offset(i_0 as isize); k_0 += 1; k_0; } *(*L.offset(j as isize)) .offset( i_0 as isize, ) = (*(*Aprime.offset(j as isize)).offset(i_0 as isize) - s) / *(*U.offset(i_0 as isize)).offset(i_0 as isize); } j += 1; j; } i_0 += 1; i_0; } mat_del(Aprime); }" }, { "index": 842, "before": "mat mat_mul(mat a, mat b, _dim) { \tmat c = _new(c); \tfor_ijk c[i][j] += a[i][k] * b[k][j]; \treturn c; }", "after": "pub unsafe extern \"C\" fn mat_mul(mut a: mat, mut b: mat, mut n: libc::c_int) -> mat { let mut c: mat = 0 as *mut *mut libc::c_double; c = mat_new(n); c = c; let mut i: libc::c_int = 0 as libc::c_int; while i < n { let mut j: libc::c_int = 0 as libc::c_int; while j < n { let mut k: libc::c_int = 0 as libc::c_int; while k < n { *(*c.offset(i as isize)).offset(j as isize) += *(*a.offset(i as isize)).offset(k as isize) * *(*b.offset(k as isize)).offset(j as isize); k += 1; k; } j += 1; j; } i += 1; i; } return c; }" }, { "index": 843, "before": "int main() { \tint n = 3; \tmat A, L, P, U; \t_new(L); _new(P); _new(U); \tA = _copy(A3); \t_LU(A, L, U, P); \t_show(A); _show(L); _show(U); _show(P); \t_del(A); _del(L); _del(U); _del(P); \tprintf(\"\\n\"); \tn = 4; \t_new(L); _new(P); _new(U); \tA = _copy(A4); \t_LU(A, L, U, P); \t_show(A); _show(L); _show(U); _show(P); \t_del(A); _del(L); _del(U); _del(P); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 3 as libc::c_int; let mut A: mat = 0 as *mut *mut libc::c_double; let mut L: mat = 0 as *mut *mut libc::c_double; let mut P: mat = 0 as *mut *mut libc::c_double; let mut U: mat = 0 as *mut *mut libc::c_double; L = mat_new(n); P = mat_new(n); U = mat_new(n); A = mat_copy(A3.as_mut_ptr() as *mut libc::c_void, n); mat_LU(A, L, U, P, n); printf(b\"A =\\0\" as *const u8 as *const libc::c_char); mat_show(A, 0 as *mut libc::c_char, n); printf(b\"L =\\0\" as *const u8 as *const libc::c_char); mat_show(L, 0 as *mut libc::c_char, n); printf(b\"U =\\0\" as *const u8 as *const libc::c_char); mat_show(U, 0 as *mut libc::c_char, n); printf(b\"P =\\0\" as *const u8 as *const libc::c_char); mat_show(P, 0 as *mut libc::c_char, n); mat_del(A); mat_del(L); mat_del(U); mat_del(P); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); n = 4 as libc::c_int; L = mat_new(n); P = mat_new(n); U = mat_new(n); A = mat_copy(A4.as_mut_ptr() as *mut libc::c_void, n); mat_LU(A, L, U, P, n); printf(b\"A =\\0\" as *const u8 as *const libc::c_char); mat_show(A, 0 as *mut libc::c_char, n); printf(b\"L =\\0\" as *const u8 as *const libc::c_char); mat_show(L, 0 as *mut libc::c_char, n); printf(b\"U =\\0\" as *const u8 as *const libc::c_char); mat_show(U, 0 as *mut libc::c_char, n); printf(b\"P =\\0\" as *const u8 as *const libc::c_char); mat_show(P, 0 as *mut libc::c_char, n); mat_del(A); mat_del(L); mat_del(U); mat_del(P); return 0 as libc::c_int; }" }, { "index": 844, "before": "void mat_del(mat x) { free(x[0]); free(x); }", "after": "pub unsafe extern \"C\" fn mat_del(mut x: mat) { free(*x.offset(0 as libc::c_int as isize) as *mut libc::c_void); free(x as *mut libc::c_void); }" }, { "index": 845, "before": "double functionB(double v) { return exp(log(v)/3); }", "after": "pub unsafe extern \"C\" fn functionB(mut v: libc::c_double) -> libc::c_double { return exp(log(v) / 3 as libc::c_int as libc::c_double); }" }, { "index": 846, "before": "double functionA( double v) { return v*v*v; }", "after": "pub unsafe extern \"C\" fn functionA(mut v: libc::c_double) -> libc::c_double { return v * v * v; }" }, { "index": 847, "before": "Class2Func WhichFunc( int idx) { return (idx < 4) ? &functionA : &functionB; }", "after": "pub unsafe extern \"C\" fn WhichFunc(mut idx: libc::c_int) -> Class2Func { return if idx < 4 as libc::c_int { Some(functionA as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double) } else { Some(functionB as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double) }; }" }, { "index": 848, "before": "int main(int argc, char *argv[]) { int ix; Composition c; printf(\"Function1(functionA, 3.0) = %f\\n\", Function1(WhichFunc(0), 3.0)); for (ix=0; ix<4; ix++) { c = Compose(funcListA[ix], funcListB[ix]); printf(\"Compostion %d(0.9) = %f\\n\", ix, CallComposed(c, 0.9)); } return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut ix: libc::c_int = 0; let mut c: Composition = 0 as *mut sComposition; printf( b\"Function1(functionA, 3.0) = %f\\n\\0\" as *const u8 as *const libc::c_char, Function1(WhichFunc(0 as libc::c_int), 3.0f64), ); ix = 0 as libc::c_int; while ix < 4 as libc::c_int { c = Compose(funcListA[ix as usize], funcListB[ix as usize]); printf( b\"Compostion %d(0.9) = %f\\n\\0\" as *const u8 as *const libc::c_char, ix, CallComposed(c, 0.9f64), ); ix += 1; ix; } return 0 as libc::c_int; }" }, { "index": 849, "before": "double Function1( Class2Func f2, double val ) { return f2(val); }", "after": "pub unsafe extern \"C\" fn Function1( mut f2: Class2Func, mut val: libc::c_double, ) -> libc::c_double { return f2.expect(\"non-null function pointer\")(val); }" }, { "index": 850, "before": "double CallComposed( Composition comp, double val ) { return comp->f1( comp->f2(val) ); }", "after": "pub unsafe extern \"C\" fn CallComposed( mut comp: Composition, mut val: libc::c_double, ) -> libc::c_double { return ((*comp).f1) .expect( \"non-null function pointer\", )(((*comp).f2).expect(\"non-null function pointer\")(val)); }" }, { "index": 851, "before": "double InvokeComposed( Class2Func f1, Class2Func f2, double val ) { return f1(f2(val)); }", "after": "pub unsafe extern \"C\" fn InvokeComposed( mut f1: Class2Func, mut f2: Class2Func, mut val: libc::c_double, ) -> libc::c_double { return f1 .expect( \"non-null function pointer\", )(f2.expect(\"non-null function pointer\")(val)); }" }, { "index": 852, "before": "Composition Compose( Class2Func f1, Class2Func f2) { Composition comp = malloc(sizeof(struct sComposition)); comp->f1 = f1; comp->f2 = f2; return comp; }", "after": "pub unsafe extern \"C\" fn Compose(mut f1: Class2Func, mut f2: Class2Func) -> Composition { let mut comp: Composition = malloc( ::core::mem::size_of::() as libc::c_ulong, ) as Composition; (*comp).f1 = f1; (*comp).f2 = f2; return comp; }" }, { "index": 853, "before": "int ParseIPv4OrIPv6(const char **ppszText, unsigned char *abyAddr, int *pnPort, int *pbIsIPv6) { unsigned char *abyAddrLocal; unsigned char abyDummyAddr[16]; //find first colon, dot, and open bracket const char *pchColon = strchr(*ppszText, ':'); const char *pchDot = strchr(*ppszText, '.'); const char *pchOpenBracket = strchr(*ppszText, '['); const char *pchCloseBracket = NULL; //we'll consider this to (probably) be IPv6 if we find an open //bracket, or an absence of dots, or if there is a colon, and it //precedes any dots that may or may not be there int bIsIPv6local = NULL != pchOpenBracket || NULL == pchDot || (NULL != pchColon && (NULL == pchDot || pchColon < pchDot)); //OK, now do a little further sanity check our initial guess... if (bIsIPv6local) { //if open bracket, then must have close bracket that follows somewhere pchCloseBracket = strchr(*ppszText, ']'); if (NULL != pchOpenBracket && (NULL == pchCloseBracket || pchCloseBracket < pchOpenBracket)) return 0; } else //probably ipv4 { //dots must exist, and precede any colons if (NULL == pchDot || (NULL != pchColon && pchColon < pchDot)) return 0; } //we figured out this much so far.... if (NULL != pbIsIPv6) *pbIsIPv6 = bIsIPv6local; //especially for IPv6 (where we will be decompressing and validating) //we really need to have a working buffer even if the caller didn't //care about the results. abyAddrLocal = abyAddr; //prefer to use the caller's if (NULL == abyAddrLocal) //but use a dummy if we must abyAddrLocal = abyDummyAddr; //OK, there should be no correctly formed strings which are miscategorized, //and now any format errors will be found out as we continue parsing //according to plan. if (!bIsIPv6local) //try to parse as IPv4 { //4 dotted quad decimal; optional port if there is a colon //since there are just 4, and because the last one can be terminated //differently, I'm just going to unroll any potential loop. unsigned char *pbyAddrCursor = abyAddrLocal; unsigned int nVal; const char *pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); //get first val if ('.' != **ppszText || nVal > 255 || pszTextBefore == *ppszText) //must be in range and followed by dot and nonempty return 0; *(pbyAddrCursor++) = (unsigned char)nVal; //stick it in addr ++(*ppszText); //past the dot pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); //get second val if ('.' != **ppszText || nVal > 255 || pszTextBefore == *ppszText) return 0; *(pbyAddrCursor++) = (unsigned char)nVal; ++(*ppszText); //past the dot pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); //get third val if ('.' != **ppszText || nVal > 255 || pszTextBefore == *ppszText) return 0; *(pbyAddrCursor++) = (unsigned char)nVal; ++(*ppszText); //past the dot pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); //get fourth val if (nVal > 255 || pszTextBefore == *ppszText) //(we can terminate this one in several ways) return 0; *(pbyAddrCursor++) = (unsigned char)nVal; if (':' == **ppszText && NULL != pnPort) //have port part, and we want it { unsigned short usPortNetwork; //save value in network order ++(*ppszText); //past the colon pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if (nVal > 65535 || pszTextBefore == *ppszText) return 0; ((unsigned char *)&usPortNetwork)[0] = (nVal & 0xff00) >> 8; ((unsigned char *)&usPortNetwork)[1] = (nVal & 0xff); *pnPort = usPortNetwork; return 1; } else //finished just with ip address { if (NULL != pnPort) *pnPort = 0; //indicate we have no port part return 1; } } else //try to parse as IPv6 { unsigned char *pbyAddrCursor; unsigned char *pbyZerosLoc; int bIPv4Detected; int nIdx; //up to 8 16-bit hex quantities, separated by colons, with at most one //empty quantity, acting as a stretchy run of zeroes. optional port //if there are brackets followed by colon and decimal port number. //A further form allows an ipv4 dotted quad instead of the last two //16-bit quantities, but only if in the ipv4 space ::ffff:x:x . if (NULL != pchOpenBracket) //start past the open bracket, if it exists *ppszText = pchOpenBracket + 1; pbyAddrCursor = abyAddrLocal; pbyZerosLoc = NULL; //if we find a 'zero compression' location bIPv4Detected = 0; for (nIdx = 0; nIdx < 8; ++nIdx) //we've got up to 8 of these, so we will use a loop { const char *pszTextBefore = *ppszText; unsigned nVal = _parseHex(ppszText); //get value; these are hex if (pszTextBefore == *ppszText) //if empty, we are zero compressing; note the loc { if (NULL != pbyZerosLoc) //there can be only one! { //unless it's a terminal empty field, then this is OK, it just means we're done with the host part if (pbyZerosLoc == pbyAddrCursor) { --nIdx; break; } return 0; //otherwise, it's a format error } if (':' != **ppszText) //empty field can only be via : return 0; if (0 == nIdx) //leading zero compression requires an extra peek, and adjustment { ++(*ppszText); if (':' != **ppszText) return 0; } pbyZerosLoc = pbyAddrCursor; ++(*ppszText); } else { if ('.' == **ppszText) //special case of ipv4 convenience notation { //who knows how to parse ipv4? we do! const char *pszTextlocal = pszTextBefore; //back it up unsigned char abyAddrlocal[16]; int bIsIPv6local; int bParseResultlocal = ParseIPv4OrIPv6(&pszTextlocal, abyAddrlocal, NULL, &bIsIPv6local); *ppszText = pszTextlocal; //success or fail, remember the terminating char if (!bParseResultlocal || bIsIPv6local) //must parse and must be ipv4 return 0; //transfer addrlocal into the present location *(pbyAddrCursor++) = abyAddrlocal[0]; *(pbyAddrCursor++) = abyAddrlocal[1]; *(pbyAddrCursor++) = abyAddrlocal[2]; *(pbyAddrCursor++) = abyAddrlocal[3]; ++nIdx; //pretend like we took another short, since the ipv4 effectively is two shorts bIPv4Detected = 1; //remember how we got here for further validation later break; //totally done with address } if (nVal > 65535) //must be 16 bit quantity return 0; *(pbyAddrCursor++) = nVal >> 8; //transfer in network order *(pbyAddrCursor++) = nVal & 0xff; if (':' == **ppszText) //typical case inside; carry on { ++(*ppszText); } else //some other terminating character; done with this parsing parts { break; } } } //handle any zero compression we found if (NULL != pbyZerosLoc) { int nHead = (int)(pbyZerosLoc - abyAddrLocal); //how much before zero compression int nTail = nIdx * 2 - (int)(pbyZerosLoc - abyAddrLocal); //how much after zero compression int nZeros = 16 - nTail - nHead; //how much zeros memmove(&abyAddrLocal[16 - nTail], pbyZerosLoc, nTail); //scootch stuff down memset(pbyZerosLoc, 0, nZeros); //clear the compressed zeros } //validation of ipv4 subspace ::ffff:x.x if (bIPv4Detected) { static const unsigned char abyPfx[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff}; if (0 != memcmp(abyAddrLocal, abyPfx, sizeof(abyPfx))) return 0; } //close bracket if (NULL != pchOpenBracket) { if (']' != **ppszText) return 0; ++(*ppszText); } if (':' == **ppszText && NULL != pnPort) //have port part, and we want it { const char *pszTextBefore; unsigned int nVal; unsigned short usPortNetwork; //save value in network order ++(*ppszText); //past the colon pszTextBefore = *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if (nVal > 65535 || pszTextBefore == *ppszText) return 0; ((unsigned char *)&usPortNetwork)[0] = (nVal & 0xff00) >> 8; ((unsigned char *)&usPortNetwork)[1] = (nVal & 0xff); *pnPort = usPortNetwork; return 1; } else //finished just with ip address { if (NULL != pnPort) *pnPort = 0; //indicate we have no port part return 1; } } }", "after": "pub unsafe extern \"C\" fn ParseIPv4OrIPv6( mut ppszText: *mut *const libc::c_char, mut abyAddr: *mut libc::c_uchar, mut pnPort: *mut libc::c_int, mut pbIsIPv6: *mut libc::c_int, ) -> libc::c_int { let mut abyAddrLocal: *mut libc::c_uchar = 0 as *mut libc::c_uchar; let mut abyDummyAddr: [libc::c_uchar; 16] = [0; 16]; let mut pchColon: *const libc::c_char = strchr(*ppszText, ':' as i32); let mut pchDot: *const libc::c_char = strchr(*ppszText, '.' as i32); let mut pchOpenBracket: *const libc::c_char = strchr(*ppszText, '[' as i32); let mut pchCloseBracket: *const libc::c_char = 0 as *const libc::c_char; let mut bIsIPv6local: libc::c_int = (!pchOpenBracket.is_null() || pchDot.is_null() || !pchColon.is_null() && (pchDot.is_null() || pchColon < pchDot)) as libc::c_int; if bIsIPv6local != 0 { pchCloseBracket = strchr(*ppszText, ']' as i32); if !pchOpenBracket.is_null() && (pchCloseBracket.is_null() || pchCloseBracket < pchOpenBracket) { return 0 as libc::c_int; } } else if pchDot.is_null() || !pchColon.is_null() && pchColon < pchDot { return 0 as libc::c_int } if !pbIsIPv6.is_null() { *pbIsIPv6 = bIsIPv6local; } abyAddrLocal = abyAddr; if abyAddrLocal.is_null() { abyAddrLocal = abyDummyAddr.as_mut_ptr(); } if bIsIPv6local == 0 { let mut pbyAddrCursor: *mut libc::c_uchar = abyAddrLocal; let mut nVal: libc::c_uint = 0; let mut pszTextBefore: *const libc::c_char = *ppszText; nVal = _parseDecimal(ppszText); if '.' as i32 != **ppszText as libc::c_int || nVal > 255 as libc::c_int as libc::c_uint || pszTextBefore == *ppszText { return 0 as libc::c_int; } let fresh0 = pbyAddrCursor; pbyAddrCursor = pbyAddrCursor.offset(1); *fresh0 = nVal as libc::c_uchar; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if '.' as i32 != **ppszText as libc::c_int || nVal > 255 as libc::c_int as libc::c_uint || pszTextBefore == *ppszText { return 0 as libc::c_int; } let fresh1 = pbyAddrCursor; pbyAddrCursor = pbyAddrCursor.offset(1); *fresh1 = nVal as libc::c_uchar; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if '.' as i32 != **ppszText as libc::c_int || nVal > 255 as libc::c_int as libc::c_uint || pszTextBefore == *ppszText { return 0 as libc::c_int; } let fresh2 = pbyAddrCursor; pbyAddrCursor = pbyAddrCursor.offset(1); *fresh2 = nVal as libc::c_uchar; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if nVal > 255 as libc::c_int as libc::c_uint || pszTextBefore == *ppszText { return 0 as libc::c_int; } let fresh3 = pbyAddrCursor; pbyAddrCursor = pbyAddrCursor.offset(1); *fresh3 = nVal as libc::c_uchar; if ':' as i32 == **ppszText as libc::c_int && !pnPort.is_null() { let mut usPortNetwork: libc::c_ushort = 0; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore = *ppszText; nVal = _parseDecimal(ppszText); if nVal > 65535 as libc::c_int as libc::c_uint || pszTextBefore == *ppszText { return 0 as libc::c_int; } *(&mut usPortNetwork as *mut libc::c_ushort as *mut libc::c_uchar) .offset( 0 as libc::c_int as isize, ) = ((nVal & 0xff00 as libc::c_int as libc::c_uint) >> 8 as libc::c_int) as libc::c_uchar; *(&mut usPortNetwork as *mut libc::c_ushort as *mut libc::c_uchar) .offset( 1 as libc::c_int as isize, ) = (nVal & 0xff as libc::c_int as libc::c_uint) as libc::c_uchar; *pnPort = usPortNetwork as libc::c_int; return 1 as libc::c_int; } else { if !pnPort.is_null() { *pnPort = 0 as libc::c_int; } return 1 as libc::c_int; } } else { let mut pbyAddrCursor_0: *mut libc::c_uchar = 0 as *mut libc::c_uchar; let mut pbyZerosLoc: *mut libc::c_uchar = 0 as *mut libc::c_uchar; let mut bIPv4Detected: libc::c_int = 0; let mut nIdx: libc::c_int = 0; if !pchOpenBracket.is_null() { *ppszText = pchOpenBracket.offset(1 as libc::c_int as isize); } pbyAddrCursor_0 = abyAddrLocal; pbyZerosLoc = 0 as *mut libc::c_uchar; bIPv4Detected = 0 as libc::c_int; nIdx = 0 as libc::c_int; while nIdx < 8 as libc::c_int { let mut pszTextBefore_0: *const libc::c_char = *ppszText; let mut nVal_0: libc::c_uint = _parseHex(ppszText); if pszTextBefore_0 == *ppszText { if !pbyZerosLoc.is_null() { if pbyZerosLoc == pbyAddrCursor_0 { nIdx -= 1; nIdx; break; } else { return 0 as libc::c_int } } else { if ':' as i32 != **ppszText as libc::c_int { return 0 as libc::c_int; } if 0 as libc::c_int == nIdx { *ppszText = (*ppszText).offset(1); *ppszText; if ':' as i32 != **ppszText as libc::c_int { return 0 as libc::c_int; } } pbyZerosLoc = pbyAddrCursor_0; *ppszText = (*ppszText).offset(1); *ppszText; } } else if '.' as i32 == **ppszText as libc::c_int { let mut pszTextlocal: *const libc::c_char = pszTextBefore_0; let mut abyAddrlocal: [libc::c_uchar; 16] = [0; 16]; let mut bIsIPv6local_0: libc::c_int = 0; let mut bParseResultlocal: libc::c_int = ParseIPv4OrIPv6( &mut pszTextlocal, abyAddrlocal.as_mut_ptr(), 0 as *mut libc::c_int, &mut bIsIPv6local_0, ); *ppszText = pszTextlocal; if bParseResultlocal == 0 || bIsIPv6local_0 != 0 { return 0 as libc::c_int; } let fresh4 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh4 = abyAddrlocal[0 as libc::c_int as usize]; let fresh5 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh5 = abyAddrlocal[1 as libc::c_int as usize]; let fresh6 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh6 = abyAddrlocal[2 as libc::c_int as usize]; let fresh7 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh7 = abyAddrlocal[3 as libc::c_int as usize]; nIdx += 1; nIdx; bIPv4Detected = 1 as libc::c_int; break; } else { if nVal_0 > 65535 as libc::c_int as libc::c_uint { return 0 as libc::c_int; } let fresh8 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh8 = (nVal_0 >> 8 as libc::c_int) as libc::c_uchar; let fresh9 = pbyAddrCursor_0; pbyAddrCursor_0 = pbyAddrCursor_0.offset(1); *fresh9 = (nVal_0 & 0xff as libc::c_int as libc::c_uint) as libc::c_uchar; if !(':' as i32 == **ppszText as libc::c_int) { break; } *ppszText = (*ppszText).offset(1); *ppszText; } nIdx += 1; nIdx; } if !pbyZerosLoc.is_null() { let mut nHead: libc::c_int = pbyZerosLoc.offset_from(abyAddrLocal) as libc::c_long as libc::c_int; let mut nTail: libc::c_int = nIdx * 2 as libc::c_int - pbyZerosLoc.offset_from(abyAddrLocal) as libc::c_long as libc::c_int; let mut nZeros: libc::c_int = 16 as libc::c_int - nTail - nHead; memmove( &mut *abyAddrLocal.offset((16 as libc::c_int - nTail) as isize) as *mut libc::c_uchar as *mut libc::c_void, pbyZerosLoc as *const libc::c_void, nTail as libc::c_ulong, ); memset( pbyZerosLoc as *mut libc::c_void, 0 as libc::c_int, nZeros as libc::c_ulong, ); } if bIPv4Detected != 0 { static mut abyPfx: [libc::c_uchar; 12] = [ 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 0xff as libc::c_int as libc::c_uchar, 0xff as libc::c_int as libc::c_uchar, ]; if 0 as libc::c_int != memcmp( abyAddrLocal as *const libc::c_void, abyPfx.as_ptr() as *const libc::c_void, ::core::mem::size_of::<[libc::c_uchar; 12]>() as libc::c_ulong, ) { return 0 as libc::c_int; } } if !pchOpenBracket.is_null() { if ']' as i32 != **ppszText as libc::c_int { return 0 as libc::c_int; } *ppszText = (*ppszText).offset(1); *ppszText; } if ':' as i32 == **ppszText as libc::c_int && !pnPort.is_null() { let mut pszTextBefore_1: *const libc::c_char = 0 as *const libc::c_char; let mut nVal_1: libc::c_uint = 0; let mut usPortNetwork_0: libc::c_ushort = 0; *ppszText = (*ppszText).offset(1); *ppszText; pszTextBefore_1 = *ppszText; pszTextBefore_1 = *ppszText; nVal_1 = _parseDecimal(ppszText); if nVal_1 > 65535 as libc::c_int as libc::c_uint || pszTextBefore_1 == *ppszText { return 0 as libc::c_int; } *(&mut usPortNetwork_0 as *mut libc::c_ushort as *mut libc::c_uchar) .offset( 0 as libc::c_int as isize, ) = ((nVal_1 & 0xff00 as libc::c_int as libc::c_uint) >> 8 as libc::c_int) as libc::c_uchar; *(&mut usPortNetwork_0 as *mut libc::c_ushort as *mut libc::c_uchar) .offset( 1 as libc::c_int as isize, ) = (nVal_1 & 0xff as libc::c_int as libc::c_uint) as libc::c_uchar; *pnPort = usPortNetwork_0 as libc::c_int; return 1 as libc::c_int; } else { if !pnPort.is_null() { *pnPort = 0 as libc::c_int; } return 1 as libc::c_int; } }; }" }, { "index": 854, "before": "void testcase(const char *pszTest) { unsigned char abyAddr[16]; int bIsIPv6; int nPort; int bSuccess; printf(\"Test case '%s'\\n\", pszTest); const char *pszTextCursor = pszTest; bSuccess = ParseIPv4OrIPv6(&pszTextCursor, abyAddr, &nPort, &bIsIPv6); if (!bSuccess) { printf(\"parse failed, at about index %d; rest: '%s'\\n\", pszTextCursor - pszTest, pszTextCursor); return; } printf(\"addr: \"); dumpbin(abyAddr, bIsIPv6 ? 16 : 4); printf(\"\\n\"); if (0 == nPort) printf(\"port absent\"); else printf(\"port: %d\", htons(nPort)); printf(\"\\n\\n\"); }", "after": "pub unsafe extern \"C\" fn testcase(mut pszTest: *const libc::c_char) { let mut abyAddr: [libc::c_uchar; 16] = [0; 16]; let mut bIsIPv6: libc::c_int = 0; let mut nPort: libc::c_int = 0; let mut bSuccess: libc::c_int = 0; printf(b\"Test case '%s'\\n\\0\" as *const u8 as *const libc::c_char, pszTest); let mut pszTextCursor: *const libc::c_char = pszTest; bSuccess = ParseIPv4OrIPv6( &mut pszTextCursor, abyAddr.as_mut_ptr(), &mut nPort, &mut bIsIPv6, ); if bSuccess == 0 { printf( b\"parse failed, at about index %d; rest: '%s'\\n\\0\" as *const u8 as *const libc::c_char, pszTextCursor.offset_from(pszTest) as libc::c_long, pszTextCursor, ); return; } printf(b\"addr: \\0\" as *const u8 as *const libc::c_char); dumpbin( abyAddr.as_mut_ptr(), if bIsIPv6 != 0 { 16 as libc::c_int } else { 4 as libc::c_int }, ); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); if 0 as libc::c_int == nPort { printf(b\"port absent\\0\" as *const u8 as *const libc::c_char); } else { printf( b\"port: %d\\0\" as *const u8 as *const libc::c_char, htons(nPort as libc::c_ushort) as libc::c_int, ); } printf(b\"\\n\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 855, "before": "static unsigned int _parseDecimal(const char **pchCursor) { unsigned int nVal = 0; char chNow; while (chNow = **pchCursor, chNow >= '0' && chNow <= '9') { //shift digit in nVal *= 10; nVal += chNow - '0'; ++*pchCursor; } return nVal; }", "after": "unsafe extern \"C\" fn _parseDecimal( mut pchCursor: *mut *const libc::c_char, ) -> libc::c_uint { let mut nVal: libc::c_uint = 0 as libc::c_int as libc::c_uint; let mut chNow: libc::c_char = 0; loop { chNow = **pchCursor; if !(chNow as libc::c_int >= '0' as i32 && chNow as libc::c_int <= '9' as i32) { break; } nVal = nVal.wrapping_mul(10 as libc::c_int as libc::c_uint); nVal = nVal.wrapping_add((chNow as libc::c_int - '0' as i32) as libc::c_uint); *pchCursor = (*pchCursor).offset(1); *pchCursor; } return nVal; }" }, { "index": 856, "before": "int main(int argc, char *argv[]) { //The \"localhost\" IPv4 address testcase(\"127.0.0.1\"); //The \"localhost\" IPv4 address, with a specified port (80) testcase(\"127.0.0.1:80\"); //The \"localhost\" IPv6 address testcase(\"::1\"); //The \"localhost\" IPv6 address, with a specified port (80) testcase(\"[::1]:80\"); //Rosetta Code's primary server's public IPv6 address testcase(\"2605:2700:0:3::4713:93e3\"); //Rosetta Code's primary server's public IPv6 address, with a specified port (80) testcase(\"[2605:2700:0:3::4713:93e3]:80\"); //ipv4 space testcase(\"::ffff:192.168.173.22\"); //ipv4 space with port testcase(\"[::ffff:192.168.173.22]:80\"); //trailing compression testcase(\"1::\"); //trailing compression with port testcase(\"[1::]:80\"); //'any' address compression testcase(\"::\"); //'any' address compression with port testcase(\"[::]:80\"); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { testcase(b\"127.0.0.1\\0\" as *const u8 as *const libc::c_char); testcase(b\"127.0.0.1:80\\0\" as *const u8 as *const libc::c_char); testcase(b\"::1\\0\" as *const u8 as *const libc::c_char); testcase(b\"[::1]:80\\0\" as *const u8 as *const libc::c_char); testcase(b\"2605:2700:0:3::4713:93e3\\0\" as *const u8 as *const libc::c_char); testcase(b\"[2605:2700:0:3::4713:93e3]:80\\0\" as *const u8 as *const libc::c_char); testcase(b\"::ffff:192.168.173.22\\0\" as *const u8 as *const libc::c_char); testcase(b\"[::ffff:192.168.173.22]:80\\0\" as *const u8 as *const libc::c_char); testcase(b\"1::\\0\" as *const u8 as *const libc::c_char); testcase(b\"[1::]:80\\0\" as *const u8 as *const libc::c_char); testcase(b\"::\\0\" as *const u8 as *const libc::c_char); testcase(b\"[::]:80\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 857, "before": "unsigned short htons(unsigned short us) { return (((unsigned char *)&us)[0] << 8) + ((unsigned char *)&us)[1]; }", "after": "pub unsafe extern \"C\" fn htons(mut us: libc::c_ushort) -> libc::c_ushort { return (((*(&mut us as *mut libc::c_ushort as *mut libc::c_uchar) .offset(0 as libc::c_int as isize) as libc::c_int) << 8 as libc::c_int) + *(&mut us as *mut libc::c_ushort as *mut libc::c_uchar) .offset(1 as libc::c_int as isize) as libc::c_int) as libc::c_ushort; }" }, { "index": 858, "before": "static unsigned int _parseHex(const char **pchCursor) { unsigned int nVal = 0; char chNow; while (chNow = **pchCursor & 0x5f, //(collapses case, but mutilates digits) (chNow >= ('0' & 0x5f) && chNow <= ('9' & 0x5f)) || (chNow >= 'A' && chNow <= 'F')) { unsigned char nybbleValue; chNow -= 0x10; //scootch digital values down; hex now offset by x31 nybbleValue = (chNow > 9 ? chNow - (0x31 - 0x0a) : chNow); //shift nybble in nVal <<= 4; nVal += nybbleValue; ++*pchCursor; } return nVal; }", "after": "unsafe extern \"C\" fn _parseHex(mut pchCursor: *mut *const libc::c_char) -> libc::c_uint { let mut nVal: libc::c_uint = 0 as libc::c_int as libc::c_uint; let mut chNow: libc::c_char = 0; loop { chNow = (**pchCursor as libc::c_int & 0x5f as libc::c_int) as libc::c_char; if !(chNow as libc::c_int >= '0' as i32 & 0x5f as libc::c_int && chNow as libc::c_int <= '9' as i32 & 0x5f as libc::c_int || chNow as libc::c_int >= 'A' as i32 && chNow as libc::c_int <= 'F' as i32) { break; } let mut nybbleValue: libc::c_uchar = 0; chNow = (chNow as libc::c_int - 0x10 as libc::c_int) as libc::c_char; nybbleValue = (if chNow as libc::c_int > 9 as libc::c_int { chNow as libc::c_int - (0x31 as libc::c_int - 0xa as libc::c_int) } else { chNow as libc::c_int }) as libc::c_uchar; nVal <<= 4 as libc::c_int; nVal = nVal.wrapping_add(nybbleValue as libc::c_uint); *pchCursor = (*pchCursor).offset(1); *pchCursor; } return nVal; }" }, { "index": 859, "before": "int ParseIPv4OrIPv6_2(const char *pszText, unsigned char *abyAddr, int *pnPort, int *pbIsIPv6) { const char *pszTextLocal = pszText; return ParseIPv4OrIPv6(&pszTextLocal, abyAddr, pnPort, pbIsIPv6); }", "after": "pub unsafe extern \"C\" fn ParseIPv4OrIPv6_2( mut pszText: *const libc::c_char, mut abyAddr: *mut libc::c_uchar, mut pnPort: *mut libc::c_int, mut pbIsIPv6: *mut libc::c_int, ) -> libc::c_int { let mut pszTextLocal: *const libc::c_char = pszText; return ParseIPv4OrIPv6(&mut pszTextLocal, abyAddr, pnPort, pbIsIPv6); }" }, { "index": 860, "before": "void dumpbin(unsigned char *pbyBin, int nLen) { int i; for (i = 0; i < nLen; ++i) { printf(\"%02x\", pbyBin[i]); } }", "after": "pub unsafe extern \"C\" fn dumpbin(mut pbyBin: *mut libc::c_uchar, mut nLen: libc::c_int) { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < nLen { printf( b\"%02x\\0\" as *const u8 as *const libc::c_char, *pbyBin.offset(i as isize) as libc::c_int, ); i += 1; i; } }" }, { "index": 861, "before": "int main(int argc, char *argv[]) { repeat(example, 4); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { repeat( ::core::mem::transmute::< Option:: ()>, Option:: ()>, >( Some( ::core::mem::transmute::< unsafe extern \"C\" fn() -> (), unsafe extern \"C\" fn() -> (), >(example), ), ), 4 as libc::c_int as libc::c_uint, ); return 0 as libc::c_int; }" }, { "index": 862, "before": "void example() { printf(\"Example\\n\"); }", "after": "pub unsafe extern \"C\" fn example() { printf(b\"Example\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 863, "before": "void repeat(void (*f)(void), unsigned int n) { while (n-->0) (*f)(); //or just f() }", "after": "pub unsafe extern \"C\" fn repeat( mut f: Option:: ()>, mut n: libc::c_uint, ) { loop { let fresh0 = n; n = n.wrapping_sub(1); if !(fresh0 > 0 as libc::c_int as libc::c_uint) { break; } (Some(f.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")(); }; }" }, { "index": 864, "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": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut d: int64_t = 0; let mut n: int64_t = 0; let mut f: libc::c_double = 0.; f = 1.0f64 / 7 as libc::c_int as libc::c_double; printf(b\"f = %16.14f\\n\\0\" as *const u8 as *const libc::c_char, f); i = 1 as libc::c_int; while i <= 20000000 as libc::c_int { printf(b\"denom <= %d: \\0\" as *const u8 as *const libc::c_char, i); rat_approx(f, i as int64_t, &mut n, &mut d); printf(b\"%lld/%lld\\n\\0\" as *const u8 as *const libc::c_char, n, d); i *= 16 as libc::c_int; } f = atan2(1 as libc::c_int as libc::c_double, 1 as libc::c_int as libc::c_double) * 4 as libc::c_int as libc::c_double; printf(b\"\\nf = %16.14f\\n\\0\" as *const u8 as *const libc::c_char, f); i = 1 as libc::c_int; while i <= 20000000 as libc::c_int { printf(b\"denom <= %d: \\0\" as *const u8 as *const libc::c_char, i); rat_approx(f, i as int64_t, &mut n, &mut d); printf(b\"%lld/%lld\\n\\0\" as *const u8 as *const libc::c_char, n, d); i *= 16 as libc::c_int; } return 0 as libc::c_int; }" }, { "index": 865, "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 unsafe extern \"C\" fn rat_approx( mut f: libc::c_double, mut md: int64_t, mut num: *mut int64_t, mut denom: *mut int64_t, ) { let mut a: int64_t = 0; let mut h: [int64_t; 3] = [ 0 as libc::c_int as int64_t, 1 as libc::c_int as int64_t, 0 as libc::c_int as int64_t, ]; let mut k: [int64_t; 3] = [ 1 as libc::c_int as int64_t, 0 as libc::c_int as int64_t, 0 as libc::c_int as int64_t, ]; let mut x: int64_t = 0; let mut d: int64_t = 0; let mut n: int64_t = 1 as libc::c_int as int64_t; let mut i: libc::c_int = 0; let mut neg: libc::c_int = 0 as libc::c_int; if md <= 1 as libc::c_int as libc::c_long { *denom = 1 as libc::c_int as int64_t; *num = f as int64_t; return; } if f < 0 as libc::c_int as libc::c_double { neg = 1 as libc::c_int; f = -f; } while f != floor(f) { n <<= 1 as libc::c_int; f *= 2 as libc::c_int as libc::c_double; } d = f as int64_t; i = 0 as libc::c_int; while i < 64 as libc::c_int { a = if n != 0 { d / n } else { 0 as libc::c_int as libc::c_long }; if i != 0 && a == 0 { break; } x = d; d = n; n = x % n; x = a; if k[1 as libc::c_int as usize] * a + k[0 as libc::c_int as usize] >= md { x = (md - k[0 as libc::c_int as usize]) / k[1 as libc::c_int as usize]; if !(x * 2 as libc::c_int as libc::c_long >= a || k[1 as libc::c_int as usize] >= md) { break; } i = 65 as libc::c_int; } h[2 as libc::c_int as usize] = x * h[1 as libc::c_int as usize] + h[0 as libc::c_int as usize]; h[0 as libc::c_int as usize] = h[1 as libc::c_int as usize]; h[1 as libc::c_int as usize] = h[2 as libc::c_int as usize]; k[2 as libc::c_int as usize] = x * k[1 as libc::c_int as usize] + k[0 as libc::c_int as usize]; k[0 as libc::c_int as usize] = k[1 as libc::c_int as usize]; k[1 as libc::c_int as usize] = k[2 as libc::c_int as usize]; i += 1; i; } *denom = k[1 as libc::c_int as usize]; *num = if neg != 0 { -h[1 as libc::c_int as usize] } else { h[1 as libc::c_int as usize] }; }" }, { "index": 866, "before": "int cmp_dbl(const void *a, const void *b) { \tdouble x = *(const double*)a - *(const double*)b; \treturn x < 0 ? -1 : x > 0; }", "after": "pub unsafe extern \"C\" fn cmp_dbl( mut a: *const libc::c_void, mut b: *const libc::c_void, ) -> libc::c_int { let mut x: libc::c_double = *(a as *const libc::c_double) - *(b as *const libc::c_double); return if x < 0 as libc::c_int as libc::c_double { -(1 as libc::c_int) } else { (x > 0 as libc::c_int as libc::c_double) as libc::c_int }; }" }, { "index": 867, "before": "int vc_cmp(const void *a, const void *b) { \treturn ((const vcount*)b)->c - ((const vcount*)a)->c; }", "after": "pub unsafe extern \"C\" fn vc_cmp( mut a: *const libc::c_void, mut b: *const libc::c_void, ) -> libc::c_int { return (*(b as *const vcount)).c - (*(a as *const vcount)).c; }" }, { "index": 868, "before": "int main() { \tdouble values[] = { 1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 12, 12, 17 }; #\tdefine len sizeof(values)/sizeof(double) \tvcount *vc; \tint i, n_modes = get_mode(values, len, &vc); \tprintf(\"got %d modes:\\n\", n_modes); \tfor (i = 0; i < n_modes; i++) \t\tprintf(\"\\tvalue = %g, count = %d\\n\", vc[i].v, vc[i].c); \tfree(vc); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut values: [libc::c_double; 13] = [ 1 as libc::c_int as libc::c_double, 3 as libc::c_int as libc::c_double, 6 as libc::c_int as libc::c_double, 6 as libc::c_int as libc::c_double, 6 as libc::c_int as libc::c_double, 6 as libc::c_int as libc::c_double, 7 as libc::c_int as libc::c_double, 7 as libc::c_int as libc::c_double, 12 as libc::c_int as libc::c_double, 12 as libc::c_int as libc::c_double, 12 as libc::c_int as libc::c_double, 12 as libc::c_int as libc::c_double, 17 as libc::c_int as libc::c_double, ]; let mut vc: *mut vcount = 0 as *mut vcount; let mut i: libc::c_int = 0; let mut n_modes: libc::c_int = get_mode( values.as_mut_ptr(), (::core::mem::size_of::<[libc::c_double; 13]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, &mut vc, ); printf(b\"got %d modes:\\n\\0\" as *const u8 as *const libc::c_char, n_modes); i = 0 as libc::c_int; while i < n_modes { printf( b\"\\tvalue = %g, count = %d\\n\\0\" as *const u8 as *const libc::c_char, (*vc.offset(i as isize)).v, (*vc.offset(i as isize)).c, ); i += 1; i; } free(vc as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 869, "before": "int get_mode(double* x, int len, vcount **list) { \tint i, j; \tvcount *vc; \t/* sort values */ \tqsort(x, len, sizeof(double), cmp_dbl); \t/* count occurence of each value */ \tfor (i = 0, j = 1; i < len - 1; i++, j += (x[i] != x[i + 1])); \t*list = vc = malloc(sizeof(vcount) * j); \tvc[0].v = x[0]; \tvc[0].c = 1; \t/* generate list value-count pairs */ \tfor (i = j = 0; i < len - 1; i++, vc[j].c++) \t\tif (x[i] != x[i + 1]) vc[++j].v = x[i + 1]; \t/* sort that by count in descending order */ \tqsort(vc, j + 1, sizeof(vcount), vc_cmp); \t/* the number of entries with same count as the highest */ \tfor (i = 0; i <= j && vc[i].c == vc[0].c; i++); \treturn i; }", "after": "pub unsafe extern \"C\" fn get_mode( mut x: *mut libc::c_double, mut len_0: libc::c_int, mut list: *mut *mut vcount, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut vc: *mut vcount = 0 as *mut vcount; qsort( x as *mut libc::c_void, len_0 as size_t, ::core::mem::size_of::() as libc::c_ulong, Some( cmp_dbl as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); i = 0 as libc::c_int; j = 1 as libc::c_int; while i < len_0 - 1 as libc::c_int { i += 1; i; j += (*x.offset(i as isize) != *x.offset((i + 1 as libc::c_int) as isize)) as libc::c_int; } vc = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(j as libc::c_ulong), ) as *mut vcount; *list = vc; (*vc.offset(0 as libc::c_int as isize)).v = *x.offset(0 as libc::c_int as isize); (*vc.offset(0 as libc::c_int as isize)).c = 1 as libc::c_int; j = 0 as libc::c_int; i = j; while i < len_0 - 1 as libc::c_int { if *x.offset(i as isize) != *x.offset((i + 1 as libc::c_int) as isize) { j += 1; (*vc.offset(j as isize)).v = *x.offset((i + 1 as libc::c_int) as isize); } i += 1; i; let ref mut fresh0 = (*vc.offset(j as isize)).c; *fresh0 += 1; *fresh0; } qsort( vc as *mut libc::c_void, (j + 1 as libc::c_int) as size_t, ::core::mem::size_of::() as libc::c_ulong, Some( vc_cmp as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); i = 0 as libc::c_int; while i <= j && (*vc.offset(i as isize)).c == (*vc.offset(0 as libc::c_int as isize)).c { i += 1; i; } return i; }" }, { "index": 870, "before": "double pi(double tolerance) { \tdouble x, y, val, error; \tunsigned long sampled = 0, hit = 0, i; \tdo { \t\t/* don't check error every turn, make loop tight */ \t\tfor (i = 1000000; i; i--, sampled++) { \t\t\tx = rand() / (RAND_MAX + 1.0); \t\t\ty = rand() / (RAND_MAX + 1.0); \t\t\tif (x * x + y * y < 1) hit ++; \t\t} \t\tval = (double) hit / sampled; \t\terror = sqrt(val * (1 - val) / sampled) * 4; \t\tval *= 4; \t\t/* some feedback, or user gets bored */ \t\tfprintf(stderr, \"Pi = %f +/- %5.3e at %ldM samples.\\r\", \t\t\tval, error, sampled/1000000); \t} while (!hit || error > tolerance); /* !hit is for completeness's sake; if no hit after 1M samples, your rand() is BROKEN */ \treturn val; }", "after": "pub unsafe extern \"C\" fn pi(mut tolerance: libc::c_double) -> libc::c_double { let mut x: libc::c_double = 0.; let mut y: libc::c_double = 0.; let mut val: libc::c_double = 0.; let mut error: libc::c_double = 0.; let mut sampled: libc::c_ulong = 0 as libc::c_int as libc::c_ulong; let mut hit: libc::c_ulong = 0 as libc::c_int as libc::c_ulong; let mut i: libc::c_ulong = 0; loop { i = 1000000 as libc::c_int as libc::c_ulong; while i != 0 { x = rand() as libc::c_double / (2147483647 as libc::c_int as libc::c_double + 1.0f64); y = rand() as libc::c_double / (2147483647 as libc::c_int as libc::c_double + 1.0f64); if x * x + y * y < 1 as libc::c_int as libc::c_double { hit = hit.wrapping_add(1); hit; } i = i.wrapping_sub(1); i; sampled = sampled.wrapping_add(1); sampled; } val = hit as libc::c_double / sampled as libc::c_double; error = sqrt( val * (1 as libc::c_int as libc::c_double - val) / sampled as libc::c_double, ) * 4 as libc::c_int as libc::c_double; val *= 4 as libc::c_int as libc::c_double; fprintf( stderr, b\"Pi = %f +/- %5.3e at %ldM samples.\\r\\0\" as *const u8 as *const libc::c_char, val, error, sampled.wrapping_div(1000000 as libc::c_int as libc::c_ulong), ); if !(hit == 0 || error > tolerance) { break; } } return val; }" }, { "index": 871, "before": "int main() { \tprintf(\"Pi is %f\\n\", pi(3e-4)); /* set to 1e-4 for some fun */ \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { printf(b\"Pi is %f\\n\\0\" as *const u8 as *const libc::c_char, pi(3e-4f64)); return 0 as libc::c_int; }" }, { "index": 872, "before": "sma_result_t sma(enum Action action, ...) { va_list vl; sma_result_t r; sma_obj_t *o; double v; va_start(vl, action); switch(action) { case SMA_NEW: // args: int period r.handle = malloc(sizeof(sma_obj_t)); r.handle->sma = 0.0; r.handle->period = va_arg(vl, int); r.handle->values = malloc(r.handle->period * sizeof(double)); r.handle->lv = 0; r.handle->sum = 0.0; break; case SMA_FREE: // args: sma_obj_t *handle r.handle = va_arg(vl, sma_obj_t *); free(r.handle->values); free(r.handle); r.handle = NULL; break; case SMA_VALUES: // args: sma_obj_t *handle o = va_arg(vl, sma_obj_t *); r.values = o->values; break; case SMA_MEAN: // args: sma_obj_t *handle o = va_arg(vl, sma_obj_t *); r.sma = o->sma; break; case SMA_ADD: // args: sma_obj_t *handle, double value o = va_arg(vl, sma_obj_t *); v = va_arg(vl, double); if ( o->lv < o->period ) { o->values[o->lv++] = v; o->sum += v; o->sma = o->sum / o->lv; } else { o->sum -= o->values[ o->lv % o->period]; o->sum += v; o->sma = o->sum / o->period; o->values[ o->lv % o->period ] = v; o->lv++; } r.sma = o->sma; break; } va_end(vl); return r; }", "after": "pub unsafe extern \"C\" fn sma(mut action: Action, mut args: ...) -> sma_result_t { let mut vl: ::core::ffi::VaListImpl; let mut r: sma_result_t = sma_result { handle: 0 as *mut sma_obj_t, }; let mut o: *mut sma_obj_t = 0 as *mut sma_obj_t; let mut v_0: libc::c_double = 0.; vl = args.clone(); match action as libc::c_uint { 0 => { r .handle = malloc(::core::mem::size_of::() as libc::c_ulong) as *mut sma_obj_t; (*r.handle).sma = 0.0f64; (*r.handle).period = vl.arg::(); (*r.handle) .values = malloc( ((*r.handle).period as libc::c_ulong) .wrapping_mul( ::core::mem::size_of::() as libc::c_ulong, ), ) as *mut libc::c_double; (*r.handle).lv = 0 as libc::c_int; (*r.handle).sum = 0.0f64; } 1 => { r.handle = vl.arg::<*mut sma_obj_t>(); free((*r.handle).values as *mut libc::c_void); free(r.handle as *mut libc::c_void); r.handle = 0 as *mut sma_obj_t; } 2 => { o = vl.arg::<*mut sma_obj_t>(); r.values = (*o).values; } 4 => { o = vl.arg::<*mut sma_obj_t>(); r.sma = (*o).sma; } 3 => { o = vl.arg::<*mut sma_obj_t>(); v_0 = vl.arg::(); if (*o).lv < (*o).period { let fresh0 = (*o).lv; (*o).lv = (*o).lv + 1; *((*o).values).offset(fresh0 as isize) = v_0; (*o).sum += v_0; (*o).sma = (*o).sum / (*o).lv as libc::c_double; } else { (*o).sum -= *((*o).values).offset(((*o).lv % (*o).period) as isize); (*o).sum += v_0; (*o).sma = (*o).sum / (*o).period as libc::c_double; *((*o).values).offset(((*o).lv % (*o).period) as isize) = v_0; (*o).lv += 1; (*o).lv; } r.sma = (*o).sma; } _ => {} } return r; }" }, { "index": 873, "before": "int main() { int i; sma_obj_t *h3 = sma(SMA_NEW, 3).handle; sma_obj_t *h5 = sma(SMA_NEW, 5).handle; for(i=0; i < sizeof(v)/sizeof(double) ; i++) { printf(\"next number %lf, SMA_3 = %lf, SMA_5 = %lf\\n\", \t v[i], sma(SMA_ADD, h3, v[i]).sma, sma(SMA_ADD, h5, v[i]).sma); } sma(SMA_FREE, h3); sma(SMA_FREE, h5); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut h3: *mut sma_obj_t = (sma(SMA_NEW, 3 as libc::c_int)).handle; let mut h5: *mut sma_obj_t = (sma(SMA_NEW, 5 as libc::c_int)).handle; i = 0 as libc::c_int; while (i as libc::c_ulong) < (::core::mem::size_of::<[libc::c_double; 10]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) { printf( b\"next number %lf, SMA_3 = %lf, SMA_5 = %lf\\n\\0\" as *const u8 as *const libc::c_char, v[i as usize], (sma(SMA_ADD, h3, v[i as usize])).sma, (sma(SMA_ADD, h5, v[i as usize])).sma, ); i += 1; i; } sma(SMA_FREE, h3); sma(SMA_FREE, h5); return 0 as libc::c_int; }" }, { "index": 874, "before": "double mapRange(double a1,double a2,double b1,double b2,double s) { \treturn b1 + (s-a1)*(b2-b1)/(a2-a1); }", "after": "pub unsafe extern \"C\" fn mapRange( mut a1: libc::c_double, mut a2: libc::c_double, mut b1: libc::c_double, mut b2: libc::c_double, mut s: libc::c_double, ) -> libc::c_double { return b1 + (s - a1) * (b2 - b1) / (a2 - a1); }" }, { "index": 875, "before": "int main() { \tint i; \tputs(\"Mapping [0,10] to [-1,0] at intervals of 1:\"); \tfor(i=0;i<=10;i++) \t{ \t\tprintf(\"f(%d) = %g\\n\",i,mapRange(0,10,-1,0,i)); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; puts( b\"Mapping [0,10] to [-1,0] at intervals of 1:\\0\" as *const u8 as *const libc::c_char, ); i = 0 as libc::c_int; while i <= 10 as libc::c_int { printf( b\"f(%d) = %g\\n\\0\" as *const u8 as *const libc::c_char, i, mapRange( 0 as libc::c_int as libc::c_double, 10 as libc::c_int as libc::c_double, -(1 as libc::c_int) as libc::c_double, 0 as libc::c_int as libc::c_double, i as libc::c_double, ), ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 876, "before": "int do_check_end_condition(void) { int ret = -1; for (int x = 0; x < 4; ++x) { for (int y = 0; y < 4; ++y) { if (values[game.grid[x][y]] == 2048) return 1; if (!game.grid[x][y] || ((x + 1 < 4) && (game.grid[x][y] == game.grid[x + 1][y])) || ((y + 1 < 4) && (game.grid[x][y] == game.grid[x][y + 1]))) ret = 0; } } return ret; }", "after": "pub unsafe extern \"C\" fn do_check_end_condition() -> libc::c_int { let mut ret: libc::c_int = -(1 as libc::c_int); let mut x: libc::c_int = 0 as libc::c_int; while x < 4 as libc::c_int { let mut y: libc::c_int = 0 as libc::c_int; while y < 4 as libc::c_int { if values[game.grid[x as usize][y as usize] as usize] == 2048 as libc::c_int as libc::c_long { return 1 as libc::c_int; } if game.grid[x as usize][y as usize] == 0 || (x + 1 as libc::c_int) < 4 as libc::c_int && game.grid[x as usize][y as usize] == game.grid[(x + 1 as libc::c_int) as usize][y as usize] || (y + 1 as libc::c_int) < 4 as libc::c_int && game.grid[x as usize][y as usize] == game.grid[x as usize][(y + 1 as libc::c_int) as usize] { ret = 0 as libc::c_int; } y += 1; y; } x += 1; x; } return ret; }" }, { "index": 877, "before": "void do_draw(void) { printf(\"\\033[2J\\033[HScore: %ld\", game.total_score); if (game.score_last_move) printf(\" (+%ld)\", game.score_last_move); printf(\"\\n\"); for (int i = 0; i < 25; ++i) printf(\"-\"); printf(\"\\n\"); for (int y = 0; y < 4; ++y) { printf(\"|\"); for (int x = 0; x < 4; ++x) { if (game.grid[x][y]) printf(\"\\033[7m\\033[%sm%*zd \\033[0m|\", colors[game.grid[x][y]], 4, values[game.grid[x][y]]); else printf(\"%*s |\", 4, \"\"); } printf(\"\\n\"); } for (int i = 0; i < 25; ++i) { printf(\"-\"); } printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn do_draw() { printf( b\"\\x1B[2J\\x1B[HScore: %ld\\0\" as *const u8 as *const libc::c_char, game.total_score, ); if game.score_last_move != 0 { printf(b\" (+%ld)\\0\" as *const u8 as *const libc::c_char, game.score_last_move); } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); let mut i: libc::c_int = 0 as libc::c_int; while i < 25 as libc::c_int { printf(b\"-\\0\" as *const u8 as *const libc::c_char); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); let mut y: libc::c_int = 0 as libc::c_int; while y < 4 as libc::c_int { printf(b\"|\\0\" as *const u8 as *const libc::c_char); let mut x: libc::c_int = 0 as libc::c_int; while x < 4 as libc::c_int { if game.grid[x as usize][y as usize] != 0 { printf( b\"\\x1B[7m\\x1B[%sm%*zd \\x1B[0m|\\0\" as *const u8 as *const libc::c_char, colors[game.grid[x as usize][y as usize] as usize], 4 as libc::c_int, values[game.grid[x as usize][y as usize] as usize], ); } else { printf( b\"%*s |\\0\" as *const u8 as *const libc::c_char, 4 as libc::c_int, b\"\\0\" as *const u8 as *const libc::c_char, ); } x += 1; x; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); y += 1; y; } let mut i_0: libc::c_int = 0 as libc::c_int; while i_0 < 25 as libc::c_int { printf(b\"-\\0\" as *const u8 as *const libc::c_char); i_0 += 1; i_0; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 878, "before": "int main(void) { /* Initialize terminal settings */ tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); srand(time(NULL)); memset(&game, 0, sizeof(game)); do_newblock(); do_newblock(); do_draw(); while (1) { int found_valid_key, direction, value; do { found_valid_key = 1; direction = D_INVALID; value = getchar(); switch (value) { case 'h': case 'a': direction = D_LEFT; break; case 'l': case 'd': direction = D_RIGHT; break; case 'j': case 's': direction = D_DOWN; break; case 'k': case 'w': direction = D_UP; break; case 'q': goto game_quit; break; case 27: if (getchar() == 91) { value = getchar(); switch (value) { case 65: direction = D_UP; break; case 66: direction = D_DOWN; break; case 67: direction = D_RIGHT; break; case 68: direction = D_LEFT; break; default: found_valid_key = 0; break; } } break; default: found_valid_key = 0; break; } } while (!found_valid_key); do_tick(direction); if (game.have_moved != 0){ do_newblock(); } do_draw(); switch (do_check_end_condition()) { case -1: goto game_lose; case 1: goto game_win; case 0: break; } } if (0) game_lose: printf(\"You lose!\\n\"); goto game_quit; if (0) game_win: printf(\"You win!\\n\"); goto game_quit; if (0) game_quit: /* Restore terminal settings */ tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut current_block: u64; tcgetattr(0 as libc::c_int, &mut oldt); newt = oldt; newt.c_lflag &= !(0o2 as libc::c_int | 0o10 as libc::c_int) as libc::c_uint; tcsetattr(0 as libc::c_int, 0 as libc::c_int, &mut newt); srand(time(0 as *mut time_t) as libc::c_uint); memset( &mut game as *mut gamestate_struct__ as *mut libc::c_void, 0 as libc::c_int, ::core::mem::size_of::() as libc::c_ulong, ); do_newblock(); do_newblock(); do_draw(); 's_31: loop { let mut found_valid_key: libc::c_int = 0; let mut direction: libc::c_int = 0; let mut value: libc::c_int = 0; loop { found_valid_key = 1 as libc::c_int; direction = -(1 as libc::c_int); value = getchar(); match value { 104 | 97 => { direction = 4 as libc::c_int; } 108 | 100 => { direction = 3 as libc::c_int; } 106 | 115 => { direction = 2 as libc::c_int; } 107 | 119 => { direction = 1 as libc::c_int; } 113 => { current_block = 1947375109854664918; break 's_31; } 27 => { if getchar() == 91 as libc::c_int { value = getchar(); match value { 65 => { direction = 1 as libc::c_int; } 66 => { direction = 2 as libc::c_int; } 67 => { direction = 3 as libc::c_int; } 68 => { direction = 4 as libc::c_int; } _ => { found_valid_key = 0 as libc::c_int; } } } } _ => { found_valid_key = 0 as libc::c_int; } } if !(found_valid_key == 0) { break; } } do_tick(direction); if game.have_moved != 0 as libc::c_int { do_newblock(); } do_draw(); match do_check_end_condition() { -1 => { current_block = 267910298023665031; break; } 1 => { current_block = 340875295666714687; break; } 0 | _ => {} } } match current_block { 267910298023665031 => { printf(b\"You lose!\\n\\0\" as *const u8 as *const libc::c_char); } 340875295666714687 => { printf(b\"You win!\\n\\0\" as *const u8 as *const libc::c_char); } _ => {} } tcsetattr(0 as libc::c_int, 0 as libc::c_int, &mut oldt); return 0 as libc::c_int; }" }, { "index": 879, "before": "void do_gravity(int d) { #define GRAVITATE_DIRECTION(_v1, _v2, _xs, _xc, _xi, _ys, _yc, _yi, _x, _y) \\ do { \\ int break_cond = 0; \\ while (!break_cond) { \\ break_cond = 1; \\ for (int _v1 = _xs; _v1 _xc; _v1 += _xi) { \\ for (int _v2 = _ys; _v2 _yc; _v2 += _yi) { \\ if (!game.grid[x][y] && game.grid[x + _x][y + _y]) { \\ game.grid[x][y] = game.grid[x + _x][y + _y]; \\ game.grid[x + _x][y + _y] = break_cond = 0; \\ game.have_moved = 1; \\ } \\ } \\ } \\ do_draw(); usleep(40000); \\ } \\ } while (0) switch (d) { case D_LEFT: GRAVITATE_DIRECTION(x, y, 0, < 3, 1, 0, < 4, 1, 1, 0); break; case D_RIGHT: GRAVITATE_DIRECTION(x, y, 3, > 0, -1, 0, < 4, 1, -1, 0); break; case D_DOWN: GRAVITATE_DIRECTION(y, x, 3, > 0, -1, 0, < 4, 1, 0, -1); break; case D_UP: GRAVITATE_DIRECTION(y, x, 0, < 3, 1, 0, < 4, 1, 0, 1); break; } #undef GRAVITATE_DIRECTION }", "after": "pub unsafe extern \"C\" fn do_gravity(mut d: libc::c_int) { match d { 4 => { let mut break_cond: libc::c_int = 0 as libc::c_int; while break_cond == 0 { break_cond = 1 as libc::c_int; let mut x: libc::c_int = 0 as libc::c_int; while x < 3 as libc::c_int { let mut y: libc::c_int = 0 as libc::c_int; while y < 4 as libc::c_int { if game.grid[x as usize][y as usize] == 0 && game .grid[(x + 1 as libc::c_int) as usize][(y + 0 as libc::c_int) as usize] != 0 { game .grid[x as usize][y as usize] = game .grid[(x + 1 as libc::c_int) as usize][(y + 0 as libc::c_int) as usize]; break_cond = 0 as libc::c_int; game .grid[(x + 1 as libc::c_int) as usize][(y + 0 as libc::c_int) as usize] = break_cond; game.have_moved = 1 as libc::c_int; } y += 1 as libc::c_int; } x += 1 as libc::c_int; } do_draw(); usleep(40000 as libc::c_int as __useconds_t); } } 3 => { let mut break_cond_0: libc::c_int = 0 as libc::c_int; while break_cond_0 == 0 { break_cond_0 = 1 as libc::c_int; let mut x_0: libc::c_int = 3 as libc::c_int; while x_0 > 0 as libc::c_int { let mut y_0: libc::c_int = 0 as libc::c_int; while y_0 < 4 as libc::c_int { if game.grid[x_0 as usize][y_0 as usize] == 0 && game .grid[(x_0 + -(1 as libc::c_int)) as usize][(y_0 + 0 as libc::c_int) as usize] != 0 { game .grid[x_0 as usize][y_0 as usize] = game .grid[(x_0 + -(1 as libc::c_int)) as usize][(y_0 + 0 as libc::c_int) as usize]; break_cond_0 = 0 as libc::c_int; game .grid[(x_0 + -(1 as libc::c_int)) as usize][(y_0 + 0 as libc::c_int) as usize] = break_cond_0; game.have_moved = 1 as libc::c_int; } y_0 += 1 as libc::c_int; } x_0 += -(1 as libc::c_int); } do_draw(); usleep(40000 as libc::c_int as __useconds_t); } } 2 => { let mut break_cond_1: libc::c_int = 0 as libc::c_int; while break_cond_1 == 0 { break_cond_1 = 1 as libc::c_int; let mut y_1: libc::c_int = 3 as libc::c_int; while y_1 > 0 as libc::c_int { let mut x_1: libc::c_int = 0 as libc::c_int; while x_1 < 4 as libc::c_int { if game.grid[x_1 as usize][y_1 as usize] == 0 && game .grid[(x_1 + 0 as libc::c_int) as usize][(y_1 + -(1 as libc::c_int)) as usize] != 0 { game .grid[x_1 as usize][y_1 as usize] = game .grid[(x_1 + 0 as libc::c_int) as usize][(y_1 + -(1 as libc::c_int)) as usize]; break_cond_1 = 0 as libc::c_int; game .grid[(x_1 + 0 as libc::c_int) as usize][(y_1 + -(1 as libc::c_int)) as usize] = break_cond_1; game.have_moved = 1 as libc::c_int; } x_1 += 1 as libc::c_int; } y_1 += -(1 as libc::c_int); } do_draw(); usleep(40000 as libc::c_int as __useconds_t); } } 1 => { let mut break_cond_2: libc::c_int = 0 as libc::c_int; while break_cond_2 == 0 { break_cond_2 = 1 as libc::c_int; let mut y_2: libc::c_int = 0 as libc::c_int; while y_2 < 3 as libc::c_int { let mut x_2: libc::c_int = 0 as libc::c_int; while x_2 < 4 as libc::c_int { if game.grid[x_2 as usize][y_2 as usize] == 0 && game .grid[(x_2 + 0 as libc::c_int) as usize][(y_2 + 1 as libc::c_int) as usize] != 0 { game .grid[x_2 as usize][y_2 as usize] = game .grid[(x_2 + 0 as libc::c_int) as usize][(y_2 + 1 as libc::c_int) as usize]; break_cond_2 = 0 as libc::c_int; game .grid[(x_2 + 0 as libc::c_int) as usize][(y_2 + 1 as libc::c_int) as usize] = break_cond_2; game.have_moved = 1 as libc::c_int; } x_2 += 1 as libc::c_int; } y_2 += 1 as libc::c_int; } do_draw(); usleep(40000 as libc::c_int as __useconds_t); } } _ => {} }; }" }, { "index": 880, "before": "int do_tick(int d) { game.have_moved = 0; do_gravity(d); do_merge(d); do_gravity(d); return game.have_moved; }", "after": "pub unsafe extern \"C\" fn do_tick(mut d: libc::c_int) -> libc::c_int { game.have_moved = 0 as libc::c_int; do_gravity(d); do_merge(d); do_gravity(d); return game.have_moved; }" }, { "index": 881, "before": "void do_newblock(void) { if (game.blocks_in_play >= 16) return; int bn = rand() % (16 - game.blocks_in_play); int pn = 0; for (int x = 0; x < 4; ++x) { for (int y = 0; y < 4; ++y) { if (game.grid[x][y]) continue; if (pn == bn){ game.grid[x][y] = rand() % 10 ? 1 : 2; game.blocks_in_play += 1; return; } else { ++pn; } } } }", "after": "pub unsafe extern \"C\" fn do_newblock() { if game.blocks_in_play >= 16 as libc::c_int { return; } let mut bn: libc::c_int = rand() % (16 as libc::c_int - game.blocks_in_play); let mut pn: libc::c_int = 0 as libc::c_int; let mut x: libc::c_int = 0 as libc::c_int; while x < 4 as libc::c_int { let mut y: libc::c_int = 0 as libc::c_int; while y < 4 as libc::c_int { if !(game.grid[x as usize][y as usize] != 0) { if pn == bn { game .grid[x as usize][y as usize] = if rand() % 10 as libc::c_int != 0 { 1 as libc::c_int } else { 2 as libc::c_int }; game.blocks_in_play += 1 as libc::c_int; return; } else { pn += 1; pn; } } y += 1; y; } x += 1; x; } }" }, { "index": 882, "before": "void do_merge(int d) { /* These macros look pretty scary, but mainly demonstrate some space saving */ #define MERGE_DIRECTION(_v1, _v2, _xs, _xc, _xi, _ys, _yc, _yi, _x, _y) \\ do { \\ for (int _v1 = _xs; _v1 _xc; _v1 += _xi) { \\ for (int _v2 = _ys; _v2 _yc; _v2 += _yi) { \\ if (game.grid[x][y] && (game.grid[x][y] == \\ game.grid[x + _x][y + _y])) { \\ game.grid[x][y] += (game.have_moved = 1); \\ game.grid[x + _x][y + _y] = (0 * game.blocks_in_play--);\\ game.score_last_move += values[game.grid[x][y]]; \\ game.total_score += values[game.grid[x][y]]; \\ } \\ } \\ } \\ } while (0) game.score_last_move = 0; switch (d) { case D_LEFT: MERGE_DIRECTION(x, y, 0, < 3, 1, 0, < 4, 1, 1, 0); break; case D_RIGHT: MERGE_DIRECTION(x, y, 3, > 0, -1, 0, < 4, 1, -1, 0); break; case D_DOWN: MERGE_DIRECTION(y, x, 3, > 0, -1, 0, < 4, 1, 0, -1); break; case D_UP: MERGE_DIRECTION(y, x, 0, < 3, 1, 0, < 4, 1, 0, 1); break; } #undef MERGE_DIRECTION }", "after": "pub unsafe extern \"C\" fn do_merge(mut d: libc::c_int) { game.score_last_move = 0 as libc::c_int as libc::c_long; match d { 4 => { let mut x: libc::c_int = 0 as libc::c_int; while x < 3 as libc::c_int { let mut y: libc::c_int = 0 as libc::c_int; while y < 4 as libc::c_int { if game.grid[x as usize][y as usize] != 0 && game.grid[x as usize][y as usize] == game .grid[(x + 1 as libc::c_int) as usize][(y + 0 as libc::c_int) as usize] { game.have_moved = 1 as libc::c_int; game.grid[x as usize][y as usize] += game.have_moved; let fresh0 = game.blocks_in_play; game.blocks_in_play = game.blocks_in_play - 1; game .grid[(x + 1 as libc::c_int) as usize][(y + 0 as libc::c_int) as usize] = 0 as libc::c_int * fresh0; game.score_last_move += values[game.grid[x as usize][y as usize] as usize]; game.total_score += values[game.grid[x as usize][y as usize] as usize]; } y += 1 as libc::c_int; } x += 1 as libc::c_int; } } 3 => { let mut x_0: libc::c_int = 3 as libc::c_int; while x_0 > 0 as libc::c_int { let mut y_0: libc::c_int = 0 as libc::c_int; while y_0 < 4 as libc::c_int { if game.grid[x_0 as usize][y_0 as usize] != 0 && game.grid[x_0 as usize][y_0 as usize] == game .grid[(x_0 + -(1 as libc::c_int)) as usize][(y_0 + 0 as libc::c_int) as usize] { game.have_moved = 1 as libc::c_int; game.grid[x_0 as usize][y_0 as usize] += game.have_moved; let fresh1 = game.blocks_in_play; game.blocks_in_play = game.blocks_in_play - 1; game .grid[(x_0 + -(1 as libc::c_int)) as usize][(y_0 + 0 as libc::c_int) as usize] = 0 as libc::c_int * fresh1; game.score_last_move += values[game.grid[x_0 as usize][y_0 as usize] as usize]; game.total_score += values[game.grid[x_0 as usize][y_0 as usize] as usize]; } y_0 += 1 as libc::c_int; } x_0 += -(1 as libc::c_int); } } 2 => { let mut y_1: libc::c_int = 3 as libc::c_int; while y_1 > 0 as libc::c_int { let mut x_1: libc::c_int = 0 as libc::c_int; while x_1 < 4 as libc::c_int { if game.grid[x_1 as usize][y_1 as usize] != 0 && game.grid[x_1 as usize][y_1 as usize] == game .grid[(x_1 + 0 as libc::c_int) as usize][(y_1 + -(1 as libc::c_int)) as usize] { game.have_moved = 1 as libc::c_int; game.grid[x_1 as usize][y_1 as usize] += game.have_moved; let fresh2 = game.blocks_in_play; game.blocks_in_play = game.blocks_in_play - 1; game .grid[(x_1 + 0 as libc::c_int) as usize][(y_1 + -(1 as libc::c_int)) as usize] = 0 as libc::c_int * fresh2; game.score_last_move += values[game.grid[x_1 as usize][y_1 as usize] as usize]; game.total_score += values[game.grid[x_1 as usize][y_1 as usize] as usize]; } x_1 += 1 as libc::c_int; } y_1 += -(1 as libc::c_int); } } 1 => { let mut y_2: libc::c_int = 0 as libc::c_int; while y_2 < 3 as libc::c_int { let mut x_2: libc::c_int = 0 as libc::c_int; while x_2 < 4 as libc::c_int { if game.grid[x_2 as usize][y_2 as usize] != 0 && game.grid[x_2 as usize][y_2 as usize] == game .grid[(x_2 + 0 as libc::c_int) as usize][(y_2 + 1 as libc::c_int) as usize] { game.have_moved = 1 as libc::c_int; game.grid[x_2 as usize][y_2 as usize] += game.have_moved; let fresh3 = game.blocks_in_play; game.blocks_in_play = game.blocks_in_play - 1; game .grid[(x_2 + 0 as libc::c_int) as usize][(y_2 + 1 as libc::c_int) as usize] = 0 as libc::c_int * fresh3; game.score_last_move += values[game.grid[x_2 as usize][y_2 as usize] as usize]; game.total_score += values[game.grid[x_2 as usize][y_2 as usize] as usize]; } x_2 += 1 as libc::c_int; } y_2 += 1 as libc::c_int; } } _ => {} }; }" }, { "index": 883, "before": "int ord(char v) { return v-'0'; }", "after": "pub unsafe extern \"C\" fn ord(mut v: libc::c_char) -> libc::c_int { return v as libc::c_int - '0' as i32; }" }, { "index": 884, "before": "void printTable( Table tbl, FILE *fout, const char *colFmts[]) { int row, col; for (row=0; rown_rows; row++) { fprintf(fout, \" \"); for(col=0; coln_cols; col++) { fprintf(fout, colFmts[col], tbl->rows[row][col]); } fprintf(fout, \"\\n\"); } fprintf(fout, \"\\n\"); }", "after": "pub unsafe extern \"C\" fn printTable( mut tbl: Table, mut fout: *mut FILE, mut colFmts: *mut *const libc::c_char, ) { let mut row: libc::c_int = 0; let mut col: libc::c_int = 0; row = 0 as libc::c_int; while row < (*tbl).n_rows { fprintf(fout, b\" \\0\" as *const u8 as *const libc::c_char); col = 0 as libc::c_int; while col < (*tbl).n_cols { fprintf( fout, *colFmts.offset(col as isize), *(*((*tbl).rows).offset(row as isize)).offset(col as isize), ); col += 1; col; } fprintf(fout, b\"\\n\\0\" as *const u8 as *const libc::c_char); row += 1; row; } fprintf(fout, b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 885, "before": "int sortTable(Table tbl, const char* argSpec,... ) { va_list vl; const char *p; int c; sortSpec.compare = &strcmp; sortSpec.column = 0; sortSpec.reversed = 0; va_start(vl, argSpec); if (argSpec) for (p=argSpec; *p; p++) { switch (*p) { case 'o': sortSpec.compare = va_arg(vl,CompareFctn); break; case 'c': c = va_arg(vl,int); if ( 0<=c && cn_cols) sortSpec.column = c; break; case 'r': sortSpec.reversed = (0!=va_arg(vl,int)); break; } } va_end(vl); qsort( tbl->rows, tbl->n_rows, sizeof(String *), CmprRows); return 0; }", "after": "pub unsafe extern \"C\" fn sortTable( mut tbl: Table, mut argSpec: *const libc::c_char, mut args: ... ) -> libc::c_int { let mut vl: ::core::ffi::VaListImpl; let mut p: *const libc::c_char = 0 as *const libc::c_char; let mut c: libc::c_int = 0; sortSpec .compare = Some( strcmp as unsafe extern \"C\" fn( *const libc::c_char, *const libc::c_char, ) -> libc::c_int, ); sortSpec.column = 0 as libc::c_int; sortSpec.reversed = 0 as libc::c_int; vl = args.clone(); if !argSpec.is_null() { p = argSpec; while *p != 0 { match *p as libc::c_int { 111 => { sortSpec .compare = ::core::mem::transmute( vl .arg::< *mut unsafe extern \"C\" fn(String_0, String_0) -> libc::c_int, >(), ); } 99 => { c = vl.arg::(); if 0 as libc::c_int <= c && c < (*tbl).n_cols { sortSpec.column = c; } } 114 => { sortSpec .reversed = (0 as libc::c_int != vl.arg::()) as libc::c_int; } _ => {} } p = p.offset(1); p; } } qsort( (*tbl).rows as *mut libc::c_void, (*tbl).n_rows as size_t, ::core::mem::size_of::<*mut String_0>() as libc::c_ulong, Some( CmprRows as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); return 0 as libc::c_int; }" }, { "index": 886, "before": "int cmprStrgs(String s1, String s2) { const char *p1 = s1; const char *p2 = s2; const char *mrk1, *mrk2; while ((tolower(*p1) == tolower(*p2)) && *p1) { p1++; p2++; } if (isdigit(*p1) && isdigit(*p2)) { long v1, v2; if ((*p1 == '0') ||(*p2 == '0')) { while (p1 > s1) { p1--; p2--; if (*p1 != '0') break; } if (!isdigit(*p1)) { p1++; p2++; } } mrk1 = p1; mrk2 = p2; v1 = 0; while(isdigit(*p1)) { v1 = 10*v1+ord(*p1); p1++; } v2 = 0; while(isdigit(*p2)) { v2 = 10*v2+ord(*p2); p2++; } if (v1 == v2) return(p2-mrk2)-(p1-mrk1); return v1 - v2; } if (tolower(*p1) != tolower(*p2)) return (tolower(*p1) - tolower(*p2)); for(p1=s1, p2=s2; (*p1 == *p2) && *p1; p1++, p2++); return (*p1 -*p2); }", "after": "pub unsafe extern \"C\" fn cmprStrgs(mut s1: String_0, mut s2: String_0) -> libc::c_int { let mut p1: *const libc::c_char = s1; let mut p2: *const libc::c_char = s2; let mut mrk1: *const libc::c_char = 0 as *const libc::c_char; let mut mrk2: *const libc::c_char = 0 as *const libc::c_char; while tolower(*p1 as libc::c_int) == tolower(*p2 as libc::c_int) && *p1 as libc::c_int != 0 { p1 = p1.offset(1); p1; p2 = p2.offset(1); p2; } if *(*__ctype_b_loc()).offset(*p1 as libc::c_int as isize) as libc::c_int & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0 && *(*__ctype_b_loc()).offset(*p2 as libc::c_int as isize) as libc::c_int & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0 { let mut v1: libc::c_long = 0; let mut v2: libc::c_long = 0; if *p1 as libc::c_int == '0' as i32 || *p2 as libc::c_int == '0' as i32 { while p1 > s1 { p1 = p1.offset(-1); p1; p2 = p2.offset(-1); p2; if *p1 as libc::c_int != '0' as i32 { break; } } if *(*__ctype_b_loc()).offset(*p1 as libc::c_int as isize) as libc::c_int & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int == 0 { p1 = p1.offset(1); p1; p2 = p2.offset(1); p2; } } mrk1 = p1; mrk2 = p2; v1 = 0 as libc::c_int as libc::c_long; while *(*__ctype_b_loc()).offset(*p1 as libc::c_int as isize) as libc::c_int & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0 { v1 = 10 as libc::c_int as libc::c_long * v1 + ord(*p1) as libc::c_long; p1 = p1.offset(1); p1; } v2 = 0 as libc::c_int as libc::c_long; while *(*__ctype_b_loc()).offset(*p2 as libc::c_int as isize) as libc::c_int & _ISdigit as libc::c_int as libc::c_ushort as libc::c_int != 0 { v2 = 10 as libc::c_int as libc::c_long * v2 + ord(*p2) as libc::c_long; p2 = p2.offset(1); p2; } if v1 == v2 { return (p2.offset_from(mrk2) as libc::c_long - p1.offset_from(mrk1) as libc::c_long) as libc::c_int; } return (v1 - v2) as libc::c_int; } if tolower(*p1 as libc::c_int) != tolower(*p2 as libc::c_int) { return tolower(*p1 as libc::c_int) - tolower(*p2 as libc::c_int); } p1 = s1; p2 = s2; while *p1 as libc::c_int == *p2 as libc::c_int && *p1 as libc::c_int != 0 { p1 = p1.offset(1); p1; p2 = p2.offset(1); p2; } return *p1 as libc::c_int - *p2 as libc::c_int; }" }, { "index": 887, "before": "int CmprRows( const void *aa, const void *bb) { String *rA = *(String *const *)aa; String *rB = *(String *const *)bb; int sortCol = sortSpec.column; String left = sortSpec.reversed ? rB[sortCol] : rA[sortCol]; String right = sortSpec.reversed ? rA[sortCol] : rB[sortCol]; return sortSpec.compare( left, right ); }", "after": "pub unsafe extern \"C\" fn CmprRows( mut aa: *const libc::c_void, mut bb: *const libc::c_void, ) -> libc::c_int { let mut rA: *mut String_0 = *(aa as *const *mut String_0); let mut rB: *mut String_0 = *(bb as *const *mut String_0); let mut sortCol: libc::c_int = sortSpec.column; let mut left: String_0 = if sortSpec.reversed != 0 { *rB.offset(sortCol as isize) } else { *rA.offset(sortCol as isize) }; let mut right: String_0 = if sortSpec.reversed != 0 { *rA.offset(sortCol as isize) } else { *rB.offset(sortCol as isize) }; return (sortSpec.compare).expect(\"non-null function pointer\")(left, right); }" }, { "index": 888, "before": "int main() { const char *colFmts[] = {\" %-5.5s\",\" %-5.5s\",\" %-9.9s\"}; String r1[] = { \"a101\", \"red\", \"Java\" }; String r2[] = { \"ab40\", \"gren\", \"Smalltalk\" }; String r3[] = { \"ab9\", \"blue\", \"Fortran\" }; String r4[] = { \"ab09\", \"ylow\", \"Python\" }; String r5[] = { \"ab1a\", \"blak\", \"Factor\" }; String r6[] = { \"ab1b\", \"brwn\", \"C Sharp\" }; String r7[] = { \"Ab1b\", \"pink\", \"Ruby\" }; String r8[] = { \"ab1\", \"orng\", \"Scheme\" }; String *rows[] = { r1, r2, r3, r4, r5, r6, r7, r8 }; struct sTable table; table.rows = rows; table.n_rows = 8; table.n_cols = 3; sortTable(&table, \"\"); printf(\"sort on col 0, ascending\\n\"); printTable(&table, stdout, colFmts); sortTable(&table, \"ro\", 1, &cmprStrgs); printf(\"sort on col 0, reverse.special\\n\"); printTable(&table, stdout, colFmts); sortTable(&table, \"c\", 1); printf(\"sort on col 1, ascending\\n\"); printTable(&table, stdout, colFmts); sortTable(&table, \"cr\", 2, 1); printf(\"sort on col 2, reverse\\n\"); printTable(&table, stdout, colFmts); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut colFmts: [*const libc::c_char; 3] = [ b\" %-5.5s\\0\" as *const u8 as *const libc::c_char, b\" %-5.5s\\0\" as *const u8 as *const libc::c_char, b\" %-9.9s\\0\" as *const u8 as *const libc::c_char, ]; let mut r1: [String_0; 3] = [ b\"a101\\0\" as *const u8 as *const libc::c_char, b\"red\\0\" as *const u8 as *const libc::c_char, b\"Java\\0\" as *const u8 as *const libc::c_char, ]; let mut r2: [String_0; 3] = [ b\"ab40\\0\" as *const u8 as *const libc::c_char, b\"gren\\0\" as *const u8 as *const libc::c_char, b\"Smalltalk\\0\" as *const u8 as *const libc::c_char, ]; let mut r3: [String_0; 3] = [ b\"ab9\\0\" as *const u8 as *const libc::c_char, b\"blue\\0\" as *const u8 as *const libc::c_char, b\"Fortran\\0\" as *const u8 as *const libc::c_char, ]; let mut r4: [String_0; 3] = [ b\"ab09\\0\" as *const u8 as *const libc::c_char, b\"ylow\\0\" as *const u8 as *const libc::c_char, b\"Python\\0\" as *const u8 as *const libc::c_char, ]; let mut r5: [String_0; 3] = [ b\"ab1a\\0\" as *const u8 as *const libc::c_char, b\"blak\\0\" as *const u8 as *const libc::c_char, b\"Factor\\0\" as *const u8 as *const libc::c_char, ]; let mut r6: [String_0; 3] = [ b\"ab1b\\0\" as *const u8 as *const libc::c_char, b\"brwn\\0\" as *const u8 as *const libc::c_char, b\"C Sharp\\0\" as *const u8 as *const libc::c_char, ]; let mut r7: [String_0; 3] = [ b\"Ab1b\\0\" as *const u8 as *const libc::c_char, b\"pink\\0\" as *const u8 as *const libc::c_char, b\"Ruby\\0\" as *const u8 as *const libc::c_char, ]; let mut r8: [String_0; 3] = [ b\"ab1\\0\" as *const u8 as *const libc::c_char, b\"orng\\0\" as *const u8 as *const libc::c_char, b\"Scheme\\0\" as *const u8 as *const libc::c_char, ]; let mut rows: [*mut String_0; 8] = [ r1.as_mut_ptr(), r2.as_mut_ptr(), r3.as_mut_ptr(), r4.as_mut_ptr(), r5.as_mut_ptr(), r6.as_mut_ptr(), r7.as_mut_ptr(), r8.as_mut_ptr(), ]; let mut table: sTable = sTable { rows: 0 as *mut *mut String_0, n_rows: 0, n_cols: 0, }; table.rows = rows.as_mut_ptr(); table.n_rows = 8 as libc::c_int; table.n_cols = 3 as libc::c_int; sortTable(&mut table as *mut sTable, b\"\\0\" as *const u8 as *const libc::c_char); printf(b\"sort on col 0, ascending\\n\\0\" as *const u8 as *const libc::c_char); printTable(&mut table, stdout, colFmts.as_mut_ptr()); sortTable( &mut table as *mut sTable, b\"ro\\0\" as *const u8 as *const libc::c_char, 1 as libc::c_int, Some(cmprStrgs as unsafe extern \"C\" fn(String_0, String_0) -> libc::c_int), ); printf(b\"sort on col 0, reverse.special\\n\\0\" as *const u8 as *const libc::c_char); printTable(&mut table, stdout, colFmts.as_mut_ptr()); sortTable( &mut table as *mut sTable, b\"c\\0\" as *const u8 as *const libc::c_char, 1 as libc::c_int, ); printf(b\"sort on col 1, ascending\\n\\0\" as *const u8 as *const libc::c_char); printTable(&mut table, stdout, colFmts.as_mut_ptr()); sortTable( &mut table as *mut sTable, b\"cr\\0\" as *const u8 as *const libc::c_char, 2 as libc::c_int, 1 as libc::c_int, ); printf(b\"sort on col 2, reverse\\n\\0\" as *const u8 as *const libc::c_char); printTable(&mut table, stdout, colFmts.as_mut_ptr()); return 0 as libc::c_int; }" }, { "index": 889, "before": "void turn(cursor_t* cursor, int angle) { cursor->angle = (cursor->angle + angle) % 360; }", "after": "pub unsafe extern \"C\" fn turn(mut cursor: *mut cursor_t, mut angle: libc::c_int) { (*cursor).angle = ((*cursor).angle + angle) % 360 as libc::c_int; }" }, { "index": 890, "before": "void draw_line(FILE* out, cursor_t* cursor, double length) { double theta = (M_PI * cursor->angle)/180.0; cursor->x += length * cos(theta); cursor->y += length * sin(theta); fprintf(out, \"L%g,%g\\n\", cursor->x, cursor->y); }", "after": "pub unsafe extern \"C\" fn draw_line( mut out: *mut FILE, mut cursor: *mut cursor_t, mut length: libc::c_double, ) { let mut theta: libc::c_double = 3.14159265358979323846f64 * (*cursor).angle as libc::c_double / 180.0f64; (*cursor).x += length * cos(theta); (*cursor).y += length * sin(theta); fprintf( out, b\"L%g,%g\\n\\0\" as *const u8 as *const libc::c_char, (*cursor).x, (*cursor).y, ); }" }, { "index": 891, "before": "int main(int argc, char** argv) { const char* filename = \"sierpinski_arrowhead.svg\"; if (argc == 2) filename = argv[1]; FILE* out = fopen(filename, \"w\"); if (!out) { perror(filename); return EXIT_FAILURE; } write_sierpinski_arrowhead(out, 600, 8); fclose(out); return EXIT_SUCCESS; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut filename: *const libc::c_char = b\"sierpinski_arrowhead.svg\\0\" as *const u8 as *const libc::c_char; if argc == 2 as libc::c_int { filename = *argv.offset(1 as libc::c_int as isize); } let mut out: *mut FILE = fopen(filename, b\"w\\0\" as *const u8 as *const libc::c_char); if out.is_null() { perror(filename); return 1 as libc::c_int; } write_sierpinski_arrowhead(out, 600 as libc::c_int, 8 as libc::c_int); fclose(out); return 0 as libc::c_int; }" }, { "index": 892, "before": "void curve(FILE* out, int order, double length, cursor_t* cursor, int angle) { if (order == 0) { draw_line(out, cursor, length); } else { curve(out, order - 1, length/2, cursor, -angle); turn(cursor, angle); curve(out, order - 1, length/2, cursor, angle); turn(cursor, angle); curve(out, order - 1, length/2, cursor, -angle); } }", "after": "pub unsafe extern \"C\" fn curve( mut out: *mut FILE, mut order: libc::c_int, mut length: libc::c_double, mut cursor: *mut cursor_t, mut angle: libc::c_int, ) { if order == 0 as libc::c_int { draw_line(out, cursor, length); } else { curve( out, order - 1 as libc::c_int, length / 2 as libc::c_int as libc::c_double, cursor, -angle, ); turn(cursor, angle); curve( out, order - 1 as libc::c_int, length / 2 as libc::c_int as libc::c_double, cursor, angle, ); turn(cursor, angle); curve( out, order - 1 as libc::c_int, length / 2 as libc::c_int as libc::c_double, cursor, -angle, ); }; }" }, { "index": 893, "before": "void write_sierpinski_arrowhead(FILE* out, int size, int order) { const double margin = 20.0; const double side = size - 2.0 * margin; cursor_t cursor; cursor.angle = 0; cursor.x = margin; cursor.y = 0.5 * size + 0.25 * sqrt(3) * side; if ((order & 1) != 0) turn(&cursor, -60); fprintf(out, \"\\n\", size, size); fprintf(out, \"\\n\"); fprintf(out, \"\\n\\n\"); }", "after": "pub unsafe extern \"C\" fn write_sierpinski_arrowhead( mut out: *mut FILE, mut size: libc::c_int, mut order: libc::c_int, ) { let margin: libc::c_double = 20.0f64; let side: libc::c_double = size as libc::c_double - 2.0f64 * margin; let mut cursor: cursor_t = cursor_t { x: 0., y: 0., angle: 0 }; cursor.angle = 0 as libc::c_int; cursor.x = margin; cursor .y = 0.5f64 * size as libc::c_double + 0.25f64 * sqrt(3 as libc::c_int as libc::c_double) * side; if order & 1 as libc::c_int != 0 as libc::c_int { turn(&mut cursor, -(60 as libc::c_int)); } fprintf( out, b\"\\n\\0\" as *const u8 as *const libc::c_char, size, size, ); fprintf( out, b\"\\n\\0\" as *const u8 as *const libc::c_char, ); fprintf( out, b\"\\n\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 894, "before": "int is_prime(unsigned int n) { if (n <= 3) { return n > 1; } else if (!(n % 2) || !(n % 3)) { return 0; } else { unsigned int i; for (i = 5; i*i <= n; i += 6) if (!(n % i) || !(n % (i + 2))) return 0; return 1; } }", "after": "pub unsafe extern \"C\" fn is_prime(mut n: libc::c_uint) -> libc::c_int { if n <= 3 as libc::c_int as libc::c_uint { return (n > 1 as libc::c_int as libc::c_uint) as libc::c_int } else if n.wrapping_rem(2 as libc::c_int as libc::c_uint) == 0 || n.wrapping_rem(3 as libc::c_int as libc::c_uint) == 0 { return 0 as libc::c_int } else { let mut i: libc::c_uint = 0; i = 5 as libc::c_int as libc::c_uint; while i.wrapping_mul(i) <= n { if n.wrapping_rem(i) == 0 || n.wrapping_rem(i.wrapping_add(2 as libc::c_int as libc::c_uint)) == 0 { return 0 as libc::c_int; } i = i.wrapping_add(6 as libc::c_int as libc::c_uint); } return 1 as libc::c_int; }; }" }, { "index": 895, "before": "int main(void) { int p1; for (p1 = 2; p1 < 62; ++p1) carmichael3(p1); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut p1: libc::c_int = 0; p1 = 2 as libc::c_int; while p1 < 62 as libc::c_int { carmichael3(p1); p1 += 1; p1; } return 0 as libc::c_int; }" }, { "index": 896, "before": "void carmichael3(int p1) { if (!is_prime(p1)) return; int h3, d, p2, p3; for (h3 = 1; h3 < p1; ++h3) { for (d = 1; d < h3 + p1; ++d) { if ((h3 + p1)*(p1 - 1) % d == 0 && mod(-p1 * p1, h3) == d % h3) { p2 = 1 + ((p1 - 1) * (h3 + p1)/d); if (!is_prime(p2)) continue; p3 = 1 + (p1 * p2 / h3); if (!is_prime(p3) || (p2 * p3) % (p1 - 1) != 1) continue; printf(\"%d %d %d\\n\", p1, p2, p3); } } } }", "after": "pub unsafe extern \"C\" fn carmichael3(mut p1: libc::c_int) { if is_prime(p1 as libc::c_uint) == 0 { return; } let mut h3: libc::c_int = 0; let mut d: libc::c_int = 0; let mut p2: libc::c_int = 0; let mut p3: libc::c_int = 0; h3 = 1 as libc::c_int; while h3 < p1 { d = 1 as libc::c_int; while d < h3 + p1 { if (h3 + p1) * (p1 - 1 as libc::c_int) % d == 0 as libc::c_int && (-p1 * p1 % h3 + h3) % h3 == d % h3 { p2 = 1 as libc::c_int + (p1 - 1 as libc::c_int) * (h3 + p1) / d; if !(is_prime(p2 as libc::c_uint) == 0) { p3 = 1 as libc::c_int + p1 * p2 / h3; if !(is_prime(p3 as libc::c_uint) == 0 || p2 * p3 % (p1 - 1 as libc::c_int) != 1 as libc::c_int) { printf( b\"%d %d %d\\n\\0\" as *const u8 as *const libc::c_char, p1, p2, p3, ); } } } d += 1; d; } h3 += 1; h3; } }" }, { "index": 897, "before": "int myopenimage(const char *in) { static int handle=0; fprintf(stderr, \"internal openimage opens %s...\\n\", in); return handle++; }", "after": "pub unsafe extern \"C\" fn myopenimage(mut in_0: *const libc::c_char) -> libc::c_int { static mut handle: libc::c_int = 0 as libc::c_int; fprintf( stderr, b\"internal openimage opens %s...\\n\\0\" as *const u8 as *const libc::c_char, in_0, ); let fresh0 = handle; handle = handle + 1; return fresh0; }" }, { "index": 898, "before": "int main() { void *imglib; int (*extopenimage)(const char *); int imghandle; imglib = dlopen(\"./fakeimglib.so\", RTLD_LAZY); if ( imglib != NULL ) { /* extopenimage = (int (*)(const char *))dlsym(imglib,...) \"man dlopen\" says that C99 standard leaves casting from \"void *\" to a function pointer undefined. The following is the POSIX.1-2003 workaround found in man */ *(void **)(&extopenimage) = dlsym(imglib, \"openimage\"); /* the following works with gcc, gives no warning even with -Wall -std=c99 -pedantic options... :D */ /* extopenimage = dlsym(imglib, \"openimage\"); */ imghandle = extopenimage(\"fake.img\"); } else { imghandle = myopenimage(\"fake.img\"); } printf(\"opened with handle %d\\n\", imghandle); /* ... */ if (imglib != NULL ) dlclose(imglib); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut imglib: *mut libc::c_void = 0 as *mut libc::c_void; let mut extopenimage: Option::< unsafe extern \"C\" fn(*const libc::c_char) -> libc::c_int, > = None; let mut imghandle: libc::c_int = 0; imglib = dlopen( b\"./fakeimglib.so\\0\" as *const u8 as *const libc::c_char, 0x1 as libc::c_int, ); if !imglib.is_null() { let ref mut fresh1 = *(&mut extopenimage as *mut Option:: libc::c_int> as *mut *mut libc::c_void); *fresh1 = dlsym(imglib, b\"openimage\\0\" as *const u8 as *const libc::c_char); imghandle = extopenimage .expect( \"non-null function pointer\", )(b\"fake.img\\0\" as *const u8 as *const libc::c_char); } else { imghandle = myopenimage(b\"fake.img\\0\" as *const u8 as *const libc::c_char); } printf(b\"opened with handle %d\\n\\0\" as *const u8 as *const libc::c_char, imghandle); if !imglib.is_null() { dlclose(imglib); } return 0 as libc::c_int; }" }, { "index": 899, "before": "void fail(const char *message) { \tperror(message); \texit(1); }", "after": "pub unsafe extern \"C\" fn fail(mut message: *const libc::c_char) { perror(message); exit(1 as libc::c_int); }" }, { "index": 900, "before": "void ooi_unlink(void) { \tunlink(ooi_path); }", "after": "pub unsafe extern \"C\" fn ooi_unlink() { unlink(ooi_path); }" }, { "index": 901, "before": "void only_one_instance(void) { \tstruct flock fl; \tsize_t dirlen; \tint fd; \tchar *dir; \t/* \t * Place the lock in the home directory of this user; \t * therefore we only check for other instances by the same \t * user (and the user can trick us by changing HOME). \t */ \tdir = getenv(\"HOME\"); \tif (dir == NULL || dir[0] != '/') { \t\tfputs(\"Bad home directory.\\n\", stderr); \t\texit(1); \t} \tdirlen = strlen(dir); \tooi_path = malloc(dirlen + sizeof(\"/\" INSTANCE_LOCK)); \tif (ooi_path == NULL) \t\tfail(\"malloc\"); \tmemcpy(ooi_path, dir, dirlen); \tmemcpy(ooi_path + dirlen, \"/\" INSTANCE_LOCK, \t sizeof(\"/\" INSTANCE_LOCK)); /* copies '\\0' */ \tfd = open(ooi_path, O_RDWR | O_CREAT, 0600); \tif (fd < 0) \t\tfail(ooi_path); \tfl.l_start = 0; \tfl.l_len = 0; \tfl.l_type = F_WRLCK; \tfl.l_whence = SEEK_SET; \tif (fcntl(fd, F_SETLK, &fl) < 0) { \t\tfputs(\"Another instance of this program is running.\\n\", \t\t stderr); \t\texit(1); \t} \t/* \t * Run unlink(ooi_path) when the program exits. The program \t * always releases locks when it exits. \t */ \tatexit(ooi_unlink); }", "after": "pub unsafe extern \"C\" fn only_one_instance() { let mut fl: flock = flock { l_type: 0, l_whence: 0, l_start: 0, l_len: 0, l_pid: 0, }; let mut dirlen: size_t = 0; let mut fd: libc::c_int = 0; let mut dir: *mut libc::c_char = 0 as *mut libc::c_char; dir = getenv(b\"HOME\\0\" as *const u8 as *const libc::c_char); if dir.is_null() || *dir.offset(0 as libc::c_int as isize) as libc::c_int != '/' as i32 { fputs(b\"Bad home directory.\\n\\0\" as *const u8 as *const libc::c_char, stderr); exit(1 as libc::c_int); } dirlen = strlen(dir); ooi_path = malloc( dirlen .wrapping_add(::core::mem::size_of::<[libc::c_char; 19]>() as libc::c_ulong), ) as *mut libc::c_char; if ooi_path.is_null() { fail(b\"malloc\\0\" as *const u8 as *const libc::c_char); } memcpy(ooi_path as *mut libc::c_void, dir as *const libc::c_void, dirlen); memcpy( ooi_path.offset(dirlen as isize) as *mut libc::c_void, b\"/rosetta-code-lock\\0\" as *const u8 as *const libc::c_char as *const libc::c_void, ::core::mem::size_of::<[libc::c_char; 19]>() as libc::c_ulong, ); fd = open(ooi_path, 0o2 as libc::c_int | 0o100 as libc::c_int, 0o600 as libc::c_int); if fd < 0 as libc::c_int { fail(ooi_path); } fl.l_start = 0 as libc::c_int as __off_t; fl.l_len = 0 as libc::c_int as __off_t; fl.l_type = 1 as libc::c_int as libc::c_short; fl.l_whence = 0 as libc::c_int as libc::c_short; if fcntl(fd, 6 as libc::c_int, &mut fl as *mut flock) < 0 as libc::c_int { fputs( b\"Another instance of this program is running.\\n\\0\" as *const u8 as *const libc::c_char, stderr, ); exit(1 as libc::c_int); } atexit(Some(ooi_unlink as unsafe extern \"C\" fn() -> ())); }" }, { "index": 902, "before": "int main() { \tint i; \tonly_one_instance(); \t/* Play for 10 seconds. */ \tfor(i = 10; i > 0; i--) { \t\tprintf(\"%d...%s\", i, i % 5 == 1 ? \"\\n\" : \" \"); \t\tfflush(stdout); \t\tsleep(1); \t} \tputs(\"Fin!\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; only_one_instance(); i = 10 as libc::c_int; while i > 0 as libc::c_int { printf( b\"%d...%s\\0\" as *const u8 as *const libc::c_char, i, if i % 5 as libc::c_int == 1 as libc::c_int { b\"\\n\\0\" as *const u8 as *const libc::c_char } else { b\" \\0\" as *const u8 as *const libc::c_char }, ); fflush(stdout); sleep(1 as libc::c_int as libc::c_uint); i -= 1; i; } puts(b\"Fin!\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 903, "before": "int main(void) { \tint x[] = {123, 12345, 1234567, 987654321, 10001, -10001, \t\t-123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0, \t\t1234567890}; \tint i; \tchar *m; \tfor (i = 0; i < sizeof(x)/sizeof(x[0]); i++) { \t\tif (!(m = mid3(x[i]))) \t\t\tm = \"error\"; \t\tprintf(\"%d: %s\\n\", x[i], m); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut x: [libc::c_int; 18] = [ 123 as libc::c_int, 12345 as libc::c_int, 1234567 as libc::c_int, 987654321 as libc::c_int, 10001 as libc::c_int, -(10001 as libc::c_int), -(123 as libc::c_int), -(100 as libc::c_int), 100 as libc::c_int, -(12345 as libc::c_int), 1 as libc::c_int, 2 as libc::c_int, -(1 as libc::c_int), -(10 as libc::c_int), 2002 as libc::c_int, -(2002 as libc::c_int), 0 as libc::c_int, 1234567890 as libc::c_int, ]; let mut i: libc::c_int = 0; let mut m: *mut libc::c_char = 0 as *mut libc::c_char; i = 0 as libc::c_int; while (i as libc::c_ulong) < (::core::mem::size_of::<[libc::c_int; 18]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) { m = mid3(x[i as usize]); if m.is_null() { m = b\"error\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; } printf(b\"%d: %s\\n\\0\" as *const u8 as *const libc::c_char, x[i as usize], m); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 904, "before": "int main() { int curr[5][5]; int max_claim[5][5]; int avl[5]; int alloc[5] = {0, 0, 0, 0, 0}; int max_res[5]; int running[5]; int i, j, exec, r, p; int count = 0; bool safe = false; printf(\"\\nEnter the number of resources: \"); scanf(\"%d\", &r); printf(\"\\nEnter the number of processes: \"); scanf(\"%d\", &p); for (i = 0; i < p; i++) { running[i] = 1; count++; } printf(\"\\nEnter Claim Vector: \"); for (i = 0; i < r; i++) scanf(\"%d\", &max_res[i]); printf(\"\\nEnter Allocated Resource Table: \"); for (i = 0; i < p; i++) { for (j = 0; j < r; j++) scanf(\"%d\", &curr[i][j]); } printf(\"\\nEnter Maximum Claim table: \"); for (i = 0; i < p; i++) { for (j = 0; j < r; j++) scanf(\"%d\", &max_claim[i][j]); } printf(\"\\nThe Claim Vector is: \"); for (i = 0; i < r; i++) printf(\"%d \", max_res[i]); printf(\"\\nThe Allocated Resource Table:\\n\"); for (i = 0; i < p; i++) { for (j = 0; j < r; j++) printf(\"\\t%d\", curr[i][j]); printf(\"\\n\"); } printf(\"\\nThe Maximum Claim Table:\\n\"); for (i = 0; i < p; i++) { for (j = 0; j < r; j++) printf(\"\\t%d\", max_claim[i][j]); printf(\"\\n\"); } for (i = 0; i < p; i++) for (j = 0; j < r; j++) alloc[j] += curr[i][j]; printf(\"\\nAllocated resources: \"); for (i = 0; i < r; i++) printf(\"%d \", alloc[i]); for (i = 0; i < r; i++) avl[i] = max_res[i] - alloc[i]; printf(\"\\nAvailable resources: \"); for (i = 0; i < r; i++) printf(\"%d \", avl[i]); printf(\"\\n\"); while (count != 0) { safe = false; for (i = 0; i < p; i++) { if (running[i]) { exec = 1; for (j = 0; j < r; j++) { if (max_claim[i][j] - curr[i][j] > avl[j]) { exec = 0; break; } } if (exec) { printf(\"\\nProcess%d is executing.\\n\", i + 1); running[i] = 0; count--; safe = true; for (j = 0; j < r; j++) avl[j] += curr[i][j]; break; } } } if (!safe) { printf(\"\\nThe processes are in unsafe state.\"); break; } if (safe) printf(\"\\nThe process is in safe state.\"); printf(\"\\nAvailable vector: \"); for (i = 0; i < r; i++) printf(\"%d \", avl[i]); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut curr: [[libc::c_int; 5]; 5] = [[0; 5]; 5]; let mut max_claim: [[libc::c_int; 5]; 5] = [[0; 5]; 5]; let mut avl: [libc::c_int; 5] = [0; 5]; let mut alloc: [libc::c_int; 5] = [ 0 as libc::c_int, 0 as libc::c_int, 0 as libc::c_int, 0 as libc::c_int, 0 as libc::c_int, ]; let mut max_res: [libc::c_int; 5] = [0; 5]; let mut running: [libc::c_int; 5] = [0; 5]; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut exec: libc::c_int = 0; let mut r: libc::c_int = 0; let mut p: libc::c_int = 0; let mut count: libc::c_int = 0 as libc::c_int; let mut safe: bool = 0 as libc::c_int != 0; printf(b\"\\nEnter the number of resources: \\0\" as *const u8 as *const libc::c_char); scanf(b\"%d\\0\" as *const u8 as *const libc::c_char, &mut r as *mut libc::c_int); printf(b\"\\nEnter the number of processes: \\0\" as *const u8 as *const libc::c_char); scanf(b\"%d\\0\" as *const u8 as *const libc::c_char, &mut p as *mut libc::c_int); i = 0 as libc::c_int; while i < p { running[i as usize] = 1 as libc::c_int; count += 1; count; i += 1; i; } printf(b\"\\nEnter Claim Vector: \\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < r { scanf( b\"%d\\0\" as *const u8 as *const libc::c_char, &mut *max_res.as_mut_ptr().offset(i as isize) as *mut libc::c_int, ); i += 1; i; } printf(b\"\\nEnter Allocated Resource Table: \\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < p { j = 0 as libc::c_int; while j < r { scanf( b\"%d\\0\" as *const u8 as *const libc::c_char, &mut *(*curr.as_mut_ptr().offset(i as isize)) .as_mut_ptr() .offset(j as isize) as *mut libc::c_int, ); j += 1; j; } i += 1; i; } printf(b\"\\nEnter Maximum Claim table: \\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < p { j = 0 as libc::c_int; while j < r { scanf( b\"%d\\0\" as *const u8 as *const libc::c_char, &mut *(*max_claim.as_mut_ptr().offset(i as isize)) .as_mut_ptr() .offset(j as isize) as *mut libc::c_int, ); j += 1; j; } i += 1; i; } printf(b\"\\nThe Claim Vector is: \\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < r { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, max_res[i as usize]); i += 1; i; } printf(b\"\\nThe Allocated Resource Table:\\n\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < p { j = 0 as libc::c_int; while j < r { printf( b\"\\t%d\\0\" as *const u8 as *const libc::c_char, curr[i as usize][j as usize], ); j += 1; j; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } printf(b\"\\nThe Maximum Claim Table:\\n\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < p { j = 0 as libc::c_int; while j < r { printf( b\"\\t%d\\0\" as *const u8 as *const libc::c_char, max_claim[i as usize][j as usize], ); j += 1; j; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } i = 0 as libc::c_int; while i < p { j = 0 as libc::c_int; while j < r { alloc[j as usize] += curr[i as usize][j as usize]; j += 1; j; } i += 1; i; } printf(b\"\\nAllocated resources: \\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < r { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, alloc[i as usize]); i += 1; i; } i = 0 as libc::c_int; while i < r { avl[i as usize] = max_res[i as usize] - alloc[i as usize]; i += 1; i; } printf(b\"\\nAvailable resources: \\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < r { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, avl[i as usize]); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); while count != 0 as libc::c_int { safe = 0 as libc::c_int != 0; i = 0 as libc::c_int; while i < p { if running[i as usize] != 0 { exec = 1 as libc::c_int; j = 0 as libc::c_int; while j < r { if max_claim[i as usize][j as usize] - curr[i as usize][j as usize] > avl[j as usize] { exec = 0 as libc::c_int; break; } else { j += 1; j; } } if exec != 0 { printf( b\"\\nProcess%d is executing.\\n\\0\" as *const u8 as *const libc::c_char, i + 1 as libc::c_int, ); running[i as usize] = 0 as libc::c_int; count -= 1; count; safe = 1 as libc::c_int != 0; j = 0 as libc::c_int; while j < r { avl[j as usize] += curr[i as usize][j as usize]; j += 1; j; } break; } } i += 1; i; } if !safe { printf( b\"\\nThe processes are in unsafe state.\\0\" as *const u8 as *const libc::c_char, ); break; } else { if safe { printf( b\"\\nThe process is in safe state.\\0\" as *const u8 as *const libc::c_char, ); } printf(b\"\\nAvailable vector: \\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < r { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, avl[i as usize]); i += 1; i; } } } return 0 as libc::c_int; }" }, { "index": 905, "before": "void powerset(char **v, int n, struct node *up) { \tstruct node me; \tif (!n) { \t\tputchar('['); \t\twhile (up) { \t\t\tprintf(\" %s\", up->s); \t\t\tup = up->prev; \t\t} \t\tputs(\" ]\"); \t} else { \t\tme.s = *v; \t\tme.prev = up; \t\tpowerset(v + 1, n - 1, up); \t\tpowerset(v + 1, n - 1, &me); \t} }", "after": "pub unsafe extern \"C\" fn powerset( mut v: *mut *mut libc::c_char, mut n: libc::c_int, mut up: *mut node, ) { let mut me: node = node { s: 0 as *mut libc::c_char, prev: 0 as *mut node, }; if n == 0 { putchar('[' as i32); while !up.is_null() { printf(b\" %s\\0\" as *const u8 as *const libc::c_char, (*up).s); up = (*up).prev; } puts(b\" ]\\0\" as *const u8 as *const libc::c_char); } else { me.s = *v; me.prev = up; powerset(v.offset(1 as libc::c_int as isize), n - 1 as libc::c_int, up); powerset(v.offset(1 as libc::c_int as isize), n - 1 as libc::c_int, &mut me); }; }" }, { "index": 906, "before": "int main(int argc, char **argv) { \tpowerset(argv + 1, argc - 1, 0); \treturn 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { powerset( argv.offset(1 as libc::c_int as isize), argc - 1 as libc::c_int, 0 as *mut node, ); return 0 as libc::c_int; }" }, { "index": 907, "before": "int main() { \tf_int funcs[10]; \tint i; \tfor (i = 0; i < 10; i++) funcs[i] = dupf(i); \tfor (i = 0; i < 9; i++) \t\tprintf(\"func[%d]: %d\\n\", i, funcs[i]()); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut funcs: [f_int; 10] = [None; 10]; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 10 as libc::c_int { funcs[i as usize] = dupf(i); i += 1; i; } i = 0 as libc::c_int; while i < 9 as libc::c_int { printf( b\"func[%d]: %d\\n\\0\" as *const u8 as *const libc::c_char, i, ::core::mem::transmute::< _, fn() -> libc::c_int, >((funcs[i as usize]).expect(\"non-null function pointer\"))(), ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 908, "before": "f_int dupf(int v) { \tsize_t len = (void*)dupf - (void*)_tmpl; \tf_int ret = mmap(NULL, len, PROT, FLAGS, 0, 0); \tchar *p; \tif(ret == MAP_FAILED) { \t\tperror(\"mmap\"); \t\texit(-1); \t} \tmemcpy(ret, _tmpl, len); \tfor (p = (char*)ret; p < (char*)ret + len - sizeof(int); p++) \t\tif (*(int *)p == TAG) *(int *)p = v; \treturn ret; }", "after": "pub unsafe extern \"C\" fn dupf(mut v: libc::c_int) -> f_int { let mut len: size_t = (::core::mem::transmute::< Option:: f_int>, *mut libc::c_void, >(Some(dupf as unsafe extern \"C\" fn(libc::c_int) -> f_int))) .offset_from( ::core::mem::transmute::< Option:: libc::c_int>, *mut libc::c_void, >( Some( ::core::mem::transmute::< unsafe extern \"C\" fn() -> libc::c_int, unsafe extern \"C\" fn() -> libc::c_int, >(_tmpl), ), ), ) as libc::c_long as size_t; let mut ret: f_int = ::core::mem::transmute::< *mut libc::c_void, f_int, >( mmap( 0 as *mut libc::c_void, len, 0x4 as libc::c_int | 0x2 as libc::c_int, 0x2 as libc::c_int | 0x20 as libc::c_int, 0 as libc::c_int, 0 as libc::c_int as __off_t, ), ); let mut p: *mut libc::c_char = 0 as *mut libc::c_char; if ret == ::core::mem::transmute::< *mut libc::c_void, f_int, >(-(1 as libc::c_int) as *mut libc::c_void) { perror(b\"mmap\\0\" as *const u8 as *const libc::c_char); exit(-(1 as libc::c_int)); } memcpy( ::core::mem::transmute::(ret), ::core::mem::transmute::< Option:: libc::c_int>, *const libc::c_void, >( Some( ::core::mem::transmute::< unsafe extern \"C\" fn() -> libc::c_int, unsafe extern \"C\" fn() -> libc::c_int, >(_tmpl), ), ), len, ); p = ::core::mem::transmute::(ret); while p < (::core::mem::transmute::(ret)) .offset(len as isize) .offset(-(::core::mem::size_of::() as libc::c_ulong as isize)) { if *(p as *mut libc::c_int) as libc::c_uint == 0xdeadbeef as libc::c_uint { *(p as *mut libc::c_int) = v; } p = p.offset(1); p; } return ret; }" }, { "index": 909, "before": "int main(void) { int a[3] = {1, 3, -5}; int b[3] = {4, -2, -1}; printf(\"%d\\n\", dot_product(a, b, sizeof(a) / sizeof(a[0]))); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut a: [libc::c_int; 3] = [ 1 as libc::c_int, 3 as libc::c_int, -(5 as libc::c_int), ]; let mut b: [libc::c_int; 3] = [ 4 as libc::c_int, -(2 as libc::c_int), -(1 as libc::c_int), ]; printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, dot_product( a.as_mut_ptr(), b.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 3]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong), ), ); return 0 as libc::c_int; }" }, { "index": 910, "before": "int dot_product(int *a, int *b, size_t n) { int sum = 0; size_t i; for (i = 0; i < n; i++) { sum += a[i] * b[i]; } return sum; }", "after": "pub unsafe extern \"C\" fn dot_product( mut a: *mut libc::c_int, mut b: *mut libc::c_int, mut n: size_t, ) -> libc::c_int { let mut sum: libc::c_int = 0 as libc::c_int; let mut i: size_t = 0; i = 0 as libc::c_int as size_t; while i < n { sum += *a.offset(i as isize) * *b.offset(i as isize); i = i.wrapping_add(1); i; } return sum; }" }, { "index": 911, "before": "int main() { \tint i; \tpoint v = gen_xy(PTS, 10); \tpoint c = lloyd(v, PTS, K); \tprint_eps(v, PTS, c, K); \t// free(v); free(c); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut v: point = gen_xy( 100000 as libc::c_int, 10 as libc::c_int as libc::c_double, ); let mut c: point = lloyd(v, 100000 as libc::c_int, 11 as libc::c_int); print_eps(v, 100000 as libc::c_int, c, 11 as libc::c_int); return 0 as libc::c_int; }" }, { "index": 912, "before": "int nearest(point pt, point cent, int n_cluster, double *d2) { \tint i, min_i; \tpoint c; \tdouble d, min_d; #define for_n for (c = cent, i = 0; i < n_cluster; i++, c++) \tfor_n \t{ \t\tmin_d = HUGE_VAL; \t\tmin_i = pt->group; \t\tfor_n \t\t{ \t\t\tif (min_d > (d = dist2(c, pt))) \t\t\t{ \t\t\t\tmin_d = d; \t\t\t\tmin_i = i; \t\t\t} \t\t} \t}", "after": "pub unsafe extern \"C\" fn nearest( mut pt: point, mut cent: point, mut n_cluster: libc::c_int, mut d2: *mut libc::c_double, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut min_i: libc::c_int = 0; let mut c: point = 0 as *mut point_t; let mut d: libc::c_double = 0.; let mut min_d: libc::c_double = 0.; c = cent; i = 0 as libc::c_int; while i < n_cluster { min_d = ::core::f64::INFINITY; min_i = (*pt).group; c = cent; i = 0 as libc::c_int; while i < n_cluster { d = dist2(c, pt); if min_d > d { min_d = d; min_i = i; } i += 1; i; c = c.offset(1); c; } i += 1; i; c = c.offset(1); c; } if !d2.is_null() { *d2 = min_d; } return min_i; }" }, { "index": 913, "before": "point gen_xy(int count, double radius) { \tdouble ang, r; \tpoint p, pt = malloc(sizeof(point_t) * count); \t/* note: this is not a uniform 2-d distribution */ \tfor (p = pt + count; p-- > pt;) \t{ \t\tang = randf(2 * M_PI); \t\tr = randf(radius); \t\tp->x = r * cos(ang); \t\tp->y = r * sin(ang); \t} \treturn pt; }", "after": "pub unsafe extern \"C\" fn gen_xy( mut count: libc::c_int, mut radius: libc::c_double, ) -> point { let mut ang: libc::c_double = 0.; let mut r: libc::c_double = 0.; let mut p: point = 0 as *mut point_t; let mut pt: point = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(count as libc::c_ulong), ) as point; p = pt.offset(count as isize); loop { let fresh0 = p; p = p.offset(-1); if !(fresh0 > pt) { break; } ang = randf(2 as libc::c_int as libc::c_double * 3.14159265358979323846f64); r = randf(radius); (*p).x = r * cos(ang); (*p).y = r * sin(ang); } return pt; }" }, { "index": 914, "before": "double randf(double m) { \treturn m * rand() / (RAND_MAX - 1.); }", "after": "pub unsafe extern \"C\" fn randf(mut m: libc::c_double) -> libc::c_double { return m * rand() as libc::c_double / (2147483647 as libc::c_int as libc::c_double - 1.0f64); }" }, { "index": 915, "before": "point lloyd(point pts, int len, int n_cluster) { \tint i, j, min_i; \tint changed; \tpoint cent = malloc(sizeof(point_t) * n_cluster), p, c; \t/* assign init grouping randomly */ \t//for_len p->group = j % n_cluster; \t/* or call k++ init */ \tkpp(pts, len, cent, n_cluster); \tdo \t{ \t\t/* group element for centroids are used as counters */ \t\tfor_n \t\t{ \t\t\tc->group = 0; \t\t\tc->x = c->y = 0; \t\t} \t\tfor_len \t\t{ \t\t\tc = cent + p->group; \t\t\tc->group++; \t\t\tc->x += p->x; \t\t\tc->y += p->y; \t\t} \t\tfor_n \t\t{ \t\t\tc->x /= c->group; \t\t\tc->y /= c->group; \t\t} \t\tchanged = 0; \t\t/* find closest centroid of each point */ \t\tfor_len \t\t{ \t\t\tmin_i = nearest(p, cent, n_cluster, 0); \t\t\tif (min_i != p->group) \t\t\t{ \t\t\t\tchanged++; \t\t\t\tp->group = min_i; \t\t\t} \t\t} \t} while (changed > (len >> 10)); /* stop when 99.9% of points are good */ \tfor_n { c->group = i; } \treturn cent; }", "after": "pub unsafe extern \"C\" fn lloyd( mut pts: point, mut len: libc::c_int, mut n_cluster: libc::c_int, ) -> point { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut min_i: libc::c_int = 0; let mut changed: libc::c_int = 0; let mut cent: point = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(n_cluster as libc::c_ulong), ) as point; let mut p: point = 0 as *mut point_t; let mut c: point = 0 as *mut point_t; kpp(pts, len, cent, n_cluster); loop { c = cent; i = 0 as libc::c_int; while i < n_cluster { (*c).group = 0 as libc::c_int; (*c).y = 0 as libc::c_int as libc::c_double; (*c).x = (*c).y; i += 1; i; c = c.offset(1); c; } j = 0 as libc::c_int; p = pts; while j < len { c = cent.offset((*p).group as isize); (*c).group += 1; (*c).group; (*c).x += (*p).x; (*c).y += (*p).y; j += 1; j; p = p.offset(1); p; } c = cent; i = 0 as libc::c_int; while i < n_cluster { (*c).x /= (*c).group as libc::c_double; (*c).y /= (*c).group as libc::c_double; i += 1; i; c = c.offset(1); c; } changed = 0 as libc::c_int; j = 0 as libc::c_int; p = pts; while j < len { min_i = nearest(p, cent, n_cluster, 0 as *mut libc::c_double); if min_i != (*p).group { changed += 1; changed; (*p).group = min_i; } j += 1; j; p = p.offset(1); p; } if !(changed > len >> 10 as libc::c_int) { break; } } c = cent; i = 0 as libc::c_int; while i < n_cluster { (*c).group = i; i += 1; i; c = c.offset(1); c; } return cent; }" }, { "index": 916, "before": "void print_eps(point pts, int len, point cent, int n_cluster) { #define W 400 #define H 400 \tint i, j; \tpoint p, c; \tdouble min_x, max_x, min_y, max_y, scale, cx, cy; \tdouble *colors = malloc(sizeof(double) * n_cluster * 3); \tfor_n \t{ \t\tcolors[3 * i + 0] = (3 * (i + 1) % 11) / 11.; \t\tcolors[3 * i + 1] = (7 * i % 11) / 11.; \t\tcolors[3 * i + 2] = (9 * i % 11) / 11.; \t}", "after": "pub unsafe extern \"C\" fn print_eps( mut pts: point, mut len: libc::c_int, mut cent: point, mut n_cluster: libc::c_int, ) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut p: point = 0 as *mut point_t; let mut c: point = 0 as *mut point_t; let mut min_x: libc::c_double = 0.; let mut max_x: libc::c_double = 0.; let mut min_y: libc::c_double = 0.; let mut max_y: libc::c_double = 0.; let mut scale: libc::c_double = 0.; let mut cx: libc::c_double = 0.; let mut cy: libc::c_double = 0.; let mut colors: *mut libc::c_double = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(n_cluster as libc::c_ulong) .wrapping_mul(3 as libc::c_int as libc::c_ulong), ) as *mut libc::c_double; c = cent; i = 0 as libc::c_int; while i < n_cluster { *colors .offset( (3 as libc::c_int * i + 0 as libc::c_int) as isize, ) = (3 as libc::c_int * (i + 1 as libc::c_int) % 11 as libc::c_int) as libc::c_double / 11.0f64; *colors .offset( (3 as libc::c_int * i + 1 as libc::c_int) as isize, ) = (7 as libc::c_int * i % 11 as libc::c_int) as libc::c_double / 11.0f64; *colors .offset( (3 as libc::c_int * i + 2 as libc::c_int) as isize, ) = (9 as libc::c_int * i % 11 as libc::c_int) as libc::c_double / 11.0f64; i += 1; i; c = c.offset(1); c; } min_y = ::core::f64::INFINITY; min_x = min_y; max_y = -min_x; max_x = max_y; j = 0 as libc::c_int; p = pts; while j < len { if max_x < (*p).x { max_x = (*p).x; } if min_x > (*p).x { min_x = (*p).x; } if max_y < (*p).y { max_y = (*p).y; } if min_y > (*p).y { min_y = (*p).y; } j += 1; j; p = p.offset(1); p; } scale = 400 as libc::c_int as libc::c_double / (max_x - min_x); if scale > 400 as libc::c_int as libc::c_double / (max_y - min_y) { scale = 400 as libc::c_int as libc::c_double / (max_y - min_y); } cx = (max_x + min_x) / 2 as libc::c_int as libc::c_double; cy = (max_y + min_y) / 2 as libc::c_int as libc::c_double; printf( b\"%%!PS-Adobe-3.0\\n%%%%BoundingBox: -5 -5 %d %d\\n\\0\" as *const u8 as *const libc::c_char, 400 as libc::c_int + 10 as libc::c_int, 400 as libc::c_int + 10 as libc::c_int, ); printf( b\"/l {rlineto} def /m {rmoveto} def\\n/c { .25 sub exch .25 sub exch .5 0 360 arc fill } def\\n/s { moveto -2 0 m 2 2 l 2 -2 l -2 -2 l closepath \\tgsave 1 setgray fill grestore gsave 3 setlinewidth 1 setgray stroke grestore 0 setgray stroke }def\\n\\0\" as *const u8 as *const libc::c_char, ); c = cent; i = 0 as libc::c_int; while i < n_cluster { printf( b\"%g %g %g setrgbcolor\\n\\0\" as *const u8 as *const libc::c_char, *colors.offset((3 as libc::c_int * i) as isize), *colors.offset((3 as libc::c_int * i + 1 as libc::c_int) as isize), *colors.offset((3 as libc::c_int * i + 2 as libc::c_int) as isize), ); j = 0 as libc::c_int; p = pts; while j < len { if !((*p).group != i) { printf( b\"%.3f %.3f c\\n\\0\" as *const u8 as *const libc::c_char, ((*p).x - cx) * scale + (400 as libc::c_int / 2 as libc::c_int) as libc::c_double, ((*p).y - cy) * scale + (400 as libc::c_int / 2 as libc::c_int) as libc::c_double, ); } j += 1; j; p = p.offset(1); p; } printf( b\"\\n0 setgray %g %g s\\n\\0\" as *const u8 as *const libc::c_char, ((*c).x - cx) * scale + (400 as libc::c_int / 2 as libc::c_int) as libc::c_double, ((*c).y - cy) * scale + (400 as libc::c_int / 2 as libc::c_int) as libc::c_double, ); i += 1; i; c = c.offset(1); c; } printf(b\"\\n%%%%EOF\\0\" as *const u8 as *const libc::c_char); free(colors as *mut libc::c_void); }" }, { "index": 917, "before": "double dist2(point a, point b) { \tdouble x = a->x - b->x, y = a->y - b->y; \treturn x * x + y * y; }", "after": "pub unsafe extern \"C\" fn dist2(mut a: point, mut b: point) -> libc::c_double { let mut x: libc::c_double = (*a).x - (*b).x; let mut y: libc::c_double = (*a).y - (*b).y; return x * x + y * y; }" }, { "index": 918, "before": "void kpp(point pts, int len, point cent, int n_cent) { #define for_len for (j = 0, p = pts; j < len; j++, p++) \tint i, j; \tint n_cluster; \tdouble sum, *d = malloc(sizeof(double) * len); \tpoint p, c; \tcent[0] = pts[rand() % len]; \tfor (n_cluster = 1; n_cluster < n_cent; n_cluster++) \t{ \t\tsum = 0; \t\tfor_len \t\t{ \t\t\tnearest(p, cent, n_cluster, d + j); \t\t\tsum += d[j]; \t\t} \t\tsum = randf(sum); \t\tfor_len \t\t{ \t\t\tif ((sum -= d[j]) > 0) \t\t\t\tcontinue; \t\t\tcent[n_cluster] = pts[j]; \t\t\tbreak; \t\t} \t} \tfor_len p->group = nearest(p, cent, n_cluster, 0); \tfree(d); }", "after": "pub unsafe extern \"C\" fn kpp( mut pts: point, mut len: libc::c_int, mut cent: point, mut n_cent: libc::c_int, ) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut n_cluster: libc::c_int = 0; let mut sum: libc::c_double = 0.; let mut d: *mut libc::c_double = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(len as libc::c_ulong), ) as *mut libc::c_double; let mut p: point = 0 as *mut point_t; let mut c: point = 0 as *mut point_t; *cent.offset(0 as libc::c_int as isize) = *pts.offset((rand() % len) as isize); n_cluster = 1 as libc::c_int; while n_cluster < n_cent { sum = 0 as libc::c_int as libc::c_double; j = 0 as libc::c_int; p = pts; while j < len { nearest(p, cent, n_cluster, d.offset(j as isize)); sum += *d.offset(j as isize); j += 1; j; p = p.offset(1); p; } sum = randf(sum); j = 0 as libc::c_int; p = pts; while j < len { sum -= *d.offset(j as isize); if sum > 0 as libc::c_int as libc::c_double { j += 1; j; p = p.offset(1); p; } else { *cent.offset(n_cluster as isize) = *pts.offset(j as isize); break; } } n_cluster += 1; n_cluster; } j = 0 as libc::c_int; p = pts; while j < len { (*p).group = nearest(p, cent, n_cluster, 0 as *mut libc::c_double); j += 1; j; p = p.offset(1); p; } free(d as *mut libc::c_void); }" }, { "index": 919, "before": "void bf() { for (f = lo;f <= hi; f++) if ((!unique) || ((f != a) && (f != c) && (f != d) && (f != g) && (f != e))) { b = e + f - c; if ((b >= lo) && (b <= hi) && ((!unique) || ((b != a) && (b != c) && (b != d) && (b != g) && (b != e) && (b != f)))) { solutions++; if (show) printf(\"%d %d %d %d %d %d %d\\n\",a,b,c,d,e,f,g); } } }", "after": "pub unsafe extern \"C\" fn bf() { f = lo; while f <= hi { if unique == 0 || f != a && f != c && f != d && f != g && f != e { b = e + f - c; if b >= lo && b <= hi && (unique == 0 || b != a && b != c && b != d && b != g && b != e && b != f) { solutions += 1; solutions; if show != 0 { printf( b\"%d %d %d %d %d %d %d\\n\\0\" as *const u8 as *const libc::c_char, a, b, c, d, e, f, g, ); } } } f += 1; f; } }" }, { "index": 920, "before": "void ge() { for (e = lo;e <= hi; e++) if ((!unique) || ((e != a) && (e != c) && (e != d))) { g = d + e; if ((g >= lo) && (g <= hi) && ((!unique) || ((g != a) && (g != c) && (g != d) && (g != e)))) bf(); } }", "after": "pub unsafe extern \"C\" fn ge() { e = lo; while e <= hi { if unique == 0 || e != a && e != c && e != d { g = d + e; if g >= lo && g <= hi && (unique == 0 || g != a && g != c && g != d && g != e) { bf(); } } e += 1; e; } }" }, { "index": 921, "before": "void acd() { for (c = lo;c <= hi; c++) for (d = lo;d <= hi; d++) if ((!unique) || (c != d)) { a = c + d; if ((a >= lo) && (a <= hi) && ((!unique) || ((c != 0) && (d != 0)))) ge(); } }", "after": "pub unsafe extern \"C\" fn acd() { c = lo; while c <= hi { d = lo; while d <= hi { if unique == 0 || c != d { a = c + d; if a >= lo && a <= hi && (unique == 0 || c != 0 as libc::c_int && d != 0 as libc::c_int) { ge(); } } d += 1; d; } c += 1; c; } }" }, { "index": 922, "before": "void foursquares(int plo,int phi, int punique,int pshow) { lo = plo; hi = phi; unique = punique; show = pshow; solutions = 0; printf(\"\\n\"); acd(); if (unique) printf(\"\\n%d unique solutions in %d to %d\\n\",solutions,lo,hi); else printf(\"\\n%d non-unique solutions in %d to %d\\n\",solutions,lo,hi); }", "after": "pub unsafe extern \"C\" fn foursquares( mut plo: libc::c_int, mut phi: libc::c_int, mut punique: libc::c_int, mut pshow: libc::c_int, ) { lo = plo; hi = phi; unique = punique; show = pshow; solutions = 0 as libc::c_int; printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); acd(); if unique != 0 { printf( b\"\\n%d unique solutions in %d to %d\\n\\0\" as *const u8 as *const libc::c_char, solutions, lo, hi, ); } else { printf( b\"\\n%d non-unique solutions in %d to %d\\n\\0\" as *const u8 as *const libc::c_char, solutions, lo, hi, ); }; }" }, { "index": 923, "before": "void freeNode(Node *ptr) { if (ptr == NULL) { return; } freeNode(ptr->next); ptr->next = NULL; free(ptr); }", "after": "pub unsafe extern \"C\" fn freeNode(mut ptr: *mut Node) { if ptr.is_null() { return; } freeNode((*ptr).next); (*ptr).next = 0 as *mut tNode; free(ptr as *mut libc::c_void); }" }, { "index": 924, "before": "void print(Node *ptr) { printf(\"[\"); if (ptr != NULL) { printf(\"(%d, %d)\", ptr->data.x, ptr->data.y); ptr = ptr->next; } while (ptr != NULL) { printf(\", (%d, %d)\", ptr->data.x, ptr->data.y); ptr = ptr->next; } printf(\"]\"); }", "after": "pub unsafe extern \"C\" fn print(mut ptr: *mut Node) { printf(b\"[\\0\" as *const u8 as *const libc::c_char); if !ptr.is_null() { printf( b\"(%d, %d)\\0\" as *const u8 as *const libc::c_char, (*ptr).data.x, (*ptr).data.y, ); ptr = (*ptr).next; } while !ptr.is_null() { printf( b\", (%d, %d)\\0\" as *const u8 as *const libc::c_char, (*ptr).data.x, (*ptr).data.y, ); ptr = (*ptr).next; } printf(b\"]\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 925, "before": "int comp(const void *lhs, const void *rhs) { Point lp = *((Point *)lhs); Point rp = *((Point *)rhs); if (lp.x < rp.x) return -1; if (rp.x < lp.x) return 1; return 0; }", "after": "pub unsafe extern \"C\" fn comp( mut lhs: *const libc::c_void, mut rhs: *const libc::c_void, ) -> libc::c_int { let mut lp: Point = *(lhs as *mut Point); let mut rp: Point = *(rhs as *mut Point); if lp.x < rp.x { return -(1 as libc::c_int); } if rp.x < lp.x { return 1 as libc::c_int; } return 0 as libc::c_int; }" }, { "index": 926, "before": "int main() { Point points[] = { {16, 3}, {12, 17}, { 0, 6}, {-4, -6}, {16, 6}, {16, -7}, {16, -3}, {17, -4}, { 5, 19}, {19, -8}, { 3, 16}, {12, 13}, { 3, -4}, {17, 5}, {-3, 15}, {-3, -9}, { 0, 11}, {-9, -3}, {-4, -2}, {12, 10} }; Node *hull = convexHull(sizeof(points) / sizeof(Point), points); printf(\"Convex Hull: \"); print(hull); printf(\"\\n\"); freeNode(hull); hull = NULL; return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut points: [Point; 20] = [ { let mut init = tPoint { x: 16 as libc::c_int, y: 3 as libc::c_int, }; init }, { let mut init = tPoint { x: 12 as libc::c_int, y: 17 as libc::c_int, }; init }, { let mut init = tPoint { x: 0 as libc::c_int, y: 6 as libc::c_int, }; init }, { let mut init = tPoint { x: -(4 as libc::c_int), y: -(6 as libc::c_int), }; init }, { let mut init = tPoint { x: 16 as libc::c_int, y: 6 as libc::c_int, }; init }, { let mut init = tPoint { x: 16 as libc::c_int, y: -(7 as libc::c_int), }; init }, { let mut init = tPoint { x: 16 as libc::c_int, y: -(3 as libc::c_int), }; init }, { let mut init = tPoint { x: 17 as libc::c_int, y: -(4 as libc::c_int), }; init }, { let mut init = tPoint { x: 5 as libc::c_int, y: 19 as libc::c_int, }; init }, { let mut init = tPoint { x: 19 as libc::c_int, y: -(8 as libc::c_int), }; init }, { let mut init = tPoint { x: 3 as libc::c_int, y: 16 as libc::c_int, }; init }, { let mut init = tPoint { x: 12 as libc::c_int, y: 13 as libc::c_int, }; init }, { let mut init = tPoint { x: 3 as libc::c_int, y: -(4 as libc::c_int), }; init }, { let mut init = tPoint { x: 17 as libc::c_int, y: 5 as libc::c_int, }; init }, { let mut init = tPoint { x: -(3 as libc::c_int), y: 15 as libc::c_int, }; init }, { let mut init = tPoint { x: -(3 as libc::c_int), y: -(9 as libc::c_int), }; init }, { let mut init = tPoint { x: 0 as libc::c_int, y: 11 as libc::c_int, }; init }, { let mut init = tPoint { x: -(9 as libc::c_int), y: -(3 as libc::c_int), }; init }, { let mut init = tPoint { x: -(4 as libc::c_int), y: -(2 as libc::c_int), }; init }, { let mut init = tPoint { x: 12 as libc::c_int, y: 10 as libc::c_int, }; init }, ]; let mut hull: *mut Node = convexHull( (::core::mem::size_of::<[Point; 20]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, points.as_mut_ptr(), ); printf(b\"Convex Hull: \\0\" as *const u8 as *const libc::c_char); print(hull); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); freeNode(hull); hull = 0 as *mut Node; return 0 as libc::c_int; }" }, { "index": 927, "before": "bool ccw(const Point *a, const Point *b, const Point *c) { return (b->x - a->x) * (c->y - a->y) > (b->y - a->y) * (c->x - a->x); }", "after": "pub unsafe extern \"C\" fn ccw( mut a: *const Point, mut b: *const Point, mut c: *const Point, ) -> bool { return ((*b).x - (*a).x) * ((*c).y - (*a).y) > ((*b).y - (*a).y) * ((*c).x - (*a).x); }" }, { "index": 928, "before": "int main() { int i, j; char k[4]; for (i = 0; i < 16; ++i) { for (j = 32 + i; j < 128; j += 16) { switch (j) { default: sprintf(k, \"%c\", j); break; case 32: sprintf(k, \"Spc\"); break; case 127: sprintf(k, \"Del\"); break; } printf(\"%3d : %-3s \", j, k); } printf(\"\\n\"); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut k: [libc::c_char; 4] = [0; 4]; i = 0 as libc::c_int; while i < 16 as libc::c_int { j = 32 as libc::c_int + i; while j < 128 as libc::c_int { match j { 32 => { sprintf( k.as_mut_ptr(), b\"Spc\\0\" as *const u8 as *const libc::c_char, ); } 127 => { sprintf( k.as_mut_ptr(), b\"Del\\0\" as *const u8 as *const libc::c_char, ); } _ => { sprintf( k.as_mut_ptr(), b\"%c\\0\" as *const u8 as *const libc::c_char, j, ); } } printf( b\"%3d : %-3s \\0\" as *const u8 as *const libc::c_char, j, k.as_mut_ptr(), ); j += 16 as libc::c_int; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 929, "before": "static void _heap_add(heap_t *heap, int c) { if ( (heap->n + 1) > heap->s ) { heap->h = realloc(heap->h, heap->s + heap->cs); heap->s += heap->cs; } heap->h[heap->n] = c; heap->n++; _heap_sort(heap); }", "after": "unsafe extern \"C\" fn _heap_add(mut heap: *mut heap_t, mut c: libc::c_int) { if (*heap).n + 1 as libc::c_int > (*heap).s { (*heap) .h = realloc( (*heap).h as *mut libc::c_void, ((*heap).s + (*heap).cs) as libc::c_ulong, ) as *mut libc::c_int; (*heap).s += (*heap).cs; } *((*heap).h).offset((*heap).n as isize) = c; (*heap).n += 1; (*heap).n; _heap_sort(heap); }" }, { "index": 930, "before": "static int _heap_remove(heap_t *heap) { if ( heap->n > 0 ) { heap->n--; return heap->h[heap->n]; } return -1; }", "after": "unsafe extern \"C\" fn _heap_remove(mut heap: *mut heap_t) -> libc::c_int { if (*heap).n > 0 as libc::c_int { (*heap).n -= 1; (*heap).n; return *((*heap).h).offset((*heap).n as isize); } return -(1 as libc::c_int); }" }, { "index": 931, "before": "void inttobits(int c, int n, char *s) { s[n] = 0; while(n > 0) { s[n-1] = (c%2) + '0'; c >>= 1; n--; } }", "after": "pub unsafe extern \"C\" fn inttobits( mut c: libc::c_int, mut n: libc::c_int, mut s: *mut libc::c_char, ) { *s.offset(n as isize) = 0 as libc::c_int as libc::c_char; while n > 0 as libc::c_int { *s .offset( (n - 1 as libc::c_int) as isize, ) = (c % 2 as libc::c_int + '0' as i32) as libc::c_char; c >>= 1 as libc::c_int; n -= 1; n; } }" }, { "index": 932, "before": "static void _heap_destroy(heap_t *heap) { free(heap->h); free(heap); }", "after": "unsafe extern \"C\" fn _heap_destroy(mut heap: *mut heap_t) { free((*heap).h as *mut libc::c_void); free(heap as *mut libc::c_void); }" }, { "index": 933, "before": "void free_huffman_codes(huffcode_t **c) { int i; for(i=0; i < BYTES; i++) free(c[i]); free(c); }", "after": "pub unsafe extern \"C\" fn free_huffman_codes(mut c: *mut *mut huffcode_t) { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 256 as libc::c_int { free(*c.offset(i as isize) as *mut libc::c_void); i += 1; i; } free(c as *mut libc::c_void); }" }, { "index": 934, "before": "int main() { huffcode_t **r; int i; char strbit[MAXBITSPERCODE]; const char *p; long freqs[BYTES]; memset(freqs, 0, sizeof freqs); p = test; while(*p != '\\0') freqs[*p++]++; r = create_huffman_codes(freqs); for(i=0; i < BYTES; i++) { if ( r[i] != NULL ) { inttobits(r[i]->code, r[i]->nbits, strbit); printf(\"%c (%d) %s\\n\", i, r[i]->code, strbit); } } free_huffman_codes(r); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut r: *mut *mut huffcode_t = 0 as *mut *mut huffcode_t; let mut i: libc::c_int = 0; let mut strbit: [libc::c_char; 100] = [0; 100]; let mut p: *const libc::c_char = 0 as *const libc::c_char; let mut freqs: [libc::c_long; 256] = [0; 256]; memset( freqs.as_mut_ptr() as *mut libc::c_void, 0 as libc::c_int, ::core::mem::size_of::<[libc::c_long; 256]>() as libc::c_ulong, ); p = test; while *p as libc::c_int != '\\0' as i32 { let fresh3 = p; p = p.offset(1); freqs[*fresh3 as usize] += 1; freqs[*fresh3 as usize]; } r = create_huffman_codes(freqs.as_mut_ptr()); i = 0 as libc::c_int; while i < 256 as libc::c_int { if !(*r.offset(i as isize)).is_null() { inttobits( (**r.offset(i as isize)).code, (**r.offset(i as isize)).nbits, strbit.as_mut_ptr(), ); printf( b\"%c (%d) %s\\n\\0\" as *const u8 as *const libc::c_char, i, (**r.offset(i as isize)).code, strbit.as_mut_ptr(), ); } i += 1; i; } free_huffman_codes(r); return 0 as libc::c_int; }" }, { "index": 935, "before": "static void _heap_sort(heap_t *heap) { int i=1, j=2; /* gnome sort */ int *a = heap->h; while(i < heap->n) { /* smaller values are kept at the end */ if ( heap->f[a[i-1]] >= heap->f[a[i]] ) { i = j; j++; } else { swap_(i-1, i); i--; i = (i==0) ? j++ : i; } } }", "after": "unsafe extern \"C\" fn _heap_sort(mut heap: *mut heap_t) { let mut i: libc::c_int = 1 as libc::c_int; let mut j: libc::c_int = 2 as libc::c_int; let mut a: *mut libc::c_int = (*heap).h; while i < (*heap).n { if *((*heap).f).offset(*a.offset((i - 1 as libc::c_int) as isize) as isize) >= *((*heap).f).offset(*a.offset(i as isize) as isize) { i = j; j += 1; j; } else { let mut t_: libc::c_int = 0; t_ = *a.offset((i - 1 as libc::c_int) as isize); *a.offset((i - 1 as libc::c_int) as isize) = *a.offset(i as isize); *a.offset(i as isize) = t_; i -= 1; i; i = if i == 0 as libc::c_int { let fresh0 = j; j = j + 1; fresh0 } else { i }; } } }" }, { "index": 936, "before": "int main() { \tcomb(5, 3, 0, 0); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { comb( 5 as libc::c_int, 3 as libc::c_int, 0 as libc::c_int as marker, 0 as libc::c_int, ); return 0 as libc::c_int; }" }, { "index": 937, "before": "void comb(int pool, int need, marker chosen, int at) { \tif (pool < need + at) return; /* not enough bits left */ \tif (!need) { \t\t/* got all we needed; print the thing. if other actions are \t\t * desired, we could have passed in a callback function. */ \t\tfor (at = 0; at < pool; at++) \t\t\tif (chosen & (one << at)) printf(\"%d \", at); \t\tprintf(\"\\n\"); \t\treturn; \t} \t/* if we choose the current item, \"or\" (|) the bit to mark it so. */ \tcomb(pool, need - 1, chosen | (one << at), at + 1); \tcomb(pool, need, chosen, at + 1); /* or don't choose it, go to next */ }", "after": "pub unsafe extern \"C\" fn comb( mut pool: libc::c_int, mut need: libc::c_int, mut chosen: marker, mut at: libc::c_int, ) { if pool < need + at { return; } if need == 0 { at = 0 as libc::c_int; while at < pool { if chosen & one << at != 0 { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, at); } at += 1; at; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return; } comb(pool, need - 1 as libc::c_int, chosen | one << at, at + 1 as libc::c_int); comb(pool, need, chosen, at + 1 as libc::c_int); }" }, { "index": 938, "before": "void init_months() { \tint i; \tif ((!(year % 4) && (year % 100)) || !(year % 400)) \t\tmonths[1].days = 29; \tyear--; \tmonths[0].start_wday \t\t= (year * 365 + year/4 - year/100 + year/400 + 1) % 7; \tfor (i = 1; i < 12; i++) \t\tmonths[i].start_wday = \t\t\t(months[i-1].start_wday + months[i-1].days) % 7; \tcols = (width + 2) / 22; \twhile (12 % cols) cols--; \tgap = cols - 1 ? (width - 20 * cols) / (cols - 1) : 0; \tif (gap > 4) gap = 4; \tlead = (width - (20 + gap) * cols + gap + 1) / 2; year++; }", "after": "pub unsafe extern \"C\" fn init_months() { let mut i: libc::c_int = 0; if year % 4 as libc::c_int == 0 && year % 100 as libc::c_int != 0 || year % 400 as libc::c_int == 0 { months[1 as libc::c_int as usize].days = 29 as libc::c_int; } year -= 1; year; months[0 as libc::c_int as usize] .start_wday = (year * 365 as libc::c_int + year / 4 as libc::c_int - year / 100 as libc::c_int + year / 400 as libc::c_int + 1 as libc::c_int) % 7 as libc::c_int; i = 1 as libc::c_int; while i < 12 as libc::c_int { months[i as usize] .start_wday = (months[(i - 1 as libc::c_int) as usize].start_wday + months[(i - 1 as libc::c_int) as usize].days) % 7 as libc::c_int; i += 1; i; } cols = (width + 2 as libc::c_int) / 22 as libc::c_int; while 12 as libc::c_int % cols != 0 { cols -= 1; cols; } gap = if cols - 1 as libc::c_int != 0 { (width - 20 as libc::c_int * cols) / (cols - 1 as libc::c_int) } else { 0 as libc::c_int }; if gap > 4 as libc::c_int { gap = 4 as libc::c_int; } lead = (width - (20 as libc::c_int + gap) * cols + gap + 1 as libc::c_int) / 2 as libc::c_int; year += 1; year; }" }, { "index": 939, "before": "int main(int c, char **v) { \tint i, year_set = 0; \tfor (i = 1; i < c; i++) { \t\tif (!strcmp(v[i], \"-w\")) { \t\t\tif (++i == c || (width = atoi(v[i])) < 20) \t\t\t\tgoto bail; \t\t} else if (!year_set) { \t\t\tif (!sscanf(v[i], \"%d\", &year) || year <= 0) \t\t\t\tyear = 1969; \t\t\tyear_set = 1; \t\t} else \t\t\tgoto bail; \t} \tinit_months(); \tprint_year(); \treturn 0; bail:\tfprintf(stderr, \"bad args\\nUsage: %s year [-w width (>= 20)]\\n\", v[0]); \texit(1); }", "after": "unsafe fn main(mut c: libc::c_int, mut v: *mut *mut libc::c_char) -> libc::c_int { let mut current_block: u64; let mut i: libc::c_int = 0; let mut year_set: libc::c_int = 0 as libc::c_int; i = 1 as libc::c_int; loop { if !(i < c) { current_block = 1394248824506584008; break; } if strcmp(*v.offset(i as isize), b\"-w\\0\" as *const u8 as *const libc::c_char) == 0 { i += 1; if i == c || { width = atoi(*v.offset(i as isize)); width < 20 as libc::c_int } { current_block = 2002819764153645144; break; } } else { if !(year_set == 0) { current_block = 2002819764153645144; break; } if sscanf( *v.offset(i as isize), b\"%d\\0\" as *const u8 as *const libc::c_char, &mut year as *mut libc::c_int, ) == 0 || year <= 0 as libc::c_int { year = 1969 as libc::c_int; } year_set = 1 as libc::c_int; } i += 1; i; } match current_block { 2002819764153645144 => { fprintf( stderr, b\"bad args\\nUsage: %s year [-w width (>= 20)]\\n\\0\" as *const u8 as *const libc::c_char, *v.offset(0 as libc::c_int as isize), ); exit(1 as libc::c_int); } _ => { init_months(); print_year(); return 0 as libc::c_int; } }; }" }, { "index": 940, "before": "void space(int n) { while (n-- > 0) putchar(' '); }", "after": "pub unsafe extern \"C\" fn space(mut n: libc::c_int) { loop { let fresh0 = n; n = n - 1; if !(fresh0 > 0 as libc::c_int) { break; } putchar(' ' as i32); }; }" }, { "index": 941, "before": "void print_row(int row) { \tint c, i, from = row * cols, to = from + cols; \tspace(lead); \tfor (c = from; c < to; c++) { \t\ti = strlen(months[c].name); \t\tspace((20 - i)/2); \t\tprintf(\"%s\", months[c].name); \t\tspace(20 - i - (20 - i)/2 + ((c == to - 1) ? 0 : gap)); \t} \tputchar('\\n'); \tspace(lead); \tfor (c = from; c < to; c++) { \t\tfor (i = 0; i < 7; i++) \t\t\tprintf(\"%s%s\", wdays[i], i == 6 ? \"\" : \" \"); \t\tif (c < to - 1) space(gap); \t\telse putchar('\\n'); \t} \twhile (1) { \t\tfor (c = from; c < to; c++) \t\t\tif (months[c].at < months[c].days) break; \t\tif (c == to) break; \t\tspace(lead); \t\tfor (c = from; c < to; c++) { \t\t\tfor (i = 0; i < months[c].start_wday; i++) space(3); \t\t\twhile(i++ < 7 && months[c].at < months[c].days) { \t\t\t\tprintf(\"%2d\", ++months[c].at); \t\t\t\tif (i < 7 || c < to - 1) putchar(' '); \t\t\t} \t\t\twhile (i++ <= 7 && c < to - 1) space(3); \t\t\tif (c < to - 1) space(gap - 1); \t\t\tmonths[c].start_wday = 0; \t\t} \t\tputchar('\\n'); \t} \tputchar('\\n'); }", "after": "pub unsafe extern \"C\" fn print_row(mut row: libc::c_int) { let mut c: libc::c_int = 0; let mut i: libc::c_int = 0; let mut from: libc::c_int = row * cols; let mut to: libc::c_int = from + cols; space(lead); c = from; while c < to { i = strlen(months[c as usize].name) as libc::c_int; space((20 as libc::c_int - i) / 2 as libc::c_int); printf(b\"%s\\0\" as *const u8 as *const libc::c_char, months[c as usize].name); space( 20 as libc::c_int - i - (20 as libc::c_int - i) / 2 as libc::c_int + (if c == to - 1 as libc::c_int { 0 as libc::c_int } else { gap }), ); c += 1; c; } putchar('\\n' as i32); space(lead); c = from; while c < to { i = 0 as libc::c_int; while i < 7 as libc::c_int { printf( b\"%s%s\\0\" as *const u8 as *const libc::c_char, wdays[i as usize], if i == 6 as libc::c_int { b\"\\0\" as *const u8 as *const libc::c_char } else { b\" \\0\" as *const u8 as *const libc::c_char }, ); i += 1; i; } if c < to - 1 as libc::c_int { space(gap); } else { putchar('\\n' as i32); } c += 1; c; } loop { c = from; while c < to { if months[c as usize].at < months[c as usize].days { break; } c += 1; c; } if c == to { break; } space(lead); c = from; while c < to { i = 0 as libc::c_int; while i < months[c as usize].start_wday { space(3 as libc::c_int); i += 1; i; } loop { let fresh1 = i; i = i + 1; if !(fresh1 < 7 as libc::c_int && months[c as usize].at < months[c as usize].days) { break; } months[c as usize].at += 1; printf( b\"%2d\\0\" as *const u8 as *const libc::c_char, months[c as usize].at, ); if i < 7 as libc::c_int || c < to - 1 as libc::c_int { putchar(' ' as i32); } } loop { let fresh2 = i; i = i + 1; if !(fresh2 <= 7 as libc::c_int && c < to - 1 as libc::c_int) { break; } space(3 as libc::c_int); } if c < to - 1 as libc::c_int { space(gap - 1 as libc::c_int); } months[c as usize].start_wday = 0 as libc::c_int; c += 1; c; } putchar('\\n' as i32); } putchar('\\n' as i32); }" }, { "index": 942, "before": "void print_year() { \tint row; \tchar buf[32]; \tsprintf(buf, \"%d\", year); \tspace((width - strlen(buf)) / 2); \tprintf(\"%s\\n\\n\", buf); \tfor (row = 0; row * cols < 12; row++) \t\tprint_row(row); }", "after": "pub unsafe extern \"C\" fn print_year() { let mut row: libc::c_int = 0; let mut buf: [libc::c_char; 32] = [0; 32]; sprintf(buf.as_mut_ptr(), b\"%d\\0\" as *const u8 as *const libc::c_char, year); space( (width as libc::c_ulong) .wrapping_sub(strlen(buf.as_mut_ptr())) .wrapping_div(2 as libc::c_int as libc::c_ulong) as libc::c_int, ); printf(b\"%s\\n\\n\\0\" as *const u8 as *const libc::c_char, buf.as_mut_ptr()); row = 0 as libc::c_int; while row * cols < 12 as libc::c_int { print_row(row); row += 1; row; } }" }, { "index": 943, "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 unsafe extern \"C\" fn push( mut h: *mut heap_t, mut priority: libc::c_int, mut data: *mut libc::c_char, ) { if (*h).len + 1 as libc::c_int >= (*h).size { (*h) .size = if (*h).size != 0 { (*h).size * 2 as libc::c_int } else { 4 as libc::c_int }; (*h) .nodes = realloc( (*h).nodes as *mut libc::c_void, ((*h).size as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut node_t; } let mut i: libc::c_int = (*h).len + 1 as libc::c_int; let mut j: libc::c_int = i / 2 as libc::c_int; while i > 1 as libc::c_int && (*((*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 as libc::c_int; } (*((*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": 944, "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": "unsafe fn main() -> libc::c_int { let mut h: *mut heap_t = calloc( 1 as libc::c_int as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut heap_t; push( h, 3 as libc::c_int, b\"Clear drains\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); push( h, 4 as libc::c_int, b\"Feed cat\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); push( h, 5 as libc::c_int, b\"Make tea\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); push( h, 1 as libc::c_int, b\"Solve RC tasks\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); push( h, 2 as libc::c_int, b\"Tax return\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 5 as libc::c_int { printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, pop(h)); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 945, "before": "bool a(bool in) { printf(\"I am a\\n\"); return in; }", "after": "pub unsafe extern \"C\" fn a(mut in_0: bool) -> bool { printf(b\"I am a\\n\\0\" as *const u8 as *const libc::c_char); return in_0; }" }, { "index": 946, "before": "int main() { bool x; TEST(false, true, &&); // b is not evaluated TEST(true, false, ||); // b is not evaluated TEST(true, false, &&); // b is evaluated TEST(false, false, ||); // b is evaluated return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut x: bool = false; x = a(0 as libc::c_int != 0) as libc::c_int != 0 && b(1 as libc::c_int != 0) as libc::c_int != 0; printf( b\"false && true = %s\\n\\n\\0\" as *const u8 as *const libc::c_char, if x as libc::c_int != 0 { b\"true\\0\" as *const u8 as *const libc::c_char } else { b\"false\\0\" as *const u8 as *const libc::c_char }, ); x = a(1 as libc::c_int != 0) as libc::c_int != 0 || b(0 as libc::c_int != 0) as libc::c_int != 0; printf( b\"true || false = %s\\n\\n\\0\" as *const u8 as *const libc::c_char, if x as libc::c_int != 0 { b\"true\\0\" as *const u8 as *const libc::c_char } else { b\"false\\0\" as *const u8 as *const libc::c_char }, ); x = a(1 as libc::c_int != 0) as libc::c_int != 0 && b(0 as libc::c_int != 0) as libc::c_int != 0; printf( b\"true && false = %s\\n\\n\\0\" as *const u8 as *const libc::c_char, if x as libc::c_int != 0 { b\"true\\0\" as *const u8 as *const libc::c_char } else { b\"false\\0\" as *const u8 as *const libc::c_char }, ); x = a(0 as libc::c_int != 0) as libc::c_int != 0 || b(0 as libc::c_int != 0) as libc::c_int != 0; printf( b\"false || false = %s\\n\\n\\0\" as *const u8 as *const libc::c_char, if x as libc::c_int != 0 { b\"true\\0\" as *const u8 as *const libc::c_char } else { b\"false\\0\" as *const u8 as *const libc::c_char }, ); return 0 as libc::c_int; }" }, { "index": 947, "before": "bool b(bool in) { printf(\"I am b\\n\"); return in; }", "after": "pub unsafe extern \"C\" fn b(mut in_0: bool) -> bool { printf(b\"I am b\\n\\0\" as *const u8 as *const libc::c_char); return in_0; }" }, { "index": 948, "before": "double mean(double *v, int len) { \tdouble sum = 0; \tint i; \tfor (i = 0; i < len; i++) \t\tsum += v[i]; \treturn sum / len; }", "after": "pub unsafe extern \"C\" fn mean( mut v: *mut libc::c_double, mut len: libc::c_int, ) -> libc::c_double { let mut sum: libc::c_double = 0 as libc::c_int as libc::c_double; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < len { sum += *v.offset(i as isize); i += 1; i; } return sum / len as libc::c_double; }" }, { "index": 949, "before": "int main(void) { \tdouble v[] = {1, 2, 2.718, 3, 3.142}; \tint i, len; \tfor (len = 5; len >= 0; len--) { \t\tprintf(\"mean[\"); \t\tfor (i = 0; i < len; i++) \t\t\tprintf(i ? \", %g\" : \"%g\", v[i]); \t\tprintf(\"] = %g\\n\", mean(v, len)); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut v: [libc::c_double; 5] = [ 1 as libc::c_int as libc::c_double, 2 as libc::c_int as libc::c_double, 2.718f64, 3 as libc::c_int as libc::c_double, 3.142f64, ]; let mut i: libc::c_int = 0; let mut len: libc::c_int = 0; len = 5 as libc::c_int; while len >= 0 as libc::c_int { printf(b\"mean[\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < len { printf( if i != 0 { b\", %g\\0\" as *const u8 as *const libc::c_char } else { b\"%g\\0\" as *const u8 as *const libc::c_char }, v[i as usize], ); i += 1; i; } printf( b\"] = %g\\n\\0\" as *const u8 as *const libc::c_char, mean(v.as_mut_ptr(), len), ); len -= 1; len; } return 0 as libc::c_int; }" }, { "index": 950, "before": "int main() { \tint i; \tprintf(\"\" \t\t\"\"); \tfor (i = 0; i < 4; i++) { \t\tprintf(\"\", i, \t\t\trand() % 10000, rand() % 10000, rand() % 10000); \t} \tprintf(\"
XYZ
%d%d%d%d
\"); \treturn 0; }", "after": "unsafe fn main() -> 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 < 4 as libc::c_int { printf( b\"\\0\" as *const u8 as *const libc::c_char, i, rand() % 10000 as libc::c_int, rand() % 10000 as libc::c_int, rand() % 10000 as libc::c_int, ); i += 1; i; } printf(b\"
XYZ
%d%d%d%d
\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 951, "before": "int main(void) { double v[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 10.}; printf(\"%f\\n\", rms(v, sizeof(v)/sizeof(double))); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut v: [libc::c_double; 10] = [ 1.0f64, 2.0f64, 3.0f64, 4.0f64, 5.0f64, 6.0f64, 7.0f64, 8.0f64, 9.0f64, 10.0f64, ]; printf( b\"%f\\n\\0\" as *const u8 as *const libc::c_char, rms( v.as_mut_ptr(), (::core::mem::size_of::<[libc::c_double; 10]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, ), ); return 0 as libc::c_int; }" }, { "index": 952, "before": "double rms(double *v, int n) { int i; double sum = 0.0; for(i = 0; i < n; i++) sum += v[i] * v[i]; return sqrt(sum / n); }", "after": "pub unsafe extern \"C\" fn rms( mut v: *mut libc::c_double, mut n: libc::c_int, ) -> libc::c_double { let mut i: libc::c_int = 0; let mut sum: libc::c_double = 0.0f64; i = 0 as libc::c_int; while i < n { sum += *v.offset(i as isize) * *v.offset(i as isize); i += 1; i; } return sqrt(sum / n as libc::c_double); }" }, { "index": 953, "before": "int main() { int *ints = malloc(SIZEOF_MEMB*NMEMB); /* realloc can be used to increase or decrease an already allocated memory (same as malloc if ints is NULL) */ ints = realloc(ints, sizeof(int)*(NMEMB+1)); /* calloc set the memory to 0s */ int *int2 = calloc(NMEMB, SIZEOF_MEMB); /* all use the same free */ free(ints); free(int2); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut ints: *mut libc::c_int = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(100 as libc::c_int as libc::c_ulong), ) as *mut libc::c_int; ints = realloc( ints as *mut libc::c_void, (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul((100 as libc::c_int + 1 as libc::c_int) as libc::c_ulong), ) as *mut libc::c_int; let mut int2: *mut libc::c_int = calloc( 100 as libc::c_int as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; free(ints as *mut libc::c_void); free(int2 as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 954, "before": "void printResults(char originalString[100], char finalString[100], int operation, char squeezeChar){ if(operation==SQUEEZE){ printf(\"Specified Operation : SQUEEZE\\nTarget Character : %c\",squeezeChar); } else printf(\"Specified Operation : COLLAPSE\"); printf(\"\\nOriginal %c%c%c%s%c%c%c\\nLength : %d\",174,174,174,originalString,175,175,175,(int)strlen(originalString)); printf(\"\\nFinal %c%c%c%s%c%c%c\\nLength : %d\\n\",174,174,174,finalString,175,175,175,(int)strlen(finalString)); }", "after": "pub unsafe extern \"C\" fn printResults( mut originalString: *mut libc::c_char, mut finalString: *mut libc::c_char, mut operation: libc::c_int, mut squeezeChar: libc::c_char, ) { if operation == 1 as libc::c_int { printf( b\"Specified Operation : SQUEEZE\\nTarget Character : %c\\0\" as *const u8 as *const libc::c_char, squeezeChar as libc::c_int, ); } else { printf(b\"Specified Operation : COLLAPSE\\0\" as *const u8 as *const libc::c_char); } printf( b\"\\nOriginal %c%c%c%s%c%c%c\\nLength : %d\\0\" as *const u8 as *const libc::c_char, 174 as libc::c_int, 174 as libc::c_int, 174 as libc::c_int, originalString, 175 as libc::c_int, 175 as libc::c_int, 175 as libc::c_int, strlen(originalString as *const libc::c_char) as libc::c_int, ); printf( b\"\\nFinal %c%c%c%s%c%c%c\\nLength : %d\\n\\0\" as *const u8 as *const libc::c_char, 174 as libc::c_int, 174 as libc::c_int, 174 as libc::c_int, finalString, 175 as libc::c_int, 175 as libc::c_int, 175 as libc::c_int, strlen(finalString as *const libc::c_char) as libc::c_int, ); }" }, { "index": 955, "before": "int main(int argc, char** argv){ int operation; char squeezeChar; if(argc<3||argc>4){ printf(\"Usage : %s \\n\",argv[0]); return 0; } if(strcmpi(argv[1],\"SQUEEZE\")==0 && argc!=4){ scanf(\"Please enter characted to be squeezed : %c\",&squeezeChar); operation = SQUEEZE; } else if(argc==4){ operation = SQUEEZE; squeezeChar = argv[3][0]; } else if(strcmpi(argv[1],\"COLLAPSE\")==0){ operation = COLLAPSE; } if(strlen(argv[2])<2){ printResults(argv[2],argv[2],operation,squeezeChar); } else{ printResults(argv[2],processString(argv[2],operation,squeezeChar),operation,squeezeChar); } return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut operation: libc::c_int = 0; let mut squeezeChar: libc::c_char = 0; if argc < 3 as libc::c_int || argc > 4 as libc::c_int { printf( b\"Usage : %s \\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); return 0 as libc::c_int; } if strcmpi( *argv.offset(1 as libc::c_int as isize), b\"SQUEEZE\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ) == 0 as libc::c_int && argc != 4 as libc::c_int { scanf( b\"Please enter characted to be squeezed : %c\\0\" as *const u8 as *const libc::c_char, &mut squeezeChar as *mut libc::c_char, ); operation = 1 as libc::c_int; } else if argc == 4 as libc::c_int { operation = 1 as libc::c_int; squeezeChar = *(*argv.offset(3 as libc::c_int as isize)) .offset(0 as libc::c_int as isize); } else if strcmpi( *argv.offset(1 as libc::c_int as isize), b\"COLLAPSE\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ) == 0 as libc::c_int { operation = 0 as libc::c_int; } if strlen(*argv.offset(2 as libc::c_int as isize)) < 2 as libc::c_int as libc::c_ulong { printResults( *argv.offset(2 as libc::c_int as isize), *argv.offset(2 as libc::c_int as isize), operation, squeezeChar, ); } else { printResults( *argv.offset(2 as libc::c_int as isize), processString( *argv.offset(2 as libc::c_int as isize), operation, squeezeChar, ), operation, squeezeChar, ); } return 0 as libc::c_int; }" }, { "index": 956, "before": "int strcmpi(char* str1,char* str2){ int len1 = strlen(str1), len2 = strlen(str2), i; if(len1!=len2){ return 1; } else{ for(i=0;i='A'&&str1[i]<='Z')&&(str2[i]>='a'&&str2[i]<='z')&&(str2[i]-65!=str1[i])) return 1; else if((str2[i]>='A'&&str2[i]<='Z')&&(str1[i]>='a'&&str1[i]<='z')&&(str1[i]-65!=str2[i])) return 1; else if(str1[i]!=str2[i]) return 1; } } return 0; }", "after": "pub unsafe extern \"C\" fn strcmpi( mut str1: *mut libc::c_char, mut str2: *mut libc::c_char, ) -> libc::c_int { let mut len1: libc::c_int = strlen(str1) as libc::c_int; let mut len2: libc::c_int = strlen(str2) as libc::c_int; let mut i: libc::c_int = 0; if len1 != len2 { return 1 as libc::c_int } else { i = 0 as libc::c_int; while i < len1 { if *str1.offset(i as isize) as libc::c_int >= 'A' as i32 && *str1.offset(i as isize) as libc::c_int <= 'Z' as i32 && (*str2.offset(i as isize) as libc::c_int >= 'a' as i32 && *str2.offset(i as isize) as libc::c_int <= 'z' as i32) && *str2.offset(i as isize) as libc::c_int - 65 as libc::c_int != *str1.offset(i as isize) as libc::c_int { return 1 as libc::c_int } else if *str2.offset(i as isize) as libc::c_int >= 'A' as i32 && *str2.offset(i as isize) as libc::c_int <= 'Z' as i32 && (*str1.offset(i as isize) as libc::c_int >= 'a' as i32 && *str1.offset(i as isize) as libc::c_int <= 'z' as i32) && *str1.offset(i as isize) as libc::c_int - 65 as libc::c_int != *str2.offset(i as isize) as libc::c_int { return 1 as libc::c_int } else if *str1.offset(i as isize) as libc::c_int != *str2.offset(i as isize) as libc::c_int { return 1 as libc::c_int } i += 1; i; } } return 0 as libc::c_int; }" }, { "index": 957, "before": "int self_desc(unsigned long long xx) { \tregister unsigned int d, x; \tunsigned char cnt[10] = {0}, dig[10] = {0}; \tfor (d = 0; xx > ~0U; xx /= 10) \t\tcnt[dig[d++] = xx % 10]++; \tfor (x = xx; x; x /= 10) \t\tcnt[dig[d++] = x % 10]++; \twhile (d-- && dig[x++] == cnt[d]) \t\t; \treturn d == -1; }", "after": "pub unsafe extern \"C\" fn self_desc(mut xx: libc::c_ulonglong) -> libc::c_int { let mut d: libc::c_uint = 0; let mut x: libc::c_uint = 0; let mut cnt: [libc::c_uchar; 10] = [ 0 as libc::c_int as libc::c_uchar, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut dig: [libc::c_uchar; 10] = [ 0 as libc::c_int as libc::c_uchar, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; d = 0 as libc::c_int as libc::c_uint; while xx > !(0 as libc::c_uint) as libc::c_ulonglong { let fresh0 = d; d = d.wrapping_add(1); dig[fresh0 as usize] = xx.wrapping_rem(10 as libc::c_int as libc::c_ulonglong) as libc::c_uchar; cnt[dig[fresh0 as usize] as usize] = (cnt[dig[fresh0 as usize] as usize]).wrapping_add(1); cnt[dig[fresh0 as usize] as usize]; xx = xx.wrapping_div(10 as libc::c_int as libc::c_ulonglong); } x = xx as libc::c_uint; while x != 0 { let fresh1 = d; d = d.wrapping_add(1); dig[fresh1 as usize] = x.wrapping_rem(10 as libc::c_int as libc::c_uint) as libc::c_uchar; cnt[dig[fresh1 as usize] as usize] = (cnt[dig[fresh1 as usize] as usize]).wrapping_add(1); cnt[dig[fresh1 as usize] as usize]; x = x.wrapping_div(10 as libc::c_int as libc::c_uint); } loop { let fresh2 = d; d = d.wrapping_sub(1); if !(fresh2 != 0 && { let fresh3 = x; x = x.wrapping_add(1); dig[fresh3 as usize] as libc::c_int == cnt[d as usize] as libc::c_int }) { break; } } return (d == -(1 as libc::c_int) as libc::c_uint) as libc::c_int; }" }, { "index": 958, "before": "int main() { \tint i; \tfor (i = 1; i < 100000000; i++) /* don't handle 0 */ \t\tif (self_desc(i)) \t\t\tprintf(\"%d\\n\", i); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; i = 1 as libc::c_int; while i < 100000000 as libc::c_int { if self_desc(i as libc::c_ulonglong) != 0 { printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, i); } i += 1; i; } return 0 as libc::c_int; }" }, { "index": 959, "before": "int main(void) { \tprintf(\"%d\\n\", mul_inv(42, 2017)); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, mul_inv(42 as libc::c_int, 2017 as libc::c_int), ); return 0 as libc::c_int; }" }, { "index": 960, "before": "int mul_inv(int a, int b) { \tint b0 = b, t, q; \tint x0 = 0, x1 = 1; \tif (b == 1) return 1; \twhile (a > 1) { \t\tq = a / b; \t\tt = b, b = a % b, a = t; \t\tt = x0, x0 = x1 - q * x0, x1 = t; \t} \tif (x1 < 0) x1 += b0; \treturn x1; }", "after": "pub unsafe extern \"C\" fn mul_inv(mut a: libc::c_int, mut b: libc::c_int) -> libc::c_int { let mut b0: libc::c_int = b; let mut t: libc::c_int = 0; let mut q: libc::c_int = 0; let mut x0: libc::c_int = 0 as libc::c_int; let mut x1: libc::c_int = 1 as libc::c_int; if b == 1 as libc::c_int { return 1 as libc::c_int; } while a > 1 as libc::c_int { q = a / b; t = b; b = a % b; a = t; t = x0; x0 = x1 - q * x0; x1 = t; } if x1 < 0 as libc::c_int { x1 += b0; } return x1; }" }, { "index": 961, "before": "void roman(char *s, unsigned int n) { if (n == 0) { fputs(\"Roman numeral for zero requested.\", stderr); exit(EXIT_FAILURE); } #define digit(loop, num, c) \\ loop (n >= num) \\ {*(s++) = c; \\ n -= num;} #define digits(loop, num, c1, c2) \\ loop (n >= num) \\ {*(s++) = c1; \\ *(s++) = c2; \\ n -= num;} digit ( while, 1000, 'M' ) digits ( if, 900, 'C', 'M' ) digit ( if, 500, 'D' ) digits ( if, 400, 'C', 'D' ) digit ( while, 100, 'C' ) digits ( if, 90, 'X', 'C' ) digit ( if, 50, 'L' ) digits ( if, 40, 'X', 'L' ) digit ( while, 10, 'X' ) digits ( if, 9, 'I', 'X' ) digit ( if, 5, 'V' ) digits ( if, 4, 'I', 'V' ) digit ( while, 1, 'I' ) #undef digit #undef digits *s = 0;}", "after": "pub unsafe extern \"C\" fn roman(mut s: *mut libc::c_char, mut n: libc::c_uint) { if n == 0 as libc::c_int as libc::c_uint { fputs( b\"Roman numeral for zero requested.\\0\" as *const u8 as *const libc::c_char, stderr, ); exit(1 as libc::c_int); } while n >= 1000 as libc::c_int as libc::c_uint { let fresh0 = s; s = s.offset(1); *fresh0 = 'M' as i32 as libc::c_char; n = n.wrapping_sub(1000 as libc::c_int as libc::c_uint); } if n >= 900 as libc::c_int as libc::c_uint { let fresh1 = s; s = s.offset(1); *fresh1 = 'C' as i32 as libc::c_char; let fresh2 = s; s = s.offset(1); *fresh2 = 'M' as i32 as libc::c_char; n = n.wrapping_sub(900 as libc::c_int as libc::c_uint); } if n >= 500 as libc::c_int as libc::c_uint { let fresh3 = s; s = s.offset(1); *fresh3 = 'D' as i32 as libc::c_char; n = n.wrapping_sub(500 as libc::c_int as libc::c_uint); } if n >= 400 as libc::c_int as libc::c_uint { let fresh4 = s; s = s.offset(1); *fresh4 = 'C' as i32 as libc::c_char; let fresh5 = s; s = s.offset(1); *fresh5 = 'D' as i32 as libc::c_char; n = n.wrapping_sub(400 as libc::c_int as libc::c_uint); } while n >= 100 as libc::c_int as libc::c_uint { let fresh6 = s; s = s.offset(1); *fresh6 = 'C' as i32 as libc::c_char; n = n.wrapping_sub(100 as libc::c_int as libc::c_uint); } if n >= 90 as libc::c_int as libc::c_uint { let fresh7 = s; s = s.offset(1); *fresh7 = 'X' as i32 as libc::c_char; let fresh8 = s; s = s.offset(1); *fresh8 = 'C' as i32 as libc::c_char; n = n.wrapping_sub(90 as libc::c_int as libc::c_uint); } if n >= 50 as libc::c_int as libc::c_uint { let fresh9 = s; s = s.offset(1); *fresh9 = 'L' as i32 as libc::c_char; n = n.wrapping_sub(50 as libc::c_int as libc::c_uint); } if n >= 40 as libc::c_int as libc::c_uint { let fresh10 = s; s = s.offset(1); *fresh10 = 'X' as i32 as libc::c_char; let fresh11 = s; s = s.offset(1); *fresh11 = 'L' as i32 as libc::c_char; n = n.wrapping_sub(40 as libc::c_int as libc::c_uint); } while n >= 10 as libc::c_int as libc::c_uint { let fresh12 = s; s = s.offset(1); *fresh12 = 'X' as i32 as libc::c_char; n = n.wrapping_sub(10 as libc::c_int as libc::c_uint); } if n >= 9 as libc::c_int as libc::c_uint { let fresh13 = s; s = s.offset(1); *fresh13 = 'I' as i32 as libc::c_char; let fresh14 = s; s = s.offset(1); *fresh14 = 'X' as i32 as libc::c_char; n = n.wrapping_sub(9 as libc::c_int as libc::c_uint); } if n >= 5 as libc::c_int as libc::c_uint { let fresh15 = s; s = s.offset(1); *fresh15 = 'V' as i32 as libc::c_char; n = n.wrapping_sub(5 as libc::c_int as libc::c_uint); } if n >= 4 as libc::c_int as libc::c_uint { let fresh16 = s; s = s.offset(1); *fresh16 = 'I' as i32 as libc::c_char; let fresh17 = s; s = s.offset(1); *fresh17 = 'V' as i32 as libc::c_char; n = n.wrapping_sub(4 as libc::c_int as libc::c_uint); } while n >= 1 as libc::c_int as libc::c_uint { let fresh18 = s; s = s.offset(1); *fresh18 = 'I' as i32 as libc::c_char; n = n.wrapping_sub(1 as libc::c_int as libc::c_uint); } *s = 0 as libc::c_int as libc::c_char; }" }, { "index": 962, "before": "int main(void) { char buffer[16]; unsigned int i; for (i = 1 ; i < 4000 ; ++i) { roman(buffer, i); printf(\"%4u: %s\\n\", i, buffer); } return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut buffer: [libc::c_char; 16] = [0; 16]; let mut i: libc::c_uint = 0; i = 1 as libc::c_int as libc::c_uint; while i < 4000 as libc::c_int as libc::c_uint { roman(buffer.as_mut_ptr(), i); printf( b\"%4u: %s\\n\\0\" as *const u8 as *const libc::c_char, i, buffer.as_mut_ptr(), ); i = i.wrapping_add(1); i; } return 0 as libc::c_int; }" }, { "index": 963, "before": "int main() { fairshare(2, 25); fairshare(3, 25); fairshare(5, 25); fairshare(11, 25); printf(\"How many times does each get a turn in 50000 iterations?\\n\"); turnCount(191, 50000); turnCount(1377, 50000); turnCount(49999, 50000); turnCount(50000, 50000); turnCount(50001, 50000); return 0; }", "after": "unsafe fn main() -> libc::c_int { fairshare(2 as libc::c_int, 25 as libc::c_int); fairshare(3 as libc::c_int, 25 as libc::c_int); fairshare(5 as libc::c_int, 25 as libc::c_int); fairshare(11 as libc::c_int, 25 as libc::c_int); printf( b\"How many times does each get a turn in 50000 iterations?\\n\\0\" as *const u8 as *const libc::c_char, ); turnCount(191 as libc::c_int, 50000 as libc::c_int); turnCount(1377 as libc::c_int, 50000 as libc::c_int); turnCount(49999 as libc::c_int, 50000 as libc::c_int); turnCount(50000 as libc::c_int, 50000 as libc::c_int); turnCount(50001 as libc::c_int, 50000 as libc::c_int); return 0 as libc::c_int; }" }, { "index": 964, "before": "void fairshare(int base, int count) { int i; printf(\"Base %2d:\", base); for (i = 0; i < count; i++) { int t = turn(base, i); printf(\" %2d\", t); } printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn fairshare(mut base: libc::c_int, mut count: libc::c_int) { let mut i: libc::c_int = 0; printf(b\"Base %2d:\\0\" as *const u8 as *const libc::c_char, base); i = 0 as libc::c_int; while i < count { let mut t: libc::c_int = turn(base, i); printf(b\" %2d\\0\" as *const u8 as *const libc::c_char, t); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 965, "before": "int turn(int base, int n) { int sum = 0; while (n != 0) { int rem = n % base; n = n / base; sum += rem; } return sum % base; }", "after": "pub unsafe extern \"C\" fn turn(mut base: libc::c_int, mut n: libc::c_int) -> libc::c_int { let mut sum: libc::c_int = 0 as libc::c_int; while n != 0 as libc::c_int { let mut rem: libc::c_int = n % base; n = n / base; sum += rem; } return sum % base; }" }, { "index": 966, "before": "void turnCount(int base, int count) { int *cnt = calloc(base, sizeof(int)); int i, minTurn, maxTurn, portion; if (NULL == cnt) { printf(\"Failed to allocate space to determine the spread of turns.\\n\"); return; } for (i = 0; i < count; i++) { int t = turn(base, i); cnt[t]++; } minTurn = INT_MAX; maxTurn = INT_MIN; portion = 0; for (i = 0; i < base; i++) { if (cnt[i] > 0) { portion++; } if (cnt[i] < minTurn) { minTurn = cnt[i]; } if (cnt[i] > maxTurn) { maxTurn = cnt[i]; } } printf(\" With %d people: \", base); if (0 == minTurn) { printf(\"Only %d have a turn\\n\", portion); } else if (minTurn == maxTurn) { printf(\"%d\\n\", minTurn); } else { printf(\"%d or %d\\n\", minTurn, maxTurn); } free(cnt); }", "after": "pub unsafe extern \"C\" fn turnCount(mut base: libc::c_int, mut count: libc::c_int) { let mut cnt: *mut libc::c_int = calloc( base as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; let mut i: libc::c_int = 0; let mut minTurn: libc::c_int = 0; let mut maxTurn: libc::c_int = 0; let mut portion: libc::c_int = 0; if cnt.is_null() { printf( b\"Failed to allocate space to determine the spread of turns.\\n\\0\" as *const u8 as *const libc::c_char, ); return; } i = 0 as libc::c_int; while i < count { let mut t: libc::c_int = turn(base, i); let ref mut fresh0 = *cnt.offset(t as isize); *fresh0 += 1; *fresh0; i += 1; i; } minTurn = 2147483647 as libc::c_int; maxTurn = -(2147483647 as libc::c_int) - 1 as libc::c_int; portion = 0 as libc::c_int; i = 0 as libc::c_int; while i < base { if *cnt.offset(i as isize) > 0 as libc::c_int { portion += 1; portion; } if *cnt.offset(i as isize) < minTurn { minTurn = *cnt.offset(i as isize); } if *cnt.offset(i as isize) > maxTurn { maxTurn = *cnt.offset(i as isize); } i += 1; i; } printf(b\" With %d people: \\0\" as *const u8 as *const libc::c_char, base); if 0 as libc::c_int == minTurn { printf(b\"Only %d have a turn\\n\\0\" as *const u8 as *const libc::c_char, portion); } else if minTurn == maxTurn { printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, minTurn); } else { printf(b\"%d or %d\\n\\0\" as *const u8 as *const libc::c_char, minTurn, maxTurn); } free(cnt as *mut libc::c_void); }" }, { "index": 967, "before": "void View_displayMessage(char* text){ printf(\"\\n%s\\n\", text); }", "after": "pub unsafe extern \"C\" fn View_displayMessage(mut text: *mut libc::c_char) { printf(b\"\\n%s\\n\\0\" as *const u8 as *const libc::c_char, text); }" }, { "index": 968, "before": "int Game_isFinished(void){ int i,j; int k = 1; for ( i = 0; i < NROWS; i++ ) for ( j = 0; j < NCOLLUMNS; j++ ) if ( (k < NROWS*NCOLLUMNS) && (cells[i][j] != k++ ) ) return 0; return 1; }", "after": "pub unsafe extern \"C\" fn Game_isFinished() -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut k: libc::c_int = 1 as libc::c_int; i = 0 as libc::c_int; while i < 4 as libc::c_int { j = 0 as libc::c_int; while j < 4 as libc::c_int { if k < 4 as libc::c_int * 4 as libc::c_int && { let fresh0 = k; k = k + 1; cells[i as usize][j as usize] != fresh0 } { return 0 as libc::c_int; } j += 1; j; } i += 1; i; } return 1 as libc::c_int; }" }, { "index": 969, "before": "void Game_setup(void){ int i,j,k; for ( i = 0; i < NROWS; i++ ) for ( j = 0; j < NCOLLUMNS; j++ ) cells[i][j] = i * NCOLLUMNS + j + 1; cells[NROWS-1][NCOLLUMNS-1] = 0; holeRow = NROWS - 1; holeCollumn = NCOLLUMNS - 1; k = 0; while ( k < nShuffles ) k += Game_update((enum Move)(rand() % 4)); }", "after": "pub unsafe extern \"C\" fn Game_setup() { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut k: libc::c_int = 0; i = 0 as libc::c_int; while i < 4 as libc::c_int { j = 0 as libc::c_int; while j < 4 as libc::c_int { cells[i as usize][j as usize] = i * 4 as libc::c_int + j + 1 as libc::c_int; j += 1; j; } i += 1; i; } cells[(4 as libc::c_int - 1 as libc::c_int) as usize][(4 as libc::c_int - 1 as libc::c_int) as usize] = 0 as libc::c_int; holeRow = 4 as libc::c_int - 1 as libc::c_int; holeCollumn = 4 as libc::c_int - 1 as libc::c_int; k = 0 as libc::c_int; while k < nShuffles { k += Game_update((rand() % 4 as libc::c_int) as Move); } }" }, { "index": 970, "before": "enum Move Controller_getMove(void){ int c; for(;;){ printf(\"%s\", \"enter u/d/l/r : \"); c = getchar(); while( getchar() != '\\n' ) ; switch ( c ){ case 27: exit(EXIT_SUCCESS); case 'd' : return MOVE_UP; case 'u' : return MOVE_DOWN; case 'r' : return MOVE_LEFT; case 'l' : return MOVE_RIGHT; } } }", "after": "pub unsafe extern \"C\" fn Controller_getMove() -> Move { let mut c: libc::c_int = 0; loop { printf( b\"%s\\0\" as *const u8 as *const libc::c_char, b\"enter u/d/l/r : \\0\" as *const u8 as *const libc::c_char, ); c = getchar(); while getchar() != '\\n' as i32 {} match c { 27 => { exit(0 as libc::c_int); } 100 => return MOVE_UP, 117 => return MOVE_DOWN, 114 => return MOVE_LEFT, 108 => return MOVE_RIGHT, _ => {} } }; }" }, { "index": 971, "before": "void Controller_pause(void){ getchar(); }", "after": "pub unsafe extern \"C\" fn Controller_pause() { getchar(); }" }, { "index": 972, "before": "int Game_update(enum Move move){ const int dx[] = { 0, 0, -1, +1 }; const int dy[] = { -1, +1, 0, 0 }; int i = holeRow + dy[move]; int j = holeCollumn + dx[move]; if ( i >= 0 && i < NROWS && j >= 0 && j < NCOLLUMNS ){ cells[holeRow][holeCollumn] = cells[i][j]; cells[i][j] = 0; holeRow = i; holeCollumn = j; return 1; } return 0; }", "after": "pub unsafe extern \"C\" fn Game_update(mut move_0: Move) -> libc::c_int { let dx: [libc::c_int; 4] = [ 0 as libc::c_int, 0 as libc::c_int, -(1 as libc::c_int), 1 as libc::c_int, ]; let dy: [libc::c_int; 4] = [ -(1 as libc::c_int), 1 as libc::c_int, 0 as libc::c_int, 0 as libc::c_int, ]; let mut i: libc::c_int = holeRow + dy[move_0 as usize]; let mut j: libc::c_int = holeCollumn + dx[move_0 as usize]; if i >= 0 as libc::c_int && i < 4 as libc::c_int && j >= 0 as libc::c_int && j < 4 as libc::c_int { cells[holeRow as usize][holeCollumn as usize] = cells[i as usize][j as usize]; cells[i as usize][j as usize] = 0 as libc::c_int; holeRow = i; holeCollumn = j; return 1 as libc::c_int; } return 0 as libc::c_int; }" }, { "index": 973, "before": "void View_showBoard(){ int i,j; putchar('\\n'); for ( i = 0; i < NROWS; i++ ) for ( j = 0; j < NCOLLUMNS; j++ ){ if ( cells[i][j] ) printf(j != NCOLLUMNS-1 ? \" %2d \" : \" %2d \\n\", cells[i][j]); else printf(j != NCOLLUMNS-1 ? \" %2s \" : \" %2s \\n\", \"\"); } putchar('\\n'); }", "after": "pub unsafe extern \"C\" fn View_showBoard() { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; putchar('\\n' as i32); i = 0 as libc::c_int; while i < 4 as libc::c_int { j = 0 as libc::c_int; while j < 4 as libc::c_int { if cells[i as usize][j as usize] != 0 { printf( if j != 4 as libc::c_int - 1 as libc::c_int { b\" %2d \\0\" as *const u8 as *const libc::c_char } else { b\" %2d \\n\\0\" as *const u8 as *const libc::c_char }, cells[i as usize][j as usize], ); } else { printf( if j != 4 as libc::c_int - 1 as libc::c_int { b\" %2s \\0\" as *const u8 as *const libc::c_char } else { b\" %2s \\n\\0\" as *const u8 as *const libc::c_char }, b\"\\0\" as *const u8 as *const libc::c_char, ); } j += 1; j; } i += 1; i; } putchar('\\n' as i32); }" }, { "index": 974, "before": "int main(void){ srand((unsigned)time(NULL)); do Game_setup(); while ( Game_isFinished() ); View_showBoard(); while( !Game_isFinished() ){ Game_update( Controller_getMove() ); View_showBoard(); } View_displayMessage(\"You win\"); Controller_pause(); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { srand(time(0 as *mut time_t) as libc::c_uint); loop { Game_setup(); if !(Game_isFinished() != 0) { break; } } View_showBoard(); while Game_isFinished() == 0 { Game_update(Controller_getMove()); View_showBoard(); } View_displayMessage( b\"You win\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); Controller_pause(); return 0 as libc::c_int; }" }, { "index": 975, "before": "int main() { int last_prime = 3, n = 5, count = 2; init(); record(2, 3); while (count < LIMIT) { if (isPrime(n)) { record(last_prime, n); last_prime = n; count++; } n += 2; if (count < LIMIT) { if (isPrime(n)) { record(last_prime, n); last_prime = n; count++; } n += 4; } } printTransitions(LIMIT, last_prime); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut last_prime: libc::c_int = 3 as libc::c_int; let mut n: libc::c_int = 5 as libc::c_int; let mut count: libc::c_int = 2 as libc::c_int; init(); record(2 as libc::c_int, 3 as libc::c_int); while count < 1000000 as libc::c_int { if isPrime(n) { record(last_prime, n); last_prime = n; count += 1; count; } n += 2 as libc::c_int; if count < 1000000 as libc::c_int { if isPrime(n) { record(last_prime, n); last_prime = n; count += 1; count; } n += 4 as libc::c_int; } } printTransitions(1000000 as libc::c_int, last_prime); return 0 as libc::c_int; }" }, { "index": 976, "before": "void printTransitions(int limit, int last_prime) { int i; printf(\"%d primes, last prime considered: %d\\n\", limit, last_prime); for (i = 0; i < 100; i++) { if (transitions[i].c > 0) { printf(\"%d->%d count: %5d frequency: %.2f\\n\", transitions[i].a, transitions[i].b, transitions[i].c, 100.0 * transitions[i].c / limit); } } }", "after": "pub unsafe extern \"C\" fn printTransitions( mut limit: libc::c_int, mut last_prime: libc::c_int, ) { let mut i: libc::c_int = 0; printf( b\"%d primes, last prime considered: %d\\n\\0\" as *const u8 as *const libc::c_char, limit, last_prime, ); i = 0 as libc::c_int; while i < 100 as libc::c_int { if transitions[i as usize].c > 0 as libc::c_int as libc::c_uint { printf( b\"%d->%d count: %5d frequency: %.2f\\n\\0\" as *const u8 as *const libc::c_char, transitions[i as usize].a as libc::c_int, transitions[i as usize].b as libc::c_int, transitions[i as usize].c, 100.0f64 * transitions[i as usize].c as libc::c_double / limit as libc::c_double, ); } i += 1; i; } }" }, { "index": 977, "before": "void record(int prev, int curr) { byte pd = prev % 10; byte cd = curr % 10; int i; for (i = 0; i < 100; i++) { int z = 0; if (transitions[i].a == pd) { int t = 0; if (transitions[i].b == cd) { transitions[i].c++; break; } } } }", "after": "pub unsafe extern \"C\" fn record(mut prev: libc::c_int, mut curr: libc::c_int) { let mut pd: byte = (prev % 10 as libc::c_int) as byte; let mut cd: byte = (curr % 10 as libc::c_int) as byte; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 100 as libc::c_int { let mut z: libc::c_int = 0 as libc::c_int; if transitions[i as usize].a as libc::c_int == pd as libc::c_int { let mut t: libc::c_int = 0 as libc::c_int; if transitions[i as usize].b as libc::c_int == cd as libc::c_int { transitions[i as usize].c = (transitions[i as usize].c).wrapping_add(1); transitions[i as usize].c; break; } } i += 1; i; } }" }, { "index": 978, "before": "void init() { int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { int idx = i * 10 + j; transitions[idx].a = i; transitions[idx].b = j; transitions[idx].c = 0; } } }", "after": "pub unsafe extern \"C\" fn init() { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; i = 0 as libc::c_int; while i < 10 as libc::c_int { j = 0 as libc::c_int; while j < 10 as libc::c_int { let mut idx: libc::c_int = i * 10 as libc::c_int + j; transitions[idx as usize].a = i as byte; transitions[idx as usize].b = j as byte; transitions[idx as usize].c = 0 as libc::c_int as libc::c_uint; j += 1; j; } i += 1; i; } }" }, { "index": 979, "before": "bool isPrime(int n) { int s, t, a1, a2; if (n % 2 == 0) return n == 2; if (n % 3 == 0) return n == 3; if (n % 5 == 0) return n == 5; if (n % 7 == 0) return n == 7; if (n % 11 == 0) return n == 11; if (n % 13 == 0) return n == 13; if (n % 17 == 0) return n == 17; if (n % 19 == 0) return n == 19; // assuming that addition is faster then multiplication t = 23; a1 = 96; a2 = 216; s = t * t; while (s <= n) { if (n % t == 0) return false; // first increment s += a1; t += 2; a1 += 24; assert(t * t == s); if (s <= n) { if (n % t == 0) return false; // second increment s += a2; t += 4; a2 += 48; assert(t * t == s); } } return true; }", "after": "pub unsafe extern \"C\" fn isPrime(mut n: libc::c_int) -> bool { let mut s: libc::c_int = 0; let mut t: libc::c_int = 0; let mut a1: libc::c_int = 0; let mut a2: libc::c_int = 0; if n % 2 as libc::c_int == 0 as libc::c_int { return n == 2 as libc::c_int; } if n % 3 as libc::c_int == 0 as libc::c_int { return n == 3 as libc::c_int; } if n % 5 as libc::c_int == 0 as libc::c_int { return n == 5 as libc::c_int; } if n % 7 as libc::c_int == 0 as libc::c_int { return n == 7 as libc::c_int; } if n % 11 as libc::c_int == 0 as libc::c_int { return n == 11 as libc::c_int; } if n % 13 as libc::c_int == 0 as libc::c_int { return n == 13 as libc::c_int; } if n % 17 as libc::c_int == 0 as libc::c_int { return n == 17 as libc::c_int; } if n % 19 as libc::c_int == 0 as libc::c_int { return n == 19 as libc::c_int; } t = 23 as libc::c_int; a1 = 96 as libc::c_int; a2 = 216 as libc::c_int; s = t * t; while s <= n { if n % t == 0 as libc::c_int { return 0 as libc::c_int != 0; } s += a1; t += 2 as libc::c_int; a1 += 24 as libc::c_int; if t * t == s {} else { __assert_fail( b\"t * t == s\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 77 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 19], &[libc::c_char; 19], >(b\"_Bool isPrime(int)\\0\")) .as_ptr(), ); } 'c_923: { if t * t == s {} else { __assert_fail( b\"t * t == s\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 77 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 19], &[libc::c_char; 19], >(b\"_Bool isPrime(int)\\0\")) .as_ptr(), ); } }; if s <= n { if n % t == 0 as libc::c_int { return 0 as libc::c_int != 0; } s += a2; t += 4 as libc::c_int; a2 += 48 as libc::c_int; if t * t == s {} else { __assert_fail( b\"t * t == s\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 86 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 19], &[libc::c_char; 19], >(b\"_Bool isPrime(int)\\0\")) .as_ptr(), ); } 'c_846: { if t * t == s {} else { __assert_fail( b\"t * t == s\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 86 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 19], &[libc::c_char; 19], >(b\"_Bool isPrime(int)\\0\")) .as_ptr(), ); } }; } } return 1 as libc::c_int != 0; }" }, { "index": 980, "before": "int unfitness(const char *a, const char *b) { \tint i, sum = 0; \tfor (i = 0; a[i]; i++) \t\tsum += (a[i] != b[i]); \treturn sum; }", "after": "pub unsafe extern \"C\" fn unfitness( mut a: *const libc::c_char, mut b: *const libc::c_char, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut sum: libc::c_int = 0 as libc::c_int; i = 0 as libc::c_int; while *a.offset(i as isize) != 0 { sum += (*a.offset(i as isize) as libc::c_int != *b.offset(i as isize) as libc::c_int) as libc::c_int; i += 1; i; } return sum; }" }, { "index": 981, "before": "void mutate(const char *a, char *b) { \tint i; \tfor (i = 0; a[i]; i++) \t\tb[i] = irand(MUTATE) ? a[i] : tbl[irand(CHOICE)]; \tb[i] = '\\0'; }", "after": "pub unsafe extern \"C\" fn mutate(mut a: *const libc::c_char, mut b: *mut libc::c_char) { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while *a.offset(i as isize) != 0 { *b .offset( i as isize, ) = (if irand(15 as libc::c_int) != 0 { *a.offset(i as isize) as libc::c_int } else { tbl[irand( (::core::mem::size_of::<[libc::c_char; 28]>() as libc::c_ulong) .wrapping_sub(1 as libc::c_int as libc::c_ulong) as libc::c_int, ) as usize] as libc::c_int }) as libc::c_char; i += 1; i; } *b.offset(i as isize) = '\\0' as i32 as libc::c_char; }" }, { "index": 982, "before": "int irand(int n) { \tint r, rand_max = RAND_MAX - (RAND_MAX % n); \twhile((r = rand()) >= rand_max); \treturn r / (rand_max / n); }", "after": "pub unsafe extern \"C\" fn irand(mut n: libc::c_int) -> libc::c_int { let mut r: libc::c_int = 0; let mut rand_max: libc::c_int = 2147483647 as libc::c_int - 2147483647 as libc::c_int % n; loop { r = rand(); if !(r >= rand_max) { break; } } return r / (rand_max / n); }" }, { "index": 983, "before": "int main() { \tint i, best_i, unfit, best, iters = 0; \tchar specimen[COPIES][sizeof(target) / sizeof(char)]; \t/* init rand string */ \tfor (i = 0; target[i]; i++) \t\tspecimen[0][i] = tbl[irand(CHOICE)]; \tspecimen[0][i] = 0; \tdo { \t\tfor (i = 1; i < COPIES; i++) \t\t\tmutate(specimen[0], specimen[i]); \t\t/* find best fitting string */ \t\tfor (best_i = i = 0; i < COPIES; i++) { \t\t\tunfit = unfitness(target, specimen[i]); \t\t\tif(unfit < best || !i) { \t\t\t\tbest = unfit; \t\t\t\tbest_i = i; \t\t\t} \t\t} \t\tif (best_i) strcpy(specimen[0], specimen[best_i]); \t\tprintf(\"iter %d, score %d: %s\\n\", iters++, best, specimen[0]); \t} while (best); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut best_i: libc::c_int = 0; let mut unfit: libc::c_int = 0; let mut best: libc::c_int = 0; let mut iters: libc::c_int = 0 as libc::c_int; let mut specimen: [[libc::c_char; 29]; 30] = [[0; 29]; 30]; i = 0 as libc::c_int; while target[i as usize] != 0 { specimen[0 as libc::c_int as usize][i as usize] = tbl[irand( (::core::mem::size_of::<[libc::c_char; 28]>() as libc::c_ulong) .wrapping_sub(1 as libc::c_int as libc::c_ulong) as libc::c_int, ) as usize]; i += 1; i; } specimen[0 as libc::c_int as usize][i as usize] = 0 as libc::c_int as libc::c_char; loop { i = 1 as libc::c_int; while i < 30 as libc::c_int { mutate( (specimen[0 as libc::c_int as usize]).as_mut_ptr(), (specimen[i as usize]).as_mut_ptr(), ); i += 1; i; } i = 0 as libc::c_int; best_i = i; while i < 30 as libc::c_int { unfit = unfitness(target.as_ptr(), (specimen[i as usize]).as_mut_ptr()); if unfit < best || i == 0 { best = unfit; best_i = i; } i += 1; i; } if best_i != 0 { strcpy( (specimen[0 as libc::c_int as usize]).as_mut_ptr(), (specimen[best_i as usize]).as_mut_ptr(), ); } let fresh0 = iters; iters = iters + 1; printf( b\"iter %d, score %d: %s\\n\\0\" as *const u8 as *const libc::c_char, fresh0, best, (specimen[0 as libc::c_int as usize]).as_mut_ptr(), ); if !(best != 0) { break; } } return 0 as libc::c_int; }" }, { "index": 984, "before": "int main() { \tsize_t len; \tchar src[] = \"Hello\"; \tchar dst1[80], dst2[80]; \tchar *dst3, *ref; \t/* \t * Option 1. Use strcpy() from . \t * \t * DANGER! strcpy() can overflow the destination buffer. \t * strcpy() is only safe if the source string is shorter than \t * the destination buffer. We know that \"Hello\" (6 characters \t * with the final '\\0') easily fits in dst1 (80 characters). \t */ \tstrcpy(dst1, src); \t/* \t * Option 2. Use strlen() and memcpy() from , to copy \t * strlen(src) + 1 bytes including the final '\\0'. \t */ \tlen = strlen(src); \tif (len >= sizeof dst2) { \t\tfputs(\"The buffer is too small!\\n\", stderr); \t\texit(1); \t} \tmemcpy(dst2, src, len + 1); \t/* \t * Option 3. Use strdup() from , to allocate a copy. \t */ \tdst3 = strdup(src); \tif (dst3 == NULL) { \t\t/* Failed to allocate memory! */ \t\tperror(\"strdup\"); \t\texit(1); \t} \t/* Create another reference to the source string. */ \tref = src; \t/* Modify the source string, not its copies. */ \tmemset(src, '-', 5); \tprintf(\" src: %s\\n\", src); /* src: ----- */ \tprintf(\"dst1: %s\\n\", dst1); /* dst1: Hello */ \tprintf(\"dst2: %s\\n\", dst2); /* dst2: Hello */ \tprintf(\"dst3: %s\\n\", dst3); /* dst3: Hello */ \tprintf(\" ref: %s\\n\", ref); /* ref: ----- */ \t/* Free memory from strdup(). */ \tfree(dst3); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut len: size_t = 0; let mut src: [libc::c_char; 6] = *::core::mem::transmute::< &[u8; 6], &mut [libc::c_char; 6], >(b\"Hello\\0\"); let mut dst1: [libc::c_char; 80] = [0; 80]; let mut dst2: [libc::c_char; 80] = [0; 80]; let mut dst3: *mut libc::c_char = 0 as *mut libc::c_char; let mut ref_0: *mut libc::c_char = 0 as *mut libc::c_char; strcpy(dst1.as_mut_ptr(), src.as_mut_ptr()); len = strlen(src.as_mut_ptr()); if len >= ::core::mem::size_of::<[libc::c_char; 80]>() as libc::c_ulong { fputs( b\"The buffer is too small!\\n\\0\" as *const u8 as *const libc::c_char, stderr, ); exit(1 as libc::c_int); } memcpy( dst2.as_mut_ptr() as *mut libc::c_void, src.as_mut_ptr() as *const libc::c_void, len.wrapping_add(1 as libc::c_int as libc::c_ulong), ); dst3 = strdup(src.as_mut_ptr()); if dst3.is_null() { perror(b\"strdup\\0\" as *const u8 as *const libc::c_char); exit(1 as libc::c_int); } ref_0 = src.as_mut_ptr(); memset( src.as_mut_ptr() as *mut libc::c_void, '-' as i32, 5 as libc::c_int as libc::c_ulong, ); printf(b\" src: %s\\n\\0\" as *const u8 as *const libc::c_char, src.as_mut_ptr()); printf(b\"dst1: %s\\n\\0\" as *const u8 as *const libc::c_char, dst1.as_mut_ptr()); printf(b\"dst2: %s\\n\\0\" as *const u8 as *const libc::c_char, dst2.as_mut_ptr()); printf(b\"dst3: %s\\n\\0\" as *const u8 as *const libc::c_char, dst3); printf(b\" ref: %s\\n\\0\" as *const u8 as *const libc::c_char, ref_0); free(dst3 as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 985, "before": "int main() { \tint police,sanitation,fire; \tprintf(\"Police Sanitation Fire\\n\"); \tprintf(\"----------------------------------\"); \tfor(police=2;police<=6;police+=2){ \t\tfor(sanitation=1;sanitation<=7;sanitation++){ \t\t\tfor(fire=1;fire<=7;fire++){ \t\t\t\tif(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){ \t\t\t\t\tprintf(\"\\n%d\\t\\t%d\\t\\t%d\",police,sanitation,fire); \t\t\t\t} \t\t\t} \t\t} \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut police: libc::c_int = 0; let mut sanitation: libc::c_int = 0; let mut fire: libc::c_int = 0; printf( b\"Police Sanitation Fire\\n\\0\" as *const u8 as *const libc::c_char, ); printf(b\"----------------------------------\\0\" as *const u8 as *const libc::c_char); police = 2 as libc::c_int; while police <= 6 as libc::c_int { sanitation = 1 as libc::c_int; while sanitation <= 7 as libc::c_int { fire = 1 as libc::c_int; while fire <= 7 as libc::c_int { if police != sanitation && sanitation != fire && fire != police && police + fire + sanitation == 12 as libc::c_int { printf( b\"\\n%d\\t\\t%d\\t\\t%d\\0\" as *const u8 as *const libc::c_char, police, sanitation, fire, ); } fire += 1; fire; } sanitation += 1; sanitation; } police += 2 as libc::c_int; } return 0 as libc::c_int; }" }, { "index": 986, "before": "int main(void) { \tgo(580, 32); }", "after": "unsafe fn main() -> libc::c_int { go(580 as libc::c_int as uint64_t, 32 as libc::c_int as uint64_t); return 0; }" }, { "index": 987, "before": "uint64_t egyptian_division(uint64_t dividend, uint64_t divisor, uint64_t *remainder) { \t// remainder is an out parameter, pass NULL if you do not need the remainder \tstatic uint64_t powers[64]; \tstatic uint64_t doublings[64]; \tint i; \tfor(i = 0; i < 64; i++) { \t\tpowers[i] = 1 << i; \t\tdoublings[i] = divisor << i; \t\tif(doublings[i] > dividend) \t\t\tbreak; \t} \tuint64_t answer = 0; \tuint64_t accumulator = 0; \tfor(i = i - 1; i >= 0; i--) { \t\t// If the current value of the accumulator added to the \t\t// doublings cell would be less than or equal to the \t\t// dividend then add it to the accumulator \t\tif(accumulator + doublings[i] <= dividend) { \t\t\taccumulator += doublings[i]; \t\t\tanswer += powers[i]; \t\t} \t} \tif(remainder) \t\t*remainder = dividend - accumulator; \treturn answer; }", "after": "pub unsafe extern \"C\" fn egyptian_division( mut dividend: uint64_t, mut divisor: uint64_t, mut remainder: *mut uint64_t, ) -> uint64_t { static mut powers: [uint64_t; 64] = [0; 64]; static mut doublings: [uint64_t; 64] = [0; 64]; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 64 as libc::c_int { powers[i as usize] = ((1 as libc::c_int) << i) as uint64_t; doublings[i as usize] = divisor << i; if doublings[i as usize] > dividend { break; } i += 1; i; } let mut answer: uint64_t = 0 as libc::c_int as uint64_t; let mut accumulator: uint64_t = 0 as libc::c_int as uint64_t; i = i - 1 as libc::c_int; while i >= 0 as libc::c_int { if accumulator.wrapping_add(doublings[i as usize]) <= dividend { accumulator = (accumulator as libc::c_ulong) .wrapping_add(doublings[i as usize]) as uint64_t as uint64_t; answer = (answer as libc::c_ulong).wrapping_add(powers[i as usize]) as uint64_t as uint64_t; } i -= 1; i; } if !remainder.is_null() { *remainder = dividend.wrapping_sub(accumulator); } return answer; }" }, { "index": 988, "before": "void go(uint64_t a, uint64_t b) { \tuint64_t x, y; \tx = egyptian_division(a, b, &y); \tprintf(\"%llu / %llu = %llu remainder %llu\\n\", a, b, x, y); \tassert(a == b * x + y); }", "after": "pub unsafe extern \"C\" fn go(mut a: uint64_t, mut b: uint64_t) { let mut x: uint64_t = 0; let mut y: uint64_t = 0; x = egyptian_division(a, b, &mut y); printf( b\"%llu / %llu = %llu remainder %llu\\n\\0\" as *const u8 as *const libc::c_char, a, b, x, y, ); if a == b.wrapping_mul(x).wrapping_add(y) {} else { __assert_fail( b\"a == b * x + y\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 43 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 28], &[libc::c_char; 28], >(b\"void go(uint64_t, uint64_t)\\0\")) .as_ptr(), ); } 'c_1638: { if a == b.wrapping_mul(x).wrapping_add(y) {} else { __assert_fail( b\"a == b * x + y\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 43 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 28], &[libc::c_char; 28], >(b\"void go(uint64_t, uint64_t)\\0\")) .as_ptr(), ); } }; }" }, { "index": 989, "before": "int main() { char is_open[100] = { 0 }; int pass, door; /* do the 100 passes */ for (pass = 0; pass < 100; ++pass) for (door = pass; door < 100; door += pass+1) is_open[door] = !is_open[door]; /* output the result */ for (door = 0; door < 100; ++door) printf(\"door #%d is %s.\\n\", door+1, (is_open[door]? \"open\" : \"closed\")); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut is_open: [libc::c_char; 100] = [ 0 as libc::c_int as libc::c_char, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut pass: libc::c_int = 0; let mut door: libc::c_int = 0; pass = 0 as libc::c_int; while pass < 100 as libc::c_int { door = pass; while door < 100 as libc::c_int { is_open[door as usize] = (is_open[door as usize] == 0) as libc::c_int as libc::c_char; door += pass + 1 as libc::c_int; } pass += 1; pass; } door = 0 as libc::c_int; while door < 100 as libc::c_int { printf( b\"door #%d is %s.\\n\\0\" as *const u8 as *const libc::c_char, door + 1 as libc::c_int, if is_open[door as usize] as libc::c_int != 0 { b\"open\\0\" as *const u8 as *const libc::c_char } else { b\"closed\\0\" as *const u8 as *const libc::c_char }, ); door += 1; door; } return 0 as libc::c_int; }" }, { "index": 990, "before": "int main() { char * result = string_repeat(5, \"ha\"); puts(result); free(result); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut result: *mut libc::c_char = string_repeat( 5 as libc::c_int, b\"ha\\0\" as *const u8 as *const libc::c_char, ); puts(result); free(result as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 991, "before": "int verify(struct node *p) { \tif (p == nnil) \t\treturn 1; \tint h0 = p->kid[0]->height, h1 = p->kid[1]->height; \tint b = h0 - h1; \tif (p->height != 1 + max(h0, h1) || b < -1 || b > 1) \t{ \t\tprintf(\"node %d bad, balance %d\\n\", p->payload, b); \t\tshow_tree(p, 0, 0); \t\tabort(); \t} \treturn verify(p->kid[0]) && verify(p->kid[1]); }", "after": "pub unsafe extern \"C\" fn verify(mut p: *mut node) -> libc::c_int { if p == nnil { return 1 as libc::c_int; } let mut h0: libc::c_int = (*(*p).kid[0 as libc::c_int as usize]).height; let mut h1: libc::c_int = (*(*p).kid[1 as libc::c_int as usize]).height; let mut b: libc::c_int = h0 - h1; if (*p).height != 1 as libc::c_int + max(h0, h1) || b < -(1 as libc::c_int) || b > 1 as libc::c_int { printf( b\"node %d bad, balance %d\\n\\0\" as *const u8 as *const libc::c_char, (*p).payload, b, ); show_tree(p, 0 as *mut trunk, 0 as libc::c_int); abort(); } return (verify((*p).kid[0 as libc::c_int as usize]) != 0 && verify((*p).kid[1 as libc::c_int as usize]) != 0) as libc::c_int; }" }, { "index": 992, "before": "void set_height(struct node *n) { \tn->height = 1 + max(n->kid[0]->height, n->kid[1]->height); }", "after": "pub unsafe extern \"C\" fn set_height(mut n: *mut node) { (*n) .height = 1 as libc::c_int + max( (*(*n).kid[0 as libc::c_int as usize]).height, (*(*n).kid[1 as libc::c_int as usize]).height, ); }" }, { "index": 993, "before": "void show_trunks(struct trunk *p) { \tif (!p) \t\treturn; \tshow_trunks(p->prev); \tprintf(\"%s\", p->str); }", "after": "pub unsafe extern \"C\" fn show_trunks(mut p: *mut trunk) { if p.is_null() { return; } show_trunks((*p).prev); printf(b\"%s\\0\" as *const u8 as *const libc::c_char, (*p).str_0); }" }, { "index": 994, "before": "int main(void) { \tint x; \tstruct node *root = nnil; \tsrand(time(0)); \tfor (x = 0; x < 10 * MAX_VAL; x++) \t{ \t\t// random insertion and deletion \t\tif (rand() & 1) \t\t\tinsert(&root, rand() % MAX_VAL); \t\telse \t\t\tdelete (&root, rand() % MAX_VAL); \t\tverify(root); \t} \tputs(\"Tree is:\"); \tshow_tree(root, 0, 0); \tputs(\"\\nQuerying values:\"); \tfor (x = 0; x < MAX_VAL; x++) \t{ \t\tstruct node *p = query(root, x); \t\tif (p) \t\t\tprintf(\"%2d found: %p %d\\n\", x, p, p->payload); \t} \tfor (x = 0; x < MAX_VAL; x++) \t{ \t\tdelete (&root, x); \t\tverify(root); \t} \tputs(\"\\nAfter deleting all values, tree is:\"); \tshow_tree(root, 0, 0); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut x: libc::c_int = 0; let mut root: *mut node = nnil; srand(time(0 as *mut time_t) as libc::c_uint); x = 0 as libc::c_int; while x < 10 as libc::c_int * 32 as libc::c_int { if rand() & 1 as libc::c_int != 0 { insert(&mut root, rand() % 32 as libc::c_int); } else { delete(&mut root, rand() % 32 as libc::c_int); } verify(root); x += 1; x; } puts(b\"Tree is:\\0\" as *const u8 as *const libc::c_char); show_tree(root, 0 as *mut trunk, 0 as libc::c_int); puts(b\"\\nQuerying values:\\0\" as *const u8 as *const libc::c_char); x = 0 as libc::c_int; while x < 32 as libc::c_int { let mut p: *mut node = query(root, x); if !p.is_null() { printf( b\"%2d found: %p %d\\n\\0\" as *const u8 as *const libc::c_char, x, p, (*p).payload, ); } x += 1; x; } x = 0 as libc::c_int; while x < 32 as libc::c_int { delete(&mut root, x); verify(root); x += 1; x; } puts(b\"\\nAfter deleting all values, tree is:\\0\" as *const u8 as *const libc::c_char); show_tree(root, 0 as *mut trunk, 0 as libc::c_int); return 0 as libc::c_int; }" }, { "index": 995, "before": "int max(int a, int b) { return a > b ? a : b; }", "after": "pub unsafe extern \"C\" fn max(mut a: libc::c_int, mut b: libc::c_int) -> libc::c_int { return if a > b { a } else { b }; }" }, { "index": 996, "before": "void adjust_balance(struct node **rootp) { \tstruct node *root = *rootp; \tint b = ballance(root) / 2; \tif (b) \t{ \t\tint dir = (1 - b) / 2; \t\tif (ballance(root->kid[dir]) == -b) \t\t\trotate(&root->kid[dir], !dir); \t\troot = rotate(rootp, dir); \t} \tif (root != nnil) \t\tset_height(root); }", "after": "pub unsafe extern \"C\" fn adjust_balance(mut rootp: *mut *mut node) { let mut root: *mut node = *rootp; let mut b: libc::c_int = ballance(root) / 2 as libc::c_int; if b != 0 { let mut dir: libc::c_int = (1 as libc::c_int - b) / 2 as libc::c_int; if ballance((*root).kid[dir as usize]) == -b { rotate( &mut *((*root).kid).as_mut_ptr().offset(dir as isize), (dir == 0) as libc::c_int, ); } root = rotate(rootp, dir); } if root != nnil { set_height(root); } }" }, { "index": 997, "before": "void insert(struct node **rootp, int value) { \tstruct node *root = *rootp; \tif (root == nnil) \t\t*rootp = new_node(value); \telse if (value != root->payload) \t{ // don't allow dup keys \t\tinsert(&root->kid[value > root->payload], value); \t\tadjust_balance(rootp); \t} }", "after": "pub unsafe extern \"C\" fn insert(mut rootp: *mut *mut node, mut value: libc::c_int) { let mut root: *mut node = *rootp; if root == nnil { *rootp = new_node(value); } else if value != (*root).payload { insert( &mut *((*root).kid) .as_mut_ptr() .offset((value > (*root).payload) as libc::c_int as isize), value, ); adjust_balance(rootp); } }" }, { "index": 998, "before": "void delete (struct node **rootp, int value) { \tstruct node *root = *rootp; \tif (root == nnil) \t\treturn; // not found \t// if this is the node we want, rotate until off the tree \tif (root->payload == value) \t\tif (nnil == (root = rotate(rootp, ballance(root) < 0))) \t\t\treturn; \tdelete (&root->kid[value > root->payload], value); \tadjust_balance(rootp); }", "after": "pub unsafe extern \"C\" fn delete(mut rootp: *mut *mut node, mut value: libc::c_int) { let mut root: *mut node = *rootp; if root == nnil { return; } if (*root).payload == value { root = rotate(rootp, (ballance(root) < 0 as libc::c_int) as libc::c_int); if nnil == root { return; } } delete( &mut *((*root).kid) .as_mut_ptr() .offset((value > (*root).payload) as libc::c_int as isize), value, ); adjust_balance(rootp); }" }, { "index": 999, "before": "int ballance(struct node *n) { \treturn n->kid[0]->height - n->kid[1]->height; }", "after": "pub unsafe extern \"C\" fn ballance(mut n: *mut node) -> libc::c_int { return (*(*n).kid[0 as libc::c_int as usize]).height - (*(*n).kid[1 as libc::c_int as usize]).height; }" }, { "index": 1000, "before": "void show_tree(struct node *root, struct trunk *prev, int is_left) { \tif (root == nnil) \t\treturn; \tstruct trunk this_disp = {prev, \" \"}; \tchar *prev_str = this_disp.str; \tshow_tree(root->kid[0], &this_disp, 1); \tif (!prev) \t\tthis_disp.str = \"---\"; \telse if (is_left) \t{ \t\tthis_disp.str = \".--\"; \t\tprev_str = \" |\"; \t} \telse \t{ \t\tthis_disp.str = \"`--\"; \t\tprev->str = prev_str; \t} \tshow_trunks(&this_disp); \tprintf(\"%d\\n\", root->payload); \tif (prev) \t\tprev->str = prev_str; \tthis_disp.str = \" |\"; \tshow_tree(root->kid[1], &this_disp, 0); \tif (!prev) \t\tputs(\"\"); }", "after": "pub unsafe extern \"C\" fn show_tree( mut root: *mut node, mut prev: *mut trunk, mut is_left: libc::c_int, ) { if root == nnil { return; } let mut this_disp: trunk = { let mut init = trunk { prev: prev, str_0: b\" \\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, }; init }; let mut prev_str: *mut libc::c_char = this_disp.str_0; show_tree((*root).kid[0 as libc::c_int as usize], &mut this_disp, 1 as libc::c_int); if prev.is_null() { this_disp .str_0 = b\"---\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; } else if is_left != 0 { this_disp .str_0 = b\".--\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; prev_str = b\" |\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; } else { this_disp .str_0 = b\"`--\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; (*prev).str_0 = prev_str; } show_trunks(&mut this_disp); printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, (*root).payload); if !prev.is_null() { (*prev).str_0 = prev_str; } this_disp.str_0 = b\" |\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; show_tree((*root).kid[1 as libc::c_int as usize], &mut this_disp, 0 as libc::c_int); if prev.is_null() { puts(b\"\\0\" as *const u8 as *const libc::c_char); } }" }, { "index": 1001, "before": "int seq_next(void *state) { \treturn ((gen_t*)state)->output = (*(seq_func*)state)(state); }", "after": "pub unsafe extern \"C\" fn seq_next(mut state: *mut libc::c_void) -> libc::c_int { let ref mut fresh0 = (*(state as *mut gen_t)).output; *fresh0 = (*(state as *mut seq_func)).expect(\"non-null function pointer\")(state); return *fresh0; }" }, { "index": 1002, "before": "int power_next(void *s) { \treturn (int)pow(++((power_gen_t*)s)->pos, ((power_gen_t*)s)->n); }", "after": "pub unsafe extern \"C\" fn power_next(mut s: *mut libc::c_void) -> libc::c_int { let ref mut fresh1 = (*(s as *mut power_gen_t)).pos; *fresh1 += 1; return pow(*fresh1 as libc::c_double, (*(s as *mut power_gen_t)).n as libc::c_double) as libc::c_int; }" }, { "index": 1003, "before": "int filter_next(void *s) { \tgen_t *in = ((filter_gen_t*)s)->in, *wo = ((filter_gen_t*)s)->without; \tdo{ \t\tseq_next(in); \t\twhile (wo->output < in->output) \t\t\tseq_next(wo); \t} while(wo->output == in->output); \treturn in->output; }", "after": "pub unsafe extern \"C\" fn filter_next(mut s: *mut libc::c_void) -> libc::c_int { let mut in_0: *mut gen_t = (*(s as *mut filter_gen_t)).in_0 as *mut gen_t; let mut wo: *mut gen_t = (*(s as *mut filter_gen_t)).without as *mut gen_t; loop { seq_next(in_0 as *mut libc::c_void); while (*wo).output < (*in_0).output { seq_next(wo as *mut libc::c_void); } if !((*wo).output == (*in_0).output) { break; } } return (*in_0).output; }" }, { "index": 1004, "before": "int main() { \tint i; \tvoid *s = filter_seq(power_seq(2), power_seq(3)); \tfor (i = 0; i < 20; i++) seq_next(s); \tfor (i = 0; i < 10; i++) \t\tprintf(\"%d\\n\", seq_next(s)); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut s: *mut libc::c_void = filter_seq( power_seq(2 as libc::c_int) as *mut gen_t, power_seq(3 as libc::c_int) as *mut gen_t, ); i = 0 as libc::c_int; while i < 20 as libc::c_int { seq_next(s); i += 1; i; } i = 0 as libc::c_int; while i < 10 as libc::c_int { printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, seq_next(s)); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1005, "before": "Range maxSubseq(const int sequence[], const int len) { int maxSum = 0, thisSum = 0, i = 0; int start = 0, end = -1, j; for (j = 0; j < len; j++) { thisSum += sequence[j]; if (thisSum < 0) { i = j + 1; thisSum = 0; } else if (thisSum > maxSum) { maxSum = thisSum; start = i; end = j; } } Range r; if (start <= end && start >= 0 && end >= 0) { r.start = start; r.end = end + 1; r.sum = maxSum; } else { r.start = 0; r.end = 0; r.sum = 0; } return r; }", "after": "pub unsafe extern \"C\" fn maxSubseq( mut sequence: *const libc::c_int, len: libc::c_int, ) -> Range { let mut maxSum: libc::c_int = 0 as libc::c_int; let mut thisSum: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 0 as libc::c_int; let mut start: libc::c_int = 0 as libc::c_int; let mut end: libc::c_int = -(1 as libc::c_int); let mut j: libc::c_int = 0; j = 0 as libc::c_int; while j < len { thisSum += *sequence.offset(j as isize); if thisSum < 0 as libc::c_int { i = j + 1 as libc::c_int; thisSum = 0 as libc::c_int; } else if thisSum > maxSum { maxSum = thisSum; start = i; end = j; } j += 1; j; } let mut r: Range = Range { start: 0, end: 0, sum: 0 }; if start <= end && start >= 0 as libc::c_int && end >= 0 as libc::c_int { r.start = start; r.end = end + 1 as libc::c_int; r.sum = maxSum; } else { r.start = 0 as libc::c_int; r.end = 0 as libc::c_int; r.sum = 0 as libc::c_int; } return r; }" }, { "index": 1006, "before": "int main(int argc, char **argv) { int a[] = {-1 , -2 , 3 , 5 , 6 , -2 , -1 , 4 , -4 , 2 , -1}; int alength = sizeof(a)/sizeof(a[0]); Range r = maxSubseq(a, alength); printf(\"Max sum = %d\\n\", r.sum); int i; for (i = r.start; i < r.end; i++) printf(\"%d \", a[i]); 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 a: [libc::c_int; 11] = [ -(1 as libc::c_int), -(2 as libc::c_int), 3 as libc::c_int, 5 as libc::c_int, 6 as libc::c_int, -(2 as libc::c_int), -(1 as libc::c_int), 4 as libc::c_int, -(4 as libc::c_int), 2 as libc::c_int, -(1 as libc::c_int), ]; let mut alength: libc::c_int = (::core::mem::size_of::<[libc::c_int; 11]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int; let mut r: Range = maxSubseq(a.as_mut_ptr() as *const libc::c_int, alength); printf(b\"Max sum = %d\\n\\0\" as *const u8 as *const libc::c_char, r.sum); let mut i: libc::c_int = 0; i = r.start; while i < r.end { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, a[i as usize]); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1007, "before": "float median(FloatList fl) { qsort(fl->list, fl->size, sizeof(float), floatcmp); return 0.5 * (fl->list[fl->size / 2] + fl->list[(fl->size - 1) / 2]); }", "after": "pub unsafe extern \"C\" fn median(mut fl: FloatList) -> libc::c_float { qsort( (*fl).list as *mut libc::c_void, (*fl).size as size_t, ::core::mem::size_of::() as libc::c_ulong, Some( floatcmp as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); return (0.5f64 * (*((*fl).list).offset(((*fl).size / 2 as libc::c_int) as isize) + *((*fl).list) .offset((((*fl).size - 1 as libc::c_int) / 2 as libc::c_int) as isize)) as libc::c_double) as libc::c_float; }" }, { "index": 1008, "before": "int floatcmp(const void *a, const void *b) { if (*(const float *)a < *(const float *)b) return -1; else return *(const float *)a > *(const float *)b; }", "after": "pub unsafe extern \"C\" fn floatcmp( mut a: *const libc::c_void, mut b: *const libc::c_void, ) -> libc::c_int { if *(a as *const libc::c_float) < *(b as *const libc::c_float) { return -(1 as libc::c_int) } else { return (*(a as *const libc::c_float) > *(b as *const libc::c_float)) as libc::c_int }; }" }, { "index": 1009, "before": "int main() { float floats1[] = {5.1, 2.6, 6.2, 8.8, 4.6, 4.1}; struct floatList flist1 = {floats1, sizeof(floats1) / sizeof(float)}; float floats2[] = {5.1, 2.6, 8.8, 4.6, 4.1}; struct floatList flist2 = {floats2, sizeof(floats2) / sizeof(float)}; printf(\"flist1 median is %7.2f\\n\", median(&flist1)); /* 4.85 */ printf(\"flist2 median is %7.2f\\n\", median(&flist2)); /* 4.60 */ return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut floats1: [libc::c_float; 6] = [ 5.1f64 as libc::c_float, 2.6f64 as libc::c_float, 6.2f64 as libc::c_float, 8.8f64 as libc::c_float, 4.6f64 as libc::c_float, 4.1f64 as libc::c_float, ]; let mut flist1: floatList = { let mut init = floatList { list: floats1.as_mut_ptr(), size: (::core::mem::size_of::<[libc::c_float; 6]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, }; init }; let mut floats2: [libc::c_float; 5] = [ 5.1f64 as libc::c_float, 2.6f64 as libc::c_float, 8.8f64 as libc::c_float, 4.6f64 as libc::c_float, 4.1f64 as libc::c_float, ]; let mut flist2: floatList = { let mut init = floatList { list: floats2.as_mut_ptr(), size: (::core::mem::size_of::<[libc::c_float; 5]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, }; init }; printf( b\"flist1 median is %7.2f\\n\\0\" as *const u8 as *const libc::c_char, median(&mut flist1) as libc::c_double, ); printf( b\"flist2 median is %7.2f\\n\\0\" as *const u8 as *const libc::c_char, median(&mut flist2) as libc::c_double, ); return 0 as libc::c_int; }" }, { "index": 1010, "before": "int main(int argc, char const *argv[]) { mpz_t fermat; mpz_init_set_ui(fermat, 3); printf(\"F(0) = 3 -> PRIME\\n\"); for (unsigned i = 1; i < 7; i++) { mpz_sub_ui(fermat, fermat, 1); mpz_mul(fermat, fermat, fermat); mpz_add_ui(fermat, fermat, 1); gmp_printf(\"F(%d) = %Zd -> \", i, fermat); mpz_factors(fermat); } return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *const libc::c_char, ) -> libc::c_int { printf(b\"F(0) = 3 -> PRIME\\n\\0\" as *const u8 as *const libc::c_char); let mut i: libc::c_uint = 1 as libc::c_int as libc::c_uint; while i < 7 as libc::c_int as libc::c_uint { i = i.wrapping_add(1); i; } return 0 as libc::c_int; }" }, { "index": 1011, "before": "int main() { int i, nCards, nShuffles; int *deck = NULL; for( i=0; i libc::c_int { let mut i: libc::c_int = 0; let mut nCards: libc::c_int = 0; let mut nShuffles: libc::c_int = 0; let mut deck: *mut libc::c_int = 0 as *mut libc::c_int; i = 0 as libc::c_int; while i < 7 as libc::c_int { nCards = kDecks[i as usize]; if CreateDeck(&mut deck, nCards) == 0 { fprintf( stderr, b\"Error: malloc() failed!\\n\\0\" as *const u8 as *const libc::c_char, ); return 1 as libc::c_int; } InitDeck(deck, nCards); nShuffles = 0 as libc::c_int; loop { ShuffleDeck(deck, nCards); nShuffles += 1; nShuffles; if !(InitedDeck(deck, nCards) == 0) { break; } } printf( b\"Cards count: %d, shuffles required: %d.\\n\\0\" as *const u8 as *const libc::c_char, nCards, nShuffles, ); FreeDeck(&mut deck); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1012, "before": "int DuplicateDeck( int **dest, const int *orig, int nCards ) { if( orig != NULL && CreateDeck(dest,nCards) ) { memcpy( *dest, orig, nCards*sizeof(*orig) ); return 1; /* success */ } else { return 0; /* failure */ } }", "after": "pub unsafe extern \"C\" fn DuplicateDeck( mut dest: *mut *mut libc::c_int, mut orig: *const libc::c_int, mut nCards: libc::c_int, ) -> libc::c_int { if !orig.is_null() && CreateDeck(dest, nCards) != 0 { memcpy( *dest as *mut libc::c_void, orig as *const libc::c_void, (nCards as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ); return 1 as libc::c_int; } else { return 0 as libc::c_int }; }" }, { "index": 1013, "before": "void InitDeck( int *deck, int nCards ) { if( deck != NULL ) { int i; for( i=0; i libc::c_int { let mut tmp: *mut libc::c_int = 0 as *mut libc::c_int; if !deck.is_null() { tmp = malloc( (nCards as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_int; } return if !tmp.is_null() { *deck = tmp; (*deck != 0 as *mut libc::c_void as *mut libc::c_int) as libc::c_int } else { 0 as libc::c_int }; }" }, { "index": 1015, "before": "int InitedDeck( int *deck, int nCards ) { int i; for( i=0; i libc::c_int { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < nCards { if *deck.offset(i as isize) != i { return 0 as libc::c_int; } i += 1; i; } return 1 as libc::c_int; }" }, { "index": 1016, "before": "int ShuffleDeck( int *deck, int nCards ) { int *copy = NULL; if( DuplicateDeck(©,deck,nCards) ) { int i, j; for( i=j=0; i libc::c_int { let mut copy: *mut libc::c_int = 0 as *mut libc::c_int; if DuplicateDeck(&mut copy, deck, nCards) != 0 { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; j = 0 as libc::c_int; i = j; while i < nCards / 2 as libc::c_int { *deck.offset(j as isize) = *copy.offset(i as isize); *deck .offset( (j + 1 as libc::c_int) as isize, ) = *copy.offset((i + nCards / 2 as libc::c_int) as isize); i += 1; i; j += 2 as libc::c_int; } FreeDeck(&mut copy); return 1 as libc::c_int; } else { return 0 as libc::c_int }; }" }, { "index": 1017, "before": "void FreeDeck( int **deck ) { if( *deck != NULL ) { free( *deck ); *deck = NULL; } }", "after": "pub unsafe extern \"C\" fn FreeDeck(mut deck: *mut *mut libc::c_int) { if !(*deck).is_null() { free(*deck as *mut libc::c_void); *deck = 0 as *mut libc::c_int; } }" }, { "index": 1018, "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": "unsafe fn main() -> libc::c_int { printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp( 3 as libc::c_int, b\"interspecies\\0\" as *const u8 as *const libc::c_char, b\"interstellar\\0\" as *const u8 as *const libc::c_char, b\"interstate\\0\" as *const u8 as *const libc::c_char, ), ); printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp( 2 as libc::c_int, b\"throne\\0\" as *const u8 as *const libc::c_char, b\"throne\\0\" as *const u8 as *const libc::c_char, ), ); printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp( 2 as libc::c_int, b\"throne\\0\" as *const u8 as *const libc::c_char, b\"dungeon\\0\" as *const u8 as *const libc::c_char, ), ); printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp( 3 as libc::c_int, b\"throne\\0\" as *const u8 as *const libc::c_char, b\"\\0\" as *const u8 as *const libc::c_char, b\"throne\\0\" as *const u8 as *const libc::c_char, ), ); printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp(1 as libc::c_int, b\"cheese\\0\" as *const u8 as *const libc::c_char), ); printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp(1 as libc::c_int, b\"\\0\" as *const u8 as *const libc::c_char), ); printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp(0 as libc::c_int, 0 as *mut libc::c_void), ); printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp( 2 as libc::c_int, b\"prefix\\0\" as *const u8 as *const libc::c_char, b\"suffix\\0\" as *const u8 as *const libc::c_char, ), ); printf( b\"\\nLongest common prefix : %s\\0\" as *const u8 as *const libc::c_char, lcp( 2 as libc::c_int, b\"foo\\0\" as *const u8 as *const libc::c_char, b\"foobar\\0\" as *const u8 as *const libc::c_char, ), ); return 0 as libc::c_int; }" }, { "index": 1019, "before": "int main(){ int bounds[ 2 ] = {1, 100}; char input[ 2 ] = \" \"; /* second char is for the newline from hitting [return] */ int choice = (bounds[ 0 ] + bounds[ 1 ]) / 2; /* using a binary search */ printf( \"Choose a number between %d and %d.\\n\", bounds[ 0 ], bounds[ 1 ] ); do{ switch( input[ 0 ] ){ case 'H': bounds[ 1 ] = choice; break; case 'L': bounds[ 0 ] = choice; break; case 'Y': printf( \"\\nAwwwright\\n\" ); return 0; } choice = (bounds[ 0 ] + bounds[ 1 ]) / 2; printf( \"Is the number %d? (Y/H/L) \", choice ); }while( scanf( \"%1s\", input ) == 1 ); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut bounds: [libc::c_int; 2] = [1 as libc::c_int, 100 as libc::c_int]; let mut input: [libc::c_char; 2] = *::core::mem::transmute::< &[u8; 2], &mut [libc::c_char; 2], >(b\" \"); let mut choice: libc::c_int = (bounds[0 as libc::c_int as usize] + bounds[1 as libc::c_int as usize]) / 2 as libc::c_int; printf( b\"Choose a number between %d and %d.\\n\\0\" as *const u8 as *const libc::c_char, bounds[0 as libc::c_int as usize], bounds[1 as libc::c_int as usize], ); loop { match input[0 as libc::c_int as usize] as libc::c_int { 72 => { bounds[1 as libc::c_int as usize] = choice; } 76 => { bounds[0 as libc::c_int as usize] = choice; } 89 => { printf(b\"\\nAwwwright\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; } _ => {} } choice = (bounds[0 as libc::c_int as usize] + bounds[1 as libc::c_int as usize]) / 2 as libc::c_int; printf( b\"Is the number %d? (Y/H/L) \\0\" as *const u8 as *const libc::c_char, choice, ); if !(scanf(b\"%1s\\0\" as *const u8 as *const libc::c_char, input.as_mut_ptr()) == 1 as libc::c_int) { break; } } return 0 as libc::c_int; }" }, { "index": 1020, "before": "int main() { time_t timestamp = time(0); const int seconds_per_day = 24*60*60; int count = 15; char str[32]; printf(\"Next %d palindrome dates:\\n\", count); for (; count > 0; timestamp += seconds_per_day) { struct tm* ptr = gmtime(×tamp); strftime(str, sizeof(str), \"%Y%m%d\", ptr); if (is_palindrome(str)) { strftime(str, sizeof(str), \"%F\", ptr); printf(\"%s\\n\", str); --count; } } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut timestamp: time_t = time(0 as *mut time_t); let seconds_per_day: libc::c_int = 24 as libc::c_int * 60 as libc::c_int * 60 as libc::c_int; let mut count: libc::c_int = 15 as libc::c_int; let mut str: [libc::c_char; 32] = [0; 32]; printf(b\"Next %d palindrome dates:\\n\\0\" as *const u8 as *const libc::c_char, count); while count > 0 as libc::c_int { let mut ptr: *mut tm = gmtime(&mut timestamp); strftime( str.as_mut_ptr(), ::core::mem::size_of::<[libc::c_char; 32]>() as libc::c_ulong, b\"%Y%m%d\\0\" as *const u8 as *const libc::c_char, ptr, ); if is_palindrome(str.as_mut_ptr()) { strftime( str.as_mut_ptr(), ::core::mem::size_of::<[libc::c_char; 32]>() as libc::c_ulong, b\"%F\\0\" as *const u8 as *const libc::c_char, ptr, ); printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, str.as_mut_ptr()); count -= 1; count; } timestamp += seconds_per_day as libc::c_long; } return 0 as libc::c_int; }" }, { "index": 1021, "before": "bool is_palindrome(const char* str) { size_t n = strlen(str); for (size_t i = 0; i + 1 < n; ++i, --n) { if (str[i] != str[n - 1]) return false; } return true; }", "after": "pub unsafe extern \"C\" fn is_palindrome(mut str: *const libc::c_char) -> bool { let mut n: size_t = strlen(str); let mut i: size_t = 0 as libc::c_int as size_t; while i.wrapping_add(1 as libc::c_int as libc::c_ulong) < n { if *str.offset(i as isize) as libc::c_int != *str.offset(n.wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize) as libc::c_int { return 0 as libc::c_int != 0; } i = i.wrapping_add(1); i; n = n.wrapping_sub(1); n; } return 1 as libc::c_int != 0; }" }, { "index": 1022, "before": "int trie_all(trie root, char path[], int depth, int (*callback)(char *)) { int i; if (root->eow && !callback(path)) return 0; for (i = 1; i < sizeof(chr_legal); i++) { if (!root->next[i]) continue; path[depth] = idx_chr[i]; path[depth + 1] = '\\0'; if (!trie_all(root->next[i], path, depth + 1, callback)) return 0; } return 1; }", "after": "pub unsafe extern \"C\" fn trie_all( mut root: trie, mut path: *mut libc::c_char, mut depth: libc::c_int, mut callback: Option:: libc::c_int>, ) -> libc::c_int { let mut i: libc::c_int = 0; if (*root).eow != 0 && callback.expect(\"non-null function pointer\")(path) == 0 { return 0 as libc::c_int; } i = 1 as libc::c_int; while (i as libc::c_ulong) < ::core::mem::size_of::<[libc::c_char; 41]>() as libc::c_ulong { if !((*root).next[i as usize]).is_null() { *path.offset(depth as isize) = idx_chr[i as usize]; *path .offset( (depth + 1 as libc::c_int) as isize, ) = '\\0' as i32 as libc::c_char; if trie_all( (*root).next[i as usize], path, depth + 1 as libc::c_int, callback, ) == 0 { return 0 as libc::c_int; } } i += 1; i; } return 1 as libc::c_int; }" }, { "index": 1023, "before": "trie trie_trav(trie root, const char * str, int no_create) { int c; while (root) { if ((c = str[0]) == '\\0') { if (!root->eow && no_create) return 0; break; } if (! (c = chr_idx[c]) ) { str++; continue; } if (!root->next[c]) { if (no_create) return 0; root->next[c] = trie_new(); } root = root->next[c]; str++; } return root; }", "after": "pub unsafe extern \"C\" fn trie_trav( mut root: trie, mut str: *const libc::c_char, mut no_create: libc::c_int, ) -> trie { let mut c: libc::c_int = 0; while !root.is_null() { c = *str.offset(0 as libc::c_int as isize) as libc::c_int; if c == '\\0' as i32 { if (*root).eow == 0 && no_create != 0 { return 0 as trie; } break; } else { c = chr_idx[c as usize]; if c == 0 { str = str.offset(1); str; } else { if ((*root).next[c as usize]).is_null() { if no_create != 0 { return 0 as trie; } (*root).next[c as usize] = trie_new(); } root = (*root).next[c as usize]; str = str.offset(1); str; } } } return root; }" }, { "index": 1024, "before": "int print_path(char *path) { printf(\" %s\", path); return 1; }", "after": "pub unsafe extern \"C\" fn print_path(mut path: *mut libc::c_char) -> libc::c_int { printf(b\" %s\\0\" as *const u8 as *const libc::c_char, path); return 1 as libc::c_int; }" }, { "index": 1025, "before": "void add_index(trie root, const char *word, const char *fname) { trie x = trie_trav(root, word, 0); x->eow = 1; if (!x->next[FNAME]) x->next[FNAME] = trie_new(); x = trie_trav(x->next[FNAME], fname, 0); x->eow = 1; }", "after": "pub unsafe extern \"C\" fn add_index( mut root: trie, mut word: *const libc::c_char, mut fname: *const libc::c_char, ) { let mut x: trie = trie_trav(root, word, 0 as libc::c_int); (*x).eow = 1 as libc::c_int; if ((*x).next[0 as libc::c_int as usize]).is_null() { (*x).next[0 as libc::c_int as usize] = trie_new(); } x = trie_trav((*x).next[0 as libc::c_int as usize], fname, 0 as libc::c_int); (*x).eow = 1 as libc::c_int; }" }, { "index": 1026, "before": "void search_index(trie root, const char *word) { char path[1024]; printf(\"Search for \\\"%s\\\": \", word); trie found = find_word(root, word); if (!found) printf(\"not found\\n\"); else { trie_all(found->next[FNAME], path, 0, print_path); printf(\"\\n\"); } }", "after": "pub unsafe extern \"C\" fn search_index(mut root: trie, mut word: *const libc::c_char) { let mut path: [libc::c_char; 1024] = [0; 1024]; printf(b\"Search for \\\"%s\\\": \\0\" as *const u8 as *const libc::c_char, word); let mut found: trie = trie_trav(root, word, 1 as libc::c_int); if found.is_null() { printf(b\"not found\\n\\0\" as *const u8 as *const libc::c_char); } else { trie_all( (*found).next[0 as libc::c_int as usize], path.as_mut_ptr(), 0 as libc::c_int, Some(print_path as unsafe extern \"C\" fn(*mut libc::c_char) -> libc::c_int), ); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }; }" }, { "index": 1027, "before": "int main() { trie root = init_tables(); search_index(root, \"what\"); search_index(root, \"is\"); search_index(root, \"banana\"); search_index(root, \"boo\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut root: trie = init_tables(); search_index(root, b\"what\\0\" as *const u8 as *const libc::c_char); search_index(root, b\"is\\0\" as *const u8 as *const libc::c_char); search_index(root, b\"banana\\0\" as *const u8 as *const libc::c_char); search_index(root, b\"boo\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1028, "before": "trie trie_new() { return calloc(sizeof(trie_t), 1); }", "after": "pub unsafe extern \"C\" fn trie_new() -> trie { return calloc( ::core::mem::size_of::() as libc::c_ulong, 1 as libc::c_int as libc::c_ulong, ) as trie; }" }, { "index": 1029, "before": "trie init_tables() { int i, j; trie root = trie_new(); for (i = 0; i < sizeof(chr_legal); i++) { chr_idx[(int)chr_legal[i]] = i + 1; idx_chr[i + 1] = chr_legal[i]; } /* Enable USE_ADVANCED_FILE_HANDLING to use advanced file handling. * You need to have files named like above files[], with words in them * like in text[][]. Case doesn't matter (told you it's advanced). */ #define USE_ADVANCED_FILE_HANDLING 0 #if USE_ADVANCED_FILE_HANDLING void read_file(const char * fname) { char cmd[1024]; char word[1024]; sprintf(cmd, \"perl -p -e 'while(/(\\\\w+)/g) {print lc($1),\\\"\\\\n\\\"}' %s\", fname); FILE *in = popen(cmd, \"r\"); while (!feof(in)) { fscanf(in, \"%1000s\", word); add_index(root, word, fname); } pclose(in); }; read_file(\"f1.txt\"); read_file(\"source/f2.txt\"); read_file(\"other_file\"); #else for (i = 0; i < 3; i++) { for (j = 0; j < 5; j++) { if (!text[i][j]) break; add_index(root, text[i][j], files[i]); } } #endif /*USE_ADVANCED_FILE_HANDLING*/ return root; }", "after": "pub unsafe extern \"C\" fn init_tables() -> trie { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut root: trie = trie_new(); i = 0 as libc::c_int; while (i as libc::c_ulong) < ::core::mem::size_of::<[libc::c_char; 41]>() as libc::c_ulong { chr_idx[chr_legal[i as usize] as libc::c_int as usize] = i + 1 as libc::c_int; idx_chr[(i + 1 as libc::c_int) as usize] = chr_legal[i as usize]; i += 1; i; } i = 0 as libc::c_int; while i < 3 as libc::c_int { j = 0 as libc::c_int; while j < 5 as libc::c_int { if (text[i as usize][j as usize]).is_null() { break; } add_index(root, text[i as usize][j as usize], files[i as usize]); j += 1; j; } i += 1; i; } return root; }" }, { "index": 1030, "before": "int main () { double angleSet1[] = { 350, 10 }; double angleSet2[] = { 90, 180, 270, 360}; double angleSet3[] = { 10, 20, 30}; printf (\"\\nMean Angle for 1st set : %lf degrees\", meanAngle (angleSet1, 2)); printf (\"\\nMean Angle for 2nd set : %lf degrees\", meanAngle (angleSet2, 4)); printf (\"\\nMean Angle for 3rd set : %lf degrees\\n\", meanAngle (angleSet3, 3)); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut angleSet1: [libc::c_double; 2] = [ 350 as libc::c_int as libc::c_double, 10 as libc::c_int as libc::c_double, ]; let mut angleSet2: [libc::c_double; 4] = [ 90 as libc::c_int as libc::c_double, 180 as libc::c_int as libc::c_double, 270 as libc::c_int as libc::c_double, 360 as libc::c_int as libc::c_double, ]; let mut angleSet3: [libc::c_double; 3] = [ 10 as libc::c_int as libc::c_double, 20 as libc::c_int as libc::c_double, 30 as libc::c_int as libc::c_double, ]; printf( b\"\\nMean Angle for 1st set : %lf degrees\\0\" as *const u8 as *const libc::c_char, meanAngle(angleSet1.as_mut_ptr(), 2 as libc::c_int), ); printf( b\"\\nMean Angle for 2nd set : %lf degrees\\0\" as *const u8 as *const libc::c_char, meanAngle(angleSet2.as_mut_ptr(), 4 as libc::c_int), ); printf( b\"\\nMean Angle for 3rd set : %lf degrees\\n\\0\" as *const u8 as *const libc::c_char, meanAngle(angleSet3.as_mut_ptr(), 3 as libc::c_int), ); return 0 as libc::c_int; }" }, { "index": 1031, "before": "double meanAngle (double *angles, int size) { double y_part = 0, x_part = 0; int i; for (i = 0; i < size; i++) { x_part += cos (angles[i] * M_PI / 180); y_part += sin (angles[i] * M_PI / 180); } return atan2 (y_part / size, x_part / size) * 180 / M_PI; }", "after": "pub unsafe extern \"C\" fn meanAngle( mut angles: *mut libc::c_double, mut size: libc::c_int, ) -> libc::c_double { let mut y_part: libc::c_double = 0 as libc::c_int as libc::c_double; let mut x_part: libc::c_double = 0 as libc::c_int as libc::c_double; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < size { x_part += cos( *angles.offset(i as isize) * 3.14159265358979323846f64 / 180 as libc::c_int as libc::c_double, ); y_part += sin( *angles.offset(i as isize) * 3.14159265358979323846f64 / 180 as libc::c_int as libc::c_double, ); i += 1; i; } return atan2(y_part / size as libc::c_double, x_part / size as libc::c_double) * 180 as libc::c_int as libc::c_double / 3.14159265358979323846f64; }" }, { "index": 1032, "before": "int main () { int fibo[] = { 1, 1, 0 }, tribo[] = { 1, 1, 2, 0 }, tetra[] = { 1, 1, 2, 4, 0 }, luca[] = { 2, 1, 0 }; int *fibonacci = anynacci (fibo, 10), *tribonacci = anynacci (tribo, 10), *tetranacci = anynacci (tetra, 10), *lucas = anynacci(luca, 10); int i; printf (\"\\nFibonacci\\tTribonacci\\tTetranacci\\tLucas\\n\"); for (i = 0; i < 10; i++) printf (\"\\n%d\\t\\t%d\\t\\t%d\\t\\t%d\", fibonacci[i], tribonacci[i], tetranacci[i], lucas[i]); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut fibo: [libc::c_int; 3] = [ 1 as libc::c_int, 1 as libc::c_int, 0 as libc::c_int, ]; let mut tribo: [libc::c_int; 4] = [ 1 as libc::c_int, 1 as libc::c_int, 2 as libc::c_int, 0 as libc::c_int, ]; let mut tetra: [libc::c_int; 5] = [ 1 as libc::c_int, 1 as libc::c_int, 2 as libc::c_int, 4 as libc::c_int, 0 as libc::c_int, ]; let mut luca: [libc::c_int; 3] = [ 2 as libc::c_int, 1 as libc::c_int, 0 as libc::c_int, ]; let mut fibonacci: *mut libc::c_int = anynacci(fibo.as_mut_ptr(), 10 as libc::c_int); let mut tribonacci: *mut libc::c_int = anynacci( tribo.as_mut_ptr(), 10 as libc::c_int, ); let mut tetranacci: *mut libc::c_int = anynacci( tetra.as_mut_ptr(), 10 as libc::c_int, ); let mut lucas: *mut libc::c_int = anynacci(luca.as_mut_ptr(), 10 as libc::c_int); let mut i: libc::c_int = 0; printf( b\"\\nFibonacci\\tTribonacci\\tTetranacci\\tLucas\\n\\0\" as *const u8 as *const libc::c_char, ); i = 0 as libc::c_int; while i < 10 as libc::c_int { printf( b\"\\n%d\\t\\t%d\\t\\t%d\\t\\t%d\\0\" as *const u8 as *const libc::c_char, *fibonacci.offset(i as isize), *tribonacci.offset(i as isize), *tetranacci.offset(i as isize), *lucas.offset(i as isize), ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1033, "before": "int test (int a, int b) { /* mov EAX, [ESP+4] add EAX, [ESP+8] ret */ char code[] = {0x8B, 0x44, 0x24, 0x4, 0x3, 0x44, 0x24, 0x8, 0xC3}; void *buf; int c; /* copy code to executable buffer */ buf = mmap (0,sizeof(code),PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON,-1,0); memcpy (buf, code, sizeof(code)); /* run code */ c = ((int (*) (int, int))buf)(a, b); /* free buffer */ munmap (buf, sizeof(code)); return c; }", "after": "pub unsafe extern \"C\" fn test(mut a: libc::c_int, mut b: libc::c_int) -> libc::c_int { let mut code: [libc::c_char; 9] = [ 0x8b as libc::c_int as libc::c_char, 0x44 as libc::c_int as libc::c_char, 0x24 as libc::c_int as libc::c_char, 0x4 as libc::c_int as libc::c_char, 0x3 as libc::c_int as libc::c_char, 0x44 as libc::c_int as libc::c_char, 0x24 as libc::c_int as libc::c_char, 0x8 as libc::c_int as libc::c_char, 0xc3 as libc::c_int as libc::c_char, ]; let mut buf: *mut libc::c_void = 0 as *mut libc::c_void; let mut c: libc::c_int = 0; buf = mmap( 0 as *mut libc::c_void, ::core::mem::size_of::<[libc::c_char; 9]>() as libc::c_ulong, 0x1 as libc::c_int | 0x2 as libc::c_int | 0x4 as libc::c_int, 0x2 as libc::c_int | 0x20 as libc::c_int, -(1 as libc::c_int), 0 as libc::c_int as __off_t, ); memcpy( buf, code.as_mut_ptr() as *const libc::c_void, ::core::mem::size_of::<[libc::c_char; 9]>() as libc::c_ulong, ); c = (::core::mem::transmute::< *mut libc::c_void, Option:: libc::c_int>, >(buf)) .expect(\"non-null function pointer\")(a, b); munmap(buf, ::core::mem::size_of::<[libc::c_char; 9]>() as libc::c_ulong); return c; }" }, { "index": 1034, "before": "int main () { printf(\"%d\\n\", test(7,12)); return 0; }", "after": "unsafe fn main() -> libc::c_int { printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, test(7 as libc::c_int, 12 as libc::c_int), ); return 0 as libc::c_int; }" }, { "index": 1035, "before": "int say_hundred(const char *s, int len, int depth, int has_lead) { \tint c[3], i; \tfor (i = -3; i < 0; i++) { \t\tif (len + i >= 0) c[i + 3] = s[len + i] - '0'; \t\telse c[i + 3] = 0; \t} \tif (!(c[0] + c[1] + c[2])) return 0; \tif (c[0]) { \t\tprintf(\"%s hundred\", ones[c[0]]); \t\thas_lead = 1; \t} \tif (has_lead && (c[1] || c[2])) \t\tprintf((!depth || c[0]) && (!c[0] || !c[1]) ? \"and \" : \t\t\tc[0] ? \" \" : \"\"); \tif (c[1] < 2) { \t\tif (c[1] || c[2]) printf(\"%s\", ones[c[1] * 10 + c[2]]); \t} else { \t\tif (c[1]) { \t\t\tprintf(\"%s\", tens[c[1]]); \t\t\tif (c[2]) putchar('-'); \t\t} \t\tif (c[2]) printf(\"%s\", ones[c[2]]); \t} \treturn 1; }", "after": "pub unsafe extern \"C\" fn say_hundred( mut s: *const libc::c_char, mut len: libc::c_int, mut depth: libc::c_int, mut has_lead: libc::c_int, ) -> libc::c_int { let mut c: [libc::c_int; 3] = [0; 3]; let mut i: libc::c_int = 0; i = -(3 as libc::c_int); while i < 0 as libc::c_int { if len + i >= 0 as libc::c_int { c[(i + 3 as libc::c_int) as usize] = *s.offset((len + i) as isize) as libc::c_int - '0' as i32; } else { c[(i + 3 as libc::c_int) as usize] = 0 as libc::c_int; } i += 1; i; } if c[0 as libc::c_int as usize] + c[1 as libc::c_int as usize] + c[2 as libc::c_int as usize] == 0 { return 0 as libc::c_int; } if c[0 as libc::c_int as usize] != 0 { printf( b\"%s hundred\\0\" as *const u8 as *const libc::c_char, ones[c[0 as libc::c_int as usize] as usize], ); has_lead = 1 as libc::c_int; } if has_lead != 0 && (c[1 as libc::c_int as usize] != 0 || c[2 as libc::c_int as usize] != 0) { printf( if (depth == 0 || c[0 as libc::c_int as usize] != 0) && (c[0 as libc::c_int as usize] == 0 || c[1 as libc::c_int as usize] == 0) { b\"and \\0\" as *const u8 as *const libc::c_char } else if c[0 as libc::c_int as usize] != 0 { b\" \\0\" as *const u8 as *const libc::c_char } else { b\"\\0\" as *const u8 as *const libc::c_char }, ); } if c[1 as libc::c_int as usize] < 2 as libc::c_int { if c[1 as libc::c_int as usize] != 0 || c[2 as libc::c_int as usize] != 0 { printf( b\"%s\\0\" as *const u8 as *const libc::c_char, ones[(c[1 as libc::c_int as usize] * 10 as libc::c_int + c[2 as libc::c_int as usize]) as usize], ); } } else { if c[1 as libc::c_int as usize] != 0 { printf( b\"%s\\0\" as *const u8 as *const libc::c_char, tens[c[1 as libc::c_int as usize] as usize], ); if c[2 as libc::c_int as usize] != 0 { putchar('-' as i32); } } if c[2 as libc::c_int as usize] != 0 { printf( b\"%s\\0\" as *const u8 as *const libc::c_char, ones[c[2 as libc::c_int as usize] as usize], ); } } return 1 as libc::c_int; }" }, { "index": 1036, "before": "int say_maxillion(const char *s, int len, int depth, int has_lead) { \tint n = len / 3, r = len % 3; \tif (!r) { \t\tn--; \t\tr = 3; \t} \tconst char *e = s + r; \tdo { \t\tif (say_hundred(s, r, n, has_lead) && n) { \t\t\thas_lead = 1; \t\t\tprintf(\" %s\", llions[n]); \t\t\tif (!depth) printf(\", \"); \t\t\telse printf(\" \"); \t\t} \t\ts = e; e += 3; \t} while (r = 3, n--); \treturn 1; }", "after": "pub unsafe extern \"C\" fn say_maxillion( mut s: *const libc::c_char, mut len: libc::c_int, mut depth: libc::c_int, mut has_lead: libc::c_int, ) -> libc::c_int { let mut n: libc::c_int = len / 3 as libc::c_int; let mut r: libc::c_int = len % 3 as libc::c_int; if r == 0 { n -= 1; n; r = 3 as libc::c_int; } let mut e: *const libc::c_char = s.offset(r as isize); loop { if say_hundred(s, r, n, has_lead) != 0 && n != 0 { has_lead = 1 as libc::c_int; printf(b\" %s\\0\" as *const u8 as *const libc::c_char, llions[n as usize]); if depth == 0 { printf(b\", \\0\" as *const u8 as *const libc::c_char); } else { printf(b\" \\0\" as *const u8 as *const libc::c_char); } } s = e; e = e.offset(3 as libc::c_int as isize); r = 3 as libc::c_int; let fresh0 = n; n = n - 1; if !(fresh0 != 0) { break; } } return 1 as libc::c_int; }" }, { "index": 1037, "before": "void say_number(const char *s) { \tint len, i, got_sign = 0; \twhile (*s == ' ') s++; \tif (*s < '0' || *s > '9') { \t\tif (*s == '-') got_sign = -1; \t\telse if (*s == '+') got_sign = 1; \t\telse goto nan; \t\ts++; \t} else \t\tgot_sign = 1; \twhile (*s == '0') { \t\ts++; \t\tif (*s == '\\0') { \t\t\tprintf(\"zero\\n\"); \t\t\treturn; \t\t} \t} \tlen = strlen(s); \tif (!len) goto nan; \tfor (i = 0; i < len; i++) { \t\tif (s[i] < '0' || s[i] > '9') { \t\t\tprintf(\"(not a number)\"); \t\t\treturn; \t\t} \t} \tif (got_sign == -1) printf(\"minus \"); \tint n = len / maxillion; \tint r = len % maxillion; \tif (!r) { \t\tr = maxillion; \t\tn--; \t} \tconst char *end = s + len - n * maxillion; \tint has_lead = 0; \tdo { \t\tif ((has_lead = say_maxillion(s, r, n, has_lead))) { \t\t\tfor (i = 0; i < n; i++) \t\t\t\tprintf(\" %s\", llions[maxillion / 3]); \t\t\tif (n) printf(\", \"); \t\t} \t\tn--; \t\tr = maxillion; \t\ts = end; \t\tend += r; \t} while (n >= 0); \tprintf(\"\\n\"); \treturn; nan:\tprintf(\"not a number\\n\"); \treturn; }", "after": "pub unsafe extern \"C\" fn say_number(mut s: *const libc::c_char) { let mut n: libc::c_int = 0; let mut r: libc::c_int = 0; let mut end: *const libc::c_char = 0 as *const libc::c_char; let mut has_lead: libc::c_int = 0; let mut current_block: u64; let mut len: libc::c_int = 0; let mut i: libc::c_int = 0; let mut got_sign: libc::c_int = 0 as libc::c_int; while *s as libc::c_int == ' ' as i32 { s = s.offset(1); s; } if (*s as libc::c_int) < '0' as i32 || *s as libc::c_int > '9' as i32 { if *s as libc::c_int == '-' as i32 { got_sign = -(1 as libc::c_int); current_block = 15619007995458559411; } else if *s as libc::c_int == '+' as i32 { got_sign = 1 as libc::c_int; current_block = 15619007995458559411; } else { current_block = 1693057788147685417; } match current_block { 1693057788147685417 => {} _ => { s = s.offset(1); s; current_block = 14523784380283086299; } } } else { got_sign = 1 as libc::c_int; current_block = 14523784380283086299; } match current_block { 14523784380283086299 => { while *s as libc::c_int == '0' as i32 { s = s.offset(1); s; if *s as libc::c_int == '\\0' as i32 { printf(b\"zero\\n\\0\" as *const u8 as *const libc::c_char); return; } } len = strlen(s) as libc::c_int; if !(len == 0) { i = 0 as libc::c_int; while i < len { if (*s.offset(i as isize) as libc::c_int) < '0' as i32 || *s.offset(i as isize) as libc::c_int > '9' as i32 { printf(b\"(not a number)\\0\" as *const u8 as *const libc::c_char); return; } i += 1; i; } if got_sign == -(1 as libc::c_int) { printf(b\"minus \\0\" as *const u8 as *const libc::c_char); } n = len / maxillion; r = len % maxillion; if r == 0 { r = maxillion; n -= 1; n; } end = s.offset(len as isize).offset(-((n * maxillion) as isize)); has_lead = 0 as libc::c_int; loop { has_lead = say_maxillion(s, r, n, has_lead); if has_lead != 0 { i = 0 as libc::c_int; while i < n { printf( b\" %s\\0\" as *const u8 as *const libc::c_char, llions[(maxillion / 3 as libc::c_int) as usize], ); i += 1; i; } if n != 0 { printf(b\", \\0\" as *const u8 as *const libc::c_char); } } n -= 1; n; r = maxillion; s = end; end = end.offset(r as isize); if !(n >= 0 as libc::c_int) { break; } } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return; } } _ => {} } printf(b\"not a number\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1038, "before": "int main() { \tsay_number(\"-42\"); \tsay_number(\"1984\"); \tsay_number(\"10000\"); \tsay_number(\"1024\"); \tsay_number(\"1001001001001\"); \tsay_number(\"123456789012345678901234567890123456789012345678900000001\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { say_number(b\"-42\\0\" as *const u8 as *const libc::c_char); say_number(b\"1984\\0\" as *const u8 as *const libc::c_char); say_number(b\"10000\\0\" as *const u8 as *const libc::c_char); say_number(b\"1024\\0\" as *const u8 as *const libc::c_char); say_number(b\"1001001001001\\0\" as *const u8 as *const libc::c_char); say_number( b\"123456789012345678901234567890123456789012345678900000001\\0\" as *const u8 as *const libc::c_char, ); return 0 as libc::c_int; }" }, { "index": 1039, "before": "int main() { int i, j, nsum, vsum, vcount, values[6], numbers[4]; srand(time(NULL)); for (;;) { vsum = 0; for (i = 0; i < 6; ++i) { for (j = 0; j < 4; ++j) { numbers[j] = 1 + rand() % 6; } qsort(numbers, 4, sizeof(int), compareInts); nsum = 0; for (j = 1; j < 4; ++j) { nsum += numbers[j]; } values[i] = nsum; vsum += values[i]; } if (vsum < 75) continue; vcount = 0; for (j = 0; j < 6; ++j) { if (values[j] >= 15) vcount++; } if (vcount < 2) continue; printf(\"The 6 random numbers generated are:\\n\"); printf(\"[\"); for (j = 0; j < 6; ++j) printf(\"%d \", values[j]); printf(\"\\b]\\n\"); printf(\"\\nTheir sum is %d and %d of them are >= 15\\n\", vsum, vcount); break; } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut nsum: libc::c_int = 0; let mut vsum: libc::c_int = 0; let mut vcount: libc::c_int = 0; let mut values: [libc::c_int; 6] = [0; 6]; let mut numbers: [libc::c_int; 4] = [0; 4]; srand(time(0 as *mut time_t) as libc::c_uint); loop { vsum = 0 as libc::c_int; i = 0 as libc::c_int; while i < 6 as libc::c_int { j = 0 as libc::c_int; while j < 4 as libc::c_int { numbers[j as usize] = 1 as libc::c_int + rand() % 6 as libc::c_int; j += 1; j; } qsort( numbers.as_mut_ptr() as *mut libc::c_void, 4 as libc::c_int as size_t, ::core::mem::size_of::() as libc::c_ulong, Some( compareInts as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); nsum = 0 as libc::c_int; j = 1 as libc::c_int; while j < 4 as libc::c_int { nsum += numbers[j as usize]; j += 1; j; } values[i as usize] = nsum; vsum += values[i as usize]; i += 1; i; } if vsum < 75 as libc::c_int { continue; } vcount = 0 as libc::c_int; j = 0 as libc::c_int; while j < 6 as libc::c_int { if values[j as usize] >= 15 as libc::c_int { vcount += 1; vcount; } j += 1; j; } if vcount < 2 as libc::c_int { continue; } printf( b\"The 6 random numbers generated are:\\n\\0\" as *const u8 as *const libc::c_char, ); printf(b\"[\\0\" as *const u8 as *const libc::c_char); j = 0 as libc::c_int; while j < 6 as libc::c_int { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, values[j as usize]); j += 1; j; } printf(b\"\\x08]\\n\\0\" as *const u8 as *const libc::c_char); printf( b\"\\nTheir sum is %d and %d of them are >= 15\\n\\0\" as *const u8 as *const libc::c_char, vsum, vcount, ); break; } return 0 as libc::c_int; }" }, { "index": 1040, "before": "int main(int argC,char* argV[]) { \tchar *str; \tif(argC<2||argC>3) \t\tprintf(\"Usage : %s \",argV[0]); \telse{ \t\tif(argC!=2){ \t\t\tstr = (char*)malloc((strlen(argV[2]) + strlen(str) + 1)*sizeof(char)); \t\t\tstrcpy(str,\"written to \"); \t\t} \t\tprintf(\"Filtered signal %s\",(argC==2)?\"is:\\n\":strcat(str,argV[2])); \t\tprintVector(processSignalFile(argV[1]),argV[2]); \t} \treturn 0; }", "after": "unsafe fn main( mut argC: libc::c_int, mut argV: *mut *mut libc::c_char, ) -> libc::c_int { let mut str: *mut libc::c_char = 0 as *mut libc::c_char; if argC < 2 as libc::c_int || argC > 3 as libc::c_int { printf( b\"Usage : %s \\0\" as *const u8 as *const libc::c_char, *argV.offset(0 as libc::c_int as isize), ); } else { if argC != 2 as libc::c_int { str = malloc( (strlen(*argV.offset(2 as libc::c_int as isize))) .wrapping_add(strlen(str)) .wrapping_add(1 as libc::c_int as libc::c_ulong) .wrapping_mul( ::core::mem::size_of::() as libc::c_ulong, ), ) as *mut libc::c_char; strcpy(str, b\"written to \\0\" as *const u8 as *const libc::c_char); } printf( b\"Filtered signal %s\\0\" as *const u8 as *const libc::c_char, if argC == 2 as libc::c_int { b\"is:\\n\\0\" as *const u8 as *const libc::c_char } else { strcat(str, *argV.offset(2 as libc::c_int as isize)) as *const libc::c_char }, ); printVector( processSignalFile(*argV.offset(1 as libc::c_int as isize)), *argV.offset(2 as libc::c_int as isize), ); } return 0 as libc::c_int; }" }, { "index": 1041, "before": "vector processSignalFile(char* fileName){ \tint i,j; \tfloat sum; \tchar str[MAX_LEN]; \tvector coeff1,coeff2,signal,filteredSignal; \tFILE* fp = fopen(fileName,\"r\"); \tfgets(str,MAX_LEN,fp); \tcoeff1 = extractVector(str); \tfgets(str,MAX_LEN,fp); \tcoeff2 = extractVector(str); \tfgets(str,MAX_LEN,fp); \tsignal = extractVector(str); fclose(fp); \tfilteredSignal.values = (float*)calloc(signal.size,sizeof(float)); \tfilteredSignal.size = signal.size; \tfor(i=0;i=0) \t\t\t\tsum += coeff2.values[j]*signal.values[i-j]; \t\t} \t\tfor(j=0;j=0) \t\t\t\tsum -= coeff1.values[j]*filteredSignal.values[i-j]; \t\t} \t\tsum /= coeff1.values[0]; \t\tfilteredSignal.values[i] = sum; \t} \treturn filteredSignal; }", "after": "pub unsafe extern \"C\" fn processSignalFile(mut fileName: *mut libc::c_char) -> vector { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut sum: libc::c_float = 0.; let mut str: [libc::c_char; 1000] = [0; 1000]; let mut coeff1: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut coeff2: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut signal: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut filteredSignal: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut fp: *mut FILE = fopen(fileName, b\"r\\0\" as *const u8 as *const libc::c_char); fgets(str.as_mut_ptr(), 1000 as libc::c_int, fp); coeff1 = extractVector(str.as_mut_ptr()); fgets(str.as_mut_ptr(), 1000 as libc::c_int, fp); coeff2 = extractVector(str.as_mut_ptr()); fgets(str.as_mut_ptr(), 1000 as libc::c_int, fp); signal = extractVector(str.as_mut_ptr()); fclose(fp); filteredSignal .values = calloc( signal.size as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_float; filteredSignal.size = signal.size; i = 0 as libc::c_int; while i < signal.size { sum = 0 as libc::c_int as libc::c_float; j = 0 as libc::c_int; while j < coeff2.size { if i - j >= 0 as libc::c_int { sum += *(coeff2.values).offset(j as isize) * *(signal.values).offset((i - j) as isize); } j += 1; j; } j = 0 as libc::c_int; while j < coeff1.size { if i - j >= 0 as libc::c_int { sum -= *(coeff1.values).offset(j as isize) * *(filteredSignal.values).offset((i - j) as isize); } j += 1; j; } sum /= *(coeff1.values).offset(0 as libc::c_int as isize); *(filteredSignal.values).offset(i as isize) = sum; i += 1; i; } return filteredSignal; }" }, { "index": 1042, "before": "vector extractVector(char* str){ \tvector coeff; \tint i=0,count = 1; \tchar* token; \twhile(str[i]!=00){ \t\tif(str[i++]==' ') \t\t\tcount++; \t} \tcoeff.values = (float*)malloc(count*sizeof(float)); \tcoeff.size = count; \ttoken = strtok(str,\" \"); \ti = 0; \twhile(token!=NULL){ \t\tcoeff.values[i++] = atof(token); \t\ttoken = strtok(NULL,\" \"); \t} \treturn coeff; }", "after": "pub unsafe extern \"C\" fn extractVector(mut str: *mut libc::c_char) -> vector { let mut coeff: vector = vector { values: 0 as *mut libc::c_float, size: 0, }; let mut i: libc::c_int = 0 as libc::c_int; let mut count: libc::c_int = 1 as libc::c_int; let mut token: *mut libc::c_char = 0 as *mut libc::c_char; while *str.offset(i as isize) as libc::c_int != 0 as libc::c_int { let fresh0 = i; i = i + 1; if *str.offset(fresh0 as isize) as libc::c_int == ' ' as i32 { count += 1; count; } } coeff .values = malloc( (count as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_float; coeff.size = count; token = strtok(str, b\" \\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while !token.is_null() { let fresh1 = i; i = i + 1; *(coeff.values).offset(fresh1 as isize) = atof(token) as libc::c_float; token = strtok( 0 as *mut libc::c_char, b\" \\0\" as *const u8 as *const libc::c_char, ); } return coeff; }" }, { "index": 1043, "before": "void printVector(vector v, char* outputFile){ \tint i; \tif(outputFile==NULL){ \t\tprintf(\"[\"); \t\tfor(i=0;i libc::c_int { let mut NumberOfDigits: libc::c_int = 0; NumberOfDigits = 0 as libc::c_int; while x != 0 as libc::c_int { x = x / 10 as libc::c_int; NumberOfDigits += 1; NumberOfDigits; } return NumberOfDigits; }" }, { "index": 1045, "before": "int main(int argc, char* argv[]) { int* convertedArray; convertedArray=convert_array(*(argv+1), argc-1); if(isSorted(convertedArray, argc-1)==1) printf(\"Did you forgot to turn on your brain?! This array is already sorted!\\n\"); else if(argc-1<=10) printf(\"Am I really supposed to sort this? Sort it by yourself!\\n\"); else printf(\"Am I really supposed to sort this? Bhahahaha!\\n\"); free(convertedArray); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut convertedArray: *mut libc::c_int = 0 as *mut libc::c_int; convertedArray = convert_array( *argv.offset(1 as libc::c_int as isize), argc - 1 as libc::c_int, ); if isSorted(convertedArray, argc - 1 as libc::c_int) == 1 as libc::c_int { printf( b\"Did you forgot to turn on your brain?! This array is already sorted!\\n\\0\" as *const u8 as *const libc::c_char, ); } else if argc - 1 as libc::c_int <= 10 as libc::c_int { printf( b\"Am I really supposed to sort this? Sort it by yourself!\\n\\0\" as *const u8 as *const libc::c_char, ); } else { printf( b\"Am I really supposed to sort this? Bhahahaha!\\n\\0\" as *const u8 as *const libc::c_char, ); } free(convertedArray as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1046, "before": "int isSorted(int array[], int numberOfElements){ int sorted=1; for(int counter=0;counterarray[counter]) sorted--; } return sorted; }", "after": "pub unsafe extern \"C\" fn isSorted( mut array: *mut libc::c_int, mut numberOfElements: libc::c_int, ) -> libc::c_int { let mut sorted: libc::c_int = 1 as libc::c_int; let mut counter: libc::c_int = 0 as libc::c_int; while counter < numberOfElements { if counter != 0 as libc::c_int && *array.offset((counter - 1 as libc::c_int) as isize) > *array.offset(counter as isize) { sorted -= 1; sorted; } counter += 1; counter; } return sorted; }" }, { "index": 1047, "before": "void show_matrix(double *A, int n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) printf(\"%2.5f \", A[i * n + j]); printf(\"\\n\"); } }", "after": "pub unsafe extern \"C\" fn show_matrix(mut A: *mut libc::c_double, mut n: libc::c_int) { let mut i: libc::c_int = 0 as libc::c_int; while i < n { let mut j: libc::c_int = 0 as libc::c_int; while j < n { printf( b\"%2.5f \\0\" as *const u8 as *const libc::c_char, *A.offset((i * n + j) as isize), ); j += 1; j; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } }" }, { "index": 1048, "before": "int main() { int n = 3; double m1[] = {25, 15, -5, 15, 18, 0, -5, 0, 11}; double *c1 = cholesky(m1, n); show_matrix(c1, n); printf(\"\\n\"); free(c1); n = 4; double m2[] = {18, 22, 54, 42, 22, 70, 86, 62, 54, 86, 174, 134, 42, 62, 134, 106}; double *c2 = cholesky(m2, n); show_matrix(c2, n); free(c2); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 3 as libc::c_int; let mut m1: [libc::c_double; 9] = [ 25 as libc::c_int as libc::c_double, 15 as libc::c_int as libc::c_double, -(5 as libc::c_int) as libc::c_double, 15 as libc::c_int as libc::c_double, 18 as libc::c_int as libc::c_double, 0 as libc::c_int as libc::c_double, -(5 as libc::c_int) as libc::c_double, 0 as libc::c_int as libc::c_double, 11 as libc::c_int as libc::c_double, ]; let mut c1: *mut libc::c_double = cholesky(m1.as_mut_ptr(), n); show_matrix(c1, n); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); free(c1 as *mut libc::c_void); n = 4 as libc::c_int; let mut m2: [libc::c_double; 16] = [ 18 as libc::c_int as libc::c_double, 22 as libc::c_int as libc::c_double, 54 as libc::c_int as libc::c_double, 42 as libc::c_int as libc::c_double, 22 as libc::c_int as libc::c_double, 70 as libc::c_int as libc::c_double, 86 as libc::c_int as libc::c_double, 62 as libc::c_int as libc::c_double, 54 as libc::c_int as libc::c_double, 86 as libc::c_int as libc::c_double, 174 as libc::c_int as libc::c_double, 134 as libc::c_int as libc::c_double, 42 as libc::c_int as libc::c_double, 62 as libc::c_int as libc::c_double, 134 as libc::c_int as libc::c_double, 106 as libc::c_int as libc::c_double, ]; let mut c2: *mut libc::c_double = cholesky(m2.as_mut_ptr(), n); show_matrix(c2, n); free(c2 as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1049, "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 unsafe extern \"C\" fn kprime(mut n: libc::c_int, mut k: 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 < k && 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 == k) as libc::c_int; }" }, { "index": 1050, "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": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut c: libc::c_int = 0; let mut k: libc::c_int = 0; k = 1 as libc::c_int; while k <= 5 as libc::c_int { printf(b\"k = %d:\\0\" as *const u8 as *const libc::c_char, k); i = 2 as libc::c_int; c = 0 as libc::c_int; while c < 10 as libc::c_int { if kprime(i, k) != 0 { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, i); c += 1; c; } i += 1; i; } putchar('\\n' as i32); k += 1; k; } return 0 as libc::c_int; }" }, { "index": 1051, "before": "int bsearch (int *a, int n, int x) { int i = 0, j = n - 1; while (i <= j) { int k = i + ((j - i) / 2); if (a[k] == x) { return k; } else if (a[k] < x) { i = k + 1; } else { j = k - 1; } } return -1; }", "after": "pub unsafe extern \"C\" fn bsearch( mut a: *mut libc::c_int, mut n: libc::c_int, mut x: libc::c_int, ) -> libc::c_int { let mut i: libc::c_int = 0 as libc::c_int; let mut j: libc::c_int = n - 1 as libc::c_int; while i <= j { let mut k: libc::c_int = i + (j - i) / 2 as libc::c_int; if *a.offset(k as isize) == x { return k } else if *a.offset(k as isize) < x { i = k + 1 as libc::c_int; } else { j = k - 1 as libc::c_int; } } return -(1 as libc::c_int); }" }, { "index": 1052, "before": "int bsearch_r (int *a, int x, int i, int j) { if (j < i) { return -1; } int k = i + ((j - i) / 2); if (a[k] == x) { return k; } else if (a[k] < x) { return bsearch_r(a, x, k + 1, j); } else { return bsearch_r(a, x, i, k - 1); } }", "after": "pub unsafe extern \"C\" fn bsearch_r( mut a: *mut libc::c_int, mut x: libc::c_int, mut i: libc::c_int, mut j: libc::c_int, ) -> libc::c_int { if j < i { return -(1 as libc::c_int); } let mut k: libc::c_int = i + (j - i) / 2 as libc::c_int; if *a.offset(k as isize) == x { return k } else if *a.offset(k as isize) < x { return bsearch_r(a, x, k + 1 as libc::c_int, j) } else { return bsearch_r(a, x, i, k - 1 as libc::c_int) }; }" }, { "index": 1053, "before": "int main () { int a[] = {-31, 0, 1, 2, 2, 4, 65, 83, 99, 782}; int n = sizeof a / sizeof a[0]; int x = 2; int i = bsearch(a, n, x); printf(\"%d is at index %d\\n\", x, i); x = 5; i = bsearch_r(a, x, 0, n - 1); printf(\"%d is at index %d\\n\", x, i); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut a: [libc::c_int; 10] = [ -(31 as libc::c_int), 0 as libc::c_int, 1 as libc::c_int, 2 as libc::c_int, 2 as libc::c_int, 4 as libc::c_int, 65 as libc::c_int, 83 as libc::c_int, 99 as libc::c_int, 782 as libc::c_int, ]; let mut n: libc::c_int = (::core::mem::size_of::<[libc::c_int; 10]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int; let mut x: libc::c_int = 2 as libc::c_int; let mut i: libc::c_int = bsearch(a.as_mut_ptr(), n, x); printf(b\"%d is at index %d\\n\\0\" as *const u8 as *const libc::c_char, x, i); x = 5 as libc::c_int; i = bsearch_r(a.as_mut_ptr(), x, 0 as libc::c_int, n - 1 as libc::c_int); printf(b\"%d is at index %d\\n\\0\" as *const u8 as *const libc::c_char, x, i); return 0 as libc::c_int; }" }, { "index": 1054, "before": "int main(){ \tint sum = 0, i, j; \tint try_max = 0; \t//1 is deficient by default and can add it deficient list \tint count_list[3] = {1,0,0}; \tfor(i=2; i <= 20000; i++){ \t\t//Set maximum to check for proper division \t\ttry_max = i/2; \t\t//1 is in all proper division number \t\tsum = 1; \t\tfor(j=2; j i){ \t\t\tcount_list[ab]++; \t\t\tcontinue; \t\t} \t\tcount_list[pe]++; \t} \tprintf(\"\\nThere are %d deficient,\" ,count_list[de]); \tprintf(\" %d perfect,\" ,count_list[pe]); \tprintf(\" %d abundant numbers between 1 and 20000.\\n\" ,count_list[ab]); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut sum: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut try_max: libc::c_int = 0 as libc::c_int; let mut count_list: [libc::c_int; 3] = [ 1 as libc::c_int, 0 as libc::c_int, 0 as libc::c_int, ]; i = 2 as libc::c_int; while i <= 20000 as libc::c_int { try_max = i / 2 as libc::c_int; sum = 1 as libc::c_int; j = 2 as libc::c_int; while j < try_max { if !(i % j != 0) { try_max = i / j; sum += j; if j != try_max { sum += try_max; } } j += 1; j; } if sum < i { count_list[0 as libc::c_int as usize] += 1; count_list[0 as libc::c_int as usize]; } else if sum > i { count_list[2 as libc::c_int as usize] += 1; count_list[2 as libc::c_int as usize]; } else { count_list[1 as libc::c_int as usize] += 1; count_list[1 as libc::c_int as usize]; } i += 1; i; } printf( b\"\\nThere are %d deficient,\\0\" as *const u8 as *const libc::c_char, count_list[0 as libc::c_int as usize], ); printf( b\" %d perfect,\\0\" as *const u8 as *const libc::c_char, count_list[1 as libc::c_int as usize], ); printf( b\" %d abundant numbers between 1 and 20000.\\n\\0\" as *const u8 as *const libc::c_char, count_list[2 as libc::c_int as usize], ); return 0 as libc::c_int; }" }, { "index": 1055, "before": "int walk_board(int w, int h, int x, int y, cell **b) { \tint i, nx, ny, least; \tint steps = 0; \tprintf(E\"H\"E\"J\"E\"%d;%dH\"E\"32m[]\"E\"m\", y + 1, 1 + 2 * x); \twhile (1) { \t\t/* occupy cell */ \t\tb[y][x] = 255; \t\t/* reduce all neighbors' neighbor count */ \t\tfor (i = 0; i < 8; i++) \t\t\tb[ y + dy[i] ][ x + dx[i] ]--; \t\t/* find neighbor with lowest neighbor count */ \t\tleast = 255; \t\tfor (i = 0; i < 8; i++) { \t\t\tif (b[ y + dy[i] ][ x + dx[i] ] < least) { \t\t\t\tnx = x + dx[i]; \t\t\t\tny = y + dy[i]; \t\t\t\tleast = b[ny][nx]; \t\t\t} \t\t} \t\tif (least > 7) { \t\t\tprintf(E\"%dH\", h + 2); \t\t\treturn steps == w * h - 1; \t\t} \t\tif (steps++) printf(E\"%d;%dH[]\", y + 1, 1 + 2 * x); \t\tx = nx, y = ny; \t\tprintf(E\"%d;%dH\"E\"31m[]\"E\"m\", y + 1, 1 + 2 * x); \t\tfflush(stdout); \t\tusleep(120000); \t}", "after": "pub unsafe extern \"C\" fn walk_board( mut w: libc::c_int, mut h: libc::c_int, mut x: libc::c_int, mut y: libc::c_int, mut b: *mut *mut cell, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut nx: libc::c_int = 0; let mut ny: libc::c_int = 0; let mut least: libc::c_int = 0; let mut steps: libc::c_int = 0 as libc::c_int; printf( b\"\\x1B[H\\x1B[J\\x1B[%d;%dH\\x1B[32m[]\\x1B[m\\0\" as *const u8 as *const libc::c_char, y + 1 as libc::c_int, 1 as libc::c_int + 2 as libc::c_int * x, ); loop { *(*b.offset(y as isize)).offset(x as isize) = 255 as libc::c_int as cell; i = 0 as libc::c_int; while i < 8 as libc::c_int { let ref mut fresh5 = *(*b.offset((y + dy[i as usize]) as isize)) .offset((x + dx[i as usize]) as isize); *fresh5 = (*fresh5).wrapping_sub(1); *fresh5; i += 1; i; } least = 255 as libc::c_int; i = 0 as libc::c_int; while i < 8 as libc::c_int { if (*(*b.offset((y + dy[i as usize]) as isize)) .offset((x + dx[i as usize]) as isize) as libc::c_int) < least { nx = x + dx[i as usize]; ny = y + dy[i as usize]; least = *(*b.offset(ny as isize)).offset(nx as isize) as libc::c_int; } i += 1; i; } if least > 7 as libc::c_int { printf( b\"\\x1B[%dH\\0\" as *const u8 as *const libc::c_char, h + 2 as libc::c_int, ); return (steps == w * h - 1 as libc::c_int) as libc::c_int; } let fresh6 = steps; steps = steps + 1; if fresh6 != 0 { printf( b\"\\x1B[%d;%dH[]\\0\" as *const u8 as *const libc::c_char, y + 1 as libc::c_int, 1 as libc::c_int + 2 as libc::c_int * x, ); } x = nx; y = ny; printf( b\"\\x1B[%d;%dH\\x1B[31m[]\\x1B[m\\0\" as *const u8 as *const libc::c_char, y + 1 as libc::c_int, 1 as libc::c_int + 2 as libc::c_int * x, ); fflush(stdout); usleep(120000 as libc::c_int as __useconds_t); }; }" }, { "index": 1056, "before": "void init_board(int w, int h, cell **a, cell **b) { \tint i, j, k, x, y, p = w + 4, q = h + 4; \t/* b is board; a is board with 2 rows padded at each side */ \ta[0] = (cell*)(a + q); \tb[0] = a[0] + 2; \tfor (i = 1; i < q; i++) { \t\ta[i] = a[i-1] + p; \t\tb[i] = a[i] + 2; \t} \tmemset(a[0], 255, p * q); \tfor (i = 0; i < h; i++) { \t\tfor (j = 0; j < w; j++) { \t\t\tfor (k = 0; k < 8; k++) { \t\t\t\tx = j + dx[k], y = i + dy[k]; \t\t\t\tif (b[i+2][j] == 255) b[i+2][j] = 0; \t\t\t\tb[i+2][j] += x >= 0 && x < w && y >= 0 && y < h; \t\t\t} \t\t} \t} }", "after": "pub unsafe extern \"C\" fn init_board( mut w: libc::c_int, mut h: libc::c_int, mut a: *mut *mut cell, mut b: *mut *mut cell, ) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut k: libc::c_int = 0; let mut x: libc::c_int = 0; let mut y: libc::c_int = 0; let mut p: libc::c_int = w + 4 as libc::c_int; let mut q: libc::c_int = h + 4 as libc::c_int; let ref mut fresh0 = *a.offset(0 as libc::c_int as isize); *fresh0 = a.offset(q as isize) as *mut cell; let ref mut fresh1 = *b.offset(0 as libc::c_int as isize); *fresh1 = (*a.offset(0 as libc::c_int as isize)).offset(2 as libc::c_int as isize); i = 1 as libc::c_int; while i < q { let ref mut fresh2 = *a.offset(i as isize); *fresh2 = (*a.offset((i - 1 as libc::c_int) as isize)).offset(p as isize); let ref mut fresh3 = *b.offset(i as isize); *fresh3 = (*a.offset(i as isize)).offset(2 as libc::c_int as isize); i += 1; i; } memset( *a.offset(0 as libc::c_int as isize) as *mut libc::c_void, 255 as libc::c_int, (p * q) as libc::c_ulong, ); i = 0 as libc::c_int; while i < h { j = 0 as libc::c_int; while j < w { k = 0 as libc::c_int; while k < 8 as libc::c_int { x = j + dx[k as usize]; y = i + dy[k as usize]; if *(*b.offset((i + 2 as libc::c_int) as isize)).offset(j as isize) as libc::c_int == 255 as libc::c_int { *(*b.offset((i + 2 as libc::c_int) as isize)) .offset(j as isize) = 0 as libc::c_int as cell; } let ref mut fresh4 = *(*b.offset((i + 2 as libc::c_int) as isize)) .offset(j as isize); *fresh4 = (*fresh4 as libc::c_int + (x >= 0 as libc::c_int && x < w && y >= 0 as libc::c_int && y < h) as libc::c_int) as cell; k += 1; k; } j += 1; j; } i += 1; i; } }" }, { "index": 1057, "before": "int solve(int w, int h) { \tint x = 0, y = 0; \tcell **a, **b; \ta = malloc((w + 4) * (h + 4) + sizeof(cell*) * (h + 4)); \tb = malloc((h + 4) * sizeof(cell*)); \twhile (1) { \t\tinit_board(w, h, a, b); \t\tif (walk_board(w, h, x, y, b + 2)) { \t\t\tprintf(\"Success!\\n\"); \t\t\treturn 1; \t\t} \t\tif (++x >= w) x = 0, y++; \t\tif (y >= h) { \t\t\tprintf(\"Failed to find a solution\\n\"); \t\t\treturn 0; \t\t} \t\tprintf(\"Any key to try next start position\"); \t\tgetchar(); \t} }", "after": "pub unsafe extern \"C\" fn solve(mut w: libc::c_int, mut h: libc::c_int) -> libc::c_int { let mut x: libc::c_int = 0 as libc::c_int; let mut y: libc::c_int = 0 as libc::c_int; let mut a: *mut *mut cell = 0 as *mut *mut cell; let mut b: *mut *mut cell = 0 as *mut *mut cell; a = malloc( (((w + 4 as libc::c_int) * (h + 4 as libc::c_int)) as libc::c_ulong) .wrapping_add( (::core::mem::size_of::<*mut cell>() as libc::c_ulong) .wrapping_mul((h + 4 as libc::c_int) as libc::c_ulong), ), ) as *mut *mut cell; b = malloc( ((h + 4 as libc::c_int) as libc::c_ulong) .wrapping_mul(::core::mem::size_of::<*mut cell>() as libc::c_ulong), ) as *mut *mut cell; loop { init_board(w, h, a, b); if walk_board(w, h, x, y, b.offset(2 as libc::c_int as isize)) != 0 { printf(b\"Success!\\n\\0\" as *const u8 as *const libc::c_char); return 1 as libc::c_int; } x += 1; if x >= w { x = 0 as libc::c_int; y += 1; y; } if y >= h { printf(b\"Failed to find a solution\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; } printf( b\"Any key to try next start position\\0\" as *const u8 as *const libc::c_char, ); getchar(); }; }" }, { "index": 1058, "before": "int main(int c, char **v) { \tint w, h; \tif (c < 2 || (w = atoi(v[1])) <= 0) w = 8; \tif (c < 3 || (h = atoi(v[2])) <= 0) h = w; \tsolve(w, h); \treturn 0; }", "after": "unsafe fn main(mut c: libc::c_int, mut v: *mut *mut libc::c_char) -> libc::c_int { let mut w: libc::c_int = 0; let mut h: libc::c_int = 0; if c < 2 as libc::c_int || { w = atoi(*v.offset(1 as libc::c_int as isize)); w <= 0 as libc::c_int } { w = 8 as libc::c_int; } if c < 3 as libc::c_int || { h = atoi(*v.offset(2 as libc::c_int as isize)); h <= 0 as libc::c_int } { h = w; } solve(w, h); return 0 as libc::c_int; }" }, { "index": 1059, "before": "int main() { \tchar *s; \twhile ((s = get_line(stdin))) { \t\tprintf(\"%s\",s); \t\tfree(s); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut s: *mut libc::c_char = 0 as *mut libc::c_char; loop { s = get_line(stdin); if s.is_null() { break; } printf(b\"%s\\0\" as *const u8 as *const libc::c_char, s); free(s as *mut libc::c_void); } return 0 as libc::c_int; }" }, { "index": 1060, "before": "int main(void) { \tint i, j, n = 12; \tfor (j = 1; j <= n; j++) printf(\"%3d%c\", j, j != n ? ' ' : '\\n'); \tfor (j = 0; j <= n; j++) printf(j != n ? \"----\" : \"+\\n\"); \tfor (i = 1; i <= n; i++) { \t\tfor (j = 1; j <= n; j++) \t\t\tprintf(j < i ? \" \" : \"%3d \", i * j); printf(\"| %d\\n\", i); } \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut n: libc::c_int = 12 as libc::c_int; j = 1 as libc::c_int; while j <= n { printf( b\"%3d%c\\0\" as *const u8 as *const libc::c_char, j, if j != n { ' ' as i32 } else { '\\n' as i32 }, ); j += 1; j; } j = 0 as libc::c_int; while j <= n { printf( if j != n { b\"----\\0\" as *const u8 as *const libc::c_char } else { b\"+\\n\\0\" as *const u8 as *const libc::c_char }, ); j += 1; j; } i = 1 as libc::c_int; while i <= n { j = 1 as libc::c_int; while j <= n { printf( if j < i { b\" \\0\" as *const u8 as *const libc::c_char } else { b\"%3d \\0\" as *const u8 as *const libc::c_char }, i * j, ); j += 1; j; } printf(b\"| %d\\n\\0\" as *const u8 as *const libc::c_char, i); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1061, "before": "static void init_rot13_table(void) { \tstatic const unsigned char upper[] = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"; \tstatic const unsigned char lower[] = \"abcdefghijklmnopqrstuvwxyz\"; \tfor (int ch = '\\0'; ch <= UCHAR_MAX; ch++) { \t\trot13_table[ch] = ch; \t} \tfor (const unsigned char *p = upper; p[13] != '\\0'; p++) { \t\trot13_table[p[0]] = p[13]; \t\trot13_table[p[13]] = p[0]; \t} \tfor (const unsigned char *p = lower; p[13] != '\\0'; p++) { \t\trot13_table[p[0]] = p[13]; \t\trot13_table[p[13]] = p[0]; \t} }", "after": "unsafe extern \"C\" fn init_rot13_table() { static mut upper: [libc::c_uchar; 27] = unsafe { *::core::mem::transmute::< &[u8; 27], &[libc::c_uchar; 27], >(b\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\\0\") }; static mut lower: [libc::c_uchar; 27] = unsafe { *::core::mem::transmute::< &[u8; 27], &[libc::c_uchar; 27], >(b\"abcdefghijklmnopqrstuvwxyz\\0\") }; let mut ch: libc::c_int = '\\0' as i32; while ch <= 127 as libc::c_int * 2 as libc::c_int + 1 as libc::c_int { rot13_table[ch as usize] = ch as libc::c_char; ch += 1; ch; } let mut p: *const libc::c_uchar = upper.as_ptr(); while *p.offset(13 as libc::c_int as isize) as libc::c_int != '\\0' as i32 { rot13_table[*p.offset(0 as libc::c_int as isize) as usize] = *p.offset(13 as libc::c_int as isize) as libc::c_char; rot13_table[*p.offset(13 as libc::c_int as isize) as usize] = *p.offset(0 as libc::c_int as isize) as libc::c_char; p = p.offset(1); p; } let mut p_0: *const libc::c_uchar = lower.as_ptr(); while *p_0.offset(13 as libc::c_int as isize) as libc::c_int != '\\0' as i32 { rot13_table[*p_0.offset(0 as libc::c_int as isize) as usize] = *p_0.offset(13 as libc::c_int as isize) as libc::c_char; rot13_table[*p_0.offset(13 as libc::c_int as isize) as usize] = *p_0.offset(0 as libc::c_int as isize) as libc::c_char; p_0 = p_0.offset(1); p_0; } }" }, { "index": 1062, "before": "int main(int argc, char *argv[]) { \tinit_rot13_table(); \tif (argc > 1) { \t\tfor (int i = 1; i < argc; i++) { \t\t\tFILE *fp = fopen(argv[i], \"r\"); \t\t\tif (fp == NULL) { \t\t\t\tperror(argv[i]); \t\t\t\treturn EXIT_FAILURE; \t\t\t} \t\t\trot13_file(fp); \t\t\tfclose(fp); \t\t} \t} else { \t\trot13_file(stdin); \t} \treturn EXIT_SUCCESS; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { init_rot13_table(); if argc > 1 as libc::c_int { let mut i: libc::c_int = 1 as libc::c_int; while i < argc { let mut fp: *mut FILE = fopen( *argv.offset(i as isize), b\"r\\0\" as *const u8 as *const libc::c_char, ); if fp.is_null() { perror(*argv.offset(i as isize)); return 1 as libc::c_int; } rot13_file(fp); fclose(fp); i += 1; i; } } else { rot13_file(stdin); } return 0 as libc::c_int; }" }, { "index": 1063, "before": "static void rot13_file(FILE *fp) { \tint ch; \twhile ((ch = fgetc(fp)) != EOF) { \t\tfputc(rot13_table[ch], stdout); \t} }", "after": "unsafe extern \"C\" fn rot13_file(mut fp: *mut FILE) { let mut ch: libc::c_int = 0; loop { ch = fgetc(fp); if !(ch != -(1 as libc::c_int)) { break; } fputc(rot13_table[ch as usize] as libc::c_int, stdout); }; }" }, { "index": 1064, "before": "int main (void) { \tmpf_set_default_prec (300000); \tmpf_t x0, y0, resA, resB, Z, var; \tmpf_init_set_ui (x0, 1); \tmpf_init_set_d (y0, 0.5); \tmpf_sqrt (y0, y0); \tmpf_init (resA); \tmpf_init (resB); \tmpf_init_set_d (Z, 0.25); \tmpf_init (var); \tint n = 1; int i; \tfor(i=0; i<8; i++){ \t\tagm(x0, y0, resA, resB); \t\tmpf_sub(var, resA, x0); \t\tmpf_mul(var, var, var); \t\tmpf_mul_ui(var, var, n); \t\tmpf_sub(Z, Z, var); \t\tn += n; \t\tagm(resA, resB, x0, y0); \t\tmpf_sub(var, x0, resA); \t\tmpf_mul(var, var, var); \t\tmpf_mul_ui(var, var, n); \t\tmpf_sub(Z, Z, var); \t\tn += n; \t} \tmpf_mul(x0, x0, x0); \tmpf_div(x0, x0, Z); \tgmp_printf (\"%.100000Ff\\n\", x0); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { mpf_set_default_prec(300000 as libc::c_int); let mut n: libc::c_int = 1 as libc::c_int; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 8 as libc::c_int { n += n; n += n; i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1065, "before": "void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) { \tmpf_add (out1, in1, in2); \tmpf_div_ui (out1, out1, 2); \tmpf_mul (out2, in1, in2); \tmpf_sqrt (out2, out2); }", "after": "pub unsafe extern \"C\" fn agm( in1: libc::c_int, in2: libc::c_int, mut out1: libc::c_int, mut out2: libc::c_int, ) {}" }, { "index": 1066, "before": "int main() { \tchar\tc[] = \"_###_##_#_#_#_#__#__\\n\", \t\tb[] = \"____________________\\n\"; \tdo { printf(c + 1); } while (evolve(c + 1, b + 1, sizeof(c) - 3)); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut c: [libc::c_char; 22] = *::core::mem::transmute::< &[u8; 22], &mut [libc::c_char; 22], >(b\"_###_##_#_#_#_#__#__\\n\\0\"); let mut b: [libc::c_char; 22] = *::core::mem::transmute::< &[u8; 22], &mut [libc::c_char; 22], >(b\"____________________\\n\\0\"); loop { printf(c.as_mut_ptr().offset(1 as libc::c_int as isize)); if !(evolve( c.as_mut_ptr().offset(1 as libc::c_int as isize), b.as_mut_ptr().offset(1 as libc::c_int as isize), (::core::mem::size_of::<[libc::c_char; 22]>() as libc::c_ulong) .wrapping_sub(3 as libc::c_int as libc::c_ulong) as libc::c_int, ) != 0) { break; } } return 0 as libc::c_int; }" }, { "index": 1067, "before": "int evolve(char cell[], char backup[], int len) { \tint i, diff = 0; \tfor (i = 0; i < len; i++) { \t\t/* use left, self, right as binary number bits for table index */ \t\tbackup[i] = trans[ v(i-1) * 4 + v(i) * 2 + v(i + 1) ]; \t\tdiff += (backup[i] != cell[i]); \t} \tstrcpy(cell, backup); \treturn diff; }", "after": "pub unsafe extern \"C\" fn evolve( mut cell: *mut libc::c_char, mut backup: *mut libc::c_char, mut len: libc::c_int, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut diff: libc::c_int = 0 as libc::c_int; i = 0 as libc::c_int; while i < len { *backup .offset( i as isize, ) = trans[((*cell.offset((i - 1 as libc::c_int) as isize) as libc::c_int != '_' as i32) as libc::c_int * 4 as libc::c_int + (*cell.offset(i as isize) as libc::c_int != '_' as i32) as libc::c_int * 2 as libc::c_int + (*cell.offset((i + 1 as libc::c_int) as isize) as libc::c_int != '_' as i32) as libc::c_int) as usize]; diff += (*backup.offset(i as isize) as libc::c_int != *cell.offset(i as isize) as libc::c_int) as libc::c_int; i += 1; i; } strcpy(cell, backup as *const libc::c_char); return diff; }" }, { "index": 1068, "before": "int compare(const void *a, const void *b) { struct replace_info *x = (struct replace_info *) a; struct replace_info *y = (struct replace_info *) b; return x->n - y->n; }", "after": "pub unsafe extern \"C\" fn compare( mut a: *const libc::c_void, mut b: *const libc::c_void, ) -> libc::c_int { let mut x: *mut replace_info = a as *mut replace_info; let mut y: *mut replace_info = b as *mut replace_info; return (*x).n - (*y).n; }" }, { "index": 1069, "before": "void generic_fizz_buzz(int max, struct replace_info *info, int info_length) { int i, it; int found_word; for (i = 1; i < max; ++i) { found_word = 0; /* Assume sorted order of values in the info array */ for (it = 0; it < info_length; ++it) { if (0 == i % info[it].n) { printf(\"%s\", info[it].text); found_word = 1; } } if (0 == found_word) printf(\"%d\", i); printf(\"\\n\"); } }", "after": "pub unsafe extern \"C\" fn generic_fizz_buzz( mut max: libc::c_int, mut info: *mut replace_info, mut info_length: libc::c_int, ) { let mut i: libc::c_int = 0; let mut it: libc::c_int = 0; let mut found_word: libc::c_int = 0; i = 1 as libc::c_int; while i < max { found_word = 0 as libc::c_int; it = 0 as libc::c_int; while it < info_length { if 0 as libc::c_int == i % (*info.offset(it as isize)).n { printf( b\"%s\\0\" as *const u8 as *const libc::c_char, (*info.offset(it as isize)).text, ); found_word = 1 as libc::c_int; } it += 1; it; } if 0 as libc::c_int == found_word { printf(b\"%d\\0\" as *const u8 as *const libc::c_char, i); } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } }" }, { "index": 1070, "before": "int main(void) { struct replace_info info[3] = { {5, \"Buzz\"}, {7, \"Baxx\"}, {3, \"Fizz\"} }; /* Sort information array */ qsort(info, 3, sizeof(struct replace_info), compare); /* Print output for generic FizzBuzz */ generic_fizz_buzz(20, info, 3); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut info: [replace_info; 3] = [ { let mut init = replace_info { n: 5 as libc::c_int, text: b\"Buzz\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, }; init }, { let mut init = replace_info { n: 7 as libc::c_int, text: b\"Baxx\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, }; init }, { let mut init = replace_info { n: 3 as libc::c_int, text: b\"Fizz\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, }; init }, ]; qsort( info.as_mut_ptr() as *mut libc::c_void, 3 as libc::c_int as size_t, ::core::mem::size_of::() as libc::c_ulong, Some( compare as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); generic_fizz_buzz(20 as libc::c_int, info.as_mut_ptr(), 3 as libc::c_int); return 0 as libc::c_int; }" }, { "index": 1071, "before": "double entropy(int *hist,int histlen,int len){ \tint i; \tdouble H; \tH=0; \tfor(i=0;i libc::c_double { let mut i: libc::c_int = 0; let mut H: libc::c_double = 0.; H = 0 as libc::c_int as libc::c_double; i = 0 as libc::c_int; while i < histlen { H -= *hist.offset(i as isize) as libc::c_double / len as libc::c_double * log2( *hist.offset(i as isize) as libc::c_double / len as libc::c_double, ); i += 1; i; } return H; }" }, { "index": 1072, "before": "int main(void){ \tchar S[MAXLEN]; \tint len,*hist,histlen; \tdouble H; \tscanf(\"%[^\\n]\",S); \tlen=strlen(S); \thist=(int*)calloc(len,sizeof(int)); \thistlen=makehist(S,hist,len); \t//hist now has no order (known to the program) but that doesn't matter \tH=entropy(hist,histlen,len); \tprintf(\"%lf\\n\",H); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut S: [libc::c_char; 100] = [0; 100]; let mut len: libc::c_int = 0; let mut hist: *mut libc::c_int = 0 as *mut libc::c_int; let mut histlen: libc::c_int = 0; let mut H: libc::c_double = 0.; scanf(b\"%[^\\n]\\0\" as *const u8 as *const libc::c_char, S.as_mut_ptr()); len = strlen(S.as_mut_ptr()) as libc::c_int; hist = calloc( len as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; histlen = makehist(S.as_mut_ptr(), hist, len); H = entropy(hist, histlen, len); printf(b\"%lf\\n\\0\" as *const u8 as *const libc::c_char, H); return 0 as libc::c_int; }" }, { "index": 1073, "before": "int makehist(char *S,int *hist,int len){ \tint wherechar[256]; \tint i,histlen; \thistlen=0; \tfor(i=0;i<256;i++)wherechar[i]=-1; \tfor(i=0;i libc::c_int { let mut wherechar: [libc::c_int; 256] = [0; 256]; let mut i: libc::c_int = 0; let mut histlen: libc::c_int = 0; histlen = 0 as libc::c_int; i = 0 as libc::c_int; while i < 256 as libc::c_int { wherechar[i as usize] = -(1 as libc::c_int); i += 1; i; } i = 0 as libc::c_int; while i < len { if wherechar[*S.offset(i as isize) as libc::c_int as usize] == -(1 as libc::c_int) { wherechar[*S.offset(i as isize) as libc::c_int as usize] = histlen; histlen += 1; histlen; } let ref mut fresh0 = *hist .offset(wherechar[*S.offset(i as isize) as libc::c_int as usize] as isize); *fresh0 += 1; *fresh0; i += 1; i; } return histlen; }" }, { "index": 1074, "before": "int main() { int max = 0, i = 0, sixes, nines, twenties; loopstart: while (i < 100) { for (sixes = 0; sixes*6 < i; sixes++) { if (sixes*6 == i) { i++; goto loopstart; } for (nines = 0; nines*9 < i; nines++) { if (sixes*6 + nines*9 == i) { i++; goto loopstart; } for (twenties = 0; twenties*20 < i; twenties++) { if (sixes*6 + nines*9 + twenties*20 == i) { i++; goto loopstart; } } } } max = i; i++; } printf(\"Maximum non-McNuggets number is %d\\n\", max); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut max: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 0 as libc::c_int; let mut sixes: libc::c_int = 0; let mut nines: libc::c_int = 0; let mut twenties: libc::c_int = 0; 's_3: while i < 100 as libc::c_int { sixes = 0 as libc::c_int; while (sixes * 6 as libc::c_int) < i { if sixes * 6 as libc::c_int == i { i += 1; i; continue 's_3; } else { nines = 0 as libc::c_int; while (nines * 9 as libc::c_int) < i { if sixes * 6 as libc::c_int + nines * 9 as libc::c_int == i { i += 1; i; continue 's_3; } else { twenties = 0 as libc::c_int; while (twenties * 20 as libc::c_int) < i { if sixes * 6 as libc::c_int + nines * 9 as libc::c_int + twenties * 20 as libc::c_int == i { i += 1; i; continue 's_3; } else { twenties += 1; twenties; } } nines += 1; nines; } } sixes += 1; sixes; } } max = i; i += 1; i; } printf( b\"Maximum non-McNuggets number is %d\\n\\0\" as *const u8 as *const libc::c_char, max, ); return 0 as libc::c_int; }" }, { "index": 1075, "before": "int main(int argc, char *argv[]) { int days[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int m, y, w; if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1; days[1] -= (y % 4) || (!(y % 100) && (y % 400)); w = y * 365 + 97 * (y - 1) / 400 + 4; for(m = 0; m < 12; m++) { w = (w + days[m]) % 7; printf(\"%d-%02d-%d\\n\", y, m + 1,days[m] - w); } return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut days: [libc::c_int; 12] = [ 31 as libc::c_int, 29 as libc::c_int, 31 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, 31 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, ]; let mut m: libc::c_int = 0; let mut y: libc::c_int = 0; let mut w: libc::c_int = 0; if argc < 2 as libc::c_int || { y = atoi(*argv.offset(1 as libc::c_int as isize)); y <= 1752 as libc::c_int } { return 1 as libc::c_int; } days[1 as libc::c_int as usize] -= (y % 4 as libc::c_int != 0 || y % 100 as libc::c_int == 0 && y % 400 as libc::c_int != 0) as libc::c_int; w = y * 365 as libc::c_int + 97 as libc::c_int * (y - 1 as libc::c_int) / 400 as libc::c_int + 4 as libc::c_int; m = 0 as libc::c_int; while m < 12 as libc::c_int { w = (w + days[m as usize]) % 7 as libc::c_int; printf( b\"%d-%02d-%d\\n\\0\" as *const u8 as *const libc::c_char, y, m + 1 as libc::c_int, days[m as usize] - w, ); m += 1; m; } return 0 as libc::c_int; }" }, { "index": 1076, "before": "int main(void) { \tputs(isatty(fileno(stdin)) \t\t? \"stdin is tty\" \t\t: \"stdin is not tty\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { puts( if isatty(fileno(stdin)) != 0 { b\"stdin is tty\\0\" as *const u8 as *const libc::c_char } else { b\"stdin is not tty\\0\" as *const u8 as *const libc::c_char }, ); return 0 as libc::c_int; }" }, { "index": 1077, "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
\",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=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=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=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 libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut sandPileEdge: libc::c_int = 0; let mut centerPileHeight: libc::c_int = 0; let mut processAgain: libc::c_int = 1 as libc::c_int; let mut top: libc::c_int = 0; let mut down: libc::c_int = 0; let mut left: libc::c_int = 0; let mut right: libc::c_int = 0; let mut sandPile: *mut *mut libc::c_int = 0 as *mut *mut libc::c_int; let mut fileName: *mut libc::c_char = 0 as *mut libc::c_char; static mut colour: [libc::c_uchar; 3] = [0; 3]; if argc != 3 as libc::c_int { printf( b\"Usage: %s
\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); return 0 as libc::c_int; } sandPileEdge = atoi(*argv.offset(1 as libc::c_int as isize)); centerPileHeight = atoi(*argv.offset(2 as libc::c_int as isize)); if sandPileEdge <= 0 as libc::c_int || centerPileHeight <= 0 as libc::c_int { printf( b\"Sand pile and center pile dimensions must be positive integers.\\0\" as *const u8 as *const libc::c_char, ); return 0 as libc::c_int; } sandPile = malloc( (sandPileEdge as libc::c_ulong) .wrapping_mul(::core::mem::size_of::<*mut libc::c_int>() as libc::c_ulong), ) as *mut *mut libc::c_int; i = 0 as libc::c_int; while i < sandPileEdge { let ref mut fresh0 = *sandPile.offset(i as isize); *fresh0 = calloc( sandPileEdge as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; i += 1; i; } *(*sandPile.offset((sandPileEdge / 2 as libc::c_int) as isize)) .offset((sandPileEdge / 2 as libc::c_int) as isize) = centerPileHeight; printf(b\"Initial sand pile :\\n\\n\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < sandPileEdge { j = 0 as libc::c_int; while j < sandPileEdge { printf( b\"%3d\\0\" as *const u8 as *const libc::c_char, *(*sandPile.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; } while processAgain == 1 as libc::c_int { processAgain = 0 as libc::c_int; top = 0 as libc::c_int; down = 0 as libc::c_int; left = 0 as libc::c_int; right = 0 as libc::c_int; i = 0 as libc::c_int; while i < sandPileEdge { j = 0 as libc::c_int; while j < sandPileEdge { if *(*sandPile.offset(i as isize)).offset(j as isize) >= 4 as libc::c_int { if i - 1 as libc::c_int >= 0 as libc::c_int { top = 1 as libc::c_int; *(*sandPile.offset((i - 1 as libc::c_int) as isize)) .offset(j as isize) += 1 as libc::c_int; if *(*sandPile.offset((i - 1 as libc::c_int) as isize)) .offset(j as isize) >= 4 as libc::c_int { processAgain = 1 as libc::c_int; } } if (i + 1 as libc::c_int) < sandPileEdge { down = 1 as libc::c_int; *(*sandPile.offset((i + 1 as libc::c_int) as isize)) .offset(j as isize) += 1 as libc::c_int; if *(*sandPile.offset((i + 1 as libc::c_int) as isize)) .offset(j as isize) >= 4 as libc::c_int { processAgain = 1 as libc::c_int; } } if j - 1 as libc::c_int >= 0 as libc::c_int { left = 1 as libc::c_int; *(*sandPile.offset(i as isize)) .offset((j - 1 as libc::c_int) as isize) += 1 as libc::c_int; if *(*sandPile.offset(i as isize)) .offset((j - 1 as libc::c_int) as isize) >= 4 as libc::c_int { processAgain = 1 as libc::c_int; } } if (j + 1 as libc::c_int) < sandPileEdge { right = 1 as libc::c_int; *(*sandPile.offset(i as isize)) .offset((j + 1 as libc::c_int) as isize) += 1 as libc::c_int; if *(*sandPile.offset(i as isize)) .offset((j + 1 as libc::c_int) as isize) >= 4 as libc::c_int { processAgain = 1 as libc::c_int; } } *(*sandPile.offset(i as isize)).offset(j as isize) -= top + down + left + right; if *(*sandPile.offset(i as isize)).offset(j as isize) >= 4 as libc::c_int { processAgain = 1 as libc::c_int; } } j += 1; j; } i += 1; i; } } printf(b\"Final sand pile : \\n\\n\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < sandPileEdge { j = 0 as libc::c_int; while j < sandPileEdge { printf( b\"%3d\\0\" as *const u8 as *const libc::c_char, *(*sandPile.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; } fileName = malloc( (strlen(*argv.offset(1 as libc::c_int as isize))) .wrapping_add(strlen(*argv.offset(2 as libc::c_int as isize))) .wrapping_add(23 as libc::c_int as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_char; strcpy(fileName, b\"Final_Sand_Pile_\\0\" as *const u8 as *const libc::c_char); strcat(fileName, *argv.offset(1 as libc::c_int as isize)); strcat(fileName, b\"_\\0\" as *const u8 as *const libc::c_char); strcat(fileName, *argv.offset(2 as libc::c_int as isize)); strcat(fileName, b\".ppm\\0\" as *const u8 as *const libc::c_char); let mut fp: *mut FILE = fopen(fileName, b\"wb\\0\" as *const u8 as *const libc::c_char); fprintf( fp, b\"P6\\n%d %d\\n255\\n\\0\" as *const u8 as *const libc::c_char, sandPileEdge, sandPileEdge, ); i = 0 as libc::c_int; while i < sandPileEdge { j = 0 as libc::c_int; while j < sandPileEdge { colour[0 as libc::c_int as usize] = ((*(*sandPile.offset(i as isize)).offset(j as isize) + i) % 256 as libc::c_int) as libc::c_uchar; colour[1 as libc::c_int as usize] = ((*(*sandPile.offset(i as isize)).offset(j as isize) + j) % 256 as libc::c_int) as libc::c_uchar; colour[2 as libc::c_int as usize] = ((*(*sandPile.offset(i as isize)).offset(j as isize) + i * j) % 256 as libc::c_int) as libc::c_uchar; fwrite( colour.as_mut_ptr() as *const libc::c_void, 1 as libc::c_int as libc::c_ulong, 3 as libc::c_int as libc::c_ulong, fp, ); j += 1; j; } i += 1; i; } fclose(fp); printf( b\"\\nImage file written to %s\\n\\0\" as *const u8 as *const libc::c_char, fileName, ); return 0 as libc::c_int; }" }, { "index": 1078, "before": "int gcd(int m, int n) { int tmp; while(m) { tmp = m; m = n % m; n = tmp; } return n; }", "after": "pub unsafe extern \"C\" fn gcd(mut m: libc::c_int, mut n: libc::c_int) -> libc::c_int { let mut tmp: libc::c_int = 0; while m != 0 { tmp = m; m = n % m; n = tmp; } return n; }" }, { "index": 1079, "before": "int main() { printf(\"lcm(35, 21) = %d\\n\", lcm(21,35)); return 0; }", "after": "unsafe fn main() -> libc::c_int { printf( b\"lcm(35, 21) = %d\\n\\0\" as *const u8 as *const libc::c_char, lcm(21 as libc::c_int, 35 as libc::c_int), ); return 0 as libc::c_int; }" }, { "index": 1080, "before": "int lcm(int m, int n) { return m / gcd(m, n) * n; }", "after": "pub unsafe extern \"C\" fn lcm(mut m: libc::c_int, mut n: libc::c_int) -> libc::c_int { return m / gcd(m, n) * n; }" }, { "index": 1081, "before": "int main(int argc, char **argv) { uint top = atoi(argv[1]); uint *divsum = malloc((top + 1) * sizeof(*divsum)); uint pows[32] = {1, 0}; for (uint i = 0; i <= top; i++) divsum[i] = 1; // sieve // only sieve within lower half , the modification starts at 2*p for (uint p = 2; p+p <= top; p++) { if (divsum[p] > 1) { divsum[p] -= p;// subtract number itself from divisor sum ('proper') continue;} // p not prime uint x; // highest power of p we need //checking x <= top/y instead of x*y <= top to avoid overflow for (x = 1; pows[x - 1] <= top/p; x++) pows[x] = p*pows[x - 1]; //counter where n is not a*p with a = ?*p, useful for most p. //think of p>31 seldom divisions or p>sqrt(top) than no division is needed //n = 2*p, so the prime itself is left unchanged => k=p-1 uint k= p-1; for (uint n = p+p; n <= top; n += p) { uint s=1+pows[1]; k--; // search the right power only if needed if ( k==0) { for (uint i = 2; i < x && !(n%pows[i]); s += pows[i++]); k = p; } divsum[n] *= s; } } //now correct the upper half for (uint p = (top >> 1)+1; p <= top; p++) { if (divsum[p] > 1){ divsum[p] -= p;} } uint cnt = 0; for (uint a = 1; a <= top; a++) { uint b = divsum[a]; if (b > a && b <= top && divsum[b] == a){ printf(\"%u %u\\n\", a, b); cnt++;} } printf(\"\\nTop %u count : %u\\n\",top,cnt); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut top: uint = atoi(*argv.offset(1 as libc::c_int as isize)) as uint; let mut divsum: *mut uint = malloc( (top.wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut uint; let mut pows: [uint; 32] = [ 1 as libc::c_int as uint, 0 as libc::c_int as uint, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut i: uint = 0 as libc::c_int as uint; while i <= top { *divsum.offset(i as isize) = 1 as libc::c_int as uint; i = i.wrapping_add(1); i; } let mut p: uint = 2 as libc::c_int as uint; while p.wrapping_add(p) <= top { if *divsum.offset(p as isize) > 1 as libc::c_int as libc::c_uint { let ref mut fresh0 = *divsum.offset(p as isize); *fresh0 = (*fresh0 as libc::c_uint).wrapping_sub(p) as uint as uint; } else { let mut x: uint = 0; x = 1 as libc::c_int as uint; while pows[x.wrapping_sub(1 as libc::c_int as libc::c_uint) as usize] <= top.wrapping_div(p) { pows[x as usize] = p .wrapping_mul( pows[x.wrapping_sub(1 as libc::c_int as libc::c_uint) as usize], ); x = x.wrapping_add(1); x; } let mut k: uint = p.wrapping_sub(1 as libc::c_int as libc::c_uint); let mut n: uint = p.wrapping_add(p); while n <= top { let mut s: uint = (1 as libc::c_int as libc::c_uint) .wrapping_add(pows[1 as libc::c_int as usize]); k = k.wrapping_sub(1); k; if k == 0 as libc::c_int as libc::c_uint { let mut i_0: uint = 2 as libc::c_int as uint; while i_0 < x && n.wrapping_rem(pows[i_0 as usize]) == 0 { let fresh1 = i_0; i_0 = i_0.wrapping_add(1); s = (s as libc::c_uint).wrapping_add(pows[fresh1 as usize]) as uint as uint; } k = p; } let ref mut fresh2 = *divsum.offset(n as isize); *fresh2 = (*fresh2 as libc::c_uint).wrapping_mul(s) as uint as uint; n = (n as libc::c_uint).wrapping_add(p) as uint as uint; } } p = p.wrapping_add(1); p; } let mut p_0: uint = (top >> 1 as libc::c_int) .wrapping_add(1 as libc::c_int as libc::c_uint); while p_0 <= top { if *divsum.offset(p_0 as isize) > 1 as libc::c_int as libc::c_uint { let ref mut fresh3 = *divsum.offset(p_0 as isize); *fresh3 = (*fresh3 as libc::c_uint).wrapping_sub(p_0) as uint as uint; } p_0 = p_0.wrapping_add(1); p_0; } let mut cnt: uint = 0 as libc::c_int as uint; let mut a: uint = 1 as libc::c_int as uint; while a <= top { let mut b: uint = *divsum.offset(a as isize); if b > a && b <= top && *divsum.offset(b as isize) == a { printf(b\"%u %u\\n\\0\" as *const u8 as *const libc::c_char, a, b); cnt = cnt.wrapping_add(1); cnt; } a = a.wrapping_add(1); a; } printf(b\"\\nTop %u count : %u\\n\\0\" as *const u8 as *const libc::c_char, top, cnt); return 0 as libc::c_int; }" }, { "index": 1082, "before": "int main() { double inf = 1/0.0; double minus_inf = -1/0.0; double minus_zero = -1/ inf ; double nan = 0.0/0.0; printf(\"positive infinity: %f\\n\",inf); printf(\"negative infinity: %f\\n\",minus_inf); printf(\"negative zero: %f\\n\",minus_zero); printf(\"not a number: %f\\n\",nan); /* some arithmetic */ printf(\"+inf + 2.0 = %f\\n\",inf + 2.0); printf(\"+inf - 10.1 = %f\\n\",inf - 10.1); printf(\"+inf + -inf = %f\\n\",inf + minus_inf); printf(\"0.0 * +inf = %f\\n\",0.0 * inf); printf(\"1.0/-0.0 = %f\\n\",1.0/minus_zero); printf(\"NaN + 1.0 = %f\\n\",nan + 1.0); printf(\"NaN + NaN = %f\\n\",nan + nan); /* some comparisons */ printf(\"NaN == NaN = %s\\n\",nan == nan ? \"true\" : \"false\"); printf(\"0.0 == -0.0 = %s\\n\",0.0 == minus_zero ? \"true\" : \"false\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut inf: libc::c_double = 1 as libc::c_int as libc::c_double / 0.0f64; let mut minus_inf: libc::c_double = -(1 as libc::c_int) as libc::c_double / 0.0f64; let mut minus_zero: libc::c_double = -(1 as libc::c_int) as libc::c_double / inf; let mut nan: libc::c_double = 0.0f64 / 0.0f64; printf(b\"positive infinity: %f\\n\\0\" as *const u8 as *const libc::c_char, inf); printf(b\"negative infinity: %f\\n\\0\" as *const u8 as *const libc::c_char, minus_inf); printf(b\"negative zero: %f\\n\\0\" as *const u8 as *const libc::c_char, minus_zero); printf(b\"not a number: %f\\n\\0\" as *const u8 as *const libc::c_char, nan); printf(b\"+inf + 2.0 = %f\\n\\0\" as *const u8 as *const libc::c_char, inf + 2.0f64); printf(b\"+inf - 10.1 = %f\\n\\0\" as *const u8 as *const libc::c_char, inf - 10.1f64); printf(b\"+inf + -inf = %f\\n\\0\" as *const u8 as *const libc::c_char, inf + minus_inf); printf(b\"0.0 * +inf = %f\\n\\0\" as *const u8 as *const libc::c_char, 0.0f64 * inf); printf( b\"1.0/-0.0 = %f\\n\\0\" as *const u8 as *const libc::c_char, 1.0f64 / minus_zero, ); printf(b\"NaN + 1.0 = %f\\n\\0\" as *const u8 as *const libc::c_char, nan + 1.0f64); printf(b\"NaN + NaN = %f\\n\\0\" as *const u8 as *const libc::c_char, nan + nan); printf( b\"NaN == NaN = %s\\n\\0\" as *const u8 as *const libc::c_char, if nan == nan { b\"true\\0\" as *const u8 as *const libc::c_char } else { b\"false\\0\" as *const u8 as *const libc::c_char }, ); printf( b\"0.0 == -0.0 = %s\\n\\0\" as *const u8 as *const libc::c_char, if 0.0f64 == minus_zero { b\"true\\0\" as *const u8 as *const libc::c_char } else { b\"false\\0\" as *const u8 as *const libc::c_char }, ); return 0 as libc::c_int; }" }, { "index": 1083, "before": "int main(int argc, char** argv){ int operation; char squeezeChar; if(argc<3||argc>4){ printf(\"Usage : %s \\n\",argv[0]); return 0; } if(strcmpi(argv[1],\"SQUEEZE\")==0 && argc!=4){ scanf(\"Please enter characted to be squeezed : %c\",&squeezeChar); operation = SQUEEZE; } else if(argc==4){ operation = SQUEEZE; squeezeChar = argv[3][0]; } else if(strcmpi(argv[1],\"COLLAPSE\")==0){ operation = COLLAPSE; } if(strlen(argv[2])<2){ printResults(argv[2],argv[2],operation,squeezeChar); } else{ printResults(argv[2],processString(argv[2],operation,squeezeChar),operation,squeezeChar); } return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut operation: libc::c_int = 0; let mut squeezeChar: libc::c_char = 0; if argc < 3 as libc::c_int || argc > 4 as libc::c_int { printf( b\"Usage : %s \\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); return 0 as libc::c_int; } if strcmpi( *argv.offset(1 as libc::c_int as isize), b\"SQUEEZE\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ) == 0 as libc::c_int && argc != 4 as libc::c_int { scanf( b\"Please enter characted to be squeezed : %c\\0\" as *const u8 as *const libc::c_char, &mut squeezeChar as *mut libc::c_char, ); operation = 1 as libc::c_int; } else if argc == 4 as libc::c_int { operation = 1 as libc::c_int; squeezeChar = *(*argv.offset(3 as libc::c_int as isize)) .offset(0 as libc::c_int as isize); } else if strcmpi( *argv.offset(1 as libc::c_int as isize), b\"COLLAPSE\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ) == 0 as libc::c_int { operation = 0 as libc::c_int; } if strlen(*argv.offset(2 as libc::c_int as isize)) < 2 as libc::c_int as libc::c_ulong { printResults( *argv.offset(2 as libc::c_int as isize), *argv.offset(2 as libc::c_int as isize), operation, squeezeChar, ); } else { printResults( *argv.offset(2 as libc::c_int as isize), processString( *argv.offset(2 as libc::c_int as isize), operation, squeezeChar, ), operation, squeezeChar, ); } return 0 as libc::c_int; }" }, { "index": 1084, "before": "void printResults(char originalString[100], char finalString[100], int operation, char squeezeChar){ if(operation==SQUEEZE){ printf(\"Specified Operation : SQUEEZE\\nTarget Character : %c\",squeezeChar); } else printf(\"Specified Operation : COLLAPSE\"); printf(\"\\nOriginal %c%c%c%s%c%c%c\\nLength : %d\",174,174,174,originalString,175,175,175,(int)strlen(originalString)); printf(\"\\nFinal %c%c%c%s%c%c%c\\nLength : %d\\n\",174,174,174,finalString,175,175,175,(int)strlen(finalString)); }", "after": "pub unsafe extern \"C\" fn printResults( mut originalString: *mut libc::c_char, mut finalString: *mut libc::c_char, mut operation: libc::c_int, mut squeezeChar: libc::c_char, ) { if operation == 1 as libc::c_int { printf( b\"Specified Operation : SQUEEZE\\nTarget Character : %c\\0\" as *const u8 as *const libc::c_char, squeezeChar as libc::c_int, ); } else { printf(b\"Specified Operation : COLLAPSE\\0\" as *const u8 as *const libc::c_char); } printf( b\"\\nOriginal %c%c%c%s%c%c%c\\nLength : %d\\0\" as *const u8 as *const libc::c_char, 174 as libc::c_int, 174 as libc::c_int, 174 as libc::c_int, originalString, 175 as libc::c_int, 175 as libc::c_int, 175 as libc::c_int, strlen(originalString as *const libc::c_char) as libc::c_int, ); printf( b\"\\nFinal %c%c%c%s%c%c%c\\nLength : %d\\n\\0\" as *const u8 as *const libc::c_char, 174 as libc::c_int, 174 as libc::c_int, 174 as libc::c_int, finalString, 175 as libc::c_int, 175 as libc::c_int, 175 as libc::c_int, strlen(finalString as *const libc::c_char) as libc::c_int, ); }" }, { "index": 1085, "before": "int strcmpi(char str1[100],char str2[100]){ int len1 = strlen(str1), len2 = strlen(str2), i; if(len1!=len2){ return 1; } else{ for(i=0;i='A'&&str1[i]<='Z')&&(str2[i]>='a'&&str2[i]<='z')&&(str2[i]-65!=str1[i])) return 1; else if((str2[i]>='A'&&str2[i]<='Z')&&(str1[i]>='a'&&str1[i]<='z')&&(str1[i]-65!=str2[i])) return 1; else if(str1[i]!=str2[i]) return 1; } } return 0; }", "after": "pub unsafe extern \"C\" fn strcmpi( mut str1: *mut libc::c_char, mut str2: *mut libc::c_char, ) -> libc::c_int { let mut len1: libc::c_int = strlen(str1 as *const libc::c_char) as libc::c_int; let mut len2: libc::c_int = strlen(str2 as *const libc::c_char) as libc::c_int; let mut i: libc::c_int = 0; if len1 != len2 { return 1 as libc::c_int } else { i = 0 as libc::c_int; while i < len1 { if *str1.offset(i as isize) as libc::c_int >= 'A' as i32 && *str1.offset(i as isize) as libc::c_int <= 'Z' as i32 && (*str2.offset(i as isize) as libc::c_int >= 'a' as i32 && *str2.offset(i as isize) as libc::c_int <= 'z' as i32) && *str2.offset(i as isize) as libc::c_int - 65 as libc::c_int != *str1.offset(i as isize) as libc::c_int { return 1 as libc::c_int } else if *str2.offset(i as isize) as libc::c_int >= 'A' as i32 && *str2.offset(i as isize) as libc::c_int <= 'Z' as i32 && (*str1.offset(i as isize) as libc::c_int >= 'a' as i32 && *str1.offset(i as isize) as libc::c_int <= 'z' as i32) && *str1.offset(i as isize) as libc::c_int - 65 as libc::c_int != *str2.offset(i as isize) as libc::c_int { return 1 as libc::c_int } else if *str1.offset(i as isize) as libc::c_int != *str2.offset(i as isize) as libc::c_int { return 1 as libc::c_int } i += 1; i; } } return 0 as libc::c_int; }" }, { "index": 1086, "before": "int main(void) { \tint idx[] = { 23, 123, 1234, 12345, 20000, 30000, 40000, 50000, N, 0 }; \tint at = 0; \tmpz_init_set_ui(p[0], 1); \tfor (int i = 1; idx[at]; i++) { \t\tcalc(i); \t\tif (i != idx[at]) continue; \t\tgmp_printf(\"%2d:\\t%Zd\\n\", i, p[i]); \t\tat++; \t} }", "after": "unsafe fn main() -> libc::c_int { let mut idx: [libc::c_int; 10] = [ 23 as libc::c_int, 123 as libc::c_int, 1234 as libc::c_int, 12345 as libc::c_int, 20000 as libc::c_int, 30000 as libc::c_int, 40000 as libc::c_int, 50000 as libc::c_int, 100000 as libc::c_int, 0 as libc::c_int, ]; let mut at: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 1 as libc::c_int; while idx[at as usize] != 0 { calc(i); if !(i != idx[at as usize]) { at += 1; at; } i += 1; i; } return 0; }" }, { "index": 1087, "before": "void calc(int n) { \tmpz_init_set_ui(p[n], 0); \tfor (int k = 1; k <= n; k++) { \t\tint d = n - k * (3 * k - 1) / 2; \t\tif (d < 0) break; \t\tif (k&1)mpz_add(p[n], p[n], p[d]); \t\telse\tmpz_sub(p[n], p[n], p[d]); \t\td -= k; \t\tif (d < 0) break; \t\tif (k&1)mpz_add(p[n], p[n], p[d]); \t\telse\tmpz_sub(p[n], p[n], p[d]); \t} }", "after": "pub unsafe extern \"C\" fn calc(mut n: libc::c_int) { let mut k: libc::c_int = 1 as libc::c_int; while k <= n { let mut d: libc::c_int = n - k * (3 as libc::c_int * k - 1 as libc::c_int) / 2 as libc::c_int; if d < 0 as libc::c_int { break; } d -= k; if d < 0 as libc::c_int { break; } k += 1; k; } }" }, { "index": 1088, "before": "double agm( double a, double g ) { /* arithmetic-geometric mean */ double iota = 1.0E-16; double a1, g1; if( a*g < 0.0 ) { printf( \"arithmetic-geometric mean undefined when x*y<0\\n\" ); exit(1); } while( fabs(a-g)>iota ) { a1 = (a + g) / 2.0; g1 = sqrt(a * g); a = a1; g = g1; } return a; }", "after": "pub unsafe extern \"C\" fn agm( mut a: libc::c_double, mut g: libc::c_double, ) -> libc::c_double { let mut iota: libc::c_double = 1.0E-16f64; let mut a1: libc::c_double = 0.; let mut g1: libc::c_double = 0.; if a * g < 0.0f64 { printf( b\"arithmetic-geometric mean undefined when x*y<0\\n\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } while fabs(a - g) > iota { a1 = (a + g) / 2.0f64; g1 = sqrt(a * g); a = a1; g = g1; } return a; }" }, { "index": 1089, "before": "int main( void ) { double x, y; printf( \"Enter two numbers: \" ); scanf( \"%lf%lf\", &x, &y ); printf( \"The arithmetic-geometric mean is %lf\\n\", agm(x, y) ); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut x: libc::c_double = 0.; let mut y: libc::c_double = 0.; printf(b\"Enter two numbers: \\0\" as *const u8 as *const libc::c_char); scanf( b\"%lf%lf\\0\" as *const u8 as *const libc::c_char, &mut x as *mut libc::c_double, &mut y as *mut libc::c_double, ); printf( b\"The arithmetic-geometric mean is %lf\\n\\0\" as *const u8 as *const libc::c_char, agm(x, y), ); return 0 as libc::c_int; }" }, { "index": 1090, "before": "int check_isbn13(const char *isbn) { int ch = *isbn, count = 0, sum = 0; /* check isbn contains 13 digits and calculate weighted sum */ for ( ; ch != 0; ch = *++isbn, ++count) { /* skip hyphens or spaces */ if (ch == ' ' || ch == '-') { --count; continue; } if (ch < '0' || ch > '9') { return 0; } if (count & 1) { sum += 3 * (ch - '0'); } else { sum += ch - '0'; } } if (count != 13) return 0; return !(sum%10); }", "after": "pub unsafe extern \"C\" fn check_isbn13(mut isbn: *const libc::c_char) -> libc::c_int { let mut ch: libc::c_int = *isbn as libc::c_int; let mut count: libc::c_int = 0 as libc::c_int; let mut sum: libc::c_int = 0 as libc::c_int; while ch != 0 as libc::c_int { if ch == ' ' as i32 || ch == '-' as i32 { count -= 1; count; } else { if ch < '0' as i32 || ch > '9' as i32 { return 0 as libc::c_int; } if count & 1 as libc::c_int != 0 { sum += 3 as libc::c_int * (ch - '0' as i32); } else { sum += ch - '0' as i32; } } isbn = isbn.offset(1); ch = *isbn as libc::c_int; count += 1; count; } if count != 13 as libc::c_int { return 0 as libc::c_int; } return (sum % 10 as libc::c_int == 0) as libc::c_int; }" }, { "index": 1091, "before": "int main() { int i; const char* isbns[] = {\"978-1734314502\", \"978-1734314509\", \"978-1788399081\", \"978-1788399083\"}; for (i = 0; i < 4; ++i) { printf(\"%s: %s\\n\", isbns[i], check_isbn13(isbns[i]) ? \"good\" : \"bad\"); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut isbns: [*const libc::c_char; 4] = [ b\"978-1734314502\\0\" as *const u8 as *const libc::c_char, b\"978-1734314509\\0\" as *const u8 as *const libc::c_char, b\"978-1788399081\\0\" as *const u8 as *const libc::c_char, b\"978-1788399083\\0\" as *const u8 as *const libc::c_char, ]; i = 0 as libc::c_int; while i < 4 as libc::c_int { printf( b\"%s: %s\\n\\0\" as *const u8 as *const libc::c_char, isbns[i as usize], if check_isbn13(isbns[i as usize]) != 0 { b\"good\\0\" as *const u8 as *const libc::c_char } else { b\"bad\\0\" as *const u8 as *const libc::c_char }, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1092, "before": "int main() { regex_t preg; regmatch_t substmatch[1]; const char *tp = \"string$\"; const char *t1 = \"this is a matching string\"; const char *t2 = \"this is not a matching string!\"; const char *ss = \"istyfied\"; regcomp(&preg, \"string$\", REG_EXTENDED); printf(\"'%s' %smatched with '%s'\\n\", t1, (regexec(&preg, t1, 0, NULL, 0)==0) ? \"\" : \"did not \", tp); printf(\"'%s' %smatched with '%s'\\n\", t2, (regexec(&preg, t2, 0, NULL, 0)==0) ? \"\" : \"did not \", tp); regfree(&preg); /* change \"a[a-z]+\" into \"istifyed\"?*/ regcomp(&preg, \"a[a-z]+\", REG_EXTENDED); if ( regexec(&preg, t1, 1, substmatch, 0) == 0 ) { //fprintf(stderr, \"%d, %d\\n\", substmatch[0].rm_so, substmatch[0].rm_eo); char *ns = malloc(substmatch[0].rm_so + 1 + strlen(ss) + (strlen(t1) - substmatch[0].rm_eo) + 2); memcpy(ns, t1, substmatch[0].rm_so+1); memcpy(&ns[substmatch[0].rm_so], ss, strlen(ss)); memcpy(&ns[substmatch[0].rm_so+strlen(ss)], &t1[substmatch[0].rm_eo], strlen(&t1[substmatch[0].rm_eo])); ns[ substmatch[0].rm_so + strlen(ss) + strlen(&t1[substmatch[0].rm_eo]) ] = 0; printf(\"mod string: '%s'\\n\", ns); free(ns); } else { printf(\"the string '%s' is the same: no matching!\\n\", t1); } regfree(&preg); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut preg: regex_t = regex_t { __buffer: 0 as *mut re_dfa_t, __allocated: 0, __used: 0, __syntax: 0, __fastmap: 0 as *mut libc::c_char, __translate: 0 as *mut libc::c_uchar, re_nsub: 0, __can_be_null___regs_allocated___fastmap_accurate___no_sub___not_bol___not_eol___newline_anchor: [0; 1], c2rust_padding: [0; 7], }; let mut substmatch: [regmatch_t; 1] = [regmatch_t { rm_so: 0, rm_eo: 0 }; 1]; let mut tp: *const libc::c_char = b\"string$\\0\" as *const u8 as *const libc::c_char; let mut t1: *const libc::c_char = b\"this is a matching string\\0\" as *const u8 as *const libc::c_char; let mut t2: *const libc::c_char = b\"this is not a matching string!\\0\" as *const u8 as *const libc::c_char; let mut ss: *const libc::c_char = b\"istyfied\\0\" as *const u8 as *const libc::c_char; regcomp( &mut preg, b\"string$\\0\" as *const u8 as *const libc::c_char, 1 as libc::c_int, ); printf( b\"'%s' %smatched with '%s'\\n\\0\" as *const u8 as *const libc::c_char, t1, if regexec( &mut preg, t1, 0 as libc::c_int as size_t, 0 as *mut regmatch_t, 0 as libc::c_int, ) == 0 as libc::c_int { b\"\\0\" as *const u8 as *const libc::c_char } else { b\"did not \\0\" as *const u8 as *const libc::c_char }, tp, ); printf( b\"'%s' %smatched with '%s'\\n\\0\" as *const u8 as *const libc::c_char, t2, if regexec( &mut preg, t2, 0 as libc::c_int as size_t, 0 as *mut regmatch_t, 0 as libc::c_int, ) == 0 as libc::c_int { b\"\\0\" as *const u8 as *const libc::c_char } else { b\"did not \\0\" as *const u8 as *const libc::c_char }, tp, ); regfree(&mut preg); regcomp( &mut preg, b\"a[a-z]+\\0\" as *const u8 as *const libc::c_char, 1 as libc::c_int, ); if regexec( &mut preg, t1, 1 as libc::c_int as size_t, substmatch.as_mut_ptr(), 0 as libc::c_int, ) == 0 as libc::c_int { let mut ns: *mut libc::c_char = malloc( ((substmatch[0 as libc::c_int as usize].rm_so + 1 as libc::c_int) as libc::c_ulong) .wrapping_add(strlen(ss)) .wrapping_add( (strlen(t1)) .wrapping_sub( substmatch[0 as libc::c_int as usize].rm_eo as libc::c_ulong, ), ) .wrapping_add(2 as libc::c_int as libc::c_ulong), ) as *mut libc::c_char; memcpy( ns as *mut libc::c_void, t1 as *const libc::c_void, (substmatch[0 as libc::c_int as usize].rm_so + 1 as libc::c_int) as libc::c_ulong, ); memcpy( &mut *ns .offset( (*substmatch.as_mut_ptr().offset(0 as libc::c_int as isize)).rm_so as isize, ) as *mut libc::c_char as *mut libc::c_void, ss as *const libc::c_void, strlen(ss), ); memcpy( &mut *ns .offset( ((*substmatch.as_mut_ptr().offset(0 as libc::c_int as isize)).rm_so as libc::c_ulong) .wrapping_add( (strlen as unsafe extern \"C\" fn( *const libc::c_char, ) -> libc::c_ulong)(ss), ) as isize, ) as *mut libc::c_char as *mut libc::c_void, &*t1 .offset( (*substmatch.as_mut_ptr().offset(0 as libc::c_int as isize)).rm_eo as isize, ) as *const libc::c_char as *const libc::c_void, strlen( &*t1 .offset( (*substmatch.as_mut_ptr().offset(0 as libc::c_int as isize)) .rm_eo as isize, ), ), ); *ns .offset( (substmatch[0 as libc::c_int as usize].rm_so as libc::c_ulong) .wrapping_add(strlen(ss)) .wrapping_add( strlen( &*t1 .offset( (*substmatch.as_mut_ptr().offset(0 as libc::c_int as isize)) .rm_eo as isize, ), ), ) as isize, ) = 0 as libc::c_int as libc::c_char; printf(b\"mod string: '%s'\\n\\0\" as *const u8 as *const libc::c_char, ns); free(ns as *mut libc::c_void); } else { printf( b\"the string '%s' is the same: no matching!\\n\\0\" as *const u8 as *const libc::c_char, t1, ); } regfree(&mut preg); return 0 as libc::c_int; }" }, { "index": 1093, "before": "uint64_t digit_sum(uint64_t n, uint64_t sum) { ++sum; while (n > 0 && n % 10 == 0) { sum -= 9; n /= 10; } return sum; }", "after": "pub unsafe extern \"C\" fn digit_sum(mut n: uint64_t, mut sum: uint64_t) -> uint64_t { sum = sum.wrapping_add(1); sum; while n > 0 as libc::c_int as libc::c_ulong && n.wrapping_rem(10 as libc::c_int as libc::c_ulong) == 0 as libc::c_int as libc::c_ulong { sum = (sum as libc::c_ulong).wrapping_sub(9 as libc::c_int as libc::c_ulong) as uint64_t as uint64_t; n = (n as libc::c_ulong).wrapping_div(10 as libc::c_int as libc::c_ulong) as uint64_t as uint64_t; } return sum; }" }, { "index": 1094, "before": "bool divisible(uint64_t n, uint64_t d) { if ((d & 1) == 0 && (n & 1) == 1) return false; return n % d == 0; }", "after": "pub unsafe extern \"C\" fn divisible(mut n: uint64_t, mut d: uint64_t) -> bool { if d & 1 as libc::c_int as libc::c_ulong == 0 as libc::c_int as libc::c_ulong && n & 1 as libc::c_int as libc::c_ulong == 1 as libc::c_int as libc::c_ulong { return 0 as libc::c_int != 0; } return n.wrapping_rem(d) == 0 as libc::c_int as libc::c_ulong; }" }, { "index": 1095, "before": "int main() { setlocale(LC_ALL, \"\"); uint64_t previous = 1, gap = 0, sum = 0; int niven_index = 0, gap_index = 1; printf(\"Gap index Gap Niven index Niven number\\n\"); for (uint64_t niven = 1; gap_index <= 32; ++niven) { sum = digit_sum(niven, sum); if (divisible(niven, sum)) { if (niven > previous + gap) { gap = niven - previous; printf(\"%'9d %'4llu %'14d %'15llu\\n\", gap_index++, gap, niven_index, previous); } previous = niven; ++niven_index; } } return 0; }", "after": "unsafe fn main() -> libc::c_int { setlocale(6 as libc::c_int, b\"\\0\" as *const u8 as *const libc::c_char); let mut previous: uint64_t = 1 as libc::c_int as uint64_t; let mut gap: uint64_t = 0 as libc::c_int as uint64_t; let mut sum: uint64_t = 0 as libc::c_int as uint64_t; let mut niven_index: libc::c_int = 0 as libc::c_int; let mut gap_index: libc::c_int = 1 as libc::c_int; printf( b\"Gap index Gap Niven index Niven number\\n\\0\" as *const u8 as *const libc::c_char, ); let mut niven: uint64_t = 1 as libc::c_int as uint64_t; while gap_index <= 32 as libc::c_int { sum = digit_sum(niven, sum); if divisible(niven, sum) { if niven > previous.wrapping_add(gap) { gap = niven.wrapping_sub(previous); let fresh0 = gap_index; gap_index = gap_index + 1; printf( b\"%'9d %'4llu %'14d %'15llu\\n\\0\" as *const u8 as *const libc::c_char, fresh0, gap, niven_index, previous, ); } previous = niven; niven_index += 1; niven_index; } niven = niven.wrapping_add(1); niven; } return 0 as libc::c_int; }" }, { "index": 1096, "before": "void print_table(unsigned kmax, unsigned nmax) { \tprintf(\"n\\\\k|\"); \tfor (int k = 0; k <= kmax; ++k) printf(\"%'3u\", k); \tprintf(\"\\n----\"); \tfor (int k = 0; k <= kmax; ++k) printf(\"---\"); \tputchar('\\n'); \tfor (int n = 1; n <= nmax; n += 2) { \t\tprintf(\"%-2u |\", n); \t\tfor (int k = 0; k <= kmax; ++k) \t\t\tprintf(\"%'3d\", jacobi(k, n)); \t\tputchar('\\n'); \t} }", "after": "pub unsafe extern \"C\" fn print_table(mut kmax: libc::c_uint, mut nmax: libc::c_uint) { printf(b\"n\\\\k|\\0\" as *const u8 as *const libc::c_char); let mut k: libc::c_int = 0 as libc::c_int; while k as libc::c_uint <= kmax { printf(b\"%'3u\\0\" as *const u8 as *const libc::c_char, k); k += 1; k; } printf(b\"\\n----\\0\" as *const u8 as *const libc::c_char); let mut k_0: libc::c_int = 0 as libc::c_int; while k_0 as libc::c_uint <= kmax { printf(b\"---\\0\" as *const u8 as *const libc::c_char); k_0 += 1; k_0; } putchar('\\n' as i32); let mut n: libc::c_int = 1 as libc::c_int; while n as libc::c_uint <= nmax { printf(b\"%-2u |\\0\" as *const u8 as *const libc::c_char, n); let mut k_1: libc::c_int = 0 as libc::c_int; while k_1 as libc::c_uint <= kmax { printf( b\"%'3d\\0\" as *const u8 as *const libc::c_char, jacobi(k_1 as libc::c_ulong, n as libc::c_ulong), ); k_1 += 1; k_1; } putchar('\\n' as i32); n += 2 as libc::c_int; } }" }, { "index": 1097, "before": "int main() { \tprint_table(20, 21); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { print_table(20 as libc::c_int as libc::c_uint, 21 as libc::c_int as libc::c_uint); return 0 as libc::c_int; }" }, { "index": 1098, "before": "int jacobi(unsigned long a, unsigned long n) { \tif (a >= n) a %= n; \tint result = 1; \twhile (a) { \t\twhile ((a & 1) == 0) { \t\t\ta >>= 1; \t\t\tif ((n & 7) == 3 || (n & 7) == 5) result = -result; \t\t} \t\tSWAP(a, n); \t\tif ((a & 3) == 3 && (n & 3) == 3) result = -result; \t\ta %= n; \t} \tif (n == 1) return result; \treturn 0; }", "after": "pub unsafe extern \"C\" fn jacobi( mut a: libc::c_ulong, mut n: libc::c_ulong, ) -> libc::c_int { if a >= n { a = a.wrapping_rem(n); } let mut result: libc::c_int = 1 as libc::c_int; while a != 0 { while a & 1 as libc::c_int as libc::c_ulong == 0 as libc::c_int as libc::c_ulong { a >>= 1 as libc::c_int; if n & 7 as libc::c_int as libc::c_ulong == 3 as libc::c_int as libc::c_ulong || n & 7 as libc::c_int as libc::c_ulong == 5 as libc::c_int as libc::c_ulong { result = -result; } } a ^= n; n ^= a; a ^= n; if a & 3 as libc::c_int as libc::c_ulong == 3 as libc::c_int as libc::c_ulong && n & 3 as libc::c_int as libc::c_ulong == 3 as libc::c_int as libc::c_ulong { result = -result; } a = a.wrapping_rem(n); } if n == 1 as libc::c_int as libc::c_ulong { return result; } return 0 as libc::c_int; }" }, { "index": 1099, "before": "int main() { \tint i, id[N]; \tpthread_t tid[N]; \tfor (i = 0; i < N; i++) \t\tpthread_mutex_init(forks + (id[i] = i), 0); \tfor (i = 0; i < N; i++) \t\tpthread_create(tid + i, 0, philosophize, id + i); \t/* wait forever: the threads don't actually stop */ \treturn pthread_join(tid[0], 0); }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut id: [libc::c_int; 5] = [0; 5]; let mut tid: [pthread_t; 5] = [0; 5]; i = 0 as libc::c_int; while i < 5 as libc::c_int { id[i as usize] = i; pthread_mutex_init( forks.as_mut_ptr().offset(id[i as usize] as isize), 0 as *const pthread_mutexattr_t, ); i += 1; i; } i = 0 as libc::c_int; while i < 5 as libc::c_int { pthread_create( tid.as_mut_ptr().offset(i as isize), 0 as *const pthread_attr_t, Some( philosophize as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void, ), id.as_mut_ptr().offset(i as isize) as *mut libc::c_void, ); i += 1; i; } return pthread_join(tid[0 as libc::c_int as usize], 0 as *mut *mut libc::c_void); }" }, { "index": 1100, "before": "void print(int y, int x, const char *fmt, ...) { \tstatic pthread_mutex_t screen = PTHREAD_MUTEX_INITIALIZER; \tva_list ap; \tva_start(ap, fmt); \tlock(&screen); \txy(y + 1, x), vprintf(fmt, ap); \txy(N + 1, 1), fflush(stdout); \tunlock(&screen); }", "after": "pub unsafe extern \"C\" fn print( mut y: libc::c_int, mut x: libc::c_int, mut fmt: *const libc::c_char, mut args: ... ) { static mut screen: pthread_mutex_t = pthread_mutex_t { __data: { let mut init = __pthread_mutex_s { __lock: 0 as libc::c_int, __count: 0 as libc::c_int as libc::c_uint, __owner: 0 as libc::c_int, __nusers: 0 as libc::c_int as libc::c_uint, __kind: PTHREAD_MUTEX_TIMED_NP as libc::c_int, __spins: 0 as libc::c_int as libc::c_short, __elision: 0 as libc::c_int as libc::c_short, __list: { let mut init = __pthread_internal_list { __prev: 0 as *const __pthread_internal_list as *mut __pthread_internal_list, __next: 0 as *const __pthread_internal_list as *mut __pthread_internal_list, }; init }, }; init }, }; let mut ap: ::core::ffi::VaListImpl; ap = args.clone(); pthread_mutex_lock(&mut screen); printf( b\"\\x1B[%d;%dH\\0\" as *const u8 as *const libc::c_char, y + 1 as libc::c_int, x, ); vprintf(fmt, ap.as_va_list()); printf( b\"\\x1B[%d;%dH\\0\" as *const u8 as *const libc::c_char, 5 as libc::c_int + 1 as libc::c_int, 1 as libc::c_int, ); fflush(stdout); pthread_mutex_unlock(&mut screen); }" }, { "index": 1101, "before": "void think(int id) { \tint i, t; \tchar buf[64] = {0}; \tdo { \t\tclear_eol(id); \t\tsprintf(buf, \"..oO (%s)\", topic[t = rand() % M]); \t\tfor (i = 0; buf[i]; i++) { \t\t\tprint(id, i+12, \"%c\", buf[i]); \t\t\tif (i < 5) usleep(200000); \t\t} \t\tusleep(500000 + rand() % 1000000); \t} while (t); }", "after": "pub unsafe extern \"C\" fn think(mut id: libc::c_int) { let mut i: libc::c_int = 0; let mut t: libc::c_int = 0; let mut buf: [libc::c_char; 64] = [ 0 as libc::c_int as libc::c_char, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; loop { print(id, 12 as libc::c_int, b\"\\x1B[K\\0\" as *const u8 as *const libc::c_char); t = rand() % 5 as libc::c_int; sprintf( buf.as_mut_ptr(), b\"..oO (%s)\\0\" as *const u8 as *const libc::c_char, topic[t as usize], ); i = 0 as libc::c_int; while buf[i as usize] != 0 { print( id, i + 12 as libc::c_int, b\"%c\\0\" as *const u8 as *const libc::c_char, buf[i as usize] as libc::c_int, ); if i < 5 as libc::c_int { usleep(200000 as libc::c_int as __useconds_t); } i += 1; i; } usleep( (500000 as libc::c_int + rand() % 1000000 as libc::c_int) as __useconds_t, ); if !(t != 0) { break; } }; }" }, { "index": 1102, "before": "void eat(int id) { \tint f[2], ration, i; /* forks */ \tf[0] = f[1] = id; \t/* make some (but not all) philosophers leftie. \t could have been f[!id] = (id + 1) %N; for example */ \tf[id & 1] = (id + 1) % N; \tclear_eol(id); \tprint(id, 12, \"..oO (forks, need forks)\"); \tfor (i = 0; i < 2; i++) { \t\tlock(forks + f[i]); \t\tif (!i) clear_eol(id); \t\tprint(id, 12 + (f[i] != id) * 6, \"fork%d\", f[i]); \t\t/* delay 1 sec to clearly show the order of fork acquisition */ \t\tsleep(1); \t} \tfor (i = 0, ration = 3 + rand() % 8; i < ration; i++) \t\tprint(id, 24 + i * 4, \"nom\"), sleep(1); \t/* done nomming, give up forks (order doesn't matter) */ \tfor (i = 0; i < 2; i++) unlock(forks + f[i]); }", "after": "pub unsafe extern \"C\" fn eat(mut id: libc::c_int) { let mut f: [libc::c_int; 2] = [0; 2]; let mut ration: libc::c_int = 0; let mut i: libc::c_int = 0; f[1 as libc::c_int as usize] = id; f[0 as libc::c_int as usize] = f[1 as libc::c_int as usize]; f[(id & 1 as libc::c_int) as usize] = (id + 1 as libc::c_int) % 5 as libc::c_int; print(id, 12 as libc::c_int, b\"\\x1B[K\\0\" as *const u8 as *const libc::c_char); print( id, 12 as libc::c_int, b\"..oO (forks, need forks)\\0\" as *const u8 as *const libc::c_char, ); i = 0 as libc::c_int; while i < 2 as libc::c_int { pthread_mutex_lock(forks.as_mut_ptr().offset(f[i as usize] as isize)); if i == 0 { print( id, 12 as libc::c_int, b\"\\x1B[K\\0\" as *const u8 as *const libc::c_char, ); } print( id, 12 as libc::c_int + (f[i as usize] != id) as libc::c_int * 6 as libc::c_int, b\"fork%d\\0\" as *const u8 as *const libc::c_char, f[i as usize], ); sleep(1 as libc::c_int as libc::c_uint); i += 1; i; } i = 0 as libc::c_int; ration = 3 as libc::c_int + rand() % 8 as libc::c_int; while i < ration { print( id, 24 as libc::c_int + i * 4 as libc::c_int, b\"nom\\0\" as *const u8 as *const libc::c_char, ); sleep(1 as libc::c_int as libc::c_uint); i += 1; i; } i = 0 as libc::c_int; while i < 2 as libc::c_int { pthread_mutex_unlock(forks.as_mut_ptr().offset(f[i as usize] as isize)); i += 1; i; } }" }, { "index": 1103, "before": "size_t mpz_digitcount(mpz_t op) { /* mpz_sizeinbase can not be trusted to give accurate base 10 length */ char *t = mpz_get_str(NULL, 10, op); size_t ret = strlen(t); free(t); return ret; }", "after": "pub unsafe extern \"C\" fn mpz_digitcount(mut op: libc::c_int) -> size_t { let mut t: *mut libc::c_char = 0 as *mut libc::c_char; let mut ret: size_t = strlen(t); free(t as *mut libc::c_void); return ret; }" }, { "index": 1104, "before": "int main(void) { mpz_t t; mpz_init(t); size_t i; for (i = 0; i <= 110; ++i) { if (i <= 10 || i % 10 == 0) { mpz_left_fac_ui(t, i); gmp_printf(\"!%u = %Zd\\n\", i, t); } } for (i = 1000; i <= 10000; i += 1000) { mpz_left_fac_ui(t, i); printf(\"!%u has %u digits\\n\", i, mpz_digitcount(t)); } mpz_clear(t); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: size_t = 0; i = 0 as libc::c_int as size_t; while i <= 110 as libc::c_int as libc::c_ulong { i <= 10 as libc::c_int as libc::c_ulong || i.wrapping_rem(10 as libc::c_int as libc::c_ulong) == 0 as libc::c_int as libc::c_ulong; i = i.wrapping_add(1); i; } i = 1000 as libc::c_int as size_t; while i <= 10000 as libc::c_int as libc::c_ulong { i = (i as libc::c_ulong).wrapping_add(1000 as libc::c_int as libc::c_ulong) as size_t as size_t; } return 0 as libc::c_int; }" }, { "index": 1105, "before": "void mpz_left_fac_ui(mpz_t rop, unsigned long op) { mpz_t t1; mpz_init_set_ui(t1, 1); mpz_set_ui(rop, 0); size_t i; for (i = 1; i <= op; ++i) { mpz_add(rop, rop, t1); mpz_mul_ui(t1, t1, i); } mpz_clear(t1); }", "after": "pub unsafe extern \"C\" fn mpz_left_fac_ui(mut rop: libc::c_int, mut op: libc::c_ulong) { let mut i: size_t = 0; i = 1 as libc::c_int as size_t; while i <= op { i = i.wrapping_add(1); i; } }" }, { "index": 1106, "before": "int main(void) { const char *test[] = {\"ABC\", \"DEF\", \"G\", \"H\"}; char *s; for (size_t i = 0; i < 5; i++) { s = quib(test, i); printf(\"%s\\n\", s); free(s); } return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut test: [*const libc::c_char; 4] = [ b\"ABC\\0\" as *const u8 as *const libc::c_char, b\"DEF\\0\" as *const u8 as *const libc::c_char, b\"G\\0\" as *const u8 as *const libc::c_char, b\"H\\0\" as *const u8 as *const libc::c_char, ]; let mut s: *mut libc::c_char = 0 as *mut libc::c_char; let mut i: size_t = 0 as libc::c_int as size_t; while i < 5 as libc::c_int as libc::c_ulong { s = quib(test.as_mut_ptr(), i); printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, s); free(s as *mut libc::c_void); i = i.wrapping_add(1); i; } return 0 as libc::c_int; }" }, { "index": 1107, "before": "int main() { int n; for (n = 2; n < 200; n++) if (perfect(n)) printf(\"%d\\n\", n); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 0; n = 2 as libc::c_int; while n < 200 as libc::c_int { if perfect(n) != 0 { printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, n); } n += 1; n; } return 0 as libc::c_int; }" }, { "index": 1108, "before": "int perfect(int n) { int max = (int)sqrt((double)n) + 1; int tot = 1; int i; for (i = 2; i < max; i++) if ((n % i) == 0) { tot += i; int q = n / i; if (q > i) tot += q; } return tot == n; }", "after": "pub unsafe extern \"C\" fn perfect(mut n: libc::c_int) -> libc::c_int { let mut max: libc::c_int = sqrt(n as libc::c_double) as libc::c_int + 1 as libc::c_int; let mut tot: libc::c_int = 1 as libc::c_int; let mut i: libc::c_int = 0; i = 2 as libc::c_int; while i < max { if n % i == 0 as libc::c_int { tot += i; let mut q: libc::c_int = n / i; if q > i { tot += q; } } i += 1; i; } return (tot == n) as libc::c_int; }" }, { "index": 1109, "before": "int main(void) { \tleven(\"raisethysword\", \"rosettacode\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { leven( b\"raisethysword\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"rosettacode\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); return 0 as libc::c_int; }" }, { "index": 1110, "before": "void leven(char *a, char *b) { \tint i, j, la = strlen(a), lb = strlen(b); \tedit *tbl = malloc(sizeof(edit) * (1 + la)); \ttbl[0] = calloc((1 + la) * (1 + lb), sizeof(edit_t)); \tfor (i = 1; i <= la; i++) \t\ttbl[i] = tbl[i-1] + (1+lb); \tfor (i = la; i >= 0; i--) { \t\tchar *aa = a + i; \t\tfor (j = lb; j >= 0; j--) { \t\t\tchar *bb = b + j; \t\t\tif (!*aa && !*bb) continue; \t\t\tedit e = &tbl[i][j]; \t\t\tedit repl = &tbl[i+1][j+1]; \t\t\tedit dela = &tbl[i+1][j]; \t\t\tedit delb = &tbl[i][j+1]; \t\t\te->c1 = *aa; \t\t\te->c2 = *bb; \t\t\tif (!*aa) { \t\t\t\te->next = delb; \t\t\t\te->n = e->next->n + 1; \t\t\t\tcontinue; \t\t\t} \t\t\tif (!*bb) { \t\t\t\te->next = dela; \t\t\t\te->n = e->next->n + 1; \t\t\t\tcontinue; \t\t\t} \t\t\te->next = repl; \t\t\tif (*aa == *bb) { \t\t\t\te->n = e->next->n; \t\t\t\tcontinue; \t\t\t} \t\t\tif (e->next->n > delb->n) { \t\t\t\te->next = delb; \t\t\t\te->c1 = 0; \t\t\t} \t\t\tif (e->next->n > dela->n) { \t\t\t\te->next = dela; \t\t\t\te->c1 = *aa; \t\t\t\te->c2 = 0; \t\t\t} \t\t\te->n = e->next->n + 1; \t\t} \t} \tedit p = tbl[0]; \tprintf(\"%s -> %s: %d edits\\n\", a, b, p->n); \twhile (p->next) { \t\tif (p->c1 == p->c2) \t\t\tprintf(\"%c\", p->c1); \t\telse { \t\t\tputchar('('); \t\t\tif (p->c1) putchar(p->c1); \t\t\tputchar(','); \t\t\tif (p->c2) putchar(p->c2); \t\t\tputchar(')'); \t\t} \t\tp = p->next; \t} \tputchar('\\n'); \tfree(tbl[0]); \tfree(tbl); }", "after": "pub unsafe extern \"C\" fn leven(mut a: *mut libc::c_char, mut b: *mut libc::c_char) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut la: libc::c_int = strlen(a) as libc::c_int; let mut lb: libc::c_int = strlen(b) as libc::c_int; let mut tbl: *mut edit = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul((1 as libc::c_int + la) as libc::c_ulong), ) as *mut edit; let ref mut fresh0 = *tbl.offset(0 as libc::c_int as isize); *fresh0 = calloc( ((1 as libc::c_int + la) * (1 as libc::c_int + lb)) as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as edit; i = 1 as libc::c_int; while i <= la { let ref mut fresh1 = *tbl.offset(i as isize); *fresh1 = (*tbl.offset((i - 1 as libc::c_int) as isize)) .offset((1 as libc::c_int + lb) as isize); i += 1; i; } i = la; while i >= 0 as libc::c_int { let mut aa: *mut libc::c_char = a.offset(i as isize); j = lb; while j >= 0 as libc::c_int { let mut bb: *mut libc::c_char = b.offset(j as isize); if !(*aa == 0 && *bb == 0) { let mut e: edit = &mut *(*tbl.offset(i as isize)).offset(j as isize) as *mut edit_s; let mut repl: edit = &mut *(*tbl.offset((i + 1 as libc::c_int) as isize)) .offset((j + 1 as libc::c_int) as isize) as *mut edit_s; let mut dela: edit = &mut *(*tbl.offset((i + 1 as libc::c_int) as isize)) .offset(j as isize) as *mut edit_s; let mut delb: edit = &mut *(*tbl.offset(i as isize)) .offset((j + 1 as libc::c_int) as isize) as *mut edit_s; (*e).c1 = *aa; (*e).c2 = *bb; if *aa == 0 { (*e).next = delb; (*e).n = (*(*e).next).n + 1 as libc::c_int; } else if *bb == 0 { (*e).next = dela; (*e).n = (*(*e).next).n + 1 as libc::c_int; } else { (*e).next = repl; if *aa as libc::c_int == *bb as libc::c_int { (*e).n = (*(*e).next).n; } else { if (*(*e).next).n > (*delb).n { (*e).next = delb; (*e).c1 = 0 as libc::c_int as libc::c_char; } if (*(*e).next).n > (*dela).n { (*e).next = dela; (*e).c1 = *aa; (*e).c2 = 0 as libc::c_int as libc::c_char; } (*e).n = (*(*e).next).n + 1 as libc::c_int; } } } j -= 1; j; } i -= 1; i; } let mut p: edit = *tbl.offset(0 as libc::c_int as isize); printf(b\"%s -> %s: %d edits\\n\\0\" as *const u8 as *const libc::c_char, a, b, (*p).n); while !((*p).next).is_null() { if (*p).c1 as libc::c_int == (*p).c2 as libc::c_int { printf(b\"%c\\0\" as *const u8 as *const libc::c_char, (*p).c1 as libc::c_int); } else { putchar('(' as i32); if (*p).c1 != 0 { putchar((*p).c1 as libc::c_int); } putchar(',' as i32); if (*p).c2 != 0 { putchar((*p).c2 as libc::c_int); } putchar(')' as i32); } p = (*p).next; } putchar('\\n' as i32); free(*tbl.offset(0 as libc::c_int as isize) as *mut libc::c_void); free(tbl as *mut libc::c_void); }" }, { "index": 1111, "before": "void main() { \tFILE * fp; \tchar * line = NULL; \tsize_t len = 0; \tssize_t read; \tfp = fopen(\"fasta.txt\", \"r\"); \tif (fp == NULL) \t\texit(EXIT_FAILURE); \tint state = 0; \twhile ((read = getline(&line, &len, fp)) != -1) { \t\t/* Delete trailing newline */ \t\tif (line[read - 1] == '\\n') \t\t\tline[read - 1] = 0; \t\t/* Handle comment lines*/ \t\tif (line[0] == '>') { \t\t\tif (state == 1) \t\t\t\tprintf(\"\\n\"); \t\t\tprintf(\"%s: \", line+1); \t\t\tstate = 1; \t\t} else { \t\t\t/* Print everything else */ \t\t\tprintf(\"%s\", line); \t\t} \t} \tprintf(\"\\n\"); \tfclose(fp); \tif (line) \t\tfree(line); \texit(EXIT_SUCCESS); }", "after": "unsafe fn main() { let mut fp: *mut FILE = 0 as *mut FILE; let mut line: *mut libc::c_char = 0 as *mut libc::c_char; let mut len: size_t = 0 as libc::c_int as size_t; let mut read: ssize_t = 0; fp = fopen( b\"fasta.txt\\0\" as *const u8 as *const libc::c_char, b\"r\\0\" as *const u8 as *const libc::c_char, ); if fp.is_null() { exit(1 as libc::c_int); } let mut state: libc::c_int = 0 as libc::c_int; loop { read = getline(&mut line, &mut len, fp); if !(read != -(1 as libc::c_int) as libc::c_long) { break; } if *line.offset((read - 1 as libc::c_int as libc::c_long) as isize) as libc::c_int == '\\n' as i32 { *line .offset( (read - 1 as libc::c_int as libc::c_long) as isize, ) = 0 as libc::c_int as libc::c_char; } if *line.offset(0 as libc::c_int as isize) as libc::c_int == '>' as i32 { if state == 1 as libc::c_int { printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); } printf( b\"%s: \\0\" as *const u8 as *const libc::c_char, line.offset(1 as libc::c_int as isize), ); state = 1 as libc::c_int; } else { printf(b\"%s\\0\" as *const u8 as *const libc::c_char, line); } } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); fclose(fp); if !line.is_null() { free(line as *mut libc::c_void); } exit(0 as libc::c_int); }" }, { "index": 1112, "before": "int main(void) { for (size_t i = 0; i < 20; i++) { char *binstr = bin(i); printf(\"%s\\n\", binstr); free(binstr); } }", "after": "unsafe fn main() -> libc::c_int { let mut i: size_t = 0 as libc::c_int as size_t; while i < 20 as libc::c_int as libc::c_ulong { let mut binstr: *mut libc::c_char = bin(i as uint32_t); printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, binstr); free(binstr as *mut libc::c_void); i = i.wrapping_add(1); i; } return 0; }" }, { "index": 1113, "before": "void swap(int i,int j){ \tint temp = pos[i]; \tpos[i] = pos[j]; \tpos[j] = temp; }", "after": "pub unsafe extern \"C\" fn swap(mut i: libc::c_int, mut j: libc::c_int) { let mut temp: libc::c_int = pos[i as usize]; pos[i as usize] = pos[j as usize]; pos[j as usize] = temp; }" }, { "index": 1114, "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 unsafe extern \"C\" fn printRank() { let mut i: libc::c_int = 0; setlocale(6 as libc::c_int, b\"\\0\" as *const u8 as *const libc::c_char); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < 8 as libc::c_int { if rank[i as usize] as libc::c_int == 'K' as i32 { printf( b\"%lc\\0\" as *const u8 as *const libc::c_char, 9812 as libc::c_int as wint_t, ); } else if rank[i as usize] as libc::c_int == 'Q' as i32 { printf( b\"%lc\\0\" as *const u8 as *const libc::c_char, 9813 as libc::c_int as wint_t, ); } else if rank[i as usize] as libc::c_int == 'R' as i32 { printf( b\"%lc\\0\" as *const u8 as *const libc::c_char, 9814 as libc::c_int as wint_t, ); } else if rank[i as usize] as libc::c_int == 'B' as i32 { printf( b\"%lc\\0\" as *const u8 as *const libc::c_char, 9815 as libc::c_int as wint_t, ); } if rank[i as usize] as libc::c_int == 'N' as i32 { printf( b\"%lc\\0\" as *const u8 as *const libc::c_char, 9816 as libc::c_int as wint_t, ); } i += 1; i; } }" }, { "index": 1115, "before": "int main() { \tint i; \tsrand((unsigned)time(NULL)); \tfor(i=0;i<9;i++){ \t\tgenerateFirstRank(); \t\tprintRank(); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; srand(time(0 as *mut time_t) as libc::c_uint); i = 0 as libc::c_int; while i < 9 as libc::c_int { generateFirstRank(); printRank(); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1116, "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 unsafe extern \"C\" fn generateFirstRank() { let mut kPos: libc::c_int = 0; let mut qPos: libc::c_int = 0; let mut bPos1: libc::c_int = 0; let mut bPos2: libc::c_int = 0; let mut rPos1: libc::c_int = 0; let mut rPos2: libc::c_int = 0; let mut nPos1: libc::c_int = 0; let mut nPos2: libc::c_int = 0; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 8 as libc::c_int { rank[i as usize] = 'e' as i32 as libc::c_char; pos[i as usize] = i; i += 1; i; } loop { kPos = rand() % 8 as libc::c_int; rPos1 = rand() % 8 as libc::c_int; rPos2 = rand() % 8 as libc::c_int; if !(rPos1 - kPos <= 0 as libc::c_int && rPos2 - kPos <= 0 as libc::c_int || rPos1 - kPos >= 0 as libc::c_int && rPos2 - kPos >= 0 as libc::c_int || (rPos1 == rPos2 || kPos == rPos1 || kPos == rPos2)) { break; } } rank[pos[rPos1 as usize] as usize] = 'R' as i32 as libc::c_char; rank[pos[kPos as usize] as usize] = 'K' as i32 as libc::c_char; rank[pos[rPos2 as usize] as usize] = 'R' as i32 as libc::c_char; swap(rPos1, 7 as libc::c_int); swap(rPos2, 6 as libc::c_int); swap(kPos, 5 as libc::c_int); loop { bPos1 = rand() % 5 as libc::c_int; bPos2 = rand() % 5 as libc::c_int; if !((pos[bPos1 as usize] - pos[bPos2 as usize]) % 2 as libc::c_int == 0 as libc::c_int || bPos1 == bPos2) { break; } } rank[pos[bPos1 as usize] as usize] = 'B' as i32 as libc::c_char; rank[pos[bPos2 as usize] as usize] = 'B' as i32 as libc::c_char; swap(bPos1, 4 as libc::c_int); swap(bPos2, 3 as libc::c_int); loop { qPos = rand() % 3 as libc::c_int; nPos1 = rand() % 3 as libc::c_int; if !(qPos == nPos1) { break; } } rank[pos[qPos as usize] as usize] = 'Q' as i32 as libc::c_char; rank[pos[nPos1 as usize] as usize] = 'N' as i32 as libc::c_char; i = 0 as libc::c_int; while i < 8 as libc::c_int { if rank[i as usize] as libc::c_int == 'e' as i32 { rank[i as usize] = 'N' as i32 as libc::c_char; break; } else { i += 1; i; } } }" }, { "index": 1117, "before": "void swap_row(double *a, double *b, int r1, int r2, int n) { \tdouble tmp, *p1, *p2; \tint i; \tif (r1 == r2) return; \tfor (i = 0; i < n; i++) { \t\tp1 = mat_elem(a, r1, i, n); \t\tp2 = mat_elem(a, r2, i, n); \t\ttmp = *p1, *p1 = *p2, *p2 = tmp; \t} \ttmp = b[r1], b[r1] = b[r2], b[r2] = tmp; }", "after": "pub unsafe extern \"C\" fn swap_row( mut a: *mut libc::c_double, mut b: *mut libc::c_double, mut r1: libc::c_int, mut r2: libc::c_int, mut n: libc::c_int, ) { let mut tmp: libc::c_double = 0.; let mut p1: *mut libc::c_double = 0 as *mut libc::c_double; let mut p2: *mut libc::c_double = 0 as *mut libc::c_double; let mut i: libc::c_int = 0; if r1 == r2 { return; } i = 0 as libc::c_int; while i < n { p1 = a.offset((r1 * n + i) as isize); p2 = a.offset((r2 * n + i) as isize); tmp = *p1; *p1 = *p2; *p2 = tmp; i += 1; i; } tmp = *b.offset(r1 as isize); *b.offset(r1 as isize) = *b.offset(r2 as isize); *b.offset(r2 as isize) = tmp; }" }, { "index": 1118, "before": "int main(void) { \tdouble a[] = { \t\t1.00, 0.00, 0.00, 0.00, 0.00, 0.00, \t\t1.00, 0.63, 0.39, 0.25, 0.16, 0.10, \t\t1.00, 1.26, 1.58, 1.98, 2.49, 3.13, \t\t1.00, 1.88, 3.55, 6.70, 12.62, 23.80, \t\t1.00, 2.51, 6.32, 15.88, 39.90, 100.28, \t\t1.00, 3.14, 9.87, 31.01, 97.41, 306.02 \t}; \tdouble b[] = { -0.01, 0.61, 0.91, 0.99, 0.60, 0.02 }; \tdouble x[6]; \tint i; \tgauss_eliminate(a, b, x, 6); \tfor (i = 0; i < 6; i++) \t\tprintf(\"%g\\n\", x[i]); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut a: [libc::c_double; 36] = [ 1.00f64, 0.00f64, 0.00f64, 0.00f64, 0.00f64, 0.00f64, 1.00f64, 0.63f64, 0.39f64, 0.25f64, 0.16f64, 0.10f64, 1.00f64, 1.26f64, 1.58f64, 1.98f64, 2.49f64, 3.13f64, 1.00f64, 1.88f64, 3.55f64, 6.70f64, 12.62f64, 23.80f64, 1.00f64, 2.51f64, 6.32f64, 15.88f64, 39.90f64, 100.28f64, 1.00f64, 3.14f64, 9.87f64, 31.01f64, 97.41f64, 306.02f64, ]; let mut b: [libc::c_double; 6] = [ -0.01f64, 0.61f64, 0.91f64, 0.99f64, 0.60f64, 0.02f64, ]; let mut x: [libc::c_double; 6] = [0.; 6]; let mut i: libc::c_int = 0; gauss_eliminate(a.as_mut_ptr(), b.as_mut_ptr(), x.as_mut_ptr(), 6 as libc::c_int); i = 0 as libc::c_int; while i < 6 as libc::c_int { printf(b\"%g\\n\\0\" as *const u8 as *const libc::c_char, x[i as usize]); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1119, "before": "void gauss_eliminate(double *a, double *b, double *x, int n) { #define A(y, x) (*mat_elem(a, y, x, n)) \tint i, j, col, row, max_row,dia; \tdouble max, tmp; \tfor (dia = 0; dia < n; dia++) { \t\tmax_row = dia, max = A(dia, dia); \t\tfor (row = dia + 1; row < n; row++) \t\t\tif ((tmp = fabs(A(row, dia))) > max) \t\t\t\tmax_row = row, max = tmp; \t\tswap_row(a, b, dia, max_row, n); \t\tfor (row = dia + 1; row < n; row++) { \t\t\ttmp = A(row, dia) / A(dia, dia); \t\t\tfor (col = dia+1; col < n; col++) \t\t\t\tA(row, col) -= tmp * A(dia, col); \t\t\tA(row, dia) = 0; \t\t\tb[row] -= tmp * b[dia]; \t\t} \t} \tfor (row = n - 1; row >= 0; row--) { \t\ttmp = b[row]; \t\tfor (j = n - 1; j > row; j--) \t\t\ttmp -= x[j] * A(row, j); \t\tx[row] = tmp / A(row, row); \t} #undef A }", "after": "pub unsafe extern \"C\" fn gauss_eliminate( mut a: *mut libc::c_double, mut b: *mut libc::c_double, mut x: *mut libc::c_double, mut n: libc::c_int, ) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut col: libc::c_int = 0; let mut row: libc::c_int = 0; let mut max_row: libc::c_int = 0; let mut dia: libc::c_int = 0; let mut max: libc::c_double = 0.; let mut tmp: libc::c_double = 0.; dia = 0 as libc::c_int; while dia < n { max_row = dia; max = *a.offset((dia * n + dia) as isize); row = dia + 1 as libc::c_int; while row < n { tmp = fabs(*a.offset((row * n + dia) as isize)); if tmp > max { max_row = row; max = tmp; } row += 1; row; } swap_row(a, b, dia, max_row, n); row = dia + 1 as libc::c_int; while row < n { tmp = *a.offset((row * n + dia) as isize) / *a.offset((dia * n + dia) as isize); col = dia + 1 as libc::c_int; while col < n { *a.offset((row * n + col) as isize) -= tmp * *a.offset((dia * n + col) as isize); col += 1; col; } *a.offset((row * n + dia) as isize) = 0 as libc::c_int as libc::c_double; *b.offset(row as isize) -= tmp * *b.offset(dia as isize); row += 1; row; } dia += 1; dia; } row = n - 1 as libc::c_int; while row >= 0 as libc::c_int { tmp = *b.offset(row as isize); j = n - 1 as libc::c_int; while j > row { tmp -= *x.offset(j as isize) * *a.offset((row * n + j) as isize); j -= 1; j; } *x.offset(row as isize) = tmp / *a.offset((row * n + row) as isize); row -= 1; row; } }" }, { "index": 1120, "before": "uint32_t rc_crc32(uint32_t crc, const char *buf, size_t len) { \tstatic uint32_t table[256]; \tstatic int have_table = 0; \tuint32_t rem; \tuint8_t octet; \tint i, j; \tconst char *p, *q; \t/* This check is not thread safe; there is no mutex. */ \tif (have_table == 0) { \t\t/* Calculate CRC table. */ \t\tfor (i = 0; i < 256; i++) { \t\t\trem = i; /* remainder from polynomial division */ \t\t\tfor (j = 0; j < 8; j++) { \t\t\t\tif (rem & 1) { \t\t\t\t\trem >>= 1; \t\t\t\t\trem ^= 0xedb88320; \t\t\t\t} else \t\t\t\t\trem >>= 1; \t\t\t} \t\t\ttable[i] = rem; \t\t} \t\thave_table = 1; \t} \tcrc = ~crc; \tq = buf + len; \tfor (p = buf; p < q; p++) { \t\toctet = *p; /* Cast to unsigned octet. */ \t\tcrc = (crc >> 8) ^ table[(crc & 0xff) ^ octet]; \t} \treturn ~crc; }", "after": "pub unsafe extern \"C\" fn rc_crc32( mut crc: uint32_t, mut buf: *const libc::c_char, mut len: size_t, ) -> uint32_t { static mut table: [uint32_t; 256] = [0; 256]; static mut have_table: libc::c_int = 0 as libc::c_int; let mut rem: uint32_t = 0; let mut octet: uint8_t = 0; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut p: *const libc::c_char = 0 as *const libc::c_char; let mut q: *const libc::c_char = 0 as *const libc::c_char; if have_table == 0 as libc::c_int { i = 0 as libc::c_int; while i < 256 as libc::c_int { rem = i as uint32_t; j = 0 as libc::c_int; while j < 8 as libc::c_int { if rem & 1 as libc::c_int as libc::c_uint != 0 { rem >>= 1 as libc::c_int; rem ^= 0xedb88320 as libc::c_uint; } else { rem >>= 1 as libc::c_int; } j += 1; j; } table[i as usize] = rem; i += 1; i; } have_table = 1 as libc::c_int; } crc = !crc; q = buf.offset(len as isize); p = buf; while p < q { octet = *p as uint8_t; crc = crc >> 8 as libc::c_int ^ table[(crc & 0xff as libc::c_int as libc::c_uint ^ octet as libc::c_uint) as usize]; p = p.offset(1); p; } return !crc; }" }, { "index": 1121, "before": "int main() { \tconst char *s = \"The quick brown fox jumps over the lazy dog\"; \tprintf(\"%\" PRIX32 \"\\n\", rc_crc32(0, s, strlen(s))); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut s: *const libc::c_char = b\"The quick brown fox jumps over the lazy dog\\0\" as *const u8 as *const libc::c_char; printf( b\"%X\\n\\0\" as *const u8 as *const libc::c_char, rc_crc32(0 as libc::c_int as uint32_t, s, strlen(s)), ); return 0 as libc::c_int; }" }, { "index": 1122, "before": "double horner(double *coeffs, int s, double x) { int i; double res = 0.0; for(i=s-1; i >= 0; i--) { res = res * x + coeffs[i]; } return res; }", "after": "pub unsafe extern \"C\" fn horner( mut coeffs: *mut libc::c_double, mut s: libc::c_int, mut x: libc::c_double, ) -> libc::c_double { let mut i: libc::c_int = 0; let mut res: libc::c_double = 0.0f64; i = s - 1 as libc::c_int; while i >= 0 as libc::c_int { res = res * x + *coeffs.offset(i as isize); i -= 1; i; } return res; }" }, { "index": 1123, "before": "int main() { double coeffs[] = { -19.0, 7.0, -4.0, 6.0 }; printf(\"%5.1f\\n\", horner(coeffs, sizeof(coeffs)/sizeof(double), 3.0)); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut coeffs: [libc::c_double; 4] = [-19.0f64, 7.0f64, -4.0f64, 6.0f64]; printf( b\"%5.1f\\n\\0\" as *const u8 as *const libc::c_char, horner( coeffs.as_mut_ptr(), (::core::mem::size_of::<[libc::c_double; 4]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, 3.0f64, ), ); return 0 as libc::c_int; }" }, { "index": 1124, "before": "xint jos_large(xint n, xint k, xint m) { \tif (k <= 1) return n - m - 1; \txint a = m; \twhile (a < n) { \t\txint q = (a - m + k - 2) / (k - 1); \t\tif (a + q > n)\tq = n - a; \t\telse if (!q)\tq = 1; \t\tm = (m + q * k) % (a += q); \t} \treturn m; }", "after": "pub unsafe extern \"C\" fn jos_large(mut n: xint, mut k: xint, mut m: xint) -> xint { if k <= 1 as libc::c_int as libc::c_ulonglong { return n.wrapping_sub(m).wrapping_sub(1 as libc::c_int as libc::c_ulonglong); } let mut a: xint = m; while a < n { let mut q: xint = a .wrapping_sub(m) .wrapping_add(k) .wrapping_sub(2 as libc::c_int as libc::c_ulonglong) .wrapping_div(k.wrapping_sub(1 as libc::c_int as libc::c_ulonglong)); if a.wrapping_add(q) > n { q = n.wrapping_sub(a); } else if q == 0 { q = 1 as libc::c_int as xint; } a = (a as libc::c_ulonglong).wrapping_add(q) as xint as xint; m = m.wrapping_add(q.wrapping_mul(k)).wrapping_rem(a); } return m; }" }, { "index": 1125, "before": "int main(void) { \txint n, k, i; \tn = 41; \tk = 3; \tprintf(\"n = %llu, k = %llu, final survivor: %d\\n\", n, k, jos(n, k, 0)); \tn = 9876543210987654321ULL; \tk = 12031; \tprintf(\"n = %llu, k = %llu, three survivors:\", n, k); \tfor (i = 3; i--; ) \t\tprintf(\" %llu\", jos_large(n, k, i)); \tputchar('\\n'); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: xint = 0; let mut k: xint = 0; let mut i: xint = 0; n = 41 as libc::c_int as xint; k = 3 as libc::c_int as xint; printf( b\"n = %llu, k = %llu, final survivor: %d\\n\\0\" as *const u8 as *const libc::c_char, n, k, jos(n as libc::c_int, k as libc::c_int, 0 as libc::c_int), ); n = 9876543210987654321 as libc::c_ulonglong; k = 12031 as libc::c_int as xint; printf( b\"n = %llu, k = %llu, three survivors:\\0\" as *const u8 as *const libc::c_char, n, k, ); i = 3 as libc::c_int as xint; loop { let fresh0 = i; i = i.wrapping_sub(1); if !(fresh0 != 0) { break; } printf(b\" %llu\\0\" as *const u8 as *const libc::c_char, jos_large(n, k, i)); } putchar('\\n' as i32); return 0 as libc::c_int; }" }, { "index": 1126, "before": "int jos(int n, int k, int m) { \tint a; \tfor (a = m + 1; a <= n; a++) \t\tm = (m + k) % a; \treturn m; }", "after": "pub unsafe extern \"C\" fn jos( mut n: libc::c_int, mut k: libc::c_int, mut m: libc::c_int, ) -> libc::c_int { let mut a: libc::c_int = 0; a = m + 1 as libc::c_int; while a <= n { m = (m + k) % a; a += 1; a; } return m; }" }, { "index": 1127, "before": "int main() { \tint x[] = {\t0, 1, 2, 4, 6, 7, 8, 11, 12, 14, \t\t\t15, 16, 17, 18, 19, 20, 21, 22, 23, 24, \t\t\t25, 27, 28, 29, 30, 31, 32, 33, 35, 36, \t\t\t37, 38, 39 }; \tchar *s = malloc(rprint(0, x, sizeof(x) / sizeof(int)) + 1); \trprint(s, x, sizeof(x) / sizeof(int)); \tprintf(\"%s\\n\", s); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut x: [libc::c_int; 33] = [ 0 as libc::c_int, 1 as libc::c_int, 2 as libc::c_int, 4 as libc::c_int, 6 as libc::c_int, 7 as libc::c_int, 8 as libc::c_int, 11 as libc::c_int, 12 as libc::c_int, 14 as libc::c_int, 15 as libc::c_int, 16 as libc::c_int, 17 as libc::c_int, 18 as libc::c_int, 19 as libc::c_int, 20 as libc::c_int, 21 as libc::c_int, 22 as libc::c_int, 23 as libc::c_int, 24 as libc::c_int, 25 as libc::c_int, 27 as libc::c_int, 28 as libc::c_int, 29 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, 32 as libc::c_int, 33 as libc::c_int, 35 as libc::c_int, 36 as libc::c_int, 37 as libc::c_int, 38 as libc::c_int, 39 as libc::c_int, ]; let mut s: *mut libc::c_char = malloc( (rprint( 0 as *mut libc::c_char, x.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 33]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, )) .wrapping_add(1 as libc::c_int as libc::c_ulong), ) as *mut libc::c_char; rprint( s, x.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 33]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, ); printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, s); return 0 as libc::c_int; }" }, { "index": 1128, "before": "size_t rprint(char *s, int *x, int len) { #define sep (a > s ? \",\" : \"\") /* use comma except before first output */ #define ol (s ? 100 : 0) /* print only if not testing for length */ \tint i, j; \tchar *a = s; \tfor (i = j = 0; i < len; i = ++j) { \t\tfor (; j < len - 1 && x[j + 1] == x[j] + 1; j++); \t\tif (i + 1 < j) \t\t\ta += snprintf(s?a:s, ol, \"%s%d-%d\", sep, x[i], x[j]); \t\telse \t\t\twhile (i <= j) \t\t\t\ta += snprintf(s?a:s, ol, \"%s%d\", sep, x[i++]); \t} \treturn a - s; #undef sep #undef ol }", "after": "pub unsafe extern \"C\" fn rprint( mut s: *mut libc::c_char, mut x: *mut libc::c_int, mut len: libc::c_int, ) -> size_t { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut a: *mut libc::c_char = s; j = 0 as libc::c_int; i = j; while i < len { while j < len - 1 as libc::c_int && *x.offset((j + 1 as libc::c_int) as isize) == *x.offset(j as isize) + 1 as libc::c_int { j += 1; j; } if (i + 1 as libc::c_int) < j { a = a .offset( snprintf( if !s.is_null() { a } else { s }, (if !s.is_null() { 100 as libc::c_int } else { 0 as libc::c_int }) as libc::c_ulong, b\"%s%d-%d\\0\" as *const u8 as *const libc::c_char, if a > s { b\",\\0\" as *const u8 as *const libc::c_char } else { b\"\\0\" as *const u8 as *const libc::c_char }, *x.offset(i as isize), *x.offset(j as isize), ) as isize, ); } else { while i <= j { let fresh0 = i; i = i + 1; a = a .offset( snprintf( if !s.is_null() { a } else { s }, (if !s.is_null() { 100 as libc::c_int } else { 0 as libc::c_int }) as libc::c_ulong, b\"%s%d\\0\" as *const u8 as *const libc::c_char, if a > s { b\",\\0\" as *const u8 as *const libc::c_char } else { b\"\\0\" as *const u8 as *const libc::c_char }, *x.offset(fresh0 as isize), ) as isize, ); } } j += 1; i = j; } return a.offset_from(s) as libc::c_long as size_t; }" }, { "index": 1129, "before": "int main(int argc,char** argv) { char str[100]; int counter = 0, len; if(argc!=2){ printf(\"Usage : %s \\n\",argv[0]); return 0; } FILE *fp = fopen(argv[1],\"r\"); while(fscanf(fp,\"%s\",str)!=EOF) buildGenome(str); fclose(fp); printGenome(); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut str: [libc::c_char; 100] = [0; 100]; let mut counter: libc::c_int = 0 as libc::c_int; let mut len: libc::c_int = 0; if argc != 2 as libc::c_int { printf( b\"Usage : %s \\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); return 0 as libc::c_int; } let mut fp: *mut FILE = fopen( *argv.offset(1 as libc::c_int as isize), b\"r\\0\" as *const u8 as *const libc::c_char, ); while fscanf(fp, b\"%s\\0\" as *const u8 as *const libc::c_char, str.as_mut_ptr()) != -(1 as libc::c_int) { buildGenome(str.as_mut_ptr()); } fclose(fp); printGenome(); return 0 as libc::c_int; }" }, { "index": 1130, "before": "void buildGenome(char str[100]){ int len = strlen(str),i; genome *genomeIterator, *newGenome; totalLength += len; for(i=0;istrand = (char*)malloc(len*sizeof(char)); strcpy(genomeData->strand,str); genomeData->length = len; genomeData->next = NULL; } else{ genomeIterator = genomeData; while(genomeIterator->next!=NULL) genomeIterator = genomeIterator->next; newGenome = (genome*)malloc(sizeof(genome)); newGenome->strand = (char*)malloc(len*sizeof(char)); strcpy(newGenome->strand,str); newGenome->length = len; newGenome->next = NULL; genomeIterator->next = newGenome; } }", "after": "pub unsafe extern \"C\" fn buildGenome(mut str: *mut libc::c_char) { let mut len: libc::c_int = strlen(str as *const libc::c_char) as libc::c_int; let mut i: libc::c_int = 0; let mut genomeIterator: *mut genome = 0 as *mut genome; let mut newGenome: *mut genome = 0 as *mut genome; totalLength += len; i = 0 as libc::c_int; while i < len { match *str.offset(i as isize) as libc::c_int { 65 => { Adenine += 1; Adenine; } 84 => { Thymine += 1; Thymine; } 67 => { Cytosine += 1; Cytosine; } 71 => { Guanine += 1; Guanine; } _ => {} } i += 1; i; } if genomeData.is_null() { genomeData = malloc(::core::mem::size_of::() as libc::c_ulong) as *mut genome; (*genomeData) .strand = malloc( (len as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_char; strcpy((*genomeData).strand, str as *const libc::c_char); (*genomeData).length = len; (*genomeData).next = 0 as *mut genome; } else { genomeIterator = genomeData; while !((*genomeIterator).next).is_null() { genomeIterator = (*genomeIterator).next; } newGenome = malloc(::core::mem::size_of::() as libc::c_ulong) as *mut genome; (*newGenome) .strand = malloc( (len as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_char; strcpy((*newGenome).strand, str as *const libc::c_char); (*newGenome).length = len; (*newGenome).next = 0 as *mut genome; (*genomeIterator).next = newGenome; }; }" }, { "index": 1131, "before": "void printGenome(){ genome* genomeIterator = genomeData; int width = numDigits(totalLength), len = 0; printf(\"Sequence:\\n\"); while(genomeIterator!=NULL){ printf(\"\\n%*d%3s%3s\",width+1,len,\":\",genomeIterator->strand); len += genomeIterator->length; genomeIterator = genomeIterator->next; } printf(\"\\n\\nBase Count\\n----------\\n\\n\"); printf(\"%3c%3s%*d\\n\",'A',\":\",width+1,Adenine); printf(\"%3c%3s%*d\\n\",'T',\":\",width+1,Thymine); printf(\"%3c%3s%*d\\n\",'C',\":\",width+1,Cytosine); printf(\"%3c%3s%*d\\n\",'G',\":\",width+1,Guanine); printf(\"\\n%3s%*d\\n\",\"Total:\",width+1,Adenine + Thymine + Cytosine + Guanine); free(genomeData); }", "after": "pub unsafe extern \"C\" fn printGenome() { let mut genomeIterator: *mut genome = genomeData; let mut width: libc::c_int = numDigits(totalLength); let mut len: libc::c_int = 0 as libc::c_int; printf(b\"Sequence:\\n\\0\" as *const u8 as *const libc::c_char); while !genomeIterator.is_null() { printf( b\"\\n%*d%3s%3s\\0\" as *const u8 as *const libc::c_char, width + 1 as libc::c_int, len, b\":\\0\" as *const u8 as *const libc::c_char, (*genomeIterator).strand, ); len += (*genomeIterator).length; genomeIterator = (*genomeIterator).next; } printf(b\"\\n\\nBase Count\\n----------\\n\\n\\0\" as *const u8 as *const libc::c_char); printf( b\"%3c%3s%*d\\n\\0\" as *const u8 as *const libc::c_char, 'A' as i32, b\":\\0\" as *const u8 as *const libc::c_char, width + 1 as libc::c_int, Adenine, ); printf( b\"%3c%3s%*d\\n\\0\" as *const u8 as *const libc::c_char, 'T' as i32, b\":\\0\" as *const u8 as *const libc::c_char, width + 1 as libc::c_int, Thymine, ); printf( b\"%3c%3s%*d\\n\\0\" as *const u8 as *const libc::c_char, 'C' as i32, b\":\\0\" as *const u8 as *const libc::c_char, width + 1 as libc::c_int, Cytosine, ); printf( b\"%3c%3s%*d\\n\\0\" as *const u8 as *const libc::c_char, 'G' as i32, b\":\\0\" as *const u8 as *const libc::c_char, width + 1 as libc::c_int, Guanine, ); printf( b\"\\n%3s%*d\\n\\0\" as *const u8 as *const libc::c_char, b\"Total:\\0\" as *const u8 as *const libc::c_char, width + 1 as libc::c_int, Adenine + Thymine + Cytosine + Guanine, ); free(genomeData as *mut libc::c_void); }" }, { "index": 1132, "before": "int numDigits(int num){ int len = 1; while(num>10){ num = num/10; len++; } return len; }", "after": "pub unsafe extern \"C\" fn numDigits(mut num: libc::c_int) -> libc::c_int { let mut len: libc::c_int = 1 as libc::c_int; while num > 10 as libc::c_int { num = num / 10 as libc::c_int; len += 1; len; } return len; }" }, { "index": 1133, "before": "int main(void) { \t// array bounds is sort of random here, it's big enough for 64bit unsigned. \tull sums[32*81 + 1] = {1, 0}; \tfor (int n = 1; ; n++) { \t\tfor (int i = n*81; i; i--) { \t\t\tfor (int j = 1; j < 10; j++) { \t\t\t\tint s = j*j; \t\t\t\tif (s > i) break; \t\t\t\tsums[i] += sums[i-s]; \t\t\t} \t\t} \t\tull count89 = 0; \t\tfor (int i = 1; i < n*81 + 1; i++) { \t\t\tif (!is89(i)) continue; \t\t\tif (sums[i] > ~0ULL - count89) { \t\t\t\tprintf(\"counter overflow for 10^%d\\n\", n); \t\t\t\treturn 0; \t\t\t} \t\t\tcount89 += sums[i]; \t\t} \t\tprintf(\"1->10^%d: %llu\\n\", n, count89); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut sums: [ull; 2593] = [ 1 as libc::c_int as ull, 0 as libc::c_int as ull, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut n: libc::c_int = 1 as libc::c_int; loop { let mut i: libc::c_int = n * 81 as libc::c_int; while i != 0 { let mut j: libc::c_int = 1 as libc::c_int; while j < 10 as libc::c_int { let mut s: libc::c_int = j * j; if s > i { break; } sums[i as usize] = (sums[i as usize] as libc::c_ulonglong) .wrapping_add(sums[(i - s) as usize]) as ull as ull; j += 1; j; } i -= 1; i; } let mut count89: ull = 0 as libc::c_int as ull; let mut i_0: libc::c_int = 1 as libc::c_int; while i_0 < n * 81 as libc::c_int + 1 as libc::c_int { if !(is89(i_0) == 0) { if sums[i_0 as usize] > (!(0 as libc::c_ulonglong)).wrapping_sub(count89) { printf( b\"counter overflow for 10^%d\\n\\0\" as *const u8 as *const libc::c_char, n, ); return 0 as libc::c_int; } count89 = (count89 as libc::c_ulonglong).wrapping_add(sums[i_0 as usize]) as ull as ull; } i_0 += 1; i_0; } printf(b\"1->10^%d: %llu\\n\\0\" as *const u8 as *const libc::c_char, n, count89); n += 1; n; }; }" }, { "index": 1134, "before": "int is89(int x) { \twhile (1) { \t\tint s = 0; \t\tdo s += (x%10)*(x%10); while ((x /= 10)); \t\tif (s == 89) return 1; \t\tif (s == 1) return 0; \t\tx = s; \t} }", "after": "pub unsafe extern \"C\" fn is89(mut x: libc::c_int) -> libc::c_int { loop { let mut s: libc::c_int = 0 as libc::c_int; loop { s += x % 10 as libc::c_int * (x % 10 as libc::c_int); x /= 10 as libc::c_int; if !(x != 0) { break; } } if s == 89 as libc::c_int { return 1 as libc::c_int; } if s == 1 as libc::c_int { return 0 as libc::c_int; } x = s; }; }" }, { "index": 1135, "before": "int main() { int one = 1; /* * Best bet: size_t typically is exactly one word. */ printf(\"word size = %d bits\\n\", (int)(CHAR_BIT * sizeof(size_t))); /* * Check if the least significant bit is located * in the lowest-address byte. */ if (*(char *)&one) printf(\"little endian\\n\"); else printf(\"big endian\\n\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut one: libc::c_int = 1 as libc::c_int; printf( b\"word size = %d bits\\n\\0\" as *const u8 as *const libc::c_char, (8 as libc::c_int as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, ); if *(&mut one as *mut libc::c_int as *mut libc::c_char) != 0 { printf(b\"little endian\\n\\0\" as *const u8 as *const libc::c_char); } else { printf(b\"big endian\\n\\0\" as *const u8 as *const libc::c_char); } return 0 as libc::c_int; }" }, { "index": 1136, "before": "StatObject NewStatObject( Action action ) { StatObject so; so = malloc(sizeof(sStatObject)); so->sum = 0.0; so->sum2 = 0.0; so->num = 0; so->action = action; return so; }", "after": "pub unsafe extern \"C\" fn NewStatObject(mut action: Action) -> StatObject { let mut so: StatObject = 0 as *mut stat_obj_struct; so = malloc(::core::mem::size_of::() as libc::c_ulong) as StatObject; (*so).sum = 0.0f64; (*so).sum2 = 0.0f64; (*so).num = 0 as libc::c_int as size_t; (*so).action = action; return so; }" }, { "index": 1137, "before": "int main() { int i; StatObject so = NewStatObject( STDDEV ); for(i=0; i < sizeof(v)/sizeof(double) ; i++) printf(\"val: %lf std dev: %lf\\n\", v[i], stat_object_add(so, v[i])); FREE_STAT_OBJECT(so); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut so: StatObject = NewStatObject(STDDEV); i = 0 as libc::c_int; while (i as libc::c_ulong) < (::core::mem::size_of::<[libc::c_double; 8]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) { printf( b\"val: %lf std dev: %lf\\n\\0\" as *const u8 as *const libc::c_char, v[i as usize], stat_object_add(so, v[i as usize]), ); i += 1; i; } free(so as *mut libc::c_void); so = 0 as StatObject; return 0 as libc::c_int; }" }, { "index": 1138, "before": "double stat_object_add(StatObject so, double v) { so->num++; so->sum += v; so->sum2 += v*v; return stat_obj_value(so, so->action); }", "after": "pub unsafe extern \"C\" fn stat_object_add( mut so: StatObject, mut v_0: libc::c_double, ) -> libc::c_double { (*so).num = ((*so).num).wrapping_add(1); (*so).num; (*so).sum += v_0; (*so).sum2 += v_0 * v_0; return stat_obj_value(so, (*so).action); }" }, { "index": 1139, "before": "double stat_obj_value(StatObject so, Action action) { double num, mean, var, stddev; if (so->num == 0.0) return 0.0; num = so->num; if (action==COUNT) return num; mean = so->sum/num; if (action==MEAN) return mean; var = so->sum2/num - mean*mean; if (action==VAR) return var; stddev = sqrt(var); if (action==STDDEV) return stddev; return 0; }", "after": "pub unsafe extern \"C\" fn stat_obj_value( mut so: StatObject, mut action: Action, ) -> libc::c_double { let mut num: libc::c_double = 0.; let mut mean: libc::c_double = 0.; let mut var: libc::c_double = 0.; let mut stddev: libc::c_double = 0.; if (*so).num as libc::c_double == 0.0f64 { return 0.0f64; } num = (*so).num as libc::c_double; if action as libc::c_uint == COUNT as libc::c_int as libc::c_uint { return num; } mean = (*so).sum / num; if action as libc::c_uint == MEAN as libc::c_int as libc::c_uint { return mean; } var = (*so).sum2 / num - mean * mean; if action as libc::c_uint == VAR as libc::c_int as libc::c_uint { return var; } stddev = sqrt(var); if action as libc::c_uint == STDDEV as libc::c_int as libc::c_uint { return stddev; } return 0 as libc::c_int as libc::c_double; }" }, { "index": 1140, "before": "int count_letters(const char *s, unsigned char *c) { \tint i, len; \tmemset(c, 0, 26); \tfor (len = i = 0; s[i]; i++) { \t\tif (s[i] < 'a' || s[i] > 'z') \t\t\treturn 0; \t\tlen++, c[char_to_idx[(unsigned char)s[i]]]++; \t} \treturn len; }", "after": "pub unsafe extern \"C\" fn count_letters( mut s: *const libc::c_char, mut c: *mut libc::c_uchar, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut len: libc::c_int = 0; memset(c as *mut libc::c_void, 0 as libc::c_int, 26 as libc::c_int as libc::c_ulong); i = 0 as libc::c_int; len = i; while *s.offset(i as isize) != 0 { if (*s.offset(i as isize) as libc::c_int) < 'a' as i32 || *s.offset(i as isize) as libc::c_int > 'z' as i32 { return 0 as libc::c_int; } len += 1; len; let ref mut fresh0 = *c .offset( char_to_idx[*s.offset(i as isize) as libc::c_uchar as usize] as isize, ); *fresh0 = (*fresh0).wrapping_add(1); *fresh0; i += 1; i; } return len; }" }, { "index": 1141, "before": "int main(int c, char **v) { \tint i, j = 0; \tchar *words; \tstruct stat st; \tint fd = open(c < 2 ? \"unixdict.txt\" : v[1], O_RDONLY); \tif (fstat(fd, &st) < 0) return 1; \twords = malloc(st.st_size); \tread(fd, words, st.st_size); \tclose(fd); \tunion node root = {{0}}; \tunsigned char cnt[26]; \tint best_len = 0; \tconst char *b1, *b2; \tfor (i = 0; freq[i]; i++) \t\tchar_to_idx[(unsigned char)freq[i]] = i; \t/* count words, change newline to null */ \tfor (i = j = 0; i < st.st_size; i++) { \t\tif (words[i] != '\\n') continue; \t\twords[i] = '\\0'; \t\tif (i - j > best_len) { \t\t\tcount_letters(words + j, cnt); \t\t\tconst char *match = insert(&root, words + j, cnt); \t\t\tif (match) { \t\t\t\tbest_len = i - j; \t\t\t\tb1 = words + j; \t\t\t\tb2 = match; \t\t\t} \t\t} \t\tj = ++i; \t} \tif (best_len) printf(\"longest derangement: %s %s\\n\", b1, b2); \treturn 0; }", "after": "unsafe fn main(mut c: libc::c_int, mut v: *mut *mut libc::c_char) -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0 as libc::c_int; let mut words: *mut libc::c_char = 0 as *mut libc::c_char; let mut st: stat = stat { st_dev: 0, st_ino: 0, st_nlink: 0, st_mode: 0, st_uid: 0, st_gid: 0, __pad0: 0, st_rdev: 0, st_size: 0, st_blksize: 0, st_blocks: 0, st_atim: timespec { tv_sec: 0, tv_nsec: 0 }, st_mtim: timespec { tv_sec: 0, tv_nsec: 0 }, st_ctim: timespec { tv_sec: 0, tv_nsec: 0 }, __glibc_reserved: [0; 3], }; let mut fd: libc::c_int = open( if c < 2 as libc::c_int { b\"unixdict.txt\\0\" as *const u8 as *const libc::c_char } else { *v.offset(1 as libc::c_int as isize) as *const libc::c_char }, 0 as libc::c_int, ); if fstat(fd, &mut st) < 0 as libc::c_int { return 1 as libc::c_int; } words = malloc(st.st_size as libc::c_ulong) as *mut libc::c_char; read(fd, words as *mut libc::c_void, st.st_size as size_t); close(fd); let mut root: node = node { down: [ 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, 0 as *mut node, ], }; let mut cnt: [libc::c_uchar; 26] = [0; 26]; let mut best_len: libc::c_int = 0 as libc::c_int; let mut b1: *const libc::c_char = 0 as *const libc::c_char; let mut b2: *const libc::c_char = 0 as *const libc::c_char; i = 0 as libc::c_int; while *freq.offset(i as isize) != 0 { char_to_idx[*freq.offset(i as isize) as libc::c_uchar as usize] = i; i += 1; i; } j = 0 as libc::c_int; i = j; while (i as libc::c_long) < st.st_size { if !(*words.offset(i as isize) as libc::c_int != '\\n' as i32) { *words.offset(i as isize) = '\\0' as i32 as libc::c_char; if i - j > best_len { count_letters(words.offset(j as isize), cnt.as_mut_ptr()); let mut match_0: *const libc::c_char = insert( &mut root, words.offset(j as isize), cnt.as_mut_ptr(), ); if !match_0.is_null() { best_len = i - j; b1 = words.offset(j as isize); b2 = match_0; } } i += 1; j = i; } i += 1; i; } if best_len != 0 { printf( b\"longest derangement: %s %s\\n\\0\" as *const u8 as *const libc::c_char, b1, b2, ); } return 0 as libc::c_int; }" }, { "index": 1142, "before": "int deranged(const char *s1, const char *s2) { \tint i; \tfor (i = 0; s1[i]; i++) \t\tif (s1[i] == s2[i]) return 0; \treturn 1; }", "after": "pub unsafe extern \"C\" fn deranged( mut s1: *const libc::c_char, mut s2: *const libc::c_char, ) -> libc::c_int { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while *s1.offset(i as isize) != 0 { if *s1.offset(i as isize) as libc::c_int == *s2.offset(i as isize) as libc::c_int { return 0 as libc::c_int; } i += 1; i; } return 1 as libc::c_int; }" }, { "index": 1143, "before": "int item_cmp(const void *aa, const void *bb) { \tconst struct item *a = aa, *b = bb; \tdouble ua = a->v / a->w, ub = b->v / b->w; \treturn ua < ub ? -1 : ua > ub; }", "after": "pub unsafe extern \"C\" fn item_cmp( mut aa: *const libc::c_void, mut bb: *const libc::c_void, ) -> libc::c_int { let mut a: *const item = aa as *const item; let mut b: *const item = bb as *const item; let mut ua: libc::c_double = (*a).v / (*a).w; let mut ub: libc::c_double = (*b).v / (*b).w; return if ua < ub { -(1 as libc::c_int) } else { (ua > ub) as libc::c_int }; }" }, { "index": 1144, "before": "int main() { \tstruct item *it; \tdouble space = 15; \tqsort(items, 9, sizeof(struct item), item_cmp); \tfor (it = items + 9; it---items && space > 0; space -= it->w) \t\tif (space >= it->w) \t\t\tprintf(\"take all %s\\n\", it->name); \t\telse \t\t\tprintf(\"take %gkg of %g kg of %s\\n\", \t\t\t\tspace, it->w, it->name); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut it: *mut item = 0 as *mut item; let mut space: libc::c_double = 15 as libc::c_int as libc::c_double; qsort( items.as_mut_ptr() as *mut libc::c_void, 9 as libc::c_int as size_t, ::core::mem::size_of::() as libc::c_ulong, Some( item_cmp as unsafe extern \"C\" fn( *const libc::c_void, *const libc::c_void, ) -> libc::c_int, ), ); it = items.as_mut_ptr().offset(9 as libc::c_int as isize); loop { let fresh0 = it; it = it.offset(-1); if !(fresh0.offset_from(items.as_mut_ptr()) as libc::c_long != 0 && space > 0 as libc::c_int as libc::c_double) { break; } if space >= (*it).w { printf(b\"take all %s\\n\\0\" as *const u8 as *const libc::c_char, (*it).name); } else { printf( b\"take %gkg of %g kg of %s\\n\\0\" as *const u8 as *const libc::c_char, space, (*it).w, (*it).name, ); } space -= (*it).w; } return 0 as libc::c_int; }" }, { "index": 1145, "before": "int r2cf(int *numerator,int *denominator) { \tint quotient=0,temp; \tif(denominator != 0) \t{ \t\tquotient = *numerator / *denominator; \t\ttemp = *numerator; \t\t*numerator = *denominator; \t\t*denominator = temp % *denominator; \t} \treturn quotient; }", "after": "pub unsafe extern \"C\" fn r2cf( mut numerator: *mut libc::c_int, mut denominator: *mut libc::c_int, ) -> libc::c_int { let mut quotient: libc::c_int = 0 as libc::c_int; let mut temp: libc::c_int = 0; if !denominator.is_null() { quotient = *numerator / *denominator; temp = *numerator; *numerator = *denominator; *denominator = temp % *denominator; } return quotient; }" }, { "index": 1146, "before": "int main() { \tint i; \tprintf(\"Running the examples :\"); \tfor(i=0;i libc::c_int { let mut i: libc::c_int = 0; printf(b\"Running the examples :\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while (i as libc::c_ulong) < (::core::mem::size_of::<[fraction; 6]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) { printf( b\"\\nFor N = %d, D = %d :\\0\" as *const u8 as *const libc::c_char, examples[i as usize].num, examples[i as usize].den, ); while examples[i as usize].den != 0 as libc::c_int { printf( b\" %d \\0\" as *const u8 as *const libc::c_char, r2cf( &mut (*examples.as_mut_ptr().offset(i as isize)).num, &mut (*examples.as_mut_ptr().offset(i as isize)).den, ), ); } i += 1; i; } printf( b\"\\n\\nRunning for %c2 :\\0\" as *const u8 as *const libc::c_char, 251 as libc::c_int, ); i = 0 as libc::c_int; while (i as libc::c_ulong) < (::core::mem::size_of::<[fraction; 4]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) { printf( b\"\\nFor N = %d, D = %d :\\0\" as *const u8 as *const libc::c_char, sqrt2[i as usize].num, sqrt2[i as usize].den, ); while sqrt2[i as usize].den != 0 as libc::c_int { printf( b\" %d \\0\" as *const u8 as *const libc::c_char, r2cf( &mut (*sqrt2.as_mut_ptr().offset(i as isize)).num, &mut (*sqrt2.as_mut_ptr().offset(i as isize)).den, ), ); } i += 1; i; } printf( b\"\\n\\nRunning for %c :\\0\" as *const u8 as *const libc::c_char, 227 as libc::c_int, ); i = 0 as libc::c_int; while (i as libc::c_ulong) < (::core::mem::size_of::<[fraction; 8]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) { printf( b\"\\nFor N = %d, D = %d :\\0\" as *const u8 as *const libc::c_char, pi[i as usize].num, pi[i as usize].den, ); while pi[i as usize].den != 0 as libc::c_int { printf( b\" %d \\0\" as *const u8 as *const libc::c_char, r2cf( &mut (*pi.as_mut_ptr().offset(i as isize)).num, &mut (*pi.as_mut_ptr().offset(i as isize)).den, ), ); } i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1147, "before": "bool cidr_parse(const char* str, cidr_t* cidr) { int a, b, c, d, m; if (sscanf(str, \"%d.%d.%d.%d/%d\", &a, &b, &c, &d, &m) != 5) return false; if (m < 1 || m > 32 || a < 0 || a > UINT8_MAX || b < 0 || b > UINT8_MAX || c < 0 || c > UINT8_MAX || d < 0 || d > UINT8_MAX) return false; uint32_t mask = ~((1 << (32 - m)) - 1); uint32_t address = (a << 24) + (b << 16) + (c << 8) + d; address &= mask; cidr->address = address; cidr->mask_length = m; return true; }", "after": "pub unsafe extern \"C\" fn cidr_parse( mut str: *const libc::c_char, mut cidr: *mut cidr_t, ) -> bool { let mut a: libc::c_int = 0; let mut b: libc::c_int = 0; let mut c: libc::c_int = 0; let mut d: libc::c_int = 0; let mut m: libc::c_int = 0; if sscanf( str, b\"%d.%d.%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 c as *mut libc::c_int, &mut d as *mut libc::c_int, &mut m as *mut libc::c_int, ) != 5 as libc::c_int { return 0 as libc::c_int != 0; } if m < 1 as libc::c_int || m > 32 as libc::c_int || a < 0 as libc::c_int || a > 255 as libc::c_int || b < 0 as libc::c_int || b > 255 as libc::c_int || c < 0 as libc::c_int || c > 255 as libc::c_int || d < 0 as libc::c_int || d > 255 as libc::c_int { return 0 as libc::c_int != 0; } let mut mask: uint32_t = !(((1 as libc::c_int) << 32 as libc::c_int - m) - 1 as libc::c_int) as uint32_t; let mut address: uint32_t = ((a << 24 as libc::c_int) + (b << 16 as libc::c_int) + (c << 8 as libc::c_int) + d) as uint32_t; address &= mask; (*cidr).address = address; (*cidr).mask_length = m as libc::c_uint; return 1 as libc::c_int != 0; }" }, { "index": 1148, "before": "int main(int argc, char** argv) { const char* tests[] = { \"87.70.141.1/22\", \"36.18.154.103/12\", \"62.62.197.11/29\", \"67.137.119.181/4\", \"161.214.74.21/24\", \"184.232.176.184/18\" }; for (int i = 0; i < sizeof(tests)/sizeof(tests[0]); ++i) { cidr_t cidr; if (cidr_parse(tests[i], &cidr)) { char out[32]; cidr_format(&cidr, out, sizeof(out)); printf(\"%-18s -> %s\\n\", tests[i], out); } else { fprintf(stderr, \"%s: invalid CIDR\\n\", tests[i]); } } return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut tests: [*const libc::c_char; 6] = [ b\"87.70.141.1/22\\0\" as *const u8 as *const libc::c_char, b\"36.18.154.103/12\\0\" as *const u8 as *const libc::c_char, b\"62.62.197.11/29\\0\" as *const u8 as *const libc::c_char, b\"67.137.119.181/4\\0\" as *const u8 as *const libc::c_char, b\"161.214.74.21/24\\0\" as *const u8 as *const libc::c_char, b\"184.232.176.184/18\\0\" as *const u8 as *const libc::c_char, ]; let mut i: libc::c_int = 0 as libc::c_int; while (i as libc::c_ulong) < (::core::mem::size_of::<[*const libc::c_char; 6]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong) { let mut cidr: cidr_t = cidr_t { address: 0, mask_length: 0, }; if cidr_parse(tests[i as usize], &mut cidr) { let mut out: [libc::c_char; 32] = [0; 32]; cidr_format( &mut cidr, out.as_mut_ptr(), ::core::mem::size_of::<[libc::c_char; 32]>() as libc::c_ulong, ); printf( b\"%-18s -> %s\\n\\0\" as *const u8 as *const libc::c_char, tests[i as usize], out.as_mut_ptr(), ); } else { fprintf( stderr, b\"%s: invalid CIDR\\n\\0\" as *const u8 as *const libc::c_char, tests[i as usize], ); } i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1149, "before": "void cidr_format(const cidr_t* cidr, char* str, size_t size) { uint32_t address = cidr->address; unsigned int d = address & UINT8_MAX; address >>= 8; unsigned int c = address & UINT8_MAX; address >>= 8; unsigned int b = address & UINT8_MAX; address >>= 8; unsigned int a = address & UINT8_MAX; snprintf(str, size, \"%u.%u.%u.%u/%u\", a, b, c, d, cidr->mask_length); }", "after": "pub unsafe extern \"C\" fn cidr_format( mut cidr: *const cidr_t, mut str: *mut libc::c_char, mut size: size_t, ) { let mut address: uint32_t = (*cidr).address; let mut d: libc::c_uint = address & 255 as libc::c_int as libc::c_uint; address >>= 8 as libc::c_int; let mut c: libc::c_uint = address & 255 as libc::c_int as libc::c_uint; address >>= 8 as libc::c_int; let mut b: libc::c_uint = address & 255 as libc::c_int as libc::c_uint; address >>= 8 as libc::c_int; let mut a: libc::c_uint = address & 255 as libc::c_int as libc::c_uint; snprintf( str, size, b\"%u.%u.%u.%u/%u\\0\" as *const u8 as *const libc::c_char, a, b, c, d, (*cidr).mask_length, ); }" }, { "index": 1150, "before": "void search(size_t curr_len) { if (curr_len == longest_path_refs_len) { n_solutions++; } else if (curr_len > longest_path_refs_len) { n_solutions = 1; longest_path_refs_len = curr_len; memcpy(longest_path_refs, refs, curr_len * sizeof(Ref)); } // recursive search intptr_t last_char = refs[curr_len - 1].last_char; for (size_t i = curr_len; i < refs_len; i++) if (refs[i].first_char == last_char) { Ref aux = refs[curr_len]; refs[curr_len] = refs[i]; refs[i] = aux; search(curr_len + 1); refs[i] = refs[curr_len]; refs[curr_len] = aux; } }", "after": "pub unsafe extern \"C\" fn search(mut curr_len: size_t) { if curr_len == longest_path_refs_len { n_solutions = n_solutions.wrapping_add(1); n_solutions; } else if curr_len > longest_path_refs_len { n_solutions = 1 as libc::c_int as size_t; longest_path_refs_len = curr_len; memcpy( longest_path_refs as *mut libc::c_void, refs as *const libc::c_void, curr_len.wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ); } let mut last_char: intptr_t = (*refs .offset(curr_len.wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize)) .last_char as intptr_t; let mut i: size_t = curr_len; while i < refs_len { if (*refs.offset(i as isize)).first_char as libc::c_long == last_char { let mut aux: Ref = *refs.offset(curr_len as isize); *refs.offset(curr_len as isize) = *refs.offset(i as isize); *refs.offset(i as isize) = aux; search(curr_len.wrapping_add(1 as libc::c_int as libc::c_ulong)); *refs.offset(i as isize) = *refs.offset(curr_len as isize); *refs.offset(curr_len as isize) = aux; } i = i.wrapping_add(1); i; } }" }, { "index": 1151, "before": "void find_longest_chain(const char* items[], size_t items_len) { refs_len = items_len; refs = calloc(refs_len, sizeof(Ref)); // enough space for all items longest_path_refs_len = 0; longest_path_refs = calloc(refs_len, sizeof(Ref)); for (size_t i = 0; i < items_len; i++) { size_t itemsi_len = strlen(items[i]); if (itemsi_len <= 1) exit(1); refs[i].index = (uint16_t)i; refs[i].last_char = items[i][itemsi_len - 1]; refs[i].first_char = items[i][0]; } // try each item as possible start for (size_t i = 0; i < items_len; i++) { Ref aux = refs[0]; refs[0] = refs[i]; refs[i] = aux; search(1); refs[i] = refs[0]; refs[0] = aux; } longest_path_len = longest_path_refs_len; longest_path = calloc(longest_path_len, sizeof(const char*)); for (size_t i = 0; i < longest_path_len; i++) longest_path[i] = items[longest_path_refs[i].index]; free(longest_path_refs); free(refs); }", "after": "pub unsafe extern \"C\" fn find_longest_chain( mut items: *mut *const libc::c_char, mut items_len: size_t, ) { refs_len = items_len; refs = calloc(refs_len, ::core::mem::size_of::() as libc::c_ulong) as *mut Ref; longest_path_refs_len = 0 as libc::c_int as size_t; longest_path_refs = calloc(refs_len, ::core::mem::size_of::() as libc::c_ulong) as *mut Ref; let mut i: size_t = 0 as libc::c_int as size_t; while i < items_len { let mut itemsi_len: size_t = strlen(*items.offset(i as isize)); if itemsi_len <= 1 as libc::c_int as libc::c_ulong { exit(1 as libc::c_int); } (*refs.offset(i as isize)).index = i as uint16_t; (*refs.offset(i as isize)) .last_char = *(*items.offset(i as isize)) .offset(itemsi_len.wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize); (*refs.offset(i as isize)) .first_char = *(*items.offset(i as isize)).offset(0 as libc::c_int as isize); i = i.wrapping_add(1); i; } let mut i_0: size_t = 0 as libc::c_int as size_t; while i_0 < items_len { let mut aux: Ref = *refs.offset(0 as libc::c_int as isize); *refs.offset(0 as libc::c_int as isize) = *refs.offset(i_0 as isize); *refs.offset(i_0 as isize) = aux; search(1 as libc::c_int as size_t); *refs.offset(i_0 as isize) = *refs.offset(0 as libc::c_int as isize); *refs.offset(0 as libc::c_int as isize) = aux; i_0 = i_0.wrapping_add(1); i_0; } longest_path_len = longest_path_refs_len; longest_path = calloc( longest_path_len, ::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong, ) as *mut *const libc::c_char; let mut i_1: size_t = 0 as libc::c_int as size_t; while i_1 < longest_path_len { let ref mut fresh0 = *longest_path.offset(i_1 as isize); *fresh0 = *items .offset((*longest_path_refs.offset(i_1 as isize)).index as isize); i_1 = i_1.wrapping_add(1); i_1; } free(longest_path_refs as *mut libc::c_void); free(refs as *mut libc::c_void); }" }, { "index": 1152, "before": "int main() { const char* pokemon[] = {\"audino\", \"bagon\", \"baltoy\", \"banette\", \"bidoof\", \"braviary\", \"bronzor\", \"carracosta\", \"charmeleon\", \"cresselia\", \"croagunk\", \"darmanitan\", \"deino\", \"emboar\", \"emolga\", \"exeggcute\", \"gabite\", \"girafarig\", \"gulpin\", \"haxorus\", \"heatmor\", \"heatran\", \"ivysaur\", \"jellicent\", \"jumpluff\", \"kangaskhan\", \"kricketune\", \"landorus\", \"ledyba\", \"loudred\", \"lumineon\", \"lunatone\", \"machamp\", \"magnezone\", \"mamoswine\", \"nosepass\", \"petilil\", \"pidgeotto\", \"pikachu\", \"pinsir\", \"poliwrath\", \"poochyena\", \"porygon2\", \"porygonz\", \"registeel\", \"relicanth\", \"remoraid\", \"rufflet\", \"sableye\", \"scolipede\", \"scrafty\", \"seaking\", \"sealeo\", \"silcoon\", \"simisear\", \"snivy\", \"snorlax\", \"spoink\", \"starly\", \"tirtouga\", \"trapinch\", \"treecko\", \"tyrogue\", \"vigoroth\", \"vulpix\", \"wailord\", \"wartortle\", \"whismur\", \"wingull\", \"yamask\"}; size_t pokemon_len = sizeof(pokemon) / sizeof(pokemon[0]); find_longest_chain(pokemon, pokemon_len); printf(\"Maximum path length: %u\\n\", longest_path_len); printf(\"Paths of that length: %u\\n\", n_solutions); printf(\"Example path of that length:\\n\"); for (size_t i = 0; i < longest_path_len; i += 7) { printf(\" \"); for (size_t j = i; j < (i+7) && j < longest_path_len; j++) printf(\"%s \", longest_path[j]); printf(\"\\n\"); } free(longest_path); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut pokemon: [*const libc::c_char; 70] = [ b\"audino\\0\" as *const u8 as *const libc::c_char, b\"bagon\\0\" as *const u8 as *const libc::c_char, b\"baltoy\\0\" as *const u8 as *const libc::c_char, b\"banette\\0\" as *const u8 as *const libc::c_char, b\"bidoof\\0\" as *const u8 as *const libc::c_char, b\"braviary\\0\" as *const u8 as *const libc::c_char, b\"bronzor\\0\" as *const u8 as *const libc::c_char, b\"carracosta\\0\" as *const u8 as *const libc::c_char, b\"charmeleon\\0\" as *const u8 as *const libc::c_char, b\"cresselia\\0\" as *const u8 as *const libc::c_char, b\"croagunk\\0\" as *const u8 as *const libc::c_char, b\"darmanitan\\0\" as *const u8 as *const libc::c_char, b\"deino\\0\" as *const u8 as *const libc::c_char, b\"emboar\\0\" as *const u8 as *const libc::c_char, b\"emolga\\0\" as *const u8 as *const libc::c_char, b\"exeggcute\\0\" as *const u8 as *const libc::c_char, b\"gabite\\0\" as *const u8 as *const libc::c_char, b\"girafarig\\0\" as *const u8 as *const libc::c_char, b\"gulpin\\0\" as *const u8 as *const libc::c_char, b\"haxorus\\0\" as *const u8 as *const libc::c_char, b\"heatmor\\0\" as *const u8 as *const libc::c_char, b\"heatran\\0\" as *const u8 as *const libc::c_char, b\"ivysaur\\0\" as *const u8 as *const libc::c_char, b\"jellicent\\0\" as *const u8 as *const libc::c_char, b\"jumpluff\\0\" as *const u8 as *const libc::c_char, b\"kangaskhan\\0\" as *const u8 as *const libc::c_char, b\"kricketune\\0\" as *const u8 as *const libc::c_char, b\"landorus\\0\" as *const u8 as *const libc::c_char, b\"ledyba\\0\" as *const u8 as *const libc::c_char, b\"loudred\\0\" as *const u8 as *const libc::c_char, b\"lumineon\\0\" as *const u8 as *const libc::c_char, b\"lunatone\\0\" as *const u8 as *const libc::c_char, b\"machamp\\0\" as *const u8 as *const libc::c_char, b\"magnezone\\0\" as *const u8 as *const libc::c_char, b\"mamoswine\\0\" as *const u8 as *const libc::c_char, b\"nosepass\\0\" as *const u8 as *const libc::c_char, b\"petilil\\0\" as *const u8 as *const libc::c_char, b\"pidgeotto\\0\" as *const u8 as *const libc::c_char, b\"pikachu\\0\" as *const u8 as *const libc::c_char, b\"pinsir\\0\" as *const u8 as *const libc::c_char, b\"poliwrath\\0\" as *const u8 as *const libc::c_char, b\"poochyena\\0\" as *const u8 as *const libc::c_char, b\"porygon2\\0\" as *const u8 as *const libc::c_char, b\"porygonz\\0\" as *const u8 as *const libc::c_char, b\"registeel\\0\" as *const u8 as *const libc::c_char, b\"relicanth\\0\" as *const u8 as *const libc::c_char, b\"remoraid\\0\" as *const u8 as *const libc::c_char, b\"rufflet\\0\" as *const u8 as *const libc::c_char, b\"sableye\\0\" as *const u8 as *const libc::c_char, b\"scolipede\\0\" as *const u8 as *const libc::c_char, b\"scrafty\\0\" as *const u8 as *const libc::c_char, b\"seaking\\0\" as *const u8 as *const libc::c_char, b\"sealeo\\0\" as *const u8 as *const libc::c_char, b\"silcoon\\0\" as *const u8 as *const libc::c_char, b\"simisear\\0\" as *const u8 as *const libc::c_char, b\"snivy\\0\" as *const u8 as *const libc::c_char, b\"snorlax\\0\" as *const u8 as *const libc::c_char, b\"spoink\\0\" as *const u8 as *const libc::c_char, b\"starly\\0\" as *const u8 as *const libc::c_char, b\"tirtouga\\0\" as *const u8 as *const libc::c_char, b\"trapinch\\0\" as *const u8 as *const libc::c_char, b\"treecko\\0\" as *const u8 as *const libc::c_char, b\"tyrogue\\0\" as *const u8 as *const libc::c_char, b\"vigoroth\\0\" as *const u8 as *const libc::c_char, b\"vulpix\\0\" as *const u8 as *const libc::c_char, b\"wailord\\0\" as *const u8 as *const libc::c_char, b\"wartortle\\0\" as *const u8 as *const libc::c_char, b\"whismur\\0\" as *const u8 as *const libc::c_char, b\"wingull\\0\" as *const u8 as *const libc::c_char, b\"yamask\\0\" as *const u8 as *const libc::c_char, ]; let mut pokemon_len: size_t = (::core::mem::size_of::<[*const libc::c_char; 70]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong); find_longest_chain(pokemon.as_mut_ptr(), pokemon_len); printf( b\"Maximum path length: %u\\n\\0\" as *const u8 as *const libc::c_char, longest_path_len, ); printf( b\"Paths of that length: %u\\n\\0\" as *const u8 as *const libc::c_char, n_solutions, ); printf(b\"Example path of that length:\\n\\0\" as *const u8 as *const libc::c_char); let mut i: size_t = 0 as libc::c_int as size_t; while i < longest_path_len { printf(b\" \\0\" as *const u8 as *const libc::c_char); let mut j: size_t = i; while j < i.wrapping_add(7 as libc::c_int as libc::c_ulong) && j < longest_path_len { printf( b\"%s \\0\" as *const u8 as *const libc::c_char, *longest_path.offset(j as isize), ); j = j.wrapping_add(1); j; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i = (i as libc::c_ulong).wrapping_add(7 as libc::c_int as libc::c_ulong) as size_t as size_t; } free(longest_path as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1153, "before": "bool is_prime(int n) { int d = 5; if (n < 2) return FALSE; if (!(n % 2)) return n == 2; if (!(n % 3)) return n == 3; while (d *d <= n) { if (!(n % d)) return FALSE; d += 2; if (!(n % d)) return FALSE; d += 4; } return TRUE; }", "after": "pub unsafe extern \"C\" fn is_prime(mut n: libc::c_int) -> bool_0 { let mut d: libc::c_int = 5 as libc::c_int; if n < 2 as libc::c_int { return 0 as libc::c_int; } if n % 2 as libc::c_int == 0 { return (n == 2 as libc::c_int) as libc::c_int; } if n % 3 as libc::c_int == 0 { return (n == 3 as libc::c_int) as libc::c_int; } while d * d <= n { if n % d == 0 { return 0 as libc::c_int; } d += 2 as libc::c_int; if n % d == 0 { return 0 as libc::c_int; } d += 4 as libc::c_int; } return 1 as libc::c_int; }" }, { "index": 1154, "before": "int main() { int i, n, count = 0; printf(\"The attractive numbers up to and including %d are:\\n\", MAX); for (i = 1; i <= MAX; ++i) { n = count_prime_factors(i); if (is_prime(n)) { printf(\"%4d\", i); if (!(++count % 20)) printf(\"\\n\"); } } printf(\"\\n\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut n: libc::c_int = 0; let mut count: libc::c_int = 0 as libc::c_int; printf( b\"The attractive numbers up to and including %d are:\\n\\0\" as *const u8 as *const libc::c_char, 120 as libc::c_int, ); i = 1 as libc::c_int; while i <= 120 as libc::c_int { n = count_prime_factors(i); if is_prime(n) != 0 { printf(b\"%4d\\0\" as *const u8 as *const libc::c_char, i); count += 1; if count % 20 as libc::c_int == 0 { printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); } } i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1155, "before": "int count_prime_factors(int n) { int count = 0, f = 2; if (n == 1) return 0; if (is_prime(n)) return 1; while (TRUE) { if (!(n % f)) { count++; n /= f; if (n == 1) return count; if (is_prime(n)) f = n; } else if (f >= 3) f += 2; else f = 3; } }", "after": "pub unsafe extern \"C\" fn count_prime_factors(mut n: libc::c_int) -> libc::c_int { let mut count: libc::c_int = 0 as libc::c_int; let mut f: libc::c_int = 2 as libc::c_int; if n == 1 as libc::c_int { return 0 as libc::c_int; } if is_prime(n) != 0 { return 1 as libc::c_int; } loop { if n % f == 0 { count += 1; count; n /= f; if n == 1 as libc::c_int { return count; } if is_prime(n) != 0 { f = n; } } else if f >= 3 as libc::c_int { f += 2 as libc::c_int; } else { f = 3 as libc::c_int; } }; }" }, { "index": 1156, "before": "int main() { int i; tree_node(double) root_d = node_new(double, (double)rand() / RAND_MAX); for (i = 0; i < 10000; i++) node_insert(double, root_d, (double)rand() / RAND_MAX); tree_node(int) root_i = node_new(int, rand()); for (i = 0; i < 10000; i++) node_insert(int, root_i, rand()); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut root_d: node_double = node_double_new( rand() as libc::c_double / 2147483647 as libc::c_int as libc::c_double, ); i = 0 as libc::c_int; while i < 10000 as libc::c_int { node_double_insert( root_d, rand() as libc::c_double / 2147483647 as libc::c_int as libc::c_double, ); i += 1; i; } let mut root_i: node_int = node_int_new(rand()); i = 0 as libc::c_int; while i < 10000 as libc::c_int { node_int_insert(root_i, rand()); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1157, "before": "int main() { const char *s1 = \"rosettacode\"; const char *s2 = \"raisethysword\"; printf(\"distance between `%s' and `%s': %d\\n\", s1, s2, levenshtein(s1, strlen(s1), s2, strlen(s2))); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut s1: *const libc::c_char = b\"rosettacode\\0\" as *const u8 as *const libc::c_char; let mut s2: *const libc::c_char = b\"raisethysword\\0\" as *const u8 as *const libc::c_char; printf( b\"distance between `%s' and `%s': %d\\n\\0\" as *const u8 as *const libc::c_char, s1, s2, levenshtein(s1, strlen(s1) as libc::c_int, s2, strlen(s2) as libc::c_int), ); return 0 as libc::c_int; }" }, { "index": 1158, "before": "int levenshtein(const char *s, int ls, const char *t, int lt) { int a, b, c; /* if either string is empty, difference is inserting all chars * from the other */ if (!ls) return lt; if (!lt) return ls; /* if last letters are the same, the difference is whatever is * required to edit the rest of the strings */ if (s[ls - 1] == t[lt - 1]) return levenshtein(s, ls - 1, t, lt - 1); /* else try: * changing last letter of s to that of t; or * remove last letter of s; or * remove last letter of t, * any of which is 1 edit plus editing the rest of the strings */ a = levenshtein(s, ls - 1, t, lt - 1); b = levenshtein(s, ls, t, lt - 1); c = levenshtein(s, ls - 1, t, lt ); if (a > b) a = b; if (a > c) a = c; return a + 1; }", "after": "pub unsafe extern \"C\" fn levenshtein( mut s: *const libc::c_char, mut ls: libc::c_int, mut t: *const libc::c_char, mut lt: libc::c_int, ) -> libc::c_int { let mut a: libc::c_int = 0; let mut b: libc::c_int = 0; let mut c: libc::c_int = 0; if ls == 0 { return lt; } if lt == 0 { return ls; } if *s.offset((ls - 1 as libc::c_int) as isize) as libc::c_int == *t.offset((lt - 1 as libc::c_int) as isize) as libc::c_int { return levenshtein(s, ls - 1 as libc::c_int, t, lt - 1 as libc::c_int); } a = levenshtein(s, ls - 1 as libc::c_int, t, lt - 1 as libc::c_int); b = levenshtein(s, ls, t, lt - 1 as libc::c_int); c = levenshtein(s, ls - 1 as libc::c_int, t, lt); if a > b { a = b; } if a > c { a = c; } return a + 1 as libc::c_int; }" }, { "index": 1159, "before": "int main(int argc, char* argv[]) { int i, count=0; double f, sum=0.0, prod=1.0, resum=0.0; for (i=1; i libc::c_int { let mut i: libc::c_int = 0; let mut count: libc::c_int = 0 as libc::c_int; let mut f: libc::c_double = 0.; let mut sum: libc::c_double = 0.0f64; let mut prod: libc::c_double = 1.0f64; let mut resum: libc::c_double = 0.0f64; i = 1 as libc::c_int; while i < argc { f = atof(*argv.offset(i as isize)); count += 1; count; sum += f; prod *= f; resum += 1.0f64 / f; i += 1; i; } printf( b\"Arithmetic mean = %f\\n\\0\" as *const u8 as *const libc::c_char, sum / count as libc::c_double, ); printf( b\"Geometric mean = %f\\n\\0\" as *const u8 as *const libc::c_char, pow(prod, 1.0f64 / count as libc::c_double), ); printf( b\"Harmonic mean = %f\\n\\0\" as *const u8 as *const libc::c_char, count as libc::c_double / resum, ); return 0 as libc::c_int; }" }, { "index": 1160, "before": "int qselect(int *v, int len, int k) { #\tdefine SWAP(a, b) { tmp = v[a]; v[a] = v[b]; v[b] = tmp; } \tint i, st, tmp; \tfor (st = i = 0; i < len - 1; i++) { \t\tif (v[i] > v[len-1]) continue; \t\tSWAP(i, st); \t\tst++; \t} \tSWAP(len-1, st); \treturn k == st\t?v[st] \t\t\t:st > k\t? qselect(v, st, k) \t\t\t\t: qselect(v + st, len - st, k - st); }", "after": "pub unsafe extern \"C\" fn qselect( mut v: *mut libc::c_int, mut len: libc::c_int, mut k: libc::c_int, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut st: libc::c_int = 0; let mut tmp: libc::c_int = 0; i = 0 as libc::c_int; st = i; while i < len - 1 as libc::c_int { if !(*v.offset(i as isize) > *v.offset((len - 1 as libc::c_int) as isize)) { tmp = *v.offset(i as isize); *v.offset(i as isize) = *v.offset(st as isize); *v.offset(st as isize) = tmp; st += 1; st; } i += 1; i; } tmp = *v.offset((len - 1 as libc::c_int) as isize); *v.offset((len - 1 as libc::c_int) as isize) = *v.offset(st as isize); *v.offset(st as isize) = tmp; return if k == st { *v.offset(st as isize) } else if st > k { qselect(v, st, k) } else { qselect(v.offset(st as isize), len - st, k - st) }; }" }, { "index": 1161, "before": "int main(void) { #\tdefine N (sizeof(x)/sizeof(x[0])) \tint x[] = {9, 8, 7, 6, 5, 0, 1, 2, 3, 4}; \tint y[N]; \tint i; \tfor (i = 0; i < 10; i++) { \t\tmemcpy(y, x, sizeof(x)); // qselect modifies array \t\tprintf(\"%d: %d\\n\", i, qselect(y, 10, i)); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut x: [libc::c_int; 10] = [ 9 as libc::c_int, 8 as libc::c_int, 7 as libc::c_int, 6 as libc::c_int, 5 as libc::c_int, 0 as libc::c_int, 1 as libc::c_int, 2 as libc::c_int, 3 as libc::c_int, 4 as libc::c_int, ]; let mut y: [libc::c_int; 10] = [0; 10]; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 10 as libc::c_int { memcpy( y.as_mut_ptr() as *mut libc::c_void, x.as_mut_ptr() as *const libc::c_void, ::core::mem::size_of::<[libc::c_int; 10]>() as libc::c_ulong, ); printf( b\"%d: %d\\n\\0\" as *const u8 as *const libc::c_char, i, qselect(y.as_mut_ptr(), 10 as libc::c_int, i), ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1162, "before": "int main(void) { for (int i = 0; i < 3; i++) { printf(\"%c%c%i\\n\", a1[i], a2[i], a3[i]); } }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0 as libc::c_int; while i < 3 as libc::c_int { printf( b\"%c%c%i\\n\\0\" as *const u8 as *const libc::c_char, a1[i as usize] as libc::c_int, a2[i as usize] as libc::c_int, a3[i as usize], ); i += 1; i; } return 0; }" }, { "index": 1163, "before": "double f1a(double x) { return x*x*x*x/4.0; }", "after": "pub unsafe extern \"C\" fn f1a(mut x: libc::c_double) -> libc::c_double { return x * x * x * x / 4.0f64; }" }, { "index": 1164, "before": "double f1(double x) { return x*x*x; }", "after": "pub unsafe extern \"C\" fn f1(mut x: libc::c_double) -> libc::c_double { return x * x * x; }" }, { "index": 1165, "before": "double int_midrect(double from, double to, double n, double (*func)()) { double h = (to-from)/n; double sum = 0.0, x; for(x=from; x <= (to-h); x += h) sum += func(x+h/2.0); return h*sum; }", "after": "pub unsafe extern \"C\" fn int_midrect( mut from: libc::c_double, mut to: libc::c_double, mut n: libc::c_double, mut func: Option:: libc::c_double>, ) -> libc::c_double { let mut h: libc::c_double = (to - from) / n; let mut sum: libc::c_double = 0.0f64; let mut x: libc::c_double = 0.; x = from; while x <= to - h { sum += ::core::mem::transmute::< _, fn(_) -> libc::c_double, >(func.expect(\"non-null function pointer\"))(x + h / 2.0f64); x += h; } return h * sum; }" }, { "index": 1166, "before": "double int_leftrect(double from, double to, double n, double (*func)()) { double h = (to-from)/n; double sum = 0.0, x; for(x=from; x <= (to-h); x += h) sum += func(x); return h*sum; }", "after": "pub unsafe extern \"C\" fn int_leftrect( mut from: libc::c_double, mut to: libc::c_double, mut n: libc::c_double, mut func: Option:: libc::c_double>, ) -> libc::c_double { let mut h: libc::c_double = (to - from) / n; let mut sum: libc::c_double = 0.0f64; let mut x: libc::c_double = 0.; x = from; while x <= to - h { sum += ::core::mem::transmute::< _, fn(_) -> libc::c_double, >(func.expect(\"non-null function pointer\"))(x); x += h; } return h * sum; }" }, { "index": 1167, "before": "double int_simpson(double from, double to, double n, double (*func)()) { double h = (to - from) / n; double sum1 = 0.0; double sum2 = 0.0; int i; double x; for(i = 0;i < n;i++) sum1 += func(from + h * i + h / 2.0); for(i = 1;i < n;i++) sum2 += func(from + h * i); return h / 6.0 * (func(from) + func(to) + 4.0 * sum1 + 2.0 * sum2); }", "after": "pub unsafe extern \"C\" fn int_simpson( mut from: libc::c_double, mut to: libc::c_double, mut n: libc::c_double, mut func: Option:: libc::c_double>, ) -> libc::c_double { let mut h: libc::c_double = (to - from) / n; let mut sum1: libc::c_double = 0.0f64; let mut sum2: libc::c_double = 0.0f64; let mut i: libc::c_int = 0; let mut x: libc::c_double = 0.; i = 0 as libc::c_int; while (i as libc::c_double) < n { sum1 += ::core::mem::transmute::< _, fn(_) -> libc::c_double, >( func.expect(\"non-null function pointer\"), )(from + h * i as libc::c_double + h / 2.0f64); i += 1; i; } i = 1 as libc::c_int; while (i as libc::c_double) < n { sum2 += ::core::mem::transmute::< _, fn(_) -> libc::c_double, >(func.expect(\"non-null function pointer\"))(from + h * i as libc::c_double); i += 1; i; } return h / 6.0f64 * (::core::mem::transmute::< _, fn(_) -> libc::c_double, >(func.expect(\"non-null function pointer\"))(from) + ::core::mem::transmute::< _, fn(_) -> libc::c_double, >(func.expect(\"non-null function pointer\"))(to) + 4.0f64 * sum1 + 2.0f64 * sum2); }" }, { "index": 1168, "before": "double int_rightrect(double from, double to, double n, double (*func)()) { double h = (to-from)/n; double sum = 0.0, x; for(x=from; x <= (to-h); x += h) sum += func(x+h); return h*sum; }", "after": "pub unsafe extern \"C\" fn int_rightrect( mut from: libc::c_double, mut to: libc::c_double, mut n: libc::c_double, mut func: Option:: libc::c_double>, ) -> libc::c_double { let mut h: libc::c_double = (to - from) / n; let mut sum: libc::c_double = 0.0f64; let mut x: libc::c_double = 0.; x = from; while x <= to - h { sum += ::core::mem::transmute::< _, fn(_) -> libc::c_double, >(func.expect(\"non-null function pointer\"))(x + h); x += h; } return h * sum; }" }, { "index": 1169, "before": "double f2(double x) { return 1.0/x; }", "after": "pub unsafe extern \"C\" fn f2(mut x: libc::c_double) -> libc::c_double { return 1.0f64 / x; }" }, { "index": 1170, "before": "double f3(double x) { return x; }", "after": "pub unsafe extern \"C\" fn f3(mut x: libc::c_double) -> libc::c_double { return x; }" }, { "index": 1171, "before": "double int_trapezium(double from, double to, double n, double (*func)()) { double h = (to - from) / n; double sum = func(from) + func(to); int i; for(i = 1;i < n;i++) sum += 2.0*func(from + i * h); return h * sum / 2.0; }", "after": "pub unsafe extern \"C\" fn int_trapezium( mut from: libc::c_double, mut to: libc::c_double, mut n: libc::c_double, mut func: Option:: libc::c_double>, ) -> libc::c_double { let mut h: libc::c_double = (to - from) / n; let mut sum: libc::c_double = ::core::mem::transmute::< _, fn(_) -> libc::c_double, >(func.expect(\"non-null function pointer\"))(from) + ::core::mem::transmute::< _, fn(_) -> libc::c_double, >(func.expect(\"non-null function pointer\"))(to); let mut i: libc::c_int = 0; i = 1 as libc::c_int; while (i as libc::c_double) < n { sum += 2.0f64 * ::core::mem::transmute::< _, fn(_) -> libc::c_double, >( func.expect(\"non-null function pointer\"), )(from + i as libc::c_double * h); i += 1; i; } return h * sum / 2.0f64; }" }, { "index": 1172, "before": "double f3a(double x) { return x*x/2.0; }", "after": "pub unsafe extern \"C\" fn f3a(mut x: libc::c_double) -> libc::c_double { return x * x / 2.0f64; }" }, { "index": 1173, "before": "double f2a(double x) { return log(x); }", "after": "pub unsafe extern \"C\" fn f2a(mut x: libc::c_double) -> libc::c_double { return log(x); }" }, { "index": 1174, "before": "int main() { int i, j; double ic; pfunc f[5] = { int_leftrect, int_rightrect, int_midrect, int_trapezium, int_simpson }; const char *names[5] = { \"leftrect\", \"rightrect\", \"midrect\", \"trapezium\", \"simpson\" }; rfunc rf[] = { f1, f2, f3, f3 }; rfunc If[] = { f1a, f2a, f3a, f3a }; double ivals[] = { 0.0, 1.0, 1.0, 100.0, 0.0, 5000.0, 0.0, 6000.0 }; double approx[] = { 100.0, 1000.0, 5000000.0, 6000000.0 }; for(j=0; j < (sizeof(rf) / sizeof(rfunc)); j++) { for(i=0; i < 5 ; i++) { ic = (*f[i])(ivals[2*j], ivals[2*j+1], approx[j], rf[j]); printf(\"%10s [ 0,1] num: %+lf, an: %lf\\n\", names[i], ic, INTG((*If[j]), ivals[2*j], ivals[2*j+1])); } printf(\"\\n\"); } }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut ic: libc::c_double = 0.; let mut f: [pfunc; 5] = [ Some( int_leftrect as unsafe extern \"C\" fn( libc::c_double, libc::c_double, libc::c_double, Option:: libc::c_double>, ) -> libc::c_double, ), Some( int_rightrect as unsafe extern \"C\" fn( libc::c_double, libc::c_double, libc::c_double, Option:: libc::c_double>, ) -> libc::c_double, ), Some( int_midrect as unsafe extern \"C\" fn( libc::c_double, libc::c_double, libc::c_double, Option:: libc::c_double>, ) -> libc::c_double, ), Some( int_trapezium as unsafe extern \"C\" fn( libc::c_double, libc::c_double, libc::c_double, Option:: libc::c_double>, ) -> libc::c_double, ), Some( int_simpson as unsafe extern \"C\" fn( libc::c_double, libc::c_double, libc::c_double, Option:: libc::c_double>, ) -> libc::c_double, ), ]; let mut names: [*const libc::c_char; 5] = [ b\"leftrect\\0\" as *const u8 as *const libc::c_char, b\"rightrect\\0\" as *const u8 as *const libc::c_char, b\"midrect\\0\" as *const u8 as *const libc::c_char, b\"trapezium\\0\" as *const u8 as *const libc::c_char, b\"simpson\\0\" as *const u8 as *const libc::c_char, ]; let mut rf: [rfunc; 4] = [ Some(f1 as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), Some(f2 as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), Some(f3 as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), Some(f3 as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), ]; let mut If: [rfunc; 4] = [ Some(f1a as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), Some(f2a as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), Some(f3a as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), Some(f3a as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), ]; let mut ivals: [libc::c_double; 8] = [ 0.0f64, 1.0f64, 1.0f64, 100.0f64, 0.0f64, 5000.0f64, 0.0f64, 6000.0f64, ]; let mut approx: [libc::c_double; 4] = [ 100.0f64, 1000.0f64, 5000000.0f64, 6000000.0f64, ]; j = 0 as libc::c_int; while (j as libc::c_ulong) < (::core::mem::size_of::<[rfunc; 4]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) { i = 0 as libc::c_int; while i < 5 as libc::c_int { ic = (Some( (*f.as_mut_ptr().offset(i as isize)).expect(\"non-null function pointer\"), )) .expect( \"non-null function pointer\", )( ivals[(2 as libc::c_int * j) as usize], ivals[(2 as libc::c_int * j + 1 as libc::c_int) as usize], approx[j as usize], ::core::mem::transmute::< rfunc, Option:: libc::c_double>, >(rf[j as usize]), ); printf( b\"%10s [ 0,1] num: %+lf, an: %lf\\n\\0\" as *const u8 as *const libc::c_char, names[i as usize], ic, (Some( (*If.as_mut_ptr().offset(j as isize)) .expect(\"non-null function pointer\"), )) .expect( \"non-null function pointer\", )(ivals[(2 as libc::c_int * j + 1 as libc::c_int) as usize]) - (Some( (*If.as_mut_ptr().offset(j as isize)) .expect(\"non-null function pointer\"), )) .expect( \"non-null function pointer\", )(ivals[(2 as libc::c_int * j) as usize]), ); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); j += 1; j; } return 0; }" }, { "index": 1175, "before": "int main() { \tdouble a, c, s, PI2 = atan2(1, 1) * 8; \tint n, i; \tfor (n = 1; n < 10; n++) for (i = 0; i < n; i++) { \t\tc = s = 0; \t\tif (!i )\t\tc = 1; \t\telse if(n == 4 * i)\ts = 1; \t\telse if(n == 2 * i)\tc = -1; \t\telse if(3 * n == 4 * i)\ts = -1; \t\telse \t\t\ta = i * PI2 / n, c = cos(a), s = sin(a); \t\tif (c) printf(\"%.2g\", c); \t\tprintf(s == 1 ? \"i\" : s == -1 ? \"-i\" : s ? \"%+.2gi\" : \"\", s); \t\tprintf(i == n - 1 ?\"\\n\":\", \"); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut a: libc::c_double = 0.; let mut c: libc::c_double = 0.; let mut s: libc::c_double = 0.; let mut PI2: libc::c_double = atan2( 1 as libc::c_int as libc::c_double, 1 as libc::c_int as libc::c_double, ) * 8 as libc::c_int as libc::c_double; let mut n: libc::c_int = 0; let mut i: libc::c_int = 0; n = 1 as libc::c_int; while n < 10 as libc::c_int { i = 0 as libc::c_int; while i < n { s = 0 as libc::c_int as libc::c_double; c = s; if i == 0 { c = 1 as libc::c_int as libc::c_double; } else if n == 4 as libc::c_int * i { s = 1 as libc::c_int as libc::c_double; } else if n == 2 as libc::c_int * i { c = -(1 as libc::c_int) as libc::c_double; } else if 3 as libc::c_int * n == 4 as libc::c_int * i { s = -(1 as libc::c_int) as libc::c_double; } else { a = i as libc::c_double * PI2 / n as libc::c_double; c = cos(a); s = sin(a); } if c != 0. { printf(b\"%.2g\\0\" as *const u8 as *const libc::c_char, c); } printf( if s == 1 as libc::c_int as libc::c_double { b\"i\\0\" as *const u8 as *const libc::c_char } else if s == -(1 as libc::c_int) as libc::c_double { b\"-i\\0\" as *const u8 as *const libc::c_char } else if s != 0. { b\"%+.2gi\\0\" as *const u8 as *const libc::c_char } else { b\"\\0\" as *const u8 as *const libc::c_char }, s, ); printf( if i == n - 1 as libc::c_int { b\"\\n\\0\" as *const u8 as *const libc::c_char } else { b\", \\0\" as *const u8 as *const libc::c_char }, ); i += 1; i; } n += 1; n; } return 0 as libc::c_int; }" }, { "index": 1176, "before": "int main() { \tconst char *s; \tprintf(\"\\n\\n\\n
\"); \tfor (s = input; *s; s++) { \t\tswitch(*s) { \t\tcase '\\n': printf(\"
\"); break; \t\tcase ',': printf(\"\"); break; \t\tcase '<': printf(\"<\"); break; \t\tcase '>': printf(\">\"); break; \t\tcase '&': printf(\"&\"); break; \t\tdefault: putchar(*s); \t\t} \t} \tputs(\"
\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut s: *const libc::c_char = 0 as *const libc::c_char; printf(b\"\\n\\n\\n
\\0\" as *const u8 as *const libc::c_char); s = input; while *s != 0 { match *s as libc::c_int { 10 => { printf(b\"
\\0\" as *const u8 as *const libc::c_char); } 44 => { printf(b\"\\0\" as *const u8 as *const libc::c_char); } 60 => { printf(b\"<\\0\" as *const u8 as *const libc::c_char); } 62 => { printf(b\">\\0\" as *const u8 as *const libc::c_char); } 38 => { printf(b\"&\\0\" as *const u8 as *const libc::c_char); } _ => { putchar(*s as libc::c_int); } } s = s.offset(1); s; } puts(b\"
\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1177, "before": "ulong root(ulong base, ulong n) { ulong n1, n2, n3, c, d, e; if (base < 2) return base; if (n == 0) return 1; n1 = n - 1; n2 = n; n3 = n1; c = 1; d = (n3 + base) / n2; e = (n3 * d + base / (ulong)powl(d, n1)) / n2; while (c != d && c != e) { c = d; d = e; e = (n3*e + base / (ulong)powl(e, n1)) / n2; } if (d < e) return d; return e; }", "after": "pub unsafe extern \"C\" fn root(mut base: ulong, mut n: ulong) -> ulong { let mut n1: ulong = 0; let mut n2: ulong = 0; let mut n3: ulong = 0; let mut c: ulong = 0; let mut d: ulong = 0; let mut e: ulong = 0; if base < 2 as libc::c_int as libc::c_ulonglong { return base; } if n == 0 as libc::c_int as libc::c_ulonglong { return 1 as libc::c_int as ulong; } n1 = n.wrapping_sub(1 as libc::c_int as libc::c_ulonglong); n2 = n; n3 = n1; c = 1 as libc::c_int as ulong; d = n3.wrapping_add(base).wrapping_div(n2); e = n3 .wrapping_mul(d) .wrapping_add( base .wrapping_div( (powl(f128::f128::new(d), f128::f128::new(n1))).to_u64().unwrap(), ), ) .wrapping_div(n2); while c != d && c != e { c = d; d = e; e = n3 .wrapping_mul(e) .wrapping_add( base .wrapping_div( (powl(f128::f128::new(e), f128::f128::new(n1))).to_u64().unwrap(), ), ) .wrapping_div(n2); } if d < e { return d; } return e; }" }, { "index": 1178, "before": "int main() { ulong b = (ulong)2e18; printf(\"3rd root of 8 = %lld\\n\", root(8, 3)); printf(\"3rd root of 9 = %lld\\n\", root(9, 3)); printf(\"2nd root of %lld = %lld\\n\", b, root(b, 2)); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut b: ulong = 2e18f64 as ulong; printf( b\"3rd root of 8 = %lld\\n\\0\" as *const u8 as *const libc::c_char, root(8 as libc::c_int as ulong, 3 as libc::c_int as ulong), ); printf( b\"3rd root of 9 = %lld\\n\\0\" as *const u8 as *const libc::c_char, root(9 as libc::c_int as ulong, 3 as libc::c_int as ulong), ); printf( b\"2nd root of %lld = %lld\\n\\0\" as *const u8 as *const libc::c_char, b, root(b, 2 as libc::c_int as ulong), ); return 0 as libc::c_int; }" }, { "index": 1179, "before": "int main() { \tint current = 0, \t//the current number \t square;\t\t//the square of the current number \t//the strategy of take the rest of division by 1e06 is \t//to take the a number how 6 last digits are 269696 \twhile (((square=current*current) % 1000000 != 269696) && (square+INT_MAX) \t printf(\"Condition not satisfied before INT_MAX reached.\"); \telse\t\t \t printf (\"The smallest number whose square ends in 269696 is %d\\n\", current); //the end \treturn 0 ; }", "after": "unsafe fn main() -> libc::c_int { let mut current: libc::c_int = 0 as libc::c_int; let mut square: libc::c_int = 0; loop { square = current * current; if !(square % 1000000 as libc::c_int != 269696 as libc::c_int && square < 2147483647 as libc::c_int) { break; } current += 1; current; } if square > 2147483647 as libc::c_int { printf( b\"Condition not satisfied before INT_MAX reached.\\0\" as *const u8 as *const libc::c_char, ); } else { printf( b\"The smallest number whose square ends in 269696 is %d\\n\\0\" as *const u8 as *const libc::c_char, current, ); } return 0 as libc::c_int; }" }, { "index": 1180, "before": "int trim(char **str) { \tint trimmed; \tint n; \tint len; \tlen = strlen(*str); \tn = len - 1; \t/* from right */ \twhile ((n >= 0) && isspace((*str)[n])) \t{ \t\t(*str)[n] = '\\0'; \t\ttrimmed += 1; \t\tn--; \t} \t/* from left */ \tn = 0; \twhile ((n < len) && (isspace((*str)[0]))) \t{ \t\t(*str)[0] = '\\0'; \t\t*str = (*str) + 1; \t\ttrimmed += 1; \t\tn++; \t} \treturn trimmed; }", "after": "pub unsafe extern \"C\" fn trim(mut str: *mut *mut libc::c_char) -> libc::c_int { let mut trimmed: libc::c_int = 0; let mut n: libc::c_int = 0; let mut len: libc::c_int = 0; len = strlen(*str) as libc::c_int; n = len - 1 as libc::c_int; while n >= 0 as libc::c_int && *(*__ctype_b_loc()).offset(*(*str).offset(n as isize) as libc::c_int as isize) as libc::c_int & _ISspace as libc::c_int as libc::c_ushort as libc::c_int != 0 { *(*str).offset(n as isize) = '\\0' as i32 as libc::c_char; trimmed += 1 as libc::c_int; n -= 1; n; } n = 0 as libc::c_int; while n < len && *(*__ctype_b_loc()) .offset(*(*str).offset(0 as libc::c_int as isize) as libc::c_int as isize) as libc::c_int & _ISspace as libc::c_int as libc::c_ushort as libc::c_int != 0 { *(*str).offset(0 as libc::c_int as isize) = '\\0' as i32 as libc::c_char; *str = (*str).offset(1 as libc::c_int as isize); trimmed += 1 as libc::c_int; n += 1; n; } return trimmed; }" }, { "index": 1181, "before": "int main(int argc, char **argv) { \tCSV *csv; \tprintf(\"%s\\n%s\\n\\n\", TITLE, URL); \tcsv = csv_create(0, 0); \tcsv_open(csv, \"input.csv\"); \tcsv_display(csv); \tcsv_set(csv, 0, 0, \"Column0\"); \tcsv_set(csv, 1, 1, \"100\"); \tcsv_set(csv, 2, 2, \"200\"); \tcsv_set(csv, 3, 3, \"300\"); \tcsv_set(csv, 4, 4, \"400\"); \tcsv_display(csv); \tcsv_save(csv, \"output.csv\"); \tcsv_destroy(csv); \treturn 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut csv: *mut CSV = 0 as *mut CSV; printf( b\"%s\\n%s\\n\\n\\0\" as *const u8 as *const libc::c_char, b\"CSV data manipulation\\0\" as *const u8 as *const libc::c_char, b\"http://rosettacode.org/wiki/CSV_data_manipulation\\0\" as *const u8 as *const libc::c_char, ); csv = csv_create(0 as libc::c_int as libc::c_uint, 0 as libc::c_int as libc::c_uint); csv_open( csv, b\"input.csv\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); csv_display(csv); csv_set( csv, 0 as libc::c_int as libc::c_uint, 0 as libc::c_int as libc::c_uint, b\"Column0\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); csv_set( csv, 1 as libc::c_int as libc::c_uint, 1 as libc::c_int as libc::c_uint, b\"100\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); csv_set( csv, 2 as libc::c_int as libc::c_uint, 2 as libc::c_int as libc::c_uint, b\"200\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); csv_set( csv, 3 as libc::c_int as libc::c_uint, 3 as libc::c_int as libc::c_uint, b\"300\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); csv_set( csv, 4 as libc::c_int as libc::c_uint, 4 as libc::c_int as libc::c_uint, b\"400\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); csv_display(csv); csv_save( csv, b\"output.csv\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); csv_destroy(csv); return 0 as libc::c_int; }" }, { "index": 1182, "before": "int csv_open(CSV *csv, char *filename) { \tFILE *fp; \tunsigned int m_rows; \tunsigned int m_cols, cols; \tchar line[2048]; \tchar *lineptr; \tchar *token; \tfp = fopen(filename, \"r\"); \tif (fp == NULL) \t{ \t\tgoto error; \t} \tm_rows = 0; \tm_cols = 0; \twhile (fgets(line, sizeof(line), fp) != NULL) \t{ \t\tm_rows += 1; \t\tcols = 0; \t\tlineptr = line; \t\twhile ((token = strtok(lineptr, csv->delim)) != NULL) \t\t{ \t\t\tlineptr = NULL; \t\t\ttrim(&token); \t\t\tcols += 1; \t\t\tif (cols > m_cols) \t\t\t{ \t\t\t\tm_cols = cols; \t\t\t} \t\t\tcsv_resize(csv, m_cols, m_rows); \t\t\tcsv_set(csv, cols - 1, m_rows - 1, strdup(token)); \t\t} \t} \tfclose(fp); \tcsv->rows = m_rows; \tcsv->cols = m_cols; \treturn 0; error: \tfclose(fp); \tprintf(\"Unable to open %s for reading.\", filename); \treturn -1; }", "after": "pub unsafe extern \"C\" fn csv_open( mut csv: *mut CSV, mut filename: *mut libc::c_char, ) -> libc::c_int { let mut fp: *mut FILE = 0 as *mut FILE; let mut m_rows: libc::c_uint = 0; let mut m_cols: libc::c_uint = 0; let mut cols: libc::c_uint = 0; let mut line: [libc::c_char; 2048] = [0; 2048]; let mut lineptr: *mut libc::c_char = 0 as *mut libc::c_char; let mut token: *mut libc::c_char = 0 as *mut libc::c_char; fp = fopen(filename, b\"r\\0\" as *const u8 as *const libc::c_char); if fp.is_null() { fclose(fp); printf( b\"Unable to open %s for reading.\\0\" as *const u8 as *const libc::c_char, filename, ); return -(1 as libc::c_int); } else { m_rows = 0 as libc::c_int as libc::c_uint; m_cols = 0 as libc::c_int as libc::c_uint; while !(fgets( line.as_mut_ptr(), ::core::mem::size_of::<[libc::c_char; 2048]>() as libc::c_ulong as libc::c_int, fp, )) .is_null() { m_rows = m_rows.wrapping_add(1 as libc::c_int as libc::c_uint); cols = 0 as libc::c_int as libc::c_uint; lineptr = line.as_mut_ptr(); loop { token = strtok(lineptr, (*csv).delim); if token.is_null() { break; } lineptr = 0 as *mut libc::c_char; trim(&mut token); cols = cols.wrapping_add(1 as libc::c_int as libc::c_uint); if cols > m_cols { m_cols = cols; } csv_resize(csv, m_cols, m_rows); csv_set( csv, cols.wrapping_sub(1 as libc::c_int as libc::c_uint), m_rows.wrapping_sub(1 as libc::c_int as libc::c_uint), strdup(token), ); } } fclose(fp); (*csv).rows = m_rows; (*csv).cols = m_cols; return 0 as libc::c_int; }; }" }, { "index": 1183, "before": "int csv_destroy(CSV *csv) { \tif (csv == NULL) \t{ \t\treturn 0; \t} \tif (csv->table != NULL) \t{ \t\tfree(csv->table); \t} \tif (csv->delim != NULL) \t{ \t\tfree(csv->delim); \t} \tfree(csv); \treturn 0; }", "after": "pub unsafe extern \"C\" fn csv_destroy(mut csv: *mut CSV) -> libc::c_int { if csv.is_null() { return 0 as libc::c_int; } if !((*csv).table).is_null() { free((*csv).table as *mut libc::c_void); } if !((*csv).delim).is_null() { free((*csv).delim as *mut libc::c_void); } free(csv as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1184, "before": "int csv_set(CSV *csv, unsigned int col, unsigned int row, char *value) { \tunsigned int idx; \tidx = col + (row * csv->cols); \tcsv->table[idx] = value; \treturn 0; }", "after": "pub unsafe extern \"C\" fn csv_set( mut csv: *mut CSV, mut col: libc::c_uint, mut row: libc::c_uint, mut value: *mut libc::c_char, ) -> libc::c_int { let mut idx: libc::c_uint = 0; idx = col.wrapping_add(row.wrapping_mul((*csv).cols)); let ref mut fresh0 = *((*csv).table).offset(idx as isize); *fresh0 = value; return 0 as libc::c_int; }" }, { "index": 1185, "before": "int csv_resize(CSV *old_csv, unsigned int new_cols, unsigned int new_rows) { \tunsigned int cur_col, \t\tcur_row, \t\tmax_cols, \t\tmax_rows; \tCSV *new_csv; \tchar *content; \tbool in_old, in_new; \t/* Build a new (fake) csv */ \tnew_csv = csv_create(new_cols, new_rows); \tif (new_csv == NULL) \t{ \t\tgoto error; \t} \tnew_csv->rows = new_rows; \tnew_csv->cols = new_cols; \tmax_cols = (new_cols > old_csv->cols) ? new_cols : old_csv->cols; \tmax_rows = (new_rows > old_csv->rows) ? new_rows : old_csv->rows; \tfor (cur_col = 0; cur_col < max_cols; cur_col++) \t{ \t\tfor (cur_row = 0; cur_row < max_rows; cur_row++) \t\t{ \t\t\tin_old = (cur_col < old_csv->cols) && (cur_row < old_csv->rows); \t\t\tin_new = (cur_col < new_csv->cols) && (cur_row < new_csv->rows); \t\t\tif (in_old && in_new) \t\t\t{ \t\t\t\t/* re-link data */ \t\t\t\tcontent = csv_get(old_csv, cur_col, cur_row); \t\t\t\tcsv_set(new_csv, cur_col, cur_row, content); \t\t\t} \t\t\telse if (in_old) \t\t\t{ \t\t\t\t/* destroy data */ \t\t\t\tcontent = csv_get(old_csv, cur_col, cur_row); \t\t\t\tfree(content); \t\t\t} \t\t\telse \t\t\t{ /* skip */ \t\t\t} \t\t} \t} \t/* on rows */ \tfree(old_csv->table); \told_csv->rows = new_rows; \told_csv->cols = new_cols; \told_csv->table = new_csv->table; \tnew_csv->table = NULL; \tcsv_destroy(new_csv); \treturn 0; error: \tprintf(\"Unable to resize CSV table: error %d - %s\\n\", errno, strerror(errno)); \treturn -1; }", "after": "pub unsafe extern \"C\" fn csv_resize( mut old_csv: *mut CSV, mut new_cols: libc::c_uint, mut new_rows: libc::c_uint, ) -> libc::c_int { let mut cur_col: libc::c_uint = 0; let mut cur_row: libc::c_uint = 0; let mut max_cols: libc::c_uint = 0; let mut max_rows: libc::c_uint = 0; let mut new_csv: *mut CSV = 0 as *mut CSV; let mut content: *mut libc::c_char = 0 as *mut libc::c_char; let mut in_old: libc::c_int = 0; let mut in_new: libc::c_int = 0; new_csv = csv_create(new_cols, new_rows); if new_csv.is_null() { printf( b\"Unable to resize CSV table: error %d - %s\\n\\0\" as *const u8 as *const libc::c_char, *__errno_location(), strerror(*__errno_location()), ); return -(1 as libc::c_int); } else { (*new_csv).rows = new_rows; (*new_csv).cols = new_cols; max_cols = if new_cols > (*old_csv).cols { new_cols } else { (*old_csv).cols }; max_rows = if new_rows > (*old_csv).rows { new_rows } else { (*old_csv).rows }; cur_col = 0 as libc::c_int as libc::c_uint; while cur_col < max_cols { cur_row = 0 as libc::c_int as libc::c_uint; while cur_row < max_rows { in_old = (cur_col < (*old_csv).cols && cur_row < (*old_csv).rows) as libc::c_int; in_new = (cur_col < (*new_csv).cols && cur_row < (*new_csv).rows) as libc::c_int; if in_old != 0 && in_new != 0 { content = csv_get(old_csv, cur_col, cur_row); csv_set(new_csv, cur_col, cur_row, content); } else if in_old != 0 { content = csv_get(old_csv, cur_col, cur_row); free(content as *mut libc::c_void); } cur_row = cur_row.wrapping_add(1); cur_row; } cur_col = cur_col.wrapping_add(1); cur_col; } free((*old_csv).table as *mut libc::c_void); (*old_csv).rows = new_rows; (*old_csv).cols = new_cols; (*old_csv).table = (*new_csv).table; (*new_csv).table = 0 as *mut *mut libc::c_char; csv_destroy(new_csv); return 0 as libc::c_int; }; }" }, { "index": 1186, "before": "void csv_display(CSV *csv) { \tint row, col; \tchar *content; \tif ((csv->rows == 0) || (csv->cols == 0)) \t{ \t\tprintf(\"[Empty table]\\n\"); \t\treturn; \t} \tprintf(\"\\n[Table cols=%d rows=%d]\\n\", csv->cols, csv->rows); \tfor (row = 0; row < csv->rows; row++) \t{ \t\tprintf(\"[|\"); \t\tfor (col = 0; col < csv->cols; col++) \t\t{ \t\t\tcontent = csv_get(csv, col, row); \t\t\tprintf(\"%s\\t|\", content); \t\t} \t\tprintf(\"]\\n\"); \t} \tprintf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn csv_display(mut csv: *mut CSV) { let mut row: libc::c_int = 0; let mut col: libc::c_int = 0; let mut content: *mut libc::c_char = 0 as *mut libc::c_char; if (*csv).rows == 0 as libc::c_int as libc::c_uint || (*csv).cols == 0 as libc::c_int as libc::c_uint { printf(b\"[Empty table]\\n\\0\" as *const u8 as *const libc::c_char); return; } printf( b\"\\n[Table cols=%d rows=%d]\\n\\0\" as *const u8 as *const libc::c_char, (*csv).cols, (*csv).rows, ); row = 0 as libc::c_int; while (row as libc::c_uint) < (*csv).rows { printf(b\"[|\\0\" as *const u8 as *const libc::c_char); col = 0 as libc::c_int; while (col as libc::c_uint) < (*csv).cols { content = csv_get(csv, col as libc::c_uint, row as libc::c_uint); printf(b\"%s\\t|\\0\" as *const u8 as *const libc::c_char, content); col += 1; col; } printf(b\"]\\n\\0\" as *const u8 as *const libc::c_char); row += 1; row; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1187, "before": "int csv_save(CSV *csv, char *filename) { \tFILE *fp; \tint row, col; \tchar *content; \tfp = fopen(filename, \"w\"); \tfor (row = 0; row < csv->rows; row++) \t{ \t\tfor (col = 0; col < csv->cols; col++) \t\t{ \t\t\tcontent = csv_get(csv, col, row); \t\t\tfprintf(fp, \"%s%s\", content, \t\t\t\t\t((col == csv->cols - 1) ? \"\" : csv->delim)); \t\t} \t\tfprintf(fp, \"\\n\"); \t} \tfclose(fp); \treturn 0; }", "after": "pub unsafe extern \"C\" fn csv_save( mut csv: *mut CSV, mut filename: *mut libc::c_char, ) -> libc::c_int { let mut fp: *mut FILE = 0 as *mut FILE; let mut row: libc::c_int = 0; let mut col: libc::c_int = 0; let mut content: *mut libc::c_char = 0 as *mut libc::c_char; fp = fopen(filename, b\"w\\0\" as *const u8 as *const libc::c_char); row = 0 as libc::c_int; while (row as libc::c_uint) < (*csv).rows { col = 0 as libc::c_int; while (col as libc::c_uint) < (*csv).cols { content = csv_get(csv, col as libc::c_uint, row as libc::c_uint); fprintf( fp, b\"%s%s\\0\" as *const u8 as *const libc::c_char, content, if col as libc::c_uint == ((*csv).cols).wrapping_sub(1 as libc::c_int as libc::c_uint) { b\"\\0\" as *const u8 as *const libc::c_char } else { (*csv).delim as *const libc::c_char }, ); col += 1; col; } fprintf(fp, b\"\\n\\0\" as *const u8 as *const libc::c_char); row += 1; row; } fclose(fp); return 0 as libc::c_int; }" }, { "index": 1188, "before": "int main(void) { \tconst int size = 512; \tint i, j; \tunsigned char *colors = malloc(size * 3); \tunsigned char *pix = malloc(size * size * 3), *p; \tFILE *fp; \tfor (i = 0; i < size; i++) \t\thue_to_rgb(i * 240. / size, i * 1. / size, colors + 3 * i); \tfor (i = 0, p = pix; i < size; i++) \t\tfor (j = 0; j < size; j++, p += 3) \t\t\tmemcpy(p, colors + (i ^ j) * 3, 3); \tfp = fopen(\"xor.ppm\", \"wb\"); \tfprintf(fp, \"P6\\n%d %d\\n255\\n\", size, size); \tfwrite(pix, size * size * 3, 1, fp); \tfclose(fp); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let size: libc::c_int = 512 as libc::c_int; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut colors: *mut libc::c_uchar = malloc( (size * 3 as libc::c_int) as libc::c_ulong, ) as *mut libc::c_uchar; let mut pix: *mut libc::c_uchar = malloc( (size * size * 3 as libc::c_int) as libc::c_ulong, ) as *mut libc::c_uchar; let mut p: *mut libc::c_uchar = 0 as *mut libc::c_uchar; let mut fp: *mut FILE = 0 as *mut FILE; i = 0 as libc::c_int; while i < size { hue_to_rgb( i as libc::c_double * 240.0f64 / size as libc::c_double, i as libc::c_double * 1.0f64 / size as libc::c_double, colors.offset((3 as libc::c_int * i) as isize), ); i += 1; i; } i = 0 as libc::c_int; p = pix; while i < size { j = 0 as libc::c_int; while j < size { memcpy( p as *mut libc::c_void, colors.offset(((i ^ j) * 3 as libc::c_int) as isize) as *const libc::c_void, 3 as libc::c_int as libc::c_ulong, ); j += 1; j; p = p.offset(3 as libc::c_int as isize); } i += 1; i; } fp = fopen( b\"xor.ppm\\0\" as *const u8 as *const libc::c_char, b\"wb\\0\" as *const u8 as *const libc::c_char, ); fprintf(fp, b\"P6\\n%d %d\\n255\\n\\0\" as *const u8 as *const libc::c_char, size, size); fwrite( pix as *const libc::c_void, (size * size * 3 as libc::c_int) as libc::c_ulong, 1 as libc::c_int as libc::c_ulong, fp, ); fclose(fp); return 0 as libc::c_int; }" }, { "index": 1189, "before": "void hue_to_rgb(double hue, double sat, unsigned char *p) { \tdouble x; \tint c = 255 * sat; \thue /= 60; \tx = (1 - fabs(fmod(hue, 2) - 1)) * 255; \tswitch((int)hue) { \tcase 0:\tp[0] = c; p[1] = x; p[2] = 0; return; \tcase 1:\tp[0] = x; p[1] = c; p[2] = 0; return; \tcase 2:\tp[0] = 0; p[1] = c; p[2] = x; return; \tcase 3:\tp[0] = 0; p[1] = x; p[2] = c; return; \tcase 4:\tp[0] = x; p[1] = 0; p[2] = c; return; \tcase 5:\tp[0] = c; p[1] = 0; p[2] = x; return; \t} }", "after": "pub unsafe extern \"C\" fn hue_to_rgb( mut hue: libc::c_double, mut sat: libc::c_double, mut p: *mut libc::c_uchar, ) { let mut x: libc::c_double = 0.; let mut c: libc::c_int = (255 as libc::c_int as libc::c_double * sat) as libc::c_int; hue /= 60 as libc::c_int as libc::c_double; x = (1 as libc::c_int as libc::c_double - fabs( fmod(hue, 2 as libc::c_int as libc::c_double) - 1 as libc::c_int as libc::c_double, )) * 255 as libc::c_int as libc::c_double; match hue as libc::c_int { 0 => { *p.offset(0 as libc::c_int as isize) = c as libc::c_uchar; *p.offset(1 as libc::c_int as isize) = x as libc::c_uchar; *p.offset(2 as libc::c_int as isize) = 0 as libc::c_int as libc::c_uchar; return; } 1 => { *p.offset(0 as libc::c_int as isize) = x as libc::c_uchar; *p.offset(1 as libc::c_int as isize) = c as libc::c_uchar; *p.offset(2 as libc::c_int as isize) = 0 as libc::c_int as libc::c_uchar; return; } 2 => { *p.offset(0 as libc::c_int as isize) = 0 as libc::c_int as libc::c_uchar; *p.offset(1 as libc::c_int as isize) = c as libc::c_uchar; *p.offset(2 as libc::c_int as isize) = x as libc::c_uchar; return; } 3 => { *p.offset(0 as libc::c_int as isize) = 0 as libc::c_int as libc::c_uchar; *p.offset(1 as libc::c_int as isize) = x as libc::c_uchar; *p.offset(2 as libc::c_int as isize) = c as libc::c_uchar; return; } 4 => { *p.offset(0 as libc::c_int as isize) = x as libc::c_uchar; *p.offset(1 as libc::c_int as isize) = 0 as libc::c_int as libc::c_uchar; *p.offset(2 as libc::c_int as isize) = c as libc::c_uchar; return; } 5 => { *p.offset(0 as libc::c_int as isize) = c as libc::c_uchar; *p.offset(1 as libc::c_int as isize) = 0 as libc::c_int as libc::c_uchar; *p.offset(2 as libc::c_int as isize) = x as libc::c_uchar; return; } _ => {} }; }" }, { "index": 1190, "before": "double calculate_entropy(int ones, int zeros) { \tdouble result = 0; \tint total = ones + zeros; \tresult -= (double) ones / total * log2((double) ones / total); \tresult -= (double) zeros / total * log2((double) zeros / total); \tif (result != result) { // NAN \t\tresult = 0; \t} \treturn result; }", "after": "pub unsafe extern \"C\" fn calculate_entropy( mut ones: libc::c_int, mut zeros: libc::c_int, ) -> libc::c_double { let mut result: libc::c_double = 0 as libc::c_int as libc::c_double; let mut total: libc::c_int = ones + zeros; result -= ones as libc::c_double / total as libc::c_double * log2(ones as libc::c_double / total as libc::c_double); result -= zeros as libc::c_double / total as libc::c_double * log2(zeros as libc::c_double / total as libc::c_double); if result != result { result = 0 as libc::c_int as libc::c_double; } return result; }" }, { "index": 1191, "before": "void print_entropy(char *word) { \tint ones = 0; \tint zeros = 0; \tint i; \tfor (i = 0; word[i]; i++) { \t\tchar c = word[i]; \t\tswitch (c) { \t\t\tcase '0': \t\t\t\tzeros++; \t\t\t\tbreak; \t\t\tcase '1': \t\t\t\tones++; \t\t\t\tbreak; \t\t} \t} \tdouble entropy = calculate_entropy(ones, zeros); \tprintf(\" %-20.18f\", entropy); }", "after": "pub unsafe extern \"C\" fn print_entropy(mut word: *mut libc::c_char) { let mut ones: libc::c_int = 0 as libc::c_int; let mut zeros: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while *word.offset(i as isize) != 0 { let mut c: libc::c_char = *word.offset(i as isize); match c as libc::c_int { 48 => { zeros += 1; zeros; } 49 => { ones += 1; ones; } _ => {} } i += 1; i; } let mut entropy: libc::c_double = calculate_entropy(ones, zeros); printf(b\" %-20.18f\\0\" as *const u8 as *const libc::c_char, entropy); }" }, { "index": 1192, "before": "void print_word(int n, char *word) { \tprintf(\"%2d\", n); \tprintf(\" %10ld\", strlen(word)); \tprint_entropy(word); \tif (n < 10) { \t\tprintf(\" %-40s\", word); \t} else { \t\tprintf(\" %-40s\", \"...\"); \t} \tprintf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn print_word(mut n: libc::c_int, mut word: *mut libc::c_char) { printf(b\"%2d\\0\" as *const u8 as *const libc::c_char, n); printf(b\" %10ld\\0\" as *const u8 as *const libc::c_char, strlen(word)); print_entropy(word); if n < 10 as libc::c_int { printf(b\" %-40s\\0\" as *const u8 as *const libc::c_char, word); } else { printf( b\" %-40s\\0\" as *const u8 as *const libc::c_char, b\"...\\0\" as *const u8 as *const libc::c_char, ); } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1193, "before": "void print_headings() { \tprintf(\"%2s\", \"N\"); \tprintf(\" %10s\", \"Length\"); \tprintf(\" %-20s\", \"Entropy\"); \tprintf(\" %-40s\", \"Word\"); \tprintf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn print_headings() { printf( b\"%2s\\0\" as *const u8 as *const libc::c_char, b\"N\\0\" as *const u8 as *const libc::c_char, ); printf( b\" %10s\\0\" as *const u8 as *const libc::c_char, b\"Length\\0\" as *const u8 as *const libc::c_char, ); printf( b\" %-20s\\0\" as *const u8 as *const libc::c_char, b\"Entropy\\0\" as *const u8 as *const libc::c_char, ); printf( b\" %-40s\\0\" as *const u8 as *const libc::c_char, b\"Word\\0\" as *const u8 as *const libc::c_char, ); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1194, "before": "int main(int argc, char *argv[]) { \tprint_headings(); \tchar *last_word = malloc(2); \tstrcpy(last_word, \"1\"); \tchar *current_word = malloc(2); \tstrcpy(current_word, \"0\"); \tprint_word(1, last_word); \tint i; \tfor (i = 2; i <= 37; i++) { \t\tprint_word(i, current_word); \t\tchar *next_word = malloc(strlen(current_word) + strlen(last_word) + 1); \t\tstrcpy(next_word, current_word); \t\tstrcat(next_word, last_word); \t\tfree(last_word); \t\tlast_word = current_word; \t\tcurrent_word = next_word; \t} \tfree(last_word); \tfree(current_word); \treturn 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { print_headings(); let mut last_word: *mut libc::c_char = malloc(2 as libc::c_int as libc::c_ulong) as *mut libc::c_char; strcpy(last_word, b\"1\\0\" as *const u8 as *const libc::c_char); let mut current_word: *mut libc::c_char = malloc(2 as libc::c_int as libc::c_ulong) as *mut libc::c_char; strcpy(current_word, b\"0\\0\" as *const u8 as *const libc::c_char); print_word(1 as libc::c_int, last_word); let mut i: libc::c_int = 0; i = 2 as libc::c_int; while i <= 37 as libc::c_int { print_word(i, current_word); let mut next_word: *mut libc::c_char = malloc( (strlen(current_word)) .wrapping_add(strlen(last_word)) .wrapping_add(1 as libc::c_int as libc::c_ulong), ) as *mut libc::c_char; strcpy(next_word, current_word); strcat(next_word, last_word); free(last_word as *mut libc::c_void); last_word = current_word; current_word = next_word; i += 1; i; } free(last_word as *mut libc::c_void); free(current_word as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1195, "before": "int main(void) { \tdouble *y, x, y2; \tdouble x0 = 0, x1 = 10, dx = .1; \tint i, n = 1 + (x1 - x0)/dx; \ty = (double *)malloc(sizeof(double) * n); \tfor (y[0] = 1, i = 1; i < n; i++) \t\ty[i] = rk4(rate, dx, x0 + dx * (i - 1), y[i-1]); \tprintf(\"x\\ty\\trel. err.\\n------------\\n\"); \tfor (i = 0; i < n; i += 10) { \t\tx = x0 + dx * i; \t\ty2 = pow(x * x / 4 + 1, 2); \t\tprintf(\"%g\\t%g\\t%g\\n\", x, y[i], y[i]/y2 - 1); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut y: *mut libc::c_double = 0 as *mut libc::c_double; let mut x: libc::c_double = 0.; let mut y2: libc::c_double = 0.; let mut x0: libc::c_double = 0 as libc::c_int as libc::c_double; let mut x1: libc::c_double = 10 as libc::c_int as libc::c_double; let mut dx: libc::c_double = 0.1f64; let mut i: libc::c_int = 0; let mut n: libc::c_int = (1 as libc::c_int as libc::c_double + (x1 - x0) / dx) as libc::c_int; y = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(n as libc::c_ulong), ) as *mut libc::c_double; *y.offset(0 as libc::c_int as isize) = 1 as libc::c_int as libc::c_double; i = 1 as libc::c_int; while i < n { *y .offset( i as isize, ) = rk4( Some( rate as unsafe extern \"C\" fn( libc::c_double, libc::c_double, ) -> libc::c_double, ), dx, x0 + dx * (i - 1 as libc::c_int) as libc::c_double, *y.offset((i - 1 as libc::c_int) as isize), ); i += 1; i; } printf(b\"x\\ty\\trel. err.\\n------------\\n\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < n { x = x0 + dx * i as libc::c_double; y2 = pow( x * x / 4 as libc::c_int as libc::c_double + 1 as libc::c_int as libc::c_double, 2 as libc::c_int as libc::c_double, ); printf( b\"%g\\t%g\\t%g\\n\\0\" as *const u8 as *const libc::c_char, x, *y.offset(i as isize), *y.offset(i as isize) / y2 - 1 as libc::c_int as libc::c_double, ); i += 10 as libc::c_int; } return 0 as libc::c_int; }" }, { "index": 1196, "before": "double rk4(double(*f)(double, double), double dx, double x, double y) { \tdouble\tk1 = dx * f(x, y), \t\tk2 = dx * f(x + dx / 2, y + k1 / 2), \t\tk3 = dx * f(x + dx / 2, y + k2 / 2), \t\tk4 = dx * f(x + dx, y + k3); \treturn y + (k1 + 2 * k2 + 2 * k3 + k4) / 6; }", "after": "pub unsafe extern \"C\" fn rk4( mut f: Option::< unsafe extern \"C\" fn(libc::c_double, libc::c_double) -> libc::c_double, >, mut dx: libc::c_double, mut x: libc::c_double, mut y: libc::c_double, ) -> libc::c_double { let mut k1: libc::c_double = dx * f.expect(\"non-null function pointer\")(x, y); let mut k2: libc::c_double = dx * f .expect( \"non-null function pointer\", )( x + dx / 2 as libc::c_int as libc::c_double, y + k1 / 2 as libc::c_int as libc::c_double, ); let mut k3: libc::c_double = dx * f .expect( \"non-null function pointer\", )( x + dx / 2 as libc::c_int as libc::c_double, y + k2 / 2 as libc::c_int as libc::c_double, ); let mut k4: libc::c_double = dx * f.expect(\"non-null function pointer\")(x + dx, y + k3); return y + (k1 + 2 as libc::c_int as libc::c_double * k2 + 2 as libc::c_int as libc::c_double * k3 + k4) / 6 as libc::c_int as libc::c_double; }" }, { "index": 1197, "before": "double rate(double x, double y) { \treturn x * sqrt(y); }", "after": "pub unsafe extern \"C\" fn rate( mut x: libc::c_double, mut y: libc::c_double, ) -> libc::c_double { return x * sqrt(y); }" }, { "index": 1198, "before": "int main(void) { const int dimx = 800, dimy = 800; int i, j; FILE *fp = fopen(\"first.ppm\", \"wb\"); /* b - binary mode */ (void) fprintf(fp, \"P6\\n%d %d\\n255\\n\", dimx, dimy); for (j = 0; j < dimy; ++j) { for (i = 0; i < dimx; ++i) { static unsigned char color[3]; color[0] = i % 256; /* red */ color[1] = j % 256; /* green */ color[2] = (i * j) % 256; /* blue */ (void) fwrite(color, 1, 3, fp); } } (void) fclose(fp); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let dimx: libc::c_int = 800 as libc::c_int; let dimy: libc::c_int = 800 as libc::c_int; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut fp: *mut FILE = fopen( b\"first.ppm\\0\" as *const u8 as *const libc::c_char, b\"wb\\0\" as *const u8 as *const libc::c_char, ); fprintf(fp, b\"P6\\n%d %d\\n255\\n\\0\" as *const u8 as *const libc::c_char, dimx, dimy); j = 0 as libc::c_int; while j < dimy { i = 0 as libc::c_int; while i < dimx { static mut color: [libc::c_uchar; 3] = [0; 3]; color[0 as libc::c_int as usize] = (i % 256 as libc::c_int) as libc::c_uchar; color[1 as libc::c_int as usize] = (j % 256 as libc::c_int) as libc::c_uchar; color[2 as libc::c_int as usize] = (i * j % 256 as libc::c_int) as libc::c_uchar; fwrite( color.as_mut_ptr() as *const libc::c_void, 1 as libc::c_int as libc::c_ulong, 3 as libc::c_int as libc::c_ulong, fp, ); i += 1; i; } j += 1; j; } fclose(fp); return 0 as libc::c_int; }" }, { "index": 1199, "before": "void show(void *u, int w, int h) { \tint (*univ)[w] = u; \tprintf(\"\\033[H\"); \tfor_y { \t\tfor_x printf(univ[y][x] ? \"\\033[07m \\033[m\" : \" \"); \t\tprintf(\"\\033[E\"); \t} \tfflush(stdout); }", "after": "pub unsafe extern \"C\" fn show( mut u: *mut libc::c_void, mut w: libc::c_int, mut h: libc::c_int, ) { let vla = w as usize; let mut univ: *mut libc::c_int = u as *mut libc::c_int; printf(b\"\\x1B[H\\0\" as *const u8 as *const libc::c_char); let mut y: libc::c_int = 0 as libc::c_int; while y < h { let mut x: libc::c_int = 0 as libc::c_int; while x < w { printf( if *univ.offset(y as isize * vla as isize).offset(x as isize) != 0 { b\"\\x1B[07m \\x1B[m\\0\" as *const u8 as *const libc::c_char } else { b\" \\0\" as *const u8 as *const libc::c_char }, ); x += 1; x; } printf(b\"\\x1B[E\\0\" as *const u8 as *const libc::c_char); y += 1; y; } fflush(stdout); }" }, { "index": 1200, "before": "int main(int c, char **v) { \tint w = 0, h = 0; \tif (c > 1) w = atoi(v[1]); \tif (c > 2) h = atoi(v[2]); \tif (w <= 0) w = 30; \tif (h <= 0) h = 30; \tgame(w, h); }", "after": "unsafe fn main(mut c: libc::c_int, mut v: *mut *mut libc::c_char) -> libc::c_int { let mut w: libc::c_int = 0 as libc::c_int; let mut h: libc::c_int = 0 as libc::c_int; if c > 1 as libc::c_int { w = atoi(*v.offset(1 as libc::c_int as isize)); } if c > 2 as libc::c_int { h = atoi(*v.offset(2 as libc::c_int as isize)); } if w <= 0 as libc::c_int { w = 30 as libc::c_int; } if h <= 0 as libc::c_int { h = 30 as libc::c_int; } game(w, h); return 0; }" }, { "index": 1201, "before": "void evolve(void *u, int w, int h) { \tunsigned (*univ)[w] = u; \tunsigned new[h][w]; \tfor_y for_x { \t\tint n = 0; \t\tfor (int y1 = y - 1; y1 <= y + 1; y1++) \t\t\tfor (int x1 = x - 1; x1 <= x + 1; x1++) \t\t\t\tif (univ[(y1 + h) % h][(x1 + w) % w]) \t\t\t\t\tn++; \t\tif (univ[y][x]) n--; \t\tnew[y][x] = (n == 3 || (n == 2 && univ[y][x])); \t} \tfor_y for_x univ[y][x] = new[y][x]; }", "after": "pub unsafe extern \"C\" fn evolve( mut u: *mut libc::c_void, mut w: libc::c_int, mut h: libc::c_int, ) { let vla = w as usize; let mut univ: *mut libc::c_uint = u as *mut libc::c_uint; let vla_0 = h as usize; let vla_1 = w as usize; let mut new: Vec:: = ::std::vec::from_elem(0, vla_0 * vla_1); let mut y: libc::c_int = 0 as libc::c_int; while y < h { let mut x: libc::c_int = 0 as libc::c_int; while x < w { let mut n: libc::c_int = 0 as libc::c_int; let mut y1: libc::c_int = y - 1 as libc::c_int; while y1 <= y + 1 as libc::c_int { let mut x1: libc::c_int = x - 1 as libc::c_int; while x1 <= x + 1 as libc::c_int { if *univ .offset(((y1 + h) % h) as isize * vla as isize) .offset(((x1 + w) % w) as isize) != 0 { n += 1; n; } x1 += 1; x1; } y1 += 1; y1; } if *univ.offset(y as isize * vla as isize).offset(x as isize) != 0 { n -= 1; n; } *new .as_mut_ptr() .offset(y as isize * vla_1 as isize) .offset( x as isize, ) = (n == 3 as libc::c_int || n == 2 as libc::c_int && *univ.offset(y as isize * vla as isize).offset(x as isize) != 0) as libc::c_int as libc::c_uint; x += 1; x; } y += 1; y; } let mut y_0: libc::c_int = 0 as libc::c_int; while y_0 < h { let mut x_0: libc::c_int = 0 as libc::c_int; while x_0 < w { *univ .offset(y_0 as isize * vla as isize) .offset( x_0 as isize, ) = *new .as_mut_ptr() .offset(y_0 as isize * vla_1 as isize) .offset(x_0 as isize); x_0 += 1; x_0; } y_0 += 1; y_0; } }" }, { "index": 1202, "before": "void game(int w, int h) { \tunsigned univ[h][w]; \tfor_xy univ[y][x] = rand() < RAND_MAX / 10 ? 1 : 0; \twhile (1) { \t\tshow(univ, w, h); \t\tevolve(univ, w, h); \t\tusleep(200000); \t} }", "after": "pub unsafe extern \"C\" fn game(mut w: libc::c_int, mut h: libc::c_int) { let vla = h as usize; let vla_0 = w as usize; let mut univ: Vec:: = ::std::vec::from_elem(0, vla * vla_0); let mut x: libc::c_int = 0 as libc::c_int; while x < w { let mut y: libc::c_int = 0 as libc::c_int; while y < h { *univ .as_mut_ptr() .offset(y as isize * vla_0 as isize) .offset( x as isize, ) = (if rand() < 2147483647 as libc::c_int / 10 as libc::c_int { 1 as libc::c_int } else { 0 as libc::c_int }) as libc::c_uint; y += 1; y; } x += 1; x; } loop { show(univ.as_mut_ptr() as *mut libc::c_void, w, h); evolve(univ.as_mut_ptr() as *mut libc::c_void, w, h); usleep(200000 as libc::c_int as __useconds_t); }; }" }, { "index": 1203, "before": "int randint(int n) { \tint r, rmax = RAND_MAX / n * n; \twhile ((r = rand()) >= rmax); \treturn r / (RAND_MAX / n); }", "after": "pub unsafe extern \"C\" fn randint(mut n: libc::c_int) -> libc::c_int { let mut r: libc::c_int = 0; let mut rmax: libc::c_int = 2147483647 as libc::c_int / n * n; loop { r = rand(); if !(r >= rmax) { break; } } return r / (2147483647 as libc::c_int / n); }" }, { "index": 1204, "before": "double factorial(int n) { \tdouble f = 1; \tint i; \tfor (i = 1; i <= n; i++) f *= i; \treturn f; }", "after": "pub unsafe extern \"C\" fn factorial(mut n: libc::c_int) -> libc::c_double { let mut f: libc::c_double = 1 as libc::c_int as libc::c_double; let mut i: libc::c_int = 0; i = 1 as libc::c_int; while i <= n { f *= i as libc::c_double; i += 1; i; } return f; }" }, { "index": 1205, "before": "double expected(int n) { \tdouble sum = 0; \tint i; \tfor (i = 1; i <= n; i++) \t\tsum += factorial(n) / pow(n, i) / factorial(n - i); \treturn sum; }", "after": "pub unsafe extern \"C\" fn expected(mut n: libc::c_int) -> libc::c_double { let mut sum: libc::c_double = 0 as libc::c_int as libc::c_double; let mut i: libc::c_int = 0; i = 1 as libc::c_int; while i <= n { sum += factorial(n) / pow(n as libc::c_double, i as libc::c_double) / factorial(n - i); i += 1; i; } return sum; }" }, { "index": 1206, "before": "int main(void) { \tsrand(time(0)); \tputs(\" n\\tavg\\texp.\\tdiff\\n-------------------------------\"); \tint n; \tfor (n = 1; n <= MAX_N; n++) { \t\tint cnt = test(n, TIMES); \t\tdouble avg = (double)cnt / TIMES; \t\tdouble theory = expected(n); \t\tdouble diff = (avg / theory - 1) * 100; \t\tprintf(\"%2d %8.4f %8.4f %6.3f%%\\n\", n, avg, theory, diff); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { srand(time(0 as *mut time_t) as libc::c_uint); puts( b\" n\\tavg\\texp.\\tdiff\\n-------------------------------\\0\" as *const u8 as *const libc::c_char, ); let mut n: libc::c_int = 0; n = 1 as libc::c_int; while n <= 20 as libc::c_int { let mut cnt: libc::c_int = test(n, 1000000 as libc::c_int); let mut avg: libc::c_double = cnt as libc::c_double / 1000000 as libc::c_int as libc::c_double; let mut theory: libc::c_double = expected(n); let mut diff: libc::c_double = (avg / theory - 1 as libc::c_int as libc::c_double) * 100 as libc::c_int as libc::c_double; printf( b\"%2d %8.4f %8.4f %6.3f%%\\n\\0\" as *const u8 as *const libc::c_char, n, avg, theory, diff, ); n += 1; n; } return 0 as libc::c_int; }" }, { "index": 1207, "before": "int test(int n, int times) { \tint i, count = 0; \tfor (i = 0; i < times; i++) { \t\tint x = 1, bits = 0; \t\twhile (!(bits & x)) { \t\t\tcount++; \t\t\tbits |= x; \t\t\tx = 1 << randint(n); \t\t} \t} \treturn count; }", "after": "pub unsafe extern \"C\" fn test( mut n: libc::c_int, mut times: libc::c_int, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut count: libc::c_int = 0 as libc::c_int; i = 0 as libc::c_int; while i < times { let mut x: libc::c_int = 1 as libc::c_int; let mut bits: libc::c_int = 0 as libc::c_int; while bits & x == 0 { count += 1; count; bits |= x; x = (1 as libc::c_int) << randint(n); } i += 1; i; } return count; }" }, { "index": 1208, "before": "int main(void) { \tprintf(\"Nim Game\\n\\n\"); \tint Tokens = 12; \twhile(Tokens > 0) \t{ \t\tprintf(\"How many tokens would you like to take?: \"); \t\tint uin; \t\tscanf(\"%i\", &uin); \t\tint nextTokens = playerTurn(Tokens, uin); \t\tif (nextTokens == Tokens) \t\t{ \t\t\tcontinue; \t\t} \t\tTokens = nextTokens; \t\tTokens = computerTurn(Tokens); \t} \tprintf(\"Computer wins.\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { printf(b\"Nim Game\\n\\n\\0\" as *const u8 as *const libc::c_char); let mut Tokens: libc::c_int = 12 as libc::c_int; while Tokens > 0 as libc::c_int { printf( b\"How many tokens would you like to take?: \\0\" as *const u8 as *const libc::c_char, ); let mut uin: libc::c_int = 0; scanf(b\"%i\\0\" as *const u8 as *const libc::c_char, &mut uin as *mut libc::c_int); let mut nextTokens: libc::c_int = playerTurn(Tokens, uin); if nextTokens == Tokens { continue; } Tokens = nextTokens; Tokens = computerTurn(Tokens); } printf(b\"Computer wins.\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1209, "before": "int playerTurn(int numTokens, int take) { \tif (take < 1 || take > 3) \t{ \t\tprintf(\"\\nTake must be between 1 and 3.\\n\\n\"); \t\treturn numTokens; \t} \tint remainingTokens = numTokens - take; \tprintf(\"\\nPlayer takes %i tokens.\\n\", take); \tprintf(\"%i tokens remaining.\\n\\n\", remainingTokens); \treturn remainingTokens; }", "after": "pub unsafe extern \"C\" fn playerTurn( mut numTokens: libc::c_int, mut take: libc::c_int, ) -> libc::c_int { if take < 1 as libc::c_int || take > 3 as libc::c_int { printf( b\"\\nTake must be between 1 and 3.\\n\\n\\0\" as *const u8 as *const libc::c_char, ); return numTokens; } let mut remainingTokens: libc::c_int = numTokens - take; printf(b\"\\nPlayer takes %i tokens.\\n\\0\" as *const u8 as *const libc::c_char, take); printf( b\"%i tokens remaining.\\n\\n\\0\" as *const u8 as *const libc::c_char, remainingTokens, ); return remainingTokens; }" }, { "index": 1210, "before": "int computerTurn(int numTokens) { \tint take = numTokens % 4; \tint remainingTokens = numTokens - take; \tprintf(\"Computer takes %u tokens.\\n\", take); \tprintf(\"%i tokens remaining.\\n\\n\", remainingTokens); \treturn remainingTokens; }", "after": "pub unsafe extern \"C\" fn computerTurn(mut numTokens: libc::c_int) -> libc::c_int { let mut take: libc::c_int = numTokens % 4 as libc::c_int; let mut remainingTokens: libc::c_int = numTokens - take; printf(b\"Computer takes %u tokens.\\n\\0\" as *const u8 as *const libc::c_char, take); printf( b\"%i tokens remaining.\\n\\n\\0\" as *const u8 as *const libc::c_char, remainingTokens, ); return remainingTokens; }" }, { "index": 1211, "before": "int main(void) { \tint x[] = { 3, 2, 6, 4, 5, 1 }; \tint y[] = { 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15 }; \tlis(x, sizeof(x) / sizeof(int)); \tlis(y, sizeof(y) / sizeof(int)); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut x: [libc::c_int; 6] = [ 3 as libc::c_int, 2 as libc::c_int, 6 as libc::c_int, 4 as libc::c_int, 5 as libc::c_int, 1 as libc::c_int, ]; let mut y: [libc::c_int; 16] = [ 0 as libc::c_int, 8 as libc::c_int, 4 as libc::c_int, 12 as libc::c_int, 2 as libc::c_int, 10 as libc::c_int, 6 as libc::c_int, 14 as libc::c_int, 1 as libc::c_int, 9 as libc::c_int, 5 as libc::c_int, 13 as libc::c_int, 3 as libc::c_int, 11 as libc::c_int, 7 as libc::c_int, 15 as libc::c_int, ]; lis( x.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 6]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, ); lis( y.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 16]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, ); return 0 as libc::c_int; }" }, { "index": 1212, "before": "void lis(int *v, int len) { \tint i; \tstruct node *p, *n = calloc(len, sizeof *n); \tfor (i = 0; i < len; i++) \t\tn[i].val = v[i]; \tfor (i = len; i--; ) { \t\t// find longest chain that can follow n[i] \t\tfor (p = n + i; p++ < n + len; ) { \t\t\tif (p->val > n[i].val && p->len >= n[i].len) { \t\t\t\tn[i].next = p; \t\t\t\tn[i].len = p->len + 1; \t\t\t} \t\t} \t} \t// find longest chain \tfor (i = 0, p = n; i < len; i++) \t\tif (n[i].len > p->len) p = n + i; \tdo printf(\" %d\", p->val); while ((p = p->next)); \tputchar('\\n'); \tfree(n); }", "after": "pub unsafe extern \"C\" fn lis(mut v: *mut libc::c_int, mut len: libc::c_int) { let mut i: libc::c_int = 0; let mut p: *mut node = 0 as *mut node; let mut n: *mut node = calloc( len as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut node; i = 0 as libc::c_int; while i < len { (*n.offset(i as isize)).val = *v.offset(i as isize); i += 1; i; } i = len; loop { let fresh0 = i; i = i - 1; if !(fresh0 != 0) { break; } p = n.offset(i as isize); loop { let fresh1 = p; p = p.offset(1); if !(fresh1 < n.offset(len as isize)) { break; } if (*p).val > (*n.offset(i as isize)).val && (*p).len >= (*n.offset(i as isize)).len { let ref mut fresh2 = (*n.offset(i as isize)).next; *fresh2 = p; (*n.offset(i as isize)).len = (*p).len + 1 as libc::c_int; } } } i = 0 as libc::c_int; p = n; while i < len { if (*n.offset(i as isize)).len > (*p).len { p = n.offset(i as isize); } i += 1; i; } loop { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, (*p).val); p = (*p).next; if p.is_null() { break; } } putchar('\\n' as i32); free(n as *mut libc::c_void); }" }, { "index": 1213, "before": "int isBal(const char*s,int l){ signed c=0; while(l--) \tif(s[l]==']') ++c; \telse if(s[l]=='[') if(--c<0) break; return !c; }", "after": "pub unsafe extern \"C\" fn isBal( mut s: *const libc::c_char, mut l: libc::c_int, ) -> libc::c_int { let mut c: libc::c_int = 0 as libc::c_int; loop { let fresh0 = l; l = l - 1; if !(fresh0 != 0) { break; } if *s.offset(l as isize) as libc::c_int == ']' as i32 { c += 1; c; } else { if !(*s.offset(l as isize) as libc::c_int == '[' as i32) { continue; } c -= 1; if c < 0 as libc::c_int { break; } } } return (c == 0) as libc::c_int; }" }, { "index": 1214, "before": "void shuffle(char*s,int h){ int x,t,i=h; while(i--){ \tt=s[x=rand()%h]; \ts[x]=s[i]; \ts[i]=t; } }", "after": "pub unsafe extern \"C\" fn shuffle(mut s: *mut libc::c_char, mut h: libc::c_int) { let mut x: libc::c_int = 0; let mut t: libc::c_int = 0; let mut i: libc::c_int = h; loop { let fresh1 = i; i = i - 1; if !(fresh1 != 0) { break; } x = rand() % h; t = *s.offset(x as isize) as libc::c_int; *s.offset(x as isize) = *s.offset(i as isize); *s.offset(i as isize) = t as libc::c_char; }; }" }, { "index": 1215, "before": "void doSeq(int n){ char s[64]; const char *o=\"False\"; genSeq(s,n); if(isBal(s,n*2)) o=\"True\"; printf(\"'%s': %s\\n\",s,o); }", "after": "pub unsafe extern \"C\" fn doSeq(mut n: libc::c_int) { let mut s: [libc::c_char; 64] = [0; 64]; let mut o: *const libc::c_char = b\"False\\0\" as *const u8 as *const libc::c_char; genSeq(s.as_mut_ptr(), n); if isBal(s.as_mut_ptr(), n * 2 as libc::c_int) != 0 { o = b\"True\\0\" as *const u8 as *const libc::c_char; } printf(b\"'%s': %s\\n\\0\" as *const u8 as *const libc::c_char, s.as_mut_ptr(), o); }" }, { "index": 1216, "before": "void genSeq(char*s,int n){ if(n){ \tmemset(s,'[',n); \tmemset(s+n,']',n); \tshuffle(s,n*2); } s[n*2]=0; }", "after": "pub unsafe extern \"C\" fn genSeq(mut s: *mut libc::c_char, mut n: libc::c_int) { if n != 0 { memset(s as *mut libc::c_void, '[' as i32, n as libc::c_ulong); memset( s.offset(n as isize) as *mut libc::c_void, ']' as i32, n as libc::c_ulong, ); shuffle(s, n * 2 as libc::c_int); } *s.offset((n * 2 as libc::c_int) as isize) = 0 as libc::c_int as libc::c_char; }" }, { "index": 1217, "before": "int main(){ int n=0; while(n<9) doSeq(n++); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 0 as libc::c_int; while n < 9 as libc::c_int { let fresh2 = n; n = n + 1; doSeq(fresh2); } return 0 as libc::c_int; }" }, { "index": 1218, "before": "int unbase58(const char *s, unsigned char *out) { \tstatic const char *tmpl = \"123456789\" \t\t\"ABCDEFGHJKLMNPQRSTUVWXYZ\" \t\t\"abcdefghijkmnopqrstuvwxyz\"; \tint i, j, c; \tconst char *p; \tmemset(out, 0, 25); \tfor (i = 0; s[i]; i++) { \t\tif (!(p = strchr(tmpl, s[i]))) \t\t\tbail(\"bad char\"); \t\tc = p - tmpl; \t\tfor (j = 25; j--; ) { \t\t\tc += 58 * out[j]; \t\t\tout[j] = c % 256; \t\t\tc /= 256; \t\t} \t\tif (c) bail(\"address too long\"); \t} \treturn 1; }", "after": "pub unsafe extern \"C\" fn unbase58( mut s: *const libc::c_char, mut out: *mut libc::c_uchar, ) -> libc::c_int { static mut tmpl: *const libc::c_char = b\"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\\0\" as *const u8 as *const libc::c_char; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut c: libc::c_int = 0; let mut p: *const libc::c_char = 0 as *const libc::c_char; memset( out as *mut libc::c_void, 0 as libc::c_int, 25 as libc::c_int as libc::c_ulong, ); i = 0 as libc::c_int; while *s.offset(i as isize) != 0 { p = strchr(tmpl, *s.offset(i as isize) as libc::c_int); if p.is_null() { coin_err = b\"bad char\\0\" as *const u8 as *const libc::c_char; return 0 as libc::c_int; } c = p.offset_from(tmpl) as libc::c_long as libc::c_int; j = 25 as libc::c_int; loop { let fresh0 = j; j = j - 1; if !(fresh0 != 0) { break; } c += 58 as libc::c_int * *out.offset(j as isize) as libc::c_int; *out.offset(j as isize) = (c % 256 as libc::c_int) as libc::c_uchar; c /= 256 as libc::c_int; } if c != 0 { coin_err = b\"address too long\\0\" as *const u8 as *const libc::c_char; return 0 as libc::c_int; } i += 1; i; } return 1 as libc::c_int; }" }, { "index": 1219, "before": "int valid(const char *s) { \tunsigned char dec[32], d1[SHA256_DIGEST_LENGTH], d2[SHA256_DIGEST_LENGTH]; \tcoin_err = \"\"; \tif (!unbase58(s, dec)) return 0; \tSHA256(SHA256(dec, 21, d1), SHA256_DIGEST_LENGTH, d2); \tif (memcmp(dec + 21, d2, 4)) \t\tbail(\"bad digest\"); \treturn 1; }", "after": "pub unsafe extern \"C\" fn valid(mut s: *const libc::c_char) -> libc::c_int { let mut dec: [libc::c_uchar; 32] = [0; 32]; let mut d1: [libc::c_uchar; 32] = [0; 32]; let mut d2: [libc::c_uchar; 32] = [0; 32]; coin_err = b\"\\0\" as *const u8 as *const libc::c_char; if unbase58(s, dec.as_mut_ptr()) == 0 { return 0 as libc::c_int; } SHA256( SHA256(dec.as_mut_ptr(), 21 as libc::c_int as size_t, d1.as_mut_ptr()), 32 as libc::c_int as size_t, d2.as_mut_ptr(), ); if memcmp( dec.as_mut_ptr().offset(21 as libc::c_int as isize) as *const libc::c_void, d2.as_mut_ptr() as *const libc::c_void, 4 as libc::c_int as libc::c_ulong, ) != 0 { coin_err = b\"bad digest\\0\" as *const u8 as *const libc::c_char; return 0 as libc::c_int; } return 1 as libc::c_int; }" }, { "index": 1220, "before": "int main (void) { \tconst char *s[] = { \t\t\"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9\", \t\t\"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i\", \t\t\"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9\", \t\t\"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I\", \t\t0 }; \tint i; \tfor (i = 0; s[i]; i++) { \t\tint status = valid(s[i]); \t\tprintf(\"%s: %s\\n\", s[i], status ? \"Ok\" : coin_err); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut s: [*const libc::c_char; 5] = [ b\"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9\\0\" as *const u8 as *const libc::c_char, b\"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i\\0\" as *const u8 as *const libc::c_char, b\"1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9\\0\" as *const u8 as *const libc::c_char, b\"1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I\\0\" as *const u8 as *const libc::c_char, 0 as *const libc::c_char, ]; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while !(s[i as usize]).is_null() { let mut status: libc::c_int = valid(s[i as usize]); printf( b\"%s: %s\\n\\0\" as *const u8 as *const libc::c_char, s[i as usize], if status != 0 { b\"Ok\\0\" as *const u8 as *const libc::c_char } else { coin_err }, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1221, "before": "int main() { printf(\"%d\\n\", 'a'); /* prints \"97\" */ printf(\"%c\\n\", 97); /* prints \"a\"; we don't have to cast because printf is type agnostic */ return 0; }", "after": "unsafe fn main() -> libc::c_int { printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, 'a' as i32); printf(b\"%c\\n\\0\" as *const u8 as *const libc::c_char, 97 as libc::c_int); return 0 as libc::c_int; }" }, { "index": 1222, "before": "int ackermann(int m, int n) { if (!m) return n + 1; if (!n) return ackermann(m - 1, 1); return ackermann(m - 1, ackermann(m, n - 1)); }", "after": "pub unsafe extern \"C\" fn ackermann( mut m: libc::c_int, mut n: libc::c_int, ) -> libc::c_int { if m == 0 { return n + 1 as libc::c_int; } if n == 0 { return ackermann(m - 1 as libc::c_int, 1 as libc::c_int); } return ackermann(m - 1 as libc::c_int, ackermann(m, n - 1 as libc::c_int)); }" }, { "index": 1223, "before": "int main() { int m, n; for (m = 0; m <= 4; m++) for (n = 0; n < 6 - m; n++) printf(\"A(%d, %d) = %d\\n\", m, n, ackermann(m, n)); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut m: libc::c_int = 0; let mut n: libc::c_int = 0; m = 0 as libc::c_int; while m <= 4 as libc::c_int { n = 0 as libc::c_int; while n < 6 as libc::c_int - m { printf( b\"A(%d, %d) = %d\\n\\0\" as *const u8 as *const libc::c_char, m, n, ackermann(m, n), ); n += 1; n; } m += 1; m; } return 0 as libc::c_int; }" }, { "index": 1224, "before": "int main() { \tint y, x; \tfor (y = 1; y <= 10; y++) \t\tfor (x = 1; x <= y; x++) \t\t\tif (!(x & 1) || !(y & 1)) \t\t\t\tprintf(\"%d x %d: %llu\\n\", y, x, solve(y, x, 1)); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut y: libc::c_int = 0; let mut x: libc::c_int = 0; y = 1 as libc::c_int; while y <= 10 as libc::c_int { x = 1 as libc::c_int; while x <= y { if x & 1 as libc::c_int == 0 || y & 1 as libc::c_int == 0 { printf( b\"%d x %d: %llu\\n\\0\" as *const u8 as *const libc::c_char, y, x, solve(y, x, 1 as libc::c_int), ); } x += 1; x; } y += 1; y; } return 0 as libc::c_int; }" }, { "index": 1225, "before": "unsigned long long solve(int hh, int ww, int recur) { \tint t, cx, cy, x; \th = hh, w = ww; \tif (h & 1) t = w, w = h, h = t; \tif (h & 1) return 0; \tif (w == 1) return 1; \tif (w == 2) return h; \tif (h == 2) return w; \tcy = h / 2, cx = w / 2; \tlen = (h + 1) * (w + 1); \tgrid = realloc(grid, len); \tmemset(grid, 0, len--); \tnext[0] = -1; \tnext[1] = -w - 1; \tnext[2] = 1; \tnext[3] = w + 1; \tif (recur) cnt = 0; \tfor (x = cx + 1; x < w; x++) { \t\tt = cy * (w + 1) + x; \t\tgrid[t] = 1; \t\tgrid[len - t] = 1; \t\twalk(cy - 1, x); \t} \tcnt++; \tif (h == w) \t\tcnt *= 2; \telse if (!(w & 1) && recur) \t\tsolve(w, h, 0); \treturn cnt; }", "after": "pub unsafe extern \"C\" fn solve( mut hh: libc::c_int, mut ww: libc::c_int, mut recur: libc::c_int, ) -> libc::c_ulonglong { let mut t: libc::c_int = 0; let mut cx: libc::c_int = 0; let mut cy: libc::c_int = 0; let mut x: libc::c_int = 0; h = hh; w = ww; if h & 1 as libc::c_int != 0 { t = w; w = h; h = t; } if h & 1 as libc::c_int != 0 { return 0 as libc::c_int as libc::c_ulonglong; } if w == 1 as libc::c_int { return 1 as libc::c_int as libc::c_ulonglong; } if w == 2 as libc::c_int { return h as libc::c_ulonglong; } if h == 2 as libc::c_int { return w as libc::c_ulonglong; } cy = h / 2 as libc::c_int; cx = w / 2 as libc::c_int; len = (h + 1 as libc::c_int) * (w + 1 as libc::c_int); grid = realloc(grid as *mut libc::c_void, len as libc::c_ulong) as *mut byte; let fresh4 = len; len = len - 1; memset(grid as *mut libc::c_void, 0 as libc::c_int, fresh4 as libc::c_ulong); next[0 as libc::c_int as usize] = -(1 as libc::c_int); next[1 as libc::c_int as usize] = -w - 1 as libc::c_int; next[2 as libc::c_int as usize] = 1 as libc::c_int; next[3 as libc::c_int as usize] = w + 1 as libc::c_int; if recur != 0 { cnt = 0 as libc::c_int as libc::c_ulonglong; } x = cx + 1 as libc::c_int; while x < w { t = cy * (w + 1 as libc::c_int) + x; *grid.offset(t as isize) = 1 as libc::c_int as byte; *grid.offset((len - t) as isize) = 1 as libc::c_int as byte; walk(cy - 1 as libc::c_int, x); x += 1; x; } cnt = cnt.wrapping_add(1); cnt; if h == w { cnt = cnt.wrapping_mul(2 as libc::c_int as libc::c_ulonglong); } else if w & 1 as libc::c_int == 0 && recur != 0 { solve(w, h, 0 as libc::c_int); } return cnt; }" }, { "index": 1226, "before": "void walk(int y, int x) { \tint i, t; \tif (!y || y == h || !x || x == w) { \t\tcnt += 2; \t\treturn; \t} \tt = y * (w + 1) + x; \tgrid[t]++, grid[len - t]++; \tfor (i = 0; i < 4; i++) \t\tif (!grid[t + next[i]]) \t\t\twalk(y + dir[i][0], x + dir[i][1]); \tgrid[t]--, grid[len - t]--; }", "after": "pub unsafe extern \"C\" fn walk(mut y: libc::c_int, mut x: libc::c_int) { let mut i: libc::c_int = 0; let mut t: libc::c_int = 0; if y == 0 || y == h || x == 0 || x == w { cnt = cnt.wrapping_add(2 as libc::c_int as libc::c_ulonglong); return; } t = y * (w + 1 as libc::c_int) + x; let ref mut fresh0 = *grid.offset(t as isize); *fresh0 = (*fresh0).wrapping_add(1); *fresh0; let ref mut fresh1 = *grid.offset((len - t) as isize); *fresh1 = (*fresh1).wrapping_add(1); *fresh1; i = 0 as libc::c_int; while i < 4 as libc::c_int { if *grid.offset((t + next[i as usize]) as isize) == 0 { walk( y + dir[i as usize][0 as libc::c_int as usize], x + dir[i as usize][1 as libc::c_int as usize], ); } i += 1; i; } let ref mut fresh2 = *grid.offset(t as isize); *fresh2 = (*fresh2).wrapping_sub(1); *fresh2; let ref mut fresh3 = *grid.offset((len - t) as isize); *fresh3 = (*fresh3).wrapping_sub(1); *fresh3; }" }, { "index": 1227, "before": "void encodeNegativeBase(long n, long base, char *out) { char *ptr = out; if (base > -1 || base < -62) { /* Bounds check*/ out = \"\"; return; } if (n == 0) { /* Trivial case */ out = \"0\"; return; } /* Convert the number into a string (in reverse) */ while (n != 0) { long rem = n % base; n = n / base; if (rem < 0) { n++; rem = rem - base; } *ptr = DIGITS[rem]; ptr++; } *ptr = 0; /* Reverse the current string to get the final result */ ptr--; while (out < ptr) { char t = *out; *out = *ptr; *ptr = t; out++; ptr--; } return; }", "after": "pub unsafe extern \"C\" fn encodeNegativeBase( mut n: libc::c_long, mut base: libc::c_long, mut out: *mut libc::c_char, ) { let mut ptr: *mut libc::c_char = out; if base > -(1 as libc::c_int) as libc::c_long || base < -(62 as libc::c_int) as libc::c_long { out = b\"\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; return; } if n == 0 as libc::c_int as libc::c_long { out = b\"0\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char; return; } while n != 0 as libc::c_int as libc::c_long { let mut rem: libc::c_long = n % base; n = n / base; if rem < 0 as libc::c_int as libc::c_long { n += 1; n; rem = rem - base; } *ptr = DIGITS[rem as usize]; ptr = ptr.offset(1); ptr; } *ptr = 0 as libc::c_int as libc::c_char; ptr = ptr.offset(-1); ptr; while out < ptr { let mut t: libc::c_char = *out; *out = *ptr; *ptr = t; out = out.offset(1); out; ptr = ptr.offset(-1); ptr; } }" }, { "index": 1228, "before": "void driver(long n, long b) { char buf[64]; long value; encodeNegativeBase(n, b, buf); printf(\"%12d encoded in base %3d = %12s\\n\", n, b, buf); value = decodeNegativeBase(buf, b); printf(\"%12s decoded in base %3d = %12d\\n\", buf, b, value); printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn driver(mut n: libc::c_long, mut b: libc::c_long) { let mut buf: [libc::c_char; 64] = [0; 64]; let mut value: libc::c_long = 0; encodeNegativeBase(n, b, buf.as_mut_ptr()); printf( b\"%12d encoded in base %3d = %12s\\n\\0\" as *const u8 as *const libc::c_char, n, b, buf.as_mut_ptr(), ); value = decodeNegativeBase(buf.as_mut_ptr(), b); printf( b\"%12s decoded in base %3d = %12d\\n\\0\" as *const u8 as *const libc::c_char, buf.as_mut_ptr(), b, value, ); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1229, "before": "long decodeNegativeBase(const char* ns, long base) { long value, bb; int i; const char *ptr; if (base < -62 || base > -1) { /* Bounds check */ return 0; } if (ns[0] == 0 || (ns[0] == '0' && ns[1] == 0)) { /* Trivial case */ return 0; } /* Find the end of the string */ ptr = ns; while (*ptr != 0) { ptr++; } /* Convert */ value = 0; bb = 1; ptr--; while (ptr >= ns) { for (i = 0; i < DIGITS_LEN; i++) { if (*ptr == DIGITS[i]) { value = value + i * bb; bb = bb * base; break; } } ptr--; } return value; }", "after": "pub unsafe extern \"C\" fn decodeNegativeBase( mut ns: *const libc::c_char, mut base: libc::c_long, ) -> libc::c_long { let mut value: libc::c_long = 0; let mut bb: libc::c_long = 0; let mut i: libc::c_int = 0; let mut ptr: *const libc::c_char = 0 as *const libc::c_char; if base < -(62 as libc::c_int) as libc::c_long || base > -(1 as libc::c_int) as libc::c_long { return 0 as libc::c_int as libc::c_long; } if *ns.offset(0 as libc::c_int as isize) as libc::c_int == 0 as libc::c_int || *ns.offset(0 as libc::c_int as isize) as libc::c_int == '0' as i32 && *ns.offset(1 as libc::c_int as isize) as libc::c_int == 0 as libc::c_int { return 0 as libc::c_int as libc::c_long; } ptr = ns; while *ptr as libc::c_int != 0 as libc::c_int { ptr = ptr.offset(1); ptr; } value = 0 as libc::c_int as libc::c_long; bb = 1 as libc::c_int as libc::c_long; ptr = ptr.offset(-1); ptr; while ptr >= ns { i = 0 as libc::c_int; while i < DIGITS_LEN { if *ptr as libc::c_int == DIGITS[i as usize] as libc::c_int { value = value + i as libc::c_long * bb; bb = bb * base; break; } else { i += 1; i; } } ptr = ptr.offset(-1); ptr; } return value; }" }, { "index": 1230, "before": "int main() { driver(10, -2); driver(146, -3); driver(15, -10); driver(12, -62); return 0; }", "after": "unsafe fn main() -> libc::c_int { driver(10 as libc::c_int as libc::c_long, -(2 as libc::c_int) as libc::c_long); driver(146 as libc::c_int as libc::c_long, -(3 as libc::c_int) as libc::c_long); driver(15 as libc::c_int as libc::c_long, -(10 as libc::c_int) as libc::c_long); driver(12 as libc::c_int as libc::c_long, -(62 as libc::c_int) as libc::c_long); return 0 as libc::c_int; }" }, { "index": 1231, "before": "void qpush(ham h) { \tint i, j; \tif (alloc <= n) { \t\talloc = alloc ? alloc * 2 : 16; \t\tq = realloc(q, sizeof(ham) * alloc); \t} \tfor (i = n++; (j = i/2) && q[j] > h; q[i] = q[j], i = j); \tq[i] = h; }", "after": "pub unsafe extern \"C\" fn qpush(mut h: ham) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; if alloc <= n { alloc = if alloc != 0 { alloc.wrapping_mul(2 as libc::c_int as libc::c_ulong) } else { 16 as libc::c_int as libc::c_ulong }; q = realloc( q as *mut libc::c_void, (::core::mem::size_of::() as libc::c_ulong).wrapping_mul(alloc), ) as *mut ham; } let fresh0 = n; n = n.wrapping_add(1); i = fresh0 as libc::c_int; loop { j = i / 2 as libc::c_int; if !(j != 0 && *q.offset(j as isize) > h) { break; } *q.offset(i as isize) = *q.offset(j as isize); i = j; } *q.offset(i as isize) = h; }" }, { "index": 1232, "before": "int main() { \tint i; \tham h; \tfor (qpush(i = 1); i <= 1691; i++) { \t\t/* takes smallest value, and queue its multiples */ \t\th = qpop(); \t\tqpush(h * 2); \t\tqpush(h * 3); \t\tqpush(h * 5); \t\tif (i <= 20 || i == 1691) \t\t\tprintf(\"%6d: %llu\\n\", i, h); \t} \t/* free(q); */ \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut h: ham = 0; i = 1 as libc::c_int; qpush(i as ham); while i <= 1691 as libc::c_int { h = qpop(); qpush(h.wrapping_mul(2 as libc::c_int as libc::c_ulonglong)); qpush(h.wrapping_mul(3 as libc::c_int as libc::c_ulonglong)); qpush(h.wrapping_mul(5 as libc::c_int as libc::c_ulonglong)); if i <= 20 as libc::c_int || i == 1691 as libc::c_int { printf(b\"%6d: %llu\\n\\0\" as *const u8 as *const libc::c_char, i, h); } i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1233, "before": "ham qpop() { \tint i, j; \tham r, t; \t/* outer loop for skipping duplicates */ \tfor (r = q[1]; n > 1 && r == q[1]; q[i] = t) { \t\t/* inner loop is the normal down heap routine */ \t\tfor (i = 1, t = q[--n]; (j = i * 2) < n;) { \t\t\tif (j + 1 < n && q[j] > q[j+1]) j++; \t\t\tif (t <= q[j]) break; \t\t\tq[i] = q[j], i = j; \t\t} \t} \treturn r; }", "after": "pub unsafe extern \"C\" fn qpop() -> ham { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut r: ham = 0; let mut t: ham = 0; r = *q.offset(1 as libc::c_int as isize); while n > 1 as libc::c_int as libc::c_ulong && r == *q.offset(1 as libc::c_int as isize) { i = 1 as libc::c_int; n = n.wrapping_sub(1); t = *q.offset(n as isize); loop { j = i * 2 as libc::c_int; if !((j as libc::c_ulong) < n) { break; } if ((j + 1 as libc::c_int) as libc::c_ulong) < n && *q.offset(j as isize) > *q.offset((j + 1 as libc::c_int) as isize) { j += 1; j; } if t <= *q.offset(j as isize) { break; } *q.offset(i as isize) = *q.offset(j as isize); i = j; } *q.offset(i as isize) = t; } return r; }" }, { "index": 1234, "before": "int dir_empty(const char *path) { \tstruct dirent *ent; \tint ret = 1; \tDIR *d = opendir(path); \tif (!d) { \t\tfprintf(stderr, \"%s: \", path); \t\tperror(\"\"); \t\treturn -1; \t} \twhile ((ent = readdir(d))) { \t\tif (!strcmp(ent->d_name, \".\") || !(strcmp(ent->d_name, \"..\"))) \t\t\tcontinue; \t\tret = 0; \t\tbreak; \t} \tclosedir(d); \treturn ret; }", "after": "pub unsafe extern \"C\" fn dir_empty(mut path: *const libc::c_char) -> libc::c_int { let mut ent: *mut dirent = 0 as *mut dirent; let mut ret: libc::c_int = 1 as libc::c_int; let mut d: *mut DIR = opendir(path); if d.is_null() { fprintf(stderr, b\"%s: \\0\" as *const u8 as *const libc::c_char, path); perror(b\"\\0\" as *const u8 as *const libc::c_char); return -(1 as libc::c_int); } loop { ent = readdir(d); if ent.is_null() { break; } if strcmp( ((*ent).d_name).as_mut_ptr(), b\".\\0\" as *const u8 as *const libc::c_char, ) == 0 || strcmp( ((*ent).d_name).as_mut_ptr(), b\"..\\0\" as *const u8 as *const libc::c_char, ) == 0 { continue; } ret = 0 as libc::c_int; break; } closedir(d); return ret; }" }, { "index": 1235, "before": "int main(int c, char **v) { \tint ret = 0, i; \tif (c < 2) return -1; \tfor (i = 1; i < c; i++) { \t\tret = dir_empty(v[i]); \t\tif (ret >= 0) \t\t\tprintf(\"%s: %sempty\\n\", v[i], ret ? \"\" : \"not \"); \t} \treturn 0; }", "after": "unsafe fn main(mut c: libc::c_int, mut v: *mut *mut libc::c_char) -> libc::c_int { let mut ret: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 0; if c < 2 as libc::c_int { return -(1 as libc::c_int); } i = 1 as libc::c_int; while i < c { ret = dir_empty(*v.offset(i as isize)); if ret >= 0 as libc::c_int { printf( b\"%s: %sempty\\n\\0\" as *const u8 as *const libc::c_char, *v.offset(i as isize), if ret != 0 { b\"\\0\" as *const u8 as *const libc::c_char } else { b\"not \\0\" as *const u8 as *const libc::c_char }, ); } i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1236, "before": "double lineSlope(point a,point b){ \tif(a.x-b.x == 0.0) \t\treturn NAN; \telse \t\treturn (a.y-b.y)/(a.x-b.x); }", "after": "pub unsafe extern \"C\" fn lineSlope(mut a: point, mut b: point) -> libc::c_double { if a.x - b.x == 0.0f64 { return ::core::f32::NAN as libc::c_double } else { return (a.y - b.y) / (a.x - b.x) }; }" }, { "index": 1237, "before": "int main(int argC,char* argV[]) { \tpoint c; \tif(argC < 5) \t\tprintf(\"Usage : %s \",argV[0]); \telse{ \t\tc = intersectionPoint(extractPoint(argV[1]),extractPoint(argV[2]),extractPoint(argV[3]),extractPoint(argV[4])); \t\tif(isnan(c.x)) \t\t\tprintf(\"The lines do not intersect, they are either parallel or co-incident.\"); \t\telse \t\t\tprintf(\"Point of intersection : (%lf,%lf)\",c.x,c.y); \t} \treturn 0; }", "after": "unsafe fn main( mut argC: libc::c_int, mut argV: *mut *mut libc::c_char, ) -> libc::c_int { let mut c: point = point { x: 0., y: 0. }; if argC < 5 as libc::c_int { printf( b\"Usage : %s \\0\" as *const u8 as *const libc::c_char, *argV.offset(0 as libc::c_int as isize), ); } else { c = intersectionPoint( extractPoint(*argV.offset(1 as libc::c_int as isize)), extractPoint(*argV.offset(2 as libc::c_int as isize)), extractPoint(*argV.offset(3 as libc::c_int as isize)), extractPoint(*argV.offset(4 as libc::c_int as isize)), ); if (c.x).is_nan() as i32 != 0 { printf( b\"The lines do not intersect, they are either parallel or co-incident.\\0\" as *const u8 as *const libc::c_char, ); } else { printf( b\"Point of intersection : (%lf,%lf)\\0\" as *const u8 as *const libc::c_char, c.x, c.y, ); } } return 0 as libc::c_int; }" }, { "index": 1238, "before": "point extractPoint(char* str){ \tint i,j,start,end,length; \tchar* holder; \tpoint c; \tfor(i=0;str[i]!=00;i++){ \t\tif(str[i]=='(') \t\t\tstart = i; \t\tif(str[i]==','||str[i]==')') \t\t{ \t\t\tend = i; \t\t\tlength = end - start; \t\t\tholder = (char*)malloc(length*sizeof(char)); \t\t\tfor(j=0;j point { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut start: libc::c_int = 0; let mut end: libc::c_int = 0; let mut length: libc::c_int = 0; let mut holder: *mut libc::c_char = 0 as *mut libc::c_char; let mut c: point = point { x: 0., y: 0. }; i = 0 as libc::c_int; while *str.offset(i as isize) as libc::c_int != 0 as libc::c_int { if *str.offset(i as isize) as libc::c_int == '(' as i32 { start = i; } if *str.offset(i as isize) as libc::c_int == ',' as i32 || *str.offset(i as isize) as libc::c_int == ')' as i32 { end = i; length = end - start; holder = malloc( (length as libc::c_ulong) .wrapping_mul( ::core::mem::size_of::() as libc::c_ulong, ), ) as *mut libc::c_char; j = 0 as libc::c_int; while j < length - 1 as libc::c_int { *holder .offset( j as isize, ) = *str.offset((start + j + 1 as libc::c_int) as isize); j += 1; j; } *holder.offset(j as isize) = 0 as libc::c_int as libc::c_char; if *str.offset(i as isize) as libc::c_int == ',' as i32 { start = i; c.x = atof(holder); } else { c.y = atof(holder); } } i += 1; i; } return c; }" }, { "index": 1239, "before": "point intersectionPoint(point a1,point a2,point b1,point b2){ \tpoint c; \tdouble slopeA = lineSlope(a1,a2), slopeB = lineSlope(b1,b2); \tif(slopeA==slopeB){ \t\tc.x = NAN; \t\tc.y = NAN; \t} \telse if(isnan(slopeA) && !isnan(slopeB)){ \t\tc.x = a1.x; \t\tc.y = (a1.x-b1.x)*slopeB + b1.y; \t} \telse if(isnan(slopeB) && !isnan(slopeA)){ \t\tc.x = b1.x; \t\tc.y = (b1.x-a1.x)*slopeA + a1.y; \t} \telse{ \t\tc.x = (slopeA*a1.x - slopeB*b1.x + b1.y - a1.y)/(slopeA - slopeB); \t\tc.y = slopeB*(c.x - b1.x) + b1.y; \t} \treturn c; }", "after": "pub unsafe extern \"C\" fn intersectionPoint( mut a1: point, mut a2: point, mut b1: point, mut b2: point, ) -> point { let mut c: point = point { x: 0., y: 0. }; let mut slopeA: libc::c_double = lineSlope(a1, a2); let mut slopeB: libc::c_double = lineSlope(b1, b2); if slopeA == slopeB { c.x = ::core::f32::NAN as libc::c_double; c.y = ::core::f32::NAN as libc::c_double; } else if slopeA.is_nan() as i32 != 0 && slopeB.is_nan() as i32 == 0 { c.x = a1.x; c.y = (a1.x - b1.x) * slopeB + b1.y; } else if slopeB.is_nan() as i32 != 0 && slopeA.is_nan() as i32 == 0 { c.x = b1.x; c.y = (b1.x - a1.x) * slopeA + a1.y; } else { c.x = (slopeA * a1.x - slopeB * b1.x + b1.y - a1.y) / (slopeA - slopeB); c.y = slopeB * (c.x - b1.x) + b1.y; } return c; }" }, { "index": 1240, "before": "int main() { \tmpz_t a; \tmpz_init_set_ui(a, 5); \tmpz_pow_ui(a, a, 1 << 18); /* 2**18 == 4**9 */ \tint len = mpz_sizeinbase(a, 10); \tprintf(\"GMP says size is: %d\\n\", len); \t/* because GMP may report size 1 too big; see doc */ \tchar *s = mpz_get_str(0, 10, a); \tprintf(\"size really is %d\\n\", len = strlen(s)); \tprintf(\"Digits: %.20s...%s\\n\", s, s + len - 20); \t// free(s); /* we could, but we won't. we are exiting anyway */ \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut len: libc::c_int = 0; printf(b\"GMP says size is: %d\\n\\0\" as *const u8 as *const libc::c_char, len); let mut s: *mut libc::c_char = 0 as *mut libc::c_char; len = strlen(s) as libc::c_int; printf(b\"size really is %d\\n\\0\" as *const u8 as *const libc::c_char, len); printf( b\"Digits: %.20s...%s\\n\\0\" as *const u8 as *const libc::c_char, s, s.offset(len as isize).offset(-(20 as libc::c_int as isize)), ); return 0 as libc::c_int; }" }, { "index": 1241, "before": "int numLen(int n) { int sum = 1; while (n > 9) { n = n / 10; sum++; } return sum; }", "after": "pub unsafe extern \"C\" fn numLen(mut n: libc::c_int) -> libc::c_int { let mut sum: libc::c_int = 1 as libc::c_int; while n > 9 as libc::c_int { n = n / 10 as libc::c_int; sum += 1; sum; } return sum; }" }, { "index": 1242, "before": "int fusc(int n) { if (n == 0 || n == 1) return n; else if (n % 2 == 0) return fusc(n / 2); else return fusc((n - 1) / 2) + fusc((n + 1) / 2); }", "after": "pub unsafe extern \"C\" fn fusc(mut n: libc::c_int) -> libc::c_int { if n == 0 as libc::c_int || n == 1 as libc::c_int { return n } else if n % 2 as libc::c_int == 0 as libc::c_int { return fusc(n / 2 as libc::c_int) } else { return fusc((n - 1 as libc::c_int) / 2 as libc::c_int) + fusc((n + 1 as libc::c_int) / 2 as libc::c_int) }; }" }, { "index": 1243, "before": "int main() { int i; printf(\"Index-------Value\"); for (i = 0; i < 61; i++) printf(\"\\n%5d%12d\", i, fusc(i)); //printLargeFuscs(INT_MAX); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; printf(b\"Index-------Value\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < 61 as libc::c_int { printf(b\"\\n%5d%12d\\0\" as *const u8 as *const libc::c_char, i, fusc(i)); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1244, "before": "void printLargeFuscs(int limit) { int i, f, len, maxLen = 1; printf(\"\\n\\nPrinting all largest Fusc numbers upto %d \\nIndex-------Value\", limit); for (i = 0; i <= limit; i++) { f = fusc(i); len = numLen(f); if (len > maxLen) { maxLen = len; printf(\"\\n%5d%12d\", i, f); } } }", "after": "pub unsafe extern \"C\" fn printLargeFuscs(mut limit: libc::c_int) { let mut i: libc::c_int = 0; let mut f: libc::c_int = 0; let mut len: libc::c_int = 0; let mut maxLen: libc::c_int = 1 as libc::c_int; printf( b\"\\n\\nPrinting all largest Fusc numbers upto %d \\nIndex-------Value\\0\" as *const u8 as *const libc::c_char, limit, ); i = 0 as libc::c_int; while i <= limit { f = fusc(i); len = numLen(f); if len > maxLen { maxLen = len; printf(b\"\\n%5d%12d\\0\" as *const u8 as *const libc::c_char, i, f); } i += 1; i; } }" }, { "index": 1245, "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": "unsafe fn main() -> libc::c_int { let mut str: [libc::c_char; 29] = *::core::mem::transmute::< &[u8; 29], &mut [libc::c_char; 29], >(b\"rosetta code phrase reversal\\0\"); let mut lenstr: size_t = (::core::mem::size_of::<[libc::c_char; 29]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong); let vla = lenstr as usize; let mut scopy: Vec:: = ::std::vec::from_elem(0, vla); let mut delim: libc::c_char = ' ' as i32 as libc::c_char; printf( b\"Original: \\\"%s\\\"\\n\\0\" as *const u8 as *const libc::c_char, str.as_mut_ptr(), ); strncpy(scopy.as_mut_ptr(), str.as_mut_ptr(), lenstr); reverse_string(scopy.as_mut_ptr()); printf( b\"Reversed: \\\"%s\\\"\\n\\0\" as *const u8 as *const libc::c_char, scopy.as_mut_ptr(), ); strncpy(scopy.as_mut_ptr(), str.as_mut_ptr(), lenstr); reverse_words_in_order(scopy.as_mut_ptr(), delim); printf( b\"Reversed words: \\\"%s\\\"\\n\\0\" as *const u8 as *const libc::c_char, scopy.as_mut_ptr(), ); strncpy(scopy.as_mut_ptr(), str.as_mut_ptr(), lenstr); reverse_order_of_words(scopy.as_mut_ptr(), delim); printf( b\"Reversed order: \\\"%s\\\"\\n\\0\" as *const u8 as *const libc::c_char, scopy.as_mut_ptr(), ); return 0 as libc::c_int; }" }, { "index": 1246, "before": "int main() { \tprintf(\"input.txt is a regular file? %s\\n\", \t check_reg(\"input.txt\") ? \"yes\" : \"no\"); \tprintf(\"docs is a directory? %s\\n\", \t check_dir(\"docs\") ? \"yes\" : \"no\"); \tprintf(\"/input.txt is a regular file? %s\\n\", \t check_reg(\"/input.txt\") ? \"yes\" : \"no\"); \tprintf(\"/docs is a directory? %s\\n\", \t check_dir(\"/docs\") ? \"yes\" : \"no\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { printf( b\"input.txt is a regular file? %s\\n\\0\" as *const u8 as *const libc::c_char, if check_reg(b\"input.txt\\0\" as *const u8 as *const libc::c_char) != 0 { b\"yes\\0\" as *const u8 as *const libc::c_char } else { b\"no\\0\" as *const u8 as *const libc::c_char }, ); printf( b\"docs is a directory? %s\\n\\0\" as *const u8 as *const libc::c_char, if check_dir(b\"docs\\0\" as *const u8 as *const libc::c_char) != 0 { b\"yes\\0\" as *const u8 as *const libc::c_char } else { b\"no\\0\" as *const u8 as *const libc::c_char }, ); printf( b\"/input.txt is a regular file? %s\\n\\0\" as *const u8 as *const libc::c_char, if check_reg(b\"/input.txt\\0\" as *const u8 as *const libc::c_char) != 0 { b\"yes\\0\" as *const u8 as *const libc::c_char } else { b\"no\\0\" as *const u8 as *const libc::c_char }, ); printf( b\"/docs is a directory? %s\\n\\0\" as *const u8 as *const libc::c_char, if check_dir(b\"/docs\\0\" as *const u8 as *const libc::c_char) != 0 { b\"yes\\0\" as *const u8 as *const libc::c_char } else { b\"no\\0\" as *const u8 as *const libc::c_char }, ); return 0 as libc::c_int; }" }, { "index": 1247, "before": "int check_reg(const char *path) { \tstruct stat sb; \treturn stat(path, &sb) == 0 && S_ISREG(sb.st_mode); }", "after": "pub unsafe extern \"C\" fn check_reg(mut path: *const libc::c_char) -> libc::c_int { let mut sb: stat = stat { st_dev: 0, st_ino: 0, st_nlink: 0, st_mode: 0, st_uid: 0, st_gid: 0, __pad0: 0, st_rdev: 0, st_size: 0, st_blksize: 0, st_blocks: 0, st_atim: timespec { tv_sec: 0, tv_nsec: 0 }, st_mtim: timespec { tv_sec: 0, tv_nsec: 0 }, st_ctim: timespec { tv_sec: 0, tv_nsec: 0 }, __glibc_reserved: [0; 3], }; return (stat(path, &mut sb) == 0 as libc::c_int && sb.st_mode & 0o170000 as libc::c_int as libc::c_uint == 0o100000 as libc::c_int as libc::c_uint) as libc::c_int; }" }, { "index": 1248, "before": "int check_dir(const char *path) { \tstruct stat sb; \treturn stat(path, &sb) == 0 && S_ISDIR(sb.st_mode); }", "after": "pub unsafe extern \"C\" fn check_dir(mut path: *const libc::c_char) -> libc::c_int { let mut sb: stat = stat { st_dev: 0, st_ino: 0, st_nlink: 0, st_mode: 0, st_uid: 0, st_gid: 0, __pad0: 0, st_rdev: 0, st_size: 0, st_blksize: 0, st_blocks: 0, st_atim: timespec { tv_sec: 0, tv_nsec: 0 }, st_mtim: timespec { tv_sec: 0, tv_nsec: 0 }, st_ctim: timespec { tv_sec: 0, tv_nsec: 0 }, __glibc_reserved: [0; 3], }; return (stat(path, &mut sb) == 0 as libc::c_int && sb.st_mode & 0o170000 as libc::c_int as libc::c_uint == 0o40000 as libc::c_int as libc::c_uint) as libc::c_int; }" }, { "index": 1249, "before": "int main() { unsigned char input[4] = {5, 7, 2, 4}; puts(damm(input, 4) ? \"Checksum correct\" : \"Checksum incorrect\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut input: [libc::c_uchar; 4] = [ 5 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, ]; puts( if damm(input.as_mut_ptr(), 4 as libc::c_int as size_t) as libc::c_int != 0 { b\"Checksum correct\\0\" as *const u8 as *const libc::c_char } else { b\"Checksum incorrect\\0\" as *const u8 as *const libc::c_char }, ); return 0 as libc::c_int; }" }, { "index": 1250, "before": "bool damm(unsigned char *input, size_t length) { static const unsigned char table[10][10] = { {0, 3, 1, 7, 5, 9, 8, 6, 4, 2}, {7, 0, 9, 2, 1, 5, 4, 8, 6, 3}, {4, 2, 0, 6, 8, 7, 1, 3, 5, 9}, {1, 7, 5, 0, 9, 8, 3, 4, 2, 6}, {6, 1, 2, 3, 0, 4, 5, 9, 7, 8}, {3, 6, 7, 4, 2, 0, 9, 5, 8, 1}, {5, 8, 6, 9, 7, 2, 0, 1, 3, 4}, {8, 9, 4, 5, 3, 6, 2, 0, 1, 7}, {9, 4, 3, 8, 6, 1, 7, 2, 0, 5}, {2, 5, 8, 1, 4, 3, 6, 7, 9, 0}, }; unsigned char interim = 0; for (size_t i = 0; i < length; i++) { interim = table[interim][input[i]]; } return interim == 0; }", "after": "pub unsafe extern \"C\" fn damm( mut input: *mut libc::c_uchar, mut length: size_t, ) -> bool { static mut table: [[libc::c_uchar; 10]; 10] = [ [ 0 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, ], [ 7 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, ], [ 4 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, ], [ 1 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, ], [ 6 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, ], [ 3 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, ], [ 5 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, ], [ 8 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, ], [ 9 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 2 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, ], [ 2 as libc::c_int as libc::c_uchar, 5 as libc::c_int as libc::c_uchar, 8 as libc::c_int as libc::c_uchar, 1 as libc::c_int as libc::c_uchar, 4 as libc::c_int as libc::c_uchar, 3 as libc::c_int as libc::c_uchar, 6 as libc::c_int as libc::c_uchar, 7 as libc::c_int as libc::c_uchar, 9 as libc::c_int as libc::c_uchar, 0 as libc::c_int as libc::c_uchar, ], ]; let mut interim: libc::c_uchar = 0 as libc::c_int as libc::c_uchar; let mut i: size_t = 0 as libc::c_int as size_t; while i < length { interim = table[interim as usize][*input.offset(i as isize) as usize]; i = i.wrapping_add(1); i; } return interim as libc::c_int == 0 as libc::c_int; }" }, { "index": 1251, "before": "int main() { test(\"~/{Downloads,Pictures}/*.{jpg,gif,png}\"); test(\"It{{em,alic}iz,erat}e{d,}, please.\"); test(\"{,{,gotta have{ ,\\\\, again\\\\, }}more }cowbell!\"); //not sure how to parse this one //test(\"{}} some }{,{\\\\{ edge, edge} \\,}{ cases, {here} \\\\\\\\\\}\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { test( b\"~/{Downloads,Pictures}/*.{jpg,gif,png}\\0\" as *const u8 as *const libc::c_char as string, ); test( b\"It{{em,alic}iz,erat}e{d,}, please.\\0\" as *const u8 as *const libc::c_char as string, ); test( b\"{,{,gotta have{ ,\\\\, again\\\\, }}more }cowbell!\\0\" as *const u8 as *const libc::c_char as string, ); return 0 as libc::c_int; }" }, { "index": 1252, "before": "void deallocate_node(node *n) { if (n == NULL) { return; } deallocate_node(n->next); n->next = NULL; if (n->tag == NODE_LEAF) { free(n->data.str); n->data.str = NULL; } else if (n->tag == NODE_TREE || n->tag == NODE_SEQ) { deallocate_node(n->data.root); n->data.root = NULL; } else { fprintf(stderr, \"Cannot deallocate node with tag: %d\\n\", n->tag); exit(1); } free(n); }", "after": "pub unsafe extern \"C\" fn deallocate_node(mut n: *mut node) { if n.is_null() { return; } deallocate_node((*n).next); (*n).next = 0 as *mut node; if (*n).tag as libc::c_uint == NODE_LEAF as libc::c_int as libc::c_uint { free((*n).data.str_0 as *mut libc::c_void); (*n).data.str_0 = 0 as string; } else if (*n).tag as libc::c_uint == NODE_TREE as libc::c_int as libc::c_uint || (*n).tag as libc::c_uint == NODE_SEQ as libc::c_int as libc::c_uint { deallocate_node((*n).data.root); (*n).data.root = 0 as *mut node; } else { fprintf( stderr, b\"Cannot deallocate node with tag: %d\\n\\0\" as *const u8 as *const libc::c_char, (*n).tag as libc::c_uint, ); exit(1 as libc::c_int); } free(n as *mut libc::c_void); }" }, { "index": 1253, "before": "void append(node *root, node *elem) { if (root == NULL) { fprintf(stderr, \"Cannot append to uninitialized node.\"); exit(1); } if (elem == NULL) { return; } if (root->tag == NODE_SEQ || root->tag == NODE_TREE) { if (root->data.root == NULL) { root->data.root = elem; } else { node *it = root->data.root; while (it->next != NULL) { it = it->next; } it->next = elem; } } else { fprintf(stderr, \"Cannot append to node with tag: %d\\n\", root->tag); exit(1); } }", "after": "pub unsafe extern \"C\" fn append(mut root: *mut node, mut elem: *mut node) { if root.is_null() { fprintf( stderr, b\"Cannot append to uninitialized node.\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } if elem.is_null() { return; } if (*root).tag as libc::c_uint == NODE_SEQ as libc::c_int as libc::c_uint || (*root).tag as libc::c_uint == NODE_TREE as libc::c_int as libc::c_uint { if ((*root).data.root).is_null() { (*root).data.root = elem; } else { let mut it: *mut node = (*root).data.root; while !((*it).next).is_null() { it = (*it).next; } (*it).next = elem; } } else { fprintf( stderr, b\"Cannot append to node with tag: %d\\n\\0\" as *const u8 as *const libc::c_char, (*root).tag as libc::c_uint, ); exit(1 as libc::c_int); }; }" }, { "index": 1254, "before": "string allocate_string(string src) { size_t len = strlen(src); string out = calloc(len + 1, sizeof(character)); if (out == NULL) { fprintf(stderr, \"Failed to allocate a copy of the string.\"); exit(1); } strcpy(out, src); return out; }", "after": "pub unsafe extern \"C\" fn allocate_string(mut src: string) -> string { let mut len: size_t = strlen(src as *const libc::c_char); let mut out: string = calloc( len.wrapping_add(1 as libc::c_int as libc::c_ulong), ::core::mem::size_of::() as libc::c_ulong, ) as string; if out.is_null() { fprintf( stderr, b\"Failed to allocate a copy of the string.\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } strcpy(out as *mut libc::c_char, src as *const libc::c_char); return out; }" }, { "index": 1255, "before": "size_t count(node *n) { if (n == NULL) { return 0; } if (n->tag == NODE_LEAF) { return 1; } if (n->tag == NODE_TREE) { size_t sum = 0; node *it = n->data.root; while (it != NULL) { sum += count(it); it = it->next; } return sum; } if (n->tag == NODE_SEQ) { size_t prod = 1; node *it = n->data.root; while (it != NULL) { prod *= count(it); it = it->next; } return prod; } fprintf(stderr, \"Cannot count node with tag: %d\\n\", n->tag); exit(1); }", "after": "pub unsafe extern \"C\" fn count(mut n: *mut node) -> size_t { if n.is_null() { return 0 as libc::c_int as size_t; } if (*n).tag as libc::c_uint == NODE_LEAF as libc::c_int as libc::c_uint { return 1 as libc::c_int as size_t; } if (*n).tag as libc::c_uint == NODE_TREE as libc::c_int as libc::c_uint { let mut sum: size_t = 0 as libc::c_int as size_t; let mut it: *mut node = (*n).data.root; while !it.is_null() { sum = (sum as libc::c_ulong).wrapping_add(count(it)) as size_t as size_t; it = (*it).next; } return sum; } if (*n).tag as libc::c_uint == NODE_SEQ as libc::c_int as libc::c_uint { let mut prod: size_t = 1 as libc::c_int as size_t; let mut it_0: *mut node = (*n).data.root; while !it_0.is_null() { prod = (prod as libc::c_ulong).wrapping_mul(count(it_0)) as size_t as size_t; it_0 = (*it_0).next; } return prod; } fprintf( stderr, b\"Cannot count node with tag: %d\\n\\0\" as *const u8 as *const libc::c_char, (*n).tag as libc::c_uint, ); exit(1 as libc::c_int); }" }, { "index": 1256, "before": "void expand(node *n, size_t pos) { if (n == NULL) { return; } if (n->tag == NODE_LEAF) { printf(n->data.str); } else if (n->tag == NODE_TREE) { node *it = n->data.root; while (true) { size_t cnt = count(it); if (pos < cnt) { expand(it, pos); break; } pos -= cnt; it = it->next; } } else if (n->tag == NODE_SEQ) { size_t prod = pos; node *it = n->data.root; while (it != NULL) { size_t cnt = count(it); size_t rem = prod % cnt; expand(it, rem); it = it->next; } } else { fprintf(stderr, \"Cannot expand node with tag: %d\\n\", n->tag); exit(1); } }", "after": "pub unsafe extern \"C\" fn expand(mut n: *mut node, mut pos: size_t) { if n.is_null() { return; } if (*n).tag as libc::c_uint == NODE_LEAF as libc::c_int as libc::c_uint { printf((*n).data.str_0 as *const libc::c_char); } else if (*n).tag as libc::c_uint == NODE_TREE as libc::c_int as libc::c_uint { let mut it: *mut node = (*n).data.root; loop { let mut cnt: size_t = count(it); if pos < cnt { expand(it, pos); break; } else { pos = (pos as libc::c_ulong).wrapping_sub(cnt) as size_t as size_t; it = (*it).next; } } } else if (*n).tag as libc::c_uint == NODE_SEQ as libc::c_int as libc::c_uint { let mut prod: size_t = pos; let mut it_0: *mut node = (*n).data.root; while !it_0.is_null() { let mut cnt_0: size_t = count(it_0); let mut rem: size_t = prod.wrapping_rem(cnt_0); expand(it_0, rem); it_0 = (*it_0).next; } } else { fprintf( stderr, b\"Cannot expand node with tag: %d\\n\\0\" as *const u8 as *const libc::c_char, (*n).tag as libc::c_uint, ); exit(1 as libc::c_int); }; }" }, { "index": 1257, "before": "void test(string input) { size_t pos = 0; node *n = parse_seq(input, &pos); size_t cnt = count(n); size_t i; printf(\"Pattern: %s\\n\", input); for (i = 0; i < cnt; i++) { expand(n, i); printf(\"\\n\"); } printf(\"\\n\"); deallocate_node(n); }", "after": "pub unsafe extern \"C\" fn test(mut input: string) { let mut pos: size_t = 0 as libc::c_int as size_t; let mut n: *mut node = parse_seq(input, &mut pos); let mut cnt: size_t = count(n); let mut i: size_t = 0; printf(b\"Pattern: %s\\n\\0\" as *const u8 as *const libc::c_char, input); i = 0 as libc::c_int as size_t; while i < cnt { expand(n, i); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i = i.wrapping_add(1); i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); deallocate_node(n); }" }, { "index": 1258, "before": "void processFile(char* name){ \tint i,records; \tdouble diff,b1,b2; \tFILE* fp = fopen(name,\"r\"); \tfscanf(fp,\"%d\\n\",&records); \tfor(i=0;i=180)?diff-360:diff));\t \t} \tfclose(fp); }", "after": "pub unsafe extern \"C\" fn processFile(mut name: *mut libc::c_char) { let mut i: libc::c_int = 0; let mut records: libc::c_int = 0; let mut diff: libc::c_double = 0.; let mut b1: libc::c_double = 0.; let mut b2: libc::c_double = 0.; let mut fp: *mut FILE = fopen(name, b\"r\\0\" as *const u8 as *const libc::c_char); fscanf( fp, b\"%d\\n\\0\" as *const u8 as *const libc::c_char, &mut records as *mut libc::c_int, ); i = 0 as libc::c_int; while i < records { fscanf( fp, b\"%lf%lf\\0\" as *const u8 as *const libc::c_char, &mut b1 as *mut libc::c_double, &mut b2 as *mut libc::c_double, ); diff = fmod(b2 - b1, 360.0f64); printf( b\"\\nDifference between b2(%lf) and b1(%lf) is %lf\\0\" as *const u8 as *const libc::c_char, b2, b1, if diff < -(180 as libc::c_int) as libc::c_double { diff + 360 as libc::c_int as libc::c_double } else if diff >= 180 as libc::c_int as libc::c_double { diff - 360 as libc::c_int as libc::c_double } else { diff }, ); i += 1; i; } fclose(fp); }" }, { "index": 1259, "before": "int main(int argC,char* argV[]) { \tdouble diff; \tif(argC < 2) \t\tprintf(\"Usage : %s \",argV[0]); \telse if(argC == 2) \t\tprocessFile(argV[1]); \telse{ \t\tdiff = fmod(atof(argV[2])-atof(argV[1]),360.0); \t\tprintf(\"Difference between b2(%s) and b1(%s) is %lf\",argV[2],argV[1],(diff<-180)?diff+360:((diff>=180)?diff-360:diff)); \t} \treturn 0; }", "after": "unsafe fn main( mut argC: libc::c_int, mut argV: *mut *mut libc::c_char, ) -> libc::c_int { let mut diff: libc::c_double = 0.; if argC < 2 as libc::c_int { printf( b\"Usage : %s \\0\" as *const u8 as *const libc::c_char, *argV.offset(0 as libc::c_int as isize), ); } else if argC == 2 as libc::c_int { processFile(*argV.offset(1 as libc::c_int as isize)); } else { diff = fmod( atof(*argV.offset(2 as libc::c_int as isize)) - atof(*argV.offset(1 as libc::c_int as isize)), 360.0f64, ); printf( b\"Difference between b2(%s) and b1(%s) is %lf\\0\" as *const u8 as *const libc::c_char, *argV.offset(2 as libc::c_int as isize), *argV.offset(1 as libc::c_int as isize), if diff < -(180 as libc::c_int) as libc::c_double { diff + 360 as libc::c_int as libc::c_double } else if diff >= 180 as libc::c_int as libc::c_double { diff - 360 as libc::c_int as libc::c_double } else { diff }, ); } return 0 as libc::c_int; }" }, { "index": 1260, "before": "frac frac_new(fr_int_t num, fr_int_t den) { \tfrac a; \tif (!den) { \t\tprintf(\"divide by zero: \"FMT\"/\"FMT\"\\n\", num, den); \t\tabort(); \t} \tint g = gcd(num, den); \tif (g)\t{ num /= g; den /= g; } \telse\t{ num = 0; den = 1; } \tif (den < 0) { \t\tden = -den; \t\tnum = -num; \t} \ta.num = num; a.den = den; \treturn a; }", "after": "pub unsafe extern \"C\" fn frac_new(mut num: fr_int_t, mut den: fr_int_t) -> frac { let mut a: frac = frac { num: 0, den: 0 }; if den == 0 { printf( b\"divide by zero: %lld/%lld\\n\\0\" as *const u8 as *const libc::c_char, num, den, ); abort(); } let mut g: libc::c_int = gcd(num, den) as libc::c_int; if g != 0 { num /= g as libc::c_longlong; den /= g as libc::c_longlong; } else { num = 0 as libc::c_int as fr_int_t; den = 1 as libc::c_int as fr_int_t; } if den < 0 as libc::c_int as libc::c_longlong { den = -den; num = -num; } a.num = num; a.den = den; return a; }" }, { "index": 1261, "before": "fr_int_t gcd(fr_int_t m, fr_int_t n) { \tfr_int_t t; \twhile (n) { t = n; n = m % n; m = t; } \treturn m; }", "after": "pub unsafe extern \"C\" fn gcd(mut m: fr_int_t, mut n: fr_int_t) -> fr_int_t { let mut t: fr_int_t = 0; while n != 0 { t = n; n = m % n; m = t; } return m; }" }, { "index": 1262, "before": "int frtoi(frac a) { return a.den / a.num; }", "after": "pub unsafe extern \"C\" fn frtoi(mut a: frac) -> libc::c_int { return (a.den / a.num) as libc::c_int; }" }, { "index": 1263, "before": "double frtod(frac a) { return (double)a.den / a.num; }", "after": "pub unsafe extern \"C\" fn frtod(mut a: frac) -> libc::c_double { return a.den as libc::c_double / a.num as libc::c_double; }" }, { "index": 1264, "before": "int main() { \tint n, k; \tfrac sum, kf; \tfor (n = 2; n < 1<<19; n++) { \t\tsum = frac_new(1, n); \t\tfor (k = 2; k * k < n; k++) { \t\t\tif (n % k) continue; \t\t\tkf = frac_new(1, k); \t\t\tsum = frac_add(sum, kf); \t\t\tkf = frac_new(1, n / k); \t\t\tsum = frac_add(sum, kf); \t\t} \t\tif (frac_cmp_int(sum, 1) == 0) printf(\"%d\\n\", n); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 0; let mut k: libc::c_int = 0; let mut sum: frac = frac { num: 0, den: 0 }; let mut kf: frac = frac { num: 0, den: 0 }; n = 2 as libc::c_int; while n < (1 as libc::c_int) << 19 as libc::c_int { sum = frac_new(1 as libc::c_int as fr_int_t, n as fr_int_t); k = 2 as libc::c_int; while k * k < n { if !(n % k != 0) { kf = frac_new(1 as libc::c_int as fr_int_t, k as fr_int_t); sum = frac_add(sum, kf); kf = frac_new(1 as libc::c_int as fr_int_t, (n / k) as fr_int_t); sum = frac_add(sum, kf); } k += 1; k; } if frac_cmp( sum, frac_new(1 as libc::c_int as fr_int_t, 1 as libc::c_int as fr_int_t), ) == 0 as libc::c_int { printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, n); } n += 1; n; } return 0 as libc::c_int; }" }, { "index": 1265, "before": "int frac_cmp(frac a, frac b) { \tint l = a.num * b.den, r = a.den * b.num; \treturn l < r ? -1 : l > r; }", "after": "pub unsafe extern \"C\" fn frac_cmp(mut a: frac, mut b: frac) -> libc::c_int { let mut l: libc::c_int = (a.num * b.den) as libc::c_int; let mut r: libc::c_int = (a.den * b.num) as libc::c_int; return if l < r { -(1 as libc::c_int) } else { (l > r) as libc::c_int }; }" }, { "index": 1266, "before": "int day_of_year( int y, int m, int d ){ int month_lengths[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; for( ; m > 1; m -- ){ d += month_lengths[ m - 2 ]; if( m == 3 && leap_year( y ) ){ ++ d; } } return d; }", "after": "pub unsafe extern \"C\" fn day_of_year( mut y: libc::c_int, mut m: libc::c_int, mut d: libc::c_int, ) -> libc::c_int { let mut month_lengths: [libc::c_int; 12] = [ 31 as libc::c_int, 28 as libc::c_int, 31 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, 31 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, 30 as libc::c_int, 31 as libc::c_int, ]; while m > 1 as libc::c_int { d += month_lengths[(m - 2 as libc::c_int) as usize]; if m == 3 as libc::c_int && (y % 400 as libc::c_int == 0 as libc::c_int || y % 4 as libc::c_int == 0 as libc::c_int && y % 100 as libc::c_int != 0) { d += 1; d; } m -= 1; m; } return d; }" }, { "index": 1267, "before": "int main( int argc, char * argv[] ){ time_t now; struct tm * now_time; int year, doy; if( argc == 1 ){ now = time( NULL ); now_time = localtime( &now ); year = now_time->tm_year + 1900; doy = now_time->tm_yday + 1; } else if( argc == 4 ){ year = atoi( argv[ 1 ] ); doy = day_of_year( atoi( argv[ 1 ] ), atoi( argv[ 2 ] ), atoi( argv[ 3 ] ) ); } char * result = ddate( year, doy ); puts( result ); free( result ); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut now: time_t = 0; let mut now_time: *mut tm = 0 as *mut tm; let mut year: libc::c_int = 0; let mut doy: libc::c_int = 0; if argc == 1 as libc::c_int { now = time(0 as *mut time_t); now_time = localtime(&mut now); year = (*now_time).tm_year + 1900 as libc::c_int; doy = (*now_time).tm_yday + 1 as libc::c_int; } else if argc == 4 as libc::c_int { year = atoi(*argv.offset(1 as libc::c_int as isize)); doy = day_of_year( atoi(*argv.offset(1 as libc::c_int as isize)), atoi(*argv.offset(2 as libc::c_int as isize)), atoi(*argv.offset(3 as libc::c_int as isize)), ); } let mut result: *mut libc::c_char = ddate(year, doy); puts(result); free(result as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1268, "before": "int main(void) { char buf[MAX_BUF]; time_t seconds = time(NULL); struct tm *now = localtime(&seconds); const char *months[] = {\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"}; const char *days[] = {\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"}; (void) printf(\"%d-%d-%d\\n\", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday); (void) printf(\"%s, %s %d, %d\\n\",days[now->tm_wday], months[now->tm_mon], now->tm_mday, now->tm_year + 1900); /* using the strftime (the result depends on the locale) */ (void) strftime(buf, MAX_BUF, \"%A, %B %e, %Y\", now); (void) printf(\"%s\\n\", buf); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut buf: [libc::c_char; 50] = [0; 50]; let mut seconds: time_t = time(0 as *mut time_t); let mut now: *mut tm = localtime(&mut seconds); let mut months: [*const libc::c_char; 12] = [ b\"January\\0\" as *const u8 as *const libc::c_char, b\"February\\0\" as *const u8 as *const libc::c_char, b\"March\\0\" as *const u8 as *const libc::c_char, b\"April\\0\" as *const u8 as *const libc::c_char, b\"May\\0\" as *const u8 as *const libc::c_char, b\"June\\0\" as *const u8 as *const libc::c_char, b\"July\\0\" as *const u8 as *const libc::c_char, b\"August\\0\" as *const u8 as *const libc::c_char, b\"September\\0\" as *const u8 as *const libc::c_char, b\"October\\0\" as *const u8 as *const libc::c_char, b\"November\\0\" as *const u8 as *const libc::c_char, b\"December\\0\" as *const u8 as *const libc::c_char, ]; let mut days: [*const libc::c_char; 7] = [ b\"Sunday\\0\" as *const u8 as *const libc::c_char, b\"Monday\\0\" as *const u8 as *const libc::c_char, b\"Tuesday\\0\" as *const u8 as *const libc::c_char, b\"Wednesday\\0\" as *const u8 as *const libc::c_char, b\"Thursday\\0\" as *const u8 as *const libc::c_char, b\"Friday\\0\" as *const u8 as *const libc::c_char, b\"Saturday\\0\" as *const u8 as *const libc::c_char, ]; printf( b\"%d-%d-%d\\n\\0\" as *const u8 as *const libc::c_char, (*now).tm_year + 1900 as libc::c_int, (*now).tm_mon + 1 as libc::c_int, (*now).tm_mday, ); printf( b\"%s, %s %d, %d\\n\\0\" as *const u8 as *const libc::c_char, days[(*now).tm_wday as usize], months[(*now).tm_mon as usize], (*now).tm_mday, (*now).tm_year + 1900 as libc::c_int, ); strftime( buf.as_mut_ptr(), 50 as libc::c_int as size_t, b\"%A, %B %e, %Y\\0\" as *const u8 as *const libc::c_char, now, ); printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, buf.as_mut_ptr()); return 0 as libc::c_int; }" }, { "index": 1269, "before": "int mul_inv(int a, int b) { \tint b0 = b, t, q; \tint x0 = 0, x1 = 1; \tif (b == 1) return 1; \twhile (a > 1) { \t\tq = a / b; \t\tt = b, b = a % b, a = t; \t\tt = x0, x0 = x1 - q * x0, x1 = t; \t} \tif (x1 < 0) x1 += b0; \treturn x1; }", "after": "pub unsafe extern \"C\" fn mul_inv(mut a: libc::c_int, mut b: libc::c_int) -> libc::c_int { let mut b0: libc::c_int = b; let mut t: libc::c_int = 0; let mut q: libc::c_int = 0; let mut x0: libc::c_int = 0 as libc::c_int; let mut x1: libc::c_int = 1 as libc::c_int; if b == 1 as libc::c_int { return 1 as libc::c_int; } while a > 1 as libc::c_int { q = a / b; t = b; b = a % b; a = t; t = x0; x0 = x1 - q * x0; x1 = t; } if x1 < 0 as libc::c_int { x1 += b0; } return x1; }" }, { "index": 1270, "before": "int main(void) { \tint n[] = { 3, 5, 7 }; \tint a[] = { 2, 3, 2 }; \tprintf(\"%d\\n\", chinese_remainder(n, a, sizeof(n)/sizeof(n[0]))); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: [libc::c_int; 3] = [3 as libc::c_int, 5 as libc::c_int, 7 as libc::c_int]; let mut a: [libc::c_int; 3] = [2 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int]; printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, chinese_remainder( n.as_mut_ptr(), a.as_mut_ptr(), (::core::mem::size_of::<[libc::c_int; 3]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int, ), ); return 0 as libc::c_int; }" }, { "index": 1271, "before": "int chinese_remainder(int *n, int *a, int len) { \tint p, i, prod = 1, sum = 0; \tfor (i = 0; i < len; i++) prod *= n[i]; \tfor (i = 0; i < len; i++) { \t\tp = prod / n[i]; \t\tsum += a[i] * mul_inv(p, n[i]) * p; \t} \treturn sum % prod; }", "after": "pub unsafe extern \"C\" fn chinese_remainder( mut n: *mut libc::c_int, mut a: *mut libc::c_int, mut len: libc::c_int, ) -> libc::c_int { let mut p: libc::c_int = 0; let mut i: libc::c_int = 0; let mut prod: libc::c_int = 1 as libc::c_int; let mut sum: libc::c_int = 0 as libc::c_int; i = 0 as libc::c_int; while i < len { prod *= *n.offset(i as isize); i += 1; i; } i = 0 as libc::c_int; while i < len { p = prod / *n.offset(i as isize); sum += *a.offset(i as isize) * mul_inv(p, *n.offset(i as isize)) * p; i += 1; i; } return sum % prod; }" }, { "index": 1272, "before": "void process(int lineNum, char buffer[]) { char days[7][64]; int i = 0, d = 0, j = 0; while (buffer[i] != 0) { if (buffer[i] == ' ') { days[d][j] = '\\0'; ++d; j = 0; } else if (buffer[i] == '\\n' || buffer[i] == '\\r') { days[d][j] = '\\0'; ++d; break; } else { days[d][j] = buffer[i]; ++j; } if (d >= 7) { printf(\"There aren't 7 days in line %d\\n\", lineNum); return; } ++i; } if (buffer[i] == '\\0') { days[d][j] = '\\0'; ++d; } if (d < 7) { printf(\"There aren't 7 days in line %d\\n\", lineNum); return; } else { int len = 0; for (len = 1; len < 64; ++len) { int d1; for (d1 = 0; d1 < 7; ++d1) { int d2; for (d2 = d1 + 1; d2 < 7; ++d2) { int unique = 0; for (i = 0; i < len; ++i) { if (days[d1][i] != days[d2][i]) { unique = 1; break; } } if (!unique) { goto next_length; } } } // uniqueness found for this length printf(\"%2d \", len); for (i = 0; i < 7; ++i) { printf(\" %s\", days[i]); } printf(\"\\n\"); return; // a duplication was found at the current length next_length: {} } } printf(\"Failed to find uniqueness within the bounds.\"); }", "after": "pub unsafe extern \"C\" fn process( mut lineNum: libc::c_int, mut buffer: *mut libc::c_char, ) { let mut days: [[libc::c_char; 64]; 7] = [[0; 64]; 7]; let mut i: libc::c_int = 0 as libc::c_int; let mut d: libc::c_int = 0 as libc::c_int; let mut j: libc::c_int = 0 as libc::c_int; while *buffer.offset(i as isize) as libc::c_int != 0 as libc::c_int { if *buffer.offset(i as isize) as libc::c_int == ' ' as i32 { days[d as usize][j as usize] = '\\0' as i32 as libc::c_char; d += 1; d; j = 0 as libc::c_int; } else if *buffer.offset(i as isize) as libc::c_int == '\\n' as i32 || *buffer.offset(i as isize) as libc::c_int == '\\r' as i32 { days[d as usize][j as usize] = '\\0' as i32 as libc::c_char; d += 1; d; break; } else { days[d as usize][j as usize] = *buffer.offset(i as isize); j += 1; j; } if d >= 7 as libc::c_int { printf( b\"There aren't 7 days in line %d\\n\\0\" as *const u8 as *const libc::c_char, lineNum, ); return; } i += 1; i; } if *buffer.offset(i as isize) as libc::c_int == '\\0' as i32 { days[d as usize][j as usize] = '\\0' as i32 as libc::c_char; d += 1; d; } if d < 7 as libc::c_int { printf( b\"There aren't 7 days in line %d\\n\\0\" as *const u8 as *const libc::c_char, lineNum, ); return; } else { let mut len: libc::c_int = 0 as libc::c_int; len = 1 as libc::c_int; while len < 64 as libc::c_int { let mut current_block_35: u64; let mut d1: libc::c_int = 0; d1 = 0 as libc::c_int; 's_113: loop { if !(d1 < 7 as libc::c_int) { current_block_35 = 18153031941552419006; break; } let mut d2: libc::c_int = 0; d2 = d1 + 1 as libc::c_int; while d2 < 7 as libc::c_int { let mut unique: libc::c_int = 0 as libc::c_int; i = 0 as libc::c_int; while i < len { if days[d1 as usize][i as usize] as libc::c_int != days[d2 as usize][i as usize] as libc::c_int { unique = 1 as libc::c_int; break; } else { i += 1; i; } } if unique == 0 { current_block_35 = 10891380440665537214; break 's_113; } d2 += 1; d2; } d1 += 1; d1; } match current_block_35 { 10891380440665537214 => {} _ => { printf(b\"%2d \\0\" as *const u8 as *const libc::c_char, len); i = 0 as libc::c_int; while i < 7 as libc::c_int { printf( b\" %s\\0\" as *const u8 as *const libc::c_char, (days[i as usize]).as_mut_ptr(), ); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return; } } len += 1; len; } } printf( b\"Failed to find uniqueness within the bounds.\\0\" as *const u8 as *const libc::c_char, ); }" }, { "index": 1273, "before": "int main() { char buffer[1024]; int lineNum = 1, len; FILE *fp; fp = fopen(\"days_of_week.txt\", \"r\"); while (1) { memset(buffer, 0, sizeof(buffer)); fgets(buffer, sizeof(buffer), fp); len = strlen(buffer); if (len == 0 || buffer[len - 1] == '\\0') { break; } process(lineNum++, buffer); } fclose(fp); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut buffer: [libc::c_char; 1024] = [0; 1024]; let mut lineNum: libc::c_int = 1 as libc::c_int; let mut len: libc::c_int = 0; let mut fp: *mut FILE = 0 as *mut FILE; fp = fopen( b\"days_of_week.txt\\0\" as *const u8 as *const libc::c_char, b\"r\\0\" as *const u8 as *const libc::c_char, ); loop { memset( buffer.as_mut_ptr() as *mut libc::c_void, 0 as libc::c_int, ::core::mem::size_of::<[libc::c_char; 1024]>() as libc::c_ulong, ); fgets( buffer.as_mut_ptr(), ::core::mem::size_of::<[libc::c_char; 1024]>() as libc::c_ulong as libc::c_int, fp, ); len = strlen(buffer.as_mut_ptr()) as libc::c_int; if len == 0 as libc::c_int || buffer[(len - 1 as libc::c_int) as usize] as libc::c_int == '\\0' as i32 { break; } let fresh0 = lineNum; lineNum = lineNum + 1; process(fresh0, buffer.as_mut_ptr()); } fclose(fp); return 0 as libc::c_int; }" }, { "index": 1274, "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": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 1 as libc::c_int; while i < 5000 as libc::c_int { let mut sum: libc::c_int = 0 as libc::c_int; let mut number: libc::c_int = i; while number > 0 as libc::c_int { let mut digit: libc::c_int = number % 10 as libc::c_int; sum = (sum as libc::c_double + pow(digit as libc::c_double, digit as libc::c_double)) as libc::c_int; number /= 10 as libc::c_int; } if sum == i { printf(b\"%i\\n\\0\" as *const u8 as *const libc::c_char, i); } i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1275, "before": "int palindrome(const char *s) { int i, l; l = strlen(s); for (i = 0; i < l / 2; i++) { if (s[i] != s[l - i - 1]) return 0; } return 1; }", "after": "pub unsafe extern \"C\" fn palindrome(mut s: *const libc::c_char) -> libc::c_int { let mut i: libc::c_int = 0; let mut l: libc::c_int = 0; l = strlen(s) as libc::c_int; i = 0 as libc::c_int; while i < l / 2 as libc::c_int { if *s.offset(i as isize) as libc::c_int != *s.offset((l - i - 1 as libc::c_int) as isize) as libc::c_int { return 0 as libc::c_int; } i += 1; i; } return 1 as libc::c_int; }" }, { "index": 1276, "before": "int main() { const char *t = \"ingirumimusnocteetconsumimurigni\"; const char *template = \"sequence \\\"%s\\\" is%s palindrome\\n\"; int l = strlen(t); printf(template, t, palindrome(t) ? \"\" : \"n't\"); printf(template, t, palindrome_r(t, 0, l) ? \"\" : \"n't\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut t: *const libc::c_char = b\"ingirumimusnocteetconsumimurigni\\0\" as *const u8 as *const libc::c_char; let mut template: *const libc::c_char = b\"sequence \\\"%s\\\" is%s palindrome\\n\\0\" as *const u8 as *const libc::c_char; let mut l: libc::c_int = strlen(t) as libc::c_int; printf( template, t, if palindrome(t) != 0 { b\"\\0\" as *const u8 as *const libc::c_char } else { b\"n't\\0\" as *const u8 as *const libc::c_char }, ); printf( template, t, if palindrome_r(t, 0 as libc::c_int, l) != 0 { b\"\\0\" as *const u8 as *const libc::c_char } else { b\"n't\\0\" as *const u8 as *const libc::c_char }, ); return 0 as libc::c_int; }" }, { "index": 1277, "before": "int palindrome_r(const char *s, int b, int e) { if ((e - 1) <= b) return 1; if (s[b] != s[e - 1]) return 0; return palindrome_r(s, b + 1, e - 1); }", "after": "pub unsafe extern \"C\" fn palindrome_r( mut s: *const libc::c_char, mut b: libc::c_int, mut e: libc::c_int, ) -> libc::c_int { if e - 1 as libc::c_int <= b { return 1 as libc::c_int; } if *s.offset(b as isize) as libc::c_int != *s.offset((e - 1 as libc::c_int) as isize) as libc::c_int { return 0 as libc::c_int; } return palindrome_r(s, b + 1 as libc::c_int, e - 1 as libc::c_int); }" }, { "index": 1278, "before": "void sieve_destroy(sieve* s) { bit_array_destroy(&s->not_prime); }", "after": "pub unsafe extern \"C\" fn sieve_destroy(mut s: *mut sieve) { bit_array_destroy(&mut (*s).not_prime); }" }, { "index": 1279, "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 unsafe extern \"C\" fn is_prime(mut s: *const sieve, mut n: uint32_t) -> bool { if n <= (*s).limit {} else { __assert_fail( b\"n <= s->limit\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 67 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 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 libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 67 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 40], &[libc::c_char; 40], >(b\"_Bool is_prime(const sieve *, uint32_t)\\0\")) .as_ptr(), ); } }; return bit_array_get(&(*s).not_prime, n) as libc::c_int == 0 as libc::c_int; }" }, { "index": 1280, "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 unsafe extern \"C\" fn print_prime_partition( mut s: *const sieve, mut number: uint32_t, mut count: uint32_t, ) { if count > 0 as libc::c_int as libc::c_uint {} else { __assert_fail( b\"count > 0\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 93 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 62], &[libc::c_char; 62], >(b\"void print_prime_partition(const sieve *, uint32_t, uint32_t)\\0\")) .as_ptr(), ); } 'c_2193: { if count > 0 as libc::c_int as libc::c_uint {} else { __assert_fail( b\"count > 0\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 93 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 62], &[libc::c_char; 62], >(b\"void print_prime_partition(const sieve *, uint32_t, uint32_t)\\0\")) .as_ptr(), ); } }; let mut primes: *mut uint32_t = malloc( (count as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut uint32_t; if primes.is_null() { fprintf(stderr, b\"Out of memory\\n\\0\" as *const u8 as *const libc::c_char); return; } if !find_prime_partition(s, number, count, 2 as libc::c_int as uint32_t, primes) { printf( b\"%u cannot be partitioned into %u primes.\\n\\0\" as *const u8 as *const libc::c_char, number, count, ); } else { printf( b\"%u = %u\\0\" as *const u8 as *const libc::c_char, number, *primes.offset(0 as libc::c_int as isize), ); let mut i: uint32_t = 1 as libc::c_int as uint32_t; while i < count { printf( b\" + %u\\0\" as *const u8 as *const libc::c_char, *primes.offset(i as isize), ); i = i.wrapping_add(1); i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); } free(primes as *mut libc::c_void); }" }, { "index": 1281, "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 unsafe extern \"C\" fn sieve_create(mut s: *mut sieve, mut limit: uint32_t) -> bool { if !bit_array_create( &mut (*s).not_prime, limit.wrapping_add(1 as libc::c_int as libc::c_uint), ) { return 0 as libc::c_int != 0; } bit_array_set( &mut (*s).not_prime, 0 as libc::c_int as uint32_t, 1 as libc::c_int != 0, ); bit_array_set( &mut (*s).not_prime, 1 as libc::c_int as uint32_t, 1 as libc::c_int != 0, ); let mut p: uint32_t = 2 as libc::c_int as uint32_t; while p.wrapping_mul(p) <= limit { if bit_array_get(&mut (*s).not_prime, p) as libc::c_int == 0 as libc::c_int { let mut q: uint32_t = p.wrapping_mul(p); while q <= limit { bit_array_set(&mut (*s).not_prime, q, 1 as libc::c_int != 0); q = (q as libc::c_uint).wrapping_add(p) as uint32_t as uint32_t; } } p = p.wrapping_add(1); p; } (*s).limit = limit; return 1 as libc::c_int != 0; }" }, { "index": 1282, "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 unsafe extern \"C\" fn bit_array_get( mut b: *const bit_array, mut index: uint32_t, ) -> bool { if index < (*b).size {} else { __assert_fail( b\"index < b->size\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 37 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 49], &[libc::c_char; 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 libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 37 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 49], &[libc::c_char; 49], >(b\"_Bool bit_array_get(const bit_array *, uint32_t)\\0\")) .as_ptr(), ); } }; let mut bit: uint32_t = ((1 as libc::c_int) << (index & 31 as libc::c_int as libc::c_uint)) as uint32_t; return *((*b).array).offset((index >> 5 as libc::c_int) as isize) & bit != 0 as libc::c_int as libc::c_uint; }" }, { "index": 1283, "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 unsafe extern \"C\" fn bit_array_create( mut b: *mut bit_array, mut size: uint32_t, ) -> bool { let mut array: *mut uint32_t = calloc( size .wrapping_add(31 as libc::c_int as libc::c_uint) .wrapping_div(32 as libc::c_int as libc::c_uint) as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut uint32_t; if array.is_null() { return 0 as libc::c_int != 0; } (*b).size = size; (*b).array = array; return 1 as libc::c_int != 0; }" }, { "index": 1284, "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 unsafe extern \"C\" fn bit_array_set( mut b: *mut bit_array, mut index: uint32_t, mut value: bool, ) { if index < (*b).size {} else { __assert_fail( b\"index < b->size\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 27 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 49], &[libc::c_char; 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 libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 27 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 49], &[libc::c_char; 49], >(b\"void bit_array_set(bit_array *, uint32_t, _Bool)\\0\")) .as_ptr(), ); } }; let mut p: *mut uint32_t = &mut *((*b).array) .offset((index >> 5 as libc::c_int) as isize) as *mut uint32_t; let mut bit: uint32_t = ((1 as libc::c_int) << (index & 31 as libc::c_int as libc::c_uint)) as uint32_t; if value { *p |= bit; } else { *p &= !bit; }; }" }, { "index": 1285, "before": "void bit_array_destroy(bit_array* b) { free(b->array); b->array = NULL; }", "after": "pub unsafe extern \"C\" fn bit_array_destroy(mut b: *mut bit_array) { free((*b).array as *mut libc::c_void); (*b).array = 0 as *mut uint32_t; }" }, { "index": 1286, "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 unsafe extern \"C\" fn find_prime_partition( mut s: *const sieve, mut number: uint32_t, mut count: uint32_t, mut min_prime: uint32_t, mut p: *mut uint32_t, ) -> bool { if count == 1 as libc::c_int as libc::c_uint { if number >= min_prime && is_prime(s, number) as libc::c_int != 0 { *p = number; return 1 as libc::c_int != 0; } return 0 as libc::c_int != 0; } let mut prime: uint32_t = min_prime; while prime < number { if is_prime(s, prime) { if find_prime_partition( s, number.wrapping_sub(prime), count.wrapping_sub(1 as libc::c_int as libc::c_uint), prime.wrapping_add(1 as libc::c_int as libc::c_uint), p.offset(1 as libc::c_int as isize), ) { *p = prime; return 1 as libc::c_int != 0; } } prime = prime.wrapping_add(1); prime; } return 0 as libc::c_int != 0; }" }, { "index": 1287, "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": "unsafe fn main() -> libc::c_int { let limit: uint32_t = 100000 as libc::c_int as uint32_t; let mut s: sieve = { let mut init = sieve_tag { limit: 0 as libc::c_int as uint32_t, not_prime: bit_array { size: 0, array: 0 as *mut uint32_t, }, }; init }; if !sieve_create(&mut s, limit) { fprintf(stderr, b\"Out of memory\\n\\0\" as *const u8 as *const libc::c_char); return 1 as libc::c_int; } print_prime_partition( &mut s, 99809 as libc::c_int as uint32_t, 1 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 18 as libc::c_int as uint32_t, 2 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 19 as libc::c_int as uint32_t, 3 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 20 as libc::c_int as uint32_t, 4 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 2017 as libc::c_int as uint32_t, 24 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 22699 as libc::c_int as uint32_t, 1 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 22699 as libc::c_int as uint32_t, 2 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 22699 as libc::c_int as uint32_t, 3 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 22699 as libc::c_int as uint32_t, 4 as libc::c_int as uint32_t, ); print_prime_partition( &mut s, 40355 as libc::c_int as uint32_t, 3 as libc::c_int as uint32_t, ); sieve_destroy(&mut s); return 0 as libc::c_int; }" }, { "index": 1288, "before": "void deal(int s, int *t) { \tint i, j; \tsrnd(s); \tfor (i = 0; i < 52; i++) t[i] = 51 - i; \tfor (i = 0; i < 51; i++) { \t\tj = 51 - rnd() % (52 - i); \t\ts = t[i], t[i] = t[j], t[j] = s; \t} }", "after": "pub unsafe extern \"C\" fn deal(mut s: libc::c_int, mut t: *mut libc::c_int) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; srnd(s); i = 0 as libc::c_int; while i < 52 as libc::c_int { *t.offset(i as isize) = 51 as libc::c_int - i; i += 1; i; } i = 0 as libc::c_int; while i < 51 as libc::c_int { j = 51 as libc::c_int - rnd() % (52 as libc::c_int - i); s = *t.offset(i as isize); *t.offset(i as isize) = *t.offset(j as isize); *t.offset(j as isize) = s; i += 1; i; } }" }, { "index": 1289, "before": "int rnd(void) { return (seed = (seed * 214013 + 2531011) & RMAX32) >> 16; }", "after": "pub unsafe extern \"C\" fn rnd() -> libc::c_int { seed = ((seed * 214013 as libc::c_int + 2531011 as libc::c_int) as libc::c_uint & ((1 as libc::c_uint) << 31 as libc::c_int) .wrapping_sub(1 as libc::c_int as libc::c_uint)) as libc::c_int; return seed >> 16 as libc::c_int; }" }, { "index": 1290, "before": "int main(int c, char **v) { \tint s, card[52]; \tif (c < 2 || (s = atoi(v[1])) <= 0) s = 11982; \tsetlocale(LC_ALL, \"\"); \tdeal(s, card); \tprintf(\"Hand %d\\n\", s); \tshow(card); \treturn 0; }", "after": "unsafe fn main(mut c: libc::c_int, mut v: *mut *mut libc::c_char) -> libc::c_int { let mut s: libc::c_int = 0; let mut card: [libc::c_int; 52] = [0; 52]; if c < 2 as libc::c_int || { s = atoi(*v.offset(1 as libc::c_int as isize)); s <= 0 as libc::c_int } { s = 11982 as libc::c_int; } setlocale(6 as libc::c_int, b\"\\0\" as *const u8 as *const libc::c_char); deal(s, card.as_mut_ptr()); printf(b\"Hand %d\\n\\0\" as *const u8 as *const libc::c_char, s); show(card.as_mut_ptr()); return 0 as libc::c_int; }" }, { "index": 1291, "before": "void srnd(int x) { seed = x; }", "after": "pub unsafe extern \"C\" fn srnd(mut x: libc::c_int) { seed = x; }" }, { "index": 1292, "before": "void show(const int *c) { \tint i; \tfor (i = 0; i < 52; c++) { \t\tprintf(\" \\033[%dm%lc\\033[m%lc\", 32 - (1 + *c) % 4 / 2, \t\t\ts_suits[*c % 4], s_nums[*c / 4]); \t\tif (!(++i % 8) || i == 52) putchar('\\n'); \t} }", "after": "pub unsafe extern \"C\" fn show(mut c: *const libc::c_int) { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 52 as libc::c_int { printf( b\" \\x1B[%dm%lc\\x1B[m%lc\\0\" as *const u8 as *const libc::c_char, 32 as libc::c_int - (1 as libc::c_int + *c) % 4 as libc::c_int / 2 as libc::c_int, s_suits[(*c % 4 as libc::c_int) as usize], s_nums[(*c / 4 as libc::c_int) as usize], ); i += 1; if i % 8 as libc::c_int == 0 || i == 52 as libc::c_int { putchar('\\n' as i32); } c = c.offset(1); c; } }" }, { "index": 1293, "before": "void showCake(layer3 cake){ \tprintf(\"\\ncake.d = %d\",cake.d); \tprintf(\"\\ncake.e = %d\",cake.e); \tprintf(\"\\ncake.l1.a = %d\",cake.l1.a); \tprintf(\"\\ncake.l2.b = %f\",cake.l2.b); \tprintf(\"\\ncake.l2.l1.a = %d\",cake.l2.l1.a); }", "after": "pub unsafe extern \"C\" fn showCake(mut cake: layer3) { printf(b\"\\ncake.d = %d\\0\" as *const u8 as *const libc::c_char, cake.d); printf(b\"\\ncake.e = %d\\0\" as *const u8 as *const libc::c_char, cake.e); printf(b\"\\ncake.l1.a = %d\\0\" as *const u8 as *const libc::c_char, cake.l1.a); printf( b\"\\ncake.l2.b = %f\\0\" as *const u8 as *const libc::c_char, cake.l2.b as libc::c_double, ); printf(b\"\\ncake.l2.l1.a = %d\\0\" as *const u8 as *const libc::c_char, cake.l2.l1.a); }" }, { "index": 1294, "before": "int main() { \tlayer3 cake1,cake2; \tcake1.d = 1; \tcake1.e = 2; \tcake1.l1.a = 3; \tcake1.l2.b = 4; \tcake1.l2.l1.a = 5; \tprintf(\"Cake 1 is : \"); \tshowCake(cake1); \tcake2 = cake1; \tcake2.l2.b += cake2.l2.l1.a; \tprintf(\"\\nCake 2 is : \"); \tshowCake(cake2); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut cake1: layer3 = layer3 { l2: layer2 { l1: layer1 { a: 0 }, b: 0., c: 0., }, l1: layer1 { a: 0 }, d: 0, e: 0, }; let mut cake2: layer3 = layer3 { l2: layer2 { l1: layer1 { a: 0 }, b: 0., c: 0., }, l1: layer1 { a: 0 }, d: 0, e: 0, }; cake1.d = 1 as libc::c_int; cake1.e = 2 as libc::c_int; cake1.l1.a = 3 as libc::c_int; cake1.l2.b = 4 as libc::c_int as libc::c_float; cake1.l2.l1.a = 5 as libc::c_int; printf(b\"Cake 1 is : \\0\" as *const u8 as *const libc::c_char); showCake(cake1); cake2 = cake1; cake2.l2.b += cake2.l2.l1.a as libc::c_float; printf(b\"\\nCake 2 is : \\0\" as *const u8 as *const libc::c_char); showCake(cake2); return 0 as libc::c_int; }" }, { "index": 1295, "before": "void analytic() { \tdouble t; \tprintf(\" Time: \"); \tfor (t = 0; t <= 100; t += 10) printf(\" %7g\", t); \tprintf(\"\\nAnalytic: \"); \tfor (t = 0; t <= 100; t += 10) \t\tprintf(FMT, 20 + 80 * exp(-0.07 * t)); \tprintf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn analytic() { let mut t: libc::c_double = 0.; printf(b\" Time: \\0\" as *const u8 as *const libc::c_char); t = 0 as libc::c_int as libc::c_double; while t <= 100 as libc::c_int as libc::c_double { printf(b\" %7g\\0\" as *const u8 as *const libc::c_char, t); t += 10 as libc::c_int as libc::c_double; } printf(b\"\\nAnalytic: \\0\" as *const u8 as *const libc::c_char); t = 0 as libc::c_int as libc::c_double; while t <= 100 as libc::c_int as libc::c_double { printf( b\" %7.3f\\0\" as *const u8 as *const libc::c_char, 20 as libc::c_int as libc::c_double + 80 as libc::c_int as libc::c_double * exp(-0.07f64 * t), ); t += 10 as libc::c_int as libc::c_double; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1296, "before": "int main() { \tanalytic(); \tivp_euler(cooling, 100, 2, 100); \tivp_euler(cooling, 100, 5, 100); \tivp_euler(cooling, 100, 10, 100); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { analytic(); ivp_euler( Some( cooling as unsafe extern \"C\" fn(libc::c_double, libc::c_double) -> libc::c_double, ), 100 as libc::c_int as libc::c_double, 2 as libc::c_int, 100 as libc::c_int, ); ivp_euler( Some( cooling as unsafe extern \"C\" fn(libc::c_double, libc::c_double) -> libc::c_double, ), 100 as libc::c_int as libc::c_double, 5 as libc::c_int, 100 as libc::c_int, ); ivp_euler( Some( cooling as unsafe extern \"C\" fn(libc::c_double, libc::c_double) -> libc::c_double, ), 100 as libc::c_int as libc::c_double, 10 as libc::c_int, 100 as libc::c_int, ); return 0 as libc::c_int; }" }, { "index": 1297, "before": "double cooling(double t, double temp) { \treturn -0.07 * (temp - 20); }", "after": "pub unsafe extern \"C\" fn cooling( mut t: libc::c_double, mut temp: libc::c_double, ) -> libc::c_double { return -0.07f64 * (temp - 20 as libc::c_int as libc::c_double); }" }, { "index": 1298, "before": "int one_of_n(int n) { \tint i, r = 0; \tfor (i = 1; i < n; i++) \t\tif (!irand(i + 1)) \t\t\tr = i; \treturn r; }", "after": "pub unsafe extern \"C\" fn one_of_n(mut n: libc::c_int) -> libc::c_int { let mut i: libc::c_int = 0; let mut r: libc::c_int = 0 as libc::c_int; i = 1 as libc::c_int; while i < n { if irand(i + 1 as libc::c_int) == 0 { r = i; } i += 1; i; } return r; }" }, { "index": 1299, "before": "int irand(int n) { \tint r, randmax = RAND_MAX / n * n; \twhile ((r = rand()) >= randmax) \t\t; \treturn r / (randmax / n); }", "after": "pub unsafe extern \"C\" fn irand(mut n: libc::c_int) -> libc::c_int { let mut r: libc::c_int = 0; let mut randmax: libc::c_int = 2147483647 as libc::c_int / n * n; loop { r = rand(); if !(r >= randmax) { break; } } return r / (randmax / n); }" }, { "index": 1300, "before": "int main(void) { \tint i, r[10] = {0}; \tfor (i = 0; i < 1000000; i++, r[one_of_n(10)]++) \t\t; \tfor (i = 0; i < 10; i++) \t\tprintf(\"%d%c\", r[i], i == 9 ? '\\n' : ' '); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut r: [libc::c_int; 10] = [0 as libc::c_int, 0, 0, 0, 0, 0, 0, 0, 0, 0]; i = 0 as libc::c_int; while i < 1000000 as libc::c_int { i += 1; i; r[one_of_n(10 as libc::c_int) as usize] += 1; r[one_of_n(10 as libc::c_int) as usize]; } i = 0 as libc::c_int; while i < 10 as libc::c_int { printf( b\"%d%c\\0\" as *const u8 as *const libc::c_char, r[i as usize], if i == 9 as libc::c_int { '\\n' as i32 } else { ' ' as i32 }, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1301, "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": "unsafe fn main() -> libc::c_int { let mut question: *mut libc::c_char = 0 as *mut libc::c_char; let mut len: size_t = 0 as libc::c_int as size_t; let mut read: ssize_t = 0; let mut answers: [*const libc::c_char; 20] = [ b\"It is certain\\0\" as *const u8 as *const libc::c_char, b\"It is decidedly so\\0\" as *const u8 as *const libc::c_char, b\"Without a doubt\\0\" as *const u8 as *const libc::c_char, b\"Yes, definitely\\0\" as *const u8 as *const libc::c_char, b\"You may rely on it\\0\" as *const u8 as *const libc::c_char, b\"As I see it, yes\\0\" as *const u8 as *const libc::c_char, b\"Most likely\\0\" as *const u8 as *const libc::c_char, b\"Outlook good\\0\" as *const u8 as *const libc::c_char, b\"Signs point to yes\\0\" as *const u8 as *const libc::c_char, b\"Yes\\0\" as *const u8 as *const libc::c_char, b\"Reply hazy, try again\\0\" as *const u8 as *const libc::c_char, b\"Ask again later\\0\" as *const u8 as *const libc::c_char, b\"Better not tell you now\\0\" as *const u8 as *const libc::c_char, b\"Cannot predict now\\0\" as *const u8 as *const libc::c_char, b\"Concentrate and ask again\\0\" as *const u8 as *const libc::c_char, b\"Don't bet on it\\0\" as *const u8 as *const libc::c_char, b\"My reply is no\\0\" as *const u8 as *const libc::c_char, b\"My sources say no\\0\" as *const u8 as *const libc::c_char, b\"Outlook not so good\\0\" as *const u8 as *const libc::c_char, b\"Very doubtful\\0\" as *const u8 as *const libc::c_char, ]; srand(time(0 as *mut time_t) as libc::c_uint); printf( b\"Please enter your question or a blank line to quit.\\n\\0\" as *const u8 as *const libc::c_char, ); loop { printf(b\"\\n? : \\0\" as *const u8 as *const libc::c_char); read = getline(&mut question, &mut len, stdin); if read < 2 as libc::c_int as libc::c_long { break; } printf( b\"\\n%s\\n\\0\" as *const u8 as *const libc::c_char, answers[(rand() % 20 as libc::c_int) as usize], ); } if !question.is_null() { free(question as *mut libc::c_void); } return 0 as libc::c_int; }" }, { "index": 1302, "before": "void s_of_n_init(struct s_env *s_env, size_t size, unsigned int n) { s_env->i = 0; s_env->n = n; s_env->size = size; s_env->sample = malloc(n * size); }", "after": "pub unsafe extern \"C\" fn s_of_n_init( mut s_env: *mut s_env, mut size: size_t, mut n: libc::c_uint, ) { (*s_env).i = 0 as libc::c_int as libc::c_uint; (*s_env).n = n; (*s_env).size = size; (*s_env).sample = malloc((n as libc::c_ulong).wrapping_mul(size)); }" }, { "index": 1303, "before": "void sample_set_i(struct s_env *s_env, unsigned int i, void *item) { memcpy(s_env->sample + i * s_env->size, item, s_env->size); }", "after": "pub unsafe extern \"C\" fn sample_set_i( mut s_env: *mut s_env, mut i: libc::c_uint, mut item: *mut libc::c_void, ) { memcpy( ((*s_env).sample) .offset((i as libc::c_ulong).wrapping_mul((*s_env).size) as isize), item, (*s_env).size, ); }" }, { "index": 1304, "before": "int main() { unsigned int i, j; unsigned int n = 3; unsigned int num_items = 10; unsigned int *frequencies; int *items_set; srand(time(NULL)); items_set = malloc(num_items * sizeof(int)); frequencies = malloc(num_items * sizeof(int)); for (i = 0; i < num_items; i++) { items_set[i] = i; frequencies[i] = 0; } for (i = 0; i < 100000; i++) { int *res = test(n, items_set, num_items); for (j = 0; j < n; j++) { frequencies[res[j]]++; } \tfree(res); } for (i = 0; i < num_items; i++) { printf(\" %d\", frequencies[i]); } puts(\"\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_uint = 0; let mut j: libc::c_uint = 0; let mut n: libc::c_uint = 3 as libc::c_int as libc::c_uint; let mut num_items: libc::c_uint = 10 as libc::c_int as libc::c_uint; let mut frequencies: *mut libc::c_uint = 0 as *mut libc::c_uint; let mut items_set: *mut libc::c_int = 0 as *mut libc::c_int; srand(time(0 as *mut time_t) as libc::c_uint); items_set = malloc( (num_items as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_int; frequencies = malloc( (num_items as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_uint; i = 0 as libc::c_int as libc::c_uint; while i < num_items { *items_set.offset(i as isize) = i as libc::c_int; *frequencies.offset(i as isize) = 0 as libc::c_int as libc::c_uint; i = i.wrapping_add(1); i; } i = 0 as libc::c_int as libc::c_uint; while i < 100000 as libc::c_int as libc::c_uint { let mut res: *mut libc::c_int = test(n, items_set, num_items); j = 0 as libc::c_int as libc::c_uint; while j < n { let ref mut fresh0 = *frequencies.offset(*res.offset(j as isize) as isize); *fresh0 = (*fresh0).wrapping_add(1); *fresh0; j = j.wrapping_add(1); j; } free(res as *mut libc::c_void); i = i.wrapping_add(1); i; } i = 0 as libc::c_int as libc::c_uint; while i < num_items { printf( b\" %d\\0\" as *const u8 as *const libc::c_char, *frequencies.offset(i as isize), ); i = i.wrapping_add(1); i; } puts(b\"\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1305, "before": "int main() { int d, x, y, cx, cy, px, py; char pts[MAX][MAX]; point curr, prev; for (x = 0; x < MAX; ++x) for (y = 0; y < MAX; ++y) pts[x][y] = ' '; prev.x = prev.y = 0; pts[0][0] = '.'; for (d = 1; d < N * N; ++d) { d2pt(N, d, &curr); cx = curr.x * K; cy = curr.y * K; px = prev.x * K; py = prev.y * K; pts[cx][cy] = '.'; if (cx == px ) { if (py < cy) for (y = py + 1; y < cy; ++y) pts[cx][y] = '|'; else for (y = cy + 1; y < py; ++y) pts[cx][y] = '|'; } else { if (px < cx) for (x = px + 1; x < cx; ++x) pts[x][cy] = '_'; else for (x = cx + 1; x < px; ++x) pts[x][cy] = '_'; } prev = curr; } for (x = 0; x < MAX; ++x) { for (y = 0; y < MAX; ++y) printf(\"%c\", pts[y][x]); printf(\"\\n\"); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut d: libc::c_int = 0; let mut x: libc::c_int = 0; let mut y: libc::c_int = 0; let mut cx: libc::c_int = 0; let mut cy: libc::c_int = 0; let mut px: libc::c_int = 0; let mut py: libc::c_int = 0; let mut pts: [[libc::c_char; 96]; 96] = [[0; 96]; 96]; let mut curr: point = point { x: 0, y: 0 }; let mut prev: point = point { x: 0, y: 0 }; x = 0 as libc::c_int; while x < 32 as libc::c_int * 3 as libc::c_int { y = 0 as libc::c_int; while y < 32 as libc::c_int * 3 as libc::c_int { pts[x as usize][y as usize] = ' ' as i32 as libc::c_char; y += 1; y; } x += 1; x; } prev.y = 0 as libc::c_int; prev.x = prev.y; pts[0 as libc::c_int as usize][0 as libc::c_int as usize] = '.' as i32 as libc::c_char; d = 1 as libc::c_int; while d < 32 as libc::c_int * 32 as libc::c_int { d2pt(32 as libc::c_int, d, &mut curr); cx = curr.x * 3 as libc::c_int; cy = curr.y * 3 as libc::c_int; px = prev.x * 3 as libc::c_int; py = prev.y * 3 as libc::c_int; pts[cx as usize][cy as usize] = '.' as i32 as libc::c_char; if cx == px { if py < cy { y = py + 1 as libc::c_int; while y < cy { pts[cx as usize][y as usize] = '|' as i32 as libc::c_char; y += 1; y; } } else { y = cy + 1 as libc::c_int; while y < py { pts[cx as usize][y as usize] = '|' as i32 as libc::c_char; y += 1; y; } } } else if px < cx { x = px + 1 as libc::c_int; while x < cx { pts[x as usize][cy as usize] = '_' as i32 as libc::c_char; x += 1; x; } } else { x = cx + 1 as libc::c_int; while x < px { pts[x as usize][cy as usize] = '_' as i32 as libc::c_char; x += 1; x; } } prev = curr; d += 1; d; } x = 0 as libc::c_int; while x < 32 as libc::c_int * 3 as libc::c_int { y = 0 as libc::c_int; while y < 32 as libc::c_int * 3 as libc::c_int { printf( b\"%c\\0\" as *const u8 as *const libc::c_char, pts[y as usize][x as usize] as libc::c_int, ); y += 1; y; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); x += 1; x; } return 0 as libc::c_int; }" }, { "index": 1306, "before": "void d2pt(int n, int d, point *p) { int s = 1, t = d, rx, ry; p->x = 0; p->y = 0; while (s < n) { rx = 1 & (t / 2); ry = 1 & (t ^ rx); rot(s, p, rx, ry); p->x += s * rx; p->y += s * ry; t /= 4; s *= 2; } }", "after": "pub unsafe extern \"C\" fn d2pt( mut n: libc::c_int, mut d: libc::c_int, mut p: *mut point, ) { let mut s: libc::c_int = 1 as libc::c_int; let mut t: libc::c_int = d; let mut rx: libc::c_int = 0; let mut ry: libc::c_int = 0; (*p).x = 0 as libc::c_int; (*p).y = 0 as libc::c_int; while s < n { rx = 1 as libc::c_int & t / 2 as libc::c_int; ry = 1 as libc::c_int & (t ^ rx); rot(s, p, rx, ry); (*p).x += s * rx; (*p).y += s * ry; t /= 4 as libc::c_int; s *= 2 as libc::c_int; } }" }, { "index": 1307, "before": "void rot(int n, point *p, int rx, int ry) { int t; if (!ry) { if (rx == 1) { p->x = n - 1 - p->x; p->y = n - 1 - p->y; } t = p->x; p->x = p->y; p->y = t; } }", "after": "pub unsafe extern \"C\" fn rot( mut n: libc::c_int, mut p: *mut point, mut rx: libc::c_int, mut ry: libc::c_int, ) { let mut t: libc::c_int = 0; if ry == 0 { if rx == 1 as libc::c_int { (*p).x = n - 1 as libc::c_int - (*p).x; (*p).y = n - 1 as libc::c_int - (*p).y; } t = (*p).x; (*p).x = (*p).y; (*p).y = t; } }" }, { "index": 1308, "before": "int main(int argc, char **argv) { int user1 = 0, user2 = 0; printf(\"Enter two integers. Space delimited, please: \"); scanf(\"%d %d\",&user1, &user2); int array[user1][user2]; array[user1/2][user2/2] = user1 + user2; printf(\"array[%d][%d] is %d\\n\",user1/2,user2/2,array[user1/2][user2/2]); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut user1: libc::c_int = 0 as libc::c_int; let mut user2: libc::c_int = 0 as libc::c_int; printf( b\"Enter two integers. Space delimited, please: \\0\" as *const u8 as *const libc::c_char, ); scanf( b\"%d %d\\0\" as *const u8 as *const libc::c_char, &mut user1 as *mut libc::c_int, &mut user2 as *mut libc::c_int, ); let vla = user1 as usize; let vla_0 = user2 as usize; let mut array: Vec:: = ::std::vec::from_elem(0, vla * vla_0); *array .as_mut_ptr() .offset((user1 / 2 as libc::c_int) as isize * vla_0 as isize) .offset((user2 / 2 as libc::c_int) as isize) = user1 + user2; printf( b\"array[%d][%d] is %d\\n\\0\" as *const u8 as *const libc::c_char, user1 / 2 as libc::c_int, user2 / 2 as libc::c_int, *array .as_mut_ptr() .offset((user1 / 2 as libc::c_int) as isize * vla_0 as isize) .offset((user2 / 2 as libc::c_int) as isize), ); return 0 as libc::c_int; }" }, { "index": 1309, "before": "int dstr_space(dstr *s, size_t grow_amount) { return s->length + grow_amount < s->alloc; }", "after": "pub unsafe extern \"C\" fn dstr_space( mut s: *mut dstr, mut grow_amount: size_t, ) -> libc::c_int { return (((*s).length).wrapping_add(grow_amount) < (*s).alloc) as libc::c_int; }" }, { "index": 1310, "before": "int dstr_grow(dstr *s) { s->alloc *= 2; char *attempt = realloc(s->data, s->alloc); if (!attempt) return 0; else s->data = attempt; return 1; }", "after": "pub unsafe extern \"C\" fn dstr_grow(mut s: *mut dstr) -> libc::c_int { (*s) .alloc = ((*s).alloc as libc::c_ulong) .wrapping_mul(2 as libc::c_int as libc::c_ulong) as size_t as size_t; let mut attempt: *mut libc::c_char = realloc( (*s).data as *mut libc::c_void, (*s).alloc, ) as *mut libc::c_char; if attempt.is_null() { return 0 as libc::c_int } else { (*s).data = attempt; } return 1 as libc::c_int; }" }, { "index": 1311, "before": "void dstr_delete(dstr *s) { if (s->data) free(s->data); if (s) free(s); }", "after": "pub unsafe extern \"C\" fn dstr_delete(mut s: *mut dstr) { if !((*s).data).is_null() { free((*s).data as *mut libc::c_void); } if !s.is_null() { free(s as *mut libc::c_void); } }" }, { "index": 1312, "before": "void dstr_replace_all(dstr *story, const char *replace, const char *insert) { const size_t replace_l = strlen(replace); const size_t insert_l = strlen(insert); char *start = story->data; while ((start = strstr(start, replace))) { if (!dstr_space(story, insert_l - replace_l)) if (!dstr_grow(story)) err(\"Failed to allocate memory\"); if (insert_l != replace_l) { memmove(start + insert_l, start + replace_l, story->length - (start + replace_l - story->data)); /* Remember to null terminate the data so we can utilize it * as we normally would */ story->length += insert_l - replace_l; story->data[story->length] = 0; } memmove(start, insert, insert_l); } }", "after": "pub unsafe extern \"C\" fn dstr_replace_all( mut story: *mut dstr, mut replace: *const libc::c_char, mut insert: *const libc::c_char, ) { let replace_l: size_t = strlen(replace); let insert_l: size_t = strlen(insert); let mut start: *mut libc::c_char = (*story).data; loop { start = strstr(start, replace); if start.is_null() { break; } if dstr_space(story, insert_l.wrapping_sub(replace_l)) == 0 { if dstr_grow(story) == 0 { fprintf( stderr, b\"Failed to allocate memory\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } } if insert_l != replace_l { memmove( start.offset(insert_l as isize) as *mut libc::c_void, start.offset(replace_l as isize) as *const libc::c_void, ((*story).length) .wrapping_sub( start.offset(replace_l as isize).offset_from((*story).data) as libc::c_long as libc::c_ulong, ), ); (*story) .length = ((*story).length as libc::c_ulong) .wrapping_add(insert_l.wrapping_sub(replace_l)) as size_t as size_t; *((*story).data) .offset((*story).length as isize) = 0 as libc::c_int as libc::c_char; } memmove(start as *mut libc::c_void, insert as *const libc::c_void, insert_l); }; }" }, { "index": 1313, "before": "void madlibs(dstr *story) { static const size_t buffer_size = 128; char insert[buffer_size]; char replace[buffer_size]; char *start, *end = story->data; while (start = strchr(end, '<')) { if (!(end = strchr(start, '>'))) err(\"Malformed brackets in input\"); /* One extra for current char and another for nul byte */ strncpy(replace, start, end - start + 1); replace[end - start + 1] = '\\0'; printf(\"Enter value for field %s: \", replace); fgets(insert, buffer_size, stdin); const size_t il = strlen(insert) - 1; if (insert[il] == '\\n') insert[il] = '\\0'; dstr_replace_all(story, replace, insert); } printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn madlibs(mut story: *mut dstr) { static mut buffer_size: size_t = 128 as libc::c_int as size_t; let vla = buffer_size as usize; let mut insert: Vec:: = ::std::vec::from_elem(0, vla); let vla_0 = buffer_size as usize; let mut replace: Vec:: = ::std::vec::from_elem(0, vla_0); let mut start: *mut libc::c_char = 0 as *mut libc::c_char; let mut end: *mut libc::c_char = (*story).data; loop { start = strchr(end, '<' as i32); if start.is_null() { break; } end = strchr(start, '>' as i32); if end.is_null() { fprintf( stderr, b\"Malformed brackets in input\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } strncpy( replace.as_mut_ptr(), start, (end.offset_from(start) as libc::c_long + 1 as libc::c_int as libc::c_long) as libc::c_ulong, ); *replace .as_mut_ptr() .offset( (end.offset_from(start) as libc::c_long + 1 as libc::c_int as libc::c_long) as isize, ) = '\\0' as i32 as libc::c_char; printf( b\"Enter value for field %s: \\0\" as *const u8 as *const libc::c_char, replace.as_mut_ptr(), ); fgets(insert.as_mut_ptr(), buffer_size as libc::c_int, stdin); let il: size_t = (strlen(insert.as_mut_ptr())) .wrapping_sub(1 as libc::c_int as libc::c_ulong); if *insert.as_mut_ptr().offset(il as isize) as libc::c_int == '\\n' as i32 { *insert.as_mut_ptr().offset(il as isize) = '\\0' as i32 as libc::c_char; } dstr_replace_all(story, replace.as_mut_ptr(), insert.as_mut_ptr()); } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1314, "before": "int main(int argc, char *argv[]) { if (argc < 2) return 0; FILE *fd = fopen(argv[1], \"r\"); if (!fd) err(\"Could not open file: '%s\\n\", argv[1]); dstr *story = readinput(fd); fclose(fd); if (!story) err(\"Failed to allocate memory\"); madlibs(story); printf(\"%s\\n\", story->data); dstr_delete(story); return 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 { return 0 as libc::c_int; } let mut fd: *mut FILE = fopen( *argv.offset(1 as libc::c_int as isize), b\"r\\0\" as *const u8 as *const libc::c_char, ); if fd.is_null() { fprintf( stderr, b\"Could not open file: '%s\\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(1 as libc::c_int as isize), ); exit(1 as libc::c_int); } let mut story: *mut dstr = readinput(fd); fclose(fd); if story.is_null() { fprintf( stderr, b\"Failed to allocate memory\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } madlibs(story); printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, (*story).data); dstr_delete(story); return 0 as libc::c_int; }" }, { "index": 1315, "before": "int empty(queue q) { return q->tail == q->head; }", "after": "pub unsafe extern \"C\" fn empty(mut q: queue) -> libc::c_int { return ((*q).tail == (*q).head) as libc::c_int; }" }, { "index": 1316, "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": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut n: libc::c_int = 0; let mut q: queue = q_new(); i = 0 as libc::c_int; while i < 100000000 as libc::c_int { n = rand(); if n > 2147483647 as libc::c_int / 2 as libc::c_int { enqueue(q, n); } else { dequeue(q, &mut n) == 0; } i += 1; i; } while dequeue(q, &mut n) != 0 {} return 0 as libc::c_int; }" }, { "index": 1317, "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 unsafe extern \"C\" fn dequeue(mut q: queue, mut n: *mut DATA) -> libc::c_int { if (*q).head == (*q).tail { return 0 as libc::c_int; } 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 as libc::c_int as size_t; if (*q).alloc >= 512 as libc::c_int as libc::c_ulong && (*q).tail < ((*q).alloc).wrapping_div(2 as libc::c_int as libc::c_ulong) { (*q) .alloc = ((*q).alloc as libc::c_ulong) .wrapping_div(2 as libc::c_int as libc::c_ulong) as size_t as size_t; (*q) .buf = realloc( (*q).buf as *mut libc::c_void, (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul((*q).alloc), ) as *mut DATA; } } return 1 as libc::c_int; }" }, { "index": 1318, "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 unsafe extern \"C\" fn q_new() -> queue { let mut q: queue = malloc(::core::mem::size_of::() as libc::c_ulong) as queue; (*q).alloc = 4 as libc::c_int as size_t; (*q) .buf = malloc( (::core::mem::size_of::() as libc::c_ulong).wrapping_mul((*q).alloc), ) as *mut DATA; (*q).tail = 0 as libc::c_int as size_t; (*q).head = (*q).tail; return q; }" }, { "index": 1319, "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 unsafe extern \"C\" fn enqueue(mut q: queue, mut n: DATA) { if (*q).tail >= (*q).alloc { (*q).tail = 0 as libc::c_int as size_t; } let fresh0 = (*q).tail; (*q).tail = ((*q).tail).wrapping_add(1); *((*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::() as libc::c_ulong) .wrapping_mul((*q).alloc) .wrapping_mul(2 as libc::c_int as libc::c_ulong), ) as *mut DATA; 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::() as libc::c_ulong) .wrapping_mul(((*q).alloc).wrapping_sub((*q).head)), ); (*q) .head = ((*q).head as libc::c_ulong).wrapping_add((*q).alloc) as size_t as size_t; } else { (*q).tail = (*q).alloc; } (*q) .alloc = ((*q).alloc as libc::c_ulong) .wrapping_mul(2 as libc::c_int as libc::c_ulong) as size_t as size_t; } }" }, { "index": 1320, "before": "void free_numbers(mpz_t* numbers, size_t count) { for (size_t i = 0; i < count; ++i) mpz_clear(numbers[i]); free(numbers); }", "after": "pub unsafe extern \"C\" fn free_numbers(mut numbers: *mut libc::c_int, mut count: size_t) {}" }, { "index": 1321, "before": "bool is_prime(uint32_t n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (uint32_t p = 3; p * p <= n; p += 2) { if (n % p == 0) return false; } return true; }", "after": "pub unsafe extern \"C\" fn is_prime(mut n: uint32_t) -> bool { if n == 2 as libc::c_int as libc::c_uint { return 1 as libc::c_int != 0; } if n < 2 as libc::c_int as libc::c_uint || n.wrapping_rem(2 as libc::c_int as libc::c_uint) == 0 as libc::c_int as libc::c_uint { return 0 as libc::c_int != 0; } let mut p: uint32_t = 3 as libc::c_int as uint32_t; while p.wrapping_mul(p) <= n { if n.wrapping_rem(p) == 0 as libc::c_int as libc::c_uint { return 0 as libc::c_int != 0; } p = (p as libc::c_uint).wrapping_add(2 as libc::c_int as libc::c_uint) as uint32_t as uint32_t; } return 1 as libc::c_int != 0; }" }, { "index": 1322, "before": "void print_nsmooth_numbers(uint32_t n, uint32_t begin, uint32_t count) { uint32_t num = begin + count; mpz_t* numbers = find_nsmooth_numbers(n, num); printf(\"%u: \", n); mpz_out_str(stdout, 10, numbers[begin]); for (uint32_t i = 1; i < count; ++i) { printf(\", \"); mpz_out_str(stdout, 10, numbers[begin + i]); } printf(\"\\n\"); free_numbers(numbers, num); }", "after": "pub unsafe extern \"C\" fn print_nsmooth_numbers( mut n: uint32_t, mut begin: uint32_t, mut count: uint32_t, ) { let mut num: uint32_t = begin.wrapping_add(count); printf(b\"%u: \\0\" as *const u8 as *const libc::c_char, n); let mut i: uint32_t = 1 as libc::c_int as uint32_t; while i < count { printf(b\", \\0\" as *const u8 as *const libc::c_char); i = i.wrapping_add(1); i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1323, "before": "int main() { printf(\"First 25 n-smooth numbers for n = 2 -> 29:\\n\"); for (uint32_t n = 2; n <= 29; ++n) { if (is_prime(n)) print_nsmooth_numbers(n, 0, 25); } printf(\"\\n3 n-smooth numbers starting from 3000th for n = 3 -> 29:\\n\"); for (uint32_t n = 3; n <= 29; ++n) { if (is_prime(n)) print_nsmooth_numbers(n, 2999, 3); } printf(\"\\n20 n-smooth numbers starting from 30,000th for n = 503 -> 521:\\n\"); for (uint32_t n = 503; n <= 521; ++n) { if (is_prime(n)) print_nsmooth_numbers(n, 29999, 20); } return 0; }", "after": "unsafe fn main() -> libc::c_int { printf( b\"First 25 n-smooth numbers for n = 2 -> 29:\\n\\0\" as *const u8 as *const libc::c_char, ); let mut n: uint32_t = 2 as libc::c_int as uint32_t; while n <= 29 as libc::c_int as libc::c_uint { if is_prime(n) { print_nsmooth_numbers( n, 0 as libc::c_int as uint32_t, 25 as libc::c_int as uint32_t, ); } n = n.wrapping_add(1); n; } printf( b\"\\n3 n-smooth numbers starting from 3000th for n = 3 -> 29:\\n\\0\" as *const u8 as *const libc::c_char, ); let mut n_0: uint32_t = 3 as libc::c_int as uint32_t; while n_0 <= 29 as libc::c_int as libc::c_uint { if is_prime(n_0) { print_nsmooth_numbers( n_0, 2999 as libc::c_int as uint32_t, 3 as libc::c_int as uint32_t, ); } n_0 = n_0.wrapping_add(1); n_0; } printf( b\"\\n20 n-smooth numbers starting from 30,000th for n = 503 -> 521:\\n\\0\" as *const u8 as *const libc::c_char, ); let mut n_1: uint32_t = 503 as libc::c_int as uint32_t; while n_1 <= 521 as libc::c_int as libc::c_uint { if is_prime(n_1) { print_nsmooth_numbers( n_1, 29999 as libc::c_int as uint32_t, 20 as libc::c_int as uint32_t, ); } n_1 = n_1.wrapping_add(1); n_1; } return 0 as libc::c_int; }" }, { "index": 1324, "before": "uint32_t find_primes(uint32_t from, uint32_t to, uint32_t** primes) { uint32_t count = 0, buffer_length = 16; uint32_t* buffer = xmalloc(sizeof(uint32_t) * buffer_length); for (uint32_t p = from; p <= to; ++p) { if (is_prime(p)) { if (count >= buffer_length) { uint32_t new_length = buffer_length * 2; if (new_length < count + 1) new_length = count + 1; buffer = xrealloc(buffer, sizeof(uint32_t) * new_length); buffer_length = new_length; } buffer[count++] = p; } } *primes = buffer; return count; }", "after": "pub unsafe extern \"C\" fn find_primes( mut from: uint32_t, mut to: uint32_t, mut primes: *mut *mut uint32_t, ) -> uint32_t { let mut count: uint32_t = 0 as libc::c_int as uint32_t; let mut buffer_length: uint32_t = 16 as libc::c_int as uint32_t; let mut buffer: *mut uint32_t = xmalloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(buffer_length as libc::c_ulong), ) as *mut uint32_t; let mut p: uint32_t = from; while p <= to { if is_prime(p) { if count >= buffer_length { let mut new_length: uint32_t = buffer_length .wrapping_mul(2 as libc::c_int as libc::c_uint); if new_length < count.wrapping_add(1 as libc::c_int as libc::c_uint) { new_length = count.wrapping_add(1 as libc::c_int as libc::c_uint); } buffer = xrealloc( buffer as *mut libc::c_void, (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(new_length as libc::c_ulong), ) as *mut uint32_t; buffer_length = new_length; } let fresh0 = count; count = count.wrapping_add(1); *buffer.offset(fresh0 as isize) = p; } p = p.wrapping_add(1); p; } *primes = buffer; return count; }" }, { "index": 1325, "before": "int main(void) { for (size_t i = 0; i < LEN(animals); i++) { printf(\"There was an old lady who swallowed a %s\\n%s\\n\", animals[i], verses[i]); for (size_t j = i; j > 0 && i < LEN(animals) - 1; j--) { printf(\"She swallowed the %s to catch the %s\\n\", animals[j], animals[j-1]); if (j == 1) { printf(\"%s\\n\", verses[0]); } } } }", "after": "unsafe fn main() -> libc::c_int { let mut i: size_t = 0 as libc::c_int as size_t; while i < (::core::mem::size_of::<[*const libc::c_char; 8]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong) { printf( b\"There was an old lady who swallowed a %s\\n%s\\n\\0\" as *const u8 as *const libc::c_char, animals[i as usize], verses[i as usize], ); let mut j: size_t = i; while j > 0 as libc::c_int as libc::c_ulong && i < (::core::mem::size_of::<[*const libc::c_char; 8]>() as libc::c_ulong) .wrapping_div( ::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong, ) .wrapping_sub(1 as libc::c_int as libc::c_ulong) { printf( b\"She swallowed the %s to catch the %s\\n\\0\" as *const u8 as *const libc::c_char, animals[j as usize], animals[j.wrapping_sub(1 as libc::c_int as libc::c_ulong) as usize], ); if j == 1 as libc::c_int as libc::c_ulong { printf( b\"%s\\n\\0\" as *const u8 as *const libc::c_char, verses[0 as libc::c_int as usize], ); } j = j.wrapping_sub(1); j; } i = i.wrapping_add(1); i; } return 0; }" }, { "index": 1326, "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": "unsafe fn main() -> libc::c_int { let mut a: [[libc::c_int; 10]; 10] = [[0; 10]; 10]; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; srand(time(0 as *mut time_t) as libc::c_uint); i = 0 as libc::c_int; while i < 10 as libc::c_int { j = 0 as libc::c_int; while j < 10 as libc::c_int { a[i as usize][j as usize] = rand() % 20 as libc::c_int + 1 as libc::c_int; j += 1; j; } i += 1; i; } i = 0 as libc::c_int; 's_32: while i < 10 as libc::c_int { j = 0 as libc::c_int; while j < 10 as libc::c_int { printf( b\" %d\\0\" as *const u8 as *const libc::c_char, a[i as usize][j as usize], ); if a[i as usize][j as usize] == 20 as libc::c_int { break 's_32; } j += 1; j; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1327, "before": "double compose_call(compose_functor *this, double x) { return CALL(this->f, CALL(this->g, x)); }", "after": "pub unsafe extern \"C\" fn compose_call( mut this: *mut compose_functor, mut x: libc::c_double, ) -> libc::c_double { return ((*(*this).f).fn_0) .expect( \"non-null function pointer\", )( (*this).f, ((*(*this).g).fn_0).expect(\"non-null function pointer\")((*this).g, x), ); }" }, { "index": 1328, "before": "int main() { double_to_double *my_sin = malloc(sizeof(double_to_double)); my_sin->fn = &sin_call; double_to_double *my_asin = malloc(sizeof(double_to_double)); my_asin->fn = &asin_call; double_to_double *sin_asin = compose(my_sin, my_asin); printf(\"%f\\n\", CALL(sin_asin, 0.5)); /* prints \"0.500000\" */ free(sin_asin); free(my_sin); free(my_asin); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut my_sin: *mut double_to_double = malloc( ::core::mem::size_of::() as libc::c_ulong, ) as *mut double_to_double; (*my_sin) .fn_0 = Some( sin_call as unsafe extern \"C\" fn( *mut double_to_double, libc::c_double, ) -> libc::c_double, ); let mut my_asin: *mut double_to_double = malloc( ::core::mem::size_of::() as libc::c_ulong, ) as *mut double_to_double; (*my_asin) .fn_0 = Some( asin_call as unsafe extern \"C\" fn( *mut double_to_double, libc::c_double, ) -> libc::c_double, ); let mut sin_asin: *mut double_to_double = compose(my_sin, my_asin); printf( b\"%f\\n\\0\" as *const u8 as *const libc::c_char, ((*sin_asin).fn_0).expect(\"non-null function pointer\")(sin_asin, 0.5f64), ); free(sin_asin as *mut libc::c_void); free(my_sin as *mut libc::c_void); free(my_asin as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1329, "before": "double sin_call(double_to_double *this, double x) { return sin(x); }", "after": "pub unsafe extern \"C\" fn sin_call( mut this: *mut double_to_double, mut x: libc::c_double, ) -> libc::c_double { return sin(x); }" }, { "index": 1330, "before": "double asin_call(double_to_double *this, double x) { return asin(x); }", "after": "pub unsafe extern \"C\" fn asin_call( mut this: *mut double_to_double, mut x: libc::c_double, ) -> libc::c_double { return asin(x); }" }, { "index": 1331, "before": "int main() { int i; for (i = 1; i <= 10; i++) { printf(\"%d\", i); printf(i == 10 ? \"\\n\" : \", \"); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; i = 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); printf( if i == 10 as libc::c_int { b\"\\n\\0\" as *const u8 as *const libc::c_char } else { b\", \\0\" as *const u8 as *const libc::c_char }, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1332, "before": "int is_prime(xint x) { pint p; if (x > 5) { if (x < MAX_PRIME) return pbits[x/30] & bit_pos[x % 30]; for (p = 2; p && (xint)p * p <= x; p = next_prime(p)) if (x % p == 0) return 0; return 1; } return x == 2 || x == 3 || x == 5; }", "after": "pub unsafe extern \"C\" fn is_prime(mut x: xint) -> libc::c_int { let mut p: pint = 0; if x > 5 as libc::c_int as libc::c_ulong { if x < !(0 as libc::c_int as pint) as libc::c_ulong { return *pbits .offset(x.wrapping_div(30 as libc::c_int as libc::c_ulong) as isize) as libc::c_int & bit_pos[x.wrapping_rem(30 as libc::c_int as libc::c_ulong) as usize] as libc::c_int; } p = 2 as libc::c_int as pint; while p != 0 && (p as xint).wrapping_mul(p as libc::c_ulong) <= x { if x.wrapping_rem(p as libc::c_ulong) == 0 as libc::c_int as libc::c_ulong { return 0 as libc::c_int; } p = next_prime(p); } return 1 as libc::c_int; } return (x == 2 as libc::c_int as libc::c_ulong || x == 3 as libc::c_int as libc::c_ulong || x == 5 as libc::c_int as libc::c_ulong) as libc::c_int; }" }, { "index": 1333, "before": "int main() { int i, len; pint p = 0; xint f[MAX_FACTORS], po; init_primes(); for (p = 1; p < 64; p++) { po = (1LLU << p) - 1; printf(\"2^%\"PRIuPINT\" - 1 = %\"PRIuXINT, p, po); fflush(stdout); if ((len = decompose(po, f)) > 1) for (i = 0; i < len; i++) printf(\" %c %\"PRIuXINT, i?'x':'=', f[i]); putchar('\\n'); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut len: libc::c_int = 0; let mut p: pint = 0 as libc::c_int as pint; let mut f: [xint; 63] = [0; 63]; let mut po: xint = 0; init_primes(); p = 1 as libc::c_int as pint; while p < 64 as libc::c_int as libc::c_uint { po = ((1 as libc::c_ulonglong) << p) .wrapping_sub(1 as libc::c_int as libc::c_ulonglong) as xint; printf(b\"2^%u - 1 = %lu\\0\" as *const u8 as *const libc::c_char, p, po); fflush(stdout); len = decompose(po, f.as_mut_ptr()); if len > 1 as libc::c_int { i = 0 as libc::c_int; while i < len { printf( b\" %c %lu\\0\" as *const u8 as *const libc::c_char, if i != 0 { 'x' as i32 } else { '=' as i32 }, f[i as usize], ); i += 1; i; } } putchar('\\n' as i32); p = p.wrapping_add(1); p; } return 0 as libc::c_int; }" }, { "index": 1334, "before": "void init_primes() { FILE *fp; pint s, tgt = 4; if (!(pbits = malloc(PBITS))) { perror(\"malloc\"); exit(1); } if ((fp = fopen(\"primebits\", \"r\"))) { fread(pbits, 1, PBITS, fp); fclose(fp); return; } memset(pbits, 255, PBITS); for (s = 7; s <= MAX_PRIME_SQ; s = next_prime(s)) { if (s > tgt) { tgt *= 2; fprintf(stderr, \"sieve %\"PRIuPINT\"\\n\", s); } sieve(s); } fp = fopen(\"primebits\", \"w\"); fwrite(pbits, 1, PBITS, fp); fclose(fp); }", "after": "pub unsafe extern \"C\" fn init_primes() { let mut fp: *mut FILE = 0 as *mut FILE; let mut s: pint = 0; let mut tgt: pint = 4 as libc::c_int as pint; pbits = malloc( (!(0 as libc::c_int as pint)) .wrapping_div(30 as libc::c_int as libc::c_uint) .wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong, ) as *mut uint8_t; if pbits.is_null() { perror(b\"malloc\\0\" as *const u8 as *const libc::c_char); exit(1 as libc::c_int); } fp = fopen( b\"primebits\\0\" as *const u8 as *const libc::c_char, b\"r\\0\" as *const u8 as *const libc::c_char, ); if !fp.is_null() { fread( pbits as *mut libc::c_void, 1 as libc::c_int as libc::c_ulong, (!(0 as libc::c_int as pint)) .wrapping_div(30 as libc::c_int as libc::c_uint) .wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong, fp, ); fclose(fp); return; } memset( pbits as *mut libc::c_void, 255 as libc::c_int, (!(0 as libc::c_int as pint)) .wrapping_div(30 as libc::c_int as libc::c_uint) .wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong, ); s = 7 as libc::c_int as pint; while s <= 65535 as libc::c_uint { if s > tgt { tgt = (tgt as libc::c_uint).wrapping_mul(2 as libc::c_int as libc::c_uint) as pint as pint; fprintf(stderr, b\"sieve %u\\n\\0\" as *const u8 as *const libc::c_char, s); } sieve(s); s = next_prime(s); } fp = fopen( b\"primebits\\0\" as *const u8 as *const libc::c_char, b\"w\\0\" as *const u8 as *const libc::c_char, ); fwrite( pbits as *const libc::c_void, 1 as libc::c_int as libc::c_ulong, (!(0 as libc::c_int as pint)) .wrapping_div(30 as libc::c_int as libc::c_uint) .wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_ulong, fp, ); fclose(fp); }" }, { "index": 1335, "before": "void sieve(pint p) { unsigned char b[8]; off_t ofs[8]; int i, q; for (i = 0; i < 8; i++) { q = rem_num[i] * p; b[i] = ~bit_pos[q % 30]; ofs[i] = q / 30; } for (q = ofs[1], i = 7; i; i--) ofs[i] -= ofs[i-1]; for (ofs[0] = p, i = 1; i < 8; i++) ofs[0] -= ofs[i]; for (i = 1; q < PBITS; q += ofs[i = (i + 1) & 7]) pbits[q] &= b[i]; }", "after": "pub unsafe extern \"C\" fn sieve(mut p: pint) { let mut b: [libc::c_uchar; 8] = [0; 8]; let mut ofs: [off_t; 8] = [0; 8]; let mut i: libc::c_int = 0; let mut q: libc::c_int = 0; i = 0 as libc::c_int; while i < 8 as libc::c_int { q = (rem_num[i as usize] as libc::c_uint).wrapping_mul(p) as libc::c_int; b[i as usize] = !(bit_pos[(q % 30 as libc::c_int) as usize] as libc::c_int) as libc::c_uchar; ofs[i as usize] = (q / 30 as libc::c_int) as off_t; i += 1; i; } q = ofs[1 as libc::c_int as usize] as libc::c_int; i = 7 as libc::c_int; while i != 0 { ofs[i as usize] -= ofs[(i - 1 as libc::c_int) as usize]; i -= 1; i; } ofs[0 as libc::c_int as usize] = p as off_t; i = 1 as libc::c_int; while i < 8 as libc::c_int { ofs[0 as libc::c_int as usize] -= ofs[i as usize]; i += 1; i; } i = 1 as libc::c_int; while (q as libc::c_uint) < (!(0 as libc::c_int as pint)) .wrapping_div(30 as libc::c_int as libc::c_uint) .wrapping_add(1 as libc::c_int as libc::c_uint) { let ref mut fresh0 = *pbits.offset(q as isize); *fresh0 = (*fresh0 as libc::c_int & b[i as usize] as libc::c_int) as uint8_t; i = i + 1 as libc::c_int & 7 as libc::c_int; q = (q as libc::c_long + ofs[i as usize]) as libc::c_int; } }" }, { "index": 1336, "before": "pint next_prime(pint p) { off_t addr; uint8_t bits, rem; if (p > 5) { addr = p / 30; bits = bit_pos[ p % 30 ] << 1; for (rem = 0; (1 << rem) < bits; rem++); while (pbits[addr] < bits || !bits) { if (++addr >= PBITS) return 0; bits = 1; rem = 0; } if (addr >= PBITS) return 0; while (!(pbits[addr] & bits)) { rem++; bits <<= 1; } return p = addr * 30 + rem_num[rem]; } switch(p) { case 2: return 3; case 3: return 5; case 5: return 7; } return 2; }", "after": "pub unsafe extern \"C\" fn next_prime(mut p: pint) -> pint { let mut addr: off_t = 0; let mut bits: uint8_t = 0; let mut rem: uint8_t = 0; if p > 5 as libc::c_int as libc::c_uint { addr = p.wrapping_div(30 as libc::c_int as libc::c_uint) as off_t; bits = ((bit_pos[p.wrapping_rem(30 as libc::c_int as libc::c_uint) as usize] as libc::c_int) << 1 as libc::c_int) as uint8_t; rem = 0 as libc::c_int as uint8_t; while ((1 as libc::c_int) << rem as libc::c_int) < bits as libc::c_int { rem = rem.wrapping_add(1); rem; } while (*pbits.offset(addr as isize) as libc::c_int) < bits as libc::c_int || bits == 0 { addr += 1; if addr >= (!(0 as libc::c_int as pint)) .wrapping_div(30 as libc::c_int as libc::c_uint) .wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_long { return 0 as libc::c_int as pint; } bits = 1 as libc::c_int as uint8_t; rem = 0 as libc::c_int as uint8_t; } if addr >= (!(0 as libc::c_int as pint)) .wrapping_div(30 as libc::c_int as libc::c_uint) .wrapping_add(1 as libc::c_int as libc::c_uint) as libc::c_long { return 0 as libc::c_int as pint; } while *pbits.offset(addr as isize) as libc::c_int & bits as libc::c_int == 0 { rem = rem.wrapping_add(1); rem; bits = ((bits as libc::c_int) << 1 as libc::c_int) as uint8_t; } p = (addr * 30 as libc::c_int as libc::c_long + rem_num[rem as usize] as libc::c_long) as pint; return p; } match p { 2 => return 3 as libc::c_int as pint, 3 => return 5 as libc::c_int as pint, 5 => return 7 as libc::c_int as pint, _ => {} } return 2 as libc::c_int as pint; }" }, { "index": 1337, "before": "int decompose(xint n, xint *f) { pint p = 0; int i = 0; /* check small primes: not strictly necessary */ if (n <= MAX_PRIME && is_prime(n)) { f[0] = n; return 1; } while (n >= (xint)p * p) { if (!(p = next_prime(p))) break; while (n % p == 0) { n /= p; f[i++] = p; } } if (n > 1) f[i++] = n; return i; }", "after": "pub unsafe extern \"C\" fn decompose(mut n: xint, mut f: *mut xint) -> libc::c_int { let mut p: pint = 0 as libc::c_int as pint; let mut i: libc::c_int = 0 as libc::c_int; if n <= !(0 as libc::c_int as pint) as libc::c_ulong && is_prime(n) != 0 { *f.offset(0 as libc::c_int as isize) = n; return 1 as libc::c_int; } while n >= (p as xint).wrapping_mul(p as libc::c_ulong) { p = next_prime(p); if p == 0 { break; } while n.wrapping_rem(p as libc::c_ulong) == 0 as libc::c_int as libc::c_ulong { n = (n as libc::c_ulong).wrapping_div(p as libc::c_ulong) as xint as xint; let fresh1 = i; i = i + 1; *f.offset(fresh1 as isize) = p as xint; } } if n > 1 as libc::c_int as libc::c_ulong { let fresh2 = i; i = i + 1; *f.offset(fresh2 as isize) = n; } return i; }" }, { "index": 1338, "before": "int main() { int j, hmax = 0; int jatmax, n; int *arry; for (j=1; j<100000; j++) { n = hailstone(j, NULL); if (hmax < n) { hmax = n; jatmax = j; } } n = hailstone(27, NULL); arry = malloc(n*sizeof(int)); n = hailstone(27, arry); printf(\"[ %d, %d, %d, %d, ...., %d, %d, %d, %d] len=%d\\n\", arry[0],arry[1],arry[2],arry[3], arry[n-4], arry[n-3], arry[n-2], arry[n-1], n); printf(\"Max %d at j= %d\\n\", hmax, jatmax); free(arry); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut j: libc::c_int = 0; let mut hmax: libc::c_int = 0 as libc::c_int; let mut jatmax: libc::c_int = 0; let mut n: libc::c_int = 0; let mut arry: *mut libc::c_int = 0 as *mut libc::c_int; j = 1 as libc::c_int; while j < 100000 as libc::c_int { n = hailstone(j, 0 as *mut libc::c_int); if hmax < n { hmax = n; jatmax = j; } j += 1; j; } n = hailstone(27 as libc::c_int, 0 as *mut libc::c_int); arry = malloc( (n as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_int; n = hailstone(27 as libc::c_int, arry); printf( b\"[ %d, %d, %d, %d, ...., %d, %d, %d, %d] len=%d\\n\\0\" as *const u8 as *const libc::c_char, *arry.offset(0 as libc::c_int as isize), *arry.offset(1 as libc::c_int as isize), *arry.offset(2 as libc::c_int as isize), *arry.offset(3 as libc::c_int as isize), *arry.offset((n - 4 as libc::c_int) as isize), *arry.offset((n - 3 as libc::c_int) as isize), *arry.offset((n - 2 as libc::c_int) as isize), *arry.offset((n - 1 as libc::c_int) as isize), n, ); printf(b\"Max %d at j= %d\\n\\0\" as *const u8 as *const libc::c_char, hmax, jatmax); free(arry as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1339, "before": "int hailstone(int n, int *arry) { int hs = 1; while (n!=1) { hs++; if (arry) *arry++ = n; n = (n&1) ? (3*n+1) : (n/2); } if (arry) *arry++ = n; return hs; }", "after": "pub unsafe extern \"C\" fn hailstone( mut n: libc::c_int, mut arry: *mut libc::c_int, ) -> libc::c_int { let mut hs: libc::c_int = 1 as libc::c_int; while n != 1 as libc::c_int { hs += 1; hs; if !arry.is_null() { let fresh0 = arry; arry = arry.offset(1); *fresh0 = n; } n = if n & 1 as libc::c_int != 0 { 3 as libc::c_int * n + 1 as libc::c_int } else { n / 2 as libc::c_int }; } if !arry.is_null() { let fresh1 = arry; arry = arry.offset(1); *fresh1 = n; } return hs; }" }, { "index": 1340, "before": "void sieve(int *a, int n) { int i = 0, j = 0; for (i = 2; i <= n; i++) { a[i] = 1; } for (i = 2; i <= n; i++) { printf(\"\\ni:%d\", i); if (a[i] == 1) { for (j = i; (i * j) <= n; j++) { printf(\"\\nj:%d\", j); printf(\"\\nBefore a[%d*%d]: %d\", i, j, a[i * j]); a[(i * j)] = 0; printf(\"\\nAfter a[%d*%d]: %d\", i, j, a[i * j]); } } } printf(\"\\nPrimes numbers from 1 to %d are : \", n); for (i = 2; i <= n; i++) { if (a[i] == 1) printf(\"%d, \", i); } printf(\"\\n\\n\"); }", "after": "pub unsafe extern \"C\" fn sieve(mut a: *mut libc::c_int, mut n: libc::c_int) { let mut i: libc::c_int = 0 as libc::c_int; let mut j: libc::c_int = 0 as libc::c_int; i = 2 as libc::c_int; while i <= n { *a.offset(i as isize) = 1 as libc::c_int; i += 1; i; } i = 2 as libc::c_int; while i <= n { printf(b\"\\ni:%d\\0\" as *const u8 as *const libc::c_char, i); if *a.offset(i as isize) == 1 as libc::c_int { j = i; while i * j <= n { printf(b\"\\nj:%d\\0\" as *const u8 as *const libc::c_char, j); printf( b\"\\nBefore a[%d*%d]: %d\\0\" as *const u8 as *const libc::c_char, i, j, *a.offset((i * j) as isize), ); *a.offset((i * j) as isize) = 0 as libc::c_int; printf( b\"\\nAfter a[%d*%d]: %d\\0\" as *const u8 as *const libc::c_char, i, j, *a.offset((i * j) as isize), ); j += 1; j; } } i += 1; i; } printf( b\"\\nPrimes numbers from 1 to %d are : \\0\" as *const u8 as *const libc::c_char, n, ); i = 2 as libc::c_int; while i <= n { if *a.offset(i as isize) == 1 as libc::c_int { printf(b\"%d, \\0\" as *const u8 as *const libc::c_char, i); } i += 1; i; } printf(b\"\\n\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1341, "before": "int main(void) { int *array, n = 10; array = (int *)malloc((n + 1) * sizeof(int)); sieve(array, n); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut array: *mut libc::c_int = 0 as *mut libc::c_int; let mut n: libc::c_int = 10 as libc::c_int; array = malloc( ((n + 1 as libc::c_int) as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_int; sieve(array, n); return 0 as libc::c_int; }" }, { "index": 1342, "before": "int main() { Delegate del1 = NewDelegate(&thing1); Delegate del2 = NewDelegate(NULL); Delegator theDelegator = NewDelegator( 14, \"A stellar vista, Baby.\"); printf(\"Delegator returns %s\\n\\n\", Delegator_Operation( theDelegator, 3, NULL)); printf(\"Delegator returns %s\\n\\n\", Delegator_Operation( theDelegator, 3, del1)); printf(\"Delegator returns %s\\n\\n\", Delegator_Operation( theDelegator, 3, del2)); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut del1: Delegate = NewDelegate( Some(thing1 as unsafe extern \"C\" fn(libc::c_int) -> *const libc::c_char), ); let mut del2: Delegate = NewDelegate(None); let mut theDelegator: Delegator = NewDelegator( 14 as libc::c_int, b\"A stellar vista, Baby.\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, ); printf( b\"Delegator returns %s\\n\\n\\0\" as *const u8 as *const libc::c_char, Delegator_Operation(theDelegator, 3 as libc::c_int, 0 as Delegate), ); printf( b\"Delegator returns %s\\n\\n\\0\" as *const u8 as *const libc::c_char, Delegator_Operation(theDelegator, 3 as libc::c_int, del1), ); printf( b\"Delegator returns %s\\n\\n\\0\" as *const u8 as *const libc::c_char, Delegator_Operation(theDelegator, 3 as libc::c_int, del2), ); return 0 as libc::c_int; }" }, { "index": 1343, "before": "Delegate NewDelegate( Responder rspndr ) { Delegate dl = malloc(sizeof(struct sDelegate)); dl->operation = rspndr; return dl; }", "after": "pub unsafe extern \"C\" fn NewDelegate(mut rspndr: Responder) -> Delegate { let mut dl: Delegate = malloc(::core::mem::size_of::() as libc::c_ulong) as Delegate; (*dl).operation = rspndr; return dl; }" }, { "index": 1344, "before": "Delegator NewDelegator( int p, char *phrase) { Delegator d = malloc(sizeof(struct sDelegator)); d->param = p; d->phrase = phrase; d->delegate = &defaultDel;\t/* default delegate */ return d; }", "after": "pub unsafe extern \"C\" fn NewDelegator( mut p: libc::c_int, mut phrase: *mut libc::c_char, ) -> Delegator { let mut d: Delegator = malloc(::core::mem::size_of::() as libc::c_ulong) as Delegator; (*d).param = p; (*d).phrase = phrase; (*d).delegate = &mut defaultDel; return d; }" }, { "index": 1345, "before": "int main() { //loop variables int k, n; //necessarily ull for reach big values unsigned long long int num, den; //the nmmber int catalan; //the first is not calculated for the formula printf(\"1 \"); //iterating from 2 to 15 for (n=2; n<=N; ++n) { //initializaing for products num = den = 1; //applying the formula for (k=2; k<=n; ++k) { num *= (n+k); den *= k; catalan = num /den; } //output printf(\"%d \", catalan); } //the end printf(\"\\n\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut k: libc::c_int = 0; let mut n: libc::c_int = 0; let mut num: libc::c_ulonglong = 0; let mut den: libc::c_ulonglong = 0; let mut catalan: libc::c_int = 0; printf(b\"1 \\0\" as *const u8 as *const libc::c_char); n = 2 as libc::c_int; while n <= N { den = 1 as libc::c_int as libc::c_ulonglong; num = den; k = 2 as libc::c_int; while k <= n { num = num.wrapping_mul((n + k) as libc::c_ulonglong); den = den.wrapping_mul(k as libc::c_ulonglong); catalan = num.wrapping_div(den) as libc::c_int; k += 1; k; } printf(b\"%d \\0\" as *const u8 as *const libc::c_char, catalan); n += 1; n; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1346, "before": "int main() { printf(\"%d\\n\", ethiopian(17, 34, true)); return 0; }", "after": "unsafe fn main() -> libc::c_int { printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, ethiopian(17 as libc::c_int, 34 as libc::c_int, 1 as libc::c_int != 0), ); return 0 as libc::c_int; }" }, { "index": 1347, "before": "void halve(int *x) { *x >>= 1; }", "after": "pub unsafe extern \"C\" fn halve(mut x: *mut libc::c_int) { *x >>= 1 as libc::c_int; }" }, { "index": 1348, "before": "void doublit(int *x) { *x <<= 1; }", "after": "pub unsafe extern \"C\" fn doublit(mut x: *mut libc::c_int) { *x <<= 1 as libc::c_int; }" }, { "index": 1349, "before": "int ethiopian(int plier, \t int plicand, const bool tutor) { int result=0; if (tutor) printf(\"ethiopian multiplication of %d by %d\\n\", plier, plicand); while(plier >= 1) { if ( iseven(plier) ) { if (tutor) printf(\"%4d %6d struck\\n\", plier, plicand); } else { if (tutor) printf(\"%4d %6d kept\\n\", plier, plicand); result += plicand; } halve(&plier); doublit(&plicand); } return result; }", "after": "pub unsafe extern \"C\" fn ethiopian( mut plier: libc::c_int, mut plicand: libc::c_int, tutor: bool, ) -> libc::c_int { let mut result: libc::c_int = 0 as libc::c_int; if tutor { printf( b\"ethiopian multiplication of %d by %d\\n\\0\" as *const u8 as *const libc::c_char, plier, plicand, ); } while plier >= 1 as libc::c_int { if iseven(plier) { if tutor { printf( b\"%4d %6d struck\\n\\0\" as *const u8 as *const libc::c_char, plier, plicand, ); } } else { if tutor { printf( b\"%4d %6d kept\\n\\0\" as *const u8 as *const libc::c_char, plier, plicand, ); } result += plicand; } halve(&mut plier); doublit(&mut plicand); } return result; }" }, { "index": 1350, "before": "bool iseven(const int x) { return (x & 1) == 0; }", "after": "pub unsafe extern \"C\" fn iseven(x: libc::c_int) -> bool { return x & 1 as libc::c_int == 0 as libc::c_int; }" }, { "index": 1351, "before": "int main(void) { int n; for( n = 99; n > 2; n-- ) printf( \"%d bottles of beer on the wall, %d bottles of beer.\\n\" \"Take one down and pass it around, %d bottles of beer on the wall.\\n\\n\", n, n, n - 1); printf( \"2 bottles of beer on the wall, 2 bottles of beer.\\n\" \"Take one down and pass it around, 1 bottle of beer on the wall.\\n\\n\" \"1 bottle of beer on the wall, 1 bottle of beer.\\n\" \"Take one down and pass it around, no more bottles of beer on the wall.\\n\\n\" \"No more bottles of beer on the wall, no more bottles of beer.\\n\" \"Go to the store and buy some more, 99 bottles of beer on the wall.\\n\"); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 0; n = 99 as libc::c_int; while n > 2 as libc::c_int { printf( b\"%d bottles of beer on the wall, %d bottles of beer.\\nTake one down and pass it around, %d bottles of beer on the wall.\\n\\n\\0\" as *const u8 as *const libc::c_char, n, n, n - 1 as libc::c_int, ); n -= 1; n; } printf( b\"2 bottles of beer on the wall, 2 bottles of beer.\\nTake one down and pass it around, 1 bottle of beer on the wall.\\n\\n1 bottle of beer on the wall, 1 bottle of beer.\\nTake one down and pass it around, no more bottles of beer on the wall.\\n\\nNo more bottles of beer on the wall, no more bottles of beer.\\nGo to the store and buy some more, 99 bottles of beer on the wall.\\n\\0\" as *const u8 as *const libc::c_char, ); return 0 as libc::c_int; }" }, { "index": 1352, "before": "int main() { \tinteg x = new_integ(sine); \tsleep(2); \tset_input(x, 0); \tusleep(500000); \tprintf(\"%g\\n\", x->v); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut x: integ = new_integ( Some(sine as unsafe extern \"C\" fn(libc::c_double) -> libc::c_double), ); sleep(2 as libc::c_int as libc::c_uint); set_input(x, None); usleep(500000 as libc::c_int as __useconds_t); printf(b\"%g\\n\\0\" as *const u8 as *const libc::c_char, (*x).v); return 0 as libc::c_int; }" }, { "index": 1353, "before": "void update(integ x) { \tstruct timeval tv; \tdouble t, v, (*f)(double); \tf = x->func; \tgettimeofday(&tv, 0); \tt = ((tv.tv_sec - x->start.tv_sec) * 1000000 \t\t+ tv.tv_usec - x->start.tv_usec) * 1e-6; \tv = f ? f(t) : 0; \tx->v += (x->last_v + v) * (t - x->last_t) / 2; \tx->last_t = t; }", "after": "pub unsafe extern \"C\" fn update(mut x: integ) { let mut tv: timeval = timeval { tv_sec: 0, tv_usec: 0 }; let mut t: libc::c_double = 0.; let mut v: libc::c_double = 0.; let mut f: Option:: libc::c_double> = None; f = (*x).func; gettimeofday(&mut tv, 0 as *mut libc::c_void); t = ((tv.tv_sec - (*x).start.tv_sec) * 1000000 as libc::c_int as libc::c_long + tv.tv_usec - (*x).start.tv_usec) as libc::c_double * 1e-6f64; v = if f.is_some() { f.expect(\"non-null function pointer\")(t) } else { 0 as libc::c_int as libc::c_double }; (*x).v += ((*x).last_v + v) * (t - (*x).last_t) / 2 as libc::c_int as libc::c_double; (*x).last_t = t; }" }, { "index": 1354, "before": "double sine(double t) { return sin(4 * atan2(1, 1) * t); }", "after": "pub unsafe extern \"C\" fn sine(mut t: libc::c_double) -> libc::c_double { return sin( 4 as libc::c_int as libc::c_double * atan2( 1 as libc::c_int as libc::c_double, 1 as libc::c_int as libc::c_double, ) * t, ); }" }, { "index": 1355, "before": "int factorial(int num){ if(num==0||num==1) return 1; else return num*factorial(num-1); }", "after": "pub unsafe extern \"C\" fn factorial(mut num: libc::c_int) -> libc::c_int { if num == 0 as libc::c_int || num == 1 as libc::c_int { return 1 as libc::c_int } else { return num * factorial(num - 1 as libc::c_int) }; }" }, { "index": 1356, "before": "int main(int argc,char** argv) { functionPair response; if(argc!=2) return printf(\"Usage : %s \",argv[0]); else{ response = (functionPair){.x = atoi(argv[1]),.funcPtr=&factorial}; printf(\"\\nFactorial of %d is %d\\n\",response.x,response.funcPtr(response.x)); } return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut response: functionPair = functionPair { x: 0, funcPtr: None, }; if argc != 2 as libc::c_int { return printf( b\"Usage : %s \\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ) } else { response = { let mut init = functionPair { x: atoi(*argv.offset(1 as libc::c_int as isize)), funcPtr: Some( factorial as unsafe extern \"C\" fn(libc::c_int) -> libc::c_int, ), }; init }; printf( b\"\\nFactorial of %d is %d\\n\\0\" as *const u8 as *const libc::c_char, response.x, (response.funcPtr).expect(\"non-null function pointer\")(response.x), ); } return 0 as libc::c_int; }" }, { "index": 1357, "before": "uint reverse(uint n) { uint r; for (r = 0; n; n /= 10) r = r*10 + (n%10); return r; }", "after": "pub unsafe extern \"C\" fn reverse(mut n: uint) -> uint { let mut r: uint = 0; r = 0 as libc::c_int as uint; while n != 0 { r = r .wrapping_mul(10 as libc::c_int as libc::c_uint) .wrapping_add(n.wrapping_rem(10 as libc::c_int as libc::c_uint)); n = (n as libc::c_uint).wrapping_div(10 as libc::c_int as libc::c_uint) as uint as uint; } return r; }" }, { "index": 1358, "before": "int main(int argc, char **argv) { uint x, c = 0; switch(argc) { // advanced args parsing case 1: for (x = 11; c < 20; x += 2) if (is_emirp(x)) printf(\" %u\", x), ++c; break; case 2: for (x = 7701; x < 8000; x += 2) if (is_emirp(x)) printf(\" %u\", x); break; default: for (x = 11; ; x += 2) if (is_emirp(x) && ++c == 10000) { printf(\"%u\", x); break; } } putchar('\\n'); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut x: uint = 0; let mut c: uint = 0 as libc::c_int as uint; match argc { 1 => { x = 11 as libc::c_int as uint; while c < 20 as libc::c_int as libc::c_uint { if is_emirp(x) != 0 { printf(b\" %u\\0\" as *const u8 as *const libc::c_char, x); c = c.wrapping_add(1); c; } x = (x as libc::c_uint).wrapping_add(2 as libc::c_int as libc::c_uint) as uint as uint; } } 2 => { x = 7701 as libc::c_int as uint; while x < 8000 as libc::c_int as libc::c_uint { if is_emirp(x) != 0 { printf(b\" %u\\0\" as *const u8 as *const libc::c_char, x); } x = (x as libc::c_uint).wrapping_add(2 as libc::c_int as libc::c_uint) as uint as uint; } } _ => { x = 11 as libc::c_int as uint; loop { if is_emirp(x) != 0 && { c = c.wrapping_add(1); c == 10000 as libc::c_int as libc::c_uint } { printf(b\"%u\\0\" as *const u8 as *const libc::c_char, x); break; } else { x = (x as libc::c_uint) .wrapping_add(2 as libc::c_int as libc::c_uint) as uint as uint; } } } } putchar('\\n' as i32); return 0 as libc::c_int; }" }, { "index": 1359, "before": "int is_prime(uint n) { if (!(n%2) || !(n%3)) return 0; uint p = 1; while(p*p < n) if (n%(p += 4) == 0 || n%(p += 2) == 0) return 0; return 1; }", "after": "pub unsafe extern \"C\" fn is_prime(mut n: uint) -> libc::c_int { if n.wrapping_rem(2 as libc::c_int as libc::c_uint) == 0 || n.wrapping_rem(3 as libc::c_int as libc::c_uint) == 0 { return 0 as libc::c_int; } let mut p: uint = 1 as libc::c_int as uint; while p.wrapping_mul(p) < n { p = (p as libc::c_uint).wrapping_add(4 as libc::c_int as libc::c_uint) as uint as uint; if n.wrapping_rem(p) == 0 as libc::c_int as libc::c_uint || { p = (p as libc::c_uint).wrapping_add(2 as libc::c_int as libc::c_uint) as uint as uint; n.wrapping_rem(p) == 0 as libc::c_int as libc::c_uint } { return 0 as libc::c_int; } } return 1 as libc::c_int; }" }, { "index": 1360, "before": "int is_emirp(uint n) { uint r = reverse(n); return r != n && is_prime(n) && is_prime(r); }", "after": "pub unsafe extern \"C\" fn is_emirp(mut n: uint) -> libc::c_int { let mut r: uint = reverse(n); return (r != n && is_prime(n) != 0 && is_prime(r) != 0) as libc::c_int; }" }, { "index": 1361, "before": "size_t b_read(byte *buf, size_t n_bits, size_t shift, bit_filter bf) { uint32_t accu = bf->accu; int bits = bf->bits; int mask, i = 0; buf += shift / 8; shift %= 8; while (n_bits) { while (bits && n_bits) { mask = 128 >> shift; if (accu & (1 << (bits - 1))) *buf |= mask; else *buf &= ~mask; n_bits--; bits--; if (++shift >= 8) { shift = 0; buf++; } } if (!n_bits) break; accu = (accu << 8) | fgetc(bf->fp); bits += 8; } bf->accu = accu; bf->bits = bits; return i; }", "after": "pub unsafe extern \"C\" fn b_read( mut buf: *mut byte, mut n_bits: size_t, mut shift: size_t, mut bf: bit_filter, ) -> size_t { let mut accu: uint32_t = (*bf).accu; let mut bits: libc::c_int = (*bf).bits; let mut mask: libc::c_int = 0; let mut i: libc::c_int = 0 as libc::c_int; buf = buf.offset(shift.wrapping_div(8 as libc::c_int as libc::c_ulong) as isize); shift = (shift as libc::c_ulong).wrapping_rem(8 as libc::c_int as libc::c_ulong) as size_t as size_t; while n_bits != 0 { while bits != 0 && n_bits != 0 { mask = 128 as libc::c_int >> shift; if accu & ((1 as libc::c_int) << bits - 1 as libc::c_int) as libc::c_uint != 0 { *buf = (*buf as libc::c_int | mask) as byte; } else { *buf = (*buf as libc::c_int & !mask) as byte; } n_bits = n_bits.wrapping_sub(1); n_bits; bits -= 1; bits; shift = shift.wrapping_add(1); if shift >= 8 as libc::c_int as libc::c_ulong { shift = 0 as libc::c_int as size_t; buf = buf.offset(1); buf; } } if n_bits == 0 { break; } accu = accu << 8 as libc::c_int | fgetc((*bf).fp) as libc::c_uint; bits += 8 as libc::c_int; } (*bf).accu = accu; (*bf).bits = bits; return i as size_t; }" }, { "index": 1362, "before": "bit_filter b_attach(FILE *f) { bit_filter b = malloc(sizeof(bit_io_t)); b->bits = b->accu = 0; b->fp = f; return b; }", "after": "pub unsafe extern \"C\" fn b_attach(mut f: *mut FILE) -> bit_filter { let mut b: bit_filter = malloc(::core::mem::size_of::() as libc::c_ulong) as bit_filter; (*b).accu = 0 as libc::c_int as uint32_t; (*b).bits = (*b).accu as libc::c_int; (*b).fp = f; return b; }" }, { "index": 1363, "before": "void b_write(byte *buf, size_t n_bits, size_t shift, bit_filter bf) { uint32_t accu = bf->accu; int bits = bf->bits; buf += shift / 8; shift %= 8; while (n_bits || bits >= 8) { while (bits >= 8) { bits -= 8; fputc(accu >> bits, bf->fp); accu &= (1 << bits) - 1; } while (bits < 8 && n_bits) { accu = (accu << 1) | (((128 >> shift) & *buf) >> (7 - shift)); --n_bits; bits++; if (++shift == 8) { shift = 0; buf++; } } } bf->accu = accu; bf->bits = bits; }", "after": "pub unsafe extern \"C\" fn b_write( mut buf: *mut byte, mut n_bits: size_t, mut shift: size_t, mut bf: bit_filter, ) { let mut accu: uint32_t = (*bf).accu; let mut bits: libc::c_int = (*bf).bits; buf = buf.offset(shift.wrapping_div(8 as libc::c_int as libc::c_ulong) as isize); shift = (shift as libc::c_ulong).wrapping_rem(8 as libc::c_int as libc::c_ulong) as size_t as size_t; while n_bits != 0 || bits >= 8 as libc::c_int { while bits >= 8 as libc::c_int { bits -= 8 as libc::c_int; fputc((accu >> bits) as libc::c_int, (*bf).fp); accu &= (((1 as libc::c_int) << bits) - 1 as libc::c_int) as libc::c_uint; } while bits < 8 as libc::c_int && n_bits != 0 { accu = accu << 1 as libc::c_int | ((128 as libc::c_int >> shift & *buf as libc::c_int) >> (7 as libc::c_int as libc::c_ulong).wrapping_sub(shift)) as libc::c_uint; n_bits = n_bits.wrapping_sub(1); n_bits; bits += 1; bits; shift = shift.wrapping_add(1); if shift == 8 as libc::c_int as libc::c_ulong { shift = 0 as libc::c_int as size_t; buf = buf.offset(1); buf; } } } (*bf).accu = accu; (*bf).bits = bits; }" }, { "index": 1364, "before": "void b_detach(bit_filter bf) { if (bf->bits) { bf->accu <<= 8 - bf->bits; fputc(bf->accu, bf->fp); } free(bf); }", "after": "pub unsafe extern \"C\" fn b_detach(mut bf: bit_filter) { if (*bf).bits != 0 { (*bf).accu <<= 8 as libc::c_int - (*bf).bits; fputc((*bf).accu as libc::c_int, (*bf).fp); } free(bf as *mut libc::c_void); }" }, { "index": 1365, "before": "int main() { unsigned char s[] = \"abcdefghijk\"; unsigned char s2[11] = {0}; int i; FILE *f = fopen(\"test.bin\", \"wb\"); bit_filter b = b_attach(f); /* for each byte in s, write 7 bits skipping 1 */ for (i = 0; i < 10; i++) b_write(s + i, 7, 1, b); b_detach(b); fclose(f); /* read 7 bits and expand to each byte of s2 skipping 1 bit */ f = fopen(\"test.bin\", \"rb\"); b = b_attach(f); for (i = 0; i < 10; i++) b_read(s2 + i, 7, 1, b); b_detach(b); fclose(f); printf(\"%10s\\n\", s2); /* should be the same first 10 bytes as in s */ return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut s: [libc::c_uchar; 12] = *::core::mem::transmute::< &[u8; 12], &mut [libc::c_uchar; 12], >(b\"abcdefghijk\\0\"); let mut s2: [libc::c_uchar; 11] = [ 0 as libc::c_int as libc::c_uchar, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut i: libc::c_int = 0; let mut f: *mut FILE = fopen( b\"test.bin\\0\" as *const u8 as *const libc::c_char, b\"wb\\0\" as *const u8 as *const libc::c_char, ); let mut b: bit_filter = b_attach(f); i = 0 as libc::c_int; while i < 10 as libc::c_int { b_write( s.as_mut_ptr().offset(i as isize), 7 as libc::c_int as size_t, 1 as libc::c_int as size_t, b, ); i += 1; i; } b_detach(b); fclose(f); f = fopen( b\"test.bin\\0\" as *const u8 as *const libc::c_char, b\"rb\\0\" as *const u8 as *const libc::c_char, ); b = b_attach(f); i = 0 as libc::c_int; while i < 10 as libc::c_int { b_read( s2.as_mut_ptr().offset(i as isize), 7 as libc::c_int as size_t, 1 as libc::c_int as size_t, b, ); i += 1; i; } b_detach(b); fclose(f); printf(b\"%10s\\n\\0\" as *const u8 as *const libc::c_char, s2.as_mut_ptr()); return 0 as libc::c_int; }" }, { "index": 1366, "before": "int tri_sel(int x) { return x % 3; }", "after": "pub unsafe extern \"C\" fn tri_sel(mut x: libc::c_int) -> libc::c_int { return x % 3 as libc::c_int; }" }, { "index": 1367, "before": "int even_sel(int x) { return !(x & 1); }", "after": "pub unsafe extern \"C\" fn even_sel(mut x: libc::c_int) -> libc::c_int { return (x & 1 as libc::c_int == 0) as libc::c_int; }" }, { "index": 1368, "before": "int main() { \tint in[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; \tint i, len; \tint *even = grep(in, 10, &len, even_sel, 0); \tprintf(\"Filtered even:\"); \tfor (i = 0; i < len; i++) printf(\" %d\", even[i]); \tprintf(\"\\n\"); \tgrep(in, 8, &len, tri_sel, 1); \tprintf(\"In-place filtered not multiple of 3:\"); \tfor (i = 0; i < len; i++) printf(\" %d\", in[i]); \tprintf(\"\\n\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut in_0: [libc::c_int; 10] = [ 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, 6 as libc::c_int, 7 as libc::c_int, 8 as libc::c_int, 9 as libc::c_int, 10 as libc::c_int, ]; let mut i: libc::c_int = 0; let mut len: libc::c_int = 0; let mut even: *mut libc::c_int = grep( in_0.as_mut_ptr(), 10 as libc::c_int, &mut len, Some(even_sel as unsafe extern \"C\" fn(libc::c_int) -> libc::c_int), 0 as libc::c_int, ); printf(b\"Filtered even:\\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, *even.offset(i as isize)); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); grep( in_0.as_mut_ptr(), 8 as libc::c_int, &mut len, Some(tri_sel as unsafe extern \"C\" fn(libc::c_int) -> libc::c_int), 1 as libc::c_int, ); printf( b\"In-place filtered not multiple of 3:\\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, in_0[i as usize]); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1369, "before": "int main(void) { \tprintf(\"10! = %d\\n\", val); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { printf(b\"10! = %d\\n\\0\" as *const u8 as *const libc::c_char, val); return 0 as libc::c_int; }" }, { "index": 1370, "before": "int main(void) { unsigned int i; int *c = ARRAY_CONCAT(int, a, 5, b, 5); for (i = 0; i < 10; i++) printf(\"%d\\n\", c[i]); free(c); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_uint = 0; let mut c: *mut libc::c_int = array_concat( a.as_ptr() as *const libc::c_void, 5 as libc::c_int as size_t, b.as_ptr() as *const libc::c_void, 5 as libc::c_int as size_t, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; i = 0 as libc::c_int as libc::c_uint; while i < 10 as libc::c_int as libc::c_uint { printf(b\"%d\\n\\0\" as *const u8 as *const libc::c_char, *c.offset(i as isize)); i = i.wrapping_add(1); i; } free(c as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1371, "before": "void show_set(set_t x, const char *name) { \tint i; \tprintf(\"%s is:\", name); \tfor (i = 0; (1U << i) <= x; i++) \t\tif (x & (1U << i)) \t\t\tprintf(\" %d\", i); \tputchar('\\n'); }", "after": "pub unsafe extern \"C\" fn show_set(mut x: set_t, mut name: *const libc::c_char) { let mut i: libc::c_int = 0; printf(b\"%s is:\\0\" as *const u8 as *const libc::c_char, name); i = 0 as libc::c_int; while (1 as libc::c_uint) << i <= x { if x & (1 as libc::c_uint) << i != 0 { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, i); } i += 1; i; } putchar('\\n' as i32); }" }, { "index": 1372, "before": "int main(void) { \tint i; \tset_t a, b, c; \ta = 0; /* empty set */ \tfor (i = 0; i < 10; i += 3) /* add 0 3 6 9 to set a */ \t\ta |= (1U << i); \tshow_set(a, \"a\"); \tfor (i = 0; i < 5; i++) \t\tprintf(\"\\t%d%s in set a\\n\", i, (a & (1U << i)) ? \"\":\" not\"); \tb = a; \tb |= (1U << 5); b |= (1U << 10); /* b is a plus 5, 10 */ \tb &= ~(1U << 0);\t/* sans 0 */ \tshow_set(b, \"b\"); \tshow_set(a | b, \"union(a, b)\"); \tshow_set(c = a & b, \"c = common(a, b)\"); \tshow_set(a & ~b, \"a - b\"); /* diff, not arithmetic minus */ \tshow_set(b & ~a, \"b - a\"); \tprintf(\"b is%s a subset of a\\n\", !(b & ~a) ? \"\" : \" not\"); \tprintf(\"c is%s a subset of a\\n\", !(c & ~a) ? \"\" : \" not\"); \tprintf(\"union(a, b) - common(a, b) %s union(a - b, b - a)\\n\", \t\t((a | b) & ~(a & b)) == ((a & ~b) | (b & ~a)) \t\t\t? \"equals\" : \"does not equal\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut a: set_t = 0; let mut b: set_t = 0; let mut c: set_t = 0; a = 0 as libc::c_int as set_t; i = 0 as libc::c_int; while i < 10 as libc::c_int { a |= (1 as libc::c_uint) << i; i += 3 as libc::c_int; } show_set(a, b\"a\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < 5 as libc::c_int { printf( b\"\\t%d%s in set a\\n\\0\" as *const u8 as *const libc::c_char, i, if a & (1 as libc::c_uint) << i != 0 { b\"\\0\" as *const u8 as *const libc::c_char } else { b\" not\\0\" as *const u8 as *const libc::c_char }, ); i += 1; i; } b = a; b |= (1 as libc::c_uint) << 5 as libc::c_int; b |= (1 as libc::c_uint) << 10 as libc::c_int; b &= !((1 as libc::c_uint) << 0 as libc::c_int); show_set(b, b\"b\\0\" as *const u8 as *const libc::c_char); show_set(a | b, b\"union(a, b)\\0\" as *const u8 as *const libc::c_char); c = a & b; show_set(c, b\"c = common(a, b)\\0\" as *const u8 as *const libc::c_char); show_set(a & !b, b\"a - b\\0\" as *const u8 as *const libc::c_char); show_set(b & !a, b\"b - a\\0\" as *const u8 as *const libc::c_char); printf( b\"b is%s a subset of a\\n\\0\" as *const u8 as *const libc::c_char, if b & !a == 0 { b\"\\0\" as *const u8 as *const libc::c_char } else { b\" not\\0\" as *const u8 as *const libc::c_char }, ); printf( b\"c is%s a subset of a\\n\\0\" as *const u8 as *const libc::c_char, if c & !a == 0 { b\"\\0\" as *const u8 as *const libc::c_char } else { b\" not\\0\" as *const u8 as *const libc::c_char }, ); printf( b\"union(a, b) - common(a, b) %s union(a - b, b - a)\\n\\0\" as *const u8 as *const libc::c_char, if (a | b) & !(a & b) == a & !b | b & !a { b\"equals\\0\" as *const u8 as *const libc::c_char } else { b\"does not equal\\0\" as *const u8 as *const libc::c_char }, ); return 0 as libc::c_int; }" }, { "index": 1373, "before": "void transfer_value(int from, int to, int howmuch) { bool swapped = false; if ((from == to) || (howmuch < 0) || (from < 0) || (to < 0) || (from >= N_BUCKETS) || (to >= N_BUCKETS)) return; if (from > to) { int temp1 = from; from = to; to = temp1; swapped = true; howmuch = -howmuch; } pthread_mutex_lock(&bucket_mutex[from]); pthread_mutex_lock(&bucket_mutex[to]); if (howmuch > buckets[from] && !swapped) howmuch = buckets[from]; if (-howmuch > buckets[to] && swapped) howmuch = -buckets[to]; buckets[from] -= howmuch; buckets[to] += howmuch; pthread_mutex_unlock(&bucket_mutex[from]); pthread_mutex_unlock(&bucket_mutex[to]); }", "after": "pub unsafe extern \"C\" fn transfer_value( mut from: libc::c_int, mut to: libc::c_int, mut howmuch: libc::c_int, ) { let mut swapped: bool = 0 as libc::c_int != 0; if from == to || howmuch < 0 as libc::c_int || from < 0 as libc::c_int || to < 0 as libc::c_int || from >= 15 as libc::c_int || to >= 15 as libc::c_int { return; } if from > to { let mut temp1: libc::c_int = from; from = to; to = temp1; swapped = 1 as libc::c_int != 0; howmuch = -howmuch; } pthread_mutex_lock(&mut *bucket_mutex.as_mut_ptr().offset(from as isize)); pthread_mutex_lock(&mut *bucket_mutex.as_mut_ptr().offset(to as isize)); if howmuch > buckets[from as usize] && !swapped { howmuch = buckets[from as usize]; } if -howmuch > buckets[to as usize] && swapped as libc::c_int != 0 { howmuch = -buckets[to as usize]; } buckets[from as usize] -= howmuch; buckets[to as usize] += howmuch; pthread_mutex_unlock(&mut *bucket_mutex.as_mut_ptr().offset(from as isize)); pthread_mutex_unlock(&mut *bucket_mutex.as_mut_ptr().offset(to as isize)); }" }, { "index": 1374, "before": "void print_buckets() { int i; int sum = 0; for (i = 0; i < N_BUCKETS; i++) pthread_mutex_lock(&bucket_mutex[i]); for (i = 0; i < N_BUCKETS; i++) { printf(\"%3d \", buckets[i]); sum += buckets[i]; } printf(\"= %d\\n\", sum); for (i = 0; i < N_BUCKETS; i++) pthread_mutex_unlock(&bucket_mutex[i]); }", "after": "pub unsafe extern \"C\" fn print_buckets() { let mut i: libc::c_int = 0; let mut sum: libc::c_int = 0 as libc::c_int; i = 0 as libc::c_int; while i < 15 as libc::c_int { pthread_mutex_lock(&mut *bucket_mutex.as_mut_ptr().offset(i as isize)); i += 1; i; } i = 0 as libc::c_int; while i < 15 as libc::c_int { printf(b\"%3d \\0\" as *const u8 as *const libc::c_char, buckets[i as usize]); sum += buckets[i as usize]; i += 1; i; } printf(b\"= %d\\n\\0\" as *const u8 as *const libc::c_char, sum); i = 0 as libc::c_int; while i < 15 as libc::c_int { pthread_mutex_unlock(&mut *bucket_mutex.as_mut_ptr().offset(i as isize)); i += 1; i; } }" }, { "index": 1375, "before": "int main() { int i, total = 0; for (i = 0; i < N_BUCKETS; i++) pthread_mutex_init(&bucket_mutex[i], NULL); for (i = 0; i < N_BUCKETS; i++) { buckets[i] = rand() % 100; total += buckets[i]; printf(\"%3d \", buckets[i]); } printf(\"= %d\\n\", total); // we should check if these succeeded pthread_create(&equalizer, NULL, equalizer_start, NULL); pthread_create(&randomizer, NULL, randomizer_start, NULL); for (int i = 0; i < 2; i++) { sleep(1); print_buckets(); } // we do not provide a \"good\" way to stop this run, so the following // is never reached indeed... for (i = 0; i < N_BUCKETS; i++) pthread_mutex_destroy(bucket_mutex + i); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut total: libc::c_int = 0 as libc::c_int; i = 0 as libc::c_int; while i < 15 as libc::c_int { pthread_mutex_init( &mut *bucket_mutex.as_mut_ptr().offset(i as isize), 0 as *const pthread_mutexattr_t, ); i += 1; i; } i = 0 as libc::c_int; while i < 15 as libc::c_int { buckets[i as usize] = rand() % 100 as libc::c_int; total += buckets[i as usize]; printf(b\"%3d \\0\" as *const u8 as *const libc::c_char, buckets[i as usize]); i += 1; i; } printf(b\"= %d\\n\\0\" as *const u8 as *const libc::c_char, total); pthread_create( &mut equalizer, 0 as *const pthread_attr_t, Some( equalizer_start as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void, ), 0 as *mut libc::c_void, ); pthread_create( &mut randomizer, 0 as *const pthread_attr_t, Some( randomizer_start as unsafe extern \"C\" fn(*mut libc::c_void) -> *mut libc::c_void, ), 0 as *mut libc::c_void, ); let mut i_0: libc::c_int = 0 as libc::c_int; while i_0 < 2 as libc::c_int { sleep(1 as libc::c_int as libc::c_uint); print_buckets(); i_0 += 1; i_0; } i = 0 as libc::c_int; while i < 15 as libc::c_int { pthread_mutex_destroy(bucket_mutex.as_mut_ptr().offset(i as isize)); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1376, "before": "void HashAddH( KeyType key, ValType value, KeyCopyF copyKey, ValCopyF copyVal, KeyHashF hashKey, KeyCmprF keySame ) { unsigned hix = (*hashKey)(key, HASH_SIZE); MapEntry m_ent; for (m_ent= hash[hix].first; m_ent && !(*keySame)(m_ent->key,key); m_ent=m_ent->link); if (m_ent) { (*copyVal)(&m_ent->value, value); } else { MapEntry last; MapEntry hme = malloc(sizeof(struct sHme)); (*copyKey)(&hme->key, key); (*copyVal)(&hme->value, value); hme->link = NULL; last = hash[hix].last; if (last) { //\t printf(\"Dup. hash key\\n\"); last->link = hme; } else hash[hix].first = hme; hash[hix].last = hme; } }", "after": "pub unsafe extern \"C\" fn HashAddH( mut key: *const libc::c_char, mut value: libc::c_int, mut copyKey: KeyCopyF, mut copyVal: ValCopyF, mut hashKey: KeyHashF, mut keySame: KeyCmprF, ) { let mut hix: libc::c_uint = (Some(hashKey.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")(key, 4096 as libc::c_int); let mut m_ent: MapEntry = 0 as *mut sHme; m_ent = hash[hix as usize].first; while !m_ent.is_null() && (Some(keySame.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")((*m_ent).key, key) == 0 { m_ent = (*m_ent).link; } if !m_ent.is_null() { (Some(copyVal.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")(&mut (*m_ent).value, value); } else { let mut last: MapEntry = 0 as *mut sHme; let mut hme: MapEntry = malloc(::core::mem::size_of::() as libc::c_ulong) as MapEntry; (Some(copyKey.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")(&mut (*hme).key, key); (Some(copyVal.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")(&mut (*hme).value, value); (*hme).link = 0 as *mut sHme; last = hash[hix as usize].last; if !last.is_null() { (*last).link = hme; } else { hash[hix as usize].first = hme; } hash[hix as usize].last = hme; }; }" }, { "index": 1377, "before": "void HashAdd( KeyType key, ValType value ) { HashAddH( key, value, ©Str, ©Int, &strhashkey, &strCompare); }", "after": "pub unsafe extern \"C\" fn HashAdd(mut key: *const libc::c_char, mut value: libc::c_int) { HashAddH( key, value, Some( copyStr as unsafe extern \"C\" fn( *mut *const libc::c_char, *const libc::c_char, ) -> (), ), Some(copyInt as unsafe extern \"C\" fn(*mut libc::c_int, libc::c_int) -> ()), Some( strhashkey as unsafe extern \"C\" fn(*const libc::c_char, libc::c_int) -> libc::c_uint, ), Some( strCompare as unsafe extern \"C\" fn( *const libc::c_char, *const libc::c_char, ) -> libc::c_int, ), ); }" }, { "index": 1378, "before": "int strCompare( const char *key1, const char *key2) { return strcmp(key1, key2) == 0; }", "after": "pub unsafe extern \"C\" fn strCompare( mut key1: *const libc::c_char, mut key2: *const libc::c_char, ) -> libc::c_int { return (strcmp(key1, key2) == 0 as libc::c_int) as libc::c_int; }" }, { "index": 1379, "before": "int HashGetH(ValType *val, KeyType key, KeyHashF hashKey, KeyCmprF keySame ) { unsigned hix = (*hashKey)(key, HASH_SIZE); MapEntry m_ent; for (m_ent= hash[hix].first; m_ent && !(*keySame)(m_ent->key,key); m_ent=m_ent->link); if (m_ent) { *val = m_ent->value; } return (m_ent != NULL); }", "after": "pub unsafe extern \"C\" fn HashGetH( mut val: *mut libc::c_int, mut key: *const libc::c_char, mut hashKey: KeyHashF, mut keySame: KeyCmprF, ) -> libc::c_int { let mut hix: libc::c_uint = (Some(hashKey.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")(key, 4096 as libc::c_int); let mut m_ent: MapEntry = 0 as *mut sHme; m_ent = hash[hix as usize].first; while !m_ent.is_null() && (Some(keySame.expect(\"non-null function pointer\"))) .expect(\"non-null function pointer\")((*m_ent).key, key) == 0 { m_ent = (*m_ent).link; } if !m_ent.is_null() { *val = (*m_ent).value; } return (m_ent != 0 as *mut libc::c_void as MapEntry) as libc::c_int; }" }, { "index": 1380, "before": "void copyStr(const char**dest, const char *src) { *dest = strdup(src); }", "after": "pub unsafe extern \"C\" fn copyStr( mut dest: *mut *const libc::c_char, mut src: *const libc::c_char, ) { *dest = strdup(src); }" }, { "index": 1381, "before": "int HashGet(ValType *val, KeyType key) { return HashGetH( val, key, &strhashkey, &strCompare); }", "after": "pub unsafe extern \"C\" fn HashGet( mut val: *mut libc::c_int, mut key: *const libc::c_char, ) -> libc::c_int { return HashGetH( val, key, Some( strhashkey as unsafe extern \"C\" fn(*const libc::c_char, libc::c_int) -> libc::c_uint, ), Some( strCompare as unsafe extern \"C\" fn( *const libc::c_char, *const libc::c_char, ) -> libc::c_int, ), ); }" }, { "index": 1382, "before": "void copyInt( int *dest, int src) { *dest = src; }", "after": "pub unsafe extern \"C\" fn copyInt(mut dest: *mut libc::c_int, mut src: libc::c_int) { *dest = src; }" }, { "index": 1383, "before": "int main() { static const char * keyList[] = {\"red\",\"orange\",\"yellow\",\"green\", \"blue\", \"violet\" }; static int valuList[] = {1,43,640, 747, 42, 42}; int ix; for (ix=0; ix<6; ix++) { HashAdd(keyList[ix], valuList[ix]); } return 0; }", "after": "unsafe fn main() -> libc::c_int { static mut keyList: [*const libc::c_char; 6] = [ b\"red\\0\" as *const u8 as *const libc::c_char, b\"orange\\0\" as *const u8 as *const libc::c_char, b\"yellow\\0\" as *const u8 as *const libc::c_char, b\"green\\0\" as *const u8 as *const libc::c_char, b\"blue\\0\" as *const u8 as *const libc::c_char, b\"violet\\0\" as *const u8 as *const libc::c_char, ]; static mut valuList: [libc::c_int; 6] = [ 1 as libc::c_int, 43 as libc::c_int, 640 as libc::c_int, 747 as libc::c_int, 42 as libc::c_int, 42 as libc::c_int, ]; let mut ix: libc::c_int = 0; ix = 0 as libc::c_int; while ix < 6 as libc::c_int { HashAdd(keyList[ix as usize], valuList[ix as usize]); ix += 1; ix; } return 0 as libc::c_int; }" }, { "index": 1384, "before": "void printMagicSquare(int** square,int rows){ \tint i,j,baseWidth = numDigits(rows*rows) + 3; \tprintf(\"Doubly Magic Square of Order : %d and Magic Constant : %d\\n\\n\",rows,(rows * rows + 1) * rows / 2); \tfor(i=0;i\",argV[0]); \telse{ \t\tn = atoi(argV[1]); \t\tprintMagicSquare(doublyEvenMagicSquare(n),n); \t} \treturn 0; }", "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 \\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(doublyEvenMagicSquare(n), n); } return 0 as libc::c_int; }" }, { "index": 1386, "before": "int numDigits(int n){ \tint count = 1; \twhile(n>=10){ \t\tn /= 10; \t\tcount++; \t} \treturn count; }", "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": 1387, "before": "int main() { const char * romans[] = { \"MCmxC\", \"MMVIII\", \"MDClXVI\", \"MCXLUJ\" }; int i; for (i = 0; i < 4; i++) printf(\"%s\\t%d\\n\", romans[i], decode(romans[i])); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut romans: [*const libc::c_char; 4] = [ b\"MCmxC\\0\" as *const u8 as *const libc::c_char, b\"MMVIII\\0\" as *const u8 as *const libc::c_char, b\"MDClXVI\\0\" as *const u8 as *const libc::c_char, b\"MCXLUJ\\0\" as *const u8 as *const libc::c_char, ]; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 4 as libc::c_int { printf( b\"%s\\t%d\\n\\0\" as *const u8 as *const libc::c_char, romans[i as usize], decode(romans[i as usize]), ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1388, "before": "int decode(const char * roman) { const char *bigger; int current; int arabic = 0; while (*roman != '\\0') { current = VALUE(*roman); /* if (!current) return -1; note: -1 can be used as error code; Romans didn't even have zero */ bigger = roman; /* look for a larger digit, like IV or XM */ while (VALUE(*bigger) <= current && *++bigger != '\\0'); if (*bigger == '\\0') arabic += current; else { arabic += VALUE(*bigger); while (roman < bigger) arabic -= VALUE(* (roman++) ); } roman ++; } return arabic; }", "after": "pub unsafe extern \"C\" fn decode(mut roman: *const libc::c_char) -> libc::c_int { let mut bigger: *const libc::c_char = 0 as *const libc::c_char; let mut current: libc::c_int = 0; let mut arabic: libc::c_int = 0 as libc::c_int; while *roman as libc::c_int != '\\0' as i32 { current = digits[((!(0x20 as libc::c_int) & *roman as libc::c_int) - 'A' as i32) as usize]; bigger = roman; while digits[((!(0x20 as libc::c_int) & *bigger as libc::c_int) - 'A' as i32) as usize] <= current && { bigger = bigger.offset(1); *bigger as libc::c_int != '\\0' as i32 } {} if *bigger as libc::c_int == '\\0' as i32 { arabic += current; } else { arabic += digits[((!(0x20 as libc::c_int) & *bigger as libc::c_int) - 'A' as i32) as usize]; while roman < bigger { let fresh0 = roman; roman = roman.offset(1); arabic -= digits[((!(0x20 as libc::c_int) & *fresh0 as libc::c_int) - 'A' as i32) as usize]; } } roman = roman.offset(1); roman; } return arabic; }" }, { "index": 1389, "before": "ulong ipow(const uint x, const uint y) { ulong result = 1; for (uint i = 1; i <= y; i++) result *= x; return result; }", "after": "pub unsafe extern \"C\" fn ipow(x: uint, y: uint) -> ulong { let mut result: ulong = 1 as libc::c_int as ulong; let mut i: uint = 1 as libc::c_int as uint; while i <= y { result = (result as libc::c_ulong).wrapping_mul(x as libc::c_ulong) as ulong as ulong; i = i.wrapping_add(1); i; } return result; }" }, { "index": 1390, "before": "void throw_die(const uint n_sides, const uint n_dice, const uint s, uint counts[]) { if (n_dice == 0) { counts[s]++; return; } for (uint i = 1; i < n_sides + 1; i++) throw_die(n_sides, n_dice - 1, s + i, counts); }", "after": "pub unsafe extern \"C\" fn throw_die( n_sides: uint, n_dice: uint, s: uint, mut counts: *mut uint, ) { if n_dice == 0 as libc::c_int as libc::c_uint { let ref mut fresh0 = *counts.offset(s as isize); *fresh0 = (*fresh0).wrapping_add(1); *fresh0; return; } let mut i: uint = 1 as libc::c_int as uint; while i < n_sides.wrapping_add(1 as libc::c_int as libc::c_uint) { throw_die( n_sides, n_dice.wrapping_sub(1 as libc::c_int as libc::c_uint), s.wrapping_add(i), counts, ); i = i.wrapping_add(1); i; } }" }, { "index": 1391, "before": "double beating_probability(const uint n_sides1, const uint n_dice1, const uint n_sides2, const uint n_dice2) { const uint len1 = (n_sides1 + 1) * n_dice1; uint C1[len1]; for (uint i = 0; i < len1; i++) C1[i] = 0; throw_die(n_sides1, n_dice1, 0, C1); const uint len2 = (n_sides2 + 1) * n_dice2; uint C2[len2]; for (uint j = 0; j < len2; j++) C2[j] = 0; throw_die(n_sides2, n_dice2, 0, C2); const double p12 = (double)(ipow(n_sides1, n_dice1) * ipow(n_sides2, n_dice2)); double tot = 0; for (uint i = 0; i < len1; i++) for (uint j = 0; j < min(i, len2); j++) tot += (double)C1[i] * C2[j] / p12; return tot; }", "after": "pub unsafe extern \"C\" fn beating_probability( n_sides1: uint, n_dice1: uint, n_sides2: uint, n_dice2: uint, ) -> libc::c_double { let len1: uint = n_sides1 .wrapping_add(1 as libc::c_int as libc::c_uint) .wrapping_mul(n_dice1); let vla = len1 as usize; let mut C1: Vec:: = ::std::vec::from_elem(0, vla); let mut i: uint = 0 as libc::c_int as uint; while i < len1 { *C1.as_mut_ptr().offset(i as isize) = 0 as libc::c_int as uint; i = i.wrapping_add(1); i; } throw_die(n_sides1, n_dice1, 0 as libc::c_int as uint, C1.as_mut_ptr()); let len2: uint = n_sides2 .wrapping_add(1 as libc::c_int as libc::c_uint) .wrapping_mul(n_dice2); let vla_0 = len2 as usize; let mut C2: Vec:: = ::std::vec::from_elem(0, vla_0); let mut j: uint = 0 as libc::c_int as uint; while j < len2 { *C2.as_mut_ptr().offset(j as isize) = 0 as libc::c_int as uint; j = j.wrapping_add(1); j; } throw_die(n_sides2, n_dice2, 0 as libc::c_int as uint, C2.as_mut_ptr()); let p12: libc::c_double = (ipow(n_sides1, n_dice1)) .wrapping_mul(ipow(n_sides2, n_dice2)) as libc::c_double; let mut tot: libc::c_double = 0 as libc::c_int as libc::c_double; let mut i_0: uint = 0 as libc::c_int as uint; while i_0 < len1 { let mut j_0: uint = 0 as libc::c_int as uint; while j_0 < min(i_0, len2) { tot += *C1.as_mut_ptr().offset(i_0 as isize) as libc::c_double * *C2.as_mut_ptr().offset(j_0 as isize) as libc::c_double / p12; j_0 = j_0.wrapping_add(1); j_0; } i_0 = i_0.wrapping_add(1); i_0; } return tot; }" }, { "index": 1392, "before": "int main() { printf(\"%1.16f\\n\", beating_probability(4, 9, 6, 6)); printf(\"%1.16f\\n\", beating_probability(10, 5, 7, 6)); return 0; }", "after": "unsafe fn main() -> libc::c_int { printf( b\"%1.16f\\n\\0\" as *const u8 as *const libc::c_char, beating_probability( 4 as libc::c_int as uint, 9 as libc::c_int as uint, 6 as libc::c_int as uint, 6 as libc::c_int as uint, ), ); printf( b\"%1.16f\\n\\0\" as *const u8 as *const libc::c_char, beating_probability( 10 as libc::c_int as uint, 5 as libc::c_int as uint, 7 as libc::c_int as uint, 6 as libc::c_int as uint, ), ); return 0 as libc::c_int; }" }, { "index": 1393, "before": "uint min(const uint x, const uint y) { return (x < y) ? x : y; }", "after": "pub unsafe extern \"C\" fn min(x: uint, y: uint) -> uint { return if x < y { x } else { y }; }" }, { "index": 1394, "before": "void decode(int* pass,int size,char *sym) { int i,index; char c; char table[]=\"abcdefghijklmnopqrstuvwxyz\"; for(i=0;i(b\"abcdefghijklmnopqrstuvwxyz\\0\"); i = 0 as libc::c_int; while i < size { c = table[*pass.offset(i as isize) as usize]; index = move_to_front(table.as_mut_ptr(), c); if *pass.offset(i as isize) != index { printf(b\"there is an error\\0\" as *const u8 as *const libc::c_char); } *sym.offset(i as isize) = c; i += 1; i; } *sym.offset(size as isize) = '\\0' as i32 as libc::c_char; }" }, { "index": 1395, "before": "int main() { char sym[3][MAX_SIZE]={\"broood\",\"bananaaa\",\"hiphophiphop\"}; int pass[MAX_SIZE]={0}; int i,len,j; for(i=0;i<3;i++) { len=strlen(sym[i]); encode(sym[i],len,pass); printf(\"%s : [\",sym[i]); for(j=0;j libc::c_int { let mut sym: [[libc::c_char; 100]; 3] = [ *::core::mem::transmute::< &[u8; 100], &mut [libc::c_char; 100], >( b\"broood\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\", ), *::core::mem::transmute::< &[u8; 100], &mut [libc::c_char; 100], >( b\"bananaaa\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\", ), *::core::mem::transmute::< &[u8; 100], &mut [libc::c_char; 100], >( b\"hiphophiphop\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\", ), ]; let mut pass: [libc::c_int; 100] = [ 0 as libc::c_int, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; let mut i: libc::c_int = 0; let mut len: libc::c_int = 0; let mut j: libc::c_int = 0; i = 0 as libc::c_int; while i < 3 as libc::c_int { len = strlen((sym[i as usize]).as_mut_ptr()) as libc::c_int; encode((sym[i as usize]).as_mut_ptr(), len, pass.as_mut_ptr()); printf( b\"%s : [\\0\" as *const u8 as *const libc::c_char, (sym[i as usize]).as_mut_ptr(), ); j = 0 as libc::c_int; while j < len { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, pass[j as usize]); j += 1; j; } printf(b\"]\\n\\0\" as *const u8 as *const libc::c_char); if check((sym[i as usize]).as_mut_ptr(), len, pass.as_mut_ptr()) != 0 { printf(b\"Correct :)\\n\\0\" as *const u8 as *const libc::c_char); } else { printf(b\"Incorrect :(\\n\\0\" as *const u8 as *const libc::c_char); } i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1396, "before": "int move_to_front(char *str,char c) { char *q,*p; int shift=0; p=(char *)malloc(strlen(str)+1); strcpy(p,str); q=strchr(p,c); //returns pointer to location of char c in string str shift=q-p; // no of characters from 0 to position of c in str strncpy(str+1,p,shift); str[0]=c; free(p); // printf(\"\\n%s\\n\",str); return shift; }", "after": "pub unsafe extern \"C\" fn move_to_front( mut str: *mut libc::c_char, mut c: libc::c_char, ) -> libc::c_int { let mut q: *mut libc::c_char = 0 as *mut libc::c_char; let mut p: *mut libc::c_char = 0 as *mut libc::c_char; let mut shift: libc::c_int = 0 as libc::c_int; p = malloc((strlen(str)).wrapping_add(1 as libc::c_int as libc::c_ulong)) as *mut libc::c_char; strcpy(p, str); q = strchr(p, c as libc::c_int); shift = q.offset_from(p) as libc::c_long as libc::c_int; strncpy(str.offset(1 as libc::c_int as isize), p, shift as libc::c_ulong); *str.offset(0 as libc::c_int as isize) = c; free(p as *mut libc::c_void); return shift; }" }, { "index": 1397, "before": "void encode(char *sym,int size,int *pass) { int i=0; char c; char table[]=\"abcdefghijklmnopqrstuvwxyz\"; for(i=0;i(b\"abcdefghijklmnopqrstuvwxyz\\0\"); i = 0 as libc::c_int; while i < size { c = *sym.offset(i as isize); *pass.offset(i as isize) = move_to_front(table.as_mut_ptr(), c); i += 1; i; } }" }, { "index": 1398, "before": "int check(char *sym,int size,int *pass) { int *pass2=malloc(sizeof(int)*size); char *sym2=malloc(sizeof(char)*size); int i,val=1; encode(sym,size,pass2); i=0; while(i libc::c_int { let mut pass2: *mut libc::c_int = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(size as libc::c_ulong), ) as *mut libc::c_int; let mut sym2: *mut libc::c_char = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(size as libc::c_ulong), ) as *mut libc::c_char; let mut i: libc::c_int = 0; let mut val: libc::c_int = 1 as libc::c_int; encode(sym, size, pass2); i = 0 as libc::c_int; while i < size && *pass.offset(i as isize) == *pass2.offset(i as isize) { i += 1; i; } if i != size { val = 0 as libc::c_int; } decode(pass, size, sym2); if strcmp(sym, sym2) != 0 as libc::c_int { val = 0 as libc::c_int; } free(sym2 as *mut libc::c_void); free(pass2 as *mut libc::c_void); return val; }" }, { "index": 1399, "before": "void add_number(int x) { \tprintf(\"%d \", x); }", "after": "pub unsafe extern \"C\" fn add_number(mut x: libc::c_int) { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, x); }" }, { "index": 1400, "before": "int get_list(const char *s, char **e) { \tint x; \twhile (1) { \t\tskip_space; \t\tif (!get_rnge(s, e) && !get_number(x, s, e)) break; \t\ts = *e; \t\tskip_space; \t\tif ((*s) == '\\0') { putchar('\\n'); return 1; } \t\tif ((*s) == ',') { s++; continue; } \t\tbreak; \t} \t*(const char **)e = s; \tprintf(\"\\nSyntax error at %s\\n\", s); \treturn 0; }", "after": "pub unsafe extern \"C\" fn get_list( mut s: *const libc::c_char, mut e: *mut *mut libc::c_char, ) -> libc::c_int { let mut x: libc::c_int = 0; loop { while *(*__ctype_b_loc()).offset(*s as libc::c_int as isize) as libc::c_int & _ISspace as libc::c_int as libc::c_ushort as libc::c_int != 0 { s = s.offset(1); s; } if get_rnge(s, e) == 0 && { x = strtol(s, e, 10 as libc::c_int) as libc::c_int; !(*e != s as *mut libc::c_char) } { break; } s = *e; while *(*__ctype_b_loc()).offset(*s as libc::c_int as isize) as libc::c_int & _ISspace as libc::c_int as libc::c_ushort as libc::c_int != 0 { s = s.offset(1); s; } if *s as libc::c_int == '\\0' as i32 { putchar('\\n' as i32); return 1 as libc::c_int; } if !(*s as libc::c_int == ',' as i32) { break; } s = s.offset(1); s; } let ref mut fresh0 = *(e as *mut *const libc::c_char); *fresh0 = s; printf(b\"\\nSyntax error at %s\\n\\0\" as *const u8 as *const libc::c_char, s); return 0 as libc::c_int; }" }, { "index": 1401, "before": "int main() { \tchar *end; \t/* this is correct */ \tif (get_list(\"-6,-3--1,3-5,7-11,14,15,17-20\", &end)) puts(\"Ok\"); \t/* this is not. note the subtle error: \"-6 -3\" is parsed \t * as range(-6, 3), so synax error comes after that */ \tget_list(\"-6 -3--1,3-5,7-11,14,15,17-20\", &end); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut end: *mut libc::c_char = 0 as *mut libc::c_char; if get_list( b\"-6,-3--1,3-5,7-11,14,15,17-20\\0\" as *const u8 as *const libc::c_char, &mut end, ) != 0 { puts(b\"Ok\\0\" as *const u8 as *const libc::c_char); } get_list( b\"-6 -3--1,3-5,7-11,14,15,17-20\\0\" as *const u8 as *const libc::c_char, &mut end, ); return 0 as libc::c_int; }" }, { "index": 1402, "before": "int get_rnge(const char *s, char **e) { \tint x, y; \tchar *ee; \tif (!get_number(x, s, &ee)) return 0; \ts = ee; \tskip_space; \tif (*s != '-') { \t\t*(const char **)e = s; \t\treturn 0; \t} \ts++; \tif(!get_number(y, s, e)) return 0; \treturn add_range(x, y); }", "after": "pub unsafe extern \"C\" fn get_rnge( mut s: *const libc::c_char, mut e: *mut *mut libc::c_char, ) -> libc::c_int { let mut x: libc::c_int = 0; let mut y: libc::c_int = 0; let mut ee: *mut libc::c_char = 0 as *mut libc::c_char; x = strtol(s, &mut ee, 10 as libc::c_int) as libc::c_int; if !(ee != s as *mut libc::c_char) { return 0 as libc::c_int; } s = ee; while *(*__ctype_b_loc()).offset(*s as libc::c_int as isize) as libc::c_int & _ISspace as libc::c_int as libc::c_ushort as libc::c_int != 0 { s = s.offset(1); s; } if *s as libc::c_int != '-' as i32 { let ref mut fresh1 = *(e as *mut *const libc::c_char); *fresh1 = s; return 0 as libc::c_int; } s = s.offset(1); s; y = strtol(s, e, 10 as libc::c_int) as libc::c_int; if !(*e != s as *mut libc::c_char) { return 0 as libc::c_int; } return add_range(x, y); }" }, { "index": 1403, "before": "int add_range(int x, int y) { \tif (y <= x) return 0; \twhile (x <= y) printf(\"%d \", x++); \treturn 1; }", "after": "pub unsafe extern \"C\" fn add_range( mut x: libc::c_int, mut y: libc::c_int, ) -> libc::c_int { if y <= x { return 0 as libc::c_int; } while x <= y { let fresh2 = x; x = x + 1; printf(b\"%d \\0\" as *const u8 as *const libc::c_char, fresh2); } return 1 as libc::c_int; }" }, { "index": 1404, "before": "int main() { \tint i, x, y, r2; \tunsigned long buf[31] = {0}; /* could just use 2d array */ \tfor (i = 0; i < 100;) \t{ \t\tx = randn(31) - 15; \t\ty = randn(31) - 15; \t\tr2 = x * x + y * y; \t\tif (r2 >= 100 && r2 <= 225) \t\t{ \t\t\tbuf[15 + y] |= 1 << (x + 15); \t\t\ti++; \t\t} \t} \tfor (y = 0; y < 31; y++) \t{ \t\tfor (x = 0; x < 31; x++) \t\t\tprintf((buf[y] & 1 << x) ? \". \" : \" \"); \t\tprintf(\"\\n\"); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut x: libc::c_int = 0; let mut y: libc::c_int = 0; let mut r2: libc::c_int = 0; let mut buf: [libc::c_ulong; 31] = [ 0 as libc::c_int as libc::c_ulong, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ]; i = 0 as libc::c_int; while i < 100 as libc::c_int { x = randn(31 as libc::c_int) - 15 as libc::c_int; y = randn(31 as libc::c_int) - 15 as libc::c_int; r2 = x * x + y * y; if r2 >= 100 as libc::c_int && r2 <= 225 as libc::c_int { buf[(15 as libc::c_int + y) as usize] |= ((1 as libc::c_int) << x + 15 as libc::c_int) as libc::c_ulong; i += 1; i; } } y = 0 as libc::c_int; while y < 31 as libc::c_int { x = 0 as libc::c_int; while x < 31 as libc::c_int { printf( if buf[y as usize] & ((1 as libc::c_int) << x) as libc::c_ulong != 0 { b\". \\0\" as *const u8 as *const libc::c_char } else { b\" \\0\" as *const u8 as *const libc::c_char }, ); x += 1; x; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); y += 1; y; } return 0 as libc::c_int; }" }, { "index": 1405, "before": "int randn(int m) { \tint rand_max = RAND_MAX - (RAND_MAX % m); \tint r; \twhile ((r = rand()) > rand_max) \t\t; \treturn r / (rand_max / m); }", "after": "pub unsafe extern \"C\" fn randn(mut m: libc::c_int) -> libc::c_int { let mut rand_max: libc::c_int = 2147483647 as libc::c_int - 2147483647 as libc::c_int % m; let mut r: libc::c_int = 0; loop { r = rand(); if !(r > rand_max) { break; } } return r / (rand_max / m); }" }, { "index": 1406, "before": "int main() { FILE *fp; char *line = NULL; size_t len = 0; ssize_t read; char *lw, *lt; fp = fopen(\"data.txt\", \"r\"); if (fp == NULL) { printf(\"Unable to open file\\n\"); exit(1); } printf(\"Those earthquakes with a magnitude > 6.0 are:\\n\\n\"); while ((read = getline(&line, &len, fp)) != EOF) { if (read < 2) continue; /* ignore blank lines */ lw = strrchr(line, ' '); /* look for last space */ lt = strrchr(line, '\\t'); /* look for last tab */ if (!lw && !lt) continue; /* ignore lines with no whitespace */ if (lt > lw) lw = lt; /* lw points to last space or tab */ if (atof(lw + 1) > 6.0) printf(\"%s\", line); } fclose(fp); if (line) free(line); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut fp: *mut FILE = 0 as *mut FILE; let mut line: *mut libc::c_char = 0 as *mut libc::c_char; let mut len: size_t = 0 as libc::c_int as size_t; let mut read: ssize_t = 0; let mut lw: *mut libc::c_char = 0 as *mut libc::c_char; let mut lt: *mut libc::c_char = 0 as *mut libc::c_char; fp = fopen( b\"data.txt\\0\" as *const u8 as *const libc::c_char, b\"r\\0\" as *const u8 as *const libc::c_char, ); if fp.is_null() { printf(b\"Unable to open file\\n\\0\" as *const u8 as *const libc::c_char); exit(1 as libc::c_int); } printf( b\"Those earthquakes with a magnitude > 6.0 are:\\n\\n\\0\" as *const u8 as *const libc::c_char, ); loop { read = getline(&mut line, &mut len, fp); if !(read != -(1 as libc::c_int) as libc::c_long) { break; } if read < 2 as libc::c_int as libc::c_long { continue; } lw = strrchr(line, ' ' as i32); lt = strrchr(line, '\\t' as i32); if lw.is_null() && lt.is_null() { continue; } if lt > lw { lw = lt; } if atof(lw.offset(1 as libc::c_int as isize)) > 6.0f64 { printf(b\"%s\\0\" as *const u8 as *const libc::c_char, line); } } fclose(fp); if !line.is_null() { free(line as *mut libc::c_void); } return 0 as libc::c_int; }" }, { "index": 1407, "before": "size_t mpz_number_of_digits(const mpz_t op) { char *opstr = mpz_get_str(NULL, 10, op); const size_t oplen = strlen(opstr); free(opstr); return oplen; }", "after": "pub unsafe extern \"C\" fn mpz_number_of_digits(op: libc::c_int) -> size_t { let mut opstr: *mut libc::c_char = 0 as *mut libc::c_char; let oplen: size_t = strlen(opstr); free(opstr as *mut libc::c_void); return oplen; }" }, { "index": 1408, "before": "int main(void) { /* Construct a sieve of the first 1,000,000 primes */ uint64_t sieve_size; uint32_t *sieve = es_sieve(PRIMORIAL_LIMIT, &sieve_size); mpz_t primorial; mpz_init_set_ui(primorial, 1); uint64_t prime_count = 0; int print = 1; double unused; for (uint64_t i = 2; i < sieve_size && prime_count <= PRIMORIAL_LIMIT; ++i) { if (print) { if (prime_count < 10) gmp_printf(\"Primorial(%\" PRIu64 \") = %Zd\\n\", prime_count, primorial); /* Is the current number a power of 10? */ else if (!modf(log10(prime_count), &unused)) printf(\"Primorial(%\" PRIu64 \") has %zu digits\\n\", prime_count, mpz_number_of_digits(primorial)); print = 0; } if (es_check(sieve, i)) { mpz_mul_ui(primorial, primorial, i); prime_count++; print = 1; } } free(sieve); mpz_clear(primorial); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut sieve_size: uint64_t = 0; let mut sieve: *mut uint32_t = es_sieve( 100000 as libc::c_int as uint64_t, &mut sieve_size, ); let mut prime_count: uint64_t = 0 as libc::c_int as uint64_t; let mut print: libc::c_int = 1 as libc::c_int; let mut unused: libc::c_double = 0.; let mut i: uint64_t = 2 as libc::c_int as uint64_t; while i < sieve_size && prime_count <= 100000 as libc::c_int as libc::c_ulong { if print != 0 { print = 0 as libc::c_int; } if es_check(sieve, i) != 0 { prime_count = prime_count.wrapping_add(1); prime_count; print = 1 as libc::c_int; } i = i.wrapping_add(1); i; } free(sieve as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1409, "before": "int es_check(uint32_t *sieve, uint64_t n) { if ((n != 2 && !(n & 1)) || (n < 2)) return 0; else return !(sieve[n >> 6] & (1 << (n >> 1 & 31))); }", "after": "pub unsafe extern \"C\" fn es_check( mut sieve: *mut uint32_t, mut n: uint64_t, ) -> libc::c_int { if n != 2 as libc::c_int as libc::c_ulong && n & 1 as libc::c_int as libc::c_ulong == 0 || n < 2 as libc::c_int as libc::c_ulong { return 0 as libc::c_int } else { return (*sieve.offset((n >> 6 as libc::c_int) as isize) & ((1 as libc::c_int) << (n >> 1 as libc::c_int & 31 as libc::c_int as libc::c_ulong)) as libc::c_uint == 0) as libc::c_int }; }" }, { "index": 1410, "before": "int main(int argc,char** argv) { int i,len; char reference; if(argc>2){ printf(\"Usage : %s \\n\",argv[0]); return 0; } if(argc==1||strlen(argv[1])==1){ printf(\"Input string : \\\"%s\\\"\\nLength : %d\\nAll characters are identical.\\n\",argc==1?\"\":argv[1],argc==1?0:(int)strlen(argv[1])); return 0; } reference = argv[1][0]; len = strlen(argv[1]); for(i=1;i libc::c_int { let mut i: libc::c_int = 0; let mut len: libc::c_int = 0; let mut reference: libc::c_char = 0; if argc > 2 as libc::c_int { printf( b\"Usage : %s \\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); return 0 as libc::c_int; } if argc == 1 as libc::c_int || strlen(*argv.offset(1 as libc::c_int as isize)) == 1 as libc::c_int as libc::c_ulong { printf( b\"Input string : \\\"%s\\\"\\nLength : %d\\nAll characters are identical.\\n\\0\" as *const u8 as *const libc::c_char, if argc == 1 as libc::c_int { b\"\\0\" as *const u8 as *const libc::c_char } else { *argv.offset(1 as libc::c_int as isize) as *const libc::c_char }, if argc == 1 as libc::c_int { 0 as libc::c_int } else { strlen(*argv.offset(1 as libc::c_int as isize)) as libc::c_int }, ); return 0 as libc::c_int; } reference = *(*argv.offset(1 as libc::c_int as isize)) .offset(0 as libc::c_int as isize); len = strlen(*argv.offset(1 as libc::c_int as isize)) as libc::c_int; i = 1 as libc::c_int; while i < len { if *(*argv.offset(1 as libc::c_int as isize)).offset(i as isize) as libc::c_int != reference as libc::c_int { printf( b\"Input string : \\\"%s\\\"\\nLength : %d\\nFirst different character : \\\"%c\\\"(0x%x) at position : %d\\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(1 as libc::c_int as isize), len, *(*argv.offset(1 as libc::c_int as isize)).offset(i as isize) as libc::c_int, *(*argv.offset(1 as libc::c_int as isize)).offset(i as isize) as libc::c_int, i + 1 as libc::c_int, ); return 0 as libc::c_int; } i += 1; i; } printf( b\"Input string : \\\"%s\\\"\\nLength : %d\\nAll characters are identical.\\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(1 as libc::c_int as isize), len, ); return 0 as libc::c_int; }" }, { "index": 1411, "before": "double price_fix(double x) { \tint i; \tfor (i = 0; table[i][0] > 0; i++) \t\tif (x < table[i][0]) return table[i][1]; \tabort(); /* what else to do? */ }", "after": "pub unsafe extern \"C\" fn price_fix(mut x: libc::c_double) -> libc::c_double { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while table[i as usize][0 as libc::c_int as usize] > 0 as libc::c_int as libc::c_double { if x < table[i as usize][0 as libc::c_int as usize] { return table[i as usize][1 as libc::c_int as usize]; } i += 1; i; } abort(); }" }, { "index": 1412, "before": "int main() { \tint i; \tfor (i = 0; i <= 100; i++) \t\tprintf(\"%.2f %.2f\\n\", i / 100., price_fix(i / 100.)); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i <= 100 as libc::c_int { printf( b\"%.2f %.2f\\n\\0\" as *const u8 as *const libc::c_char, i as libc::c_double / 100.0f64, price_fix(i as libc::c_double / 100.0f64), ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1413, "before": "void delete_list(list l) { \tint i; \tif (!l) return; \tif (l->is_list && l->ival) { \t\tfor (i = 0; i < l->ival; i++) \t\t\tdelete_list(l->lst[i]); \t\tfree(l->lst); \t} \tfree(l); }", "after": "pub unsafe extern \"C\" fn delete_list(mut l: list) { let mut i: libc::c_int = 0; if l.is_null() { return; } if (*l).is_list != 0 && (*l).ival != 0 { i = 0 as libc::c_int; while i < (*l).ival { delete_list(*((*l).lst).offset(i as isize)); i += 1; i; } free((*l).lst as *mut libc::c_void); } free(l as *mut libc::c_void); }" }, { "index": 1414, "before": "void show_list(list l) { \tint i; \tif (!l) return; \tif (!l->is_list) { \t\tprintf(\"%d\", l->ival); \t\treturn; \t} \tprintf(\"[\"); \tfor (i = 0; i < l->ival; i++) { \t\tshow_list(l->lst[i]); \t\tif (i < l->ival - 1) printf(\", \"); \t} \tprintf(\"]\"); }", "after": "pub unsafe extern \"C\" fn show_list(mut l: list) { let mut i: libc::c_int = 0; if l.is_null() { return; } if (*l).is_list == 0 { printf(b\"%d\\0\" as *const u8 as *const libc::c_char, (*l).ival); return; } printf(b\"[\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < (*l).ival { show_list(*((*l).lst).offset(i as isize)); if i < (*l).ival - 1 as libc::c_int { printf(b\", \\0\" as *const u8 as *const libc::c_char); } i += 1; i; } printf(b\"]\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1415, "before": "void append(list parent, list child) { \tparent->lst = realloc(parent->lst, sizeof(list) * (parent->ival + 1)); \tparent->lst[parent->ival++] = child; }", "after": "pub unsafe extern \"C\" fn append(mut parent: list, mut child: list) { (*parent) .lst = realloc( (*parent).lst as *mut libc::c_void, (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(((*parent).ival + 1 as libc::c_int) as libc::c_ulong), ) as *mut list; let fresh0 = (*parent).ival; (*parent).ival = (*parent).ival + 1; let ref mut fresh1 = *((*parent).lst).offset(fresh0 as isize); *fresh1 = child; }" }, { "index": 1416, "before": "list new_list() { \tlist x = malloc(sizeof(list_t)); \tx->ival = 0; \tx->is_list = 1; \tx->lst = 0; \treturn x; }", "after": "pub unsafe extern \"C\" fn new_list() -> list { let mut x: list = malloc(::core::mem::size_of::() as libc::c_ulong) as list; (*x).ival = 0 as libc::c_int; (*x).is_list = 1 as libc::c_int; (*x).lst = 0 as *mut list; return x; }" }, { "index": 1417, "before": "list from_string(char *s, char **e, list parent) { \tlist ret = 0; \tif (!parent) parent = new_list(); \twhile (*s != '\\0') { \t\tif (*s == ']') { \t\t\tif (e) *e = s + 1; \t\t\treturn parent; \t\t} \t\tif (*s == '[') { \t\t\tret = new_list(); \t\t\tret->is_list = 1; \t\t\tret->ival = 0; \t\t\tappend(parent, ret); \t\t\tfrom_string(s + 1, &s, ret); \t\t\tcontinue; \t\t} \t\tif (*s >= '0' && *s <= '9') { \t\t\tret = new_list(); \t\t\tret->is_list = 0; \t\t\tret->ival = strtol(s, &s, 10); \t\t\tappend(parent, ret); \t\t\tcontinue; \t\t} \t\ts++; \t} \tif (e) *e = s; \treturn parent; }", "after": "pub unsafe extern \"C\" fn from_string( mut s: *mut libc::c_char, mut e: *mut *mut libc::c_char, mut parent: list, ) -> list { let mut ret: list = 0 as list; if parent.is_null() { parent = new_list(); } while *s as libc::c_int != '\\0' as i32 { if *s as libc::c_int == ']' as i32 { if !e.is_null() { *e = s.offset(1 as libc::c_int as isize); } return parent; } if *s as libc::c_int == '[' as i32 { ret = new_list(); (*ret).is_list = 1 as libc::c_int; (*ret).ival = 0 as libc::c_int; append(parent, ret); from_string(s.offset(1 as libc::c_int as isize), &mut s, ret); } else if *s as libc::c_int >= '0' as i32 && *s as libc::c_int <= '9' as i32 { ret = new_list(); (*ret).is_list = 0 as libc::c_int; (*ret).ival = strtol(s, &mut s, 10 as libc::c_int) as libc::c_int; append(parent, ret); } else { s = s.offset(1); s; } } if !e.is_null() { *e = s; } return parent; }" }, { "index": 1418, "before": "int main() { \tlist l = from_string(\"[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []\", 0, 0); \tprintf(\"Nested: \"); \tshow_list(l); \tprintf(\"\\n\"); \tlist flat = flatten(l, 0); \tprintf(\"Flattened: \"); \tshow_list(flat); \t/* delete_list(l); delete_list(flat); */ \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut l: list = from_string( b\"[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, 0 as *mut *mut libc::c_char, 0 as list, ); printf(b\"Nested: \\0\" as *const u8 as *const libc::c_char); show_list(l); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); let mut flat: list = flatten(l, 0 as list); printf(b\"Flattened: \\0\" as *const u8 as *const libc::c_char); show_list(flat); return 0 as libc::c_int; }" }, { "index": 1419, "before": "list flatten(list from, list to) { \tint i; \tlist t; \tif (!to) to = new_list(); \tif (!from->is_list) { \t\tt = new_list(); \t\t*t = *from; \t\tappend(to, t); \t} else \t\tfor (i = 0; i < from->ival; i++) \t\t\tflatten(from->lst[i], to); \treturn to; }", "after": "pub unsafe extern \"C\" fn flatten(mut from: list, mut to: list) -> list { let mut i: libc::c_int = 0; let mut t: list = 0 as *mut list_t; if to.is_null() { to = new_list(); } if (*from).is_list == 0 { t = new_list(); *t = *from; append(to, t); } else { i = 0 as libc::c_int; while i < (*from).ival { flatten(*((*from).lst).offset(i as isize), to); i += 1; i; } } return to; }" }, { "index": 1420, "before": "int buildAnagrams( FILE *fin ) { char buffer[40]; char bufr2[40]; char *hkey; int hix; HashEntry he, *hep; DictWord we; int maxPC = 2; int numWords = 0; while ( fgets(buffer, 40, fin)) { for(hkey = buffer; *hkey && (*hkey!='\\n'); hkey++); *hkey = 0; hkey = sortedWord(buffer, bufr2); hix = Str_Hash(hkey, HT_SIZE); he = hashTable[hix]; hep = &hashTable[hix]; while( he && strcmp(he->key , hkey) ) { hep = &he->next; he = he->next; } if ( ! he ) { he = malloc(sizeof(struct sHashEntry)); he->next = NULL; he->key = strdup(hkey); he->wordCount = 0; he->words = NULL; he->link = NULL; *hep = he; } we = malloc(sizeof(struct sDictWord)); we->word = strdup(buffer); we->next = he->words; he->words = we; he->wordCount++; if ( maxPC < he->wordCount) { maxPC = he->wordCount; mostPerms = he; he->link = NULL; } else if (maxPC == he->wordCount) { he->link = mostPerms; mostPerms = he; } numWords++; } printf(\"%d words in dictionary max ana=%d\\n\", numWords, maxPC); return maxPC; }", "after": "pub unsafe extern \"C\" fn buildAnagrams(mut fin: *mut FILE) -> libc::c_int { let mut buffer: [libc::c_char; 40] = [0; 40]; let mut bufr2: [libc::c_char; 40] = [0; 40]; let mut hkey: *mut libc::c_char = 0 as *mut libc::c_char; let mut hix: libc::c_int = 0; let mut he: HashEntry = 0 as *mut sHashEntry; let mut hep: *mut HashEntry = 0 as *mut HashEntry; let mut we: DictWord = 0 as *mut sDictWord; let mut maxPC: libc::c_int = 2 as libc::c_int; let mut numWords: libc::c_int = 0 as libc::c_int; while !(fgets(buffer.as_mut_ptr(), 40 as libc::c_int, fin)).is_null() { hkey = buffer.as_mut_ptr(); while *hkey as libc::c_int != 0 && *hkey as libc::c_int != '\\n' as i32 { hkey = hkey.offset(1); hkey; } *hkey = 0 as libc::c_int as libc::c_char; hkey = sortedWord(buffer.as_mut_ptr(), bufr2.as_mut_ptr()); hix = Str_Hash(hkey, 8192 as libc::c_int); he = hashTable[hix as usize]; hep = &mut *hashTable.as_mut_ptr().offset(hix as isize) as *mut HashEntry; while !he.is_null() && strcmp((*he).key, hkey) != 0 { hep = &mut (*he).next; he = (*he).next; } if he.is_null() { he = malloc(::core::mem::size_of::() as libc::c_ulong) as HashEntry; (*he).next = 0 as HashEntry; (*he).key = strdup(hkey); (*he).wordCount = 0 as libc::c_int as libc::c_short; (*he).words = 0 as DictWord; (*he).link = 0 as HashEntry; *hep = he; } we = malloc(::core::mem::size_of::() as libc::c_ulong) as DictWord; (*we).word = strdup(buffer.as_mut_ptr()); (*we).next = (*he).words; (*he).words = we; (*he).wordCount += 1; (*he).wordCount; if maxPC < (*he).wordCount as libc::c_int { maxPC = (*he).wordCount as libc::c_int; mostPerms = he; (*he).link = 0 as HashEntry; } else if maxPC == (*he).wordCount as libc::c_int { (*he).link = mostPerms; mostPerms = he; } numWords += 1; numWords; } printf( b\"%d words in dictionary max ana=%d\\n\\0\" as *const u8 as *const libc::c_char, numWords, maxPC, ); return maxPC; }" }, { "index": 1421, "before": "int main( ) { HashEntry he; DictWord we; FILE *f1; f1 = fopen(\"unixdict.txt\",\"r\"); buildAnagrams(f1); fclose(f1); f1 = fopen(\"anaout.txt\",\"w\"); // f1 = stdout; for (he = mostPerms; he; he = he->link) { fprintf(f1,\"%d:\", he->wordCount); for(we = he->words; we; we = we->next) { fprintf(f1,\"%s, \", we->word); } fprintf(f1, \"\\n\"); } fclose(f1); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut he: HashEntry = 0 as *mut sHashEntry; let mut we: DictWord = 0 as *mut sDictWord; let mut f1: *mut FILE = 0 as *mut FILE; f1 = fopen( b\"unixdict.txt\\0\" as *const u8 as *const libc::c_char, b\"r\\0\" as *const u8 as *const libc::c_char, ); buildAnagrams(f1); fclose(f1); f1 = fopen( b\"anaout.txt\\0\" as *const u8 as *const libc::c_char, b\"w\\0\" as *const u8 as *const libc::c_char, ); he = mostPerms; while !he.is_null() { fprintf( f1, b\"%d:\\0\" as *const u8 as *const libc::c_char, (*he).wordCount as libc::c_int, ); we = (*he).words; while !we.is_null() { fprintf(f1, b\"%s, \\0\" as *const u8 as *const libc::c_char, (*we).word); we = (*we).next; } fprintf(f1, b\"\\n\\0\" as *const u8 as *const libc::c_char); he = (*he).link; } fclose(f1); return 0 as libc::c_int; }" }, { "index": 1422, "before": "int Str_Hash( const char *key, int ix_max ) { const char *cp; short mash; int hash = 33501551; for (cp = key; *cp; cp++) { mash = cxmap[*cp % CXMAP_SIZE]; hash = (hash >>4) ^ 0x5C5CF5C ^ ((hash<<1) + (mash<<5)); hash &= 0x3FFFFFFF; } return hash % ix_max; }", "after": "pub unsafe extern \"C\" fn Str_Hash( mut key: *const libc::c_char, mut ix_max: libc::c_int, ) -> libc::c_int { let mut cp: *const libc::c_char = 0 as *const libc::c_char; let mut mash: libc::c_short = 0; let mut hash: libc::c_int = 33501551 as libc::c_int; cp = key; while *cp != 0 { mash = cxmap[(*cp as libc::c_ulong) .wrapping_rem( (::core::mem::size_of::<[libc::c_short; 96]>() as libc::c_ulong) .wrapping_div( ::core::mem::size_of::() as libc::c_ulong, ), ) as usize]; hash = hash >> 4 as libc::c_int ^ 0x5c5cf5c as libc::c_int ^ (hash << 1 as libc::c_int) + ((mash as libc::c_int) << 5 as libc::c_int); hash &= 0x3fffffff as libc::c_int; cp = cp.offset(1); cp; } return hash % ix_max; }" }, { "index": 1423, "before": "int is_ordered_word(const TWord word) { assert(word != NULL); int i; for (i = 0; word[i] != '\\0'; i++) if (word[i] > word[i + 1] && word[i + 1] != '\\0') return 0; return 1; }", "after": "pub unsafe extern \"C\" fn is_ordered_word(mut word: *const libc::c_char) -> libc::c_int { if !word.is_null() {} else { __assert_fail( b\"word != NULL\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 18 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 34], &[libc::c_char; 34], >(b\"int is_ordered_word(const char *)\\0\")) .as_ptr(), ); } 'c_1788: { if !word.is_null() {} else { __assert_fail( b\"word != NULL\\0\" as *const u8 as *const libc::c_char, b\"main.c\\0\" as *const u8 as *const libc::c_char, 18 as libc::c_int as libc::c_uint, (*::core::mem::transmute::< &[u8; 34], &[libc::c_char; 34], >(b\"int is_ordered_word(const char *)\\0\")) .as_ptr(), ); } }; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while *word.offset(i as isize) as libc::c_int != '\\0' as i32 { if *word.offset(i as isize) as libc::c_int > *word.offset((i + 1 as libc::c_int) as isize) as libc::c_int && *word.offset((i + 1 as libc::c_int) as isize) as libc::c_int != '\\0' as i32 { return 0 as libc::c_int; } i += 1; i; } return 1 as libc::c_int; }" }, { "index": 1424, "before": "int main() { FILE *fp = fopen(\"unixdict.txt\", \"r\"); if (fp == NULL) return EXIT_FAILURE; Node *words = NULL; TWord line; unsigned int max_len = 0; while (fscanf(fp, \"%99s\\n\", line) != EOF) { if (strlen(line) > max_len && is_ordered_word(line)) { max_len = strlen(line); words = list_destroy(words); words = list_prepend(words, line); } else if (strlen(line) == max_len && is_ordered_word(line)) { words = list_prepend(words, line); } } fclose(fp); list_print(words); return EXIT_SUCCESS; }", "after": "unsafe fn main() -> libc::c_int { let mut fp: *mut FILE = fopen( b\"unixdict.txt\\0\" as *const u8 as *const libc::c_char, b\"r\\0\" as *const u8 as *const libc::c_char, ); if fp.is_null() { return 1 as libc::c_int; } let mut words: *mut Node = 0 as *mut Node; let mut line: TWord = [0; 100]; let mut max_len: libc::c_uint = 0 as libc::c_int as libc::c_uint; while fscanf(fp, b\"%99s\\n\\0\" as *const u8 as *const libc::c_char, line.as_mut_ptr()) != -(1 as libc::c_int) { if strlen(line.as_mut_ptr()) > max_len as libc::c_ulong && is_ordered_word(line.as_mut_ptr() as *const libc::c_char) != 0 { max_len = strlen(line.as_mut_ptr()) as libc::c_uint; words = list_destroy(words); words = list_prepend(words, line.as_mut_ptr() as *const libc::c_char); } else if strlen(line.as_mut_ptr()) == max_len as libc::c_ulong && is_ordered_word(line.as_mut_ptr() as *const libc::c_char) != 0 { words = list_prepend(words, line.as_mut_ptr() as *const libc::c_char); } } fclose(fp); list_print(words); return 0 as libc::c_int; }" }, { "index": 1425, "before": "void list_print(Node *words_list) { while (words_list != NULL) { printf(\"\\n%s\", words_list->word); words_list = words_list->next; } }", "after": "pub unsafe extern \"C\" fn list_print(mut words_list: *mut Node) { while !words_list.is_null() { printf( b\"\\n%s\\0\" as *const u8 as *const libc::c_char, ((*words_list).word).as_mut_ptr(), ); words_list = (*words_list).next; } }" }, { "index": 1426, "before": "void setBell(int *bellTri, int row, int col, int value) { size_t index = bellIndex(row, col); bellTri[index] = value; }", "after": "pub unsafe extern \"C\" fn setBell( mut bellTri: *mut libc::c_int, mut row: libc::c_int, mut col: libc::c_int, mut value: libc::c_int, ) { let mut index: size_t = bellIndex(row, col); *bellTri.offset(index as isize) = value; }" }, { "index": 1427, "before": "size_t bellIndex(int row, int col) { return row * (row - 1) / 2 + col; }", "after": "pub unsafe extern \"C\" fn bellIndex( mut row: libc::c_int, mut col: libc::c_int, ) -> size_t { return (row * (row - 1 as libc::c_int) / 2 as libc::c_int + col) as size_t; }" }, { "index": 1428, "before": "int main() { const int rows = 15; int *bt = bellTriangle(rows); int i, j; printf(\"First fifteen Bell numbers:\\n\"); for (i = 1; i <= rows; ++i) { printf(\"%2d: %d\\n\", i, getBell(bt, i, 0)); } printf(\"\\nThe first ten rows of Bell's triangle:\\n\"); for (i = 1; i <= 10; ++i) { printf(\"%d\", getBell(bt, i, 0)); for (j = 1; j < i; ++j) { printf(\", %d\", getBell(bt, i, j)); } printf(\"\\n\"); } free(bt); return 0; }", "after": "unsafe fn main() -> libc::c_int { let rows: libc::c_int = 15 as libc::c_int; let mut bt: *mut libc::c_int = bellTriangle(rows); let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; printf(b\"First fifteen Bell numbers:\\n\\0\" as *const u8 as *const libc::c_char); i = 1 as libc::c_int; while i <= rows { printf( b\"%2d: %d\\n\\0\" as *const u8 as *const libc::c_char, i, getBell(bt, i, 0 as libc::c_int), ); i += 1; i; } printf( b\"\\nThe first ten rows of Bell's triangle:\\n\\0\" as *const u8 as *const libc::c_char, ); i = 1 as libc::c_int; while i <= 10 as libc::c_int { printf( b\"%d\\0\" as *const u8 as *const libc::c_char, getBell(bt, i, 0 as libc::c_int), ); j = 1 as libc::c_int; while j < i { printf(b\", %d\\0\" as *const u8 as *const libc::c_char, getBell(bt, i, j)); j += 1; j; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i += 1; i; } free(bt as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1429, "before": "int getBell(int *bellTri, int row, int col) { size_t index = bellIndex(row, col); return bellTri[index]; }", "after": "pub unsafe extern \"C\" fn getBell( mut bellTri: *mut libc::c_int, mut row: libc::c_int, mut col: libc::c_int, ) -> libc::c_int { let mut index: size_t = bellIndex(row, col); return *bellTri.offset(index as isize); }" }, { "index": 1430, "before": "int main() { \tint i, j; \tdouble a[3][5] = {{ 0, 1, 2, 3, 4 }, \t\t\t { 5, 6, 7, 8, 9 }, \t\t\t { 1, 0, 0, 0, 42}}; \tdouble b[5][3]; \ttranspose(b, a, 3, 5); \tfor (i = 0; i < 5; i++) \t\tfor (j = 0; j < 3; j++) \t\t\tprintf(\"%g%c\", b[i][j], j == 2 ? '\\n' : ' '); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut a: [[libc::c_double; 5]; 3] = [ [ 0 as libc::c_int as libc::c_double, 1 as libc::c_int as libc::c_double, 2 as libc::c_int as libc::c_double, 3 as libc::c_int as libc::c_double, 4 as libc::c_int as libc::c_double, ], [ 5 as libc::c_int as libc::c_double, 6 as libc::c_int as libc::c_double, 7 as libc::c_int as libc::c_double, 8 as libc::c_int as libc::c_double, 9 as libc::c_int as libc::c_double, ], [ 1 as libc::c_int as libc::c_double, 0 as libc::c_int as libc::c_double, 0 as libc::c_int as libc::c_double, 0 as libc::c_int as libc::c_double, 42 as libc::c_int as libc::c_double, ], ]; let mut b: [[libc::c_double; 3]; 5] = [[0.; 3]; 5]; transpose( b.as_mut_ptr() as *mut libc::c_void, a.as_mut_ptr() as *mut libc::c_void, 3 as libc::c_int, 5 as libc::c_int, ); i = 0 as libc::c_int; while i < 5 as libc::c_int { j = 0 as libc::c_int; while j < 3 as libc::c_int { printf( b\"%g%c\\0\" as *const u8 as *const libc::c_char, b[i as usize][j as usize], if j == 2 as libc::c_int { '\\n' as i32 } else { ' ' as i32 }, ); j += 1; j; } i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1431, "before": "void transpose(void *dest, void *src, int src_h, int src_w) { \tint i, j; \tdouble (*d)[src_h] = dest, (*s)[src_w] = src; \tfor (i = 0; i < src_h; i++) \t\tfor (j = 0; j < src_w; j++) \t\t\td[j][i] = s[i][j]; }", "after": "pub unsafe extern \"C\" fn transpose( mut dest: *mut libc::c_void, mut src: *mut libc::c_void, mut src_h: libc::c_int, mut src_w: libc::c_int, ) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let vla = src_h as usize; let mut d: *mut libc::c_double = dest as *mut libc::c_double; let vla_0 = src_w as usize; let mut s: *mut libc::c_double = src as *mut libc::c_double; i = 0 as libc::c_int; while i < src_h { j = 0 as libc::c_int; while j < src_w { *d .offset(j as isize * vla as isize) .offset( i as isize, ) = *s.offset(i as isize * vla_0 as isize).offset(j as isize); j += 1; j; } i += 1; i; } }" }, { "index": 1432, "before": "int main() { \tint y; \tfor (y = 2008; y <= 2121; y++) { \t\tif (wday(y, 12, 25) == 0) printf(\"%04d-12-25\\n\", y); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut y: libc::c_int = 0; y = 2008 as libc::c_int; while y <= 2121 as libc::c_int { if wday(y, 12 as libc::c_int, 25 as libc::c_int) == 0 as libc::c_int { printf(b\"%04d-12-25\\n\\0\" as *const u8 as *const libc::c_char, y); } y += 1; y; } return 0 as libc::c_int; }" }, { "index": 1433, "before": "int wday(int year, int month, int day) { \tint adjustment, mm, yy; \tadjustment = (14 - month) / 12; \tmm = month + 12 * adjustment - 2; \tyy = year - adjustment; \treturn (day + (13 * mm - 1) / 5 + \t\tyy + yy / 4 - yy / 100 + yy / 400) % 7; }", "after": "pub unsafe extern \"C\" fn wday( mut year: libc::c_int, mut month: libc::c_int, mut day: libc::c_int, ) -> libc::c_int { let mut adjustment: libc::c_int = 0; let mut mm: libc::c_int = 0; let mut yy: libc::c_int = 0; adjustment = (14 as libc::c_int - month) / 12 as libc::c_int; mm = month + 12 as libc::c_int * adjustment - 2 as libc::c_int; yy = year - adjustment; return (day + (13 as libc::c_int * mm - 1 as libc::c_int) / 5 as libc::c_int + yy + yy / 4 as libc::c_int - yy / 100 as libc::c_int + yy / 400 as libc::c_int) % 7 as libc::c_int; }" }, { "index": 1434, "before": "int main(int argC,char* argV[]) { \tif(argC!=2) \t\tprintf(\"Usage : %s \",argV[0]); \telse \t\tprocessInputString(argV[1]); \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 \\0\" as *const u8 as *const libc::c_char, *argV.offset(0 as libc::c_int as isize), ); } else { processInputString(*argV.offset(1 as libc::c_int as isize)); } return 0 as libc::c_int; }" }, { "index": 1435, "before": "void processInputString(char* str){ \tint **sets, *currentSet, *setLengths, setLength, numSets = 0, i,j,k,l,start,counter=0; \tchar *token,*holder,*holderToken; \tfor(i=0;str[i]!=00;i++) \t\tif(str[i]=='x') \t\t\tnumSets++; \tif(numSets==0){ \t\t\tprintf(\"\\n%s\",str); \t\t\treturn; \t} \tcurrentSet = (int*)calloc(sizeof(int),numSets + 1); \tsetLengths = (int*)calloc(sizeof(int),numSets + 1); \tsets = (int**)malloc((numSets + 1)*sizeof(int*)); \ttoken = strtok(str,\"x\"); \twhile(token!=NULL){ \t\tholder = (char*)malloc(strlen(token)*sizeof(char)); \t\tj = 0; \t\tfor(i=0;token[i]!=00;i++){ \t\t\tif(token[i]>='0' && token[i]<='9') \t\t\t\tholder[j++] = token[i]; \t\t\telse if(token[i]==',') \t\t\t\tholder[j++] = ' '; \t\t} \t\tholder[j] = 00; \t\tsetLength = 0; \t\tfor(i=0;holder[i]!=00;i++) \t\t\tif(holder[i]==' ') \t\t\t\tsetLength++; \t\tif(setLength==0 && strlen(holder)==0){ \t\t\tprintf(\"\\n{}\"); \t\t\treturn; \t\t} \t\tsetLengths[counter] = setLength+1; \t\tsets[counter] = (int*)malloc((1+setLength)*sizeof(int)); \t\tk = 0; \t\tstart = 0; \t\tfor(l=0;holder[l]!=00;l++){ \t\t\tif(holder[l+1]==' '||holder[l+1]==00){ \t\t\t\tholderToken = (char*)malloc((l+1-start)*sizeof(char)); \t\t\t\tstrncpy(holderToken,holder + start,l+1-start); \t\t\t\tsets[counter][k++] = atoi(holderToken); \t\t\t\tstart = l+2; \t\t\t} \t\t} \t\tcounter++; \t\ttoken = strtok(NULL,\"x\"); \t} \tprintf(\"\\n{\"); \tcartesianProduct(sets,setLengths,currentSet,numSets + 1,0); \tprintf(\"\\b}\"); }", "after": "pub unsafe extern \"C\" fn processInputString(mut str: *mut libc::c_char) { let mut sets: *mut *mut libc::c_int = 0 as *mut *mut libc::c_int; let mut currentSet: *mut libc::c_int = 0 as *mut libc::c_int; let mut setLengths: *mut libc::c_int = 0 as *mut libc::c_int; let mut setLength: libc::c_int = 0; let mut numSets: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut k: libc::c_int = 0; let mut l: libc::c_int = 0; let mut start: libc::c_int = 0; let mut counter: libc::c_int = 0 as libc::c_int; let mut token: *mut libc::c_char = 0 as *mut libc::c_char; let mut holder: *mut libc::c_char = 0 as *mut libc::c_char; let mut holderToken: *mut libc::c_char = 0 as *mut libc::c_char; i = 0 as libc::c_int; while *str.offset(i as isize) as libc::c_int != 0 as libc::c_int { if *str.offset(i as isize) as libc::c_int == 'x' as i32 { numSets += 1; numSets; } i += 1; i; } if numSets == 0 as libc::c_int { printf(b\"\\n%s\\0\" as *const u8 as *const libc::c_char, str); return; } currentSet = calloc( ::core::mem::size_of::() as libc::c_ulong, (numSets + 1 as libc::c_int) as libc::c_ulong, ) as *mut libc::c_int; setLengths = calloc( ::core::mem::size_of::() as libc::c_ulong, (numSets + 1 as libc::c_int) as libc::c_ulong, ) as *mut libc::c_int; sets = malloc( ((numSets + 1 as libc::c_int) as libc::c_ulong) .wrapping_mul(::core::mem::size_of::<*mut libc::c_int>() as libc::c_ulong), ) as *mut *mut libc::c_int; token = strtok(str, b\"x\\0\" as *const u8 as *const libc::c_char); while !token.is_null() { holder = malloc( (strlen(token)) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_char; j = 0 as libc::c_int; i = 0 as libc::c_int; while *token.offset(i as isize) as libc::c_int != 0 as libc::c_int { if *token.offset(i as isize) as libc::c_int >= '0' as i32 && *token.offset(i as isize) as libc::c_int <= '9' as i32 { let fresh0 = j; j = j + 1; *holder.offset(fresh0 as isize) = *token.offset(i as isize); } else if *token.offset(i as isize) as libc::c_int == ',' as i32 { let fresh1 = j; j = j + 1; *holder.offset(fresh1 as isize) = ' ' as i32 as libc::c_char; } i += 1; i; } *holder.offset(j as isize) = 0 as libc::c_int as libc::c_char; setLength = 0 as libc::c_int; i = 0 as libc::c_int; while *holder.offset(i as isize) as libc::c_int != 0 as libc::c_int { if *holder.offset(i as isize) as libc::c_int == ' ' as i32 { setLength += 1; setLength; } i += 1; i; } if setLength == 0 as libc::c_int && strlen(holder) == 0 as libc::c_int as libc::c_ulong { printf(b\"\\n{}\\0\" as *const u8 as *const libc::c_char); return; } *setLengths.offset(counter as isize) = setLength + 1 as libc::c_int; let ref mut fresh2 = *sets.offset(counter as isize); *fresh2 = malloc( ((1 as libc::c_int + setLength) as libc::c_ulong) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut libc::c_int; k = 0 as libc::c_int; start = 0 as libc::c_int; l = 0 as libc::c_int; while *holder.offset(l as isize) as libc::c_int != 0 as libc::c_int { if *holder.offset((l + 1 as libc::c_int) as isize) as libc::c_int == ' ' as i32 || *holder.offset((l + 1 as libc::c_int) as isize) as libc::c_int == 0 as libc::c_int { holderToken = malloc( ((l + 1 as libc::c_int - start) as libc::c_ulong) .wrapping_mul( ::core::mem::size_of::() as libc::c_ulong, ), ) as *mut libc::c_char; strncpy( holderToken, holder.offset(start as isize), (l + 1 as libc::c_int - start) as libc::c_ulong, ); let fresh3 = k; k = k + 1; *(*sets.offset(counter as isize)) .offset(fresh3 as isize) = atoi(holderToken); start = l + 2 as libc::c_int; } l += 1; l; } counter += 1; counter; token = strtok( 0 as *mut libc::c_char, b\"x\\0\" as *const u8 as *const libc::c_char, ); } printf(b\"\\n{\\0\" as *const u8 as *const libc::c_char); cartesianProduct( sets, setLengths, currentSet, numSets + 1 as libc::c_int, 0 as libc::c_int, ); printf(b\"\\x08}\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1436, "before": "void cartesianProduct(int** sets, int* setLengths, int* currentSet, int numSets, int times){ \tint i,j; \tif(times==numSets){ \t\tprintf(\"(\"); \t\tfor(i=0;i libc::c_int { if n % 2 as libc::c_int == 0 as libc::c_int { return (n == 2 as libc::c_int) as libc::c_int; } if n % 3 as libc::c_int == 0 as libc::c_int { return (n == 3 as libc::c_int) as libc::c_int; } let mut d: libc::c_int = 5 as libc::c_int; while d * d <= n { if n % d == 0 as libc::c_int { return 0 as libc::c_int; } d += 2 as libc::c_int; if n % d == 0 as libc::c_int { return 0 as libc::c_int; } d += 4 as libc::c_int; } return 1 as libc::c_int; }" }, { "index": 1439, "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": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *const libc::c_char, ) -> libc::c_int { let mut n: libc::c_uint = 0; let mut c: libc::c_uint = 0; n = 1 as libc::c_int as libc::c_uint; c = 0 as libc::c_int as libc::c_uint; while c < 25 as libc::c_int as libc::c_uint { if n < sum_proper_divisors(n) { c = c.wrapping_add(1); printf(b\"%u: %u\\n\\0\" as *const u8 as *const libc::c_char, c, n); } n = n.wrapping_add(2 as libc::c_int as libc::c_uint); } while c < 1000 as libc::c_int as libc::c_uint { if n < sum_proper_divisors(n) { c = c.wrapping_add(1); c; } n = n.wrapping_add(2 as libc::c_int as libc::c_uint); } printf( b\"\\nThe one thousandth abundant odd number is: %u\\n\\0\" as *const u8 as *const libc::c_char, n, ); n = 1000000001 as libc::c_int as libc::c_uint; while !(n < sum_proper_divisors(n)) { n = n.wrapping_add(2 as libc::c_int as libc::c_uint); } printf( b\"The first abundant odd number above one billion is: %u\\n\\0\" as *const u8 as *const libc::c_char, n, ); return 0 as libc::c_int; }" }, { "index": 1440, "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 unsafe extern \"C\" fn sum_proper_divisors(n: libc::c_uint) -> libc::c_uint { let mut sum: libc::c_uint = 1 as libc::c_int as libc::c_uint; let mut i: libc::c_uint = 3 as libc::c_int as libc::c_uint; let mut j: libc::c_uint = 0; while (i as libc::c_double) < sqrt(n as libc::c_double) + 1 as libc::c_int as libc::c_double { if n.wrapping_rem(i) == 0 as libc::c_int as libc::c_uint { j = n.wrapping_div(i); sum = sum .wrapping_add( i .wrapping_add( (if i == j { 0 as libc::c_int as libc::c_uint } else { j }), ), ); } i = i.wrapping_add(2 as libc::c_int as libc::c_uint); } return sum; }" }, { "index": 1441, "before": "void fatal(const char* message) { fprintf(stderr, \"%s\\n\", message); exit(1); }", "after": "pub unsafe extern \"C\" fn fatal(mut message: *const libc::c_char) { fprintf(stderr, b\"%s\\n\\0\" as *const u8 as *const libc::c_char, message); exit(1 as libc::c_int); }" }, { "index": 1442, "before": "void free_command_list(command_t* cmd) { while (cmd != NULL) { command_t* next = cmd->next; free(cmd->cmd); free(cmd); cmd = next; } }", "after": "pub unsafe extern \"C\" fn free_command_list(mut cmd: *mut command_t) { while !cmd.is_null() { let mut next: *mut command_t = (*cmd).next; free((*cmd).cmd as *mut libc::c_void); free(cmd as *mut libc::c_void); cmd = next; } }" }, { "index": 1443, "before": "bool command_match(const command_t* command, const char* str) { size_t olen = strlen(str); return olen >= command->min_len && olen <= command->length && strncmp(str, command->cmd, olen) == 0; }", "after": "pub unsafe extern \"C\" fn command_match( mut command: *const command_t, mut str: *const libc::c_char, ) -> bool { let mut olen: size_t = strlen(str); return olen >= (*command).min_len && olen <= (*command).length && strncmp(str, (*command).cmd, olen) == 0 as libc::c_int; }" }, { "index": 1444, "before": "void test(const command_t* commands, const char* input) { printf(\" input: %s\\n\", input); printf(\"output:\"); size_t count = 0; char** words = split_into_words(input, &count); for (size_t i = 0; i < count; ++i) { char* word = words[i]; uppercase(word, strlen(word)); const command_t* cmd_ptr = find_command(commands, word); printf(\" %s\", cmd_ptr ? cmd_ptr->cmd : \"*error*\"); free(word); } free(words); printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn test( mut commands: *const command_t, mut input: *const libc::c_char, ) { printf(b\" input: %s\\n\\0\" as *const u8 as *const libc::c_char, input); printf(b\"output:\\0\" as *const u8 as *const libc::c_char); let mut count: size_t = 0 as libc::c_int as size_t; let mut words: *mut *mut libc::c_char = split_into_words(input, &mut count); let mut i: size_t = 0 as libc::c_int as size_t; while i < count { let mut word: *mut libc::c_char = *words.offset(i as isize); uppercase(word, strlen(word)); let mut cmd_ptr: *const command_t = find_command(commands, word); printf( b\" %s\\0\" as *const u8 as *const libc::c_char, if !cmd_ptr.is_null() { (*cmd_ptr).cmd as *const libc::c_char } else { b\"*error*\\0\" as *const u8 as *const libc::c_char }, ); free(word as *mut libc::c_void); i = i.wrapping_add(1); i; } free(words as *mut libc::c_void); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1445, "before": "int main() { command_t* commands = make_command_list(command_table); const char* input = \"riG rePEAT copies put mo rest types fup. 6 poweRin\"; test(commands, input); free_command_list(commands); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut commands: *mut command_t = make_command_list(command_table); let mut input: *const libc::c_char = b\"riG rePEAT copies put mo rest types fup. 6 poweRin\\0\" as *const u8 as *const libc::c_char; test(commands, input); free_command_list(commands); return 0 as libc::c_int; }" }, { "index": 1446, "before": "void bernoulli(mpq_t rop, unsigned int n) { unsigned int m, j; mpq_t *a = malloc(sizeof(mpq_t) * (n + 1)); mpq_for(a, init, n + 1); for (m = 0; m <= n; ++m) { mpq_set_ui(a[m], 1, m + 1); for (j = m; j > 0; --j) { mpq_sub(a[j-1], a[j], a[j-1]); mpq_set_ui(rop, j, 1); mpq_mul(a[j-1], a[j-1], rop); } } mpq_set(rop, a[0]); mpq_for(a, clear, n + 1); free(a); }", "after": "pub unsafe extern \"C\" fn bernoulli(mut rop: libc::c_int, mut n: libc::c_uint) { let mut m: libc::c_uint = 0; let mut j: libc::c_uint = 0; let mut i: size_t = 0; m = 0 as libc::c_int as libc::c_uint; while m <= n { j = m; while j > 0 as libc::c_int as libc::c_uint { j = j.wrapping_sub(1); j; } m = m.wrapping_add(1); m; } let mut i_0: size_t = 0; }" }, { "index": 1447, "before": "int main() { const int N = 2; int base = 10; int c1 = 0; int c2 = 0; int k; for (k = 1; k < pow(base, N); k++) { c1++; if (k % (base - 1) == (k * k) % (base - 1)) { c2++; printf(\"%d \", k); } } printf(\"\\nTring %d numbers instead of %d numbers saves %f%%\\n\", c2, c1, 100.0 - 100.0 * c2 / c1); return 0; }", "after": "unsafe fn main() -> libc::c_int { let N: libc::c_int = 2 as libc::c_int; let mut base: libc::c_int = 10 as libc::c_int; let mut c1: libc::c_int = 0 as libc::c_int; let mut c2: libc::c_int = 0 as libc::c_int; let mut k: libc::c_int = 0; k = 1 as libc::c_int; while (k as libc::c_double) < pow(base as libc::c_double, N as libc::c_double) { c1 += 1; c1; if k % (base - 1 as libc::c_int) == k * k % (base - 1 as libc::c_int) { c2 += 1; c2; printf(b\"%d \\0\" as *const u8 as *const libc::c_char, k); } k += 1; k; } printf( b\"\\nTring %d numbers instead of %d numbers saves %f%%\\n\\0\" as *const u8 as *const libc::c_char, c2, c1, 100.0f64 - 100.0f64 * c2 as libc::c_double / c1 as libc::c_double, ); return 0 as libc::c_int; }" }, { "index": 1448, "before": "struct PrimeArray allocate() { struct PrimeArray primes; primes.size = 0; primes.capacity = 10; primes.ptr = malloc(primes.capacity * sizeof(llong_t)); return primes; }", "after": "pub unsafe extern \"C\" fn allocate() -> PrimeArray { let mut primes: PrimeArray = PrimeArray { ptr: 0 as *mut llong_t, size: 0, capacity: 0, }; primes.size = 0 as libc::c_int as size_t; primes.capacity = 10 as libc::c_int as size_t; primes .ptr = malloc( (primes.capacity) .wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut llong_t; return primes; }" }, { "index": 1449, "before": "void deallocate(struct PrimeArray *primes) { free(primes->ptr); primes->ptr = NULL; }", "after": "pub unsafe extern \"C\" fn deallocate(mut primes: *mut PrimeArray) { free((*primes).ptr as *mut libc::c_void); (*primes).ptr = 0 as *mut llong_t; }" }, { "index": 1450, "before": "void push_back(struct PrimeArray *primes, llong_t p) { if (primes->size >= primes->capacity) { size_t new_capacity = (3 * primes->capacity) / 2 + 1; llong_t *temp = realloc(primes->ptr, new_capacity * sizeof(llong_t)); if (NULL == temp) { fprintf(stderr, \"Failed to reallocate the prime array.\"); exit(1); } else { primes->ptr = temp; primes->capacity = new_capacity; } } primes->ptr[primes->size++] = p; }", "after": "pub unsafe extern \"C\" fn push_back(mut primes: *mut PrimeArray, mut p: llong_t) { if (*primes).size >= (*primes).capacity { let mut new_capacity: size_t = (3 as libc::c_int as libc::c_ulong) .wrapping_mul((*primes).capacity) .wrapping_div(2 as libc::c_int as libc::c_ulong) .wrapping_add(1 as libc::c_int as libc::c_ulong); let mut temp: *mut llong_t = realloc( (*primes).ptr as *mut libc::c_void, new_capacity.wrapping_mul(::core::mem::size_of::() as libc::c_ulong), ) as *mut llong_t; if temp.is_null() { fprintf( stderr, b\"Failed to reallocate the prime array.\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } else { (*primes).ptr = temp; (*primes).capacity = new_capacity; } } let fresh0 = (*primes).size; (*primes).size = ((*primes).size).wrapping_add(1); *((*primes).ptr).offset(fresh0 as isize) = p; }" }, { "index": 1451, "before": "int main() { const int cutOff = 200, bigUn = 100000, chunks = 50, little = bigUn / chunks; struct PrimeArray primes = allocate(); int c = 0; bool showEach = true; llong_t u = 0, v = 1, i; push_back(&primes, 3); push_back(&primes, 5); printf(\"The first %d cuban primes:\\n\", cutOff); for (i = 1; i < LLONG_MAX; ++i) { bool found = false; llong_t mx = ceil(sqrt(v += (u += 6))); llong_t j; for (j = 0; j < primes.size; ++j) { if (primes.ptr[j] > mx) { break; } if (v % primes.ptr[j] == 0) { found = true; break; } } if (!found) { c += 1; if (showEach) { llong_t z; for (z = primes.ptr[primes.size - 1] + 2; z <= v - 2; z += 2) { bool fnd = false; for (j = 0; j < primes.size; ++j) { if (primes.ptr[j] > mx) { break; } if (z % primes.ptr[j] == 0) { fnd = true; break; } } if (!fnd) { push_back(&primes, z); } } push_back(&primes, v); printf(\"%11lld\", v); if (c % 10 == 0) { printf(\"\\n\"); } if (c == cutOff) { showEach = false; printf(\"\\nProgress to the %dth cuban prime: \", bigUn); } } if (c % little == 0) { printf(\".\"); if (c == bigUn) { break; } } } } printf(\"\\nThe %dth cuban prime is %lld\\n\", c, v); deallocate(&primes); return 0; }", "after": "unsafe fn main() -> libc::c_int { let cutOff: libc::c_int = 200 as libc::c_int; let bigUn: libc::c_int = 100000 as libc::c_int; let chunks: libc::c_int = 50 as libc::c_int; let little: libc::c_int = bigUn / chunks; let mut primes: PrimeArray = allocate(); let mut c: libc::c_int = 0 as libc::c_int; let mut showEach: bool = 1 as libc::c_int != 0; let mut u: llong_t = 0 as libc::c_int as llong_t; let mut v: llong_t = 1 as libc::c_int as llong_t; let mut i: llong_t = 0; push_back(&mut primes, 3 as libc::c_int as llong_t); push_back(&mut primes, 5 as libc::c_int as llong_t); printf( b\"The first %d cuban primes:\\n\\0\" as *const u8 as *const libc::c_char, cutOff, ); i = 1 as libc::c_int as llong_t; while i < 9223372036854775807 as libc::c_longlong { let mut found: bool = 0 as libc::c_int != 0; u += 6 as libc::c_int as libc::c_longlong; v += u; let mut mx: llong_t = ceil(sqrt(v as libc::c_double)) as llong_t; let mut j: llong_t = 0; j = 0 as libc::c_int as llong_t; while (j as libc::c_ulonglong) < primes.size as libc::c_ulonglong { if *(primes.ptr).offset(j as isize) > mx { break; } if v % *(primes.ptr).offset(j as isize) == 0 as libc::c_int as libc::c_longlong { found = 1 as libc::c_int != 0; break; } else { j += 1; j; } } if !found { c += 1 as libc::c_int; if showEach { let mut z: llong_t = 0; z = *(primes.ptr) .offset( (primes.size).wrapping_sub(1 as libc::c_int as libc::c_ulong) as isize, ) + 2 as libc::c_int as libc::c_longlong; while z <= v - 2 as libc::c_int as libc::c_longlong { let mut fnd: bool = 0 as libc::c_int != 0; j = 0 as libc::c_int as llong_t; while (j as libc::c_ulonglong) < primes.size as libc::c_ulonglong { if *(primes.ptr).offset(j as isize) > mx { break; } if z % *(primes.ptr).offset(j as isize) == 0 as libc::c_int as libc::c_longlong { fnd = 1 as libc::c_int != 0; break; } else { j += 1; j; } } if !fnd { push_back(&mut primes, z); } z += 2 as libc::c_int as libc::c_longlong; } push_back(&mut primes, v); printf(b\"%11lld\\0\" as *const u8 as *const libc::c_char, v); if c % 10 as libc::c_int == 0 as libc::c_int { printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); } if c == cutOff { showEach = 0 as libc::c_int != 0; printf( b\"\\nProgress to the %dth cuban prime: \\0\" as *const u8 as *const libc::c_char, bigUn, ); } } if c % little == 0 as libc::c_int { printf(b\".\\0\" as *const u8 as *const libc::c_char); if c == bigUn { break; } } } i += 1; i; } printf( b\"\\nThe %dth cuban prime is %lld\\n\\0\" as *const u8 as *const libc::c_char, c, v, ); deallocate(&mut primes); return 0 as libc::c_int; }" }, { "index": 1452, "before": "double inf(void) { return HUGE_VAL; }", "after": "pub unsafe extern \"C\" fn inf() -> libc::c_double { return ::core::f64::INFINITY; }" }, { "index": 1453, "before": "int main() { printf(\"%g\\n\", inf()); return 0; }", "after": "unsafe fn main() -> libc::c_int { printf(b\"%g\\n\\0\" as *const u8 as *const libc::c_char, inf()); return 0 as libc::c_int; }" }, { "index": 1454, "before": "int main() { ULONG n, x, p; int i, first; for (x = 1; x < 1000; x++) { printf(\"%lld = \", n = x); for (i = 0, first = 1;; i++) { p = get_prime(i); while (n % p == 0) { n /= p; if (!first) printf(\" x \"); first = 0; printf(\"%lld\", p); } if (n <= p * p) break; } if (first) printf(\"%lld\\n\", n); else if (n > 1) printf(\" x %lld\\n\", n); else printf(\"\\n\"); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: ULONG = 0; let mut x: ULONG = 0; let mut p: ULONG = 0; let mut i: libc::c_int = 0; let mut first: libc::c_int = 0; x = 1 as libc::c_int as ULONG; while x < 1000 as libc::c_int as libc::c_ulonglong { n = x; printf(b\"%lld = \\0\" as *const u8 as *const libc::c_char, n); i = 0 as libc::c_int; first = 1 as libc::c_int; loop { p = get_prime(i); while n.wrapping_rem(p) == 0 as libc::c_int as libc::c_ulonglong { n = (n as libc::c_ulonglong).wrapping_div(p) as ULONG as ULONG; if first == 0 { printf(b\" x \\0\" as *const u8 as *const libc::c_char); } first = 0 as libc::c_int; printf(b\"%lld\\0\" as *const u8 as *const libc::c_char, p); } if n <= p.wrapping_mul(p) { break; } i += 1; i; } if first != 0 { printf(b\"%lld\\n\\0\" as *const u8 as *const libc::c_char, n); } else if n > 1 as libc::c_int as libc::c_ulonglong { printf(b\" x %lld\\n\\0\" as *const u8 as *const libc::c_char, n); } else { printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); } x = x.wrapping_add(1); x; } return 0 as libc::c_int; }" }, { "index": 1455, "before": "ULONG get_prime(int idx) { static long n_primes = 0, alloc = 0; static ULONG *primes = 0; ULONG last, p; int i; if (idx >= n_primes) { if (n_primes >= alloc) { alloc += 16; /* be conservative */ primes = realloc(primes, sizeof(ULONG) * alloc); } if (!n_primes) { primes[0] = 2; primes[1] = 3; n_primes = 2; } last = primes[n_primes - 1]; while (idx >= n_primes) { last += 2; for (i = 0; i < n_primes; i++) { p = primes[i]; if (p * p > last) { primes[n_primes++] = last; break; } if (last % p == 0) break; } } } return primes[idx]; }", "after": "pub unsafe extern \"C\" fn get_prime(mut idx: libc::c_int) -> ULONG { static mut n_primes: libc::c_long = 0 as libc::c_int as libc::c_long; static mut alloc: libc::c_long = 0 as libc::c_int as libc::c_long; static mut primes: *mut ULONG = 0 as *const ULONG as *mut ULONG; let mut last: ULONG = 0; let mut p: ULONG = 0; let mut i: libc::c_int = 0; if idx as libc::c_long >= n_primes { if n_primes >= alloc { alloc += 16 as libc::c_int as libc::c_long; primes = realloc( primes as *mut libc::c_void, (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(alloc as libc::c_ulong), ) as *mut ULONG; } if n_primes == 0 { *primes.offset(0 as libc::c_int as isize) = 2 as libc::c_int as ULONG; *primes.offset(1 as libc::c_int as isize) = 3 as libc::c_int as ULONG; n_primes = 2 as libc::c_int as libc::c_long; } last = *primes.offset((n_primes - 1 as libc::c_int as libc::c_long) as isize); while idx as libc::c_long >= n_primes { last = (last as libc::c_ulonglong) .wrapping_add(2 as libc::c_int as libc::c_ulonglong) as ULONG as ULONG; i = 0 as libc::c_int; while (i as libc::c_long) < n_primes { p = *primes.offset(i as isize); if p.wrapping_mul(p) > last { let fresh0 = n_primes; n_primes = n_primes + 1; *primes.offset(fresh0 as isize) = last; break; } else { if last.wrapping_rem(p) == 0 as libc::c_int as libc::c_ulonglong { break; } i += 1; i; } } } } return *primes.offset(idx as isize); }" }, { "index": 1456, "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 unsafe extern \"C\" fn mat_mul(mut a: matrix, mut b: matrix) -> matrix { let mut r: matrix = 0 as *mut matrix_t; let mut p: *mut libc::c_double = 0 as *mut libc::c_double; let mut pa: *mut libc::c_double = 0 as *mut libc::c_double; let mut i: libc::c_int = 0; let mut j: libc::c_int = 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 as libc::c_int; while i < (*a).h { j = 0 as libc::c_int; 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": 1457, "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 unsafe extern \"C\" fn mat_new(mut h: libc::c_int, mut w: libc::c_int) -> matrix { let mut r: matrix = malloc( (::core::mem::size_of::() as libc::c_ulong) .wrapping_add( (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(w as libc::c_ulong) .wrapping_mul(h as libc::c_ulong), ), ) as matrix; (*r).h = h; (*r).w = w; (*r).x = r.offset(1 as libc::c_int as isize) as *mut libc::c_double; return r; }" }, { "index": 1458, "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 unsafe extern \"C\" fn mat_show(mut a: matrix) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut p: *mut libc::c_double = (*a).x; i = 0 as libc::c_int; while i < (*a).h { j = 0 as libc::c_int; while j < (*a).w { let fresh3 = p; p = p.offset(1); printf(b\"\\t%7.3f\\0\" as *const u8 as *const libc::c_char, *fresh3); j += 1; j; } i += 1; i; putchar('\\n' as i32); } putchar('\\n' as i32); }" }, { "index": 1459, "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 unsafe extern \"C\" fn dot( mut a: *mut libc::c_double, mut b: *mut libc::c_double, mut len: libc::c_int, mut step: libc::c_int, ) -> libc::c_double { let mut r: libc::c_double = 0 as libc::c_int as libc::c_double; 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": 1460, "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": "unsafe fn main() -> libc::c_int { let mut da: [libc::c_double; 16] = [ 1 as libc::c_int as libc::c_double, 1 as libc::c_int as libc::c_double, 1 as libc::c_int as libc::c_double, 1 as libc::c_int as libc::c_double, 2 as libc::c_int as libc::c_double, 4 as libc::c_int as libc::c_double, 8 as libc::c_int as libc::c_double, 16 as libc::c_int as libc::c_double, 3 as libc::c_int as libc::c_double, 9 as libc::c_int as libc::c_double, 27 as libc::c_int as libc::c_double, 81 as libc::c_int as libc::c_double, 4 as libc::c_int as libc::c_double, 16 as libc::c_int as libc::c_double, 64 as libc::c_int as libc::c_double, 256 as libc::c_int as libc::c_double, ]; let mut db: [libc::c_double; 12] = [ 4.0f64, -3.0f64, 4.0f64 / 3 as libc::c_int as libc::c_double, -13.0f64 / 3 as libc::c_int as libc::c_double, 19.0f64 / 4 as libc::c_int as libc::c_double, -7.0f64 / 3 as libc::c_int as libc::c_double, 3.0f64 / 2 as libc::c_int as libc::c_double, -2.0f64, 7.0f64 / 6 as libc::c_int as libc::c_double, -1.0f64 / 6 as libc::c_int as libc::c_double, 1.0f64 / 4 as libc::c_int as libc::c_double, -1.0f64 / 6 as libc::c_int as libc::c_double, ]; let mut a: matrix_t = { let mut init = matrix_t { h: 4 as libc::c_int, w: 4 as libc::c_int, x: da.as_mut_ptr(), }; init }; let mut b: matrix_t = { let mut init = matrix_t { h: 4 as libc::c_int, w: 3 as libc::c_int, x: db.as_mut_ptr(), }; init }; let mut c: matrix = mat_mul(&mut a, &mut b); mat_show(c); return 0 as libc::c_int; }" }, { "index": 1461, "before": "void draw_sphere(double R, double k, double ambient) { int i, j, intensity; double b; double vec[3], x, y; for (i = floor(-R); i <= ceil(R); i++) { x = i + .5; for (j = floor(-2 * R); j <= ceil(2 * R); j++) { y = j / 2. + .5; if (x * x + y * y <= R * R) { vec[0] = x; vec[1] = y; vec[2] = sqrt(R * R - x * x - y * y); normalize(vec); b = pow(dot(light, vec), k) + ambient; intensity = (1 - b) * (sizeof(shades) - 1); if (intensity < 0) intensity = 0; if (intensity >= sizeof(shades) - 1) intensity = sizeof(shades) - 2; putchar(shades[intensity]); } else putchar(' '); } putchar('\\n'); } }", "after": "pub unsafe extern \"C\" fn draw_sphere( mut R: libc::c_double, mut k: libc::c_double, mut ambient: libc::c_double, ) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut intensity: libc::c_int = 0; let mut b: libc::c_double = 0.; let mut vec: [libc::c_double; 3] = [0.; 3]; let mut x: libc::c_double = 0.; let mut y: libc::c_double = 0.; i = floor(-R) as libc::c_int; while i as libc::c_double <= ceil(R) { x = i as libc::c_double + 0.5f64; j = floor(-(2 as libc::c_int) as libc::c_double * R) as libc::c_int; while j as libc::c_double <= ceil(2 as libc::c_int as libc::c_double * R) { y = j as libc::c_double / 2.0f64 + 0.5f64; if x * x + y * y <= R * R { vec[0 as libc::c_int as usize] = x; vec[1 as libc::c_int as usize] = y; vec[2 as libc::c_int as usize] = sqrt(R * R - x * x - y * y); normalize(vec.as_mut_ptr()); b = pow(dot(light.as_mut_ptr(), vec.as_mut_ptr()), k) + ambient; intensity = ((1 as libc::c_int as libc::c_double - b) * (::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong) .wrapping_sub(1 as libc::c_int as libc::c_ulong) as libc::c_double) as libc::c_int; if intensity < 0 as libc::c_int { intensity = 0 as libc::c_int; } if intensity as libc::c_ulong >= (::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong) .wrapping_sub(1 as libc::c_int as libc::c_ulong) { intensity = (::core::mem::size_of::<*const libc::c_char>() as libc::c_ulong) .wrapping_sub(2 as libc::c_int as libc::c_ulong) as libc::c_int; } putchar(*shades.offset(intensity as isize) as libc::c_int); } else { putchar(' ' as i32); } j += 1; j; } putchar('\\n' as i32); i += 1; i; } }" }, { "index": 1462, "before": "double dot(double *x, double *y) { double d = x[0]*y[0] + x[1]*y[1] + x[2]*y[2]; return d < 0 ? -d : 0; }", "after": "pub unsafe extern \"C\" fn dot( mut x: *mut libc::c_double, mut y: *mut libc::c_double, ) -> libc::c_double { let mut d: libc::c_double = *x.offset(0 as libc::c_int as isize) * *y.offset(0 as libc::c_int as isize) + *x.offset(1 as libc::c_int as isize) * *y.offset(1 as libc::c_int as isize) + *x.offset(2 as libc::c_int as isize) * *y.offset(2 as libc::c_int as isize); return if d < 0 as libc::c_int as libc::c_double { -d } else { 0 as libc::c_int as libc::c_double }; }" }, { "index": 1463, "before": "int main() { normalize(light); draw_sphere(20, 4, .1); draw_sphere(10, 2, .4); return 0; }", "after": "unsafe fn main() -> libc::c_int { normalize(light.as_mut_ptr()); draw_sphere( 20 as libc::c_int as libc::c_double, 4 as libc::c_int as libc::c_double, 0.1f64, ); draw_sphere( 10 as libc::c_int as libc::c_double, 2 as libc::c_int as libc::c_double, 0.4f64, ); return 0 as libc::c_int; }" }, { "index": 1464, "before": "void normalize(double * v) { double len = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); v[0] /= len; v[1] /= len; v[2] /= len; }", "after": "pub unsafe extern \"C\" fn normalize(mut v: *mut libc::c_double) { let mut len: libc::c_double = sqrt( *v.offset(0 as libc::c_int as isize) * *v.offset(0 as libc::c_int as isize) + *v.offset(1 as libc::c_int as isize) * *v.offset(1 as libc::c_int as isize) + *v.offset(2 as libc::c_int as isize) * *v.offset(2 as libc::c_int as isize), ); *v.offset(0 as libc::c_int as isize) /= len; *v.offset(1 as libc::c_int as isize) /= len; *v.offset(2 as libc::c_int as isize) /= len; }" }, { "index": 1465, "before": "int main() { time_t t = 0; printf(\"%s\", asctime(gmtime(&t))); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut t: time_t = 0 as libc::c_int as time_t; printf(b\"%s\\0\" as *const u8 as *const libc::c_char, asctime(gmtime(&mut t))); return 0 as libc::c_int; }" }, { "index": 1466, "before": "int M(const int n) { return (n == 0) ? 0 : n - F(M(n - 1)); }", "after": "pub unsafe extern \"C\" fn M(n: libc::c_int) -> libc::c_int { return if n == 0 as libc::c_int { 0 as libc::c_int } else { n - F(M(n - 1 as libc::c_int)) }; }" }, { "index": 1467, "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": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 20 as libc::c_int { printf(b\"%2d \\0\" as *const u8 as *const libc::c_char, F(i)); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < 20 as libc::c_int { printf(b\"%2d \\0\" as *const u8 as *const libc::c_char, M(i)); i += 1; i; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); return 0 as libc::c_int; }" }, { "index": 1468, "before": "int F(const int n) { return (n == 0) ? 1 : n - M(F(n - 1)); }", "after": "pub unsafe extern \"C\" fn F(n: libc::c_int) -> libc::c_int { return if n == 0 as libc::c_int { 1 as libc::c_int } else { n - M(F(n - 1 as libc::c_int)) }; }" }, { "index": 1469, "before": "date extractDate(char* str){ return (date){.year = 1000 * (str[0]-'0') + 100 * (str[1]-'0') + 10 * (str[2]-'0') + (str[3]-'0'), .month = 10*(str[5]-'0') + (str[6]-'0'), .day = 10*(str[8]-'0') + (str[9]-'0')}; }", "after": "pub unsafe extern \"C\" fn extractDate(mut str: *mut libc::c_char) -> date { return { let mut init = date { year: 1000 as libc::c_int * (*str.offset(0 as libc::c_int as isize) as libc::c_int - '0' as i32) + 100 as libc::c_int * (*str.offset(1 as libc::c_int as isize) as libc::c_int - '0' as i32) + 10 as libc::c_int * (*str.offset(2 as libc::c_int as isize) as libc::c_int - '0' as i32) + (*str.offset(3 as libc::c_int as isize) as libc::c_int - '0' as i32), month: 10 as libc::c_int * (*str.offset(5 as libc::c_int as isize) as libc::c_int - '0' as i32) + (*str.offset(6 as libc::c_int as isize) as libc::c_int - '0' as i32), day: 10 as libc::c_int * (*str.offset(8 as libc::c_int as isize) as libc::c_int - '0' as i32) + (*str.offset(9 as libc::c_int as isize) as libc::c_int - '0' as i32), }; init }; }" }, { "index": 1470, "before": "int diffDays(date date1,date date2){ int days1, days2; date1.month = (date1.month + 9)%12; date1.year = date1.year - date1.month/10; date2.month = (date2.month + 9)%12; date2.year = date2.year - date2.month/10; days1 = 365*date1.year + date1.year/4 - date1.year/100 + date1.year/400 + (date1.month*306 + 5)/10 + ( date1.day - 1 ); days2 = 365*date2.year + date2.year/4 - date2.year/100 + date2.year/400 + (date2.month*306 + 5)/10 + ( date2.day - 1 ); return days2 - days1; }", "after": "pub unsafe extern \"C\" fn diffDays(mut date1: date, mut date2: date) -> libc::c_int { let mut days1: libc::c_int = 0; let mut days2: libc::c_int = 0; date1.month = (date1.month + 9 as libc::c_int) % 12 as libc::c_int; date1.year = date1.year - date1.month / 10 as libc::c_int; date2.month = (date2.month + 9 as libc::c_int) % 12 as libc::c_int; date2.year = date2.year - date2.month / 10 as libc::c_int; days1 = 365 as libc::c_int * date1.year + date1.year / 4 as libc::c_int - date1.year / 100 as libc::c_int + date1.year / 400 as libc::c_int + (date1.month * 306 as libc::c_int + 5 as libc::c_int) / 10 as libc::c_int + (date1.day - 1 as libc::c_int); days2 = 365 as libc::c_int * date2.year + date2.year / 4 as libc::c_int - date2.year / 100 as libc::c_int + date2.year / 400 as libc::c_int + (date2.month * 306 as libc::c_int + 5 as libc::c_int) / 10 as libc::c_int + (date2.day - 1 as libc::c_int); return days2 - days1; }" }, { "index": 1471, "before": "bool isValidDate(char* str){ date newDate; if(strlen(str)!=10 && str[4]!='-' && str[7]!='-'){ return false; } newDate = extractDate(str); if(newDate.year<=0 || newDate.month<=0 || newDate.day<=0 || newDate.month>12 || (newDate.month==2 && newDate.day>29) || ((newDate.month==1 || newDate.month==3 || newDate.month==5 || newDate.month==7 || newDate.month==8 || newDate.month==10 || newDate.month==12) && newDate.day>31) || newDate.day>30 || (newDate.year%4==0 && newDate.month==2 && newDate.month>28)){ return false; } return true; }", "after": "pub unsafe extern \"C\" fn isValidDate(mut str: *mut libc::c_char) -> bool { let mut newDate: date = date { year: 0, month: 0, day: 0 }; if strlen(str) != 10 as libc::c_int as libc::c_ulong && *str.offset(4 as libc::c_int as isize) as libc::c_int != '-' as i32 && *str.offset(7 as libc::c_int as isize) as libc::c_int != '-' as i32 { return 0 as libc::c_int != 0; } newDate = extractDate(str); if newDate.year <= 0 as libc::c_int || newDate.month <= 0 as libc::c_int || newDate.day <= 0 as libc::c_int || newDate.month > 12 as libc::c_int || newDate.month == 2 as libc::c_int && newDate.day > 29 as libc::c_int || (newDate.month == 1 as libc::c_int || newDate.month == 3 as libc::c_int || newDate.month == 5 as libc::c_int || newDate.month == 7 as libc::c_int || newDate.month == 8 as libc::c_int || newDate.month == 10 as libc::c_int || newDate.month == 12 as libc::c_int) && newDate.day > 31 as libc::c_int || newDate.day > 30 as libc::c_int || newDate.year % 4 as libc::c_int == 0 as libc::c_int && newDate.month == 2 as libc::c_int && newDate.month > 28 as libc::c_int { return 0 as libc::c_int != 0; } return 1 as libc::c_int != 0; }" }, { "index": 1472, "before": "int main(int argc,char** argv) { if(argc!=3){ return printf(\"Usage : %s \",argv[0]); } if(isValidDate(argv[1])&&isValidDate(argv[2]) == false){ return printf(\"Dates are invalid.\\n\"); } printf(\"Days Difference : %d\\n\", diffDays(extractDate(argv[1]),extractDate(argv[2]))); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { if argc != 3 as libc::c_int { return printf( b\"Usage : %s \\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); } if isValidDate(*argv.offset(1 as libc::c_int as isize)) as libc::c_int != 0 && isValidDate(*argv.offset(2 as libc::c_int as isize)) as libc::c_int == 0 as libc::c_int { return printf(b\"Dates are invalid.\\n\\0\" as *const u8 as *const libc::c_char); } printf( b\"Days Difference : %d\\n\\0\" as *const u8 as *const libc::c_char, diffDays( extractDate(*argv.offset(1 as libc::c_int as isize)), extractDate(*argv.offset(2 as libc::c_int as isize)), ), ); return 0 as libc::c_int; }" }, { "index": 1473, "before": "int main () { int i, n, tw = 0, tv = 0, *s; n = sizeof (items) / sizeof (item_t); s = knapsack(items, n, 400); for (i = 0; i < n; i++) { if (s[i]) { printf(\"%-22s %5d %5d\\n\", items[i].name, items[i].weight, items[i].value); tw += items[i].weight; tv += items[i].value; } } printf(\"%-22s %5d %5d\\n\", \"totals:\", tw, tv); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut n: libc::c_int = 0; let mut tw: libc::c_int = 0 as libc::c_int; let mut tv: libc::c_int = 0 as libc::c_int; let mut s: *mut libc::c_int = 0 as *mut libc::c_int; n = (::core::mem::size_of::<[item_t; 22]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int; s = knapsack(items.as_mut_ptr(), n, 400 as libc::c_int); i = 0 as libc::c_int; while i < n { if *s.offset(i as isize) != 0 { printf( b\"%-22s %5d %5d\\n\\0\" as *const u8 as *const libc::c_char, items[i as usize].name, items[i as usize].weight, items[i as usize].value, ); tw += items[i as usize].weight; tv += items[i as usize].value; } i += 1; i; } printf( b\"%-22s %5d %5d\\n\\0\" as *const u8 as *const libc::c_char, b\"totals:\\0\" as *const u8 as *const libc::c_char, tw, tv, ); return 0 as libc::c_int; }" }, { "index": 1474, "before": "int main(int argc,char** argv) { int i,len; if(argc>2){ printf(\"Usage : %s \\n\",argv[0]); return 0; } if(argc==1||strlen(argv[1])==1){ printf(\"\\\"%s\\\" - Length %d - Contains only unique characters.\\n\",argc==1?\"\":argv[1],argc==1?0:1); return 0; } len = strlen(argv[1]); for(i=0;i libc::c_int { let mut i: libc::c_int = 0; let mut len: libc::c_int = 0; if argc > 2 as libc::c_int { printf( b\"Usage : %s \\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); return 0 as libc::c_int; } if argc == 1 as libc::c_int || strlen(*argv.offset(1 as libc::c_int as isize)) == 1 as libc::c_int as libc::c_ulong { printf( b\"\\\"%s\\\" - Length %d - Contains only unique characters.\\n\\0\" as *const u8 as *const libc::c_char, if argc == 1 as libc::c_int { b\"\\0\" as *const u8 as *const libc::c_char } else { *argv.offset(1 as libc::c_int as isize) as *const libc::c_char }, if argc == 1 as libc::c_int { 0 as libc::c_int } else { 1 as libc::c_int }, ); return 0 as libc::c_int; } len = strlen(*argv.offset(1 as libc::c_int as isize)) as libc::c_int; i = 0 as libc::c_int; while i < len { checkAndUpdateLetterList( *(*argv.offset(1 as libc::c_int as isize)).offset(i as isize), i, ); i += 1; i; } printf( b\"\\\"%s\\\" - Length %d - %s\\0\" as *const u8 as *const libc::c_char, *argv.offset(1 as libc::c_int as isize), len, if duplicatesFound as libc::c_int == 0 as libc::c_int { b\"Contains only unique characters.\\n\\0\" as *const u8 as *const libc::c_char } else { b\"Contains the following duplicate characters :\\0\" as *const u8 as *const libc::c_char }, ); if duplicatesFound as libc::c_int == 1 as libc::c_int { printLetterList(); } return 0 as libc::c_int; }" }, { "index": 1475, "before": "void checkAndUpdateLetterList(char c,int pos){ bool letterOccurs = false; letterList *letterIterator,*newLetter; positionList *positionIterator,*newPosition; if(letterSet==NULL){ letterSet = (letterList*)malloc(sizeof(letterList)); letterSet->letter = c; letterSet->repititions = 0; letterSet->positions = (positionList*)malloc(sizeof(positionList)); letterSet->positions->position = pos; letterSet->positions->next = NULL; letterSet->next = NULL; } else{ letterIterator = letterSet; while(letterIterator!=NULL){ if(letterIterator->letter==c){ letterOccurs = true; duplicatesFound = true; letterIterator->repititions++; positionIterator = letterIterator->positions; while(positionIterator->next!=NULL) positionIterator = positionIterator->next; newPosition = (positionList*)malloc(sizeof(positionList)); newPosition->position = pos; newPosition->next = NULL; positionIterator->next = newPosition; } if(letterOccurs==false && letterIterator->next==NULL) break; else letterIterator = letterIterator->next; } if(letterOccurs==false){ newLetter = (letterList*)malloc(sizeof(letterList)); newLetter->letter = c; newLetter->repititions = 0; newLetter->positions = (positionList*)malloc(sizeof(positionList)); newLetter->positions->position = pos; newLetter->positions->next = NULL; newLetter->next = NULL; letterIterator->next = newLetter; } } }", "after": "pub unsafe extern \"C\" fn checkAndUpdateLetterList( mut c: libc::c_char, mut pos: libc::c_int, ) { let mut letterOccurs: bool = 0 as libc::c_int != 0; let mut letterIterator: *mut letterList = 0 as *mut letterList; let mut newLetter: *mut letterList = 0 as *mut letterList; let mut positionIterator: *mut positionList = 0 as *mut positionList; let mut newPosition: *mut positionList = 0 as *mut positionList; if letterSet.is_null() { letterSet = malloc(::core::mem::size_of::() as libc::c_ulong) as *mut letterList; (*letterSet).letter = c; (*letterSet).repititions = 0 as libc::c_int; (*letterSet) .positions = malloc(::core::mem::size_of::() as libc::c_ulong) as *mut positionList; (*(*letterSet).positions).position = pos; (*(*letterSet).positions).next = 0 as *mut positionList; (*letterSet).next = 0 as *mut letterList; } else { letterIterator = letterSet; while !letterIterator.is_null() { if (*letterIterator).letter as libc::c_int == c as libc::c_int { letterOccurs = 1 as libc::c_int != 0; duplicatesFound = 1 as libc::c_int != 0; (*letterIterator).repititions += 1; (*letterIterator).repititions; positionIterator = (*letterIterator).positions; while !((*positionIterator).next).is_null() { positionIterator = (*positionIterator).next; } newPosition = malloc( ::core::mem::size_of::() as libc::c_ulong, ) as *mut positionList; (*newPosition).position = pos; (*newPosition).next = 0 as *mut positionList; (*positionIterator).next = newPosition; } if letterOccurs as libc::c_int == 0 as libc::c_int && ((*letterIterator).next).is_null() { break; } letterIterator = (*letterIterator).next; } if letterOccurs as libc::c_int == 0 as libc::c_int { newLetter = malloc(::core::mem::size_of::() as libc::c_ulong) as *mut letterList; (*newLetter).letter = c; (*newLetter).repititions = 0 as libc::c_int; (*newLetter) .positions = malloc( ::core::mem::size_of::() as libc::c_ulong, ) as *mut positionList; (*(*newLetter).positions).position = pos; (*(*newLetter).positions).next = 0 as *mut positionList; (*newLetter).next = 0 as *mut letterList; (*letterIterator).next = newLetter; } }; }" }, { "index": 1476, "before": "void printLetterList(){ positionList* positionIterator; letterList* letterIterator = letterSet; while(letterIterator!=NULL){ if(letterIterator->repititions>0){ printf(\"\\n'%c' (0x%x) at positions :\",letterIterator->letter,letterIterator->letter); positionIterator = letterIterator->positions; while(positionIterator!=NULL){ printf(\"%3d\",positionIterator->position + 1); positionIterator = positionIterator->next; } } letterIterator = letterIterator->next; } printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn printLetterList() { let mut positionIterator: *mut positionList = 0 as *mut positionList; let mut letterIterator: *mut letterList = letterSet; while !letterIterator.is_null() { if (*letterIterator).repititions > 0 as libc::c_int { printf( b\"\\n'%c' (0x%x) at positions :\\0\" as *const u8 as *const libc::c_char, (*letterIterator).letter as libc::c_int, (*letterIterator).letter as libc::c_int, ); positionIterator = (*letterIterator).positions; while !positionIterator.is_null() { printf( b\"%3d\\0\" as *const u8 as *const libc::c_char, (*positionIterator).position + 1 as libc::c_int, ); positionIterator = (*positionIterator).next; } } letterIterator = (*letterIterator).next; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1477, "before": "int droot(long long int x, int base, int *pers) { \tint d = 0; \tif (pers) \t\tfor (*pers = 0; x >= base; x = d, (*pers)++) \t\t\tfor (d = 0; x; d += x % base, x /= base); \telse if (x && !(d = x % (base - 1))) \t\t\td = base - 1; \treturn d; }", "after": "pub unsafe extern \"C\" fn droot( mut x: libc::c_longlong, mut base: libc::c_int, mut pers: *mut libc::c_int, ) -> libc::c_int { let mut d: libc::c_int = 0 as libc::c_int; if !pers.is_null() { *pers = 0 as libc::c_int; while x >= base as libc::c_longlong { d = 0 as libc::c_int; while x != 0 { d = (d as libc::c_longlong + x % base as libc::c_longlong) as libc::c_int; x /= base as libc::c_longlong; } x = d as libc::c_longlong; *pers += 1; *pers; } } else if x != 0 && { d = (x % (base - 1 as libc::c_int) as libc::c_longlong) as libc::c_int; d == 0 } { d = base - 1 as libc::c_int; } return d; }" }, { "index": 1478, "before": "int main(void) { \tint i, d, pers; \tlong long x[] = {627615, 39390, 588225, 393900588225LL}; \tfor (i = 0; i < 4; i++) { \t\td = droot(x[i], 10, &pers); \t\tprintf(\"%lld: pers %d, root %d\\n\", x[i], pers, d); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut d: libc::c_int = 0; let mut pers: libc::c_int = 0; let mut x: [libc::c_longlong; 4] = [ 627615 as libc::c_int as libc::c_longlong, 39390 as libc::c_int as libc::c_longlong, 588225 as libc::c_int as libc::c_longlong, 393900588225 as libc::c_longlong, ]; i = 0 as libc::c_int; while i < 4 as libc::c_int { d = droot(x[i as usize], 10 as libc::c_int, &mut pers); printf( b\"%lld: pers %d, root %d\\n\\0\" as *const u8 as *const libc::c_char, x[i as usize], pers, d, ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1479, "before": "int main() { \tstring_test(\"+0\"); \tstring_test(\"-1\"); \tstring_test(\"-41\"); \tstring_test(\"+41\"); \tstring_test(\"999\"); \tstring_test(\"+999\"); \tstring_test(\"109999999999999999999999999999999999999999\"); \tstring_test(\"-100000000000000000000000000000000000000000000\"); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { string_test(b\"+0\\0\" as *const u8 as *const libc::c_char); string_test(b\"-1\\0\" as *const u8 as *const libc::c_char); string_test(b\"-41\\0\" as *const u8 as *const libc::c_char); string_test(b\"+41\\0\" as *const u8 as *const libc::c_char); string_test(b\"999\\0\" as *const u8 as *const libc::c_char); string_test(b\"+999\\0\" as *const u8 as *const libc::c_char); string_test( b\"109999999999999999999999999999999999999999\\0\" as *const u8 as *const libc::c_char, ); string_test( b\"-100000000000000000000000000000000000000000000\\0\" as *const u8 as *const libc::c_char, ); return 0 as libc::c_int; }" }, { "index": 1480, "before": "void string_test(const char *s) { \tchar *ret = malloc(strlen(s)); \tstrcpy(ret, s); \tprintf(\"text: %s\\n\", ret); \tprintf(\" ->: %s\\n\", ret = incr(ret)); \tfree(ret); }", "after": "pub unsafe extern \"C\" fn string_test(mut s: *const libc::c_char) { let mut ret: *mut libc::c_char = malloc(strlen(s)) as *mut libc::c_char; strcpy(ret, s); printf(b\"text: %s\\n\\0\" as *const u8 as *const libc::c_char, ret); ret = incr(ret); printf(b\" ->: %s\\n\\0\" as *const u8 as *const libc::c_char, ret); free(ret as *mut libc::c_void); }" }, { "index": 1481, "before": "int main (int argc, char *argv[]) { //here we check arguments \tif (argc < 2) { printf(\"Enter an argument. Example 1234 or dcba:\\n\"); return 0; \t} //it calculates an array's length int x; for (x = 0; argv[1][x] != '\\0'; x++); //buble sort the array \tint f, v, m; \t for(f=0; f < x; f++) { \t for(v = x-1; v > f; v-- ) { \t if (argv[1][v-1] > argv[1][v]) { \tm=argv[1][v-1]; \targv[1][v-1]=argv[1][v]; \targv[1][v]=m; } } } //it calculates a factorial to stop the algorithm char a[x]; \tint k=0; \tint fact=k+1; while (k!=x) { a[k]=argv[1][k]; \t k++; \t\t fact = k*fact; } a[k]='\\0'; //Main part: here we permutate int i, j; int y=0; char c; while (y != fact) { printf(\"%s\\n\", a); i=x-2; while(a[i] > a[i+1] ) i--; j=x-1; while(a[j] < a[i] ) j--; c=a[j]; a[j]=a[i]; a[i]=c; i++; for (j = x-1; j > i; i++, j--) { c = a[i]; a[i] = a[j]; a[j] = c; } y++; } }", "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\"Enter an argument. Example 1234 or dcba:\\n\\0\" as *const u8 as *const libc::c_char, ); return 0 as libc::c_int; } let mut x: libc::c_int = 0; x = 0 as libc::c_int; while *(*argv.offset(1 as libc::c_int as isize)).offset(x as isize) as libc::c_int != '\\0' as i32 { x += 1; x; } let mut f: libc::c_int = 0; let mut v: libc::c_int = 0; let mut m: libc::c_int = 0; f = 0 as libc::c_int; while f < x { v = x - 1 as libc::c_int; while v > f { if *(*argv.offset(1 as libc::c_int as isize)) .offset((v - 1 as libc::c_int) as isize) as libc::c_int > *(*argv.offset(1 as libc::c_int as isize)).offset(v as isize) as libc::c_int { m = *(*argv.offset(1 as libc::c_int as isize)) .offset((v - 1 as libc::c_int) as isize) as libc::c_int; *(*argv.offset(1 as libc::c_int as isize)) .offset( (v - 1 as libc::c_int) as isize, ) = *(*argv.offset(1 as libc::c_int as isize)).offset(v as isize); *(*argv.offset(1 as libc::c_int as isize)) .offset(v as isize) = m as libc::c_char; } v -= 1; v; } f += 1; f; } let vla = x as usize; let mut a: Vec:: = ::std::vec::from_elem(0, vla); let mut k: libc::c_int = 0 as libc::c_int; let mut fact: libc::c_int = k + 1 as libc::c_int; while k != x { *a .as_mut_ptr() .offset( k as isize, ) = *(*argv.offset(1 as libc::c_int as isize)).offset(k as isize); k += 1; k; fact = k * fact; } *a.as_mut_ptr().offset(k as isize) = '\\0' as i32 as libc::c_char; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut y: libc::c_int = 0 as libc::c_int; let mut c: libc::c_char = 0; while y != fact { printf(b\"%s\\n\\0\" as *const u8 as *const libc::c_char, a.as_mut_ptr()); i = x - 2 as libc::c_int; while *a.as_mut_ptr().offset(i as isize) as libc::c_int > *a.as_mut_ptr().offset((i + 1 as libc::c_int) as isize) as libc::c_int { i -= 1; i; } j = x - 1 as libc::c_int; while (*a.as_mut_ptr().offset(j as isize) as libc::c_int) < *a.as_mut_ptr().offset(i as isize) as libc::c_int { j -= 1; j; } c = *a.as_mut_ptr().offset(j as isize); *a.as_mut_ptr().offset(j as isize) = *a.as_mut_ptr().offset(i as isize); *a.as_mut_ptr().offset(i as isize) = c; i += 1; i; j = x - 1 as libc::c_int; while j > i { c = *a.as_mut_ptr().offset(i as isize); *a.as_mut_ptr().offset(i as isize) = *a.as_mut_ptr().offset(j as isize); *a.as_mut_ptr().offset(j as isize) = c; i += 1; i; j -= 1; j; } y += 1; y; } return 0; }" }, { "index": 1482, "before": "int main() { int years[] = { 1935, 1938, 1968, 1972, 1976, 2017 }; int i; //the zodiac cycle didnt start until 4 CE, so years <4 shouldnt be valid for (i = 0; i < 6; ++i) { int year = years[i]; printf(\"%d is the year of the %s %s (%s).\\n\", year, getElement(year), getAnimal(year), getYY(year)); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut years: [libc::c_int; 6] = [ 1935 as libc::c_int, 1938 as libc::c_int, 1968 as libc::c_int, 1972 as libc::c_int, 1976 as libc::c_int, 2017 as libc::c_int, ]; let mut i: libc::c_int = 0; i = 0 as libc::c_int; while i < 6 as libc::c_int { let mut year: libc::c_int = years[i as usize]; printf( b\"%d is the year of the %s %s (%s).\\n\\0\" as *const u8 as *const libc::c_char, year, getElement(year), getAnimal(year), getYY(year), ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1483, "before": "int main() { int i, j, n; int a1[4] = {5, 6, 3, 1}; int a2[13] = {1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2}; int a3[12] = {1000, 1, 500, 12, 1, 700, 2500, 3, 2, 5, 14, 10}; int *dims_list[3] = {a1, a2, a3}; int sizes[3] = {4, 13, 12}; for (i = 0; i < 3; ++i) { printf(\"Dims : [\"); n = sizes[i]; for (j = 0; j < n; ++j) { printf(\"%d\", dims_list[i][j]); if (j < n - 1) printf(\", \"); else printf(\"]\\n\"); } optimal_matrix_chain_order(dims_list[i], n); printf(\"Order : \"); print_optimal_chain_order(0, n - 2); printf(\"\\nCost : %d\\n\\n\", m[0][n - 2]); for (j = 0; j <= n - 2; ++j) free(m[j]); free(m); for (j = 0; j <= n - 2; ++j) free(s[j]); free(s); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut n: libc::c_int = 0; let mut a1: [libc::c_int; 4] = [ 5 as libc::c_int, 6 as libc::c_int, 3 as libc::c_int, 1 as libc::c_int, ]; let mut a2: [libc::c_int; 13] = [ 1 as libc::c_int, 5 as libc::c_int, 25 as libc::c_int, 30 as libc::c_int, 100 as libc::c_int, 70 as libc::c_int, 2 as libc::c_int, 1 as libc::c_int, 100 as libc::c_int, 250 as libc::c_int, 1 as libc::c_int, 1000 as libc::c_int, 2 as libc::c_int, ]; let mut a3: [libc::c_int; 12] = [ 1000 as libc::c_int, 1 as libc::c_int, 500 as libc::c_int, 12 as libc::c_int, 1 as libc::c_int, 700 as libc::c_int, 2500 as libc::c_int, 3 as libc::c_int, 2 as libc::c_int, 5 as libc::c_int, 14 as libc::c_int, 10 as libc::c_int, ]; let mut dims_list: [*mut libc::c_int; 3] = [ a1.as_mut_ptr(), a2.as_mut_ptr(), a3.as_mut_ptr(), ]; let mut sizes: [libc::c_int; 3] = [ 4 as libc::c_int, 13 as libc::c_int, 12 as libc::c_int, ]; i = 0 as libc::c_int; while i < 3 as libc::c_int { printf(b\"Dims : [\\0\" as *const u8 as *const libc::c_char); n = sizes[i as usize]; j = 0 as libc::c_int; while j < n { printf( b\"%d\\0\" as *const u8 as *const libc::c_char, *(dims_list[i as usize]).offset(j as isize), ); if j < n - 1 as libc::c_int { printf(b\", \\0\" as *const u8 as *const libc::c_char); } else { printf(b\"]\\n\\0\" as *const u8 as *const libc::c_char); } j += 1; j; } optimal_matrix_chain_order(dims_list[i as usize], n); printf(b\"Order : \\0\" as *const u8 as *const libc::c_char); print_optimal_chain_order(0 as libc::c_int, n - 2 as libc::c_int); printf( b\"\\nCost : %d\\n\\n\\0\" as *const u8 as *const libc::c_char, *(*m.offset(0 as libc::c_int as isize)) .offset((n - 2 as libc::c_int) as isize), ); j = 0 as libc::c_int; while j <= n - 2 as libc::c_int { free(*m.offset(j as isize) as *mut libc::c_void); j += 1; j; } free(m as *mut libc::c_void); j = 0 as libc::c_int; while j <= n - 2 as libc::c_int { free(*s.offset(j as isize) as *mut libc::c_void); j += 1; j; } free(s as *mut libc::c_void); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1484, "before": "void optimal_matrix_chain_order(int *dims, int n) { int len, i, j, k, temp, cost; n--; m = (int **)malloc(n * sizeof(int *)); for (i = 0; i < n; ++i) { m[i] = (int *)calloc(n, sizeof(int)); } s = (int **)malloc(n * sizeof(int *)); for (i = 0; i < n; ++i) { s[i] = (int *)calloc(n, sizeof(int)); } for (len = 1; len < n; ++len) { for (i = 0; i < n - len; ++i) { j = i + len; m[i][j] = INT_MAX; for (k = i; k < j; ++k) { temp = dims[i] * dims[k + 1] * dims[j + 1]; cost = m[i][k] + m[k + 1][j] + temp; if (cost < m[i][j]) { m[i][j] = cost; s[i][j] = k; } } } } }", "after": "pub unsafe extern \"C\" fn optimal_matrix_chain_order( mut dims: *mut libc::c_int, mut n: libc::c_int, ) { let mut len: libc::c_int = 0; let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut k: libc::c_int = 0; let mut temp: libc::c_int = 0; let mut cost: libc::c_int = 0; n -= 1; n; m = malloc( (n as libc::c_ulong) .wrapping_mul(::core::mem::size_of::<*mut libc::c_int>() as libc::c_ulong), ) as *mut *mut libc::c_int; i = 0 as libc::c_int; while i < n { let ref mut fresh0 = *m.offset(i as isize); *fresh0 = calloc( n as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; i += 1; i; } s = malloc( (n as libc::c_ulong) .wrapping_mul(::core::mem::size_of::<*mut libc::c_int>() as libc::c_ulong), ) as *mut *mut libc::c_int; i = 0 as libc::c_int; while i < n { let ref mut fresh1 = *s.offset(i as isize); *fresh1 = calloc( n as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; i += 1; i; } len = 1 as libc::c_int; while len < n { i = 0 as libc::c_int; while i < n - len { j = i + len; *(*m.offset(i as isize)).offset(j as isize) = 2147483647 as libc::c_int; k = i; while k < j { temp = *dims.offset(i as isize) * *dims.offset((k + 1 as libc::c_int) as isize) * *dims.offset((j + 1 as libc::c_int) as isize); cost = *(*m.offset(i as isize)).offset(k as isize) + *(*m.offset((k + 1 as libc::c_int) as isize)).offset(j as isize) + temp; if cost < *(*m.offset(i as isize)).offset(j as isize) { *(*m.offset(i as isize)).offset(j as isize) = cost; *(*s.offset(i as isize)).offset(j as isize) = k; } k += 1; k; } i += 1; i; } len += 1; len; } }" }, { "index": 1485, "before": "void print_optimal_chain_order(int i, int j) { if (i == j) printf(\"%c\", i + 65); else { printf(\"(\"); print_optimal_chain_order(i, s[i][j]); print_optimal_chain_order(s[i][j] + 1, j); printf(\")\"); } }", "after": "pub unsafe extern \"C\" fn print_optimal_chain_order( mut i: libc::c_int, mut j: libc::c_int, ) { if i == j { printf(b\"%c\\0\" as *const u8 as *const libc::c_char, i + 65 as libc::c_int); } else { printf(b\"(\\0\" as *const u8 as *const libc::c_char); print_optimal_chain_order(i, *(*s.offset(i as isize)).offset(j as isize)); print_optimal_chain_order( *(*s.offset(i as isize)).offset(j as isize) + 1 as libc::c_int, j, ); printf(b\")\\0\" as *const u8 as *const libc::c_char); }; }" }, { "index": 1486, "before": "int main(void) { const int len = sizeof(tri) / sizeof(tri[0]); const int base = (sqrt(8*len + 1) - 1) / 2; int step = base - 1; int stepc = 0; int i; for (i = len - base - 1; i >= 0; --i) { tri[i] += max(tri[i + step], tri[i + step + 1]); if (++stepc == step) { step--; stepc = 0; } } printf(\"%d\\n\", tri[0]); return 0; }", "after": "unsafe fn main() -> libc::c_int { let len: libc::c_int = (::core::mem::size_of::<[libc::c_int; 171]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int; let base: libc::c_int = ((sqrt( (8 as libc::c_int * len + 1 as libc::c_int) as libc::c_double, ) - 1 as libc::c_int as libc::c_double) / 2 as libc::c_int as libc::c_double) as libc::c_int; let mut step: libc::c_int = base - 1 as libc::c_int; let mut stepc: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 0; i = len - base - 1 as libc::c_int; while i >= 0 as libc::c_int { tri[i as usize] += if tri[(i + step) as usize] > tri[(i + step + 1 as libc::c_int) as usize] { tri[(i + step) as usize] } else { tri[(i + step + 1 as libc::c_int) as usize] }; stepc += 1; if stepc == step { step -= 1; step; stepc = 0 as libc::c_int; } i -= 1; i; } printf( b\"%d\\n\\0\" as *const u8 as *const libc::c_char, tri[0 as libc::c_int as usize], ); return 0 as libc::c_int; }" }, { "index": 1487, "before": "ull catalan2(int n) { \tint i; \tull r = !n; \tfor (i = 0; i < n; i++) \t\tr += catalan2(i) * catalan2(n - 1 - i); \treturn r; }", "after": "pub unsafe extern \"C\" fn catalan2(mut n: libc::c_int) -> ull { let mut i: libc::c_int = 0; let mut r: ull = (n == 0) as libc::c_int as ull; i = 0 as libc::c_int; while i < n { r = (r as libc::c_ulonglong) .wrapping_add((catalan2(i)).wrapping_mul(catalan2(n - 1 as libc::c_int - i))) as ull as ull; i += 1; i; } return r; }" }, { "index": 1488, "before": "ull catalan3(int n) { \treturn n ? 2 * (2 * n - 1) * catalan3(n - 1) / (1 + n) : 1; }", "after": "pub unsafe extern \"C\" fn catalan3(mut n: libc::c_int) -> ull { return if n != 0 { ((2 as libc::c_int * (2 as libc::c_int * n - 1 as libc::c_int)) as libc::c_ulonglong) .wrapping_mul(catalan3(n - 1 as libc::c_int)) .wrapping_div((1 as libc::c_int + n) as libc::c_ulonglong) } else { 1 as libc::c_int as libc::c_ulonglong }; }" }, { "index": 1489, "before": "ull catalan1(int n) { \treturn binomial(2 * n, n) / (1 + n); }", "after": "pub unsafe extern \"C\" fn catalan1(mut n: libc::c_int) -> ull { return (binomial((2 as libc::c_int * n) as ull, n as ull)) .wrapping_div((1 as libc::c_int + n) as libc::c_ulonglong); }" }, { "index": 1490, "before": "ull binomial(ull m, ull n) { \tull r = 1, d = m - n; \tif (d > n) { n = d; d = m - n; } \twhile (m > n) { \t\tr *= m--; \t\twhile (d > 1 && ! (r%d) ) r /= d--; \t} \treturn r; }", "after": "pub unsafe extern \"C\" fn binomial(mut m: ull, mut n: ull) -> ull { let mut r: ull = 1 as libc::c_int as ull; let mut d: ull = m.wrapping_sub(n); if d > n { n = d; d = m.wrapping_sub(n); } while m > n { let fresh0 = m; m = m.wrapping_sub(1); r = (r as libc::c_ulonglong).wrapping_mul(fresh0) as ull as ull; while d > 1 as libc::c_int as libc::c_ulonglong && r.wrapping_rem(d) == 0 { let fresh1 = d; d = d.wrapping_sub(1); r = (r as libc::c_ulonglong).wrapping_div(fresh1) as ull as ull; } } return r; }" }, { "index": 1491, "before": "int main(void) { \tint i; \tputs(\"\\tdirect\\tsumming\\tfrac\"); \tfor (i = 0; i < 16; i++) { \t\tprintf(\"%d\\t%llu\\t%llu\\t%llu\\n\", i, \t\t\tcatalan1(i), catalan2(i), catalan3(i)); \t} \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut i: libc::c_int = 0; puts(b\"\\tdirect\\tsumming\\tfrac\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < 16 as libc::c_int { printf( b\"%d\\t%llu\\t%llu\\t%llu\\n\\0\" as *const u8 as *const libc::c_char, i, catalan1(i), catalan2(i), catalan3(i), ); i += 1; i; } return 0 as libc::c_int; }" }, { "index": 1492, "before": "int main() { xint seed[3] = {3, 4, 5}; for (max_peri = 10; max_peri <= 100000000; max_peri *= 10) { total = prim = 0; new_tri(seed); printf( \"Up to \"FMT\": \"FMT\" triples, \"FMT\" primitives.\\n\", max_peri, total, prim); } return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut seed: [xint; 3] = [ 3 as libc::c_int as xint, 4 as libc::c_int as xint, 5 as libc::c_int as xint, ]; max_peri = 10 as libc::c_int as xint; while max_peri <= 100000000 as libc::c_int as libc::c_ulong { prim = 0 as libc::c_int as xint; total = prim; new_tri(seed.as_mut_ptr()); printf( b\"Up to %lu: %lu triples, %lu primitives.\\n\\0\" as *const u8 as *const libc::c_char, max_peri, total, prim, ); max_peri = (max_peri as libc::c_ulong) .wrapping_mul(10 as libc::c_int as libc::c_ulong) as xint as xint; } return 0 as libc::c_int; }" }, { "index": 1493, "before": "void new_tri(xint in[]) { int i; xint t[3], p = in[0] + in[1] + in[2]; if (p > max_peri) return; prim ++; /* for every primitive triangle, its multiples would be right-angled too; * count them up to the max perimeter */ total += max_peri / p; /* recursively produce next tier by multiplying the matrices */ for (i = 0; i < 3; i++) { t[0] = U[i][0] * in[0] + U[i][1] * in[1] + U[i][2] * in[2]; t[1] = U[i][3] * in[0] + U[i][4] * in[1] + U[i][5] * in[2]; t[2] = U[i][6] * in[0] + U[i][7] * in[1] + U[i][8] * in[2]; new_tri(t); } }", "after": "pub unsafe extern \"C\" fn new_tri(mut in_0: *mut xint) { let mut i: libc::c_int = 0; let mut t: [xint; 3] = [0; 3]; let mut p: xint = (*in_0.offset(0 as libc::c_int as isize)) .wrapping_add(*in_0.offset(1 as libc::c_int as isize)) .wrapping_add(*in_0.offset(2 as libc::c_int as isize)); if p > max_peri { return; } prim = prim.wrapping_add(1); prim; total = (total as libc::c_ulong).wrapping_add(max_peri.wrapping_div(p)) as xint as xint; i = 0 as libc::c_int; while i < 3 as libc::c_int { t[0 as libc::c_int as usize] = (U[i as usize][0 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(0 as libc::c_int as isize)) .wrapping_add( (U[i as usize][1 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(1 as libc::c_int as isize)), ) .wrapping_add( (U[i as usize][2 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(2 as libc::c_int as isize)), ); t[1 as libc::c_int as usize] = (U[i as usize][3 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(0 as libc::c_int as isize)) .wrapping_add( (U[i as usize][4 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(1 as libc::c_int as isize)), ) .wrapping_add( (U[i as usize][5 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(2 as libc::c_int as isize)), ); t[2 as libc::c_int as usize] = (U[i as usize][6 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(0 as libc::c_int as isize)) .wrapping_add( (U[i as usize][7 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(1 as libc::c_int as isize)), ) .wrapping_add( (U[i as usize][8 as libc::c_int as usize]) .wrapping_mul(*in_0.offset(2 as libc::c_int as isize)), ); new_tri(t.as_mut_ptr()); i += 1; i; } }" }, { "index": 1494, "before": "int is_leap_year(int year) { return (!(year % 4) && year % 100 || !(year % 400)) ? 1 : 0; }", "after": "pub unsafe extern \"C\" fn is_leap_year(mut year: libc::c_int) -> libc::c_int { return if year % 4 as libc::c_int == 0 && year % 100 as libc::c_int != 0 || year % 400 as libc::c_int == 0 { 1 as libc::c_int } else { 0 as libc::c_int }; }" }, { "index": 1495, "before": "int main() { int test_case[] = {1900, 1994, 1996, 1997, 2000}, key, end, year; for (key = 0, end = sizeof(test_case)/sizeof(test_case[0]); key < end; ++key) { year = test_case[key]; printf(\"%d is %sa leap year.\\n\", year, (is_leap_year(year) == 1 ? \"\" : \"not \")); } }", "after": "unsafe fn main() -> libc::c_int { let mut test_case: [libc::c_int; 5] = [ 1900 as libc::c_int, 1994 as libc::c_int, 1996 as libc::c_int, 1997 as libc::c_int, 2000 as libc::c_int, ]; let mut key: libc::c_int = 0; let mut end: libc::c_int = 0; let mut year: libc::c_int = 0; key = 0 as libc::c_int; end = (::core::mem::size_of::<[libc::c_int; 5]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int; while key < end { year = test_case[key as usize]; printf( b\"%d is %sa leap year.\\n\\0\" as *const u8 as *const libc::c_char, year, if is_leap_year(year) == 1 as libc::c_int { b\"\\0\" as *const u8 as *const libc::c_char } else { b\"not \\0\" as *const u8 as *const libc::c_char }, ); key += 1; key; } return 0; }" }, { "index": 1496, "before": "uint32_t cycle(uint32_t n) { uint32_t m = n, p = 1; while (m >= 10) { p *= 10; m /= 10; } return m + 10 * (n % p); }", "after": "pub unsafe extern \"C\" fn cycle(mut n: uint32_t) -> uint32_t { let mut m: uint32_t = n; let mut p: uint32_t = 1 as libc::c_int as uint32_t; while m >= 10 as libc::c_int as libc::c_uint { p = (p as libc::c_uint).wrapping_mul(10 as libc::c_int as libc::c_uint) as uint32_t as uint32_t; m = (m as libc::c_uint).wrapping_div(10 as libc::c_int as libc::c_uint) as uint32_t as uint32_t; } return m .wrapping_add( (10 as libc::c_int as libc::c_uint).wrapping_mul(n.wrapping_rem(p)), ); }" }, { "index": 1497, "before": "bool is_circular_prime(uint32_t p) { if (!is_prime(p)) return false; uint32_t p2 = cycle(p); while (p2 != p) { if (p2 < p || !is_prime(p2)) return false; p2 = cycle(p2); } return true; }", "after": "pub unsafe extern \"C\" fn is_circular_prime(mut p: uint32_t) -> bool { if !is_prime(p) { return 0 as libc::c_int != 0; } let mut p2: uint32_t = cycle(p); while p2 != p { if p2 < p || !is_prime(p2) { return 0 as libc::c_int != 0; } p2 = cycle(p2); } return 1 as libc::c_int != 0; }" }, { "index": 1498, "before": "bool is_prime(uint32_t n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (uint32_t p = 3; p * p <= n; p += 2) { if (n % p == 0) return false; } return true; }", "after": "pub unsafe extern \"C\" fn is_prime(mut n: uint32_t) -> bool { if n == 2 as libc::c_int as libc::c_uint { return 1 as libc::c_int != 0; } if n < 2 as libc::c_int as libc::c_uint || n.wrapping_rem(2 as libc::c_int as libc::c_uint) == 0 as libc::c_int as libc::c_uint { return 0 as libc::c_int != 0; } let mut p: uint32_t = 3 as libc::c_int as uint32_t; while p.wrapping_mul(p) <= n { if n.wrapping_rem(p) == 0 as libc::c_int as libc::c_uint { return 0 as libc::c_int != 0; } p = (p as libc::c_uint).wrapping_add(2 as libc::c_int as libc::c_uint) as uint32_t as uint32_t; } return 1 as libc::c_int != 0; }" }, { "index": 1499, "before": "void fatal(const char* message) { fprintf(stderr, \"%s\\n\", message); exit(1); }", "after": "pub unsafe extern \"C\" fn fatal(mut message: *const libc::c_char) { fprintf(stderr, b\"%s\\n\\0\" as *const u8 as *const libc::c_char, message); exit(1 as libc::c_int); }" }, { "index": 1500, "before": "bool command_match(const command_t* command, const char* str) { size_t olen = strlen(str); return olen >= command->min_len && olen <= command->length && strncmp(str, command->cmd, olen) == 0; }", "after": "pub unsafe extern \"C\" fn command_match( mut command: *const command_t, mut str: *const libc::c_char, ) -> bool { let mut olen: size_t = strlen(str); return olen >= (*command).min_len && olen <= (*command).length && strncmp(str, (*command).cmd, olen) == 0 as libc::c_int; }" }, { "index": 1501, "before": "size_t get_min_length(const char* str, size_t n) { size_t len = 0; while (len < n && isupper((unsigned char)str[len])) ++len; return len; }", "after": "pub unsafe extern \"C\" fn get_min_length( mut str: *const libc::c_char, mut n: size_t, ) -> size_t { let mut len: size_t = 0 as libc::c_int as size_t; while len < n && *(*__ctype_b_loc()) .offset(*str.offset(len as isize) as libc::c_uchar as libc::c_int as isize) as libc::c_int & _ISupper as libc::c_int as libc::c_ushort as libc::c_int != 0 { len = len.wrapping_add(1); len; } return len; }" }, { "index": 1502, "before": "int main() { command_t* commands = make_command_list(command_table); const char* input = \"riG rePEAT copies put mo rest types fup. 6 poweRin\"; test(commands, input); free_command_list(commands); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut commands: *mut command_t = make_command_list(command_table); let mut input: *const libc::c_char = b\"riG rePEAT copies put mo rest types fup. 6 poweRin\\0\" as *const u8 as *const libc::c_char; test(commands, input); free_command_list(commands); return 0 as libc::c_int; }" }, { "index": 1503, "before": "void test(const command_t* commands, const char* input) { printf(\" input: %s\\n\", input); printf(\"output:\"); size_t count = 0; char** words = split_into_words(input, &count); for (size_t i = 0; i < count; ++i) { char* word = words[i]; uppercase(word, strlen(word)); const command_t* cmd_ptr = find_command(commands, word); printf(\" %s\", cmd_ptr ? cmd_ptr->cmd : \"*error*\"); free(word); } free(words); printf(\"\\n\"); }", "after": "pub unsafe extern \"C\" fn test( mut commands: *const command_t, mut input: *const libc::c_char, ) { printf(b\" input: %s\\n\\0\" as *const u8 as *const libc::c_char, input); printf(b\"output:\\0\" as *const u8 as *const libc::c_char); let mut count: size_t = 0 as libc::c_int as size_t; let mut words: *mut *mut libc::c_char = split_into_words(input, &mut count); let mut i: size_t = 0 as libc::c_int as size_t; while i < count { let mut word: *mut libc::c_char = *words.offset(i as isize); uppercase(word, strlen(word)); let mut cmd_ptr: *const command_t = find_command(commands, word); printf( b\" %s\\0\" as *const u8 as *const libc::c_char, if !cmd_ptr.is_null() { (*cmd_ptr).cmd as *const libc::c_char } else { b\"*error*\\0\" as *const u8 as *const libc::c_char }, ); free(word as *mut libc::c_void); i = i.wrapping_add(1); i; } free(words as *mut libc::c_void); printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); }" }, { "index": 1504, "before": "void free_command_list(command_t* cmd) { while (cmd != NULL) { command_t* next = cmd->next; free(cmd->cmd); free(cmd); cmd = next; } }", "after": "pub unsafe extern \"C\" fn free_command_list(mut cmd: *mut command_t) { while !cmd.is_null() { let mut next: *mut command_t = (*cmd).next; free((*cmd).cmd as *mut libc::c_void); free(cmd as *mut libc::c_void); cmd = next; } }" }, { "index": 1505, "before": "int main(int argc, char **argv) { \tint i, j, n; \t//Edit: Add argument checking \tif(argc!=2) return 1; \t//Edit: Input must be odd and not less than 3. \tn = atoi(argv[1]); \tif (n < 3 || (n%2) == 0) return 2; \tfor (i = 0; i < n; i++) { \t\tfor (j = 0; j < n; j++) \t\t\tprintf(\"% 4d\", f(n, n - j - 1, i)*n + f(n, j, i) + 1); \t\tputchar('\\n'); \t} \tprintf(\"\\n Magic Constant: %d.\\n\", (n*n+1)/2*n); \treturn 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut n: libc::c_int = 0; if argc != 2 as libc::c_int { return 1 as libc::c_int; } n = atoi(*argv.offset(1 as libc::c_int as isize)); if n < 3 as libc::c_int || n % 2 as libc::c_int == 0 as libc::c_int { return 2 as libc::c_int; } i = 0 as libc::c_int; while i < n { j = 0 as libc::c_int; while j < n { printf( b\"% 4d\\0\" as *const u8 as *const libc::c_char, f(n, n - j - 1 as libc::c_int, i) * n + f(n, j, i) + 1 as libc::c_int, ); j += 1; j; } putchar('\\n' as i32); i += 1; i; } printf( b\"\\n Magic Constant: %d.\\n\\0\" as *const u8 as *const libc::c_char, (n * n + 1 as libc::c_int) / 2 as libc::c_int * n, ); return 0 as libc::c_int; }" }, { "index": 1506, "before": "int f(int n, int x, int y) { \treturn (x + y*2 + 1)%n; }", "after": "pub unsafe extern \"C\" fn f( mut n: libc::c_int, mut x: libc::c_int, mut y: libc::c_int, ) -> libc::c_int { return (x + y * 2 as libc::c_int + 1 as libc::c_int) % n; }" }, { "index": 1507, "before": "void coef(int n) { \tint i, j; \tif (n < 0 || n > 63) abort(); // gracefully deal with range issue \tfor (c[i=0] = 1; i < n; c[0] = -c[0], i++) \t\tfor (c[1 + (j=i)] = 1; j > 0; j--) \t\t\tc[j] = c[j-1] - c[j]; }", "after": "pub unsafe extern \"C\" fn coef(mut n: libc::c_int) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; if n < 0 as libc::c_int || n > 63 as libc::c_int { abort(); } i = 0 as libc::c_int; c[i as usize] = 1 as libc::c_int as libc::c_longlong; while i < n { j = i; c[(1 as libc::c_int + j) as usize] = 1 as libc::c_int as libc::c_longlong; while j > 0 as libc::c_int { c[j as usize] = c[(j - 1 as libc::c_int) as usize] - c[j as usize]; j -= 1; j; } c[0 as libc::c_int as usize] = -c[0 as libc::c_int as usize]; i += 1; i; } }" }, { "index": 1508, "before": "void show(int n) { \tdo printf(\"%+lldx^%d\", c[n], n); while (n--); }", "after": "pub unsafe extern \"C\" fn show(mut n: libc::c_int) { loop { printf(b\"%+lldx^%d\\0\" as *const u8 as *const libc::c_char, c[n as usize], n); let fresh1 = n; n = n - 1; if !(fresh1 != 0) { break; } }; }" }, { "index": 1509, "before": "int is_prime(int n) { \tint i; \tcoef(n); \tc[0] += 1, c[i=n] -= 1; \twhile (i-- && !(c[i] % n)); \treturn i < 0; }", "after": "pub unsafe extern \"C\" fn is_prime(mut n: libc::c_int) -> libc::c_int { let mut i: libc::c_int = 0; coef(n); c[0 as libc::c_int as usize] += 1 as libc::c_int as libc::c_longlong; i = n; c[i as usize] -= 1 as libc::c_int as libc::c_longlong; loop { let fresh0 = i; i = i - 1; if !(fresh0 != 0 && c[i as usize] % n as libc::c_longlong == 0) { break; } } return (i < 0 as libc::c_int) as libc::c_int; }" }, { "index": 1510, "before": "int main(void) { \tint n; \tfor (n = 0; n < 10; n++) { \t\tcoef(n); \t\tprintf(\"(x-1)^%d = \", n); \t\tshow(n); \t\tputchar('\\n'); \t} \tprintf(\"\\nprimes (never mind the 1):\"); \tfor (n = 1; n <= 63; n++) \t\tif (is_prime(n)) \t\t\tprintf(\" %d\", n); \tputchar('\\n'); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 0; n = 0 as libc::c_int; while n < 10 as libc::c_int { coef(n); printf(b\"(x-1)^%d = \\0\" as *const u8 as *const libc::c_char, n); show(n); putchar('\\n' as i32); n += 1; n; } printf(b\"\\nprimes (never mind the 1):\\0\" as *const u8 as *const libc::c_char); n = 1 as libc::c_int; while n <= 63 as libc::c_int { if is_prime(n) != 0 { printf(b\" %d\\0\" as *const u8 as *const libc::c_char, n); } n += 1; n; } putchar('\\n' as i32); return 0 as libc::c_int; }" }, { "index": 1511, "before": "uintmax_t week_to_sec(uintmax_t weeks) { return day_to_sec(weeks*7); }", "after": "pub unsafe extern \"C\" fn week_to_sec(mut weeks: uintmax_t) -> uintmax_t { return day_to_sec(weeks.wrapping_mul(7 as libc::c_int as libc::c_ulong)); }" }, { "index": 1512, "before": "uintmax_t hour_to_sec(uintmax_t hours) { return min_to_sec(hours*60); }", "after": "pub unsafe extern \"C\" fn hour_to_sec(mut hours: uintmax_t) -> uintmax_t { return min_to_sec(hours.wrapping_mul(60 as libc::c_int as libc::c_ulong)); }" }, { "index": 1513, "before": "uintmax_t min_to_sec(uintmax_t minutes) { return minutes*60; }", "after": "pub unsafe extern \"C\" fn min_to_sec(mut minutes: uintmax_t) -> uintmax_t { return minutes.wrapping_mul(60 as libc::c_int as libc::c_ulong); }" }, { "index": 1514, "before": "uintmax_t sec_to_hour(uintmax_t seconds) { return sec_to_min(seconds)/60; }", "after": "pub unsafe extern \"C\" fn sec_to_hour(mut seconds: uintmax_t) -> uintmax_t { return (sec_to_min(seconds)).wrapping_div(60 as libc::c_int as libc::c_ulong); }" }, { "index": 1515, "before": "uintmax_t day_to_sec(uintmax_t days) { return hour_to_sec(days*24); }", "after": "pub unsafe extern \"C\" fn day_to_sec(mut days: uintmax_t) -> uintmax_t { return hour_to_sec(days.wrapping_mul(24 as libc::c_int as libc::c_ulong)); }" }, { "index": 1516, "before": "uintmax_t sec_to_week(uintmax_t seconds) { return sec_to_day(seconds)/7; }", "after": "pub unsafe extern \"C\" fn sec_to_week(mut seconds: uintmax_t) -> uintmax_t { return (sec_to_day(seconds)).wrapping_div(7 as libc::c_int as libc::c_ulong); }" }, { "index": 1517, "before": "uintmax_t sec_to_day(uintmax_t seconds) { return sec_to_hour(seconds)/24; }", "after": "pub unsafe extern \"C\" fn sec_to_day(mut seconds: uintmax_t) -> uintmax_t { return (sec_to_hour(seconds)).wrapping_div(24 as libc::c_int as libc::c_ulong); }" }, { "index": 1518, "before": "uintmax_t sec_to_min(uintmax_t seconds) { return seconds/60; }", "after": "pub unsafe extern \"C\" fn sec_to_min(mut seconds: uintmax_t) -> uintmax_t { return seconds.wrapping_div(60 as libc::c_int as libc::c_ulong); }" }, { "index": 1519, "before": "int main(int argc, char *argv[]) { uintmax_t input; char *a; if(argc<2) { printf(\"usage: %s #seconds\\n\", argv[0]); return 1; } input = strtoumax(argv[1],(void *)0, 10 /*base 10*/); if(input<1) { printf(\"Bad input: %s\\n\", argv[1]); printf(\"usage: %s #seconds\\n\", argv[0]); return 1; } printf(\"Number entered: %\" PRIuMAX \"\\n\", input); a = format_sec(input); printf(a); free(a); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut input: uintmax_t = 0; let mut a: *mut libc::c_char = 0 as *mut libc::c_char; if argc < 2 as libc::c_int { printf( b\"usage: %s #seconds\\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); return 1 as libc::c_int; } input = strtoumax( *argv.offset(1 as libc::c_int as isize), 0 as *mut *mut libc::c_char, 10 as libc::c_int, ); if input < 1 as libc::c_int as libc::c_ulong { printf( b\"Bad input: %s\\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(1 as libc::c_int as isize), ); printf( b\"usage: %s #seconds\\n\\0\" as *const u8 as *const libc::c_char, *argv.offset(0 as libc::c_int as isize), ); return 1 as libc::c_int; } printf(b\"Number entered: %lu\\n\\0\" as *const u8 as *const libc::c_char, input); a = format_sec(input); printf(a); free(a as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1520, "before": "int main(int argc, char **argv) { int a, b, c, d, a2, s = 3, s1, s2; int r[N + 1]; memset(r, 0, sizeof(r)); int *ab = calloc(N2 + 1, sizeof(int)); // allocate on heap, zero filled for (a = 1; a <= N; a++) { a2 = a * a; for (b = a; b <= N; b++) ab[a2 + b * b] = 1; } for (c = 1; c <= N; c++) { s1 = s; s += 2; s2 = s; for (d = c + 1; d <= N; d++) { if (ab[s1]) r[d] = 1; s1 += s2; s2 += 2; } } for (d = 1; d <= N; d++) { if (!r[d]) printf(\"%d \", d); } printf(\"\\n\"); free(ab); return 0; }", "after": "unsafe fn main( mut argc: libc::c_int, mut argv: *mut *mut libc::c_char, ) -> libc::c_int { let mut a: libc::c_int = 0; let mut b: libc::c_int = 0; let mut c: libc::c_int = 0; let mut d: libc::c_int = 0; let mut a2: libc::c_int = 0; let mut s: libc::c_int = 3 as libc::c_int; let mut s1: libc::c_int = 0; let mut s2: libc::c_int = 0; let mut r: [libc::c_int; 2201] = [0; 2201]; memset( r.as_mut_ptr() as *mut libc::c_void, 0 as libc::c_int, ::core::mem::size_of::<[libc::c_int; 2201]>() as libc::c_ulong, ); let mut ab: *mut libc::c_int = calloc( (2200 as libc::c_int * 2200 as libc::c_int * 2 as libc::c_int + 1 as libc::c_int) as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; a = 1 as libc::c_int; while a <= 2200 as libc::c_int { a2 = a * a; b = a; while b <= 2200 as libc::c_int { *ab.offset((a2 + b * b) as isize) = 1 as libc::c_int; b += 1; b; } a += 1; a; } c = 1 as libc::c_int; while c <= 2200 as libc::c_int { s1 = s; s += 2 as libc::c_int; s2 = s; d = c + 1 as libc::c_int; while d <= 2200 as libc::c_int { if *ab.offset(s1 as isize) != 0 { r[d as usize] = 1 as libc::c_int; } s1 += s2; s2 += 2 as libc::c_int; d += 1; d; } c += 1; c; } d = 1 as libc::c_int; while d <= 2200 as libc::c_int { if r[d as usize] == 0 { printf(b\"%d \\0\" as *const u8 as *const libc::c_char, d); } d += 1; d; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); free(ab as *mut libc::c_void); return 0 as libc::c_int; }" }, { "index": 1521, "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 unsafe extern \"C\" fn walk() { let mut dx: libc::c_int = 0 as libc::c_int; let mut dy: libc::c_int = 1 as libc::c_int; let mut i: libc::c_int = 0; let mut k: libc::c_int = 0; let mut x: libc::c_int = w / 2 as libc::c_int; let mut y: libc::c_int = h / 2 as libc::c_int; pix = calloc(1 as libc::c_int as libc::c_ulong, (w * h) as libc::c_ulong) as *mut libc::c_uchar; printf(b\"\\x1B[H\\x1B[J\\0\" as *const u8 as *const libc::c_char); 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 libc::c_int as libc::c_uchar; printf( b\"\\x1B[%d;%dH%c\\0\" as *const u8 as *const libc::c_char, y + 1 as libc::c_int, x + 1 as libc::c_int, if *pix.offset(i as isize) as libc::c_int != 0 { '#' as i32 } else { ' ' as i32 }, ); x += dx; y += dy; k = 0 as libc::c_int; if x < 0 as libc::c_int { memmove( pix.offset(1 as libc::c_int as isize) as *mut libc::c_void, pix as *const libc::c_void, (w * h - 1 as libc::c_int) as libc::c_ulong, ); i = 0 as libc::c_int; while i < w * h { *pix.offset(i as isize) = 0 as libc::c_int as libc::c_uchar; i += w; } x += 1; x; k = 1 as libc::c_int; } else if x >= w { memmove( pix as *mut libc::c_void, pix.offset(1 as libc::c_int as isize) as *const libc::c_void, (w * h - 1 as libc::c_int) as libc::c_ulong, ); i = w - 1 as libc::c_int; while i < w * h { *pix.offset(i as isize) = 0 as libc::c_int as libc::c_uchar; i += w; } x -= 1; x; k = 1 as libc::c_int; } if y >= h { memmove( pix as *mut libc::c_void, pix.offset(w as isize) as *const libc::c_void, (w * (h - 1 as libc::c_int)) as libc::c_ulong, ); memset( pix.offset((w * (h - 1 as libc::c_int)) as isize) as *mut libc::c_void, 0 as libc::c_int, w as libc::c_ulong, ); y -= 1; y; k = 1 as libc::c_int; } else if y < 0 as libc::c_int { memmove( pix.offset(w as isize) as *mut libc::c_void, pix as *const libc::c_void, (w * (h - 1 as libc::c_int)) as libc::c_ulong, ); memset(pix as *mut libc::c_void, 0 as libc::c_int, w as libc::c_ulong); y += 1; y; k = 1 as libc::c_int; } if k != 0 { refresh(x, y); } printf( b\"\\x1B[%d;%dH\\x1B[31m@\\x1B[m\\0\" as *const u8 as *const libc::c_char, y + 1 as libc::c_int, x + 1 as libc::c_int, ); fflush(stdout); usleep(10000 as libc::c_int as __useconds_t); }; }" }, { "index": 1522, "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 unsafe extern \"C\" fn refresh(mut x: libc::c_int, mut y: libc::c_int) { let mut i: libc::c_int = 0; let mut j: libc::c_int = 0; let mut k: libc::c_int = 0; printf(b\"\\x1B[H\\0\" as *const u8 as *const libc::c_char); k = 0 as libc::c_int; i = k; while i < h { j = 0 as libc::c_int; while j < w { putchar( if *pix.offset(k as isize) as libc::c_int != 0 { '#' as i32 } else { ' ' as i32 }, ); j += 1; j; k += 1; k; } putchar('\\n' as i32); i += 1; i; } }" }, { "index": 1523, "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": "unsafe fn main(mut c: libc::c_int, mut v: *mut *mut libc::c_char) -> libc::c_int { if c > 1 as libc::c_int { w = atoi(*v.offset(1 as libc::c_int as isize)); } if c > 2 as libc::c_int { h = atoi(*v.offset(2 as libc::c_int as isize)); } if w < 40 as libc::c_int { w = 40 as libc::c_int; } if h < 25 as libc::c_int { h = 25 as libc::c_int; } walk(); return 0 as libc::c_int; }" }, { "index": 1524, "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": "unsafe fn main() -> libc::c_int { let mut blocks: [*mut libc::c_char; 21] = [ b\"BO\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"XK\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"DQ\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"CP\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"NA\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"GT\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"RE\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"TG\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"QD\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"FS\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"JW\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"HU\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"VI\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"AN\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"OB\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"ER\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"FS\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"LY\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"PC\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"ZM\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, 0 as *mut libc::c_char, ]; let mut words: [*mut libc::c_char; 9] = [ b\"\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"A\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"BARK\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"BOOK\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"TREAT\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"COMMON\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"SQUAD\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, b\"Confuse\\0\" as *const u8 as *const libc::c_char as *mut libc::c_char, 0 as *mut libc::c_char, ]; let mut w: *mut *mut libc::c_char = 0 as *mut *mut libc::c_char; w = words.as_mut_ptr(); while !(*w).is_null() { printf( b\"%s\\t%d\\n\\0\" as *const u8 as *const libc::c_char, *w, can_make_words(blocks.as_mut_ptr(), *w), ); w = w.offset(1); w; } return 0 as libc::c_int; }" }, { "index": 1525, "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 unsafe extern \"C\" fn can_make_words( mut b: *mut *mut libc::c_char, mut word: *mut libc::c_char, ) -> libc::c_int { let mut i: libc::c_int = 0; let mut ret: libc::c_int = 0 as libc::c_int; let mut c: libc::c_int = toupper(*word as libc::c_int); if c == 0 { return 1 as libc::c_int; } if (*b.offset(0 as libc::c_int as isize)).is_null() { return 0 as libc::c_int; } i = 0 as libc::c_int; while !(*b.offset(i as isize)).is_null() && ret == 0 { if !(*(*b.offset(i as isize)).offset(0 as libc::c_int as isize) as libc::c_int != c && *(*b.offset(i as isize)).offset(1 as libc::c_int as isize) as libc::c_int != c) { if *b.offset(i as isize) != *b.offset(0 as libc::c_int as isize) { let mut tmp: *mut libc::c_char = *b.offset(i as isize); let ref mut fresh0 = *b.offset(i as isize); *fresh0 = *b.offset(0 as libc::c_int as isize); let ref mut fresh1 = *b.offset(0 as libc::c_int as isize); *fresh1 = tmp; } ret = can_make_words( b.offset(1 as libc::c_int as isize), word.offset(1 as libc::c_int as isize), ); if *b.offset(i as isize) != *b.offset(0 as libc::c_int as isize) { let mut tmp_0: *mut libc::c_char = *b.offset(i as isize); let ref mut fresh2 = *b.offset(i as isize); *fresh2 = *b.offset(0 as libc::c_int as isize); let ref mut fresh3 = *b.offset(0 as libc::c_int as isize); *fresh3 = tmp_0; } } i += 1; i; } return ret; }" }, { "index": 1526, "before": "uint32_t next_highest_int(uint32_t n) { char str[16]; snprintf(str, sizeof(str), \"%u\", n); if (!next_permutation(str)) return 0; return strtoul(str, 0, 10); }", "after": "pub unsafe extern \"C\" fn next_highest_int(mut n: uint32_t) -> uint32_t { let mut str: [libc::c_char; 16] = [0; 16]; snprintf( str.as_mut_ptr(), ::core::mem::size_of::<[libc::c_char; 16]>() as libc::c_ulong, b\"%u\\0\" as *const u8 as *const libc::c_char, n, ); if !next_permutation(str.as_mut_ptr()) { return 0 as libc::c_int as uint32_t; } return strtoul(str.as_mut_ptr(), 0 as *mut *mut libc::c_char, 10 as libc::c_int) as uint32_t; }" }, { "index": 1527, "before": "int main() { uint32_t numbers[] = {0, 9, 12, 21, 12453, 738440, 45072010, 95322020}; const int count = sizeof(numbers)/sizeof(int); for (int i = 0; i < count; ++i) printf(\"%d -> %d\\n\", numbers[i], next_highest_int(numbers[i])); // Last one is too large to convert to an integer const char big[] = \"9589776899767587796600\"; char next[sizeof(big)]; memcpy(next, big, sizeof(big)); next_permutation(next); printf(\"%s -> %s\\n\", big, next); return 0; }", "after": "unsafe fn main() -> libc::c_int { let mut numbers: [uint32_t; 8] = [ 0 as libc::c_int as uint32_t, 9 as libc::c_int as uint32_t, 12 as libc::c_int as uint32_t, 21 as libc::c_int as uint32_t, 12453 as libc::c_int as uint32_t, 738440 as libc::c_int as uint32_t, 45072010 as libc::c_int as uint32_t, 95322020 as libc::c_int as uint32_t, ]; let count: libc::c_int = (::core::mem::size_of::<[uint32_t; 8]>() as libc::c_ulong) .wrapping_div(::core::mem::size_of::() as libc::c_ulong) as libc::c_int; let mut i: libc::c_int = 0 as libc::c_int; while i < count { printf( b\"%d -> %d\\n\\0\" as *const u8 as *const libc::c_char, numbers[i as usize], next_highest_int(numbers[i as usize]), ); i += 1; i; } let big: [libc::c_char; 23] = *::core::mem::transmute::< &[u8; 23], &[libc::c_char; 23], >(b\"9589776899767587796600\\0\"); let mut next: [libc::c_char; 23] = [0; 23]; memcpy( next.as_mut_ptr() as *mut libc::c_void, big.as_ptr() as *const libc::c_void, ::core::mem::size_of::<[libc::c_char; 23]>() as libc::c_ulong, ); next_permutation(next.as_mut_ptr()); printf( b\"%s -> %s\\n\\0\" as *const u8 as *const libc::c_char, big.as_ptr(), next.as_mut_ptr(), ); return 0 as libc::c_int; }" }, { "index": 1528, "before": "bool next_permutation(char* str) { int len = strlen(str); if (len < 2) return false; for (int i = len - 1; i > 0; ) { int j = i, k; if (str[--i] < str[j]) { k = len; while (str[i] >= str[--k]) {} swap(str, i, k); reverse(str, j, len - 1); return true; } } return false; }", "after": "pub unsafe extern \"C\" fn next_permutation(mut str: *mut libc::c_char) -> bool { let mut len: libc::c_int = strlen(str) as libc::c_int; if len < 2 as libc::c_int { return 0 as libc::c_int != 0; } let mut i: libc::c_int = len - 1 as libc::c_int; while i > 0 as libc::c_int { let mut j: libc::c_int = i; let mut k: libc::c_int = 0; i -= 1; if (*str.offset(i as isize) as libc::c_int) < *str.offset(j as isize) as libc::c_int { k = len; loop { k -= 1; if !(*str.offset(i as isize) as libc::c_int >= *str.offset(k as isize) as libc::c_int) { break; } } swap(str, i, k); reverse(str, j, len - 1 as libc::c_int); return 1 as libc::c_int != 0; } } return 0 as libc::c_int != 0; }" }, { "index": 1529, "before": "void reverse(char* str, int i, int j) { for (; i < j; ++i, --j) swap(str, i, j); }", "after": "pub unsafe extern \"C\" fn reverse( mut str: *mut libc::c_char, mut i: libc::c_int, mut j: libc::c_int, ) { while i < j { swap(str, i, j); i += 1; i; j -= 1; j; } }" }, { "index": 1530, "before": "void swap(char* str, int i, int j) { char c = str[i]; str[i] = str[j]; str[j] = c; }", "after": "pub unsafe extern \"C\" fn swap( mut str: *mut libc::c_char, mut i: libc::c_int, mut j: libc::c_int, ) { let mut c: libc::c_char = *str.offset(i as isize); *str.offset(i as isize) = *str.offset(j as isize); *str.offset(j as isize) = c; }" }, { "index": 1531, "before": "ull farey_len(int n) { \tif (n >= ccap) { \t\tsize_t old = ccap; \t\tif (!ccap) ccap = 16; \t\twhile (ccap <= n) ccap *= 2; \t\tcache = realloc(cache, sizeof(ull) * ccap); \t\tmemset(cache + old, 0, sizeof(ull) * (ccap - old)); \t} else if (cache[n]) \t\treturn cache[n]; \tull len = (ull)n*(n + 3) / 2; \tint p, q = 0; \tfor (p = 2; p <= n; p = q) { \t\tq = n/(n/p) + 1; \t\tlen -= farey_len(n/p) * (q - p); \t} \tcache[n] = len; \treturn len; }", "after": "pub unsafe extern \"C\" fn farey_len(mut n: libc::c_int) -> ull { if n as libc::c_ulong >= ccap { let mut old: size_t = ccap; if ccap == 0 { ccap = 16 as libc::c_int as size_t; } while ccap <= n as libc::c_ulong { ccap = (ccap as libc::c_ulong) .wrapping_mul(2 as libc::c_int as libc::c_ulong) as size_t as size_t; } cache = realloc( cache as *mut libc::c_void, (::core::mem::size_of::() as libc::c_ulong).wrapping_mul(ccap), ) as *mut ull; memset( cache.offset(old as isize) as *mut libc::c_void, 0 as libc::c_int, (::core::mem::size_of::() as libc::c_ulong) .wrapping_mul(ccap.wrapping_sub(old)), ); } else if *cache.offset(n as isize) != 0 { return *cache.offset(n as isize) } let mut len: ull = (n as ull) .wrapping_mul((n + 3 as libc::c_int) as libc::c_ulonglong) .wrapping_div(2 as libc::c_int as libc::c_ulonglong); let mut p: libc::c_int = 0; let mut q: libc::c_int = 0 as libc::c_int; p = 2 as libc::c_int; while p <= n { q = n / (n / p) + 1 as libc::c_int; len = (len as libc::c_ulonglong) .wrapping_sub((farey_len(n / p)).wrapping_mul((q - p) as libc::c_ulonglong)) as ull as ull; p = q; } *cache.offset(n as isize) = len; return len; }" }, { "index": 1532, "before": "void farey(int n) { \ttypedef struct { int d, n; } frac; \tfrac f1 = {0, 1}, f2 = {1, n}, t; \tint k; \tprintf(\"%d/%d %d/%d\", 0, 1, 1, n); \twhile (f2.n > 1) { \t\tk = (n + f1.n) / f2.n; \t\tt = f1, f1 = f2, f2 = (frac) { f2.d * k - t.d, f2.n * k - t.n }; \t\tprintf(\" %d/%d\", f2.d, f2.n); \t} \tputchar('\\n'); }", "after": "pub unsafe extern \"C\" fn farey(mut n: libc::c_int) { let mut f1: frac = { let mut init = frac { d: 0 as libc::c_int, n: 1 as libc::c_int, }; init }; let mut f2: frac = { let mut init = frac { d: 1 as libc::c_int, n: n }; init }; let mut t: frac = frac { d: 0, n: 0 }; let mut k: libc::c_int = 0; printf( b\"%d/%d %d/%d\\0\" as *const u8 as *const libc::c_char, 0 as libc::c_int, 1 as libc::c_int, 1 as libc::c_int, n, ); while f2.n > 1 as libc::c_int { k = (n + f1.n) / f2.n; t = f1; f1 = f2; f2 = { let mut init = frac { d: f2.d * k - t.d, n: f2.n * k - t.n, }; init }; printf(b\" %d/%d\\0\" as *const u8 as *const libc::c_char, f2.d, f2.n); } putchar('\\n' as i32); }" }, { "index": 1533, "before": "int main(void) { \tint n; \tfor (n = 1; n <= 11; n++) { \t\tprintf(\"%d: \", n); \t\tfarey(n); \t} \tfor (n = 100; n <= 1000; n += 100) \t\tprintf(\"%d: %llu items\\n\", n, farey_len(n)); \tn = 10000000; \tprintf(\"\\n%d: %llu items\\n\", n, farey_len(n)); \treturn 0; }", "after": "unsafe fn main() -> libc::c_int { let mut n: libc::c_int = 0; n = 1 as libc::c_int; while n <= 11 as libc::c_int { printf(b\"%d: \\0\" as *const u8 as *const libc::c_char, n); farey(n); n += 1; n; } n = 100 as libc::c_int; while n <= 1000 as libc::c_int { printf( b\"%d: %llu items\\n\\0\" as *const u8 as *const libc::c_char, n, farey_len(n), ); n += 100 as libc::c_int; } n = 10000000 as libc::c_int; printf(b\"\\n%d: %llu items\\n\\0\" as *const u8 as *const libc::c_char, n, farey_len(n)); return 0 as libc::c_int; }" }, { "index": 1534, "before": "int main(int argc, char** argv) { if (argc < 2) { printf(\"usage: identitymatrix \\n\"); exit(EXIT_FAILURE); } signed int rowsize = atoi(argv[1]); if (rowsize < 0) { printf(\"Dimensions of matrix cannot be negative\\n\"); exit(EXIT_FAILURE); } volatile int numElements = rowsize * rowsize; if (numElements < rowsize) { printf(\"Squaring %d caused result to overflow to %d.\\n\", rowsize, numElements); abort(); } int** matrix = calloc(numElements, sizeof(int*)); if (!matrix) { printf(\"Failed to allocate %d elements of %d bytes each\\n\", numElements, sizeof(int*)); abort(); } for (unsigned int row = 0;row < rowsize;row++) { matrix[row] = calloc(numElements, sizeof(int)); if (!matrix[row]) { printf(\"Failed to allocate %d elements of %d bytes each\\n\", numElements, sizeof(int)); abort(); } matrix[row][row] = 1; } printf(\"Matrix is: \\n\"); for (unsigned int row = 0;row < rowsize;row++) { for (unsigned int column = 0;column < rowsize;column++) { printf(\"%d \", matrix[row][column]); } printf(\"\\n\"); } }", "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: identitymatrix \\n\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } let mut rowsize: libc::c_int = atoi(*argv.offset(1 as libc::c_int as isize)); if rowsize < 0 as libc::c_int { printf( b\"Dimensions of matrix cannot be negative\\n\\0\" as *const u8 as *const libc::c_char, ); exit(1 as libc::c_int); } let mut numElements: libc::c_int = rowsize * rowsize; if numElements < rowsize { printf( b\"Squaring %d caused result to overflow to %d.\\n\\0\" as *const u8 as *const libc::c_char, rowsize, numElements, ); abort(); } let mut matrix: *mut *mut libc::c_int = calloc( numElements as libc::c_ulong, ::core::mem::size_of::<*mut libc::c_int>() as libc::c_ulong, ) as *mut *mut libc::c_int; if matrix.is_null() { printf( b\"Failed to allocate %d elements of %d bytes each\\n\\0\" as *const u8 as *const libc::c_char, numElements, ::core::mem::size_of::<*mut libc::c_int>() as libc::c_ulong, ); abort(); } let mut row: libc::c_uint = 0 as libc::c_int as libc::c_uint; while row < rowsize as libc::c_uint { let ref mut fresh0 = *matrix.offset(row as isize); *fresh0 = calloc( numElements as libc::c_ulong, ::core::mem::size_of::() as libc::c_ulong, ) as *mut libc::c_int; if (*matrix.offset(row as isize)).is_null() { printf( b\"Failed to allocate %d elements of %d bytes each\\n\\0\" as *const u8 as *const libc::c_char, numElements, ::core::mem::size_of::() as libc::c_ulong, ); abort(); } *(*matrix.offset(row as isize)).offset(row as isize) = 1 as libc::c_int; row = row.wrapping_add(1); row; } printf(b\"Matrix is: \\n\\0\" as *const u8 as *const libc::c_char); let mut row_0: libc::c_uint = 0 as libc::c_int as libc::c_uint; while row_0 < rowsize as libc::c_uint { let mut column: libc::c_uint = 0 as libc::c_int as libc::c_uint; while column < rowsize as libc::c_uint { printf( b\"%d \\0\" as *const u8 as *const libc::c_char, *(*matrix.offset(row_0 as isize)).offset(column as isize), ); column = column.wrapping_add(1); column; } printf(b\"\\n\\0\" as *const u8 as *const libc::c_char); row_0 = row_0.wrapping_add(1); row_0; } return 0; }" }, { "index": 1535, "before": "int cusipCheck(char str[10]){ \tint sum=0,i,v; \tfor(i=0;i<8;i++){ \t\tif(str[i]>='0'&&str[i]<='9') \t\t\tv = str[i]-'0'; \t\telse if(str[i]>='A'&&str[i]<='Z') \t\t\tv = (str[i] - 'A' + 10); \t\telse if(str[i]=='*') \t\t\tv = 36; \t\telse if(str[i]=='@') \t\t\tv = 37; \t\telse if(str[i]=='#') \t\t\tv = 38; \t\tif(i%2!=0) \t\t\tv*=2; \t\tsum += ((int)(v/10) + v%10); \t} \treturn ((10 - (sum%10))%10); }", "after": "pub unsafe extern \"C\" fn cusipCheck(mut str: *mut libc::c_char) -> libc::c_int { let mut sum: libc::c_int = 0 as libc::c_int; let mut i: libc::c_int = 0; let mut v: libc::c_int = 0; i = 0 as libc::c_int; while i < 8 as libc::c_int { if *str.offset(i as isize) as libc::c_int >= '0' as i32 && *str.offset(i as isize) as libc::c_int <= '9' as i32 { v = *str.offset(i as isize) as libc::c_int - '0' as i32; } else if *str.offset(i as isize) as libc::c_int >= 'A' as i32 && *str.offset(i as isize) as libc::c_int <= 'Z' as i32 { v = *str.offset(i as isize) as libc::c_int - 'A' as i32 + 10 as libc::c_int; } else if *str.offset(i as isize) as libc::c_int == '*' as i32 { v = 36 as libc::c_int; } else if *str.offset(i as isize) as libc::c_int == '@' as i32 { v = 37 as libc::c_int; } else if *str.offset(i as isize) as libc::c_int == '#' as i32 { v = 38 as libc::c_int; } if i % 2 as libc::c_int != 0 as libc::c_int { v *= 2 as libc::c_int; } sum += v / 10 as libc::c_int + v % 10 as libc::c_int; i += 1; i; } return (10 as libc::c_int - sum % 10 as libc::c_int) % 10 as libc::c_int; }" }, { "index": 1536, "before": "int main(int argC,char* argV[]) { \tchar cusipStr[10]; \tint i,numLines; \tif(argC==1) \t\tprintf(\"Usage : %s \",argV[0]); \telse{ \t\tFILE* fp = fopen(argV[1],\"r\"); \t\tfscanf(fp,\"%d\",&numLines); \t\tprintf(\"CUSIP Verdict\\n\"); \t\tprintf(\"-------------------\"); \t\tfor(i=0;i libc::c_int { let mut cusipStr: [libc::c_char; 10] = [0; 10]; let mut i: libc::c_int = 0; let mut numLines: libc::c_int = 0; if argC == 1 as libc::c_int { printf( b\"Usage : %s \\0\" as *const u8 as *const libc::c_char, *argV.offset(0 as libc::c_int as isize), ); } else { let mut fp: *mut FILE = fopen( *argV.offset(1 as libc::c_int as isize), b\"r\\0\" as *const u8 as *const libc::c_char, ); fscanf( fp, b\"%d\\0\" as *const u8 as *const libc::c_char, &mut numLines as *mut libc::c_int, ); printf(b\"CUSIP Verdict\\n\\0\" as *const u8 as *const libc::c_char); printf(b\"-------------------\\0\" as *const u8 as *const libc::c_char); i = 0 as libc::c_int; while i < numLines { fscanf( fp, b\"%s\\0\" as *const u8 as *const libc::c_char, cusipStr.as_mut_ptr(), ); printf( b\"\\n%s : %s\\0\" as *const u8 as *const libc::c_char, cusipStr.as_mut_ptr(), if cusipCheck(cusipStr.as_mut_ptr()) == cusipStr[8 as libc::c_int as usize] as libc::c_int - '0' as i32 { b\"Valid\\0\" as *const u8 as *const libc::c_char } else { b\"Invalid\\0\" as *const u8 as *const libc::c_char }, ); i += 1; i; } fclose(fp); } return 0 as libc::c_int; }" }, { "index": 1537, "before": "int main() { const char *plain_text = \"WELLDONEISBETTERTHANWELLSAID\"; char *cipher_text = malloc(strlen(plain_text) + 1); char *plain_text2 = malloc(strlen(plain_text) + 1); printf(\"The original plaintext is : %s\\n\", plain_text); printf(\"\\nThe left and right alphabets after each permutation\" \" during encryption are :\\n\\n\"); chao(plain_text, cipher_text, ENCRYPT, TRUE); printf(\"\\nThe ciphertext is : %s\\n\", cipher_text); chao(cipher_text, plain_text2, DECRYPT, FALSE); printf(\"\\nThe recovered plaintext is : %s\\n\", plain_text2); free(cipher_text); free(plain_text2); return 0; }", "after": "fn main() -> i32 { unsafe { let mut plain_text: *const i8 = b\"WELLDONEISBETTERTHANWELLSAID\\0\" as *const u8 as *const i8; let mut cipher_text: *mut i8 = malloc((strlen(plain_text)).wrapping_add(1)) as *mut i8; let mut plain_text2: *mut i8 = malloc((strlen(plain_text)).wrapping_add(1)) as *mut i8; print!( \"The original plaintext is : {}\\n\", build_str_from_raw_ptr(plain_text as *mut u8) ); print!(\"\\nThe left and right alphabets after each permutation during encryption are :\\n\\n\"); chao(plain_text, cipher_text, ENCRYPT, 1); print!( \"\\nThe ciphertext is : {}\\n\", build_str_from_raw_ptr(cipher_text as *mut u8) ); chao(cipher_text, plain_text2, DECRYPT, 0); print!( \"\\nThe recovered plaintext is : {}\\n\", build_str_from_raw_ptr(plain_text2 as *mut u8) ); free(cipher_text as *mut libc::c_void); free(plain_text2 as *mut libc::c_void); return 0; } }" }, { "index": 1538, "before": "void chao(const char *in, char *out, cmode mode, bool show_steps) { int i, j, index; char store; size_t len = strlen(in); char left[27], right[27], temp[27]; strcpy(left, l_alphabet); strcpy(right, r_alphabet); temp[26] = '\\0'; for (i = 0; i < len; ++i ) { if (show_steps) printf(\"%s %s\\n\", left, right); if (mode == ENCRYPT) { index = strchr(right, in[i]) - right; out[i] = left[index]; } else { index = strchr(left, in[i]) - left; out[i] = right[index]; } if (i == len - 1) break; /* permute left */ for (j = index; j < 26; ++j) temp[j - index] = left[j]; for (j = 0; j < index; ++j) temp[26 - index + j] = left[j]; store = temp[1]; for (j = 2; j < 14; ++j) temp[j - 1] = temp[j]; temp[13] = store; strcpy(left, temp); /* permute right */ for (j = index; j < 26; ++j) temp[j - index] = right[j]; for (j = 0; j < index; ++j) temp[26 - index + j] = right[j]; store = temp[0]; for (j = 1; j < 26; ++j) temp[j - 1] = temp[j]; temp[25] = store; store = temp[2]; for (j = 3; j < 14; ++j) temp[j - 1] = temp[j]; temp[13] = store; strcpy(right, temp); } }", "after": "pub extern \"C\" fn chao(mut in_0: *const i8, mut out: *mut i8, mut mode: u32, mut show_steps: i32) { unsafe { let mut i: i32 = 0; let mut j: i32 = 0; let mut index: i32 = 0; let mut store: i8 = 0; let mut len: u64 = strlen(in_0); let mut left: [i8; 27] = [0; 27]; let mut right: [i8; 27] = [0; 27]; let mut temp: [i8; 27] = [0; 27]; strcpy(left.as_mut_ptr(), l_alphabet); strcpy(right.as_mut_ptr(), r_alphabet); temp[26 as usize] = '\\0' as i8; i = 0; while (i as u64) < len { if show_steps != 0 { print!( \"{} {}\\n\", build_str_from_raw_ptr(left.as_mut_ptr() as *mut u8), build_str_from_raw_ptr(right.as_mut_ptr() as *mut u8) ); } if mode as u32 == ENCRYPT as u32 { index = (strchr(right.as_mut_ptr(), *in_0.offset(i as isize) as i32)) .offset_from(right.as_mut_ptr()) as i32; *out.offset(i as isize) = left[index as usize]; } else { index = (strchr(left.as_mut_ptr(), *in_0.offset(i as isize) as i32)) .offset_from(left.as_mut_ptr()) as i32; *out.offset(i as isize) = right[index as usize]; } if i as u64 == len.wrapping_sub(1) { break; } j = index; while j < 26 { temp[(j - index) as usize] = left[j as usize]; j += 1; j; } j = 0; while j < index { temp[(26 - index + j) as usize] = left[j as usize]; j += 1; j; } store = temp[1 as usize]; j = 2; while j < 14 { temp[(j - 1i32) as usize] = temp[j as usize]; j += 1; j; } temp[13 as usize] = store; strcpy(left.as_mut_ptr(), temp.as_mut_ptr()); j = index; while j < 26 { temp[(j - index) as usize] = right[j as usize]; j += 1; j; } j = 0; while j < index { temp[(26 - index + j) as usize] = right[j as usize]; j += 1; j; } store = temp[0 as usize]; j = 1; while j < 26 { temp[(j - 1i32) as usize] = temp[j as usize]; j += 1; j; } temp[25 as usize] = store; store = temp[2 as usize]; j = 3; while j < 14 { temp[(j - 1i32) as usize] = temp[j as usize]; j += 1; j; } temp[13 as usize] = store; strcpy(right.as_mut_ptr(), temp.as_mut_ptr()); i += 1; i; } } }" } ]