1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// #![allow(
// dead_code,
// mutable_transmutes,
// non_camel_case_types,
// non_snake_case,
// non_upper_case_globals,
// unused_assignments,
// unused_mut
// )]
// #![register_tool(c2rust)]
// #![feature(extern_types, label_break_value, register_tool)]
// extern "C" {
// pub type queue;
// fn __assert_fail(
// __assertion: *const libc::c_char,
// __file: *const libc::c_char,
// __line: libc::c_uint,
// __function: *const libc::c_char,
// ) -> !;
// fn malloc(_: libc::c_ulong) -> *mut libc::c_void;
// fn free(_: *mut libc::c_void);
// fn printf(_: *const libc::c_char, _: ...) -> libc::c_int;
// fn pthread_create(
// __newthread: *mut pthread_t,
// __attr: *const pthread_attr_t,
// __start_routine: Option<unsafe extern "C" fn(_: *mut libc::c_void) -> *mut libc::c_void>,
// __arg: *mut libc::c_void,
// ) -> libc::c_int;
// fn pthread_join(__th: pthread_t, __thread_return: *mut *mut libc::c_void) -> libc::c_int;
// fn pthread_mutex_init(
// __mutex: *mut pthread_mutex_t,
// __mutexattr: *const pthread_mutexattr_t,
// ) -> libc::c_int;
// fn pthread_mutex_destroy(__mutex: *mut pthread_mutex_t) -> libc::c_int;
// fn pthread_mutex_lock(__mutex: *mut pthread_mutex_t) -> libc::c_int;
// fn pthread_mutex_unlock(__mutex: *mut pthread_mutex_t) -> libc::c_int;
// fn queue_init() -> *mut queue_t;
// fn queue_enqueue(queue_0: *mut queue_t, value: *mut libc::c_void);
// fn queue_dequeue(queue_0: *mut queue_t) -> *mut libc::c_void;
// fn queue_free(queue_0: *mut queue_t);
// }
// pub type size_t = libc::c_ulong;
// #[derive(Copy, Clone)]
// #[repr(C)]
// pub struct __pthread_internal_list {
// pub __prev: *mut __pthread_internal_list,
// pub __next: *mut __pthread_internal_list,
// }
// pub type __pthread_list_t = __pthread_internal_list;
// #[derive(Copy, Clone)]
// #[repr(C)]
// pub struct __pthread_mutex_s {
// pub __lock: libc::c_int,
// pub __count: libc::c_uint,
// pub __owner: libc::c_int,
// pub __nusers: libc::c_uint,
// pub __kind: libc::c_int,
// pub __spins: libc::c_short,
// pub __elision: libc::c_short,
// pub __list: __pthread_list_t,
// }
// pub type pthread_t = libc::c_ulong;
// #[derive(Copy, Clone)]
// #[repr(C)]
// pub union pthread_mutexattr_t {
// pub __size: [libc::c_char; 4],
// pub __align: libc::c_int,
// }
// #[derive(Copy, Clone)]
// #[repr(C)]
// pub union pthread_attr_t {
// pub __size: [libc::c_char; 56],
// pub __align: libc::c_long,
// }
// #[derive(Copy, Clone)]
// #[repr(C)]
// pub union pthread_mutex_t {
// pub __data: __pthread_mutex_s,
// pub __size: [libc::c_char; 40],
// pub __align: libc::c_long,
// }
// pub type queue_t = queue;
// #[no_mangle]
// pub static mut MAX_QUEUE_SIZE: size_t = 100000 as libc::c_int as size_t;
// #[no_mangle]
// pub static mut NUM_PUSH_THREADS: size_t = 8 as libc::c_int as size_t;
// #[no_mangle]
// pub static mut NUM_POP_THREADS: size_t = 8 as libc::c_int as size_t;
// #[no_mangle]
// pub static mut queue: *mut queue_t = 0 as *const queue_t as *mut queue_t;
// #[no_mangle]
// pub static mut num_seen: size_t = 0;
// #[no_mangle]
// pub static mut num_seen_mutex: pthread_mutex_t = pthread_mutex_t {
// __data: __pthread_mutex_s {
// __lock: 0,
// __count: 0,
// __owner: 0,
// __nusers: 0,
// __kind: 0,
// __spins: 0,
// __elision: 0,
// __list: __pthread_list_t {
// __prev: 0 as *const __pthread_internal_list as *mut __pthread_internal_list,
// __next: 0 as *const __pthread_internal_list as *mut __pthread_internal_list,
// },
// },
// };
// #[no_mangle]
// pub unsafe extern "C" fn enqueue_worker(mut arg: *mut libc::c_void) -> *mut libc::c_void {
// let mut thread_id: size_t = *(arg as *mut size_t);
// free(arg);
// let mut i: size_t = thread_id;
// while i < MAX_QUEUE_SIZE {
// let mut value: *mut size_t =
// malloc(::std::mem::size_of::<size_t>() as libc::c_ulong) as *mut size_t;
// if !value.is_null() {
// } else {
// __assert_fail(
// b"value != NULL\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_push_pop.c\x00" as *const u8 as *const libc::c_char,
// 22 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 29], &[libc::c_char; 29]>(
// b"void *enqueue_worker(void *)\x00",
// ))
// .as_ptr(),
// );
// }
// *value = i;
// queue_enqueue(queue, value as *mut libc::c_void);
// i = (i as libc::c_ulong).wrapping_add(NUM_PUSH_THREADS) as size_t as size_t
// }
// return 0 as *mut libc::c_void;
// }
// #[no_mangle]
// pub unsafe extern "C" fn dequeue_worker(mut _arg: *mut libc::c_void) -> *mut libc::c_void {
// let mut i: size_t = 0 as libc::c_int as size_t;
// while i < MAX_QUEUE_SIZE {
// pthread_mutex_lock(&mut num_seen_mutex);
// if num_seen == MAX_QUEUE_SIZE {
// pthread_mutex_unlock(&mut num_seen_mutex);
// break;
// } else {
// num_seen = num_seen.wrapping_add(1);
// pthread_mutex_unlock(&mut num_seen_mutex);
// let mut value: *mut size_t = queue_dequeue(queue) as *mut size_t;
// printf(b"%zu\n\x00" as *const u8 as *const libc::c_char, *value);
// free(value as *mut libc::c_void);
// i = i.wrapping_add(1)
// }
// }
// return 0 as *mut libc::c_void;
// }
// unsafe fn main_0() -> libc::c_int {
// queue = queue_init();
// num_seen = 0 as libc::c_int as size_t;
// let mut result: libc::c_int =
// pthread_mutex_init(&mut num_seen_mutex, 0 as *const pthread_mutexattr_t);
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_push_pop.c\x00" as *const u8 as *const libc::c_char,
// 52 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00")).as_ptr(),
// );
// }
// let vla = NUM_PUSH_THREADS as usize;
// let mut enqueue_threads: Vec<pthread_t> = ::std::vec::from_elem(0, vla);
// let vla_0 = NUM_POP_THREADS as usize;
// let mut dequeue_threads: Vec<pthread_t> = ::std::vec::from_elem(0, vla_0);
// let mut i: size_t = 0 as libc::c_int as size_t;
// while i < NUM_PUSH_THREADS {
// let mut thread_id: *mut size_t =
// malloc(::std::mem::size_of::<size_t>() as libc::c_ulong) as *mut size_t;
// if !thread_id.is_null() {
// } else {
// __assert_fail(
// b"thread_id != NULL\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_push_pop.c\x00" as *const u8 as *const libc::c_char,
// 59 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00"))
// .as_ptr(),
// );
// }
// *thread_id = i;
// result = pthread_create(
// &mut *enqueue_threads.as_mut_ptr().offset(i as isize),
// 0 as *const pthread_attr_t,
// Some(enqueue_worker as unsafe extern "C" fn(_: *mut libc::c_void) -> *mut libc::c_void),
// thread_id as *mut libc::c_void,
// );
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_push_pop.c\x00" as *const u8 as *const libc::c_char,
// 62 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00"))
// .as_ptr(),
// );
// }
// i = i.wrapping_add(1)
// }
// let mut i_0: size_t = 0 as libc::c_int as size_t;
// while i_0 < NUM_POP_THREADS {
// result = pthread_create(
// &mut *dequeue_threads.as_mut_ptr().offset(i_0 as isize),
// 0 as *const pthread_attr_t,
// Some(dequeue_worker as unsafe extern "C" fn(_: *mut libc::c_void) -> *mut libc::c_void),
// 0 as *mut libc::c_void,
// );
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_push_pop.c\x00" as *const u8 as *const libc::c_char,
// 66 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00"))
// .as_ptr(),
// );
// }
// i_0 = i_0.wrapping_add(1)
// }
// let mut i_1: size_t = 0 as libc::c_int as size_t;
// while i_1 < NUM_PUSH_THREADS {
// result = pthread_join(
// *enqueue_threads.as_mut_ptr().offset(i_1 as isize),
// 0 as *mut *mut libc::c_void,
// );
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_push_pop.c\x00" as *const u8 as *const libc::c_char,
// 71 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00"))
// .as_ptr(),
// );
// }
// i_1 = i_1.wrapping_add(1)
// }
// let mut i_2: size_t = 0 as libc::c_int as size_t;
// while i_2 < NUM_POP_THREADS {
// result = pthread_join(
// *dequeue_threads.as_mut_ptr().offset(i_2 as isize),
// 0 as *mut *mut libc::c_void,
// );
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_push_pop.c\x00" as *const u8 as *const libc::c_char,
// 75 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00"))
// .as_ptr(),
// );
// }
// i_2 = i_2.wrapping_add(1)
// }
// result = pthread_mutex_destroy(&mut num_seen_mutex);
// if result == 0 as libc::c_int {
// } else {
// __assert_fail(
// b"result == 0\x00" as *const u8 as *const libc::c_char,
// b"tests/mqueue_push_pop.c\x00" as *const u8 as *const libc::c_char,
// 79 as libc::c_int as libc::c_uint,
// (*::std::mem::transmute::<&[u8; 11], &[libc::c_char; 11]>(b"int main()\x00")).as_ptr(),
// );
// }
// queue_free(queue);
// return 0;
// }
// pub fn main() {
// unsafe { ::std::process::exit(main_0() as i32) }
// }