; LLVM IR from CLASS-SZ/class_sz :: class-sz/tools (r8lib)

; 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: 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @r8mat_kronecker(i32 noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %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 i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #3
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = mul nsw i32 %24, %25
  store i32 %26, ptr %22, align 4, !tbaa !5
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !5
  %29 = mul nsw i32 %27, %28
  store i32 %29, ptr %23, align 4, !tbaa !5
  %30 = load i32, ptr %22, align 4, !tbaa !5
  %31 = load i32, ptr %23, align 4, !tbaa !5
  %32 = mul nsw i32 %30, %31
  %33 = sext i32 %32 to i64
  %34 = mul i64 %33, 8
  %35 = call noalias ptr @malloc(i64 noundef %34) #4
  store ptr %35, ptr %13, align 8, !tbaa !9
  store i32 0, ptr %20, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %107, %6
  %37 = load i32, ptr %20, align 4, !tbaa !5
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %110

40:                                               ; preds = %36
  store i32 0, ptr %16, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %103, %40
  %42 = load i32, ptr %16, align 4, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %45, label %106

45:                                               ; preds = %41
  %46 = load i32, ptr %16, align 4, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = mul nsw i32 %46, %47
  store i32 %48, ptr %15, align 4, !tbaa !5
  %49 = load i32, ptr %20, align 4, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = mul nsw i32 %49, %50
  store i32 %51, ptr %19, align 4, !tbaa !5
  %52 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %52, ptr %18, align 4, !tbaa !5
  store i32 0, ptr %21, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %99, %45
  %54 = load i32, ptr %21, align 4, !tbaa !5
  %55 = load i32, ptr %11, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %102

57:                                               ; preds = %53
  %58 = load i32, ptr %15, align 4, !tbaa !5
  store i32 %58, ptr %14, align 4, !tbaa !5
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %93, %57
  %60 = load i32, ptr %17, align 4, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %63, label %96

63:                                               ; preds = %59
  %64 = load ptr, ptr %9, align 8, !tbaa !9
  %65 = load i32, ptr %16, align 4, !tbaa !5
  %66 = load i32, ptr %20, align 4, !tbaa !5
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = mul nsw i32 %66, %67
  %69 = add nsw i32 %65, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds double, ptr %64, i64 %70
  %72 = load double, ptr %71, align 8, !tbaa !11
  %73 = load ptr, ptr %12, align 8, !tbaa !9
  %74 = load i32, ptr %17, align 4, !tbaa !5
  %75 = load i32, ptr %21, align 4, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !5
  %77 = mul nsw i32 %75, %76
  %78 = add nsw i32 %74, %77
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds double, ptr %73, i64 %79
  %81 = load double, ptr %80, align 8, !tbaa !11
  %82 = fmul double %72, %81
  %83 = load ptr, ptr %13, align 8, !tbaa !9
  %84 = load i32, ptr %14, align 4, !tbaa !5
  %85 = load i32, ptr %18, align 4, !tbaa !5
  %86 = load i32, ptr %22, align 4, !tbaa !5
  %87 = mul nsw i32 %85, %86
  %88 = add nsw i32 %84, %87
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds double, ptr %83, i64 %89
  store double %82, ptr %90, align 8, !tbaa !11
  %91 = load i32, ptr %14, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr %14, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %63
  %94 = load i32, ptr %17, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %17, align 4, !tbaa !5
  br label %59, !llvm.loop !13

96:                                               ; preds = %59
  %97 = load i32, ptr %18, align 4, !tbaa !5
  %98 = add nsw i32 %97, 1
  store i32 %98, ptr %18, align 4, !tbaa !5
  br label %99

99:                                               ; preds = %96
  %100 = load i32, ptr %21, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %21, align 4, !tbaa !5
  br label %53, !llvm.loop !15

102:                                              ; preds = %53
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %16, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %16, align 4, !tbaa !5
  br label %41, !llvm.loop !16

106:                                              ; preds = %41
  br label %107

107:                                              ; preds = %106
  %108 = load i32, ptr %20, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %20, align 4, !tbaa !5
  br label %36, !llvm.loop !17

110:                                              ; preds = %36
  %111 = load ptr, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, 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
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  ret ptr %111
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 }
attributes #4 = { nounwind allocsize(0) }

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


; 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 nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind memory(write, argmem: read, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @r8mat_kronecker(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, i32 noundef %3, i32 noundef %4, ptr nocapture noundef readonly %5) local_unnamed_addr #1 {
  %7 = mul nsw i32 %3, %0
  %8 = mul nsw i32 %4, %1
  %9 = mul nsw i32 %8, %7
  %10 = sext i32 %9 to i64
  %11 = shl nsw i64 %10, 3
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #2
  %13 = icmp sgt i32 %1, 0
  br i1 %13, label %.preheader45.lr.ph, label %._crit_edge58

.preheader45.lr.ph:                               ; preds = %6
  %14 = icmp slt i32 %0, 1
  %15 = icmp slt i32 %3, 1
  %16 = icmp slt i32 %4, 1
  %or.cond.not103 = or i1 %14, %16
  %brmerge = or i1 %or.cond.not103, %15
  br i1 %brmerge, label %._crit_edge58, label %.preheader45.us.us.us.preheader

.preheader45.us.us.us.preheader:                  ; preds = %.preheader45.lr.ph
  %17 = zext nneg i32 %3 to i64
  %18 = zext nneg i32 %7 to i64
  %19 = zext nneg i32 %0 to i64
  %wide.trip.count95 = zext nneg i32 %1 to i64
  %wide.trip.count85 = zext nneg i32 %4 to i64
  %min.iters.check = icmp ult i32 %3, 4
  %n.vec = and i64 %17, 2147483644
  %cmp.n = icmp eq i64 %n.vec, %17
  br label %.preheader45.us.us.us

.preheader45.us.us.us:                            ; preds = %.preheader45.us.us.us.preheader, %._crit_edge.split.us.split.us.us.us.us
  %indvars.iv92 = phi i64 [ 0, %.preheader45.us.us.us.preheader ], [ %indvars.iv.next93, %._crit_edge.split.us.split.us.us.us.us ]
  %indvars.iv78 = phi i32 [ 0, %.preheader45.us.us.us.preheader ], [ %indvars.iv.next79, %._crit_edge.split.us.split.us.us.us.us ]
  %20 = zext i32 %indvars.iv78 to i64
  %21 = mul nuw nsw i64 %indvars.iv92, %19
  %invariant.gep99 = getelementptr inbounds double, ptr %2, i64 %21
  br label %.preheader.lr.ph.us.us.us.us.us

.preheader.lr.ph.us.us.us.us.us:                  ; preds = %._crit_edge50.split.us.us.us.us.us.us, %.preheader45.us.us.us
  %indvars.iv87 = phi i64 [ %indvars.iv.next88, %._crit_edge50.split.us.us.us.us.us.us ], [ 0, %.preheader45.us.us.us ]
  %indvars.iv = phi i32 [ %indvars.iv.next, %._crit_edge50.split.us.us.us.us.us.us ], [ 0, %.preheader45.us.us.us ]
  %22 = zext i32 %indvars.iv to i64
  %gep100 = getelementptr inbounds double, ptr %invariant.gep99, i64 %indvars.iv87
  %23 = load double, ptr %gep100, align 8, !tbaa !5
  %ind.end = add nuw nsw i64 %n.vec, %22
  %broadcast.splatinsert = insertelement <2 x double> poison, double %23, i64 0
  %broadcast.splat = shufflevector <2 x double> %broadcast.splatinsert, <2 x double> poison, <2 x i32> zeroinitializer
  br label %.preheader.us.us.us.us.us.us

.preheader.us.us.us.us.us.us:                     ; preds = %._crit_edge.us.us.us.us.us.us, %.preheader.lr.ph.us.us.us.us.us
  %indvars.iv80 = phi i64 [ %indvars.iv.next81, %._crit_edge.us.us.us.us.us.us ], [ %20, %.preheader.lr.ph.us.us.us.us.us ]
  %indvars.iv76 = phi i64 [ %indvars.iv.next77, %._crit_edge.us.us.us.us.us.us ], [ 0, %.preheader.lr.ph.us.us.us.us.us ]
  %24 = mul nuw nsw i64 %indvars.iv76, %17
  %25 = mul nuw nsw i64 %indvars.iv80, %18
  %invariant.gep = getelementptr inbounds double, ptr %5, i64 %24
  %invariant.gep97 = getelementptr inbounds double, ptr %12, i64 %25
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.preheader.us.us.us.us.us.us
  %invariant.gep106 = getelementptr double, ptr %invariant.gep97, i64 %22
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %26 = getelementptr inbounds double, ptr %invariant.gep, i64 %index
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %wide.load = load <2 x double>, ptr %26, align 8, !tbaa !5
  %wide.load105 = load <2 x double>, ptr %27, align 8, !tbaa !5
  %28 = fmul <2 x double> %broadcast.splat, %wide.load
  %29 = fmul <2 x double> %broadcast.splat, %wide.load105
  %gep107 = getelementptr double, ptr %invariant.gep106, i64 %index
  %30 = getelementptr inbounds i8, ptr %gep107, i64 16
  store <2 x double> %28, ptr %gep107, align 8, !tbaa !5
  store <2 x double> %29, ptr %30, align 8, !tbaa !5
  %index.next = add nuw i64 %index, 4
  %31 = icmp eq i64 %index.next, %n.vec
  br i1 %31, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us.us.us.us.us.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.preheader.us.us.us.us.us.us
  %indvars.iv71.ph = phi i64 [ 0, %.preheader.us.us.us.us.us.us ], [ %n.vec, %middle.block ]
  %indvars.iv69.ph = phi i64 [ %22, %.preheader.us.us.us.us.us.us ], [ %ind.end, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv71 = phi i64 [ %indvars.iv.next72, %scalar.ph ], [ %indvars.iv71.ph, %scalar.ph.preheader ]
  %indvars.iv69 = phi i64 [ %indvars.iv.next70, %scalar.ph ], [ %indvars.iv69.ph, %scalar.ph.preheader ]
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %indvars.iv71
  %32 = load double, ptr %gep, align 8, !tbaa !5
  %33 = fmul double %23, %32
  %gep98 = getelementptr inbounds double, ptr %invariant.gep97, i64 %indvars.iv69
  store double %33, ptr %gep98, align 8, !tbaa !5
  %indvars.iv.next70 = add nuw nsw i64 %indvars.iv69, 1
  %indvars.iv.next72 = add nuw nsw i64 %indvars.iv71, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next72, %17
  br i1 %exitcond.not, label %._crit_edge.us.us.us.us.us.us, label %scalar.ph, !llvm.loop !13

._crit_edge.us.us.us.us.us.us:                    ; preds = %scalar.ph, %middle.block
  %indvars.iv.next81 = add nuw nsw i64 %indvars.iv80, 1
  %indvars.iv.next77 = add nuw nsw i64 %indvars.iv76, 1
  %exitcond86.not = icmp eq i64 %indvars.iv.next77, %wide.trip.count85
  br i1 %exitcond86.not, label %._crit_edge50.split.us.us.us.us.us.us, label %.preheader.us.us.us.us.us.us, !llvm.loop !14

._crit_edge50.split.us.us.us.us.us.us:            ; preds = %._crit_edge.us.us.us.us.us.us
  %indvars.iv.next88 = add nuw nsw i64 %indvars.iv87, 1
  %indvars.iv.next = add i32 %indvars.iv, %3
  %exitcond91.not = icmp eq i64 %indvars.iv.next88, %19
  br i1 %exitcond91.not, label %._crit_edge.split.us.split.us.us.us.us, label %.preheader.lr.ph.us.us.us.us.us, !llvm.loop !15

._crit_edge.split.us.split.us.us.us.us:           ; preds = %._crit_edge50.split.us.us.us.us.us.us
  %indvars.iv.next93 = add nuw nsw i64 %indvars.iv92, 1
  %indvars.iv.next79 = add i32 %indvars.iv78, %4
  %exitcond96.not = icmp eq i64 %indvars.iv.next93, %wide.trip.count95
  br i1 %exitcond96.not, label %._crit_edge58, label %.preheader45.us.us.us, !llvm.loop !16

._crit_edge58:                                    ; preds = %._crit_edge.split.us.split.us.us.us.us, %.preheader45.lr.ph, %6
  ret ptr %12
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree nounwind memory(write, argmem: read, inaccessiblemem: 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" }
attributes #2 = { nounwind allocsize(0) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/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, !12, !11}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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