; LLVM IR from intel/cryptography-primitives :: sources/ippcp/xmss (wots_internal)

; 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.cpWOTSParams = type { i32, i32, i32, i32, i32, ptr }

; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @cp_do_xmss_hash(i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @cp_xmss_prf(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @cp_xmss_chain(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) #1 {
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i8, align 1
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i8, align 1
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  store ptr %0, ptr %10, align 8, !tbaa !5
  store i8 %1, ptr %11, align 1, !tbaa !9
  store i8 %2, ptr %12, align 1, !tbaa !9
  store ptr %3, ptr %13, align 8, !tbaa !5
  store ptr %4, ptr %14, align 8, !tbaa !5
  store ptr %5, ptr %15, align 8, !tbaa !5
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  store i32 0, ptr %18, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %24 = load ptr, ptr %16, align 8, !tbaa !5
  store ptr %24, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #3
  %25 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %25, ptr %20, align 8, !tbaa !5
  %26 = load ptr, ptr %10, align 8, !tbaa !5
  %27 = load ptr, ptr %15, align 8, !tbaa !5
  %28 = load ptr, ptr %17, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.cpWOTSParams, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !12
  call void @CopyBlock(ptr noundef %26, ptr noundef %27, i32 noundef %30)
  call void @llvm.lifetime.start.p0(i64 1, ptr %21) #3
  %31 = load i8, ptr %11, align 1, !tbaa !9
  store i8 %31, ptr %21, align 1, !tbaa !9
  br label %32

32:                                               ; preds = %137, %8
  %33 = load i8, ptr %21, align 1, !tbaa !9
  %34 = zext i8 %33 to i32
  %35 = load i8, ptr %11, align 1, !tbaa !9
  %36 = zext i8 %35 to i32
  %37 = load i8, ptr %12, align 1, !tbaa !9
  %38 = zext i8 %37 to i32
  %39 = add nsw i32 %36, %38
  %40 = icmp slt i32 %34, %39
  br i1 %40, label %41, label %48

41:                                               ; preds = %32
  %42 = load i8, ptr %21, align 1, !tbaa !9
  %43 = zext i8 %42 to i32
  %44 = load ptr, ptr %17, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.cpWOTSParams, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !14
  %47 = icmp ult i32 %43, %46
  br label %48

48:                                               ; preds = %41, %32
  %49 = phi i1 [ false, %32 ], [ %47, %41 ]
  br i1 %49, label %51, label %50

50:                                               ; preds = %48
  store i32 2, ptr %22, align 4
  br label %140

51:                                               ; preds = %48
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = load i8, ptr %21, align 1, !tbaa !9
  call void @cp_xmss_set_hash_address(ptr noundef %52, i8 noundef zeroext %53)
  %54 = load ptr, ptr %14, align 8, !tbaa !5
  call void @cp_xmss_set_key_and_mask(ptr noundef %54, i8 noundef zeroext 1)
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = load ptr, ptr %19, align 8, !tbaa !5
  %58 = load ptr, ptr %16, align 8, !tbaa !5
  %59 = load ptr, ptr %17, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.cpWOTSParams, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !12
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds i8, ptr %58, i64 %62
  %64 = load ptr, ptr %17, align 8, !tbaa !5
  %65 = call i32 @cp_xmss_prf(ptr noundef %55, ptr noundef %56, ptr noundef %57, ptr noundef %63, ptr noundef %64)
  store i32 %65, ptr %18, align 4, !tbaa !10
  %66 = load i32, ptr %18, align 4, !tbaa !10
  %67 = icmp ne i32 0, %66
  br i1 %67, label %68, label %70

68:                                               ; preds = %51
  %69 = load i32, ptr %18, align 4, !tbaa !10
  store i32 %69, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %140

70:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #3
  store i32 0, ptr %23, align 4, !tbaa !10
  br label %71

71:                                               ; preds = %97, %70
  %72 = load i32, ptr %23, align 4, !tbaa !10
  %73 = load ptr, ptr %17, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.cpWOTSParams, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !12
  %76 = icmp slt i32 %72, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %71
  store i32 5, ptr %22, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #3
  br label %100

78:                                               ; preds = %71
  %79 = load ptr, ptr %15, align 8, !tbaa !5
  %80 = load i32, ptr %23, align 4, !tbaa !10
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds i8, ptr %79, i64 %81
  %83 = load i8, ptr %82, align 1, !tbaa !9
  %84 = zext i8 %83 to i32
  %85 = load ptr, ptr %19, align 8, !tbaa !5
  %86 = load i32, ptr %23, align 4, !tbaa !10
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds i8, ptr %85, i64 %87
  %89 = load i8, ptr %88, align 1, !tbaa !9
  %90 = zext i8 %89 to i32
  %91 = xor i32 %84, %90
  %92 = trunc i32 %91 to i8
  %93 = load ptr, ptr %15, align 8, !tbaa !5
  %94 = load i32, ptr %23, align 4, !tbaa !10
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds i8, ptr %93, i64 %95
  store i8 %92, ptr %96, align 1, !tbaa !9
  br label %97

97:                                               ; preds = %78
  %98 = load i32, ptr %23, align 4, !tbaa !10
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %23, align 4, !tbaa !10
  br label %71, !llvm.loop !15

100:                                              ; preds = %77
  %101 = load ptr, ptr %14, align 8, !tbaa !5
  call void @cp_xmss_set_key_and_mask(ptr noundef %101, i8 noundef zeroext 0)
  %102 = load ptr, ptr %13, align 8, !tbaa !5
  %103 = load ptr, ptr %14, align 8, !tbaa !5
  %104 = load ptr, ptr %20, align 8, !tbaa !5
  %105 = load ptr, ptr %16, align 8, !tbaa !5
  %106 = load ptr, ptr %17, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.cpWOTSParams, ptr %106, i32 0, i32 0
  %108 = load i32, ptr %107, align 8, !tbaa !12
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds i8, ptr %105, i64 %109
  %111 = load ptr, ptr %17, align 8, !tbaa !5
  %112 = call i32 @cp_xmss_prf(ptr noundef %102, ptr noundef %103, ptr noundef %104, ptr noundef %110, ptr noundef %111)
  store i32 %112, ptr %18, align 4, !tbaa !10
  %113 = load i32, ptr %18, align 4, !tbaa !10
  %114 = icmp ne i32 0, %113
  br i1 %114, label %115, label %117

115:                                              ; preds = %100
  %116 = load i32, ptr %18, align 4, !tbaa !10
  store i32 %116, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %140

117:                                              ; preds = %100
  %118 = load ptr, ptr %20, align 8, !tbaa !5
  %119 = load ptr, ptr %15, align 8, !tbaa !5
  %120 = load ptr, ptr %17, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.cpWOTSParams, ptr %120, i32 0, i32 0
  %122 = load i32, ptr %121, align 8, !tbaa !12
  %123 = load ptr, ptr %15, align 8, !tbaa !5
  %124 = load ptr, ptr %16, align 8, !tbaa !5
  %125 = load ptr, ptr %17, align 8, !tbaa !5
  %126 = getelementptr inbounds %struct.cpWOTSParams, ptr %125, i32 0, i32 0
  %127 = load i32, ptr %126, align 8, !tbaa !12
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds i8, ptr %124, i64 %128
  %130 = load ptr, ptr %17, align 8, !tbaa !5
  %131 = call i32 @cp_do_xmss_hash(i32 noundef 0, ptr noundef %118, ptr noundef %119, i32 noundef %122, ptr noundef %123, ptr noundef %129, ptr noundef %130)
  store i32 %131, ptr %18, align 4, !tbaa !10
  %132 = load i32, ptr %18, align 4, !tbaa !10
  %133 = icmp ne i32 0, %132
  br i1 %133, label %134, label %136

134:                                              ; preds = %117
  %135 = load i32, ptr %18, align 4, !tbaa !10
  store i32 %135, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %140

136:                                              ; preds = %117
  br label %137

137:                                              ; preds = %136
  %138 = load i8, ptr %21, align 1, !tbaa !9
  %139 = add i8 %138, 1
  store i8 %139, ptr %21, align 1, !tbaa !9
  br label %32, !llvm.loop !17

140:                                              ; preds = %134, %115, %68, %50
  call void @llvm.lifetime.end.p0(i64 1, ptr %21) #3
  %141 = load i32, ptr %22, align 4
  switch i32 %141, label %144 [
    i32 2, label %142
  ]

142:                                              ; preds = %140
  %143 = load i32, ptr %18, align 4, !tbaa !10
  store i32 %143, ptr %9, align 4
  store i32 1, ptr %22, align 4
  br label %144

144:                                              ; preds = %142, %140
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  %145 = load i32, ptr %9, align 4
  ret i32 %145
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cp_xmss_set_hash_address(ptr noundef, i8 noundef zeroext) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cp_xmss_set_key_and_mask(ptr noundef, i8 noundef zeroext) #2

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


; 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: nounwind uwtable
declare dso_local i32 @cp_do_xmss_hash(i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @CopyBlock(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @cp_xmss_prf(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @cp_xmss_chain(ptr noundef %0, i8 noundef zeroext %1, i8 noundef zeroext %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) local_unnamed_addr #0 {
  %9 = load i32, ptr %7, align 8, !tbaa !5
  tail call void @CopyBlock(ptr noundef %0, ptr noundef %5, i32 noundef %9)
  %10 = getelementptr inbounds i8, ptr %7, i64 4
  %11 = zext i8 %1 to i32
  %12 = zext i8 %2 to i32
  %13 = add nuw nsw i32 %12, %11
  %.not80 = icmp eq i8 %2, 0
  br i1 %.not80, label %.critedge, label %.lr.ph70

14:                                               ; preds = %40
  %15 = add i8 %.05368, 1
  %16 = zext i8 %15 to i32
  %17 = icmp ugt i32 %13, %16
  br i1 %17, label %.lr.ph70, label %.critedge, !llvm.loop !11

.lr.ph70:                                         ; preds = %8, %14
  %18 = phi i32 [ %16, %14 ], [ %11, %8 ]
  %.05368 = phi i8 [ %15, %14 ], [ %1, %8 ]
  %19 = load i32, ptr %10, align 4, !tbaa !13
  %20 = icmp ugt i32 %19, %18
  br i1 %20, label %21, label %.critedge

21:                                               ; preds = %.lr.ph70
  tail call void @cp_xmss_set_hash_address(ptr noundef %4, i8 noundef zeroext %.05368)
  tail call void @cp_xmss_set_key_and_mask(ptr noundef %4, i8 noundef zeroext 1)
  %22 = load i32, ptr %7, align 8, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %6, i64 %23
  %25 = tail call i32 @cp_xmss_prf(ptr noundef %3, ptr noundef %4, ptr noundef %6, ptr noundef %24, ptr noundef nonnull %7)
  %.not = icmp eq i32 %25, 0
  br i1 %.not, label %.preheader, label %.critedge

.preheader:                                       ; preds = %21
  %26 = load i32, ptr %7, align 8, !tbaa !5
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  tail call void @cp_xmss_set_key_and_mask(ptr noundef %4, i8 noundef zeroext 0)
  %28 = load i32, ptr %7, align 8, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %6, i64 %29
  %31 = tail call i32 @cp_xmss_prf(ptr noundef %3, ptr noundef %4, ptr noundef %6, ptr noundef %30, ptr noundef nonnull %7)
  %.not62 = icmp eq i32 %31, 0
  br i1 %.not62, label %40, label %.critedge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %32 = getelementptr inbounds i8, ptr %5, i64 %indvars.iv
  %33 = load i8, ptr %32, align 1, !tbaa !14
  %34 = getelementptr inbounds i8, ptr %6, i64 %indvars.iv
  %35 = load i8, ptr %34, align 1, !tbaa !14
  %36 = xor i8 %35, %33
  store i8 %36, ptr %32, align 1, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = load i32, ptr %7, align 8, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = icmp slt i64 %indvars.iv.next, %38
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !15

40:                                               ; preds = %._crit_edge
  %41 = load i32, ptr %7, align 8, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i8, ptr %6, i64 %42
  %44 = tail call i32 @cp_do_xmss_hash(i32 noundef 0, ptr noundef %6, ptr noundef %5, i32 noundef %41, ptr noundef %5, ptr noundef %43, ptr noundef nonnull %7)
  %.not63 = icmp eq i32 %44, 0
  br i1 %.not63, label %14, label %.critedge

.critedge:                                        ; preds = %14, %.lr.ph70, %21, %._crit_edge, %40, %8
  %45 = phi i32 [ 0, %8 ], [ %44, %40 ], [ %31, %._crit_edge ], [ %25, %21 ], [ 0, %.lr.ph70 ], [ 0, %14 ]
  ret i32 %45
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cp_xmss_set_hash_address(ptr noundef, i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cp_xmss_set_key_and_mask(ptr noundef, i8 noundef zeroext) local_unnamed_addr #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 = { inlinehint 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" }

!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 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 4}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass