datealgo 0.2.0

Low-level date algorithms for libraries
Documentation
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
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
# Compilation provided by Compiler Explorer at https://godbolt.org/
example::rd_to_date:
  lea ecx, [4*rdi - 2147385461]
  imul rax, rcx, 963315389
  shr rax, 47
  imul edx, eax, 146097
  sub ecx, edx
  or ecx, 3
  imul rcx, rcx, 2939745
  mov edx, ecx
  imul rdx, rdx, 1531969483
  shr rdx, 54
  imul edx, edx, 2141
  add edx, 197913
  movzx esi, dx
  shr edx, 16
  lea edi, [rdx + 244]
  imul r8d, eax, 100
  mov rax, rcx
  shr rax, 32
  add eax, r8d
  cmp ecx, -696719416
  cmovb edi, edx
  sbb eax, -1
  add eax, -1468000
  imul ecx, esi, 31345
  shr ecx, 26
  inc ecx
  shl rcx, 40
  movzx edx, dil
  shl rdx, 32
  or rdx, rcx
  or rax, rdx
  ret

example::date_to_rd:
  mov rax, rdi
  shr rax, 32
  cmp al, 3
  mov ecx, edi
  sbb ecx, 0
  movzx edx, al
  lea esi, [rdx + 12]
  cmp al, 3
  cmovae esi, edx
  shr rdi, 40
  add ecx, 1468000
  movzx eax, dil
  imul rdx, rcx, 1374389535
  mov rdi, rdx
  shr rdi, 37
  imul ecx, ecx, 1461
  shr ecx, 2
  shr rdx, 39
  imul esi, esi, 979
  add esi, -2919
  shr esi, 5
  sub eax, edi
  add edx, ecx
  add edx, eax
  lea eax, [rsi + rdx]
  add eax, -536895459
  ret

example::rd_to_weekday:
  lea eax, [rdi + 536895460]
  imul rcx, rax, 613566757
  shr rcx, 32
  sub eax, ecx
  shr eax
  add eax, ecx
  shr eax, 2
  lea ecx, [8*rax]
  sub eax, ecx
  add eax, edi
  add eax, 536895460
  inc al
  ret

example::date_to_weekday:
  movabs rax, 281474976710655
  and rax, rdi
  mov rcx, rax
  shr rcx, 32
  cmp cl, 3
  sbb edi, 0
  movzx edx, cl
  lea esi, [rdx + 12]
  cmp cl, 3
  cmovae esi, edx
  shr rax, 40
  add edi, 1468000
  imul rcx, rdi, 1374389535
  mov rdx, rcx
  shr rdx, 37
  imul edi, edi, 1461
  shr edi, 2
  shr rcx, 39
  imul esi, esi, 979
  add esi, -2919
  shr esi, 5
  sub eax, edx
  add ecx, edi
  add ecx, eax
  add ecx, esi
  inc ecx
  imul rdx, rcx, 613566757
  shr rdx, 32
  mov eax, ecx
  sub eax, edx
  shr eax
  add eax, edx
  shr eax, 2
  lea edx, [8*rax]
  sub eax, edx
  add eax, ecx
  inc al
  ret

example::next_date:
  movabs rcx, 1099511627776
  mov rax, rdi
  shr rax, 32
  mov rdx, rdi
  shr rdx, 40
  cmp dl, 28
  jb .LBB4_6
  cmp al, 2
  jne .LBB4_2
  imul esi, edi, -1030792151
  add esi, 85899345
  cmp esi, 171798691
  mov esi, 15
  mov r8d, 3
  cmovb r8d, esi
  test r8d, edi
  sete sil
  or sil, 28
  cmp sil, dl
  ja .LBB4_6
  jmp .LBB4_7
.LBB4_2:
  mov esi, eax
  shr sil, 3
  xor sil, al
  or sil, 30
  cmp sil, dl
  jbe .LBB4_3
.LBB4_6:
  add rcx, rdi
  movabs rdx, 280375465082880
  and rcx, rdx
  jmp .LBB4_8
.LBB4_3:
  cmp al, 12
  jae .LBB4_4
.LBB4_7:
  inc rax
  jmp .LBB4_8
.LBB4_4:
  inc rdi
  mov eax, 1
.LBB4_8:
  movzx edx, al
  shl rdx, 32
  mov eax, edi
  or rax, rcx
  or rax, rdx
  ret

example::prev_date:
  mov rax, rdi
  shr rax, 32
  mov rcx, rdi
  shr rcx, 40
  cmp cl, 1
  jbe .LBB5_1
  dec cl
  jmp .LBB5_6
.LBB5_1:
  cmp al, 1
  jbe .LBB5_2
  dec al
  cmp al, 2
  jne .LBB5_5
  imul eax, edi, -1030792151
  add eax, 85899345
  cmp eax, 171798691
  mov eax, 15
  mov ecx, 3
  cmovb ecx, eax
  test ecx, edi
  sete cl
  or cl, 28
  mov al, 2
  jmp .LBB5_6
.LBB5_2:
  mov eax, 4294967295
  add rdi, rax
  mov cl, 31
  mov al, 12
  jmp .LBB5_6
.LBB5_5:
  mov ecx, eax
  shr cl, 3
  xor cl, al
  or cl, 30
.LBB5_6:
  movzx ecx, cl
  shl rcx, 40
  movzx edx, al
  shl rdx, 32
  or rdx, rcx
  mov eax, edi
  or rax, rdx
  ret

example::secs_to_dhms:
  movabs rax, 46387767571200
  lea rcx, [rdi + rax]
  movabs rdx, 46381619174399
  cmp rdi, rdx
  cmovg rcx, rax
  movabs rdx, -4454547087429121353
  mov rax, rcx
  mul rdx
  shr rdx, 16
  imul rax, rdx, 86400
  sub rcx, rax
  imul rax, rcx, 71582789
  mov ecx, eax
  shr rax, 32
  mov esi, 4026531799
  imul rcx, rsi
  imul rax, rax, 71582789
  movabs rdi, 545460846592
  and rdi, rax
  mov r8d, eax
  imul r8, rsi
  lea eax, [rdx - 536895458]
  shr rcx, 10
  movabs rdx, 17732923532771328
  and rdx, rcx
  shr r8, 18
  movabs rcx, 69269232549888
  and rcx, r8
  or rcx, rdx
  or rcx, rdi
  or rax, rcx
  ret

example::dhms_to_secs:
  lea eax, [rdi + 536895152]
  cmp eax, 1073719447
  ja .LBB7_1
  mov rax, rdi
  shr rax, 48
  mov rcx, rdi
  shr rcx, 40
  mov rdx, rdi
  shr rdx, 32
  movsxd rsi, edi
  imul rsi, rsi, 86400
  movzx edx, dl
  imul rdx, rdx, 3600
  movzx ecx, cl
  imul rcx, rcx, 60
  movzx eax, al
  add rax, rsi
  add rax, rdx
  add rax, rcx
  ret
.LBB7_1:
  xor eax, eax
  ret

example::secs_to_datetime:
  movabs rax, 46387767571200
  lea rcx, [rsi + rax]
  movabs rdx, 46381619174399
  cmp rsi, rdx
  cmovg rcx, rax
  movabs rdx, -4454547087429121353
  mov rax, rcx
  mul rdx
  shr rdx, 16
  lea esi, [4*rdx + 3]
  imul rax, rsi, 963315389
  shr rax, 47
  imul r8d, eax, 146097
  sub esi, r8d
  or esi, 3
  imul rsi, rsi, 2939745
  mov r8d, esi
  imul r8, r8, 1531969483
  shr r8, 54
  imul r8d, r8d, 2141
  add r8d, 197913
  movzx r9d, r8w
  shr r8d, 16
  lea r10d, [r8 - 12]
  imul eax, eax, 100
  mov r11, rsi
  shr r11, 32
  add r11d, eax
  cmp esi, -696719416
  sbb r11d, -1
  cmp esi, -696719416
  movzx eax, r10b
  cmovb eax, r8d
  imul rdx, rdx, 86400
  sub rcx, rdx
  imul rcx, rcx, 71582789
  mov edx, ecx
  shr rcx, 32
  mov esi, 4026531799
  imul rdx, rsi
  shr rdx, 58
  imul rcx, rcx, 71582789
  mov r8d, ecx
  imul r8, rsi
  shr r8, 58
  shr rcx, 32
  add r11d, -1468000
  imul esi, r9d, 31345
  shr esi, 26
  inc sil
  mov dword ptr [rdi], r11d
  mov byte ptr [rdi + 4], al
  mov byte ptr [rdi + 5], sil
  mov byte ptr [rdi + 6], cl
  mov byte ptr [rdi + 7], r8b
  mov byte ptr [rdi + 8], dl
  mov rax, rdi
  ret

example::datetime_to_secs:
  mov ecx, dword ptr [rdi]
  movzx eax, byte ptr [rdi + 4]
  cmp eax, 3
  sbb ecx, 0
  lea edx, [rax + 12]
  cmp eax, 3
  cmovae edx, eax
  movzx esi, byte ptr [rdi + 5]
  add ecx, 1468000
  imul rax, rcx, 1374389535
  mov r8, rax
  shr r8, 37
  imul r9d, ecx, 1461
  shr r9d, 2
  shr rax, 39
  imul ecx, edx, 979
  add ecx, -2919
  shr ecx, 5
  sub esi, r8d
  add eax, r9d
  add eax, esi
  lea edx, [rcx + rax]
  add edx, -307
  cmp edx, 1073719447
  ja .LBB9_1
  add eax, ecx
  add eax, -536895459
  movzx ecx, byte ptr [rdi + 8]
  movzx edx, byte ptr [rdi + 7]
  movzx esi, byte ptr [rdi + 6]
  cdqe
  imul rdi, rax, 86400
  imul rsi, rsi, 3600
  imul rax, rdx, 60
  add rax, rcx
  add rax, rsi
  add rax, rdi
  ret
.LBB9_1:
  xor eax, eax
  ret

example::is_leap_year:
  imul eax, edi, -1030792151
  add eax, 85899345
  cmp eax, 171798691
  mov eax, 15
  mov ecx, 3
  cmovb ecx, eax
  test ecx, edi
  sete al
  ret

example::days_in_month:
  cmp sil, 2
  jne .LBB11_2
  imul eax, edi, -1030792151
  add eax, 85899345
  cmp eax, 171798691
  mov eax, 15
  mov ecx, 3
  cmovb ecx, eax
  test ecx, edi
  sete al
  or al, 28
  ret
.LBB11_2:
  mov eax, esi
  shr al, 3
  xor al, sil
  or al, 30
  ret

example::rd_to_isoweekdate:
  lea eax, [rdi + 536895460]
  imul rcx, rax, 613566757
  shr rcx, 32
  sub eax, ecx
  shr eax
  add eax, ecx
  shr eax, 2
  lea ecx, [8*rax]
  sub eax, ecx
  lea edx, [rdi + rax]
  add edx, 536895460
  lea ecx, [rdi + rax]
  add ecx, 536895461
  inc dl
  movzx eax, dl
  sub edi, eax
  lea eax, [4*rdi - 2147385445]
  imul rdx, rax, 963315389
  shr rdx, 47
  imul esi, edx, 146097
  sub eax, esi
  or eax, 3
  imul rax, rax, 2939745
  imul edx, edx, 100
  mov rsi, rax
  shr rsi, 32
  add esi, edx
  cmp eax, -696719416
  sbb esi, -1
  lea edx, [rsi - 1468000]
  dec esi
  imul rax, rsi, 1374389535
  mov r8, rax
  shr r8, 37
  imul esi, esi, 1461
  shr esi, 2
  shr rax, 39
  add r8d, edi
  add eax, esi
  sub r8d, eax
  mov eax, r8d
  add eax, 536895156
  cdqe
  imul rax, rax, -1840700269
  shr rax, 32
  add eax, r8d
  add eax, 536895156
  mov esi, eax
  shr esi, 2
  shr eax, 31
  shl rcx, 40
  add eax, esi
  inc eax
  movzx eax, al
  shl rax, 32
  or rax, rcx
  or rax, rdx
  ret

example::isoweekdate_to_rd:
  mov rax, rdi
  shr rax, 32
  mov rcx, rdi
  shr rcx, 40
  add edi, 1467999
  imul rdx, rdi, 1374389535
  mov rsi, rdx
  shr rsi, 37
  imul edi, edi, 1461
  shr edi, 2
  shr rdx, 39
  sub edx, esi
  movzx eax, al
  lea esi, [8*rax]
  sub esi, eax
  movzx eax, cl
  add eax, esi
  add eax, edi
  add eax, edx
  lea ecx, [rdx + rdi]
  add ecx, 311
  imul rdx, rcx, 613566757
  shr rdx, 32
  mov esi, ecx
  sub esi, edx
  shr esi
  add esi, edx
  shr esi, 2
  lea edx, [8*rsi]
  sub edx, esi
  sub edx, ecx
  add eax, edx
  add eax, -536895157
  ret

example::date_to_isoweekdate:
  movabs rax, 281474976710655
  and rax, rdi
  mov rcx, rax
  shr rcx, 32
  cmp cl, 3
  sbb edi, 0
  movzx edx, cl
  lea esi, [rdx + 12]
  cmp cl, 3
  cmovae esi, edx
  shr rax, 40
  add edi, 1468000
  imul rcx, rdi, 1374389535
  mov rdx, rcx
  shr rdx, 37
  imul edi, edi, 1461
  shr edi, 2
  shr rcx, 39
  imul esi, esi, 979
  add esi, -2919
  shr esi, 5
  sub eax, edx
  add ecx, edi
  add ecx, eax
  lea eax, [rcx + rsi]
  add ecx, esi
  inc ecx
  imul rsi, rcx, 613566757
  shr rsi, 32
  mov edx, ecx
  sub edx, esi
  shr edx
  add edx, esi
  shr edx, 2
  lea esi, [8*rdx]
  sub edx, esi
  lea esi, [rcx + rdx]
  inc sil
  movzx esi, sil
  sub eax, esi
  lea esi, [rax - 536895459]
  lea esi, [4*rsi - 2147385445]
  imul rdi, rsi, 963315389
  shr rdi, 47
  imul r8d, edi, 146097
  sub esi, r8d
  or esi, 3
  imul rsi, rsi, 2939745
  imul edi, edi, 100
  mov r8, rsi
  shr r8, 32
  add r8d, edi
  cmp esi, -696719416
  sbb r8d, -1
  add edx, ecx
  inc edx
  lea ecx, [r8 - 1468000]
  dec r8d
  imul rsi, r8, 1374389535
  mov rdi, rsi
  shr rdi, 37
  imul r8d, r8d, 1461
  shr r8d, 2
  shr rsi, 39
  add eax, edi
  add eax, -536895459
  add esi, r8d
  sub eax, esi
  mov esi, eax
  add esi, 536895156
  movsxd rsi, esi
  imul rsi, rsi, -1840700269
  shr rsi, 32
  add eax, esi
  add eax, 536895156
  mov esi, eax
  shr esi, 2
  shr eax, 31
  shl rdx, 40
  add eax, esi
  inc eax
  movzx eax, al
  shl rax, 32
  or rax, rdx
  or rax, rcx
  ret

example::isoweekdate_to_date:
  mov rax, rdi
  shr rax, 32
  mov rcx, rdi
  shr rcx, 40
  movzx ecx, cl
  add edi, 1467999
  imul rdx, rdi, 1374389535
  mov rsi, rdx
  shr rsi, 37
  imul edi, edi, 1461
  shr edi, 2
  shr rdx, 39
  sub edx, esi
  movzx esi, al
  lea eax, [8*rsi]
  sub eax, esi
  add eax, ecx
  add eax, edi
  add eax, edx
  lea ecx, [rdx + rdi]
  add ecx, 311
  imul rdx, rcx, 613566757
  shr rdx, 32
  mov esi, ecx
  sub esi, edx
  shr esi
  add esi, edx
  shr esi, 2
  lea edx, [8*rsi]
  sub edx, esi
  sub edx, ecx
  add edx, eax
  lea ecx, [4*rdx + 1207]
  imul rax, rcx, 963315389
  shr rax, 47
  imul edx, eax, 146097
  sub ecx, edx
  or ecx, 3
  imul rcx, rcx, 2939745
  mov edx, ecx
  imul rdx, rdx, 1531969483
  shr rdx, 54
  imul edx, edx, 2141
  add edx, 197913
  movzx esi, dx
  shr edx, 16
  lea edi, [rdx + 244]
  imul r8d, eax, 100
  mov rax, rcx
  shr rax, 32
  add eax, r8d
  cmp ecx, -696719416
  cmovb edi, edx
  sbb eax, -1
  add eax, -1468000
  imul ecx, esi, 31345
  shr ecx, 26
  inc ecx
  shl rcx, 40
  movzx edx, dil
  shl rdx, 32
  or rdx, rcx
  or rax, rdx
  ret

example::isoweeks_in_year:
  lea eax, [rdi + 1467999]
  imul rcx, rax, 1374389535
  mov rdx, rcx
  shr rdx, 37
  imul eax, eax, 1461
  shr eax, 2
  shr rcx, 39
  sub ecx, edx
  add eax, ecx
  add eax, 308
  imul rdx, rax, 613566757
  shr rdx, 32
  mov ecx, eax
  sub ecx, edx
  shr ecx
  add ecx, edx
  shr ecx, 2
  lea edx, [8*rcx]
  sub ecx, edx
  add ecx, eax
  cmp cl, 2
  je .LBB16_3
  mov al, 52
  cmp ecx, 3
  jne .LBB16_4
  mov al, 53
  ret
.LBB16_3:
  imul eax, edi, -1030792151
  add eax, 85899345
  cmp eax, 171798691
  mov eax, 15
  mov ecx, 3
  cmovb ecx, eax
  test ecx, edi
  sete al
  or al, 52
.LBB16_4:
  ret

example::systemtime_to_secs:
  push rbx
  sub rsp, 64
  mov rbx, rdi
  mov qword ptr [rsp + 32], rsi
  mov dword ptr [rsp + 40], edx
  lea rdi, [rsp + 8]
  lea rsi, [rsp + 32]
  xor edx, edx
  xor ecx, ecx
  call qword ptr [rip + std::time::SystemTime::duration_since@GOTPCREL]
  cmp qword ptr [rsp + 8], 0
  je .LBB17_1
  mov rax, qword ptr [rsp + 16]
  mov ecx, dword ptr [rsp + 24]
  mov qword ptr [rsp + 48], rax
  mov dword ptr [rsp + 56], ecx
  lea rdi, [rsp + 48]
  call qword ptr [rip + std::time::SystemTimeError::duration@GOTPCREL]
  cmp edx, 1
  sbb rax, -1
  movabs rcx, 46387741132800
  cmp rax, rcx
  ja .LBB17_6
  mov ecx, 1000000000
  sub ecx, edx
  test edx, edx
  cmove ecx, edx
  neg rax
  jmp .LBB17_3
.LBB17_1:
  mov rax, qword ptr [rsp + 16]
  movabs rcx, 46381619174399
  cmp rax, rcx
  jbe .LBB17_2
.LBB17_6:
  mov qword ptr [rbx], 0
  mov rax, rbx
  add rsp, 64
  pop rbx
  ret
.LBB17_2:
  mov ecx, dword ptr [rsp + 24]
.LBB17_3:
  mov qword ptr [rbx + 8], rax
  mov dword ptr [rbx + 16], ecx
  mov qword ptr [rbx], 1
  mov rax, rbx
  add rsp, 64
  pop rbx
  ret

example::secs_to_systemtime:
  mov eax, esi
  mov rsi, rdi
  test rdi, rdi
  js .LBB18_1
  mov ecx, eax
  shr ecx, 9
  imul rcx, rcx, 281475
  shr rcx, 39
  add rsi, rcx
  imul ecx, ecx, 1000000000
  sub eax, ecx
  lea rdi, [rip + .L__unnamed_1]
  mov edx, eax
  jmp qword ptr [rip + _ZN3std4time10SystemTime11checked_add17h23ec42ea1b09df70E@GOTPCREL]
.LBB18_1:
  test eax, eax
  je .LBB18_4
  not rsi
  mov edx, 1000000000
  sub edx, eax
  mov eax, edx
  shr eax, 9
  imul rax, rax, 281475
  shr rax, 39
  add rsi, rax
  imul eax, eax, 1000000000
  sub edx, eax
  lea rdi, [rip + .L__unnamed_1]
  jmp qword ptr [rip + _ZN3std4time10SystemTime11checked_sub17h855e2dc31d3cb494E@GOTPCREL]
.LBB18_4:
  neg rsi
  lea rdi, [rip + .L__unnamed_1]
  xor edx, edx
  jmp qword ptr [rip + _ZN3std4time10SystemTime11checked_sub17h855e2dc31d3cb494E@GOTPCREL]

example::systemtime_to_datetime:
  push r14
  push rbx
  sub rsp, 56
  mov rbx, rdi
  movabs r14, 46387741132800
  mov qword ptr [rsp + 24], rsi
  mov dword ptr [rsp + 32], edx
  mov rdi, rsp
  lea rsi, [rsp + 24]
  xor edx, edx
  xor ecx, ecx
  call qword ptr [rip + std::time::SystemTime::duration_since@GOTPCREL]
  cmp qword ptr [rsp], 0
  je .LBB19_1
  mov rax, qword ptr [rsp + 8]
  mov ecx, dword ptr [rsp + 16]
  mov qword ptr [rsp + 40], rax
  mov dword ptr [rsp + 48], ecx
  lea rdi, [rsp + 40]
  call qword ptr [rip + std::time::SystemTimeError::duration@GOTPCREL]
  cmp edx, 1
  sbb rax, -1
  cmp rax, r14
  ja .LBB19_6
  mov esi, 1000000000
  sub esi, edx
  test edx, edx
  cmove esi, edx
  neg rax
  jmp .LBB19_5
.LBB19_1:
  mov rax, qword ptr [rsp + 8]
  movabs rcx, 46381619174399
  cmp rax, rcx
  jbe .LBB19_2
.LBB19_6:
  xor eax, eax
  jmp .LBB19_7
.LBB19_2:
  mov esi, dword ptr [rsp + 16]
.LBB19_5:
  lea rcx, [r14 + rax]
  add rcx, 26438400
  movabs rdx, -4454547087429121353
  mov rax, rcx
  mul rdx
  shr rdx, 16
  lea edi, [4*rdx + 3]
  imul rax, rdi, 963315389
  shr rax, 47
  imul r8d, eax, 146097
  sub edi, r8d
  or edi, 3
  imul rdi, rdi, 2939745
  mov r8d, edi
  imul r8, r8, 1531969483
  shr r8, 54
  imul r8d, r8d, 2141
  add r8d, 197913
  movzx r9d, r8w
  shr r8d, 16
  lea r10d, [r8 - 12]
  imul eax, eax, 100
  mov r11, rdi
  shr r11, 32
  add r11d, eax
  cmp edi, -696719416
  sbb r11d, -1
  cmp edi, -696719416
  movzx eax, r10b
  cmovb eax, r8d
  imul rdx, rdx, 86400
  sub rcx, rdx
  imul rcx, rcx, 71582789
  mov edx, ecx
  shr rcx, 32
  mov edi, 4026531799
  imul rdx, rdi
  shr rdx, 58
  imul rcx, rcx, 71582789
  mov r8d, ecx
  imul r8, rdi
  shr r8, 58
  shr rcx, 32
  add r11d, -1468000
  imul edi, r9d, 31345
  shr edi, 26
  inc dil
  mov dword ptr [rbx + 4], r11d
  mov byte ptr [rbx + 8], al
  mov byte ptr [rbx + 9], dil
  mov byte ptr [rbx + 10], cl
  mov byte ptr [rbx + 11], r8b
  mov byte ptr [rbx + 12], dl
  mov dword ptr [rbx + 16], esi
  mov eax, 1
.LBB19_7:
  mov dword ptr [rbx], eax
  mov rax, rbx
  add rsp, 56
  pop rbx
  pop r14
  ret

example::datetime_to_systemtime:
  movzx eax, byte ptr [rdi + 4]
  cmp eax, 3
  mov ecx, dword ptr [rdi]
  mov edx, dword ptr [rdi + 12]
  sbb ecx, 0
  lea esi, [rax + 12]
  cmp eax, 3
  cmovae esi, eax
  movzx r8d, byte ptr [rdi + 5]
  add ecx, 1468000
  imul rax, rcx, 1374389535
  mov r9, rax
  shr r9, 37
  imul r10d, ecx, 1461
  shr r10d, 2
  shr rax, 39
  imul ecx, esi, 979
  add ecx, -2919
  shr ecx, 5
  sub r8d, r9d
  add eax, r10d
  add eax, r8d
  lea esi, [rcx + rax]
  add esi, -307
  cmp esi, 1073719447
  ja .LBB20_1
  add eax, ecx
  add eax, -536895459
  movzx ecx, byte ptr [rdi + 8]
  movzx esi, byte ptr [rdi + 7]
  movzx edi, byte ptr [rdi + 6]
  cdqe
  imul rax, rax, 86400
  imul rdi, rdi, 3600
  imul rsi, rsi, 60
  add rsi, rcx
  add rsi, rax
  add rsi, rdi
  jns .LBB20_2
  test edx, edx
  je .LBB20_5
  not rsi
  mov eax, 1000000000
  sub eax, edx
  mov ecx, eax
  shr ecx, 9
  imul rcx, rcx, 281475
  shr rcx, 39
  add rsi, rcx
  imul ecx, ecx, 1000000000
  sub eax, ecx
  lea rdi, [rip + .L__unnamed_1]
  mov edx, eax
  jmp qword ptr [rip + _ZN3std4time10SystemTime11checked_sub17h855e2dc31d3cb494E@GOTPCREL]
.LBB20_1:
  xor esi, esi
.LBB20_2:
  mov eax, edx
  shr eax, 9
  imul rax, rax, 281475
  shr rax, 39
  add rsi, rax
  imul eax, eax, 1000000000
  sub edx, eax
  lea rdi, [rip + .L__unnamed_1]
  jmp qword ptr [rip + _ZN3std4time10SystemTime11checked_add17h23ec42ea1b09df70E@GOTPCREL]
.LBB20_5:
  neg rsi
  lea rdi, [rip + .L__unnamed_1]
  xor edx, edx
  jmp qword ptr [rip + _ZN3std4time10SystemTime11checked_sub17h855e2dc31d3cb494E@GOTPCREL]

.L__unnamed_1:
  .zero 12
  .zero 4