; LLVM IR from specinfo-ua/UAPKI :: library/uapkic/src (sm3)

; 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"

%struct.ByteArray_st = type { ptr, i64 }
%struct.Sm3Ctx_st = type { [2 x i32], [8 x i32], [64 x i8] }

@.str = external hidden unnamed_addr constant [13 x i8], align 1

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

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

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @sm3_update(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, 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) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  br label %10

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %15, label %13

13:                                               ; preds = %10
  store i32 2, ptr %5, align 4, !tbaa !9
  %14 = load i32, ptr %5, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 217, i32 noundef %14, ptr noundef null)
  br label %112

15:                                               ; preds = %10
  br label %16

16:                                               ; preds = %15
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %23, label %21

21:                                               ; preds = %18
  store i32 2, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !9
  call void @stacktrace_create(ptr noundef @.str, i64 noundef 218, i32 noundef %22, ptr noundef null)
  br label %112

23:                                               ; preds = %18
  br label %24

24:                                               ; preds = %23
  br label %25

25:                                               ; preds = %24
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.ByteArray_st, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %9, align 8, !tbaa !5
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ByteArray_st, ptr %29, i32 0, i32 1
  %31 = load i64, ptr %30, align 8, !tbaa !14
  store i64 %31, ptr %8, align 8, !tbaa !15
  %32 = load i64, ptr %8, align 8, !tbaa !15
  %33 = icmp eq i64 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %25
  br label %112

35:                                               ; preds = %25
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Sm3Ctx_st, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [2 x i32], ptr %37, i64 0, i64 0
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = and i32 %39, 63
  %41 = zext i32 %40 to i64
  store i64 %41, ptr %7, align 8, !tbaa !15
  %42 = load i64, ptr %7, align 8, !tbaa !15
  %43 = sub i64 64, %42
  store i64 %43, ptr %6, align 8, !tbaa !15
  %44 = load i64, ptr %8, align 8, !tbaa !15
  %45 = trunc i64 %44 to i32
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Sm3Ctx_st, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds [2 x i32], ptr %47, i64 0, i64 0
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = add i32 %49, %45
  store i32 %50, ptr %48, align 4, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.Sm3Ctx_st, ptr %51, i32 0, i32 0
  %53 = getelementptr inbounds [2 x i32], ptr %52, i64 0, i64 0
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = load i64, ptr %8, align 8, !tbaa !15
  %56 = trunc i64 %55 to i32
  %57 = icmp ult i32 %54, %56
  br i1 %57, label %58, label %64

58:                                               ; preds = %35
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.Sm3Ctx_st, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds [2 x i32], ptr %60, i64 0, i64 1
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = add i32 %62, 1
  store i32 %63, ptr %61, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %58, %35
  %65 = load i64, ptr %7, align 8, !tbaa !15
  %66 = icmp ne i64 %65, 0
  br i1 %66, label %67, label %89

67:                                               ; preds = %64
  %68 = load i64, ptr %8, align 8, !tbaa !15
  %69 = load i64, ptr %6, align 8, !tbaa !15
  %70 = icmp uge i64 %68, %69
  br i1 %70, label %71, label %89

71:                                               ; preds = %67
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.Sm3Ctx_st, ptr %72, i32 0, i32 2
  %74 = getelementptr inbounds [64 x i8], ptr %73, i64 0, i64 0
  %75 = load i64, ptr %7, align 8, !tbaa !15
  %76 = getelementptr inbounds i8, ptr %74, i64 %75
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load i64, ptr %6, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %76, ptr align 1 %77, i64 %78, i1 false)
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.Sm3Ctx_st, ptr %80, i32 0, i32 2
  %82 = getelementptr inbounds [64 x i8], ptr %81, i64 0, i64 0
  call void @sm3_process(ptr noundef %79, ptr noundef %82)
  %83 = load i64, ptr %6, align 8, !tbaa !15
  %84 = load ptr, ptr %9, align 8, !tbaa !5
  %85 = getelementptr inbounds i8, ptr %84, i64 %83
  store ptr %85, ptr %9, align 8, !tbaa !5
  %86 = load i64, ptr %6, align 8, !tbaa !15
  %87 = load i64, ptr %8, align 8, !tbaa !15
  %88 = sub i64 %87, %86
  store i64 %88, ptr %8, align 8, !tbaa !15
  store i64 0, ptr %7, align 8, !tbaa !15
  br label %89

89:                                               ; preds = %71, %67, %64
  br label %90

90:                                               ; preds = %93, %89
  %91 = load i64, ptr %8, align 8, !tbaa !15
  %92 = icmp uge i64 %91, 64
  br i1 %92, label %93, label %100

93:                                               ; preds = %90
  %94 = load ptr, ptr %3, align 8, !tbaa !5
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  call void @sm3_process(ptr noundef %94, ptr noundef %95)
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  %97 = getelementptr inbounds i8, ptr %96, i64 64
  store ptr %97, ptr %9, align 8, !tbaa !5
  %98 = load i64, ptr %8, align 8, !tbaa !15
  %99 = sub i64 %98, 64
  store i64 %99, ptr %8, align 8, !tbaa !15
  br label %90, !llvm.loop !16

100:                                              ; preds = %90
  %101 = load i64, ptr %8, align 8, !tbaa !15
  %102 = icmp ugt i64 %101, 0
  br i1 %102, label %103, label %111

103:                                              ; preds = %100
  %104 = load ptr, ptr %3, align 8, !tbaa !5
  %105 = getelementptr inbounds %struct.Sm3Ctx_st, ptr %104, i32 0, i32 2
  %106 = getelementptr inbounds [64 x i8], ptr %105, i64 0, i64 0
  %107 = load i64, ptr %7, align 8, !tbaa !15
  %108 = getelementptr inbounds i8, ptr %106, i64 %107
  %109 = load ptr, ptr %9, align 8, !tbaa !5
  %110 = load i64, ptr %8, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %108, ptr align 1 %109, i64 %110, i1 false)
  br label %111

111:                                              ; preds = %103, %100
  br label %112

112:                                              ; preds = %111, %34, %21, %13
  %113 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %113
}

; Function Attrs: nounwind uwtable
declare hidden void @sm3_process(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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, !6, i64 0}
!12 = !{!"ByteArray_st", !6, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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"

@.str = external hidden unnamed_addr constant [13 x i8], align 1

declare void @stacktrace_create(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 3) i32 @sm3_update(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %2
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 217, i32 noundef 2, ptr noundef null) #3
  br label %37

4:                                                ; preds = %2
  %.not47 = icmp eq ptr %1, null
  br i1 %.not47, label %5, label %6

5:                                                ; preds = %4
  tail call void @stacktrace_create(ptr noundef nonnull @.str, i64 noundef 218, i32 noundef 2, ptr noundef null) #3
  br label %37

6:                                                ; preds = %4
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %1, i64 8
  %9 = load i64, ptr %8, align 8, !tbaa !11
  %10 = icmp eq i64 %9, 0
  br i1 %10, label %37, label %11

11:                                               ; preds = %6
  %12 = load i32, ptr %0, align 4, !tbaa !12
  %13 = and i32 %12, 63
  %14 = zext nneg i32 %13 to i64
  %15 = sub nuw nsw i64 64, %14
  %16 = trunc i64 %9 to i32
  %17 = add i32 %12, %16
  store i32 %17, ptr %0, align 4, !tbaa !12
  %18 = icmp ult i32 %17, %16
  br i1 %18, label %19, label %23

19:                                               ; preds = %11
  %20 = getelementptr inbounds i8, ptr %0, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = add i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !12
  br label %23

23:                                               ; preds = %19, %11
  %.not48 = icmp eq i32 %13, 0
  br i1 %.not48, label %30, label %24

24:                                               ; preds = %23
  %.not49 = icmp ult i64 %9, %15
  br i1 %.not49, label %._crit_edge.thread, label %25

25:                                               ; preds = %24
  %26 = getelementptr inbounds i8, ptr %0, i64 40
  %27 = getelementptr inbounds i8, ptr %26, i64 %14
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %27, ptr noundef nonnull align 1 dereferenceable(1) %7, i64 %15, i1 false)
  tail call void @sm3_process(ptr noundef nonnull %0, ptr noundef nonnull %26)
  %28 = getelementptr inbounds i8, ptr %7, i64 %15
  %29 = sub i64 %9, %15
  br label %30

30:                                               ; preds = %25, %23
  %.037 = phi i64 [ %29, %25 ], [ %9, %23 ]
  %.0 = phi ptr [ %28, %25 ], [ %7, %23 ]
  %31 = icmp ugt i64 %.037, 63
  br i1 %31, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %30, %.lr.ph
  %.152 = phi ptr [ %32, %.lr.ph ], [ %.0, %30 ]
  %.13851 = phi i64 [ %33, %.lr.ph ], [ %.037, %30 ]
  tail call void @sm3_process(ptr noundef nonnull %0, ptr noundef %.152)
  %32 = getelementptr inbounds i8, ptr %.152, i64 64
  %33 = add i64 %.13851, -64
  %34 = icmp ugt i64 %33, 63
  br i1 %34, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %30
  %.138.lcssa = phi i64 [ %.037, %30 ], [ %33, %.lr.ph ]
  %.1.lcssa = phi ptr [ %.0, %30 ], [ %32, %.lr.ph ]
  %.not50 = icmp eq i64 %.138.lcssa, 0
  br i1 %.not50, label %37, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %24, %._crit_edge
  %.1.lcssa65 = phi ptr [ %.1.lcssa, %._crit_edge ], [ %7, %24 ]
  %.138.lcssa64 = phi i64 [ %.138.lcssa, %._crit_edge ], [ %9, %24 ]
  %.0395863 = phi i64 [ 0, %._crit_edge ], [ %14, %24 ]
  %35 = getelementptr inbounds i8, ptr %0, i64 40
  %36 = getelementptr inbounds i8, ptr %35, i64 %.0395863
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %36, ptr align 1 %.1.lcssa65, i64 %.138.lcssa64, i1 false)
  br label %37

37:                                               ; preds = %._crit_edge, %._crit_edge.thread, %6, %5, %3
  %.040 = phi i32 [ 0, %6 ], [ 0, %._crit_edge.thread ], [ 0, %._crit_edge ], [ 2, %5 ], [ 2, %3 ]
  ret i32 %.040
}

; Function Attrs: nounwind uwtable
declare hidden void @sm3_process(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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, !7, i64 0}
!6 = !{!"ByteArray_st", !7, i64 0, !10, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass