; LLVM IR from guanzhi/GmSSL :: src (sm9_z256)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local void @sm9_z256_to_bits(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 3, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %35, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %11, label %38

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i64, ptr %12, i64 %14
  %16 = load i64, ptr %15, align 8, !tbaa !11
  store i64 %16, ptr %7, align 8, !tbaa !11
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %31, %11
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 64
  br i1 %19, label %20, label %34

20:                                               ; preds = %17
  %21 = load i64, ptr %7, align 8, !tbaa !11
  %22 = and i64 %21, -9223372036854775808
  %23 = icmp ne i64 %22, 0
  %24 = zext i1 %23 to i64
  %25 = select i1 %23, i32 49, i32 48
  %26 = trunc i32 %25 to i8
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds i8, ptr %27, i32 1
  store ptr %28, ptr %4, align 8, !tbaa !5
  store i8 %26, ptr %27, align 1, !tbaa !13
  %29 = load i64, ptr %7, align 8, !tbaa !11
  %30 = shl i64 %29, 1
  store i64 %30, ptr %7, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %20
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %6, align 4, !tbaa !9
  br label %17, !llvm.loop !14

34:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = add nsw i32 %36, -1
  store i32 %37, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !16

38:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local void @sm9_z256_to_bits(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 24
  %4 = load i64, ptr %3, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %5, %2
  %.013 = phi i64 [ %4, %2 ], [ %14, %5 ]
  %.0812 = phi i32 [ 0, %2 ], [ %15, %5 ]
  %.111 = phi ptr [ %1, %2 ], [ %13, %5 ]
  %.not = icmp sgt i64 %.013, -1
  %6 = select i1 %.not, i8 48, i8 49
  %7 = getelementptr inbounds i8, ptr %.111, i64 1
  store i8 %6, ptr %.111, align 1, !tbaa !9
  %.mask = and i64 %.013, 4611686018427387904
  %.not.126 = icmp eq i64 %.mask, 0
  %8 = select i1 %.not.126, i8 48, i8 49
  %9 = getelementptr inbounds i8, ptr %.111, i64 2
  store i8 %8, ptr %7, align 1, !tbaa !9
  %.mask35 = and i64 %.013, 2305843009213693952
  %.not.230 = icmp eq i64 %.mask35, 0
  %10 = select i1 %.not.230, i8 48, i8 49
  %11 = getelementptr inbounds i8, ptr %.111, i64 3
  store i8 %10, ptr %9, align 1, !tbaa !9
  %.mask36 = and i64 %.013, 1152921504606846976
  %.not.334 = icmp eq i64 %.mask36, 0
  %12 = select i1 %.not.334, i8 48, i8 49
  %13 = getelementptr inbounds i8, ptr %.111, i64 4
  store i8 %12, ptr %11, align 1, !tbaa !9
  %14 = shl i64 %.013, 4
  %15 = add nuw nsw i32 %.0812, 4
  %exitcond.not.3 = icmp eq i32 %15, 64
  br i1 %exitcond.not.3, label %16, label %5, !llvm.loop !10

16:                                               ; preds = %5
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %19, %16
  %.013.1 = phi i64 [ %18, %16 ], [ %28, %19 ]
  %.0812.1 = phi i32 [ 0, %16 ], [ %29, %19 ]
  %.111.1 = phi ptr [ %13, %16 ], [ %27, %19 ]
  %.not.1 = icmp sgt i64 %.013.1, -1
  %20 = select i1 %.not.1, i8 48, i8 49
  %21 = getelementptr inbounds i8, ptr %.111.1, i64 1
  store i8 %20, ptr %.111.1, align 1, !tbaa !9
  %.mask37 = and i64 %.013.1, 4611686018427387904
  %.not.1.1 = icmp eq i64 %.mask37, 0
  %22 = select i1 %.not.1.1, i8 48, i8 49
  %23 = getelementptr inbounds i8, ptr %.111.1, i64 2
  store i8 %22, ptr %21, align 1, !tbaa !9
  %.mask38 = and i64 %.013.1, 2305843009213693952
  %.not.1.2 = icmp eq i64 %.mask38, 0
  %24 = select i1 %.not.1.2, i8 48, i8 49
  %25 = getelementptr inbounds i8, ptr %.111.1, i64 3
  store i8 %24, ptr %23, align 1, !tbaa !9
  %.mask39 = and i64 %.013.1, 1152921504606846976
  %.not.1.3 = icmp eq i64 %.mask39, 0
  %26 = select i1 %.not.1.3, i8 48, i8 49
  %27 = getelementptr inbounds i8, ptr %.111.1, i64 4
  store i8 %26, ptr %25, align 1, !tbaa !9
  %28 = shl i64 %.013.1, 4
  %29 = add nuw nsw i32 %.0812.1, 4
  %exitcond.1.not.3 = icmp eq i32 %29, 64
  br i1 %exitcond.1.not.3, label %30, label %19, !llvm.loop !10

30:                                               ; preds = %19
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  %32 = load i64, ptr %31, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %33, %30
  %.013.2 = phi i64 [ %32, %30 ], [ %42, %33 ]
  %.0812.2 = phi i32 [ 0, %30 ], [ %43, %33 ]
  %.111.2 = phi ptr [ %27, %30 ], [ %41, %33 ]
  %.not.2 = icmp sgt i64 %.013.2, -1
  %34 = select i1 %.not.2, i8 48, i8 49
  %35 = getelementptr inbounds i8, ptr %.111.2, i64 1
  store i8 %34, ptr %.111.2, align 1, !tbaa !9
  %.mask40 = and i64 %.013.2, 4611686018427387904
  %.not.2.1 = icmp eq i64 %.mask40, 0
  %36 = select i1 %.not.2.1, i8 48, i8 49
  %37 = getelementptr inbounds i8, ptr %.111.2, i64 2
  store i8 %36, ptr %35, align 1, !tbaa !9
  %.mask41 = and i64 %.013.2, 2305843009213693952
  %.not.2.2 = icmp eq i64 %.mask41, 0
  %38 = select i1 %.not.2.2, i8 48, i8 49
  %39 = getelementptr inbounds i8, ptr %.111.2, i64 3
  store i8 %38, ptr %37, align 1, !tbaa !9
  %.mask42 = and i64 %.013.2, 1152921504606846976
  %.not.2.3 = icmp eq i64 %.mask42, 0
  %40 = select i1 %.not.2.3, i8 48, i8 49
  %41 = getelementptr inbounds i8, ptr %.111.2, i64 4
  store i8 %40, ptr %39, align 1, !tbaa !9
  %42 = shl i64 %.013.2, 4
  %43 = add nuw nsw i32 %.0812.2, 4
  %exitcond.2.not.3 = icmp eq i32 %43, 64
  br i1 %exitcond.2.not.3, label %44, label %33, !llvm.loop !10

44:                                               ; preds = %33
  %45 = load i64, ptr %0, align 8, !tbaa !5
  br label %46

46:                                               ; preds = %46, %44
  %.013.3 = phi i64 [ %45, %44 ], [ %55, %46 ]
  %.0812.3 = phi i32 [ 0, %44 ], [ %56, %46 ]
  %.111.3 = phi ptr [ %41, %44 ], [ %54, %46 ]
  %.not.3 = icmp sgt i64 %.013.3, -1
  %47 = select i1 %.not.3, i8 48, i8 49
  %48 = getelementptr inbounds i8, ptr %.111.3, i64 1
  store i8 %47, ptr %.111.3, align 1, !tbaa !9
  %.mask43 = and i64 %.013.3, 4611686018427387904
  %.not.3.1 = icmp eq i64 %.mask43, 0
  %49 = select i1 %.not.3.1, i8 48, i8 49
  %50 = getelementptr inbounds i8, ptr %.111.3, i64 2
  store i8 %49, ptr %48, align 1, !tbaa !9
  %.mask44 = and i64 %.013.3, 2305843009213693952
  %.not.3.2 = icmp eq i64 %.mask44, 0
  %51 = select i1 %.not.3.2, i8 48, i8 49
  %52 = getelementptr inbounds i8, ptr %.111.3, i64 3
  store i8 %51, ptr %50, align 1, !tbaa !9
  %.mask45 = and i64 %.013.3, 1152921504606846976
  %.not.3.3 = icmp eq i64 %.mask45, 0
  %53 = select i1 %.not.3.3, i8 48, i8 49
  %54 = getelementptr inbounds i8, ptr %.111.3, i64 4
  store i8 %53, ptr %52, align 1, !tbaa !9
  %55 = shl i64 %.013.3, 4
  %56 = add nuw nsw i32 %.0812.3, 4
  %exitcond.3.not.3 = icmp eq i32 %56, 64
  br i1 %exitcond.3.not.3, label %57, label %46, !llvm.loop !10

57:                                               ; preds = %46
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: readwrite, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass