; 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nounwind uwtable
define dso_local double @r8mat_is_identity(i32 noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store double 0.000000e+00, ptr %5, align 8, !tbaa !11
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %52, %2
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %13, label %55

13:                                               ; preds = %9
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %48, %13
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %18, label %51

18:                                               ; preds = %14
  %19 = load i32, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = icmp eq i32 %19, %20
  br i1 %21, label %22, label %33

22:                                               ; preds = %18
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = load i32, ptr %3, align 4, !tbaa !5
  %27 = mul nsw i32 %25, %26
  %28 = add nsw i32 %24, %27
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds double, ptr %23, i64 %29
  %31 = load double, ptr %30, align 8, !tbaa !11
  %32 = fsub double %31, 1.000000e+00
  store double %32, ptr %8, align 8, !tbaa !11
  br label %43

33:                                               ; preds = %18
  %34 = load ptr, ptr %4, align 8, !tbaa !9
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = mul nsw i32 %36, %37
  %39 = add nsw i32 %35, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds double, ptr %34, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !11
  store double %42, ptr %8, align 8, !tbaa !11
  br label %43

43:                                               ; preds = %33, %22
  %44 = load double, ptr %5, align 8, !tbaa !11
  %45 = load double, ptr %8, align 8, !tbaa !11
  %46 = load double, ptr %8, align 8, !tbaa !11
  %47 = call double @llvm.fmuladd.f64(double %45, double %46, double %44)
  store double %47, ptr %5, align 8, !tbaa !11
  br label %48

48:                                               ; preds = %43
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %7, align 4, !tbaa !5
  br label %14, !llvm.loop !13

51:                                               ; preds = %14
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %6, align 4, !tbaa !5
  br label %9, !llvm.loop !15

55:                                               ; preds = %9
  %56 = load double, ptr %5, align 8, !tbaa !11
  %57 = call double @sqrt(double noundef %56) #4
  store double %57, ptr %5, align 8, !tbaa !11
  %58 = load double, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret double %58
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nounwind "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 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 = !{!"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}


; 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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind memory(write, argmem: readwrite) uwtable
define dso_local double @r8mat_is_identity(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = icmp sgt i32 %0, 0
  br i1 %3, label %.preheader.us.preheader, label %._crit_edge28

.preheader.us.preheader:                          ; preds = %2
  %4 = zext nneg i32 %0 to i64
  %indvars.iv3136 = add nuw nsw i64 %4, 1
  %xtraiter = and i64 %4, 1
  %5 = icmp eq i32 %0, 1
  %unroll_iter = and i64 %4, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %indvars.iv31 = phi i64 [ 0, %.preheader.us.preheader ], [ %indvars.iv.next32, %._crit_edge.us ]
  %.02226.us = phi double [ 0.000000e+00, %.preheader.us.preheader ], [ %.lcssa, %._crit_edge.us ]
  %invariant.gep = getelementptr inbounds double, ptr %1, i64 %indvars.iv31
  %6 = mul nuw i64 %indvars.iv31, %indvars.iv3136
  %7 = getelementptr inbounds double, ptr %1, i64 %6
  br i1 %5, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %24
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %24 ], [ 0, %.preheader.us ]
  %.124.us = phi double [ %25, %24 ], [ %.02226.us, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %24 ], [ 0, %.preheader.us ]
  %8 = icmp eq i64 %indvars.iv31, %indvars.iv
  br i1 %8, label %12, label %9

9:                                                ; preds = %.preheader.us.new
  %10 = mul nuw nsw i64 %indvars.iv, %4
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %10
  %11 = load double, ptr %gep, align 8, !tbaa !5
  br label %15

12:                                               ; preds = %.preheader.us.new
  %13 = load double, ptr %7, align 8, !tbaa !5
  %14 = fadd double %13, -1.000000e+00
  br label %15

15:                                               ; preds = %12, %9
  %.0.us = phi double [ %14, %12 ], [ %11, %9 ]
  %16 = tail call double @llvm.fmuladd.f64(double %.0.us, double %.0.us, double %.124.us)
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = icmp eq i64 %indvars.iv31, %indvars.iv.next
  br i1 %17, label %21, label %18

18:                                               ; preds = %15
  %19 = mul nuw nsw i64 %indvars.iv.next, %4
  %gep.1 = getelementptr inbounds double, ptr %invariant.gep, i64 %19
  %20 = load double, ptr %gep.1, align 8, !tbaa !5
  br label %24

21:                                               ; preds = %15
  %22 = load double, ptr %7, align 8, !tbaa !5
  %23 = fadd double %22, -1.000000e+00
  br label %24

24:                                               ; preds = %21, %18
  %.0.us.1 = phi double [ %23, %21 ], [ %20, %18 ]
  %25 = tail call double @llvm.fmuladd.f64(double %.0.us.1, double %.0.us.1, double %16)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !9

._crit_edge.us.unr-lcssa:                         ; preds = %24, %.preheader.us
  %.lcssa.ph = phi double [ poison, %.preheader.us ], [ %25, %24 ]
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %24 ]
  %.124.us.unr = phi double [ %.02226.us, %.preheader.us ], [ %25, %24 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %26 = icmp eq i64 %indvars.iv31, %indvars.iv.unr
  br i1 %26, label %30, label %27

27:                                               ; preds = %.epil.preheader
  %28 = mul nuw nsw i64 %indvars.iv.unr, %4
  %gep.epil = getelementptr inbounds double, ptr %invariant.gep, i64 %28
  %29 = load double, ptr %gep.epil, align 8, !tbaa !5
  br label %._crit_edge.us.epilog-lcssa

30:                                               ; preds = %.epil.preheader
  %31 = load double, ptr %7, align 8, !tbaa !5
  %32 = fadd double %31, -1.000000e+00
  br label %._crit_edge.us.epilog-lcssa

._crit_edge.us.epilog-lcssa:                      ; preds = %30, %27
  %.0.us.epil = phi double [ %32, %30 ], [ %29, %27 ]
  %33 = tail call double @llvm.fmuladd.f64(double %.0.us.epil, double %.0.us.epil, double %.124.us.unr)
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %._crit_edge.us.epilog-lcssa
  %.lcssa = phi double [ %.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %33, %._crit_edge.us.epilog-lcssa ]
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %exitcond35.not = icmp eq i64 %indvars.iv.next32, %4
  br i1 %exitcond35.not, label %._crit_edge28, label %.preheader.us, !llvm.loop !11

._crit_edge28:                                    ; preds = %._crit_edge.us, %2
  %.022.lcssa = phi double [ 0.000000e+00, %2 ], [ %.lcssa, %._crit_edge.us ]
  %34 = tail call double @sqrt(double noundef %.022.lcssa) #3
  ret double %34
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(write) "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 = { nofree nounwind memory(write, 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" }
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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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