; 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: inlinehint nounwind uwtable
declare hidden void @cp_to_byte(ptr noundef, i32 noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @cp_xmss_chain(ptr noundef, i8 noundef zeroext, i8 noundef zeroext, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

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

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

32:                                               ; preds = %85, %6
  %33 = load i32, ptr %19, align 4, !tbaa !9
  %34 = load i32, ptr %16, align 4, !tbaa !9
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %32
  store i32 2, ptr %20, align 4
  br label %88

37:                                               ; preds = %32
  %38 = load ptr, ptr %18, align 8, !tbaa !5
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = load i32, ptr %19, align 4, !tbaa !9
  call void @cp_to_byte(ptr noundef %38, i32 noundef %39, i32 noundef %40)
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %18, align 8, !tbaa !5
  %43 = load ptr, ptr %17, align 8, !tbaa !5
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load i32, ptr %15, align 4, !tbaa !9
  %46 = mul nsw i32 2, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i8, ptr %44, i64 %47
  %49 = load ptr, ptr %13, align 8, !tbaa !5
  %50 = call i32 @cp_xmss_prf(ptr noundef %41, ptr noundef %42, ptr noundef %43, ptr noundef %48, ptr noundef %49)
  store i32 %50, ptr %14, align 4, !tbaa !9
  %51 = load i32, ptr %14, align 4, !tbaa !9
  %52 = icmp ne i32 0, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %37
  %54 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %54, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %88

55:                                               ; preds = %37
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i32, ptr %19, align 4, !tbaa !9
  %58 = trunc i32 %57 to i8
  call void @cp_xmss_set_chain_address(ptr noundef %56, i8 noundef zeroext %58)
  %59 = load ptr, ptr %17, align 8, !tbaa !5
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.cpWOTSParams, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 4, !tbaa !14
  %63 = sub i32 %62, 1
  %64 = trunc i32 %63 to i8
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = load ptr, ptr %11, align 8, !tbaa !5
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load i32, ptr %19, align 4, !tbaa !9
  %69 = load i32, ptr %15, align 4, !tbaa !9
  %70 = mul nsw i32 %68, %69
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds i8, ptr %67, i64 %71
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = load i32, ptr %15, align 4, !tbaa !9
  %75 = mul nsw i32 2, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %73, i64 %76
  %78 = load ptr, ptr %13, align 8, !tbaa !5
  %79 = call i32 @cp_xmss_chain(ptr noundef %59, i8 noundef zeroext 0, i8 noundef zeroext %64, ptr noundef %65, ptr noundef %66, ptr noundef %72, ptr noundef %77, ptr noundef %78)
  store i32 %79, ptr %14, align 4, !tbaa !9
  %80 = load i32, ptr %14, align 4, !tbaa !9
  %81 = icmp ne i32 0, %80
  br i1 %81, label %82, label %84

82:                                               ; preds = %55
  %83 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %83, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %88

84:                                               ; preds = %55
  br label %85

85:                                               ; preds = %84
  %86 = load i32, ptr %19, align 4, !tbaa !9
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %19, align 4, !tbaa !9
  br label %32, !llvm.loop !15

88:                                               ; preds = %82, %53, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  %89 = load i32, ptr %20, align 4
  switch i32 %89, label %93 [
    i32 2, label %90
  ]

90:                                               ; preds = %88
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  call void @cp_xmss_set_chain_address(ptr noundef %91, i8 noundef zeroext 0)
  %92 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %92, ptr %7, align 4
  store i32 1, ptr %20, align 4
  br label %93

93:                                               ; preds = %90, %88
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  %94 = load i32, ptr %7, align 4
  ret i32 %94
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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, !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, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24}
!13 = !{!12, !10, i64 12}
!14 = !{!12, !10, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"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"

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @cp_xmss_chain(ptr noundef, i8 noundef zeroext, i8 noundef zeroext, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @cp_xmss_WOTS_genPK(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #1 {
  %7 = load i32, ptr %5, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %5, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = sext i32 %7 to i64
  %11 = getelementptr inbounds i8, ptr %4, i64 %10
  %.not4447 = icmp sgt i32 %9, 0
  br i1 %.not4447, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %6
  %12 = shl nsw i32 %7, 1
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %4, i64 %13
  %15 = getelementptr inbounds i8, ptr %5, i64 4
  %wide.trip.count = zext nneg i32 %9 to i64
  br label %17

16:                                               ; preds = %20
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %17, !llvm.loop !12

17:                                               ; preds = %.lr.ph, %16
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %18 = trunc nuw nsw i64 %indvars.iv to i32
  tail call void @cp_to_byte(ptr noundef %11, i32 noundef %7, i32 noundef %18)
  %19 = tail call i32 @cp_xmss_prf(ptr noundef %0, ptr noundef %11, ptr noundef %4, ptr noundef %14, ptr noundef nonnull %5)
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %20, label %.thread

20:                                               ; preds = %17
  %21 = trunc i64 %indvars.iv to i8
  tail call void @cp_xmss_set_chain_address(ptr noundef %3, i8 noundef zeroext %21)
  %22 = load i32, ptr %15, align 4, !tbaa !14
  %23 = trunc i32 %22 to i8
  %24 = add i8 %23, -1
  %25 = mul nsw i64 %indvars.iv, %10
  %26 = getelementptr inbounds i8, ptr %1, i64 %25
  %27 = tail call i32 @cp_xmss_chain(ptr noundef %4, i8 noundef zeroext 0, i8 noundef zeroext %24, ptr noundef %2, ptr noundef %3, ptr noundef %26, ptr noundef %14, ptr noundef nonnull %5)
  %.not43 = icmp eq i32 %27, 0
  br i1 %.not43, label %16, label %.thread

._crit_edge:                                      ; preds = %16, %6
  tail call void @cp_xmss_set_chain_address(ptr noundef %3, i8 noundef zeroext 0)
  br label %.thread

.thread:                                          ; preds = %17, %20, %._crit_edge
  %.1 = phi i32 [ 0, %._crit_edge ], [ %19, %17 ], [ %27, %20 ]
  ret i32 %.1
}

attributes #0 = { 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 #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" }

!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 = !{!6, !7, i64 12}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!6, !7, i64 4}


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