-
Notifications
You must be signed in to change notification settings - Fork 1
/
sha256.wat
607 lines (529 loc) · 36.4 KB
/
sha256.wat
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
(module
(memory $0 1)
(export "memory" (memory $0))
(global $a (mut i32) (i32.const 0))
(global $b (mut i32) (i32.const 0))
(global $c (mut i32) (i32.const 0))
(global $d (mut i32) (i32.const 0))
(global $e (mut i32) (i32.const 0))
(global $f (mut i32) (i32.const 0))
(global $g (mut i32) (i32.const 0))
(global $h (mut i32) (i32.const 0))
(func $i32.bswap
(param $b i32)
(result i32)
;; 2 get, 4 const, 5 bitwise
(i32.or
(get_local $b)
(i32.const 0x00FF00FF)
(i32.and)
(i32.rotr (i32.const 8))
(get_local $b)
(i32.const 0xFF00FF00)
(i32.and)
(i32.rotl (i32.const 8))))
(func $four_round
(param $w0 i32) (param $w1 i32) (param $w2 i32) (param $w3 i32)
(param $k0 i32) (param $k1 i32) (param $k2 i32) (param $k3 i32)
;; precomputed values
(local $T1 i32)
(local $T2 i32)
(local $ch_res i32)
(local $maj_res i32)
(local $big_sig0_res i32)
(local $big_sig1_res i32)
;; precompute intermediate values
;; T1 = h + big_sig1(e) + ch(e, f, g) + K0 + W0
;; T2 = big_sig0(a) + Maj(a, b, c)
;; can compute 4 rounds independently
(set_local $ch_res (i32.xor (i32.and (get_global $e) (get_global $f)) (i32.and (i32.xor (get_global $e) (i32.const -1)) (get_global $g))))
(set_local $maj_res (i32.xor (i32.xor (i32.and (get_global $a) (get_global $b)) (i32.and (get_global $a) (get_global $c))) (i32.and (get_global $b) (get_global $c))))
(set_local $big_sig0_res (i32.xor (i32.xor (i32.rotr (get_global $a) (i32.const 2)) (i32.rotr (get_global $a) (i32.const 13))) (i32.rotr (get_global $a) (i32.const 22))))
(set_local $big_sig1_res (i32.xor (i32.xor (i32.rotr (get_global $e) (i32.const 6)) (i32.rotr (get_global $e) (i32.const 11))) (i32.rotr (get_global $e) (i32.const 25))))
(set_local $T1 (i32.add (i32.add (i32.add (i32.add (get_global $h) (get_local $ch_res)) (get_local $big_sig1_res)) (get_local $w0)) (get_local $k0)))
(set_local $T2 (i32.add (get_local $big_sig0_res) (get_local $maj_res)))
(set_global $h (i32.add (get_global $d) (get_local $T1)))
(set_global $d (i32.add (get_local $T1) (get_local $T2)))
(set_local $ch_res (i32.xor (i32.and (get_global $h) (get_global $e)) (i32.and (i32.xor (get_global $h) (i32.const -1)) (get_global $f))))
(set_local $maj_res (i32.xor (i32.xor (i32.and (get_global $d) (get_global $a)) (i32.and (get_global $d) (get_global $b))) (i32.and (get_global $a) (get_global $b))))
(set_local $big_sig0_res (i32.xor (i32.xor (i32.rotr (get_global $d) (i32.const 2)) (i32.rotr (get_global $d) (i32.const 13))) (i32.rotr (get_global $d) (i32.const 22))))
(set_local $big_sig1_res (i32.xor (i32.xor (i32.rotr (get_global $h) (i32.const 6)) (i32.rotr (get_global $h) (i32.const 11))) (i32.rotr (get_global $h) (i32.const 25))))
(set_local $T1 (i32.add (i32.add (i32.add (i32.add (get_global $g) (get_local $ch_res)) (get_local $big_sig1_res)) (get_local $w1)) (get_local $k1)))
(set_local $T2 (i32.add (get_local $big_sig0_res) (get_local $maj_res)))
(set_global $g (i32.add (get_global $c) (get_local $T1)))
(set_global $c (i32.add (get_local $T1) (get_local $T2)))
(set_local $ch_res (i32.xor (i32.and (get_global $g) (get_global $h)) (i32.and (i32.xor (get_global $g) (i32.const -1)) (get_global $e))))
(set_local $maj_res (i32.xor (i32.xor (i32.and (get_global $c) (get_global $d)) (i32.and (get_global $c) (get_global $a))) (i32.and (get_global $d) (get_global $a))))
(set_local $big_sig0_res (i32.xor (i32.xor (i32.rotr (get_global $c) (i32.const 2)) (i32.rotr (get_global $c) (i32.const 13))) (i32.rotr (get_global $c) (i32.const 22))))
(set_local $big_sig1_res (i32.xor (i32.xor (i32.rotr (get_global $g) (i32.const 6)) (i32.rotr (get_global $g) (i32.const 11))) (i32.rotr (get_global $g) (i32.const 25))))
(set_local $T1 (i32.add (i32.add (i32.add (i32.add (get_global $f) (get_local $ch_res)) (get_local $big_sig1_res)) (get_local $w2)) (get_local $k2)))
(set_local $T2 (i32.add (get_local $big_sig0_res) (get_local $maj_res)))
(set_global $f (i32.add (get_global $b) (get_local $T1)))
(set_global $b (i32.add (get_local $T1) (get_local $T2)))
(set_local $ch_res (i32.xor (i32.and (get_global $f) (get_global $g)) (i32.and (i32.xor (get_global $f) (i32.const -1)) (get_global $h))))
(set_local $maj_res (i32.xor (i32.xor (i32.and (get_global $b) (get_global $c)) (i32.and (get_global $b) (get_global $d))) (i32.and (get_global $c) (get_global $d))))
(set_local $big_sig0_res (i32.xor (i32.xor (i32.rotr (get_global $b) (i32.const 2)) (i32.rotr (get_global $b) (i32.const 13))) (i32.rotr (get_global $b) (i32.const 22))))
(set_local $big_sig1_res (i32.xor (i32.xor (i32.rotr (get_global $f) (i32.const 6)) (i32.rotr (get_global $f) (i32.const 11))) (i32.rotr (get_global $f) (i32.const 25))))
(set_local $T1 (i32.add (i32.add (i32.add (i32.add (get_global $e) (get_local $ch_res)) (get_local $big_sig1_res)) (get_local $w3)) (get_local $k3)))
(set_local $T2 (i32.add (get_local $big_sig0_res) (get_local $maj_res)))
(set_global $e (i32.add (get_global $a) (get_local $T1)))
(set_global $a (i32.add (get_local $T1) (get_local $T2))))
(func $expand
(param $a i32) (param $b i32) (param $c i32) (param $d i32)
(result i32)
(i32.add
(i32.add
(i32.add
(i32.xor
(i32.xor
(i32.rotr (get_local $a) (i32.const 17))
(i32.rotr (get_local $a) (i32.const 19)))
(i32.shr_u (get_local $a) (i32.const 10)))
(get_local $b))
(i32.xor
(i32.xor
(i32.rotr (get_local $c) (i32.const 7))
(i32.rotr (get_local $c) (i32.const 18)))
(i32.shr_u (get_local $c) (i32.const 3)))
(get_local $d))))
(func $compress
(param $ctx i32)
(param $w0 i32) (param $w1 i32) (param $w2 i32) (param $w3 i32)
(param $w4 i32) (param $w5 i32) (param $w6 i32) (param $w7 i32)
(param $w8 i32) (param $w9 i32) (param $w10 i32) (param $w11 i32)
(param $w12 i32) (param $w13 i32) (param $w14 i32) (param $w15 i32)
;; expanded message schedule
(local $w16 i32) (local $w17 i32) (local $w18 i32) (local $w19 i32)
(local $w20 i32) (local $w21 i32) (local $w22 i32) (local $w23 i32)
(local $w24 i32) (local $w25 i32) (local $w26 i32) (local $w27 i32)
(local $w28 i32) (local $w29 i32) (local $w30 i32) (local $w31 i32)
(local $w32 i32) (local $w33 i32) (local $w34 i32) (local $w35 i32)
(local $w36 i32) (local $w37 i32) (local $w38 i32) (local $w39 i32)
(local $w40 i32) (local $w41 i32) (local $w42 i32) (local $w43 i32)
(local $w44 i32) (local $w45 i32) (local $w46 i32) (local $w47 i32)
(local $w48 i32) (local $w49 i32) (local $w50 i32) (local $w51 i32)
(local $w52 i32) (local $w53 i32) (local $w54 i32) (local $w55 i32)
(local $w56 i32) (local $w57 i32) (local $w58 i32) (local $w59 i32)
(local $w60 i32) (local $w61 i32) (local $w62 i32) (local $w63 i32)
;; store inital state
(if (i32.eqz (i32.load offset=104 (get_local $ctx)))
(then
(i32.store offset=0 (get_local $ctx) (i32.const 0x6a09e667))
(i32.store offset=4 (get_local $ctx) (i32.const 0xbb67ae85))
(i32.store offset=8 (get_local $ctx) (i32.const 0x3c6ef372))
(i32.store offset=12 (get_local $ctx) (i32.const 0xa54ff53a))
(i32.store offset=16 (get_local $ctx) (i32.const 0x510e527f))
(i32.store offset=20 (get_local $ctx) (i32.const 0x9b05688c))
(i32.store offset=24 (get_local $ctx) (i32.const 0x1f83d9ab))
(i32.store offset=28 (get_local $ctx) (i32.const 0x5be0cd19))
(i32.store offset=104 (get_local $ctx) (i32.const 1))))
;; load previous hash state into registers
(set_global $a (i32.load offset=0 (get_local $ctx)))
(set_global $b (i32.load offset=4 (get_local $ctx)))
(set_global $c (i32.load offset=8 (get_local $ctx)))
(set_global $d (i32.load offset=12 (get_local $ctx)))
(set_global $e (i32.load offset=16 (get_local $ctx)))
(set_global $f (i32.load offset=20 (get_local $ctx)))
(set_global $g (i32.load offset=24 (get_local $ctx)))
(set_global $h (i32.load offset=28 (get_local $ctx)))
(set_local $w0 (call $i32.bswap (get_local $w0 )))
(set_local $w1 (call $i32.bswap (get_local $w1 )))
(set_local $w2 (call $i32.bswap (get_local $w2 )))
(set_local $w3 (call $i32.bswap (get_local $w3 )))
(set_local $w4 (call $i32.bswap (get_local $w4 )))
(set_local $w5 (call $i32.bswap (get_local $w5 )))
(set_local $w6 (call $i32.bswap (get_local $w6 )))
(set_local $w7 (call $i32.bswap (get_local $w7 )))
(set_local $w8 (call $i32.bswap (get_local $w8 )))
(set_local $w9 (call $i32.bswap (get_local $w9 )))
(set_local $w10 (call $i32.bswap (get_local $w10)))
(set_local $w11 (call $i32.bswap (get_local $w11)))
(set_local $w12 (call $i32.bswap (get_local $w12)))
(set_local $w13 (call $i32.bswap (get_local $w13)))
(set_local $w14 (call $i32.bswap (get_local $w14)))
(set_local $w15 (call $i32.bswap (get_local $w15)))
(call $four_round (get_local $w0) (get_local $w1) (get_local $w2) (get_local $w3) (i32.const 0x428a2f98) (i32.const 0x71374491) (i32.const 0xb5c0fbcf) (i32.const 0xe9b5dba5))
(call $four_round (get_local $w4) (get_local $w5) (get_local $w6) (get_local $w7) (i32.const 0x3956c25b) (i32.const 0x59f111f1) (i32.const 0x923f82a4) (i32.const 0xab1c5ed5))
(call $four_round (get_local $w8) (get_local $w9) (get_local $w10) (get_local $w11) (i32.const 0xd807aa98) (i32.const 0x12835b01) (i32.const 0x243185be) (i32.const 0x550c7dc3))
(call $four_round (get_local $w12) (get_local $w13) (get_local $w14) (get_local $w15) (i32.const 0x72be5d74) (i32.const 0x80deb1fe) (i32.const 0x9bdc06a7) (i32.const 0xc19bf174))
(set_local $w0 (call $expand (get_local $w14) (get_local $w9) (get_local $w1) (get_local $w0)))
(set_local $w1 (call $expand (get_local $w15) (get_local $w10) (get_local $w2) (get_local $w1)))
(set_local $w2 (call $expand (get_local $w0 ) (get_local $w11) (get_local $w3) (get_local $w2)))
(set_local $w3 (call $expand (get_local $w1 ) (get_local $w12) (get_local $w4) (get_local $w3)))
(set_local $w4 (call $expand (get_local $w2 ) (get_local $w13) (get_local $w5) (get_local $w4)))
(set_local $w5 (call $expand (get_local $w3 ) (get_local $w14) (get_local $w6) (get_local $w5)))
(set_local $w6 (call $expand (get_local $w4 ) (get_local $w15) (get_local $w7) (get_local $w6)))
(set_local $w7 (call $expand (get_local $w5 ) (get_local $w0) (get_local $w8) (get_local $w7)))
(set_local $w8 (call $expand (get_local $w6 ) (get_local $w1) (get_local $w9) (get_local $w8)))
(set_local $w9 (call $expand (get_local $w7 ) (get_local $w2) (get_local $w10) (get_local $w9)))
(set_local $w10 (call $expand (get_local $w8 ) (get_local $w3) (get_local $w11) (get_local $w10)))
(set_local $w11 (call $expand (get_local $w9 ) (get_local $w4) (get_local $w12) (get_local $w11)))
(set_local $w12 (call $expand (get_local $w10) (get_local $w5) (get_local $w13) (get_local $w12)))
(set_local $w13 (call $expand (get_local $w11) (get_local $w6) (get_local $w14) (get_local $w13)))
(set_local $w14 (call $expand (get_local $w12) (get_local $w7) (get_local $w15) (get_local $w14)))
(set_local $w15 (call $expand (get_local $w13) (get_local $w8) (get_local $w0) (get_local $w15)))
(call $four_round (get_local $w0) (get_local $w1) (get_local $w2) (get_local $w3) (i32.const 0xe49b69c1) (i32.const 0xefbe4786) (i32.const 0x0fc19dc6) (i32.const 0x240ca1cc))
(call $four_round (get_local $w4) (get_local $w5) (get_local $w6) (get_local $w7) (i32.const 0x2de92c6f) (i32.const 0x4a7484aa) (i32.const 0x5cb0a9dc) (i32.const 0x76f988da))
(call $four_round (get_local $w8) (get_local $w9) (get_local $w10) (get_local $w11) (i32.const 0x983e5152) (i32.const 0xa831c66d) (i32.const 0xb00327c8) (i32.const 0xbf597fc7))
(call $four_round (get_local $w12) (get_local $w13) (get_local $w14) (get_local $w15) (i32.const 0xc6e00bf3) (i32.const 0xd5a79147) (i32.const 0x06ca6351) (i32.const 0x14292967))
(set_local $w0 (call $expand (get_local $w14) (get_local $w9) (get_local $w1) (get_local $w0)))
(set_local $w1 (call $expand (get_local $w15) (get_local $w10) (get_local $w2) (get_local $w1)))
(set_local $w2 (call $expand (get_local $w0 ) (get_local $w11) (get_local $w3) (get_local $w2)))
(set_local $w3 (call $expand (get_local $w1 ) (get_local $w12) (get_local $w4) (get_local $w3)))
(set_local $w4 (call $expand (get_local $w2 ) (get_local $w13) (get_local $w5) (get_local $w4)))
(set_local $w5 (call $expand (get_local $w3 ) (get_local $w14) (get_local $w6) (get_local $w5)))
(set_local $w6 (call $expand (get_local $w4 ) (get_local $w15) (get_local $w7) (get_local $w6)))
(set_local $w7 (call $expand (get_local $w5 ) (get_local $w0) (get_local $w8) (get_local $w7)))
(set_local $w8 (call $expand (get_local $w6 ) (get_local $w1) (get_local $w9) (get_local $w8)))
(set_local $w9 (call $expand (get_local $w7 ) (get_local $w2) (get_local $w10) (get_local $w9)))
(set_local $w10 (call $expand (get_local $w8 ) (get_local $w3) (get_local $w11) (get_local $w10)))
(set_local $w11 (call $expand (get_local $w9 ) (get_local $w4) (get_local $w12) (get_local $w11)))
(set_local $w12 (call $expand (get_local $w10) (get_local $w5) (get_local $w13) (get_local $w12)))
(set_local $w13 (call $expand (get_local $w11) (get_local $w6) (get_local $w14) (get_local $w13)))
(set_local $w14 (call $expand (get_local $w12) (get_local $w7) (get_local $w15) (get_local $w14)))
(set_local $w15 (call $expand (get_local $w13) (get_local $w8) (get_local $w0) (get_local $w15)))
(call $four_round (get_local $w0) (get_local $w1) (get_local $w2) (get_local $w3) (i32.const 0x27b70a85) (i32.const 0x2e1b2138) (i32.const 0x4d2c6dfc) (i32.const 0x53380d13))
(call $four_round (get_local $w4) (get_local $w5) (get_local $w6) (get_local $w7) (i32.const 0x650a7354) (i32.const 0x766a0abb) (i32.const 0x81c2c92e) (i32.const 0x92722c85))
(call $four_round (get_local $w8) (get_local $w9) (get_local $w10) (get_local $w11) (i32.const 0xa2bfe8a1) (i32.const 0xa81a664b) (i32.const 0xc24b8b70) (i32.const 0xc76c51a3))
(call $four_round (get_local $w12) (get_local $w13) (get_local $w14) (get_local $w15) (i32.const 0xd192e819) (i32.const 0xd6990624) (i32.const 0xf40e3585) (i32.const 0x106aa070))
(set_local $w0 (call $expand (get_local $w14) (get_local $w9) (get_local $w1) (get_local $w0)))
(set_local $w1 (call $expand (get_local $w15) (get_local $w10) (get_local $w2) (get_local $w1)))
(set_local $w2 (call $expand (get_local $w0 ) (get_local $w11) (get_local $w3) (get_local $w2)))
(set_local $w3 (call $expand (get_local $w1 ) (get_local $w12) (get_local $w4) (get_local $w3)))
(set_local $w4 (call $expand (get_local $w2 ) (get_local $w13) (get_local $w5) (get_local $w4)))
(set_local $w5 (call $expand (get_local $w3 ) (get_local $w14) (get_local $w6) (get_local $w5)))
(set_local $w6 (call $expand (get_local $w4 ) (get_local $w15) (get_local $w7) (get_local $w6)))
(set_local $w7 (call $expand (get_local $w5 ) (get_local $w0) (get_local $w8) (get_local $w7)))
(set_local $w8 (call $expand (get_local $w6 ) (get_local $w1) (get_local $w9) (get_local $w8)))
(set_local $w9 (call $expand (get_local $w7 ) (get_local $w2) (get_local $w10) (get_local $w9)))
(set_local $w10 (call $expand (get_local $w8 ) (get_local $w3) (get_local $w11) (get_local $w10)))
(set_local $w11 (call $expand (get_local $w9 ) (get_local $w4) (get_local $w12) (get_local $w11)))
(set_local $w12 (call $expand (get_local $w10) (get_local $w5) (get_local $w13) (get_local $w12)))
(set_local $w13 (call $expand (get_local $w11) (get_local $w6) (get_local $w14) (get_local $w13)))
(set_local $w14 (call $expand (get_local $w12) (get_local $w7) (get_local $w15) (get_local $w14)))
(set_local $w15 (call $expand (get_local $w13) (get_local $w8) (get_local $w0) (get_local $w15)))
(call $four_round (get_local $w0) (get_local $w1) (get_local $w2) (get_local $w3) (i32.const 0x19a4c116) (i32.const 0x1e376c08) (i32.const 0x2748774c) (i32.const 0x34b0bcb5))
(call $four_round (get_local $w4) (get_local $w5) (get_local $w6) (get_local $w7) (i32.const 0x391c0cb3) (i32.const 0x4ed8aa4a) (i32.const 0x5b9cca4f) (i32.const 0x682e6ff3))
(call $four_round (get_local $w8) (get_local $w9) (get_local $w10) (get_local $w11) (i32.const 0x748f82ee) (i32.const 0x78a5636f) (i32.const 0x84c87814) (i32.const 0x8cc70208))
(call $four_round (get_local $w12) (get_local $w13) (get_local $w14) (get_local $w15) (i32.const 0x90befffa) (i32.const 0xa4506ceb) (i32.const 0xbef9a3f7) (i32.const 0xc67178f2))
;; store hash values
(i32.store offset=0 (get_local $ctx) (i32.add (i32.load offset=0 (get_local $ctx)) (get_global $a)))
(i32.store offset=4 (get_local $ctx) (i32.add (i32.load offset=4 (get_local $ctx)) (get_global $b)))
(i32.store offset=8 (get_local $ctx) (i32.add (i32.load offset=8 (get_local $ctx)) (get_global $c)))
(i32.store offset=12 (get_local $ctx) (i32.add (i32.load offset=12 (get_local $ctx)) (get_global $d)))
(i32.store offset=16 (get_local $ctx) (i32.add (i32.load offset=16 (get_local $ctx)) (get_global $e)))
(i32.store offset=20 (get_local $ctx) (i32.add (i32.load offset=20 (get_local $ctx)) (get_global $f)))
(i32.store offset=24 (get_local $ctx) (i32.add (i32.load offset=24 (get_local $ctx)) (get_global $g)))
(i32.store offset=28 (get_local $ctx) (i32.add (i32.load offset=28 (get_local $ctx)) (get_global $h))))
(func $sha256 (export "sha256") (param $ctx i32) (param $roi i32) (param $length i32) (param $final i32)
;; schema 208 bytes
;; 0..32 hash state
;; 32..40 number of bytes read across all updates (128bit)
;; 40..104 store words between updates
;; 104..108 init flag
(local $bytes_read i64)
(local $last_word i32)
(local $tail i32)
;; expanded message schedule
(local $w0 i32) (local $w1 i32) (local $w2 i32) (local $w3 i32)
(local $w4 i32) (local $w5 i32) (local $w6 i32) (local $w7 i32)
(local $w8 i32) (local $w9 i32) (local $w10 i32) (local $w11 i32)
(local $w12 i32) (local $w13 i32) (local $w14 i32) (local $w15 i32)
(set_local $bytes_read (i64.load offset=32 (get_local $ctx)))
(set_local $tail (i32.add (i32.and (i32.wrap/i64 (get_local $bytes_read)) (i32.const 0x3f)) (get_local $length)))
;; load current block position
(set_local $bytes_read (i64.add (get_local $bytes_read) (i64.extend_u/i32 (get_local $length))))
(i64.store offset=32 (get_local $ctx) (get_local $bytes_read))
(block $finish
(set_local $w0 (i32.load offset=40 (get_local $ctx)))
(set_local $w1 (i32.load offset=44 (get_local $ctx)))
(set_local $w2 (i32.load offset=48 (get_local $ctx)))
(set_local $w3 (i32.load offset=52 (get_local $ctx)))
(set_local $w4 (i32.load offset=56 (get_local $ctx)))
(set_local $w5 (i32.load offset=60 (get_local $ctx)))
(set_local $w6 (i32.load offset=64 (get_local $ctx)))
(set_local $w7 (i32.load offset=68 (get_local $ctx)))
(set_local $w8 (i32.load offset=72 (get_local $ctx)))
(set_local $w9 (i32.load offset=76 (get_local $ctx)))
(set_local $w10 (i32.load offset=80 (get_local $ctx)))
(set_local $w11 (i32.load offset=84 (get_local $ctx)))
(set_local $w12 (i32.load offset=88 (get_local $ctx)))
(set_local $w13 (i32.load offset=92 (get_local $ctx)))
(set_local $w14 (i32.load offset=96 (get_local $ctx)))
(set_local $w15 (i32.load offset=100 (get_local $ctx)))
(tee_local $tail (i32.sub (get_local $tail) (i32.const 64)))
(i32.const 0)
(i32.lt_s)
(br_if $finish)
(get_local $ctx)
(get_local $w0 )
(get_local $w1 )
(get_local $w2 )
(get_local $w3 )
(get_local $w4 )
(get_local $w5 )
(get_local $w6 )
(get_local $w7 )
(get_local $w8 )
(get_local $w9 )
(get_local $w10)
(get_local $w11)
(get_local $w12)
(get_local $w13)
(get_local $w14)
(get_local $w15)
(call $compress)
(loop $rest_of_input
(set_local $w0 (i32.load offset=0 (get_local $roi)))
(set_local $w1 (i32.load offset=4 (get_local $roi)))
(set_local $w2 (i32.load offset=8 (get_local $roi)))
(set_local $w3 (i32.load offset=12 (get_local $roi)))
(set_local $w4 (i32.load offset=16 (get_local $roi)))
(set_local $w5 (i32.load offset=20 (get_local $roi)))
(set_local $w6 (i32.load offset=24 (get_local $roi)))
(set_local $w7 (i32.load offset=28 (get_local $roi)))
(set_local $w8 (i32.load offset=32 (get_local $roi)))
(set_local $w9 (i32.load offset=36 (get_local $roi)))
(set_local $w10 (i32.load offset=40 (get_local $roi)))
(set_local $w11 (i32.load offset=44 (get_local $roi)))
(set_local $w12 (i32.load offset=48 (get_local $roi)))
(set_local $w13 (i32.load offset=52 (get_local $roi)))
(set_local $w14 (i32.load offset=56 (get_local $roi)))
(set_local $w15 (i32.load offset=60 (get_local $roi)))
(set_local $roi (i32.add (get_local $roi) (i32.const 64)))
(tee_local $tail (i32.sub (get_local $tail) (i32.const 64)))
(i32.const 0)
(i32.lt_s)
(if
(then
(i32.store offset=40 (get_local $ctx) (get_local $w0))
(i32.store offset=44 (get_local $ctx) (get_local $w1))
(i32.store offset=48 (get_local $ctx) (get_local $w2))
(i32.store offset=52 (get_local $ctx) (get_local $w3))
(i32.store offset=56 (get_local $ctx) (get_local $w4))
(i32.store offset=60 (get_local $ctx) (get_local $w5))
(i32.store offset=64 (get_local $ctx) (get_local $w6))
(i32.store offset=68 (get_local $ctx) (get_local $w7))
(i32.store offset=72 (get_local $ctx) (get_local $w8))
(i32.store offset=76 (get_local $ctx) (get_local $w9))
(i32.store offset=80 (get_local $ctx) (get_local $w10))
(i32.store offset=84 (get_local $ctx) (get_local $w11))
(i32.store offset=88 (get_local $ctx) (get_local $w12))
(i32.store offset=92 (get_local $ctx) (get_local $w13))
(i32.store offset=96 (get_local $ctx) (get_local $w14))
(i32.store offset=100 (get_local $ctx) (get_local $w15))
(br $finish)))
(get_local $ctx)
(get_local $w0 )
(get_local $w1 )
(get_local $w2 )
(get_local $w3 )
(get_local $w4 )
(get_local $w5 )
(get_local $w6 )
(get_local $w7 )
(get_local $w8 )
(get_local $w9 )
(get_local $w10)
(get_local $w11)
(get_local $w12)
(get_local $w13)
(get_local $w14)
(get_local $w15)
(call $compress)
(br $rest_of_input)))
(if (i32.eq (get_local $final) (i32.const 1))
(then
(set_local $tail (i32.and (i32.wrap/i64 (get_local $bytes_read)) (i32.const 0x3f)))
(set_local $last_word (i32.shl (i32.const 0x80) (i32.shl (i32.and (get_local $tail) (i32.const 0x3)) (i32.const 3))))
(block $pad_end
(block $13
(block $12
(block $11
(block $10
(block $9
(block $8
(block $7
(block $6
(block $5
(block $4
(block $3
(block $2
(block $1
(block $0
(block $15
(block $14
(block $switch
(get_local $tail)
(i32.const 2)
(i32.shr_u)
(br_table $0 $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15)))
(get_local $last_word)
(get_local $w14)
(i32.or)
(set_local $w14)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w15)
(i32.or)
(set_local $w15)
(set_local $last_word (i32.const 0))
;; compress
(get_local $ctx)
(get_local $w0)
(get_local $w1)
(get_local $w2)
(get_local $w3)
(get_local $w4)
(get_local $w5)
(get_local $w6)
(get_local $w7)
(get_local $w8)
(get_local $w9)
(get_local $w10)
(get_local $w11)
(get_local $w12)
(get_local $w13)
(get_local $w14)
(get_local $w15)
(call $compress)
(i64.store offset=32 (get_local $ctx) (get_local $bytes_read))
;; zero out words
(set_local $w0 (i32.const 0))
(set_local $w1 (i32.const 0))
(set_local $w2 (i32.const 0))
(set_local $w3 (i32.const 0))
(set_local $w4 (i32.const 0))
(set_local $w5 (i32.const 0))
(set_local $w6 (i32.const 0))
(set_local $w7 (i32.const 0))
(set_local $w8 (i32.const 0))
(set_local $w9 (i32.const 0))
(set_local $w10 (i32.const 0))
(set_local $w11 (i32.const 0))
(set_local $w12 (i32.const 0))
(set_local $w13 (i32.const 0))
(set_local $w14 (i32.const 0))
(set_local $w15 (i32.const 0)))
(get_local $last_word)
(get_local $w0)
(i32.or)
(set_local $w0)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w1)
(i32.or)
(set_local $w1)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w2)
(i32.or)
(set_local $w2)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w3)
(i32.or)
(set_local $w3)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w4)
(i32.or)
(set_local $w4)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w5)
(i32.or)
(set_local $w5)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w6)
(i32.or)
(set_local $w6)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w7)
(i32.or)
(set_local $w7)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w8)
(i32.or)
(set_local $w8)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w9)
(i32.or)
(set_local $w9)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w10)
(i32.or)
(set_local $w10)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w11)
(i32.or)
(set_local $w11)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w12)
(i32.or)
(set_local $w12)
(set_local $last_word (i32.const 0)))
(get_local $last_word)
(get_local $w13)
(i32.or)
(set_local $w13)
(set_local $last_word (i32.const 0)))
(set_local $w14 (call $i32.bswap (i32.wrap/i64 (i64.shr_u (get_local $bytes_read) (i64.const 29)))))
(set_local $w15 (call $i32.bswap (i32.wrap/i64 (i64.shl (get_local $bytes_read) (i64.const 3)))))
(get_local $ctx)
(get_local $w0)
(get_local $w1)
(get_local $w2)
(get_local $w3)
(get_local $w4)
(get_local $w5)
(get_local $w6)
(get_local $w7)
(get_local $w8)
(get_local $w9)
(get_local $w10)
(get_local $w11)
(get_local $w12)
(get_local $w13)
(get_local $w14)
(get_local $w15)
(call $compress)
(get_local $ctx)
(i32.load offset=0 (get_local $ctx))
(call $i32.bswap)
(i32.store offset=0)
(get_local $ctx)
(i32.load offset=4 (get_local $ctx))
(call $i32.bswap)
(i32.store offset=4)
(get_local $ctx)
(i32.load offset=8 (get_local $ctx))
(call $i32.bswap)
(i32.store offset=8)
(get_local $ctx)
(i32.load offset=12 (get_local $ctx))
(call $i32.bswap)
(i32.store offset=12)
(get_local $ctx)
(i32.load offset=16 (get_local $ctx))
(call $i32.bswap)
(i32.store offset=16)
(get_local $ctx)
(i32.load offset=20 (get_local $ctx))
(call $i32.bswap)
(i32.store offset=20)
(get_local $ctx)
(i32.load offset=24 (get_local $ctx))
(call $i32.bswap)
(i32.store offset=24)
(get_local $ctx)
(i32.load offset=28 (get_local $ctx))
(call $i32.bswap)
(i32.store offset=28)))))