; LLVM IR from sgtlaugh/algovault :: code_library/walsh_hadamard.ll (ZN4fwht15walsh_transformEPxii)

; 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: mustprogress uwtable
define dso_local void @_ZN4fwht15walsh_transformEPxii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %14, label %13

13:                                               ; preds = %3
  br label %104

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = ashr i32 %15, 1
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN4fwht15walsh_transformEPxii(ptr noundef %17, i32 noundef %18, i32 noundef %19)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i64, ptr %20, i64 %22
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  call void @_ZN4fwht15walsh_transformEPxii(ptr noundef %23, i32 noundef %24, i32 noundef %25)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %100, %14
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = load i32, ptr %7, align 4, !tbaa !9
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %103

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i64, ptr %32, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !11
  store i64 %36, ptr %9, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = load i32, ptr %7, align 4, !tbaa !9
  %40 = add nsw i32 %38, %39
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i64, ptr %37, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !11
  store i64 %43, ptr %10, align 8, !tbaa !11
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %61

46:                                               ; preds = %31
  %47 = load i64, ptr %9, align 8, !tbaa !11
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i64, ptr %48, i64 %50
  store i64 %47, ptr %51, align 8, !tbaa !11
  %52 = load i64, ptr %9, align 8, !tbaa !11
  %53 = load i64, ptr %10, align 8, !tbaa !11
  %54 = add nsw i64 %52, %53
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = add nsw i32 %56, %57
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i64, ptr %55, i64 %59
  store i64 %54, ptr %60, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %46, %31
  %62 = load i32, ptr %6, align 4, !tbaa !9
  %63 = icmp eq i32 %62, 1
  br i1 %63, label %64, label %79

64:                                               ; preds = %61
  %65 = load i64, ptr %9, align 8, !tbaa !11
  %66 = load i64, ptr %10, align 8, !tbaa !11
  %67 = add nsw i64 %65, %66
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = load i32, ptr %8, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i64, ptr %68, i64 %70
  store i64 %67, ptr %71, align 8, !tbaa !11
  %72 = load i64, ptr %10, align 8, !tbaa !11
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = load i32, ptr %8, align 4, !tbaa !9
  %75 = load i32, ptr %7, align 4, !tbaa !9
  %76 = add nsw i32 %74, %75
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i64, ptr %73, i64 %77
  store i64 %72, ptr %78, align 8, !tbaa !11
  br label %79

79:                                               ; preds = %64, %61
  %80 = load i32, ptr %6, align 4, !tbaa !9
  %81 = icmp eq i32 %80, 2
  br i1 %81, label %82, label %99

82:                                               ; preds = %79
  %83 = load i64, ptr %9, align 8, !tbaa !11
  %84 = load i64, ptr %10, align 8, !tbaa !11
  %85 = add nsw i64 %83, %84
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load i32, ptr %8, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds i64, ptr %86, i64 %88
  store i64 %85, ptr %89, align 8, !tbaa !11
  %90 = load i64, ptr %9, align 8, !tbaa !11
  %91 = load i64, ptr %10, align 8, !tbaa !11
  %92 = sub nsw i64 %90, %91
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = load i32, ptr %8, align 4, !tbaa !9
  %95 = load i32, ptr %7, align 4, !tbaa !9
  %96 = add nsw i32 %94, %95
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds i64, ptr %93, i64 %97
  store i64 %92, ptr %98, align 8, !tbaa !11
  br label %99

99:                                               ; preds = %82, %79
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  br label %100

100:                                              ; preds = %99
  %101 = load i32, ptr %8, align 4, !tbaa !9
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr %8, align 4, !tbaa !9
  br label %26, !llvm.loop !13

103:                                              ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %104

104:                                              ; preds = %103, %13
  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 = { mustprogress 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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: mustprogress nofree nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN4fwht15walsh_transformEPxii(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.loopexit, label %4

4:                                                ; preds = %3
  %5 = ashr i32 %1, 1
  tail call void @_ZN4fwht15walsh_transformEPxii(ptr noundef %0, i32 noundef %5, i32 noundef %2)
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds i64, ptr %0, i64 %6
  tail call void @_ZN4fwht15walsh_transformEPxii(ptr noundef %7, i32 noundef %5, i32 noundef %2)
  %8 = icmp sgt i32 %5, 0
  br i1 %8, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %4
  switch i32 %2, label %.loopexit [
    i32 0, label %.lr.ph.split.us.preheader
    i32 1, label %.lr.ph.split.us47.preheader
    i32 2, label %.lr.ph.split.us49.preheader
  ]

.lr.ph.split.us49.preheader:                      ; preds = %.lr.ph
  %9 = zext nneg i32 %5 to i64
  %invariant.gep = getelementptr inbounds i64, ptr %0, i64 %9
  %min.iters.check = icmp ult i32 %5, 4
  br i1 %min.iters.check, label %.lr.ph.split.us49.preheader109, label %vector.ph

.lr.ph.split.us49.preheader109:                   ; preds = %middle.block, %.lr.ph.split.us49.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.split.us49.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.split.us49

vector.ph:                                        ; preds = %.lr.ph.split.us49.preheader
  %n.vec = and i64 %9, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %10 = getelementptr inbounds i64, ptr %0, i64 %index
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %wide.load = load <2 x i64>, ptr %10, align 8, !tbaa !5
  %wide.load73 = load <2 x i64>, ptr %11, align 8, !tbaa !5
  %12 = getelementptr inbounds i64, ptr %invariant.gep, i64 %index
  %13 = getelementptr inbounds i8, ptr %12, i64 16
  %wide.load74 = load <2 x i64>, ptr %12, align 8, !tbaa !5
  %wide.load75 = load <2 x i64>, ptr %13, align 8, !tbaa !5
  %14 = add nsw <2 x i64> %wide.load74, %wide.load
  %15 = add nsw <2 x i64> %wide.load75, %wide.load73
  store <2 x i64> %14, ptr %10, align 8, !tbaa !5
  store <2 x i64> %15, ptr %11, align 8, !tbaa !5
  %16 = sub nsw <2 x i64> %wide.load, %wide.load74
  %17 = sub nsw <2 x i64> %wide.load73, %wide.load75
  store <2 x i64> %16, ptr %12, align 8, !tbaa !5
  store <2 x i64> %17, ptr %13, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %18 = icmp eq i64 %index.next, %n.vec
  br i1 %18, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %9
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.split.us49.preheader109

.lr.ph.split.us47.preheader:                      ; preds = %.lr.ph
  %19 = zext nneg i32 %5 to i64
  %invariant.gep67 = getelementptr inbounds i64, ptr %0, i64 %19
  %min.iters.check78 = icmp ult i32 %5, 4
  br i1 %min.iters.check78, label %.lr.ph.split.us47.preheader107, label %vector.ph79

.lr.ph.split.us47.preheader107:                   ; preds = %middle.block76, %.lr.ph.split.us47.preheader
  %indvars.iv55.ph = phi i64 [ 0, %.lr.ph.split.us47.preheader ], [ %n.vec81, %middle.block76 ]
  br label %.lr.ph.split.us47

vector.ph79:                                      ; preds = %.lr.ph.split.us47.preheader
  %n.vec81 = and i64 %19, 2147483644
  br label %vector.body83

vector.body83:                                    ; preds = %vector.body83, %vector.ph79
  %index84 = phi i64 [ 0, %vector.ph79 ], [ %index.next89, %vector.body83 ]
  %20 = getelementptr inbounds i64, ptr %0, i64 %index84
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  %wide.load85 = load <2 x i64>, ptr %20, align 8, !tbaa !5
  %wide.load86 = load <2 x i64>, ptr %21, align 8, !tbaa !5
  %22 = getelementptr inbounds i64, ptr %invariant.gep67, i64 %index84
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %wide.load87 = load <2 x i64>, ptr %22, align 8, !tbaa !5
  %wide.load88 = load <2 x i64>, ptr %23, align 8, !tbaa !5
  %24 = add nsw <2 x i64> %wide.load87, %wide.load85
  %25 = add nsw <2 x i64> %wide.load88, %wide.load86
  store <2 x i64> %24, ptr %20, align 8, !tbaa !5
  store <2 x i64> %25, ptr %21, align 8, !tbaa !5
  store <2 x i64> %wide.load87, ptr %22, align 8, !tbaa !5
  store <2 x i64> %wide.load88, ptr %23, align 8, !tbaa !5
  %index.next89 = add nuw i64 %index84, 4
  %26 = icmp eq i64 %index.next89, %n.vec81
  br i1 %26, label %middle.block76, label %vector.body83, !llvm.loop !13

middle.block76:                                   ; preds = %vector.body83
  %cmp.n90 = icmp eq i64 %n.vec81, %19
  br i1 %cmp.n90, label %.loopexit, label %.lr.ph.split.us47.preheader107

.lr.ph.split.us.preheader:                        ; preds = %.lr.ph
  %27 = zext nneg i32 %5 to i64
  %invariant.gep69 = getelementptr inbounds i64, ptr %0, i64 %27
  %min.iters.check93 = icmp ult i32 %5, 4
  br i1 %min.iters.check93, label %.lr.ph.split.us.preheader106, label %vector.ph94

vector.ph94:                                      ; preds = %.lr.ph.split.us.preheader
  %n.vec96 = and i64 %27, 2147483644
  br label %vector.body98

vector.body98:                                    ; preds = %vector.body98, %vector.ph94
  %index99 = phi i64 [ 0, %vector.ph94 ], [ %index.next104, %vector.body98 ]
  %28 = getelementptr inbounds i64, ptr %0, i64 %index99
  %29 = getelementptr inbounds i8, ptr %28, i64 16
  %wide.load100 = load <2 x i64>, ptr %28, align 8, !tbaa !5
  %wide.load101 = load <2 x i64>, ptr %29, align 8, !tbaa !5
  %30 = getelementptr inbounds i64, ptr %invariant.gep69, i64 %index99
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  %wide.load102 = load <2 x i64>, ptr %30, align 8, !tbaa !5
  %wide.load103 = load <2 x i64>, ptr %31, align 8, !tbaa !5
  %32 = add nsw <2 x i64> %wide.load102, %wide.load100
  %33 = add nsw <2 x i64> %wide.load103, %wide.load101
  store <2 x i64> %32, ptr %30, align 8, !tbaa !5
  store <2 x i64> %33, ptr %31, align 8, !tbaa !5
  %index.next104 = add nuw i64 %index99, 4
  %34 = icmp eq i64 %index.next104, %n.vec96
  br i1 %34, label %middle.block91, label %vector.body98, !llvm.loop !14

middle.block91:                                   ; preds = %vector.body98
  %cmp.n105 = icmp eq i64 %n.vec96, %27
  br i1 %cmp.n105, label %.loopexit, label %.lr.ph.split.us.preheader106

.lr.ph.split.us.preheader106:                     ; preds = %middle.block91, %.lr.ph.split.us.preheader
  %indvars.iv60.ph = phi i64 [ 0, %.lr.ph.split.us.preheader ], [ %n.vec96, %middle.block91 ]
  br label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph.split.us.preheader106, %.lr.ph.split.us
  %indvars.iv60 = phi i64 [ %indvars.iv.next61, %.lr.ph.split.us ], [ %indvars.iv60.ph, %.lr.ph.split.us.preheader106 ]
  %35 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv60
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %gep70 = getelementptr inbounds i64, ptr %invariant.gep69, i64 %indvars.iv60
  %37 = load i64, ptr %gep70, align 8, !tbaa !5
  %38 = add nsw i64 %37, %36
  store i64 %38, ptr %gep70, align 8, !tbaa !5
  %indvars.iv.next61 = add nuw nsw i64 %indvars.iv60, 1
  %exitcond64.not = icmp eq i64 %indvars.iv.next61, %27
  br i1 %exitcond64.not, label %.loopexit, label %.lr.ph.split.us, !llvm.loop !15

.lr.ph.split.us47:                                ; preds = %.lr.ph.split.us47.preheader107, %.lr.ph.split.us47
  %indvars.iv55 = phi i64 [ %indvars.iv.next56, %.lr.ph.split.us47 ], [ %indvars.iv55.ph, %.lr.ph.split.us47.preheader107 ]
  %39 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv55
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %gep68 = getelementptr inbounds i64, ptr %invariant.gep67, i64 %indvars.iv55
  %41 = load i64, ptr %gep68, align 8, !tbaa !5
  %42 = add nsw i64 %41, %40
  store i64 %42, ptr %39, align 8, !tbaa !5
  store i64 %41, ptr %gep68, align 8, !tbaa !5
  %indvars.iv.next56 = add nuw nsw i64 %indvars.iv55, 1
  %exitcond59.not = icmp eq i64 %indvars.iv.next56, %19
  br i1 %exitcond59.not, label %.loopexit, label %.lr.ph.split.us47, !llvm.loop !16

.lr.ph.split.us49:                                ; preds = %.lr.ph.split.us49.preheader109, %.lr.ph.split.us49
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph.split.us49 ], [ %indvars.iv.ph, %.lr.ph.split.us49.preheader109 ]
  %43 = getelementptr inbounds i64, ptr %0, i64 %indvars.iv
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %gep = getelementptr inbounds i64, ptr %invariant.gep, i64 %indvars.iv
  %45 = load i64, ptr %gep, align 8, !tbaa !5
  %46 = add nsw i64 %45, %44
  store i64 %46, ptr %43, align 8, !tbaa !5
  %47 = sub nsw i64 %44, %45
  store i64 %47, ptr %gep, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %9
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph.split.us49, !llvm.loop !17

.loopexit:                                        ; preds = %.lr.ph.split.us49, %.lr.ph.split.us47, %.lr.ph.split.us, %middle.block, %middle.block76, %middle.block91, %.lr.ph, %4, %3
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(argmem: readwrite) 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 long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11, !12}
!14 = distinct !{!14, !10, !11, !12}
!15 = distinct !{!15, !10, !12, !11}
!16 = distinct !{!16, !10, !12, !11}
!17 = distinct !{!17, !10, !12, !11}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass